- add ir_bk_outport and ir_bk_inport
[libfirm] / ir / ir / irdump_grgen.c
index b301f6b..2da860f 100644 (file)
@@ -21,7 +21,7 @@
 * @file
 * @brief   Write ir graph as a grgen construction rule
 * @author  Andreas Schoesser
-* @version $Id:$
+* @version $Id$
 */
 
 /*
@@ -42,6 +42,7 @@
 #include "tv.h"
 #include "irgwalk.h"
 #include "firm_types.h"
+#include "irdump_grgen.h"
 
 
 typedef struct
@@ -114,7 +115,7 @@ static int edge_counter;
 
 irg_grgen_dumper_env_t *init_irg_grgen_dumper(char *file, int append)
 {
-       irg_grgen_dumper_env_t *const grgen_dumper_env = xmalloc(sizeof(*grgen_dumper_env));
+       irg_grgen_dumper_env_t *const grgen_dumper_env = XMALLOC(irg_grgen_dumper_env_t);
        FILE *fp;
 
        if(append)
@@ -157,7 +158,7 @@ static void collect_nodes(ir_node *n, void * env)
  * Starts dumping
  ************************************************************************/
 
-void dump_irg_grgen(ir_graph *irg, char *filename, int append)
+void dump_irg_grgen_file(ir_graph *irg, char *filename, int append)
 {
        FILE *fp;
        grgen_dumpinfo_t dump_info;
@@ -212,6 +213,18 @@ void dump_irg_grgen(ir_graph *irg, char *filename, int append)
 }
 
 
+void dump_irg_grgen(ir_graph *irg, char *suffix)
+{
+  char filename[100] = "";
+
+  strncat(filename, get_entity_name(get_irg_entity(irg)), 100);
+  strncat(filename, suffix, 100);
+  strncat(filename, ".grg", 100);
+
+  dump_irg_grgen_file(irg, filename, 0);
+}
+
+
 /************************************************************************
  * Dumps the left hand side of the rule
  ************************************************************************/
@@ -241,7 +254,7 @@ static int dump_pattern(grgen_dumpinfo_t *dump_info, FILE *fp)
                int i;
 
                // Dump edges
-               for(i = -1; i < get_irn_arity(n); i++)
+               for(i = is_Block(n) ? 0 : -1; i < get_irn_arity(n); i++)
                        dump_grg_egde(n, i, dump_info, fp);
        }
 
@@ -378,7 +391,7 @@ static void dump_grgen_mode(ir_node *n, grgen_dumpinfo_t *dump_info, FILE *fp, i
 
 static char *dump_grgen_mode_node(ir_mode *irn_mode, grgen_dumpinfo_t *dump_info, FILE *fp)
 {
-       modecode mode_code = get_mode_modecode(irn_mode);
+       ir_modecode mode_code = get_mode_modecode(irn_mode);
        const char *mode_name =  get_mode_name(irn_mode);
        char *mode_node_name;
 
@@ -451,7 +464,7 @@ static void dump_grgen_eval(ir_node *n, grgen_dumpinfo_t *dump_info, FILE *fp)
 
                // Correlate the matched phi edges with the matched block edges
                // Caution: Position 0 in the edge_names array is the block edge, so start at 1
-               for(i = 0; i < get_irn_arity(n) + 1; i++)
+               for(i = code == iro_Block; i < get_irn_arity(n) + 1; i++)
                {
                        assert(edge_names[i] != NULL && "Some edges have not been dumped!");