Thu Sep 28 15:37:51 CEST 2006 Paolo Molaro <lupus@ximian.com>
authorPaolo Molaro <lupus@oddwiz.org>
Thu, 28 Sep 2006 13:41:24 +0000 (13:41 -0000)
committerPaolo Molaro <lupus@oddwiz.org>
Thu, 28 Sep 2006 13:41:24 +0000 (13:41 -0000)
* monoburg.c: the emit code for each rule is now run
from a single function, avoiding hundreds of relocations.
The C code present in .brg files is emitted at the start of
generated source file, allowing the use of static helper functions.

svn path=/trunk/mono/; revision=66030

mono/monoburg/ChangeLog
mono/monoburg/monoburg.c

index 5d67a5541b6160632e2b6802f52f7242d0ac3d5c..6cf486b2b78fa1deb3b11e99530e37fe9f52f4cb 100644 (file)
@@ -1,3 +1,11 @@
+
+Thu Sep 28 15:37:51 CEST 2006 Paolo Molaro <lupus@ximian.com>
+
+       * monoburg.c: the emit code for each rule is now run
+       from a single function, avoiding hundreds of relocations.
+       The C code present in .brg files is emitted at the start of
+       generated source file, allowing the use of static helper functions.
+
 2006-08-31  Zoltan Varga  <vargaz@freemail.hu>
 
        * monoburg.vcproj: Fix include paths for newer glib versions.
index 32c75012610b52ebc39f79b5b4c9522bd0afb961..6e8bcaceb0475e411436a6c8e0a3a16983a4114b 100644 (file)
@@ -703,48 +703,48 @@ static void
 emit_emitter_func ()
 {
        GList *l;
-       int i, rulen;
+       int i;
        GHashTable *cache = g_hash_table_new (g_str_hash, g_str_equal);
 
        for (l =  rule_list, i = 0; l; l = l->next) {
                Rule *rule = (Rule *)l->data;
                
                if (rule->code) {
-                       if ((rulen = GPOINTER_TO_INT (g_hash_table_lookup (cache, rule->code)))) {
-                               emit_rule_string (rule, "");
-                               output ("#define mono_burg_emit_%d mono_burg_emit_%d\n\n", i, rulen);
-                               i++;
-                               continue;
+                       GList *cases;
+                       if ((cases = g_hash_table_lookup (cache, rule->code))) {
+                               cases = g_list_append (cases, GINT_TO_POINTER (i));
+                       } else {
+                               cases = g_list_append (NULL, GINT_TO_POINTER (i));
                        }
-                       output ("static void ");
-
-                       emit_rule_string (rule, "");
-
-                       if (dag_mode)
-                               output ("mono_burg_emit_%d (MBState *state, MBTREE_TYPE *tree, MBCGEN_TYPE *s)\n", i);
-                       else
-                               output ("mono_burg_emit_%d (MBTREE_TYPE *tree, MBCGEN_TYPE *s)\n", i);
-                       output ("{\n");
-                       output ("%s\n", rule->code);
-                       output ("}\n\n");
-                       g_hash_table_insert (cache, rule->code, GINT_TO_POINTER (i));
+                       g_hash_table_insert (cache, rule->code, cases);
                }
                i++;
        }
 
-       g_hash_table_destroy (cache);
-
-       output ("MBEmitFunc const mono_burg_func [] = {\n");
-       output ("\tNULL,\n");
+       output ("void mono_burg_emit (int ern, MBState *state, MBTREE_TYPE *tree, MBCGEN_TYPE *s)\n {\n");
+       output ("\tswitch (ern) {");
        for (l =  rule_list, i = 0; l; l = l->next) {
                Rule *rule = (Rule *)l->data;
-               if (rule->code)
-                       output ("\tmono_burg_emit_%d,\n", i);
-               else
-                       output ("\tNULL,\n");
+
+               if (rule->code) {
+                       GList *cases, *tmp;
+                       cases = g_hash_table_lookup (cache, rule->code);
+                       if (cases && i != GPOINTER_TO_INT (cases->data)) {
+                               i++;
+                               continue;
+                       }
+                       emit_rule_string (rule, "");
+                       for (tmp = cases; tmp; tmp = tmp->next) {
+                               output ("\tcase %d:\n", GPOINTER_TO_INT (tmp->data) + 1);
+                       }
+                       output ("\t{\n");
+                       output ("%s\n", rule->code);
+                       output ("\t}\n\treturn;\n");
+               }
                i++;
        }
-       output ("};\n\n");
+       output ("\t}\n}\n\n");
+       g_hash_table_destroy (cache);
 }
 
 static void
@@ -840,6 +840,7 @@ emit_vardefs ()
        int *nts_offsets;
        int current_offset;
 
+       output ("\n");
        if (predefined_terms) {
                output ("#if HAVE_ARRAY_ELEM_INIT\n");
                output ("const guint8 mono_burg_arity [MBMAX_OPCODES] = {\n"); 
@@ -940,18 +941,13 @@ emit_vardefs ()
 static void
 emit_prototypes ()
 {
-       if (dag_mode)
-               output ("typedef void (*MBEmitFunc) (MBState *state, MBTREE_TYPE *tree, MBCGEN_TYPE *s);\n\n");
-       else
-               output ("typedef void (*MBEmitFunc) (MBTREE_TYPE *tree, MBCGEN_TYPE *s);\n\n");
-       
        output ("extern const char * const mono_burg_term_string [];\n");
        output ("#if MONOBURG_LOG\n");
        output ("extern const char * const mono_burg_rule_string [];\n");
        output ("#endif /* MONOBURG_LOG */\n");
        output ("extern const guint16 mono_burg_nts_data [];\n");
        output ("extern const guint8 mono_burg_nts [];\n");
-       output ("extern MBEmitFunc const mono_burg_func [];\n");
+       output ("extern void mono_burg_emit (int ern, MBState *state, MBTREE_TYPE *tree, MBCGEN_TYPE *s);\n\n");
 
        output ("MBState *mono_burg_label (MBTREE_TYPE *tree, MBCOST_DATA *data);\n");
        output ("int mono_burg_rule (MBState *state, int goal);\n");
@@ -1125,16 +1121,6 @@ main (int argc, char *argv [])
                output ("#include \"%s\"\n\n", deffile);
        }
        
-       emit_vardefs ();
-       emit_cost_func ();
-       emit_emitter_func ();
-       emit_decoders ();
-
-       emit_closure ();
-       emit_label_func ();
-
-       emit_kids ();
-
        if (infiles) {
                GList *l = infiles;
                while (l) {
@@ -1147,6 +1133,16 @@ main (int argc, char *argv [])
                yyparsetail ();
        }
 
+       emit_vardefs ();
+       emit_cost_func ();
+       emit_emitter_func ();
+       emit_decoders ();
+
+       emit_closure ();
+       emit_label_func ();
+
+       emit_kids ();
+
        if (cfile)
                fclose (cfd);