Esempio n. 1
0
        public override FieldInfo Compile(LoadClasses load, Scop scop, Tree tree)
        {
            var      hasElse = tree.Count == 3;
            AsmLabel debElse = load.Optimum.SetLabel(null, false),
                     finElse = load.Optimum.SetLabel(null, false);

            var condition = load.Compile(scop, tree[0]);

            if (condition == null || condition.Return != Assembly.Bool)
            {
                load.LogIn(scop, tree, condition, "Condition Value Must be Of Type System.Bool");
            }

            load.Add("test", condition, FieldInfo.Immediate(0));
            load.Optimum.SetGoto("jne", debElse);
            if (tree[1].GeneratedBy != null)
            {
                tree[1].GeneratedBy.Compile(load, scop, tree[1]);
                load.Optimum.SetLabel(debElse);
                if (!hasElse)
                {
                    return(null);
                }
                load.Optimum.SetGoto("jmp", finElse);
                tree[2].GeneratedBy.Compile(load, scop, tree[2]);
                load.Optimum.SetLabel(finElse);
            }
            else
            {
                load.Optimum.SetLabel(debElse);
            }
            return(null);
        }
Esempio n. 2
0
 private static void ConvertToLong(LoadClasses load, FieldInfo f, bool left)
 {
     if (IsSigned(f))
     {
         if (left)
         {
             load.Add("mov", RegInfo.eax, f);
             load.Add("cdq");
         }
         else
         {
             load.Add("mov", RegInfo.ecx, f);
             load.Add("mov", RegInfo.ebx, RegInfo.ecx);
             load.Add("sar", RegInfo.ebx, new ConstInfo(Assembly.Byte, new[] { (byte)0x1F }));
         }
     }
     else if (left)
     {
         load.Add("mov", RegInfo.eax, f);
         load.Add("xor", RegInfo.edx, RegInfo.edx);
     }
     else
     {
         load.Add("mov", RegInfo.ecx, f);
         load.Add("xor", RegInfo.ebx, RegInfo.ebx);
     }
 }
Esempio n. 3
0
        public override FieldInfo Compile(LoadClasses load, Scop scop, Tree tree)
        {
            if (tree.Count == 3 && tree[2].Kind == Kind.Numbre)
            {
            }
            var dataPortor = scop as DataPortor;
            var l          = load.SetVariable(dataPortor, tree);

            tree[1].BaseCall = tree.BaseCall = dataPortor;
            tree[1].Type     = tree.Type = l.Return;
            tree[1].Membre   = tree.Membre = l;
            tree[1].Compiled = true;
            tree.Compiled    = true;
            if (tree.Children.Count == 2)
            {
                return(null);
            }
            var fieldInfo = load.Compile(scop, tree[2]);

            if (l != fieldInfo)
            {
                load.Optimum.Assign(l, fieldInfo);
            }
            return(l);
        }
Esempio n. 4
0
 public override FieldInfo Compile(LoadClasses load, Scop scop, Tree tree)
 {
     if (tree.Method == null)
     {
         tree.Method = load.GetMethod(tree[0], tree[1].Children);
     }
     if (tree.Method == null)
     {
         load.LogIn(scop, tree, this, "Function(" + tree[0].Content + ") Entrer cannot be found");
         return(null);
     }
     if (tree.Method.ISCPUMethod)
     {
         var parm = new List <FieldInfo>(2);
         foreach (Tree e in tree[1])
         {
             parm.Add(load.Compile(scop, e));
         }
     }
     foreach (Tree e in tree[1])
     {
         var z = load.Compile(scop, e);
         load.Optimum.PushParam(z);
     }
     load.Optimum.Call(tree.Method);
     return(tree.Membre = RegInfo.eax);
 }
