mirror of https://github.com/zachjs/sv2v.git
fix typeof bounds for part selects
- split out typeof handling of part selects - account for directionality of base dimension - refactor dimensions test case with detailed output
This commit is contained in:
parent
5c8d838eef
commit
8eb9523d06
|
|
@ -18,7 +18,7 @@ module Convert.TypeOf (convert) where
|
|||
import Data.Tuple (swap)
|
||||
import qualified Data.Map.Strict as Map
|
||||
|
||||
import Convert.ExprUtils (simplify)
|
||||
import Convert.ExprUtils (endianCondRange, simplify)
|
||||
import Convert.Scoper
|
||||
import Convert.Traverse
|
||||
import Language.SystemVerilog.AST
|
||||
|
|
@ -122,19 +122,27 @@ typeof (orig @ (Bit e _)) = do
|
|||
TypeOf{} -> lookupTypeOf orig
|
||||
Alias{} -> return $ TypeOf orig
|
||||
_ -> return $ typeSignednessOverride t' Unsigned t'
|
||||
typeof (orig @ (Range e mode r)) = do
|
||||
typeof (orig @ (Range e NonIndexed r)) = do
|
||||
t <- typeof e
|
||||
let t' = replaceRange (lo, hi) t
|
||||
let t' = replaceRange r t
|
||||
return $ case t of
|
||||
TypeOf{} -> TypeOf orig
|
||||
Alias{} -> TypeOf orig
|
||||
_ -> typeSignednessOverride t' Unsigned t'
|
||||
typeof (Range expr mode (base, len)) =
|
||||
typeof $ Range expr NonIndexed $
|
||||
endianCondRange index (base, end) (end, base)
|
||||
where
|
||||
lo = fst r
|
||||
hi = case mode of
|
||||
NonIndexed -> snd r
|
||||
IndexedPlus -> BinOp Sub (uncurry (BinOp Add) r) (RawNum 1)
|
||||
IndexedMinus -> BinOp Add (uncurry (BinOp Sub) r) (RawNum 1)
|
||||
index =
|
||||
if mode == IndexedPlus
|
||||
then (boundR, boundL)
|
||||
else (boundL, boundR)
|
||||
boundL = DimFn FnLeft (Left $ TypeOf expr) (RawNum 1)
|
||||
boundR = DimFn FnRight (Left $ TypeOf expr) (RawNum 1)
|
||||
end =
|
||||
if mode == IndexedPlus
|
||||
then BinOp Sub (BinOp Add base len) (RawNum 1)
|
||||
else BinOp Add (BinOp Sub base len) (RawNum 1)
|
||||
typeof (orig @ (Dot e x)) = do
|
||||
t <- typeof e
|
||||
case t of
|
||||
|
|
|
|||
|
|
@ -1,17 +1,26 @@
|
|||
`define EXHAUST(t) \
|
||||
$display($size(t), $size(t,1), $size(t,2)); \
|
||||
$display($left(t), $left(t,1), $left(t,2)); \
|
||||
$display($right(t), $right(t,1), $right(t,2)); \
|
||||
$display($high(t), $high(t,1), $high(t,2)); \
|
||||
$display($low(t), $low(t,1), $low(t,2)); \
|
||||
$display($increment(t), $increment(t,1), $increment(t,2)); \
|
||||
$display($dimensions(t)); \
|
||||
$display($unpacked_dimensions(t)); \
|
||||
$display($bits(t));
|
||||
`define DUMP_DIM(typ, dim) \
|
||||
$display(" $size %0d", $size (typ, dim)); \
|
||||
$display(" $left %0d", $left (typ, dim)); \
|
||||
$display(" $right %0d", $right (typ, dim)); \
|
||||
$display(" $high %0d", $high (typ, dim)); \
|
||||
$display(" $low %0d", $low (typ, dim)); \
|
||||
$display(" $increment %0d", $increment(typ, dim));
|
||||
|
||||
`define EXHAUST(typ) \
|
||||
$display(`"Dumping info for typ`"); \
|
||||
$display(" $dimensions %0d", $dimensions(typ)); \
|
||||
$display(" $unpacked_dimensions %0d", $unpacked_dimensions(typ)); \
|
||||
$display(" $bits %0d", $bits(typ)); \
|
||||
$display(" 1st dimension"); \
|
||||
`DUMP_DIM(typ, 1) \
|
||||
$display(" 2nd dimension"); \
|
||||
`DUMP_DIM(typ, 2)
|
||||
|
||||
module top;
|
||||
typedef logic [16:1] Word;
|
||||
Word Ram[0:9];
|
||||
typedef logic [1:16] WordFlip;
|
||||
WordFlip RamFlip[9:0];
|
||||
type(Ram) RamPair [2];
|
||||
integer ints [3:0];
|
||||
integer ints_rev [0:3];
|
||||
|
|
@ -39,12 +48,26 @@ module top;
|
|||
`EXHAUST($signed(Ram[0]));
|
||||
`EXHAUST(Ram[0+:2]);
|
||||
`EXHAUST(Ram[1+:2]);
|
||||
`EXHAUST(Ram[2-:2]);
|
||||
`EXHAUST(Ram[3-:2]);
|
||||
`EXHAUST(Ram[0][2-:1]);
|
||||
`EXHAUST(Ram[0][2-:2]);
|
||||
|
||||
`EXHAUST(RamFlip);
|
||||
`EXHAUST(RamFlip[0]);
|
||||
`EXHAUST($unsigned(RamFlip[0]));
|
||||
`EXHAUST($signed(RamFlip[0]));
|
||||
`EXHAUST(RamFlip[0+:2]);
|
||||
`EXHAUST(RamFlip[1+:2]);
|
||||
`EXHAUST(RamFlip[2-:2]);
|
||||
`EXHAUST(RamFlip[3-:2]);
|
||||
`EXHAUST(RamFlip[0][2-:1]);
|
||||
`EXHAUST(RamFlip[0][2-:2]);
|
||||
|
||||
`EXHAUST(RamPair);
|
||||
`EXHAUST(RamPair[0]);
|
||||
`EXHAUST(Word);
|
||||
`EXHAUST(integer);
|
||||
`EXHAUST(bit);
|
||||
`EXHAUST(byte);
|
||||
`EXHAUST(ints);
|
||||
`EXHAUST(ints_rev);
|
||||
|
|
@ -54,5 +77,7 @@ module top;
|
|||
`EXHAUST(type(ints[2][3:0]));
|
||||
`EXHAUST(type(ints[1:0]));
|
||||
`EXHAUST(type(ints_rev[0:1]));
|
||||
`EXHAUST(type(ints[2:1]));
|
||||
`EXHAUST(type(ints_rev[1:2]));
|
||||
end
|
||||
endmodule
|
||||
|
|
|
|||
|
|
@ -1,4 +1,30 @@
|
|||
`define DUMP_DIM(left, right) \
|
||||
$display(" $size %0d", \
|
||||
1 + (left >= right ? left - right : right - left)); \
|
||||
$display(" $left %0d", left); \
|
||||
$display(" $right %0d", right); \
|
||||
$display(" $high %0d", left >= right ? left : right); \
|
||||
$display(" $low %0d", left >= right ? right : left); \
|
||||
if (left === 1'bx) \
|
||||
$display(" $increment %0d", 1'bx); \
|
||||
else \
|
||||
$display(" $increment %0d", left >= right ? 1 : -1);
|
||||
|
||||
`define EXHAUST(typ,
|
||||
left1, right1,
|
||||
left2, right2,
|
||||
dimensions, unpacked_dimensions, bits) \
|
||||
$display(`"Dumping info for typ`"); \
|
||||
$display(" $dimensions %0d", dimensions); \
|
||||
$display(" $unpacked_dimensions %0d", unpacked_dimensions); \
|
||||
$display(" $bits %0d", bits); \
|
||||
$display(" 1st dimension"); \
|
||||
`DUMP_DIM(left1, right1); \
|
||||
$display(" 2nd dimension"); \
|
||||
`DUMP_DIM(left2, right2);
|
||||
|
||||
module top;
|
||||
reg [16:1] arr [0:0];
|
||||
initial begin
|
||||
$display(16);
|
||||
$display(16);
|
||||
|
|
@ -13,215 +39,147 @@ module top;
|
|||
$display("args %b", 2);
|
||||
$display("args %b", 1'bx);
|
||||
|
||||
$display(10, 10, 16);
|
||||
$display(0, 0, 16);
|
||||
$display(9, 9, 1);
|
||||
$display(9, 9, 16);
|
||||
$display(0, 0, 1);
|
||||
$display(-1, -1, 1);
|
||||
$display(2);
|
||||
$display(1);
|
||||
$display(160);
|
||||
`EXHAUST(Ram,
|
||||
0, 9,
|
||||
16, 1,
|
||||
2, 1, 160);
|
||||
`EXHAUST(Ram[0],
|
||||
16, 1,
|
||||
1'bx, 1'bx,
|
||||
1, 0, 16)
|
||||
`EXHAUST($unsigned(Ram[0]),
|
||||
15, 0,
|
||||
1'bx, 1'bx,
|
||||
1, 0, 16)
|
||||
`EXHAUST($signed(Ram[0]),
|
||||
15, 0,
|
||||
1'bx, 1'bx,
|
||||
1, 0, 16)
|
||||
`EXHAUST(Ram[0+:2],
|
||||
0, 1,
|
||||
16, 1,
|
||||
2, 1, 32)
|
||||
`EXHAUST(Ram[1+:2],
|
||||
1, 2,
|
||||
16, 1,
|
||||
2, 1, 32)
|
||||
`EXHAUST(Ram[2-:2],
|
||||
1, 2,
|
||||
16, 1,
|
||||
2, 1, 32)
|
||||
`EXHAUST(Ram[3-:2],
|
||||
2, 3,
|
||||
16, 1,
|
||||
2, 1, 32)
|
||||
`EXHAUST(Ram[0][2-:1],
|
||||
2, 2,
|
||||
1'bx, 1'bx,
|
||||
1, 0, 1)
|
||||
`EXHAUST(Ram[0][2-:2],
|
||||
2, 1,
|
||||
1'bx, 1'bx,
|
||||
1, 0, 2)
|
||||
|
||||
$display(16, 16, 1'bx);
|
||||
$display(16, 16, 1'bx);
|
||||
$display(1, 1, 1'bx);
|
||||
$display(16, 16, 1'bx);
|
||||
$display(1, 1, 1'bx);
|
||||
$display(1, 1, 1'bx);
|
||||
$display(1);
|
||||
$display(0);
|
||||
$display(16);
|
||||
|
||||
$display(16, 16, 1'bx);
|
||||
$display(15, 15, 1'bx);
|
||||
$display(0, 0, 1'bx);
|
||||
$display(15, 15, 1'bx);
|
||||
$display(0, 0, 1'bx);
|
||||
$display(1, 1, 1'bx);
|
||||
$display(1);
|
||||
$display(0);
|
||||
$display(16);
|
||||
|
||||
$display(16, 16, 1'bx);
|
||||
$display(15, 15, 1'bx);
|
||||
$display(0, 0, 1'bx);
|
||||
$display(15, 15, 1'bx);
|
||||
$display(0, 0, 1'bx);
|
||||
$display(1, 1, 1'bx);
|
||||
$display(1);
|
||||
$display(0);
|
||||
$display(16);
|
||||
|
||||
$display(2, 2, 16);
|
||||
$display(0, 0, 16);
|
||||
$display(1, 1, 1);
|
||||
$display(1, 1, 16);
|
||||
$display(0, 0, 1);
|
||||
$display(-1, -1, 1);
|
||||
$display(2);
|
||||
$display(1);
|
||||
$display(32);
|
||||
|
||||
$display(2, 2, 16);
|
||||
$display(1, 1, 16);
|
||||
$display(2, 2, 1);
|
||||
$display(2, 2, 16);
|
||||
$display(1, 1, 1);
|
||||
$display(-1, -1, 1);
|
||||
$display(2);
|
||||
$display(1);
|
||||
$display(32);
|
||||
|
||||
$display(1, 1, 1'bx);
|
||||
$display(2, 2, 1'bx);
|
||||
$display(2, 2, 1'bx);
|
||||
$display(2, 2, 1'bx);
|
||||
$display(2, 2, 1'bx);
|
||||
$display(1, 1, 1'bx);
|
||||
$display(1);
|
||||
$display(0);
|
||||
$display(1);
|
||||
|
||||
$display(2, 2, 10);
|
||||
$display(0, 0, 0);
|
||||
$display(1, 1, 9);
|
||||
$display(1, 1, 9);
|
||||
$display(0, 0, 0);
|
||||
$display(-1, -1, -1);
|
||||
$display(3);
|
||||
$display(2);
|
||||
$display(320);
|
||||
|
||||
$display(10, 10, 16);
|
||||
$display(0, 0, 16);
|
||||
$display(9, 9, 1);
|
||||
$display(9, 9, 16);
|
||||
$display(0, 0, 1);
|
||||
$display(-1, -1, 1);
|
||||
$display(2);
|
||||
$display(1);
|
||||
$display(160);
|
||||
|
||||
$display(16, 16, 1'bx);
|
||||
$display(16, 16, 1'bx);
|
||||
$display(1, 1, 1'bx);
|
||||
$display(16, 16, 1'bx);
|
||||
$display(1, 1, 1'bx);
|
||||
$display(1, 1, 1'bx);
|
||||
$display(1);
|
||||
$display(0);
|
||||
$display(16);
|
||||
|
||||
$display(32, 32, 1'bx);
|
||||
$display(31, 31, 1'bx);
|
||||
$display(0, 0, 1'bx);
|
||||
$display(31, 31, 1'bx);
|
||||
$display(0, 0, 1'bx);
|
||||
$display(1, 1, 1'bx);
|
||||
$display(1);
|
||||
$display(0);
|
||||
$display(32);
|
||||
|
||||
$display(1'bx, 1'bx, 1'bx);
|
||||
$display(1'bx, 1'bx, 1'bx);
|
||||
$display(1'bx, 1'bx, 1'bx);
|
||||
$display(1'bx, 1'bx, 1'bx);
|
||||
$display(1'bx, 1'bx, 1'bx);
|
||||
$display(1'bx, 1'bx, 1'bx);
|
||||
$display(0);
|
||||
$display(0);
|
||||
$display(1);
|
||||
|
||||
$display(8, 8, 1'bx);
|
||||
$display(7, 7, 1'bx);
|
||||
$display(0, 0, 1'bx);
|
||||
$display(7, 7, 1'bx);
|
||||
$display(0, 0, 1'bx);
|
||||
$display(1, 1, 1'bx);
|
||||
$display(1);
|
||||
$display(0);
|
||||
$display(8);
|
||||
|
||||
$display(4, 4, 32);
|
||||
$display(3, 3, 31);
|
||||
$display(0, 0, 0);
|
||||
$display(3, 3, 31);
|
||||
$display(0, 0, 0);
|
||||
$display(1, 1, 1);
|
||||
$display(2);
|
||||
$display(1);
|
||||
$display(128);
|
||||
|
||||
$display(4, 4, 32);
|
||||
$display(0, 0, 31);
|
||||
$display(3, 3, 0);
|
||||
$display(3, 3, 31);
|
||||
$display(0, 0, 0);
|
||||
$display(-1, -1, 1);
|
||||
$display(2);
|
||||
$display(1);
|
||||
$display(128);
|
||||
|
||||
$display(3, 3, 8);
|
||||
$display(0, 0, 7);
|
||||
$display(2, 2, 0);
|
||||
$display(2, 2, 7);
|
||||
$display(0, 0, 0);
|
||||
$display(-1, -1, 1);
|
||||
$display(2);
|
||||
$display(1);
|
||||
$display(24);
|
||||
|
||||
$display(3, 3, 8);
|
||||
$display(0, 0, 7);
|
||||
$display(2, 2, 0);
|
||||
$display(2, 2, 7);
|
||||
$display(0, 0, 0);
|
||||
$display(-1, -1, 1);
|
||||
$display(2);
|
||||
$display(1);
|
||||
$display(24);
|
||||
|
||||
$display(4, 4, 1'bx);
|
||||
$display(3, 3, 1'bx);
|
||||
$display(0, 0, 1'bx);
|
||||
$display(3, 3, 1'bx);
|
||||
$display(0, 0, 1'bx);
|
||||
$display(1, 1, 1'bx);
|
||||
$display(1);
|
||||
$display(0);
|
||||
$display(4);
|
||||
|
||||
$display(4, 4, 1'bx);
|
||||
$display(3, 3, 1'bx);
|
||||
$display(0, 0, 1'bx);
|
||||
$display(3, 3, 1'bx);
|
||||
$display(0, 0, 1'bx);
|
||||
$display(1, 1, 1'bx);
|
||||
$display(1);
|
||||
$display(0);
|
||||
$display(4);
|
||||
|
||||
$display(2, 2, 32);
|
||||
$display(1, 1, 31);
|
||||
$display(0, 0, 0);
|
||||
$display(1, 1, 31);
|
||||
$display(0, 0, 0);
|
||||
$display(1, 1, 1);
|
||||
$display(2);
|
||||
$display(1);
|
||||
$display(64);
|
||||
|
||||
$display(2, 2, 32);
|
||||
$display(0, 0, 31);
|
||||
$display(1, 1, 0);
|
||||
$display(1, 1, 31);
|
||||
$display(0, 0, 0);
|
||||
$display(-1, -1, 1);
|
||||
$display(2);
|
||||
$display(1);
|
||||
$display(64);
|
||||
`EXHAUST(RamFlip,
|
||||
9, 0,
|
||||
1, 16,
|
||||
2, 1, 160)
|
||||
`EXHAUST(RamFlip[0],
|
||||
1, 16,
|
||||
1'bx, 1'bx,
|
||||
1, 0, 16)
|
||||
`EXHAUST($unsigned(RamFlip[0]),
|
||||
15, 0,
|
||||
1'bx, 1'bx,
|
||||
1, 0, 16)
|
||||
`EXHAUST($signed(RamFlip[0]),
|
||||
15, 0,
|
||||
1'bx, 1'bx,
|
||||
1, 0, 16)
|
||||
`EXHAUST(RamFlip[0+:2],
|
||||
1, 0,
|
||||
1, 16,
|
||||
2, 1, 32)
|
||||
`EXHAUST(RamFlip[1+:2],
|
||||
2, 1,
|
||||
1, 16,
|
||||
2, 1, 32)
|
||||
`EXHAUST(RamFlip[2-:2],
|
||||
2, 1,
|
||||
1, 16,
|
||||
2, 1, 32)
|
||||
`EXHAUST(RamFlip[3-:2],
|
||||
3, 2,
|
||||
1, 16,
|
||||
2, 1, 32)
|
||||
`EXHAUST(RamFlip[0][2-:1],
|
||||
2, 2,
|
||||
1'bx, 1'bx,
|
||||
1, 0, 1)
|
||||
`EXHAUST(RamFlip[0][2-:2],
|
||||
1, 2,
|
||||
1'bx, 1'bx,
|
||||
1, 0, 2)
|
||||
|
||||
`EXHAUST(RamPair,
|
||||
0, 1,
|
||||
0, 9,
|
||||
3, 2, 320)
|
||||
`EXHAUST(RamPair[0],
|
||||
0, 9,
|
||||
16, 1,
|
||||
2, 1, 160)
|
||||
`EXHAUST(Word,
|
||||
16, 1,
|
||||
1'bx, 1'bx,
|
||||
1, 0, 16)
|
||||
`EXHAUST(integer,
|
||||
31, 0,
|
||||
1'bx, 1'bx,
|
||||
1, 0, 32)
|
||||
`EXHAUST(byte,
|
||||
7, 0,
|
||||
1'bx, 1'bx,
|
||||
1, 0, 8)
|
||||
`EXHAUST(ints,
|
||||
3, 0,
|
||||
31, 0,
|
||||
2, 1, 128)
|
||||
`EXHAUST(ints_rev,
|
||||
0, 3,
|
||||
31, 0,
|
||||
2, 1, 128)
|
||||
`EXHAUST(unpacked_t,
|
||||
0, 2,
|
||||
7, 0,
|
||||
2, 1, 24)
|
||||
`EXHAUST(unpacked,
|
||||
0, 2,
|
||||
7, 0,
|
||||
2, 1, 24)
|
||||
`EXHAUST(type(foo[3:0]),
|
||||
3, 0,
|
||||
1'bx, 1'bx,
|
||||
1, 0, 4)
|
||||
`EXHAUST(type(ints[2][3:0]),
|
||||
3, 0,
|
||||
1'bx, 1'bx,
|
||||
1, 0, 4)
|
||||
`EXHAUST(type(ints[1:0]),
|
||||
1, 0,
|
||||
31, 0,
|
||||
2, 1, 64)
|
||||
`EXHAUST(type(ints_rev[0:1]),
|
||||
0, 1,
|
||||
31, 0,
|
||||
2, 1, 64)
|
||||
`EXHAUST(type(ints[2:1]),
|
||||
2, 1,
|
||||
31, 0,
|
||||
2, 1, 64)
|
||||
`EXHAUST(type(ints_rev[1:2]),
|
||||
1, 2,
|
||||
31, 0,
|
||||
2, 1, 64)
|
||||
end
|
||||
endmodule
|
||||
|
|
|
|||
Loading…
Reference in New Issue