Commit 81d82256 by Zachary Snow

fix stringToInteger byte order

parent e9c01d24
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
* Fixed an issue that prevented parsing tasks and functions with `inout` ports * Fixed an issue that prevented parsing tasks and functions with `inout` ports
* Fixed conflicting genvar names when inlining interfaces and modules that use * Fixed conflicting genvar names when inlining interfaces and modules that use
them; all genvars are now given a design-wide unique name 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 structs within explicit type casts
* Fixed unconverted multidimensional struct fields within dimension queries * Fixed unconverted multidimensional struct fields within dimension queries
* Fixed non-typenames (e.g., from packages or subsequent declarations) * Fixed non-typenames (e.g., from packages or subsequent declarations)
......
...@@ -288,9 +288,7 @@ stringToNumber str = ...@@ -288,9 +288,7 @@ stringToNumber str =
-- convert a string to big integer -- convert a string to big integer
stringToInteger :: String -> Integer stringToInteger :: String -> Integer
stringToInteger [] = 0 stringToInteger = foldl ((+) . (256 *)) 0 . map (fromIntegral . ord)
stringToInteger (x : xs) =
fromIntegral (ord x) + (256 :: Integer) * stringToInteger xs
-- cast string to number at least as big as the width of the given number -- cast string to number at least as big as the width of the given number
sizeStringAs :: String -> Number -> Expr sizeStringAs :: String -> Number -> Expr
......
// This verifies that sv2v can evaluate certain constant expressions by // This verifies that sv2v can evaluate certain constant expressions by
// producing iverilog-incompatible code if the expression cannot be simplified // producing iverilog-incompatible code if the expression cannot be simplified
// or is evaluated incorrectly. // or is evaluated incorrectly.
`define ASSERT_TRUE(expr) if (expr) begin end else begin shortreal x; end `define ASSERT_FALSE(expr) \
`define ASSERT_FALSE(expr) if (expr) begin shortreal x; end if (expr) begin \
initial $display("fail"); \
shortreal x; \
end
`define ASSERT_TRUE(expr) `ASSERT_FALSE(!(expr))
module top; module top;
`ASSERT_TRUE(1) `ASSERT_TRUE(1)
...@@ -19,8 +23,8 @@ module top; ...@@ -19,8 +23,8 @@ module top;
`ASSERT_TRUE("invv" != "inv") `ASSERT_TRUE("invv" != "inv")
`ASSERT_TRUE("0inv" != "inv") `ASSERT_TRUE("0inv" != "inv")
`ASSERT_TRUE(24'("inv0") == "inv") `ASSERT_TRUE(24'("inv0") != "inv")
`ASSERT_TRUE(24'("0inv") != "inv") `ASSERT_TRUE(24'("0inv") == "inv")
`ASSERT_FALSE("inv" == 0) `ASSERT_FALSE("inv" == 0)
`ASSERT_FALSE("inv" == '0) `ASSERT_FALSE("inv" == '0)
`ASSERT_FALSE('0 == "inv") `ASSERT_FALSE('0 == "inv")
......
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
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
`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)
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