Commit 90421456 by Zachary Snow

substitute localparams into type params

parent ea81d55c
......@@ -42,6 +42,14 @@ traverseDeclM decl = do
return decl'
traverseModuleItemM :: ModuleItem -> State Info ModuleItem
traverseModuleItemM (Instance m p x r l) = do
p' <- mapM paramBindingMapper p
traverseExprsM traverseExprM $ Instance m p' x r l
where
paramBindingMapper (param, Left t) = do
t' <- traverseTypeExprsM substituteExprM t
return (param, Left t')
paramBindingMapper (param, Right e) = return (param, Right e)
traverseModuleItemM item = traverseExprsM traverseExprM item
traverseStmtM :: Stmt -> State Info Stmt
......@@ -50,6 +58,9 @@ traverseStmtM stmt = traverseStmtExprsM traverseExprM stmt
traverseExprM :: Expr -> State Info Expr
traverseExprM = traverseNestedExprsM $ stately convertExpr
substituteExprM :: Expr -> State Info Expr
substituteExprM = traverseNestedExprsM $ stately substitute
convertExpr :: Info -> Expr -> Expr
convertExpr info (Cast (Right c) e) =
Cast (Right c') e
......
......@@ -54,6 +54,9 @@ module Convert.Traverse
, traverseExprTypesM
, traverseExprTypes
, collectExprTypesM
, traverseTypeExprsM
, traverseTypeExprs
, collectTypeExprsM
, traverseTypesM'
, traverseTypes'
, collectTypesM'
......@@ -896,6 +899,16 @@ traverseExprTypes = unmonad traverseExprTypesM
collectExprTypesM :: Monad m => CollectorM m Type -> CollectorM m Expr
collectExprTypesM = collectify traverseExprTypesM
traverseTypeExprsM :: Monad m => MapperM m Expr -> MapperM m Type
traverseTypeExprsM mapper =
typeMapper
where (_, _, _, _, typeMapper) = exprMapperHelpers mapper
traverseTypeExprs :: Mapper Expr -> Mapper Type
traverseTypeExprs = unmonad traverseTypeExprsM
collectTypeExprsM :: Monad m => CollectorM m Expr -> CollectorM m Type
collectTypeExprsM = collectify traverseTypeExprsM
traverseTypesM' :: Monad m => TypeStrategy -> MapperM m Type -> MapperM m ModuleItem
traverseTypesM' strategy mapper item =
miMapper item >>=
......
......@@ -112,3 +112,4 @@ module f_4; o_nodef #(.T(logic [1:0]), .U(logic), .b(0), .a(1)) x(); endmodule
module p_1; p #(logic [1:0], logic [2:0]) x(); endmodule
module p_2; p x(); endmodule
module p_3; localparam W = 2; p #(logic [W:0], logic [W:0]) x(); endmodule
......@@ -40,5 +40,7 @@ module top;
$display("p 001 00000000000000000000000000000010 3");
$display("p 0 00000000000000000000000000000001 1");
$display("p 1 00000000000000000000000000000010 1");
$display("p 000 00000000000000000000000000000001 3");
$display("p 001 00000000000000000000000000000010 3");
end
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