Internals: Determine needing verilated_std without symbol table

This commit is contained in:
Wilson Snyder 2024-12-01 11:35:00 -05:00
parent 9ec5413d33
commit b0f898cec8
6 changed files with 38 additions and 18 deletions

View File

@ -21,6 +21,9 @@
/// It is only for internal use.
///
//*************************************************************************
//
// The following keywords from this file are hardcoded for detection in the parser:
// "mailbox", "process", "randomize", "semaphore", "std"
// verilator lint_off DECLFILENAME
// verilator lint_off TIMESCALEMOD

View File

@ -142,6 +142,8 @@ BISONPRE = $(srcdir)/bisonpre
FLEXFIX = $(srcdir)/flexfix
VLCOVGEN = $(srcdir)/vlcovgen
# BISON_DEBUG = -Wcounterexamples
######################################################################
# CCACHE flags (via environment as no command line option available)
CCACHE_SLOPPINESS ?= pch_defines,time_macros
@ -417,7 +419,7 @@ V3ParseBison.h: V3ParseBison.c
# Have only one output file in this rule to prevent parallel make issues
V3ParseBison.c: verilog.y $(BISONPRE)
@echo "If you get errors from verilog.y below, try upgrading bison to version 1.875 or newer."
$(PYTHON3) $(BISONPRE) --yacc ${YACC} -d -v -o V3ParseBison.c $<
$(PYTHON3) $(BISONPRE) --yacc ${YACC} -d -v -o V3ParseBison.c $(BISON_DEBUG) $<
V3Lexer_pregen.yy.cpp: verilog.l V3ParseBison.h $(HEADERS)
${LEX} --version

View File

