Skip to content

Commit e7ac592

Browse files
committed
Check for too many arg_names supplied for a method
1 parent f2607e0 commit e7ac592

File tree

4 files changed

+73
-4
lines changed

4 files changed

+73
-4
lines changed

src/Libraries/Base1/Prelude.bs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4561,15 +4561,23 @@ instance (SplitPorts a p, TupleSize p n, WrapPorts p pb, WrapMethod b v, Curry (
45614561
instance (Bits a n) => WrapMethod (ActionValue a) (ActionValue_ n) where
45624562
toWrapMethod = toActionValue_
45634563
fromWrapMethod = fromActionValue_
4564-
methodArgBaseNames _ _ _ _ = Nil
4565-
inputPortNames _ _ = Nil
4564+
methodArgBaseNames _ _ Nil _ = Nil
4565+
methodArgBaseNames prx prefix argNames _ =
4566+
primError (getEvalPosition prx) $ integerToString (listLength argNames) +++
4567+
" excess arg_names provided for method " +++ prefix
4568+
inputPortNames _ Nil = Nil
4569+
inputPortNames _ (Cons _ _) = error "inputPortNames: uncaught excess arg names"
45664570
saveMethodPortTypes _ modName _ result = primSavePortType modName result $ typeOf (_ :: a)
45674571

45684572
instance (Bits a n) => WrapMethod a (Bit n) where
45694573
toWrapMethod = pack
45704574
fromWrapMethod = unpack
4571-
methodArgBaseNames _ _ _ _ = Nil
4572-
inputPortNames _ _ = Nil
4575+
methodArgBaseNames _ _ Nil _ = Nil
4576+
methodArgBaseNames prx prefix argNames _ =
4577+
primError (getEvalPosition prx) $ integerToString (listLength argNames) +++
4578+
" excess arg_names provided for method " +++ prefix
4579+
inputPortNames _ Nil = Nil
4580+
inputPortNames _ (Cons _ _) = error "inputPortNames: uncaught excess arg names"
45734581
saveMethodPortTypes _ modName _ result = primSavePortType modName result $ typeOf (_ :: a)
45744582

45754583
{-
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package TooManyArgNames where
2+
3+
import SplitPorts
4+
import CShow
5+
6+
struct Foo =
7+
x :: Int 8
8+
y :: Int 8
9+
deriving (Bits)
10+
11+
instance (ShallowSplitPorts Foo p) => SplitPorts Foo p where
12+
splitPorts = shallowSplitPorts
13+
unsplitPorts = shallowUnsplitPorts
14+
portNames = shallowSplitPortNames
15+
16+
struct Bar =
17+
f :: Foo
18+
b :: Bool
19+
deriving (Bits)
20+
21+
instance (ShallowSplitPorts Bar p) => SplitPorts Bar p where
22+
splitPorts = shallowSplitPorts
23+
unsplitPorts = shallowUnsplitPorts
24+
portNames = shallowSplitPortNames
25+
26+
interface SplitTest =
27+
putFooBar :: Foo -> Bar -> Action {-# arg_names = ["fooIn1", "fooIn2", "fooIn3", "fooIn4"] #-}
28+
29+
{-# synthesize mkTooManyArgNamesSplitTest #-}
30+
mkTooManyArgNamesSplitTest :: Module SplitTest
31+
mkTooManyArgNamesSplitTest =
32+
module
33+
interface
34+
putFooBar x y = $display "putFooBar: " (cshow x) " " (cshow y)
35+
36+
{-# synthesize sysTooManyArgNames #-}
37+
sysTooManyArgNames :: Module Empty
38+
sysTooManyArgNames =
39+
module
40+
s <- mkTooManyArgNamesSplitTest
41+
i :: Reg (UInt 8) <- mkReg 0
42+
rules
43+
when True ==> i := i + 1
44+
when i == 0 ==> s.putFooBar (Foo { x = 5; y = 6; }) (Bar { f = Foo { x = 7; y = 8; }; b = True; })
45+
when i == 1 ==> $finish
46+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
checking package dependencies
2+
compiling TooManyArgNames.bs
3+
code generation for mkTooManyArgNamesSplitTest starts
4+
Error: "TooManyArgNames.bs", line 27, column 29: (S0015)
5+
Bluespec evaluation-time error: 2 excess arg_names provided for method
6+
putFooBar
7+
During elaboration of the interface method `putFooBar' at
8+
"TooManyArgNames.bs", line 30, column 0.
9+
During elaboration of `mkTooManyArgNamesSplitTest' at "TooManyArgNames.bs",
10+
line 30, column 0.

testsuite/bsc.verilog/splitports/splitports.exp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ if { $vtest == 1 } {
3939
find_regexp mkInstanceSplitTest.v {input \[491 : 0\] putBaz_1_c;}
4040
}
4141

42+
# Supplying an arg_names pragma that is shorter than the number of arguments
43+
# is currently supported:
4244
test_c_veri SomeArgNames
4345
if { $vtest == 1 } {
4446
find_regexp mkSomeArgNamesSplitTest.v {input \[7 : 0\] putFooBar_fooIn_x;}
@@ -48,6 +50,9 @@ if { $vtest == 1 } {
4850
find_regexp mkSomeArgNamesSplitTest.v {input putFooBar_2_b;}
4951
}
5052

53+
compile_verilog_fail_error TooManyArgNames.bs S0015
54+
compare_file TooManyArgNames.bs.bsc-vcomp-out
55+
5156
compile_verilog_fail_error PortNameConflict.bs G0055
5257
compare_file PortNameConflict.bs.bsc-vcomp-out
5358

0 commit comments

Comments
 (0)