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.
|
|
|
|
*
|
|
|
|
* ---
|
|
|
|
*
|
|
|
|
* A simple lexer for Verilog code. Non-preprocessor compiler directives are
|
|
|
|
* handled here. The preprocessor stuff is handled in preproc.cc. Everything
|
|
|
|
* else is left to the bison parser (see parser.y).
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
%{
|
|
|
|
|
2014-04-20 07:28:23 -05:00
|
|
|
#ifdef __clang__
|
|
|
|
// bison generates code using the 'register' storage class specifier
|
|
|
|
#pragma clang diagnostic ignored "-Wdeprecated-register"
|
|
|
|
#endif
|
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
#include "kernel/log.h"
|
2015-08-12 08:04:44 -05:00
|
|
|
#include "frontends/verilog/verilog_frontend.h"
|
2013-01-05 04:13:26 -06:00
|
|
|
#include "frontends/ast/ast.h"
|
2018-08-27 07:22:21 -05:00
|
|
|
#include "verilog_parser.tab.hh"
|
2013-01-05 04:13:26 -06:00
|
|
|
|
2014-07-31 06:19:47 -05:00
|
|
|
USING_YOSYS_NAMESPACE
|
2013-01-05 04:13:26 -06:00
|
|
|
using namespace AST;
|
|
|
|
using namespace VERILOG_FRONTEND;
|
|
|
|
|
2014-07-31 06:19:47 -05:00
|
|
|
YOSYS_NAMESPACE_BEGIN
|
2013-01-05 04:13:26 -06:00
|
|
|
namespace VERILOG_FRONTEND {
|
|
|
|
std::vector<std::string> fn_stack;
|
|
|
|
std::vector<int> ln_stack;
|
|
|
|
}
|
2014-07-31 06:19:47 -05:00
|
|
|
YOSYS_NAMESPACE_END
|
2013-01-05 04:13:26 -06:00
|
|
|
|
2014-06-12 04:54:20 -05:00
|
|
|
#define SV_KEYWORD(_tok) \
|
|
|
|
if (sv_mode) 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()); \
|
|
|
|
frontend_verilog_yylval.string = new std::string(std::string("\\") + yytext); \
|
|
|
|
return TOK_ID;
|
|
|
|
|
2016-07-21 06:34:33 -05:00
|
|
|
#define NON_KEYWORD() \
|
|
|
|
frontend_verilog_yylval.string = new std::string(std::string("\\") + yytext); \
|
|
|
|
return TOK_ID;
|
|
|
|
|
2014-08-23 08:03:55 -05:00
|
|
|
#define YY_INPUT(buf,result,max_size) \
|
2014-10-23 03:47:21 -05:00
|
|
|
result = readsome(*VERILOG_FRONTEND::lexin, buf, max_size)
|
2014-08-23 08:03:55 -05:00
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
%}
|
|
|
|
|
|
|
|
%option yylineno
|
|
|
|
%option noyywrap
|
|
|
|
%option nounput
|
|
|
|
%option prefix="frontend_verilog_yy"
|
|
|
|
|
|
|
|
%x COMMENT
|
|
|
|
%x STRING
|
|
|
|
%x SYNOPSYS_TRANSLATE_OFF
|
|
|
|
%x SYNOPSYS_FLAGS
|
2014-08-21 05:43:51 -05:00
|
|
|
%x IMPORT_DPI
|
2013-01-05 04:13:26 -06:00
|
|
|
|
|
|
|
%%
|
|
|
|
|
2014-07-30 13:18:48 -05:00
|
|
|
<INITIAL,SYNOPSYS_TRANSLATE_OFF>"`file_push "[^\n]* {
|
2013-01-05 04:13:26 -06:00
|
|
|
fn_stack.push_back(current_filename);
|
|
|
|
ln_stack.push_back(frontend_verilog_yyget_lineno());
|
|
|
|
current_filename = yytext+11;
|
2015-02-14 01:41:03 -06:00
|
|
|
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);
|
2013-01-05 04:13:26 -06:00
|
|
|
frontend_verilog_yyset_lineno(0);
|
|
|
|
}
|
|
|
|
|
2014-07-30 13:18:48 -05:00
|
|
|
<INITIAL,SYNOPSYS_TRANSLATE_OFF>"`file_pop"[^\n]*\n {
|
2013-01-05 04:13:26 -06:00
|
|
|
current_filename = fn_stack.back();
|
2013-08-21 02:20:59 -05:00
|
|
|
fn_stack.pop_back();
|
2013-01-05 04:13:26 -06:00
|
|
|
frontend_verilog_yyset_lineno(ln_stack.back());
|
2013-08-21 02:20:59 -05:00
|
|
|
ln_stack.pop_back();
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
|
|
|
|
2014-07-30 13:18:48 -05:00
|
|
|
<INITIAL,SYNOPSYS_TRANSLATE_OFF>"`line"[ \t]+[^ \t\r\n]+[ \t]+\"[^ \r\n]+\"[^\r\n]*\n {
|
2014-03-11 08:06:57 -05:00
|
|
|
char *p = yytext + 5;
|
|
|
|
while (*p == ' ' || *p == '\t') p++;
|
|
|
|
frontend_verilog_yyset_lineno(atoi(p));
|
|
|
|
while (*p && *p != ' ' && *p != '\t') p++;
|
|
|
|
while (*p == ' ' || *p == '\t') p++;
|
|
|
|
char *q = *p ? p + 1 : p;
|
|
|
|
while (*q && *q != '"') q++;
|
|
|
|
current_filename = std::string(p).substr(1, q-p-1);
|
|
|
|
}
|
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
"`file_notfound "[^\n]* {
|
|
|
|
log_error("Can't open include file `%s'!\n", yytext + 15);
|
|
|
|
}
|
|
|
|
|
|
|
|
"`timescale"[ \t]+[^ \t\r\n/]+[ \t]*"/"[ \t]*[^ \t\r\n]* /* ignore timescale directive */
|
|
|
|
|
2015-03-25 13:46:12 -05:00
|
|
|
"`celldefine"[^\n]* /* ignore `celldefine */
|
|
|
|
"`endcelldefine"[^\n]* /* ignore `endcelldefine */
|
|
|
|
|
2014-02-17 07:28:52 -06:00
|
|
|
"`default_nettype"[ \t]+[^ \t\r\n/]+ {
|
|
|
|
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;
|
|
|
|
else if (!strcmp(p, "wire"))
|
|
|
|
VERILOG_FRONTEND::default_nettype_wire = true;
|
|
|
|
else
|
|
|
|
frontend_verilog_yyerror("Unsupported default nettype: %s", p);
|
|
|
|
}
|
|
|
|
|
2018-10-16 08:33:37 -05:00
|
|
|
"`protect"[^\n]* /* ignore `protect*/
|
|
|
|
"`endprotect"[^\n]* /* ignore `endprotect*/
|
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
"`"[a-zA-Z_$][a-zA-Z0-9_$]* {
|
|
|
|
frontend_verilog_yyerror("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; }
|
2019-04-21 14:58:57 -05:00
|
|
|
"specify" { return specify_mode ? TOK_SPECIFY : TOK_IGNORED_SPECIFY; }
|
2018-03-04 15:35:08 -06:00
|
|
|
"endspecify" { return TOK_ENDSPECIFY; }
|
|
|
|
"specparam" { return TOK_SPECPARAM; }
|
2016-06-18 03:24:21 -05:00
|
|
|
"package" { SV_KEYWORD(TOK_PACKAGE); }
|
|
|
|
"endpackage" { SV_KEYWORD(TOK_ENDPACKAGE); }
|
2018-10-11 16:33:31 -05:00
|
|
|
"interface" { SV_KEYWORD(TOK_INTERFACE); }
|
|
|
|
"endinterface" { SV_KEYWORD(TOK_ENDINTERFACE); }
|
|
|
|
"modport" { SV_KEYWORD(TOK_MODPORT); }
|
2013-01-05 04:13:26 -06:00
|
|
|
"parameter" { return TOK_PARAMETER; }
|
|
|
|
"localparam" { return TOK_LOCALPARAM; }
|
2013-07-04 07:12:33 -05:00
|
|
|
"defparam" { return TOK_DEFPARAM; }
|
2013-01-05 04:13:26 -06:00
|
|
|
"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; }
|
2014-06-06 10:40:04 -05:00
|
|
|
"while" { return TOK_WHILE; }
|
|
|
|
"repeat" { return TOK_REPEAT; }
|
2017-11-23 01:48:17 -06:00
|
|
|
"automatic" { return TOK_AUTOMATIC; }
|
2013-01-05 04:13:26 -06:00
|
|
|
|
2017-02-23 09:33:19 -06:00
|
|
|
"unique" { SV_KEYWORD(TOK_UNIQUE); }
|
|
|
|
"unique0" { SV_KEYWORD(TOK_UNIQUE); }
|
|
|
|
"priority" { SV_KEYWORD(TOK_PRIORITY); }
|
|
|
|
|
2014-06-12 04:54:20 -05:00
|
|
|
"always_comb" { SV_KEYWORD(TOK_ALWAYS); }
|
|
|
|
"always_ff" { SV_KEYWORD(TOK_ALWAYS); }
|
|
|
|
"always_latch" { SV_KEYWORD(TOK_ALWAYS); }
|
|
|
|
|
2019-03-10 18:27:18 -05:00
|
|
|
/* 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_$\.] {
|
|
|
|
frontend_verilog_yylval.string = new std::string(std::string("\\") + yytext);
|
|
|
|
return TOK_SVA_LABEL;
|
2019-03-09 00:53:58 -06:00
|
|
|
}
|
|
|
|
|
2019-03-10 18:27:18 -05:00
|
|
|
"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); }
|
2017-02-09 06:51:44 -06:00
|
|
|
"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); }
|
2019-05-04 02:25:32 -05:00
|
|
|
"final" { SV_KEYWORD(TOK_FINAL); }
|
2018-03-09 02:35:33 -06:00
|
|
|
"logic" { SV_KEYWORD(TOK_LOGIC); }
|
2019-05-04 00:52:51 -05:00
|
|
|
"var" { SV_KEYWORD(TOK_VAR); }
|
2017-02-09 06:51:44 -06:00
|
|
|
"bit" { SV_KEYWORD(TOK_REG); }
|
2014-01-18 21:18:22 -06:00
|
|
|
|
2017-02-25 03:36:39 -06:00
|
|
|
"eventually" { if (formal_mode) return TOK_EVENTUALLY; SV_KEYWORD(TOK_EVENTUALLY); }
|
|
|
|
"s_eventually" { if (formal_mode) return TOK_EVENTUALLY; SV_KEYWORD(TOK_EVENTUALLY); }
|
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
"input" { return TOK_INPUT; }
|
|
|
|
"output" { return TOK_OUTPUT; }
|
|
|
|
"inout" { return TOK_INOUT; }
|
|
|
|
"wire" { return TOK_WIRE; }
|
2019-05-22 07:22:42 -05:00
|
|
|
"wor" { return TOK_WOR; }
|
|
|
|
"wand" { return TOK_WAND; }
|
2013-01-05 04:13:26 -06:00
|
|
|
"reg" { return TOK_REG; }
|
|
|
|
"integer" { return TOK_INTEGER; }
|
|
|
|
"signed" { return TOK_SIGNED; }
|
|
|
|
"genvar" { return TOK_GENVAR; }
|
2014-06-14 05:00:47 -05:00
|
|
|
"real" { return TOK_REAL; }
|
2013-01-05 04:13:26 -06:00
|
|
|
|
2017-01-17 10:33:52 -06:00
|
|
|
"enum" { SV_KEYWORD(TOK_ENUM); }
|
|
|
|
"typedef" { SV_KEYWORD(TOK_TYPEDEF); }
|
|
|
|
|
2014-11-24 07:39:24 -06:00
|
|
|
[0-9][0-9_]* {
|
2013-01-05 04:13:26 -06:00
|
|
|
frontend_verilog_yylval.string = new std::string(yytext);
|
2017-02-08 07:38:15 -06:00
|
|
|
return TOK_CONSTVAL;
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
|
|
|
|
2019-05-27 04:42:10 -05:00
|
|
|
[0-9]*[ \t]*\'s?[bodhBODH]*[ \t\r\n]*[0-9a-fA-FzxZX?_]+ {
|
2013-01-05 04:13:26 -06:00
|
|
|
frontend_verilog_yylval.string = new std::string(yytext);
|
2017-02-08 07:38:15 -06:00
|
|
|
return TOK_CONSTVAL;
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
|
|
|
|
2014-06-13 04:29:23 -05:00
|
|
|
[0-9][0-9_]*\.[0-9][0-9_]*([eE][-+]?[0-9_]+)? {
|
|
|
|
frontend_verilog_yylval.string = new std::string(yytext);
|
2014-06-14 05:00:47 -05:00
|
|
|
return TOK_REALVAL;
|
2014-06-13 04:29:23 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
[0-9][0-9_]*[eE][-+]?[0-9_]+ {
|
|
|
|
frontend_verilog_yylval.string = new std::string(yytext);
|
2014-06-14 05:00:47 -05:00
|
|
|
return TOK_REALVAL;
|
2014-06-13 04:29:23 -05:00
|
|
|
}
|
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
\" { BEGIN(STRING); }
|
|
|
|
<STRING>\\. { yymore(); }
|
|
|
|
<STRING>\" {
|
|
|
|
BEGIN(0);
|
|
|
|
char *yystr = strdup(yytext);
|
|
|
|
yystr[strlen(yytext) - 1] = 0;
|
|
|
|
int i = 0, j = 0;
|
|
|
|
while (yystr[i]) {
|
|
|
|
if (yystr[i] == '\\' && yystr[i + 1]) {
|
|
|
|
i++;
|
2018-05-03 05:35:01 -05:00
|
|
|
if (yystr[i] == 'a')
|
|
|
|
yystr[i] = '\a';
|
|
|
|
else if (yystr[i] == 'f')
|
|
|
|
yystr[i] = '\f';
|
|
|
|
else if (yystr[i] == 'n')
|
2013-01-05 04:13:26 -06:00
|
|
|
yystr[i] = '\n';
|
2018-05-03 05:35:01 -05:00
|
|
|
else if (yystr[i] == 'r')
|
|
|
|
yystr[i] = '\r';
|
2013-01-05 04:13:26 -06:00
|
|
|
else if (yystr[i] == 't')
|
|
|
|
yystr[i] = '\t';
|
2018-05-03 05:35:01 -05:00
|
|
|
else if (yystr[i] == 'v')
|
|
|
|
yystr[i] = '\v';
|
2013-01-05 04:13:26 -06:00
|
|
|
else if ('0' <= yystr[i] && yystr[i] <= '7') {
|
|
|
|
yystr[i] = yystr[i] - '0';
|
|
|
|
if ('0' <= yystr[i + 1] && yystr[i + 1] <= '7') {
|
|
|
|
yystr[i + 1] = yystr[i] * 8 + yystr[i + 1] - '0';
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
if ('0' <= yystr[i + 1] && yystr[i + 1] <= '7') {
|
|
|
|
yystr[i + 1] = yystr[i] * 8 + yystr[i + 1] - '0';
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
yystr[j++] = yystr[i++];
|
|
|
|
}
|
|
|
|
yystr[j] = 0;
|
2019-01-05 05:10:24 -06:00
|
|
|
frontend_verilog_yylval.string = new std::string(yystr, j);
|
2013-01-05 04:13:26 -06:00
|
|
|
free(yystr);
|
|
|
|
return TOK_STRING;
|
|
|
|
}
|
|
|
|
<STRING>. { yymore(); }
|
|
|
|
|
2013-08-20 04:23:59 -05:00
|
|
|
and|nand|or|nor|xor|xnor|not|buf|bufif0|bufif1|notif0|notif1 {
|
2013-01-05 04:13:26 -06:00
|
|
|
frontend_verilog_yylval.string = new std::string(yytext);
|
|
|
|
return TOK_PRIMITIVE;
|
|
|
|
}
|
|
|
|
|
|
|
|
supply0 { return TOK_SUPPLY0; }
|
|
|
|
supply1 { return TOK_SUPPLY1; }
|
|
|
|
|
2015-09-23 00:10:56 -05:00
|
|
|
"$"(display|write|strobe|monitor|time|stop|finish|dumpfile|dumpvars|dumpon|dumpoff|dumpall) {
|
2013-01-05 04:13:26 -06:00
|
|
|
frontend_verilog_yylval.string = new std::string(yytext);
|
|
|
|
return TOK_ID;
|
|
|
|
}
|
|
|
|
|
2019-04-23 15:57:10 -05:00
|
|
|
"$"(setup|hold|setuphold|removal|recovery|recrem|skew|timeskew|fullskew|nochange) {
|
2019-04-23 08:46:40 -05:00
|
|
|
if (!specify_mode) REJECT;
|
|
|
|
frontend_verilog_yylval.string = new std::string(yytext);
|
|
|
|
return TOK_ID;
|
|
|
|
}
|
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
"$signed" { return TOK_TO_SIGNED; }
|
|
|
|
"$unsigned" { return TOK_TO_UNSIGNED; }
|
|
|
|
|
2013-07-04 07:12:33 -05:00
|
|
|
[a-zA-Z_$][a-zA-Z0-9_$]* {
|
2013-01-05 04:13:26 -06:00
|
|
|
frontend_verilog_yylval.string = new std::string(std::string("\\") + yytext);
|
|
|
|
return TOK_ID;
|
|
|
|
}
|
|
|
|
|
2018-10-11 16:33:31 -05:00
|
|
|
[a-zA-Z_$][a-zA-Z0-9_$\.]* {
|
|
|
|
frontend_verilog_yylval.string = new std::string(std::string("\\") + yytext);
|
2019-03-09 00:53:58 -06:00
|
|
|
return TOK_ID;
|
2018-10-11 16:33:31 -05:00
|
|
|
}
|
|
|
|
|
2013-11-20 04:44:09 -06:00
|
|
|
"/*"[ \t]*(synopsys|synthesis)[ \t]*translate_off[ \t]*"*/" {
|
2014-12-26 20:40:27 -06:00
|
|
|
static bool printed_warning = false;
|
|
|
|
if (!printed_warning) {
|
|
|
|
log_warning("Found one of those horrible `(synopsys|synthesis) translate_off' comments.\n"
|
|
|
|
"Yosys does support them but it is recommended to use `ifdef constructs instead!\n");
|
|
|
|
printed_warning = true;
|
|
|
|
}
|
2013-01-05 04:13:26 -06:00
|
|
|
BEGIN(SYNOPSYS_TRANSLATE_OFF);
|
|
|
|
}
|
|
|
|
<SYNOPSYS_TRANSLATE_OFF>. /* ignore synopsys translate_off body */
|
|
|
|
<SYNOPSYS_TRANSLATE_OFF>\n /* ignore synopsys translate_off body */
|
2013-11-20 04:44:09 -06:00
|
|
|
<SYNOPSYS_TRANSLATE_OFF>"/*"[ \t]*(synopsys|synthesis)[ \t]*"translate_on"[ \t]*"*/" { BEGIN(0); }
|
2013-01-05 04:13:26 -06:00
|
|
|
|
2013-11-20 04:44:09 -06:00
|
|
|
"/*"[ \t]*(synopsys|synthesis)[ \t]+ {
|
2013-01-05 04:13:26 -06:00
|
|
|
BEGIN(SYNOPSYS_FLAGS);
|
|
|
|
}
|
|
|
|
<SYNOPSYS_FLAGS>full_case {
|
2014-12-26 20:40:27 -06:00
|
|
|
static bool printed_warning = false;
|
|
|
|
if (!printed_warning) {
|
|
|
|
log_warning("Found one of those horrible `(synopsys|synthesis) full_case' comments.\n"
|
2015-08-14 15:23:01 -05:00
|
|
|
"Yosys does support them but it is recommended to use Verilog `full_case' attributes instead!\n");
|
2014-12-26 20:40:27 -06:00
|
|
|
printed_warning = true;
|
|
|
|
}
|
2013-01-05 04:13:26 -06:00
|
|
|
return TOK_SYNOPSYS_FULL_CASE;
|
|
|
|
}
|
|
|
|
<SYNOPSYS_FLAGS>parallel_case {
|
2014-12-26 20:40:27 -06:00
|
|
|
static bool printed_warning = false;
|
|
|
|
if (!printed_warning) {
|
|
|
|
log_warning("Found one of those horrible `(synopsys|synthesis) parallel_case' comments.\n"
|
2015-08-14 15:23:01 -05:00
|
|
|
"Yosys does support them but it is recommended to use Verilog `parallel_case' attributes instead!\n");
|
2014-12-26 20:40:27 -06:00
|
|
|
printed_warning = true;
|
|
|
|
}
|
2013-01-05 04:13:26 -06:00
|
|
|
return TOK_SYNOPSYS_PARALLEL_CASE;
|
|
|
|
}
|
|
|
|
<SYNOPSYS_FLAGS>. /* ignore everything else */
|
|
|
|
<SYNOPSYS_FLAGS>"*/" { BEGIN(0); }
|
|
|
|
|
2014-08-21 05:43:51 -05:00
|
|
|
import[ \t\r\n]+\"(DPI|DPI-C)\"[ \t\r\n]+function[ \t\r\n]+ {
|
|
|
|
BEGIN(IMPORT_DPI);
|
|
|
|
return TOK_DPI_FUNCTION;
|
|
|
|
}
|
|
|
|
|
|
|
|
<IMPORT_DPI>[a-zA-Z_$][a-zA-Z0-9_$]* {
|
|
|
|
frontend_verilog_yylval.string = new std::string(std::string("\\") + yytext);
|
|
|
|
return TOK_ID;
|
|
|
|
}
|
|
|
|
|
|
|
|
<IMPORT_DPI>[ \t\r\n] /* ignore whitespaces */
|
|
|
|
|
|
|
|
<IMPORT_DPI>";" {
|
|
|
|
BEGIN(0);
|
|
|
|
return *yytext;
|
|
|
|
}
|
|
|
|
|
2014-08-21 10:22:04 -05:00
|
|
|
<IMPORT_DPI>. {
|
|
|
|
return *yytext;
|
|
|
|
}
|
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
"\\"[^ \t\r\n]+ {
|
|
|
|
frontend_verilog_yylval.string = new std::string(yytext);
|
|
|
|
return TOK_ID;
|
|
|
|
}
|
|
|
|
|
|
|
|
"(*" { return ATTR_BEGIN; }
|
|
|
|
"*)" { return ATTR_END; }
|
|
|
|
|
2013-11-22 05:46:02 -06:00
|
|
|
"{*" { return DEFATTR_BEGIN; }
|
|
|
|
"*}" { return DEFATTR_END; }
|
2013-01-05 04:13:26 -06:00
|
|
|
|
|
|
|
"**" { return OP_POW; }
|
|
|
|
"||" { return OP_LOR; }
|
|
|
|
"&&" { return OP_LAND; }
|
|
|
|
"==" { return OP_EQ; }
|
|
|
|
"!=" { return OP_NE; }
|
|
|
|
"<=" { return OP_LE; }
|
|
|
|
">=" { return OP_GE; }
|
|
|
|
|
2013-12-27 06:50:08 -06:00
|
|
|
"===" { return OP_EQX; }
|
|
|
|
"!==" { return OP_NEX; }
|
2013-05-07 07:35:40 -05:00
|
|
|
|
2013-06-13 04:18:45 -05:00
|
|
|
"~&" { return OP_NAND; }
|
|
|
|
"~|" { return OP_NOR; }
|
2013-01-05 04:13:26 -06:00
|
|
|
"~^" { return OP_XNOR; }
|
|
|
|
"^~" { return OP_XNOR; }
|
|
|
|
|
|
|
|
"<<" { return OP_SHL; }
|
|
|
|
">>" { return OP_SHR; }
|
|
|
|
"<<<" { return OP_SSHL; }
|
|
|
|
">>>" { return OP_SSHR; }
|
|
|
|
|
2017-02-23 04:21:33 -06:00
|
|
|
"::" { return TOK_PACKAGESEP; }
|
|
|
|
"++" { return TOK_INCREMENT; }
|
|
|
|
"--" { return TOK_DECREMENT; }
|
2016-06-18 03:24:21 -05:00
|
|
|
|
2013-11-20 06:05:27 -06:00
|
|
|
"+:" { return TOK_POS_INDEXED; }
|
|
|
|
"-:" { return TOK_NEG_INDEXED; }
|
|
|
|
|
2019-04-21 14:58:57 -05:00
|
|
|
[-+]?[=*]> {
|
2019-04-21 15:58:51 -05:00
|
|
|
if (!specify_mode) REJECT;
|
2019-04-21 14:58:57 -05:00
|
|
|
frontend_verilog_yylval.string = new std::string(yytext);
|
|
|
|
return TOK_SPECIFY_OPER;
|
|
|
|
}
|
|
|
|
|
2019-04-23 08:46:40 -05:00
|
|
|
"&&&" {
|
|
|
|
if (!specify_mode) REJECT;
|
|
|
|
return TOK_SPECIFY_AND;
|
|
|
|
}
|
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
"/*" { BEGIN(COMMENT); }
|
|
|
|
<COMMENT>. /* ignore comment body */
|
|
|
|
<COMMENT>\n /* ignore comment body */
|
|
|
|
<COMMENT>"*/" { BEGIN(0); }
|
|
|
|
|
|
|
|
[ \t\r\n] /* ignore whitespaces */
|
|
|
|
\\[\r\n] /* ignore continuation sequence */
|
|
|
|
"//"[^\r\n]* /* ignore one-line comments */
|
2014-11-24 07:48:07 -06:00
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
. { return *yytext; }
|
|
|
|
|
|
|
|
%%
|
|
|
|
|
|
|
|
// this is a hack to avoid the 'yyinput defined but not used' error msgs
|
|
|
|
void *frontend_verilog_avoid_input_warnings() {
|
|
|
|
return (void*)&yyinput;
|
|
|
|
}
|
|
|
|
|