From dd8d5ef687b4319f60bde506356d906866952979 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Tue, 11 Jun 2019 21:03:03 -0400 Subject: [PATCH] Internals: Move code out of verilog.l. No functional change. --- src/V3ParseImp.cpp | 91 +++++++++++++++++++++++++++++++++++++++++++++- src/verilog.l | 77 --------------------------------------- 2 files changed, 90 insertions(+), 78 deletions(-) diff --git a/src/V3ParseImp.cpp b/src/V3ParseImp.cpp index eff0e2835..4842bce77 100644 --- a/src/V3ParseImp.cpp +++ b/src/V3ParseImp.cpp @@ -48,8 +48,11 @@ V3ParseImp* V3ParseImp::s_parsep = NULL; int V3ParseSym::s_anonNum = 0; +extern void yyerror(const char*); +extern void yyerrorf(const char* format, ...); + //###################################################################### -// Read class functions +// Parser constructor V3ParseImp::~V3ParseImp() { for (std::deque::iterator it = m_stringps.begin(); it != m_stringps.end(); ++it) { @@ -66,6 +69,92 @@ V3ParseImp::~V3ParseImp() { if (debug()>=9) { UINFO(0,"~V3ParseImp\n"); symp()->dump(cout, "-vpi: "); } } +//###################################################################### +// Parser utility methods + +void V3ParseImp::ppline(const char* textp) { + // Handle `line directive + int enterExit; + fileline()->lineDirective(textp, enterExit/*ref*/); +} + +void V3ParseImp::verilatorCmtLintSave() { + m_lintState.push_back(*parsep()->fileline()); +} + +void V3ParseImp::verilatorCmtLintRestore() { + if (m_lintState.empty()) { + yyerrorf("/*verilator lint_restore*/ without matching save."); + return; + } + parsep()->fileline()->warnStateFrom(m_lintState.back()); + m_lintState.pop_back(); +} + +void V3ParseImp::verilatorCmtLint(const char* textp, bool warnOff) { + const char* sp = textp; + while (*sp && !isspace(*sp)) sp++; + while (*sp && isspace(*sp)) sp++; + while (*sp && !isspace(*sp)) sp++; + while (*sp && isspace(*sp)) sp++; + string msg = sp; + string::size_type pos; + if ((pos = msg.find('*')) != string::npos) { msg.erase(pos); } + if (!(parsep()->fileline()->warnOff(msg, warnOff))) { + if (!parsep()->optFuture(msg)) { + yyerrorf("Unknown verilator lint message code: %s, in %s", msg.c_str(), textp); + } + } +} + +void V3ParseImp::verilatorCmtBad(const char* textp) { + string cmtparse = textp; + if (cmtparse.substr(0, strlen("/*verilator")) == "/*verilator") { + cmtparse.replace(0, strlen("/*verilator"), ""); + } + while (isspace(cmtparse[0])) { + cmtparse.replace(0, 1, ""); + } + string cmtname; + for (int i = 0; isalnum(cmtparse[i]); i++) { + cmtname += cmtparse[i]; + } + if (!parsep()->optFuture(cmtname)) { + yyerrorf("Unknown verilator comment: %s", textp); + } +} + +void V3ParseImp::tag(const char* text) { + if (m_tagNodep) { + string tmp = text + strlen("/*verilator tag "); + string::size_type pos; + if ((pos = tmp.rfind("*/")) != string::npos) { tmp.erase(pos); } + m_tagNodep->tag(tmp); + } +} + +double V3ParseImp::parseDouble(const char* textp, size_t length, bool* successp) { + char* strgp = new char[length+1]; + char* dp = strgp; + if (successp) *successp = true; + for (const char* sp = textp; sp < (textp+length); ++sp) { + if (*sp != '_') *dp++ = *sp; + } + *dp++ = '\0'; + char* endp = strgp; + double d = strtod(strgp, &endp); + size_t parsed_len = endp-strgp; + if (parsed_len != strlen(strgp)) { + if (successp) *successp = false; + else yyerrorf("Syntax error parsing real: %s", strgp); + } + delete[] strgp; + return d; +} + +//###################################################################### +// Parser tokenization + size_t V3ParseImp::ppInputToLex(char* buf, size_t max_size) { size_t got = 0; while (got < max_size // Haven't got enough diff --git a/src/verilog.l b/src/verilog.l index 095f00ee8..d381615b3 100644 --- a/src/verilog.l +++ b/src/verilog.l @@ -52,64 +52,6 @@ extern void yyerrorf(const char* format, ...); if (!v3Global.opt.bboxSys()) yyerrorf(msg, yytext); \ return yaD_IGNORE; } -void V3ParseImp::ppline(const char* textp) { - // Handle `line directive - int enterExit; - fileline()->lineDirective(textp, enterExit/*ref*/); -} - -void V3ParseImp::verilatorCmtLint(const char* textp, bool warnOff) { - const char* sp = textp; - while (*sp && !isspace(*sp)) sp++; while (*sp && isspace(*sp)) sp++; - while (*sp && !isspace(*sp)) sp++; while (*sp && isspace(*sp)) sp++; - string msg = sp; - string::size_type pos; - if ((pos = msg.find('*')) != string::npos) { msg.erase(pos); } - if (!(PARSEP->fileline()->warnOff(msg, warnOff))) { - if (!PARSEP->optFuture(msg)) { - yyerrorf("Unknown verilator lint message code: %s, in %s",msg.c_str(), textp); - } - } -} - -void V3ParseImp::verilatorCmtLintSave() { - m_lintState.push_back(*PARSEP->fileline()); -} -void V3ParseImp::verilatorCmtLintRestore() { - if (m_lintState.empty()) { - yyerrorf("/*verilator lint_restore*/ without matching save."); - return; - } - PARSEP->fileline()->warnStateFrom(m_lintState.back()); - m_lintState.pop_back(); -} - -void V3ParseImp::verilatorCmtBad(const char* textp) { - string cmtparse = textp; - if (cmtparse.substr(0,strlen("/*verilator")) == "/*verilator") { - cmtparse.replace(0,strlen("/*verilator"), ""); - } - while (isspace(cmtparse[0])) { - cmtparse.replace(0,1, ""); - } - string cmtname; - for (int i=0; isalnum(cmtparse[i]); i++) { - cmtname += cmtparse[i]; - } - if (!PARSEP->optFuture(cmtname)) { - yyerrorf("Unknown verilator comment: %s",textp); - } -} - -void V3ParseImp::tag(const char* text) { - if (m_tagNodep) { - string tmp = text + strlen("/*verilator tag "); - string::size_type pos; - if ((pos=tmp.rfind("*/")) != string::npos) { tmp.erase(pos); } - m_tagNodep->tag(tmp); - } -} - // See V3Read.cpp //void V3ParseImp::statePop() { yy_pop_state(); } @@ -1026,25 +968,6 @@ vnum {vnum1}|{vnum2}|{vnum3}|{vnum4}|{vnum5} %% int V3ParseImp::stateVerilogRecent() { return STATE_VERILOG_RECENT; } -double V3ParseImp::parseDouble(const char* textp, size_t length, bool* successp) { - char* strgp = new char[length+1]; - char* dp=strgp; - if (successp) *successp = true; - for (const char* sp=textp; sp<(textp+length); ++sp) { - if (*sp != '_') *dp++ = *sp; - } - *dp++ = '\0'; - char* endp = strgp; - double d = strtod(strgp, &endp); - size_t parsed_len = endp-strgp; - if (parsed_len != strlen(strgp)) { - if (successp) *successp = false; - else yyerrorf("Syntax error parsing real: %s",strgp); - } - delete[] strgp; - return d; -} - void V3ParseImp::lexToken() { // called from lexToBison, has a "this" // Fetch next token from prefetch or real lexer