//
using System;
+
+#if STATIC
+using IKVM.Reflection;
+using IKVM.Reflection.Emit;
+#else
using System.Reflection;
using System.Reflection.Emit;
+#endif
using Mono.CompilerServices.SymbolWriter;
-namespace Mono.CSharp {
- public static class SymbolWriter
+namespace Mono.CSharp
+{
+ static class SymbolWriter
{
- public static bool HasSymbolWriter {
- get { return symwriter != null; }
- }
-
- private static SymbolWriterImpl symwriter;
+#if !NET_4_0 && !STATIC
+ delegate int GetILOffsetFunc (ILGenerator ig);
+ static GetILOffsetFunc get_il_offset_func;
- class SymbolWriterImpl : MonoSymbolWriter {
-#if !NET_4_0
- delegate int GetILOffsetFunc (ILGenerator ig);
- GetILOffsetFunc get_il_offset_func;
+ delegate Guid GetGuidFunc (ModuleBuilder mb);
+ static GetGuidFunc get_guid_func;
- delegate Guid GetGuidFunc (ModuleBuilder mb);
- GetGuidFunc get_guid_func;
-#endif
+ static void Initialize ()
+ {
+ var mi = typeof (ILGenerator).GetMethod (
+ "Mono_GetCurrentOffset",
+ BindingFlags.Static | BindingFlags.NonPublic);
+ if (mi == null)
+ throw new MissingMethodException ("Mono_GetCurrentOffset");
- ModuleBuilder module_builder;
+ get_il_offset_func = (GetILOffsetFunc) System.Delegate.CreateDelegate (
+ typeof (GetILOffsetFunc), mi);
- public SymbolWriterImpl (ModuleBuilder module_builder, string filename)
- : base (filename)
- {
- this.module_builder = module_builder;
- }
+ mi = typeof (ModuleBuilder).GetMethod (
+ "Mono_GetGuid",
+ BindingFlags.Static | BindingFlags.NonPublic);
+ if (mi == null)
+ throw new MissingMethodException ("Mono_GetGuid");
- public int GetILOffset (ILGenerator ig)
- {
-#if NET_4_0
- return ig.ILOffset;
-#else
- return get_il_offset_func (ig);
+ get_guid_func = (GetGuidFunc) System.Delegate.CreateDelegate (
+ typeof (GetGuidFunc), mi);
+ }
#endif
- }
- public void WriteSymbolFile ()
- {
- Guid guid;
-#if NET_4_0
- guid = module_builder.ModuleVersionId;
+ static int GetILOffset (ILGenerator ig)
+ {
+#if NET_4_0 || STATIC
+ return ig.ILOffset;
#else
- guid = get_guid_func (module_builder);
-#endif
- WriteSymbolFile (guid);
- }
-
- public bool Initialize ()
- {
-#if !NET_4_0
- MethodInfo mi;
-
- mi = typeof (ILGenerator).GetMethod (
- "Mono_GetCurrentOffset",
- BindingFlags.Static | BindingFlags.NonPublic);
- if (mi == null)
- return false;
+ if (get_il_offset_func == null)
+ Initialize ();
- get_il_offset_func = (GetILOffsetFunc) System.Delegate.CreateDelegate (
- typeof (GetILOffsetFunc), mi);
+ return get_il_offset_func (ig);
+#endif
+ }
- mi = typeof (ModuleBuilder).GetMethod (
- "Mono_GetGuid",
- BindingFlags.Static | BindingFlags.NonPublic);
- if (mi == null)
- return false;
+ public static Guid GetGuid (ModuleBuilder module)
+ {
+#if NET_4_0 || STATIC
+ return module.ModuleVersionId;
+#else
+ if (get_guid_func == null)
+ Initialize ();
- get_guid_func = (GetGuidFunc) System.Delegate.CreateDelegate (
- typeof (GetGuidFunc), mi);
+ return get_guid_func (module);
#endif
+ }
- Location.DefineSymbolDocuments (this);
- return true;
- }
+ public static bool HasSymbolWriter {
+ get { return symwriter != null; }
}
+ public static MonoSymbolWriter symwriter;
+
public static void DefineLocalVariable (string name, LocalBuilder builder)
{
if (symwriter != null) {
public static int OpenScope (ILGenerator ig)
{
if (symwriter != null) {
- int offset = symwriter.GetILOffset (ig);
+ int offset = GetILOffset (ig);
return symwriter.OpenScope (offset);
} else {
return -1;
public static void CloseScope (ILGenerator ig)
{
if (symwriter != null) {
- int offset = symwriter.GetILOffset (ig);
+ int offset = GetILOffset (ig);
symwriter.CloseScope (offset);
}
}
public static void OpenCompilerGeneratedBlock (EmitContext ec)
{
if (symwriter != null) {
- int offset = symwriter.GetILOffset (ec.ig);
+ int offset = GetILOffset (ec.ig);
symwriter.OpenCompilerGeneratedBlock (offset);
}
}
public static void CloseCompilerGeneratedBlock (EmitContext ec)
{
if (symwriter != null) {
- int offset = symwriter.GetILOffset (ec.ig);
+ int offset = GetILOffset (ec.ig);
symwriter.CloseCompilerGeneratedBlock (offset);
}
}
public static void StartIteratorBody (EmitContext ec)
{
if (symwriter != null) {
- int offset = symwriter.GetILOffset (ec.ig);
+ int offset = GetILOffset (ec.ig);
symwriter.StartIteratorBody (offset);
}
}
public static void EndIteratorBody (EmitContext ec)
{
if (symwriter != null) {
- int offset = symwriter.GetILOffset (ec.ig);
+ int offset = GetILOffset (ec.ig);
symwriter.EndIteratorBody (offset);
}
}
public static void StartIteratorDispatcher (EmitContext ec)
{
if (symwriter != null) {
- int offset = symwriter.GetILOffset (ec.ig);
+ int offset = GetILOffset (ec.ig);
symwriter.StartIteratorDispatcher (offset);
}
}
public static void EndIteratorDispatcher (EmitContext ec)
{
if (symwriter != null) {
- int offset = symwriter.GetILOffset (ec.ig);
+ int offset = GetILOffset (ec.ig);
symwriter.EndIteratorDispatcher (offset);
}
}
{
if (symwriter != null) {
SourceFileEntry file = loc.SourceFile.SourceFileEntry;
- int offset = symwriter.GetILOffset (ig);
+ int offset = GetILOffset (ig);
symwriter.MarkSequencePoint (
offset, file, loc.Row, loc.Column, loc.Hidden);
}
}
- public static void WriteSymbolFile ()
- {
- if (symwriter != null)
- symwriter.WriteSymbolFile ();
- }
-
- public static bool Initialize (ModuleBuilder module, string filename)
- {
- symwriter = new SymbolWriterImpl (module, filename);
- if (!symwriter.Initialize ()) {
- symwriter = null;
- return false;
- }
-
- return true;
- }
-
public static void Reset ()
{
symwriter = null;