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


C# ILGenerator.MarkLabel方法代码示例

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


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

示例1: GenerateCode

        public override void GenerateCode(ILGenerator codeGenerator, TypeBuilder typeBuilder, ModuleBuilder moduleBuilder)
        {
            Label forStart = codeGenerator.DefineLabel();
            Label forEnd = codeGenerator.DefineLabel();
            EndLabel = forEnd;

            InitExp.GenerateCode(codeGenerator, typeBuilder, moduleBuilder);

            UpperBoundExp.GenerateCode(codeGenerator, typeBuilder, moduleBuilder);

            codeGenerator.MarkLabel(forStart);

            codeGenerator.Emit(OpCodes.Dup);
            codeGenerator.Emit(OpCodes.Ldsfld, InitExp.ForVariableBuilder);
            codeGenerator.Emit(OpCodes.Blt, forEnd);

            BodyExp.GenerateCode(codeGenerator, typeBuilder, moduleBuilder);

            codeGenerator.Emit(OpCodes.Ldsfld, InitExp.ForVariableBuilder);
            codeGenerator.Emit(OpCodes.Ldc_I4_1);
            codeGenerator.Emit(OpCodes.Add);
            codeGenerator.Emit(OpCodes.Stsfld, InitExp.ForVariableBuilder);
            codeGenerator.Emit(OpCodes.Br, forStart);

            codeGenerator.MarkLabel(forEnd);

            codeGenerator.Emit(OpCodes.Pop);
            InitExp.RestoreVariable(codeGenerator);
        }
开发者ID:sandygk,项目名称:Tiger-Compiler,代码行数:29,代码来源:ForNode.cs

示例2: GenerateCode

        public override void GenerateCode(ILGenerator codeGenerator, TypeBuilder typeBuilder, ModuleBuilder moduleBuilder)
        {
            LeftOperand.GenerateCode(codeGenerator, typeBuilder, moduleBuilder);
            RightOperand.GenerateCode(codeGenerator, typeBuilder, moduleBuilder);

            Label endLabel = codeGenerator.DefineLabel();
            Label trueLabel = codeGenerator.DefineLabel();

            if (LeftOperand.ReturnType == StringType.StringInstance)
            {
                codeGenerator.Emit(OpCodes.Call, typeof(String).GetMethod("CompareTo", new Type[] { typeof(string) }));
                codeGenerator.Emit(OpCodes.Ldc_I4_0);
                codeGenerator.Emit(OpCodes.Bne_Un, trueLabel);
            }
            else
                codeGenerator.Emit(OpCodes.Bne_Un, trueLabel);

            codeGenerator.Emit(OpCodes.Ldc_I4_0);
            codeGenerator.Emit(OpCodes.Br, endLabel);

            codeGenerator.MarkLabel(trueLabel);
            codeGenerator.Emit(OpCodes.Ldc_I4_1);

            codeGenerator.MarkLabel(endLabel);
        }
开发者ID:sandygk,项目名称:Tiger-Compiler,代码行数:25,代码来源:NotEqNode.cs

示例3: BuildUp

        /// <summary>
        /// 
        /// </summary>
        /// <param name="context"></param>
        /// <param name="typeToBuild"></param>
        /// <param name="existing"></param>
        /// <param name="idToBuild"></param>
        /// <param name="il"></param>
        protected override void BuildUp(IBuilderContext context, Type typeToBuild, object existing, string idToBuild,
		                                ILGenerator il)
        {
            IConstructorChooserPolicy ctorChooser = GetConstructorChooser(context, typeToBuild, idToBuild);
            ConstructorInfo ctor = ctorChooser.ChooseConstructor(typeToBuild);
            Label existingObjectNotNull = il.DefineLabel();
            Label done = il.DefineLabel();

            // If existing object (arg 2) is null, call the constructor
            il.Emit(OpCodes.Ldarg_2);
            il.Emit(OpCodes.Ldnull);
            il.Emit(OpCodes.Ceq);
            il.Emit(OpCodes.Brfalse, existingObjectNotNull);

            // resolve all constructor parameters...
            if (ctor != null)
            {
                foreach (ParameterInfo parameter in ctor.GetParameters())
                {
                    EmitResolveParameter(il, parameter);
                    FixupParameterType(il, parameter.ParameterType);
                }
            }
            // invoke constructor, leaving the new object on the top of the stack...
            EmitCallConstructor(il, ctor, typeToBuild);

            // And skip around the else clause
            il.Emit(OpCodes.Br_S, done);

            // We have an existing object, just get it on top of the stack
            il.MarkLabel(existingObjectNotNull);
            il.Emit(OpCodes.Ldarg_2);
            il.MarkLabel(done);
        }
