本文整理汇总了C#中System.Reflection.Emit.ILGenerator类的典型用法代码示例。如果您正苦于以下问题:C# ILGenerator类的具体用法?C# ILGenerator怎么用?C# ILGenerator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ILGenerator类属于System.Reflection.Emit命名空间,在下文中一共展示了ILGenerator类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: FleeILGenerator
public FleeILGenerator(ILGenerator ilg, int startLength = 0, bool isTemp = false)
{
MyILGenerator = ilg;
MyTempLocals = new Dictionary<Type, LocalBuilder>();
MyIsTemp = isTemp;
MyLength = startLength;
}
开发者ID:netgrim,项目名称:FleeSharp,代码行数:7,代码来源:FleeILGenerator.cs
示例3: ArgumentReferenceEmitter
internal ArgumentReferenceEmitter(IdentifierExpression identifierExpression, ParameterDefinition parameterDefinition, ILGenerator ilGenerator, IOpCodeIndexer instructionsIndexer)
: base(ilGenerator, instructionsIndexer) {
_parameterDefinition = parameterDefinition;
_identifierExpression = identifierExpression;
Type = parameterDefinition.ParameterType.GetActualType();
}
开发者ID:sagifogel,项目名称:NJection.LambdaConverter,代码行数:7,代码来源:ArgumentReferenceEmitter.cs
示例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);
}
}
开发者ID:nats,项目名称:castle-1.0.3-mono,代码行数:39,代码来源:OpCodeUtil.cs
示例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);
}
}
开发者ID:OpenRIAServices,项目名称:OpenRiaServices,代码行数:12,代码来源:DynamicMethodUtility.cs
示例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);
}
开发者ID:ralescano,项目名称:castle,代码行数:31,代码来源:ReferencesToObjectArrayExpression.cs
示例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);
}
开发者ID:hansel0691,项目名称:Tiger,代码行数:26,代码来源:LetInEndNode.cs
示例8: 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
示例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);
}
开发者ID:radischevo,项目名称:Radischevo.Wahha,代码行数:30,代码来源:NullableFieldIO.cs
示例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);
}
开发者ID:Cussa,项目名称:simple-commons,代码行数:7,代码来源:DelegateFactory.cs
示例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);
}
开发者ID:sandygk,项目名称:Tiger-Compiler,代码行数:25,代码来源:NotEqNode.cs
示例12: TypeLocalPool
public TypeLocalPool(ILGenerator gen, Type t)
{
this.Type = t;
this.stack = new Stack<LocalBuilder>();
this.queue = new Queue<LocalBuilder>();
this.ilgen = gen;
}
开发者ID:Redflameman0,项目名称:SteamKit2,代码行数:7,代码来源:JITContext.cs
示例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;
}
开发者ID:sagifogel,项目名称:NCop,代码行数:26,代码来源:TopGetPropertyInterceptionArgumentsWeaver.cs
示例14: AbstractCodeBuilder
protected AbstractCodeBuilder(ILGenerator generator)
{
this.generator = generator;
stmts = new ArrayList();
ilmarkers = new ArrayList();
isEmpty = true;
}
开发者ID:nats,项目名称:castle-1.0.3-mono,代码行数:7,代码来源:AbstractCodeBuilder.cs
示例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);
}
开发者ID:pchalamet,项目名称:netserializer,代码行数:32,代码来源:Deserializer.cs
示例16: Main
static void Main()
{
// prepare
TypeBuilder typeBuilder = AppDomain.CurrentDomain
.DefineDynamicAssembly(new AssemblyName("TLE"), AssemblyBuilderAccess.Run)
.DefineDynamicModule("TLE")
.DefineType("TLE", TypeAttributes.Public);
MethodBuilder methodBuilder = typeBuilder.DefineMethod("Run",
MethodAttributes.Static | MethodAttributes.Public,
null, new Type[] { typeof(int[]), typeof(bool[]) });
ILGen = methodBuilder.GetILGenerator();
// parse
foreach (string s in Console.In.ReadToEnd().Split(new char[] { '\n', '\r' }).Select(s => s.Trim())) Parse(s);
ILGen.Emit(OpCodes.Ret);
values = new int[variables.Count];
inits = new bool[variables.Count];
// run
try
{
typeBuilder.CreateType().InvokeMember("Run",
BindingFlags.InvokeMethod | BindingFlags.Static | BindingFlags.Public,
null, null, new object[] { values, inits });
}
catch (Exception)
{
Console.WriteLine("Program terminated. Variables state:");
foreach (var variable in variables.OrderBy(x => x.Key, StringComparer.Ordinal))
if (inits[variable.Value]) Console.WriteLine("{0}: {1}", variable.Key, values[variable.Value]);
}
}
开发者ID:Etrnls,项目名称:etrnlabs,代码行数:32,代码来源:1438_compile.cs
示例17: LoadReference
public override void LoadReference(ILGenerator gen)
{
if (Position == -1)
{
throw new ApplicationException("ArgumentReference unitialized");
}
switch(Position)
{
case 0:
gen.Emit(OpCodes.Ldarg_0);
break;
case 1:
gen.Emit(OpCodes.Ldarg_1);
break;
case 2:
gen.Emit(OpCodes.Ldarg_2);
break;
case 3:
gen.Emit(OpCodes.Ldarg_3);
break;
default:
gen.Emit(OpCodes.Ldarg, Position);
break;
}
}
开发者ID:nats,项目名称:castle-1.0.3-mono,代码行数:25,代码来源:ArgumentReference.cs
示例18: FillEntity
public static void FillEntity(ILGenerator generator, Type entityType, LocalBuilder entity)
{
//Dictionary<string, int> fields = DataPortal.FindFields(data);
LocalBuilder fields = generator.DeclareLocal(typeof(Dictionary<string, int>));
generator.Emit(OpCodes.Ldarg_0);
generator.Emit(OpCodes.Call, typeof(DataPortal).GetMethod("FindFields", new Type[]{typeof(IDataRecord)}));
generator.Emit(OpCodes.Stloc, fields);
foreach(PropertyInfo property in entityType.GetProperties())
{
DbFieldAttribute fieldInfo = ReflectionHelper.GetAttribute<DbFieldAttribute>(property);
if(fieldInfo == null)
{
continue;
}
//int fieldIndex = DataPortal.FindField(fields, propInfo.Name);
LocalBuilder fieldIndex = generator.DeclareLocal(typeof(Int32));
generator.Emit(OpCodes.Ldloc, fields);
generator.Emit(OpCodes.Ldstr, fieldInfo.FieldName);
generator.Emit(OpCodes.Call, typeof(DataPortal).GetMethod("FindField", new Type[] { typeof(Dictionary<string, int>), typeof(string) }));
generator.Emit(OpCodes.Stloc, fieldIndex);
//if(fieldIndex >= 0)
Label notFieldExists = generator.DefineLabel();
generator.Emit(OpCodes.Ldloc, fieldIndex);
generator.Emit(OpCodes.Ldc_I4_0);
generator.Emit(OpCodes.Clt);
generator.Emit(OpCodes.Brtrue_S, notFieldExists);
{
FillProperty(generator, entityType, entity, property, fieldIndex);
generator.Emit(OpCodes.Nop);
}
generator.MarkLabel(notFieldExists);
}
}
开发者ID:ritacc,项目名称:RitaccTest,代码行数:35,代码来源:DataEntityBuilder.cs
示例19: EmitBoxIfNeeded
private static void EmitBoxIfNeeded(ILGenerator il, System.Type type)
{
if (type.IsValueType)
{
il.Emit(OpCodes.Box, type);
}
}
开发者ID:sdgdsffdsfff,项目名称:HelloData,代码行数:7,代码来源:ReflectionMSIL.cs
示例20: op_restore
private void op_restore(ILGenerator il)
{
if (argc == 0)
{
MethodInfo impl = typeof(ZMachine).GetMethod("RestoreQuetzal", BindingFlags.NonPublic | BindingFlags.Instance);
il.Emit(OpCodes.Ldarg_0);
il.Emit(OpCodes.Ldc_I4, resultStorage);
il.Emit(OpCodes.Ldc_I4, PC + ZCodeLength);
il.Emit(OpCodes.Call, impl);
compiling = false;
}
else
{
MethodInfo impl = typeof(ZMachine).GetMethod("RestoreAuxiliary", BindingFlags.NonPublic | BindingFlags.Instance);
il.Emit(OpCodes.Ldarg_0);
LoadOperand(il, 0);
LoadOperand(il, 1);
LoadOperand(il, 2);
il.Emit(OpCodes.Call, impl);
StoreResult(il);
}
}
开发者ID:zerodowned,项目名称:angelisland,代码行数:25,代码来源:Opcodes_EXT.cs
注:本文中的System.Reflection.Emit.ILGenerator类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论