some fixes for xml dumper / still buggy.
[libfirm] / ir / ir / irdump.c
index 91f0de6..b769b8b 100644 (file)
 
 
 #if DEBUG_libfirm && NODEID_AS_LABEL
-#define PRINT_NODEID(X) fprintf(F, "\"n%ld\"", get_irn_node_nr(X))
+#define PRINT_NODEID(X) fprintf(F, "n%ld", get_irn_node_nr(X))
 #define PRINT_TYPEID(X) fprintf(F, "\"t%ld\"", get_type_nr(X))
-#define PRINT_ENTID(X)  fprintf(F, "\"e%ld\"", get_entity_nr(X))
+#define PRINT_ENTID(X)  fprintf(F, "e%ld", get_entity_nr(X))
 #define PRINT_IRGID(X)  fprintf(F, "g%ld", get_irg_graph_nr(X))
 #define PRINT_CONSTID(X,Y) fprintf(F, "\"n%ldn%ld\"", get_irn_node_nr(X),get_irn_node_nr(Y))
 
 #else
-#define PRINT_NODEID(X) fprintf(F, "\"n%p\"", (void*) X)
+#define PRINT_NODEID(X) fprintf(F, "n%p", (void*) X)
 #define PRINT_TYPEID(X) fprintf(F, "\"t%p\"", (void *) X)
-#define PRINT_ENTID(X) fprintf(F, "\"e%p\"", (void*) X)
-#define PRINT_IRGID(X) fprintf(F,"g%p",void(*)X)
+#define PRINT_ENTID(X)  fprintf(F, "e%p", (void*) X)
+#define PRINT_IRGID(X)  fprintf(F, "g%p",(void*) X)
 #define PRINT_CONSTID(X,Y) fprintf(F, "\"%p%p\"", (void*) X, (void*) Y)
 #endif
 
 #define PRINT_TYPE_TYPE_EDGE(S,T,...){fprintf (F, "edge: { sourcename: "); PRINT_TYPEID(S); fprintf (F, " targetname: "); PRINT_TYPEID(T); fprintf (F, ##__VA_ARGS__); fprintf(F,"}\n"); }
-#define PRINT_TYPE_ENT_EDGE(S,T,...) {fprintf (F, "edge: { sourcename: "); PRINT_TYPEID(S); fprintf (F, " targetname: "); PRINT_ENTID(T);  fprintf (F, ##__VA_ARGS__); fprintf(F,"}\n"); }
-#define PRINT_ENT_ENT_EDGE(S,T,...)  {fprintf (F, "edge: { sourcename: "); PRINT_ENTID(S);  fprintf (F, " targetname: "); PRINT_ENTID(T);  fprintf (F, ##__VA_ARGS__); fprintf(F,"}\n"); }
-#define PRINT_ENT_TYPE_EDGE(S,T,...) {fprintf (F, "edge: { sourcename: "); PRINT_ENTID(S);  fprintf (F, " targetname: "); PRINT_TYPEID(T); fprintf (F, ##__VA_ARGS__); fprintf(F,"}\n"); }
-#define PRINT_NODE_TYPE_EDGE(S,T,...){fprintf (F, "edge: { sourcename: "); PRINT_NODEID(S); fprintf (F, " targetname: "); PRINT_TYPEID(T); fprintf (F, ##__VA_ARGS__); fprintf(F,"}\n"); }
-#define PRINT_NODE_ENT_EDGE(S,T,...) {fprintf (F, "edge: { sourcename: "); PRINT_NODEID(S); fprintf (F, " targetname: "); PRINT_ENTID(T);  fprintf (F, ##__VA_ARGS__); fprintf(F,"}\n"); }
-#define PRINT_ENT_NODE_EDGE(S,T,...) {fprintf (F, "edge: { sourcename: "); PRINT_ENTID(S);  fprintf (F, " targetname: "); PRINT_NODEID(T); fprintf (F, ##__VA_ARGS__); fprintf(F,"}\n"); }
+#define PRINT_TYPE_ENT_EDGE(S,T,...) {fprintf (F, "edge: { sourcename: "); PRINT_TYPEID(S); fprintf (F, " targetname: \""); PRINT_ENTID(T); fprintf(F, "\"");  fprintf (F, ##__VA_ARGS__); fprintf(F,"}\n"); }
+#define PRINT_ENT_ENT_EDGE(S,T,...)  {fprintf (F, "edge: { sourcename: \""); PRINT_ENTID(S);  fprintf (F, "\" targetname: \""); PRINT_ENTID(T);  fprintf(F, "\""); fprintf (F, ##__VA_ARGS__); fprintf(F,"}\n"); }
+#define PRINT_ENT_TYPE_EDGE(S,T,...) {fprintf (F, "edge: { sourcename: \""); PRINT_ENTID(S);  fprintf (F, "\" targetname: "); PRINT_TYPEID(T); fprintf (F, ##__VA_ARGS__); fprintf(F,"}\n"); }
+#define PRINT_NODE_TYPE_EDGE(S,T,...){fprintf (F, "edge: { sourcename: \""); PRINT_NODEID(S); fprintf (F, "\" targetname: "); PRINT_TYPEID(T); fprintf (F, ##__VA_ARGS__); fprintf(F,"}\n"); }
+#define PRINT_NODE_ENT_EDGE(S,T,...) {fprintf (F, "edge: { sourcename: \""); PRINT_NODEID(S); fprintf (F, "\" targetname: \""); PRINT_ENTID(T);  fprintf(F, "\""); fprintf (F, ##__VA_ARGS__); fprintf(F,"}\n"); }
+#define PRINT_ENT_NODE_EDGE(S,T,...) {fprintf (F, "edge: { sourcename: \""); PRINT_ENTID(S);  fprintf (F, "\" targetname: \""); PRINT_NODEID(T); fprintf(F, "\""); fprintf (F, ##__VA_ARGS__); fprintf(F,"}\n"); }
 
 
 /* A suffix to manipulate the file name. */