@ -70,6 +70,25 @@ V3ParseImp::~V3ParseImp() {
//######################################################################
// Parser utility methods
void V3ParseImp::importIfInStd(FileLine* fileline, const string& id) {
// Keywords that auto-import to require use of verilated_std.vh.
// OK if overly sensitive; will over-import and keep std:: around
// longer than migt otherwise.
if (v3Global.usesStdPackage()) return; // Run once then short-circuit
const bool identifierImportsStd = (id == "mailbox" || id == "process" || id == "randomize"
|| id == "semaphore" || id == "std");
if (!identifierImportsStd) return;
// Ignore Std:: used inside verilated_std.vh itself
if (fileline->filename() == V3Options::getStdPackagePath()) return;
if (AstPackage* const stdpkgp
= v3Global.rootp()->stdPackagep()) { // else e.g. --no-std-package
UINFO(9, "import and keep std:: for " << fileline << "\n");
AstPackageImport* const impp = new AstPackageImport{stdpkgp->fileline(), stdpkgp, "*"};
unitPackage(stdpkgp->fileline())->addStmtsp(impp);
v3Global.setUsesStdPackage();
}
}
void V3ParseImp::lexPpline(const char* textp) {
// Handle lexer `line directive
// FileLine* const prevFl = lexFileline();
@ -647,6 +666,9 @@ void V3ParseImp::tokenPipelineSym() {
// Note above sometimes converts yGLOBAL to a yaID__LEX
tokenPipeline(); // sets yylval
int token = yylval.token;
if (token == yaID__LEX || token == yaID__CC || token == yaID__aTYPE) {
importIfInStd(yylval.fl, *(yylval.strp));
}
if (token == yaID__LEX || token == yaID__CC) {
const VSymEnt* foundp;
if (const VSymEnt* const look_underp = V3ParseImp::parsep()->symp()->nextId()) {
@ -669,12 +691,6 @@ void V3ParseImp::tokenPipelineSym() {
VSymEnt* const stdsymp = stdpkgp->user4u().toSymEnt();
foundp = stdsymp->findIdFallback(*(yylval.strp));
}
if (foundp && !v3Global.usesStdPackage()) {
AstPackageImport* const impp
= new AstPackageImport{stdpkgp->fileline(), stdpkgp, "*"};
unitPackage(stdpkgp->fileline())->addStmtsp(impp);
v3Global.setUsesStdPackage();
}
}
if (foundp) {
AstNode* const scp = foundp->nodep();
@ -692,8 +708,6 @@ void V3ParseImp::tokenPipelineSym() {
} else {
token = yaID__ETC;
}
} else if (!m_afterColonColon && *(yylval.strp) == "std") {
v3Global.setUsesStdPackage();
}
} else { // Not found
yylval.scp = nullptr;

View File

@ -309,6 +309,7 @@ private:
void preprocDumps(std::ostream& os);
void lexFile(const string& modname) VL_MT_DISABLED;
void yylexReadTok() VL_MT_DISABLED;
void importIfInStd(FileLine* fileline, const string& id);
void tokenPull() VL_MT_DISABLED;
void tokenPipeline() VL_MT_DISABLED; // Internal; called from tokenToBison
int tokenPipelineId(int token) VL_MT_DISABLED;

View File

@ -519,14 +519,14 @@
"miscsp": [
{"type":"TYPETABLE","name":"","addr":"(C)","loc":"a,0:0,0:0","constraintRefp":"UNLINKED","emptyQueuep":"UNLINKED","queueIndexp":"UNLINKED","streamp":"UNLINKED","voidp":"(HI)",
"typesp": [
{"type":"BASICDTYPE","name":"integer","addr":"(II)","loc":"d,31:27,31:28","dtypep":"(II)","keyword":"integer","range":"31:0","generic":true,"rangep": []},
{"type":"BASICDTYPE","name":"logic","addr":"(L)","loc":"d,33:32,33:33","dtypep":"(L)","keyword":"logic","range":"31:0","generic":true,"rangep": []},
{"type":"BASICDTYPE","name":"logic","addr":"(UE)","loc":"d,50:22,50:24","dtypep":"(UE)","keyword":"logic","generic":true,"rangep": []},
{"type":"VOIDDTYPE","name":"","addr":"(HI)","loc":"d,51:21,51:30","dtypep":"(HI)","generic":false},
{"type":"BASICDTYPE","name":"logic","addr":"(QD)","loc":"d,125:22,125:23","dtypep":"(QD)","keyword":"logic","range":"31:0","generic":true,"rangep": []},
{"type":"BASICDTYPE","name":"logic","addr":"(JI)","loc":"d,127:22,127:23","dtypep":"(JI)","keyword":"logic","range":"31:0","generic":true,"rangep": []},
{"type":"BASICDTYPE","name":"logic","addr":"(KI)","loc":"d,162:17,162:56","dtypep":"(KI)","keyword":"logic","range":"295:0","generic":true,"rangep": []},
{"type":"BASICDTYPE","name":"string","addr":"(BG)","loc":"d,162:10,162:16","dtypep":"(BG)","keyword":"string","generic":true,"rangep": []},
{"type":"BASICDTYPE","name":"integer","addr":"(II)","loc":"d,34:27,34:28","dtypep":"(II)","keyword":"integer","range":"31:0","generic":true,"rangep": []},
{"type":"BASICDTYPE","name":"logic","addr":"(L)","loc":"d,36:32,36:33","dtypep":"(L)","keyword":"logic","range":"31:0","generic":true,"rangep": []},
{"type":"BASICDTYPE","name":"logic","addr":"(UE)","loc":"d,53:22,53:24","dtypep":"(UE)","keyword":"logic","generic":true,"rangep": []},
{"type":"VOIDDTYPE","name":"","addr":"(HI)","loc":"d,54:21,54:30","dtypep":"(HI)","generic":false},
{"type":"BASICDTYPE","name":"logic","addr":"(QD)","loc":"d,128:22,128:23","dtypep":"(QD)","keyword":"logic","range":"31:0","generic":true,"rangep": []},
{"type":"BASICDTYPE","name":"logic","addr":"(JI)","loc":"d,130:22,130:23","dtypep":"(JI)","keyword":"logic","range":"31:0","generic":true,"rangep": []},
{"type":"BASICDTYPE","name":"logic","addr":"(KI)","loc":"d,165:17,165:56","dtypep":"(KI)","keyword":"logic","range":"295:0","generic":true,"rangep": []},
{"type":"BASICDTYPE","name":"string","addr":"(BG)","loc":"d,165:10,165:16","dtypep":"(BG)","keyword":"string","generic":true,"rangep": []},
{"type":"BASICDTYPE","name":"logic","addr":"(Q)","loc":"e,14:9,14:11","dtypep":"(Q)","keyword":"logic","range":"31:0","generic":true,"rangep": []},
{"type":"BASICDTYPE","name":"logic","addr":"(BB)","loc":"e,18:10,18:12","dtypep":"(BB)","keyword":"logic","range":"31:0","generic":true,"rangep": []},
{"type":"BASICDTYPE","name":"logic","addr":"(MC)","loc":"e,33:26,33:31","dtypep":"(MC)","keyword":"logic","range":"31:0","generic":true,"rangep": []},

View File

@ -11,6 +11,6 @@ import vltest_bootstrap
test.scenarios('linter')
test.lint(verilator_flags2=["-DTEST_DECLARE_STD"])
test.lint(verilator_flags2=["-DTEST_DECLARE_STD"], fails=test.vlt_all) # Issue #4705 due to ::
test.passes()