added function for convertion debug info
[libfirm] / ir / ir / irargs.c
index dc559a9..48782f4 100644 (file)
@@ -6,7 +6,7 @@
  * Modified by:
  * Created:
  * CVS-ID:      $Id$
- * Copyright:   (c) 1998-2005 Universitt Karlsruhe
+ * Copyright:   (c) 1998-2005 Universitaet Karlsruhe
  * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
  */
 
@@ -14,6 +14,8 @@
 # include "config.h"
 #endif
 
+#include "bitset.h"
+
 #include <ctype.h>
 #include <libcore/xprintf.h>
 
@@ -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
  */
@@ -86,7 +115,14 @@ static int firm_emit(appendable_t *app, const arg_occ_t *occ, const arg_value_t
         snprintf(buf, sizeof(buf), "%ld", get_irn_node_nr(X));
         break;
       default:
-        snprintf(buf, sizeof(buf), "%s%s%s", A("irn"), get_irn_opname(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));
       }
@@ -140,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.
  */
@@ -156,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}
@@ -165,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;
@@ -179,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;
@@ -193,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;