Ejemplo n.º 1
0
        internal override string Generate(DirectTranslation translation)
        {
            string v1 = expression1.Generate(translation);
            string v2 = expression2.Generate(translation);
            string i1 = id1.Generate(translation);
            string i2 = id2.Generate(translation);

            translation.AddAssembly("v_mov", "RV14", v1);
            translation.AddAssembly("v_mov", "RV15", v2);
            translation.AddCallerSave();
            translation.AddAssembly("Trace");
            translation.AddCallerRestore();
            translation.AddAssembly("v_mov", i1, "RV14");
            translation.AddAssembly("v_mov", i2, "RV15");
            return(null);
        }
Ejemplo n.º 2
0
        internal override string Generate(DirectTranslation translation)
        {
            string temp    = expression.Generate(translation);
            string tempVar = $".S{VariableCounter}";

            translation.AddAssembly("v_reduce", tempVar, temp);
            return(tempVar);
        }
Ejemplo n.º 3
0
        internal override string Generate(DirectTranslation translation)
        {
            string tempVar = func.Type == Type.VECTOR ? ".V" : ".S" + VariableCounter;
            var    args    = expressionList.GenerateArgs(translation, func);

            translation.AddAssembly("s_push", "RS30");
            // translation.AddBranch("jmp_link", identifier);
            translation.AddCallerSave();
            translation.AddFunctionCall(identifier, args, func.Type);
            translation.AddCallerRestore();
            translation.AddAssembly("s_pop", "RS30");
            if (func.Type == Type.VECTOR)
            {
                translation.AddAssembly("v_mov", tempVar, "RV1");
            }
            else
            {
                translation.AddAssembly("s_mov", tempVar, "RS1");
            }
            return(tempVar);
        }
Ejemplo n.º 4
0
        internal override string Generate(DirectTranslation translation)
        {
            string temp = expression.Generate(translation);
            string tempVar;

            if (temp[2] == '.') // temp is not temporary
            {
                tempVar = $".S{VariableCounter}";
            }
            else
            {
                tempVar = temp;
            }
            if (type == Type.FLOAT)
            {
                translation.AddAssembly("s_itof", tempVar, temp);
            }
            else
            {
                translation.AddAssembly("s_ftoi", tempVar, temp);
            }
            return(tempVar);
        }
Ejemplo n.º 5
0
        internal List <string> GenerateArgs(DirectTranslation translation, Symbol func)
        {
            int           vector = 1, scalar = 1;
            List <string> ret = new List <string>();

            for (int i = 0; i < list.Count; i++)
            {
                string tempVar = list[i].Generate(translation);
                if (func.ParametersType[i] == Type.VECTOR)
                {
                    ret.Add($"RV{vector}");
                    translation.AddAssembly("v_mov", $"RV{vector}", tempVar);
                    vector++;
                }
                else
                {
                    ret.Add($"RS{scalar}");
                    translation.AddAssembly("s_mov", $"RS{scalar}", tempVar);
                    scalar++;
                }
            }
            return(ret);
        }
Ejemplo n.º 6
0
        internal override string Generate(DirectTranslation translation)
        {
            string temp = exp.Generate(translation);
            string tempVar;

            if (temp[2] == '.') // temp is not temporary
            {
                tempVar = $".{temp[1]}{VariableCounter}";
            }
            else
            {
                tempVar = temp;
            }
            switch (expType)
            {
            case CompilerCore.Type.INT:
                switch (type)
                {
                case Type.NEGATE:
                    translation.AddAssembly("ii_sub", tempVar, "RS0", temp);
                    break;

                case Type.NOT:
                {
                    string skipLabel = "L" + LabelCounter;
                    translation.AddAssembly("cmp_i", "RS0", temp);
                    translation.AddAssembly("s_setzero", tempVar);             // != 0
                    translation.AddBranch("bne", skipLabel);
                    translation.AddAssembly("ii_addi", tempVar, "RS0", "1");   // == 0
                    translation.AddLabel(skipLabel);
                }
                break;

                case Type.BITWISE_NOT:
                    translation.AddAssembly("not", tempVar, temp);
                    break;

                default:
                    break;
                }
                break;

            case CompilerCore.Type.FLOAT:
                translation.AddAssembly("ff_sub", tempVar, "RS0", temp);
                break;

            case CompilerCore.Type.VECTOR:
                translation.AddAssembly("vv_sub", tempVar, "RV0", temp);
                break;
            }
            return(tempVar);
        }
Ejemplo n.º 7
0
        internal override string Generate(DirectTranslation translation)
        {
            string temp = expression.Generate(translation);
            string tempVar;

            if (temp[2] == '.') // temp is not temporary
            {
                tempVar = $".S{VariableCounter}";
            }
            else
            {
                tempVar = temp;
            }
            translation.AddAssembly("s_sqrt", tempVar, temp);
            return(tempVar);
        }
Ejemplo n.º 8
0
        internal override string Generate(DirectTranslation translation)
        {
            string pointer = expression.Generate(translation);
            string index   = indexExpression.Generate(translation);
            string tempVar = valueType == Type.VECTOR_POINTER ? $".V{VariableCounter}" :
                             pointer[2] == '.' ? $".S{VariableCounter}" : pointer;
            string indexVar, pointerVar;

            if (index[2] == '.') // index is not temporary
            {
                indexVar = $".{index[1]}{VariableCounter}";
            }
            else
            {
                indexVar = index;
            }
            if (pointer[2] == '.') // index is not temporary
            {
                pointerVar = $".{pointer[1]}{VariableCounter}";
            }
            else
            {
                pointerVar = pointer;
            }
            if (valueType == Type.VECTOR)
            {
                translation.AddAssembly("s_get_from_v", tempVar, pointer,
                                        (indexExpression as IntLiteralExpression).i.ToString());
            }
            else if (valueType == Type.VECTOR_POINTER)
            {
                translation.AddAssembly("ii_muli", indexVar, index, "16");
                translation.AddAssembly("ii_add", pointerVar, indexVar, pointer);
                translation.AddAssembly("v_load_16byte", tempVar, pointerVar, "0");
            }
            else
            {
                translation.AddAssembly("ii_muli", indexVar, index, "4");
                translation.AddAssembly("ii_add", pointerVar, indexVar, pointer);
                translation.AddAssembly("s_load_4byte", tempVar, pointerVar, "0");
            }
            return(tempVar);
        }