2 // symbolwriter.cs: The symbol writer
5 // Martin Baulig (martin@ximian.com)
7 // (C) 2003 Ximian, Inc.
11 using System.Collections;
12 using System.Reflection;
13 using System.Reflection.Emit;
15 using Mono.CompilerServices.SymbolWriter;
17 namespace Mono.CSharp {
18 public static class SymbolWriter
20 public static bool HasSymbolWriter {
21 get { return symwriter != null; }
24 private static SymbolWriterImpl symwriter;
26 class SymbolWriterImpl : MonoSymbolWriter {
27 delegate int GetILOffsetFunc (ILGenerator ig);
28 delegate Guid GetGuidFunc (ModuleBuilder mb);
30 GetILOffsetFunc get_il_offset_func;
31 GetGuidFunc get_guid_func;
33 ModuleBuilder module_builder;
35 public SymbolWriterImpl (ModuleBuilder module_builder, string filename)
38 this.module_builder = module_builder;
41 public int GetILOffset (ILGenerator ig)
43 return get_il_offset_func (ig);
46 public void WriteSymbolFile ()
48 Guid guid = get_guid_func (module_builder);
49 WriteSymbolFile (guid);
52 public bool Initialize ()
54 MethodInfo mi = typeof (ILGenerator).GetMethod (
55 "Mono_GetCurrentOffset",
56 BindingFlags.Static | BindingFlags.NonPublic);
60 get_il_offset_func = (GetILOffsetFunc) System.Delegate.CreateDelegate (
61 typeof (GetILOffsetFunc), mi);
63 mi = typeof (ModuleBuilder).GetMethod (
65 BindingFlags.Static | BindingFlags.NonPublic);
69 get_guid_func = (GetGuidFunc) System.Delegate.CreateDelegate (
70 typeof (GetGuidFunc), mi);
72 Location.DefineSymbolDocuments (this);
78 public static void DefineLocalVariable (string name, LocalBuilder builder)
80 if (symwriter != null) {
81 int index = MonoDebuggerSupport.GetLocalIndex (builder);
82 symwriter.DefineLocalVariable (index, name);
86 public static void OpenMethod (ISourceFile file, ISourceMethod method,
87 int start_row, int start_column,
88 int end_row, int end_column)
90 if (symwriter != null)
91 symwriter.OpenMethod (file, method, start_row, start_column,
95 public static void CloseMethod ()
97 if (symwriter != null)
98 symwriter.CloseMethod ();
101 public static int OpenScope (ILGenerator ig)
103 if (symwriter != null) {
104 int offset = symwriter.GetILOffset (ig);
105 return symwriter.OpenScope (offset);
111 public static void CloseScope (ILGenerator ig)
113 if (symwriter != null) {
114 int offset = symwriter.GetILOffset (ig);
115 symwriter.CloseScope (offset);
119 public static int DefineNamespace (string name, SourceFileEntry source,
120 string[] using_clauses, int parent)
122 if (symwriter != null)
123 return symwriter.DefineNamespace (name, source, using_clauses, parent);
128 #region Terrania additions
129 public static void DefineAnonymousScope (int id)
131 if (symwriter != null)
132 symwriter.DefineAnonymousScope (id);
135 public static void DefineScopeVariable (int scope, LocalBuilder builder)
137 if (symwriter != null) {
138 int index = MonoDebuggerSupport.GetLocalIndex (builder);
139 symwriter.DefineScopeVariable (scope, index);
143 public static void DefineScopeVariable (int scope)
145 if (symwriter != null)
146 symwriter.DefineScopeVariable (scope, -1);
149 public static void DefineCapturedLocal (int scope_id, string name,
150 string captured_name)
152 if (symwriter != null)
153 symwriter.DefineCapturedLocal (scope_id, name, captured_name);
156 public static void DefineCapturedParameter (int scope_id, string name,
157 string captured_name)
159 if (symwriter != null)
160 symwriter.DefineCapturedParameter (scope_id, name, captured_name);
163 public static void DefineCapturedThis (int scope_id, string captured_name)
165 if (symwriter != null)
166 symwriter.DefineCapturedThis (scope_id, captured_name);
169 public static void DefineCapturedScope (int scope_id, int id, string captured_name)
171 if (symwriter != null)
172 symwriter.DefineCapturedScope (scope_id, id, captured_name);
175 public static void SetRealMethodName (string name)
177 if (symwriter != null)
178 symwriter.SetRealMethodName (name);
181 public static void OpenCompilerGeneratedBlock (ILGenerator ig)
183 if (symwriter != null) {
184 int offset = symwriter.GetILOffset (ig);
185 symwriter.OpenCompilerGeneratedBlock (offset);
189 public static void CloseCompilerGeneratedBlock (ILGenerator ig)
191 if (symwriter != null) {
192 int offset = symwriter.GetILOffset (ig);
193 symwriter.CloseCompilerGeneratedBlock (offset);
197 public static void StartIteratorBody (ILGenerator ig)
199 if (symwriter != null) {
200 int offset = symwriter.GetILOffset (ig);
201 symwriter.StartIteratorBody (offset);
205 public static void EndIteratorBody (ILGenerator ig)
207 if (symwriter != null) {
208 int offset = symwriter.GetILOffset (ig);
209 symwriter.EndIteratorBody (offset);
213 public static void StartIteratorDispatcher (ILGenerator ig)
215 if (symwriter != null) {
216 int offset = symwriter.GetILOffset (ig);
217 symwriter.StartIteratorDispatcher (offset);
221 public static void EndIteratorDispatcher (ILGenerator ig)
223 if (symwriter != null) {
224 int offset = symwriter.GetILOffset (ig);
225 symwriter.EndIteratorDispatcher (offset);
230 public static void MarkSequencePoint (ILGenerator ig, int row, int column)
232 if (symwriter != null) {
233 int offset = symwriter.GetILOffset (ig);
234 symwriter.MarkSequencePoint (offset, row, column);
238 public static void WriteSymbolFile ()
240 if (symwriter != null)
241 symwriter.WriteSymbolFile ();
244 public static bool Initialize (ModuleBuilder module, string filename)
246 symwriter = new SymbolWriterImpl (module, filename);
247 if (!symwriter.Initialize ()) {