Exemplo n.º 1
0
        public override string GenerateCode()
        {
            /**/
            var s        = "";
            var register = "";

            var v = TryGetValue();

            if (v != null)
            {
                register = MIPS.GetReg();
                s       += MIPS.Emit(MIPS.Opcodes.li, register, v.ToString(), "\t\t\t# calculated in compilation time :)");
                return(s);
            }
            var l = LE.GenerateCode();
            //var reg2 = (MIPS.regCount - 1).ToReg();
            var reg2 = MIPS.LastReg();//

            var r = RE.GenerateCode();
            //var reg1 = (MIPS.regCount - 1).ToReg();
            var reg1 = MIPS.LastReg();//

            register = MIPS.GetReg();

            switch (OP)
            {
            case "+":
                s += MIPS.Emit(MIPS.Opcodes.add, register, reg2, reg1);
                break;

            case "-":
                s += MIPS.Emit(MIPS.Opcodes.sub, register, reg2, reg1);
                break;

            case "*":
                s += MIPS.Emit(MIPS.Opcodes.mul, register, reg2, reg1);
                break;

            case "/":
                s += MIPS.Emit(MIPS.Opcodes.div, register, reg2, reg1);
                break;

            default:
                break;
            }
            if (l.Contains("Method"))
            {
                return(l + r + s);
            }
            else
            {
                return(r + l + s);
            }
        }