- BugFix: *__remove_iterator(): after _next(), the iterator already points to the...
[libfirm] / ir / ir / irargs.c
index 2e8af24..66bbd7f 100644 (file)
@@ -1,24 +1,39 @@
 /*
- * Project:     libFIRM
- * File name:   ir/ir/irargs.c
- * Purpose:     Support for libcore IR object output.
- * Author:      Sebastian Hack
- * Modified by:
- * Created:
- * CVS-ID:      $Id$
- * Copyright:   (c) 1998-2005 Universitaet Karlsruhe
- * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
+ * Copyright (C) 1995-2008 University of Karlsruhe.  All right reserved.
+ *
+ * This file is part of libFirm.
+ *
+ * This file may be distributed and/or modified under the terms of the
+ * GNU General Public License version 2 as published by the Free Software
+ * Foundation and appearing in the file LICENSE.GPL included in the
+ * packaging of this file.
+ *
+ * Licensees holding valid libFirm Professional Edition licenses may use
+ * this file in accordance with the libFirm Commercial License.
+ * Agreement provided with the Software.
+ *
+ * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
+ * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE.
  */
 
+/**
+ * @file
+ * @brief    Support for libcore IR object output.
+ * @author   Sebastian Hack
+ * @version  $Id$
+ */
 #ifdef HAVE_CONFIG_H
 # include "config.h"
 #endif
 
+#include "firm_config.h"
+
 #include "bitset.h"
 
 #include <ctype.h>
-#include <libcore/lc_printf.h>
 
+#include "lc_printf.h"
 #include "firm_common.h"
 #include "irnode_t.h"
 #include "entity_t.h"
 /**
  * identify a firm object type
  */
