Limbo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
VerilogDataBase.h
Go to the documentation of this file.
1 
8 #ifndef VERILOGPARSER_DATABASE_H
9 #define VERILOGPARSER_DATABASE_H
10 
11 #include <string>
12 #include <vector>
13 #include <iostream>
14 #include <fstream>
15 #include <sstream>
16 #include <cassert>
17 #include <limits>
18 
20 namespace VerilogParser {
21 
23 enum PinType
24 {
25  kINPUT = 0x1,
26  kOUTPUT = 0x2,
27  kREG = 0x4
28 };
29 
31 struct Range
32 {
33  int low;
34  int high;
35  Range() {low = high = std::numeric_limits<int>::min();}
40  Range(int l, int h) : low(l), high(h) {}
41 };
42 
46 {
47  std::string name;
49 
52  GeneralName(std::string const& n = "") {name = n; range.low = range.high = std::numeric_limits<int>::min();}
57  GeneralName(std::string const& n, int low, int high) {name = n; range.low = low; range.high = high;}
58 };
59 
67 struct NetPin
68 {
69  std::string net;
70  std::string pin;
72 
74  union Extension {
75  int constant;
76  std::vector<GeneralName>* vNetName;
77  } extension;
78 
83  NetPin(std::string& n, std::string& p, Range const& r = Range())
84  {
85  net.swap(n);
86  pin.swap(p);
87  range = r;
88  }
94  NetPin(std::string& n, std::string& p, Range const& r, int c)
95  {
96  net.swap(n);
97  pin.swap(p);
98  range = r;
99  extension.constant = c;
100  }
105  NetPin(std::string& n, std::string& p, std::vector<GeneralName>& vNetName)
106  {
107  net.swap(n);
108  pin.swap(p);
109  range = Range();
110  extension.vNetName = new std::vector<GeneralName>();
111  extension.vNetName->swap(vNetName);
112  }
115  NetPin(NetPin const& rhs)
116  {
117  copy(rhs);
118  }
121  NetPin& operator=(NetPin const& rhs)
122  {
123  if (this != &rhs)
124  copy(rhs);
125  return *this;
126  }
129  {
130  if (net == "VerilogParser::GROUP_NETS")
131  {
132  delete extension.vNetName;
133  }
134  }
135 
138  void copy(NetPin const& rhs)
139  {
140  if (net == "VerilogParser::GROUP_NETS")
141  {
142  delete extension.vNetName;
143  }
144  net = rhs.net;
145  pin = rhs.pin;
146  range = rhs.range;
147  if (net == "VerilogParser::CONSTANT_NET")
148  {
150  }
151  else if (net == "VerilogParser::GROUP_NETS")
152  {
153  extension.vNetName = new std::vector<GeneralName> (*rhs.extension.vNetName);
154  }
155  }
156 };
157 
160 class StringArray : public std::vector<std::string>
161 {
162  public:
164  typedef std::vector<std::string> base_type;
165  using base_type::size_type;
166  using base_type::value_type;
167  using base_type::allocator_type;
169 
172  StringArray(const allocator_type& alloc = allocator_type())
173  : base_type(alloc) {}
178  StringArray(size_type n, const value_type& val, const allocator_type& alloc = allocator_type())
179  : base_type(n, val, alloc) {}
180 };
181 
184 class GeneralNameArray : public std::vector<GeneralName>
185 {
186  public:
188  typedef std::vector<GeneralName> base_type;
189  using base_type::size_type;
190  using base_type::value_type;
191  using base_type::allocator_type;
193 
196  GeneralNameArray(const allocator_type& alloc = allocator_type())
197  : base_type(alloc) {}
202  GeneralNameArray(size_type n, const value_type& val, const allocator_type& alloc = allocator_type())
203  : base_type(n, val, alloc) {}
204 };
205 
206 // forward declaration
212 {
213  public:
220  virtual void verilog_module_declaration_cbk(std::string const& module_name, std::vector<GeneralName> const& vPinName);
230  virtual void verilog_instance_cbk(std::string const& macro_name, std::string const& inst_name, std::vector<NetPin> const& vNetPin) = 0;
237  virtual void verilog_net_declare_cbk(std::string const& net_name, Range const& range) = 0;
245  virtual void verilog_pin_declare_cbk(std::string const& pin_name, unsigned type, Range const& range) = 0;
254  virtual void verilog_assignment_cbk(std::string const& target_name, Range const& target_range, std::string const& source_name, Range const& source_range);
255 
256  protected:
259  void verilog_user_cbk_reminder(const char* str) const;
260 };
261 
262 } // namespace VerilogParser
263 
264 #endif
union VerilogParser::NetPin::Extension extension
extension to handle a net with constant values or a regular net
GeneralName(std::string const &n, int low, int high)
constructor
StringArray(size_type n, const value_type &val, const allocator_type &alloc=allocator_type())
constructor
virtual void verilog_net_declare_cbk(std::string const &net_name, Range const &range)=0
read an net declaration
range with pair of low and high values
GeneralName(std::string const &n="")
constructor
Range(int l, int h)
constructor
std::string net
net name, reserved names VerilogParser::CONSTANT_NET, VerilogParser::GROUP_NETS
virtual void verilog_pin_declare_cbk(std::string const &pin_name, unsigned type, Range const &range)=0
read an pin declaration
GeneralNameArray(const allocator_type &alloc=allocator_type())
constructor
NetPin & operator=(NetPin const &rhs)
assignment
NetPin(std::string &n, std::string &p, Range const &r, int c)
constructor
std::vector< GeneralName > * vNetName
a group of net names if the net is a group of nets
void copy(NetPin const &rhs)
copy function
int low
low value, min infinity if not specified
Extension to handle a net with constant values or a regular net.
virtual void verilog_module_declaration_cbk(std::string const &module_name, std::vector< GeneralName > const &vPinName)
read a module declaration
Describe the connection of pins to nets.
Range range
min infinity if not specified
int constant
constant value if the net is a constant
PinType
pin type
bison does not support vector very well, so here create a dummy class for string array.
NetPin(std::string &n, std::string &p, std::vector< GeneralName > &vNetName)
constructor
StringArray(const allocator_type &alloc=allocator_type())
constructor
GeneralNameArray(size_type n, const value_type &val, const allocator_type &alloc=allocator_type())
constructor
virtual void verilog_instance_cbk(std::string const &macro_name, std::string const &inst_name, std::vector< NetPin > const &vNetPin)=0
read an instance.
NetPin(std::string &n, std::string &p, Range const &r=Range())
constructor
std::string pin
pin name
std::string name
name string, empty if not specified
NetPin(NetPin const &rhs)
copy constructor
std::iterator_traits< Iterator >::value_type min(Iterator first, Iterator last)
get min of an array
Definition: Math.h:77
Range range
range of net
bison does not support vector very well, so here create a dummy class for VerilogParser::GeneralName ...
void verilog_user_cbk_reminder(const char *str) const
remind users to define some optional callback functions at runtime
Base class for verilog database. Only pure virtual functions are defined. User needs to inheritate th...
virtual void verilog_assignment_cbk(std::string const &target_name, Range const &target_range, std::string const &source_name, Range const &source_range)
read an assignment
namespace for VerilogParser