2004-07-27 Martin Baulig <martin@ximian.com>
[mono.git] / mcs / ilasm / codegen / SwitchInstr.cs
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 //
9
10
11 using System;
12 using System.Collections;
13
14 namespace Mono.ILASM {
15
16         public class SwitchInstr : IInstr {
17
18                 private ArrayList label_list;
19
20                 public SwitchInstr (ArrayList label_list, Location loc)
21                         : base (loc)
22                 {
23                         this.label_list = label_list;
24                 }
25
26                 public override void Emit (CodeGen code_gen, MethodDef meth,
27                                            PEAPI.CILInstructions cil)
28                 {
29                         int count = 0;
30                         PEAPI.CILLabel[] label_array;
31
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 string) {
36                                                 label_array[count++] = meth.GetLabelDef ((string) lab);
37                                         } else {                                                
38                                                 throw new NotImplementedException ("offsets in switch statements.");
39                                         }
40                                 }
41                         } else {
42                                 label_array = new PEAPI.CILLabel [0];
43                         }
44
45                         cil.Switch (label_array);
46                 }
47         }
48
49 }
50