Ejemplo n.º 1
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);
                }
            }
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        private static FieldInfo UintSOperation(FieldInfo ret, FieldInfo l, FieldInfo r, LoadClasses load, string oper,
                                                string operC)
        {
            var lsigned = IsSigned(l);
            var rsigned = IsSigned(r);

            if (lsigned == rsigned)
            {
                load.Add(oper, l, r);
                load.Add("mov", ret, RegInfo.eax);
                return(ret);
            }
            PushParams(load, l, r);
            load.Add(oper, RegInfo.eax, RegInfo.ecx);
            load.Add(operC, RegInfo.edx, RegInfo.ebx);
            Move(load, l, Reg.eax, Reg.edx);
            return(ret);
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
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);
 }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
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);
        }
Ejemplo n.º 9
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));
        }
Ejemplo n.º 10
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);
        }
Ejemplo n.º 11
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)
                        {
                        }
                    }
                }
            }
        }
Ejemplo n.º 12
0
        public override FieldInfo Compile(LoadClasses load, Scop scop, Tree tree)
        {
            AsmLabel
                label1 = load.Optimum.SetLabel(null, true),
                label2 = 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", label2);
            var bloc = tree[1];

            if (tree.Count == 2 && bloc.GeneratedBy != null)
            {
                bloc.GeneratedBy.Compile(load, scop, bloc);
            }
            load.Optimum.SetGoto("jmp", label1);
            load.Optimum.SetLabel(label2);
            return(RegInfo.eax);
        }
Ejemplo n.º 13
0
 private static void Move(LoadClasses load, FieldInfo f, Reg a0, Reg a2)
 {
     load.Add("mov", f.Handle.ToDwordPtr, a0);
     load.Add("mov", f.Handle.ToDwordPtr + 4, a2);
 }
Ejemplo n.º 14
0
 private static void FPReturn(FieldInfo ret, LoadClasses load, string cn, AsmLabel returnTrue, AsmLabel returnFalse, AsmLabel @return, bool OrEqual)
 {
     load.Add("cmp", RegInfo.eax, RegInfo.ecx);
     load.Optimum.SetGoto(cn, returnTrue);
     Return(ret, load, returnTrue, returnFalse, @return, OrEqual);
 }
