Beispiel #1
0
Datei: Is.cs Projekt: 7shi/LLPML
        public override void AddCodesV(OpModule codes, string op, Addr32 dest)
        {
            var f = Parent.GetFunction(Tag);
            if (f == null) throw Abort("is: can not find: {0}", Tag);

            TypeOf.AddCodes(this, Parent, values[1] as NodeBase, codes, "push", null);
            TypeOf.AddCodes(this, Parent, values[0] as NodeBase, codes, "push", null);
            codes.Add(I386.CallD(f.First));
            codes.Add(I386.AddR(Reg32.ESP, Val32.New(8)));
            codes.AddCodes(op, dest);
        }
Beispiel #2
0
 public override void AddCodes(OpModule codes)
 {
     var st = GetStruct();
     if (!st.NeedsInit && values.Count == 0 && !st.NeedsCtor)
         return;
     codes.Add(I386.Lea(Reg32.EAX, GetAddress(codes, Parent)));
     codes.Add(I386.Push(Reg32.EAX));
     var ad = Addr32.New(Reg32.ESP);
     st.AddInit(codes, ad);
     AddInitValues(codes, st);
     st.AddConstructor(codes, ad);
     codes.Add(I386.AddR(Reg32.ESP, Val32.New(4)));
 }
Beispiel #3
0
Datei: New.cs Projekt: 7shi/LLPML
 public override void AddCodesV(OpModule codes, string op, Addr32 dest)
 {
     var tt = Type.Type;
     var tts = tt as TypeStruct;
     if (!IsArray && (tts == null || !tts.IsClass))
         throw Abort("new: is not class: {0}", tts.Name);
     var f = Parent.GetFunction(Function);
     if (f == null)
         throw Abort("new: undefined function: {0}", Function);
     Val32 type = codes.GetTypeObject(Type), izer = Val32.New(0), ctor = Val32.New(0), init = null;
     if (!IsArray)
     {
         var st = tts.GetStruct();
         if (st.IsEmpty)
         {
             init = st.First;
             st = st.GetBaseStruct();
             type = codes.GetTypeObjectD(st);
         }
         izer = codes.GetAddress(st.GetFunction(Define.Initializer));
         ctor = codes.GetAddress(st.GetFunction(Define.Constructor));
     }
     codes.Add(I386.PushD(ctor));
     codes.Add(I386.PushD(izer));
     Length.AddCodesV(codes, "push", null);
     codes.Add(I386.PushD(Val32.NewI(tt.Size)));
     codes.Add(I386.PushD(type));
     codes.Add(I386.CallD(f.First));
     codes.Add(I386.AddR(Reg32.ESP, Val32.New(16)));
     if (init != null)
     {
         codes.Add(I386.Push(Reg32.EAX));
         codes.Add(I386.CallD(init));
         codes.Add(I386.Pop(Reg32.EAX));
     }
     codes.AddCodes(op, dest);
 }
Beispiel #4
0
 protected override void BeforeAddCodes(OpModule codes)
 {
     thisptr.Address = Addr32.NewRO(Reg32.EBP, 8);
     int lv = Level + 1;
     codes.Add(I386.Enter((ushort)(lv * 4), (byte)lv));
     var st = GetBaseStruct();
     if (st != null && !IsEmpty) st.AddInit(codes, thisptr.Address);
 }
Beispiel #5
0
        public void AddInit(OpModule codes, Addr32 ad)
        {
            if (!NeedsInit) return;

            //AddDebug(codes, "AddInit: " + name);
            CallBlock(codes, ad, this, CallType.CDecl);
        }
Beispiel #6
0
 protected override void AfterAddCodes(OpModule codes)
 {
     AddExitCodes(codes);
 }
Beispiel #7
0
 public override void AddDestructors(OpModule codes, VarDeclare[] ptrs)
 {
 }
Beispiel #8
0
 public override void AddExitCodes(OpModule codes)
 {
     codes.Add(I386.Leave());
     codes.Add(I386.Ret());
 }
Beispiel #9
0
 public void AddSetterCodes(OpModule codes, NodeBase arg)
 {
     if (Child != null)
         Child.AddSetterCodes(codes, arg);
     else
         AddSetterCodesInternal(codes, arg);
 }
Beispiel #10
0
        public void AddConstructor(OpModule codes, Addr32 ad)
        {
            if (!NeedsCtor) return;

            //AddDebug(codes, "AddConstructor: " + name);
            var f = GetFunction(Constructor);
            CallBlock(codes, ad, f, f.CallType);
        }
