예제 #1
0
        private void EmitSwitchBucket(SwitchBucket switchBucket, object bucketFallThroughLabel)
        {
            if (switchBucket.LabelsCount == 1)
            {
                var c = switchBucket[0];
                //  if(key == constant)
                //      goto caseLabel;
                ConstantValue constant  = c.Key;
                object        caseLabel = c.Value;
                this.EmitEqBranchForSwitch(constant, caseLabel);
            }
            else
            {
                //  Emit key normalized to startConstant (i.e. key - startConstant)
                //  switch (N, label1, label2... labelN)
                //  goto fallThroughLabel;

                this.EmitNormalizedSwitchKey(switchBucket.StartConstant, switchBucket.EndConstant, bucketFallThroughLabel);

                // Create the labels array for emitting a switch instruction for the bucket
                object[] labels = this.CreateBucketLabels(switchBucket);

                // Emit the switch instruction
                _builder.EmitSwitch(labels);
            }

            _builder.EmitBranch(ILOpCode.Br, bucketFallThroughLabel);
        }