Ejemplo n.º 1
0
        private List <DatToken> GetTokens(BaseExecBlockContext execBlock)
        {
            List <DatToken>          tokens         = new List <DatToken>();
            Dictionary <string, int> labelToAddress = GetLabelToAddressDict(execBlock);

            foreach (var instruction in execBlock.Body)
            {
                if (instruction is AssemblyLabel)
                {
                    continue;
                }


                int? intParam  = null;
                byte?byteParam = null;
                switch (instruction)
                {
                case Call call:
                {
                    intParam = call.Symbol.FirstTokenAddress;
                    break;
                }

                case PushArrayVar pushArrVar:
                {
                    intParam  = pushArrVar.Symbol.Index;
                    byteParam = (byte)pushArrVar.Index;
                    break;
                }

                case JumpToLabel jumpToLabel:
                {
                    intParam = labelToAddress[jumpToLabel.Label];
                    break;
                }

                case SymbolInstruction symbolInstruction:
                {
                    intParam = symbolInstruction.Symbol.Index;
                    break;
                }

                case ValueInstruction valueInstruction:
                {
                    intParam = (int)valueInstruction.Value;
                    break;
                }

                case AddressInstruction addressInstruction:     // TODO check if there is any possibility for this
                {
                    intParam = addressInstruction.Address;
                    break;
                }
                }


                string tokenName = instruction.GetType().Name;
                if (instruction is JumpToLabel)
                {
                    tokenName = tokenName.Substring(0, tokenName.Length - "ToLabel".Length);
                }

                DatTokenType datTokenType = Enum.Parse <DatTokenType>(tokenName);
                tokens.Add(new DatToken {
                    TokenType = datTokenType, IntParam = intParam, ByteParam = byteParam
                });
            }

            return(tokens);
        }
Ejemplo n.º 2
0
        private List <DatToken> GetTokens(BlockSymbol blockSymbol)
        {
            List <DatToken> tokens = new List <DatToken>();

            foreach (AssemblyElement it in blockSymbol.Instructions)
            {
                AssemblyElement instruction = it;

                if (instruction is AssemblyLabel)
                {
                    continue;
                }

                int? intParam  = null;
                byte?byteParam = null;
                switch (instruction)
                {
                case Call call:
                {
                    intParam = ((BlockSymbol)call.Symbol).FirstTokenAddress;
                    break;
                }

                case PushArrayVar pushArrVar:
                {
                    intParam  = pushArrVar.Symbol.Index;
                    byteParam = (byte)pushArrVar.Index;
                    break;
                }

                case JumpToLabel jumpToLabel:
                {
                    intParam = blockSymbol.Label2Address[jumpToLabel.Label];
                    break;
                }

                case SymbolInstruction symbolInstruction:
                {
                    intParam = symbolInstruction.Symbol.Index;
                    break;
                }

                case ValueInstruction valueInstruction:
                {
                    intParam = (int)valueInstruction.Value;
                    break;
                }

                case AddressInstruction addressInstruction:
                {
                    intParam = addressInstruction.Address;
                    break;
                }

                case PushNullInstance _:
                    intParam = 0;
                    break;
                }

                string tokenName = instruction.GetType().Name;
                if (instruction is JumpToLabel)
                {
                    tokenName = tokenName.Substring(0, tokenName.Length - "ToLabel".Length);
                }

                DatTokenType datTokenType = Enum.Parse <DatTokenType>(tokenName);
                tokens.Add(new DatToken {
                    TokenType = datTokenType, IntParam = intParam, ByteParam = byteParam
                });
            }

            return(tokens);
        }