当前位置: 首页>>代码示例>>C#>>正文


C# InstructionBlock类代码示例

本文整理汇总了C#中InstructionBlock的典型用法代码示例。如果您正苦于以下问题:C# InstructionBlock类的具体用法?C# InstructionBlock怎么用?C# InstructionBlock使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


InstructionBlock类属于命名空间,在下文中一共展示了InstructionBlock类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Weave

        /// <summary>
        /// Weaves the specified context.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="block">The block.</param>
        public void Weave(WeavingContext context, InstructionBlock block)
        {
            LocalVariableSymbol parameters = block.DefineLocalVariable(context.Method.Module.FindType(typeof(ParameterDictionary), BindingOptions.Default), NameGenerator.Generate("parameters"));

            InstructionSequence entrySequence = context.Method.MethodBody.CreateInstructionSequence();
            block.AddInstructionSequence(entrySequence, NodePosition.Before, null);

            InstructionWriter writer = context.InstructionWriter;
            writer.AttachInstructionSequence(entrySequence);
            writer.EmitSymbolSequencePoint(SymbolSequencePoint.Hidden);

            writer.EmitInstructionMethod(OpCodeNumber.Call, context.Method.Module.FindMethod(typeof(InternalHelperMethods).GetMethod("CreateParameterCollection"), BindingOptions.Default));

            IMethod add = context.Method.Module.FindMethod(typeof(ParameterDictionary).GetMethod("Add", new[] { typeof(string), typeof(object) }), BindingOptions.Default);

            short parameterIndex = context.Method.IsStatic ? (short)0 : (short)1;
            foreach (var parameter in method.Parameters)
            {
                writer.EmitInstruction(OpCodeNumber.Dup);

                writer.EmitInstructionString(OpCodeNumber.Ldstr, new LiteralString(parameter.Name));
                writer.EmitInstructionInt16(OpCodeNumber.Ldarg, parameterIndex++);

                if (parameter.ParameterType.GetSystemType(null, null).IsValueType)
                {
                    writer.EmitInstructionType(OpCodeNumber.Box, parameter.ParameterType);
                }

                writer.EmitInstructionMethod(OpCodeNumber.Callvirt, add);
            }

            writer.EmitInstructionLocalVariable(OpCodeNumber.Stloc, parameters);

            writer.DetachInstructionSequence();
        }
开发者ID:zevinganez,项目名称:code-o-matic,代码行数:40,代码来源:BuildParameterCollectionAdvice.cs

示例2: LocaVariableSymbolCollectionTreeNode

 public LocaVariableSymbolCollectionTreeNode( InstructionBlock block )
     : base( TreeViewImage.Folder, null )
 {
     this.block = block;
     this.Text = "Symbols";
     this.EnableLatePopulate();
 }
开发者ID:jogibear9988,项目名称:ormbattle,代码行数:7,代码来源:LocalCollectionTreeNode.cs

示例3: Weave

        public void Weave(WeavingContext context, InstructionBlock block)
        {
            InstructionSequence nextSequence = null;
            InstructionSequence sequence = null;

            sequence = context.Method.MethodBody.CreateInstructionSequence();
            block.AddInstructionSequence(sequence, NodePosition.Before, null);
            context.InstructionWriter.AttachInstructionSequence(sequence);

            context.InstructionWriter.EmitInstructionParameter(OpCodeNumber.Ldarg, this.paramDef);
            context.InstructionWriter.EmitInstructionType(OpCodeNumber.Box, this.paramDef.ParameterType);
            context.InstructionWriter.EmitInstruction(OpCodeNumber.Ldnull);
            context.InstructionWriter.EmitInstruction(OpCodeNumber.Ceq);

            nextSequence = context.Method.MethodBody.CreateInstructionSequence();

            context.InstructionWriter.EmitBranchingInstruction(OpCodeNumber.Brfalse_S, nextSequence);
            context.InstructionWriter.EmitInstructionString(OpCodeNumber.Ldstr, this.paramDef.Name);
            context.InstructionWriter.EmitInstructionMethod(OpCodeNumber.Newobj,
                                                            context.Method.Module.FindMethod(
                                                                typeof (ArgumentNullException).GetConstructor(
                                                                    new[] {typeof (string)}),
                                                                BindingOptions.Default));
            context.InstructionWriter.EmitInstruction(OpCodeNumber.Throw);

            context.InstructionWriter.DetachInstructionSequence();
            block.AddInstructionSequence(nextSequence, NodePosition.After, sequence);
            sequence = nextSequence;
            context.InstructionWriter.AttachInstructionSequence(sequence);

            context.InstructionWriter.DetachInstructionSequence();
        }
