Esempio n. 1
0
File: TypeOf.cs Progetto: 7shi/LLPML
        public static void AddCodes(NodeBase caller, BlockBase parent, NodeBase target, OpModule codes, string op, Addr32 dest)
        {
            if (target is TypeOf) target = (target as TypeOf).Target;

            var v = target as Variant;
            if (v != null && parent.GetFunction(v.Name) == null)
            {
                var fpname = (target as Variant).Name;
                var fpt = Types.GetType(parent, fpname);
                if (fpt == null || !fpt.Check())
                    throw caller.Abort("undefined type: {0}", fpname);
                codes.AddCodesV(op, dest, codes.GetTypeObject(fpt));
                return;
            }

            var tt = target.Type;
            var tr = tt as TypeReference;
            var tts = tt.Type as TypeStruct;
            if (tr != null && (tr.IsArray || (tts != null && tts.IsClass)))
            {
                target.AddCodesV(codes, "mov", null);
                var label = new OpCode();
                codes.Add(I386.Test(Reg32.EAX, Reg32.EAX));
                codes.Add(I386.Jcc(Cc.Z, label.Address));
                codes.Add(I386.MovRA(Reg32.EAX, Addr32.NewRO(Reg32.EAX, -16)));
                codes.Add(label);
                codes.AddCodes(op, dest);
            }
            else
                codes.AddCodesV(op, dest, codes.GetTypeObject(tt));
        }
Esempio n. 2
0
File: AddrOf.cs Progetto: 7shi/LLPML
 public override void AddCodesV(OpModule codes, string op, Addr32 dest)
 {
     var t = Var.Get(Target);
     if (t == null)
         throw Abort("addrof: variable required");
     var ad = t.GetAddress(codes);
     codes.Add(I386.Lea(Reg32.EAX, ad));
     codes.AddCodes(op, dest);
 }
Esempio n. 3
0
        public override void AddCodesV(OpModule codes, string op, Addr32 dest)
        {
            if (AddConstCodes(codes, op, dest)) return;

            var v = values[0] as NodeBase;
            if (!OpModule.NeedsDtor(v))
                v.AddCodesV(codes, op, dest);
            else
            {
                v.AddCodesV(codes, "mov", null);
                codes.Add(I386.Push(Reg32.EAX));
                codes.AddCodes(op, dest);
                codes.AddDtorCodes(v.Type);
            }
        }
Esempio n. 4
0
        public override void AddCodesV(OpModule codes, string op, Addr32 dest)
        {
            if (AddConstCodes(codes, op, dest)) return;

            var last = new OpCode();
            for (int i = 0; i < values.Count; i++)
            {
                var v = values[i] as NodeBase;
                v.AddCodesV(codes, "mov", null);
                codes.Add(I386.Test(Reg32.EAX, Reg32.EAX));
                codes.Add(I386.Jcc(Cc.Z, last.Address));
            }
            codes.Add(I386.MovR(Reg32.EAX, Val32.New(1)));
            codes.Add(last);
            codes.AddCodes(op, dest);
        }
Esempio n. 5
0
File: OrElse.cs Progetto: 7shi/LLPML
        public override void AddCodesV(OpModule codes, string op, Addr32 dest)
        {
            if (AddConstCodes(codes, op, dest)) return;

            OpCode last = new OpCode();
            for (int i = 0; i < values.Count; i++)
            {
                (values[i] as NodeBase).AddCodesV(codes, "mov", null);
                codes.Add(I386.Test(Reg32.EAX, Reg32.EAX));
                if (i < values.Count - 1)
                    codes.Add(I386.Jcc(Cc.NZ, last.Address));
            }
            codes.Add(last);
            codes.Add(I386.MovR(Reg32.EAX, Val32.New(0)));
            codes.Add(I386.Setcc(Cc.NZ, Reg8.AL));
            codes.AddCodes(op, dest);
        }
