/// <summary> /// structure: /// first_label: /// # body { /// ... /// continue_label: ; /// } /// # pred /// jmp first_label /// break_label: /// /// </summary> /// <param name="gen"></param> public override void ToX86(X86Gen gen) { gen.Comment(X86Gen.Seg.TEXT, "do body"); gen.Tag(X86Gen.Seg.TEXT, firstLabel); body.ToX86WithLabel(gen, continueLabel); gen.Comment(X86Gen.Seg.TEXT, "do pred"); gen.Branch(expr, firstLabel, true); gen.Comment(X86Gen.Seg.TEXT, "do end"); gen.Tag(X86Gen.Seg.TEXT, breakLabel); }
/// <summary> /// Basic structure: /// /// first_label: /// # pred /// je break_label /// # body /// jmp first_label /// break_label: /// /// </summary> /// <param name="gen"></param> public override void ToX86(X86Gen gen) { gen.Comment(X86Gen.Seg.TEXT, "while pred"); gen.Tag(X86Gen.Seg.TEXT, firstLabel); gen.Branch(expr, breakLabel, false); gen.Comment(X86Gen.Seg.TEXT, "while body"); body.ToX86WithLabel(gen, continueLabel); gen.Inst(X86Gen.jmp, firstLabel); gen.Comment(X86Gen.Seg.TEXT, "while end"); gen.Tag(X86Gen.Seg.TEXT, breakLabel); }
public override void ToX86(X86Gen gen) { gen.Comment(X86Gen.Seg.TEXT, "if"); gen.Branch(expr, other != null ? elseLabel : endIfLabel, false); /// Generate code for then branch. /// Remember to jump to endif label since /// "If the first substatement is reached via a label, the second substatement is not executed. gen.Comment(X86Gen.Seg.TEXT, "then"); then.ToX86(gen); gen.Inst(X86Gen.jmp, endIfLabel); if (other != null) { gen.Comment(X86Gen.Seg.TEXT, "else"); gen.Tag(X86Gen.Seg.TEXT, elseLabel); other.ToX86(gen); } gen.Tag(X86Gen.Seg.TEXT, endIfLabel); }
/// <summary> /// The basic structure is like: /// /// # init /// jmp first_label /// second_plus_label: /// # iter /// first_label: /// # pred /// je break_label /// # body /// jmp second_plus_label /// break_label: /// /// </summary> /// <param name="gen"></param> public override void ToX86(X86Gen gen) { /// Generate the initialize code. /// Jump to first_label if iter is not omitted. gen.Comment(X86Gen.Seg.TEXT, "for init"); if (init != null) { init.ToX86(gen); if (iter != null) { gen.Inst(X86Gen.jmp, firstLabel); } } /// Generate the iterate code. gen.Comment(X86Gen.Seg.TEXT, "for iter"); if (iter != null) { gen.Tag(X86Gen.Seg.TEXT, secondPlusLabel); iter.ToX86(gen); } /// Generate the controlling (predicating) code. gen.Comment(X86Gen.Seg.TEXT, "for pred"); gen.Tag(X86Gen.Seg.TEXT, firstLabel); gen.Branch(pred, breakLabel, false); /// Generate body code. gen.Comment(X86Gen.Seg.TEXT, "for body"); body.ToX86WithLabel(gen, continueLabel); gen.Inst(X86Gen.jmp, iter != null ? secondPlusLabel : firstLabel); /// Generate break labe. gen.Comment(X86Gen.Seg.TEXT, "for end"); gen.Tag(X86Gen.Seg.TEXT, breakLabel); }