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


C# ILGenerator.Emit方法代码示例

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


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

示例1: EmitIL

 public void EmitIL(ILGenerator body, FieldInfo tape, FieldInfo ptr)
 {
     body.Emit(OpCodes.Ldsfld, ptr);
     body.Emit(OpCodes.Ldc_I4_1);
     body.Emit(OpCodes.Sub);
     body.Emit(OpCodes.Stsfld, ptr);
 }
开发者ID:paf31,项目名称:BF,代码行数:7,代码来源:DecrPtr.cs

示例2: Emit

        public void Emit(ILGenerator il)
        {
            for (var i = 0; i < _arguments.Length; i++)
            {
                _arguments[i].Emit(il);
            }

            if (_method.IsStatic)
            {
                il.Emit(OpCodes.Call, _method);
            }
            else if (_method.IsVirtual)
            {
                il.Emit(OpCodes.Callvirt, _method);
            }
            else
            {
                il.Emit(OpCodes.Call, _method);
            }

            if (_method.ReturnType.IsValueType)
            {
                il.Emit(OpCodes.Unbox_Any, _method.ReturnType);
            }
            else if (_method.ReturnType != typeof(object))
            {
                il.Emit(OpCodes.Castclass, _method.ReturnType);
            }
        }
开发者ID:bradleyjford,项目名称:inception,代码行数:29,代码来源:CallMethodExpression.cs

示例3: Generate

        public override void Generate(ILGenerator generator, Symbols symbols)
        {
            //Save the previous variables
            var currentVariables = new List<string>();
            foreach (var item in symbols.Variables)
            {
                currentVariables.Add(item.Key);
                generator.Emit(OpCodes.Ldsfld, symbols.Variables[item.Key]);
            }

            DeclarationBlock.Generate(generator, symbols);
            InstructionsBlock.Generate(generator, symbols);

            LocalBuilder returnValue = null;
            if (InstructionsBlock.ExpressionType.Type != TypesEnumeration.Void)
            {
                returnValue = generator.DeclareLocal(symbols.GetRealType(InstructionsBlock.ExpressionType.ILName));
                generator.Emit(OpCodes.Stloc, returnValue);
            }

            currentVariables.Reverse();
            //load in the variables it's previous values
            currentVariables.ForEach(x => generator.Emit(OpCodes.Stsfld, symbols.Variables[x]));
            if (InstructionsBlock.ExpressionType.Type != TypesEnumeration.Void)
                generator.Emit(OpCodes.Ldloc, returnValue);
        }
开发者ID:hansel0691,项目名称:Tiger,代码行数:26,代码来源:LetInEndNode.cs

示例4: BuildArguments

        public override LocalBuilder BuildArguments(ILGenerator ilGenerator)
        {
            LocalBuilder propertyLocalBuilder = null;
            FieldBuilder contractFieldBuilder = null;
            LocalBuilder aspectArgLocalBuilder = null;
            ConstructorInfo ctorInterceptionArgs = null;
            AbstractAspectPropertyArgsWeaver methodWeaver = null;

            propertyLocalBuilder = LocalBuilderRepository.Declare(() => {
                return ilGenerator.DeclareLocal(typeof(PropertyInfo));
            });

            ctorInterceptionArgs = ArgumentType.GetConstructors()[0];
            aspectArgLocalBuilder = ilGenerator.DeclareLocal(ArgumentType);
            contractFieldBuilder = WeavingSettings.TypeDefinition.GetFieldBuilder(WeavingSettings.ContractType);
            methodWeaver = new AspectArgsGetPropertyWeaver(Member, propertyLocalBuilder, aspectWeavingSettings);
            methodWeaver.Weave(ilGenerator);
            ilGenerator.EmitLoadArg(0);
            ilGenerator.Emit(OpCodes.Ldfld, contractFieldBuilder);
            ilGenerator.EmitLoadLocal(propertyLocalBuilder);
            ilGenerator.Emit(OpCodes.Ldsfld, BindingsDependency);
            ilGenerator.Emit(OpCodes.Newobj, ctorInterceptionArgs);
            ilGenerator.EmitStoreLocal(aspectArgLocalBuilder);

            return aspectArgLocalBuilder;
        }
开发者ID:sagifogel,项目名称:NCop,代码行数:26,代码来源:TopGetPropertyInterceptionArgumentsWeaver.cs

