本文整理汇总了C#中System.Reflection.Emit.ILGenerator类的典型用法代码示例。如果您正苦于以下问题:C# ILGenerator类的具体用法?C# ILGenerator怎么用?C# ILGenerator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ILGenerator类属于System.Reflection.Emit命名空间,在下文中一共展示了ILGenerator类的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);
}
示例2: FleeILGenerator
public FleeILGenerator(ILGenerator ilg, int startLength = 0, bool isTemp = false)
{
MyILGenerator = ilg;
MyTempLocals = new Dictionary<Type, LocalBuilder>();
MyIsTemp = isTemp;
MyLength = startLength;
}
示例3: ArgumentReferenceEmitter
internal ArgumentReferenceEmitter(IdentifierExpression identifierExpression, ParameterDefinition parameterDefinition, ILGenerator ilGenerator, IOpCodeIndexer instructionsIndexer)
: base(ilGenerator, instructionsIndexer) {
_parameterDefinition = parameterDefinition;
_identifierExpression = identifierExpression;
Type = parameterDefinition.ParameterType.GetActualType();
}
示例4: EmitLoadIndirectOpCodeForType
/// <summary>
/// Emits a load indirect opcode of the appropriate type for a value or object reference.
/// Pops a pointer off the evaluation stack, dereferences it and loads
/// a value of the specified type.
/// </summary>
/// <param name="gen"></param>
/// <param name="type"></param>
public static void EmitLoadIndirectOpCodeForType(ILGenerator gen, Type type)
{
if (type.IsEnum)
{
EmitLoadIndirectOpCodeForType(gen, GetUnderlyingTypeOfEnum(type));
return;
}
if (type.IsByRef)
{
throw new NotSupportedException("Cannot load ByRef values");
}
else if (type.IsPrimitive)
{
OpCode opCode = LdindOpCodesDictionary.Instance[type];
if (Object.ReferenceEquals(opCode, LdindOpCodesDictionary.EmptyOpCode))
{
throw new ArgumentException("Type " + type + " could not be converted to a OpCode");
}
gen.Emit(opCode);
}
else if (type.IsValueType)
{
gen.Emit(OpCodes.Ldobj, type);
}
else
{
gen.Emit(OpCodes.Ldind_Ref);
}
}
示例5: EmitToObjectConversion
/// <summary>
/// Emits a conversion to type object for the value on the stack.
/// </summary>
/// <param name="generator">The code generator to use.</param>
/// <param name="sourceType">The type of value on the stack.</param>
public static void EmitToObjectConversion(ILGenerator generator, Type sourceType)
{
if (sourceType.IsValueType)
{
generator.Emit(OpCodes.Box, sourceType);
}
}
示例6: Emit
public override void Emit(IEasyMember member, ILGenerator gen)
{
LocalBuilder local = gen.DeclareLocal( typeof(object[]) );
gen.Emit(OpCodes.Ldc_I4, _args.Length);
gen.Emit(OpCodes.Newarr, typeof(object));
gen.Emit(OpCodes.Stloc, local);
for(int i=0; i < _args.Length; i++)
{
gen.Emit(OpCodes.Ldloc, local);
gen.Emit(OpCodes.Ldc_I4, i);
TypeReference reference = _args[i];
ArgumentsUtil.EmitLoadOwnerAndReference(reference, gen);
if (reference.Type.IsByRef)
{
throw new NotSupportedException();
}
if (reference.Type.IsValueType)
{
gen.Emit(OpCodes.Box, reference.Type.UnderlyingSystemType);
}
gen.Emit(OpCodes.Stelem_Ref);
}
gen.Emit(OpCodes.Ldloc, local);
}
示例7: 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);
}
示例8: CopyLabels
void CopyLabels(ILGenerator Gen, int i, Dictionary<int, Label> LateLabels)
{
if(!LateLabels.ContainsKey(i)) return;
Gen.MarkLabel(LateLabels[i]);
LateLabels.Remove(i);
}
示例9: AppendWrite
public override void AppendWrite(ILGenerator generator, MessageField field)
{
var done = generator.DefineLabel();
var tmp = generator.DeclareLocal(typeof(Nullable<>).MakeGenericType(FieldType));
generator.Emit(OpCodes.Ldloc_0);
generator.Emit(OpCodes.Call, Property.GetGetMethod());
generator.Emit(OpCodes.Stloc, tmp.LocalIndex);
generator.Emit(OpCodes.Ldloca, tmp.LocalIndex);
generator.Emit(OpCodes.Call, typeof(Nullable<>)
.MakeGenericType(FieldType)
.GetProperty("HasValue")
.GetGetMethod());
generator.Emit(OpCodes.Brfalse_S, done);
field.AppendGuard(generator, Property.GetGetMethod(), done);
field.AppendHeader(generator);
generator.Emit(OpCodes.Ldloca, tmp.LocalIndex);
generator.Emit(OpCodes.Call, typeof(Nullable<>)
.MakeGenericType(FieldType)
.GetProperty("Value")
.GetGetMethod());
field.AppendWriteField(generator);
generator.Emit(OpCodes.Pop);
generator.MarkLabel(done);
}
示例10: EmitCallMethod
private static void EmitCallMethod(ILGenerator il, MethodInfo methodInfo)
{
if (methodInfo.IsStatic)
il.EmitCall(OpCodes.Call, methodInfo, null);
else
il.EmitCall(OpCodes.Callvirt, methodInfo, null);
}
示例11: 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);
}
示例12: TypeLocalPool
public TypeLocalPool(ILGenerator gen, Type t)
{
this.Type = t;
this.stack = new Stack<LocalBuilder>();
this.queue = new Queue<LocalBuilder>();
this.ilgen = gen;
}
示例13: 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;
}
示例14: AbstractCodeBuilder
protected AbstractCodeBuilder(ILGenerator generator)
{
this.generator = generator;
stmts = new ArrayList();
ilmarkers = new ArrayList();
isEmpty = true;
}
示例15: GenDeserializerBody
static void GenDeserializerBody(CodeGenContext ctx, Type type, ILGenerator il)
{
if (type.IsClass)
{
// instantiate empty class
il.Emit(OpCodes.Ldarg_1);
var gtfh = typeof(Type).GetMethod("GetTypeFromHandle", BindingFlags.Public | BindingFlags.Static);
var guo = typeof(System.Runtime.Serialization.FormatterServices).GetMethod("GetUninitializedObject", BindingFlags.Public | BindingFlags.Static);
il.Emit(OpCodes.Ldtoken, type);
il.Emit(OpCodes.Call, gtfh);
il.Emit(OpCodes.Call, guo);
il.Emit(OpCodes.Castclass, type);
il.Emit(OpCodes.Stind_Ref);
}
var fields = GetFieldInfos(type);
foreach (var field in fields)
{
il.Emit(OpCodes.Ldarg_0);
il.Emit(OpCodes.Ldarg_1);
if (type.IsClass)
il.Emit(OpCodes.Ldind_Ref);
il.Emit(OpCodes.Ldflda, field);
GenDeserializerCall(ctx, il, field.FieldType);
}
il.Emit(OpCodes.Ret);
}