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


C# Compiler.IsRuntimeMethod方法代码示例

本文整理汇总了C#中Compiler.IsRuntimeMethod方法的典型用法代码示例。如果您正苦于以下问题:C# Compiler.IsRuntimeMethod方法的具体用法?C# Compiler.IsRuntimeMethod怎么用?C# Compiler.IsRuntimeMethod使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Compiler的用法示例。


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

示例1: GetSize

        public override int GetSize(Compiler compiler, Instruction instruction)
        {
            // Get destination
            MethodReference destinationRef = instruction.Operand as MethodReference;
            string methodName = Util.GetFriendlyMethodName(destinationRef);

            // See below
            if (compiler.IsRuntimeMethod(methodName))
                return 2;

            return 3;
        }
开发者ID:NielsDev,项目名称:IL2VM,代码行数:12,代码来源:Call.cs

示例2: GetSize

        public override int GetSize(Compiler compiler, Instruction instruction)
        {
            // Get .ctor method from operand and get the class associated with it
            MethodReference ctor = instruction.Operand as MethodReference;
            TypeReference type = ctor.DeclaringType;

            // See below, if native type, this is just a CALL (3 or 2)
            // Else, this is a NEWOBJ (4)
            if (Util.IsNativeType(type))
            {
                string methodName = Util.GetFriendlyMethodName(ctor);
                if (compiler.IsRuntimeMethod(methodName))
                    return 2;

                return 3;
            }
            else
            {
                return 4;
            }
        }
开发者ID:NielsDev,项目名称:IL2VM,代码行数:21,代码来源:NEWOBJ.cs

示例3: Process

        public override void Process(Compiler compiler, MethodData methodData, Instruction instruction)
        {
            // Get destination
            MethodReference destinationRef = instruction.Operand as MethodReference;
            string methodName = Util.GetFriendlyMethodName(destinationRef);

            // Check if it's a special method that should be caught here
            if (methodName == "ILVM_Asm_Execute2")
            {
                // IL code at this point will look like this
                // LOAD STRING "<assembly code>"
                // LOAD REGS
                // CALL ASM.EXECUTE

                // So we must check if two instructions before this the assembly code is loaded
                // else we need to throw an error
                Instruction ldstr = instruction.Previous.Previous;
                if (ldstr.OpCode != OpCodes.Ldstr)
                {
                    throw new Exception("Assembly code needs to be directly in the call");
                }
                else
                {
                    // Prepare assembler
                    string code = ldstr.Operand as string;
                    Assembler asm = compiler.Assembler;
                    int offset = asm.GetOffset();

                    // Since this is used as a "method" we need to place a return at the end
                    asm.HandleCode(code);
                    asm.HandleInstruction("ret");
                    int codeSize = asm.GetOffset() - offset;

                    // Write instruction followed by asm offset and asm size
                    methodData.AddInstruction(Ops.OP_RUNTIME_ASM);
                    methodData.AddInstruction(offset);
                    methodData.AddInstruction(codeSize);
                }
                return;
            }

            // If it's implemented in runtime, emit a special seperate instruction for this
            if (compiler.IsRuntimeMethod(methodName))
            {
                // Write instruction followed by the runtime method ID
                methodData.AddInstruction(Ops.OP_RUNTIME_CALL);
                methodData.AddInstruction(compiler.GetRuntimeMethodID(methodName));
            }
            else
            {
                // Get definition from reference
                MethodDefinition destination = destinationRef.Resolve();

                // Lookup the method, if it isn't processed yet, process it
                int methodId = compiler.GetMethodID(destination);
                if (methodId == -1)
                    methodId = compiler.ProcessMethod(destination);

                // If the method is not static, we pass "this" as argument, so we count 1 parameter extra
                int paramCount = destinationRef.Parameters.Count;
                if (!destination.IsStatic)
                    paramCount++;

                // Write instruction followed by the method ID
                methodData.AddInstruction(instruction.OpCode.Value);
                methodData.AddInstruction(methodId);
                methodData.AddInstruction(paramCount);
            }
        }
开发者ID:NielsDev,项目名称:IL2VM,代码行数:69,代码来源:Call.cs


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