2010-06-03 Jb Evain <jbevain@novell.com>
[mcs.git] / ilasm / codegen / DebuggingInfo.cs
blob57ff6c643555eb7913c07da8772bf060977accf9
1 //
2 // Mono.ILASM.DebuggingInfo.cs
3 //
4 // Author(s):
5 // Martin Baulig (martin@ximian.com)
6 //
7 // Copyright (C) 2004 Novell, Inc.
8 //
10 using PEAPI;
11 using System;
12 using System.IO;
13 using System.Collections;
14 using Mono.CompilerServices.SymbolWriter;
16 namespace Mono.ILASM {
18 public class SymbolWriter : MonoSymbolWriter
20 Mono.ILASM.SourceMethod current_method;
21 CompileUnitEntry current_source;
22 ArrayList methods;
24 public SymbolWriter (string filename)
25 : base (filename)
27 methods = new ArrayList ();
30 public Mono.ILASM.SourceMethod BeginMethod (MethodDef method, Location start)
32 current_method = new Mono.ILASM.SourceMethod (current_source, method, start);
33 methods.Add (current_method);
34 return current_method;
37 public void EndMethod (Location end)
39 current_method.EndLine = end.line;
40 current_method = null;
43 public void BeginSourceFile (string filename)
45 SourceFileEntry file = DefineDocument (filename, null, null);
46 current_source = DefineCompilationUnit (file);
49 public void EndSourceFile ()
51 current_source = null;
54 public void Write (Guid guid)
56 foreach (Mono.ILASM.SourceMethod method in methods)
57 method.Write (this);
59 WriteSymbolFile (guid);
63 public class SourceMethod : IMethodDef
65 CompileUnitEntry file;
66 MethodDef method;
67 ArrayList lines;
68 public int StartLine, EndLine;
70 public SourceMethod (CompileUnitEntry file, MethodDef method, Location start)
72 this.file = file;
73 this.method = method;
74 this.StartLine = start.line;
76 lines = new ArrayList ();
77 MarkLocation (start.line, 0);
80 public string Name {
81 get { return method.Name; }
84 public int Token {
85 get {
86 PEAPI.MethodDef pemethod = method.PeapiMethodDef;
87 return (int) (((uint) PEAPI.MDTable.Method << 24) | pemethod.Row);
91 public void MarkLocation (int line, uint offset)
93 lines.Add (new LineNumberEntry (0, line, (int) offset));
96 public void Write (MonoSymbolWriter writer)
98 LineNumberEntry[] the_lines = new LineNumberEntry [lines.Count];
99 lines.CopyTo (the_lines, 0);
101 LocalVariableEntry[] locals = method.GetLocalVars ();
103 MethodEntry entry = writer.SymbolFile.DefineMethod (
104 file, Token, null, locals, the_lines, null, null, 0, 0);