Commit 8eb9523d by Zachary Snow

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
parent 5c8d838e
...@@ -18,7 +18,7 @@ module Convert.TypeOf (convert) where ...@@ -18,7 +18,7 @@ module Convert.TypeOf (convert) where
import Data.Tuple (swap) import Data.Tuple (swap)
import qualified Data.Map.Strict as Map import qualified Data.Map.Strict as Map
import Convert.ExprUtils (simplify) import Convert.ExprUtils (endianCondRange, simplify)
import Convert.Scoper import Convert.Scoper
import Convert.Traverse import Convert.Traverse
import Language.SystemVerilog.AST import Language.SystemVerilog.AST
...@@ -122,19 +122,27 @@ typeof (orig @ (Bit e _)) = do ...@@ -122,19 +122,27 @@ typeof (orig @ (Bit e _)) = do
TypeOf{} -> lookupTypeOf orig TypeOf{} -> lookupTypeOf orig
Alias{} -> return $ TypeOf orig Alias{} -> return $ TypeOf orig
_ -> return $ typeSignednessOverride t' Unsigned t' _ -> return $ typeSignednessOverride t' Unsigned t'
typeof (orig @ (Range e mode r)) = do typeof (orig @ (Range e NonIndexed r)) = do
t <- typeof e t <- typeof e
let t' = replaceRange (lo, hi) t let t' = replaceRange r t
return $ case t of return $ case t of
TypeOf{} -> TypeOf orig TypeOf{} -> TypeOf orig
Alias{} -> TypeOf orig Alias{} -> TypeOf orig
_ -> typeSignednessOverride t' Unsigned t' _ -> typeSignednessOverride t' Unsigned t'
typeof (Range expr mode (base, len)) =
typeof $ Range expr NonIndexed $
endianCondRange index (base, end) (end, base)
where where
lo = fst r index =
hi = case mode of if mode == IndexedPlus
NonIndexed -> snd r then (boundR, boundL)
IndexedPlus -> BinOp Sub (uncurry (BinOp Add) r) (RawNum 1) else (boundL, boundR)
IndexedMinus -> BinOp Add (uncurry (BinOp Sub) r) (RawNum 1) 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 typeof (orig @ (Dot e x)) = do
t <- typeof e t <- typeof e
case t of case t of
......
`define EXHAUST(t) \ `define DUMP_DIM(typ, dim) \
$display($size(t), $size(t,1), $size(t,2)); \ $display(" $size %0d", $size (typ, dim)); \
$display($left(t), $left(t,1), $left(t,2)); \ $display(" $left %0d", $left (typ, dim)); \
$display($right(t), $right(t,1), $right(t,2)); \ $display(" $right %0d", $right (typ, dim)); \
$display($high(t), $high(t,1), $high(t,2)); \ $display(" $high %0d", $high (typ, dim)); \
$display($low(t), $low(t,1), $low(t,2)); \ $display(" $low %0d", $low (typ, dim)); \
$display($increment(t), $increment(t,1), $increment(t,2)); \ $display(" $increment %0d", $increment(typ, dim));
$display($dimensions(t)); \
$display($unpacked_dimensions(t)); \ `define EXHAUST(typ) \
$display($bits(t)); $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; module top;
typedef logic [16:1] Word; typedef logic [16:1] Word;
Word Ram[0:9]; Word Ram[0:9];
typedef logic [1:16] WordFlip;
WordFlip RamFlip[9:0];
type(Ram) RamPair [2]; type(Ram) RamPair [2];
integer ints [3:0]; integer ints [3:0];
integer ints_rev [0:3]; integer ints_rev [0:3];
...@@ -39,12 +48,26 @@ module top; ...@@ -39,12 +48,26 @@ module top;
`EXHAUST($signed(Ram[0])); `EXHAUST($signed(Ram[0]));
`EXHAUST(Ram[0+:2]); `EXHAUST(Ram[0+:2]);
`EXHAUST(Ram[1+:2]); `EXHAUST(Ram[1+:2]);
`EXHAUST(Ram[2-:2]);
`EXHAUST(Ram[3-:2]);
`EXHAUST(Ram[0][2-:1]); `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);
`EXHAUST(RamPair[0]); `EXHAUST(RamPair[0]);
`EXHAUST(Word); `EXHAUST(Word);
`EXHAUST(integer); `EXHAUST(integer);
`EXHAUST(bit);
`EXHAUST(byte); `EXHAUST(byte);
`EXHAUST(ints); `EXHAUST(ints);
`EXHAUST(ints_rev); `EXHAUST(ints_rev);
...@@ -54,5 +77,7 @@ module top; ...@@ -54,5 +77,7 @@ module top;
`EXHAUST(type(ints[2][3:0])); `EXHAUST(type(ints[2][3:0]));
`EXHAUST(type(ints[1:0])); `EXHAUST(type(ints[1:0]));
`EXHAUST(type(ints_rev[0:1])); `EXHAUST(type(ints_rev[0:1]));
`EXHAUST(type(ints[2:1]));
`EXHAUST(type(ints_rev[1:2]));
end end
endmodule endmodule
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