示例5: Emit

        public override void Emit(ILGenerator gen, bool labelSetAlready)
        {
            if (!labelSetAlready) MarkLabel(gen);
            MarkSequencePoint(gen);
            numericExpression.Emit(gen);
            gen.Emit(OpCodes.Call, typeof(BuiltIns).GetMethod("Round"));

            // We need to subtract one from the expression. OnGoto starts
            // counting at 1 and switch starts counting at 0.
            gen.Emit(OpCodes.Ldc_I4_1);
            gen.Emit(OpCodes.Sub);

            List<Label> destinations = new List<Label>();
            foreach (string target in targets)
            {
               destinations.Add(labels[target]);
            }
            gen.Emit(OpCodes.Switch, destinations.ToArray());

            // if the integer was larger than number of labels, then
            // switch falls thru to next statement. An On-Goto should
            // output BAD VALUE IN xx  error.
            gen.Emit(OpCodes.Ldstr, line.Label);
            BuiltInsMethodCall.BadValueError().Emit(gen);
        }
开发者ID:michaelgwelch,项目名称:mbasic99,代码行数:25,代码来源:OnGoto.cs

示例6: Generator

        public Generator(Statement stmt, string moduleName)
        {
            var path = Path.GetFileNameWithoutExtension(moduleName);
            var assemblyName = new AssemblyName(path);
            var assemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Save);
            var moduleBuilder = assemblyBuilder.DefineDynamicModule(moduleName);
            var typeBuilder = moduleBuilder.DefineType(moduleName);

            var methodBuilder = typeBuilder.DefineMethod("Main", MethodAttributes.Static, typeof(void), Type.EmptyTypes);

            // CodeGenerator
            ilgenerator = methodBuilder.GetILGenerator();
            symbolsTable = new Dictionary<string, LocalBuilder>();

            // Go Compile!
            GenerateStatements(stmt);

            ilgenerator.Emit(OpCodes.Call, typeof(Console).GetMethod("ReadKey", BindingFlags.Public | BindingFlags.Static, null, new Type[] { }, null));
            ilgenerator.Emit(OpCodes.Ret);
            typeBuilder.CreateType();
            moduleBuilder.CreateGlobalFunctions();
            assemblyBuilder.SetEntryPoint(methodBuilder);
            assemblyBuilder.Save(moduleName);

            symbolsTable = null;
            ilgenerator = null;
        }
开发者ID:DVitinnik,项目名称:UniversityApps,代码行数:27,代码来源:CodeGenerator.cs

示例7: TranslateToILCall

 internal override void TranslateToILCall(ILGenerator il, Type rtype, ASTList argList, bool construct, bool brackets){
   if (this.defaultMember != null && construct && brackets){
     base.TranslateToILCall(il, rtype, argList, construct, brackets);
     return;
   }
   JSGlobalField gf = this.member as JSGlobalField;
   if (gf != null && gf.IsLiteral && argList.count == 1){
     Type t = Convert.ToType((IReflect)gf.value);
     argList[0].TranslateToIL(il, t);
     Convert.Emit(this, il, t, rtype);
     return;
   }
   this.TranslateToILWithDupOfThisOb(il);
   argList.TranslateToIL(il, typeof(Object[]));
   if (construct)
     il.Emit(OpCodes.Ldc_I4_1);
   else
     il.Emit(OpCodes.Ldc_I4_0);
   if (brackets)
     il.Emit(OpCodes.Ldc_I4_1);
   else
     il.Emit(OpCodes.Ldc_I4_0);
   this.EmitILToLoadEngine(il);
   il.Emit(OpCodes.Call, CompilerGlobals.callValueMethod);
   Convert.Emit(this, il, Typeob.Object, rtype);
 }
开发者ID:ArildF,项目名称:masters,代码行数:26,代码来源:callableexpression.cs

示例8: AppendRead

 public override void AppendRead(ILGenerator il, MessageField field)
 {
     il.Emit(OpCodes.Ldloc_0);
     il.Emit(OpCodes.Ldarg_1);
     field.AppendReadField(il);
     il.Emit(OpCodes.Call, property.GetSetMethod());
 }
开发者ID:drunkcod,项目名称:ProtoSharp,代码行数:7,代码来源:FieldIO.cs

示例9: EmitNullableCast

 protected override void EmitNullableCast(ILGenerator ilGenerator, Type nullableType)
 {
     ilGenerator.DeclareLocal(outputType);
     ilGenerator.Emit(OpCodes.Stloc_0);
     ilGenerator.Emit(OpCodes.Ldloca_S, 0);
     ilGenerator.Emit(OpCodes.Call, nullableType.GetProperty("Value").GetGetMethod());
 }
开发者ID:undeadcat,项目名称:simple-container,代码行数:7,代码来源:UnboxingCaster.cs

示例10: Load

 public override void Load(ILGenerator il)
 {
     if (field.IsStatic)
         il.Emit(OpCodes.Ldsfld, field);
     else
         il.Emit(OpCodes.Ldfld, field);
 }
