ilang  1.1.4
ILAng: A Modeling and Verification Platform for SoCs
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Macros
smt_switch_itf.h
Go to the documentation of this file.
1 
4 #ifndef ILANG_ILA_MNGR_U_SMT_SWITCH_H__
5 #define ILANG_ILA_MNGR_U_SMT_SWITCH_H__
6 
7 #ifdef SMTSWITCH_INTERFACE
8 
9 #include <string>
10 #include <unordered_map>
11 
12 #include <smt-switch/smt.h>
13 
14 #include <ilang/ila/ast_hub.h>
15 
17 namespace ilang {
18 
20 class SmtSwitchItf {
21 public:
22  // ------------------------- CONSTRUCTOR/DESTRUCTOR ----------------------- //
24  SmtSwitchItf(smt::SmtSolver& solver);
26  ~SmtSwitchItf();
27 
28  // ------------------------- METHODS -------------------------------------- //
30  smt::Term GetSmtTerm(const ExprPtr& expr, const std::string& suffix = "");
32  void Reset();
34  inline smt::SmtSolver& solver() const { return solver_; }
35 
37  bool pre(const ExprPtr& expr);
39  void post(const ExprPtr& expr);
40 
41  // ------------------------- SHIM INTERFACE ------------------------------- //
43  inline auto GetShimExpr(const ExprPtr& expr, const std::string& suffix) {
44  return GetSmtTerm(expr, suffix);
45  }
47  inline auto GetShimFunc(const FuncPtr& func) { return Func2Term(func); }
49  inline auto BoolAnd(const smt::Term& a, const smt::Term& b) {
50  return solver_->make_term(smt::PrimOp::And, a, b);
51  }
53  inline auto Equal(const smt::Term& a, const smt::Term& b) {
54  return solver_->make_term(smt::PrimOp::Equal, a, b);
55  }
56 
57 private:
59  typedef std::unordered_map<const ExprPtr, smt::Term, ExprHash> ExprTermMap;
61  typedef std::unordered_map<const FuncPtr, smt::Term, FuncHash> FuncTermMap;
62 
63  // ------------------------- MEMBERS -------------------------------------- //
65  smt::SmtSolver& solver_;
67  ExprTermMap expr_map_;
69  FuncTermMap func_map_;
71  std::string suffix_ = "";
72 
73  // ------------------------- HELPERS -------------------------------------- //
75  void PopulateExprMap(const ExprPtr& expr);
77  smt::Term ExprVar2Term(const ExprPtr& expr);
79  smt::Term ExprConst2Term(const ExprPtr& expr);
81  smt::Term ExprOp2Term(const ExprPtr& expr, const smt::TermVec& arg_terms);
83  smt::Term Func2Term(const FuncPtr& func);
85  smt::Sort IlaSort2SmtSort(const SortPtr& s);
86 
87 }; // class SmtSwitchItf
88 
89 } // namespace ilang
90 
91 #endif // SMTSWITCH_INTERFACE
92 
93 #endif // ILANG_ILA_MNGR_U_SMT_SWITCH_H__
94 
Expr::ExprPtr ExprPtr
Pointer type for normal use of Expr.
Definition: expr.h:138
Sort::SortPtr SortPtr
Pointer type for storing/passing Sort.
Definition: sort.h:82
Func::FuncPtr FuncPtr
Pointer type for normal use of Func.
Definition: func.h:83