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 protected 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 !DISABLE_TERRANIA_CHANGES
132 if (symwriter != null)
133 symwriter.DefineAnonymousScope (id);
137 public static void DefineScopeVariable (int scope, LocalBuilder builder)
139 #if !DISABLE_TERRANIA_CHANGES
140 if (symwriter != null) {
141 int index = MonoDebuggerSupport.GetLocalIndex (builder);
142 symwriter.DefineScopeVariable (scope, index);
147 public static void DefineScopeVariable (int scope)
149 #if !DISABLE_TERRANIA_CHANGES
150 if (symwriter != null)
151 symwriter.DefineScopeVariable (scope, -1);
155 public static void DefineCapturedLocal (int scope_id, string name,
156 string captured_name)
158 #if !DISABLE_TERRANIA_CHANGES
159 if (symwriter != null)
160 symwriter.DefineCapturedLocal (scope_id, name, captured_name);
164 public static void DefineCapturedParameter (int scope_id, string name,
165 string captured_name)
167 #if !DISABLE_TERRANIA_CHANGES
168 if (symwriter != null)
169 symwriter.DefineCapturedParameter (scope_id, name, captured_name);
173 public static void DefineCapturedThis (int scope_id, string captured_name)
175 #if !DISABLE_TERRANIA_CHANGES
176 if (symwriter != null)
177 symwriter.DefineCapturedThis (scope_id, captured_name);
181 public static void DefineCapturedScope (int scope_id, int id, string captured_name)
183 #if !DISABLE_TERRANIA_CHANGES
184 if (symwriter != null)
185 symwriter.DefineCapturedScope (scope_id, id, captured_name);
189 public static void SetRealMethodName (string name)
191 #if !DISABLE_TERRANIA_CHANGES
192 if (symwriter != null)
193 symwriter.SetRealMethodName (name);
197 public static void OpenCompilerGeneratedBlock (ILGenerator ig)
199 #if !DISABLE_TERRANIA_CHANGES
200 if (symwriter != null) {
201 int offset = symwriter.GetILOffset (ig);
202 symwriter.OpenCompilerGeneratedBlock (offset);
207 public static void CloseCompilerGeneratedBlock (ILGenerator ig)
209 #if !DISABLE_TERRANIA_CHANGES
210 if (symwriter != null) {
211 int offset = symwriter.GetILOffset (ig);
212 symwriter.CloseCompilerGeneratedBlock (offset);
217 public static void StartIteratorBody (ILGenerator ig)
219 #if !DISABLE_TERRANIA_CHANGES
220 if (symwriter != null) {
221 int offset = symwriter.GetILOffset (ig);
222 symwriter.StartIteratorBody (offset);
227 public static void EndIteratorBody (ILGenerator ig)
229 #if !DISABLE_TERRANIA_CHANGES
230 if (symwriter != null) {
231 int offset = symwriter.GetILOffset (ig);
232 symwriter.EndIteratorBody (offset);
237 public static void StartIteratorDispatcher (ILGenerator ig)
239 #if !DISABLE_TERRANIA_CHANGES
240 if (symwriter != null) {
241 int offset = symwriter.GetILOffset (ig);
242 symwriter.StartIteratorDispatcher (offset);
247 public static void EndIteratorDispatcher (ILGenerator ig)
249 #if !DISABLE_TERRANIA_CHANGES
250 if (symwriter != null) {
251 int offset = symwriter.GetILOffset (ig);
252 symwriter.EndIteratorDispatcher (offset);
258 public static void MarkSequencePoint (ILGenerator ig, int row, int column)
260 if (symwriter != null) {
261 int offset = symwriter.GetILOffset (ig);
262 symwriter.MarkSequencePoint (offset, row, column);
266 public static void WriteSymbolFile ()
268 if (symwriter != null)
269 symwriter.WriteSymbolFile ();
272 public static bool Initialize (ModuleBuilder module, string filename)
274 symwriter = new SymbolWriterImpl (module, filename);
275 if (!symwriter.Initialize ()) {