00001 #ifndef Rose_YicesSolver_H
00002 #define Rose_YicesSolver_H
00003
00004 #include "SMTSolver.h"
00005
00006 #ifdef HAVE_LIBYICES
00007 # include <yices_c.h>
00008 #endif
00009
00017 class YicesSolver: public SMTSolver {
00018 public:
00020 enum LinkMode
00021 {
00022 LM_NONE=0x0000,
00023 LM_LIBRARY=0x0001,
00024 LM_EXECUTABLE=0x0002
00025 };
00026
00028 YicesSolver(): linkage(LM_NONE), context(NULL) {
00029 init();
00030 }
00031 virtual ~YicesSolver();
00032
00033 virtual void generate_file(std::ostream&, const std::vector<InsnSemanticsExpr::TreeNodePtr> &exprs, Definitions*);
00034 virtual std::string get_command(const std::string &config_name);
00035
00037 unsigned available_linkage() const;
00038
00040 LinkMode get_linkage() const {
00041 return linkage;
00042 }
00043
00045 void set_linkage(LinkMode lm) {
00046 ROSE_ASSERT(lm & available_linkage());
00047 linkage = lm;
00048 }
00049
00055 virtual bool satisfiable(const std::vector<InsnSemanticsExpr::TreeNodePtr> &exprs);
00056 virtual bool satisfiable(const InsnSemanticsExpr::TreeNodePtr &tn) {
00057 std::vector<InsnSemanticsExpr::TreeNodePtr> exprs;
00058 exprs.push_back(tn);
00059 return satisfiable(exprs);
00060 }
00065 virtual InsnSemanticsExpr::TreeNodePtr get_definition(uint64_t varno);
00066
00067 virtual InsnSemanticsExpr::TreeNodePtr get_definition(const InsnSemanticsExpr::LeafNodePtr &var) {
00068 assert(var!=NULL && !var->is_known());
00069 return get_definition(var->get_name());
00070 }
00073 protected:
00074 virtual void parse_evidence();
00075 std::map<uint64_t, std::pair<size_t, uint64_t> > evidence;
00076
00077 private:
00078 LinkMode linkage;
00079 void init();
00080
00081
00082
00083 void out_define(std::ostream&, const InsnSemanticsExpr::TreeNodePtr&, Definitions*);
00084 void out_assert(std::ostream&, const InsnSemanticsExpr::TreeNodePtr&);
00085 void out_number(std::ostream&, const InsnSemanticsExpr::TreeNodePtr&);
00086 void out_expr(std::ostream&, const InsnSemanticsExpr::TreeNodePtr&);
00087 void out_unary(std::ostream&, const char *opname, const InsnSemanticsExpr::InternalNodePtr&);
00088 void out_binary(std::ostream&, const char *opname, const InsnSemanticsExpr::InternalNodePtr&);
00089 void out_ite(std::ostream&, const InsnSemanticsExpr::InternalNodePtr&);
00090 void out_la(std::ostream&, const char *opname, const InsnSemanticsExpr::InternalNodePtr&, bool identity_elmt);
00091 void out_la(std::ostream&, const char *opname, const InsnSemanticsExpr::InternalNodePtr&);
00092 void out_extract(std::ostream&, const InsnSemanticsExpr::InternalNodePtr&);
00093 void out_sext(std::ostream&, const InsnSemanticsExpr::InternalNodePtr&);
00094 void out_uext(std::ostream&, const InsnSemanticsExpr::InternalNodePtr&);
00095 void out_shift(std::ostream&, const char *opname, const InsnSemanticsExpr::InternalNodePtr&, bool newbits);
00096 void out_asr(std::ostream&, const InsnSemanticsExpr::InternalNodePtr&);
00097 void out_zerop(std::ostream&, const InsnSemanticsExpr::InternalNodePtr&);
00098 void out_mult(std::ostream &o, const InsnSemanticsExpr::InternalNodePtr&);
00099
00100 #ifdef HAVE_LIBYICES
00101
00102 typedef yices_expr (*UnaryAPI)(yices_context, yices_expr operand);
00103 typedef yices_expr (*BinaryAPI)(yices_context, yices_expr operand1, yices_expr operand2);
00104 typedef yices_expr (*NaryAPI)(yices_context, yices_expr *operands, unsigned n_operands);
00105 typedef yices_expr (*ShiftAPI)(yices_context, yices_expr, unsigned amount);
00106
00107 yices_context context;
00108 void ctx_define(const InsnSemanticsExpr::TreeNodePtr&, Definitions*);
00109 void ctx_assert(const InsnSemanticsExpr::TreeNodePtr&);
00110 yices_expr ctx_expr(const InsnSemanticsExpr::TreeNodePtr&);
00111 yices_expr ctx_unary(UnaryAPI, const InsnSemanticsExpr::InternalNodePtr&);
00112 yices_expr ctx_binary(BinaryAPI, const InsnSemanticsExpr::InternalNodePtr&);
00113 yices_expr ctx_ite(const InsnSemanticsExpr::InternalNodePtr&);
00114 yices_expr ctx_la(BinaryAPI, const InsnSemanticsExpr::InternalNodePtr&, bool identity_elmt);
00115 yices_expr ctx_la(NaryAPI, const InsnSemanticsExpr::InternalNodePtr&, bool identity_elmt);
00116 yices_expr ctx_la(BinaryAPI, const InsnSemanticsExpr::InternalNodePtr&);
00117 yices_expr ctx_extract(const InsnSemanticsExpr::InternalNodePtr&);
00118 yices_expr ctx_sext(const InsnSemanticsExpr::InternalNodePtr&);
00119 yices_expr ctx_uext(const InsnSemanticsExpr::InternalNodePtr&);
00120 yices_expr ctx_shift(ShiftAPI, const InsnSemanticsExpr::InternalNodePtr&);
00121 yices_expr ctx_asr(const InsnSemanticsExpr::InternalNodePtr&);
00122 yices_expr ctx_zerop(const InsnSemanticsExpr::InternalNodePtr&);
00123 yices_expr ctx_mult(const InsnSemanticsExpr::InternalNodePtr&);
00124 #else
00125 void *context;
00126 #endif
00127
00128 };
00129
00130 #endif