Esempio n. 5
0
        public override FieldInfo Compile(LoadClasses load, Scop scop, Tree tree)
        {
            if (!new TypeCalc(load.ByteCodeMapper).CalcTypes(tree))
            {
                load.LogIn(scop, tree, this, "there are undefined variables or methods in expression : " + tree.Content);
                return(tree[0].Membre);
            }
            tree.Parcure(tree.Parent, (MethodInfo)scop);
            var m = load.Compile(scop, tree[0]);
            var n = tree.Count == 3 ? load.Compile(scop, tree[2]) : null;

            if (tree.Method is CPUMethodInfo)
            {
                var e = Qs.Pdb.CPU.CPUType.Call(load, scop, tree.Membre, tree.Method, tree[0].Membre, tree[2].Membre);
                //TODO :Obsolete load.Caller.Call(scop, tree.Method, m, n, tree.Membre);
            }
            else
            {
                load.Optimum.PushParam(m);
                if (n != null)
                {
                    load.Optimum.PushParam(n);
                }
                load.Optimum.Call(tree.Method);
            }
            return(tree.Membre);
        }
Esempio n. 6
0
        public static FieldInfo Call(LoadClasses load, Scop scop, FieldInfo ret, MethodInfo method, FieldInfo l, FieldInfo r)
        {
            var cpuTypeL = instants[l.Return];
            var cpuTypeR = instants[r.Return];

            return((cpuTypeL.Index < cpuTypeR.Index ? cpuTypeL : cpuTypeR).BeginCompile(method, ret, l, r, load, scop));
        }
Esempio n. 7
0
        internal static void pushParam(LoadClasses load, Operand l, bool first, bool signed, bool islong = true)
        {
            if (first)
            {
                load.Add("mov", Reg.eax, l);
                if (islong)
                {
                    load.Add("mov", Reg.edx, l + 4);
                }
                else if (signed)
                {
                    load.Add("cdq");
                }
                else
                {
                    load.Add("xor", Reg.edx, Reg.edx);
                }
            }
            else

            {
                load.Add("mov", Reg.ecx, l);
                if (signed)
                {
                    load.Add("mov", Reg.ebx, Reg.ecx);
                    load.Add("sar", RegInfo.ebx, c1F);
                }
                else
                {
                    load.Add("xor", Reg.ebx, Reg.ebx);
                }
            }
        }
Esempio n. 8
0
        public override FieldInfo Compile(LoadClasses load, Scop scop, Tree tree)
        {
            var ret = load.Compile(scop, tree[1]); //.GeneratedBy.Compile(load, scop, tree[0]);

            load.Return(scop, ret);
            return(null);
        }
Esempio n. 9
0
 internal void pushParam(LoadClasses load, Operand l, bool first, bool isigned, bool islong, bool iscpucall)
 {
     if (iscpucall)
     {
         pushParam(load, l, first, isigned, islong);
     }
     else
     //if (first)
     if (islong)
     {
         load.Add("push", l + 4);
         load.Add("push", l);
     }
     else if (isigned)
     {
         load.Add("mov", Reg.eax, l);
         load.Add("cdq");
         load.Add("push", Reg.edx);
         load.Add("push", Reg.eax);
     }
     else
     {
         load.Add("xor", Reg.edx, Reg.edx);
         load.Add("push", Reg.edx);
         load.Add("push", l);
     }
 }
Esempio n. 10
0
        private static FieldInfo @return(LoadClasses load, FieldInfo ret)
        {
            var _ret = ret.Handle;

            load.Add("mov", _ret, Reg.eax);
            load.Add("mov", _ret + 4, Reg.eax);
            return(ret);
        }
Esempio n. 11
0
 public virtual FieldInfo Compile(LoadClasses load, Scop scop, Tree tree)
 {
     foreach (Tree t in tree)
     {
         t.GeneratedBy.Compile(load, scop, t);
     }
     return(null);
 }