开发者ID:riseandcode,项目名称:open-wscf-2010,代码行数:42,代码来源:CallConstructorStrategy.cs

示例4: Generate

        public override void Generate(ILGenerator generator, Symbols s)
        {
            var Is_False = generator.DefineLabel();
            var End = generator.DefineLabel();

            LeftOperand.Generate(generator, s);
            //Pregunto si hay un 0 en el tope d la pila
            generator.Emit(OpCodes.Ldc_I4_0);
            //Si es verdad salto para la etiqueta es falso
            generator.Emit(OpCodes.Beq, Is_False);

            RightOperand.Generate(generator, s);
            //Pregunto si hay un 0 en el tope d la pila
            generator.Emit(OpCodes.Ldc_I4_0);
            //Si es verdad salto para la etiqueta es falso
            generator.Emit(OpCodes.Beq, Is_False);
            //Si hay un 1 en el tope es porque no salte para el label que me dice si hay algun false ,
            //por lo q el primer operando es true y entonces es true el and
            generator.Emit(OpCodes.Ldc_I4_1);

            generator.Emit(OpCodes.Br, End);

            generator.MarkLabel(Is_False);

            generator.Emit(OpCodes.Ldc_I4_0);
            generator.MarkLabel(End);
        }
开发者ID:hansel0691,项目名称:Tiger,代码行数:27,代码来源:AndNode.cs

示例5: GenerateWriterMethod

		public void GenerateWriterMethod(Type obtype, CodeGenContext ctx, ILGenerator il)
		{
			var getTypeIDMethodInfo = typeof(Serializer).GetMethod("GetTypeID", BindingFlags.NonPublic | BindingFlags.Instance, null,
				new Type[] { typeof(object) }, null);

			var map = ctx.TypeMap;

			// arg0: Serializer, arg1: Stream, arg2: object

			var idLocal = il.DeclareLocal(typeof(ushort));

			// get TypeID from object's Type
			il.Emit(OpCodes.Ldarg_0);
			il.Emit(OpCodes.Ldarg_2);
			il.Emit(OpCodes.Call, getTypeIDMethodInfo);
			il.Emit(OpCodes.Stloc_S, idLocal);

			// write typeID
			il.Emit(OpCodes.Ldarg_1);
			il.Emit(OpCodes.Ldloc_S, idLocal);
			il.Emit(OpCodes.Call, ctx.GetWriterMethodInfo(typeof(ushort)));

			// +1 for 0 (null)
			var jumpTable = new Label[map.Count + 1];
			jumpTable[0] = il.DefineLabel();
			foreach (var kvp in map)
				jumpTable[kvp.Value.TypeID] = il.DefineLabel();

			il.Emit(OpCodes.Ldloc_S, idLocal);
			il.Emit(OpCodes.Switch, jumpTable);

			il.Emit(OpCodes.Newobj, Helpers.ExceptionCtorInfo);
			il.Emit(OpCodes.Throw);

			/* null case */
			il.MarkLabel(jumpTable[0]);
			il.Emit(OpCodes.Ret);

			/* cases for types */
			foreach (var kvp in map)
			{
				var type = kvp.Key;
				var data = kvp.Value;

				il.MarkLabel(jumpTable[data.TypeID]);

				if (data.NeedsInstanceParameter)
					il.Emit(OpCodes.Ldarg_0);

				il.Emit(OpCodes.Ldarg_1);
				il.Emit(OpCodes.Ldarg_2);
				il.Emit(type.IsValueType ? OpCodes.Unbox_Any : OpCodes.Castclass, type);

				il.Emit(OpCodes.Tailcall);
				il.Emit(OpCodes.Call, data.WriterMethodInfo);

				il.Emit(OpCodes.Ret);
			}
		}
开发者ID:yashodhank,项目名称:QuasarRAT,代码行数:59,代码来源:ObjectSerializer.cs

示例6: TranslateToIL

 internal override void TranslateToIL(ILGenerator il, Type rtype){
   Label else_label = il.DefineLabel();
   Label endif_label = il.DefineLabel();
   this.condition.TranslateToConditionalBranch(il, false, else_label, false);
   this.operand1.TranslateToIL(il, rtype);
   il.Emit(OpCodes.Br, endif_label);
   il.MarkLabel(else_label);
   this.operand2.TranslateToIL(il, rtype);
   il.MarkLabel(endif_label);
 }
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:10,代码来源:conditional.cs

示例7: GenerateIL

        public override void GenerateIL(ILGenerator il, SymbolTable st)
        {
            Label beginLoop = il.DefineLabel();
            Label endLoop = il.DefineLabel();
            il.MarkLabel(beginLoop);
            var newTable = new SymbolTable(st, endLoop);
            Block.GenerateIL(il, newTable);

            il.Emit(OpCodes.Br, beginLoop);
            il.MarkLabel(endLoop);
        }
开发者ID:mirhagk,项目名称:IronTuring,代码行数:11,代码来源:LoopNode.cs

示例8: GenerateCode

        public override void GenerateCode(ILGenerator codeGenerator, TypeBuilder typeBuilder, ModuleBuilder moduleBuilder)
        {
            Label thenLabel = codeGenerator.DefineLabel();
            Label endLabel = codeGenerator.DefineLabel();

            ConditionExp.GenerateCode(codeGenerator, typeBuilder, moduleBuilder);
            codeGenerator.Emit(OpCodes.Brfalse, thenLabel);
            ThenExp.GenerateCode(codeGenerator, typeBuilder, moduleBuilder);
            codeGenerator.Emit(OpCodes.Br, endLabel);
            codeGenerator.MarkLabel(thenLabel);
            ElseExp.GenerateCode(codeGenerator, typeBuilder, moduleBuilder);
            codeGenerator.MarkLabel(endLabel);
        }
开发者ID:sandygk,项目名称:Tiger-Compiler,代码行数:13,代码来源:IfThenElseNode.cs

示例9: Generate

		public override void Generate (ILGenerator gen)
		{
			Label falseLabel = gen.DefineLabel ();
			Label endLabel = gen.DefineLabel ();
			
			GenerateCondition (gen, falseLabel);
			trueBlock.Generate (gen);
			gen.Emit (OpCodes.Br, endLabel);
			gen.MarkLabel(falseLabel);
			falseBlock.Generate (gen);
			
			gen.MarkLabel(endLabel);
		}
开发者ID:nickchal,项目名称:pash,代码行数:13,代码来源:CodeWhen.cs

