public override void GenerateCode(AbsynCodeGenerator codeGen, StructureNode node, StructureNode latchNode, AbsynStatementEmitter emitter) { codeGen.EmitLinearBlockStatements(node, emitter); if (node == latchNode) return; var exp = codeGen.BranchCondition(node); var ifStm = EmitIfCondition(exp, this, emitter); var succ = FirstBranch(node); var emitThen = new AbsynStatementEmitter(ifStm.Then); if (node.UnstructType == UnstructuredType.JumpInOutLoop) { codeGen.DeferRendering(node, succ, emitThen); codeGen.GenerateCode(SecondBranch(node), latchNode, emitter); } else { if (Follow == null) throw new NotSupportedException("Null condfollow"); codeGen.PushFollow(Follow); if (node.Conditional is IfThenElse) { codeGen.IncompleteNodes.Add(node); } if (codeGen.IsVisited(succ) || (node.Loop != null && succ == node.Loop.Follow)) codeGen.EmitGotoAndForceLabel(node, succ, emitThen); else codeGen.GenerateCode(succ, latchNode, emitThen); if (node.Conditional is IfThenElse) { codeGen.IncompleteNodes.Remove(node); succ = node.Then; AbsynStatementEmitter emitElse = new AbsynStatementEmitter(ifStm.Else); if (codeGen.IsVisited(succ)) codeGen.EmitGotoAndForceLabel(node, succ, emitElse); else codeGen.GenerateCode(succ, latchNode, emitElse); if (HasSingleIfThenElseStatement(ifStm.Then)) { ifStm.InvertCondition(); } } codeGen.PopFollow(); codeGen.GenerateCode(Follow, latchNode, emitter); } }
protected override void GenerateCodeInner(AbsynCodeGenerator codeGen, StructureNode node, AbsynStatementEmitter emitter) { List<AbsynStatement> loopBody = new List<AbsynStatement>(); AbsynStatementEmitter bodyEmitter = new AbsynStatementEmitter(loopBody); if (node.IsLatchNode()) { codeGen.EmitLinearBlockStatements(node, bodyEmitter); } else { if (node.Conditional != null) { node.Conditional.GenerateCode(codeGen, node, Latch, bodyEmitter); } else { codeGen.EmitLinearBlockStatements(node, bodyEmitter); if (node.OutEdges.Count != 1) throw new NotSupportedException(string.Format("Expected top of PostTestedLoop {0} to have only 1 out edge, but found {1} out edges.", node.Name, node.OutEdges.Count)); codeGen.GenerateCode(node.OutEdges[0], Latch, bodyEmitter); } } emitter.EmitDoWhile(loopBody, codeGen.BranchCondition(Latch)); }
protected override void GenerateCodeInner(AbsynCodeGenerator codeGen, StructureNode node, AbsynStatementEmitter emitter) { codeGen.EmitLinearBlockStatements(node, emitter); var loopBody = new List<AbsynStatement>(); var bodyNode = (node.Else == node.Loop.Follow) ? node.Then : node.Else; var bodyEmitter = new AbsynStatementEmitter(loopBody); codeGen.GenerateCode(bodyNode, node.Loop.Latch, bodyEmitter); bodyEmitter.StripDeclarations = true; codeGen.EmitLinearBlockStatements(node, bodyEmitter); emitter.EmitWhile(node, codeGen.BranchCondition(node), loopBody); }