开发者ID:kamillangowski,项目名称:postsharp-user-plugins,代码行数:32,代码来源:NonNullParameterAdvice.cs

示例4: Weave

        public void Weave(WeavingContext context, InstructionBlock block)
        {
            InstructionSequence sequence = context.Method.MethodBody.CreateInstructionSequence();
            block.AddInstructionSequence(sequence, NodePosition.After, null);
            InstructionWriter writer = context.InstructionWriter;
            writer.AttachInstructionSequence(sequence);

            context.InstructionWriter.EmitInstructionLocalVariable(OpCodeNumber.Ldloc, context.ReturnValueVariable);
            context.InstructionWriter.EmitInstructionType(OpCodeNumber.Box,
                                                          context.ReturnValueVariable.LocalVariable.Type);
            context.InstructionWriter.EmitInstruction(OpCodeNumber.Ldnull);
            context.InstructionWriter.EmitInstruction(OpCodeNumber.Ceq);

            InstructionSequence nextSequence = context.Method.MethodBody.CreateInstructionSequence();

            context.InstructionWriter.EmitBranchingInstruction(OpCodeNumber.Brfalse_S, nextSequence);
            context.InstructionWriter.EmitInstructionString(OpCodeNumber.Ldstr, "return value is null");
            context.InstructionWriter.EmitInstructionMethod(OpCodeNumber.Newobj,
                                                            context.Method.Module.FindMethod(
                                                                typeof (ArgumentNullException).GetConstructor(new[]
                                                                                                                  {
                                                                                                                      typeof
                                                                                                                          (
                                                                                                                          string
                                                                                                                          )
                                                                                                                  }),
                                                                BindingOptions.Default));
            context.InstructionWriter.EmitInstruction(OpCodeNumber.Throw);

            block.AddInstructionSequence(nextSequence, NodePosition.After, sequence);

            writer.DetachInstructionSequence();
        }
开发者ID:kamillangowski,项目名称:postsharp-user-plugins,代码行数:33,代码来源:NonNullReturnAdvice.cs

示例5: AddBlock

 private static InstructionBlock[] AddBlock(InstructionBlock block, InstructionBlock[] blocks)
 {
     InstructionBlock[] destinationArray = new InstructionBlock[blocks.Length + 1];
     Array.Copy(blocks, destinationArray, blocks.Length);
     destinationArray[destinationArray.Length - 1] = block;
     return destinationArray;
 }
开发者ID:CarlosHBC,项目名称:UnityDecompiled,代码行数:7,代码来源:ControlFlowGraphBuilder.cs

示例6: IsFinallyCheckBlock

        /// <summary>
        /// Checks whether <paramref name="theBlock"/> is a do-finally-check block.
        /// </summary>
        /// <remarks>
        /// Pattern:
        /// (nop) - sequence of nop blocks
        /// ldloc* doFinallyVariable
        /// brfalse* - branch to endfinally - this check varies between compilers
        /// original handler:
        /// ...............
        /// </remarks>
        /// <param name="theBlock"></param>
        /// <returns></returns>
        protected override bool IsFinallyCheckBlock(InstructionBlock theBlock)
        {
            Instruction currentInstruction = theBlock.First;
            while (currentInstruction.OpCode.Code == Code.Nop)
            {
                if (currentInstruction == theBlock.Last)
                {
                    return false;
                }
                currentInstruction = currentInstruction.Next;
            }

            VariableReference loadedVariable;
            if (currentInstruction == theBlock.Last ||
                !StateMachineUtilities.TryGetVariableFromInstruction(currentInstruction, methodVariables, out loadedVariable) ||
                loadedVariable != doFinallyVariable)
            {
                return false;
            }
            currentInstruction = currentInstruction.Next;

            if (currentInstruction.OpCode.Code == Code.Brfalse || currentInstruction.OpCode.Code == Code.Brfalse_S)
            {
                return true;
            }

            return IsCSharpDebugCheck(theBlock, currentInstruction) || IsVisualBasicDebugCheck(theBlock, currentInstruction);
        }