Beispiel #11
0
        private bool AddInitValues(OpModule codes, Define st)
        {
            if (values.Count == 0) return false;

            var members = st.GetMemberDecls();
            if (members.Length != values.Count)
                throw Abort("initializers mismatched: " + st.Name);

            var ad = Addr32.New(Reg32.ESP);
            codes.Add(I386.PushA(ad));
            for (int i = 0; i < values.Count; i++)
            {
                VarDeclare mem = members[i];
                object obj = values[i];
                if (obj is Declare)
                {
                    Define memst = Types.GetStruct(mem.Type);
                    if (!(mem is Declare) || memst == null)
                        throw Abort("struct required: " + mem.Name);
                    (obj as Declare).AddInitValues(codes, memst);
                }
                else if (obj is NodeBase)
                {
                    if (!(mem is VarDeclare))
                        throw Abort("value required: " + mem.Name);
                    (obj as NodeBase).AddCodesV(codes, "mov", null);
                    codes.Add(I386.MovRA(Var.DestRegister, ad));
                    mem.Type.AddSetCodes(codes, Addr32.New(Var.DestRegister));
                }
                else
                    throw Abort("invalid parameter: " + mem.Name);
                codes.Add(I386.AddA(ad, Val32.NewI(mem.Type.Size)));
            }
            codes.Add(I386.AddR(Reg32.ESP, Val32.New(4)));
            return true;
        }
Beispiel #12
0
 public void AddAfterDtor(OpModule codes)
 {
     var list = new ArrayList();
     var poslist = new List<int>();
     int offset = 0;
     var st = GetBaseStruct();
     if (st != null) offset = st.GetSizeInternal();
     ForEachMembers(delegate(VarDeclare p, int pos)
     {
         if (!p.IsStatic && p.NeedsDtor)
         {
             list.Add(p);
             poslist.Add(offset + pos);
         }
         return false;
     }, null);
     var ad = Addr32.NewRO(Reg32.EBP, 8);
     for (int i = list.Count - 1; i >= 0; i--)
     {
         var p = list[i] as VarDeclare;
         codes.Add(I386.MovRA(Var.DestRegister, ad));
         p.Type.AddDestructorA(codes, Addr32.NewRO(Var.DestRegister, poslist[i]));
     }
     if (st != null)
         st.AddDestructor(codes, ad);
 }
Beispiel #13
0
        protected Addr32 GetAddressInternal(OpModule codes)
        {
            var st = GetTargetStruct();
            if (st == null)
                throw Abort("can not find member: {0}", name);

            var mem = st.GetMemberDecl(name);
            if (mem != null && mem.IsStatic)
                return Addr32.NewAd(mem.Address);

            Addr32 ret = null;
            TypeBase t = null;
            var target = Target;
            if (target is Member)
            {
                var tsm = target as Member;
                ret = tsm.GetAddressInternal(codes);
                if (ret != null)
                    t = tsm.TypeInternal;
                else
                {
                    tsm.AddCodesInternal(codes, "mov", null);
                    codes.Add(I386.Mov(Var.DestRegister, Reg32.EAX));
                    ret = Addr32.New(Var.DestRegister);
                }
            }
            else if (target is Var)
            {
                var tv = Var.Get(target);
                ret = tv.GetAddress(codes);
                if (!(tv is Index)) t = tv.Type;
            }
            else if (target != null)
            {
                target.AddCodesV(codes, "mov", null);
                codes.Add(I386.Mov(Var.DestRegister, Reg32.EAX));
                ret = Addr32.New(Var.DestRegister);
            }
            else
            {
                var g = Parent.GetFunction("get_" + TargetType);
                if (g != null)
                {
                    Call.NewName(Parent, g.Name).AddCodesV(codes, "mov", null);
                    if (mem != null)
                    {
                        codes.Add(I386.AddR(Reg32.EAX, Val32.NewI(st.GetOffset(name))));
                        codes.Add(I386.Mov(Var.DestRegister, Reg32.EAX));
                        return Addr32.New(Var.DestRegister);
                    }
                    if (IsFunctionInternal)
                    {
                        // TODO: Delegate
                    }
                    else if (IsGetterInternal)
                    {
                        var gg = GetFunctionPrefix("get_");
                        codes.Add(I386.Push(Reg32.EAX));
                        codes.Add(I386.CallD(gg.First));
                        if (gg.CallType == CallType.CDecl)
                            codes.Add(I386.AddR(Reg32.ESP, Val32.New(4)));
                        return null;
                    }
                    throw Abort("undefined member: {0}.{1}", st.FullName, name);
                }
            }

            if (t != null && t.IsValue)
            {
                codes.Add(I386.MovRA(Var.DestRegister, ret));
                ret = Addr32.New(Var.DestRegister);
            }
            if (mem != null)
            {
                if (ret == null)
                    throw Abort("not static: {0}.{1}", st.FullName, name);
                ret.Add(st.GetOffset(name));
                return ret;
            }

            if (IsFunctionInternal)
            {
                // TODO: Delegate
            }
            else if (IsGetterInternal)
            {
                GetCall("get_", null).AddCodesV(codes, "mov", null);
                return null;
            }

            throw Abort("undefined member: {0}.{1}", st.FullName, name);
        }
