當前位置: 首頁>>代碼示例>>C#>>正文


C# Instruction.ResolveOperand方法代碼示例

本文整理匯總了C#中Mono.Cecil.Cil.Instruction.ResolveOperand方法的典型用法代碼示例。如果您正苦於以下問題:C# Instruction.ResolveOperand方法的具體用法?C# Instruction.ResolveOperand怎麽用?C# Instruction.ResolveOperand使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Mono.Cecil.Cil.Instruction的用法示例。


在下文中一共展示了Instruction.ResolveOperand方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: CopyBranchStackSize

        static void CopyBranchStackSize(Instruction instruction, ref Dictionary<Instruction, int> stack_sizes, int stack_size)
        {
            if (stack_size == 0)
                return;

            switch (instruction.opcode.OperandType) {
                case OperandType.ShortInlineBrTarget:
                case OperandType.InlineBrTarget:
                    {
                        if (instruction.ResolveOperand != null)
                        {
                            instruction.Operand = instruction.ResolveOperand(instruction);
                        }

                        CopyBranchStackSize(ref stack_sizes, (Instruction) instruction.operand, stack_size);
                        break;
                    }
                case OperandType.InlineSwitch:
                var targets = (Instruction[]) instruction.operand;
                for (int i = 0; i < targets.Length; i++)
                    CopyBranchStackSize (ref stack_sizes, targets [i], stack_size);
                break;
            }
        }
開發者ID:nugarin,項目名稱:cecil,代碼行數:24,代碼來源:CodeWriter.cs

示例2: WriteOperand

        void WriteOperand(Instruction instruction)
        {
            var opcode = instruction.opcode;
            var operand_type = opcode.OperandType;
            if (operand_type == OperandType.InlineNone)
                return;

            var operand = instruction.operand;
            if (instruction.ResolveOperand != null)
            {
                operand = instruction.ResolveOperand(instruction);
            }
            if (operand == null)
            {
                throw new ArgumentException();
            }

            switch (operand_type) {
            case OperandType.InlineSwitch: {
                var targets = (Instruction []) operand;
                WriteInt32 (targets.Length);
                var diff = instruction.Offset + opcode.Size + (4 * (targets.Length + 1));
                for (int i = 0; i < targets.Length; i++)
                    WriteInt32 (GetTargetOffset (targets [i]) - diff);
                break;
            }
            case OperandType.ShortInlineBrTarget: {
                var target = (Instruction) operand;
                WriteSByte ((sbyte) (GetTargetOffset (target) - (instruction.Offset + opcode.Size + 1)));
                break;
            }
            case OperandType.InlineBrTarget: {
                var target = (Instruction) operand;
                WriteInt32 (GetTargetOffset (target) - (instruction.Offset + opcode.Size + 4));
                break;
            }
            case OperandType.ShortInlineVar:
                WriteByte ((byte) GetVariableIndex ((VariableDefinition) operand));
                break;
            case OperandType.ShortInlineArg:
                WriteByte ((byte) GetParameterIndex ((ParameterDefinition) operand));
                break;
            case OperandType.InlineVar:
                WriteInt16 ((short) GetVariableIndex ((VariableDefinition) operand));
                break;
            case OperandType.InlineArg:
                WriteInt16 ((short) GetParameterIndex ((ParameterDefinition) operand));
                break;
            case OperandType.InlineSig:
                WriteMetadataToken (GetStandAloneSignature ((CallSite) operand));
                break;
            case OperandType.ShortInlineI:
                if (opcode == OpCodes.Ldc_I4_S)
                    WriteSByte ((sbyte) operand);
                else
                    WriteByte ((byte) operand);
                break;
            case OperandType.InlineI:
                WriteInt32 ((int) operand);
                break;
            case OperandType.InlineI8:
                WriteInt64 ((long) operand);
                break;
            case OperandType.ShortInlineR:
                WriteSingle ((float) operand);
                break;
            case OperandType.InlineR:
                WriteDouble ((double) operand);
                break;
            case OperandType.InlineString:
                WriteMetadataToken (
                    new MetadataToken (
                        TokenType.String,
                        GetUserStringIndex ((string) operand)));
                break;
            case OperandType.InlineType:
            case OperandType.InlineField:
            case OperandType.InlineMethod:
            case OperandType.InlineTok:
                WriteMetadataToken (metadata.LookupToken ((IMetadataTokenProvider) operand));
                break;
            default:
                throw new ArgumentException ();
            }
        }
開發者ID:nugarin,項目名稱:cecil,代碼行數:85,代碼來源:CodeWriter.cs

示例3: ComputeStackDelta

        static void ComputeStackDelta(Instruction instruction, ref int stack_size)
        {
            if (instruction.ResolveOperand != null)
            {
                instruction.Operand = instruction.ResolveOperand(instruction);

                if (instruction.Operand == null)
                {
                    throw new ApplicationException("Couldn't resolve instruction operand.");
                }
            }
            switch (instruction.opcode.FlowControl) {
            case FlowControl.Call: {
                var method = (IMethodSignature) instruction.operand;
                // pop 'this' argument
                if (method.HasImplicitThis() && instruction.opcode.Code != Code.Newobj)
                    stack_size--;
                // pop normal arguments
                if (method.HasParameters)
                    stack_size -= method.Parameters.Count;
                // pop function pointer
                if (instruction.opcode.Code == Code.Calli)
                    stack_size--;
                // push return value
                if (method.ReturnType.etype != ElementType.Void || instruction.opcode.Code == Code.Newobj)
                    stack_size++;
                break;
            }
            default:
                ComputePopDelta (instruction.opcode.StackBehaviourPop, ref stack_size);
                ComputePushDelta (instruction.opcode.StackBehaviourPush, ref stack_size);
                break;
            }
        }
開發者ID:nugarin,項目名稱:cecil,代碼行數:34,代碼來源:CodeWriter.cs


注:本文中的Mono.Cecil.Cil.Instruction.ResolveOperand方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。