From 49353784fd246f9de05212aa9a12de4826143953 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Thu, 29 Nov 2018 20:35:21 -0500 Subject: [PATCH] Fix __Slow files getting compiled with OPT_FAST, bug1370. --- Changes | 2 ++ include/verilated.mk.in | 15 ++++++---- src/V3EmitC.cpp | 9 +++--- test_regress/t/t_flag_csplit.pl | 52 ++++++++++++++++++++++++++++----- test_regress/t/t_flag_csplit.v | 14 ++++----- 5 files changed, 68 insertions(+), 24 deletions(-) diff --git a/Changes b/Changes index 06cc6c4cf..99d0f6d00 100644 --- a/Changes +++ b/Changes @@ -20,6 +20,8 @@ The contributors that suggested a given feature are shown in []. Thanks! **** Fix crash due to cygwin bug in getline, bug1349. [Affe Mao] +**** Fix __Slow files getting compiled with OPT_FAST, bug1370. [Thomas Watts] + * Verilator 4.006 2018-10-27 diff --git a/include/verilated.mk.in b/include/verilated.mk.in index c64d148f3..e80c8d7a8 100644 --- a/include/verilated.mk.in +++ b/include/verilated.mk.in @@ -167,17 +167,19 @@ $(VM_PREFIX)__ALL.a: $(VK_OBJS) ### Compile rules ifneq ($(VM_DEFAULT_RULES),0) -$(VM_PREFIX)__ALLsup.o: $(VM_PREFIX)__ALLsup.cpp - $(OBJCACHE) $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(OPT_SLOW) -c -o $@ $< - $(VM_PREFIX)__ALLcls.o: $(VM_PREFIX)__ALLcls.cpp $(OBJCACHE) $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(OPT_FAST) -c -o $@ $< -$(VM_PREFIX)%__Slow.o: $(VM_PREFIX)%__Slow.cpp +$(VM_PREFIX)__ALLsup.o: $(VM_PREFIX)__ALLsup.cpp $(OBJCACHE) $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(OPT_SLOW) -c -o $@ $< -$(VM_PREFIX)%.o: $(VM_PREFIX)%.cpp +# VM_GLOBAL_FAST files including verilated.o use this rule +%.o: %.cpp $(OBJCACHE) $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(OPT_FAST) -c -o $@ $< + +%__Slow.o: %__Slow.cpp + $(OBJCACHE) $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(OPT_SLOW) -c -o $@ $< + endif #Default rule embedded in make: @@ -189,7 +191,10 @@ endif debug-make:: @echo + @echo CXXFLAGS: $(CXXFLAGS) @echo CPPFLAGS: $(CPPFLAGS) + @echo OPT_FAST: $(OPT_FAST) + @echo OPT_SLOW: $(OPT_SLOW) @echo VM_PREFIX: $(VM_PREFIX) @echo VM_PARALLEL_BUILDS: $(VM_PARALLEL_BUILDS) @echo VM_CLASSES_FAST: $(VM_CLASSES_FAST) diff --git a/src/V3EmitC.cpp b/src/V3EmitC.cpp index a501336e1..e254d4acb 100644 --- a/src/V3EmitC.cpp +++ b/src/V3EmitC.cpp @@ -2730,10 +2730,11 @@ class EmitCTrace : EmitCStmts { // METHODS void newOutCFile(int filenum) { - string filename = (v3Global.opt.makeDir()+"/"+ topClassName() - + (m_slow?"__Trace__Slow":"__Trace")); - if (filenum) filename += "__"+cvtToStr(filenum); - filename += ".cpp"; + string filename = (v3Global.opt.makeDir()+"/"+ topClassName() + +"__Trace"); + if (filenum) filename += "__"+cvtToStr(filenum); + filename += (m_slow ? "__Slow":""); + filename += ".cpp"; AstCFile* cfilep = newCFile(filename, m_slow, true/*source*/); cfilep->support(true); diff --git a/test_regress/t/t_flag_csplit.pl b/test_regress/t/t_flag_csplit.pl index ee4a145aa..6eee47b40 100755 --- a/test_regress/t/t_flag_csplit.pl +++ b/test_regress/t/t_flag_csplit.pl @@ -10,25 +10,45 @@ if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); di scenarios(vlt_all => 1); compile( - v_flags2 => ["--trace --output-split 1 --output-split-cfuncs 1"], + v_flags2 => ["--trace --output-split 1 --output-split-cfuncs 1 --exe ../$Self->{main_filename}"], + verilator_make_gcc => 0, ); +# We don't use the standard test_regress rules, as want to test the rules +# properly build +run(logfile=>"$Self->{obj_dir}/vlt_gcc.log", + cmd=>["make", + "-C ".$Self->{obj_dir}, + "-f $Self->{VM_PREFIX}.mk", + "-j 4", + "VM_PARALLEL_BUILDS=1", # Important to this test + "VM_PREFIX=$Self->{VM_PREFIX}", + "TEST_OBJ_DIR=$Self->{obj_dir}", + "CPPFLAGS_DRIVER=-D".uc($Self->{name}), + ($opt_verbose ? "CPPFLAGS_DRIVER2=-DTEST_VERBOSE=1":""), + "OPT_FAST=-O2", + "OPT_SLOW=-O0", + ($param{make_flags}||""), + ]); + execute( check_finished => 1, ); -my $got1; -foreach my $file (glob("$Self->{obj_dir}/*.cpp")) { - $got1 = 1 if $file =~ /__1/; - check($file); +{ + my $got1; + foreach my $file (glob("$Self->{obj_dir}/*.cpp")) { + $got1 = 1 if $file =~ /__1/; + check_cpp($file); + } + $got1 or error("No __1 split file found"); } -$got1 or error("No __1 split file found"); +check_gcc_flags("$Self->{obj_dir}/vlt_gcc.log"); ok(1); 1; - -sub check { +sub check_cpp { my $filename = shift; my $size = -s $filename; printf " File %6d %s\n", $size, $filename if $Self->{verbose}; @@ -53,3 +73,19 @@ sub check { error("Split had multiple functions in $filename\n\t".join("\n\t",@funcs)); } } + +sub check_gcc_flags { + my $filename = shift; + my $fh = IO::File->new("<$filename") or error("$! $filenme"); + while (defined (my $line = $fh->getline)) { + chomp $line; + if ($line =~ /\.cpp/) { + my $filetype = ($line =~ /Slow/) ? "slow":"fast"; + my $opt = ($line !~ /-O2/) ? "slow":"fast"; + print "$filetype, $opt, $line\n"; + if ($filetype ne $opt) { + error("${filetype} file compiled as if was ${opt}: $line"); + } + } + } +} diff --git a/test_regress/t/t_flag_csplit.v b/test_regress/t/t_flag_csplit.v index 462666a9a..b90ab148d 100644 --- a/test_regress/t/t_flag_csplit.v +++ b/test_regress/t/t_flag_csplit.v @@ -9,9 +9,9 @@ module t (/*AUTOARG*/ ); input clk; - integer cyc=0; + integer cyc=0; - parameter CNT = 10; + parameter CNT = 5; wire [31:0] w [CNT:0]; @@ -33,13 +33,13 @@ module t (/*AUTOARG*/ else if (cyc<90) begin end else if (cyc==99) begin -`define EXPECTED_SUM 32'h123e +`define EXPECTED_SUM 32'h1239 `ifdef TEST_VERBOSE - $write("[%0t] cyc==%0d sum=%x\n",$time, cyc, w[CNT]); + $write("[%0t] cyc==%0d sum=%x\n",$time, cyc, w[CNT]); `endif - if (w[CNT] !== `EXPECTED_SUM) $stop; - $write("*-* All Finished *-*\n"); - $finish; + if (w[CNT] !== `EXPECTED_SUM) $stop; + $write("*-* All Finished *-*\n"); + $finish; end end