本文整理汇总了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);
}
示例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);
}
}
示例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);
}
示例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;
}
示例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);
}
示例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;
}
示例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);
}
示例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());
}
示例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());
}
示例10: Load
public override void Load(ILGenerator il)
{
if (field.IsStatic)
il.Emit(OpCodes.Ldsfld, field);
else
il.Emit(OpCodes.Ldfld, field);
}
示例11: Store
public override void Store(ILGenerator il)
{
if (field.IsStatic)
il.Emit(OpCodes.Stsfld, field);
else
il.Emit(OpCodes.Stfld, field);
}
示例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);
}
示例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;
}
}
示例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);
}
}
示例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"));
}