2013-01-05 04:13:26 -06:00
|
|
|
/*
|
|
|
|
* yosys -- Yosys Open SYnthesis Suite
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 Clifford Wolf <clifford@clifford.at>
|
2015-07-02 04:14:30 -05:00
|
|
|
*
|
2013-01-05 04:13:26 -06:00
|
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
2015-07-02 04:14:30 -05:00
|
|
|
*
|
2013-01-05 04:13:26 -06:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*
|
|
|
|
* ---
|
|
|
|
*
|
|
|
|
* The Verilog frontend.
|
|
|
|
*
|
|
|
|
* This frontend is using the AST frontend library (see frontends/ast/).
|
|
|
|
* Thus this frontend does not generate RTLIL code directly but creates an
|
|
|
|
* AST directly from the Verilog parse tree and then passes this AST to
|
|
|
|
* the AST frontend library.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "verilog_frontend.h"
|
2014-08-23 08:14:58 -05:00
|
|
|
#include "kernel/yosys.h"
|
2013-02-27 02:32:19 -06:00
|
|
|
#include "libs/sha1/sha1.h"
|
2013-01-05 04:13:26 -06:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
2014-07-31 06:19:47 -05:00
|
|
|
YOSYS_NAMESPACE_BEGIN
|
2013-01-05 04:13:26 -06:00
|
|
|
using namespace VERILOG_FRONTEND;
|
|
|
|
|
|
|
|
// use the Verilog bison/flex parser to generate an AST and use AST::process() to convert it to RTLIL
|
|
|
|
|
2014-01-17 10:22:29 -06:00
|
|
|
static std::vector<std::string> verilog_defaults;
|
|
|
|
static std::list<std::vector<std::string>> verilog_defaults_stack;
|
|
|
|
|
2015-09-23 01:23:38 -05:00
|
|
|
static void error_on_dpi_function(AST::AstNode *node)
|
|
|
|
{
|
|
|
|
if (node->type == AST::AST_DPI_FUNCTION)
|
2018-07-20 10:11:20 -05:00
|
|
|
log_file_error(node->filename, node->linenum, "Found DPI function %s.\n", node->str.c_str());
|
2015-09-23 01:23:38 -05:00
|
|
|
for (auto child : node->children)
|
|
|
|
error_on_dpi_function(child);
|
|
|
|
}
|
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
struct VerilogFrontend : public Frontend {
|
2015-08-14 04:27:19 -05:00
|
|
|
VerilogFrontend() : Frontend("verilog", "read modules from Verilog file") { }
|
2018-07-21 01:41:18 -05:00
|
|
|
void help() YS_OVERRIDE
|
2013-03-01 01:03:00 -06:00
|
|
|
{
|
|
|
|
// |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
|
|
|
|
log("\n");
|
2014-06-04 02:10:50 -05:00
|
|
|
log(" read_verilog [options] [filename]\n");
|
2013-03-01 01:03:00 -06:00
|
|
|
log("\n");
|
2015-08-14 04:27:19 -05:00
|
|
|
log("Load modules from a Verilog file to the current design. A large subset of\n");
|
2013-03-01 01:03:00 -06:00
|
|
|
log("Verilog-2005 is supported.\n");
|
|
|
|
log("\n");
|
2014-06-12 04:54:20 -05:00
|
|
|
log(" -sv\n");
|
|
|
|
log(" enable support for SystemVerilog features. (only a small subset\n");
|
|
|
|
log(" of SystemVerilog is supported)\n");
|
|
|
|
log("\n");
|
2015-02-26 11:47:39 -06:00
|
|
|
log(" -formal\n");
|
2016-08-26 16:35:27 -05:00
|
|
|
log(" enable support for SystemVerilog assertions and some Yosys extensions\n");
|
2015-10-13 07:21:20 -05:00
|
|
|
log(" replace the implicit -D SYNTHESIS with -D FORMAL\n");
|
2015-02-26 11:47:39 -06:00
|
|
|
log("\n");
|
2018-09-24 13:51:16 -05:00
|
|
|
log(" -noassert\n");
|
|
|
|
log(" ignore assert() statements\n");
|
|
|
|
log("\n");
|
|
|
|
log(" -noassume\n");
|
|
|
|
log(" ignore assume() statements\n");
|
|
|
|
log("\n");
|
2016-08-26 16:35:27 -05:00
|
|
|
log(" -norestrict\n");
|
2018-09-24 13:51:16 -05:00
|
|
|
log(" ignore restrict() statements\n");
|
2016-08-26 16:35:27 -05:00
|
|
|
log("\n");
|
|
|
|
log(" -assume-asserts\n");
|
|
|
|
log(" treat all assert() statements like assume() statements\n");
|
|
|
|
log("\n");
|
2018-09-24 13:51:16 -05:00
|
|
|
log(" -assert-assumes\n");
|
|
|
|
log(" treat all assume() statements like assert() statements\n");
|
|
|
|
log("\n");
|
2019-03-21 14:52:29 -05:00
|
|
|
log(" -debug\n");
|
|
|
|
log(" alias for -dump_ast1 -dump_ast2 -dump_vlog1 -dump_vlog2 -yydebug\n");
|
|
|
|
log("\n");
|
2013-08-19 12:49:14 -05:00
|
|
|
log(" -dump_ast1\n");
|
|
|
|
log(" dump abstract syntax tree (before simplification)\n");
|
2013-03-01 01:03:00 -06:00
|
|
|
log("\n");
|
2013-08-19 12:49:14 -05:00
|
|
|
log(" -dump_ast2\n");
|
|
|
|
log(" dump abstract syntax tree (after simplification)\n");
|
2013-03-01 01:03:00 -06:00
|
|
|
log("\n");
|
2018-08-23 07:19:46 -05:00
|
|
|
log(" -no_dump_ptr\n");
|
|
|
|
log(" do not include hex memory addresses in dump (easier to diff dumps)\n");
|
|
|
|
log("\n");
|
2019-03-21 14:52:29 -05:00
|
|
|
log(" -dump_vlog1\n");
|
|
|
|
log(" dump ast as Verilog code (before simplification)\n");
|
|
|
|
log("\n");
|
|
|
|
log(" -dump_vlog2\n");
|
2015-08-14 04:27:19 -05:00
|
|
|
log(" dump ast as Verilog code (after simplification)\n");
|
2013-03-01 01:03:00 -06:00
|
|
|
log("\n");
|
2016-07-27 08:40:17 -05:00
|
|
|
log(" -dump_rtlil\n");
|
|
|
|
log(" dump generated RTLIL netlist\n");
|
|
|
|
log("\n");
|
2013-03-01 01:03:00 -06:00
|
|
|
log(" -yydebug\n");
|
|
|
|
log(" enable parser debug output\n");
|
|
|
|
log("\n");
|
|
|
|
log(" -nolatches\n");
|
|
|
|
log(" usually latches are synthesized into logic loops\n");
|
|
|
|
log(" this option prohibits this and sets the output to 'x'\n");
|
|
|
|
log(" in what would be the latches hold condition\n");
|
|
|
|
log("\n");
|
|
|
|
log(" this behavior can also be achieved by setting the\n");
|
|
|
|
log(" 'nolatches' attribute on the respective module or\n");
|
|
|
|
log(" always block.\n");
|
|
|
|
log("\n");
|
|
|
|
log(" -nomem2reg\n");
|
|
|
|
log(" under certain conditions memories are converted to registers\n");
|
|
|
|
log(" early during simplification to ensure correct handling of\n");
|
|
|
|
log(" complex corner cases. this option disables this behavior.\n");
|
|
|
|
log("\n");
|
|
|
|
log(" this can also be achieved by setting the 'nomem2reg'\n");
|
|
|
|
log(" attribute on the respective module or register.\n");
|
|
|
|
log("\n");
|
2015-02-14 04:21:12 -06:00
|
|
|
log(" This is potentially dangerous. Usually the front-end has good\n");
|
|
|
|
log(" reasons for converting an array to a list of registers.\n");
|
|
|
|
log(" Prohibiting this step will likely result in incorrect synthesis\n");
|
|
|
|
log(" results.\n");
|
|
|
|
log("\n");
|
2013-03-24 05:13:32 -05:00
|
|
|
log(" -mem2reg\n");
|
|
|
|
log(" always convert memories to registers. this can also be\n");
|
|
|
|
log(" achieved by setting the 'mem2reg' attribute on the respective\n");
|
|
|
|
log(" module or register.\n");
|
|
|
|
log("\n");
|
2015-02-14 04:21:12 -06:00
|
|
|
log(" -nomeminit\n");
|
|
|
|
log(" do not infer $meminit cells and instead convert initialized\n");
|
|
|
|
log(" memories to registers directly in the front-end.\n");
|
|
|
|
log("\n");
|
2013-03-01 01:03:00 -06:00
|
|
|
log(" -ppdump\n");
|
2015-08-14 04:27:19 -05:00
|
|
|
log(" dump Verilog code after pre-processor\n");
|
2013-03-01 01:03:00 -06:00
|
|
|
log("\n");
|
|
|
|
log(" -nopp\n");
|
|
|
|
log(" do not run the pre-processor\n");
|
|
|
|
log("\n");
|
2015-09-23 01:23:38 -05:00
|
|
|
log(" -nodpi\n");
|
|
|
|
log(" disable DPI-C support\n");
|
|
|
|
log("\n");
|
2019-04-20 15:24:50 -05:00
|
|
|
log(" -noblackbox\n");
|
|
|
|
log(" do not automatically add a (* blackbox *) attribute to an\n");
|
|
|
|
log(" empty module.\n");
|
|
|
|
log("\n");
|
2013-03-28 03:20:10 -05:00
|
|
|
log(" -lib\n");
|
2015-04-19 14:30:46 -05:00
|
|
|
log(" only create empty blackbox modules. This implies -DBLACKBOX.\n");
|
2019-04-20 15:24:50 -05:00
|
|
|
log(" modules with the (* whitebox *) attribute will be preserved.\n");
|
|
|
|
log(" (* lib_whitebox *) will be treated like (* whitebox *).\n");
|
2013-03-28 03:20:10 -05:00
|
|
|
log("\n");
|
2019-04-20 15:24:50 -05:00
|
|
|
log(" -nowb\n");
|
|
|
|
log(" delete (* whitebox *) and (* lib_whitebox *) attributes from\n");
|
|
|
|
log(" all modules.\n");
|
2019-04-18 10:42:12 -05:00
|
|
|
log("\n");
|
2019-04-21 14:58:57 -05:00
|
|
|
log(" -specify\n");
|
|
|
|
log(" parse and import specify blocks\n");
|
|
|
|
log("\n");
|
2013-06-10 06:19:04 -05:00
|
|
|
log(" -noopt\n");
|
|
|
|
log(" don't perform basic optimizations (such as const folding) in the\n");
|
|
|
|
log(" high-level front-end.\n");
|
|
|
|
log("\n");
|
2014-01-28 17:59:28 -06:00
|
|
|
log(" -icells\n");
|
|
|
|
log(" interpret cell types starting with '$' as internal cell types\n");
|
|
|
|
log("\n");
|
2018-05-03 08:25:59 -05:00
|
|
|
log(" -nooverwrite\n");
|
2013-11-24 12:57:42 -06:00
|
|
|
log(" ignore re-definitions of modules. (the default behavior is to\n");
|
2018-05-03 08:25:59 -05:00
|
|
|
log(" create an error message if the existing module is not a black box\n");
|
|
|
|
log(" module, and overwrite the existing module otherwise.)\n");
|
|
|
|
log("\n");
|
|
|
|
log(" -overwrite\n");
|
|
|
|
log(" overwrite existing modules with the same name\n");
|
2013-11-24 12:57:42 -06:00
|
|
|
log("\n");
|
2014-02-13 06:59:13 -06:00
|
|
|
log(" -defer\n");
|
|
|
|
log(" only read the abstract syntax tree and defer actual compilation\n");
|
|
|
|
log(" to a later 'hierarchy' command. Useful in cases where the default\n");
|
|
|
|
log(" parameters of modules yield invalid or not synthesizable code.\n");
|
|
|
|
log("\n");
|
2015-08-01 05:16:54 -05:00
|
|
|
log(" -noautowire\n");
|
|
|
|
log(" make the default of `default_nettype be \"none\" instead of \"wire\".\n");
|
|
|
|
log("\n");
|
2014-02-05 04:22:10 -06:00
|
|
|
log(" -setattr <attribute_name>\n");
|
|
|
|
log(" set the specified attribute (to the value 1) on all loaded modules\n");
|
|
|
|
log("\n");
|
2013-05-19 10:07:52 -05:00
|
|
|
log(" -Dname[=definition]\n");
|
|
|
|
log(" define the preprocessor symbol 'name' and set its optional value\n");
|
|
|
|
log(" 'definition'\n");
|
|
|
|
log("\n");
|
2013-08-20 08:48:16 -05:00
|
|
|
log(" -Idir\n");
|
|
|
|
log(" add 'dir' to the directories which are used when searching include\n");
|
|
|
|
log(" files\n");
|
|
|
|
log("\n");
|
2014-01-17 10:22:29 -06:00
|
|
|
log("The command 'verilog_defaults' can be used to register default options for\n");
|
|
|
|
log("subsequent calls to 'read_verilog'.\n");
|
|
|
|
log("\n");
|
2014-02-16 13:20:25 -06:00
|
|
|
log("Note that the Verilog frontend does a pretty good job of processing valid\n");
|
|
|
|
log("verilog input, but has not very good error reporting. It generally is\n");
|
2015-08-14 04:27:19 -05:00
|
|
|
log("recommended to use a simulator (for example Icarus Verilog) for checking\n");
|
2014-02-16 13:20:25 -06:00
|
|
|
log("the syntax of the code, rather than to rely on read_verilog for that.\n");
|
|
|
|
log("\n");
|
2017-07-21 07:34:53 -05:00
|
|
|
log("Depending on if read_verilog is run in -formal mode, either the macro\n");
|
|
|
|
log("SYNTHESIS or FORMAL is defined automatically. In addition, read_verilog\n");
|
|
|
|
log("always defines the macro YOSYS.\n");
|
|
|
|
log("\n");
|
2016-05-20 09:21:35 -05:00
|
|
|
log("See the Yosys README file for a list of non-standard Verilog features\n");
|
|
|
|
log("supported by the Yosys Verilog front-end.\n");
|
|
|
|
log("\n");
|
2013-03-01 01:03:00 -06:00
|
|
|
}
|
2018-07-21 01:41:18 -05:00
|
|
|
void execute(std::istream *&f, std::string filename, std::vector<std::string> args, RTLIL::Design *design) YS_OVERRIDE
|
2013-01-05 04:13:26 -06:00
|
|
|
{
|
2013-08-19 12:49:14 -05:00
|
|
|
bool flag_dump_ast1 = false;
|
|
|
|
bool flag_dump_ast2 = false;
|
2018-08-23 07:19:46 -05:00
|
|
|
bool flag_no_dump_ptr = false;
|
2019-03-21 14:52:29 -05:00
|
|
|
bool flag_dump_vlog1 = false;
|
|
|
|
bool flag_dump_vlog2 = false;
|
2016-07-27 08:40:17 -05:00
|
|
|
bool flag_dump_rtlil = false;
|
2013-01-05 04:13:26 -06:00
|
|
|
bool flag_nolatches = false;
|
2015-02-14 04:21:12 -06:00
|
|
|
bool flag_nomeminit = false;
|
2013-01-05 04:13:26 -06:00
|
|
|
bool flag_nomem2reg = false;
|
2013-03-24 05:13:32 -05:00
|
|
|
bool flag_mem2reg = false;
|
2013-01-05 04:13:26 -06:00
|
|
|
bool flag_ppdump = false;
|
|
|
|
bool flag_nopp = false;
|
2015-09-23 01:23:38 -05:00
|
|
|
bool flag_nodpi = false;
|
2013-06-10 06:19:04 -05:00
|
|
|
bool flag_noopt = false;
|
2014-01-28 17:59:28 -06:00
|
|
|
bool flag_icells = false;
|
2018-05-03 08:25:59 -05:00
|
|
|
bool flag_nooverwrite = false;
|
|
|
|
bool flag_overwrite = false;
|
2014-02-13 06:59:13 -06:00
|
|
|
bool flag_defer = false;
|
2019-04-21 14:58:57 -05:00
|
|
|
bool flag_noblackbox = false;
|
|
|
|
bool flag_nowb = false;
|
2013-05-19 10:07:52 -05:00
|
|
|
std::map<std::string, std::string> defines_map;
|
2013-08-20 08:48:16 -05:00
|
|
|
std::list<std::string> include_dirs;
|
2014-02-05 04:22:10 -06:00
|
|
|
std::list<std::string> attributes;
|
2014-06-12 04:54:20 -05:00
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
frontend_verilog_yydebug = false;
|
2014-06-12 04:54:20 -05:00
|
|
|
sv_mode = false;
|
2015-02-26 11:47:39 -06:00
|
|
|
formal_mode = false;
|
2016-08-26 16:35:27 -05:00
|
|
|
norestrict_mode = false;
|
|
|
|
assume_asserts_mode = false;
|
2016-07-23 04:56:53 -05:00
|
|
|
lib_mode = false;
|
2019-04-21 14:58:57 -05:00
|
|
|
specify_mode = false;
|
2015-08-01 05:16:54 -05:00
|
|
|
default_nettype_wire = true;
|
2013-01-05 04:13:26 -06:00
|
|
|
|
2014-01-17 10:22:29 -06:00
|
|
|
args.insert(args.begin()+1, verilog_defaults.begin(), verilog_defaults.end());
|
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
size_t argidx;
|
|
|
|
for (argidx = 1; argidx < args.size(); argidx++) {
|
|
|
|
std::string arg = args[argidx];
|
2014-06-12 04:54:20 -05:00
|
|
|
if (arg == "-sv") {
|
|
|
|
sv_mode = true;
|
|
|
|
continue;
|
|
|
|
}
|
2015-02-26 11:47:39 -06:00
|
|
|
if (arg == "-formal") {
|
|
|
|
formal_mode = true;
|
|
|
|
continue;
|
|
|
|
}
|
2018-09-24 13:51:16 -05:00
|
|
|
if (arg == "-noassert") {
|
|
|
|
noassert_mode = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (arg == "-noassume") {
|
|
|
|
noassume_mode = true;
|
|
|
|
continue;
|
|
|
|
}
|
2016-08-26 16:35:27 -05:00
|
|
|
if (arg == "-norestrict") {
|
|
|
|
norestrict_mode = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (arg == "-assume-asserts") {
|
|
|
|
assume_asserts_mode = true;
|
|
|
|
continue;
|
|
|
|
}
|
2018-09-24 13:51:16 -05:00
|
|
|
if (arg == "-assert-assumes") {
|
|
|
|
assert_assumes_mode = true;
|
|
|
|
continue;
|
|
|
|
}
|
2019-03-21 14:52:29 -05:00
|
|
|
if (arg == "-debug") {
|
|
|
|
flag_dump_ast1 = true;
|
|
|
|
flag_dump_ast2 = true;
|
|
|
|
flag_dump_vlog1 = true;
|
|
|
|
flag_dump_vlog2 = true;
|
|
|
|
frontend_verilog_yydebug = true;
|
|
|
|
continue;
|
|
|
|
}
|
2013-08-19 12:49:14 -05:00
|
|
|
if (arg == "-dump_ast1") {
|
|
|
|
flag_dump_ast1 = true;
|
2013-01-05 04:13:26 -06:00
|
|
|
continue;
|
|
|
|
}
|
2013-08-19 12:49:14 -05:00
|
|
|
if (arg == "-dump_ast2") {
|
|
|
|
flag_dump_ast2 = true;
|
2013-01-05 04:13:26 -06:00
|
|
|
continue;
|
|
|
|
}
|
2018-08-23 07:19:46 -05:00
|
|
|
if (arg == "-no_dump_ptr") {
|
|
|
|
flag_no_dump_ptr = true;
|
|
|
|
continue;
|
|
|
|
}
|
2019-03-21 14:52:29 -05:00
|
|
|
if (arg == "-dump_vlog1") {
|
|
|
|
flag_dump_vlog1 = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (arg == "-dump_vlog2") {
|
|
|
|
flag_dump_vlog2 = true;
|
2013-01-05 04:13:26 -06:00
|
|
|
continue;
|
|
|
|
}
|
2016-07-27 08:40:17 -05:00
|
|
|
if (arg == "-dump_rtlil") {
|
|
|
|
flag_dump_rtlil = true;
|
|
|
|
continue;
|
|
|
|
}
|
2013-01-05 04:13:26 -06:00
|
|
|
if (arg == "-yydebug") {
|
|
|
|
frontend_verilog_yydebug = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (arg == "-nolatches") {
|
|
|
|
flag_nolatches = true;
|
|
|
|
continue;
|
|
|
|
}
|
2015-02-14 04:21:12 -06:00
|
|
|
if (arg == "-nomeminit") {
|
|
|
|
flag_nomeminit = true;
|
|
|
|
continue;
|
|
|
|
}
|
2013-01-05 04:13:26 -06:00
|
|
|
if (arg == "-nomem2reg") {
|
|
|
|
flag_nomem2reg = true;
|
|
|
|
continue;
|
|
|
|
}
|
2013-03-24 05:13:32 -05:00
|
|
|
if (arg == "-mem2reg") {
|
|
|
|
flag_mem2reg = true;
|
|
|
|
continue;
|
|
|
|
}
|
2013-01-05 04:13:26 -06:00
|
|
|
if (arg == "-ppdump") {
|
|
|
|
flag_ppdump = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (arg == "-nopp") {
|
|
|
|
flag_nopp = true;
|
|
|
|
continue;
|
|
|
|
}
|
2015-09-23 01:23:38 -05:00
|
|
|
if (arg == "-nodpi") {
|
|
|
|
flag_nodpi = true;
|
|
|
|
continue;
|
|
|
|
}
|
2019-04-20 15:24:50 -05:00
|
|
|
if (arg == "-noblackbox") {
|
2019-04-21 14:58:57 -05:00
|
|
|
flag_noblackbox = true;
|
2019-04-20 15:24:50 -05:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (arg == "-lib") {
|
2016-07-23 04:56:53 -05:00
|
|
|
lib_mode = true;
|
2015-04-19 14:30:46 -05:00
|
|
|
defines_map["BLACKBOX"] = string();
|
2013-03-28 03:20:10 -05:00
|
|
|
continue;
|
|
|
|
}
|
2019-04-20 15:24:50 -05:00
|
|
|
if (arg == "-nowb") {
|
2019-04-21 14:58:57 -05:00
|
|
|
flag_nowb = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (arg == "-specify") {
|
|
|
|
specify_mode = true;
|
2019-04-18 10:42:12 -05:00
|
|
|
continue;
|
|
|
|
}
|
2013-06-10 06:19:04 -05:00
|
|
|
if (arg == "-noopt") {
|
|
|
|
flag_noopt = true;
|
|
|
|
continue;
|
|
|
|
}
|
2014-01-28 17:59:28 -06:00
|
|
|
if (arg == "-icells") {
|
|
|
|
flag_icells = true;
|
|
|
|
continue;
|
|
|
|
}
|
2018-05-03 08:25:59 -05:00
|
|
|
if (arg == "-ignore_redef" || arg == "-nooverwrite") {
|
|
|
|
flag_nooverwrite = true;
|
|
|
|
flag_overwrite = false;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (arg == "-overwrite") {
|
|
|
|
flag_nooverwrite = false;
|
|
|
|
flag_overwrite = true;
|
2013-11-24 12:57:42 -06:00
|
|
|
continue;
|
|
|
|
}
|
2014-02-13 06:59:13 -06:00
|
|
|
if (arg == "-defer") {
|
|
|
|
flag_defer = true;
|
|
|
|
continue;
|
|
|
|
}
|
2015-08-01 05:16:54 -05:00
|
|
|
if (arg == "-noautowire") {
|
|
|
|
default_nettype_wire = false;
|
|
|
|
continue;
|
|
|
|
}
|
2014-02-05 04:22:10 -06:00
|
|
|
if (arg == "-setattr" && argidx+1 < args.size()) {
|
|
|
|
attributes.push_back(RTLIL::escape_id(args[++argidx]));
|
|
|
|
continue;
|
|
|
|
}
|
2014-02-02 06:06:21 -06:00
|
|
|
if (arg == "-D" && argidx+1 < args.size()) {
|
|
|
|
std::string name = args[++argidx], value;
|
2016-11-28 07:45:05 -06:00
|
|
|
size_t equal = name.find('=');
|
2013-05-19 10:07:52 -05:00
|
|
|
if (equal != std::string::npos) {
|
2016-11-28 07:45:05 -06:00
|
|
|
value = name.substr(equal+1);
|
|
|
|
name = name.substr(0, equal);
|
2013-05-19 10:07:52 -05:00
|
|
|
}
|
|
|
|
defines_map[name] = value;
|
|
|
|
continue;
|
|
|
|
}
|
2014-02-02 06:06:21 -06:00
|
|
|
if (arg.compare(0, 2, "-D") == 0) {
|
|
|
|
size_t equal = arg.find('=', 2);
|
|
|
|
std::string name = arg.substr(2, equal-2);
|
|
|
|
std::string value;
|
|
|
|
if (equal != std::string::npos)
|
|
|
|
value = arg.substr(equal+1);
|
|
|
|
defines_map[name] = value;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (arg == "-I" && argidx+1 < args.size()) {
|
|
|
|
include_dirs.push_back(args[++argidx]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (arg.compare(0, 2, "-I") == 0) {
|
|
|
|
include_dirs.push_back(arg.substr(2));
|
2013-08-20 08:48:16 -05:00
|
|
|
continue;
|
|
|
|
}
|
2013-01-05 04:13:26 -06:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
extra_args(f, filename, args, argidx);
|
|
|
|
|
2019-04-30 08:35:36 -05:00
|
|
|
log_header(design, "Executing Verilog-2005 frontend: %s\n", filename.c_str());
|
|
|
|
|
2015-02-26 11:47:39 -06:00
|
|
|
log("Parsing %s%s input from `%s' to AST representation.\n",
|
|
|
|
formal_mode ? "formal " : "", sv_mode ? "SystemVerilog" : "Verilog", filename.c_str());
|
2013-01-05 04:13:26 -06:00
|
|
|
|
|
|
|
AST::current_filename = filename;
|
|
|
|
AST::set_line_num = &frontend_verilog_yyset_lineno;
|
|
|
|
AST::get_line_num = &frontend_verilog_yyget_lineno;
|
|
|
|
|
|
|
|
current_ast = new AST::AstNode(AST::AST_DESIGN);
|
|
|
|
|
2014-08-23 08:03:55 -05:00
|
|
|
lexin = f;
|
2013-01-05 04:13:26 -06:00
|
|
|
std::string code_after_preproc;
|
|
|
|
|
|
|
|
if (!flag_nopp) {
|
2016-11-15 05:42:43 -06:00
|
|
|
code_after_preproc = frontend_verilog_preproc(*f, filename, defines_map, design->verilog_defines, include_dirs);
|
2013-01-05 04:13:26 -06:00
|
|
|
if (flag_ppdump)
|
|
|
|
log("-- Verilog code after preprocessor --\n%s-- END OF DUMP --\n", code_after_preproc.c_str());
|
2014-08-23 08:03:55 -05:00
|
|
|
lexin = new std::istringstream(code_after_preproc);
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
frontend_verilog_yyset_lineno(1);
|
2014-08-23 08:03:55 -05:00
|
|
|
frontend_verilog_yyrestart(NULL);
|
2013-01-05 04:13:26 -06:00
|
|
|
frontend_verilog_yyparse();
|
|
|
|
frontend_verilog_yylex_destroy();
|
|
|
|
|
2014-02-05 04:22:10 -06:00
|
|
|
for (auto &child : current_ast->children) {
|
2014-08-21 05:42:28 -05:00
|
|
|
if (child->type == AST::AST_MODULE)
|
|
|
|
for (auto &attr : attributes)
|
|
|
|
if (child->attributes.count(attr) == 0)
|
|
|
|
child->attributes[attr] = AST::AstNode::mkconst_int(1, false);
|
2014-02-05 04:22:10 -06:00
|
|
|
}
|
|
|
|
|
2015-09-23 01:23:38 -05:00
|
|
|
if (flag_nodpi)
|
|
|
|
error_on_dpi_function(current_ast);
|
|
|
|
|
2019-04-20 15:24:50 -05:00
|
|
|
AST::process(design, current_ast, flag_dump_ast1, flag_dump_ast2, flag_no_dump_ptr, flag_dump_vlog1, flag_dump_vlog2, flag_dump_rtlil, flag_nolatches,
|
2019-04-21 14:58:57 -05:00
|
|
|
flag_nomeminit, flag_nomem2reg, flag_mem2reg, flag_noblackbox, lib_mode, flag_nowb, flag_noopt, flag_icells, flag_nooverwrite, flag_overwrite, flag_defer, default_nettype_wire);
|
2013-01-05 04:13:26 -06:00
|
|
|
|
|
|
|
if (!flag_nopp)
|
2014-08-23 08:03:55 -05:00
|
|
|
delete lexin;
|
2013-01-05 04:13:26 -06:00
|
|
|
|
|
|
|
delete current_ast;
|
|
|
|
current_ast = NULL;
|
|
|
|
|
|
|
|
log("Successfully finished Verilog frontend.\n");
|
|
|
|
}
|
|
|
|
} VerilogFrontend;
|
|
|
|
|
2014-01-17 10:22:29 -06:00
|
|
|
struct VerilogDefaults : public Pass {
|
|
|
|
VerilogDefaults() : Pass("verilog_defaults", "set default options for read_verilog") { }
|
2018-07-21 01:41:18 -05:00
|
|
|
void help() YS_OVERRIDE
|
2014-01-17 10:22:29 -06:00
|
|
|
{
|
|
|
|
// |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
|
|
|
|
log("\n");
|
|
|
|
log(" verilog_defaults -add [options]\n");
|
|
|
|
log("\n");
|
2015-08-14 03:56:05 -05:00
|
|
|
log("Add the specified options to the list of default options to read_verilog.\n");
|
2014-01-17 10:22:29 -06:00
|
|
|
log("\n");
|
|
|
|
log("\n");
|
2016-03-10 04:14:51 -06:00
|
|
|
log(" verilog_defaults -clear\n");
|
2014-01-17 10:22:29 -06:00
|
|
|
log("\n");
|
2015-08-14 04:27:19 -05:00
|
|
|
log("Clear the list of Verilog default options.\n");
|
2014-01-17 10:22:29 -06:00
|
|
|
log("\n");
|
|
|
|
log("\n");
|
2016-03-10 04:14:51 -06:00
|
|
|
log(" verilog_defaults -push\n");
|
|
|
|
log(" verilog_defaults -pop\n");
|
2014-01-17 10:22:29 -06:00
|
|
|
log("\n");
|
|
|
|
log("Push or pop the list of default options to a stack. Note that -push does\n");
|
|
|
|
log("not imply -clear.\n");
|
|
|
|
log("\n");
|
|
|
|
}
|
2018-07-21 01:41:18 -05:00
|
|
|
void execute(std::vector<std::string> args, RTLIL::Design*) YS_OVERRIDE
|
2014-01-17 10:22:29 -06:00
|
|
|
{
|
2017-12-24 10:21:37 -06:00
|
|
|
if (args.size() < 2)
|
2014-01-17 10:22:29 -06:00
|
|
|
cmd_error(args, 1, "Missing argument.");
|
|
|
|
|
|
|
|
if (args[1] == "-add") {
|
|
|
|
verilog_defaults.insert(verilog_defaults.end(), args.begin()+2, args.end());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (args.size() != 2)
|
|
|
|
cmd_error(args, 2, "Extra argument.");
|
|
|
|
|
|
|
|
if (args[1] == "-clear") {
|
|
|
|
verilog_defaults.clear();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (args[1] == "-push") {
|
|
|
|
verilog_defaults_stack.push_back(verilog_defaults);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (args[1] == "-pop") {
|
|
|
|
if (verilog_defaults_stack.empty()) {
|
|
|
|
verilog_defaults.clear();
|
|
|
|
} else {
|
|
|
|
verilog_defaults.swap(verilog_defaults_stack.back());
|
|
|
|
verilog_defaults_stack.pop_back();
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} VerilogDefaults;
|
|
|
|
|
2016-12-15 10:49:11 -06:00
|
|
|
struct VerilogDefines : public Pass {
|
|
|
|
VerilogDefines() : Pass("verilog_defines", "define and undefine verilog defines") { }
|
2018-07-21 01:41:18 -05:00
|
|
|
void help() YS_OVERRIDE
|
2016-12-15 10:49:11 -06:00
|
|
|
{
|
|
|
|
// |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
|
|
|
|
log("\n");
|
|
|
|
log(" verilog_defines [options]\n");
|
|
|
|
log("\n");
|
|
|
|
log("Define and undefine verilog preprocessor macros.\n");
|
|
|
|
log("\n");
|
|
|
|
log(" -Dname[=definition]\n");
|
|
|
|
log(" define the preprocessor symbol 'name' and set its optional value\n");
|
|
|
|
log(" 'definition'\n");
|
|
|
|
log("\n");
|
|
|
|
log(" -Uname[=definition]\n");
|
|
|
|
log(" undefine the preprocessor symbol 'name'\n");
|
|
|
|
log("\n");
|
|
|
|
}
|
2018-07-21 01:41:18 -05:00
|
|
|
void execute(std::vector<std::string> args, RTLIL::Design *design) YS_OVERRIDE
|
2016-12-15 10:49:11 -06:00
|
|
|
{
|
|
|
|
size_t argidx;
|
|
|
|
for (argidx = 1; argidx < args.size(); argidx++) {
|
|
|
|
std::string arg = args[argidx];
|
|
|
|
if (arg == "-D" && argidx+1 < args.size()) {
|
|
|
|
std::string name = args[++argidx], value;
|
|
|
|
size_t equal = name.find('=');
|
|
|
|
if (equal != std::string::npos) {
|
|
|
|
value = name.substr(equal+1);
|
|
|
|
name = name.substr(0, equal);
|
|
|
|
}
|
|
|
|
design->verilog_defines[name] = std::pair<std::string, bool>(value, false);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (arg.compare(0, 2, "-D") == 0) {
|
|
|
|
size_t equal = arg.find('=', 2);
|
|
|
|
std::string name = arg.substr(2, equal-2);
|
|
|
|
std::string value;
|
|
|
|
if (equal != std::string::npos)
|
|
|
|
value = arg.substr(equal+1);
|
|
|
|
design->verilog_defines[name] = std::pair<std::string, bool>(value, false);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (arg == "-U" && argidx+1 < args.size()) {
|
|
|
|
std::string name = args[++argidx];
|
|
|
|
design->verilog_defines.erase(name);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (arg.compare(0, 2, "-U") == 0) {
|
|
|
|
std::string name = arg.substr(2);
|
|
|
|
design->verilog_defines.erase(name);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (args.size() != argidx)
|
|
|
|
cmd_error(args, argidx, "Extra argument.");
|
|
|
|
}
|
|
|
|
} VerilogDefines;
|
|
|
|
|
2014-07-31 06:19:47 -05:00
|
|
|
YOSYS_NAMESPACE_END
|
|
|
|
|
2014-09-27 09:17:53 -05:00
|
|
|
// the yyerror function used by bison to report parser errors
|
|
|
|
void frontend_verilog_yyerror(char const *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
char buffer[1024];
|
|
|
|
char *p = buffer;
|
|
|
|
va_start(ap, fmt);
|
|
|
|
p += vsnprintf(p, buffer + sizeof(buffer) - p, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
p += snprintf(p, buffer + sizeof(buffer) - p, "\n");
|
2018-07-20 10:11:20 -05:00
|
|
|
YOSYS_NAMESPACE_PREFIX log_file_error(YOSYS_NAMESPACE_PREFIX AST::current_filename, frontend_verilog_yyget_lineno(),
|
|
|
|
"%s", buffer);
|
2014-09-27 09:17:53 -05:00
|
|
|
exit(1);
|
|
|
|
}
|