Commit b1f1b822 by Zachary Snow

fix conversion of interface-based typedefs

parent 6788ecbf
...@@ -30,6 +30,8 @@ ...@@ -30,6 +30,8 @@
whitespace except for the newline which terminates the comment whitespace except for the newline which terminates the comment
* Fix conversion of references to modports nested within types in expressions * Fix conversion of references to modports nested within types in expressions
* Fix conversion of module-scoped references to modports * Fix conversion of module-scoped references to modports
* Fix conversion of interface-based typedefs when used with explicit modports,
unpacked arrays, or in designs with multi-dimensional instances
## v0.0.8 ## v0.0.8
......
...@@ -126,6 +126,7 @@ traverseDeclM decl = do ...@@ -126,6 +126,7 @@ traverseDeclM decl = do
isRangeable IntegerAtom{} = False isRangeable IntegerAtom{} = False
isRangeable NonInteger{} = False isRangeable NonInteger{} = False
isRangeable TypeOf{} = False isRangeable TypeOf{} = False
isRangeable TypedefRef{} = False
isRangeable _ = True isRangeable _ = True
traverseGenItemM :: GenItem -> Scoper Type GenItem traverseGenItemM :: GenItem -> Scoper Type GenItem
......
...@@ -882,7 +882,16 @@ traverseTypeExprsM exprMapper = ...@@ -882,7 +882,16 @@ traverseTypeExprsM exprMapper =
typeOrExprMapper (Right e) = exprMapper e >>= return . Right typeOrExprMapper (Right e) = exprMapper e >>= return . Right
typeMapper (TypeOf expr) = typeMapper (TypeOf expr) =
exprMapper expr >>= return . TypeOf exprMapper expr >>= return . TypeOf
-- TypedefRef is excluded because it isn't really an expression -- TypedefRef root is a reference to a port, but the "field" here is
-- really a typename; this indirection circumvents the interface
-- expression resolution check and ensures the underlying modport is
-- appropriately resolved to the corresponding interface instance
typeMapper (TypedefRef expr) = do
let Dot inn typ = expr
let wrap = Dot inn "*"
wrap' <- exprMapper wrap
let Dot inn' "*" = wrap'
return $ TypedefRef $ Dot inn' typ
typeMapper (CSAlias ps pm xx rs) = do typeMapper (CSAlias ps pm xx rs) = do
vals' <- mapM typeOrExprMapper $ map snd pm vals' <- mapM typeOrExprMapper $ map snd pm
let pm' = zip (map fst pm) vals' let pm' = zip (map fst pm) vals'
......
...@@ -16,8 +16,9 @@ import Convert.Traverse ...@@ -16,8 +16,9 @@ import Convert.Traverse
import Language.SystemVerilog.AST import Language.SystemVerilog.AST
convert :: [AST] -> [AST] convert :: [AST] -> [AST]
convert = map $ traverseDescriptions $ partScoper convert = map $ traverseDescriptions $ evalScoper . scopeModule scoper
traverseDeclM traverseModuleItemM traverseGenItemM traverseStmtM where scoper = scopeModuleItem
traverseDeclM traverseModuleItemM traverseGenItemM traverseStmtM
traverseTypeOrExprM :: TypeOrExpr -> Scoper Type TypeOrExpr traverseTypeOrExprM :: TypeOrExpr -> Scoper Type TypeOrExpr
traverseTypeOrExprM (Left (TypeOf (Ident x))) = do traverseTypeOrExprM (Left (TypeOf (Ident x))) = do
......
...@@ -2,21 +2,36 @@ interface intf_i; ...@@ -2,21 +2,36 @@ interface intf_i;
typedef int data_t; typedef int data_t;
endinterface endinterface
module sub(intf_i p, intf_i q [2]); interface intf_j;
typedef logic [1:0] data_t;
logic dummy;
modport m(input dummy);
endinterface
module sub(interface p, interface q [2]);
typedef p.data_t p_data_t; // interface based typedef typedef p.data_t p_data_t; // interface based typedef
typedef q[0].data_t q_data_t; // interface based typedef typedef q[0].data_t q_data_t; // interface based typedef
p_data_t p_data; p_data_t p_data;
q_data_t q_data; q_data_t q_data;
p_data_t p_data_arr [2];
q_data_t q_data_arr [2];
initial begin initial begin
p_data = 1; p_data = 1;
q_data = 2; q_data = 2;
p_data_arr[0] = 2;
q_data_arr[0] = 2;
$display("p %0d %b", $bits(p_data), p_data); $display("p %0d %b", $bits(p_data), p_data);
$display("q %0d %b", $bits(q_data), q_data); $display("q %0d %b", $bits(q_data), q_data);
$display("p %0d", $bits(p_data_arr));
$display("q %0d", $bits(q_data_arr));
end end
endmodule endmodule
module top; module top;
intf_i p(); intf_i p();
intf_i q[2](); intf_i q[2]();
sub s(p, q); sub si(p, q);
intf_j r();
intf_j s[2]();
sub sj(r.m, s);
endmodule endmodule
module top; module top;
initial $display("p %0d %b", 32, 32'd1); initial $display("p %0d %b", 32, 32'd1);
initial $display("q %0d %b", 32, 32'd2); initial $display("q %0d %b", 32, 32'd2);
initial $display("p %0d", 64);
initial $display("q %0d", 64);
initial $display("p %0d %b", 2, 2'd1);
initial $display("q %0d %b", 2, 2'd2);
initial $display("p %0d", 4);
initial $display("q %0d", 4);
endmodule endmodule
module poof;
initial $display("poof");
endmodule
module alt;
poof poof[2][2]();
endmodule
`include "interface_based_typedef.sv"
module poof;
initial $display("poof");
endmodule
module alt;
poof poof[0:3]();
endmodule
`include "interface_based_typedef.v"
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