Commit 211e4b0e by Zachary Snow

fix literal casts larger than 32 bits

parent 1dfa9a9e
...@@ -66,8 +66,8 @@ traverseExprM = ...@@ -66,8 +66,8 @@ traverseExprM =
where where
str = (show size) ++ "'d" ++ (show num) str = (show size) ++ "'d" ++ (show num)
size = s' size = s'
num = if size == 32 num = if size >= 32
then n' then n' -- already read as 32 bits
else n' `mod` (2 ^ s') else n' `mod` (2 ^ s')
_ -> convertCastM (Number s) (Number n) _ -> convertCastM (Number s) (Number n)
convertExprM (orig @ (Cast (Right DimsFn{}) _)) = convertExprM (orig @ (Cast (Right DimsFn{}) _)) =
......
...@@ -207,7 +207,13 @@ readNumber ('\'' : 'h' : rest) = ...@@ -207,7 +207,13 @@ readNumber ('\'' : 'h' : rest) =
case readHex rest of case readHex rest of
[(v, _)] -> Just v [(v, _)] -> Just v
_ -> Nothing _ -> Nothing
readNumber n = readMaybe n readNumber n =
case readMaybe n of
Nothing -> Nothing
Just res ->
if show res == n
then Just res
else Nothing
showUniOpPrec :: Expr -> ShowS showUniOpPrec :: Expr -> ShowS
showUniOpPrec (e @ UniOp{}) = (showParen True . shows) e showUniOpPrec (e @ UniOp{}) = (showParen True . shows) e
......
...@@ -23,6 +23,12 @@ module top; ...@@ -23,6 +23,12 @@ module top;
$display("%0d %0d", y, ($clog2(WIDTH))'(y)); $display("%0d %0d", y, ($clog2(WIDTH))'(y));
$display("%0d %0d", z, ($clog2(WIDTH))'(z)); $display("%0d %0d", z, ($clog2(WIDTH))'(z));
$display("%b", 32'(4)); $display("%b", 32'(4));
$display("%b", 33'(4));
$display("%b", 33'(64'hFFFF_FFFF_FFFF_FFFF));
$display("%b", 32'(4294967296));
$display("%b", 33'(4294967296));
$display("%b", 32'(4294967297));
$display("%b", 33'(4294967297));
end end
localparam bit foo = '0; localparam bit foo = '0;
......
...@@ -26,6 +26,12 @@ module top; ...@@ -26,6 +26,12 @@ module top;
$display("%0d %0d", y, $signed(y[4:0])); $display("%0d %0d", y, $signed(y[4:0]));
$display("%0d %0d", z, z[4:0]); $display("%0d %0d", z, z[4:0]);
$display("%b", 32'd4); $display("%b", 32'd4);
$display("%b", 33'd4);
$display("%b", 33'h1_FFFF_FFFF);
$display("%b", 32'd0);
$display("%b", 33'd4294967296);
$display("%b", 32'd1);
$display("%b", 33'd4294967297);
end end
localparam [0:0] foo = 0; localparam [0:0] foo = 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment