Revert "[aot] Re-organize JSON dumping code."
authorJoão Matos <joao@tritao.eu>
Mon, 16 Feb 2015 12:46:29 +0000 (12:46 +0000)
committerJoão Matos <joao@tritao.eu>
Mon, 16 Feb 2015 12:46:29 +0000 (12:46 +0000)
This reverts commit 25969466b5339ed263eaca87d5181ce5c4ef9baa.

mono/mini/Makefile.am.in
mono/mini/aot-compiler.c
mono/mini/aot_dump.c [new file with mode: 0644]
mono/utils/Makefile.am
mono/utils/json.c [deleted file]
mono/utils/json.h [deleted file]
msvc/libmonoutils.vcxproj

index 7578f15e7155340dda44dc14ce94934d9b0fcd61..ad1a4b3239da02b72e3a6c255ec97cc9a23e6fca 100755 (executable)
@@ -405,7 +405,6 @@ common_sources = \
        linear-scan.c           \
        aot-compiler.c          \
        aot-runtime.c           \
-       aot_dump.c                      \
        graph.c                 \
        mini-codegen.c          \
        mini-exceptions.c       \
index 3ac620526b10681825d7f430c4b8280aa28fd1cf..b48bb5d87f5d07a811567a8e2213087e9a879b1c 100644 (file)
@@ -50,7 +50,6 @@
 #include <mono/utils/mono-compiler.h>
 #include <mono/utils/mono-time.h>
 #include <mono/utils/mono-mmap.h>
-#include <mono/utils/json.h>
 
 #include "mini.h"
 #include "seq-points.h"
@@ -8905,159 +8904,7 @@ acfg_free (MonoAotCompile *acfg)
        g_free (acfg);
 }
 
