Limbo 3.5.4
Loading...
Searching...
No Matches
VerilogDataBase.h
Go to the documentation of this file.
1
7
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
20namespace VerilogParser {
21
24{
25 kINPUT = 0x1,
26 kOUTPUT = 0x2,
27 kREG = 0x4
28};
29
31struct Range
32{
33 int low;
34 int high;
36 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
67struct NetPin
68{
69 std::string net;
70 std::string pin;
72
74 union Extension {
76 std::vector<GeneralName>* vNetName;
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 }
89
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 }
101
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 }
113
115 NetPin(NetPin const& rhs)
116 {
117 copy(rhs);
118 }
119
122 {
123 if (this != &rhs)
124 copy(rhs);
125 return *this;
126 }
127
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 {
149 extension.constant = rhs.extension.constant;
150 }
151 else if (net == "VerilogParser::GROUP_NETS")
152 {
153 extension.vNetName = new std::vector<GeneralName> (*rhs.extension.vNetName);
154 }
155 }
156};
157
160class 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) {}
174
178 StringArray(size_type n, const value_type& val, const allocator_type& alloc = allocator_type())
179 : base_type(n, val, alloc) {}
180};
181
184class 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) {}
198
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
GeneralNameArray(const allocator_type &alloc=allocator_type())
constructor
GeneralNameArray(size_type n, const value_type &val, const allocator_type &alloc=allocator_type())
constructor
StringArray(size_type n, const value_type &val, const allocator_type &alloc=allocator_type())
constructor
StringArray(const allocator_type &alloc=allocator_type())
constructor
Base class for verilog database. Only pure virtual functions are defined. User needs to inheritate ...
void verilog_user_cbk_reminder(const char *str) const
remind users to define some optional callback functions at runtime
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
virtual void verilog_instance_cbk(std::string const &macro_name, std::string const &inst_name, std::vector< NetPin > const &vNetPin)=0
read an instance.
virtual void verilog_net_declare_cbk(std::string const &net_name, Range const &range)=0
read an net declaration
virtual void verilog_module_declaration_cbk(std::string const &module_name, std::vector< GeneralName > const &vPinName)
read a module declaration
virtual void verilog_pin_declare_cbk(std::string const &pin_name, unsigned type, Range const &range)=0
read an pin declaration
namespace for VerilogParser
std::string name
name string, empty if not specified
GeneralName(std::string const &n, int low, int high)
constructor
GeneralName(std::string const &n="")
constructor
Range range
min infinity if not specified
Range range
range of net
void copy(NetPin const &rhs)
copy function
NetPin(NetPin const &rhs)
copy constructor
std::string pin
pin name
NetPin & operator=(NetPin const &rhs)
assignment
std::string net
net name, reserved names VerilogParser::CONSTANT_NET, VerilogParser::GROUP_NETS
NetPin(std::string &n, std::string &p, std::vector< GeneralName > &vNetName)
constructor
NetPin(std::string &n, std::string &p, Range const &r, int c)
constructor
NetPin(std::string &n, std::string &p, Range const &r=Range())
constructor
union VerilogParser::NetPin::Extension extension
extension to handle a net with constant values or a regular net
range with pair of low and high values
int low
low value, min infinity if not specified
Range(int l, int h)
constructor
Extension to handle a net with constant values or a regular net.
std::vector< GeneralName > * vNetName
a group of net names if the net is a group of nets
int constant
constant value if the net is a constant