fix stringToInteger byte order

This commit is contained in:
Zachary Snow 2023-12-07 23:43:19 -05:00
parent e9c01d2434
commit 81d822562a
6 changed files with 33 additions and 7 deletions

View File

@ -16,6 +16,7 @@
* Fixed an issue that prevented parsing tasks and functions with `inout` ports
* Fixed conflicting genvar names when inlining interfaces and modules that use
them; all genvars are now given a design-wide unique name
* Fixed byte order of strings in size casts
* Fixed unconverted structs within explicit type casts
* Fixed unconverted multidimensional struct fields within dimension queries
* Fixed non-typenames (e.g., from packages or subsequent declarations)

View File

@ -288,9 +288,7 @@ stringToNumber str =
-- convert a string to big integer
stringToInteger :: String -> Integer
stringToInteger [] = 0
stringToInteger (x : xs) =
fromIntegral (ord x) + (256 :: Integer) * stringToInteger xs
stringToInteger = foldl ((+) . (256 *)) 0 . map (fromIntegral . ord)
-- cast string to number at least as big as the width of the given number
sizeStringAs :: String -> Number -> Expr

View File

@ -1,8 +1,12 @@
// This verifies that sv2v can evaluate certain constant expressions by
// producing iverilog-incompatible code if the expression cannot be simplified
// or is evaluated incorrectly.
`define ASSERT_TRUE(expr) if (expr) begin end else begin shortreal x; end
`define ASSERT_FALSE(expr) if (expr) begin shortreal x; end
`define ASSERT_FALSE(expr) \
if (expr) begin \
initial $display("fail"); \
shortreal x; \
end
`define ASSERT_TRUE(expr) `ASSERT_FALSE(!(expr))
module top;
`ASSERT_TRUE(1)
@ -19,8 +23,8 @@ module top;
`ASSERT_TRUE("invv" != "inv")
`ASSERT_TRUE("0inv" != "inv")
`ASSERT_TRUE(24'("inv0") == "inv")
`ASSERT_TRUE(24'("0inv") != "inv")
`ASSERT_TRUE(24'("inv0") != "inv")
`ASSERT_TRUE(24'("0inv") == "inv")
`ASSERT_FALSE("inv" == 0)
`ASSERT_FALSE("inv" == '0)
`ASSERT_FALSE('0 == "inv")

View File

@ -0,0 +1,8 @@
module top;
localparam a = "abcd";
localparam b = 64'("abcd");
logic [3:0][7:0] c = "abcd";
integer d = b; // truncate
localparam e = 32'("abcd");
`include "string_byte_order.vh"
endmodule

View File

@ -0,0 +1,8 @@
module top;
localparam a = "abcd";
localparam [63:0] b = "abcd";
reg [3:0][7:0] c = "abcd";
integer d = b; // truncate
localparam [31:0] e = "abcd";
`include "string_byte_order.vh"
endmodule

View File

@ -0,0 +1,7 @@
`define TEST(str) initial \
$display("%s %b %c %c", str, str, str[0], str[3]);
`TEST(a)
`TEST(b)
`TEST(c)
`TEST(d)
`TEST(e)