@@ -257,6 +257,11 @@ dump_node_vcgattr (ir_node *n)
   }
 }
 
+static INLINE void
+dump_node_info (ir_node *n) {
+  fprintf (F, " info1: \"visited: %ld\n\"", get_irn_visited(n));
+}
+
 static bool pred_in_wrong_graph(ir_node *n, int pos, pmap *irgmap) {
   ir_node *block = (is_Block(n)) ? n : get_nodes_Block(n);
 
@@ -310,6 +315,7 @@ static void dump_const_node_local(ir_node *n, pmap *irgmap) {
 #endif
       fprintf (F, "\" ");
       dump_node_vcgattr(con);
+      dump_node_info(con);
       fprintf (F, "}\n");
     }
   }
@@ -320,7 +326,7 @@ dump_node (ir_node *n, pmap * map) {
   if (get_opt_dump_const_local() && is_constlike_node(n)) return;
 
   /* dump this node */
-  fprintf (F, "node: {title: "); PRINT_NODEID(n); fprintf(F, " label: \"");
+  fprintf (F, "node: {title: \""); PRINT_NODEID(n); fprintf(F, "\" label: \"");
 
   dump_node_opcode(n);
   dump_node_mode (n);
@@ -331,6 +337,7 @@ dump_node (ir_node *n, pmap * map) {
 #endif
   fprintf (F, "\" ");
   dump_node_vcgattr(n);
+  dump_node_info(n);
   fprintf (F, "}\n");
   dump_const_node_local(n, map);
 }
@@ -340,11 +347,11 @@ static void
 dump_ir_block_edge(ir_node *n)  {
   if (get_opt_dump_const_local() && is_constlike_node(n)) return;
   if (is_no_Block(n)) {
-    fprintf (F, "edge: { sourcename: ");
+    fprintf (F, "edge: { sourcename: \"");
     PRINT_NODEID(n);
-    fprintf (F, " targetname: ");
+    fprintf (F, "\" targetname: \"");
     PRINT_NODEID(get_nodes_Block(n));
-    fprintf (F, " "    BLOCK_EDGE_ATTR "}\n");
+    fprintf (F, "\" "  BLOCK_EDGE_ATTR "}\n");
   }
 }
 
@@ -451,16 +458,15 @@ dump_ir_data_edges(ir_node *n)  {
     if (is_backedge(n, i))
       fprintf (F, "backedge: {sourcename: ");
     else
-      fprintf (F, "edge: {sourcename: ");
+      fprintf (F, "edge: {sourcename: \"");
     PRINT_NODEID(n);
-    fprintf (F, " targetname: ");
+    fprintf (F, " \" targetname: ");
     if ((get_opt_dump_const_local()) && is_constlike_node(pred))
     {
       PRINT_CONSTID(n,pred);
     }
     else
-    {
-      PRINT_NODEID(pred);
+      {fprintf(F, "\""); PRINT_NODEID(pred); fprintf(F, "\"");
     }
     fprintf (F, " label: \"%d\" ", i);
     print_edge_vcgattr(n, i);
@@ -474,11 +480,11 @@ dump_out_edge (ir_node *n, void* env) {
   int i;
   for (i = 0; i < get_irn_n_outs(n); i++) {
     assert(get_irn_out(n, i));
-    fprintf (F, "edge: {sourcename: ");
+    fprintf (F, "edge: {sourcename: \"");
     PRINT_NODEID(n);
-    fprintf (F, " targetname: ");
+    fprintf (F, "\" targetname: \"");
     PRINT_NODEID(get_irn_out(n, i));
-    fprintf (F, " color: red linestyle: dashed");
+    fprintf (F, "\" color: red linestyle: dashed");
     fprintf (F, "}\n");
   }
 }
@@ -486,9 +492,9 @@ dump_out_edge (ir_node *n, void* env) {
 static INLINE void
 dump_loop_node_edge (ir_loop *loop, int i) {
   assert(loop);
-  fprintf (F, "edge: {sourcename: \"%p\" targetname: ", (void*) loop);
+  fprintf (F, "edge: {sourcename: \"%p\" targetname: \"", (void*) loop);
   PRINT_NODEID(get_loop_node(loop, i));
-  fprintf (F, " color: green");
+  fprintf (F, "\" color: green");
   fprintf (F, "}\n");
 }
 
@@ -555,6 +561,7 @@ static void dump_node2type_edges (ir_node *n, void *env)
 }
 
 
+/* @@@@ Does not work as someone kills the visited flag. */
 static void dump_const_expression(ir_node *value) {
   ir_graph *rem = current_ir_graph;
   int rem_dump_const_local = dump_const_local;
@@ -629,12 +636,13 @@ static void print_type_node(type *tp) {
 }
 
 void dump_entity_node(entity *ent) {
-  fprintf (F, "node: {title: ");
-  PRINT_ENTID(ent);
+  fprintf (F, "node: {title: \"");
+  PRINT_ENTID(ent); fprintf(F, "\"");
   fprintf (F, DEFAULT_TYPE_ATTRIBUTE);
   fprintf (F, "label: ");
   fprintf (F, "\"ent %s\" " ENTITY_NODE_ATTR , id_to_str(get_entity_ident(ent)));
-  fprintf (F, "\n info1:\"\nallocation:  ");
+  fprintf (F, "\n info1: \"\nid: "); PRINT_ENTID(ent);
+  fprintf (F, "\nallocation:  ");
   switch (get_entity_allocation(ent)) {
     case dynamic_allocated:   fprintf (F, "dynamic allocated");   break;
     case automatic_allocated: fprintf (F, "automatic allocated"); break;
@@ -644,8 +652,8 @@ void dump_entity_node(entity *ent) {
   fprintf (F, "\nvisibility:  ");
   switch (get_entity_visibility(ent)) {
     case local:              fprintf (F, "local");             break;
-    case external_visible:   fprintf (F, "external_visible");  break;
-    case external_allocated: fprintf (F, "external_allocate"); break;
+    case external_visible:   fprintf (F, "external visible");  break;
+    case external_allocated: fprintf (F, "external allocated"); break;
   }
   fprintf (F, "\nvariability: ");
   switch (get_entity_variability(ent)) {
@@ -665,7 +673,9 @@ void dump_entity_node(entity *ent) {
     case inherited:   fprintf (F, "inherited");   break;
     case existent:    fprintf (F, "existent");    break;
   }
-  fprintf(F, "\nname:    %s\nld_name: %s", id_to_str(get_entity_ident(ent)), id_to_str(get_entity_ld_ident(ent)));
+  fprintf(F, "\nname:    %s\nld_name: %s",
+         id_to_str(get_entity_ident(ent)),
+         id_to_str(get_entity_ld_ident(ent)));
   fprintf(F, "\noffset:  %d", get_entity_offset(ent));
   if (is_method_type(get_entity_type(ent))) {
     if (get_entity_irg(ent))   /* can be null */
@@ -706,11 +716,7 @@ dump_type_info (type_or_ent *tore, void *env) {
          value = get_atomic_ent_value(ent);
          if (value) {
             PRINT_ENT_NODE_EDGE(ent, value, ENT_VALUE_EDGE_ATTR, i);
-           /*
-           fprintf (F, "edge: { sourcename: \"%p\" targetname: ", GET_ENTID(ent));
-           PRINT_NODEID(value);
-           fprintf(F, " " ENT_VALUE_EDGE_ATTR "\"}\n");
-           */
+           /* DDMN(value);  $$$ */
            dump_const_expression(value);
          }
        }
@@ -1025,9 +1031,9 @@ dump_ir_block (ir_node *block, void *env) {
   if (get_irn_opcode(block) == iro_Block) {
 
     /* This is a block. So dump the vcg information to make a block. */
-    fprintf(F, "graph: { title: ");
+    fprintf(F, "graph: { title: \"");
        PRINT_NODEID(block);
-       fprintf(F, "  label: \"");
+       fprintf(F, "\" label: \"");
 #ifdef DEBUG_libfirm
     fprintf (F, "%ld", get_irn_node_nr(block));
 #else
@@ -1111,8 +1117,8 @@ dump_block_to_cfg (ir_node *block, void *env) {
 
   if (get_irn_opcode(block) == iro_Block) {
     /* This is a block. Dump a node for the block. */
-    fprintf (F, "node: {title:"); PRINT_NODEID(block);
-    fprintf (F, " label: \"%s ", get_op_name(get_irn_op(block)));
+    fprintf (F, "node: {title: \""); PRINT_NODEID(block);
+    fprintf (F, "\" label: \"%s ", get_op_name(get_irn_op(block)));
 #ifdef DEBUG_libfirm
     fprintf (F, "%ld", get_irn_node_nr(block));
 #else
@@ -1130,21 +1136,21 @@ dump_block_to_cfg (ir_node *block, void *env) {
     for ( i = 0; i < get_Block_n_cfgpreds(block); i++)
       if (get_irn_op(skip_Proj(get_Block_cfgpred(block, i))) != op_Bad) {
        pred = get_nodes_Block(skip_Proj(get_Block_cfgpred(block, i)));
-       fprintf (F, "edge: { sourcename: ");
+       fprintf (F, "edge: { sourcename: \"");
        PRINT_NODEID(block);
-       fprintf (F, " targetname: ");
+       fprintf (F, "\" targetname: \"");
        PRINT_NODEID(pred);
-       fprintf (F, " }\n");
+       fprintf (F, "\"}\n");
       }
 
     /* Dump dominator edge */
     if (dump_dominator_information_flag && get_Block_idom(block)) {
       pred = get_Block_idom(block);
-      fprintf (F, "edge: { sourcename: ");
+      fprintf (F, "edge: { sourcename: \"");
       PRINT_NODEID(block);
-      fprintf (F, " targetname: ");
+      fprintf (F, "\" targetname: \"");
       PRINT_NODEID(pred);
-      fprintf (F, " " DOMINATOR_EDGE_ATTR "}\n");
+      fprintf (F, "\" " DOMINATOR_EDGE_ATTR "}\n");
     }
   }
 }
@@ -1329,6 +1335,7 @@ static void clear_link(ir_node * node, void * env) {
 }
 
 static void collect_blocks_floats_cg(ir_node * node, pmap * map) {
+  assert(node); assert(map);
   if (is_Block(node)
       || node_floats(node)
       || get_irn_op(node) == op_Bad
@@ -1338,9 +1345,11 @@ static void collect_blocks_floats_cg(ir_node * node, pmap * map) {
     {
       ir_node ** arr;
       arr = entry->value;
+      assert(arr);
       ARR_APP1(ir_node *, arr , node);
     } else {
       ir_node ** arr = NEW_ARR_F(ir_node *, 1);
+      assert(arr);
       arr[0] = node;
       pmap_insert(map, current_ir_graph, arr);
     }
@@ -1356,9 +1365,9 @@ static void dump_cg_ir_block(ir_node * block, void * env) {
   ir_node *node;
   pmap *irgmap = (pmap *)env;
   assert(is_Block(block));
-  fprintf(F, "graph: { title: ");
+  fprintf(F, "graph: { title: \"");
   PRINT_NODEID(block);
-  fprintf(F, "  label: \"");
+  fprintf(F, "\"  label: \"");
   fprintf (F, "%s ", get_op_name(get_irn_op(block)));
 #ifdef DEBUG_libfirm
   fprintf (F, "%ld", get_irn_node_nr(block));