private void ZeroCompare(QilNodeType relOp, bool isBoolVal) {
Label lblTrue;
Debug.Assert(relOp == QilNodeType.Eq || relOp == QilNodeType.Ne);
// Test to determine if top stack value is zero (if relOp is Eq) or is not zero (if relOp is Ne)
switch (this.iterCurr.CurrentBranchingContext) {
case BranchingContext.OnTrue:
// If relOp is Eq, jump to true label if top value is zero (Brfalse)
// If relOp is Ne, jump to true label if top value is non-zero (Brtrue)
this.helper.Emit((relOp == QilNodeType.Eq) ? OpCodes.Brfalse : OpCodes.Brtrue, this.iterCurr.LabelBranch);
this.iterCurr.Storage = StorageDescriptor.None();
break;
case BranchingContext.OnFalse:
// If relOp is Eq, jump to false label if top value is non-zero (Brtrue)
// If relOp is Ne, jump to false label if top value is zero (Brfalse)
this.helper.Emit((relOp == QilNodeType.Eq) ? OpCodes.Brtrue : OpCodes.Brfalse, this.iterCurr.LabelBranch);
this.iterCurr.Storage = StorageDescriptor.None();
break;
default:
Debug.Assert(this.iterCurr.CurrentBranchingContext == BranchingContext.None);
// Since (boolval != 0) = boolval, value on top of the stack is already correct
if (!isBoolVal || relOp == QilNodeType.Eq) {
// If relOp is Eq, push "true" if top value is zero, "false" otherwise
// If relOp is Ne, push "true" if top value is non-zero, "false" otherwise
lblTrue = this.helper.DefineLabel();
this.helper.Emit((relOp == QilNodeType.Eq) ? OpCodes.Brfalse : OpCodes.Brtrue, lblTrue);
this.helper.ConvBranchToBool(lblTrue, true);
}
this.iterCurr.Storage = StorageDescriptor.Stack(typeof(bool), false);
break;
}
}