ilang  1.1.4
ILAng: A Modeling and Verification Platform for SoCs
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Macros
ast_helper.h
Go to the documentation of this file.
1 
4 #ifndef ILANG_MCM_AST_HELPER_H__
5 #define ILANG_MCM_AST_HELPER_H__
6 
7 #include <functional>
8 #include <set>
9 #include <unordered_map>
10 #include <utility>
11 
13 #include "ilang/vtarget-out/directive.h"
14 
16 namespace ilang {
17 
18 /******************************************************************************/
19 // Helper Class
20 /******************************************************************************/
21 
29 // T can be ExprPtr or std::string
30 
31 template <class T> class VarUseFinder {
32 public:
34  typedef std::set<T> VarUseList;
36  typedef std::function<T(const ExprPtr&)> ProcessFuncType;
37  // ------------------------- CONSTRUCTOR/DESTRUCTOR ----------------------- //
39  VarUseFinder(ProcessFuncType f) : procFunc(f) {}
42 
43  // ------------------------- METHODS -------------------------------------- //
45  void Traverse(const ExprPtr& expr, VarUseList& uses);
47  void Traverse(const InstrPtr& i, VarUseList& uses);
49  void Traverse(const InstrLvlAbsPtr& i, VarUseList& uses);
50 
51 private:
52  // ------------------------- MEMBERS -------------------------------------- //
53  ProcessFuncType procFunc;
54 }; // class VarUseFinder
55 
59  typedef std::unordered_map<Expr*, bool>
60  HashTable; // here we do use the raw pointer
61 public:
62  // ------------------------- CONSTRUCTOR ---------------------------------- //
63  NestedMemAddrDataAvoider() : InAddrOrData(false) {}
64  // ------------------------- METHODS -------------------------------------- //
68  bool NotNested(const ExprPtr& node);
69 
70 private:
71  // ------------------------- MEMBERS -------------------------------------- //
73  HashTable map_;
75  bool InAddrOrData;
76 }; // class NestedMemAddrDataAvoider
77 
79 bool getIteUnknownCondVal(const ExprPtr& e, ExprPtr& c, ExprPtr& v);
80 
83 protected:
84  // ------------------------- MEMBERS -------------------------------------- //
86  std::set<std::shared_ptr<Func>> _func_refs;
88  std::set<Expr*> visited;
90  void hasFuncAppOnNode(const ExprPtr& e);
92  void hasFuncApp(const ExprPtr& expr);
93 
94 public:
95  // ------------------------- CONSTRUCTOR ---------------------------------- //
97  // get the set of the pointer of the functions
98  const std::set<std::shared_ptr<Func>> GetReferredFunc() const;
99 }; // class FunctionApplicationFinder
100 
101 #if 0
102 class PureNestedStoreDetector {
105  typedef std::vector<std::pair<ExprPtr, ExprPtr>>
106  AddrDataVec; // (addr,data) list
107 
110  typedef std::unordered_map<Expr*, AddrDataVec>
111  HashTable; // here we do use the raw pointer public:
112 
113  // ------------------------- METHODS -------------------------------------- //
115  bool isNestedStore(const ExprPtr&);
117  const AddrDataVec& getStoreAddrDataVec(const ExprPtr&);
118 
119 private:
120  // ------------------------- MEMBERS -------------------------------------- //
121  // a map
122  HashTable map_;
123 }
124 #endif
125 
126 #if 0
127 struct MRF_HASH_FUNC {
128  std::size_t operator()(const std::pair<TraceStep*, Expr*>& p) const {
129  return std::hash()(p.first) ^ std::hash()(p.second);
130  }
131 };
132 #endif
133 
134 #if 0
135 part that exists in a trace step ? class MemReadFinder {
137 public:
138  // Type of (addr,data) pair list
139  typedef std::vector<std::pair<ExprPtr, ExprPtr>> AddrDataVec;
140 
141 private:
143  typedef Instr*
144  MRFHashKey; // typedef std::pair< TraceStep *, Expr * > MRFHashKey;
146  typedef std::unordered_map<std::string, AddrDataVec>
147  MRFVal; // statename -> (addr,data) list
151  typedef std::unordered_map<MRFHashKey, MRFVal> MRFHashTable;
152 
153 private:
154  // ------------------------- MEMBERS -------------------------------------- //
156  void FindAddrDataPairVecInExpr(const ExprPtr& node, MRFVal& nad_map_);
159  void VisitNode(const ExprPtr& node, MRFVal& nad_map_);
160 
161 public:
165  const AddrDataVec& FindAddrDataPairVecInInst(const InstrPtr& instr,
166  const std::string& sname);
167 
168  // ------------------------- CONSTRUCTOR/DESTRUCTOR ----------------------- //
171  MemReadFinder(NestedMemAddrDataAvoider& n) : nested_finder_(n) {}
172 
173 private:
174  // ------------------------- MEMBERS -------------------------------------- //
176  MRFHashTable map_;
178  NestedMemAddrDataAvoider& nested_finder_;
179 
180 }; // class MemReadFinder
181 #endif
182 
183 } // namespace ilang
184 
185 #endif // ILANG_MCM_AST_HELPER_H__
bool getIteUnknownCondVal(const ExprPtr &e, ExprPtr &c, ExprPtr &v)
Function to deal with Ite(c, v, apply(unknown) );.
VarUseFinder(ProcessFuncType f)
Default constructor: do nothing.
Definition: ast_helper.h:39
Expr::ExprPtr ExprPtr
Pointer type for normal use of Expr.
Definition: expr.h:138
Class of traversing to find the application of functions in an AST.
Definition: ast_helper.h:82
std::set< std::shared_ptr< Func > > _func_refs
the functions used in app_func
Definition: ast_helper.h:86
Instr::InstrPtr InstrPtr
Pointer type for normal use of Instr.
Definition: instr.h:132
void hasFuncAppOnNode(const ExprPtr &e)
does a node contain a funcapp
void Traverse(const ExprPtr &expr, VarUseList &uses)
Find variable uses for an expression.
std::set< Expr * > visited
record whether a node has been visited
Definition: ast_helper.h:88
std::function< T(const ExprPtr &)> ProcessFuncType
Type of the function to process ExprPtr to T.
Definition: ast_helper.h:36
InstrLvlAbs::InstrLvlAbsPtr InstrLvlAbsPtr
Pointer type for normal use of InstrLvlAbs.
Definition: instr_lvl_abs.h:326
Class of traversing to avoid nested memory access in address.
Definition: ast_helper.h:57
bool NotNested(const ExprPtr &node)
std::set< T > VarUseList
Type of vector of ExprPtr with is_var() == true.
Definition: ast_helper.h:34
void hasFuncApp(const ExprPtr &expr)
does a tree contain funcapps?
~VarUseFinder()
Default destructor: do nothing.
Definition: ast_helper.h:41
Class of finding variable uses. So that we don&#39;t need to create pi variables for unused state variabl...
Definition: ast_helper.h:31