Esempio n. 12
0
        protected override FieldInfo BeginCompile(MethodInfo method, FieldInfo ret, FieldInfo l, FieldInfo r,
                                                  LoadClasses load, Scop scop)
        {
            switch (method.Name)
            {
            case "+":
                return(add(ret, l, r, load));

            case "-":
                return(sub(ret, l, r, load));

            case "*":
            case "/":
                return(mul(method, ret, l, r, load));

            case "&":
                return(and(ret, l, r, load));

            case "^":
                return(xor(ret, l, r, load));

            case "|":
                return(or(ret, l, r, load));

            case ">>":
                return(shr(method, ret, l, r, load));

            case "<<":
                return(shl(method, ret, l, r, load));

            case "++":
                return(inc(l, load));

            case "--":
                return(dec(l, load));

            case "==":
                return(eq_ne(ret, l, r, load, true));

            case "!=":
                return(eq_ne(ret, l, r, load));

            case ">=":
                return(lte_gte(ret, l, r, load, false));

            case "<=":
                return(lte_gte(ret, l, r, load, true));

            case ">":
                return(lt_gt(ret, l, r, load, false));

            case "<":
                return(lt_gt(ret, l, r, load, true));
            }
            return(ret);
        }
Esempio n. 13
0
 private static FieldInfo Compile(FieldInfo ret, FieldInfo l, FieldInfo r, LoadClasses load, string o, AsmLabel returnFalse, string oc, AsmLabel returnTrue, string cn, AsmLabel @return, bool orEqual, bool IsEquality = false)
 {
     PushParams(load, l, r);
     load.Add("cmp", RegInfo.edx, RegInfo.ebx);
     load.Optimum.SetGoto(o, returnFalse);
     if (!IsEquality)
     {
         load.Optimum.SetGoto(oc, returnTrue);
     }
     FPReturn(ret, load, cn, returnTrue, returnFalse, @return, orEqual);
     return(ret);
 }
Esempio n. 14
0
        private AsmLabel PushParams(FieldInfo l, FieldInfo r, LoadClasses load, out AsmLabel trueLabel,
                                    out AsmLabel returnLabel)
        {
            trueLabel   = new AsmLabel("{asm3}");
            returnLabel = new AsmLabel("{ret}" + CPUUInt.u);
            pushParam(load, l.Handle, true, IsSigned(l.Return), l.Return == Assembly.Long);

            if (r.Return != Assembly.Long)
            {
                pushParam(load, r.Handle, false, IsSigned(r.Return), false);
            }
            return(new AsmLabel("{asm1}"));
        }
Esempio n. 15
0
 internal static void call(LoadClasses load, string op, string cop, Operand r = null)
 {
     if (r == null)
     {
         load.Add(op, Reg.eax, Reg.ecx);
         load.Add(cop, Reg.edx, Reg.ebx);
     }
     else
     {
         load.Add(op, Reg.eax, r);
         load.Add(cop, Reg.edx, r + 4);
     }
 }
Esempio n. 16
0
        FieldInfo mul(MethodInfo method, FieldInfo ret, FieldInfo l, FieldInfo r, LoadClasses load)
        {
            var ol      = l.Handle;
            var or      = r.Handle;
            var rsigned = r.Return == Assembly.Int || r.Return == Assembly.Short;
            var lsigned = l.Return == Assembly.Int || l.Return == Assembly.Short;

            pushParam(load, ol, true, lsigned, l.Return == Assembly.Long, false);
            pushParam(load, or, true, rsigned, l.Return == Assembly.Long, false);
            load.Optimum.Call(method);
            @return(load, ret);
            return(ret);
        }
Esempio n. 17
0
        public override FieldInfo Compile(LoadClasses load, Scop scop, Tree tree)
        {
            var method = scop as MethodInfo;
            var l      = load.SetVariable(method, tree);

            tree.BaseCall = method;
            tree.Type     = l.Return;
            tree.Membre   = l;
            tree.Compiled = true;
            if (tree.Children.Count == 2)
            {
                return(l);
            }
            return(l);
        }
Esempio n. 18
0
        public override FieldInfo Compile(LoadClasses load, Scop scop, Tree tree)
        {
            var space = scop.GetSpace(tree[0].Content, SearcheMode.Flaten);

            load.ByteCodeMapper.OpenScop(space);
            foreach (Tree t in tree)
            {
                if (t.GeneratedBy != null)
                {
                    t.GeneratedBy.Compile(load, space, t);
                }
            }
            load.ByteCodeMapper.CloseScop();
            return(null);
        }
