Limbo
3.5.4
Toggle main menu visibility
Loading...
Searching...
No Matches
test
parsers
verilog
test_bison.cpp
Go to the documentation of this file.
1
7
8
#include <iostream>
9
#include <fstream>
10
11
#include <
limbo/parsers/verilog/bison/VerilogDriver.h
>
12
13
using
std::cout;
14
using
std::cin;
15
using
std::endl;
16
using
std::string;
17
20
class
VerilogDataBase
:
public
VerilogParser::VerilogDataBase
21
{
22
public
:
24
VerilogDataBase
()
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
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
}
VerilogDriver.h
Driver for Verilog parser.
test2
void test2(string const &filename)
test 2: use class wrapper BookshelfParser::Driver
Definition
test_bison.cpp:149
VerilogDataBase
Custom class that inheritates VerilogParser::VerilogDataBase with all the required callbacks defined.
Definition
test_bison.cpp:21
VerilogDataBase::VerilogDataBase
VerilogDataBase()
constructor
Definition
test_bison.cpp:24
VerilogDataBase::verilog_module_declaration_cbk
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
VerilogDataBase::verilog_instance_cbk
virtual void verilog_instance_cbk(std::string const ¯o_name, std::string const &inst_name, std::vector< VerilogParser::NetPin > const &vNetPin)
read an instance.
Definition
test_bison.cpp:51
VerilogDataBase::verilog_assignment_cbk
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
VerilogDataBase::verilog_pin_declare_cbk
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
VerilogDataBase::verilog_net_declare_cbk
virtual void verilog_net_declare_cbk(std::string const &net_name, VerilogParser::Range const &range)
read an net declaration
Definition
test_bison.cpp:82
VerilogParser::Driver
Definition
VerilogDriver.h:36
VerilogParser::Driver::parse_file
bool parse_file(const string &filename)
VerilogParser::VerilogDataBase
Base class for verilog database. Only pure virtual functions are defined. User needs to inheritate ...
Definition
VerilogDataBase.h:212
VerilogParser::read
bool read(VerilogDataBase &db, const string &verilogFile)
API for VerilogParser. Read Verilog file and initialize database by calling user-defined callback fun...
VerilogParser::Range
range with pair of low and high values
Definition
VerilogDataBase.h:32
VerilogParser::Range::low
int low
low value, min infinity if not specified
Definition
VerilogDataBase.h:33
VerilogParser::Range::high
int high
Definition
VerilogDataBase.h:34
main
int main()
Definition
test_ChromaticNumber.cpp:78
test1
void test1()
test function API
Definition
test_solvers.cpp:11
Generated on
for Limbo by
1.17.0