diff --git a/src/V3Ast.h b/src/V3Ast.h index e7dd18687..18c92b0b0 100644 --- a/src/V3Ast.h +++ b/src/V3Ast.h @@ -1954,7 +1954,7 @@ public: static constexpr int INSTR_COUNT_PLI = 20; // PLI routines // ACCESSORS - virtual string name() const { return ""; } + virtual string name() const VL_MT_STABLE { return ""; } virtual string origName() const { return ""; } virtual void name(const string& name) { this->v3fatalSrc("name() called on object without name() method"); diff --git a/src/V3EmitCBase.h b/src/V3EmitCBase.h index 7067f8ed6..f5b42b8b3 100644 --- a/src/V3EmitCBase.h +++ b/src/V3EmitCBase.h @@ -66,7 +66,7 @@ public: static string topClassName() VL_MT_SAFE { // Return name of top wrapper module return v3Global.opt.prefix(); } - static string prefixNameProtect(const AstNode* nodep) { // C++ name with prefix + static string prefixNameProtect(const AstNode* nodep) VL_MT_STABLE { // C++ name with prefix return v3Global.opt.modPrefix() + "_" + VIdProtect::protect(nodep->name()); } static bool isAnonOk(const AstVar* varp) { diff --git a/src/V3EmitCImp.cpp b/src/V3EmitCImp.cpp index 8d8602957..964888a9c 100644 --- a/src/V3EmitCImp.cpp +++ b/src/V3EmitCImp.cpp @@ -577,6 +577,9 @@ class EmitCTrace final : EmitCFunc { V3UniqueNames m_uniqueNames; // For generating unique file names std::unordered_map m_enumNumMap; // EnumDType to enumeration number std::deque& m_cfilesr; // cfiles generated by this emit + V3OutCFile* m_typesFp = nullptr; // File for type declarations + int m_traceTypeSubs = 0; // Number of trace type declaration sub-functions + int m_typeSplitSize = 0; // # of cfunc nodes placed into output file // METHODS void openNextOutputFile() { @@ -610,6 +613,66 @@ class EmitCTrace final : EmitCFunc { puts("\n"); } + V3OutCFile* typesFp() const VL_MT_SAFE { return m_typesFp; } + + void openNextTypesFile() { + UASSERT(!m_typesFp, "Declarations output file already open"); + + string filename + = (v3Global.opt.makeDir() + "/" + topClassName() + "_" + protect("_TraceDecls")); + filename = m_uniqueNames.get(filename); + filename += "__Slow.cpp"; + + AstCFile* const cfilep = createCFile(filename, m_slow, true /*source*/); + cfilep->support(true); + m_cfilesr.push_back(cfilep); + + if (optSystemC()) { + m_typesFp = new V3OutScFile{filename}; + } else { + m_typesFp = new V3OutCFile{filename}; + } + typesFp()->putsHeader(); + typesFp()->puts("// DESCR" + "IPTION: Verilator output: Tracing declarations\n"); + + // Includes + typesFp()->puts("#include \"" + v3Global.opt.traceSourceLang() + ".h\"\n"); + typesFp()->puts("\n"); + + typesFp()->puts("\nvoid " + prefixNameProtect(m_modp) + "__" + + protect("traceDeclTypesSub" + cvtToStr(m_traceTypeSubs++)) + "(" + + v3Global.opt.traceClassBase() + "* tracep) {\n"); + } + + void closeTypesFile() { + typesFp()->puts("}\n"); + VL_DO_CLEAR(delete m_typesFp, m_typesFp = nullptr); + } + + void callTypeSubs() { + typesFp()->puts("}\n"); + + // Forward declarations for subs in other files + for (int i = 0; i < m_traceTypeSubs - 1; ++i) { + typesFp()->puts("void " + prefixNameProtect(m_modp) + "__" + + protect("traceDeclTypesSub" + cvtToStr(i)) + "(" + + v3Global.opt.traceClassBase() + "* tracep);\n"); + } + + typesFp()->puts("\nvoid " + prefixNameProtect(m_modp) + "__" + protect("trace_decl_types") + + "(" + v3Global.opt.traceClassBase() + "* tracep) {\n"); + for (int i = 0; i < m_traceTypeSubs; ++i) { + typesFp()->puts(prefixNameProtect(m_modp) + "__" + + protect("traceDeclTypesSub" + cvtToStr(i)) + "(tracep);\n"); + } + } + + bool typesSplitNeeded() { + return v3Global.opt.outputSplitCTrace() + && m_typeSplitSize >= v3Global.opt.outputSplitCTrace(); + } + bool emitTraceIsScBv(AstTraceInc* nodep) { const AstVarRef* const varrefp = VN_CAST(nodep->declp()->valuep(), VarRef); if (!varrefp) return false; @@ -697,43 +760,54 @@ class EmitCTrace final : EmitCFunc { puts(");"); } + int getEnumMapNum(AstEnumDType* nodep) { + int enumNum = m_enumNumMap[nodep]; + if (!enumNum) { + if (typesSplitNeeded()) { + // Splitting file, so using parallel build. + v3Global.useParallelBuild(true); + closeTypesFile(); + openNextTypesFile(); + } + enumNum = ++m_enumNum; + m_enumNumMap[nodep] = enumNum; + int nvals = 0; + typesFp()->puts("{\n"); + typesFp()->puts("const char* " + protect("__VenumItemNames") + "[]\n"); + typesFp()->puts("= {"); + for (AstEnumItem* itemp = nodep->itemsp(); itemp; + itemp = VN_AS(itemp->nextp(), EnumItem)) { + if (++nvals > 1) typesFp()->puts(", "); + typesFp()->putbs("\"" + itemp->prettyName() + "\""); + } + typesFp()->puts("};\n"); + nvals = 0; + typesFp()->puts("const char* " + protect("__VenumItemValues") + "[]\n"); + typesFp()->puts("= {"); + for (AstEnumItem* itemp = nodep->itemsp(); itemp; + itemp = VN_AS(itemp->nextp(), EnumItem)) { + AstConst* const constp = VN_AS(itemp->valuep(), Const); + if (++nvals > 1) typesFp()->puts(", "); + typesFp()->putbs("\"" + constp->num().displayed(nodep, "%0b") + "\""); + } + typesFp()->puts("};\n"); + typesFp()->puts("tracep->declDTypeEnum(" + cvtToStr(enumNum) + ", \"" + + nodep->prettyName() + "\", " + cvtToStr(nvals) + ", " + + cvtToStr(nodep->widthMin()) + ", " + protect("__VenumItemNames") + + ", " + protect("__VenumItemValues") + ");\n"); + typesFp()->puts("}\n"); + m_typeSplitSize += 3; + } + return enumNum; + } + int emitTraceDeclDType(AstNodeDType* nodep) { // Return enum number or -1 for none if (v3Global.opt.traceFormat().fst()) { // Skip over refs-to-refs, but stop before final ref so can get data type name // Alternatively back in V3Width we could push enum names from upper typedefs if (AstEnumDType* const enump = VN_CAST(nodep->skipRefToEnump(), EnumDType)) { - int enumNum = m_enumNumMap[enump]; - if (!enumNum) { - enumNum = ++m_enumNum; - m_enumNumMap[enump] = enumNum; - int nvals = 0; - puts("{\n"); - puts("const char* " + protect("__VenumItemNames") + "[]\n"); - puts("= {"); - for (AstEnumItem* itemp = enump->itemsp(); itemp; - itemp = VN_AS(itemp->nextp(), EnumItem)) { - if (++nvals > 1) puts(", "); - putbs("\"" + itemp->prettyName() + "\""); - } - puts("};\n"); - nvals = 0; - puts("const char* " + protect("__VenumItemValues") + "[]\n"); - puts("= {"); - for (AstEnumItem* itemp = enump->itemsp(); itemp; - itemp = VN_AS(itemp->nextp(), EnumItem)) { - AstConst* const constp = VN_AS(itemp->valuep(), Const); - if (++nvals > 1) puts(", "); - putbs("\"" + constp->num().displayed(nodep, "%0b") + "\""); - } - puts("};\n"); - puts("tracep->declDTypeEnum(" + cvtToStr(enumNum) + ", \"" - + enump->prettyName() + "\", " + cvtToStr(nvals) + ", " - + cvtToStr(enump->widthMin()) + ", " + protect("__VenumItemNames") + ", " - + protect("__VenumItemValues") + ");\n"); - puts("}\n"); - } - return enumNum; + return getEnumMapNum(enump); } } return -1; @@ -869,12 +943,17 @@ class EmitCTrace final : EmitCFunc { m_modp = modp; // Open output file openNextOutputFile(); + if (m_slow) openNextTypesFile(); // Emit functions for (AstNode* nodep = modp->stmtsp(); nodep; nodep = nodep->nextp()) { if (AstCFunc* const funcp = VN_CAST(nodep, CFunc)) { iterateConst(funcp); } } // Close output file VL_DO_CLEAR(delete m_ofp, m_ofp = nullptr); + if (m_slow) { + callTypeSubs(); + closeTypesFile(); + } } ~EmitCTrace() override = default; diff --git a/src/V3EmitCModel.cpp b/src/V3EmitCModel.cpp index 326aa21a9..beadfabc0 100644 --- a/src/V3EmitCModel.cpp +++ b/src/V3EmitCModel.cpp @@ -498,6 +498,8 @@ class EmitCModel final : public EmitCFunc { putSectionDelimiter("Trace configuration"); // Forward declaration + puts("\nvoid " + topModNameProtected + "__" + protect("trace_decl_types") + "(" + + v3Global.opt.traceClassBase() + "* tracep);\n"); puts("\nvoid " + topModNameProtected + "__" + protect("trace_init_top") + "(" + topModNameProtected + "* vlSelf, " + v3Global.opt.traceClassBase() + "* tracep);\n"); @@ -516,6 +518,7 @@ class EmitCModel final : public EmitCFunc { puts("vlSymsp->__Vm_baseCode = code;\n"); puts("tracep->pushPrefix(std::string{vlSymsp->name()}, " "VerilatedTracePrefixType::SCOPE_MODULE);\n"); + puts(topModNameProtected + "__" + protect("trace_decl_types") + "(tracep);\n"); puts(topModNameProtected + "__" + protect("trace_init_top") + "(vlSelf, tracep);\n"); puts("tracep->popPrefix();\n"); puts("}\n"); diff --git a/src/V3Options.h b/src/V3Options.h index 77b5e5e8d..7a4a8cd97 100644 --- a/src/V3Options.h +++ b/src/V3Options.h @@ -143,7 +143,7 @@ public: constexpr operator en() const { return m_e; } bool fst() const { return m_e == FST; } bool vcd() const { return m_e == VCD; } - string classBase() const { + string classBase() const VL_MT_SAFE { static const char* const names[] = {"VerilatedVcd", "VerilatedFst"}; return names[m_e]; } @@ -643,7 +643,7 @@ public: bool fTable() const { return m_fTable; } bool fTaskifyAll() const { return m_fTaskifyAll; } - string traceClassBase() const { return m_traceFormat.classBase(); } + string traceClassBase() const VL_MT_SAFE { return m_traceFormat.classBase(); } string traceClassLang() const { return m_traceFormat.classBase() + (systemC() ? "Sc" : "C"); } string traceSourceBase() const { return m_traceFormat.sourceName(); } string traceSourceLang() const VL_MT_SAFE { diff --git a/test_regress/driver.pl b/test_regress/driver.pl index 4685a066d..c26d0b112 100755 --- a/test_regress/driver.pl +++ b/test_regress/driver.pl @@ -2492,6 +2492,20 @@ sub file_grep { } } +sub file_grep_count { + my $self = (ref $_[0] ? shift : $Self); + my $filename = shift; + my $regexp = shift; + my $expcount = shift; + return if $self->errors || $self->skips; + + my $contents = $self->file_contents($filename); + my $count = () = $contents =~ /$regexp/g; + if ($count != $expcount) { + $self->error("file_grep_count: $filename: Got='$count' Expected='$expcount' for regexp: $regexp\n"); + } +} + sub file_grep_any { my $self = $Self; my @filenames = @{$_[0]}; shift; diff --git a/test_regress/t/t_trace_complex_fst.out b/test_regress/t/t_trace_complex_fst.out index 39236fad4..d4ca2fffa 100644 --- a/test_regress/t/t_trace_complex_fst.out +++ b/test_regress/t/t_trace_complex_fst.out @@ -1,5 +1,5 @@ $date - Tue Oct 24 11:00:03 2023 + Thu Dec 14 09:06:44 2023 $end $version @@ -9,6 +9,8 @@ $timescale 1ps $end $scope module top $end +$attrbegin misc 07 t.enumed_t 4 ZERO ONE TWO THREE 00000000000000000000000000000000 00000000000000000000000000000001 00000000000000000000000000000010 00000000000000000000000000000011 1 $end +$attrbegin misc 07 t.enumb_t 4 BZERO BONE BTWO BTHREE 000 001 010 011 2 $end $scope module $unit $end $var bit 1 ! global_bit $end $upscope $end @@ -36,12 +38,10 @@ $var real 64 4 v_real $end $var real 64 5 v_arr_real[0] $end $var real 64 6 v_arr_real[1] $end $var logic 64 7 v_str32x2 [63:0] $end -$attrbegin misc 07 t.enumed_t 4 ZERO ONE TWO THREE 00000000000000000000000000000000 00000000000000000000000000000001 00000000000000000000000000000010 00000000000000000000000000000011 1 $end $attrbegin misc 07 "" 1 $end $var int 32 8 v_enumed [31:0] $end $attrbegin misc 07 "" 1 $end $var int 32 9 v_enumed2 [31:0] $end -$attrbegin misc 07 t.enumb_t 4 BZERO BONE BTWO BTHREE 000 001 010 011 2 $end $attrbegin misc 07 "" 2 $end $var logic 3 : v_enumb [2:0] $end $var logic 6 ; v_enumb2_str [5:0] $end @@ -67,8 +67,8 @@ $upscope $end $upscope $end $upscope $end $enddefinitions $end -#0 $dumpvars +#0 b00000000000000000000000000000000 D b00000000000000000000000000000000 C b00000000000000000000000000000011 B @@ -105,7 +105,6 @@ b00 $ b00000000000000000000000000000000 # 0" 1! -$end #10 1" b00000000000000000000000000000001 # diff --git a/test_regress/t/t_trace_complex_fst_sc.out b/test_regress/t/t_trace_complex_fst_sc.out index ceef7646a..9cb3b3fdd 100644 --- a/test_regress/t/t_trace_complex_fst_sc.out +++ b/test_regress/t/t_trace_complex_fst_sc.out @@ -1,5 +1,5 @@ $date - Tue Oct 24 11:09:24 2023 + Thu Dec 14 10:34:23 2023 $end $version @@ -9,6 +9,8 @@ $timescale 1ps $end $scope module top $end +$attrbegin misc 07 t.enumed_t 4 ZERO ONE TWO THREE 00000000000000000000000000000000 00000000000000000000000000000001 00000000000000000000000000000010 00000000000000000000000000000011 1 $end +$attrbegin misc 07 t.enumb_t 4 BZERO BONE BTWO BTHREE 000 001 010 011 2 $end $scope module $unit $end $var bit 1 ! global_bit $end $upscope $end @@ -35,12 +37,10 @@ $var real 64 4 v_real $end $var real 64 5 v_arr_real[0] $end $var real 64 6 v_arr_real[1] $end $var logic 64 7 v_str32x2 [63:0] $end -$attrbegin misc 07 t.enumed_t 4 ZERO ONE TWO THREE 00000000000000000000000000000000 00000000000000000000000000000001 00000000000000000000000000000010 00000000000000000000000000000011 1 $end $attrbegin misc 07 "" 1 $end $var int 32 8 v_enumed [31:0] $end $attrbegin misc 07 "" 1 $end $var int 32 9 v_enumed2 [31:0] $end -$attrbegin misc 07 t.enumb_t 4 BZERO BONE BTWO BTHREE 000 001 010 011 2 $end $attrbegin misc 07 "" 2 $end $var logic 3 : v_enumb [2:0] $end $var logic 6 ; v_enumb2_str [5:0] $end @@ -66,8 +66,8 @@ $upscope $end $upscope $end $upscope $end $enddefinitions $end -#0 $dumpvars +#0 b00000000000000000000000000000000 D b00000000000000000000000000000000 C b00000000000000000000000000000011 B @@ -104,7 +104,6 @@ b00 $ b00000000000000000000000000000000 # 0" 1! -$end #10 1" b00000000000000000000000000000001 # diff --git a/test_regress/t/t_trace_complex_params_fst.out b/test_regress/t/t_trace_complex_params_fst.out index 803d49c16..b212749f5 100644 --- a/test_regress/t/t_trace_complex_params_fst.out +++ b/test_regress/t/t_trace_complex_params_fst.out @@ -1,5 +1,5 @@ $date - Tue Oct 24 11:02:57 2023 + Thu Dec 14 09:16:48 2023 $end $version @@ -9,6 +9,8 @@ $timescale 1ps $end $scope module top $end +$attrbegin misc 07 t.enumed_t 4 ZERO ONE TWO THREE 00000000000000000000000000000000 00000000000000000000000000000001 00000000000000000000000000000010 00000000000000000000000000000011 1 $end +$attrbegin misc 07 t.enumb_t 4 BZERO BONE BTWO BTHREE 000 001 010 011 2 $end $scope module $unit $end $var bit 1 ! global_bit $end $upscope $end @@ -36,12 +38,10 @@ $var real 64 4 v_real $end $var real 64 5 v_arr_real[0] $end $var real 64 6 v_arr_real[1] $end $var logic 64 7 v_str32x2 [63:0] $end -$attrbegin misc 07 t.enumed_t 4 ZERO ONE TWO THREE 00000000000000000000000000000000 00000000000000000000000000000001 00000000000000000000000000000010 00000000000000000000000000000011 1 $end $attrbegin misc 07 "" 1 $end $var int 32 8 v_enumed [31:0] $end $attrbegin misc 07 "" 1 $end $var int 32 9 v_enumed2 [31:0] $end -$attrbegin misc 07 t.enumb_t 4 BZERO BONE BTWO BTHREE 000 001 010 011 2 $end $attrbegin misc 07 "" 2 $end $var logic 3 : v_enumb [2:0] $end $var logic 6 ; v_enumb2_str [5:0] $end @@ -67,8 +67,8 @@ $upscope $end $upscope $end $upscope $end $enddefinitions $end -#0 $dumpvars +#0 b00000000000000000000000000000000 D b00000000000000000000000000000000 C b00000000000000000000000000000011 B @@ -105,7 +105,6 @@ b00 $ b00000000000000000000000000000000 # 0" 1! -$end #10 1" b00000000000000000000000000000001 # diff --git a/test_regress/t/t_trace_complex_params_fst_sc.out b/test_regress/t/t_trace_complex_params_fst_sc.out index 46e0911c9..f05ce81a0 100644 --- a/test_regress/t/t_trace_complex_params_fst_sc.out +++ b/test_regress/t/t_trace_complex_params_fst_sc.out @@ -1,5 +1,5 @@ $date - Tue Oct 24 11:09:58 2023 + Thu Dec 14 10:35:10 2023 $end $version @@ -9,6 +9,8 @@ $timescale 1ps $end $scope module top $end +$attrbegin misc 07 t.enumed_t 4 ZERO ONE TWO THREE 00000000000000000000000000000000 00000000000000000000000000000001 00000000000000000000000000000010 00000000000000000000000000000011 1 $end +$attrbegin misc 07 t.enumb_t 4 BZERO BONE BTWO BTHREE 000 001 010 011 2 $end $scope module $unit $end $var bit 1 ! global_bit $end $upscope $end @@ -35,12 +37,10 @@ $var real 64 4 v_real $end $var real 64 5 v_arr_real[0] $end $var real 64 6 v_arr_real[1] $end $var logic 64 7 v_str32x2 [63:0] $end -$attrbegin misc 07 t.enumed_t 4 ZERO ONE TWO THREE 00000000000000000000000000000000 00000000000000000000000000000001 00000000000000000000000000000010 00000000000000000000000000000011 1 $end $attrbegin misc 07 "" 1 $end $var int 32 8 v_enumed [31:0] $end $attrbegin misc 07 "" 1 $end $var int 32 9 v_enumed2 [31:0] $end -$attrbegin misc 07 t.enumb_t 4 BZERO BONE BTWO BTHREE 000 001 010 011 2 $end $attrbegin misc 07 "" 2 $end $var logic 3 : v_enumb [2:0] $end $var logic 6 ; v_enumb2_str [5:0] $end @@ -66,8 +66,8 @@ $upscope $end $upscope $end $upscope $end $enddefinitions $end -#0 $dumpvars +#0 b00000000000000000000000000000000 D b00000000000000000000000000000000 C b00000000000000000000000000000011 B @@ -104,7 +104,6 @@ b00 $ b00000000000000000000000000000000 # 0" 1! -$end #10 1" b00000000000000000000000000000001 # diff --git a/test_regress/t/t_trace_complex_structs_fst.out b/test_regress/t/t_trace_complex_structs_fst.out index 81ae0ea36..e3ded82e6 100644 --- a/test_regress/t/t_trace_complex_structs_fst.out +++ b/test_regress/t/t_trace_complex_structs_fst.out @@ -1,5 +1,5 @@ $date - Tue Oct 24 11:01:27 2023 + Thu Dec 14 09:17:16 2023 $end $version @@ -9,6 +9,8 @@ $timescale 1ps $end $scope module top $end +$attrbegin misc 07 t.enumed_t 4 ZERO ONE TWO THREE 00000000000000000000000000000000 00000000000000000000000000000001 00000000000000000000000000000010 00000000000000000000000000000011 1 $end +$attrbegin misc 07 t.enumb_t 4 BZERO BONE BTWO BTHREE 000 001 010 011 2 $end $scope module $unit $end $var bit 1 ! global_bit $end $upscope $end @@ -76,12 +78,10 @@ $upscope $end $scope struct v_str32x2[1] $end $var logic 32 C data [31:0] $end $upscope $end -$attrbegin misc 07 t.enumed_t 4 ZERO ONE TWO THREE 00000000000000000000000000000000 00000000000000000000000000000001 00000000000000000000000000000010 00000000000000000000000000000011 1 $end $attrbegin misc 07 "" 1 $end $var int 32 D v_enumed [31:0] $end $attrbegin misc 07 "" 1 $end $var int 32 E v_enumed2 [31:0] $end -$attrbegin misc 07 t.enumb_t 4 BZERO BONE BTWO BTHREE 000 001 010 011 2 $end $attrbegin misc 07 "" 2 $end $var logic 3 F v_enumb [2:0] $end $scope struct v_enumb2_str $end @@ -103,8 +103,8 @@ $upscope $end $upscope $end $upscope $end $enddefinitions $end -#0 $dumpvars +#0 b00000000000000000000000000000000 N b00000000000000000000000000000000 M 0L @@ -151,7 +151,6 @@ b00 , b00000000000000000000000000000000 # 0" 1! -$end #10 1" b00000000000000000000000000000001 # diff --git a/test_regress/t/t_trace_complex_structs_fst_sc.out b/test_regress/t/t_trace_complex_structs_fst_sc.out index 8bfcf9b29..05920c5f0 100644 --- a/test_regress/t/t_trace_complex_structs_fst_sc.out +++ b/test_regress/t/t_trace_complex_structs_fst_sc.out @@ -1,5 +1,5 @@ $date - Tue Oct 24 11:01:32 2023 + Thu Dec 14 10:35:37 2023 $end $version @@ -9,6 +9,8 @@ $timescale 1ps $end $scope module top $end +$attrbegin misc 07 t.enumed_t 4 ZERO ONE TWO THREE 00000000000000000000000000000000 00000000000000000000000000000001 00000000000000000000000000000010 00000000000000000000000000000011 1 $end +$attrbegin misc 07 t.enumb_t 4 BZERO BONE BTWO BTHREE 000 001 010 011 2 $end $scope module $unit $end $var bit 1 ! global_bit $end $upscope $end @@ -75,12 +77,10 @@ $upscope $end $scope struct v_str32x2[1] $end $var logic 32 C data [31:0] $end $upscope $end -$attrbegin misc 07 t.enumed_t 4 ZERO ONE TWO THREE 00000000000000000000000000000000 00000000000000000000000000000001 00000000000000000000000000000010 00000000000000000000000000000011 1 $end $attrbegin misc 07 "" 1 $end $var int 32 D v_enumed [31:0] $end $attrbegin misc 07 "" 1 $end $var int 32 E v_enumed2 [31:0] $end -$attrbegin misc 07 t.enumb_t 4 BZERO BONE BTWO BTHREE 000 001 010 011 2 $end $attrbegin misc 07 "" 2 $end $var logic 3 F v_enumb [2:0] $end $scope struct v_enumb2_str $end @@ -102,8 +102,8 @@ $upscope $end $upscope $end $upscope $end $enddefinitions $end -#0 $dumpvars +#0 b00000000000000000000000000000000 N b00000000000000000000000000000000 M 0L @@ -150,7 +150,6 @@ b00 , b00000000000000000000000000000000 # 0" 1! -$end #10 1" b00000000000000000000000000000001 # diff --git a/test_regress/t/t_trace_enum.v b/test_regress/t/t_trace_enum.v new file mode 100644 index 000000000..2e4e7005a --- /dev/null +++ b/test_regress/t/t_trace_enum.v @@ -0,0 +1,27 @@ +// DESCRIPTION: Verilator: Verilog Test module +// +// This file ONLY is placed under the Creative Commons Public Domain, for +// any use, without warranty, 2009 by Wilson Snyder. +// SPDX-License-Identifier: CC0-1.0 + +typedef enum logic [1:0] {VAL_A, VAL_B, VAL_C, VAL_D} state_t; + +interface MyIntf; + state_t state; +endinterface + + +module t (clk); + input clk; + + MyIntf #() sink (); + state_t v_enumed; + + typedef enum logic [1:0] {VAL_X, VAL_Y, VAL_Z} other_state_t; + other_state_t v_other_enumed; + + always @ (posedge clk) begin + $write("*-* All Finished *-*\n"); + $finish; + end +endmodule diff --git a/test_regress/t/t_trace_enum_fst.out b/test_regress/t/t_trace_enum_fst.out new file mode 100644 index 000000000..c13e7b815 --- /dev/null +++ b/test_regress/t/t_trace_enum_fst.out @@ -0,0 +1,35 @@ +$date + Tue Dec 19 07:15:22 2023 + +$end +$version + fstWriter +$end +$timescale + 1ps +$end +$scope module top $end +$attrbegin misc 07 $unit::state_t 4 VAL_A VAL_B VAL_C VAL_D 00 01 10 11 1 $end +$attrbegin misc 07 t.other_state_t 3 VAL_X VAL_Y VAL_Z 00 01 10 2 $end +$var wire 1 ! clk $end +$scope module t $end +$var wire 1 ! clk $end +$scope interface sink $end +$attrbegin misc 07 "" 1 $end +$var logic 2 " state [1:0] $end +$upscope $end +$attrbegin misc 07 "" 1 $end +$var logic 2 # v_enumed [1:0] $end +$attrbegin misc 07 "" 2 $end +$var logic 2 $ v_other_enumed [1:0] $end +$upscope $end +$upscope $end +$enddefinitions $end +$dumpvars +#0 +b00 $ +b00 # +b00 " +0! +#10 +1! diff --git a/test_regress/t/t_trace_enum_fst.pl b/test_regress/t/t_trace_enum_fst.pl new file mode 100755 index 000000000..d59b6459d --- /dev/null +++ b/test_regress/t/t_trace_enum_fst.pl @@ -0,0 +1,34 @@ +#!/usr/bin/env perl +if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); die; } +# DESCRIPTION: Verilator: Verilog Test driver/expect definition +# +# Copyright 2003-2009 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 + +scenarios(simulator => 1); + +top_filename("t/t_trace_enum.v"); + +compile( + verilator_flags2 => ['--cc --trace-fst --output-split-ctrace 1'], + ); + +execute( + check_finished => 1, + ); + +fst_identical($Self->trace_filename, $Self->{golden_filename}); + +# Five $attrbegin expected: +# - state_t declaration +# - t.v_enumed +# - t.sink.state +# - other_state_t declaration +# - t.v_other_enumed +file_grep_count($Self->{golden_filename}, qr/attrbegin/, 5); + +ok(1); +1;