Internals: Move code out of verilog.l. No functional change.

This commit is contained in:
Wilson Snyder 2019-06-11 21:03:03 -04:00
parent cfb05cd70a
commit dd8d5ef687
2 changed files with 90 additions and 78 deletions

View File

@ -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<string*>::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

View File

@ -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