예제 #1
0
        public override void PrintASM(string levelTabulatiion, bool isNewLine = false)
        {
            IdentificatorAST identificatorRight = (IdentificatorAST)SymTable.symTabls.FindNode((id as IdentificatorAST).GetName());
            int startInStack = identificatorRight.GetAddresInStack();

            ASM.WriteASMCode(levelTabulatiion + ASMregisters.GetCrement(crement) + "\t" + ASMregisters.GetNameType(identificatorRight.GetTypeId()) + " [ebp-" + startInStack + "], 1");
        }
예제 #2
0
 public int GetAddresInStack(bool stackRoot = false)
 {
     if (stackRoot)
     {
         IdentificatorAST identificatorFindInTable = (IdentificatorAST)SymTable.symTabls.FindNode(GetName());
         if (identificatorFindInTable != null)
         {
             return(identificatorFindInTable.GetAddresInStack());
         }
     }
     return(startInStack);
 }
예제 #3
0
        private string IdentificatorPrint(string levelTabulatiion, IdentificatorAST sideNodeIdentificatorAST)
        {
            string           reigster          = "";
            IdentificatorAST identificatorSide = (IdentificatorAST)SymTable.symTabls.FindNode(sideNodeIdentificatorAST.GetName());

            if (sideNodeIdentificatorAST.IsArray)
            {
                sideNodeIdentificatorAST.PrintArrayIterationASM(levelTabulatiion, isPushResult: true);
            }
            else
            {
                reigster = ASMregisters.GetFreeRegister(ASMregisters.Register.DATA);
                int offsetInStack = sideNodeIdentificatorAST.GetOffseIfTtArray();
                int startInStack  = identificatorSide.GetAddresInStack() + offsetInStack;
                ASM.WriteASMCode(levelTabulatiion + "mov\t" + reigster + ", " + ASMregisters.GetNameType(identificatorSide.GetTypeId()) + " [ebp-" + startInStack + "]");
            }
            return(reigster);
        }
예제 #4
0
 public override void PrintASM(string levelTabulatiion, bool isNewLine = false)
 {
     if (storage is IdentificatorAST identificatorStorage)
     {
         IdentificatorAST identificatorAST = (IdentificatorAST)SymTable.symTabls.FindNode(identificatorStorage.GetName());
         if (identificatorAST.IsArray)
         {
             identificatorAST.PrintArrayASM(levelTabulatiion);
         }
         else
         {
             identificatorAST.PrintIdentificatorASM(levelTabulatiion);
         }
     }
     else if (storage is StringAST stringAST)
     {
         //Вывод строек не работает
         //stringAST.PrintSringArray(levelTabulatiion, stringAST.GetString(), startInStack);
     }
 }