Esempio n. 19
0
        internal static FieldInfo sub(FieldInfo ret, FieldInfo l, FieldInfo r, LoadClasses load)
        {
            var ol      = l.Handle;
            var or      = r.Handle;
            var rsigned = r.Return == Assembly.Int || r.Return == Assembly.Short;
            var lsigned = l.Return == Assembly.Int || l.Return == Assembly.Short;

            pushParam(load, ol, true, lsigned, l.Return == Assembly.Long);
            if (instants[l.Return].Index <= instants[r.Return].Index && r.Return != Assembly.Long)
            {
                pushParam(load, or, false, rsigned);
            }
            call(load, "sub", "sbb", r.Return == Assembly.Long ? or : null);
            return(@return(load, ret));
        }
Esempio n. 20
0
        public override FieldInfo Compile(LoadClasses load, Scop scop, Tree tree)
        {
            var
                label1 = load.Optimum.SetLabel(null, true);

            load.Compile(scop, tree[0]);
            var condition = tree[1].GeneratedBy.Compile(load, scop, tree[1]);

            if (condition == null || condition.Return != Assembly.Bool)
            {
                load.LogIn(scop, tree, tree[1], "Condition Value Must be Of Type System.Bool");
            }
            load.Add("test", condition, FieldInfo.Immediate(0));
            load.Optimum.SetGoto("jne", label1);
            return(RegInfo.eax);
        }
Esempio n. 21
0
        internal static FieldInfo add(FieldInfo ret, FieldInfo l, FieldInfo r, LoadClasses load)
        {
            if (instants[l.Return].Index > instants[r.Return].Index)
            {
                CallManager.swap(ref l, ref r);
            }
            var ol = l.Handle;
            var or = r.Handle;

            pushParam(load, ol, true, false);
            if (r.Return != Assembly.Long)
            {
                pushParam(load, or, false, r.Return == Assembly.Int || r.Return == Assembly.Short);
            }
            call(load, "add", "adc", r.Return == Assembly.Long ? or : null);
            return(@return(load, ret));
        }
Esempio n. 22
0
        public override FieldInfo Compile(LoadClasses load, Scop scop, Tree tree)
        {
            var dataPortor = scop as DataPortor;
            var l          = load.SetVariable(dataPortor, tree[0]);

            tree.BaseCall = dataPortor;
            tree.Type     = l.Return;
            tree.Membre   = l;
            tree.Compiled = true;
            if (tree.Children.Count == 2)
            {
                return(null);
            }
            var fieldInfo = load.Compile(scop, tree[1]);

            return(load.Add("mov", l, fieldInfo));
        }
Esempio n. 23
0
        private static void Return(FieldInfo ret, LoadClasses load, AsmLabel returnTrue, AsmLabel returnFalse, AsmLabel @return, bool OrEqual)
        {
//Return True
            load.Optimum.SetLabel(returnTrue);
            load.Add("mov", RegInfo.eax, ConstInfo.True);
//Return False
            load.Optimum.SetLabel(returnFalse);
            load.Add("xor", RegInfo.eax, RegInfo.eax);
            load.Optimum.SetGoto("jmp", @return);
//Return
            load.Optimum.SetLabel(@return);
            if (OrEqual)
            {
                load.Add("test", RegInfo.eax, RegInfo.eax);
                load.Add("sete", RegInfo.eax);
            }
            load.Add("mov", ret, RegInfo.eax);
        }
Esempio n. 24
0
        public override FieldInfo Compile(LoadClasses load, Scop scop, Tree tree)
        {
            var @class = scop.GetClass(tree[0].Content, SearcheMode.Flaten);

            load.ByteCodeMapper.OpenScop(@class);
            foreach (Tree t in tree)
            {
                if (t.Kind == Kind.Function || t.Kind == Kind.Constructor)
                {
                    if (t.GeneratedBy != null)
                    {
                        t.GeneratedBy.Compile(load, @class, t);
                    }
                }
            }
            load.ByteCodeMapper.CloseScop();
            return(null);
        }
