ilang  1.1.4
ILAng: A Modeling and Verification Platform for SoCs
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Macros
instr_lvl_abs.h
Go to the documentation of this file.
1 
4 #ifndef ILANG_ILA_INSTR_LVL_ABS_H__
5 #define ILANG_ILA_INSTR_LVL_ABS_H__
6 
7 #include <map>
8 #include <memory>
9 #include <ostream>
10 #include <stack>
11 #include <string>
12 
13 #include <ilang/ila/ast/func.h>
14 #include <ilang/ila/ast_hub.h>
15 #include <ilang/ila/hash_ast.h>
16 #include <ilang/ila/instr.h>
17 #include <ilang/ila/object.h>
18 #include <ilang/ila/transition.h>
19 #include <ilang/util/container.h>
20 
22 namespace ilang {
23 
35 class InstrLvlAbs : public Object,
36  public std::enable_shared_from_this<InstrLvlAbs> {
37 public:
39  typedef std::shared_ptr<InstrLvlAbs> InstrLvlAbsPtr;
41  typedef std::shared_ptr<const InstrLvlAbs> InstrLvlAbsCnstPtr;
44 
45 private:
50 
51 public:
52  // ------------------------- CONSTRUCTOR/DESTRUCTOR ----------------------- //
54  InstrLvlAbs(const std::string& name = "",
55  const InstrLvlAbsPtr& parent = nullptr);
57  ~InstrLvlAbs();
58 
59  // ------------------------- HELPERS -------------------------------------- //
62  static InstrLvlAbsPtr New(const std::string& name,
63  const InstrLvlAbsPtr& parent = nullptr);
64 
65  // ------------------------- ACCESSORS/MUTATORS --------------------------- //
67  bool is_instr_lvl_abs() const { return true; }
68 
70  inline bool is_spec() const { return is_spec_; }
72  inline const InstrLvlAbsPtr parent() const { return parent_; }
74  inline const ExprMngrPtr expr_mngr() const { return expr_mngr_; }
75 
77  inline void set_spec(bool spec) { is_spec_ = spec; }
79  inline void set_expr_mngr(const ExprMngrPtr expr_mngr) {
80  expr_mngr_ = expr_mngr;
81  }
82 
84  inline size_t input_num() const { return inputs_.size(); }
86  inline size_t state_num() const { return states_.size(); }
88  inline size_t instr_num() const { return instrs_.size(); }
90  inline size_t child_num() const { return childs_.size(); }
92  inline size_t init_num() const { return inits_.size(); }
93 
95  inline const ExprPtr fetch() const { return fetch_; }
97  inline const ExprPtr valid() const { return valid_; }
98 
100  inline const ExprPtr input(const size_t& i) const { return inputs_[i]; }
102  inline const ExprPtr state(const size_t& i) const { return states_[i]; }
104  inline const InstrPtr instr(const size_t& i) const { return instrs_[i]; }
106  inline const InstrLvlAbsPtr child(const size_t& i) const {
107  return childs_[i];
108  }
110  const ExprPtr init(const size_t& i) const { return inits_[i]; }
111 
113  const ExprPtr input(const std::string& name) const;
115  const ExprPtr state(const std::string& name) const;
117  const InstrPtr instr(const std::string& name) const;
119  const InstrLvlAbsPtr child(const std::string& name) const;
120 
122  const ExprPtr find_input(const Symbol& name) const;
124  const ExprPtr find_state(const Symbol& name) const;
126  const InstrPtr find_instr(const Symbol& name) const;
128  const InstrLvlAbsPtr find_child(const Symbol& name) const;
129 
130  const InstrSeqPtr& instr_seq() const { return instr_seq_; }
131 
132  // ------------------------- METHODS -------------------------------------- //
135  void AddInput(const ExprPtr& input_var);
136 
139  void AddState(const ExprPtr& state_var);
140 
144  void AddInit(const ExprPtr& cntr_expr);
145 
148  void SetFetch(const ExprPtr& fetch_expr);
149 
152  void SetValid(const ExprPtr& valid_expr);
153 
157  void AddInstr(const InstrPtr& instr);
158 
161  void AddChild(const InstrLvlAbsPtr& child);
162 
166  const ExprPtr NewBoolInput(const std::string& name);
167 
172  const ExprPtr NewBvInput(const std::string& name, const int& bit_width);
173 
179  const ExprPtr NewMemInput(const std::string& name, const int& addr_width,
180  const int& data_width);
181 
185  const ExprPtr NewBoolState(const std::string& name);
186 
191  const ExprPtr NewBvState(const std::string& name, const int& bit_width);
192 
198  const ExprPtr NewMemState(const std::string& name, const int& addr_width,
199  const int& data_width);
200 
204  const ExprPtr NewBoolFreeVar(const std::string& name);
205 
210  const ExprPtr NewBvFreeVar(const std::string& name, const int& bit_width);
211 
217  const ExprPtr NewMemFreeVar(const std::string& name, const int& addr_width,
218  const int& data_width);
219 
223  const InstrPtr NewInstr(const std::string& name = "");
224 
228  const InstrLvlAbsPtr NewChild(const std::string& name);
229 
232  void ForceSetFetch(const ExprPtr& fetch_expr);
233 
236  void ForceSetValid(const ExprPtr& valid_expr);
237 
242  void AddSeqTran(const InstrPtr& src, const InstrPtr& dst, const ExprPtr& cnd);
243 
245  std::string GetRootName() const;
246 
248  std::ostream& Print(std::ostream& out) const;
249 
251  friend std::ostream& operator<<(std::ostream& out, InstrLvlAbs& ila);
253  friend std::ostream& operator<<(std::ostream& out, InstrLvlAbsPtr ila);
255  friend std::ostream& operator<<(std::ostream& out, InstrLvlAbsCnstPtr ila);
256 
257  friend class Instr;
258 
260  template <class F> void DepthFirstVisit(F& func) const {
261  // traverse child
262  for (decltype(child_num()) i = 0; i != child_num(); i++) {
263  auto child_i = this->child(i);
264  child_i->DepthFirstVisit<F>(func);
265  }
266  // apply function ()
267  func(shared_from_this());
268  }
269 
272  template <class F> void DepthFirstVisitPrePost(F& func) const {
273  // pre
274  if (func.pre(shared_from_this())) { // break if return true
275  return;
276  }
277  // traverse child
278  for (decltype(child_num()) i = 0; i != child_num(); i++) {
279  auto child_i = this->child(i);
280  child_i->DepthFirstVisitPrePost<F>(func);
281  }
282  // post
283  func.post(shared_from_this());
284  }
285 
286 private:
287  // ------------------------- MEMBERS -------------------------------------- //
289  InstrLvlAbsPtr parent_;
291  VarMap inputs_;
293  VarMap states_;
295  ExprPtrVec inits_;
297  ExprPtr fetch_ = nullptr;
299  ExprPtr valid_ = nullptr;
301  InstrMap instrs_;
303  InstrLvlAbsMap childs_;
304  // child-instr sequencing
305  InstrSeqPtr instr_seq_ = nullptr;
306 
308  bool is_spec_ = true;
309 
311  ExprMngrPtr expr_mngr_ = nullptr;
312 
313  // ------------------------- HELPERS -------------------------------------- //
315  ExprPtr Unify(const ExprPtr& e);
317  void InitObject();
319  void CheckInstr(const InstrPtr& instr);
321  void SimplifyInstr(const InstrPtr& instr);
322 
323 }; // class InstrLvlAbs
324 
330 typedef std::map<InstrLvlAbsCnstPtr, InstrLvlAbsPtr> CnstIlaMap;
331 
332 } // namespace ilang
333 
334 #endif // ILANG_ILA_INSTR_LVL_ABS_H__
size_t input_num() const
Return the number of input variables.
Definition: instr_lvl_abs.h:84
const ExprPtr init(const size_t &i) const
Access the i-th initial condition.
Definition: instr_lvl_abs.h:110
void ForceSetFetch(const ExprPtr &fetch_expr)
Set the fetch function no matter if is already set.
const InstrPtr find_instr(const Symbol &name) const
Return the named instruction; return NULL if not registered.
const ExprPtr find_input(const Symbol &name) const
Return the named input variable; return NULL if not registered.
ExprMngr::ExprMngrPtr ExprMngrPtr
Pointer type for passing shared ast simplifier.
Definition: hash_ast.h:56
std::shared_ptr< const InstrLvlAbs > InstrLvlAbsCnstPtr
Pointer type for read-only usage of InstrLvlAbs.
Definition: instr_lvl_abs.h:41
Expr::ExprPtr ExprPtr
Pointer type for normal use of Expr.
Definition: expr.h:138
size_t instr_num() const
Return the number of instructions.
Definition: instr_lvl_abs.h:88
bool is_instr_lvl_abs() const
Return true if is InstrLvlAbs.
Definition: instr_lvl_abs.h:67
InstrLvlAbs::InstrLvlAbsCnstPtr InstrLvlAbsCnstPtr
Pointer type for read-only usage of InstrLvlAbs.
Definition: instr_lvl_abs.h:328
std::string GetRootName() const
Return the ancestor names in sequence.
void AddSeqTran(const InstrPtr &src, const InstrPtr &dst, const ExprPtr &cnd)
Define instruction sequencing by adding a transition edge.
std::shared_ptr< InstrLvlAbs > InstrLvlAbsPtr
Pointer type for normal use of InstrLvlAbs.
Definition: instr_lvl_abs.h:39
std::ostream & Print(std::ostream &out) const
Output stream function.
void set_expr_mngr(const ExprMngrPtr expr_mngr)
Update the ast simplifier.
Definition: instr_lvl_abs.h:79
const ExprPtr NewBvState(const std::string &name, const int &bit_width)
Create one Bitvector variable and register as a state.
void AddChild(const InstrLvlAbsPtr &child)
Add one ILA to the child list. No simplification between ILAs.
const InstrLvlAbsPtr find_child(const Symbol &name) const
Return the named child-ILA; return NULL if not registered.
const ExprPtr fetch() const
Return the fetch function.
Definition: instr_lvl_abs.h:95
const ExprPtr state(const size_t &i) const
Access the i-th state variable.
Definition: instr_lvl_abs.h:102
size_t state_num() const
Return the number of state variables.
Definition: instr_lvl_abs.h:86
void ForceSetValid(const ExprPtr &valid_expr)
Set the valid function no matter if is already set.
void set_spec(bool spec)
Set the ILA to be specification if true.
Definition: instr_lvl_abs.h:77
KeyVec< Symbol, InstrLvlAbsPtr > InstrLvlAbsMap
Type for storing a set of ILA (child-ILAs).
Definition: instr_lvl_abs.h:43
void SetFetch(const ExprPtr &fetch_expr)
Set the fetch function, and simplify (if needed) by the simplifier.
void AddInit(const ExprPtr &cntr_expr)
Add one constraint to the initial condition, i.e. no contraint means arbitrary initial values to the ...
void DepthFirstVisit(F &func) const
Templated visitor: visit each child-ILA in a depth-first order.
Definition: instr_lvl_abs.h:260
Instr::InstrPtr InstrPtr
Pointer type for normal use of Instr.
Definition: instr.h:132
size_t size() const
Return the number of data stored.
Definition: container.h:78
const ExprPtr NewMemState(const std::string &name, const int &addr_width, const int &data_width)
Create one Memory variable and register as a state.
const InstrPtr NewInstr(const std::string &name="")
Create and register one instruction.
The class of Instruction-Level Abstraction (ILA). An ILA contains:
Definition: instr_lvl_abs.h:35
const ExprPtr valid() const
Return the valid function.
Definition: instr_lvl_abs.h:97
std::map< InstrLvlAbsCnstPtr, InstrLvlAbsPtr > CnstIlaMap
Type for storing a mapping from constant ILA ptr to ILA ptr.
Definition: instr_lvl_abs.h:330
InstrLvlAbs(const std::string &name="", const InstrLvlAbsPtr &parent=nullptr)
Consturctor.
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
void DepthFirstVisitPrePost(F &func) const
Templated visitor: visit each child-ILA in a depth-first order and apply the function object F pre/po...
Definition: instr_lvl_abs.h:272
const InstrLvlAbsPtr child(const size_t &i) const
Access the i-th child-ILA.
Definition: instr_lvl_abs.h:106
const ExprPtr NewBvInput(const std::string &name, const int &bit_width)
Create one Bitvector variable and register as an input.
const InstrLvlAbsPtr parent() const
Return the parent ILA.
Definition: instr_lvl_abs.h:72
void AddInstr(const InstrPtr &instr)
Add one instruction to the ILA, and simplify (if needed). Note that only fully constructed instructio...
size_t child_num() const
Return the number of child-ILAs.
Definition: instr_lvl_abs.h:90
The basest type in the ILA structure. It can be either Ast, Instr, or InstrLvlAbs.
Definition: object.h:17
InstrSeq::InstrSeqPtr InstrSeqPtr
Pointer type for passing around InstrSeq.
Definition: transition.h:140
const InstrPtr instr(const size_t &i) const
Access the i-th instruction.
Definition: instr_lvl_abs.h:104
void AddState(const ExprPtr &state_var)
Add one state variable to the ILA, and register to the simplifier.
const ExprPtr NewBoolInput(const std::string &name)
Create one Boolean variable and register as an input.
bool is_spec() const
Return true if is specification (not implementation).
Definition: instr_lvl_abs.h:70
The symbol is the name and ID of an object. Every object has an unique symbol.
Definition: symbol.h:16
const ExprPtr input(const size_t &i) const
Access the i-th input variable.
Definition: instr_lvl_abs.h:100
const ExprPtr NewMemInput(const std::string &name, const int &addr_width, const int &data_width)
Create one Memory variable and register as an input.
friend std::ostream & operator<<(std::ostream &out, InstrLvlAbs &ila)
Overload output stream for object.
static InstrLvlAbsPtr New(const std::string &name, const InstrLvlAbsPtr &parent=nullptr)
Create a new ILA (InstrLvlAbs) with the name. Used for hiding implementation specific type details...
const ExprPtr NewBoolFreeVar(const std::string &name)
Create one free Boolean variable.
void SetValid(const ExprPtr &valid_expr)
Set the valid function, and simplify (if needed) by the simplifier.
void AddInput(const ExprPtr &input_var)
Add one input variable to the ILA, and register to the simplifier.
~InstrLvlAbs()
Default destructor.
size_t init_num() const
Return the number of initial condition.
Definition: instr_lvl_abs.h:92
const ExprPtr NewMemFreeVar(const std::string &name, const int &addr_width, const int &data_width)
Create one free Memory variable.
const ExprPtr NewBoolState(const std::string &name)
Create one Boolean variable and register as a state.
const InstrLvlAbsPtr NewChild(const std::string &name)
Create and register one child-ILA.
const ExprMngrPtr expr_mngr() const
Return the ast simplifier.
Definition: instr_lvl_abs.h:74
const ExprPtr NewBvFreeVar(const std::string &name, const int &bit_width)
Create one free bit-vector variable.
const ExprPtr find_state(const Symbol &name) const
Return the named state variable; return NULL if not registered.
const Symbol & name() const
Get the symbol (name).