Commit fd96b8a7 by Zachary Snow

unbased unsized conversion inlines module stubs

- support ports with sizes which depend on constant functions
- restore package item injection utility to package conversion module
- additional unbased unsized conversion test coverage
parent 37c8938e
...@@ -18,7 +18,11 @@ ...@@ -18,7 +18,11 @@
- into modules and interfaces as needed. - into modules and interfaces as needed.
-} -}
module Convert.Package (convert) where module Convert.Package
( convert
, inject
, prefixItems
) where
import Control.Monad.State.Strict import Control.Monad.State.Strict
import Control.Monad.Writer.Strict import Control.Monad.Writer.Strict
...@@ -57,6 +61,21 @@ makeLocal (Decl (Param _ t x e)) = Decl $ Param Localparam t x e ...@@ -57,6 +61,21 @@ makeLocal (Decl (Param _ t x e)) = Decl $ Param Localparam t x e
makeLocal (Decl (ParamType _ x t)) = Decl $ ParamType Localparam x t makeLocal (Decl (ParamType _ x t)) = Decl $ ParamType Localparam x t
makeLocal other = other makeLocal other = other
-- utility for inserting package items into a set of module items as needed
inject :: [PackageItem] -> [ModuleItem] -> [ModuleItem]
inject packageItems items =
addItems localPIs Set.empty (map addUsedPIs items)
where
localPIs = Map.fromList $ concatMap toPIElem packageItems
toPIElem :: PackageItem -> [(Identifier, PackageItem)]
toPIElem item = map (, item) (piNames item)
-- utility for appling a prefix to all of the top level items in a module
prefixItems :: Identifier -> [ModuleItem] -> [ModuleItem]
prefixItems prefix items =
snd $ evalState (processItems "" prefix items) initialState
where initialState = ([], Map.empty, Map.empty)
-- collect packages and global package items -- collect packages and global package items
collectPackageM :: Description -> Writer (Packages, Classes, [PackageItem]) () collectPackageM :: Description -> Writer (Packages, Classes, [PackageItem]) ()
collectPackageM (PackageItem item) = collectPackageM (PackageItem item) =
......
...@@ -77,6 +77,12 @@ module top; ...@@ -77,6 +77,12 @@ module top;
`TEST_OP(32'hffffffff , ==, '1, 1'b1) `TEST_OP(32'hffffffff , ==, '1, 1'b1)
`TEST_OP(33'h1ffffffff, ==, '1, 1'b1) `TEST_OP(33'h1ffffffff, ==, '1, 1'b1)
`TEST_OP('1, ==, 1'h1 , 1'b1)
`TEST_OP('1, ==, 2'h3 , 1'b1)
`TEST_OP('1, ==, 31'h7fffffff , 1'b1)
`TEST_OP('1, ==, 32'hffffffff , 1'b1)
`TEST_OP('1, ==, 33'h1ffffffff, 1'b1)
`TEST_OP( 1'h1 , <=, '1, 1'b1) `TEST_OP( 1'h1 , <=, '1, 1'b1)
`TEST_OP( 2'h3 , <=, '1, 1'b1) `TEST_OP( 2'h3 , <=, '1, 1'b1)
`TEST_OP(31'h7fffffff , <=, '1, 1'b1) `TEST_OP(31'h7fffffff , <=, '1, 1'b1)
...@@ -97,6 +103,7 @@ module top; ...@@ -97,6 +103,7 @@ module top;
`TEST_OP(33'h1ffffffff, &, P ? '1 : '0, 33'h1ffffffff) `TEST_OP(33'h1ffffffff, &, P ? '1 : '0, 33'h1ffffffff)
`TEST_OP(33'h1ffffffff, &, '1 & '1, 33'h1ffffffff) `TEST_OP(33'h1ffffffff, &, '1 & '1, 33'h1ffffffff)
`TEST_OP('1 & '1, &, 33'h1ffffffff, 33'h1ffffffff)
`TEST_OP(33'h1ffffffff, &, !P ? '1 : '0 - 1, 33'h1ffffffff) `TEST_OP(33'h1ffffffff, &, !P ? '1 : '0 - 1, 33'h1ffffffff)
`TEST_OP(34'h3ffffffff, &, '0 - 1, 34'h3ffffffff) `TEST_OP(34'h3ffffffff, &, '0 - 1, 34'h3ffffffff)
...@@ -126,6 +133,12 @@ module top; ...@@ -126,6 +133,12 @@ module top;
#1 pick = 0; #1 pick = 0;
#1 pick = 1; #1 pick = 1;
end end
initial begin
$display("tern %b", A ? '1 : 'X);
$display("tern %b", A ? '1 : A);
$display("tern %b", A ? A : '1);
end
endmodule endmodule
module M(a, b, c, d); module M(a, b, c, d);
......
...@@ -72,6 +72,12 @@ module top; ...@@ -72,6 +72,12 @@ module top;
`TEST_OP(32'hffffffff , ==, '1, 1'b1) `TEST_OP(32'hffffffff , ==, '1, 1'b1)
`TEST_OP(33'h1ffffffff, ==, '1, 1'b1) `TEST_OP(33'h1ffffffff, ==, '1, 1'b1)
`TEST_OP('1, ==, 1'h1 , 1'b1)
`TEST_OP('1, ==, 2'h3 , 1'b1)
`TEST_OP('1, ==, 31'h7fffffff , 1'b1)
`TEST_OP('1, ==, 32'hffffffff , 1'b1)
`TEST_OP('1, ==, 33'h1ffffffff, 1'b1)
`TEST_OP( 1'h1 , <=, '1, 1'b1) `TEST_OP( 1'h1 , <=, '1, 1'b1)
`TEST_OP( 2'h3 , <=, '1, 1'b1) `TEST_OP( 2'h3 , <=, '1, 1'b1)
`TEST_OP(31'h7fffffff , <=, '1, 1'b1) `TEST_OP(31'h7fffffff , <=, '1, 1'b1)
...@@ -92,6 +98,7 @@ module top; ...@@ -92,6 +98,7 @@ module top;
`TEST_OP(33'h1ffffffff, &, P ? '1 : '0, 33'h1ffffffff) `TEST_OP(33'h1ffffffff, &, P ? '1 : '0, 33'h1ffffffff)
`TEST_OP(33'h1ffffffff, &, '1 & '1, 33'h1ffffffff) `TEST_OP(33'h1ffffffff, &, '1 & '1, 33'h1ffffffff)
`TEST_OP('1 & '1, &, 33'h1ffffffff, 33'h1ffffffff)
`TEST_OP(33'h1ffffffff, &, !P ? '1 : '0 - 1, 33'h1ffffffff) `TEST_OP(33'h1ffffffff, &, !P ? '1 : '0 - 1, 33'h1ffffffff)
`TEST_OP(34'h3ffffffff, &, '0 - 1, 34'h3ffffffff) `TEST_OP(34'h3ffffffff, &, '0 - 1, 34'h3ffffffff)
...@@ -121,6 +128,12 @@ module top; ...@@ -121,6 +128,12 @@ module top;
#1 pick = 0; #1 pick = 0;
#1 pick = 1; #1 pick = 1;
end end
initial begin
$display("tern %b", 1'b1);
$display("tern %b", A ? -1 : A);
$display("tern %b", A ? A : -1);
end
endmodule endmodule
module M(a, b, c, d); module M(a, b, c, d);
......
module mod(a, b, c, d);
parameter P = 2;
function automatic [P - 1:0] F;
input signed inp;
F = inp;
endfunction
parameter Q = 1;
if (1) begin : blk
localparam X = F(Q) + Q;
wire [X - 1:0] g;
end
wire x = blk.g;
localparam R = $bits(blk.g);
input logic [P - 1:0] a;
input wire [Q - 1:0] b;
input [R - 1:0] c;
input d;
initial #1 $display("mod P=%0d Q=%0d R=%0d a=%b b=%b c=%b d=%b",
P, Q, R, a, b, c, d);
endmodule
module top;
parameter P = 1;
parameter Q = 2;
parameter R = 3;
mod #() m1('1, 'X, 'Z, '1);
mod #(P, Q) m2('1, '1, '1, '1);
mod #(P, R) m3('1, '1, '1, '1);
mod #(Q, R) m4('1, '1, P ? '1 : 'X, '1);
endmodule
module mod(a, b, c, d);
parameter P = 2;
function automatic [P - 1:0] F;
input signed inp;
F = inp;
endfunction
parameter Q = 1;
localparam R = F(Q) + Q;
input signed a;
input signed b;
input signed c;
input d;
initial #1 $display("mod P=%0d Q=%0d R=%0d a=%b b=%b c=%b d=%b",
P, Q, R, {P{a}}, {Q{b}}, {R{c}}, d);
endmodule
module top;
parameter P = 1;
parameter Q = 2;
parameter R = 3;
mod #() m1(1'b1, 1'bX, 1'bZ, 1'b1);
mod #(P, Q) m2(1'b1, 1'b1, 1'b1, 1'b1);
mod #(P, R) m3(1'b1, 1'b1, 1'b1, 1'b1);
mod #(Q, R) m4(1'b1, 1'b1, 1'b1, 1'b1);
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