本文整理汇总了C#中CodeGen.DefineLabel方法的典型用法代码示例。如果您正苦于以下问题:C# CodeGen.DefineLabel方法的具体用法?C# CodeGen.DefineLabel怎么用?C# CodeGen.DefineLabel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CodeGen
的用法示例。
在下文中一共展示了CodeGen.DefineLabel方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
}
示例2: EnsureLabel
internal Label EnsureLabel(CodeGen cg) {
if (!_initialized) {
_label = cg.DefineLabel();
_initialized = true;
}
return _label;
}
示例3: Emit
public override void Emit(CodeGen cg)
{
if (_statement == null) {
throw new InvalidOperationException("Incomplete LabelStatement");
}
Label label = cg.DefineLabel();
Label label2 = cg.DefineLabel();
cg.MarkLabel(label2);
cg.PushTargets(label, label2, this);
_statement.Emit(cg);
cg.MarkLabel(label);
cg.PopTargets();
}
示例4: 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);
}
示例5: 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);
}
示例6: 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);
}
}
示例7: Emit
public override void Emit(CodeGen cg) {
Nullable<Label> firstTime = null;
Label eol = cg.DefineLabel();
Label breakTarget = cg.DefineLabel();
Label continueTarget = cg.DefineLabel();
if (_increment != null) {
firstTime = cg.DefineLabel();
cg.Emit(OpCodes.Br, firstTime.Value);
}
if (_header.IsValid) {
//cg.EmitPosition(Start, _header);
}
cg.MarkLabel(continueTarget);
if (_increment != null) {
_increment.EmitAs(cg, typeof(void));
cg.MarkLabel(firstTime.Value);
}
if (_test != null) {
_test.Emit(cg);
cg.Emit(OpCodes.Brfalse, eol);
}
cg.PushTargets(breakTarget, continueTarget, this);
_body.Emit(cg);
cg.Emit(OpCodes.Br, continueTarget);
cg.PopTargets();
cg.MarkLabel(eol);
if (_else != null) {
_else.Emit(cg);
}
cg.MarkLabel(breakTarget);
}
示例8: 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);
}
示例9: EmitWithCatchBlock
private void EmitWithCatchBlock(CodeGen cg, Slot exc, Slot exit)
{
cg.BeginCatchBlock(typeof(Exception));
// Extract state from the carrier exception
cg.EmitCallerContext();
cg.EmitCall(typeof(Ops), "ExtractException",
new Type[] { typeof(Exception), typeof(ICallerContext) });
cg.Emit(OpCodes.Pop);
// except body
cg.PushExceptionBlock(Targets.TargetBlockType.Catch, null, null);
cg.EmitConstantBoxed(false);
exc.EmitSet(cg);
cg.EmitCallerContext();
exit.EmitGet(cg);
cg.EmitObjectArray(new Expression[0]);
cg.EmitCallerContext();
cg.EmitCall(typeof(Ops), "ExtractSysExcInfo");
cg.EmitCall(typeof(Ops), "CallWithArgsTupleAndContext", new Type[] { typeof(ICallerContext), typeof(object), typeof(object[]), typeof(object) });
Label afterRaise = cg.DefineLabel();
cg.EmitTestTrue();
cg.Emit(OpCodes.Brtrue, afterRaise);
cg.EmitCall(typeof(Ops), "Raise", new Type[0]); //, new Type[] { typeof(object), typeof(SymbolId) });
cg.MarkLabel(afterRaise);
cg.EmitCallerContext();
cg.EmitCall(typeof(Ops), "ClearException", new Type[] { typeof(ICallerContext) });
cg.PopTargets();
}
示例10: EmitTopYieldTargetLabels
private void EmitTopYieldTargetLabels(List<YieldTarget> yieldTargets, Slot choiceVar, CodeGen cg)
{
if (IsBlockYieldable(yieldTargets)) {
Label label = cg.DefineLabel();
cg.EmitInt(-1);
choiceVar.EmitSet(cg);
cg.Emit(OpCodes.Br, label);
int index = 0;
foreach (YieldTarget yt in yieldTargets) {
cg.MarkLabel(yt.TopBranchTarget);
cg.EmitInt(index++);
choiceVar.EmitSet(cg);
cg.Emit(OpCodes.Br, label);
}
cg.MarkLabel(label);
}
}
示例11: Emit
public override void Emit(CodeGen cg) {
Label eoi = cg.DefineLabel();
Label next = cg.DefineLabel();
_test.Emit(cg);
//cg.EmitSequencePointNone();
//cg.Emit(OpCodes.Nop);
cg.Emit(OpCodes.Brfalse, next);
_true.Emit(cg);
//cg.EmitSequencePointNone();
//cg.Emit(OpCodes.Nop);
cg.Emit(OpCodes.Br, eoi);
cg.MarkLabel(next);
_false.Emit(cg);
//cg.EmitSequencePointNone();
//cg.Emit(OpCodes.Nop);
cg.MarkLabel(eoi);
}
示例12: EmitBranchFalse
public override void EmitBranchFalse(CodeGen cg, Label label) {
switch (NodeType) {
case AstNodeType.Equal:
EmitLocation(cg);
EmitBranchTrue(cg, AstNodeType.NotEqual, label);
if (ScriptDomainManager.Options.LightweightDebugging)
{
if (!cg.IsDynamicMethod)
{
var s = SpanToLong(Span);
cg.EmitConstant(s);
cg.EmitCall(Debugging.DebugMethods.ExpressionOut);
}
}
break;
case AstNodeType.NotEqual:
EmitLocation(cg);
EmitBranchTrue(cg, AstNodeType.Equal, label);
if (ScriptDomainManager.Options.LightweightDebugging)
{
if (!cg.IsDynamicMethod)
{
var s = SpanToLong(Span);
cg.EmitConstant(s);
cg.EmitCall(Debugging.DebugMethods.ExpressionOut);
}
}
break;
case AstNodeType.AndAlso:
// if NOT (left AND right) branch label
if (_left.IsConstant(false)) {
cg.Emit(OpCodes.Br, label);
} else {
if (!_left.IsConstant(true)) {
_left.EmitBranchFalse(cg, label);
}
if (_right.IsConstant(false)) {
cg.Emit(OpCodes.Br, label);
} else if (!_right.IsConstant(true)) {
_right.EmitBranchFalse(cg, label);
}
}
break;
case AstNodeType.OrElse:
// if NOT left AND NOT right branch label
if (!_left.IsConstant(true) && !_right.IsConstant(true)) {
if (_left.IsConstant(false)) {
_right.EmitBranchFalse(cg, label);
} else if (_right.IsConstant(false)) {
_left.EmitBranchFalse(cg, label);
} else {
// if (NOT left) then
// if (NOT right) branch label
// endif
Label endif = cg.DefineLabel();
_left.EmitBranchTrue(cg, endif);
_right.EmitBranchFalse(cg, label);
cg.MarkLabel(endif);
}
}
break;
case AstNodeType.LessThan:
EmitLocation(cg);
EmitBranchTrue(cg, AstNodeType.GreaterThanOrEqual, label);
break;
case AstNodeType.LessThanOrEqual:
EmitLocation(cg);
EmitBranchTrue(cg, AstNodeType.GreaterThan, label);
break;
case AstNodeType.GreaterThan:
EmitLocation(cg);
EmitBranchTrue(cg, AstNodeType.LessThanOrEqual, label);
break;
case AstNodeType.GreaterThanOrEqual:
EmitLocation(cg);
EmitBranchTrue(cg, AstNodeType.LessThan, label);
break;
default:
base.EmitBranchFalse(cg, label);
break;
}
}
示例13: FinishCompare
internal void FinishCompare(CodeGen cg)
{
BinaryExpression bright = (BinaryExpression)right;
Slot valTmp = cg.GetLocalTmp(typeof(object));
Slot retTmp = cg.GetLocalTmp(typeof(object));
bright.left.Emit(cg);
cg.Emit(OpCodes.Dup);
valTmp.EmitSet(cg);
cg.EmitCall(op.Target.Method);
cg.Emit(OpCodes.Dup);
retTmp.EmitSet(cg);
cg.EmitTestTrue();
Label end = cg.DefineLabel();
cg.Emit(OpCodes.Brfalse, end);
valTmp.EmitGet(cg);
if (IsComparison(bright.right)) {
bright.FinishCompare(cg);
} else {
bright.right.Emit(cg);
cg.EmitCall(bright.op.Target.Method);
}
retTmp.EmitSet(cg);
cg.MarkLabel(end);
retTmp.EmitGet(cg);
}
示例14: Emit
internal override void Emit(CodeGen cg)
{
Label eoi = cg.DefineLabel();
Label next = cg.DefineLabel();
cg.EmitTestTrue(testExpr);
cg.Emit(OpCodes.Brfalse, next);
trueExpr.Emit(cg);
cg.Emit(OpCodes.Br, eoi);
cg.MarkLabel(next);
falseExpr.Emit(cg);
cg.MarkLabel(eoi);
}
示例15: EmitSet
internal override void EmitSet(CodeGen cg)
{
// Disallow "[] = l", "[], a = l, l", "[[]] = [l]", etc
if (items.Length == 0) {
cg.Context.AddError("can't assign to " + EmptySequenceString, this);
return;
}
// int leftCount = items.Length;
Slot leftCount = cg.GetLocalTmp(typeof(int));
cg.EmitInt(items.Length);
leftCount.EmitSet(cg);
// object[] values = new object[leftCount];
Slot values = cg.GetLocalTmp(typeof(object[]));
leftCount.EmitGet(cg);
cg.Emit(OpCodes.Newarr, typeof(object));
values.EmitSet(cg);
// ie = Ops.GetEnumerator(<value on stack>)
Slot ie = cg.GetLocalTmp(typeof(IEnumerator));
cg.EmitCall(typeof(Ops), "GetEnumeratorForUnpack");
ie.EmitSet(cg);
// int rightCount = Ops.GetEnumeratorValues(ie, ref values);
Slot rightCount = cg.GetLocalTmp(typeof(int));
ie.EmitGet(cg);
values.EmitGetAddr(cg);
cg.EmitCall(typeof(Ops), "GetEnumeratorValues");
rightCount.EmitSet(cg);
// if (leftCount != rightCount)
// throw Ops.ValueErrorForUnpackMismatch(leftCount, rightCount);
Label equalSizes = cg.DefineLabel();
leftCount.EmitGet(cg);
rightCount.EmitGet(cg);
cg.Emit(OpCodes.Ceq);
cg.Emit(OpCodes.Brtrue_S, equalSizes);
leftCount.EmitGet(cg);
rightCount.EmitGet(cg);
cg.EmitCall(typeof(Ops).GetMethod("ValueErrorForUnpackMismatch"));
cg.Emit(OpCodes.Throw);
cg.MarkLabel(equalSizes);
// for (int i = 0; i < leftCount; i++)
// items[i].Assign(values[i], env);
int i = 0;
foreach (Expression expr in items) {
values.EmitGet(cg);
cg.EmitInt(i++);
cg.Emit(OpCodes.Ldelem_Ref);
expr.EmitSet(cg);
}
cg.FreeLocalTmp(leftCount);
cg.FreeLocalTmp(rightCount);
cg.FreeLocalTmp(values);
cg.FreeLocalTmp(ie);
}