35 using namespace VERILOG_FRONTEND;
48 log(
" read_verilog [options] [filename]\n");
50 log(
"Load modules from a verilog file to the current design. A large subset of\n");
51 log(
"Verilog-2005 is supported.\n");
54 log(
" enable support for SystemVerilog features. (only a small subset\n");
55 log(
" of SystemVerilog is supported)\n");
58 log(
" dump abstract syntax tree (before simplification)\n");
61 log(
" dump abstract syntax tree (after simplification)\n");
64 log(
" dump ast as verilog code (after simplification)\n");
67 log(
" enable parser debug output\n");
70 log(
" usually latches are synthesized into logic loops\n");
71 log(
" this option prohibits this and sets the output to 'x'\n");
72 log(
" in what would be the latches hold condition\n");
74 log(
" this behavior can also be achieved by setting the\n");
75 log(
" 'nolatches' attribute on the respective module or\n");
76 log(
" always block.\n");
79 log(
" under certain conditions memories are converted to registers\n");
80 log(
" early during simplification to ensure correct handling of\n");
81 log(
" complex corner cases. this option disables this behavior.\n");
83 log(
" this can also be achieved by setting the 'nomem2reg'\n");
84 log(
" attribute on the respective module or register.\n");
87 log(
" always convert memories to registers. this can also be\n");
88 log(
" achieved by setting the 'mem2reg' attribute on the respective\n");
89 log(
" module or register.\n");
92 log(
" dump verilog code after pre-processor\n");
95 log(
" do not run the pre-processor\n");
98 log(
" only create empty blackbox modules\n");
101 log(
" don't perform basic optimizations (such as const folding) in the\n");
102 log(
" high-level front-end.\n");
105 log(
" interpret cell types starting with '$' as internal cell types\n");
107 log(
" -ignore_redef\n");
108 log(
" ignore re-definitions of modules. (the default behavior is to\n");
109 log(
" create an error message.)\n");
112 log(
" only read the abstract syntax tree and defer actual compilation\n");
113 log(
" to a later 'hierarchy' command. Useful in cases where the default\n");
114 log(
" parameters of modules yield invalid or not synthesizable code.\n");
116 log(
" -setattr <attribute_name>\n");
117 log(
" set the specified attribute (to the value 1) on all loaded modules\n");
119 log(
" -Dname[=definition]\n");
120 log(
" define the preprocessor symbol 'name' and set its optional value\n");
121 log(
" 'definition'\n");
124 log(
" add 'dir' to the directories which are used when searching include\n");
127 log(
"The command 'verilog_defaults' can be used to register default options for\n");
128 log(
"subsequent calls to 'read_verilog'.\n");
130 log(
"Note that the Verilog frontend does a pretty good job of processing valid\n");
131 log(
"verilog input, but has not very good error reporting. It generally is\n");
132 log(
"recommended to use a simulator (for example icarus verilog) for checking\n");
133 log(
"the syntax of the code, rather than to rely on read_verilog for that.\n");
144 bool flag_ppdump =
false;
145 bool flag_nopp =
false;
149 bool flag_ignore_redef =
false;
150 bool flag_defer =
false;
151 std::map<std::string, std::string> defines_map;
152 std::list<std::string> include_dirs;
153 std::list<std::string> attributes;
158 log_header(
"Executing Verilog-2005 frontend.\n");
163 for (argidx = 1; argidx < args.size(); argidx++) {
164 std::string arg = args[argidx];
169 if (arg ==
"-dump_ast1") {
170 flag_dump_ast1 =
true;
173 if (arg ==
"-dump_ast2") {
174 flag_dump_ast2 =
true;
177 if (arg ==
"-dump_vlog") {
178 flag_dump_vlog =
true;
181 if (arg ==
"-yydebug") {
185 if (arg ==
"-nolatches") {
186 flag_nolatches =
true;
189 if (arg ==
"-nomem2reg") {
190 flag_nomem2reg =
true;
193 if (arg ==
"-mem2reg") {
197 if (arg ==
"-ppdump") {
201 if (arg ==
"-nopp") {
209 if (arg ==
"-noopt") {
213 if (arg ==
"-icells") {
217 if (arg ==
"-ignore_redef") {
218 flag_ignore_redef =
true;
221 if (arg ==
"-defer") {
225 if (arg ==
"-setattr" && argidx+1 < args.size()) {
229 if (arg ==
"-D" && argidx+1 < args.size()) {
230 std::string name = args[++argidx], value;
231 size_t equal = name.find(
'=', 2);
232 if (equal != std::string::npos) {
233 value = arg.substr(equal+1);
234 name = arg.substr(0, equal);
236 defines_map[name] = value;
239 if (arg.compare(0, 2,
"-D") == 0) {
240 size_t equal = arg.find(
'=', 2);
241 std::string name = arg.substr(2, equal-2);
243 if (equal != std::string::npos)
244 value = arg.substr(equal+1);
245 defines_map[name] = value;
248 if (arg ==
"-I" && argidx+1 < args.size()) {
249 include_dirs.push_back(args[++argidx]);
252 if (arg.compare(0, 2,
"-I") == 0) {
253 include_dirs.push_back(arg.substr(2));
258 extra_args(f, filename, args, argidx);
260 log(
"Parsing %s input from `%s' to AST representation.\n",
sv_mode ?
"SystemVerilog" :
"Verilog", filename.c_str());
270 std::string code_after_preproc;
275 log(
"-- Verilog code after preprocessor --\n%s-- END OF DUMP --\n", code_after_preproc.c_str());
276 lexin =
new std::istringstream(code_after_preproc);
286 for (
auto &attr : attributes)
287 if (child->attributes.count(attr) == 0)
291 AST::process(design,
current_ast, flag_dump_ast1, flag_dump_ast2, flag_dump_vlog, flag_nolatches, flag_nomem2reg, flag_mem2reg, flag_lib, flag_noopt, flag_icells, flag_ignore_redef, flag_defer,
default_nettype_wire);
299 log(
"Successfully finished Verilog frontend.\n");
309 log(
" verilog_defaults -add [options]\n");
311 log(
"Add the sepcified options to the list of default options to read_verilog.\n");
314 log(
" verilog_defaults -clear");
316 log(
"Clear the list of verilog default options.\n");
319 log(
" verilog_defaults -push");
320 log(
" verilog_defaults -pop");
322 log(
"Push or pop the list of default options to a stack. Note that -push does\n");
323 log(
"not imply -clear.\n");
328 if (args.size() == 0)
329 cmd_error(args, 1,
"Missing argument.");
331 if (args[1] ==
"-add") {
336 if (args.size() != 2)
337 cmd_error(args, 2,
"Extra argument.");
339 if (args[1] ==
"-clear") {
344 if (args[1] ==
"-push") {
349 if (args[1] ==
"-pop") {
369 p += snprintf(p, buffer +
sizeof(buffer) - p,
"Parser error in line %s:%d: ",
372 p += vsnprintf(p, buffer +
sizeof(buffer) - p, fmt, ap);
374 p += snprintf(p, buffer +
sizeof(buffer) - p,
"\n");
bool default_nettype_wire
virtual void execute(std::istream *&f, std::string filename, std::vector< std::string > args, RTLIL::Design *design)
static AstNode * mkconst_int(uint32_t v, bool is_signed, int width=32)
void log_header(const char *format,...)
#define YOSYS_NAMESPACE_PREFIX
#define YOSYS_NAMESPACE_END
YOSYS_NAMESPACE_END void frontend_verilog_yyerror(char const *fmt,...)
std::string frontend_verilog_preproc(std::istream &f, std::string filename, const std::map< std::string, std::string > pre_defines_map, const std::list< std::string > include_dirs)
void(* set_line_num)(int)
void log_error(const char *format,...)
static std::vector< std::string > verilog_defaults
virtual void execute(std::vector< std::string > args, RTLIL::Design *)
static std::string escape_id(std::string str)
int frontend_verilog_yyget_lineno(void)
YOSYS_NAMESPACE_END int frontend_verilog_yydebug
int frontend_verilog_yyparse(void)
std::string current_filename
#define YOSYS_NAMESPACE_BEGIN
void log(const char *format,...)
void frontend_verilog_yyrestart(FILE *f)
std::vector< AstNode * > children
VerilogDefaults VerilogDefaults
void process(RTLIL::Design *design, AstNode *ast, bool dump_ast1, bool dump_ast2, bool dump_vlog, bool nolatches, bool nomem2reg, bool mem2reg, bool lib, bool noopt, bool icells, bool ignore_redef, bool defer, bool autowire)
struct AST::AstNode * current_ast
int frontend_verilog_yylex_destroy(void)
static std::list< std::vector< std::string > > verilog_defaults_stack
VerilogFrontend VerilogFrontend
void frontend_verilog_yyset_lineno(int)