Beispiel #14
0
Datei: New.cs Projekt: 7shi/LLPML
 public override void AddCodes(OpModule codes)
 {
     AddCodesV(codes, "mov", null);
 }
Beispiel #15
0
 protected void AddSetterCodesInternal(OpModule codes, NodeBase arg)
 {
     var args = new NodeBase[1];
     args[0] = arg;
     GetCall("set_", args).AddCodes(codes);
 }
Beispiel #16
0
 protected void AddCodesInternal(OpModule codes, string op, Addr32 dest)
 {
     var st = GetTargetStruct();
     var target = Target;
     if (IsLengthInternal)
     {
         if (target is Member)
             (target as Member).AddCodesInternal(codes, "mov", null);
         else
             target.AddCodesV(codes, "mov", null);
         codes.Add(I386.MovRA(Reg32.EAX, Addr32.NewRO(Reg32.EAX, -4)));
         codes.AddCodes(op, dest);
         return;
     }
     else if (IsGetterInternal)
     {
         if (target == null)
         {
             var g = Parent.GetFunction("get_" + TargetType);
             if (g != null)
             {
                 Call.NewName(Parent, g.Name).AddCodesV(codes, "mov", null);
                 var gg = GetFunctionPrefix("get_");
                 codes.Add(I386.Push(Reg32.EAX));
                 codes.Add(I386.CallD(gg.First));
                 if (gg.CallType == CallType.CDecl)
                     codes.Add(I386.AddR(Reg32.ESP, Val32.New(4)));
                 codes.AddCodes(op, dest);
                 return;
             }
         }
         GetCall("get_", null).AddCodesV(codes, op, dest);
         return;
     }
     else if (IsFunctionInternal)
     {
         var delg = GetDelegate();
         if (delg != null)
             delg.AddCodesV(codes, op, dest);
         else
         {
             var fp = Variant.NewName(GetTargetStruct(), name);
             fp.AddCodesV(codes, op, dest);
         }
         return;
     }
     if (st != null)
     {
         var ci = st.GetInt(name);
         if (ci != null)
         {
             ci.AddCodesV(codes, op, dest);
             return;
         }
         var cs = st.GetString(name);
         if (cs != null)
         {
             cs.AddCodesV(codes, op, dest);
             return;
         }
     }
     TypeInternal.AddGetCodes(codes, op, dest, GetAddressInternal(codes));
 }
Beispiel #17
0
 public override Addr32 GetAddress(OpModule codes)
 {
     if (Child != null)
         return Child.GetAddress(codes);
     else
         return GetAddressInternal(codes);
 }
Beispiel #18
0
        private void AddDestructor(OpModule codes, Addr32 ad)
        {
            if (!NeedsDtor) return;

            //AddDebug(codes, "AddDestructor: " + name);
            var dtor = GetFunction(Destructor);
            if (dtor.IsVirtual)
                dtor = GetFunction("override_" + Destructor);
            CallBlock(codes, ad, dtor, dtor.CallType);
        }
Beispiel #19
0
 public void AddBeforeCtor(OpModule codes)
 {
     Define st = GetBaseStruct();
     if (st != null)
         st.AddConstructor(codes, Addr32.NewRO(Reg32.EBP, 8));
 }
Beispiel #20
0
 private void CallBlock(OpModule codes, Addr32 ad, Block b, CallType ct)
 {
     if (ad != null)
         codes.Add(I386.PushA(ad));
     else
         codes.Add(I386.Push(Reg32.EAX));
     codes.Add(I386.CallD(b.First));
     if (ct == CallType.CDecl)
         codes.Add(I386.AddR(Reg32.ESP, Val32.New(4)));
 }
Beispiel #21
0
 public override void AddCodesV(OpModule codes, string op, Addr32 dest)
 {
     if (Child != null)
         Child.AddCodesV(codes, op, dest);
     else
         AddCodesInternal(codes, op, dest);
 }