fpaStf is now Proj less
[libfirm] / ir / ir / irprintf.c
index d13dfab..cffcbb8 100644 (file)
@@ -1,22 +1,29 @@
 /*
- * Project:     libFIRM
- * File name:   ir/ir/irprintf.c
- * Purpose:     A little printf helper unterstanding firm types
- * Author:      Sebastian Hack
- * Created:     29.11.2004
- * CVS-ID:      $Id$
- * Copyright:   (c) 1998-2004 Universität Karlsruhe
- * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
+ * Copyright (C) 1995-2007 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 irprintf.c
- *
- * A little printf helper unterstanding firm types.
- * @author Sebastian Hack
- * @date 29.11.2004
+ * @file
+ * @brief   A little printf helper unterstanding firm types
+ * @author  Sebastian Hack
+ * @date    29.11.2004
+ * @version $Id$
  */
-
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
@@ -55,7 +62,7 @@
  */
 static void str_init(void *object, size_t n)
 {
-       strcpy(object, "");
+  strcpy(object, "");
 }
 
 /**
@@ -63,12 +70,12 @@ static void str_init(void *object, size_t n)
  */
 static void str_append_char(void *object, size_t n, char ch)
 {
-       char buf[2];
+  char buf[2];
 
-       buf[0] = ch;
-       buf[1] = 0;
+  buf[0] = ch;
+  buf[1] = 0;
 
-       strncat(object, buf, n);
+  strncat(object, buf, n);
 }
 
 /**
@@ -76,7 +83,7 @@ static void str_append_char(void *object, size_t n, char ch)
  */
 static void str_append_str(void *object, size_t n, const char *str)
 {
-       strncat(object, str, n);
+  strncat(object, str, n);
 }
 
 
@@ -92,7 +99,7 @@ static void file_init(void *object, size_t n)
  */
 static void file_append_char(void *object, size_t n, char ch)
 {
-       fputc(ch, object);
+  fputc(ch, object);
 }
 
 /**
@@ -100,7 +107,7 @@ static void file_append_char(void *object, size_t n, char ch)
  */
 static void file_append_str(void *object, size_t n, const char *str)
 {
-       fputs(str, object);
+  fputs(str, object);
 }
 
 /**
@@ -115,8 +122,8 @@ static void obst_init(void *object, size_t n)
  */
 static void obst_append_char(void *object, size_t n, char ch)
 {
-       struct obstack *obst = object;
-       obstack_1grow(obst, ch);
+  struct obstack *obst = object;
+  obstack_1grow(obst, ch);
 }
 
 /**
@@ -124,8 +131,8 @@ static void obst_append_char(void *object, size_t n, char ch)
  */
 static void obst_append_str(void *object, size_t n, const char *str)
 {
-       struct obstack *obst = object;
-       obstack_grow(obst, str, strlen(str));
+  struct obstack *obst = object;
+  obstack_grow(obst, str, strlen(str));
 }
 
 
@@ -133,27 +140,27 @@ static void obst_append_str(void *object, size_t n, const char *str)
  * the file appender
  */
 static const appender_t file_appender = {
-       file_init,
-       file_append_char,
-       file_append_str
+  file_init,
+  file_append_char,
+  file_append_str
 };
 
 /**
  * the string buffer appender
  */
 static const appender_t str_appender = {
-       str_init,
-       str_append_char,
-       str_append_str
+  str_init,
+  str_append_char,
+  str_append_str
 };
 
 /**
  * the obstack appender.
  */
 static const appender_t obst_appender = {
-       obst_init,
-       obst_append_char,
-       obst_append_str
+  obst_init,
+  obst_append_char,
+  obst_append_str
 };
 
 #ifndef WITH_LIBCORE