Esempio n. 25
0
        private static FieldInfo lt_gt(FieldInfo ret, FieldInfo l, FieldInfo r, LoadClasses load, bool is_lt_gt)
        {
            string jm1, jm2, jm3;

            if (is_lt_gt)
            {
                jm1 = "jg";
                jm2 = "jl";
                jm3 = "jb";
            }
            else
            {
                jm1 = "jl";
                jm2 = "jg";
                jm3 = "ja";
            }
            AsmLabel falseLabel  = new AsmLabel("{asm1}"),
                     trueLabel   = new AsmLabel("{asm3}"),
                     returnLabel = new AsmLabel("{ret}" + CPUUInt.u);

            var r_islong = r.Return == Assembly.Long;

            pushParam(load, l.Handle, true, IsSigned(l.Return), l.Return == Assembly.Long);
            if (!r_islong)
            {
                pushParam(load, r.Handle, false, IsSigned(r.Return), false);
            }

            load.Add("cmp", Reg.edx, !r_islong ? Reg.ebx : r.GetHandle(4));
            load.Optimum.SetGoto(jm1, trueLabel, load, cByte.Clone());
            load.Optimum.SetGoto(jm2, falseLabel, load, cByte.Clone());
            load.Add("cmp", RegInfo.eax, !r_islong ? RegInfo.ecx : r);
            load.Optimum.SetGoto(jm3, trueLabel, load, cByte.Clone());
            load.Optimum.SetLabel(falseLabel);
            load.Add("xor", RegInfo.eax, RegInfo.eax);
            load.Optimum.SetGoto("jmp", returnLabel, load, new Operand(0xFF, DataType.Byte));
            load.Optimum.SetLabel(trueLabel);
            load.Add("mov", Reg.eax, new Operand(1, DataType.Byte));
            load.Optimum.SetLabel(returnLabel);
            load.Add("mov", ret, RegInfo.eax);
            return(ret);
        }
Esempio n. 26
0
        private FieldInfo lte_gte(FieldInfo ret, FieldInfo l, FieldInfo r, LoadClasses load, bool is_lte_gte)
        {
            string jm1;
            string jm2;
            string jm3;

            if (is_lte_gte)
            {
                jm1 = "jl";
                jm2 = "jg";
                jm3 = "ja";
            }
            else
            {
                jm1 = "jg";
                jm2 = "jl";
                jm3 = "jb";
            }
            var      r_islong = r.Return == Assembly.Long;
            AsmLabel trueLabel;
            AsmLabel returnLabel;
            var      falseLabel = PushParams(l, r, load, out trueLabel, out returnLabel);

            load.Add("cmp", Reg.edx, r_islong ? r.Handle + 4 : Reg.ebx);
            load.Optimum.SetGoto(jm1, trueLabel, load, cByte.Clone());
            load.Optimum.SetGoto(jm2, falseLabel, load, cByte.Clone());
            load.Add("cmp", RegInfo.eax, r_islong ? r : RegInfo.ecx);

            load.Optimum.SetGoto(jm3, trueLabel, load, cByte.Clone());
            load.Optimum.SetLabel(falseLabel);
            load.Add("xor", RegInfo.eax, RegInfo.eax);
            load.Optimum.SetGoto("jmp", returnLabel, load, new Operand(0xFF, DataType.Byte));
            load.Optimum.SetLabel(trueLabel);
            load.Add("mov", Reg.eax, new Operand(1, DataType.Byte));
            load.Optimum.SetLabel(returnLabel);

            load.Add("test", RegInfo.eax, RegInfo.eax);
            load.Add("sete", RegInfo.eax);
            load.Add("mov", ret, RegInfo.eax);
            return(ret);
        }
Esempio n. 27
0
        public static void _Test()
        {
            while (true)
            {
                __test();

                var parse = new BasicParse {
                    Pile = new Pile(Prg_Example)
                };
                var parent = new Tree(parse.Pile, null, Kind.Program);
                var glob   = CurrentScop.Initialize("globe");
                Update(parse);
                var s = new Space(parse);
                if (s.Parse(parent))
                {
                    var byteCode = new ByteCodeMapper(glob);
                    var load     = new LoadClasses(byteCode);
                    load.Add(parent[0]);
                    load.Compile();
                    var inst = load.Optimum.Instructs;
                    var sw   = new IO.Stream.StreamWriter(true);
                    for (int i = 0; i < inst.Count; i++)
                    {
                        inst[i].Push(sw);
                    }
                    var tt = inst[0].Length;
                    var sr = new IO.Stream.StreamReader(sw);
                    for (int i = 0; i < inst.Count; i++)
                    {
                        var x     = Instruct.Pop(sr);
                        var isieq = x.Equals(inst[i]);
                        if (!isieq)
                        {
                        }
                    }
                }
            }
        }