-static int firm_get_lc_arg_type(const lc_arg_occ_t *occ) {
+static int firm_get_arg_type(const lc_arg_occ_t *occ) {
+  (void) occ;
   /* Firm objects are always pointer */
   return lc_arg_type_ptr;
 }
 
-static int firm_get_lc_arg_type_int(const lc_arg_occ_t *occ) {
+static int firm_get_arg_type_int(const lc_arg_occ_t *occ) {
+  (void) occ;
   return lc_arg_type_int;
 }
 
 
-static int bitset_get_lc_arg_type(const lc_arg_occ_t *occ) {
+static int bitset_get_arg_type(const lc_arg_occ_t *occ) {
+  (void) occ;
   return lc_arg_type_ptr;
 }
 
@@ -53,7 +71,7 @@ static int bitset_emit(lc_appendable_t *app,
   const char *prefix = "";
 
   lc_arg_append(app, occ, "[", 1);
-  for(p = bitset_next_set(b, 0); p != -1; p = bitset_next_set(b, p)) {
+  bitset_foreach(b, p) {
     int n;
 
     n = snprintf(buf, sizeof(buf), "%s%d", prefix, (int) p);
@@ -84,6 +102,15 @@ static int firm_emit_dbg(lc_appendable_t *app,
   return lc_arg_append(app, occ, buf, strlen(buf));
 }
 
+/**
+ * Beware: do not set the entity ld_name
+ */
+static const char *get_entity_ld_name_ex(ir_entity *ent) {
+  if (ent->ld_name)
+    return get_entity_ld_name(ent);
+  return get_entity_name(ent);
+}
+
 /**
  * emit a Firm object
  */
@@ -98,7 +125,8 @@ static int firm_emit(lc_appendable_t *app,
   ir_node *block;
   char add[64];
   char buf[256];
-  char tv[256];
+  char tv_buf[256];
+  ir_entity *ent;
 
   buf[0] = '\0';
   add[0] = '\0';
@@ -113,7 +141,7 @@ static int firm_emit(lc_appendable_t *app,
       break;
     case k_entity:
       snprintf(buf, sizeof(buf), "%s%s", A("ent"),
-          isupper(occ->conversion) ? get_entity_ld_name(X): get_entity_name(X));
+          isupper(occ->conversion) ? get_entity_ld_name_ex(X): get_entity_name(X));
       snprintf(add, sizeof(add), "[%ld]", get_entity_nr(X));
       break;
     case k_type:
@@ -121,7 +149,10 @@ static int firm_emit(lc_appendable_t *app,
       snprintf(add, sizeof(add), "[%ld]", get_type_nr(X));
       break;
     case k_ir_graph:
-      snprintf(buf, sizeof(buf), "%s%s", A("irg"), get_entity_name(get_irg_entity(X)));
+      if (X == get_const_code_irg())
+        snprintf(buf, sizeof(buf), "%s<ConstCodeIrg>", A("irg"));
+      else
+        snprintf(buf, sizeof(buf), "%s%s", A("irg"), get_entity_name(get_irg_entity(X)));
       snprintf(add, sizeof(add), "[%ld]", get_irg_graph_nr(X));
       break;
     case k_ir_node:
@@ -137,47 +168,61 @@ static int firm_emit(lc_appendable_t *app,
         break;
       default:
         if (is_Const(X)) {
-          tarval_snprintf(tv, sizeof(tv), get_Const_tarval(X));
+          tarval *tv = get_Const_tarval(X);
+          if (tv)
+            tarval_snprintf(tv_buf, sizeof(tv_buf), tv);
+          else
+            strncpy(tv_buf, "(NULL)", sizeof(tv_buf));
           snprintf(buf, sizeof(buf), "%s%s%s<%s>", A("irn"), get_irn_opname(X),
-            get_mode_name(get_irn_mode(X)), tv);
+            get_mode_name(get_irn_mode(X)), tv_buf);
         }
         else
           snprintf(buf, sizeof(buf), "%s%s%s", A("irn"), get_irn_opname(X),
             get_mode_name(get_irn_mode(X)));
-        snprintf(add, sizeof(add), "[%ld]", get_irn_node_nr(X));
+        snprintf(add, sizeof(add), "[%ld:%d]", get_irn_node_nr(X), get_irn_idx(X));
       }
       break;
     case k_ir_mode:
       snprintf(buf, sizeof(buf), "%s%s", A("mode"), get_mode_name(X));
       break;
     case k_tarval:
-      tarval_snprintf(tv, sizeof(tv), X);
-      snprintf(buf, sizeof(buf), "%s%s", A("tv"), tv);
+      tarval_snprintf(tv_buf, sizeof(tv_buf), X);
+      snprintf(buf, sizeof(buf), "%s%s", A("tv"), tv_buf);
       break;
     case k_ir_loop:
-      snprintf(buf, sizeof(buf), "ldepth[%d]", get_loop_depth(X));
+      snprintf(buf, sizeof(buf), "loop[%d:%d]", get_loop_loop_nr(X), get_loop_depth(X));
       break;
     case k_ir_op:
       snprintf(buf, sizeof(buf), "%s%s", A("op"), get_op_name(X));
       break;
     case k_ir_compound_graph_path:
-      strncat(buf, A("cgp"), sizeof(buf));
-
       n = get_compound_graph_path_length(X);
+
       for (i = 0; i < n; ++i) {
-        entity *ent = get_compound_graph_path_node(X, i);
+        ent = get_compound_graph_path_node(X, i);
+
+        strncat(buf, ".", sizeof(buf));
         strncat(buf, get_entity_name(ent), sizeof(buf));
-        if (i < n - 1)
-          strncat(buf, ".", sizeof(buf));
+        if (is_Array_type(get_entity_owner(ent))) {
+          snprintf(add, sizeof(add), "[%d]",
+            get_compound_graph_path_array_index(X, i));
+          strncat(buf, add, sizeof(buf));
+        }
       }
+      add[0] = '\0';
+      break;
+    case k_ir_extblk:
+      snprintf(buf, sizeof(buf), "ExtBlock");
+      snprintf(add, sizeof(add), "[%ld]", get_irn_node_nr(get_extbb_leader(X)));
       break;
+
     default:
       snprintf(buf, sizeof(buf), "UNKWN");
       snprintf(add, sizeof(add), "[%p]", X);
     }
   }
 
-  if(occ->flag_plus)
+  if (occ->flag_plus)
        strncat(buf, add, sizeof(buf));
 
   return lc_arg_append(app, occ, buf, strlen(buf));
@@ -204,10 +249,11 @@ static int firm_emit_indent(lc_appendable_t *app,
     const lc_arg_occ_t *occ, const lc_arg_value_t *arg)
 {
        int i;
-       int amount = arg->v_int;
+       int width  = occ->width > 0 ? occ->width : 1;
+       int amount = arg->v_int * width;
 
        for(i = 0; i < amount; ++i)
-               lc_appendable_chadd(app, ' ');
+               lc_appendable_chadd(app, (i % width) == 0 ? '|' : ' ');
 
        return amount;
 }
@@ -224,23 +270,23 @@ static int firm_emit_pnc(lc_appendable_t *app,
   return lc_arg_append(app, occ, p, strlen(p));
 }
 
-lc_arg_env_t *firm_get_lc_arg_env(void)
+lc_arg_env_t *firm_get_arg_env(void)
 {
-#define X(name, letter) {"firm:" name, letter}
 
   static lc_arg_env_t *env = NULL;
 
-  static lc_arg_handler_t firm_handler   = { firm_get_lc_arg_type, firm_emit };
-  static lc_arg_handler_t ident_handler  = { firm_get_lc_arg_type, firm_emit_ident };
-  static lc_arg_handler_t indent_handler = { firm_get_lc_arg_type_int, firm_emit_indent };
-  static lc_arg_handler_t pnc_handler    = { firm_get_lc_arg_type_int, firm_emit_pnc };
-  static lc_arg_handler_t bitset_handler = { bitset_get_lc_arg_type, bitset_emit };
-  static lc_arg_handler_t debug_handler  = { firm_get_lc_arg_type, firm_emit_dbg };
+  static lc_arg_handler_t firm_handler   = { firm_get_arg_type, firm_emit };
+  static lc_arg_handler_t ident_handler  = { firm_get_arg_type, firm_emit_ident };
+  static lc_arg_handler_t indent_handler = { firm_get_arg_type_int, firm_emit_indent };
+  static lc_arg_handler_t pnc_handler    = { firm_get_arg_type_int, firm_emit_pnc };
+  static lc_arg_handler_t bitset_handler = { bitset_get_arg_type, bitset_emit };
+  static lc_arg_handler_t debug_handler  = { firm_get_arg_type, firm_emit_dbg };
 
   static struct {
     const char *name;
     char letter;
   } args[] = {
+#define X(name, letter) {"firm:" name, letter}
     X("type",      't'),
     X("entity",    'e'),
     X("entity_ld", 'E'),
@@ -250,10 +296,11 @@ lc_arg_env_t *firm_get_lc_arg_env(void)
     X("irn_nr",    'N'),
     X("mode",      'm'),
     X("block",     'B'),
-    X("pnc",       '='),
+    X("cg_path",   'P'),
+#undef X
   };
 
-  int i;
+  size_t i;
 
   if(env == NULL) {
     env = lc_arg_new_env();
@@ -263,11 +310,11 @@ lc_arg_env_t *firm_get_lc_arg_env(void)
     for (i = 0; i < sizeof(args)/sizeof(args[0]); ++i)
       lc_arg_register(env, args[i].name, args[i].letter, &firm_handler);
 
-    lc_arg_register(env, "firm:ident", 'I', &ident_handler);
-    lc_arg_register(env, "firm:indent", 'D', &indent_handler);
+    lc_arg_register(env, "firm:ident",    'I', &ident_handler);
+    lc_arg_register(env, "firm:indent",   'D', &indent_handler);
+    lc_arg_register(env, "firm:dbg_info", 'G', &debug_handler);
+    lc_arg_register(env, "firm:bitset",   'B', &bitset_handler);
     lc_arg_register(env, "firm:pnc",      '=', &pnc_handler);
-    lc_arg_register(env, "firm:dbg_info", 'g', &debug_handler);
-    /* lc_arg_register(env, "firm:bitset", 'b', &bitset_handler); */
   }
 
   return env;