ilang  1.1.4
ILAng: A Modeling and Verification Platform for SoCs
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Macros
u_unroller.h
Go to the documentation of this file.
1 
4 #ifndef ILANG_ILA_MNGR_U_UNROLLER_H__
5 #define ILANG_ILA_MNGR_U_UNROLLER_H__
6 
7 #include <map>
8 #include <vector>
9 
10 #include <z3++.h>
11 
14 
16 namespace ilang {
17 
19 class Unroller {
20 protected:
22  typedef z3::expr ZExpr;
24  typedef z3::expr_vector ZExprVec;
27 
28 public:
29  // ------------------------- CONSTRUCTOR/DESTRUCTOR ----------------------- //
31  Unroller(z3::context& ctx, const std::string& suffix);
33  virtual ~Unroller();
34 
35  // ------------------------- METHODS -------------------------------------- //
37  void AddGlobPred(const ExprPtr& p);
39  void AddInitPred(const ExprPtr& p);
41  void AddStepPred(const ExprPtr& p, const int& k);
43  void ClearGlobPred();
45  void ClearInitPred();
47  void ClearStepPred();
49  void ClearPred();
50 
51  // ------------------------- HELPERS -------------------------------------- //
53  ZExpr CurrState(const ExprPtr& v, const int& t);
55  ZExpr NextState(const ExprPtr& v, const int& t);
57  ZExpr GetZ3Expr(const ExprPtr& e, const int& t);
59  ZExpr GetZ3Expr(const ExprPtr& e);
61  ZExpr Equal(const ExprPtr& va, const int& ta, const ExprPtr& vb,
62  const int& tb);
64  z3::func_decl GetZ3FuncDecl(const FuncPtr& f) const;
65 
66 protected:
67  // ------------------------- MEMBERS -------------------------------------- //
74 
75  // ------------------------- METHODS -------------------------------------- //
80  virtual void DefineDepVar() = 0;
81 
88  virtual void Transition(const int& idx) = 0;
89 
91  ZExpr UnrollSubs(const size_t& len, const int& pos);
93  ZExpr UnrollAssn(const size_t& len, const int& pos, bool cache = false);
95  ZExpr UnrollNone(const size_t& len, const int& pos);
96 
97  // ------------------------- HELPERS -------------------------------------- //
99  static ExprPtr StateUpdCmpl(const InstrPtr& instr, const ExprPtr& var);
101  static ExprPtr DecodeCmpl(const InstrPtr& instr);
102 
104  static ExprPtr NewFreeVar(const ExprPtr& var, const std::string& name);
105 
106 private:
107  // ------------------------- MEMBERS -------------------------------------- //
109  z3::context& ctx_;
111  Z3ExprAdapter gen_;
112 
114  std::string extra_suff_ = "";
115 
117  IExprVec g_pred_;
119  IExprVec i_pred_;
121  std::map<int, IExprVec> s_pred_;
122 
124  ZExprVec k_prev_z3_;
126  ZExprVec k_curr_z3_;
128  ZExprVec k_next_z3_;
129 
131  ZExprVec cstr_;
132 
133  // ------------------------- ACCESSORS/MUTATORS --------------------------- //
135  inline z3::context& ctx() const { return ctx_; }
137  inline Z3ExprAdapter& gen() { return gen_; }
138 
139  // ------------------------- HELPERS -------------------------------------- //
143  void BootStrap(const int& pos, bool cache = false);
144 
146  void AssertEqual(const ZExprVec& z, const IExprVec& e,
147  const std::string& suffix);
148 
150  void Clear(ZExprVec& z3_vec);
151 
153  void IExprToZExpr(const IExprVec& i_expr_src, const std::string& suffix,
154  ZExprVec& z_expr_dst);
157  void IExprToZExpr(const IExprVec& i_expr_src, const std::string& suffix,
158  ZExprVec& z_expr_dst, const ZExprVec& subs_src,
159  const ZExprVec& subs_dst);
160 
162  void CopyZExprVec(const ZExprVec& src, ZExprVec& dst);
163 
165  ZExpr ConjPred(const ZExprVec& vec) const;
166 
168  inline std::string SuffCurr(const int& t) const {
169  return std::to_string(t) + "_" + extra_suff_;
170  }
172  inline std::string SuffNext(const int& t) const {
173  return std::to_string(t) + "_" + extra_suff_ + ".nxt";
174  }
175 
176 }; // class Unroller
177 
179 class PathUnroll : public Unroller {
180 public:
182  typedef std::vector<InstrPtr> InstrVec;
183 
184  // ------------------------- CONSTRUCTOR/DESTRUCTOR ----------------------- //
186  PathUnroll(z3::context& ctx, const std::string& suff = "");
188  ~PathUnroll();
189 
190  // ------------------------- METHODS -------------------------------------- //
194  ZExpr PathSubs(const std::vector<InstrPtr>& seq, const int& pos = 0);
195 
200  ZExpr PathAssn(const std::vector<InstrPtr>& seq, const int& pos = 0);
201 
206  ZExpr PathNone(const std::vector<InstrPtr>& seq, const int& pos = 0);
207 
208 protected:
209  // ------------------------- METHODS -------------------------------------- //
214  void DefineDepVar();
215 
222  void Transition(const int& idx);
223 
224 private:
225  // ------------------------- MEMBERS -------------------------------------- //
227  InstrVec seq_;
228 }; // class PathUnroll
229 
232 class MonoUnroll : public Unroller {
233 public:
234  // ------------------------- CONSTRUCTOR/DESTRUCTOR ----------------------- //
236  MonoUnroll(z3::context& ctx, const std::string& suff = "");
238  ~MonoUnroll();
239 
240  // ------------------------- METHODS -------------------------------------- //
245  ZExpr MonoSubs(const InstrLvlAbsPtr& top, const int& length,
246  const int& pos = 0);
247 
252  ZExpr MonoAssn(const InstrLvlAbsPtr& top, const int& length,
253  const int& pos = 0);
254 
259  ZExpr MonoNone(const InstrLvlAbsPtr& top, const int& length,
260  const int& pos = 0);
261 
267  ZExpr MonoIncr(const InstrLvlAbsPtr& top, const int& length, const int& pos);
268 
269 protected:
270  // ------------------------- METHODS -------------------------------------- //
275  void DefineDepVar();
276 
283  void Transition(const int& idx);
284 
285 private:
286  // ------------------------- MEMBERS -------------------------------------- //
288  InstrLvlAbsPtr top_;
289 
290 }; // class MonoUnroll
291 
292 } // namespace ilang
293 
294 #endif // ILANG_ILA_MNGR_U_UNROLLER_H__
ZExpr NextState(const ExprPtr &v, const int &t)
Return the z3::expr representing the next state at the time.
Base class for unrolling ILA execution in different settings.
Definition: u_unroller.h:19
Application class for unrolling a path of instruction sequence.
Definition: u_unroller.h:179
IExprVec k_pred_
The set of predicates to be asserted of each step.
Definition: u_unroller.h:71
ZExpr CurrState(const ExprPtr &v, const int &t)
Return the z3::expr representing the current state at the time.
void AddGlobPred(const ExprPtr &p)
Add a predicate that should be asserted globally.
static ExprPtr NewFreeVar(const ExprPtr &var, const std::string &name)
Create a new free variable (with same sort) under the same host.
void Transition(const int &idx)
[Application-specific] Define next state update functions.
void ClearPred()
Clear all predicates.
Expr::ExprPtr ExprPtr
Pointer type for normal use of Expr.
Definition: expr.h:138
~MonoUnroll()
Default destructor.
ZExpr UnrollAssn(const size_t &len, const int &pos, bool cache=false)
Unroll without substituting internal expression.
z3::expr_vector ZExprVec
Type for containing a set of z3::expr.
Definition: u_unroller.h:24
z3::expr ZExpr
Type alias for z3::expr.
Definition: u_unroller.h:22
ZExpr PathSubs(const std::vector< InstrPtr > &seq, const int &pos=0)
Unroll a sequence of instructions with internal states substituted.
ZExpr MonoSubs(const InstrLvlAbsPtr &top, const int &length, const int &pos=0)
Unroll the ILA with internal states substituted.
Unroller(z3::context &ctx, const std::string &suffix)
Default constructor.
Application class for unrolling the ILA as a monolithic transition system.
Definition: u_unroller.h:232
void AddInitPred(const ExprPtr &p)
Add a predicate that should be asserted in the initial condition.
PathUnroll(z3::context &ctx, const std::string &suff="")
Default constructor.
void DefineDepVar()
[Application-specific] Define dependant state variables.
ZExpr MonoAssn(const InstrLvlAbsPtr &top, const int &length, const int &pos=0)
Unroll the ILA while asserting states are equal between each step.
void AddStepPred(const ExprPtr &p, const int &k)
Add a predicate that should be asserted at the k-th step.
IExprVec vars_
The set of dependant state variables.
Definition: u_unroller.h:69
ZExpr PathNone(const std::vector< InstrPtr > &seq, const int &pos=0)
Unroll a sequence of instructions without asserting states relations between steps. &quot;N(var_i) == var_i.nxt_suff&quot;.
Instr::InstrPtr InstrPtr
Pointer type for normal use of Instr.
Definition: instr.h:132
ZExpr UnrollSubs(const size_t &len, const int &pos)
Unroll while substituting internal expression.
MonoUnroll(z3::context &ctx, const std::string &suff="")
Default constructor.
Func::FuncPtr FuncPtr
Pointer type for normal use of Func.
Definition: func.h:83
static ExprPtr StateUpdCmpl(const InstrPtr &instr, const ExprPtr &var)
Return the state update function (unchanged if not defined).
std::vector< InstrPtr > InstrVec
Type of a list of instruction sequence.
Definition: u_unroller.h:182
ZExpr MonoNone(const InstrLvlAbsPtr &top, const int &length, const int &pos=0)
Unroll the ILA without asserting states relations between steps.
static ExprPtr DecodeCmpl(const InstrPtr &instr)
Return the decode function (true if not defined).
virtual void Transition(const int &idx)=0
[Application-specific] Define next state update functions.
~PathUnroll()
Default destructor.
void Transition(const int &idx)
[Application-specific] Define next state update functions.
void ClearStepPred()
Clear the step-specific predicates.
ExprPtrVec IExprVec
Type alias for a set of ExprPtr.
Definition: u_unroller.h:26
Expr::ExprPtrVec ExprPtrVec
Type for storing a set of Expr.
Definition: expr.h:140
InstrLvlAbs::InstrLvlAbsPtr InstrLvlAbsPtr
Pointer type for normal use of InstrLvlAbs.
Definition: instr_lvl_abs.h:326
virtual void DefineDepVar()=0
[Application-specific] Define dependant state variables.
ZExpr MonoIncr(const InstrLvlAbsPtr &top, const int &length, const int &pos)
Incrementally unrolling the ILA using MonoAssn (with transition relation being cached).
void DefineDepVar()
[Application-specific] Define dependant state variables.
virtual ~Unroller()
Default virtual destructor.
ZExpr PathAssn(const std::vector< InstrPtr > &seq, const int &pos=0)
Unroll a sequence of instructions while asserting states are equal between each step.
ZExpr Equal(const ExprPtr &va, const int &ta, const ExprPtr &vb, const int &tb)
Return the z3::expr representing a and b are equal at their time.
IExprVec k_next_
The set of state update functions of each step.
Definition: u_unroller.h:73
void ClearInitPred()
Clear the initial predicates.
void ClearGlobPred()
Clear the global predicates.
The class for generating z3 expression from an ILA.
Definition: z3_expr_adapter.h:20
ZExpr UnrollNone(const size_t &len, const int &pos)
Unroll without asserting state equality between each step.
ZExpr GetZ3Expr(const ExprPtr &e, const int &t)
Return the z3::expr representing the current-based Expr at the time.
z3::func_decl GetZ3FuncDecl(const FuncPtr &f) const
Return the z3::func_decl representing f.