Esempio n. 28
0
        private FieldInfo eq_ne(FieldInfo ret, FieldInfo l, FieldInfo r, LoadClasses load,
                                bool iseq = false)
        {
            var      r_islong = r.Return == Assembly.Long;
            AsmLabel trueLabel;
            AsmLabel returnLabel;
            var      falseLabel = PushParams(l, r, load, out trueLabel, out returnLabel);

            load.Add("cmp", Reg.edx, r_islong ? r.GetHandle(4) : Reg.ebx);

            load.Optimum.SetGoto("jne", iseq ? falseLabel : trueLabel, load, new Operand(0xFFFF, DataType.Byte));
            load.Add("cmp", RegInfo.eax, r_islong ? r : RegInfo.ecx);

            load.Optimum.SetGoto(iseq ? "je" : "jne", trueLabel, load, new Operand(0xFFFF, DataType.Byte));
            load.Optimum.SetLabel(falseLabel);
            load.Add("xor", RegInfo.eax, RegInfo.eax);
            load.Optimum.SetGoto("jmp", returnLabel, load, new Operand(0xFFFF, DataType.Byte));
            load.Optimum.SetLabel(trueLabel);
            load.Add("mov", Reg.eax, new Operand(1, DataType.Byte));
            load.Optimum.SetLabel(returnLabel);
            load.Add("mov", ret, RegInfo.eax);
            return(ret);
        }
Esempio n. 29
0
        private bool Initialize(LoadClasses load, Scop scop, Tree tree, out MethodInfo method)
        {
            if (tree.Method == null)
            {
                load.LogIn(scop, tree, this, "Method Name " + tree[1].Content + " not founded");
                method = null;
                return(false);
            }
            method = tree.Method;
            if (method.Return == null)
            {
                method.Return = load.ByteCodeMapper.Finder.GetClass(load.ByteCodeMapper.CurrentScop.Root,
                                                                    tree[0].Content);
            }
            if (method.Return == null || !method.Return.Finalized)
            {
                throw new BadImageFormatException();
            }
            method.Offset = load.ByteCodeMapper.StreamWriter.Offset;
            load.ByteCodeMapper.OpenScop(method);

            return(true);
        }
Esempio n. 30
0
        public override FieldInfo Compile(LoadClasses load, Scop scop, Tree tree)
        {
            MethodInfo method;

            if (!Initialize(load, scop, tree, out method))
            {
                return(null);
            }
            load.Optimum.Reset(method);
            #region Function Head
            var param = tree[2].Children;
            load.Optimum.Add("mov", Reg.esi, Reg.ebp);
            load.Optimum.Add("pop", Reg.ebp);
            Operand op = new Operand(0xFFFF);
            load.Optimum.Add("add", Reg.esp, op);
            for (var i = param.Count - 1; i >= 0; i--)
            {
                var pr = param[i];
                load.Optimum.PopParam(pr.GeneratedBy.Compile(load, method, pr));
            }
            load.Optimum.Add("push", Reg.esi);
            #endregion

            var fieldInfo = tree[3].GeneratedBy.Compile(load, method, tree[3]);

            #region Function Feet
            load.Optimum.SetLabel(MethodInfo.ReturnLabel);
            load.Optimum.Add("pop", Reg.ebp);
            load.Optimum.Add("sub", Reg.esp, op);
            load.Optimum.Add("ret", (Operand)null);
            #endregion
            op.Imm = method.DataSize;
            load.ByteCodeMapper.CloseScop();
            load.Optimum.Finalize();
            return(fieldInfo);
        }