コード例 #1
0
        private bool HandleExtraInstructions(Instruction instruction,
                                             MetaMidRepresentationOperationFactory operationFactory, string opcodeStr)
        {
            if (opcodeStr == "ret")
            {
                var isVoid = Method.GetReturnType().IsVoid();

                operationFactory.Return(isVoid);
                return(true);
            }
            if (opcodeStr.StartsWith("conv."))
            {
                if (ConversionOperations(opcodeStr, operationFactory))
                {
                    return(true);
                }
                return(true);
            }
            if (opcodeStr == "dup")
            {
                operationFactory.Dup();
                return(true);
            }
            if (opcodeStr == "pop")
            {
                operationFactory.Pop();
                return(true);
            }
            if (HandleArrayOperations(instruction, operationFactory, opcodeStr))
            {
                return(true);
            }
            if (opcodeStr == "ldtoken")
            {
                operationFactory.SetToken((FieldInfo)instruction.Operand);
                return(true);
            }
            if (opcodeStr == "ldftn")
            {
                operationFactory.LoadFunction((MethodInfo)instruction.Operand);
                return(true);
            }
            if (opcodeStr == "switch")
            {
                operationFactory.Switch((Instruction[])instruction.Operand);
                return(true);
            }
            if (opcodeStr == "sizeof")
            {
                operationFactory.SizeOf((Type)instruction.Operand);
                return(true);
            }
            if (opcodeStr == "ldsfld")
            {
                operationFactory.LoadStaticField((FieldInfo)instruction.Operand);
                return(true);
            }
            if (opcodeStr == "stsfld")
            {
                operationFactory.StoreStaticField((FieldInfo)instruction.Operand);
                return(true);
            }
            if (opcodeStr == "ldloca.s" || opcodeStr == "ldloca")
            {
                //TODO: load the address into evaluation stack
                var index = (LocalVariableInfo)instruction.Operand;

                operationFactory.LoadAddressIntoEvaluationStack(index);
                return(true);
            }
            if (opcodeStr == "ldflda.s" || opcodeStr == "ldflda")
            {
                var fieldInfo = (FieldInfo)instruction.Operand;

                operationFactory.LoadFieldAddressIntoEvaluationStack(fieldInfo);
                return(true);
            }

            if (opcodeStr == "ldelema")
            {
                operationFactory.LoadAddressOfArrayItemIntoStack((Type)instruction.Operand);
                return(true);
            }

            if (opcodeStr.StartsWith("stind."))
            {
                //TODO: load the address into evaluation stack
                operationFactory.StoresValueFromAddress();
                return(true);
            }

            if (opcodeStr.StartsWith("ldind."))
            {
                //TODO: load the address into evaluation stack
                operationFactory.LoadValueFromAddress();
                return(true);
            }

            if (opcodeStr.StartsWith("initobj"))
            {
                //TODO: load the address into evaluation stack
                operationFactory.InitObject();
                return(true);
            }
            return(false);
        }