Limbo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
test_bison.cpp
Go to the documentation of this file.
1 
8 #include <iostream>
9 #include <fstream>
10 
12 
13 using std::cout;
14 using std::cin;
15 using std::endl;
16 using std::string;
17 
21 {
22  public:
25  {
26  cout << "VerilogDataBase::" << __func__ << endl;
27  }
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  }
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  }
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  }
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  }
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 
113 void test1(string const& filename)
114 {
115  cout << "////////////// test1 ////////////////" << endl;
116  VerilogDataBase db;
117  VerilogParser::read(db, filename);
118 }
119 
121 void test2(string const& filename)
122 {
123  cout << "////////////// test2 ////////////////" << endl;
124  VerilogDataBase db;
125  VerilogParser::Driver driver (db);
126  //driver.trace_scanning = true;
127  //driver.trace_parsing = true;
128 
129  driver.parse_file(filename);
130 }
131 
136 int 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 }
virtual void verilog_instance_cbk(std::string const &macro_name, std::string const &inst_name, std::vector< VerilogParser::NetPin > const &vNetPin)
read an instance.
Definition: test_bison.cpp:51
range with pair of low and high values
Custom class that inheritates VerilogParser::VerilogDataBase with all the required callbacks defined...
Definition: test_bison.cpp:20
virtual void verilog_net_declare_cbk(std::string const &net_name, VerilogParser::Range const &range)
read an net declaration
Definition: test_bison.cpp:82
virtual void verilog_module_declaration_cbk(std::string const &module_name, std::vector< VerilogParser::GeneralName > const &vPinName)
read a module declaration
Definition: test_bison.cpp:35
Driver for Verilog parser.
int low
low value, min infinity if not specified
void test2(string const &filename)
test 2: use class wrapper BookshelfParser::Driver
Definition: test_bison.cpp:104
bool parse_file(const string &filename)
bool read(VerilogDataBase &db, const string &verilogFile)
API for VerilogParser. Read Verilog file and initialize database by calling user-defined callback fun...
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
Definition: test_bison.cpp:105
void test1(string const &filename)
test 1: use function wrapper BookshelfParser::read
Definition: test_bison.cpp:96
VerilogDataBase()
constructor
Definition: test_bison.cpp:24
int main(int argc, char **argv)
main function
Definition: test_bison.cpp:119
virtual void verilog_pin_declare_cbk(std::string const &pin_name, unsigned type, VerilogParser::Range const &range)
read an pin declaration
Definition: test_bison.cpp:93
Base class for verilog database. Only pure virtual functions are defined. User needs to inheritate th...