elaboration avoid introducing illegal selects

This commit is contained in:
Zachary Snow 2020-06-25 17:36:09 -07:00
parent 80154feb5e
commit 82d06b3915
3 changed files with 33 additions and 1 deletions

View File

@ -34,13 +34,24 @@ convertDescription =
traverseDeclM :: Decl -> State Info Decl
traverseDeclM decl = do
case decl of
Param Localparam _ x e -> modify $ Map.insert x e
Param Localparam _ x e ->
when (isSimpleExpr e) $ modify $ Map.insert x e
_ -> return ()
let mi = MIPackageItem $ Decl decl
mi' <- traverseModuleItemM mi
let MIPackageItem (Decl decl') = mi'
return decl'
isSimpleExpr :: Expr -> Bool
isSimpleExpr Ident{} = True
isSimpleExpr PSIdent{} = True
isSimpleExpr Number{} = True
isSimpleExpr String{} = True
isSimpleExpr (Dot e _ ) = isSimpleExpr e
isSimpleExpr (Bit e _ ) = isSimpleExpr e
isSimpleExpr (Range e _ _) = isSimpleExpr e
isSimpleExpr _ = False
traverseModuleItemM :: ModuleItem -> State Info ModuleItem
traverseModuleItemM (Instance m p x rs l) = do
p' <- mapM paramBindingMapper p

View File

@ -0,0 +1,15 @@
package PKG;
typedef struct packed {
int F;
} S;
function automatic S f();
return '0;
endfunction
endpackage
module top;
localparam PKG::S L0 = PKG::f();
localparam int L1 = L0.F;
localparam int L2 = $clog2(L1);
initial $display("%b %b %b", L0, L1, L2);
endmodule

View File

@ -0,0 +1,6 @@
module top;
localparam L0 = 0;
localparam L1 = L0;
localparam L2 = $clog2(L1);
initial $display("%b %b %b", L0, L1, L2);
endmodule