Limbo 3.5.4
Loading...
Searching...
No Matches
test_bison.cpp
Go to the documentation of this file.
1
7
8#include <iostream>
9#include <fstream>
10
12
13using std::cout;
14using std::cin;
15using std::endl;
16using std::string;
17
21{
22 public:
25 {
26 cout << "VerilogDataBase::" << __func__ << endl;
27 }
28
35 virtual void verilog_module_declaration_cbk(std::string const& module_name, std::vector<VerilogParser::GeneralName> const& vPinName)
36 {
37 cout << __func__ << " => " << module_name << "\n";
38 for (std::vector<VerilogParser::GeneralName>::const_iterator it = vPinName.begin(); it != vPinName.end(); ++it)
39 cout << "\t" << it->name << "[" << it->range.low << ":" << it->range.high << "] ";
40 cout << endl;
41 }
42
51 virtual void verilog_instance_cbk(std::string const& macro_name, std::string const& inst_name, std::vector<VerilogParser::NetPin> const& vNetPin)
52 {
53 cout << __func__ << " => " << macro_name << ", " << inst_name << ", ";
54 for (std::vector<VerilogParser::NetPin>::const_iterator it = vNetPin.begin(); it != vNetPin.end(); ++it)
55 {
56 if (it->net == "VerilogParser::CONSTANT_NET")
57 {
58 cout << it->pin << "(" << it->net << " " << it->extension.constant << ")" << "[" << it->range.low << ":" << it->range.high << "] ";
59 }
60 else if (it->net == "VerilogParser::GROUP_NETS")
61 {
62 cout << it->pin << "(" << it->net << " {";
63 for (std::vector<VerilogParser::GeneralName>::const_iterator itn = it->extension.vNetName->begin(); itn != it->extension.vNetName->end(); ++itn)
64 {
65 cout << "(" << itn->name << ")" << "[" << itn->range.low << ":" << itn->range.high << "] ";
66 }
67 cout << "} " << ")" << "[" << it->range.low << ":" << it->range.high << "] ";
68 }
69 else
70 {
71 cout << it->pin << "(" << it->net << ")" << "[" << it->range.low << ":" << it->range.high << "] ";
72 }
73 }
74 cout << endl;
75 }
76
82 virtual void verilog_net_declare_cbk(std::string const& net_name, VerilogParser::Range const& range)
83 {
84 cout << __func__ << " => " << net_name << " (" << range.low << ", " << range.high << ")" << endl;
85 }
86
93 virtual void verilog_pin_declare_cbk(std::string const& pin_name, unsigned type, VerilogParser::Range const& range)
94 {
95 cout << __func__ << " => " << pin_name << " " << type << " (" << range.low << ", " << range.high << ")" << endl;
96 }
97
105 virtual void verilog_assignment_cbk(std::string const& target_name, VerilogParser::Range const& target_range, std::string const& source_name, VerilogParser::Range const& source_range)
106 {
107 cout << __func__ << " => " << target_name << " (" << target_range.low << ", " << target_range.high << ")" << " = "
108 << source_name << " (" << source_range.low << ", " << source_range.high << ")" << endl;
109 }
110};
111
113void test1(string const& filename)
114{
115 cout << "////////////// test1 ////////////////" << endl;
117 VerilogParser::read(db, filename);
118}
119
121void test2(string const& filename)
122{
123 cout << "////////////// test2 ////////////////" << endl;
125 VerilogParser::Driver driver (db);
126 //driver.trace_scanning = true;
127 //driver.trace_parsing = true;
128
129 driver.parse_file(filename);
130}
131
136int main(int argc, char** argv)
137{
138
139 if (argc > 1)
140 {
141 test1(argv[1]);
142 test2(argv[1]);
143 }
144 else
145 cout << "at least 1 argument is required" << endl;
146
147 return 0;
148}
Driver for Verilog parser.
void test2(string const &filename)
test 2: use class wrapper BookshelfParser::Driver
Custom class that inheritates VerilogParser::VerilogDataBase with all the required callbacks defined.
VerilogDataBase()
constructor
virtual void verilog_module_declaration_cbk(std::string const &module_name, std::vector< VerilogParser::GeneralName > const &vPinName)
read a module declaration
virtual void verilog_instance_cbk(std::string const &macro_name, std::string const &inst_name, std::vector< VerilogParser::NetPin > const &vNetPin)
read an instance.
virtual void verilog_assignment_cbk(std::string const &target_name, VerilogParser::Range const &target_range, std::string const &source_name, VerilogParser::Range const &source_range)
read an assignment
virtual void verilog_pin_declare_cbk(std::string const &pin_name, unsigned type, VerilogParser::Range const &range)
read an pin declaration
virtual void verilog_net_declare_cbk(std::string const &net_name, VerilogParser::Range const &range)
read an net declaration
bool parse_file(const string &filename)
Base class for verilog database. Only pure virtual functions are defined. User needs to inheritate ...
bool read(VerilogDataBase &db, const string &verilogFile)
API for VerilogParser. Read Verilog file and initialize database by calling user-defined callback fun...
range with pair of low and high values
int low
low value, min infinity if not specified
int main()
void test1()
test function API