Commit a23c084 1 parent 388a61e commit a23c084 Copy full SHA for a23c084
File tree 4 files changed +55
-3
lines changed
testsuite/bsc.bluesim/misc
4 files changed +55
-3
lines changed Original file line number Diff line number Diff line change @@ -675,10 +675,20 @@ instance PPrint CCFragment where
675
675
pPrint d p (CPPInclude file True ) = text (" #include <" ++ file ++ " >" )
676
676
pPrint d p (CPPInclude file False ) = text (" #include \" " ++ file ++ " \" " )
677
677
pPrint d p (CIf c th Nothing ) =
678
- (text " if (" ) <> (pp c) <> (text " )" ) $+$ (printClauseOrBlock th)
678
+ -- If the true-arm is a nested if-stmt with an else-clause,
679
+ -- braces are needed to avoid ambiguous 'else'
680
+ let th' = case th of
681
+ CIf _ _ (Just _) -> CBlock [th]
682
+ _ -> th
683
+ in (text " if (" ) <> (pp c) <> (text " )" ) $+$ (printClauseOrBlock th')
679
684
pPrint d p (CIf c th (Just el)) =
680
- (text " if (" ) <> (pp c) <> (text " )" ) $+$
681
- (printClauseOrBlock th) $+$ (text " else" ) $+$ (printClauseOrBlock el)
685
+ -- If the true-arm is a nested if-stmt without an else-clause,
686
+ -- parentheses are needed to avoid ambiguous 'else'
687
+ let th' = case th of
688
+ CIf _ _ Nothing -> CBlock [th]
689
+ _ -> th
690
+ in (text " if (" ) <> (pp c) <> (text " )" ) $+$
691
+ (printClauseOrBlock th') $+$ (text " else" ) $+$ (printClauseOrBlock el)
682
692
pPrint d p (CSwitch idx arms deflt) =
683
693
let ppArm (n, blk) = (text " case" ) <+> (pp n) <> (text " :" ) $+$
684
694
nest 2 (vsep (map printStmt blk))
Original file line number Diff line number Diff line change
1
+
2
+
3
+ ActionValue # ( Bit # ( 32 )) cur_cycle = actionvalue
4
+ Bit # ( 32 ) t < - $stime ;
5
+ if ( genVerilog)
6
+ t = t + 5 ;
7
+ return t / 10 ;
8
+ endactionvalue ;
9
+
10
+ (* synthesize *)
11
+ module sysNestedIfBraces () ;
12
+
13
+ Reg # ( Bit # ( 4 )) cfg_verbosity < - mkReg ( 1 ) ;
14
+
15
+ Reg # ( Bool ) rg_state < - mkReg ( False ) ;
16
+
17
+ rule rl_display ( ! rg_state) ;
18
+ if ( cfg_verbosity != 0 )
19
+ $display ( " %0d: display" , cur_cycle) ;
20
+ rg_state <= True ;
21
+ endrule
22
+
23
+ rule rl_finish ( rg_state) ;
24
+ $finish ( 0 ) ;
25
+ endrule
26
+
27
+ endmodule
28
+
Original file line number Diff line number Diff line change @@ -90,3 +90,13 @@ compile_object_pass AVMethBDPIWithReset.bsv
90
90
copy c_func.c.keep c_func.c
91
91
link_objects_pass {} sysAVMethBDPIWithReset {c_func.c}
92
92
}
93
+
94
+ # GitHub #442: Nested if-else needs braces when possible ambiguity
95
+ # This tests "if (!RST) if (cond) e1 else e2" in the code for
96
+ # executing system tasks.
97
+ if {$ctest == 1} {
98
+ compile_object_pass NestedIfBraces.bsv
99
+ link_objects_pass {} sysNestedIfBraces
100
+ # Test that there were no warnings during C++ compilation
101
+ compare_file [make_bsc_ccomp_output_name sysNestedIfBraces]
102
+ }
Original file line number Diff line number Diff line change
1
+ Bluesim object created: sysNestedIfBraces.{h,o}
2
+ Bluesim object created: model_sysNestedIfBraces.{h,o}
3
+ Simulation shared library created: sysNestedIfBraces.cexe.so
4
+ Simulation executable created: sysNestedIfBraces.cexe
You can’t perform that action at this time.
0 commit comments