本文整理汇总了C#中CodeGen.Emit方法的典型用法代码示例。如果您正苦于以下问题:C# CodeGen.Emit方法的具体用法?C# CodeGen.Emit怎么用?C# CodeGen.Emit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CodeGen
的用法示例。
在下文中一共展示了CodeGen.Emit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Emit
public override void Emit(CodeGen cg) {
if (_typeOperand.IsAssignableFrom(_expression.Type)) {
// if its always true just emit the bool
cg.EmitConstant(true);
return;
}
_expression.EmitAsObject(cg);
EmitLocation(cg);
cg.Emit(OpCodes.Isinst, _typeOperand);
cg.Emit(OpCodes.Ldnull);
cg.Emit(OpCodes.Cgt_Un);
if (ScriptDomainManager.Options.LightweightDebugging)
{
if (!cg.IsDynamicMethod)
{
var s = SpanToLong(Span);
cg.EmitConstant(s);
cg.EmitCall(Debugging.DebugMethods.ExpressionOut);
}
}
}
示例2: EmitGet
public override void EmitGet(CodeGen cg)
{
Contract.RequiresNotNull(cg, "cg");
_instance.EmitGet(cg);
cg.EmitInt(_index);
if (Type == typeof(object)) cg.Emit(OpCodes.Ldelem_Ref);
else cg.Emit(OpCodes.Ldelem, Type);
}
示例3: EmitGet
public override void EmitGet(CodeGen cg)
{
Contract.RequiresNotNull(cg, "cg");
_instance.EmitGet(cg);
if (!_type.IsAssignableFrom(_instance.Type)) {
if (_type.IsValueType) {
Debug.Assert(_instance.Type == typeof(object));
cg.Emit(OpCodes.Unbox_Any, _type);
} else {
cg.Emit(OpCodes.Castclass, _type);
}
}
}
示例4: Emit
public override void Emit(CodeGen cg)
{
bool eoiused = false;
Label eoi = cg.DefineLabel();
foreach (IfStatementTest t in _tests) {
Label next = cg.DefineLabel();
if (t.Test.Span.IsValid)
{
cg.EmitPosition(t.Test.Start, t.Test.End);
}
t.Test.EmitBranchFalse(cg, next);
t.Body.Emit(cg);
// optimize no else case
if (IsNotIfOrReturn(t.Body))
{
eoiused = true;
cg.Emit(OpCodes.Br, eoi);
}
cg.MarkLabel(next);
}
if (_else != null) {
_else.Emit(cg);
}
if (eoiused)
{
cg.MarkLabel(eoi);
}
}
示例5: EmitGetAddr
public override void EmitGetAddr(CodeGen cg)
{
Contract.RequiresNotNull(cg, "cg");
Debug.Assert(cg == _codeGen);
cg.Emit(OpCodes.Ldloca, _localBuilder);
}
示例6: EmitGet
public override void EmitGet(CodeGen cg)
{
Contract.RequiresNotNull(cg, "cg");
_param.EmitGet(cg);
cg.EmitInt(_index);
cg.Emit(OpCodes.Ldelem_Ref);
}
示例7: EmitDelete
public override void EmitDelete(CodeGen cg, SymbolId name, bool check)
{
// Emit the following:
// RuntimeHelpers.RemoveName(context, symbol_id)
_frame.EmitGet(cg);
cg.EmitSymbolId(name);
cg.EmitCall(typeof(RuntimeHelpers), "RemoveName");
cg.Emit(OpCodes.Pop);
}
示例8: Emit
internal override void Emit(CodeGen cg)
{
left.Emit(cg);
cg.Emit(OpCodes.Dup);
cg.EmitCall(typeof(Ops), "IsTrue");
//cg.emitNonzero(left);
Label l = cg.DefineLabel();
cg.Emit(OpCodes.Brfalse, l);
cg.Emit(OpCodes.Pop);
right.Emit(cg);
cg.MarkLabel(l);
}
示例9: EmitCheck
public virtual void EmitCheck(CodeGen cg, SymbolId name)
{
Contract.RequiresNotNull(cg, "cg");
Label endCheck = cg.DefineLabel();
cg.Emit(OpCodes.Dup);
cg.EmitUninitialized();
cg.Emit(OpCodes.Bne_Un_S, endCheck);
if (_local) {
cg.EmitSymbolId(name);
cg.EmitUnbox(typeof(SymbolId));
cg.EmitCall(typeof(RuntimeHelpers), "ThrowUnboundLocalError");
} else {
cg.Emit(OpCodes.Pop);
cg.EmitCodeContext();
cg.EmitSymbolId(name);
cg.EmitUnbox(typeof(SymbolId));
cg.EmitCall(typeof(RuntimeHelpers), "LookupName");
}
cg.MarkLabel(endCheck);
}
示例10: EmitSet
public override void EmitSet(CodeGen cg)
{
Contract.RequiresNotNull(cg, "cg");
Debug.Assert(cg == this._codeGen);
if (_index < byte.MaxValue)
{
cg.Emit(OpCodes.Starg_S, (byte)_index);
}
else
{
cg.Emit(OpCodes.Starg, (short)_index);
}
}
示例11: Emit
internal override void Emit(CodeGen cg)
{
if (Options.DebugMode) {
cg.EmitPosition(this);
cg.EmitTestTrue(test);
Label endLabel = cg.DefineLabel();
cg.Emit(OpCodes.Brtrue, endLabel);
cg.EmitExprOrNone(message);
cg.EmitConvertFromObject(typeof(string));
cg.EmitCall(typeof(Ops), "AssertionError", new Type[] { typeof(string) });
cg.Emit(OpCodes.Throw);
cg.MarkLabel(endLabel);
}
}
示例12: Emit
public override void Emit(CodeGen cg) {
//cg.EmitPosition(Start, _header);
Label breakTarget = cg.DefineLabel();
Label defaultTarget = breakTarget;
Label[] labels = new Label[_cases.Count];
// Create all labels
for (int i = 0; i < _cases.Count; i++) {
labels[i] = cg.DefineLabel();
// Default case.
if (_cases[i].IsDefault) {
// Set the default target
defaultTarget = labels[i];
}
}
// Emit the test value
_testValue.Emit(cg);
// Check if jmp table can be emitted
if (!TryEmitJumpTable(cg, labels, defaultTarget)) {
// There might be scenario(s) where the jmp table is not emitted
// Emit the switch as conditional branches then
EmitConditionalBranches(cg, labels);
}
// If "default" present, execute default code, else exit the switch
cg.Emit(OpCodes.Br, defaultTarget);
cg.PushTargets(breakTarget, cg.BlockContinueLabel, this);
// Emit the bodies
for (int i = 0; i < _cases.Count; i++) {
// First put the corresponding labels
cg.MarkLabel(labels[i]);
// And then emit the Body!!
_cases[i].Body.Emit(cg);
}
cg.PopTargets();
cg.MarkLabel(breakTarget);
}
示例13: Emit
public override void Emit(CodeGen cg) {
Label startTarget = cg.DefineLabel();
Label breakTarget = cg.DefineLabel();
Label continueTarget = cg.DefineLabel();
cg.MarkLabel(startTarget);
cg.PushTargets(breakTarget, continueTarget, this);
_body.Emit(cg);
cg.MarkLabel(continueTarget);
// TODO: Check if we need to emit position somewhere else also.
//cg.EmitPosition(Start, _header);
_test.Emit(cg);
cg.Emit(OpCodes.Brtrue, startTarget);
cg.PopTargets();
cg.MarkLabel(breakTarget);
}
示例14: EmitNewEnvironment
public override void EmitNewEnvironment(CodeGen cg)
{
ConstructorInfo ctor = EnvironmentType.GetConstructor(new Type[] {StorageType});
// emit: dict.Tuple[.Item000...].Item000 = dict, and then leave dict on the stack
cg.EmitNew(ctor);
cg.Emit(OpCodes.Dup);
Slot tmp = cg.GetLocalTmp(EnvironmentType);
tmp.EmitSet(cg);
cg.EmitPropertyGet(EnvironmentType, "Data");
var fld = StorageType.GetField("$parent$");
//cg.EmitFieldGet(fld);
tmp.EmitGet(cg);
cg.EmitFieldSet(fld);
cg.FreeLocalTmp(tmp);
}
示例15: EmitWithFinallyBlock
private void EmitWithFinallyBlock(CodeGen cg, Slot exc, Slot exit, Slot isTryYielded)
{
// we are certain that Finally will never yield
cg.PushFinallyBlock(null, null);
cg.BeginFinallyBlock();
//finally body
Label endOfFinally = cg.DefineLabel();
// isTryYielded == True ?
isTryYielded.EmitGet(cg);
cg.EmitTestTrue();
cg.Emit(OpCodes.Brtrue, endOfFinally);
// exc == False ?
exc.EmitGet(cg);
cg.EmitTestTrue();
cg.Emit(OpCodes.Brfalse, endOfFinally);
//exit(None, None, None)
cg.EmitCallerContext();
exit.EmitGet(cg);
cg.Emit(OpCodes.Ldnull);
cg.Emit(OpCodes.Ldnull);
cg.Emit(OpCodes.Ldnull);
cg.EmitCall(typeof(Ops), "CallWithContext", new Type[] { typeof(ICallerContext), typeof(object), typeof(object), typeof(object), typeof(object) });
cg.Emit(OpCodes.Pop);
cg.MarkLabel(endOfFinally);
cg.PopTargets();
// finally end
}