示例#1
0
        public override string GenerateCode()
        {
            var s    = "";
            var reg1 = "";

            var exp = Childs[0];//why it only has one son
            var es  = exp.GenerateCode();

            reg1 = MIPS.LastReg();// here we asume that an int has been loaded to the last position

            //s += "\t# Assign\n";
            s += MIPS.Emit(MIPS.Opcodes.usw, reg1, ID + "\t\t\t# " + ID);

            return(es + s);
        }
示例#2
0
        public override string GenerateCode()
        {
            MIPS.ifCount++;
            string actualif = MIPS.ifCount.ToString();
            string tempReg  = MIPS.GetReg();

            string result = "\t#if \n";

            string ifCode = IfExp.GenerateCode();
            string ifReg  = MIPS.LastReg();

            result += ifCode;

            result += MIPS.Emit(MIPS.Opcodes.bne, ifReg, "1", "else" + actualif);

            string thenCode = ThenExp.GenerateCode();

            result += thenCode;
            result += MIPS.Emit(MIPS.Opcodes.move, tempReg, MIPS.LastReg());

            result += MIPS.Emit(MIPS.Opcodes.b, "endif" + actualif);

            result += "\telse" + actualif + ":\n";

            string elseCode = ElseExp.GenerateCode();

            result += elseCode;
            result += MIPS.Emit(MIPS.Opcodes.move, tempReg, MIPS.LastReg());
            result += "\tendif" + actualif + ":\n";

            string resultReg = MIPS.GetReg();

            result += MIPS.Emit(MIPS.Opcodes.move, resultReg, tempReg);

            return(result);
        }