示例10: WriteDeserializerArray

        static void WriteDeserializerArray(TypeBuilder typeBuilder, ILGenerator il, Type type, int tag, MethodInfo setMethod,
            int? itemLocalIndex = null)
        {
            var itemType = type.GetElementType();

            var lengthLocal = il.DeclareLocal(typeof(int));
            var arrayLocal = il.DeclareLocal(type);
            var itemLocal = il.DeclareLocal(itemType);
            var indexLocal = il.DeclareLocal(typeof(int));
            var startLabel = il.DefineLabel();
            var endLabel = il.DefineLabel();

            il.Emit(OpCodes.Ldarg_2);
            il.Emit(OpCodes.Ldarg_3);
            il.Emit(OpCodes.Ldc_I4, tag);
            il.Emit(OpCodes.Call, GetCollectionLengthMethod);
            il.Emit(OpCodes.Stloc, lengthLocal);
            il.Emit(OpCodes.Ldloc, lengthLocal.LocalIndex);
            il.Emit(OpCodes.Newarr, itemType);
            il.Emit(OpCodes.Stloc, arrayLocal.LocalIndex);

            il.Emit(OpCodes.Ldc_I4_0);
            il.Emit(OpCodes.Stloc, indexLocal.LocalIndex);
            il.Emit(OpCodes.Br, startLabel);
            il.MarkLabel(endLabel);

            WriteDeserializerReadValue(typeBuilder, il, itemType, 1, itemLocal.LocalIndex);

            il.Emit(OpCodes.Ldloc, arrayLocal.LocalIndex);
            il.Emit(OpCodes.Ldloc, indexLocal.LocalIndex);
            il.Emit(OpCodes.Ldloc, itemLocal.LocalIndex);
            il.Emit(OpCodes.Stelem, itemType);

            il.Emit(OpCodes.Ldloc, indexLocal.LocalIndex);
            il.Emit(OpCodes.Ldc_I4_1);
            il.Emit(OpCodes.Add);
            il.Emit(OpCodes.Stloc, indexLocal.LocalIndex);
            il.MarkLabel(startLabel);
            il.Emit(OpCodes.Ldloc, indexLocal.LocalIndex);
            il.Emit(OpCodes.Ldloc, lengthLocal.LocalIndex);
            il.Emit(OpCodes.Blt, endLabel);

            if (itemLocalIndex == null) {
                il.Emit(OpCodes.Ldarg_1);
                il.Emit(OpCodes.Ldloc, arrayLocal.LocalIndex);
                il.Emit(OpCodes.Callvirt, setMethod);
            } else {
                il.Emit(OpCodes.Ldloc, arrayLocal.LocalIndex);
                il.Emit(OpCodes.Stloc, itemLocalIndex.Value);
            }
        }
开发者ID:blooop,项目名称:MessageShark,代码行数:51,代码来源:CustomBinary.IL.Deserialize.cs

示例11: GenerateSerializerSwitch

        public static void GenerateSerializerSwitch(CodeGenContext ctx, ILGenerator il, IDictionary<Type, TypeData> map)
        {
            // arg0: Stream, arg1: object

            var idLocal = il.DeclareLocal(typeof(ushort));

            // get TypeID from object's Type
            var getTypeIDMethod = typeof(Serializer).GetMethod("GetTypeID", BindingFlags.NonPublic | BindingFlags.Static, null, new Type[] { typeof(object) }, null);
            il.Emit(OpCodes.Ldarg_1);
            il.EmitCall(OpCodes.Call, getTypeIDMethod, null);
            il.Emit(OpCodes.Stloc_S, idLocal);

            // write typeID
            il.Emit(OpCodes.Ldarg_0);
            il.Emit(OpCodes.Ldloc_S, idLocal);
            il.EmitCall(OpCodes.Call, ctx.GetWriterMethodInfo(typeof(ushort)), null);

            // +1 for 0 (null)
            var jumpTable = new Label[map.Count + 1];
            jumpTable[0] = il.DefineLabel();
            foreach (var kvp in map)
                jumpTable[kvp.Value.TypeID] = il.DefineLabel();

            il.Emit(OpCodes.Ldloc_S, idLocal);
            il.Emit(OpCodes.Switch, jumpTable);

            ConstructorInfo exceptionCtor = typeof(Exception).GetConstructor(BindingFlags.Public | BindingFlags.Instance, null, new Type[0], null);
            il.Emit(OpCodes.Newobj, exceptionCtor);
            il.Emit(OpCodes.Throw);

            /* null case */
            il.MarkLabel(jumpTable[0]);
            il.Emit(OpCodes.Ret);

            /* cases for types */
            foreach (var kvp in map)
            {
                var type = kvp.Key;
                var data = kvp.Value;

                il.MarkLabel(jumpTable[data.TypeID]);

                il.Emit(OpCodes.Ldarg_0);
                il.Emit(OpCodes.Ldarg_1);
                il.Emit(type.IsValueType ? OpCodes.Unbox_Any : OpCodes.Castclass, type);

                il.EmitCall(OpCodes.Call, data.WriterMethodInfo, null);

                il.Emit(OpCodes.Ret);
            }
        }