开发者ID:AustinWise,项目名称:CSC431,代码行数:7,代码来源:VarField.cs

示例11: Store

 public override void Store(ILGenerator il)
 {
     if (field.IsStatic)
         il.Emit(OpCodes.Stsfld, field);
     else
         il.Emit(OpCodes.Stfld, field);
 }
开发者ID:AustinWise,项目名称:CSC431,代码行数:7,代码来源:VarField.cs

示例12: op_storeb

        private void op_storeb(ILGenerator il)
        {
            MethodInfo setByteCheckedMI = typeof(ZMachine).GetMethod("SetByteChecked", BindingFlags.NonPublic | BindingFlags.Instance);
            MethodInfo setByteMI = typeof(ZMachine).GetMethod("SetByte", BindingFlags.NonPublic | BindingFlags.Instance);
            MethodInfo trapMemoryMI = typeof(ZMachine).GetMethod("TrapMemory", BindingFlags.NonPublic | BindingFlags.Instance);

            il.Emit(OpCodes.Ldarg_0);
            LoadOperand(il, 0);
            LoadOperand(il, 1);
            il.Emit(OpCodes.Add);
            il.Emit(OpCodes.Stloc, zm.TempWordLocal);
            il.Emit(OpCodes.Ldloc, zm.TempWordLocal);
            il.Emit(OpCodes.Conv_U2);
            LoadOperand(il, 2);

            MethodInfo impl = setByteCheckedMI;
            if (operandTypes[0] != OperandType.Variable && operandTypes[1] != OperandType.Variable)
            {
                int address = (ushort)operandValues[0] + operandValues[1];
                if (address > 64 && address < zm.RomStart)
                    impl = setByteMI;
            }
            il.Emit(OpCodes.Call, impl);

            il.Emit(OpCodes.Ldarg_0);
            il.Emit(OpCodes.Ldloc, zm.TempWordLocal);
            il.Emit(OpCodes.Ldc_I4_1);
            il.Emit(OpCodes.Call, trapMemoryMI);
        }
开发者ID:dbremner,项目名称:zlr,代码行数:29,代码来源:Opcodes_VAR.cs

示例13: Emit

        public void Emit(ILGenerator il)
        {
            switch (_index)
            {
                case 0:
                    il.Emit(OpCodes.Ldarg_0);
                    break;

                case 1:
                    il.Emit(OpCodes.Ldarg_1);
                    break;

                case 2:
                    il.Emit(OpCodes.Ldarg_2);
                    break;

                case 3:
                    il.Emit(OpCodes.Ldarg_3);
                    break;

                default:
                    il.Emit(OpCodes.Ldarg_S, _index);
                    break;
            }
        }
开发者ID:bradleyjford,项目名称:inception,代码行数:25,代码来源:LoadArgumentExpression.cs

示例14: GenCode

        public override void GenCode(TypeBuilder tb, MethodBuilder mb, ILGenerator cg)
        {
            Type type = Type.EmptyTypes.GetType();

            for (int i = 0; i < Compiler.Types.Count; i++)
                if (Compiler.Types[i].name == Expr.ReturnType.Name)
                    type = Compiler.SearchType(Compiler.Types[i].typeArray);

            if (assign)
            {
                assign = false;
                LocalBuilder local = cg.DeclareLocal(type);
                cg.Emit(OpCodes.Stloc, local);
                Expr.GenCode(tb, mb, cg);//pone el array, luego el index y luego el valor para hacer stelem
                Index.GenCode(tb, mb, cg);
                cg.Emit(OpCodes.Ldloc, local);
                cg.Emit(OpCodes.Stelem, type);
            }
            else
            {
                Expr.GenCode(tb, mb, cg);
                Index.GenCode(tb, mb, cg);
                cg.Emit(OpCodes.Ldelem, type);
            }
        }
开发者ID:oisbel,项目名称:TigerCompiler,代码行数:25,代码来源:ElemArrayNode.cs

示例15: GenerateLoadType

 /// <summary>Generates IL that loads a Type on the stack.</summary>
 /// <param name="generator"><see cref="ILGenerator"/> to write to.</param>
 /// <param name="type"><see cref="Type"/> to load.</param>
 public static void GenerateLoadType(ILGenerator generator, Type type)
 {
     System.Data.Test.Astoria.TestUtil.CheckArgumentNotNull(generator, "generator");
     System.Data.Test.Astoria.TestUtil.CheckArgumentNotNull(type, "type");
     generator.Emit(OpCodes.Ldtoken, type);
     generator.Emit(OpCodes.Call, typeof(Type).GetMethod("GetTypeFromHandle"));
 }
开发者ID:AlineGuan,项目名称:odata.net,代码行数:10,代码来源:ReflectionUtility.cs


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