* FilterBlock.cs: Use a handler block for the this block. This
[mono.git] / mcs / ilasm / codegen / HandlerBlock.cs
1 //
2 // Mono.ILASM.HandlerBlock
3 //
4 // Author(s):
5 //  Jackson Harper (Jackson@LatitudeGeo.com)
6 //
7 // (C) 2003 Jackson Harper (Jackson@LatitudeGeo.com)
8 //
9
10
11 using System;
12
13 namespace Mono.ILASM {
14
15         public class HandlerBlock {
16                 
17                 private enum Mode {
18                         Str,
19                         Pos,
20                         Offset
21                 }
22
23                 private Mode mode;
24                 private string from_label;
25                 private string to_label;
26                 private int from_pos;
27                 private int to_pos;
28                 private int from_offset;
29                 private int to_offset;
30
31                 public HandlerBlock (string from_label, string to_label)
32                 {
33                         this.from_label = from_label;
34                         this.to_label = to_label;
35                         mode = Mode.Str;
36                 }
37
38                 public HandlerBlock (int from_pos, int to_pos)
39                 {
40                         this.from_pos = from_pos;
41                         this.to_pos = to_pos;
42                         mode = Mode.Pos;
43                 }
44
45                 public HandlerBlock (int from_offset, int to_offset, bool place_holder)
46                 {
47                         this.from_offset = from_offset;
48                         this.to_offset = to_offset;
49                         mode = Mode.Offset;
50                 }
51
52                 public PEAPI.CILLabel GetFromLabel (CodeGen code_gen, MethodDef method)
53                 {
54                         switch (mode) {
55                         case Mode.Str: 
56                                 return method.GetLabelDef (from_label);
57                         case Mode.Pos:
58                                 return method.GetLabelDef (from_pos);
59                         case Mode.Offset:
60                                 return method.GetLabelDef ((uint) from_offset);
61                         default:
62                                 throw new Exception ("Should not reach this point.");
63                         }
64                 }
65
66                 public PEAPI.CILLabel GetToLabel (CodeGen code_gen, MethodDef method)
67                 {
68                         switch (mode) {
69                         case Mode.Str: 
70                                 return method.GetLabelDef (to_label);
71                         case Mode.Pos:
72                                 return method.GetLabelDef (to_pos);
73                         case Mode.Offset:
74                                 return method.GetLabelDef ((uint) to_offset);
75                         default:
76                                 throw new Exception ("Should not reach this point.");
77                         }
78                 }
79         }
80
81 }
82
83