Ignore generated files.
[libfirm] / ir / ir / irdump.c
index 97b934b..5b9577c 100644 (file)
@@ -29,8 +29,6 @@
 #include <stdlib.h>
 #include <stdarg.h>
 
-#include "firm_common_t.h"
-
 #include "list.h"
 
 #include "irnode_t.h"
@@ -40,6 +38,7 @@
 #include "irop.h"
 
 #include "irdump_t.h"
+#include "irpass_t.h"
 
 #include "irgwalk.h"
 #include "tv_t.h"
@@ -260,17 +259,6 @@ const char *get_mode_name_ex(const ir_mode *mode, int *bad) {
        return ERROR_TXT;
 }
 
-/**
- * returns the name of a type or <ERROR> if mode is NOT a mode object.
- * in the later case, sets bad
- */
-const char *get_type_name_ex(const ir_type *tp, int *bad) {
-       if (is_type(tp))
-               return get_type_name(tp);
-       *bad |= 1;
-       return ERROR_TXT;
-}
-
 #define CUSTOM_COLOR_BASE    100
 static const char *color_names[ird_color_count];
 static const char *color_rgb[ird_color_count];
@@ -330,6 +318,19 @@ static void print_vcg_color(FILE *F, ird_color_t color) {
        fprintf(F, "color:%s", color_names[color]);
 }
 
+/**
+ * Prints the edge kind of a given IR node.
+ *
+ * Projs should be dumped near their predecessor, so they get "nearedge".
+ */
+static void print_node_edge_kind(FILE *F, ir_node *node) {
+       if (is_Proj(node)) {
+               fprintf(F, "nearedge: ");
+       } else {
+               fprintf(F, "edge: ");
+       }
+}
+
 /**
  * Prints the edge from a type S to a type T with additional info fmt, ...
  * to the file F.
@@ -748,19 +749,16 @@ int dump_node_opcode(FILE *F, ir_node *n)
                        fprintf(F, "SymC %s offset", get_entity_name(get_SymConst_entity(n)));
                        break;
                case symconst_type_tag:
-                       fprintf(F, "SymC %s tag", get_type_name_ex(get_SymConst_type(n), &bad));
+                       ir_fprintf(F, "SymC %+F tag", get_SymConst_type(n));
                        break;
                case symconst_type_size:
-                       fprintf(F, "SymC %s size", get_type_name_ex(get_SymConst_type(n), &bad));
+                       ir_fprintf(F, "SymC %+F size", get_SymConst_type(n));
                        break;
                case symconst_type_align:
-                       fprintf(F, "SymC %s align", get_type_name_ex(get_SymConst_type(n), &bad));
+                       ir_fprintf(F, "SymC %+F align", get_SymConst_type(n));
                        break;
                case symconst_enum_const:
-                       fprintf(F, "SymC %s enum", get_enumeration_name(get_SymConst_enum(n)));
-                       break;
-               case symconst_label:
-                       fprintf(F, "SymC %lu label", get_SymConst_label(n));
+                       fprintf(F, "SymC %s enum", get_enumeration_const_name(get_SymConst_enum(n)));
                        break;
                }
                break;
@@ -894,10 +892,11 @@ static int dump_node_typeinfo(FILE *F, ir_node *n) {
                if (get_irg_typeinfo_state(current_ir_graph) == ir_typeinfo_consistent  ||
                        get_irg_typeinfo_state(current_ir_graph) == ir_typeinfo_inconsistent) {
                        ir_type *tp = get_irn_typeinfo_type(n);
-                       if (tp != firm_none_type)
-                               fprintf(F, "[%s] ", get_type_name_ex(tp, &bad));
-                       else
+                       if (tp != firm_none_type) {
+                               ir_fprintf(F, "[%+F]", tp);
+                       } else {
                                fprintf(F, "[] ");
+                       }
                }
        }
        return bad;
@@ -937,11 +936,10 @@ static const pns_lookup_t cond_lut[] = {
 /** the lookup table for Proj(Call) names */
 static const pns_lookup_t call_lut[] = {
 #define X(a)    { pn_Call_##a, #a }
-       X(M_regular),
+       X(M),
        X(X_regular),
        X(X_except),
        X(T_result),
-       X(M_except),
        X(P_value_res_base)
 #undef X
 };