开发者ID:Feng2012,项目名称:JustDecompileEngine,代码行数:41,代码来源:StateMachineDoFinallyCheckRemover.cs

示例7: ControlFlowGraph

 public ControlFlowGraph(Mono.Cecil.Cil.MethodBody body, InstructionBlock[] blocks, Dictionary<int, InstructionData> instructionData, List<ExceptionHandlerData> exception_data, HashSet<int> exception_objects_offsets)
 {
     this.body = body;
     this.blocks = blocks;
     this.data = instructionData;
     this.exception_data = exception_data;
     this.exception_objects_offsets = exception_objects_offsets;
 }
开发者ID:CarlosHBC,项目名称:UnityDecompiled,代码行数:8,代码来源:ControlFlowGraph.cs

示例8: ImplementOnEntry

 protected override void ImplementOnEntry(InstructionBlock block, InstructionWriter writer)
 {
     foreach (var implementation in GetOnEntryImplementations()) {
         using (var factory = implementation.CreateExport()) {
             var instance = factory.Value;
             instance.Initialize(Context);
             instance.ImplementOnEntry(block, writer);
         }
     }
 }
开发者ID:DamianReeves,项目名称:PostEdge,代码行数:10,代码来源:ComposedMethodBodyWrappingImplementation.cs

示例9: SwitchData

 public SwitchData(InstructionBlock switchBlock, InstructionBlock defaultCase, IList<InstructionBlock> orderedCases)
 {
     SwitchBlock = switchBlock;
     DefaultCase = defaultCase;
     OrderedCasesArray = new InstructionBlock[orderedCases.Count];
     for (int i = 0; i < orderedCases.Count; i++)
     {
         OrderedCasesArray[i] = orderedCases[i];
     }
 }
开发者ID:juancarlosbaezpozos,项目名称:JustDecompileEngine,代码行数:10,代码来源:SwitchData.cs

示例10: Weave

        public void Weave(WeavingContext context, InstructionBlock block)
        {
            InstructionSequence sequence = null;

            sequence = context.Method.MethodBody.CreateInstructionSequence();
            block.AddInstructionSequence(sequence, NodePosition.After, null);
            context.InstructionWriter.AttachInstructionSequence(sequence);

            context.InstructionWriter.EmitInstructionMethod(OpCodeNumber.Call, context.Method.Module.FindMethod(m_type.Methods.GetOneByName("get_Instance").GetReflectionWrapper(new Type[]{},new Type[]{}),BindingOptions.Default));
            context.InstructionWriter.DetachInstructionSequence();
        }
开发者ID:kamillangowski,项目名称:postsharp-user-plugins,代码行数:11,代码来源:SingletonAdvice.cs

示例11: MarkBlocksDeadIfNeeded

 public static void MarkBlocksDeadIfNeeded(InstructionBlock[] instructionBlocks)
 {
     if (Enumerable.Count<InstructionBlock>(instructionBlocks) != 1)
     {
         foreach (InstructionBlock block in instructionBlocks)
         {
             block.MarkIsDead();
         }
         instructionBlocks[0].MarkIsAliveRecursive();
     }
 }
开发者ID:CarlosHBC,项目名称:UnityDecompiled,代码行数:11,代码来源:DeadBlockAnalysis.cs

示例12: InstructionBlockTreeNode

        public InstructionBlockTreeNode( InstructionBlock block, string name )
            : base( TreeViewImage.Namespace, block )
        {
            this.Text = name + " " + block.ToString();
            this.block = block;

            if ( this.block.HasChildrenBlocks || this.block.HasExceptionHandlers || this.block.HasLocalVariableSymbols )
            {
                this.EnableLatePopulate();
            }
        }
