some fixes for xml dumper / still buggy.
[libfirm] / ir / tv / tv.c
index d1fb32c..954d37d 100644 (file)
@@ -166,7 +166,6 @@ static int overflows(tarval *tv)
 {
   switch (get_mode_sort(tv->mode))
   {
-    case irms_character:
     case irms_int_number:
       if (sc_comp(tv->value, get_mode_max(tv->mode)->value) == 1) return 1;
       if (sc_comp(tv->value, get_mode_min(tv->mode)->value) == -1) return 1;
@@ -293,16 +292,28 @@ tarval *new_tarval_from_long(long l, ir_mode *mode)
 int tarval_is_long(tarval *tv)
 {
   ANNOUNCE();
-  return ((get_mode_sort(tv->mode) == irms_int_number) || (get_mode_sort(tv->mode) == irms_character));
+  if (get_mode_sort(tv->mode) != irms_int_number) return 0;
+
+  if (get_mode_size_bits(tv->mode) > sizeof(long)<<3)
+  {
+    /* the value might be too big to fit in a long */
+    sc_max_from_bits(sizeof(long)<<3, 0);
+    if (sc_comp(sc_get_buffer(), tv->value) == -1)
+    {
+      /* really doesn't fit */
+      return 0;
+    }
+  }
+  return 1;
 }
 
 /* this might overflow the machine's long, so use only with small values */
 long tarval_to_long(tarval* tv)
 {
   ANNOUNCE();
-  assert(tv && get_mode_sort(tv->mode) == irms_int_number);
+  assert(tarval_is_long(tv) && "tarval too big to fit in long");
 
-  return sc_val_to_long(tv->value); /* might overflow */
+  return sc_val_to_long(tv->value);
 }
 
 tarval *new_tarval_from_double(long double d, ir_mode *mode)
@@ -1164,6 +1175,19 @@ int tarval_set_mode_output_option(ir_mode *mode, const tarval_mode_info *modeinf
   return 0;
 }
 
+/*
+ * Returns the output options of one mode.
+ *
+ * This functions returns the modinfo of a given mode.
+ */
+const tarval_mode_info *tarval_get_mode_output_option(ir_mode *mode)
+{
+  assert(mode);
+
+  return mode->tv_priv;
+}
+
+
 /* Identifying some tarvals ??? */
 /* Implemented in old tv.c as such:
  *   return 0 for additive neutral,
@@ -1198,11 +1222,11 @@ void init_tarval_1(void)
   /* init with default precision */
   init_strcalc(0);
   /* init_fltcalc(0); not yet*/
-  tarval_bad = (tarval*)malloc(sizeof(tarval));
+  tarval_bad       = (tarval*)malloc(sizeof(tarval));
   tarval_undefined = (tarval*)malloc(sizeof(tarval));
-  tarval_b_true = (tarval*)malloc(sizeof(tarval));
-  tarval_b_false = (tarval*)malloc(sizeof(tarval));
-  tarval_P_void = (tarval*)malloc(sizeof(tarval));
+  tarval_b_true    = (tarval*)malloc(sizeof(tarval));
+  tarval_b_false   = (tarval*)malloc(sizeof(tarval));
+  tarval_P_void    = (tarval*)malloc(sizeof(tarval));
 }
 
 /**
@@ -1231,11 +1255,11 @@ void init_tarval_2(void)
 {
   ANNOUNCE();
 
-  tarval_bad->mode = mode_BAD;
+  tarval_bad->mode       = mode_BAD;
   tarval_undefined->mode = mode_ANY;
-  tarval_b_true->mode = mode_b;
-  tarval_b_false->mode = mode_b;
-  tarval_P_void->mode = mode_P;
+  tarval_b_true->mode    = mode_b;
+  tarval_b_false->mode   = mode_b;
+  tarval_P_void->mode    = mode_P;
 
   /*
    * assign output modes that are compatible with the