-#define WRAPPER(e,n) n,
-static const char* const
-wrapper_type_names [MONO_WRAPPER_NUM + 1] = {
-#include "mono/metadata/wrapper-types.h"
-       NULL
-};
-
-static G_GNUC_UNUSED const char*
-get_wrapper_type_name (int type)
-{
-       return wrapper_type_names [type];
-}
-
-//#define DUMP_PLT
-//#define DUMP_GOT
-
-static void aot_dump (MonoAotCompile *acfg)
-{
-       FILE *dumpfile;
-       char * dumpname;
-
-       JsonWriter writer;
-       json_writer_init (&writer);
-
-       json_writer_object_begin(&writer);
-
-       // Methods
-       json_writer_indent (&writer);
-       json_writer_object_key(&writer, "methods");
-       json_writer_array_begin (&writer);
-
-       int i;
-       for (i = 0; i < acfg->nmethods; ++i) {
-               MonoCompile *cfg;
-               MonoMethod *method;
-               MonoClass *klass;
-               int index;
-
-               cfg = acfg->cfgs [i];
-               if (!cfg)
-                       continue;
-
-               method = cfg->orig_method;
-
-               json_writer_indent (&writer);
-               json_writer_object_begin(&writer);
-
-               json_writer_indent (&writer);
-               json_writer_object_key(&writer, "name");
-               json_writer_printf (&writer, "\"%s\",\n", method->name);
-
-               json_writer_indent (&writer);
-               json_writer_object_key(&writer, "signature");
-               json_writer_printf (&writer, "\"%s\",\n", mono_method_full_name (method,
-                       /*signature=*/TRUE));
-
-               json_writer_indent (&writer);
-               json_writer_object_key(&writer, "code_size");
-               json_writer_printf (&writer, "\"%d\",\n", cfg->code_size);
-
-               klass = method->klass;
-
-               json_writer_indent (&writer);
-               json_writer_object_key(&writer, "class");
-               json_writer_printf (&writer, "\"%s\",\n", klass->name);
-
-               json_writer_indent (&writer);
-               json_writer_object_key(&writer, "namespace");
-               json_writer_printf (&writer, "\"%s\",\n", klass->name_space);
-
-               json_writer_indent (&writer);
-               json_writer_object_key(&writer, "wrapper_type");
-               json_writer_printf (&writer, "\"%s\",\n", get_wrapper_type_name(method->wrapper_type));
-
-               json_writer_indent_pop (&writer);
-               json_writer_indent (&writer);
-               json_writer_object_end (&writer);
-               json_writer_printf (&writer, ",\n");
-       }
-
-       json_writer_indent_pop (&writer);
-       json_writer_indent (&writer);
-       json_writer_array_end (&writer);
-       json_writer_printf (&writer, ",\n");
-
-       // PLT entries
-#ifdef DUMP_PLT
-       json_writer_indent_push (&writer);
-       json_writer_indent (&writer);
-       json_writer_object_key(&writer, "plt");
-       json_writer_array_begin (&writer);
-
-       for (i = 0; i < acfg->plt_offset; ++i) {
-               MonoPltEntry *plt_entry = NULL;
-               MonoJumpInfo *ji;
-
-               if (i == 0)
-                       /* 
-                        * The first plt entry is unused.
-                        */
-                       continue;
-
-               plt_entry = g_hash_table_lookup (acfg->plt_offset_to_entry, GUINT_TO_POINTER (i));
-               ji = plt_entry->ji;
-
-               json_writer_indent (&writer);
-               json_writer_printf (&writer, "{ ");
-               json_writer_object_key(&writer, "symbol");
-               json_writer_printf (&writer, "\"%s\" },\n", plt_entry->symbol);
-       }
-
-       json_writer_indent_pop (&writer);
-       json_writer_indent (&writer);
-       json_writer_array_end (&writer);
-       json_writer_printf (&writer, ",\n");
-#endif
-
-       // GOT entries
-#ifdef DUMP_GOT
-       json_writer_indent_push (&writer);
-       json_writer_indent (&writer);
-       json_writer_object_key(&writer, "got");
-       json_writer_array_begin (&writer);
-
-       json_writer_indent_push (&writer);
-       for (i = 0; i < acfg->got_info.got_patches->len; ++i) {
-               MonoJumpInfo *ji = g_ptr_array_index (acfg->got_info.got_patches, i);
-
-               json_writer_indent (&writer);
-               json_writer_printf (&writer, "{ ");
-               json_writer_object_key(&writer, "patch_name");
-               json_writer_printf (&writer, "\"%s\" },\n", get_patch_name (ji->type));
-       }
-
-       json_writer_indent_pop (&writer);
-       json_writer_indent (&writer);
-       json_writer_array_end (&writer);
-       json_writer_printf (&writer, ",\n");
-#endif
-
-       json_writer_indent_pop (&writer);
-       json_writer_indent (&writer);
-       json_writer_object_end (&writer);
-
-       dumpname = g_strdup_printf ("%s.json", g_path_get_basename (acfg->image->name));
-       dumpfile = fopen (dumpname, "w+");
-       g_free (dumpname);
-
-       fprintf (dumpfile, "%s", writer.text->str);
-       fclose (dumpfile);
-
-       json_writer_destroy (&writer);
-}
+#include "aot_dump.c"
 
 int
 mono_compile_assembly (MonoAssembly *ass, guint32 opts, const char *aot_options)