@@ -164,63 +171,63 @@ static void ir_common_vprintf(const appender_t *app, void *object,
 static INLINE void ir_common_printf(const appender_t *app, void *object,
                size_t limit, const char *fmt, ...)
 {
-       va_list args;
+  va_list args;
 
-       va_start(args, fmt);
-       ir_common_vprintf(app, object, limit, fmt, args);
-       va_end(args);
+  va_start(args, fmt);
+  ir_common_vprintf(app, object, limit, fmt, args);
+  va_end(args);
 }
 
 #if 0
 static int is_std_fmt(const char *fmt)
 {
-       static const char *fmt_re_str =
-               "^[0 -+#']?[1-9]*(\\.[1-9]*)?[hlLqjzt]?[diouxXeEfFgGaAc]";
+  static const char *fmt_re_str =
+         "^[0 -+#']?[1-9]*(\\.[1-9]*)?[hlLqjzt]?[diouxXeEfFgGaAc]";
 
-       static regex_t fmt_re;
-       static int preapred_re = 0;
+  static regex_t fmt_re;
+  static int preapred_re = 0;
 
-       regmatch_t match[1];
-       int res;
+  regmatch_t match[1];
+  int res;
 
-       if(!preapred_re) {
-               int res = regcomp(&fmt_re, fmt_re_str, REG_EXTENDED);
-               assert(res == 0 && "Could not prepare regex");
-               preapred_re = 1;
-       }
+  if(!preapred_re) {
+    int res = regcomp(&fmt_re, fmt_re_str, REG_EXTENDED);
+    assert(res == 0 && "Could not prepare regex");
+    preapred_re = 1;
+  }
 
-       res = regexec(&fmt_re, fmt, 1, &match[0], 0);
+  res = regexec(&fmt_re, fmt, 1, &match[0], 0);
 
 #if 0
-       if(res != 0) {
-               char buf[256];
-               regerror(res, &fmt_re, buf, sizeof(buf));
-               printf("%s ", buf);
-       }
+  if(res != 0) {
+    char buf[256];
+    regerror(res, &fmt_re, buf, sizeof(buf));
+    printf("%s ", buf);
+  }
 
-       printf("res: %d, start: %d, end: %d\n",
-                       res, match[0].rm_so, match[0].rm_eo);
+  printf("res: %d, start: %d, end: %d\n",
+         res, match[0].rm_so, match[0].rm_eo);
 #endif
 
-       return res == 0 ? match[0].rm_eo : -1;
+  return res == 0 ? match[0].rm_eo : -1;
 }
 #endif
 
 struct settings {
-       char flag_zero;
-       int width;
-       int flag_minus;
-       int flag_plus;
-       int flag_hash;
+  char flag_zero;
+  int width;
+  int flag_minus;
+  int flag_plus;
+  int flag_hash;
 };
 
 /* Length specifiers. */
 enum {
-       len_char,
-       len_short,
-       len_int,
-       len_long,
-       len_long_long
+  len_char,
+  len_short,
+  len_int,
+  len_long,
+  len_long_long
 };
 
 
@@ -230,32 +237,32 @@ enum {
 static void dump_with_settings(const appender_t *app, void *object, size_t limit,
                const struct settings *settings, const char *str)
 {
-       if (settings->width >= 0) {
-               int i;
-               size_t n = strlen(str);
-               int lim = MIN(settings->width, (int)limit);
-               int to_print = MIN(lim, (int)n);
-               int to_pad = to_print - lim;
-
-               if (!settings->flag_minus)
-                       for(i = 0; i < to_pad; ++i)
-                               app->append_char(object, lim, settings->flag_zero);
-
-               app->append_str(object, to_print, str);
-
-               if (!settings->flag_minus)
-                       for(i = 0; i < to_pad; ++i)
-                               app->append_char(object, lim, settings->flag_zero);
-       }
+  if (settings->width >= 0) {
+    int i;
+    size_t n = strlen(str);
+    int lim = MIN(settings->width, (int)limit);
+    int to_print = MIN(lim, (int)n);
+    int to_pad = to_print - lim;
+
+    if (!settings->flag_minus)
+      for(i = 0; i < to_pad; ++i)
+       app->append_char(object, lim, settings->flag_zero);
+
+    app->append_str(object, to_print, str);
+
+    if (!settings->flag_minus)
+      for(i = 0; i < to_pad; ++i)
+       app->append_char(object, lim, settings->flag_zero);
+  }
 
-       else
-               app->append_str(object, limit, str);
+  else
+    app->append_str(object, limit, str);
 }
 
 /**
  * Beware: do not set the entity ld_name
  */
-static const char *get_entity_ld_name_ex(entity *ent) {
+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);
@@ -274,7 +281,7 @@ static void firm_emit(char *buf, int buflen, char conversion,
   ir_node *block;
   char add[64];
   char tv_buf[256];
-  entity *ent;
+  ir_entity *ent;
 
   buf[0] = '\0';
   add[0] = '\0';
@@ -323,10 +330,36 @@ static void firm_emit(char *buf, int buflen, char conversion,
           snprintf(buf, buflen, "%s%s%s<%s>", A("irn"), get_irn_opname(X),
             get_mode_name(get_irn_mode(X)), tv ? tv_buf : ">NULL<");
         }
+        else if (get_irn_op(X) == op_SymConst) {
+          switch (get_SymConst_kind(X)) {
+          case symconst_type_tag:    /* type tag */
+            snprintf(tv_buf, sizeof(tv_buf), "<ID:%s>", get_type_name(get_SymConst_type(X)));
+            break;
+          case symconst_type_size:   /* type size */
+            snprintf(tv_buf, sizeof(tv_buf), "<SIZE:%s>", get_type_name(get_SymConst_type(X)));
+            break;
+          case symconst_type_align:  /* type alignment */
+            snprintf(tv_buf, sizeof(tv_buf), "<ALIGN:%s>", get_type_name(get_SymConst_type(X)));
+            break;
+          case symconst_addr_name:   /* linker name */
+            snprintf(tv_buf, sizeof(tv_buf), "<EXT:%s>", get_id_str(get_SymConst_name(X)));
+            break;
+          case symconst_addr_ent:    /* entity name */
+            snprintf(tv_buf, sizeof(tv_buf), "<%s>", get_entity_name(get_SymConst_entity(X)));
+            break;
+          case symconst_enum_const:  /* enumeration constant */
+            snprintf(tv_buf, sizeof(tv_buf), "<ENUM:%s>", get_enumeration_name(get_SymConst_enum(X)));
+            break;
+          default:
+            tv_buf[0] = '\0';
+          }
+          snprintf(buf, buflen, "%s%s%s%s", A("irn"), get_irn_opname(X),
+            get_mode_name(get_irn_mode(X)), tv_buf);
+        }
         else
           snprintf(buf, buflen, "%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:
@@ -337,7 +370,7 @@ static void firm_emit(char *buf, int buflen, char conversion,
       snprintf(buf, buflen, "%s%s", A("tv"), tv_buf);
       break;
     case k_ir_loop:
-      snprintf(buf, buflen, "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, buflen, "%s%s", A("op"), get_op_name(X));
@@ -455,18 +488,27 @@ static void ir_common_vprintf(const appender_t *app, void *object,
                                case 'h':
                                        len_str = "h";
                                        len = len_short;
-                                       if((ch = fmt[++i]) == 'h') {
+                                       ++i;
+                                       if((ch = fmt[i]) == 'h') {
                                                len_str = "hh";
                                                len = len_char;
+                                               ++i;
                                        }
                                        break;
 
                                case 'l':
                                        len_str = "l";
                                        len = len_long;
-                                       if((ch = fmt[++i]) == 'l') {
+                                       ++i;
+                                       if ((ch = fmt[i]) == 'l') {
                                                len_str = "ll";
                                                len = len_long_long;
+                                               ++i;
+                                       }
+                                       else if ((ch = fmt[i]) == 'u') {
+                                               len_str = "lu";
+                                               len = len_long_long;
+                                               ++i;
                                        }
                                        break;