Commit 24071d74 by Zachary Snow

paramtype conversion resolves dimension queries before substitution

parent 2d134a86
...@@ -219,13 +219,27 @@ exprToType _ = Nothing ...@@ -219,13 +219,27 @@ exprToType _ = Nothing
-- TODO: If a type parameter contains an expression, that expression should be -- TODO: If a type parameter contains an expression, that expression should be
-- substituted into the new module, or created as a new parameter. -- substituted into the new module, or created as a new parameter.
isSimpleType :: Type -> Bool isSimpleType :: Type -> Bool
isSimpleType (IntegerVector _ _ _) = True isSimpleType typ =
isSimpleType (IntegerAtom _ _ ) = True (not $ typeHasQueries typ) &&
isSimpleType (NonInteger _ ) = True case typ of
isSimpleType (Net _ _ _) = True IntegerVector{} -> True
isSimpleType (Struct _ fields _) = all (isSimpleType . fst) fields IntegerAtom {} -> True
isSimpleType (Union _ fields _) = all (isSimpleType . fst) fields NonInteger {} -> True
isSimpleType _ = False Net {} -> True
Struct _ fields _ -> all (isSimpleType . fst) fields
Union _ fields _ -> all (isSimpleType . fst) fields
_ -> False
-- returns whether a type contains any dimension queries
typeHasQueries :: Type -> Bool
typeHasQueries =
not . null . execWriter . collectTypeExprsM
(collectNestedExprsM collectUnresolvedExprM)
where
collectUnresolvedExprM :: Expr -> Writer [Expr] ()
collectUnresolvedExprM (expr @ DimsFn{}) = tell [expr]
collectUnresolvedExprM (expr @ DimFn {}) = tell [expr]
collectUnresolvedExprM _ = return ()
-- attempt to rewrite instantiations with type parameters -- attempt to rewrite instantiations with type parameters
convertModuleItemM :: Info -> ModuleItem -> Writer Instances ModuleItem convertModuleItemM :: Info -> ModuleItem -> Writer Instances ModuleItem
......
module Module(out);
parameter type T = logic;
output T out;
assign out = '1;
endmodule
module top;
logic w;
logic [$bits(w)-1:0] b;
logic o0, o1;
logic [1:0] o2;
Module m0(o0);
Module #(logic[$bits(w)-1:0]) m1(o1);
Module #(logic[$bits(b)*2-1:0]) m2(o2);
endmodule
module Module_Size1(out);
output wire out;
assign out = 1'b1;
endmodule
module Module_Size2(out);
output wire [1:0] out;
assign out = 2'b11;
endmodule
module top;
wire w;
wire [0:0] b;
wire o0, o1;
wire [1:0] o2;
Module_Size1 m0(o0);
Module_Size1 m1(o1);
Module_Size2 m2(o2);
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