Ejemplo n.º 1
0
 /// <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);
 }
Ejemplo n.º 2
0
        /// <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);
        }
Ejemplo n.º 3
0
        public override void ToX86(X86Gen gen)
        {
            gen.Comment(X86Gen.Seg.TEXT, ToString());
            if (expr == null)
            {
                gen.Inst(X86Gen.jmp, label);
                return;
            }
            var ret = expr.ToX86Expr(gen);

            switch (expr.Type.Kind)
            {
            case TKind.CHAR:
            case TKind.SCHAR:
            case TKind.UCHAR:
                if (ret == X86Gen.Ret.PTR)
                {
                    gen.Inst(X86Gen.mov, X86Gen.al, X86Gen.eax.Addr(X86Gen.Size.BYTE));
                }
                gen.Inst(X86Gen.jmp, label);
                return;

            case TKind.SHORT:
            case TKind.USHORT:
                if (ret == X86Gen.Ret.PTR)
                {
                    gen.Inst(X86Gen.mov, X86Gen.ax, X86Gen.eax.Addr(X86Gen.Size.WORD));
                }
                gen.Inst(X86Gen.jmp, label);
                return;

            case TKind.ENUM:
            case TKind.PTR:
            case TKind.UINT:
            case TKind.ULONG:
            case TKind.INT:
            case TKind.LONG:
                if (ret == X86Gen.Ret.PTR)
                {
                    gen.Inst(X86Gen.mov, X86Gen.eax, X86Gen.eax.Addr());
                }
                gen.Inst(X86Gen.jmp, label);
                return;

            case TKind.DOUBLE:
                if (ret == X86Gen.Ret.PTR)
                {
                    gen.Inst(X86Gen.movsd, X86Gen.xmm0, X86Gen.eax.Addr(X86Gen.Size.QWORD));
                }
                gen.Inst(X86Gen.sub, X86Gen.esp, 8);
                gen.Inst(X86Gen.movsd, X86Gen.esp.Addr(X86Gen.Size.QWORD), X86Gen.xmm0);
                gen.Inst(X86Gen.fld, X86Gen.esp.Addr(X86Gen.Size.QWORD));
                gen.Inst(X86Gen.add, X86Gen.esp, 8);
                gen.Inst(X86Gen.jmp, label);
                return;
            }

            throw new NotImplementedException();
        }
Ejemplo n.º 4
0
 public void Dump(X86Gen gen)
 {
     gen.Comment(X86Gen.Seg.TEXT, string.Format("Frame Size: {0}", size));
     gen.Comment(X86Gen.Seg.TEXT, string.Format("{0, -10} {1, -5} {2, -10} {3, -20}",
                                                "EBP",
                                                "UID",
                                                "SYMBOL",
                                                "TYPE"
                                                ));
     foreach (var o in objs)
     {
         gen.Comment(X86Gen.Seg.TEXT, string.Format("{0, -10} {1, -5} {2, -10} {3, -20}",
                                                    o.ebp,
                                                    o.uid,
                                                    o.symbol,
                                                    o.type
                                                    ));
     }
 }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
        /// <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);
        }
Ejemplo n.º 7
0
 public override void ToX86(X86Gen gen)
 {
     gen.Comment(X86Gen.Seg.TEXT, ToString());
     gen.Inst(X86Gen.jmp, label);
 }