mirror of https://github.com/zachjs/sv2v.git
handle size casts of string parameters
This commit is contained in:
parent
91a45ce234
commit
1de9b69efb
|
|
@ -131,9 +131,21 @@ traverseExprM other =
|
||||||
elaborateSizeCast :: Expr -> Expr -> ST Expr
|
elaborateSizeCast :: Expr -> Expr -> ST Expr
|
||||||
elaborateSizeCast size value = do
|
elaborateSizeCast size value = do
|
||||||
t <- typeof value
|
t <- typeof value
|
||||||
case typeSignedness t of
|
force <- isStringParam value
|
||||||
Unspecified -> return $ Cast (Right size) value
|
case (typeSignedness t, force) of
|
||||||
sg -> traverseExprM $ Cast (Left $ typeOfSize sg size) value
|
(Unspecified, False)-> return $ Cast (Right size) value
|
||||||
|
(sg, _) -> traverseExprM $ Cast (Left $ typeOfSize sg size) value
|
||||||
|
|
||||||
|
-- string params use a self-referential type to enable the string param
|
||||||
|
-- conversion to add a synthetic parameter if necessary; this check enables size
|
||||||
|
-- casts to assume a string parameter is unsigned regardless of its length
|
||||||
|
isStringParam :: Expr -> ST Bool
|
||||||
|
isStringParam (Ident x) = do
|
||||||
|
details <- lookupElemM x
|
||||||
|
return $ case details of
|
||||||
|
Nothing -> False
|
||||||
|
Just (_, _, typ) -> typ == TypeOf (Ident x)
|
||||||
|
isStringParam _ = return False
|
||||||
|
|
||||||
-- convert TypeOf in a Type
|
-- convert TypeOf in a Type
|
||||||
traverseTypeM :: Type -> ST Type
|
traverseTypeM :: Type -> ST Type
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,29 @@
|
||||||
|
`ifdef REF
|
||||||
|
`define TEST(size) \
|
||||||
|
begin : blk``size \
|
||||||
|
reg [size - 1:0] trim; \
|
||||||
|
trim = P; $display(`"size'(P) = %b`", trim); \
|
||||||
|
trim = L; $display(`"size'(L) = %b`", trim); \
|
||||||
|
end
|
||||||
|
`else
|
||||||
|
`define TEST(size) \
|
||||||
|
$display(`"size'(P) = %b`", size'(P)); \
|
||||||
|
$display(`"size'(L) = %b`", size'(L));
|
||||||
|
`endif
|
||||||
|
module mod;
|
||||||
|
parameter P = "asdf";
|
||||||
|
localparam L = "foobar";
|
||||||
|
initial begin
|
||||||
|
`TEST(1) `TEST(2) `TEST(3) `TEST(4) `TEST(5)
|
||||||
|
`TEST(6) `TEST(7) `TEST(8) `TEST(9) `TEST(10)
|
||||||
|
`TEST(11) `TEST(12) `TEST(13) `TEST(14) `TEST(15)
|
||||||
|
`TEST(16) `TEST(17) `TEST(18) `TEST(19) `TEST(20)
|
||||||
|
`TEST(21) `TEST(22) `TEST(23) `TEST(24) `TEST(25)
|
||||||
|
`TEST(26) `TEST(27) `TEST(28) `TEST(29) `TEST(30)
|
||||||
|
`TEST(31) `TEST(32) `TEST(33) `TEST(34) `TEST(35)
|
||||||
|
`TEST(36) `TEST(37) `TEST(38) `TEST(39) `TEST(40)
|
||||||
|
`TEST(41) `TEST(42) `TEST(43) `TEST(44) `TEST(45)
|
||||||
|
`TEST(46) `TEST(47) `TEST(48) `TEST(49) `TEST(50)
|
||||||
|
`TEST(51) `TEST(52) `TEST(53) `TEST(54) `TEST(55)
|
||||||
|
end
|
||||||
|
endmodule
|
||||||
|
|
@ -0,0 +1,2 @@
|
||||||
|
`define REF
|
||||||
|
`include "string_cast.sv"
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
module top;
|
||||||
|
mod m1();
|
||||||
|
mod #("foo") m2();
|
||||||
|
mod #("bar") m3();
|
||||||
|
mod #("foobar") m4();
|
||||||
|
endmodule
|
||||||
|
|
@ -199,4 +199,11 @@ module top;
|
||||||
`ASSERT_UNSIGNED(integer_signed[1])
|
`ASSERT_UNSIGNED(integer_signed[1])
|
||||||
`ASSERT_UNSIGNED(integer_unsigned[0])
|
`ASSERT_UNSIGNED(integer_unsigned[0])
|
||||||
`ASSERT_UNSIGNED(integer_unsigned[1])
|
`ASSERT_UNSIGNED(integer_unsigned[1])
|
||||||
|
|
||||||
|
parameter STR_P = "foo";
|
||||||
|
localparam STR_L = "foo";
|
||||||
|
`ASSERT_UNSIGNED(STR_P)
|
||||||
|
`ASSERT_UNSIGNED(STR_L)
|
||||||
|
`ASSERT_UNSIGNED(64'(STR_P))
|
||||||
|
`ASSERT_UNSIGNED(64'(STR_L))
|
||||||
endmodule
|
endmodule
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue