Commit cd7b53c6 by Zachary Snow

fix multipack conversion type and expr traversal

parent fe90c7bb
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
* Fixed conflicting genvar names when inlining interfaces and modules that use * Fixed conflicting genvar names when inlining interfaces and modules that use
them; all genvars are now given a design-wide unique name them; all genvars are now given a design-wide unique name
* Fixed unconverted structs within explicit type casts * Fixed unconverted structs within explicit type casts
* Fixed unconverted multidimensional struct fields within dimension queries
* Fixed non-typenames (e.g., from packages or subsequent declarations) * Fixed non-typenames (e.g., from packages or subsequent declarations)
improperly shadowing the names of `struct` pattern fields improperly shadowing the names of `struct` pattern fields
* Fixed failure to resolve typenames suffixed with dimensions in contexts * Fixed failure to resolve typenames suffixed with dimensions in contexts
......
...@@ -50,21 +50,22 @@ convertDescription other = other ...@@ -50,21 +50,22 @@ convertDescription other = other
-- collects and converts declarations with multiple packed dimensions -- collects and converts declarations with multiple packed dimensions
traverseDeclM :: Decl -> Scoper TypeInfo Decl traverseDeclM :: Decl -> Scoper TypeInfo Decl
traverseDeclM (Variable dir t ident a e) = do traverseDeclM (Variable dir t ident a e) = do
t' <- traverseTypeM t a ident recordTypeM t a ident
traverseDeclExprsM traverseExprM $ Variable dir t' ident a e traverseDeclExprsM traverseExprM $ Variable dir t' ident a e
where t' = flattenType t
traverseDeclM net@Net{} = traverseDeclM net@Net{} =
traverseNetAsVarM traverseDeclM net traverseNetAsVarM traverseDeclM net
traverseDeclM (Param s t ident e) = do traverseDeclM (Param s t ident e) = do
t' <- traverseTypeM t [] ident recordTypeM t [] ident
traverseDeclExprsM traverseExprM $ Param s t' ident e traverseDeclExprsM traverseExprM $ Param s t' ident e
where t' = flattenType t
traverseDeclM other = traverseDeclExprsM traverseExprM other traverseDeclM other = traverseDeclExprsM traverseExprM other
-- write down the given declaration and then flatten it -- write down the given declaration
traverseTypeM :: Type -> [Range] -> Identifier -> Scoper TypeInfo Type recordTypeM :: Type -> [Range] -> Identifier -> Scoper TypeInfo ()
traverseTypeM t a ident = do recordTypeM t a ident = do
tScoped <- scopeType t tScoped <- scopeType t
insertElem ident (tScoped, a) insertElem ident (tScoped, a)
return $ flattenType t
-- flatten the innermost dimension of the given type, and any types it contains -- flatten the innermost dimension of the given type, and any types it contains
flattenType :: Type -> Type flattenType :: Type -> Type
...@@ -132,7 +133,20 @@ traverseStmtM = ...@@ -132,7 +133,20 @@ traverseStmtM =
traverseStmtExprsM traverseExprM traverseStmtExprsM traverseExprM
traverseExprM :: Expr -> Scoper TypeInfo Expr traverseExprM :: Expr -> Scoper TypeInfo Expr
traverseExprM = traverseNestedExprsM convertExprM traverseExprM =
embedScopes convertExpr >=>
traverseExprTypesM traverseTypeM >=>
traverseSinglyNestedExprsM traverseExprM
traverseTypeM :: Type -> Scoper TypeInfo Type
traverseTypeM typ =
traverseTypeExprsM traverseExprM >=>
traverseSinglyNestedTypesM traverseTypeM $
case typ of
Struct{} -> typ'
Union {} -> typ'
_ -> typ
where typ' = traverseSinglyNestedTypes flattenType typ
traverseGenItemM :: GenItem -> Scoper TypeInfo GenItem traverseGenItemM :: GenItem -> Scoper TypeInfo GenItem
traverseGenItemM = traverseGenItemExprsM traverseExprM traverseGenItemM = traverseGenItemExprsM traverseExprM
...@@ -147,20 +161,10 @@ traverseLHSM = traverseNestedLHSsM traverseLHSSingleM ...@@ -147,20 +161,10 @@ traverseLHSM = traverseNestedLHSsM traverseLHSSingleM
traverseLHSSingleM :: LHS -> Scoper TypeInfo LHS traverseLHSSingleM :: LHS -> Scoper TypeInfo LHS
traverseLHSSingleM lhs = do traverseLHSSingleM lhs = do
let expr = lhsToExpr lhs let expr = lhsToExpr lhs
expr' <- convertExprM expr expr' <- embedScopes convertExpr expr
let Just lhs' = exprToLHS expr' let Just lhs' = exprToLHS expr'
return lhs' return lhs'
convertExprM :: Expr -> Scoper TypeInfo Expr
convertExprM =
traverseExprTypesM convertTypeM >=>
embedScopes convertExpr
convertTypeM :: Type -> Scoper TypeInfo Type
convertTypeM =
traverseNestedTypesM $ traverseTypeExprsM $
traverseNestedExprsM convertExprM
convertExpr :: Scopes TypeInfo -> Expr -> Expr convertExpr :: Scopes TypeInfo -> Expr -> Expr
convertExpr scopes = convertExpr scopes =
rewriteExpr rewriteExpr
......
module top;
typedef struct packed {
logic [1:0][1:0][1:0] x;
} U;
typedef union packed {
logic [$bits(U) - 1:0][7:0] a;
logic [3:0][15:0] b;
U [7:0] c;
} T;
typedef struct packed {
logic [$bits(U) - 1:0][7:0] a;
logic [3:0][15:0] b;
U [7:0] c;
T [2:0] d;
} S;
if ($bits(U) != 8)
$error("invalid width U");
if ($bits(T) != 64)
$error("invalid width T");
if ($bits(S) != 64 * 6)
$error("invalid width S");
logic [31:0] x;
assign x[$bits(U) - 1:0] = '1;
endmodule
module top;
wire [31:0] x;
assign x[7:0] = 1'sb1;
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