@@ -1022,7 +1020,6 @@ static const pns_lookup_t copyb_lut[] = {
        X(M),
        X(X_regular),
        X(X_except),
-       X(M_except)
 #undef X
 };
 
@@ -1033,7 +1030,6 @@ static const pns_lookup_t instof_lut[] = {
        X(X_regular),
        X(X_except),
        X(res),
-       X(M_except),
 #undef X
 };
 
@@ -1152,13 +1148,13 @@ handle_lut:
                fprintf(F, "%s ", get_ent_dump_name(get_Sel_entity(n)));
                break;
        case iro_Cast:
-               fprintf(F, "(%s) ", get_type_name_ex(get_Cast_type(n), &bad));
+               ir_fprintf(F, "(%+F)", get_Cast_type(n));
                break;
        case iro_Confirm:
                fprintf(F, "%s ", get_pnc_string(get_Confirm_cmp(n)));
                break;
        case iro_CopyB:
-               fprintf(F, "(%s) ", get_type_name_ex(get_CopyB_type(n), &bad));
+               ir_fprintf(F, "(%+F)", get_CopyB_type(n));
                break;
 
        default:
@@ -1191,6 +1187,7 @@ int dump_node_label(FILE *F, ir_node *n) {
        int bad = 0;
 
        bad |= dump_node_opcode(F, n);
+       fputs(" ", F);
        bad |= dump_node_mode(F, n);
        fprintf(F, " ");
        bad |= dump_node_typeinfo(F, n);
@@ -1204,6 +1201,29 @@ int dump_node_label(FILE *F, ir_node *n) {
        return bad;
 }
 
+/* Dumps the vrp information of a node to a file */
+int dump_vrp_info(FILE *F, ir_node *n) {
+       if (!n->vrp.valid) {
+               return 1;
+       }
+
+       fprintf(F, "range_type: %d\n", n->vrp.range_type);
+       if (n->vrp.range_type == VRP_RANGE || n->vrp.range_type ==
+                       VRP_ANTIRANGE) {
+               ir_fprintf(F, "range_bottom: %F\n",n->vrp.range_bottom);
+               ir_fprintf(F, "range_top: %F\n", n->vrp.range_top);
+       }
+       ir_fprintf(F, "bits_set: %T\n", n->vrp.bits_set);
+       ir_fprintf(F, "bits_not_set: %T\n", n->vrp.bits_not_set);
+       if (n->vrp.bits_node == NULL) {
+               fprintf(F, "bits_node: None");
+       } else {
+               fprintf(F, "bits_node: #%ld\n", get_irn_node_nr(n->vrp.bits_node));
+       }
+
+       return 0;
+}
+
 /**
  * Dumps the attributes of a node n into the file F.
  * Currently this is only the color of a node.
@@ -1423,13 +1443,19 @@ static void print_dbg_info(FILE *F, dbg_info *dbg)
 {
        char buf[1024];
 
-       if (__dbg_info_snprint) {
-               buf[0] = '\0';
-               if (__dbg_info_snprint(buf, sizeof(buf), dbg) > 0)
-                       fprintf(F, " info3: \"%s\"\n", buf);
+       ir_dbg_info_snprint(buf, sizeof(buf), dbg);
+       if (buf[0] != 0) {
+               fprintf(F, " info3: \"%s\"\n", buf);
        }
 }
 
+static void print_type_dbg_info(FILE *F, type_dbg_info *dbg)
+{
+       (void) F;
+       (void) dbg;
+       /* TODO */
+}
+
 /**
  * Dump a node
  */
