2010-04-01 Jb Evain <jbevain@novell.com>
[mcs.git] / ilasm / codegen / SwitchInstr.cs
blob810e779628db8ccd0489308ec2f6038daf7655a2
1 //
2 // Mono.ILASM.SwitchInstr
3 //
4 // Author(s):
5 // Jackson Harper (Jackson@LatitudeGeo.com)
6 //
7 // (C) 2003 Jackson Harper, All rights reserved
8 //
11 using System;
12 using System.Collections;
14 namespace Mono.ILASM {
16 public class SwitchInstr : IInstr {
18 private ArrayList label_list;
20 public SwitchInstr (ArrayList label_list, Location loc)
21 : base (loc)
23 this.label_list = label_list;
26 public override void Emit (CodeGen code_gen, MethodDef meth,
27 PEAPI.CILInstructions cil)
29 int count = 0;
30 PEAPI.CILLabel[] label_array;
32 if (label_list != null) {
33 label_array = new PEAPI.CILLabel[label_list.Count];
34 foreach (object lab in label_list) {
35 if (lab is LabelInfo) {
36 label_array[count++] = ((LabelInfo)lab).Label;
37 } else {
38 throw new InternalErrorException ("offsets in switch statements.");
41 } else {
42 label_array = new PEAPI.CILLabel [0];
45 cil.Switch (label_array);