fixed sc_val_from_str()
[libfirm] / ir / tv / tv.c
index e724cdc..5015ad2 100644 (file)
@@ -34,7 +34,9 @@
 #ifdef HAVE_STRINGS_H
 #include <strings.h>        /* strings.h also includes bsd only function strcasecmp */
 #endif
-#include <stdlib.h>
+#ifdef HAVE_STDLIB_H
+# include <stdlib.h>
+#endif
 #ifdef HAVE_ALLOCA_H
 # include <alloca.h>
 #endif
@@ -50,6 +52,7 @@
 #include "strcalc.h"
 #include "fltcalc.h"
 #include "irtools.h"
+#include "firm_common.h"
 
 /** Size of hash tables.  Should correspond to average number of distinct constant
     target values */
@@ -153,12 +156,13 @@ static int hash_val(const void *value, unsigned int length)
   return hash;
 }
 
-/* finds tarval with value/mode or creates new tarval */
+/** finds tarval with value/mode or creates new tarval */
 static tarval *get_tarval(const void *value, int length, ir_mode *mode)
 {
   tarval tv;
 
-  tv.mode = mode;
+  tv.kind   = k_tarval;
+  tv.mode   = mode;
   tv.length = length;
   if (length > 0) {
     /* if there already is such a value, it is returned, else value
@@ -301,7 +305,7 @@ tarval *new_tarval_from_str(const char *str, size_t len, ir_mode *mode)
 
     case irms_int_number:
     case irms_character:
-      sc_val_from_str(str, len, NULL);
+      sc_val_from_str(str, len, NULL, mode);
       return get_tarval(sc_get_buffer(), sc_get_buffer_length(), mode);
 
     case irms_reference:
@@ -945,7 +949,6 @@ tarval *tarval_convert_to(tarval *src, ir_mode *m)
               break;
           }
           return get_tarval(fc_get_buffer(), fc_get_buffer_length(), m);
-
 #if 0
         case irms_reference:
           /* allow 0 to be casted */
@@ -1721,10 +1724,19 @@ void init_tarval_2(void)
 {
   ANNOUNCE();
 
+  tarval_bad->kind       = k_tarval;
   tarval_bad->mode       = mode_BAD;
+
+  tarval_undefined->kind = k_tarval;
   tarval_undefined->mode = mode_ANY;
+
+  tarval_b_true->kind    = k_tarval;
   tarval_b_true->mode    = mode_b;
+
+  tarval_b_false->kind   = k_tarval;
   tarval_b_false->mode   = mode_b;
+
+  tarval_P_void->kind    = k_tarval;
   tarval_P_void->mode    = mode_P;
 
   /*