Merge pull request #1981 from akoeplinger/ilasm
[mono.git] / mcs / ilasm / codegen / TryBlock.cs
1 //
2 // Mono.ILASM.TryBlock
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 TryBlock : IInstr {
17
18                 private HandlerBlock block;
19                 private ArrayList clause_list;
20
21                 public TryBlock (HandlerBlock block, Location loc)
22                         : base (loc)
23                 {
24                         this.block = block;
25                         clause_list = new ArrayList ();
26                 }
27
28                 public void AddSehClause (ISehClause clause)
29                 {
30                         clause_list.Add (clause);
31                 }
32
33                 public override void Emit (CodeGen code_gen, MethodDef meth,
34                                            PEAPI.CILInstructions cil)
35                 {
36                         PEAPI.CILLabel from = block.GetFromLabel (code_gen, meth);
37                         PEAPI.CILLabel to = block.GetToLabel (code_gen, meth);
38                         PEAPI.TryBlock try_block = new PEAPI.TryBlock (from, to);
39
40                         foreach (ISehClause clause in clause_list)
41                                 try_block.AddHandler (clause.Resolve (code_gen, meth));
42                         
43                         cil.AddTryBlock (try_block);
44                 }
45
46         }
47
48 }
49