2 // symbolwriter.cs: The symbol writer
5 // Martin Baulig (martin@ximian.com)
7 // Copyright 2003 Ximian, Inc.
8 // Copyright 2003-2008 Novell, Inc.
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
{
28 delegate int GetILOffsetFunc (ILGenerator ig
);
29 GetILOffsetFunc get_il_offset_func
;
31 delegate Guid
GetGuidFunc (ModuleBuilder mb
);
33 GetGuidFunc get_guid_func
;
35 ModuleBuilder module_builder
;
37 public SymbolWriterImpl (ModuleBuilder module_builder
, string filename
)
40 this.module_builder
= module_builder
;
43 public int GetILOffset (ILGenerator ig
)
48 return get_il_offset_func (ig
);
52 public void WriteSymbolFile ()
54 Guid guid
= get_guid_func (module_builder
);
55 WriteSymbolFile (guid
);
58 public bool Initialize ()
62 mi
= typeof (ILGenerator
).GetMethod (
63 "Mono_GetCurrentOffset",
64 BindingFlags
.Static
| BindingFlags
.NonPublic
);
68 get_il_offset_func
= (GetILOffsetFunc
) System
.Delegate
.CreateDelegate (
69 typeof (GetILOffsetFunc
), mi
);
72 mi
= typeof (ModuleBuilder
).GetMethod (
74 BindingFlags
.Static
| BindingFlags
.NonPublic
);
78 get_guid_func
= (GetGuidFunc
) System
.Delegate
.CreateDelegate (
79 typeof (GetGuidFunc
), mi
);
81 Location
.DefineSymbolDocuments (this);
87 public static void DefineLocalVariable (string name
, LocalBuilder builder
)
89 if (symwriter
!= null) {
90 int index
= MonoDebuggerSupport
.GetLocalIndex (builder
);
91 symwriter
.DefineLocalVariable (index
, name
);
95 public static SourceMethodBuilder
OpenMethod (ICompileUnit file
, int ns_id
,
98 if (symwriter
!= null)
99 return symwriter
.OpenMethod (file
, ns_id
, method
);
104 public static void CloseMethod ()
106 if (symwriter
!= null)
107 symwriter
.CloseMethod ();
110 public static int OpenScope (ILGenerator ig
)
112 if (symwriter
!= null) {
113 int offset
= symwriter
.GetILOffset (ig
);
114 return symwriter
.OpenScope (offset
);
120 public static void CloseScope (ILGenerator ig
)
122 if (symwriter
!= null) {
123 int offset
= symwriter
.GetILOffset (ig
);
124 symwriter
.CloseScope (offset
);
128 public static int DefineNamespace (string name
, CompileUnitEntry source
,
129 string[] using_clauses
, int parent
)
131 if (symwriter
!= null)
132 return symwriter
.DefineNamespace (name
, source
, using_clauses
, parent
);
137 #region Terrania additions
138 public static void DefineAnonymousScope (int id
)
140 if (symwriter
!= null)
141 symwriter
.DefineAnonymousScope (id
);
144 public static void DefineScopeVariable (int scope
, LocalBuilder builder
)
146 if (symwriter
!= null) {
147 int index
= MonoDebuggerSupport
.GetLocalIndex (builder
);
148 symwriter
.DefineScopeVariable (scope
, index
);
152 public static void DefineScopeVariable (int scope
)
154 if (symwriter
!= null)
155 symwriter
.DefineScopeVariable (scope
, -1);
158 public static void DefineCapturedLocal (int scope_id
, string name
,
159 string captured_name
)
161 if (symwriter
!= null)
162 symwriter
.DefineCapturedLocal (scope_id
, name
, captured_name
);
165 public static void DefineCapturedParameter (int scope_id
, string name
,
166 string captured_name
)
168 if (symwriter
!= null)
169 symwriter
.DefineCapturedParameter (scope_id
, name
, captured_name
);
172 public static void DefineCapturedThis (int scope_id
, string captured_name
)
174 if (symwriter
!= null)
175 symwriter
.DefineCapturedThis (scope_id
, captured_name
);
178 public static void DefineCapturedScope (int scope_id
, int id
, string captured_name
)
180 if (symwriter
!= null)
181 symwriter
.DefineCapturedScope (scope_id
, id
, captured_name
);
184 public static void OpenCompilerGeneratedBlock (ILGenerator ig
)
186 if (symwriter
!= null) {
187 int offset
= symwriter
.GetILOffset (ig
);
188 symwriter
.OpenCompilerGeneratedBlock (offset
);
192 public static void CloseCompilerGeneratedBlock (ILGenerator ig
)
194 if (symwriter
!= null) {
195 int offset
= symwriter
.GetILOffset (ig
);
196 symwriter
.CloseCompilerGeneratedBlock (offset
);
200 public static void StartIteratorBody (ILGenerator ig
)
202 if (symwriter
!= null) {
203 int offset
= symwriter
.GetILOffset (ig
);
204 symwriter
.StartIteratorBody (offset
);
208 public static void EndIteratorBody (ILGenerator ig
)
210 if (symwriter
!= null) {
211 int offset
= symwriter
.GetILOffset (ig
);
212 symwriter
.EndIteratorBody (offset
);
216 public static void StartIteratorDispatcher (ILGenerator ig
)
218 if (symwriter
!= null) {
219 int offset
= symwriter
.GetILOffset (ig
);
220 symwriter
.StartIteratorDispatcher (offset
);
224 public static void EndIteratorDispatcher (ILGenerator ig
)
226 if (symwriter
!= null) {
227 int offset
= symwriter
.GetILOffset (ig
);
228 symwriter
.EndIteratorDispatcher (offset
);
233 public static void MarkSequencePoint (ILGenerator ig
, Location loc
)
235 if (symwriter
!= null) {
236 SourceFileEntry file
= loc
.SourceFile
.SourceFileEntry
;
237 int offset
= symwriter
.GetILOffset (ig
);
238 symwriter
.MarkSequencePoint (
239 offset
, file
, loc
.Row
, loc
.Column
, loc
.Hidden
);
243 public static void WriteSymbolFile ()
245 if (symwriter
!= null)
246 symwriter
.WriteSymbolFile ();
249 public static bool Initialize (ModuleBuilder module
, string filename
)
251 symwriter
= new SymbolWriterImpl (module
, filename
);
252 if (!symwriter
.Initialize ()) {
260 public static void Reset ()