Ejemplo n.º 1
0
        private static bool HandleLoads(string opcodeStr, Instruction instruction,
                                        MetaMidRepresentationOperationFactory operationFactory)
        {
            if (opcodeStr == "ldelem.ref")
            {
                operationFactory.LoadReferenceInArray();
                return(true);
            }
            if (opcodeStr == "ldelem.i" ||
                opcodeStr == "ldelem.i1" ||
                opcodeStr == "ldelem.i2" ||
                opcodeStr == "ldelem.i4" ||
                opcodeStr == "ldelem.i8" ||
                opcodeStr == "ldelem.i1" ||
                opcodeStr == "ldelem.r4" ||
                opcodeStr == "ldelem.r8" ||
                opcodeStr == "ldelem.u1" ||
                opcodeStr == "ldelem.u2" ||
                opcodeStr == "ldelem.u2" ||
                opcodeStr == "ldelem.u4" ||
                opcodeStr == "ldelem.u8"
                )
            {
                operationFactory.LoadReferenceInArray();

                return(true);
            }

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

            if (opcodeStr == "ldc.i4.s" || opcodeStr == "ldc.i4")
            {
                operationFactory.PushInt4(instruction.GetIntOperand());
                return(true);
            }
            if (opcodeStr == "ldc.i8.s" || opcodeStr == "ldc.i8")
            {
                operationFactory.PushInt8(instruction.GetLongOperand());
                return(true);
            }
            if (opcodeStr.StartsWith("ldc.i4."))
            {
                var pushedIntValue = opcodeStr.Remove(0, "ldc.i4.".Length).ToInt();
                operationFactory.PushInt4(pushedIntValue);
                return(true);
            }
            if (opcodeStr == "ldloc" || opcodeStr == "ldloc.s")
            {
                operationFactory.CopyLocalVariableIntoStack(instruction.GetIntOperand());
                return(true);
            }

            if (opcodeStr.StartsWith("ldloc."))
            {
                var pushedIntValue = opcodeStr.Remove(0, "ldloc.".Length).ToInt();

                operationFactory.CopyLocalVariableIntoStack(pushedIntValue);
                return(true);
            }

            if (opcodeStr == "ldstr")
            {
                operationFactory.PushString((string)instruction.Operand);
                return(true);
            }
            if (opcodeStr == "ldc.r8")
            {
                operationFactory.PushDouble((double)instruction.Operand);
                return(true);
            }
            if (opcodeStr == "ldc.r4")
            {
                operationFactory.PushDouble((float)instruction.Operand);
                return(true);
            }
            if (opcodeStr.StartsWith("ldarg."))
            {
                var pushedIntValue = opcodeStr.Remove(0, "ldarg.".Length).ToInt();
                operationFactory.LoadArgument(pushedIntValue);
                return(true);
            }
            if (opcodeStr == "ldfld")
            {
                var operand = (FieldInfo)instruction.Operand;

                operationFactory.LoadField(operand.Name);
                return(true);
            }
            if (opcodeStr == "ldlen")
            {
                operationFactory.LoadLength();
                return(true);
            }

            if (opcodeStr == "ldnull")
            {
                operationFactory.LoadNull();
                return(true);
            }
            return(false);
        }