internal string GetUniqueName() { if (RootHelper != null) { return(RootHelper.GetUniqueName()); } else { return($"~{UniqueNumber++}"); } }
private static void VisitConditional(VisitHelper parentHelper, FIRRTL.Conditionally conditional) { GraphFIR.Conditional cond = new GraphFIR.Conditional(conditional); void AddCondModule(GraphFIR.IO.Output ena, FIRRTL.Statement body) { VisitHelper helper = parentHelper.ForNewCondModule(parentHelper.GetUniqueName(), null); var internalEnaDummy = new GraphFIR.DummyPassthrough(ena); var internalUseEna = new GraphFIR.DummySink(internalEnaDummy.Result); helper.AddNodeToModule(internalEnaDummy); helper.AddNodeToModule(internalUseEna); helper.Mod.SetEnableCond(internalEnaDummy.Result); //Set signal that enables this scope as things like memory //ports need it helper.EnterEnabledScope(internalEnaDummy.Result); //Fill out module VisitStatement(helper, body); cond.AddConditionalModule(internalEnaDummy.InIO, helper.Mod); helper.ExitEnabledScope(); } GraphFIR.IO.Output enableCond = (GraphFIR.IO.Output)VisitExp(parentHelper, conditional.Pred, GraphFIR.IO.IOGender.Male); if (conditional.HasIf()) { GraphFIR.IO.Output ifEnableCond = enableCond; if (parentHelper.Mod.IsConditional) { GraphFIR.FIRAnd chainConditions = new GraphFIR.FIRAnd(parentHelper.Mod.EnableCon, enableCond, new FIRRTL.UIntType(1), null); parentHelper.AddNodeToModule(chainConditions); ifEnableCond = chainConditions.Result; } AddCondModule(ifEnableCond, conditional.WhenTrue); } if (conditional.HasElse()) { GraphFIR.FIRNot notEnableComponent = new GraphFIR.FIRNot(enableCond, new FIRRTL.UIntType(1), null); parentHelper.AddNodeToModule(notEnableComponent); GraphFIR.IO.Output elseEnableCond = notEnableComponent.Result; if (parentHelper.Mod.IsConditional) { GraphFIR.FIRAnd chainConditions = new GraphFIR.FIRAnd(parentHelper.Mod.EnableCon, elseEnableCond, new FIRRTL.UIntType(1), null); parentHelper.AddNodeToModule(chainConditions); elseEnableCond = chainConditions.Result; } AddCondModule(elseEnableCond, conditional.Alt); } parentHelper.AddNodeToModule(cond); }