ilang  1.1.4
ILAng: A Modeling and Verification Platform for SoCs
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Macros
verilog_analysis.h
1 // ---Hongce Zhang
16 
17 #ifndef ILANG_VERILOG_IN_VERILOG_ANALYSIS_H__
18 #define ILANG_VERILOG_IN_VERILOG_ANALYSIS_H__
19 
20 #include <map>
21 
22 // I have to put this include here, because it needs to know the class
23 // VerilogAnalyzerBase
24 #include <ilang/verilog-in/verilog_analysis_wrapper.h>
26 
27 extern "C" {
28 #include <verilogparser/verilog_ast_util.h>
29 #include <verilogparser/verilog_parser.h>
30 }
31 
32 namespace ilang {
33 
35 class VerilogAnalyzer;
36 
39 protected:
41  ast_port_declaration* _def;
42 
43 public:
46  SignalInfoPort(ast_port_declaration* def, const std::string& full_name,
48  const std::map<std::string, int>* const width_info,
49  const VerilogAnalyzer* _ana);
51  ast_port_declaration* get_def() { return _def; }
52 }; // class SignalInfoPort
53 
55 class SignalInfoReg : public SignalInfoBase {
56 protected:
58  ast_reg_declaration* _def;
59 
60 public:
63  SignalInfoReg(ast_reg_declaration* def, const std::string& full_name,
65  const std::map<std::string, int>* const width_info,
66  const VerilogAnalyzer* _ana);
68  ast_reg_declaration* get_def() { return _def; }
69 }; // class SignalInfoPort
70 
73 protected:
75  ast_net_declaration* _def;
76 
77 public:
80  SignalInfoWire(ast_net_declaration* def, const std::string& full_name,
82  const std::map<std::string, int>* const width_info,
83  const VerilogAnalyzer* _ana);
85  ast_net_declaration* get_def() { return _def; }
86 }; // class SignalInfoPort
87 
90 public:
96  typedef std::map<std::string, ast_module_declaration*> name_module_ast_map_t;
112  typedef std::map<std::string, ast_module_instantiation*> mod_inst_ast_t;
114  typedef std::map<std::string, mod_inst_ast_t> name_insts_ast_map_t;
115 
116 protected:
122  std::string top_module_name;
131 
134  std::string top_inst_name;
135 
136 public:
137  // --------------------- CONSTRUCTOR ---------------------------- //
142  VerilogAnalyzer(const path_vec_t& include_path, const path_vec_t& srcs,
143  const std::string& top_module_inst_name,
144  const std::string& optional_top_module);
145 
146  // --------------------- DESTRUCTOR ---------------------------- //
149 
150 protected:
151  // --------------------- HELPER FUNCTIONS ---------------------------- //
153  void invoke_parser();
155  void find_top_module(verilog_source_tree* source,
156  const std::string& optional_top_module);
158  void check_resolve_modules(verilog_source_tree* source);
160  void create_module_submodule_map(verilog_source_tree* source);
163  static unsigned instance_count;
164 
165 public:
166  // --------------------- MEMBERS ---------------------------- //
169  check_hierarchical_name_type(const std::string& net_name) const;
171  vlg_loc_t find_definition_of_signal(const std::string& net_name) const;
173  vlg_loc_t find_definition_of_a_module(const std::string& module_name) const;
177  void* find_declaration_of_name(const std::string& net_name) const;
179  vlg_loc_t name2loc(const std::string& net_name) const;
181  vlg_loc_t get_module_inst_loc(const std::string& inst_name) const;
183  std::string get_top_module_name() const { return top_module_name; }
186  const std::map<std::string, int>* const width_info = NULL) const;
189  get_signal(const std::string& net_name,
190  const std::map<std::string, int>* const width_info = NULL) const;
192  vlg_loc_t get_endmodule_loc(const std::string& inst_name) const;
194  std::string get_module_name_of_net_name(const std::string& net_name) const;
195 
196  // --------------------- HELPERS ---------------------------- //
198  static std::ostream& PrintMeta(std::ostream& os, const ast_metadata& md) {
199  return (os << (md.file) << ":" << (md.line));
200  }
202  template <class T>
203  static std::ostream& PrintMetaAst(std::ostream& os, const T* n) {
204  return PrintMeta(os, n->meta);
205  }
207  static vlg_loc_t Meta2Loc(const ast_metadata& md) {
208  return vlg_loc_t(md.file, md.line);
209  }
210  // --------------------- FOR verilog const parser ----------- //
214  const std::string& full_name,
216  ast_module_declaration** lowest_level) const;
217 
218 private:
219  // --------------------- MEMBERS ---------------------------- //
221  mutable name_type_buffer_t name_type_buffer;
223  mutable name_decl_buffer_t name_decl_buffer;
226  _check_hierarchical_name_type(const std::string& net_name) const;
227 
228 public:
230  bool in_bad_state() const { return _bad_state; }
231 
232 private:
234  bool _bad_state;
236  bool _bad_state_return() const;
237 
238 }; // class VerilogAnalyzer
239 
240 }; // namespace ilang
241 
242 #endif // ILANG_VERILOG_IN_VERILOG_ANALYSIS_H__
void * find_declaration_of_name(const std::string &net_name) const
void invoke_parser()
invoke the parser to parse the files
std::map< std::string, ast_module_instantiation * > mod_inst_ast_t
type of instance_name -&gt; instance_ast_node
Definition: verilog_analysis.h:112
VerilogAnalyzerBase::path_vec_t path_vec_t
type to store multiple paths
Definition: verilog_analysis.h:92
std::string top_inst_name
Definition: verilog_analysis.h:134
vlg_loc_t get_endmodule_loc(const std::string &inst_name) const
Return the location of a module&#39;s endmodule statement.
name_module_ast_map_t name_module_map
a map from name to module ast
Definition: verilog_analysis.h:124
static vlg_loc_t Meta2Loc(const ast_metadata &md)
Convert ast_meta to location.
Definition: verilog_analysis.h:207
std::map< std::string, hierarchical_name_type > name_type_buffer_t
hierarchical name -&gt; hierarchical_name_type map
Definition: verilog_analysis_wrapper.h:56
std::string top_module_name
top module name
Definition: verilog_analysis.h:122
std::vector< std::string > path_vec_t
type to store multiple paths
Definition: verilog_analysis_wrapper.h:27
VerilogAnalyzerBase::name_decl_buffer_t name_decl_buffer_t
hierarchical name -&gt; declaration pointer
Definition: verilog_analysis.h:108
name_insts_map_t modules_to_submodules_map
module -&gt; all sub modules
Definition: verilog_analysis.h:128
bool get_hierarchy_from_full_name(const std::string &full_name, VerilogConstantExprEval::param_def_hierarchy &hier, ast_module_declaration **lowest_level) const
static std::ostream & PrintMetaAst(std::ostream &os, const T *n)
Print the meta of an Ast node (cannot be void* , has to be converted)
Definition: verilog_analysis.h:203
std::map< std::string, std::vector< std::string > > name_names_map_t
A map of name -&gt; names.
Definition: verilog_analysis_wrapper.h:31
std::map< std::string, SignalInfoBase > module_io_vec_t
Top module signal list.
Definition: verilog_analysis_wrapper.h:60
VerilogAnalyzer(const path_vec_t &include_path, const path_vec_t &srcs, const std::string &top_module_inst_name, const std::string &optional_top_module)
vlg_loc_t find_definition_of_signal(const std::string &net_name) const
Return the file location of the definition of a signal.
VerilogAnalyzerBase::name_type_buffer_t name_type_buffer_t
hierarchical name -&gt; hierarchical_name_type map
Definition: verilog_analysis.h:106
hierarchical_name_type check_hierarchical_name_type(const std::string &net_name) const
Return the type of a name (used externally, cached)
std::map< std::string, mod_inst_t > name_insts_map_t
A map of module name -&gt; instantiation.
Definition: verilog_analysis_wrapper.h:35
std::string get_module_name_of_net_name(const std::string &net_name) const
Return the module name of a net — will check if the module names are.
static unsigned instance_count
Definition: verilog_analysis.h:163
vlg_loc_t find_definition_of_a_module(const std::string &module_name) const
Return the file location of the definition of a module.
void create_module_submodule_map(verilog_source_tree *source)
Update the modules_to_submodules_map.
std::map< std::string, void * > name_decl_buffer_t
hierarchical name -&gt; declaration pointer
Definition: verilog_analysis_wrapper.h:58
ast_reg_declaration * _def
Stores its own definition.
Definition: verilog_analysis.h:58
std::map< std::string, ast_module_declaration * > name_module_ast_map_t
A map to find module ast faster.
Definition: verilog_analysis.h:96
std::string get_top_module_name() const
Return top module name.
Definition: verilog_analysis.h:183
std::pair< std::string, long > vlg_loc_t
filename, line number pair : location type
Definition: verilog_analysis_wrapper.h:29
vlg_loc_t name2loc(const std::string &net_name) const
Return the location of a hierarchical name.
VerilogAnalyzerBase::module_io_vec_t module_io_vec_t
Top module signal list.
Definition: verilog_analysis.h:110
VerilogAnalyzerBase::name_names_map_t name_names_map_t
A map of name -&gt; names.
Definition: verilog_analysis.h:98
Class for Verilog analysis.
Definition: verilog_analysis.h:89
name_insts_ast_map_t modules_to_submodule_inst_ast_map
module -&gt; all sub modules and their instantiation ast
Definition: verilog_analysis.h:130
path_vec_t vlg_src_files
verilog source files
Definition: verilog_analysis.h:120
VerilogAnalyzerBase::mod_inst_t mod_inst_t
type of modulename instance name : instance_name-&gt;module_name
Definition: verilog_analysis.h:100
Class to convert reg to signal info.
Definition: verilog_analysis.h:55
VerilogAnalyzerBase::hierarchical_name_type hierarchical_name_type
The result of querying a name (please don&#39;t change the order of them)
Definition: verilog_analysis.h:104
hierarchical_name_type
The result of querying a name (please don&#39;t change the order of them)
Definition: verilog_analysis_wrapper.h:37
VerilogAnalyzerBase should never be instantiated, only used as a pointer type in class VerilogInfo...
Definition: verilog_analysis_wrapper.h:24
ast_port_declaration * get_def()
Return its definition.
Definition: verilog_analysis.h:51
VerilogAnalyzerBase::name_insts_map_t name_insts_map_t
A map of module name -&gt; instantiation.
Definition: verilog_analysis.h:102
std::map< std::string, std::string > mod_inst_t
type of modulename instance name : instance_name-&gt;module_name
Definition: verilog_analysis_wrapper.h:33
VerilogAnalyzerBase::vlg_loc_t vlg_loc_t
filename, line number pair : location type
Definition: verilog_analysis.h:94
SignalInfoReg(ast_reg_declaration *def, const std::string &full_name, VerilogAnalyzerBase::hierarchical_name_type tp, const std::map< std::string, int > *const width_info, const VerilogAnalyzer *_ana)
SignalInfoBase get_signal(const std::string &net_name, const std::map< std::string, int > *const width_info=NULL) const
Find a signal.
std::map< std::string, mod_inst_ast_t > name_insts_ast_map_t
A map of module name -&gt; the instantiation ast.
Definition: verilog_analysis.h:114
module_io_vec_t get_top_module_io(const std::map< std::string, int > *const width_info=NULL) const
Return top module signal.
Class to hold signal info.
Definition: verilog_analysis_wrapper.h:112
name_names_map_t module_to_whereuses_map
module -&gt; instantiations
Definition: verilog_analysis.h:126
SignalInfoWire(ast_net_declaration *def, const std::string &full_name, VerilogAnalyzerBase::hierarchical_name_type tp, const std::map< std::string, int > *const width_info, const VerilogAnalyzer *_ana)
ast_port_declaration * _def
Stores its own definition.
Definition: verilog_analysis.h:41
vlg_loc_t get_module_inst_loc(const std::string &inst_name) const
Return the location of a module instantiation.
~VerilogAnalyzer()
Destructor: clear vlg parser things.
std::vector< param_hier_item_t > param_def_hierarchy
The hierarchy.
Definition: verilog_const_parser.h:28
ast_reg_declaration * get_def()
Return its definition.
Definition: verilog_analysis.h:68
static std::ostream & PrintMeta(std::ostream &os, const ast_metadata &md)
Print Meta info (Usage PrintMeta(os, ?? ) &lt;&lt; ?? ; )
Definition: verilog_analysis.h:198
SignalInfoPort(ast_port_declaration *def, const std::string &full_name, VerilogAnalyzerBase::hierarchical_name_type tp, const std::map< std::string, int > *const width_info, const VerilogAnalyzer *_ana)
path_vec_t vlg_include_path
include path for all verilog modules
Definition: verilog_analysis.h:118
bool in_bad_state() const
whether this analyzer is in bad state
Definition: verilog_analysis.h:230
void find_top_module(verilog_source_tree *source, const std::string &optional_top_module)
extract the top module name
Class to convert port to signal info.
Definition: verilog_analysis.h:38
Class to convert wire to signal info.
Definition: verilog_analysis.h:72
ast_net_declaration * get_def()
Return its definition.
Definition: verilog_analysis.h:85
ast_net_declaration * _def
Stores its own definition.
Definition: verilog_analysis.h:75
void check_resolve_modules(verilog_source_tree *source)
check the result of module resolution and update the name_module_map;