@@ -1581,7 +1607,8 @@ static void dump_ir_data_edges(FILE *F, ir_node *n)  {
                ir_node *dep = get_irn_dep(n, i);
 
                if (dep) {
-                       fprintf(F, "edge: {sourcename: \"");
+                       print_node_edge_kind(F, n);
+                       fprintf(F, "{sourcename: \"");
                        PRINT_NODEID(n);
                        fprintf(F, "\" targetname: ");
                        if ((get_opt_dump_const_local()) && is_constlike_node(dep)) {
@@ -1606,8 +1633,10 @@ static void dump_ir_data_edges(FILE *F, ir_node *n)  {
 
                if (dump_backedge_information_flag && is_backedge(n, i))
                        fprintf(F, "backedge: {sourcename: \"");
-               else
-                       fprintf(F, "edge: {sourcename: \"");
+               else {
+                       print_node_edge_kind(F, n);
+                       fprintf(F, "{sourcename: \"");
+               }
                PRINT_NODEID(n);
                fprintf(F, "\" targetname: ");
                if ((get_opt_dump_const_local()) && is_constlike_node(pred)) {
@@ -1642,7 +1671,8 @@ dump_ir_edges(FILE *F, ir_node *n) {
        foreach_out_edge(n, edge) {
                ir_node *succ = get_edge_src_irn(edge);
 
-               fprintf(F, "edge: {sourcename: \"");
+               print_node_edge_kind(F, succ);
+               fprintf(F, "{sourcename: \"");
                PRINT_NODEID(n);
                fprintf(F, "\" targetname: \"");
                PRINT_NODEID(succ);
@@ -1940,10 +1970,7 @@ static void print_typespecific_info(FILE *F, ir_type *tp) {
 static void print_typespecific_vcgattr(FILE *F, ir_type *tp) {
        switch (get_type_tpop_code(tp)) {
        case tpo_class:
-               if (peculiarity_existent == get_class_peculiarity(tp))
-                       fprintf(F, " " TYPE_CLASS_NODE_ATTR);
-               else
-                       fprintf(F, " " TYPE_DESCRIPTION_NODE_ATTR);
+               fprintf(F, " " TYPE_CLASS_NODE_ATTR);
                break;
        case tpo_struct:
                fprintf(F, " " TYPE_METH_NODE_ATTR);
@@ -1965,23 +1992,16 @@ static void print_typespecific_vcgattr(FILE *F, ir_type *tp) {
        } /* switch type */
 }
 
-
 int dump_type_node(FILE *F, ir_type *tp)
 {
        int bad = 0;
 
        fprintf(F, "node: {title: ");
        PRINT_TYPEID(tp);
-       fprintf(F, " label: \"%s %s\"", get_type_tpop_name(tp), get_type_name_ex(tp, &bad));
-       fprintf(F, " info1: \"");
-#if 0
-       bad |= print_type_info(F, tp);
-       print_typespecific_info(F, tp);
-#else
+       ir_fprintf(F, " label: \"%s %+F\" info1: \"", get_type_tpop_name(tp), tp);
        dump_type_to_file(F, tp, dump_verbosity_max);
-#endif
        fprintf(F, "\"\n");
-       print_dbg_info(F, get_type_dbg_info(tp));
+       print_type_dbg_info(F, get_type_dbg_info(tp));
        print_typespecific_vcgattr(F, tp);
        fprintf(F, "}\n");
 
@@ -2011,7 +2031,7 @@ static void dump_enum_item(FILE *F, ir_type *tp, int pos)
 {
        char buf[1024];
        ir_enum_const *ec = get_enumeration_const(tp, pos);
-       ident         *id = get_enumeration_nameid(ec);
+       ident         *id = get_enumeration_const_nameid(ec);
        tarval        *tv = get_enumeration_value(ec);
 
        if (tv)
@@ -2030,7 +2050,9 @@ static void dump_enum_item(FILE *F, ir_type *tp, int pos)
  * Dumps a new style initializer.
  */
 static void dump_entity_initializer(FILE *F, const ir_entity *ent) {
-
+       /* TODO */
+       (void) F;
+       (void) ent;
 }
 
 /** Dumps a type or entity and it's edges. */
@@ -2056,33 +2078,23 @@ static void dump_type_info(type_or_ent tore, void *env) {
                                print_ent_ent_edge(F,ent, get_entity_overwrites(ent, i), 0, -1, ENT_OVERWRITES_EDGE_ATTR);
                }
                /* attached subgraphs */
-               if (const_entities && (get_entity_variability(ent) != variability_uninitialized)) {
-                       if (is_atomic_entity(ent)) {
-                               value = get_atomic_ent_value(ent);
-                               if (value) {
-                                       print_ent_node_edge(F, ent, value, ENT_VALUE_EDGE_ATTR, i);
-                                       /* DDMN(value);  $$$ */
-                                       dump_const_expression(F, value);
-                               }
-                       }
-                       if (is_compound_entity(ent)) {
-                               if (has_entity_initializer(ent)) {
-                                       /* new style initializers */
-                                       dump_entity_initializer(F, ent);
-                               } else {
-                                       /* old style compound entity values */
-                                       for (i = get_compound_ent_n_values(ent) - 1; i >= 0; --i) {
-                                               value = get_compound_ent_value(ent, i);
-                                               if (value) {
-                                                       print_ent_node_edge(F, ent, value, ENT_VALUE_EDGE_ATTR, i);
-                                                       dump_const_expression(F, value);
-                                                       print_ent_ent_edge(F, ent, get_compound_ent_value_member(ent, i), 0, -1, ENT_CORR_EDGE_ATTR, i);
-                                                       /*
-                                                       fprintf(F, "edge: { sourcename: \"%p\" targetname: \"%p\" "
-                                                       ENT_CORR_EDGE_ATTR  "}\n", GET_ENTID(ent),
-                                                       get_compound_ent_value_member(ent, i), i);
-                                                       */
-                                               }
+               if (const_entities) {
+                       if (ent->initializer != NULL) {
+                               /* new style initializers */
+                               dump_entity_initializer(F, ent);
+                       } else if (entity_has_compound_ent_values(ent)) {
+                               /* old style compound entity values */
+                               for (i = get_compound_ent_n_values(ent) - 1; i >= 0; --i) {
+                                       value = get_compound_ent_value(ent, i);
+                                       if (value) {
+                                               print_ent_node_edge(F, ent, value, ENT_VALUE_EDGE_ATTR, i);
+                                               dump_const_expression(F, value);
+                                               print_ent_ent_edge(F, ent, get_compound_ent_value_member(ent, i), 0, -1, ENT_CORR_EDGE_ATTR, i);
+                                               /*
+                                               fprintf(F, "edge: { sourcename: \"%p\" targetname: \"%p\" "
+                                               ENT_CORR_EDGE_ATTR  "}\n", GET_ENTID(ent),
+                                               get_compound_ent_value_member(ent, i), i);
+                                               */
                                        }
                                }
                        }
@@ -2212,7 +2224,8 @@ dump_out_edge(ir_node *n, void *env) {
        for (i = get_irn_n_outs(n) - 1; i >= 0; --i) {
                ir_node *succ = get_irn_out(n, i);
                assert(succ);
-               fprintf(F, "edge: {sourcename: \"");
+               print_node_edge_kind(F, succ);
+               fprintf(F, "{sourcename: \"");
                PRINT_NODEID(n);
                fprintf(F, "\" targetname: \"");
                PRINT_NODEID(succ);
@@ -2366,7 +2379,7 @@ void dump_vcg_header(FILE *F, const char *name, const char *layout, const char *
  * @param suffix1 first filename suffix
  * @param suffix2 second filename suffix
  */
-FILE *vcg_open(ir_graph *irg, const char *suffix1, const char *suffix2) {
+FILE *vcg_open(const ir_graph *irg, const char *suffix1, const char *suffix2) {
        FILE *F;
        const char *nm = get_irg_dump_name(irg);
        int len = strlen(nm), i, j;
@@ -2981,6 +2994,39 @@ void dump_all_ir_graphs(dump_graph_func *dmp_grph, const char *suffix) {
                dmp_grph(get_irp_irg(i), suffix);
 }
 
+struct pass_t {
+       ir_prog_pass_t  pass;
+       dump_graph_func *dump_graph;
+       char            suffix[1];
+};
+
+/**
+ * Wrapper around dump_all_ir_graphs().
+ */
+static int dump_all_ir_graphs_wrapper(ir_prog *irp, void *context) {
+       struct pass_t *pass = context;
+
+       (void)irp;
+       dump_all_ir_graphs(pass->dump_graph, pass->suffix);
+       return 0;
+}
+
+ir_prog_pass_t *dump_all_ir_graph_pass(
+       const char *name, dump_graph_func *dump_graph, const char *suffix) {
+       size_t         len   = strlen(suffix);
+       struct pass_t  *pass = xmalloc(sizeof(*pass) + len);
+       ir_prog_pass_t *res  = def_prog_pass_constructor(
+               &pass->pass, name ? name : "dump_all_graphs", dump_all_ir_graphs_wrapper);
+
+       /* this pass does not change anything, so neither dump nor verify is needed. */
+       res->dump_irprog   = ir_prog_no_dump;
+       res->verify_irprog = ir_prog_no_verify;
+
+       pass->dump_graph = dump_graph;
+       strcpy(pass->suffix, suffix);
+
+       return res;
+}
 
 /*--------------------------------------------------------------------------------*
  * Dumps a stand alone loop graph with firm nodes which belong to one loop node   *