开发者ID:NelsonDrueding,项目名称:netserializer,代码行数:51,代码来源:SerializerCodegen.cs

示例12: GenerateCode

 public override void GenerateCode(ILGenerator codeGenerator, TypeBuilder typeBuilder, ModuleBuilder moduleBuilder)
 {
     Label trueLabel = codeGenerator.DefineLabel();
     Label endLabel = codeGenerator.DefineLabel();
     LeftOperand.GenerateCode(codeGenerator, typeBuilder, moduleBuilder);
     codeGenerator.Emit(OpCodes.Brtrue, trueLabel);
     RightOperand.GenerateCode(codeGenerator, typeBuilder, moduleBuilder);
     codeGenerator.Emit(OpCodes.Brtrue, trueLabel);
     codeGenerator.Emit(OpCodes.Ldc_I4_0);
     codeGenerator.Emit(OpCodes.Br, endLabel);
     codeGenerator.MarkLabel(trueLabel);
     codeGenerator.Emit(OpCodes.Ldc_I4_1);
     codeGenerator.MarkLabel(endLabel);
 }
开发者ID:sandygk,项目名称:Tiger-Compiler,代码行数:14,代码来源:OrNode.cs

示例13: IfNull

 public void IfNull(ILGenerator il, Emitter isTrue, Emitter isFalse)
 {
     Label nope = il.DefineLabel();
       Label done = il.DefineLabel();
       il.Emit(OpCodes.Ldnull);
       il.Emit(OpCodes.Ceq); // Has 1 if NULL
       il.Emit(OpCodes.Ldc_I4_0);
       il.Emit(OpCodes.Ceq); // Has 1 if NOT NULL
       il.Emit(OpCodes.Brtrue, nope);
       isTrue();
       il.Emit(OpCodes.Br, done);
       il.MarkLabel(nope);
       isFalse();
       il.MarkLabel(done);
 }
开发者ID:benlovell,项目名称:machine,代码行数:15,代码来源:AbstractValueTypeInspector.cs

示例14: GenerateWriterMethod

		public void GenerateWriterMethod(Serializer serializer, Type type, ILGenerator il)
		{
			var valueType = type.GetGenericArguments()[0];

			var noValueLabel = il.DefineLabel();

			MethodInfo getHasValue = type.GetProperty("HasValue").GetGetMethod();
			MethodInfo getValue = type.GetProperty("Value").GetGetMethod();

			var data = serializer.GetIndirectData(valueType);

			il.Emit(OpCodes.Ldarg_1);       // Stream
			il.Emit(OpCodes.Ldarga_S, 2);   // &value
			il.Emit(OpCodes.Call, getHasValue);
			il.Emit(OpCodes.Call, serializer.GetDirectWriter(typeof(bool)));

			il.Emit(OpCodes.Ldarga_S, 2);   // &value
			il.Emit(OpCodes.Call, getHasValue);
			il.Emit(OpCodes.Brfalse_S, noValueLabel);

			if (data.WriterNeedsInstance)
				il.Emit(OpCodes.Ldarg_0);   // Serializer
			il.Emit(OpCodes.Ldarg_1);       // Stream
			il.Emit(OpCodes.Ldarga_S, 2);   // &value
			il.Emit(OpCodes.Call, getValue);

			// XXX for some reason Tailcall causes huge slowdown, at least with "decimal?"
			//il.Emit(OpCodes.Tailcall);
			il.Emit(OpCodes.Call, data.WriterMethodInfo);

			il.MarkLabel(noValueLabel);
			il.Emit(OpCodes.Ret);
		}
开发者ID:kowalot,项目名称:netserializer,代码行数:33,代码来源:NullableSerializer.cs

示例15: CopyLabels

 void CopyLabels(ILGenerator Gen, int i, Dictionary<int, Label> LateLabels)
 {
     if(!LateLabels.ContainsKey(i)) return;
     
     Gen.MarkLabel(LateLabels[i]);
     LateLabels.Remove(i);
 }
开发者ID:BillTheBest,项目名称:IronAHK,代码行数:7,代码来源:CopyLabels.cs


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