ilang  1.1.4
ILAng: A Modeling and Verification Platform for SoCs
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Macros
verilog_analysis_wrapper.h
1 
10 #ifndef ILANG_VERILOG_IN_VERILOG_ANALYSIS_WRAPPER_H__
11 #define ILANG_VERILOG_IN_VERILOG_ANALYSIS_WRAPPER_H__
12 
13 #include <iostream>
14 #include <map>
15 #include <string>
16 #include <vector>
17 
18 namespace ilang {
19 
20 class SignalInfoBase;
21 
25 public:
27  typedef std::vector<std::string> path_vec_t;
29  typedef std::pair<std::string, long> vlg_loc_t;
31  typedef std::map<std::string, std::vector<std::string>> name_names_map_t;
33  typedef std::map<std::string, std::string> mod_inst_t;
35  typedef std::map<std::string, mod_inst_t> name_insts_map_t;
37  typedef enum {
38  NONE = 0,
39  MODULE, /*1*/
40  I_WIRE_wo_INTERNAL_DEF,
41  /*2*/ // module (input [3:0] a, output reg b) ; no internal defininition
42  O_WIRE_wo_INTERNAL_DEF, /*3*/
43  IO_WIRE_wo_INTERNAL_DEF, /*4*/
44  I_WIRE_w_INTERNAL_DEF,
45  /*5*/ // module (a,b,c); input c **OR** module (input [3:0] a) ; wire [3:0]
46  // a;
47  O_WIRE_w_INTERNAL_DEF, /*6*/
48  IO_WIRE_w_INTERNAL_DEF, /*7*/
49  O_REG_wo_INTERNAL_DEF, /*8*/
50  O_REG_w_INTERNAL_DEF, /*9*/
51  REG /*10*/,
52  WIRE /*11*/,
53  OTHERS /*12*/
56  typedef std::map<std::string, hierarchical_name_type> name_type_buffer_t;
58  typedef std::map<std::string, void*> name_decl_buffer_t;
60  typedef std::map<std::string, SignalInfoBase> module_io_vec_t;
61 
62 public:
63  // --------------------- HELPER FUNCTIONS ---------------------------- //
65  static bool is_reg(hierarchical_name_type tp_) {
66  return tp_ == O_REG_wo_INTERNAL_DEF || tp_ == O_REG_w_INTERNAL_DEF ||
67  tp_ == REG;
68  }
70  static bool is_wire(hierarchical_name_type tp_) {
71  return (tp_ >= I_WIRE_wo_INTERNAL_DEF && tp_ <= IO_WIRE_w_INTERNAL_DEF) ||
72  tp_ == WIRE;
73  }
76  return (tp_ >= I_WIRE_wo_INTERNAL_DEF && tp_ <= IO_WIRE_wo_INTERNAL_DEF) ||
77  tp_ == O_REG_wo_INTERNAL_DEF;
78  }
80  static bool is_module(hierarchical_name_type tp_) {
81  return tp_ == hierarchical_name_type::MODULE;
82  }
84  static bool is_io_sig(hierarchical_name_type tp_) {
85  return tp_ >= I_WIRE_wo_INTERNAL_DEF && tp_ <= O_REG_w_INTERNAL_DEF;
86  }
88  static bool is_input(hierarchical_name_type tp_) {
89  return (tp_ == I_WIRE_wo_INTERNAL_DEF) || (tp_ == I_WIRE_w_INTERNAL_DEF);
90  }
92  static bool is_output(hierarchical_name_type tp_) {
93  return is_io_sig(tp_) && !is_input(tp_);
94  }
96  static std::ostream& PrintLoc(std::ostream& os, const vlg_loc_t& loc) {
97  return (os << (loc.first) << ":" << (loc.second));
98  }
99 
100 public:
101  // --------------------- CONSTRUCTOR ---------------------------- //
104  // --------------------- DESTRUCTOR ---------------------------- //
106  virtual ~VerilogAnalyzerBase(){};
107 
109 };
110 
113 protected:
116  const std::string _name;
118  const std::string _hierarchical_name;
120  const unsigned _width;
125 
126 public:
129  virtual unsigned get_width() const { return _width; }
131  virtual bool is_io_sig() const {
133  }
135  virtual bool no_internal_def() const {
137  }
139  virtual bool is_reg() const { return VerilogAnalyzerBase::is_reg(_type); }
141  virtual bool is_input() const { return VerilogAnalyzerBase::is_input(_type); }
143  virtual bool is_output() const {
145  }
147  virtual bool is_bad_signal() const {
148  return _type == VerilogAnalyzerBase::hierarchical_name_type::NONE;
149  }
152  return _type;
153  }
157  virtual std::string get_signal_name() const { return _name; }
159  virtual std::string get_hierarchical_name() const {
160  return _hierarchical_name;
161  }
162 
163 public:
165  SignalInfoBase(const std::string& n, const std::string& h, unsigned w,
168  : _name(n), _hierarchical_name(h), _width(w), _type(typ), _loc(loc) {}
170 }; // class SignalInfoBase
171 
173 class VerilogInfo {
174 
175 public:
194 
195 private:
196  // --------------------- MEMBERS ---------------------------- //
198  VerilogAnalyzerBase* _analyzer;
199 
200 public:
201  // --------------------- CONSTRUCTOR ---------------------------- //
207  VerilogInfo(const path_vec_t& include_path, const path_vec_t& srcs,
208  const std::string& top_module_inst_name,
209  const std::string& optional_top_module = "");
211  VerilogInfo(const VerilogInfo&) = delete;
213  VerilogInfo& operator=(const VerilogInfo&) = delete;
214  // --------------------- DESTRUCTOR ---------------------------- //
216  virtual ~VerilogInfo();
217 
218 public:
219  // --------------------- INTERFACE ---------------------------- //
222  check_hierarchical_name_type(const std::string& net_name) const;
227  void* find_declaration_of_name(const std::string& net_name) const;
229  vlg_loc_t name2loc(const std::string& net_name) const;
231  vlg_loc_t get_module_inst_loc(const std::string& inst_name) const;
233  vlg_loc_t get_endmodule_loc(const std::string& inst_name) const;
235  std::string get_top_module_name() const;
240  get_top_module_io(const std::map<std::string, int>& width_info) const;
242  SignalInfoBase get_signal(const std::string& net_name) const;
244  SignalInfoBase get_signal(const std::string& net_name,
245  const std::map<std::string, int>& width_info) const;
247  bool in_bad_state() const;
248 
249 }; // class Verilog Info
250 
252 std::ostream& operator<<(std::ostream& os,
253  const VerilogAnalyzerBase::vlg_loc_t& obj);
254 
255 }; // namespace ilang
256 
257 #endif // ILANG_VERILOG_IN_VERILOG_ANALYSIS_WRAPPER_H__
ExprRef operator<<(const ExprRef &a, const ExprRef &b)
Left shift for bit-vectors.
void * find_declaration_of_name(const std::string &net_name) const
vlg_loc_t get_module_inst_loc(const std::string &inst_name) const
Return the location of a module instantiation.
virtual bool is_input() const
Whether it is an input signal.
Definition: verilog_analysis_wrapper.h:141
static bool is_module(hierarchical_name_type tp_)
decide if a type is module
Definition: verilog_analysis_wrapper.h:80
const VerilogAnalyzerBase::hierarchical_name_type _type
its type
Definition: verilog_analysis_wrapper.h:122
VerilogAnalyzerBase::name_type_buffer_t name_type_buffer_t
hierarchical name -&gt; hierarchical_name_type map
Definition: verilog_analysis_wrapper.h:189
bool in_bad_state() const
whether this analyzer is in bad state
std::map< std::string, hierarchical_name_type > name_type_buffer_t
hierarchical name -&gt; hierarchical_name_type map
Definition: verilog_analysis_wrapper.h:56
virtual std::string get_hierarchical_name() const
Return its hierarchical name.
Definition: verilog_analysis_wrapper.h:159
std::vector< std::string > path_vec_t
type to store multiple paths
Definition: verilog_analysis_wrapper.h:27
static bool is_input(hierarchical_name_type tp_)
decide if it is input signal
Definition: verilog_analysis_wrapper.h:88
const VerilogAnalyzerBase::vlg_loc_t _loc
its location of definition
Definition: verilog_analysis_wrapper.h:124
VerilogAnalyzerBase::vlg_loc_t vlg_loc_t
filename, line number pair : location type
Definition: verilog_analysis_wrapper.h:179
virtual bool no_internal_def() const
Whether it is defined only at the port.
Definition: verilog_analysis_wrapper.h:135
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
virtual VerilogAnalyzerBase::vlg_loc_t get_decl_loc() const
Return its location.
Definition: verilog_analysis_wrapper.h:155
std::map< std::string, mod_inst_t > name_insts_map_t
A map of module name -&gt; instantiation.
Definition: verilog_analysis_wrapper.h:35
vlg_loc_t name2loc(const std::string &net_name) const
Return the location of a hierarchical name.
static std::ostream & PrintLoc(std::ostream &os, const vlg_loc_t &loc)
Print location info.
Definition: verilog_analysis_wrapper.h:96
virtual bool is_output() const
Whether it is an output signal.
Definition: verilog_analysis_wrapper.h:143
std::map< std::string, void * > name_decl_buffer_t
hierarchical name -&gt; declaration pointer
Definition: verilog_analysis_wrapper.h:58
static bool is_wire(hierarchical_name_type tp_)
decide if the type is a wire (port w or wo internal def / internal)
Definition: verilog_analysis_wrapper.h:70
virtual ~VerilogAnalyzerBase()
do nothing!
Definition: verilog_analysis_wrapper.h:106
std::pair< std::string, long > vlg_loc_t
filename, line number pair : location type
Definition: verilog_analysis_wrapper.h:29
VerilogAnalyzerBase::name_insts_map_t name_insts_map_t
A map of module name -&gt; instantiation.
Definition: verilog_analysis_wrapper.h:185
static bool is_output(hierarchical_name_type tp_)
decide if it is output signal
Definition: verilog_analysis_wrapper.h:92
static bool is_reg(hierarchical_name_type tp_)
decide if a type is a register (port w or wo internal def / internal)
Definition: verilog_analysis_wrapper.h:65
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
VerilogAnalyzerBase::module_io_vec_t module_io_vec_t
Top module signal list.
Definition: verilog_analysis_wrapper.h:193
static bool no_internal_def(hierarchical_name_type tp_)
decide if a type has no internal def
Definition: verilog_analysis_wrapper.h:75
VerilogInfo(const path_vec_t &include_path, const path_vec_t &srcs, const std::string &top_module_inst_name, const std::string &optional_top_module="")
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::name_names_map_t name_names_map_t
A map of name -&gt; names.
Definition: verilog_analysis_wrapper.h:181
const std::string _name
Definition: verilog_analysis_wrapper.h:116
VerilogAnalyzerBase()
Constructor: do nothing.
Definition: verilog_analysis_wrapper.h:103
module_io_vec_t get_top_module_io() const
Return top module signal with no hint on the width.
virtual VerilogAnalyzerBase::hierarchical_name_type get_type() const
return its type
Definition: verilog_analysis_wrapper.h:151
virtual std::string get_signal_name() const
Return is own name.
Definition: verilog_analysis_wrapper.h:157
Class to hold signal info.
Definition: verilog_analysis_wrapper.h:112
static bool is_io_sig(hierarchical_name_type tp_)
decide if it is port signal
Definition: verilog_analysis_wrapper.h:84
std::string get_top_module_name() const
Return top module name.
const unsigned _width
width of the signal
Definition: verilog_analysis_wrapper.h:120
VerilogAnalyzerBase::path_vec_t path_vec_t
type to store multiple paths
Definition: verilog_analysis_wrapper.h:177
virtual bool is_io_sig() const
Whether is a IO signal.
Definition: verilog_analysis_wrapper.h:131
VerilogInfo & operator=(const VerilogInfo &)=delete
Please don&#39;t use assignment over it.
vlg_loc_t get_endmodule_loc(const std::string &inst_name) const
Return the location of a module&#39;s endmodule statement.
virtual ~VerilogInfo()
Destructor: no need to clean, unique_ptr does the job.
SignalInfoBase(const std::string &n, const std::string &h, unsigned w, const VerilogAnalyzerBase::hierarchical_name_type &typ, const VerilogAnalyzerBase::vlg_loc_t &loc)
------------------— ACCESSORS ----------------— ///
Definition: verilog_analysis_wrapper.h:165
VerilogAnalyzerBase::name_decl_buffer_t name_decl_buffer_t
hierarchical name -&gt; declaration pointer
Definition: verilog_analysis_wrapper.h:191
The class that invoke the analyzer.
Definition: verilog_analysis_wrapper.h:173
virtual unsigned get_width() const
Definition: verilog_analysis_wrapper.h:129
virtual bool is_reg() const
Whether it is a register.
Definition: verilog_analysis_wrapper.h:139
virtual bool is_bad_signal() const
Whether this info is usable.
Definition: verilog_analysis_wrapper.h:147
const std::string _hierarchical_name
full name
Definition: verilog_analysis_wrapper.h:118
VerilogAnalyzerBase::mod_inst_t mod_inst_t
type of modulename instance name : instance_name-&gt;module_name
Definition: verilog_analysis_wrapper.h:183
hierarchical_name_type check_hierarchical_name_type(const std::string &net_name) const
Return the type of a name (used externally, cached)
SignalInfoBase get_signal(const std::string &net_name) const
Find a signal.