当前位置: 首页>>代码示例>>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;未经允许,请勿转载。