diff --git a/src/V3ParseImp.cpp b/src/V3ParseImp.cpp index 8365a9ad0..8770cddd3 100644 --- a/src/V3ParseImp.cpp +++ b/src/V3ParseImp.cpp @@ -69,8 +69,8 @@ V3ParseImp::~V3ParseImp() { //###################################################################### // Parser utility methods -void V3ParseImp::ppline(const char* textp) { - // Handle `line directive +void V3ParseImp::lexPpline(const char* textp) { + // Handle lexer `line directive FileLine* prevFl = copyOrSameFileLine(); int enterExit; fileline()->lineDirective(textp, enterExit /*ref*/); @@ -83,7 +83,7 @@ void V3ParseImp::ppline(const char* textp) { } } -void V3ParseImp::timescalePreproc(FileLine* fl, const char* textp) { +void V3ParseImp::lexTimescaleParse(FileLine* fl, const char* textp) { // Parse `timescale of / VTimescale unit; VTimescale prec; @@ -121,18 +121,18 @@ void V3ParseImp::timescaleMod(FileLine* fl, AstNodeModule* modp, bool unitSet, d v3Global.rootp()->timeprecisionMerge(fl, prec); } -void V3ParseImp::verilatorCmtLintSave() { m_lintState.push_back(*parsep()->fileline()); } +void V3ParseImp::lexVerilatorCmtLintSave(const FileLine* fl) { m_lexLintState.push_back(*fl); } -void V3ParseImp::verilatorCmtLintRestore(FileLine* fl) { - if (m_lintState.empty()) { +void V3ParseImp::lexVerilatorCmtLintRestore(FileLine* fl) { + if (m_lexLintState.empty()) { fl->v3error("/*verilator lint_restore*/ without matching save"); return; } - fl->warnStateFrom(m_lintState.back()); - m_lintState.pop_back(); + fl->warnStateFrom(m_lexLintState.back()); + m_lexLintState.pop_back(); } -void V3ParseImp::verilatorCmtLint(FileLine* fl, const char* textp, bool warnOff) { +void V3ParseImp::lexVerilatorCmtLint(FileLine* fl, const char* textp, bool warnOff) { const char* sp = textp; while (*sp && !isspace(*sp)) ++sp; while (*sp && isspace(*sp)) ++sp; @@ -150,7 +150,7 @@ void V3ParseImp::verilatorCmtLint(FileLine* fl, const char* textp, bool warnOff) } } -void V3ParseImp::verilatorCmtBad(FileLine* fl, const char* textp) { +void V3ParseImp::lexVerilatorCmtBad(FileLine* fl, const char* textp) { string cmtparse = textp; if (cmtparse.substr(0, strlen("/*verilator")) == "/*verilator") { cmtparse.replace(0, strlen("/*verilator"), ""); @@ -163,7 +163,7 @@ void V3ParseImp::verilatorCmtBad(FileLine* fl, const char* textp) { } } -void V3ParseImp::errorPreprocDirective(FileLine* fl, const char* textp) { +void V3ParseImp::lexErrorPreprocDirective(FileLine* fl, const char* textp) { // Find all `preprocessor spelling candidates // Can't make this static as might get more defines later when read cells VSpellCheck speller; @@ -188,7 +188,7 @@ void V3ParseImp::tag(const char* text) { } } -double V3ParseImp::parseTimenum(const char* textp) { +double V3ParseImp::lexParseTimenum(const char* textp) { size_t length = strlen(textp); char* strgp = new char[length + 1]; char* dp = strgp; diff --git a/src/V3ParseImp.h b/src/V3ParseImp.h index 46a66c382..750d9930f 100644 --- a/src/V3ParseImp.h +++ b/src/V3ParseImp.h @@ -108,11 +108,11 @@ class V3ParseImp { FileLine* m_fileline; // Filename/linenumber currently active bool m_inLibrary; // Currently reading a library vs. regular file - int m_inBeginKwd; // Inside a `begin_keywords - int m_lastVerilogState; // Last LEX state in `begin_keywords + int m_lexKwdDepth; // Inside a `begin_keywords + int m_lexKwdLast; // Last LEX state in `begin_keywords VOptionBool m_unconnectedDrive; // Last unconnected drive - int m_prevLexToken; // previous parsed token (for lexer) + int m_lexPrevToken; // previous parsed token (for lexer) bool m_ahead; // aheadval is valid V3ParseBisonYYSType m_aheadVal; // ahead token value V3ParseBisonYYSType m_bisonValCur; // current token for error reporting @@ -120,7 +120,7 @@ class V3ParseImp { std::deque m_stringps; // Created strings for later cleanup std::deque m_numberps; // Created numbers for later cleanup - std::deque m_lintState; // Current lint state for save/restore + std::deque m_lexLintState; // Current lint state for save/restore std::deque m_ppBuffers; // Preprocessor->lex buffer of characters to process string m_tag; // Contents (if any) of current verilator tag @@ -145,35 +145,36 @@ public: int yylexThis(); static bool optFuture(const string& flag) { return v3Global.opt.isFuture(flag); } - void ppline(const char* textp); void linenoInc() { fileline()->linenoInc(); } - void verilatorCmtLint(FileLine* fl, const char* textp, bool warnOff); - void verilatorCmtLintSave(); - void verilatorCmtLintRestore(FileLine* fl); - void verilatorCmtBad(FileLine* fl, const char* textp); - static void errorPreprocDirective(FileLine* fl, const char* textp); void tag(const char* text); void tagNodep(AstNode* nodep) { m_tagNodep = nodep; } AstNode* tagNodep() const { return m_tagNodep; } - void timescalePreproc(FileLine* fl, const char* textp); + void lexTimescaleParse(FileLine* fl, const char* textp); void timescaleMod(FileLine* fl, AstNodeModule* modp, bool unitSet, double unitVal, bool precSet, double precVal); VTimescale timeLastUnit() const { return m_timeLastUnit; } - static double parseTimenum(const char* text); - void pushBeginKeywords(int state) { - m_inBeginKwd++; - m_lastVerilogState = state; + static void lexErrorPreprocDirective(FileLine* fl, const char* textp); + static double lexParseTimenum(const char* text); + void lexPpline(const char* textp); + void lexVerilatorCmtLint(FileLine* fl, const char* textp, bool warnOff); + void lexVerilatorCmtLintSave(const FileLine* fl); + void lexVerilatorCmtLintRestore(FileLine* fl); + static void lexVerilatorCmtBad(FileLine* fl, const char* textp); + + void lexPushKeywords(int state) { + ++m_lexKwdDepth; + m_lexKwdLast = state; } - bool popBeginKeywords() { - if (m_inBeginKwd) { - m_inBeginKwd--; + bool lexPopKeywords() { + if (m_lexKwdDepth) { + --m_lexKwdDepth; return true; } else { return false; } } - int lastVerilogState() const { return m_lastVerilogState; } + int lexKwdLastState() const { return m_lexKwdLast; } static const char* tokenName(int tok); void ppPushText(const string& text) { @@ -224,7 +225,7 @@ public: void lexNew(); void lexDestroy(); static int stateVerilogRecent(); // Parser -> lexer communication - int prevLexToken() const { return m_prevLexToken; } // Parser -> lexer communication + int lexPrevToken() const { return m_lexPrevToken; } // Parser -> lexer communication size_t flexPpInputToLex(char* buf, size_t max_size) { return ppInputToLex(buf, max_size); } V3ParseBisonYYSType bisonValCur() const { return m_bisonValCur; } V3ParseBisonYYSType bisonValPrev() const { return m_bisonValPrev; } @@ -242,9 +243,9 @@ public: m_fileline = NULL; m_lexerp = NULL; m_inLibrary = false; - m_inBeginKwd = 0; - m_lastVerilogState = stateVerilogRecent(); - m_prevLexToken = 0; + m_lexKwdDepth = 0; + m_lexKwdLast = stateVerilogRecent(); + m_lexPrevToken = 0; m_ahead = false; m_bisonValCur.token = 0; m_bisonValPrev.token = 0; @@ -254,7 +255,7 @@ public: } ~V3ParseImp(); void parserClear(); - void unputString(const char* textp, size_t length); + void lexUnputString(const char* textp, size_t length); // METHODS // Preprocess and read the Verilog file specified into the netlist database diff --git a/src/V3ParseLex.cpp b/src/V3ParseLex.cpp index 14100969a..33225d9ab 100644 --- a/src/V3ParseLex.cpp +++ b/src/V3ParseLex.cpp @@ -46,7 +46,7 @@ public: } }; -void V3ParseImp::unputString(const char* textp, size_t length) { +void V3ParseImp::lexUnputString(const char* textp, size_t length) { parsep()->m_lexerp->unputString(textp, length); } @@ -54,7 +54,7 @@ int V3ParseImp::yylexReadTok() { // Call yylex() remembering last non-whitespace token parsep()->fileline()->startToken(); int token = parsep()->m_lexerp->yylex(); - m_prevLexToken = token; // Save so can find '#' to parse following number + m_lexPrevToken = token; // Save so can find '#' to parse following number return token; } diff --git a/src/verilog.l b/src/verilog.l index fb95bb789..d1c813ed3 100644 --- a/src/verilog.l +++ b/src/verilog.l @@ -691,10 +691,10 @@ vnum {vnum1}|{vnum2}|{vnum3}|{vnum4}|{vnum5} "/*verilator full_case*/" { FL; return yVL_FULL_CASE; } "/*verilator inline_module*/" { FL; return yVL_INLINE_MODULE; } "/*verilator isolate_assignments*/" { FL; return yVL_ISOLATE_ASSIGNMENTS; } - "/*verilator lint_off"[^*]*"*/" { FL; PARSEP->verilatorCmtLint(yylval.fl, yytext, true); FL_BRK; } - "/*verilator lint_on"[^*]*"*/" { FL; PARSEP->verilatorCmtLint(yylval.fl, yytext, false); FL_BRK; } - "/*verilator lint_restore*/" { FL; PARSEP->verilatorCmtLintRestore(PARSEP->fileline()); FL_BRK; } - "/*verilator lint_save*/" { FL; PARSEP->verilatorCmtLintSave(); FL_BRK; } + "/*verilator lint_off"[^*]*"*/" { FL; PARSEP->lexVerilatorCmtLint(yylval.fl, yytext, true); FL_BRK; } + "/*verilator lint_on"[^*]*"*/" { FL; PARSEP->lexVerilatorCmtLint(yylval.fl, yytext, false); FL_BRK; } + "/*verilator lint_restore*/" { FL; PARSEP->lexVerilatorCmtLintRestore(PARSEP->fileline()); FL_BRK; } + "/*verilator lint_save*/" { FL; PARSEP->lexVerilatorCmtLintSave(PARSEP->fileline()); FL_BRK; } "/*verilator no_clocker*/" { FL; return yVL_NO_CLOCKER; } "/*verilator no_inline_module*/" { FL; return yVL_NO_INLINE_MODULE; } "/*verilator no_inline_task*/" { FL; return yVL_NO_INLINE_TASK; } @@ -714,7 +714,7 @@ vnum {vnum1}|{vnum2}|{vnum3}|{vnum4}|{vnum5} "/*verilator tracing_on*/" { FL_FWD; PARSEP->fileline()->tracingOn(true); FL_BRK; } "/**/" { FL_FWD; FL_BRK; } - "/*"[^*]+"*/" { FL; PARSEP->verilatorCmtBad(yylval.fl, yytext); FL_BRK; } + "/*"[^*]+"*/" { FL; V3ParseImp::lexVerilatorCmtBad(yylval.fl, yytext); FL_BRK; } } /************************************************************************/ @@ -842,12 +842,12 @@ vnum {vnum1}|{vnum2}|{vnum3}|{vnum4}|{vnum5} \" { yy_push_state(STRING); yymore(); } {vnum} { /* "# 1'b0" is a delay value so must lex as "#" "1" "'b0" */ - if (PARSEP->prevLexToken()=='#') { + if (PARSEP->lexPrevToken()=='#') { int shortlen = 0; while (isdigit(yytext[shortlen])) shortlen++; if (shortlen) { // Push rest past numbers for later parse - PARSEP->unputString(yytext+shortlen, yyleng-shortlen); + PARSEP->lexUnputString(yytext+shortlen, yyleng-shortlen); // Return is stuff before the tick yyleng = shortlen; yytext[yyleng] = '\0'; @@ -871,7 +871,7 @@ vnum {vnum1}|{vnum2}|{vnum3}|{vnum4}|{vnum5} return yaFLOATNUM; } [0-9][_0-9]*(\.[_0-9]+)?(fs|ps|ns|us|ms|s) { - FL; yylval.cdouble = PARSEP->parseTimenum(yytext); + FL; yylval.cdouble = V3ParseImp::lexParseTimenum(yytext); return yaTIMENUM; } 1step { @@ -916,7 +916,7 @@ vnum {vnum1}|{vnum2}|{vnum3}|{vnum4}|{vnum5} {crnl} { yymore(); }
";" { FL; yylval.strp = PARSEP->newString(yytext, yyleng); return yaTABLELINE; }
"endtable" { yy_pop_state(); FL; return yENDTABLE; } -
"`line"{ws}+[^\n\r]*{crnl} { FL_FWD; PARSEP->ppline(yytext); FL_BRK; } +
"`line"{ws}+[^\n\r]*{crnl} { FL_FWD; PARSEP->lexPpline(yytext); FL_BRK; }
. { yymore(); }
<> { FL; yylval.fl->v3error("EOF in TABLE"); yyleng = 0; yy_pop_state(); FL_BRK; yyterminate(); } @@ -947,7 +947,7 @@ vnum {vnum1}|{vnum2}|{vnum3}|{vnum4}|{vnum5} "`endprotect" { FL_FWD; FL_BRK; } "`expand_vectornets" { FL_FWD; FL_BRK; } // Verilog-XL compatibility "`inline" { FL_FWD; FL_BRK; } - "`line"{ws}+[^\n\r]*{crnl} { FL_FWD; PARSEP->ppline(yytext); FL_BRK; } + "`line"{ws}+[^\n\r]*{crnl} { FL_FWD; PARSEP->lexPpline(yytext); FL_BRK; } "`noaccelerate" { FL_FWD; FL_BRK; } // Verilog-XL compatibility "`noexpand_vectornets" { FL_FWD; FL_BRK; } // Verilog-XL compatibility "`noremove_gatenames" { FL_FWD; FL_BRK; } // Verilog-XL compatibility @@ -962,8 +962,8 @@ vnum {vnum1}|{vnum2}|{vnum3}|{vnum4}|{vnum5} "`resetall" { FL; PARSEP->fileline()->warnOn(V3ErrorCode::I_DEF_NETTYPE_WIRE, true); return yaT_RESETALL; } // Rest handled by preproc "`suppress_faults" { FL_FWD; FL_BRK; } // Verilog-XL compatibility - "`timescale"{ws}+[^\n\r]* { FL; PARSEP->timescalePreproc(yylval.fl, - yytext + strlen("`timescale")); + "`timescale"{ws}+[^\n\r]* { FL; PARSEP->lexTimescaleParse(yylval.fl, + yytext + strlen("`timescale")); FL_BRK; } "`unconnected_drive"{ws}+"pull0" { FL; return yaT_UNCONNECTED_PULL0; } "`unconnected_drive"{ws}+"pull1" { FL; return yaT_UNCONNECTED_PULL1; } @@ -971,18 +971,18 @@ vnum {vnum1}|{vnum2}|{vnum3}|{vnum4}|{vnum5} "`uselib"{ws}+[^\n\r]* { FL_FWD; FL_BRK; } // Verilog-XL compatibility /* See also setLanguage below */ - "`begin_keywords"[ \t]*\"1364-1995\" { FL_FWD; yy_push_state(V95); PARSEP->pushBeginKeywords(YY_START); FL_BRK; } - "`begin_keywords"[ \t]*\"1364-2001\" { FL_FWD; yy_push_state(V01); PARSEP->pushBeginKeywords(YY_START); FL_BRK; } - "`begin_keywords"[ \t]*\"1364-2001-noconfig\" { FL_FWD; yy_push_state(V01); PARSEP->pushBeginKeywords(YY_START); FL_BRK; } - "`begin_keywords"[ \t]*\"1364-2005\" { FL_FWD; yy_push_state(V05); PARSEP->pushBeginKeywords(YY_START); FL_BRK; } - "`begin_keywords"[ \t]*\"VAMS[-0-9.]*\" { FL_FWD; yy_push_state(VA5); PARSEP->pushBeginKeywords(YY_START); FL_BRK; } - "`begin_keywords"[ \t]*\"1800-2005\" { FL_FWD; yy_push_state(S05); PARSEP->pushBeginKeywords(YY_START); FL_BRK; } - "`begin_keywords"[ \t]*\"1800-2009\" { FL_FWD; yy_push_state(S09); PARSEP->pushBeginKeywords(YY_START); FL_BRK; } - "`begin_keywords"[ \t]*\"1800-2012\" { FL_FWD; yy_push_state(S12); PARSEP->pushBeginKeywords(YY_START); FL_BRK; } - "`begin_keywords"[ \t]*\"1800-2017\" { FL_FWD; yy_push_state(S17); PARSEP->pushBeginKeywords(YY_START); FL_BRK; } - "`begin_keywords"[ \t]*\"1800[+]VAMS\" { FL_FWD; yy_push_state(SAX); PARSEP->pushBeginKeywords(YY_START); FL_BRK; } /*Latest SV*/ + "`begin_keywords"[ \t]*\"1364-1995\" { FL_FWD; yy_push_state(V95); PARSEP->lexPushKeywords(YY_START); FL_BRK; } + "`begin_keywords"[ \t]*\"1364-2001\" { FL_FWD; yy_push_state(V01); PARSEP->lexPushKeywords(YY_START); FL_BRK; } + "`begin_keywords"[ \t]*\"1364-2001-noconfig\" { FL_FWD; yy_push_state(V01); PARSEP->lexPushKeywords(YY_START); FL_BRK; } + "`begin_keywords"[ \t]*\"1364-2005\" { FL_FWD; yy_push_state(V05); PARSEP->lexPushKeywords(YY_START); FL_BRK; } + "`begin_keywords"[ \t]*\"VAMS[-0-9.]*\" { FL_FWD; yy_push_state(VA5); PARSEP->lexPushKeywords(YY_START); FL_BRK; } + "`begin_keywords"[ \t]*\"1800-2005\" { FL_FWD; yy_push_state(S05); PARSEP->lexPushKeywords(YY_START); FL_BRK; } + "`begin_keywords"[ \t]*\"1800-2009\" { FL_FWD; yy_push_state(S09); PARSEP->lexPushKeywords(YY_START); FL_BRK; } + "`begin_keywords"[ \t]*\"1800-2012\" { FL_FWD; yy_push_state(S12); PARSEP->lexPushKeywords(YY_START); FL_BRK; } + "`begin_keywords"[ \t]*\"1800-2017\" { FL_FWD; yy_push_state(S17); PARSEP->lexPushKeywords(YY_START); FL_BRK; } + "`begin_keywords"[ \t]*\"1800[+]VAMS\" { FL_FWD; yy_push_state(SAX); PARSEP->lexPushKeywords(YY_START); FL_BRK; } /*Latest SV*/ "`end_keywords" { FL; yy_pop_state(); - if (!PARSEP->popBeginKeywords()) yylval.fl->v3error("`end_keywords when not inside `begin_keywords block"); + if (!PARSEP->lexPopKeywords()) yylval.fl->v3error("`end_keywords when not inside `begin_keywords block"); FL_BRK; } /* Verilator */ @@ -993,7 +993,7 @@ vnum {vnum1}|{vnum2}|{vnum3}|{vnum4}|{vnum5} "`systemc_implementation" { FL_FWD; BEGIN SYSCIMP; FL_BRK; } "`systemc_interface" { FL_FWD; BEGIN SYSCINT; FL_BRK; } "`verilator_config" { FL_FWD; BEGIN VLT; FL_BRK; } - "`verilog" { FL_FWD; BEGIN PARSEP->lastVerilogState(); FL_BRK; } + "`verilog" { FL_FWD; BEGIN PARSEP->lexKwdLastState(); FL_BRK; } /* Errors */ "<<<<<<<"[^\n\r]* { FL; yylval.fl->v3error("version control conflict marker in file"); FL_BRK; } @@ -1021,7 +1021,7 @@ vnum {vnum1}|{vnum2}|{vnum3}|{vnum4}|{vnum5} /* Default rules - leave last */ { - "`"[a-zA-Z_0-9]+ { FL; PARSEP->errorPreprocDirective(yylval.fl, yytext); FL_BRK; } + "`"[a-zA-Z_0-9]+ { FL; V3ParseImp::lexErrorPreprocDirective(yylval.fl, yytext); FL_BRK; } "//"[^\n]* { FL_FWD; FL_BRK; } /* throw away single line comments */ . { FL; return yytext[0]; } /* return single char ops. */ }