diff --git a/mono/mini/aot_dump.c b/mono/mini/aot_dump.c
new file mode 100644 (file)
index 0000000..8dbefcd
--- /dev/null
@@ -0,0 +1,287 @@
+/*
+ * aot-dump.c: mono Ahead of Time compiler JSON dumping
+ *
+ * Author:
+ *   Joao Matos (joao.matos@xamarin.com)
+ *
+ * Copyright 2015 Xamarin Inc (http://www.xamarin.com)
+ */
+
+#ifndef MONO_SMALL_CONFIG
+
+#define JSON_INDENT_VALUE 2
+
+typedef struct JsonWriter {
+       GString* text;
+       int indent;
+} JsonWriter;
+
+static void json_writer_init (JsonWriter* writer) MONO_INTERNAL;
+static void json_writer_destroy (JsonWriter* writer);
+static void json_writer_indent(JsonWriter* writer);
+static void json_writer_indent_push(JsonWriter* writer);
+static void json_writer_indent_pop(JsonWriter* writer);
+static void json_writer_vprintf(JsonWriter* writer, const gchar *format, va_list args);
+static void json_writer_printf(JsonWriter* writer, const gchar *format, ...);
+static void json_writer_array_begin(JsonWriter* writer);
+static void json_writer_array_end(JsonWriter* writer);
+static void json_writer_object_begin(JsonWriter* writer);
+static void json_writer_object_end(JsonWriter* writer);
+static void json_writer_object_key(JsonWriter* writer, const gchar* format, ...);
+
+static void json_writer_init (JsonWriter* writer)
+{
+       g_assert (writer && "Expected a valid JSON writer instance");
+
+       writer->text = g_string_new ("");
+       writer->indent = 0;
+}
+
+static void json_writer_destroy (JsonWriter* writer)
+{
+       g_assert (writer && "Expected a valid JSON writer instance");
+       g_string_free (writer->text, /*free_segment=*/TRUE);
+}
+
+static void json_writer_indent_push(JsonWriter* writer)
+{
+       g_assert (writer && "Expected a valid JSON writer instance");
+       writer->indent += JSON_INDENT_VALUE;
+}
+
+static void json_writer_indent_pop(JsonWriter* writer)
+{
+       g_assert (writer && "Expected a valid JSON writer instance");
+       writer->indent -= JSON_INDENT_VALUE;
+}
+
+static void json_writer_indent(JsonWriter* writer)
+{
+       g_assert (writer && "Expected a valid JSON writer instance");
+
+       int i = 0;
+       for (i = 0; i < writer->indent; ++i)
+               g_string_append_c (writer->text, ' ');
+}
+
+static void json_writer_vprintf(JsonWriter* writer, const gchar *format, va_list args)
+{
+       g_assert (writer && "Expected a valid JSON writer instance");
+       g_string_append_vprintf (writer->text, format, args);
+}
+
+static void json_writer_printf(JsonWriter* writer, const gchar *format, ...)
+{
+       g_assert (writer && "Expected a valid JSON writer instance");
+
+       va_list args;
+       va_start (args, format);
+
+       g_string_append_vprintf (writer->text, format, args);
+
+       va_end (args);
+}
+
+static void json_writer_array_begin(JsonWriter* writer)
+{
+       g_assert (writer && "Expected a valid JSON writer instance");
+       g_string_append_printf (writer->text, "[\n");
+       writer->indent += JSON_INDENT_VALUE;
+}
+
+static void json_writer_array_end(JsonWriter* writer)
+{
+       g_assert (writer && "Expected a valid JSON writer instance");
+       g_string_append_printf (writer->text, "]");
+       writer->indent -= JSON_INDENT_VALUE;
+}
+
+static void json_writer_object_begin(JsonWriter* writer)
+{
+       g_assert (writer && "Expected a valid JSON writer instance");
+       json_writer_printf (writer, "{\n");
+       writer->indent += JSON_INDENT_VALUE;
+}
+
+static void json_writer_object_end(JsonWriter* writer)
+{
+       g_assert (writer && "Expected a valid JSON writer instance");
+       json_writer_printf (writer, "}");
+}
+
+static void json_writer_object_key(JsonWriter* writer, const gchar* format, ...)
+{
+       g_assert (writer && "Expected a valid JSON writer instance");
+
+       va_list args;
+       va_start (args, format);
+
+       g_string_append_printf (writer->text, "\"");
+       json_writer_vprintf (writer, format, args);
+       g_string_append_printf (writer->text, "\" : ");
+
+       va_end (args);
+}
+
+#define WRAPPER(e,n) n,
+static const char* const
+wrapper_type_names [MONO_WRAPPER_NUM + 1] = {
+#include "mono/metadata/wrapper-types.h"
+       NULL
+};
+
+static G_GNUC_UNUSED const char*
+get_wrapper_type_name (int type)
+{
+       return wrapper_type_names [type];
+}
+
+//#define DUMP_PLT
+//#define DUMP_GOT
+
+static void aot_dump (MonoAotCompile *acfg)
+{
+       FILE *dumpfile;
+       char * dumpname;
+
+       JsonWriter writer;
+       json_writer_init (&writer);
+
+       json_writer_object_begin(&writer);
+
+       // Methods
+       json_writer_indent (&writer);
+       json_writer_object_key(&writer, "methods");
+       json_writer_array_begin (&writer);
+
+       int i;
+       for (i = 0; i < acfg->nmethods; ++i) {
+               MonoCompile *cfg;
+               MonoMethod *method;
+               MonoClass *klass;
+               int index;
+
+               cfg = acfg->cfgs [i];
+               if (!cfg)
+                       continue;
+
+               method = cfg->orig_method;
+
+               json_writer_indent (&writer);
+               json_writer_object_begin(&writer);
+
+               json_writer_indent (&writer);
+               json_writer_object_key(&writer, "name");
+               json_writer_printf (&writer, "\"%s\",\n", method->name);
+
+               json_writer_indent (&writer);
+               json_writer_object_key(&writer, "signature");
+               json_writer_printf (&writer, "\"%s\",\n", mono_method_full_name (method,
+                       /*signature=*/TRUE));
+
+               json_writer_indent (&writer);
+               json_writer_object_key(&writer, "code_size");
+               json_writer_printf (&writer, "\"%d\",\n", cfg->code_size);
+
+               klass = method->klass;
+
+               json_writer_indent (&writer);
+               json_writer_object_key(&writer, "class");
+               json_writer_printf (&writer, "\"%s\",\n", klass->name);
+
+               json_writer_indent (&writer);
+               json_writer_object_key(&writer, "namespace");
+               json_writer_printf (&writer, "\"%s\",\n", klass->name_space);
+
+               json_writer_indent (&writer);
+               json_writer_object_key(&writer, "wrapper_type");
+               json_writer_printf (&writer, "\"%s\",\n", get_wrapper_type_name(method->wrapper_type));
+
+               json_writer_indent_pop (&writer);
+               json_writer_indent (&writer);
+               json_writer_object_end (&writer);
+               json_writer_printf (&writer, ",\n");
+       }
+
+       json_writer_indent_pop (&writer);
+       json_writer_indent (&writer);
+       json_writer_array_end (&writer);
+       json_writer_printf (&writer, ",\n");
+
+       // PLT entries
+#ifdef DUMP_PLT
+       json_writer_indent_push (&writer);
+       json_writer_indent (&writer);
+       json_writer_object_key(&writer, "plt");
+       json_writer_array_begin (&writer);
+
+       for (i = 0; i < acfg->plt_offset; ++i) {
+               MonoPltEntry *plt_entry = NULL;
+               MonoJumpInfo *ji;
+
+               if (i == 0)
+                       /* 
+                        * The first plt entry is unused.
+                        */
+                       continue;
+
+               plt_entry = g_hash_table_lookup (acfg->plt_offset_to_entry, GUINT_TO_POINTER (i));
+               ji = plt_entry->ji;
+
+               json_writer_indent (&writer);
+               json_writer_printf (&writer, "{ ");
+               json_writer_object_key(&writer, "symbol");
+               json_writer_printf (&writer, "\"%s\" },\n", plt_entry->symbol);
+       }
+
+       json_writer_indent_pop (&writer);
+       json_writer_indent (&writer);
+       json_writer_array_end (&writer);
+       json_writer_printf (&writer, ",\n");
+#endif
+
+       // GOT entries
+#ifdef DUMP_GOT
+       json_writer_indent_push (&writer);
+       json_writer_indent (&writer);
+       json_writer_object_key(&writer, "got");
+       json_writer_array_begin (&writer);
+
+       json_writer_indent_push (&writer);
+       for (i = 0; i < acfg->got_info.got_patches->len; ++i) {
+               MonoJumpInfo *ji = g_ptr_array_index (acfg->got_info.got_patches, i);
+
+               json_writer_indent (&writer);
+               json_writer_printf (&writer, "{ ");
+               json_writer_object_key(&writer, "patch_name");
+               json_writer_printf (&writer, "\"%s\" },\n", get_patch_name (ji->type));
+       }
+
+       json_writer_indent_pop (&writer);
+       json_writer_indent (&writer);
+       json_writer_array_end (&writer);
+       json_writer_printf (&writer, ",\n");
+#endif
+
+       json_writer_indent_pop (&writer);
+       json_writer_indent (&writer);
+       json_writer_object_end (&writer);
+
+       dumpname = g_strdup_printf ("%s.json", g_path_get_basename (acfg->image->name));
+       dumpfile = fopen (dumpname, "w+");
+       g_free (dumpname);
+
+       fprintf (dumpfile, "%s", writer.text->str);
+       fclose (dumpfile);
+
+       json_writer_destroy (&writer);
+}
+
+#else
+
+static void aot_dump (MonoAotCompile *acfg)
+{
+
+}
+
+#endif
\ No newline at end of file
index ec199f2ce8a5f40b8caf0d4c4632fb30e0ce4d4e..7e16bc60ffac240fb43f9dd351173dc9ccacf4a6 100644 (file)
@@ -123,8 +123,6 @@ monoutils_sources = \
        mono-conc-hashtable.c   \
        sha1.h          \
        sha1.c  \