예제 #5
0
        public override void PrintASM(string levelTabulatiion, bool isNewLine = false)
        {
            if (storage == null && brackets == null)
            {
                return;
            }

            if (startInStack == 0)
            {
                IdentificatorAST identificatorFindInTable = (IdentificatorAST)SymTable.symTabls.FindNode(GetName());
                int offsetInStack = GetOffseIfTtArray();

                if (identificatorFindInTable != null && identificatorFindInTable != this)
                {
                    startInStack = identificatorFindInTable.GetAddresInStack() + offsetInStack;
                }
                else
                {
                    startInStack           = ASMregisters.stepByte;
                    ASMregisters.stepByte += ASMregisters.GetSizeStep(type);
                }
            }

            if (isArray)
            {
                if (storage is NewAST newASTArray)
                {
                    lengthArray = newASTArray.GetSizeArray();

                    int locateStack = startInStack;
                    ASM.WriteASMCode(levelTabulatiion + "mov\t" + ASMregisters.GetNameType(type) + " [ebp-" + locateStack + "], 0");
                    for (int i = 1; i < lengthArray; i++)
                    {
                        locateStack            = startInStack + (ASMregisters.GetSizeStep(type) * i);
                        ASMregisters.stepByte += ASMregisters.GetSizeStep(type);
                        ASM.WriteASMCode(levelTabulatiion + "mov\t" + ASMregisters.GetNameType(type) + " [ebp-" + locateStack + "], 0");
                    }
                }
                else if (storage is BinaryExprAST || storage is ParenthesisExprAST)
                {
                    storage.PrintASM(levelTabulatiion);
                    PrintArrayIterationASM(levelTabulatiion, isPushResult: true);
                }
                else
                {
                    if (isNewLine)
                    {
                        string elementStorage;
                        if (storage is StringAST stringAST)
                        {
                            isArray = true;
                            stringAST.PrintSringArray(levelTabulatiion, startInStack);
                            lengthArray = stringAST.GetString().Length;
                        }
                        else if (storage is IEject ejectedStorage)
                        {
                            elementStorage = ejectedStorage.GetValue();
                            ASM.WriteASMCode(levelTabulatiion + "mov\t" + ASMregisters.GetNameType(type) + " [ebp-" + startInStack + "], " + elementStorage);
                        }
                        else
                        {
                            storage.PrintASM(levelTabulatiion);
                            PrintArrayIterationASM(levelTabulatiion, isPopInArray: true);
                        }
                    }
                    else
                    {
                        PrintArrayIterationASM(levelTabulatiion, isPushResult: true);
                    }
                }
            }
            else
            {
                if (storage is NewAST)
                {
                    ASM.WriteASMCode(levelTabulatiion + "mov\t" + ASMregisters.GetNameType(type) + " [ebp-" + startInStack + "], 0");
                }
                else if (storage is BinaryExprAST || storage is ParenthesisExprAST)
                {
                    storage.PrintASM(levelTabulatiion);
                    string register = ASMregisters.GetFreeRegister(ASMregisters.Register.DATA);
                    ASM.WriteASMCode(levelTabulatiion + "pop\t" + register);
                    ASM.WriteASMCode(levelTabulatiion + "mov\t" + ASMregisters.GetNameType(type) + " [ebp-" + startInStack + "], " + register);
                    ASMregisters.SetStateRegister(ASMregisters.Register.DATA, register, true);
                }
                else
                {
                    if (isNewLine)
                    {
                        string elementStorage;
                        if (storage is StringAST stringAST)
                        {
                            isArray = true;
                            stringAST.PrintSringArray(levelTabulatiion, startInStack);
                            lengthArray = stringAST.GetString().Length;
                        }
                        else if (storage is IEject ejectedStorage)
                        {
                            elementStorage = ejectedStorage.GetValue();
                            ASM.WriteASMCode(levelTabulatiion + "mov\t" + ASMregisters.GetNameType(type) + " [ebp-" + startInStack + "], " + elementStorage);
                        }
                        else
                        {
                            storage.PrintASM(levelTabulatiion);
                            elementStorage = ASMregisters.GetFreeRegister(ASMregisters.Register.DATA);
                            ASM.WriteASMCode(levelTabulatiion + "pop\t" + elementStorage);
                            ASM.WriteASMCode(levelTabulatiion + "mov\t" + ASMregisters.GetNameType(type) + " [ebp-" + startInStack + "], " + elementStorage);
                            ASMregisters.SetStateRegister(ASMregisters.Register.DATA, elementStorage, true);
                        }
                    }
                    else
                    {
                        takeRegister = ASMregisters.GetFreeRegister(ASMregisters.Register.DATA);
                        ASM.WriteASMCode(levelTabulatiion + "mov\t" + takeRegister + ", " + ASMregisters.GetNameType(type) + " [ebp-" + startInStack + "]");
                        ASM.WriteASMCode(levelTabulatiion + "push\t" + takeRegister);
                        ASMregisters.SetStateRegister(ASMregisters.Register.DATA, takeRegister, true);
                    }
                }
            }
        }
예제 #6
0
        private void IdentificatorMainPrint(string levelTabulatiion, ASTNode rightNode, IdentificatorAST leftNodeIdentificator, ref string registerLeft, ref string registerRight)
        {
            registerLeft = IdentificatorPrint(levelTabulatiion, leftNodeIdentificator);

            if (rightNode is BinaryExprAST || rightNode is ParenthesisExprAST || rightNode is BoolAST)
            {
                PrintExprAST(rightNode, levelTabulatiion);
                PrintPop(levelTabulatiion, ref registerLeft);
                PrintPop(levelTabulatiion, ref registerRight);
            }
            else
            {
                registerRight = IdentificatorOrValuePrint(levelTabulatiion, rightNode);
            }
        }