本文整理汇总了C#中CodeGenContext类的典型用法代码示例。如果您正苦于以下问题:C# CodeGenContext类的具体用法?C# CodeGenContext怎么用?C# CodeGenContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CodeGenContext类属于命名空间,在下文中一共展示了CodeGenContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateWriterMethod
public void GenerateWriterMethod(Type type, CodeGenContext ctx, ILGenerator il)
{
// arg0: Serializer, arg1: Stream, arg2: value
var fields = Helpers.GetFieldInfos(type);
foreach (var field in fields)
{
// Note: the user defined value type is not passed as reference. could cause perf problems with big structs
var fieldType = field.FieldType;
var data = ctx.GetTypeDataForCall(fieldType);
if (data.NeedsInstanceParameter)
il.Emit(OpCodes.Ldarg_0);
il.Emit(OpCodes.Ldarg_1);
if (type.IsValueType)
il.Emit(OpCodes.Ldarga_S, 2);
else
il.Emit(OpCodes.Ldarg_2);
il.Emit(OpCodes.Ldfld, field);
il.Emit(OpCodes.Call, data.WriterMethodInfo);
}
il.Emit(OpCodes.Ret);
}
示例2: ReturnArray
protected void ReturnArray(CodeGenContext context)
{
// Ruby.Eval.Return(array, caller);
array.GenCode(context);
context.ldloc(0);
context.call(Runtime.Eval.Return);
}
示例3: GenCall
internal void GenCall(CodeGenContext context)
{
int result = context.CreateLocal("result", PrimitiveType.Object);
PERWAPI.CILLabel endLabel = context.NewLabel();
PERWAPI.CILLabel retryLabel = context.NewLabel();
context.CodeLabel(retryLabel);
context.StartBlock(Clause.Try);
{
// object result = Call(...)
GenCall0(context);
context.stloc(result);
context.Goto(endLabel);
}
PERWAPI.TryBlock tryBlock = context.EndTryBlock();
context.StartBlock(Clause.Catch);
{
CatchBreakException(context, result, endLabel);
}
context.EndCatchBlock(Runtime.BreakExceptionRef, tryBlock);
context.StartBlock(Clause.Catch);
{
CatchRetryException(context, retryLabel);
}
context.EndCatchBlock(Runtime.RetryExceptionRef, tryBlock);
context.CodeLabel(endLabel);
context.ldloc(result);
context.ReleaseLocal(result, true);
}
示例4: GenCode0
internal override void GenCode0(CodeGenContext context)
{
// String.Concat(String.Concat(arg1, arg2), args, ...);
head.GenCode0(context);
if (head.nd_next != null)
{
int first = context.StoreInTemp("head", Runtime.StringRef, head.location);
for (Node n = head.nd_next; n != null; n = n.nd_next)
{
n.GenCode0(context);
int second = context.StoreInTemp("tail", Runtime.StringRef, n.location);
context.ldloc(first);
context.ldloc(second);
context.callvirt(Runtime.String.Concat);
context.stloc(first);
context.ReleaseLocal(second, true);
}
context.ldloc(first);
context.ReleaseLocal(first, true);
}
}
示例5: Defined
internal override void Defined(CodeGenContext context)
{
if (args != null)
new AND(new ProxyNode(MethodDefined, location), new ProxyNode(((Node)args).Defined, location), location).GenCode(context);
else
MethodDefined(context);
}
示例6: GenCode0
internal override void GenCode0(CodeGenContext context)
{
// hash = new Hash();
context.newobj(Runtime.Hash.ctor);
int hash = context.StoreInTemp("hash", Runtime.HashRef, location);
Node entry = elements;
while (entry != null)
{
bool key_created, value_created;
ISimple key = context.PreCompute0(entry, "key", out key_created);
entry = entry.nd_next;
ISimple value = context.PreCompute0(entry, "value", out value_created);
entry = entry.nd_next;
// hash.Add(key, value);
context.ldloc(hash);
key.GenSimple(context);
value.GenSimple(context);
context.callvirt(Runtime.Hash.Add);
context.ReleaseLocal(key, key_created);
context.ReleaseLocal(value, value_created);
}
context.ldloc(hash);
context.ReleaseLocal(hash, true);
}
示例7: Assign
internal override void Assign(CodeGenContext context, Node rhs)
{
// Gen right hand sides
ListGen mrhs;
if (rhs is ListGen && !(rhs is MultipleRHS))
mrhs = (ListGen)rhs;
else
mrhs = new ARGS(null, null, rhs, null, location, true);
bool created;
ISimple list = mrhs.GenArgList(context, out created);
list.GenSimple(context);
context.callvirt(Runtime.ArgList.CheckSingleRHS);
int array = context.StoreInTemp("mrhs", Runtime.ArgListRef, location);
context.ReleaseLocal(list, created);
// Gen assignments to left hand sides
for (LVALUE l = elements; l != null; l = (LVALUE)l.nd_next)
{
l.Assign(context, new MultipleRHS(array, l.location));
context.pop();
}
context.ldloc(array);
context.callvirt(Runtime.ArgList.ToRubyArray);
context.ReleaseLocal(array, true);
}
示例8: GenerateClassForMethod
protected new PERWAPI.MethodDef GenerateClassForMethod(CodeGenContext context)
{
// public class Eval: IEval {
evalClass = context.CreateGlobalClass("_Internal", "Eval", Runtime.SystemObjectRef);
evalClass.AddImplementedInterface(Runtime.IEvalRef);
if (context.CurrentRubyClass == null)
{
context.CurrentRubyClass = CodeGenContext.AddField(evalClass, PERWAPI.FieldAttr.PublicStatic, "myRubyClass", Runtime.ClassRef);
CodeGenContext cctor = context.CreateStaticConstructor(evalClass);
cctor.ldsfld(Runtime.Init.rb_cObject);
cctor.stsfld(context.CurrentRubyClass);
cctor.ret();
cctor.Close();
}
MethodDef constructor = GenConstructor(evalClass, context);
GenInvokeMethod(evalClass, context);
return constructor;
// }
}
示例9: GenCode0
internal virtual void GenCode0(CodeGenContext context)
{
if (this is ISimple)
((ISimple)this).GenSimple(context);
else
throw new NotImplementedException(GetType().ToString());
}
示例10: 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);
}
}
示例11: GenCode0
internal override void GenCode0(CodeGenContext context)
{
bool created;
ISimple left = context.PreCompute(lhs, "lhs", out created);
new COND((Node)left, (Node)left, rhs, location).GenCode(context);
context.ReleaseLocal(left, created);
}
示例12: GenCode0
internal override void GenCode0(CodeGenContext context)
{
bool created;
ISimple list = GenArgList(context, out created);
list.GenSimple(context);
context.callvirt(Runtime.ArgList.ToRubyObject);
context.ReleaseLocal(list, created);
}
示例13: GenCode
internal void GenCode(CodeGenContext context)
{
for (Node stmt = this; stmt != null; stmt = stmt.nd_next)
{
stmt.GenCode0(context);
if (stmt.nd_next != null && context.Reachable())
context.pop();
}
}
示例14: GenerateReaderMethod
public void GenerateReaderMethod(Type type, CodeGenContext ctx, ILGenerator il)
{
// arg0: Serializer, arg1: stream, arg2: out value
if (type.IsClass)
{
// instantiate empty class
il.Emit(OpCodes.Ldarg_2);
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 = Helpers.GetFieldInfos(type);
foreach (var field in fields)
{
var fieldType = field.FieldType;
var data = ctx.GetTypeDataForCall(fieldType);
if (data.NeedsInstanceParameter)
il.Emit(OpCodes.Ldarg_0);
il.Emit(OpCodes.Ldarg_1);
il.Emit(OpCodes.Ldarg_2);
if (type.IsClass)
il.Emit(OpCodes.Ldind_Ref);
il.Emit(OpCodes.Ldflda, field);
il.Emit(OpCodes.Call, data.ReaderMethodInfo);
}
if (typeof(System.Runtime.Serialization.IDeserializationCallback).IsAssignableFrom(type))
{
var miOnDeserialization = typeof(System.Runtime.Serialization.IDeserializationCallback).GetMethod("OnDeserialization",
BindingFlags.Instance | BindingFlags.Public,
null, new[] { typeof(Object) }, null);
il.Emit(OpCodes.Ldarg_2);
il.Emit(OpCodes.Ldnull);
il.Emit(OpCodes.Constrained, type);
il.Emit(OpCodes.Callvirt, miOnDeserialization);
}
il.Emit(OpCodes.Ret);
}
示例15: GenerateCode
internal PERWAPI.PEFile GenerateCode(Field CurrentRubyClass)
{
CodeGenContext context = new CodeGenContext();
context.CurrentRubyClass = CurrentRubyClass;
string name = "Eval_" + System.Guid.NewGuid().ToString("N");
context.CreateAssembly("./", name + ".dll", name, false);
GenerateClassForMethod(context);
return context.Assembly;
}