开发者ID:jogibear9988,项目名称:ormbattle,代码行数:11,代码来源:InstructionBlockTreeNode.cs

示例13: ControlFlowGraph

 public ControlFlowGraph(
     MethodBody body, 
     InstructionBlock[] blocks, 
     Dictionary<int, InstructionBlock> instructiontoBlockMapping,
     Dictionary<InstructionBlock, SwitchData> switchBlocksInformation, 
     Dictionary<int, Instruction> offsetToInstruction)
 {
     this.MethodBody = body;
     this.Blocks = blocks;
     this.InstructionToBlockMapping = instructiontoBlockMapping;
     this.SwitchBlocksInformation = switchBlocksInformation;
     this.OffsetToInstruction = offsetToInstruction;
 }
开发者ID:Feng2012,项目名称:JustDecompileEngine,代码行数:13,代码来源:ControlFlowGraph.cs

示例14: AddPropertyGuard

        public static void AddPropertyGuard(PropertyDeclaration property, MethodBodyTransformationContext context, InstructionBlock block, InstructionWriter writer)
        {
            var propertyType = property.PropertyType;
            var methodBody = block.MethodBody;

            var sequence = block.AddInstructionSequence(null, NodePosition.After, null);
            if (sequence == null) return;

            var oldValueVariable =
                block.DefineLocalVariable(propertyType, string.Format("old{0}Value", property.Name));
            var assets = GetTransformationAssets(property.Module);

            writer.AttachInstructionSequence(sequence);
            var isLocationBinding = CheckIfIsLocationBinding(methodBody,assets);
            if (isLocationBinding) {
                writer.AssignValue_LocalVariable(oldValueVariable
                    , () => writer.Call_MethodOnTarget(property.GetGetter()
                        ,
                        () => {
                            //Load the instance parameter of the SetValue method
                            //and convert it to the type
                            writer.EmitInstruction(OpCodeNumber.Ldarg_1);
                            //writer.EmitInstructionLoadIndirect(Assets.ObjectTypeSignature);
                            writer.EmitInstructionType(OpCodeNumber.Ldobj, assets.ObjectTypeSignature);
                            writer.EmitConvertFromObject(property.Parent);
                        }
                    )
                );
                //On the location binding the value parameter is at psotion 3
                writer.EmitInstruction(OpCodeNumber.Ldarg_3);
            } else {
                writer.AssignValue_LocalVariable(oldValueVariable,
                                                    () => writer.Get_PropertyValue(property));
                //For a normal property the value parameter is at position 1
                writer.EmitInstruction(OpCodeNumber.Ldarg_1);
            }
            if (propertyType.IsStruct()) {
                writer.EmitInstructionType(OpCodeNumber.Box, propertyType);
            }
            writer.Box_LocalVariableIfNeeded(oldValueVariable);
            var isPrimitive = propertyType.IsPrimitive();
            if (isPrimitive) {
                writer.Compare_Primitives();
            } else {
                //TODO: Try and use the equality operator when present
                writer.Compare_Objects(assets.ObjectEqualsMethod);
            }
            //writer.Leave_IfTrue(_context.LeaveBranchTarget);
            writer.Leave_IfTrue(context.LeaveBranchTarget);
            writer.DetachInstructionSequence();
        }
开发者ID:DamianReeves,项目名称:PostEdge,代码行数:51,代码来源:EnhancePropertySetterMethodBodyWrappingImplementation.cs

示例15: Weave

        public void Weave(WeavingContext context, InstructionBlock block)
        {
            InstructionSequence entrySequence = context.Method.MethodBody.CreateInstructionSequence();
            block.AddInstructionSequence(entrySequence, NodePosition.Before, null);

            InstructionWriter writer = context.InstructionWriter;

            writer.AttachInstructionSequence(entrySequence);
            writer.EmitSymbolSequencePoint(SymbolSequencePoint.Hidden);

            Weave(context, writer);

            writer.DetachInstructionSequence();
        }
开发者ID:zevinganez,项目名称:code-o-matic,代码行数:14,代码来源:BaseLogAdvice.cs


注:本文中的InstructionBlock类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。