-       json.h  \
-       json.c  \       
        networking.c    \
        networking-posix.c      \
        networking-fallback.c   \
diff --git a/mono/utils/json.c b/mono/utils/json.c
deleted file mode 100644 (file)
index 4de3e9f..0000000
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * json.c: JSON writer
- *
- * Author:
- *   Joao Matos (joao.matos@xamarin.com)
- *
- * Copyright 2015 Xamarin Inc (http://www.xamarin.com)
- */
-
-#include <mono/utils/json.h>
-
-void json_writer_init (JsonWriter* writer)
-{
-       g_assert (writer && "Expected a valid JSON writer instance");
-
-       writer->text = g_string_new ("");
-       writer->indent = 0;
-}
-
-void json_writer_destroy (JsonWriter* writer)
-{
-       g_assert (writer && "Expected a valid JSON writer instance");
-       g_string_free (writer->text, /*free_segment=*/TRUE);
-}
-
-void json_writer_indent_push(JsonWriter* writer)
-{
-       g_assert (writer && "Expected a valid JSON writer instance");
-       writer->indent += JSON_INDENT_VALUE;
-}
-
-void json_writer_indent_pop(JsonWriter* writer)
-{
-       g_assert (writer && "Expected a valid JSON writer instance");
-       writer->indent -= JSON_INDENT_VALUE;
-}
-
-void json_writer_indent(JsonWriter* writer)
-{
-       g_assert (writer && "Expected a valid JSON writer instance");
-
-       int i = 0;
-       for (i = 0; i < writer->indent; ++i)
-               g_string_append_c (writer->text, ' ');
-}
-
-void json_writer_vprintf(JsonWriter* writer, const gchar *format, va_list args)
-{
-       g_assert (writer && "Expected a valid JSON writer instance");
-       g_string_append_vprintf (writer->text, format, args);
-}
-
-void json_writer_printf(JsonWriter* writer, const gchar *format, ...)
-{
-       g_assert (writer && "Expected a valid JSON writer instance");
-
-       va_list args;
-       va_start (args, format);
-
-       g_string_append_vprintf (writer->text, format, args);
-
-       va_end (args);
-}
-
-void json_writer_array_begin(JsonWriter* writer)
-{
-       g_assert (writer && "Expected a valid JSON writer instance");
-       g_string_append_printf (writer->text, "[\n");
-       writer->indent += JSON_INDENT_VALUE;
-}
-
-void json_writer_array_end(JsonWriter* writer)
-{
-       g_assert (writer && "Expected a valid JSON writer instance");
-       g_string_append_printf (writer->text, "]");
-       writer->indent -= JSON_INDENT_VALUE;
-}
-
-void json_writer_object_begin(JsonWriter* writer)
-{
-       g_assert (writer && "Expected a valid JSON writer instance");
-       json_writer_printf (writer, "{\n");
-       writer->indent += JSON_INDENT_VALUE;
-}
-
-void json_writer_object_end(JsonWriter* writer)
-{
-       g_assert (writer && "Expected a valid JSON writer instance");
-       json_writer_printf (writer, "}");
-}
-
-void json_writer_object_key(JsonWriter* writer, const gchar* format, ...)
-{
-       g_assert (writer && "Expected a valid JSON writer instance");
-
-       va_list args;
-       va_start (args, format);
-
-       g_string_append_printf (writer->text, "\"");
-       json_writer_vprintf (writer, format, args);
-       g_string_append_printf (writer->text, "\" : ");
-
-       va_end (args);
-}
diff --git a/mono/utils/json.h b/mono/utils/json.h
deleted file mode 100644 (file)
index 5e5a06a..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * json.h: JSON writer
- *
- * Author:
- *   Joao Matos (joao.matos@xamarin.com)
- *
- * Copyright 2015 Xamarin Inc (http://www.xamarin.com)
- */
-
-#ifndef __MONO_UTILS_JSON_H__
-#define __MONO_UTILS_JSON_H__
-
- #include <glib.h>
-
-#define JSON_INDENT_VALUE 2
-
-typedef struct JsonWriter {
-       GString* text;
-       int indent;
-} JsonWriter;
-
-void json_writer_init (JsonWriter* writer);
-void json_writer_destroy (JsonWriter* writer);
-void json_writer_indent(JsonWriter* writer);
-void json_writer_indent_push(JsonWriter* writer);
-void json_writer_indent_pop(JsonWriter* writer);
-void json_writer_vprintf(JsonWriter* writer, const gchar *format, va_list args);
-void json_writer_printf(JsonWriter* writer, const gchar *format, ...);
-void json_writer_array_begin(JsonWriter* writer);
-void json_writer_array_end(JsonWriter* writer);
-void json_writer_object_begin(JsonWriter* writer);
-void json_writer_object_end(JsonWriter* writer);
-void json_writer_object_key(JsonWriter* writer, const gchar* format, ...);
-
-#endif
index a091267ea896a81a1d73d318bf8f266ea67ad41f..681f758ed7ec9308ffc177bc7022f98f49faff2a 100644 (file)
@@ -73,7 +73,6 @@
     <ClCompile Include="..\mono\utils\mono-hwcap.c" />\r
     <ClCompile Include="..\mono\utils\mono-hwcap-x86.c" />\r
     <ClCompile Include="..\mono\utils\bsearch.c" />\r
-    <ClInclude Include="..\mono\utils\json.c" />    \r
   </ItemGroup>\r
   <ItemGroup>\r
     <ClInclude Include="..\mono\utils\dlmalloc.h" />\r
     <ClInclude Include="..\mono\utils\mono-hwcap.h" />\r
     <ClInclude Include="..\mono\utils\mono-hwcap-x86.h" />\r
     <ClInclude Include="..\mono\utils\bsearch.h" />\r
-    <ClInclude Include="..\mono\utils\json.h" />\r
   </ItemGroup>\r
   <ItemGroup>\r
     <MASM Include="..\mono\utils\win64.asm">\r