Commit f0368714 by Zachary Snow

support generate for without explicit block

parent a1735ffe
...@@ -19,8 +19,8 @@ convert = ...@@ -19,8 +19,8 @@ convert =
) )
convertGenItem :: GenItem -> GenItem convertGenItem :: GenItem -> GenItem
convertGenItem (GenFor a b (ident, AsgnOp op, expr) c d) = convertGenItem (GenFor a b (ident, AsgnOp op, expr) c) =
GenFor a b (ident, AsgnOpEq, BinOp op (Ident ident) expr) c d GenFor a b (ident, AsgnOpEq, BinOp op (Ident ident) expr) c
convertGenItem other = other convertGenItem other = other
convertStmt :: Stmt -> Stmt convertStmt :: Stmt -> Stmt
......
...@@ -22,14 +22,17 @@ convert = ...@@ -22,14 +22,17 @@ convert =
) )
convertGenItem :: GenItem -> GenItem convertGenItem :: GenItem -> GenItem
convertGenItem (GenFor (True, x, e) a b bx c) = convertGenItem (GenFor (True, x, e) a b c) =
GenBlock "" genItems GenBlock "" genItems
where where
bx = case c of
GenBlock name _ -> name
_ -> ""
x' = if null bx then x else bx ++ "_" ++ x x' = if null bx then x else bx ++ "_" ++ x
Generate genItems = Generate genItems =
traverseNestedModuleItems converter $ Generate $ traverseNestedModuleItems converter $ Generate $
[ GenModuleItem $ Genvar x' [ GenModuleItem $ Genvar x'
, GenFor (False, x, e) a b bx c , GenFor (False, x, e) a b c
] ]
converter = converter =
(traverseExprs $ traverseNestedExprs convertExpr) . (traverseExprs $ traverseNestedExprs convertExpr) .
......
...@@ -619,11 +619,11 @@ traverseExprsM' strat exprMapper = moduleItemMapper ...@@ -619,11 +619,11 @@ traverseExprsM' strat exprMapper = moduleItemMapper
a'' <- traverseAssertionExprsM exprMapper a' a'' <- traverseAssertionExprsM exprMapper a'
return $ AssertionItem (mx, a'') return $ AssertionItem (mx, a'')
genItemMapper (GenFor (n1, x1, e1) cc (x2, op2, e2) mn subItems) = do genItemMapper (GenFor (n1, x1, e1) cc (x2, op2, e2) subItem) = do
e1' <- exprMapper e1 e1' <- exprMapper e1
e2' <- exprMapper e2 e2' <- exprMapper e2
cc' <- exprMapper cc cc' <- exprMapper cc
return $ GenFor (n1, x1, e1') cc' (x2, op2, e2') mn subItems return $ GenFor (n1, x1, e1') cc' (x2, op2, e2') subItem
genItemMapper (GenIf e i1 i2) = do genItemMapper (GenIf e i1 i2) = do
e' <- exprMapper e e' <- exprMapper e
return $ GenIf e' i1 i2 return $ GenIf e' i1 i2
...@@ -748,12 +748,12 @@ traverseLHSsM' strat mapper item = ...@@ -748,12 +748,12 @@ traverseLHSsM' strat mapper item =
items' <- mapM (traverseNestedGenItemsM traverGenItemLHSsM) items items' <- mapM (traverseNestedGenItemsM traverGenItemLHSsM) items
return $ Generate items' return $ Generate items'
traverseModuleItemLHSsM other = return other traverseModuleItemLHSsM other = return other
traverGenItemLHSsM (GenFor (n1, x1, e1) cc (x2, op2, e2) mn subItems) = do traverGenItemLHSsM (GenFor (n1, x1, e1) cc (x2, op2, e2) subItem) = do
wrapped_x1' <- (if n1 then return else mapper) $ LHSIdent x1 wrapped_x1' <- (if n1 then return else mapper) $ LHSIdent x1
wrapped_x2' <- mapper $ LHSIdent x2 wrapped_x2' <- mapper $ LHSIdent x2
let LHSIdent x1' = wrapped_x1' let LHSIdent x1' = wrapped_x1'
let LHSIdent x2' = wrapped_x2' let LHSIdent x2' = wrapped_x2'
return $ GenFor (n1, x1', e1) cc (x2', op2, e2) mn subItems return $ GenFor (n1, x1', e1) cc (x2', op2, e2) subItem
traverGenItemLHSsM other = return other traverGenItemLHSsM other = return other
traverseLHSs' :: TFStrategy -> Mapper LHS -> Mapper ModuleItem traverseLHSs' :: TFStrategy -> Mapper LHS -> Mapper ModuleItem
...@@ -924,9 +924,9 @@ traverseSinglyNestedGenItemsM fullMapper = gim ...@@ -924,9 +924,9 @@ traverseSinglyNestedGenItemsM fullMapper = gim
gim (GenBlock x subItems) = do gim (GenBlock x subItems) = do
subItems' <- mapM fullMapper subItems subItems' <- mapM fullMapper subItems
return $ GenBlock x (concatMap flattenBlocks subItems') return $ GenBlock x (concatMap flattenBlocks subItems')
gim (GenFor a b c d subItems) = do gim (GenFor a b c subItem) = do
subItems' <- mapM fullMapper subItems subItem' <- fullMapper subItem
return $ GenFor a b c d (concatMap flattenBlocks subItems') return $ GenFor a b c subItem'
gim (GenIf e i1 i2) = do gim (GenIf e i1 i2) = do
i1' <- fullMapper i1 i1' <- fullMapper i1
i2' <- fullMapper i2 i2' <- fullMapper i2
......
...@@ -22,7 +22,7 @@ import {-# SOURCE #-} Language.SystemVerilog.AST.ModuleItem (ModuleItem) ...@@ -22,7 +22,7 @@ import {-# SOURCE #-} Language.SystemVerilog.AST.ModuleItem (ModuleItem)
data GenItem data GenItem
= GenBlock Identifier [GenItem] = GenBlock Identifier [GenItem]
| GenCase Expr [GenCase] (Maybe GenItem) | GenCase Expr [GenCase] (Maybe GenItem)
| GenFor (Bool, Identifier, Expr) Expr (Identifier, AsgnOp, Expr) Identifier [GenItem] | GenFor (Bool, Identifier, Expr) Expr (Identifier, AsgnOp, Expr) GenItem
| GenIf Expr GenItem GenItem | GenIf Expr GenItem GenItem
| GenNull | GenNull
| GenModuleItem ModuleItem | GenModuleItem ModuleItem
...@@ -43,13 +43,13 @@ instance Show GenItem where ...@@ -43,13 +43,13 @@ instance Show GenItem where
Just c -> printf "\n\tdefault: %s" (show c) Just c -> printf "\n\tdefault: %s" (show c)
show (GenIf e a GenNull) = printf "if (%s) %s" (show e) (show a) show (GenIf e a GenNull) = printf "if (%s) %s" (show e) (show a)
show (GenIf e a b ) = printf "if (%s) %s\nelse %s" (show e) (show a) (show b) show (GenIf e a b ) = printf "if (%s) %s\nelse %s" (show e) (show a) (show b)
show (GenFor (new, x1, e1) c (x2, o2, e2) x is) = show (GenFor (new, x1, e1) c (x2, o2, e2) s) =
printf "for (%s%s = %s; %s; %s %s %s) %s" printf "for (%s%s = %s; %s; %s %s %s) %s"
(if new then "genvar " else "") (if new then "genvar " else "")
x1 (show e1) x1 (show e1)
(show c) (show c)
x2 (show o2) (show e2) x2 (show o2) (show e2)
(show $ GenBlock x is) (show s)
show (GenNull) = ";" show (GenNull) = ";"
show (GenModuleItem item) = show item show (GenModuleItem item) = show item
......
...@@ -1189,7 +1189,7 @@ ConditionalGenerateConstruct :: { GenItem } ...@@ -1189,7 +1189,7 @@ ConditionalGenerateConstruct :: { GenItem }
| "if" "(" Expr ")" GenItemOrNull %prec NoElse { GenIf $3 $5 GenNull } | "if" "(" Expr ")" GenItemOrNull %prec NoElse { GenIf $3 $5 GenNull }
| "case" "(" Expr ")" GenCasesWithDefault "endcase" { GenCase $3 (fst $5) (snd $5) } | "case" "(" Expr ")" GenCasesWithDefault "endcase" { GenCase $3 (fst $5) (snd $5) }
LoopGenerateConstruct :: { GenItem } LoopGenerateConstruct :: { GenItem }
: "for" "(" GenvarInitialization ";" Expr ";" GenvarIteration ")" GenBlock { (uncurry $ GenFor $3 $5 $7) $9 } : "for" "(" GenvarInitialization ";" Expr ";" GenvarIteration ")" GenItem { GenFor $3 $5 $7 $9 }
GenBlock :: { (Identifier, [GenItem]) } GenBlock :: { (Identifier, [GenItem]) }
: "begin" StrTag GenItems "end" StrTag { (combineTags $2 $5, $3) } : "begin" StrTag GenItems "end" StrTag { (combineTags $2 $5, $3) }
......
...@@ -64,4 +64,10 @@ module top; ...@@ -64,4 +64,10 @@ module top;
assign start = gen_filter[0].x; assign start = gen_filter[0].x;
initial $display(start); initial $display(start);
logic [0:31] c;
generate
for (genvar n = 0; n < 32; n = n + 1)
assign c[n] = n & 1;
endgenerate
endmodule endmodule
...@@ -75,4 +75,10 @@ module top; ...@@ -75,4 +75,10 @@ module top;
assign start = gen_filter[0].x; assign start = gen_filter[0].x;
initial $display(start); initial $display(start);
wire [0:31] c;
generate
for (n = 0; n < 32; n = n + 1)
assign c[n] = n & 1;
endgenerate
endmodule 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