Optimize constant string arguments before Emit, and cleanup V3EmitV
This commit is contained in:
parent
eae1e5bdf2
commit
01157d414b
|
|
@ -4872,7 +4872,7 @@ public:
|
||||||
}
|
}
|
||||||
ASTGEN_MEMBERS_AstCvtPackString;
|
ASTGEN_MEMBERS_AstCvtPackString;
|
||||||
void numberOperate(V3Number& out, const V3Number& lhs) override { out.opAssign(lhs); }
|
void numberOperate(V3Number& out, const V3Number& lhs) override { out.opAssign(lhs); }
|
||||||
string emitVerilog() override { return "%f$_CAST(%l)"; }
|
string emitVerilog() override { V3ERROR_NA_RETURN(""); }
|
||||||
string emitC() override { V3ERROR_NA_RETURN(""); }
|
string emitC() override { V3ERROR_NA_RETURN(""); }
|
||||||
bool cleanOut() const override { return true; }
|
bool cleanOut() const override { return true; }
|
||||||
bool cleanLhs() const override { return true; }
|
bool cleanLhs() const override { return true; }
|
||||||
|
|
|
||||||
|
|
@ -864,7 +864,7 @@ public:
|
||||||
switch (nodep->ctlType()) {
|
switch (nodep->ctlType()) {
|
||||||
case VDumpCtlType::FILE:
|
case VDumpCtlType::FILE:
|
||||||
putns(nodep, "vlSymsp->_vm_contextp__->dumpfile(");
|
putns(nodep, "vlSymsp->_vm_contextp__->dumpfile(");
|
||||||
emitCvtPackStr(nodep->exprp());
|
iterateConst(nodep->exprp());
|
||||||
puts(");\n");
|
puts(");\n");
|
||||||
break;
|
break;
|
||||||
case VDumpCtlType::VARS:
|
case VDumpCtlType::VARS:
|
||||||
|
|
@ -927,7 +927,7 @@ public:
|
||||||
puts("(");
|
puts("(");
|
||||||
puts(cvtToStr(nodep->outp()->widthMin()));
|
puts(cvtToStr(nodep->outp()->widthMin()));
|
||||||
puts(", ");
|
puts(", ");
|
||||||
emitCvtPackStr(nodep->searchp());
|
iterateConst(nodep->searchp());
|
||||||
puts(", ");
|
puts(", ");
|
||||||
putbs("");
|
putbs("");
|
||||||
iterateAndNextConstNull(nodep->outp());
|
iterateAndNextConstNull(nodep->outp());
|
||||||
|
|
@ -935,7 +935,7 @@ public:
|
||||||
}
|
}
|
||||||
void visit(AstTestPlusArgs* nodep) override {
|
void visit(AstTestPlusArgs* nodep) override {
|
||||||
putns(nodep, "VL_TESTPLUSARGS_I(");
|
putns(nodep, "VL_TESTPLUSARGS_I(");
|
||||||
emitCvtPackStr(nodep->searchp());
|
iterateConst(nodep->searchp());
|
||||||
puts(")");
|
puts(")");
|
||||||
}
|
}
|
||||||
void visit(AstFError* nodep) override {
|
void visit(AstFError* nodep) override {
|
||||||
|
|
@ -965,16 +965,14 @@ public:
|
||||||
}
|
}
|
||||||
void visit(AstFOpen* nodep) override {
|
void visit(AstFOpen* nodep) override {
|
||||||
putns(nodep, "VL_FOPEN_NN(");
|
putns(nodep, "VL_FOPEN_NN(");
|
||||||
emitCvtPackStr(nodep->filenamep());
|
iterateConst(nodep->filenamep());
|
||||||
putbs(", ");
|
putbs(", ");
|
||||||
if (nodep->modep()->width() > 4 * 8)
|
iterateConst(nodep->modep());
|
||||||
nodep->modep()->v3error("$fopen mode should be <= 4 characters");
|
|
||||||
emitCvtPackStr(nodep->modep());
|
|
||||||
puts(");\n");
|
puts(");\n");
|
||||||
}
|
}
|
||||||
void visit(AstFOpenMcd* nodep) override {
|
void visit(AstFOpenMcd* nodep) override {
|
||||||
putns(nodep, "VL_FOPEN_MCD_N(");
|
putns(nodep, "VL_FOPEN_MCD_N(");
|
||||||
emitCvtPackStr(nodep->filenamep());
|
iterateConst(nodep->filenamep());
|
||||||
puts(");\n");
|
puts(");\n");
|
||||||
}
|
}
|
||||||
void visit(AstNodeReadWriteMem* nodep) override {
|
void visit(AstNodeReadWriteMem* nodep) override {
|
||||||
|
|
@ -1004,7 +1002,7 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
putbs(", ");
|
putbs(", ");
|
||||||
emitCvtPackStr(nodep->filenamep());
|
iterateConst(nodep->filenamep());
|
||||||
putbs(", ");
|
putbs(", ");
|
||||||
{
|
{
|
||||||
const bool need_ptr = !VN_IS(nodep->memp()->dtypep(), AssocArrayDType);
|
const bool need_ptr = !VN_IS(nodep->memp()->dtypep(), AssocArrayDType);
|
||||||
|
|
@ -1297,7 +1295,7 @@ public:
|
||||||
puts(", ");
|
puts(", ");
|
||||||
if (nodep->suffixp()) {
|
if (nodep->suffixp()) {
|
||||||
puts("true, ");
|
puts("true, ");
|
||||||
emitCvtPackStr(nodep->suffixp());
|
iterateAndNextConstNull(nodep->suffixp());
|
||||||
} else {
|
} else {
|
||||||
puts("false, \"\"");
|
puts("false, \"\"");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -283,6 +283,16 @@ class EmitVBaseVisitorConst VL_NOT_FINAL : public VNVisitorConst {
|
||||||
void visit(AstCoverInc*) override {} // N/A
|
void visit(AstCoverInc*) override {} // N/A
|
||||||
void visit(AstCoverToggle*) override {} // N/A
|
void visit(AstCoverToggle*) override {} // N/A
|
||||||
|
|
||||||
|
void visit(AstCvtPackString* nodep) override {
|
||||||
|
putfs(nodep, "");
|
||||||
|
if (AstConst* const lhsConstp = VN_CAST(nodep->lhsp(), Const)) {
|
||||||
|
putsQuoted(lhsConstp->num().toString());
|
||||||
|
} else {
|
||||||
|
puts("string'(");
|
||||||
|
iterateAndNextConstNull(nodep->lhsp());
|
||||||
|
puts(")");
|
||||||
|
}
|
||||||
|
}
|
||||||
void visit(AstTestPlusArgs* nodep) override {
|
void visit(AstTestPlusArgs* nodep) override {
|
||||||
putfs(nodep, nodep->verilogKwd());
|
putfs(nodep, nodep->verilogKwd());
|
||||||
putbs("(");
|
putbs("(");
|
||||||
|
|
@ -292,7 +302,9 @@ class EmitVBaseVisitorConst VL_NOT_FINAL : public VNVisitorConst {
|
||||||
void visit(AstValuePlusArgs* nodep) override {
|
void visit(AstValuePlusArgs* nodep) override {
|
||||||
putfs(nodep, nodep->verilogKwd());
|
putfs(nodep, nodep->verilogKwd());
|
||||||
putbs("(");
|
putbs("(");
|
||||||
iterateChildrenConst(nodep);
|
iterateConstNull(nodep->searchp());
|
||||||
|
putbs(", ");
|
||||||
|
iterateConstNull(nodep->outp());
|
||||||
puts(")");
|
puts(")");
|
||||||
}
|
}
|
||||||
void visitNodeDisplay(AstNode* nodep, AstNode* fileOrStrgp, const string& text,
|
void visitNodeDisplay(AstNode* nodep, AstNode* fileOrStrgp, const string& text,
|
||||||
|
|
|
||||||
|
|
@ -5893,17 +5893,16 @@ class WidthVisitor final : public VNVisitor {
|
||||||
}
|
}
|
||||||
void visit(AstDumpCtl* nodep) override {
|
void visit(AstDumpCtl* nodep) override {
|
||||||
assertAtStatement(nodep);
|
assertAtStatement(nodep);
|
||||||
// Just let all arguments seek their natural sizes
|
if (nodep->exprp()) iterateCheckString(nodep, "LHS", nodep->exprp(), BOTH);
|
||||||
userIterateChildren(nodep, WidthVP{SELF, BOTH}.p());
|
|
||||||
}
|
}
|
||||||
void visit(AstFOpen* nodep) override {
|
void visit(AstFOpen* nodep) override {
|
||||||
// Although a system function in IEEE, here a statement which sets the file pointer (MCD)
|
// Although a system function in IEEE, here a statement which sets the file pointer (MCD)
|
||||||
userIterateAndNext(nodep->filenamep(), WidthVP{SELF, BOTH}.p());
|
iterateCheckString(nodep, "filename", nodep->filenamep(), BOTH);
|
||||||
userIterateAndNext(nodep->modep(), WidthVP{SELF, BOTH}.p());
|
iterateCheckString(nodep, "mode", nodep->modep(), BOTH);
|
||||||
nodep->dtypeSetLogicUnsized(32, 1, VSigning::SIGNED); // Spec says integer return
|
nodep->dtypeSetLogicUnsized(32, 1, VSigning::SIGNED); // Spec says integer return
|
||||||
}
|
}
|
||||||
void visit(AstFOpenMcd* nodep) override {
|
void visit(AstFOpenMcd* nodep) override {
|
||||||
userIterateAndNext(nodep->filenamep(), WidthVP{SELF, BOTH}.p());
|
iterateCheckString(nodep, "filename", nodep->filenamep(), BOTH);
|
||||||
nodep->dtypeSetLogicUnsized(32, 1, VSigning::SIGNED); // Spec says integer return
|
nodep->dtypeSetLogicUnsized(32, 1, VSigning::SIGNED); // Spec says integer return
|
||||||
}
|
}
|
||||||
void visit(AstFClose* nodep) override {
|
void visit(AstFClose* nodep) override {
|
||||||
|
|
@ -6005,7 +6004,7 @@ class WidthVisitor final : public VNVisitor {
|
||||||
}
|
}
|
||||||
void visit(AstNodeReadWriteMem* nodep) override {
|
void visit(AstNodeReadWriteMem* nodep) override {
|
||||||
assertAtStatement(nodep);
|
assertAtStatement(nodep);
|
||||||
userIterateAndNext(nodep->filenamep(), WidthVP{SELF, BOTH}.p());
|
iterateCheckString(nodep, "filename", nodep->filenamep(), BOTH);
|
||||||
userIterateAndNext(nodep->memp(), WidthVP{SELF, BOTH}.p());
|
userIterateAndNext(nodep->memp(), WidthVP{SELF, BOTH}.p());
|
||||||
const AstNodeDType* subp = nullptr;
|
const AstNodeDType* subp = nullptr;
|
||||||
if (const AstAssocArrayDType* adtypep
|
if (const AstAssocArrayDType* adtypep
|
||||||
|
|
@ -6037,13 +6036,13 @@ class WidthVisitor final : public VNVisitor {
|
||||||
}
|
}
|
||||||
void visit(AstTestPlusArgs* nodep) override {
|
void visit(AstTestPlusArgs* nodep) override {
|
||||||
if (m_vup->prelim()) {
|
if (m_vup->prelim()) {
|
||||||
userIterateAndNext(nodep->searchp(), WidthVP{SELF, BOTH}.p());
|
iterateCheckString(nodep, "LHS", nodep->searchp(), BOTH);
|
||||||
nodep->dtypeChgWidthSigned(32, 1, VSigning::SIGNED); // Spec says integer return
|
nodep->dtypeChgWidthSigned(32, 1, VSigning::SIGNED); // Spec says integer return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void visit(AstValuePlusArgs* nodep) override {
|
void visit(AstValuePlusArgs* nodep) override {
|
||||||
if (m_vup->prelim()) {
|
if (m_vup->prelim()) {
|
||||||
userIterateAndNext(nodep->searchp(), WidthVP{SELF, BOTH}.p());
|
iterateCheckString(nodep, "LHS", nodep->searchp(), BOTH);
|
||||||
userIterateAndNext(nodep->outp(), WidthVP{SELF, BOTH}.p());
|
userIterateAndNext(nodep->outp(), WidthVP{SELF, BOTH}.p());
|
||||||
nodep->dtypeChgWidthSigned(32, 1, VSigning::SIGNED); // Spec says integer return
|
nodep->dtypeChgWidthSigned(32, 1, VSigning::SIGNED); // Spec says integer return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ module Vt_debug_emitv_t;
|
||||||
Iface the_ifaces[3:0] ();
|
Iface the_ifaces[3:0] ();
|
||||||
initial begin
|
initial begin
|
||||||
begin
|
begin
|
||||||
if ($test$plusargs(40'h48454c4c4f)) begin
|
if ($test$plusargs("HELLO")) begin
|
||||||
$display("Hello argument found.");
|
$display("Hello argument found.");
|
||||||
end
|
end
|
||||||
if ((Pkg::FOO == 'sh0)) begin
|
if ((Pkg::FOO == 'sh0)) begin
|
||||||
|
|
@ -49,7 +49,7 @@ module Vt_debug_emitv_t;
|
||||||
if ((ZERO == 'sh0)) begin
|
if ((ZERO == 'sh0)) begin
|
||||||
$write("");
|
$write("");
|
||||||
end
|
end
|
||||||
if ($value$plusargs(56'h544553543d2564i1)) begin
|
if ($value$plusargs("TEST=%d", i1)) begin
|
||||||
$display("value was %~", i1);
|
$display("value was %~", i1);
|
||||||
end
|
end
|
||||||
else begin
|
else begin
|
||||||
|
|
@ -185,10 +185,10 @@ module Vt_debug_emitv_t;
|
||||||
: $c('sh1e)));
|
: $c('sh1e)));
|
||||||
$c(;);
|
$c(;);
|
||||||
$display("%d", $c(0));
|
$display("%d", $c(0));
|
||||||
fd = $fopen(72'h2f6465762f6e756c6c);
|
fd = $fopen("/dev/null");
|
||||||
;
|
;
|
||||||
$fclose(fd);
|
$fclose(fd);
|
||||||
fd = $fopen(72'h2f6465762f6e756c6c, 8'h72);
|
fd = $fopen("/dev/null", "r");
|
||||||
;
|
;
|
||||||
$fgetc(fd);
|
$fgetc(fd);
|
||||||
$fflush(fd);
|
$fflush(fd);
|
||||||
|
|
@ -196,9 +196,9 @@ module Vt_debug_emitv_t;
|
||||||
;
|
;
|
||||||
$fdisplay(32'h69203d20, "%~", sum);
|
$fdisplay(32'h69203d20, "%~", sum);
|
||||||
$fwrite(fd, "hello");
|
$fwrite(fd, "hello");
|
||||||
$readmemh(fd, array);
|
$readmemh(string'(fd), array);
|
||||||
$readmemh(fd, array, 'sh0);
|
$readmemh(string'(fd), array, 'sh0);
|
||||||
$readmemh(fd, array, 'sh0, 'sh0);
|
$readmemh(string'(fd), array, 'sh0, 'sh0);
|
||||||
sum = 'sh0;
|
sum = 'sh0;
|
||||||
begin : unnamedblk3
|
begin : unnamedblk3
|
||||||
int signed i;
|
int signed i;
|
||||||
|
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
%Error: t/t_sys_fopen_bad.v:14:34: $fopen mode should be <= 4 characters
|
|
||||||
14 | file = $fopen("/dev/null", "somereallywidebad");
|
|
||||||
| ^~~~~~~~~~~~~~~~~~~
|
|
||||||
... See the manual at https://verilator.org/verilator_doc.html?v=latest for more assistance.
|
|
||||||
%Error: Exiting due to
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
#!/usr/bin/env python3
|
|
||||||
# DESCRIPTION: Verilator: Verilog Test driver/expect definition
|
|
||||||
#
|
|
||||||
# Copyright 2024 by Wilson Snyder. This program is free software; you
|
|
||||||
# can redistribute it and/or modify it under the terms of either the GNU
|
|
||||||
# Lesser General Public License Version 3 or the Perl Artistic License
|
|
||||||
# Version 2.0.
|
|
||||||
# SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
|
|
||||||
|
|
||||||
import vltest_bootstrap
|
|
||||||
|
|
||||||
test.scenarios('vlt')
|
|
||||||
|
|
||||||
test.lint(fails=True, expect_filename=test.golden_filename)
|
|
||||||
|
|
||||||
test.passes()
|
|
||||||
|
|
@ -1,17 +0,0 @@
|
||||||
// DESCRIPTION: Verilator: Verilog Test module
|
|
||||||
//
|
|
||||||
// Copyright 2022 by Wilson Snyder. This program is free software; you can
|
|
||||||
// redistribute it and/or modify it under the terms of either the GNU
|
|
||||||
// Lesser General Public License Version 3 or the Perl Artistic License
|
|
||||||
// Version 2.0.
|
|
||||||
// SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
|
|
||||||
|
|
||||||
module t ();
|
|
||||||
|
|
||||||
integer file;
|
|
||||||
|
|
||||||
initial begin
|
|
||||||
file = $fopen("/dev/null", "somereallywidebad");
|
|
||||||
end
|
|
||||||
|
|
||||||
endmodule
|
|
||||||
Loading…
Reference in New Issue