本文整理汇总了C#中Compiler.EmitCall方法的典型用法代码示例。如果您正苦于以下问题:C# Compiler.EmitCall方法的具体用法?C# Compiler.EmitCall怎么用?C# Compiler.EmitCall使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Compiler
的用法示例。
在下文中一共展示了Compiler.EmitCall方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EmitRead
protected override void EmitRead(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
{
using (Compiler.Local oldValue = ctx.GetLocalWithValue(expectedType, valueFrom))
using (Compiler.Local token = new Compiler.Local(ctx, ctx.MapType(typeof(SubItemToken))))
using (Compiler.Local field = new Compiler.Local(ctx, ctx.MapType(typeof(int))))
{
ctx.LoadReaderWriter();
ctx.EmitCall(ctx.MapType(typeof(ProtoReader)).GetMethod("StartSubItem"));
ctx.StoreValue(token);
Compiler.CodeLabel next = ctx.DefineLabel(), processField = ctx.DefineLabel(), end = ctx.DefineLabel();
ctx.MarkLabel(next);
ctx.EmitBasicRead("ReadFieldHeader", ctx.MapType(typeof(int)));
ctx.CopyValue();
ctx.StoreValue(field);
ctx.LoadValue(Tag); // = 1 - process
ctx.BranchIfEqual(processField, true);
ctx.LoadValue(field);
ctx.LoadValue(1); // < 1 - exit
ctx.BranchIfLess(end, false);
// default: skip
ctx.LoadReaderWriter();
ctx.EmitCall(ctx.MapType(typeof(ProtoReader)).GetMethod("SkipField"));
ctx.Branch(next, true);
// process
ctx.MarkLabel(processField);
if (Tail.RequiresOldValue)
{
if (Helpers.IsValueType(expectedType))
{
ctx.LoadAddress(oldValue, expectedType);
ctx.EmitCall(expectedType.GetMethod("GetValueOrDefault", Helpers.EmptyTypes));
}
else
{
ctx.LoadValue(oldValue);
}
}
Tail.EmitRead(ctx, null);
// note we demanded always returns a value
if (Helpers.IsValueType(expectedType))
{
ctx.EmitCtor(expectedType, Tail.ExpectedType); // re-nullable<T> it
}
ctx.StoreValue(oldValue);
ctx.Branch(next, false);
// outro
ctx.MarkLabel(end);
ctx.LoadValue(token);
ctx.LoadReaderWriter();
ctx.EmitCall(ctx.MapType(typeof(ProtoReader)).GetMethod("EndSubItem"));
ctx.LoadValue(oldValue); // load the old value
}
}
示例2: EmitDedicatedMethod
bool EmitDedicatedMethod(Compiler.CompilerContext ctx, Compiler.Local valueFrom, bool read)
{
System.Reflection.Emit.MethodBuilder method = ctx.GetDedicatedMethod(key, read);
if (method == null) return false;
using (Compiler.Local token = new ProtoBuf.Compiler.Local(ctx, typeof(SubItemToken)))
{
Type rwType = read ? typeof(ProtoReader) : typeof(ProtoWriter);
ctx.LoadValue(valueFrom);
if (!read) // write requires the object for StartSubItem; read doesn't
{
if (type.IsValueType) { ctx.LoadNullRef(); }
else { ctx.CopyValue(); }
}
ctx.LoadReaderWriter();
ctx.EmitCall(rwType.GetMethod("StartSubItem"));
ctx.StoreValue(token);
// note: value already on the stack
ctx.LoadReaderWriter();
ctx.EmitCall(method);
// handle inheritance (we will be calling the *base* version of things,
// but we expect Read to return the "type" type)
if (read && type != method.ReturnType) ctx.Cast(this.type);
ctx.LoadValue(token);
ctx.LoadReaderWriter();
ctx.EmitCall(rwType.GetMethod("EndSubItem"));
}
return true;
}
示例3:
void IProtoSerializer.EmitWrite(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
{
Type type = ExpectedType;
if (type.IsValueType)
{
ctx.EmitCall(GetCustomToString(type));
}
else {
ctx.EmitCall(typeof(object).GetMethod("ToString"));
}
ctx.EmitBasicWrite("WriteString", valueFrom);
}
示例4: using
void IProtoSerializer.EmitRead(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
{
Helpers.DebugAssert(valueFrom != null); // don't support stack-head for this
using (Compiler.Local converted = new Compiler.Local(ctx, tail.ExpectedType)) // declare/re-use local
{
ctx.LoadValue(valueFrom); // load primary onto stack
ctx.EmitCall(toTail); // static convert op, primary-to-surrogate
ctx.StoreValue(converted); // store into surrogate local
tail.EmitRead(ctx, converted); // downstream processing against surrogate local
ctx.LoadValue(converted); // load from surrogate local
ctx.EmitCall(fromTail); // static convert op, surrogate-to-primary
ctx.StoreValue(valueFrom); // store back into primary
}
}
示例5: EmitBeq
private void EmitBeq(Compiler.CompilerContext ctx, Compiler.CodeLabel label, Type type)
{
switch (Helpers.GetTypeCode(type))
{
case ProtoTypeCode.Boolean:
case ProtoTypeCode.Byte:
case ProtoTypeCode.Char:
case ProtoTypeCode.Double:
case ProtoTypeCode.Int16:
case ProtoTypeCode.Int32:
case ProtoTypeCode.Int64:
case ProtoTypeCode.SByte:
case ProtoTypeCode.Single:
case ProtoTypeCode.UInt16:
case ProtoTypeCode.UInt32:
case ProtoTypeCode.UInt64:
ctx.BranchIfEqual(label, false);
break;
default:
MethodInfo method = type.GetMethod("op_Equality", BindingFlags.Public | BindingFlags.Static,
null, new Type[] { type, type }, null);
if (method == null || method.ReturnType != typeof(bool))
{
throw new InvalidOperationException("No suitable equality operator found for default-values of type: " + type.FullName);
}
ctx.EmitCall(method);
ctx.BranchIfTrue(label, false);
break;
}
}
示例6: EmitWrite
protected override void EmitWrite(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
{
ctx.LoadValue((int)fieldNumber);
ctx.LoadValue((int)wireType);
ctx.LoadReaderWriter();
ctx.EmitCall(typeof(ProtoWriter).GetMethod("WriteFieldHeader"));
Tail.EmitWrite(ctx, valueFrom);
}
示例7: EmitWrite
public void EmitWrite(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
{
ctx.LoadValue(valueFrom);
ctx.CastToObject(type);
ctx.LoadReaderWriter();
ctx.LoadValue(ctx.MapMetaKeyToCompiledKey(key));
ctx.LoadValue((int)options);
ctx.EmitCall(ctx.MapType(typeof(BclHelpers)).GetMethod("WriteNetObject"));
}
示例8: EmitRead
public void EmitRead(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
{
ctx.LoadValue(valueFrom);
ctx.CastToObject(type);
ctx.LoadReaderWriter();
ctx.LoadValue(ctx.MapMetaKeyToCompiledKey(key));
if (type == ctx.MapType(typeof(object))) ctx.LoadNullRef();
else ctx.LoadValue(type);
ctx.LoadValue((int)options);
ctx.EmitCall(ctx.MapType(typeof(BclHelpers)).GetMethod("ReadNetObject"));
ctx.CastFromObject(type);
}
示例9:
void IProtoSerializer.EmitRead(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
{
if (overwriteList)
{
ctx.LoadNullRef();
}
else
{
ctx.LoadValue(valueFrom);
}
ctx.LoadReaderWriter();
ctx.EmitCall(typeof(ProtoReader).GetMethod("AppendBytes"));
}
示例10: EmitRead
protected override void EmitRead(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
{
if (setSpecified == null)
{
Tail.EmitRead(ctx, valueFrom);
return;
}
using (Compiler.Local loc = ctx.GetLocalWithValue(ExpectedType, valueFrom))
{
Tail.EmitRead(ctx, loc);
ctx.LoadAddress(loc, ExpectedType);
ctx.LoadValue(1); // true
ctx.EmitCall(setSpecified);
}
}
示例11: EmitWrite
protected override void EmitWrite(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
{
if (getSpecified == null)
{
Tail.EmitWrite(ctx, valueFrom);
return;
}
using (Compiler.Local loc = ctx.GetLocalWithValue(ExpectedType, valueFrom))
{
ctx.LoadAddress(loc, ExpectedType);
ctx.EmitCall(getSpecified);
Compiler.CodeLabel done = ctx.DefineLabel();
ctx.BranchIfFalse(done, false);
Tail.EmitWrite(ctx, loc);
ctx.MarkLabel(done);
}
}
示例12: EmitRead
public void EmitRead(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
{
ctx.LoadValue(valueFrom);
ctx.CastToObject(type);
ctx.LoadReaderWriter();
ctx.LoadValue(key);
if (type == typeof(object))
{
ctx.LoadNullRef();
}
else
{
ctx.LoadValue(type);
}
ctx.LoadValue((int)options);
ctx.EmitCall(typeof(BclHelpers).GetMethod("ReadNetObject"));
ctx.CastFromObject(type);
}
示例13: EmitRead
protected override void EmitRead(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
{
bool writeValue;
SanityCheck(ctx.Model, property, Tail, out writeValue, ctx.NonPublic, ctx.AllowInternal(property));
if (ExpectedType.IsValueType && valueFrom == null)
{
throw new InvalidOperationException("Attempt to mutate struct on the head of the stack; changes would be lost");
}
using (Compiler.Local loc = ctx.GetLocalWithValue(ExpectedType, valueFrom))
{
if (Tail.RequiresOldValue)
{
ctx.LoadAddress(loc, ExpectedType); // stack is: old-addr
ctx.LoadValue(property); // stack is: old-value
}
Type propertyType = property.PropertyType;
ctx.ReadNullCheckedTail(propertyType, Tail, null); // stack is [new-value]
if (writeValue)
{
using (Compiler.Local newVal = new Compiler.Local(ctx, property.PropertyType))
{
ctx.StoreValue(newVal); // stack is empty
Compiler.CodeLabel allDone = new Compiler.CodeLabel(); // <=== default structs
if (!propertyType.IsValueType)
{ // if the tail returns a null, intepret that as *no assign*
allDone = ctx.DefineLabel();
ctx.LoadValue(newVal); // stack is: new-value
ctx.BranchIfFalse(@allDone, true); // stack is empty
}
// assign the value
ctx.LoadAddress(loc, ExpectedType); // parent-addr
ctx.LoadValue(newVal); // parent-obj|new-value
if (shadowSetter == null)
{
ctx.StoreValue(property); // empty
}
else
{
ctx.EmitCall(shadowSetter); // empty
}
if (!propertyType.IsValueType)
{
ctx.MarkLabel(allDone);
}
}
}
else
{ // don't want return value; drop it if anything there
// stack is [new-value]
if (Tail.ReturnsValue) { ctx.DiscardValue(); }
}
}
}
示例14: EmitRead
//.........这里部分代码省略.........
{
ctx.LoadAddress(objValue, ExpectedType);
ctx.BranchIfFalse(skipOld, false);
}
for (int i = 0; i < members.Length; i++)
{
ctx.LoadAddress(objValue, ExpectedType);
if (members[i] is FieldInfo)
{
ctx.LoadValue((FieldInfo)members[i]);
}
else if (members[i] is PropertyInfo)
{
ctx.LoadValue((PropertyInfo)members[i]);
}
ctx.StoreValue(locals[i]);
}
if (!Helpers.IsValueType(ExpectedType)) ctx.MarkLabel(skipOld);
using (Compiler.Local fieldNumber = new Compiler.Local(ctx, ctx.MapType(typeof(int))))
{
Compiler.CodeLabel @continue = ctx.DefineLabel(),
processField = ctx.DefineLabel(),
notRecognised = ctx.DefineLabel();
ctx.Branch(@continue, false);
Compiler.CodeLabel[] handlers = new Compiler.CodeLabel[members.Length];
for (int i = 0; i < members.Length; i++)
{
handlers[i] = ctx.DefineLabel();
}
ctx.MarkLabel(processField);
ctx.LoadValue(fieldNumber);
ctx.LoadValue(1);
ctx.Subtract(); // jump-table is zero-based
ctx.Switch(handlers);
// and the default:
ctx.Branch(notRecognised, false);
for (int i = 0; i < handlers.Length; i++)
{
ctx.MarkLabel(handlers[i]);
IProtoSerializer tail = tails[i];
Compiler.Local oldValIfNeeded = tail.RequiresOldValue ? locals[i] : null;
ctx.ReadNullCheckedTail(locals[i].Type, tail, oldValIfNeeded);
if (tail.ReturnsValue)
{
if (Helpers.IsValueType(locals[i].Type))
{
ctx.StoreValue(locals[i]);
}
else
{
Compiler.CodeLabel hasValue = ctx.DefineLabel(), allDone = ctx.DefineLabel();
ctx.CopyValue();
ctx.BranchIfTrue(hasValue, true); // interpret null as "don't assign"
ctx.DiscardValue();
ctx.Branch(allDone, true);
ctx.MarkLabel(hasValue);
ctx.StoreValue(locals[i]);
ctx.MarkLabel(allDone);
}
}
ctx.Branch(@continue, false);
}
ctx.MarkLabel(notRecognised);
ctx.LoadReaderWriter();
ctx.EmitCall(ctx.MapType(typeof(ProtoReader)).GetMethod("SkipField"));
ctx.MarkLabel(@continue);
ctx.EmitBasicRead("ReadFieldHeader", ctx.MapType(typeof(int)));
ctx.CopyValue();
ctx.StoreValue(fieldNumber);
ctx.LoadValue(0);
ctx.BranchIfGreater(processField, false);
}
for (int i = 0; i < locals.Length; i++)
{
ctx.LoadValue(locals[i]);
}
ctx.EmitCtor(ctor);
ctx.StoreValue(objValue);
}
finally
{
for (int i = 0; i < locals.Length; i++)
{
if (locals[i] != null)
locals[i].Dispose(); // release for re-use
}
}
}
}
示例15: using
void IProtoSerializer.EmitWrite(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
{
Type type = ExpectedType;
if (Helpers.IsValueType(type))
{ // note that for structs, we've already asserted that a custom ToString
// exists; no need to handle the box/callvirt scenario
// force it to a variable if needed, so we can take the address
using (Compiler.Local loc = ctx.GetLocalWithValue(type, valueFrom))
{
ctx.LoadAddress(loc, type);
ctx.EmitCall(GetCustomToString(type));
}
}
else {
ctx.EmitCall(ctx.MapType(typeof(object)).GetMethod("ToString"));
}
ctx.EmitBasicWrite("WriteString", valueFrom);
}