From 05e5fb04edba24b31d7c2cc0d9807081c41d91d7 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Sat, 27 Feb 2021 20:06:46 -0500 Subject: [PATCH] Fix formatting vars in protect-lib wrapper --- examples/make_protect_lib/secret_impl.v | 2 +- src/V3EmitV.cpp | 40 ++++++++++++------------- src/V3ProtectLib.cpp | 3 +- 3 files changed, 22 insertions(+), 23 deletions(-) diff --git a/examples/make_protect_lib/secret_impl.v b/examples/make_protect_lib/secret_impl.v index 1e39257f5..2a12a272c 100644 --- a/examples/make_protect_lib/secret_impl.v +++ b/examples/make_protect_lib/secret_impl.v @@ -17,7 +17,7 @@ module secret_impl logic [31:0] accum_q = 0; logic [31:0] secret_value = 9; - initial $display("%m: initialized"); + initial $display("[%0t] %m: initialized", $time); always @(posedge clk) begin accum_q <= accum_q + a; diff --git a/src/V3EmitV.cpp b/src/V3EmitV.cpp index 238341569..a79cb32d4 100644 --- a/src/V3EmitV.cpp +++ b/src/V3EmitV.cpp @@ -310,13 +310,15 @@ class EmitVBaseVisitor VL_NOT_FINAL : public EmitCBaseVisitor { } virtual void visit(AstNodeFor* nodep) override { putfs(nodep, "for ("); - m_suppressSemi = true; - iterateAndNextNull(nodep->initsp()); - puts(";"); - iterateAndNextNull(nodep->condp()); - puts(";"); - iterateAndNextNull(nodep->incsp()); - m_suppressSemi = false; + { + VL_RESTORER(m_suppressSemi); + m_suppressSemi = true; + iterateAndNextNull(nodep->initsp()); + puts(";"); + iterateAndNextNull(nodep->condp()); + puts(";"); + iterateAndNextNull(nodep->incsp()); + } puts(") begin\n"); iterateAndNextNull(nodep->bodysp()); putqs(nodep, "end\n"); @@ -381,9 +383,13 @@ class EmitVBaseVisitor VL_NOT_FINAL : public EmitCBaseVisitor { } virtual void visit(AstTextBlock* nodep) override { visit(VN_CAST(nodep, NodeSimpleText)); - for (AstNode* childp = nodep->nodesp(); childp; childp = childp->nextp()) { - iterate(childp); - if (nodep->commas() && childp->nextp()) puts(", "); + { + VL_RESTORER(m_suppressSemi); + m_suppressVarSemi = nodep->commas(); + for (AstNode* childp = nodep->nodesp(); childp; childp = childp->nextp()) { + iterate(childp); + if (nodep->commas() && childp->nextp()) puts(", "); + } } } virtual void visit(AstScopeName* nodep) override {} @@ -659,11 +665,7 @@ class EmitVBaseVisitor VL_NOT_FINAL : public EmitCBaseVisitor { puts(cvtToStr(unpackp->rangep()->rightConst())); puts("]"); } - if (!m_suppressVarSemi) { - puts(";\n"); - } else { - puts("\n"); - } + puts(m_suppressVarSemi ? "\n" : ";\n"); } virtual void visit(AstActive* nodep) override { m_sensesp = nodep->sensesp(); @@ -711,12 +713,10 @@ class EmitVFileVisitor final : public EmitVBaseVisitor { virtual void putsNoTracking(const string& str) override { ofp()->putsNoTracking(str); } public: - EmitVFileVisitor(AstNode* nodep, V3OutFile* ofp, bool trackText, bool suppressVarSemi, - bool suppressUnknown) + EmitVFileVisitor(AstNode* nodep, V3OutFile* ofp, bool trackText, bool suppressUnknown) : EmitVBaseVisitor{suppressUnknown, nullptr} { m_ofp = ofp; m_trackText = trackText; - m_suppressVarSemi = suppressVarSemi; iterate(nodep); } virtual ~EmitVFileVisitor() override = default; @@ -840,7 +840,7 @@ void V3EmitV::emitvFiles() { V3OutVFile of(vfilep->name()); of.puts("// DESCR" "IPTION: Verilator generated Verilog\n"); - EmitVFileVisitor visitor(vfilep->tblockp(), &of, true, true, false); + EmitVFileVisitor visitor(vfilep->tblockp(), &of, true, false); } } } @@ -849,5 +849,5 @@ void V3EmitV::debugEmitV(const string& stage) { UINFO(2, __FUNCTION__ << ": " << endl); string filename = v3Global.opt.makeDir() + "/" + v3Global.opt.prefix() + "__" + stage + ".v"; V3OutVFile of(filename); - EmitVFileVisitor visitor(v3Global.rootp(), &of, true, false, true); + EmitVFileVisitor visitor(v3Global.rootp(), &of, true, true); } diff --git a/src/V3ProtectLib.cpp b/src/V3ProtectLib.cpp index 2432ffada..b7327c2be 100644 --- a/src/V3ProtectLib.cpp +++ b/src/V3ProtectLib.cpp @@ -263,7 +263,7 @@ private: m_seqAssignsp = new AstTextBlock(fl, "if (last_seq_seqnum__V > " "last_combo_seqnum__V) begin\n"); txtp->addNodep(m_seqAssignsp); - m_comboAssignsp = new AstTextBlock(fl, "end else begin\n"); + m_comboAssignsp = new AstTextBlock(fl, "end\nelse begin\n"); txtp->addNodep(m_comboAssignsp); txtp->addText(fl, "end\n"); } else { @@ -437,7 +437,6 @@ private: AstVar* newVarp = new AstVar(varp->fileline(), AstVarType::VAR, varp->name() + suffix, varp->dtypep()); textp->addNodep(newVarp); - textp->addText(varp->fileline(), ";\n"); } void handleOutput(AstVar* varp) {