Ejemplo n.º 15
0
        protected override FieldInfo BeginCompile(MethodInfo method, FieldInfo ret, FieldInfo l, FieldInfo r,
                                                  LoadClasses load, Scop scop)
        {
            var    lsigned = IsSigned(l);
            var    rsigned = IsSigned(r);
            var    returnTrue = new AsmLabel("{lasm" + u++ + "}");
            var    returnFalse = new AsmLabel("{lasm" + u++ + "}");
            var    @return = new AsmLabel("{lasm" + u++ + "}");
            string o = "", oc = "";
            var    cnc = "";

            switch (method.Name)
            {
                #region +-&^|
            case "opers":
                return(UintSOperation(ret, l, r, load, o, oc));

            case "+":
                o  = "add";
                oc = "adc";
                goto case "opers";

            case "-":
                o  = "sub";
                oc = "sbb";
                goto case "opers";

            case "&":
                oc = o = "and";
                goto case "opers";

            case "^":
                oc = o = "xor";
                goto case "opers";

            case "|":
                oc = o = "or";
                goto case "opers";
                #endregion

                #region */

            case "*":
                o = "imul";
                goto case "*/";

            case "/":
                o = "idiv";
                goto case "*/";

            case "*/":
                if (lsigned == rsigned)
                {
                    load.Add(o, l, r);
                    load.Add("mov", ret, RegInfo.eax);
                    return(ret);
                }
                if (lsigned)
                {
                    CallManager.swap(ref l, ref r);
                }
                ConvertToLong(load, l, true);
                load.Add("push", RegInfo.edx);
                load.Add("push", RegInfo.eax);
                ConvertToLong(load, r, true);
                load.Add("push", RegInfo.edx);
                load.Add("push", RegInfo.eax);
                load.Optimum.Call(method);
                Move(load, ret, Reg.eax, Reg.eax);
                break;

                #endregion

                #region none

            case ">>":
                break;

            case "<<":
                break;

            case "++":
            case "--":
                load.Add("mov", RegInfo.eax, l);
                load.Add(method.Name == "++" ? "inc" : "dec", RegInfo.eax);
                load.Add("mov", l, RegInfo.eax);
                return(ret);

                #endregion

                #region       ==  !=
            case "==!=":
                if (lsigned != rsigned)
                {
                    return(Compile(ret, l, r, load, o, returnFalse, oc, returnTrue, "je", @return, false, true));
                }
                load.Add("mov", RegInfo.eax, l);
                load.Add("cmp", RegInfo.eax, r);
                load.Add(cnc, RegInfo.eax);
                load.Add("mov", ret, RegInfo.eax);
                return(ret);

            case "==":
                cnc = "sete";
                o   = "jne";
                goto case "==!=";

            case "!=":
                o   = "je";
                cnc = "setne";
                goto case "==!=";

                #endregion
                #region <==>
            case ">=":

                cnc = "sete";
                if (lsigned != rsigned)
                {
                    return(Compile(ret, l, r, load, "jg", returnFalse, "jl", returnTrue, "jb", @return, true));
                }
                goto case "<==>";

            case "<==>":
                load.Add("mov", RegInfo.eax, l);
                load.Add("cmp", RegInfo.eax, r);
                if (cnc == "sete")
                {
                    load.Add("sbb", RegInfo.eax, RegInfo.eax);
                }
                load.Add(cnc, RegInfo.eax);
                load.Add("mov", ret, RegInfo.eax);
                break;

            case "<=":
                cnc = "setbe";
                if (lsigned != rsigned)
                {
                    return(Compile(ret, l, r, load, "jl", returnFalse, "jb", returnTrue, "ja", @return, true));
                }
                goto case "<==>";

                #endregion
            case ">":
                #region >
                if (lsigned == rsigned)
                {
                    load.Add("mov", RegInfo.eax, l);
                    load.Add("cmp", RegInfo.eax, r);
                    load.Add("seta", RegInfo.eax);
                    load.Add("mov", ret, RegInfo.eax);
                    return(ret);
                }
                return(Compile(ret, l, r, load, "jl", returnFalse, "jg", returnTrue, "ja", @return, false));

                #endregion

            case "<":
                #region >
                if (lsigned == rsigned)
                {
                    load.Add("mov", RegInfo.eax, l);
                    load.Add("cmp", RegInfo.eax, r);
                    load.Add("sbb", RegInfo.eax, RegInfo.eax);
                    load.Add("neg", RegInfo.eax);
                    load.Add("mov", ret, RegInfo.eax);
                    return(ret);
                }
                return(Compile(ret, l, r, load, "jg", returnFalse, "jl", returnTrue, "jb", @return, false));

                #endregion
            }
            return(ret);
        }
Ejemplo n.º 16
0
        protected override FieldInfo BeginCompile(MethodInfo method, FieldInfo ret, FieldInfo l, FieldInfo r,
                                                  LoadClasses load, Scop scop)
        {
            var o = (string)null;

            switch (method.Name)
            {
            case "+":
                o = "add";
                break;

            case "-":
                o = "sub";
                break;

            case "*":
                o = "imul";
                break;

            case "/":
                o = "idiv";
                break;

            case "&":
                o = "and";
                break;

            case "^":
                o = "xor";
                break;

            case "|":
                o = "or";
                break;

            case ">>":
                o = "shr";
                break;

            case "<<":
                o = "shl";
                break;

            case "++":
                load.Add("mov", RegInfo.eax, l);
                load.Add("inc", RegInfo.eax);
                load.Add("mov", l, RegInfo.eax);
                return(ret);

            case "--":
                load.Add("mov", RegInfo.eax, l);
                load.Add("dec", RegInfo.eax);
                load.Add("mov", l, RegInfo.eax);
                return(ret);

            case "==":
                load.Add("mov", RegInfo.eax, l);
                load.Add("cmp", RegInfo.eax, r);
                load.Add("sete", RegInfo.eax);
                break;

            case ">=":
                load.Add("mov", RegInfo.eax, l);
                load.Add("cmp", RegInfo.eax, r);
                load.Add("setge", RegInfo.eax);
                break;

            case "<=":
                load.Add("mov", RegInfo.eax, l);
                load.Add("cmp", RegInfo.eax, r);
                load.Add("setle", RegInfo.eax);
                break;

            case ">":
                load.Add("cmp", l, r);
                load.Add("setg", RegInfo.eax);
                break;

            case "<":
                load.Add("cmp", l, r);
                load.Add("setl", RegInfo.eax);
                break;

            case "!=":
                load.Add("cmp", l, r);
                load.Add("setne", RegInfo.eax);
                break;
            }
            if (o != null)
            {
                load.Add(o, l, r);
            }
            load.Add("mov", ret, RegInfo.eax);
            return(ret);
        }