mirror of
https://github.com/YosysHQ/yosys
synced 2025-06-18 20:03:39 +00:00
ast, read_verilog: ownership in AST, use C++ styles for parser and lexer
This commit is contained in:
parent
cd71f190cd
commit
8a9f491ffc
19 changed files with 3295 additions and 3312 deletions
3
frontends/verilog/.gitignore
vendored
3
frontends/verilog/.gitignore
vendored
|
@ -2,3 +2,6 @@ verilog_lexer.cc
|
|||
verilog_parser.output
|
||||
verilog_parser.tab.cc
|
||||
verilog_parser.tab.hh
|
||||
position.hh
|
||||
location.hh
|
||||
stack.hh
|
||||
|
|
|
@ -9,6 +9,7 @@ frontends/verilog/verilog_parser.tab.cc: frontends/verilog/verilog_parser.y
|
|||
$(P) $(BISON) -Wall -Werror -o $@ -d -r all -b frontends/verilog/verilog_parser $<
|
||||
|
||||
frontends/verilog/verilog_parser.tab.hh: frontends/verilog/verilog_parser.tab.cc
|
||||
frontends/verilog/verilog_frontend.h: frontends/verilog/verilog_parser.tab.hh
|
||||
|
||||
frontends/verilog/verilog_lexer.cc: frontends/verilog/verilog_lexer.l frontends/verilog/verilog_parser.tab.cc
|
||||
$(Q) mkdir -p $(dir $@)
|
||||
|
|
|
@ -42,14 +42,35 @@
|
|||
YOSYS_NAMESPACE_BEGIN
|
||||
|
||||
using namespace AST;
|
||||
using namespace VERILOG_FRONTEND;
|
||||
|
||||
std::string ConstParser::fmt_maybe_loc(std::string msg) {
|
||||
std::string s;
|
||||
s += filename.value_or("INTERNAL");
|
||||
|
||||
if (loc)
|
||||
s += stringf("%d", loc->first_line);
|
||||
s += ": ";
|
||||
|
||||
s += msg;
|
||||
return s;
|
||||
}
|
||||
|
||||
void ConstParser::log_maybe_loc_error(std::string msg) {
|
||||
log_error("%s", fmt_maybe_loc(msg).c_str());
|
||||
}
|
||||
|
||||
void ConstParser::log_maybe_loc_warn(std::string msg) {
|
||||
log_warning("%s", fmt_maybe_loc(msg).c_str());
|
||||
}
|
||||
|
||||
// divide an arbitrary length decimal number by two and return the rest
|
||||
static int my_decimal_div_by_two(std::vector<uint8_t> &digits)
|
||||
int ConstParser::my_decimal_div_by_two(std::vector<uint8_t> &digits)
|
||||
{
|
||||
int carry = 0;
|
||||
for (size_t i = 0; i < digits.size(); i++) {
|
||||
if (digits[i] >= 10)
|
||||
log_file_error(current_filename, get_line_num(), "Invalid use of [a-fxz?] in decimal constant.\n");
|
||||
log_maybe_loc_error("Invalid use of [a-fxz?] in decimal constant.\n");
|
||||
digits[i] += carry * 10;
|
||||
carry = digits[i] % 2;
|
||||
digits[i] /= 2;
|
||||
|
@ -60,7 +81,7 @@ static int my_decimal_div_by_two(std::vector<uint8_t> &digits)
|
|||
}
|
||||
|
||||
// find the number of significant bits in a binary number (not including the sign bit)
|
||||
static int my_ilog2(int x)
|
||||
int ConstParser::my_ilog2(int x)
|
||||
{
|
||||
int ret = 0;
|
||||
while (x != 0 && x != -1) {
|
||||
|
@ -71,7 +92,7 @@ static int my_ilog2(int x)
|
|||
}
|
||||
|
||||
// parse a binary, decimal, hexadecimal or octal number with support for special bits ('x', 'z' and '?')
|
||||
static void my_strtobin(std::vector<RTLIL::State> &data, const char *str, int len_in_bits, int base, char case_type, bool is_unsized)
|
||||
void ConstParser::my_strtobin(std::vector<RTLIL::State> &data, const char *str, int len_in_bits, int base, char case_type, bool is_unsized)
|
||||
{
|
||||
// all digits in string (MSB at index 0)
|
||||
std::vector<uint8_t> digits;
|
||||
|
@ -102,8 +123,8 @@ static void my_strtobin(std::vector<RTLIL::State> &data, const char *str, int le
|
|||
int bits_per_digit = my_ilog2(base-1);
|
||||
for (auto it = digits.rbegin(), e = digits.rend(); it != e; it++) {
|
||||
if (*it > (base-1) && *it < 0xf0)
|
||||
log_file_error(current_filename, get_line_num(), "Digit larger than %d used in in base-%d constant.\n",
|
||||
base-1, base);
|
||||
log_maybe_loc_error(stringf("Digit larger than %d used in in base-%d constant.\n",
|
||||
base-1, base));
|
||||
for (int i = 0; i < bits_per_digit; i++) {
|
||||
int bitmask = 1 << i;
|
||||
if (*it == 0xf0)
|
||||
|
@ -126,7 +147,7 @@ static void my_strtobin(std::vector<RTLIL::State> &data, const char *str, int le
|
|||
}
|
||||
|
||||
if (is_unsized && (len > len_in_bits))
|
||||
log_file_error(current_filename, get_line_num(), "Unsized constant must have width of 1 bit, but have %d bits!\n", len);
|
||||
log_maybe_loc_error(stringf("Unsized constant must have width of 1 bit, but have %d bits!\n", len));
|
||||
|
||||
for (len = len - 1; len >= 0; len--)
|
||||
if (data[len] == State::S1)
|
||||
|
@ -140,21 +161,19 @@ static void my_strtobin(std::vector<RTLIL::State> &data, const char *str, int le
|
|||
}
|
||||
|
||||
if (len_in_bits == 0)
|
||||
log_file_error(current_filename, get_line_num(), "Illegal integer constant size of zero (IEEE 1800-2012, 5.7).\n");
|
||||
log_maybe_loc_error("Illegal integer constant size of zero (IEEE 1800-2012, 5.7).\n");
|
||||
|
||||
if (len > len_in_bits)
|
||||
log_warning("Literal has a width of %d bit, but value requires %d bit. (%s:%d)\n",
|
||||
len_in_bits, len, current_filename.c_str(), get_line_num());
|
||||
log_maybe_loc_warn(stringf("Literal has a width of %d bit, but value requires %d bit.\n",
|
||||
len_in_bits, len));
|
||||
}
|
||||
|
||||
// convert the Verilog code for a constant to an AST node
|
||||
AstNode *VERILOG_FRONTEND::const2ast(std::string code, char case_type, bool warn_z)
|
||||
std::unique_ptr<AstNode> ConstParser::const2ast(std::string code, char case_type, bool warn_z)
|
||||
{
|
||||
if (warn_z) {
|
||||
AstNode *ret = const2ast(code, case_type);
|
||||
auto ret = const2ast(code, case_type);
|
||||
if (ret != nullptr && std::find(ret->bits.begin(), ret->bits.end(), RTLIL::State::Sz) != ret->bits.end())
|
||||
log_warning("Yosys has only limited support for tri-state logic at the moment. (%s:%d)\n",
|
||||
current_filename.c_str(), get_line_num());
|
||||
log_maybe_loc_warn("Yosys has only limited support for tri-state logic at the moment.\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -172,7 +191,7 @@ AstNode *VERILOG_FRONTEND::const2ast(std::string code, char case_type, bool warn
|
|||
ch = ch >> 1;
|
||||
}
|
||||
}
|
||||
AstNode *ast = AstNode::mkconst_bits(data, false);
|
||||
auto ast = AstNode::mkconst_bits(data, false);
|
||||
ast->str = code;
|
||||
return ast;
|
||||
}
|
||||
|
@ -245,4 +264,5 @@ AstNode *VERILOG_FRONTEND::const2ast(std::string code, char case_type, bool warn
|
|||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
YOSYS_NAMESPACE_END
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
|
||||
#include "preproc.h"
|
||||
#include "verilog_frontend.h"
|
||||
#include "verilog_parser.tab.hh"
|
||||
#include "kernel/log.h"
|
||||
#include <assert.h>
|
||||
#include <stack>
|
||||
|
@ -749,7 +750,9 @@ frontend_verilog_preproc(std::istream &f,
|
|||
std::string filename,
|
||||
const define_map_t &pre_defines,
|
||||
define_map_t &global_defines_cache,
|
||||
const std::list<std::string> &include_dirs)
|
||||
const std::list<std::string> &include_dirs,
|
||||
ParseState &parse_state,
|
||||
ParseMode &parse_mode)
|
||||
{
|
||||
define_map_t defines;
|
||||
defines.merge(pre_defines);
|
||||
|
@ -961,11 +964,11 @@ frontend_verilog_preproc(std::istream &f,
|
|||
}
|
||||
|
||||
if (tok == "`resetall") {
|
||||
default_nettype_wire = true;
|
||||
parse_state.default_nettype_wire = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (tok == "`undefineall" && sv_mode) {
|
||||
if (tok == "`undefineall" && parse_mode.sv) {
|
||||
defines.clear();
|
||||
global_defines_cache.clear();
|
||||
continue;
|
||||
|
|
|
@ -35,6 +35,11 @@ YOSYS_NAMESPACE_BEGIN
|
|||
struct define_body_t;
|
||||
struct arg_map_t;
|
||||
|
||||
namespace VERILOG_FRONTEND {
|
||||
struct ParseState;
|
||||
struct ParseMode;
|
||||
};
|
||||
|
||||
struct define_map_t
|
||||
{
|
||||
define_map_t();
|
||||
|
@ -71,7 +76,9 @@ frontend_verilog_preproc(std::istream &f,
|
|||
std::string filename,
|
||||
const define_map_t &pre_defines,
|
||||
define_map_t &global_defines_cache,
|
||||
const std::list<std::string> &include_dirs);
|
||||
const std::list<std::string> &include_dirs,
|
||||
VERILOG_FRONTEND::ParseState &parse_state,
|
||||
VERILOG_FRONTEND::ParseMode &parse_mode);
|
||||
|
||||
YOSYS_NAMESPACE_END
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
#endif
|
||||
|
||||
#include "verilog_frontend.h"
|
||||
#include "verilog_lexer.h"
|
||||
#include "preproc.h"
|
||||
#include "kernel/yosys.h"
|
||||
#include "libs/sha1/sha1.h"
|
||||
|
@ -48,11 +49,11 @@ static void error_on_dpi_function(AST::AstNode *node)
|
|||
{
|
||||
if (node->type == AST::AST_DPI_FUNCTION)
|
||||
log_file_error(node->filename, node->location.first_line, "Found DPI function %s.\n", node->str.c_str());
|
||||
for (auto child : node->children)
|
||||
error_on_dpi_function(child);
|
||||
for (auto& child : node->children)
|
||||
error_on_dpi_function(child.get());
|
||||
}
|
||||
|
||||
static void add_package_types(dict<std::string, AST::AstNode *> &user_types, std::vector<AST::AstNode *> &package_list)
|
||||
static void add_package_types(dict<std::string, AST::AstNode *> &user_types, std::vector<std::unique_ptr<AST::AstNode>> &package_list)
|
||||
{
|
||||
// prime the parser's user type lookup table with the package qualified names
|
||||
// of typedefed names in the packages seen so far.
|
||||
|
@ -61,14 +62,22 @@ static void add_package_types(dict<std::string, AST::AstNode *> &user_types, std
|
|||
for (const auto &node: pkg->children) {
|
||||
if (node->type == AST::AST_TYPEDEF) {
|
||||
std::string s = pkg->str + "::" + node->str.substr(1);
|
||||
user_types[s] = node;
|
||||
user_types[s] = node.get();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct VerilogFrontend : public Frontend {
|
||||
VerilogFrontend() : Frontend("verilog", "read modules from Verilog file") { }
|
||||
ParseMode parse_mode;
|
||||
ParseState parse_state;
|
||||
VerilogLexer lexer;
|
||||
frontend_verilog_yy::parser parser;
|
||||
VerilogFrontend() : Frontend("verilog", "read modules from Verilog file"),
|
||||
parse_mode(),
|
||||
parse_state(),
|
||||
lexer(&parse_state, &parse_mode),
|
||||
parser(&lexer, &parse_state, &parse_mode) { }
|
||||
void help() override
|
||||
{
|
||||
// |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
|
||||
|
@ -266,22 +275,24 @@ struct VerilogFrontend : public Frontend {
|
|||
bool flag_noblackbox = false;
|
||||
bool flag_nowb = false;
|
||||
bool flag_nosynthesis = false;
|
||||
bool flag_yydebug = false;
|
||||
define_map_t defines_map;
|
||||
|
||||
std::list<std::string> include_dirs;
|
||||
std::list<std::string> attributes;
|
||||
|
||||
frontend_verilog_yydebug = false;
|
||||
sv_mode = false;
|
||||
formal_mode = false;
|
||||
noassert_mode = false;
|
||||
noassume_mode = false;
|
||||
norestrict_mode = false;
|
||||
assume_asserts_mode = false;
|
||||
assert_assumes_mode = false;
|
||||
lib_mode = false;
|
||||
specify_mode = false;
|
||||
default_nettype_wire = true;
|
||||
lexer.set_debug(false);
|
||||
parser.set_debug_level(0);
|
||||
parse_mode.sv = false;
|
||||
parse_mode.formal = false;
|
||||
parse_mode.noassert = false;
|
||||
parse_mode.noassume = false;
|
||||
parse_mode.norestrict = false;
|
||||
parse_mode.assume_asserts = false;
|
||||
parse_mode.assert_assumes = false;
|
||||
parse_mode.lib = false;
|
||||
parse_mode.specify = false;
|
||||
parse_state.default_nettype_wire = true;
|
||||
|
||||
args.insert(args.begin()+1, verilog_defaults.begin(), verilog_defaults.end());
|
||||
|
||||
|
@ -289,11 +300,11 @@ struct VerilogFrontend : public Frontend {
|
|||
for (argidx = 1; argidx < args.size(); argidx++) {
|
||||
std::string arg = args[argidx];
|
||||
if (arg == "-sv") {
|
||||
sv_mode = true;
|
||||
parse_mode.sv = true;
|
||||
continue;
|
||||
}
|
||||
if (arg == "-formal") {
|
||||
formal_mode = true;
|
||||
parse_mode.formal = true;
|
||||
continue;
|
||||
}
|
||||
if (arg == "-nosynthesis") {
|
||||
|
@ -301,23 +312,23 @@ struct VerilogFrontend : public Frontend {
|
|||
continue;
|
||||
}
|
||||
if (arg == "-noassert") {
|
||||
noassert_mode = true;
|
||||
parse_mode.noassert = true;
|
||||
continue;
|
||||
}
|
||||
if (arg == "-noassume") {
|
||||
noassume_mode = true;
|
||||
parse_mode.noassume = true;
|
||||
continue;
|
||||
}
|
||||
if (arg == "-norestrict") {
|
||||
norestrict_mode = true;
|
||||
parse_mode.norestrict = true;
|
||||
continue;
|
||||
}
|
||||
if (arg == "-assume-asserts") {
|
||||
assume_asserts_mode = true;
|
||||
parse_mode.assume_asserts = true;
|
||||
continue;
|
||||
}
|
||||
if (arg == "-assert-assumes") {
|
||||
assert_assumes_mode = true;
|
||||
parse_mode.assert_assumes = true;
|
||||
continue;
|
||||
}
|
||||
if (arg == "-nodisplay") {
|
||||
|
@ -329,7 +340,8 @@ struct VerilogFrontend : public Frontend {
|
|||
flag_dump_ast2 = true;
|
||||
flag_dump_vlog1 = true;
|
||||
flag_dump_vlog2 = true;
|
||||
frontend_verilog_yydebug = true;
|
||||
lexer.set_debug(true);
|
||||
parser.set_debug_level(1);
|
||||
continue;
|
||||
}
|
||||
if (arg == "-dump_ast1") {
|
||||
|
@ -357,7 +369,7 @@ struct VerilogFrontend : public Frontend {
|
|||
continue;
|
||||
}
|
||||
if (arg == "-yydebug") {
|
||||
frontend_verilog_yydebug = true;
|
||||
flag_yydebug = true;
|
||||
continue;
|
||||
}
|
||||
if (arg == "-nolatches") {
|
||||
|
@ -393,7 +405,7 @@ struct VerilogFrontend : public Frontend {
|
|||
continue;
|
||||
}
|
||||
if (arg == "-lib") {
|
||||
lib_mode = true;
|
||||
parse_mode.lib = true;
|
||||
defines_map.add("BLACKBOX", "");
|
||||
continue;
|
||||
}
|
||||
|
@ -402,7 +414,7 @@ struct VerilogFrontend : public Frontend {
|
|||
continue;
|
||||
}
|
||||
if (arg == "-specify") {
|
||||
specify_mode = true;
|
||||
parse_mode.specify = true;
|
||||
continue;
|
||||
}
|
||||
if (arg == "-noopt") {
|
||||
|
@ -432,7 +444,7 @@ struct VerilogFrontend : public Frontend {
|
|||
continue;
|
||||
}
|
||||
if (arg == "-noautowire") {
|
||||
default_nettype_wire = false;
|
||||
parse_state.default_nettype_wire = false;
|
||||
continue;
|
||||
}
|
||||
if (arg == "-setattr" && argidx+1 < args.size()) {
|
||||
|
@ -469,54 +481,59 @@ struct VerilogFrontend : public Frontend {
|
|||
break;
|
||||
}
|
||||
|
||||
if (formal_mode || !flag_nosynthesis)
|
||||
defines_map.add(formal_mode ? "FORMAL" : "SYNTHESIS", "1");
|
||||
if (parse_mode.formal || !flag_nosynthesis)
|
||||
defines_map.add(parse_mode.formal ? "FORMAL" : "SYNTHESIS", "1");
|
||||
|
||||
extra_args(f, filename, args, argidx);
|
||||
|
||||
log_header(design, "Executing Verilog-2005 frontend: %s\n", filename.c_str());
|
||||
|
||||
log("Parsing %s%s input from `%s' to AST representation.\n",
|
||||
formal_mode ? "formal " : "", sv_mode ? "SystemVerilog" : "Verilog", filename.c_str());
|
||||
parse_mode.formal ? "formal " : "", parse_mode.sv ? "SystemVerilog" : "Verilog", filename.c_str());
|
||||
|
||||
AST::current_filename = filename;
|
||||
AST::set_line_num = &frontend_verilog_yyset_lineno;
|
||||
AST::get_line_num = &frontend_verilog_yyget_lineno;
|
||||
AST::sv_mode = parse_mode.sv;
|
||||
|
||||
current_ast = new AST::AstNode(AST::AST_DESIGN);
|
||||
parse_state.current_ast = new AST::AstNode(AST::AST_DESIGN);
|
||||
|
||||
lexin = f;
|
||||
parse_state.lexin = f;
|
||||
std::string code_after_preproc;
|
||||
|
||||
if (!flag_nopp) {
|
||||
code_after_preproc = frontend_verilog_preproc(*f, filename, defines_map, *design->verilog_defines, include_dirs);
|
||||
code_after_preproc = frontend_verilog_preproc(*f, filename, defines_map, *design->verilog_defines, include_dirs, parse_state, parse_mode);
|
||||
if (flag_ppdump)
|
||||
log("-- Verilog code after preprocessor --\n%s-- END OF DUMP --\n", code_after_preproc.c_str());
|
||||
lexin = new std::istringstream(code_after_preproc);
|
||||
parse_state.lexin = new std::istringstream(code_after_preproc);
|
||||
}
|
||||
|
||||
// make package typedefs available to parser
|
||||
add_package_types(pkg_user_types, design->verilog_packages);
|
||||
add_package_types(parse_state.pkg_user_types, design->verilog_packages);
|
||||
|
||||
UserTypeMap global_types_map;
|
||||
for (auto def : design->verilog_globals) {
|
||||
for (auto& def : design->verilog_globals) {
|
||||
if (def->type == AST::AST_TYPEDEF) {
|
||||
global_types_map[def->str] = def;
|
||||
global_types_map[def->str] = def.get();
|
||||
}
|
||||
}
|
||||
|
||||
log_assert(user_type_stack.empty());
|
||||
log_assert(parse_state.user_type_stack.empty());
|
||||
// use previous global typedefs as bottom level of user type stack
|
||||
user_type_stack.push_back(std::move(global_types_map));
|
||||
parse_state.user_type_stack.push_back(std::move(global_types_map));
|
||||
// add a new empty type map to allow overriding existing global definitions
|
||||
user_type_stack.push_back(UserTypeMap());
|
||||
parse_state.user_type_stack.push_back(UserTypeMap());
|
||||
|
||||
frontend_verilog_yyset_lineno(1);
|
||||
frontend_verilog_yyrestart(NULL);
|
||||
frontend_verilog_yyparse();
|
||||
frontend_verilog_yylex_destroy();
|
||||
parser.~parser();
|
||||
lexer.~VerilogLexer();
|
||||
new (&lexer) VerilogLexer(&parse_state, &parse_mode);
|
||||
new (&parser) frontend_verilog_yy::parser(&lexer, &parse_state, &parse_mode);
|
||||
if (flag_yydebug) {
|
||||
lexer.set_debug(true);
|
||||
parser.set_debug_level(1);
|
||||
}
|
||||
parser.parse();
|
||||
// frontend_verilog_yyset_lineno(1);
|
||||
|
||||
for (auto &child : current_ast->children) {
|
||||
for (auto &child : parse_state.current_ast->children) {
|
||||
if (child->type == AST::AST_MODULE)
|
||||
for (auto &attr : attributes)
|
||||
if (child->attributes.count(attr) == 0)
|
||||
|
@ -524,21 +541,21 @@ struct VerilogFrontend : public Frontend {
|
|||
}
|
||||
|
||||
if (flag_nodpi)
|
||||
error_on_dpi_function(current_ast);
|
||||
error_on_dpi_function(parse_state.current_ast);
|
||||
|
||||
AST::process(design, current_ast, flag_nodisplay, flag_dump_ast1, flag_dump_ast2, flag_no_dump_ptr, flag_dump_vlog1, flag_dump_vlog2, flag_dump_rtlil, flag_nolatches,
|
||||
flag_nomeminit, flag_nomem2reg, flag_mem2reg, flag_noblackbox, lib_mode, flag_nowb, flag_noopt, flag_icells, flag_pwires, flag_nooverwrite, flag_overwrite, flag_defer, default_nettype_wire);
|
||||
AST::process(design, parse_state.current_ast, flag_nodisplay, flag_dump_ast1, flag_dump_ast2, flag_no_dump_ptr, flag_dump_vlog1, flag_dump_vlog2, flag_dump_rtlil, flag_nolatches,
|
||||
flag_nomeminit, flag_nomem2reg, flag_mem2reg, flag_noblackbox, parse_mode.lib, flag_nowb, flag_noopt, flag_icells, flag_pwires, flag_nooverwrite, flag_overwrite, flag_defer, parse_state.default_nettype_wire);
|
||||
|
||||
|
||||
if (!flag_nopp)
|
||||
delete lexin;
|
||||
delete parse_state.lexin;
|
||||
|
||||
// only the previous and new global type maps remain
|
||||
log_assert(user_type_stack.size() == 2);
|
||||
user_type_stack.clear();
|
||||
log_assert(parse_state.user_type_stack.size() == 2);
|
||||
parse_state.user_type_stack.clear();
|
||||
|
||||
delete current_ast;
|
||||
current_ast = NULL;
|
||||
delete parse_state.current_ast;
|
||||
parse_state.current_ast = NULL;
|
||||
|
||||
log("Successfully finished Verilog frontend.\n");
|
||||
}
|
||||
|
@ -759,19 +776,33 @@ struct VerilogFileList : public Pass {
|
|||
|
||||
#endif
|
||||
|
||||
YOSYS_NAMESPACE_END
|
||||
|
||||
// the yyerror function used by bison to report parser errors
|
||||
void frontend_verilog_yyerror(char const *fmt, ...)
|
||||
[[noreturn]]
|
||||
void VERILOG_FRONTEND::verr_at(std::string filename, int begin_line, char const *fmt, va_list ap)
|
||||
{
|
||||
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");
|
||||
YOSYS_NAMESPACE_PREFIX log_file_error(YOSYS_NAMESPACE_PREFIX AST::current_filename, frontend_verilog_yyget_lineno(),
|
||||
"%s", buffer);
|
||||
exit(1);
|
||||
char buffer[1024];
|
||||
char *p = buffer;
|
||||
p += vsnprintf(p, buffer + sizeof(buffer) - p, fmt, ap);
|
||||
p += snprintf(p, buffer + sizeof(buffer) - p, "\n");
|
||||
YOSYS_NAMESPACE_PREFIX log_file_error(filename, begin_line, "%s", buffer);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
[[noreturn]]
|
||||
void VERILOG_FRONTEND::err_at_loc(parser::location_type loc, char const *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
verr_at(AST::current_filename, loc.begin.line, fmt, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
[[noreturn]]
|
||||
void VERILOG_FRONTEND::err_at_ast(AstSrcLocType loc, char const *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
verr_at(AST::current_filename, loc.first_line, fmt, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
YOSYS_NAMESPACE_END
|
||||
|
|
|
@ -31,6 +31,13 @@
|
|||
|
||||
#include "kernel/yosys.h"
|
||||
#include "frontends/ast/ast.h"
|
||||
#include "frontends/verilog/location.hh"
|
||||
|
||||
#if ! defined(yyFlexLexerOnce)
|
||||
#define yyFlexLexer frontend_verilog_yyFlexLexer
|
||||
#include <FlexLexer.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <list>
|
||||
|
@ -39,62 +46,33 @@ YOSYS_NAMESPACE_BEGIN
|
|||
|
||||
namespace VERILOG_FRONTEND
|
||||
{
|
||||
// this variable is set to a new AST_DESIGN node and then filled with the AST by the bison parser
|
||||
extern struct AST::AstNode *current_ast;
|
||||
/* Ephemeral context class */
|
||||
struct ConstParser {
|
||||
std::optional<std::string> filename;
|
||||
std::optional<AST::AstSrcLocType> loc;
|
||||
private:
|
||||
std::string fmt_maybe_loc(std::string msg);
|
||||
void log_maybe_loc_error(std::string msg);
|
||||
void log_maybe_loc_warn(std::string msg);
|
||||
// divide an arbitrary length decimal number by two and return the rest
|
||||
int my_decimal_div_by_two(std::vector<uint8_t> &digits);
|
||||
// find the number of significant bits in a binary number (not including the sign bit)
|
||||
int my_ilog2(int x);
|
||||
// parse a binary, decimal, hexadecimal or octal number with support for special bits ('x', 'z' and '?')
|
||||
void my_strtobin(std::vector<RTLIL::State> &data, const char *str, int len_in_bits, int base, char case_type, bool is_unsized);
|
||||
public:
|
||||
// convert the Verilog code for a constant to an AST node
|
||||
std::unique_ptr<AST::AstNode> const2ast(std::string code, char case_type = 0, bool warn_z = false);
|
||||
|
||||
// this function converts a Verilog constant to an AST_CONSTANT node
|
||||
AST::AstNode *const2ast(std::string code, char case_type = 0, bool warn_z = false);
|
||||
|
||||
// names of locally typedef'ed types in a stack
|
||||
typedef std::map<std::string, AST::AstNode*> UserTypeMap;
|
||||
extern std::vector<UserTypeMap> user_type_stack;
|
||||
|
||||
// names of package typedef'ed types
|
||||
extern dict<std::string, AST::AstNode*> pkg_user_types;
|
||||
|
||||
// state of `default_nettype
|
||||
extern bool default_nettype_wire;
|
||||
|
||||
// running in SystemVerilog mode
|
||||
extern bool sv_mode;
|
||||
|
||||
// running in -formal mode
|
||||
extern bool formal_mode;
|
||||
|
||||
// running in -noassert mode
|
||||
extern bool noassert_mode;
|
||||
|
||||
// running in -noassume mode
|
||||
extern bool noassume_mode;
|
||||
|
||||
// running in -norestrict mode
|
||||
extern bool norestrict_mode;
|
||||
|
||||
// running in -assume-asserts mode
|
||||
extern bool assume_asserts_mode;
|
||||
|
||||
// running in -assert-assumes mode
|
||||
extern bool assert_assumes_mode;
|
||||
|
||||
// running in -lib mode
|
||||
extern bool lib_mode;
|
||||
|
||||
// running in -specify mode
|
||||
extern bool specify_mode;
|
||||
|
||||
// lexer input stream
|
||||
extern std::istream *lexin;
|
||||
}
|
||||
};
|
||||
[[noreturn]]
|
||||
extern void verr_at(std::string filename, int begin_line, char const *fmt, va_list ap);
|
||||
[[noreturn]]
|
||||
extern void err_at_loc(frontend_verilog_yy::location loc, char const *fmt, ...);
|
||||
[[noreturn]]
|
||||
extern void err_at_ast(AST::AstSrcLocType loc, char const *fmt, ...);
|
||||
};
|
||||
|
||||
YOSYS_NAMESPACE_END
|
||||
|
||||
// the usual bison/flex stuff
|
||||
extern int frontend_verilog_yydebug;
|
||||
void frontend_verilog_yyerror(char const *fmt, ...);
|
||||
void frontend_verilog_yyrestart(FILE *f);
|
||||
int frontend_verilog_yyparse(void);
|
||||
int frontend_verilog_yylex_destroy(void);
|
||||
int frontend_verilog_yyget_lineno(void);
|
||||
void frontend_verilog_yyset_lineno (int);
|
||||
|
||||
#endif
|
||||
|
|
48
frontends/verilog/verilog_lexer.h
Normal file
48
frontends/verilog/verilog_lexer.h
Normal file
|
@ -0,0 +1,48 @@
|
|||
#ifndef VERILOG_LEXER_H
|
||||
#define VERILOG_LEXER_H
|
||||
|
||||
#include "kernel/yosys.h"
|
||||
#include "frontends/ast/ast.h"
|
||||
#include "frontends/verilog/verilog_parser.tab.hh"
|
||||
|
||||
YOSYS_NAMESPACE_BEGIN
|
||||
|
||||
namespace VERILOG_FRONTEND {
|
||||
// lexer input stream
|
||||
using parser = frontend_verilog_yy::parser;
|
||||
class VerilogLexer : public frontend_verilog_yyFlexLexer {
|
||||
ParseState* extra;
|
||||
ParseMode* mode;
|
||||
public:
|
||||
VerilogLexer(ParseState* e, ParseMode* m) : frontend_verilog_yyFlexLexer(e->lexin), extra(e), mode(m) {}
|
||||
~VerilogLexer() override {}
|
||||
// autogenerated body due to YY_DECL
|
||||
parser::symbol_type nextToken();
|
||||
// get rid of override virtual function warning
|
||||
using FlexLexer::yylex;
|
||||
parser::symbol_type terminate() {
|
||||
return parser::make_FRONTEND_VERILOG_YYEOF(out_loc);
|
||||
}
|
||||
parser::location_type out_loc;
|
||||
[[noreturn]]
|
||||
void err(char const *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
verr_at(AST::current_filename, yylineno, fmt, args);
|
||||
}
|
||||
private:
|
||||
std::vector<std::string> fn_stack;
|
||||
std::vector<int> ln_stack;
|
||||
parser::location_type real_loc;
|
||||
parser::location_type old_loc;
|
||||
int LexerInput(char* buf, int max_size) override {
|
||||
return readsome(*extra->lexin, buf, max_size);
|
||||
}
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
YOSYS_NAMESPACE_END
|
||||
|
||||
#endif
|
|
@ -32,6 +32,13 @@
|
|||
*
|
||||
*/
|
||||
|
||||
%option c++
|
||||
%option yyclass="VerilogLexer"
|
||||
%option noyywrap
|
||||
%option nounput
|
||||
%option yylineno
|
||||
%option prefix="frontend_verilog_yy"
|
||||
|
||||
%{
|
||||
|
||||
#ifdef __clang__
|
||||
|
@ -41,85 +48,112 @@
|
|||
#pragma clang diagnostic ignored "-Wmisleading-indentation"
|
||||
#endif
|
||||
|
||||
#include "kernel/log.h"
|
||||
#include "frontends/verilog/verilog_frontend.h"
|
||||
#include "frontends/verilog/verilog_lexer.h"
|
||||
#include "frontends/ast/ast.h"
|
||||
#include "verilog_parser.tab.hh"
|
||||
#include "kernel/log.h"
|
||||
#include <vector>
|
||||
|
||||
USING_YOSYS_NAMESPACE
|
||||
using namespace AST;
|
||||
using namespace VERILOG_FRONTEND;
|
||||
|
||||
#define YYSTYPE FRONTEND_VERILOG_YYSTYPE
|
||||
#define YYLTYPE FRONTEND_VERILOG_YYLTYPE
|
||||
using parser = frontend_verilog_yy::parser;
|
||||
//#define YYSTYPE FRONTEND_VERILOG_YYSTYPE
|
||||
//#define YYLTYPE FRONTEND_VERILOG_YYLTYPE
|
||||
|
||||
YOSYS_NAMESPACE_BEGIN
|
||||
namespace VERILOG_FRONTEND {
|
||||
std::vector<std::string> fn_stack;
|
||||
std::vector<int> ln_stack;
|
||||
YYLTYPE real_location;
|
||||
YYLTYPE old_location;
|
||||
}
|
||||
#undef YY_DECL
|
||||
#define YY_DECL parser::symbol_type VerilogLexer::nextToken()
|
||||
|
||||
#undef yyterminate
|
||||
#define yyterminate() terminate()
|
||||
|
||||
YOSYS_NAMESPACE_END
|
||||
|
||||
#define SV_KEYWORD(_tok) \
|
||||
if (sv_mode) return _tok; \
|
||||
if (mode->sv) return _tok; \
|
||||
log("Lexer warning: The SystemVerilog keyword `%s' (at %s:%d) is not "\
|
||||
"recognized unless read_verilog is called with -sv!\n", yytext, \
|
||||
AST::current_filename.c_str(), frontend_verilog_yyget_lineno()); \
|
||||
yylval->string = new std::string(std::string("\\") + yytext); \
|
||||
return TOK_ID;
|
||||
"recognized unless read_verilog is called with -sv!\n", YYText(), \
|
||||
AST::current_filename.c_str(), yylineno); \
|
||||
string_t val = new std::string(std::string("\\") + YYText()); \
|
||||
return parser::make_TOK_ID(val, out_loc);
|
||||
|
||||
#define NON_KEYWORD() \
|
||||
yylval->string = new std::string(std::string("\\") + yytext); \
|
||||
return TOK_ID;
|
||||
string_t val = new std::string(std::string("\\") + YYText()); \
|
||||
return parser::make_TOK_ID(val, out_loc);
|
||||
|
||||
#define YY_INPUT(buf,result,max_size) \
|
||||
result = readsome(*VERILOG_FRONTEND::lexin, buf, max_size)
|
||||
// #define YY_INPUT(buf,result,max_size) \
|
||||
// result = readsome(*extra->lexin, buf, max_size)
|
||||
|
||||
#define YY_USER_ACTION \
|
||||
old_location = real_location; \
|
||||
real_location.first_line = real_location.last_line; \
|
||||
real_location.first_column = real_location.last_column; \
|
||||
for(int i = 0; yytext[i] != '\0'; ++i){ \
|
||||
if(yytext[i] == '\n') { \
|
||||
real_location.last_line++; \
|
||||
real_location.last_column = 1; \
|
||||
} \
|
||||
else { \
|
||||
real_location.last_column++; \
|
||||
} \
|
||||
} \
|
||||
(*yylloc) = real_location;
|
||||
real_loc.begin = real_loc.end; \
|
||||
for(int i = 0; YYText()[i] != '\0'; ++i){ \
|
||||
if(YYText()[i] == '\n') { \
|
||||
real_loc.end.line++; \
|
||||
real_loc.end.column = 1; \
|
||||
} \
|
||||
else { \
|
||||
real_loc.end.column++; \
|
||||
} \
|
||||
} \
|
||||
out_loc = real_loc;
|
||||
|
||||
#define YY_BREAK \
|
||||
(*yylloc) = old_location; \
|
||||
break;
|
||||
|
||||
#undef YY_BUF_SIZE
|
||||
#define YY_BUF_SIZE 65536
|
||||
|
||||
extern int frontend_verilog_yylex(YYSTYPE *yylval_param, YYLTYPE *yyloc_param);
|
||||
|
||||
static bool isUserType(std::string &s)
|
||||
static bool isUserType(ParseState* extra, std::string &s)
|
||||
{
|
||||
// check current scope then outer scopes for a name
|
||||
for (auto it = user_type_stack.rbegin(); it != user_type_stack.rend(); ++it) {
|
||||
for (auto it = extra->user_type_stack.rbegin(); it != extra->user_type_stack.rend(); ++it) {
|
||||
if (it->count(s) > 0) {
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
%}
|
||||
parser::symbol_type char_tok(char c, parser::location_type loc) {
|
||||
switch (c) {
|
||||
case '!': return parser::make_TOK_EXCL(loc);
|
||||
case '#': return parser::make_TOK_HASH(loc);
|
||||
case '%': return parser::make_TOK_PERC(loc);
|
||||
case '&': return parser::make_TOK_AMP(loc);
|
||||
case '(': return parser::make_TOK_LPAREN(loc);
|
||||
case ')': return parser::make_TOK_RPAREN(loc);
|
||||
case '*': return parser::make_TOK_ASTER(loc);
|
||||
case '+': return parser::make_TOK_PLUS(loc);
|
||||
case ',': return parser::make_TOK_COMMA(loc);
|
||||
case '-': return parser::make_TOK_MINUS(loc);
|
||||
case '.': return parser::make_TOK_DOT(loc);
|
||||
case '/': return parser::make_TOK_SLASH(loc);
|
||||
case ':': return parser::make_TOK_COL(loc);
|
||||
case ';': return parser::make_TOK_SEMICOL(loc);
|
||||
case '<': return parser::make_TOK_LT(loc);
|
||||
case '=': return parser::make_TOK_EQ(loc);
|
||||
case '>': return parser::make_TOK_GT(loc);
|
||||
case '?': return parser::make_TOK_QUE(loc);
|
||||
case '@': return parser::make_TOK_AT(loc);
|
||||
case '[': return parser::make_TOK_LBRA(loc);
|
||||
case ']': return parser::make_TOK_RBRA(loc);
|
||||
case '^': return parser::make_TOK_CARET(loc);
|
||||
case '_': return parser::make_TOK_UNDER(loc);
|
||||
case '{': return parser::make_TOK_LCURL(loc);
|
||||
case '|': return parser::make_TOK_PIPE(loc);
|
||||
case '}': return parser::make_TOK_RCURL(loc);
|
||||
case '~': return parser::make_TOK_TILDE(loc);
|
||||
case 'n': return parser::make_TOK_n(loc);
|
||||
case 'p': return parser::make_TOK_p(loc);
|
||||
case 'x': return parser::make_TOK_x(loc);
|
||||
case 'z': return parser::make_TOK_z(loc);
|
||||
case 0: return parser::make_FRONTEND_VERILOG_YYEOF(loc);
|
||||
default:
|
||||
return parser::make_ch_t(c, loc);
|
||||
}
|
||||
}
|
||||
|
||||
%option yylineno
|
||||
%option noyywrap
|
||||
%option nounput
|
||||
%option bison-locations
|
||||
%option bison-bridge
|
||||
%option prefix="frontend_verilog_yy"
|
||||
%}
|
||||
|
||||
%x COMMENT
|
||||
%x STRING
|
||||
|
@ -134,47 +168,48 @@ FIXED_POINT_NUMBER_NO_DEC [0-9][0-9_]*[eE][-+]?[0-9_]+
|
|||
TIME_SCALE_SUFFIX [munpf]?s
|
||||
|
||||
%%
|
||||
|
||||
// Initialise comment_caller to something to avoid a "maybe undefined"
|
||||
// warning from GCC.
|
||||
int comment_caller = INITIAL;
|
||||
|
||||
<INITIAL,SYNOPSYS_TRANSLATE_OFF>"`file_push "[^\n]* {
|
||||
fn_stack.push_back(current_filename);
|
||||
ln_stack.push_back(frontend_verilog_yyget_lineno());
|
||||
current_filename = yytext+11;
|
||||
ln_stack.push_back(yylineno);
|
||||
current_filename = YYText()+11;
|
||||
if (!current_filename.empty() && current_filename.front() == '"')
|
||||
current_filename = current_filename.substr(1);
|
||||
if (!current_filename.empty() && current_filename.back() == '"')
|
||||
current_filename = current_filename.substr(0, current_filename.size()-1);
|
||||
frontend_verilog_yyset_lineno(0);
|
||||
yylloc->first_line = yylloc->last_line = 0;
|
||||
real_location.first_line = real_location.last_line = 0;
|
||||
yylineno = (0);
|
||||
out_loc.begin.line = out_loc.end.line = 0;
|
||||
real_loc.begin.line = real_loc.end.line = 0;
|
||||
}
|
||||
|
||||
<INITIAL,SYNOPSYS_TRANSLATE_OFF>"`file_pop"[^\n]*\n {
|
||||
current_filename = fn_stack.back();
|
||||
fn_stack.pop_back();
|
||||
frontend_verilog_yyset_lineno(ln_stack.back());
|
||||
yylloc->first_line = yylloc->last_line = ln_stack.back();
|
||||
real_location.first_line = real_location.last_line = ln_stack.back();
|
||||
yylineno = (ln_stack.back());
|
||||
out_loc.begin.line = out_loc.end.line = ln_stack.back();
|
||||
real_loc.begin.line = real_loc.end.line = ln_stack.back();
|
||||
ln_stack.pop_back();
|
||||
}
|
||||
|
||||
<INITIAL,SYNOPSYS_TRANSLATE_OFF>"`line"[ \t]+[^ \t\r\n]+[ \t]+\"[^ \r\n]+\"[^\r\n]*\n {
|
||||
char *p = yytext + 5;
|
||||
const char *p = YYText() + 5;
|
||||
while (*p == ' ' || *p == '\t') p++;
|
||||
frontend_verilog_yyset_lineno(atoi(p));
|
||||
yylloc->first_line = yylloc->last_line = atoi(p);
|
||||
real_location.first_line = real_location.last_line = atoi(p);
|
||||
yylineno = (atoi(p));
|
||||
out_loc.begin.line = out_loc.end.line = atoi(p);
|
||||
real_loc.begin.line = real_loc.end.line = atoi(p);
|
||||
while (*p && *p != ' ' && *p != '\t') p++;
|
||||
while (*p == ' ' || *p == '\t') p++;
|
||||
char *q = *p ? p + 1 : p;
|
||||
const char *q = *p ? p + 1 : p;
|
||||
while (*q && *q != '"') q++;
|
||||
current_filename = std::string(p).substr(1, q-p-1);
|
||||
}
|
||||
|
||||
"`file_notfound "[^\n]* {
|
||||
log_error("Can't open include file `%s'!\n", yytext + 15);
|
||||
log_error("Can't open include file `%s'!\n", YYText() + 15);
|
||||
}
|
||||
|
||||
"`timescale"[ \t]+[^ \t\r\n/]+[ \t]*"/"[ \t]*[^ \t\r\n]* /* ignore timescale directive */
|
||||
|
@ -183,164 +218,164 @@ TIME_SCALE_SUFFIX [munpf]?s
|
|||
"`endcelldefine"[^\n]* /* ignore `endcelldefine */
|
||||
|
||||
"`default_nettype"[ \t]+[^ \t\r\n/]+ {
|
||||
char *p = yytext;
|
||||
const char *p = YYText();
|
||||
while (*p != 0 && *p != ' ' && *p != '\t') p++;
|
||||
while (*p == ' ' || *p == '\t') p++;
|
||||
if (!strcmp(p, "none"))
|
||||
VERILOG_FRONTEND::default_nettype_wire = false;
|
||||
extra->default_nettype_wire = false;
|
||||
else if (!strcmp(p, "wire"))
|
||||
VERILOG_FRONTEND::default_nettype_wire = true;
|
||||
extra->default_nettype_wire = true;
|
||||
else
|
||||
frontend_verilog_yyerror("Unsupported default nettype: %s", p);
|
||||
err("Unsupported default nettype: %s", p);
|
||||
}
|
||||
|
||||
"`protect"[^\n]* /* ignore `protect*/
|
||||
"`endprotect"[^\n]* /* ignore `endprotect*/
|
||||
|
||||
"`"[a-zA-Z_$][a-zA-Z0-9_$]* {
|
||||
frontend_verilog_yyerror("Unimplemented compiler directive or undefined macro %s.", yytext);
|
||||
err("Unimplemented compiler directive or undefined macro %s.", YYText());
|
||||
}
|
||||
|
||||
"module" { return TOK_MODULE; }
|
||||
"endmodule" { return TOK_ENDMODULE; }
|
||||
"function" { return TOK_FUNCTION; }
|
||||
"endfunction" { return TOK_ENDFUNCTION; }
|
||||
"task" { return TOK_TASK; }
|
||||
"endtask" { return TOK_ENDTASK; }
|
||||
"specify" { return specify_mode ? TOK_SPECIFY : TOK_IGNORED_SPECIFY; }
|
||||
"endspecify" { return TOK_ENDSPECIFY; }
|
||||
"specparam" { return TOK_SPECPARAM; }
|
||||
"package" { SV_KEYWORD(TOK_PACKAGE); }
|
||||
"endpackage" { SV_KEYWORD(TOK_ENDPACKAGE); }
|
||||
"interface" { SV_KEYWORD(TOK_INTERFACE); }
|
||||
"endinterface" { SV_KEYWORD(TOK_ENDINTERFACE); }
|
||||
"modport" { SV_KEYWORD(TOK_MODPORT); }
|
||||
"parameter" { return TOK_PARAMETER; }
|
||||
"localparam" { return TOK_LOCALPARAM; }
|
||||
"defparam" { return TOK_DEFPARAM; }
|
||||
"assign" { return TOK_ASSIGN; }
|
||||
"always" { return TOK_ALWAYS; }
|
||||
"initial" { return TOK_INITIAL; }
|
||||
"begin" { return TOK_BEGIN; }
|
||||
"end" { return TOK_END; }
|
||||
"if" { return TOK_IF; }
|
||||
"else" { return TOK_ELSE; }
|
||||
"for" { return TOK_FOR; }
|
||||
"posedge" { return TOK_POSEDGE; }
|
||||
"negedge" { return TOK_NEGEDGE; }
|
||||
"or" { return TOK_OR; }
|
||||
"case" { return TOK_CASE; }
|
||||
"casex" { return TOK_CASEX; }
|
||||
"casez" { return TOK_CASEZ; }
|
||||
"endcase" { return TOK_ENDCASE; }
|
||||
"default" { return TOK_DEFAULT; }
|
||||
"generate" { return TOK_GENERATE; }
|
||||
"endgenerate" { return TOK_ENDGENERATE; }
|
||||
"while" { return TOK_WHILE; }
|
||||
"repeat" { return TOK_REPEAT; }
|
||||
"automatic" { return TOK_AUTOMATIC; }
|
||||
"module" { return parser::make_TOK_MODULE(out_loc); }
|
||||
"endmodule" { return parser::make_TOK_ENDMODULE(out_loc); }
|
||||
"function" { return parser::make_TOK_FUNCTION(out_loc); }
|
||||
"endfunction" { return parser::make_TOK_ENDFUNCTION(out_loc); }
|
||||
"task" { return parser::make_TOK_TASK(out_loc); }
|
||||
"endtask" { return parser::make_TOK_ENDTASK(out_loc); }
|
||||
"specify" { return mode->specify ? parser::make_TOK_SPECIFY(out_loc) : parser::make_TOK_IGNORED_SPECIFY(out_loc); }
|
||||
"endspecify" { return parser::make_TOK_ENDSPECIFY(out_loc); }
|
||||
"specparam" { return parser::make_TOK_SPECPARAM(out_loc); }
|
||||
"package" { SV_KEYWORD(parser::make_TOK_PACKAGE(out_loc)); }
|
||||
"endpackage" { SV_KEYWORD(parser::make_TOK_ENDPACKAGE(out_loc)); }
|
||||
"interface" { SV_KEYWORD(parser::make_TOK_INTERFACE(out_loc)); }
|
||||
"endinterface" { SV_KEYWORD(parser::make_TOK_ENDINTERFACE(out_loc)); }
|
||||
"modport" { SV_KEYWORD(parser::make_TOK_MODPORT(out_loc)); }
|
||||
"parameter" { return parser::make_TOK_PARAMETER(out_loc); }
|
||||
"localparam" { return parser::make_TOK_LOCALPARAM(out_loc); }
|
||||
"defparam" { return parser::make_TOK_DEFPARAM(out_loc); }
|
||||
"assign" { return parser::make_TOK_ASSIGN(out_loc); }
|
||||
"always" { return parser::make_TOK_ALWAYS(out_loc); }
|
||||
"initial" { return parser::make_TOK_INITIAL(out_loc); }
|
||||
"begin" { return parser::make_TOK_BEGIN(out_loc); }
|
||||
"end" { return parser::make_TOK_END(out_loc); }
|
||||
"if" { return parser::make_TOK_IF(out_loc); }
|
||||
"else" { return parser::make_TOK_ELSE(out_loc); }
|
||||
"for" { return parser::make_TOK_FOR(out_loc); }
|
||||
"posedge" { return parser::make_TOK_POSEDGE(out_loc); }
|
||||
"negedge" { return parser::make_TOK_NEGEDGE(out_loc); }
|
||||
"or" { return parser::make_TOK_OR(out_loc); }
|
||||
"case" { return parser::make_TOK_CASE(out_loc); }
|
||||
"casex" { return parser::make_TOK_CASEX(out_loc); }
|
||||
"casez" { return parser::make_TOK_CASEZ(out_loc); }
|
||||
"endcase" { return parser::make_TOK_ENDCASE(out_loc); }
|
||||
"default" { return parser::make_TOK_DEFAULT(out_loc); }
|
||||
"generate" { return parser::make_TOK_GENERATE(out_loc); }
|
||||
"endgenerate" { return parser::make_TOK_ENDGENERATE(out_loc); }
|
||||
"while" { return parser::make_TOK_WHILE(out_loc); }
|
||||
"repeat" { return parser::make_TOK_REPEAT(out_loc); }
|
||||
"automatic" { return parser::make_TOK_AUTOMATIC(out_loc); }
|
||||
|
||||
"unique" { SV_KEYWORD(TOK_UNIQUE); }
|
||||
"unique0" { SV_KEYWORD(TOK_UNIQUE0); }
|
||||
"priority" { SV_KEYWORD(TOK_PRIORITY); }
|
||||
"unique" { SV_KEYWORD(parser::make_TOK_UNIQUE(out_loc)); }
|
||||
"unique0" { SV_KEYWORD(parser::make_TOK_UNIQUE0(out_loc)); }
|
||||
"priority" { SV_KEYWORD(parser::make_TOK_PRIORITY(out_loc)); }
|
||||
|
||||
"always_comb" { SV_KEYWORD(TOK_ALWAYS_COMB); }
|
||||
"always_ff" { SV_KEYWORD(TOK_ALWAYS_FF); }
|
||||
"always_latch" { SV_KEYWORD(TOK_ALWAYS_LATCH); }
|
||||
"always_comb" { SV_KEYWORD(parser::make_TOK_ALWAYS_COMB(out_loc)); }
|
||||
"always_ff" { SV_KEYWORD(parser::make_TOK_ALWAYS_FF(out_loc)); }
|
||||
"always_latch" { SV_KEYWORD(parser::make_TOK_ALWAYS_LATCH(out_loc)); }
|
||||
|
||||
/* use special token for labels on assert, assume, cover, and restrict because it's insanley complex
|
||||
to fix parsing of cells otherwise. (the current cell parser forces a reduce very early to update some
|
||||
global state.. its a mess) */
|
||||
[a-zA-Z_$][a-zA-Z0-9_$]*/[ \t\r\n]*:[ \t\r\n]*(assert|assume|cover|restrict)[^a-zA-Z0-9_$\.] {
|
||||
if (!strcmp(yytext, "default"))
|
||||
return TOK_DEFAULT;
|
||||
yylval->string = new std::string(std::string("\\") + yytext);
|
||||
return TOK_SVA_LABEL;
|
||||
if (!strcmp(YYText(), "default"))
|
||||
return parser::make_TOK_DEFAULT(out_loc);
|
||||
string_t val = new std::string(std::string("\\") + YYText());
|
||||
return parser::make_TOK_SVA_LABEL(val, out_loc);
|
||||
}
|
||||
|
||||
"assert" { if (formal_mode) return TOK_ASSERT; SV_KEYWORD(TOK_ASSERT); }
|
||||
"assume" { if (formal_mode) return TOK_ASSUME; SV_KEYWORD(TOK_ASSUME); }
|
||||
"cover" { if (formal_mode) return TOK_COVER; SV_KEYWORD(TOK_COVER); }
|
||||
"restrict" { if (formal_mode) return TOK_RESTRICT; SV_KEYWORD(TOK_RESTRICT); }
|
||||
"property" { if (formal_mode) return TOK_PROPERTY; SV_KEYWORD(TOK_PROPERTY); }
|
||||
"rand" { if (formal_mode) return TOK_RAND; SV_KEYWORD(TOK_RAND); }
|
||||
"const" { if (formal_mode) return TOK_CONST; SV_KEYWORD(TOK_CONST); }
|
||||
"checker" { if (formal_mode) return TOK_CHECKER; SV_KEYWORD(TOK_CHECKER); }
|
||||
"endchecker" { if (formal_mode) return TOK_ENDCHECKER; SV_KEYWORD(TOK_ENDCHECKER); }
|
||||
"bind" { if (formal_mode) return TOK_BIND; SV_KEYWORD(TOK_BIND); }
|
||||
"final" { SV_KEYWORD(TOK_FINAL); }
|
||||
"logic" { SV_KEYWORD(TOK_LOGIC); }
|
||||
"var" { SV_KEYWORD(TOK_VAR); }
|
||||
"bit" { SV_KEYWORD(TOK_LOGIC); }
|
||||
"int" { SV_KEYWORD(TOK_INT); }
|
||||
"byte" { SV_KEYWORD(TOK_BYTE); }
|
||||
"shortint" { SV_KEYWORD(TOK_SHORTINT); }
|
||||
"longint" { SV_KEYWORD(TOK_LONGINT); }
|
||||
"void" { SV_KEYWORD(TOK_VOID); }
|
||||
"assert" { if (mode->formal) return parser::make_TOK_ASSERT(out_loc); SV_KEYWORD(parser::make_TOK_ASSERT(out_loc)); }
|
||||
"assume" { if (mode->formal) return parser::make_TOK_ASSUME(out_loc); SV_KEYWORD(parser::make_TOK_ASSUME(out_loc)); }
|
||||
"cover" { if (mode->formal) return parser::make_TOK_COVER(out_loc); SV_KEYWORD(parser::make_TOK_COVER(out_loc)); }
|
||||
"restrict" { if (mode->formal) return parser::make_TOK_RESTRICT(out_loc); SV_KEYWORD(parser::make_TOK_RESTRICT(out_loc)); }
|
||||
"property" { if (mode->formal) return parser::make_TOK_PROPERTY(out_loc); SV_KEYWORD(parser::make_TOK_PROPERTY(out_loc)); }
|
||||
"rand" { if (mode->formal) return parser::make_TOK_RAND(out_loc); SV_KEYWORD(parser::make_TOK_RAND(out_loc)); }
|
||||
"const" { if (mode->formal) return parser::make_TOK_CONST(out_loc); SV_KEYWORD(parser::make_TOK_CONST(out_loc)); }
|
||||
"checker" { if (mode->formal) return parser::make_TOK_CHECKER(out_loc); SV_KEYWORD(parser::make_TOK_CHECKER(out_loc)); }
|
||||
"endchecker" { if (mode->formal) return parser::make_TOK_ENDCHECKER(out_loc); SV_KEYWORD(parser::make_TOK_ENDCHECKER(out_loc)); }
|
||||
"bind" { if (mode->formal) return parser::make_TOK_BIND(out_loc); SV_KEYWORD(parser::make_TOK_BIND(out_loc)); }
|
||||
"final" { SV_KEYWORD(parser::make_TOK_FINAL(out_loc)); }
|
||||
"logic" { SV_KEYWORD(parser::make_TOK_LOGIC(out_loc)); }
|
||||
"var" { SV_KEYWORD(parser::make_TOK_VAR(out_loc)); }
|
||||
"bit" { SV_KEYWORD(parser::make_TOK_LOGIC(out_loc)); }
|
||||
"int" { SV_KEYWORD(parser::make_TOK_INT(out_loc)); }
|
||||
"byte" { SV_KEYWORD(parser::make_TOK_BYTE(out_loc)); }
|
||||
"shortint" { SV_KEYWORD(parser::make_TOK_SHORTINT(out_loc)); }
|
||||
"longint" { SV_KEYWORD(parser::make_TOK_LONGINT(out_loc)); }
|
||||
"void" { SV_KEYWORD(parser::make_TOK_VOID(out_loc)); }
|
||||
|
||||
"eventually" { if (formal_mode) return TOK_EVENTUALLY; SV_KEYWORD(TOK_EVENTUALLY); }
|
||||
"s_eventually" { if (formal_mode) return TOK_EVENTUALLY; SV_KEYWORD(TOK_EVENTUALLY); }
|
||||
"eventually" { if (mode->formal) return parser::make_TOK_EVENTUALLY(out_loc); SV_KEYWORD(parser::make_TOK_EVENTUALLY(out_loc)); }
|
||||
"s_eventually" { if (mode->formal) return parser::make_TOK_EVENTUALLY(out_loc); SV_KEYWORD(parser::make_TOK_EVENTUALLY(out_loc)); }
|
||||
|
||||
"input" { return TOK_INPUT; }
|
||||
"output" { return TOK_OUTPUT; }
|
||||
"inout" { return TOK_INOUT; }
|
||||
"wire" { return TOK_WIRE; }
|
||||
"tri" { return TOK_WIRE; }
|
||||
"wor" { return TOK_WOR; }
|
||||
"trior" { return TOK_WOR; }
|
||||
"wand" { return TOK_WAND; }
|
||||
"triand" { return TOK_WAND; }
|
||||
"reg" { return TOK_REG; }
|
||||
"integer" { return TOK_INTEGER; }
|
||||
"signed" { return TOK_SIGNED; }
|
||||
"unsigned" { SV_KEYWORD(TOK_UNSIGNED); }
|
||||
"genvar" { return TOK_GENVAR; }
|
||||
"real" { return TOK_REAL; }
|
||||
"input" { return parser::make_TOK_INPUT(out_loc); }
|
||||
"output" { return parser::make_TOK_OUTPUT(out_loc); }
|
||||
"inout" { return parser::make_TOK_INOUT(out_loc); }
|
||||
"wire" { return parser::make_TOK_WIRE(out_loc); }
|
||||
"tri" { return parser::make_TOK_WIRE(out_loc); }
|
||||
"wor" { return parser::make_TOK_WOR(out_loc); }
|
||||
"trior" { return parser::make_TOK_WOR(out_loc); }
|
||||
"wand" { return parser::make_TOK_WAND(out_loc); }
|
||||
"triand" { return parser::make_TOK_WAND(out_loc); }
|
||||
"reg" { return parser::make_TOK_REG(out_loc); }
|
||||
"integer" { return parser::make_TOK_INTEGER(out_loc); }
|
||||
"signed" { return parser::make_TOK_SIGNED(out_loc); }
|
||||
"unsigned" { SV_KEYWORD(parser::make_TOK_UNSIGNED(out_loc)); }
|
||||
"genvar" { return parser::make_TOK_GENVAR(out_loc); }
|
||||
"real" { return parser::make_TOK_REAL(out_loc); }
|
||||
|
||||
"enum" { SV_KEYWORD(TOK_ENUM); }
|
||||
"typedef" { SV_KEYWORD(TOK_TYPEDEF); }
|
||||
"struct" { SV_KEYWORD(TOK_STRUCT); }
|
||||
"union" { SV_KEYWORD(TOK_UNION); }
|
||||
"packed" { SV_KEYWORD(TOK_PACKED); }
|
||||
"enum" { SV_KEYWORD(parser::make_TOK_ENUM(out_loc)); }
|
||||
"typedef" { SV_KEYWORD(parser::make_TOK_TYPEDEF(out_loc)); }
|
||||
"struct" { SV_KEYWORD(parser::make_TOK_STRUCT(out_loc)); }
|
||||
"union" { SV_KEYWORD(parser::make_TOK_UNION(out_loc)); }
|
||||
"packed" { SV_KEYWORD(parser::make_TOK_PACKED(out_loc)); }
|
||||
|
||||
{UNSIGNED_NUMBER} {
|
||||
yylval->string = new std::string(yytext);
|
||||
return TOK_CONSTVAL;
|
||||
string_t val = new std::string(YYText());
|
||||
return parser::make_TOK_CONSTVAL(val, out_loc);
|
||||
}
|
||||
|
||||
\'[01zxZX] {
|
||||
yylval->string = new std::string(yytext);
|
||||
return TOK_UNBASED_UNSIZED_CONSTVAL;
|
||||
string_t val = new std::string(YYText());
|
||||
return parser::make_TOK_UNBASED_UNSIZED_CONSTVAL(val, out_loc);
|
||||
}
|
||||
|
||||
\'[sS]?[bodhBODH] {
|
||||
BEGIN(BASED_CONST);
|
||||
yylval->string = new std::string(yytext);
|
||||
return TOK_BASE;
|
||||
string_t val = new std::string(YYText());
|
||||
return parser::make_TOK_BASE(val, out_loc);
|
||||
}
|
||||
|
||||
<BASED_CONST>[0-9a-fA-FzxZX?][0-9a-fA-FzxZX?_]* {
|
||||
BEGIN(0);
|
||||
yylval->string = new std::string(yytext);
|
||||
return TOK_BASED_CONSTVAL;
|
||||
string_t val = new std::string(YYText());
|
||||
return parser::make_TOK_BASED_CONSTVAL(val, out_loc);
|
||||
}
|
||||
|
||||
{FIXED_POINT_NUMBER_DEC} {
|
||||
yylval->string = new std::string(yytext);
|
||||
return TOK_REALVAL;
|
||||
string_t val = new std::string(YYText());
|
||||
return parser::make_TOK_REALVAL(val, out_loc);
|
||||
}
|
||||
|
||||
{FIXED_POINT_NUMBER_NO_DEC} {
|
||||
yylval->string = new std::string(yytext);
|
||||
return TOK_REALVAL;
|
||||
string_t val = new std::string(YYText());
|
||||
return parser::make_TOK_REALVAL(val, out_loc);
|
||||
}
|
||||
|
||||
\" { BEGIN(STRING); }
|
||||
<STRING>([^\"]|\\.)+ { yymore(); real_location = old_location; }
|
||||
<STRING>([^\"]|\\.)+ { yymore(); }
|
||||
<STRING>\" {
|
||||
BEGIN(0);
|
||||
char *yystr = strdup(yytext);
|
||||
yystr[strlen(yytext) - 1] = 0;
|
||||
char *yystr = strdup(YYText());
|
||||
yystr[strlen(YYText()) - 1] = 0;
|
||||
int i = 0, j = 0;
|
||||
while (yystr[i]) {
|
||||
if (yystr[i] == '\\' && yystr[i + 1]) {
|
||||
|
@ -372,71 +407,71 @@ TIME_SCALE_SUFFIX [munpf]?s
|
|||
yystr[j++] = yystr[i++];
|
||||
}
|
||||
yystr[j] = 0;
|
||||
yylval->string = new std::string(yystr, j);
|
||||
string_t val = new std::string(yystr, j);
|
||||
free(yystr);
|
||||
return TOK_STRING;
|
||||
return parser::make_TOK_STRING(val, out_loc);
|
||||
}
|
||||
|
||||
and|nand|or|nor|xor|xnor|not|buf|bufif0|bufif1|notif0|notif1 {
|
||||
yylval->string = new std::string(yytext);
|
||||
return TOK_PRIMITIVE;
|
||||
auto val = new std::string(YYText());
|
||||
return parser::make_TOK_PRIMITIVE(val, out_loc);
|
||||
}
|
||||
|
||||
supply0 { return TOK_SUPPLY0; }
|
||||
supply1 { return TOK_SUPPLY1; }
|
||||
supply0 { return parser::make_TOK_SUPPLY0(out_loc); }
|
||||
supply1 { return parser::make_TOK_SUPPLY1(out_loc); }
|
||||
|
||||
"$"(display[bho]?|write[bho]?|strobe|monitor|time|realtime|stop|finish|dumpfile|dumpvars|dumpon|dumpoff|dumpall) {
|
||||
yylval->string = new std::string(yytext);
|
||||
return TOK_ID;
|
||||
auto val = new std::string(YYText());
|
||||
return parser::make_TOK_ID(val, out_loc);
|
||||
}
|
||||
|
||||
"$"(setup|hold|setuphold|removal|recovery|recrem|skew|timeskew|fullskew|nochange) {
|
||||
if (!specify_mode) REJECT;
|
||||
yylval->string = new std::string(yytext);
|
||||
return TOK_ID;
|
||||
if (!mode->specify) REJECT;
|
||||
auto val = new std::string(YYText());
|
||||
return parser::make_TOK_ID(val, out_loc);
|
||||
}
|
||||
|
||||
"$"(info|warning|error|fatal) {
|
||||
yylval->string = new std::string(yytext);
|
||||
return TOK_MSG_TASKS;
|
||||
auto val = new std::string(YYText());
|
||||
return parser::make_TOK_MSG_TASKS(val, out_loc);
|
||||
}
|
||||
|
||||
"$signed" { return TOK_TO_SIGNED; }
|
||||
"$unsigned" { return TOK_TO_UNSIGNED; }
|
||||
"$signed" { return parser::make_TOK_TO_SIGNED(out_loc); }
|
||||
"$unsigned" { return parser::make_TOK_TO_UNSIGNED(out_loc); }
|
||||
|
||||
[a-zA-Z_][a-zA-Z0-9_]*::[a-zA-Z_$][a-zA-Z0-9_$]* {
|
||||
// package qualifier
|
||||
auto s = std::string("\\") + yytext;
|
||||
if (pkg_user_types.count(s) > 0) {
|
||||
auto s = std::string("\\") + YYText();
|
||||
if (extra->pkg_user_types.count(s) > 0) {
|
||||
// package qualified typedefed name
|
||||
yylval->string = new std::string(s);
|
||||
return TOK_PKG_USER_TYPE;
|
||||
auto val = new std::string(s);
|
||||
return parser::make_TOK_PKG_USER_TYPE(val, out_loc);
|
||||
}
|
||||
else {
|
||||
// backup before :: just return first part
|
||||
size_t len = strchr(yytext, ':') - yytext;
|
||||
size_t len = strchr(YYText(), ':') - YYText();
|
||||
yyless(len);
|
||||
yylval->string = new std::string(std::string("\\") + yytext);
|
||||
return TOK_ID;
|
||||
auto val = new std::string(std::string("\\") + YYText());
|
||||
return parser::make_TOK_ID(val, out_loc);
|
||||
}
|
||||
}
|
||||
|
||||
[a-zA-Z_$][a-zA-Z0-9_$]* {
|
||||
auto s = std::string("\\") + yytext;
|
||||
if (isUserType(s)) {
|
||||
auto s = std::string("\\") + YYText();
|
||||
if (isUserType(extra, s)) {
|
||||
// previously typedefed name
|
||||
yylval->string = new std::string(s);
|
||||
return TOK_USER_TYPE;
|
||||
auto val = new std::string(s);
|
||||
return parser::make_TOK_USER_TYPE(val, out_loc);
|
||||
}
|
||||
else {
|
||||
yylval->string = new std::string(std::string("\\") + yytext);
|
||||
return TOK_ID;
|
||||
auto val = new std::string(std::string("\\") + YYText());
|
||||
return parser::make_TOK_ID(val, out_loc);
|
||||
}
|
||||
}
|
||||
|
||||
[a-zA-Z_$][a-zA-Z0-9_$\.]* {
|
||||
yylval->string = new std::string(std::string("\\") + yytext);
|
||||
return TOK_ID;
|
||||
auto val = new std::string(std::string("\\") + YYText());
|
||||
return parser::make_TOK_ID(val, out_loc);
|
||||
}
|
||||
|
||||
"/*"[ \t]*(synopsys|synthesis)[ \t]*translate_off[ \t]*"*/" {
|
||||
|
@ -472,7 +507,7 @@ supply1 { return TOK_SUPPLY1; }
|
|||
);
|
||||
printed_warning = true;
|
||||
}
|
||||
return TOK_SYNOPSYS_FULL_CASE;
|
||||
return parser::make_TOK_SYNOPSYS_FULL_CASE(out_loc);
|
||||
}
|
||||
<SYNOPSYS_FLAGS>parallel_case {
|
||||
static bool printed_warning = false;
|
||||
|
@ -486,119 +521,115 @@ supply1 { return TOK_SUPPLY1; }
|
|||
);
|
||||
printed_warning = true;
|
||||
}
|
||||
return TOK_SYNOPSYS_PARALLEL_CASE;
|
||||
return parser::make_TOK_SYNOPSYS_PARALLEL_CASE(out_loc);
|
||||
}
|
||||
<SYNOPSYS_FLAGS>. /* ignore everything else */
|
||||
<SYNOPSYS_FLAGS>"*/" { BEGIN(0); }
|
||||
|
||||
import[ \t\r\n]+\"(DPI|DPI-C)\"[ \t\r\n]+function[ \t\r\n]+ {
|
||||
BEGIN(IMPORT_DPI);
|
||||
return TOK_DPI_FUNCTION;
|
||||
return parser::make_TOK_DPI_FUNCTION(out_loc);
|
||||
}
|
||||
|
||||
<IMPORT_DPI>[a-zA-Z_$][a-zA-Z0-9_$]* {
|
||||
yylval->string = new std::string(std::string("\\") + yytext);
|
||||
return TOK_ID;
|
||||
auto val = new std::string(std::string("\\") + YYText());
|
||||
return parser::make_TOK_ID(val, out_loc);
|
||||
}
|
||||
|
||||
<IMPORT_DPI>[ \t\r\n] /* ignore whitespaces */
|
||||
|
||||
<IMPORT_DPI>";" {
|
||||
BEGIN(0);
|
||||
return *yytext;
|
||||
return char_tok(*YYText(), out_loc);
|
||||
}
|
||||
|
||||
<IMPORT_DPI>. {
|
||||
return *yytext;
|
||||
return char_tok(*YYText(), out_loc);
|
||||
}
|
||||
|
||||
"\\"[^ \t\r\n]+ {
|
||||
yylval->string = new std::string(yytext);
|
||||
return TOK_ID;
|
||||
auto val = new std::string(YYText());
|
||||
return parser::make_TOK_ID(val, out_loc);
|
||||
}
|
||||
|
||||
"(*" { return ATTR_BEGIN; }
|
||||
"*)" { return ATTR_END; }
|
||||
"(*" { return parser::make_ATTR_BEGIN(out_loc); }
|
||||
"*)" { return parser::make_ATTR_END(out_loc); }
|
||||
|
||||
"{*" { return DEFATTR_BEGIN; }
|
||||
"*}" { return DEFATTR_END; }
|
||||
"{*" { return parser::make_DEFATTR_BEGIN(out_loc); }
|
||||
"*}" { return parser::make_DEFATTR_END(out_loc); }
|
||||
|
||||
"**" { return OP_POW; }
|
||||
"||" { return OP_LOR; }
|
||||
"&&" { return OP_LAND; }
|
||||
"==" { return OP_EQ; }
|
||||
"!=" { return OP_NE; }
|
||||
"<=" { return OP_LE; }
|
||||
">=" { return OP_GE; }
|
||||
"**" { return parser::make_OP_POW(out_loc); }
|
||||
"||" { return parser::make_OP_LOR(out_loc); }
|
||||
"&&" { return parser::make_OP_LAND(out_loc); }
|
||||
"==" { return parser::make_OP_EQ(out_loc); }
|
||||
"!=" { return parser::make_OP_NE(out_loc); }
|
||||
"<=" { return parser::make_OP_LE(out_loc); }
|
||||
">=" { return parser::make_OP_GE(out_loc); }
|
||||
|
||||
"===" { return OP_EQX; }
|
||||
"!==" { return OP_NEX; }
|
||||
"===" { return parser::make_OP_EQX(out_loc); }
|
||||
"!==" { return parser::make_OP_NEX(out_loc); }
|
||||
|
||||
"~&" { return OP_NAND; }
|
||||
"~|" { return OP_NOR; }
|
||||
"~^" { return OP_XNOR; }
|
||||
"^~" { return OP_XNOR; }
|
||||
"~&" { return parser::make_OP_NAND(out_loc); }
|
||||
"~|" { return parser::make_OP_NOR(out_loc); }
|
||||
"~^" { return parser::make_OP_XNOR(out_loc); }
|
||||
"^~" { return parser::make_OP_XNOR(out_loc); }
|
||||
|
||||
"<<" { return OP_SHL; }
|
||||
">>" { return OP_SHR; }
|
||||
"<<<" { return OP_SSHL; }
|
||||
">>>" { return OP_SSHR; }
|
||||
"<<" { return parser::make_OP_SHL(out_loc); }
|
||||
">>" { return parser::make_OP_SHR(out_loc); }
|
||||
"<<<" { return parser::make_OP_SSHL(out_loc); }
|
||||
">>>" { return parser::make_OP_SSHR(out_loc); }
|
||||
|
||||
"'" { return OP_CAST; }
|
||||
"'" { return parser::make_OP_CAST(out_loc); }
|
||||
|
||||
"::" { return TOK_PACKAGESEP; }
|
||||
"++" { return TOK_INCREMENT; }
|
||||
"--" { return TOK_DECREMENT; }
|
||||
"::" { return parser::make_TOK_PACKAGESEP(out_loc); }
|
||||
"++" { return parser::make_TOK_INCREMENT(out_loc); }
|
||||
"--" { return parser::make_TOK_DECREMENT(out_loc); }
|
||||
|
||||
"+:" { return TOK_POS_INDEXED; }
|
||||
"-:" { return TOK_NEG_INDEXED; }
|
||||
"+:" { return parser::make_TOK_POS_INDEXED(out_loc); }
|
||||
"-:" { return parser::make_TOK_NEG_INDEXED(out_loc); }
|
||||
|
||||
".*" { return TOK_WILDCARD_CONNECT; }
|
||||
".*" { return parser::make_TOK_WILDCARD_CONNECT(out_loc); }
|
||||
|
||||
"|=" { SV_KEYWORD(TOK_BIT_OR_ASSIGN); }
|
||||
"&=" { SV_KEYWORD(TOK_BIT_AND_ASSIGN); }
|
||||
"+=" { SV_KEYWORD(TOK_ADD_ASSIGN); }
|
||||
"-=" { SV_KEYWORD(TOK_SUB_ASSIGN); }
|
||||
"^=" { SV_KEYWORD(TOK_BIT_XOR_ASSIGN); }
|
||||
"/=" { SV_KEYWORD(TOK_DIV_ASSIGN); }
|
||||
"%=" { SV_KEYWORD(TOK_MOD_ASSIGN); }
|
||||
"*=" { SV_KEYWORD(TOK_MUL_ASSIGN); }
|
||||
"<<=" { SV_KEYWORD(TOK_SHL_ASSIGN); }
|
||||
">>=" { SV_KEYWORD(TOK_SHR_ASSIGN); }
|
||||
"<<<=" { SV_KEYWORD(TOK_SSHL_ASSIGN); }
|
||||
">>>=" { SV_KEYWORD(TOK_SSHR_ASSIGN); }
|
||||
"|=" { SV_KEYWORD(parser::make_TOK_BIT_OR_ASSIGN(out_loc)); }
|
||||
"&=" { SV_KEYWORD(parser::make_TOK_BIT_AND_ASSIGN(out_loc)); }
|
||||
"+=" { SV_KEYWORD(parser::make_TOK_ADD_ASSIGN(out_loc)); }
|
||||
"-=" { SV_KEYWORD(parser::make_TOK_SUB_ASSIGN(out_loc)); }
|
||||
"^=" { SV_KEYWORD(parser::make_TOK_BIT_XOR_ASSIGN(out_loc)); }
|
||||
"/=" { SV_KEYWORD(parser::make_TOK_DIV_ASSIGN(out_loc)); }
|
||||
"%=" { SV_KEYWORD(parser::make_TOK_MOD_ASSIGN(out_loc)); }
|
||||
"*=" { SV_KEYWORD(parser::make_TOK_MUL_ASSIGN(out_loc)); }
|
||||
"<<=" { SV_KEYWORD(parser::make_TOK_SHL_ASSIGN(out_loc)); }
|
||||
">>=" { SV_KEYWORD(parser::make_TOK_SHR_ASSIGN(out_loc)); }
|
||||
"<<<=" { SV_KEYWORD(parser::make_TOK_SSHL_ASSIGN(out_loc)); }
|
||||
">>>=" { SV_KEYWORD(parser::make_TOK_SSHR_ASSIGN(out_loc)); }
|
||||
|
||||
[-+]?[=*]> {
|
||||
if (!specify_mode) REJECT;
|
||||
yylval->string = new std::string(yytext);
|
||||
return TOK_SPECIFY_OPER;
|
||||
if (!mode->specify) REJECT;
|
||||
auto val = new std::string(YYText());
|
||||
return parser::make_TOK_SPECIFY_OPER(val, out_loc);
|
||||
}
|
||||
|
||||
"&&&" {
|
||||
if (!specify_mode) return TOK_IGNORED_SPECIFY_AND;
|
||||
return TOK_SPECIFY_AND;
|
||||
if (!mode->specify) return parser::make_TOK_IGNORED_SPECIFY_AND(out_loc);
|
||||
return parser::make_TOK_SPECIFY_AND(out_loc);
|
||||
}
|
||||
|
||||
{UNSIGNED_NUMBER}{TIME_SCALE_SUFFIX} { return TOK_TIME_SCALE; }
|
||||
{FIXED_POINT_NUMBER_DEC}{TIME_SCALE_SUFFIX} { return TOK_TIME_SCALE; }
|
||||
{FIXED_POINT_NUMBER_NO_DEC}{TIME_SCALE_SUFFIX} { return TOK_TIME_SCALE; }
|
||||
{UNSIGNED_NUMBER}{TIME_SCALE_SUFFIX} { return parser::make_TOK_TIME_SCALE(out_loc); }
|
||||
{FIXED_POINT_NUMBER_DEC}{TIME_SCALE_SUFFIX} { return parser::make_TOK_TIME_SCALE(out_loc); }
|
||||
{FIXED_POINT_NUMBER_NO_DEC}{TIME_SCALE_SUFFIX} { return parser::make_TOK_TIME_SCALE(out_loc); }
|
||||
|
||||
<INITIAL,BASED_CONST>"/*" { comment_caller=YY_START; BEGIN(COMMENT); }
|
||||
<COMMENT>. /* ignore comment body */
|
||||
<COMMENT>\n /* ignore comment body */
|
||||
<COMMENT>"*/" { BEGIN(comment_caller); }
|
||||
|
||||
|
||||
<INITIAL,BASED_CONST>[ \t\r\n] /* ignore whitespaces */
|
||||
<INITIAL,BASED_CONST>\\[\r\n] /* ignore continuation sequence */
|
||||
<INITIAL,BASED_CONST>"//"[^\r\n]* /* ignore one-line comments */
|
||||
|
||||
<INITIAL>. { return *yytext; }
|
||||
<*>. { BEGIN(0); return *yytext; }
|
||||
<INITIAL>. { return char_tok(*YYText(), out_loc); }
|
||||
<*>. { BEGIN(0); return char_tok(*YYText(), out_loc); }
|
||||
|
||||
%%
|
||||
|
||||
// this is a hack to avoid the 'yyinput defined but not used' error msgs
|
||||
void *frontend_verilog_avoid_input_warnings() {
|
||||
return (void*)&yyinput;
|
||||
}
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue