* IInstr.cs: Instructions now get their parent method when being
[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)
21                 {
22                         this.label_list = label_list;
23                 }
24
25                 public void Emit (CodeGen code_gen, MethodDef meth, PEAPI.CILInstructions cil)
26                 {
27                         int count = 0;
28                         PEAPI.CILLabel[] label_array = new PEAPI.CILLabel[label_list.Count];
29
30                         foreach (object lab in label_list) {
31                                 if (lab is string) {
32                                         label_array[count++] = meth.GetLabelDef ((string) lab);
33                                 } else {
34                                         // TODO: int32 labels
35                                         throw new NotImplementedException ("offsets in switch statements.");
36                                 }
37                         }
38
39                         cil.Switch (label_array);
40                 }
41         }
42
43 }
44