Fixed optimization of Div/Mod/DivMod nodes
[libfirm] / ir / ir / irargs.c
index 9ca33e7..48782f4 100644 (file)
@@ -6,7 +6,7 @@
  * Modified by:
  * Created:
  * CVS-ID:      $Id$
- * Copyright:   (c) 1998-2005 Universitรคt Karlsruhe
+ * Copyright:   (c) 1998-2005 Universitaet Karlsruhe
  * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
  */
 
 # include "config.h"
 #endif
 
+#include "bitset.h"
+
 #include <ctype.h>
 #include <libcore/xprintf.h>
 
 #include "firm_common.h"
-#include "irnode.h"
-#include "entity.h"
-#include "irloop.h"
-#include "tv.h"
+#include "irnode_t.h"
+#include "entity_t.h"
+#include "irloop_t.h"
+#include "tv_t.h"
 
 /**
  * identify a firm object type
@@ -35,6 +37,33 @@ static int firm_get_arg_type_int(const arg_occ_t *occ) {
   return arg_type_int;
 }
 
+
+static int bitset_get_arg_type(const arg_occ_t *occ) {
+  return arg_type_ptr;
+}
+
+static int bitset_emit(appendable_t *app, const arg_occ_t *occ, const arg_value_t *arg)
+{
+  int res = 2;
+  bitset_t *b = arg->v_ptr;
+  bitset_pos_t p;
+  char buf[32];
+  const char *prefix = "";
+
+  arg_append(app, occ, "[", 1);
+  for(p = bitset_next_set(b, 0); p != -1; p = bitset_next_set(b, p)) {
+    int n;
+
+    n = snprintf(buf, sizeof(buf), "%s%d", prefix, (int) p);
+    arg_append(app, occ, buf, n);
+    prefix = ", ";
+    res += n;
+  }
+  arg_append(app, occ, "]", 1);
+
+  return res;
+}
+
 /**
  * emit a Firm object
  */
@@ -44,45 +73,58 @@ static int firm_emit(appendable_t *app, const arg_occ_t *occ, const arg_value_t
 
   void *X = arg->v_ptr;
   firm_kind *obj = X;
-
   int i, n;
   ir_node *block;
+       char add[64];
   char buf[256];
   char tv[256];
 
   buf[0] = '\0';
+  add[0] = '\0';
 
   if (! X)
     strncpy(buf, "(null)", sizeof(buf));
   else {
     switch (*obj) {
     case k_BAD:
-      snprintf(buf, sizeof(buf), "BAD[%p]", X);
+      snprintf(buf, sizeof(buf), "BAD");
+      snprintf(add, sizeof(add), "[%p]", X);
       break;
     case k_entity:
-      snprintf(buf, sizeof(buf), "%s%s[%ld]", A("ent"),
-          isupper(occ->conversion) ? get_entity_ld_name(X): get_entity_name(X),
-          get_entity_nr(X));
+      snprintf(buf, sizeof(buf), "%s%s", A("ent"),
+          isupper(occ->conversion) ? get_entity_ld_name(X): get_entity_name(X));
+      snprintf(add, sizeof(add), "[%ld]", get_entity_nr(X));
       break;
     case k_type:
-      snprintf(buf, sizeof(buf), "%s%s:%s[%ld]", A("type"), get_type_tpop_name(X), get_type_name(X), get_type_nr(X));
+      snprintf(buf, sizeof(buf), "%s%s:%s", A("type"), get_type_tpop_name(X), get_type_name(X));
+      snprintf(add, sizeof(add), "[%ld]", get_type_nr(X));
       break;
     case k_ir_graph:
-      snprintf(buf, sizeof(buf), "%s%s[%ld]", A("irg"), get_entity_name(get_irg_entity(X)), get_irg_graph_nr(X));
+      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:
       switch (occ->conversion) {
       case 'B':
         block = is_no_Block(X) ? get_nodes_block(X) : X;
-        snprintf(buf, sizeof(buf), "%s%s%s[%ld]", A("irn"), get_irn_opname(block),
-            get_mode_name(get_irn_mode(block)), get_irn_node_nr(block));
+        snprintf(buf, sizeof(buf), "%s%s%s", A("irn"), get_irn_opname(block),
+            get_mode_name(get_irn_mode(block)));
+        snprintf(add, sizeof(add), "[%ld]", get_irn_node_nr(block));
         break;
       case 'N':
         snprintf(buf, sizeof(buf), "%ld", get_irn_node_nr(X));
         break;
       default:
-        snprintf(buf, sizeof(buf), "%s%s%s[%ld]", A("irn"), get_irn_opname(X),
-            get_mode_name(get_irn_mode(X)), get_irn_node_nr(X));
+        if (is_Const(irn)) {
+          char tbuf[128];
+          tarval_snprintf(tv, sizeof(tv), X);
+          snprintf(buf, sizeof(buf), "%s%s%s<%s>", A("irn"), get_irn_opname(X),
+            get_mode_name(get_irn_mode(X)), tbuf);
+        }
+        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));
       }
       break;
     case k_ir_mode:
@@ -110,9 +152,14 @@ static int firm_emit(appendable_t *app, const arg_occ_t *occ, const arg_value_t
       }
       break;
     default:
-      snprintf(buf, sizeof(buf), "UNKWN[%p]", X);
+      snprintf(buf, sizeof(buf), "UNKWN");
+      snprintf(add, sizeof(add), "[%p]", X);
     }
   }
+
+  if(occ->flag_plus)
+       strncat(buf, add, sizeof(buf));
+
   return arg_append(app, occ, buf, strlen(buf));
 
 #undef A
@@ -129,8 +176,6 @@ static int firm_emit_ident(appendable_t *app, const arg_occ_t *occ, const arg_va
   return arg_append(app, occ, p, strlen(p));
 }
 
-
-
 /**
  * Emit indent.
  */
@@ -145,6 +190,18 @@ static int firm_emit_indent(appendable_t *app, const arg_occ_t *occ, const arg_v
        return amount;
 }
 
+/**
+ * Emit pnc.
+ */
+static int firm_emit_pnc(appendable_t *app, const arg_occ_t *occ, const arg_value_t *arg)
+{
+  int i;
+  int value = arg->v_int;
+  const char *p = get_pnc_string(value);
+
+  return arg_append(app, occ, p, strlen(p));
+}
+
 arg_env_t *firm_get_arg_env(void)
 {
 #define X(name, letter) {"firm:" name, letter}
@@ -154,6 +211,8 @@ arg_env_t *firm_get_arg_env(void)
   static arg_handler_t firm_handler   = { firm_get_arg_type, firm_emit };
   static arg_handler_t ident_handler  = { firm_get_arg_type, firm_emit_ident };
   static arg_handler_t indent_handler = { firm_get_arg_type_int, firm_emit_indent };
+  static arg_handler_t pnc_handler    = { firm_get_arg_type_int, firm_emit_pnc };
+  static arg_handler_t bitset_handler = { bitset_get_arg_type, bitset_emit };
 
   static struct {
     const char *name;
@@ -168,6 +227,7 @@ arg_env_t *firm_get_arg_env(void)
     X("irn_nr",    'N'),
     X("mode",      'm'),
     X("block",     'B'),
+    X("pnc",       '='),
   };
 
   int i;
@@ -182,6 +242,7 @@ arg_env_t *firm_get_arg_env(void)
 
     arg_register(env, "firm:ident", 'I', &ident_handler);
                arg_register(env, "firm:indent", 'D', &indent_handler);
+               /* arg_register(env, "firm:bitset", 'b', &bitset_handler); */
   }
 
   return env;