@@ -79,22 +79,53 @@ void CompileHelper::compileGenStmt(ModuleDefinition* component,
7979 if (fC ->Type (stmtId) == VObjectType::slIf_generate_construct) {
8080 NodeId ifElseId = fC ->Child (stmtId);
8181 if (fC ->Type (ifElseId) == VObjectType::slIF) {
82+ // lookahead
83+ NodeId tmp = ifElseId;
84+ bool ifelse = false ;
85+ while (tmp) {
86+ if (fC ->Type (tmp) == VObjectType::slElse) {
87+ ifelse = true ;
88+ break ;
89+ }
90+ tmp = fC ->Sibling (tmp);
91+ }
92+
8293 NodeId condId = fC ->Sibling (ifElseId);
8394 expr* cond = (expr*)compileExpression (component, fC , condId,
8495 compileDesign, Reduce::No, nullptr );
8596 NodeId stmtId = fC ->Sibling (condId);
86- gen_if* genif = s.MakeGen_if ();
87- genif->VpiCondition (cond);
88- fC ->populateCoreMembers (ifElseId, ifElseId, genif);
89- begin* stmt = s.MakeBegin ();
90- VectorOfany* stmts = compileStmt (component, fC , stmtId, compileDesign,
91- Reduce::No, nullptr , nullptr , true );
92- stmt->Stmts (stmts);
93- genif->VpiStmt (stmt);
97+ gen_stmt* genstmt = nullptr ;
98+ if (ifelse) {
99+ gen_if_else* genif = s.MakeGen_if_else ();
100+ genstmt = genif;
101+ genif->VpiCondition (cond);
102+ begin* stmt = s.MakeBegin ();
103+ VectorOfany* stmts = compileStmt (component, fC , stmtId, compileDesign,
104+ Reduce::No, nullptr , nullptr , true );
105+ stmt->Stmts (stmts);
106+ genif->VpiStmt (stmt);
107+ NodeId ElseId = fC ->Sibling (stmtId);
108+ NodeId elseStmtId = fC ->Sibling (ElseId);
109+ stmts = compileStmt (component, fC , elseStmtId, compileDesign,
110+ Reduce::No, nullptr , nullptr , true );
111+ stmt = s.MakeBegin ();
112+ stmt->Stmts (stmts);
113+ genif->VpiElseStmt (stmt);
114+ } else {
115+ gen_if* genif = s.MakeGen_if ();
116+ genstmt = genif;
117+ genif->VpiCondition (cond);
118+ fC ->populateCoreMembers (ifElseId, ifElseId, genif);
119+ begin* stmt = s.MakeBegin ();
120+ VectorOfany* stmts = compileStmt (component, fC , stmtId, compileDesign,
121+ Reduce::No, nullptr , nullptr , true );
122+ stmt->Stmts (stmts);
123+ genif->VpiStmt (stmt);
124+ }
94125 if (component->getGenStmts () == nullptr ) {
95126 component->setGenStmts (s.MakeGen_stmtVec ());
96127 }
97- component->getGenStmts ()->push_back (genif );
128+ component->getGenStmts ()->push_back (genstmt );
98129 }
99130 }
100131}
0 commit comments