Esempio n. 6
0
 public override void AddCodesV(OpModule codes, string op, Addr32 dest)
 {
     var thisdest = Var.Get(this.dest);
     if (thisdest == null)
         throw Abort("{0}: destination is not variable", Tag);
     var ad1 = thisdest.GetAddress(codes);
     var ad2 = ad1;
     thisdest.Type.AddGetCodes(codes, "push", null, ad1);
     if (thisdest.Type.Size < Var.DefaultSize)
     {
         ad2 = Addr32.New(Reg32.ESP);
         codes.Add(I386.PushA(ad2));
     }
     CheckFunc().AddOpCodes(Tag, codes, ad2);
     if (thisdest.Type.Size < Var.DefaultSize)
     {
         codes.Add(I386.Pop(Reg32.EAX));
         thisdest.Type.AddSetCodes(codes, ad1);
     }
     codes.Add(I386.Pop(Reg32.EAX));
     codes.AddCodes(op, dest);
 }
Esempio n. 7
0
 public override void AddCodesV(OpModule codes, string op, Addr32 dest)
 {
     var ad = Calculate(codes);
     if (this.dest.Type.Size < Var.DefaultSize)
         codes.AddCodes(op, dest);
     else
         codes.AddCodesA(op, dest, ad);
 }
Esempio n. 8
0
File: Set.cs Progetto: 7shi/LLPML
 public override void AddCodesV(OpModule codes, string op, Addr32 dest)
 {
     AddCodes(codes);
     codes.AddCodes(op, dest);
 }
Esempio n. 9
0
        public override void AddCodesV(OpModule codes, string op, Addr32 dest)
        {
            if (AddConstCodes(codes, op, dest)) return;

            OpCode last = new OpCode();
            Addr32 ad = Addr32.New(Reg32.ESP);
            var tb = CheckFunc();
            var c = GetCond();
            var v = values[0] as NodeBase;
            v.AddCodesV(codes, "push", null);
            for (int i = 1; i < values.Count; i++)
            {
                codes.AddOperatorCodes(tb, Tag, ad, values[i] as NodeBase, true);
                if (i < values.Count - 1)
                {
                    codes.Add(I386.Jcc(c.NotCondition, last.Address));
                    codes.Add(I386.MovAR(ad, Reg32.EAX));
                }
            }
            codes.Add(last);
            codes.Add(I386.MovR(Reg32.EAX, Val32.New(0)));
            codes.Add(I386.Setcc(c.Condition, Reg8.AL));
            if (!OpModule.NeedsDtor(v))
                codes.Add(I386.AddR(Reg32.ESP, Val32.New(4)));
            else
            {
                codes.Add(I386.XchgRA(Reg32.EAX, Addr32.New(Reg32.ESP)));
                codes.Add(I386.Push(Reg32.EAX));
                codes.AddDtorCodes(v.Type);
                codes.Add(I386.Pop(Reg32.EAX));
            }
            codes.AddCodes(op, dest);
        }
Esempio n. 10
0
 // get value
 public virtual void AddGetCodes(OpModule codes, string op, Addr32 dest, Addr32 src)
 {
     if (src != null) codes.Add(I386.Lea(Reg32.EAX, src));
     codes.AddCodes(op, dest);
 }
Esempio n. 11
0
        public override void AddCodesV(OpModule codes, string op, Addr32 dest)
        {
            if (AddConstCodes(codes, op, dest)) return;

            var ad = Addr32.New(Reg32.ESP);
            var tb = CheckFunc();
            var v = values[0] as NodeBase;
            var schar = "";
            var sint = "";
            if (v.Type is TypeString)
            {
                if (v.Type.CheckFunc(Tag + "-char"))
                    schar = Tag + "-char";
                if (v.Type.CheckFunc(Tag + "-int"))
                    sint = Tag + "-int";
            }
            var tr = v.Type as TypeReference;
            if (tr != null && tr.UseGC && !OpModule.NeedsDtor(v))
            {
                v.AddCodesV(codes, "mov", null);
                codes.Add(I386.Push(Reg32.EAX));
                TypeReference.AddReferenceCodes(codes);
            }
            else
                v.AddCodesV(codes, "push", null);
            for (int i = 1; i < values.Count; i++)
            {
                var vv = values[i] as NodeBase;
                var tag = Tag;
                if (schar != "" && vv.Type is TypeChar)
                    tag = schar;
                else if (sint != "" && vv.Type is TypeIntBase)
                    tag = sint;
                codes.AddOperatorCodes(tb, tag, ad, vv, false);
            }
            if (op != "push")
            {
                codes.Add(I386.Pop(Reg32.EAX));
                codes.AddCodes(op, dest);
            }
        }