1 /* TV --- Target Values, aka Constant Table.
2 Copyright (C) 1995, 1996 Christian von Roques */
6 /****i* tv/implementation
13 * Internal storage for tarvals, 1st draft:
14 * Integers as well as pointers are stored in a hex formatted string holding
15 * 16 characters. Booleans are not stored as there are only two of them.
17 * Floats are just reinterpreted as byte strings, because I am not sure if
18 * there is loss if I convert float to long double and back and furthermore
19 * the implementation of a fully ieee compatible floating point emulation
20 * is not sensible for now
21 * With this information it is easy to decide the kind of stored value:
22 * Integers have size 16, floats 4, doubles 8, long doubles 12.
25 /* This implementation assumes:
26 * both host and target have IEEE-754 floating-point arithmetic. */
28 /* !!! float and double divides MUST NOT SIGNAL !!! */
29 /* @@@ query the floating-point expception status flags */
31 /* @@@ Problem: All Values are stored twice, once as Univ_*s and a 2nd
32 time in their real target mode. :-( */
34 #define MAX_INT_LENGTH 8
35 #define CHAR_BUFFER_SIZE ((MAX_INT_LENGTH) * 2)
41 #include <assert.h> /* assertions */
42 #include <stdlib.h> /* atoi() */
43 #include <string.h> /* nice things for strings */
47 #include "set.h" /* to store tarvals in */
48 #include "tune.h" /* some constants */
49 #include "entity_t.h" /* needed to store pointers to entities */
50 #include "irmode.h" /* defines modes etc */
52 #include "irnode.h" /* defines boolean return values */
59 /****************************************************************************
60 * local definitions and macros
61 ****************************************************************************/
63 # define TARVAL_VERIFY(a) tarval_verify((a))
65 # define TARVAL_VERIFY(a) ((void)0)
68 #define INSERT_TARVAL(tv) ((tarval*)set_insert(tarvals, (tv), sizeof(tarval), hash_tv((tv))))
69 #define FIND_TARVAL(tv) ((tarval*)set_find(tarvals, (tv), sizeof(tarval), hash_tv((tv))))
71 #define INSERT_VALUE(val, size) (set_insert(values, (val), size, hash_val((val), size)))
72 #define FIND_VALUE(val, size) (set_find(values, (val), size, hash_val((val), size)))
74 #define fail_verify(a) _fail_verify((a), __FILE__, __LINE__)
76 static long long count = 0;
77 # define ANNOUNCE() printf(__FILE__": call no. %lld (%s)\n", count++, __FUNCTION__);
79 # define ANNOUNCE() ((void)0)
81 /****************************************************************************
83 ****************************************************************************/
84 static struct set *tarvals; /* container for tarval structs */
85 static struct set *values; /* container for values */
87 /****************************************************************************
89 ****************************************************************************/
91 static int hash_val(const void *value, unsigned int length);
92 static int hash_tv(tarval *tv);
93 static void _fail_verify(tarval *tv, const char* file, int line)
95 /* print a memory image of the tarval and throw an assertion */
97 printf("%s:%d: Invalid tarval:\n mode: %s\n value: [%p]\n", file, line, get_mode_name(tv->mode), tv->value);
99 printf("%s:%d: Invalid tarval (null)", file, line);
103 static void tarval_verify(tarval *tv)
109 if ((tv == tarval_bad) || (tv == tarval_undefined)) return;
110 if ((tv == tarval_b_true) || (tv == tarval_b_false)) return;
112 if (!FIND_TARVAL(tv)) fail_verify(tv);
113 if (tv->length > 0 && !FIND_VALUE(tv->value, tv->length)) fail_verify(tv);
119 static int hash_tv(tarval *tv)
121 return ((unsigned int)tv->value ^ (unsigned int)tv->mode) + tv->length;
124 static int hash_val(const void *value, unsigned int length)
127 unsigned int hash = 0;
129 /* scramble the byte - array */
130 for (i = 0; i < length; i++)
132 hash += (hash << 5) ^ (hash >> 27) ^ ((char*)value)[i];
133 hash += (hash << 11) ^ (hash >> 17);
139 /* finds tarval with value/mode or creates new tarval */
140 static tarval *get_tarval(const void *value, int length, ir_mode *mode)
147 /* if there already is such a value, it is returned, else value
148 * is copied into the set */
149 tv.value = INSERT_VALUE(value, length);
153 /* if there is such a tarval, it is returned, else tv is copied
155 return (tarval *)INSERT_TARVAL(&tv);
159 * Returns non-zero if a tarval overflows.
161 * @todo Implementation did not work on all modes
163 static int overflows(tarval *tv)
165 switch (get_mode_sort(tv->mode))
168 case irms_int_number:
169 if (sc_comp(tv->value, get_mode_max(tv->mode)->value) == 1) return 1;
170 if (sc_comp(tv->value, get_mode_min(tv->mode)->value) == -1) return 1;
173 case irms_float_number:
174 if (fc_comp(tv->value, get_mode_max(tv->mode)->value) == 1) return 1;
175 if (fc_comp(tv->value, get_mode_min(tv->mode)->value) == -1) return 1;
186 * public variables declared in tv.h
189 tarval *tarval_undefined;
190 tarval *tarval_b_false;
191 tarval *tarval_b_true;
192 tarval *tarval_P_void;
195 * public functions declared in tv.h
199 * Constructors =============================================================
201 tarval *new_tarval_from_str(const char *str, size_t len, ir_mode *mode)
208 switch (get_mode_sort(mode))
214 case irms_internal_boolean:
215 /* match tTrRuUeE/fFaAlLsSeE */
216 if (strcasecmp(str, "true")) return tarval_b_true;
217 else if (strcasecmp(str, "false")) return tarval_b_true;
219 return atoi(str) ? tarval_b_true : tarval_b_false;
221 case irms_float_number:
222 fc_val_from_str(str, len);
223 return get_tarval(fc_get_buffer(), fc_get_buffer_length(), mode);
225 case irms_int_number:
227 sc_val_from_str(str, len);
228 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), mode);
231 return get_tarval(str, len, mode);
234 assert(0); /* can't be reached, can it? */
239 int tarval_is_str(tarval *tv)
244 return ((get_mode_sort(tv->mode) == reference) && (tv->value != NULL) && (tv->length > 0));
246 char *tarval_to_str(tarval *tv)
249 assert(tarval_is_str(tv));
250 return (char *)tv->value;
255 * helper function, creta a tarval from long
257 tarval *new_tarval_from_long(long l, ir_mode *mode)
260 assert(mode && !(get_mode_sort(mode) == irms_auxiliary));
262 switch(get_mode_sort(mode))
264 case irms_internal_boolean:
265 /* XXX C-Semantics ! */
266 return l ? tarval_b_true : tarval_b_false ;
268 case irms_int_number:
271 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), mode);
273 case irms_float_number:
274 return new_tarval_from_double((long double)l, mode);
277 return l ? tarval_bad : get_tarval(NULL, 0, mode); /* null pointer or tarval_bad */
285 /* returns non-zero if can be converted to long */
286 int tarval_is_long(tarval *tv)
289 return ((get_mode_sort(tv->mode) == irms_int_number) || (get_mode_sort(tv->mode) == irms_character));
292 /* this might overflow the machine's long, so use only with small values */
293 long tarval_to_long(tarval* tv)
296 assert(tv && get_mode_sort(tv->mode) == irms_int_number);
298 return sc_val_to_long(tv->value); /* might overflow */
301 tarval *new_tarval_from_double(long double d, ir_mode *mode)
304 assert(mode && (get_mode_sort(mode) == irms_float_number));
306 fc_val_from_float(d);
307 return get_tarval(fc_get_buffer(), fc_get_buffer_length(), mode);
310 /* returns non-zero if can be converted to double */
311 int tarval_is_double(tarval *tv)
316 return (get_mode_sort(tv->mode) == irms_float_number);
319 long double tarval_to_double(tarval *tv)
322 assert(tarval_is_double(tv));
324 return fc_val_to_float(tv->value);
327 /* The tarval represents the address of the entity. As the address must
328 be constant the entity must have as owner the global type. */
329 tarval *new_tarval_from_entity (entity *ent, ir_mode *mode)
333 assert(mode && (get_mode_sort(mode) == irms_reference));
335 return get_tarval((void *)ent, 0, mode);
337 int tarval_is_entity(tarval *tv)
341 /* tv->value == NULL means dereferencing a null pointer */
342 return ((get_mode_sort(tv->mode) == irms_reference) && (tv->value != NULL) && (tv->length == 0));
345 entity *tarval_to_entity(tarval *tv)
350 if (tarval_is_entity(tv))
351 return (entity *)tv->value;
353 assert(0 && "tarval did not represent an entity");
358 void free_tarval_entity(entity *ent) {
359 /* There can be a tarval referencing this entity. Even if the
360 tarval is not used by the code any more, it can still reference
361 the entity as tarvals live indepently of the entity referenced.
362 Further the tarval is hashed into a set. If a hash function
363 evaluation happens to collide with this tarval, we will vrfy that
364 it contains a proper entity and we will crash if the entity is
367 Unluckily, tarvals can neither be changed nor deleted, and to find
368 one, all existing reference modes have to be tried -> a facility
369 to retrieve all modes of a kind is needed. */
374 * Access routines for tarval fields ========================================
376 ir_mode *get_tarval_mode (tarval *tv) /* get the mode of the tarval */
384 * Special value query functions ============================================
386 * These functions calculate and return a tarval representing the requested
388 * The functions get_mode_{Max,Min,...} return tarvals retrieved from these
389 * functions, but these are stored on initialization of the irmode module and
390 * therefore the irmode functions should be prefered to the functions below.
393 tarval *get_tarval_bad(void)
398 tarval *get_tarval_undefined(void)
401 return tarval_undefined;
403 tarval *get_tarval_b_false(void)
406 return tarval_b_false;
408 tarval *get_tarval_b_true(void)
411 return tarval_b_true;
413 tarval *get_tarval_P_void(void)
416 return tarval_P_void;
419 tarval *get_tarval_max(ir_mode *mode)
424 switch(get_mode_sort(mode))
431 case irms_internal_boolean:
432 return tarval_b_true;
434 case irms_float_number:
435 fc_get_max(get_mode_size_bits(mode));
436 return get_tarval(fc_get_buffer(), fc_get_buffer_length(), mode);
438 case irms_int_number:
440 sc_max_from_bits(get_mode_size_bits(mode), mode_is_signed(mode));
441 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), mode);
446 tarval *get_tarval_min(ir_mode *mode)
451 switch(get_mode_sort(mode))
458 case irms_internal_boolean:
459 return tarval_b_false;
461 case irms_float_number:
462 fc_get_min(get_mode_size_bits(mode));
463 return get_tarval(fc_get_buffer(), fc_get_buffer_length(), mode);
465 case irms_int_number:
467 sc_min_from_bits(get_mode_size_bits(mode), mode_is_signed(mode));
468 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), mode);
473 tarval *get_tarval_null(ir_mode *mode)
478 switch(get_mode_sort(mode))
481 case irms_internal_boolean:
485 case irms_float_number:
486 return new_tarval_from_double(0.0, mode);
488 case irms_int_number:
490 return new_tarval_from_long(0l, mode);
493 return tarval_P_void;
498 tarval *get_tarval_one(ir_mode *mode)
503 switch(get_mode_sort(mode))
506 case irms_internal_boolean:
511 case irms_float_number:
512 return new_tarval_from_double(1.0, mode);
514 case irms_int_number:
516 return new_tarval_from_long(1l, mode);
522 tarval *get_tarval_nan(ir_mode *mode)
527 if (get_mode_sort(mode) == irms_float_number) {
529 return get_tarval(fc_get_buffer(), fc_get_buffer_length(), mode);
532 assert(0 && "tarval is not floating point");
537 tarval *get_tarval_inf(ir_mode *mode)
542 if (get_mode_sort(mode) == irms_float_number) {
544 return get_tarval(fc_get_buffer(), fc_get_buffer_length(), mode);
547 assert(0 && "tarval is not floating point");
553 * Arithmethic operations on tarvals ========================================
557 * test if negative number, 1 means 'yes'
559 int tarval_is_negative(tarval *a)
564 switch (get_mode_sort(a->mode))
566 case irms_int_number:
567 if (!mode_is_signed(a->mode)) return 0;
569 return sc_comp(a->value, get_mode_null(a->mode)->value) == -1 ? 1 : 0;
571 case irms_float_number:
572 return fc_comp(a->value, get_mode_null(a->mode)->value) == -1 ? 1 : 0;
575 assert(0 && "not implemented");
583 pnc_number tarval_cmp(tarval *a, tarval *b)
589 if (a == tarval_bad || b == tarval_bad) assert(0 && "Comparison with tarval_bad");
590 if (a == tarval_undefined || b == tarval_undefined) return False;
591 if (a == b) return Eq;
592 if (get_tarval_mode(a) != get_tarval_mode(b)) return Uo;
594 /* Here the two tarvals are unequal and of the same mode */
595 switch (get_mode_sort(a->mode))
600 case irms_float_number:
601 return (fc_comp(a->value, b->value)==1)?(Gt):(Lt);
603 case irms_int_number:
605 return (sc_comp(a->value, b->value)==1)?(Gt):(Lt);
607 case irms_internal_boolean:
608 return (a == tarval_b_true)?(Gt):(Lt);
617 * convert to other mode
619 tarval *tarval_convert_to(tarval *src, ir_mode *m)
627 if (src->mode == m) return src;
629 switch (get_mode_sort(src->mode))
634 case irms_float_number:
637 case irms_int_number:
638 switch (get_mode_sort(m))
640 case irms_int_number:
643 tv.length = src->length;
644 tv.value = src->value;
649 return INSERT_TARVAL(&tv);
651 case irms_internal_boolean:
652 /* XXX C semantics */
653 if (src == get_mode_null(src->mode)) return tarval_b_false;
654 else return tarval_b_true;
661 case irms_internal_boolean:
662 switch (get_mode_sort(m))
664 case irms_int_number:
665 if (src == tarval_b_true) return get_mode_one(m);
666 else return get_mode_null(m);
685 tarval *tarval_neg(tarval *a)
689 assert(mode_is_num(a->mode)); /* negation only for numerical values */
690 assert(mode_is_signed(a->mode)); /* negation is difficult without negative numbers, isn't it */
692 switch (get_mode_sort(a->mode))
694 case irms_int_number:
696 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
698 case irms_float_number:
700 return get_tarval(fc_get_buffer(), fc_get_buffer_length(), a->mode);
710 tarval *tarval_add(tarval *a, tarval *b)
715 assert((a->mode == b->mode) || (get_mode_sort(a->mode) == irms_character && mode_is_int(b->mode)));
717 switch (get_mode_sort(a->mode))
720 case irms_int_number:
721 /* modes of a,b are equal, so result has mode of a as this might be the character */
722 sc_add(a->value, b->value);
723 /* FIXME: Check for overflow */
724 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
726 case irms_float_number:
727 /* FIXME: Overflow/Underflow/transition to inf when mode < 80bit */
728 fc_add(a->value, b->value);
729 return get_tarval(fc_get_buffer(), fc_get_buffer_length(), a->mode);
739 tarval *tarval_sub(tarval *a, tarval *b)
744 assert((a->mode == b->mode) || (get_mode_sort(a->mode) == irms_character && mode_is_int(b->mode)));
746 switch (get_mode_sort(a->mode))
749 case irms_int_number:
750 /* modes of a,b are equal, so result has mode of a as this might be the character */
751 sc_sub(a->value, b->value);
752 /* FIXME: check for overflow */
753 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
755 case irms_float_number:
756 /* FIXME: Overflow/Underflow/transition to inf when mode < 80bit */
757 fc_add(a->value, b->value);
758 return get_tarval(fc_get_buffer(), fc_get_buffer_length(), a->mode);
768 tarval *tarval_mul(tarval *a, tarval *b)
773 assert((a->mode == b->mode) && mode_is_num(a->mode));
775 switch (get_mode_sort(a->mode))
777 case irms_int_number:
778 /* modes of a,b are equal */
779 sc_mul(a->value, b->value);
780 /* FIXME: check for overflow */
781 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
783 case irms_float_number:
784 /* FIXME: Overflow/Underflow/transition to inf when mode < 80bit */
785 fc_add(a->value, b->value);
786 return get_tarval(fc_get_buffer(), fc_get_buffer_length(), a->mode);
794 * floating point division
796 tarval *tarval_quo(tarval *a, tarval *b)
801 assert((a->mode == b->mode) && mode_is_float(a->mode));
803 /* FIXME: Overflow/Underflow/transition to inf when mode < 80bit */
804 fc_div(a->value, b->value);
805 return get_tarval(fc_get_buffer(), fc_get_buffer_length(), a->mode);
811 tarval *tarval_div(tarval *a, tarval *b)
816 assert((a->mode == b->mode) && mode_is_int(a->mode));
818 /* modes of a,b are equal */
819 sc_div(a->value, b->value);
820 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
826 tarval *tarval_mod(tarval *a, tarval *b)
831 assert((a->mode == b->mode) && mode_is_int(a->mode));
833 /* modes of a,b are equal */
834 sc_mod(a->value, b->value);
835 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
841 tarval *tarval_abs(tarval *a)
845 assert(mode_is_num(a->mode));
847 switch (get_mode_sort(a->mode))
849 case irms_int_number:
850 if (sc_comp(a->value, get_mode_null(a->mode)->value) == -1)
853 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
857 case irms_float_number:
869 tarval *tarval_and(tarval *a, tarval *b)
874 assert((a->mode == b->mode) && mode_is_int(a->mode));
876 sc_and(a->value, b->value);
877 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
883 tarval *tarval_or (tarval *a, tarval *b)
888 assert((a->mode == b->mode) && mode_is_int(a->mode));
890 sc_or(a->value, b->value);
891 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
895 * bitwise exclusive or (xor)
897 tarval *tarval_eor(tarval *a, tarval *b)
902 assert((a->mode == b->mode) && mode_is_int(a->mode));
904 sc_or(a->value, b->value);
905 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
911 tarval *tarval_shl(tarval *a, tarval *b)
916 assert(mode_is_int(a->mode) && mode_is_int(b->mode));
918 sc_shl(a->value, b->value, get_mode_size_bits(a->mode), mode_is_signed(a->mode));
919 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
923 * bitwise unsigned right shift
925 tarval *tarval_shr(tarval *a, tarval *b)
930 assert(mode_is_int(a->mode) && mode_is_int(b->mode));
932 sc_shr(a->value, b->value, get_mode_size_bits(a->mode), mode_is_signed(a->mode));
933 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
937 * bitwise signed right shift
939 tarval *tarval_shrs(tarval *a, tarval *b)
944 assert(mode_is_int(a->mode) && mode_is_int(b->mode));
946 sc_shrs(a->value, b->value, get_mode_size_bits(a->mode), mode_is_signed(a->mode));
947 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
953 tarval *tarval_rot(tarval *a, tarval *b)
958 assert(mode_is_int(a->mode) && mode_is_int(b->mode));
960 sc_rot(a->value, b->value, get_mode_size_bits(a->mode), mode_is_signed(a->mode));
961 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
967 int tarval_print(XP_PAR1, const xprintf_info *info ATTRIBUTE((unused)), XP_PARN)
969 static const tarval_mode_info default_info = { TVO_NATIVE, NULL, NULL };
974 const tarval_mode_info *mode_info;
975 const char *prefix, *suffix;
979 tv = XP_GETARG(tarval *, 0);
980 mode_info = tv->mode->tv_priv;
982 mode_info = &default_info;
983 prefix = mode_info->mode_prefix ? mode_info->mode_prefix : "";
984 suffix = mode_info->mode_suffix ? mode_info->mode_suffix : "";
986 switch (get_mode_sort(tv->mode))
988 case irms_int_number:
990 switch (mode_info->mode_output) {
993 str = sc_print(tv->value, get_mode_size_bits(tv->mode), SC_DEC);
997 str = sc_print(tv->value, get_mode_size_bits(tv->mode), SC_OCT);
1003 str = sc_print(tv->value, get_mode_size_bits(tv->mode), SC_HEX);
1006 return XPF3R("%s%s%s", prefix, str, suffix);
1008 case irms_float_number:
1009 return XPF3R("%s%s%s", prefix, fc_print_dec(tv->value, buf, sizeof(buf)), suffix);
1011 case irms_reference:
1012 if (tv->value != NULL)
1013 if (tarval_is_entity(tv))
1014 if (get_entity_peculiarity((entity *)tv->value) == existent)
1015 return XPF1R("&(%I)", get_entity_ld_ident((entity *)tv->value));
1017 return XPSR("NULL");
1019 return XPMR((char*)tv->value, tv->length);
1021 return XPSR("void");
1023 case irms_internal_boolean:
1024 switch (mode_info->mode_output) {
1030 return XPF3R("%s%c%s", prefix, (tv == tarval_b_true) ? '1' : '0', suffix);
1034 return XPF3R("%s%s%s", prefix, (tv == tarval_b_true) ? "true" : "false", suffix);
1037 case irms_auxiliary:
1038 return XPSR("<BAD>");
1047 int tarval_snprintf(char *buf, size_t len, tarval *tv)
1049 static const tarval_mode_info default_info = { TVO_NATIVE, NULL, NULL };
1053 const tarval_mode_info *mode_info;
1054 const char *prefix, *suffix;
1058 mode_info = tv->mode->tv_priv;
1060 mode_info = &default_info;
1061 prefix = mode_info->mode_prefix ? mode_info->mode_prefix : "";
1062 suffix = mode_info->mode_suffix ? mode_info->mode_suffix : "";
1064 switch (get_mode_sort(tv->mode))
1066 case irms_int_number:
1067 case irms_character:
1068 switch (mode_info->mode_output) {
1071 str = sc_print(tv->value, get_mode_size_bits(tv->mode), SC_DEC);
1075 str = sc_print(tv->value, get_mode_size_bits(tv->mode), SC_OCT);
1081 str = sc_print(tv->value, get_mode_size_bits(tv->mode), SC_HEX);
1084 return snprintf(buf, len, "%s%s%s", prefix, str, suffix);
1086 case irms_float_number:
1087 return snprintf(buf, len, "%s%s%s", prefix, fc_print_dec(tv->value, tv_buf, sizeof(tv_buf)), suffix);
1089 case irms_reference:
1090 if (tv->value != NULL)
1091 if (tarval_is_entity(tv))
1092 if (get_entity_peculiarity((entity *)tv->value) == existent)
1093 return snprintf(buf, len, "&(%s)", get_entity_ld_name((entity *)tv->value));
1095 return snprintf(buf, len, "NULL");
1097 if (size > tv->length) {
1098 memcpy(buf, tv->value, tv->length);
1099 buf[tv->length] = '\0';
1103 memcpy(buf, tv->value, size-1);
1109 return snprintf(buf, len, "void");
1111 case irms_internal_boolean:
1112 switch (mode_info->mode_output) {
1118 return snprintf(buf, len, "%s%c%s", prefix, (tv == tarval_b_true) ? '1' : '0', suffix);
1122 return snprintf(buf, len, "%s%s%s", prefix, (tv == tarval_b_true) ? "true" : "false", suffix);
1125 case irms_auxiliary:
1126 return snprintf(buf, len, "<BAD>");
1132 char *tarval_bitpattern(tarval *tv)
1138 * access to the bitpattern
1140 unsigned char tarval_sub_bits(tarval *tv, unsigned byte_ofs)
1142 switch (get_mode_sort(tv->mode)) {
1143 case irms_int_number:
1144 case irms_character:
1145 return sc_sub_bits(tv->value, tv->length, byte_ofs);
1147 case irms_float_number:
1148 return fc_sub_bits(tv->value, get_mode_size_bits(tv->mode), byte_ofs);
1156 * Specify the output options of one mode.
1158 * This functions stores the modinfo, so DO NOT DESTROY it.
1160 * Returns zero on success.
1162 int tarval_set_mode_output_option(ir_mode *mode, const tarval_mode_info *modeinfo)
1166 mode->tv_priv = modeinfo;
1170 /* Identifying some tarvals ??? */
1171 /* Implemented in old tv.c as such:
1172 * return 0 for additive neutral,
1173 * 1 for multiplicative neutral,
1174 * -1 for bitwise-and neutral
1177 * Implemented for completeness */
1178 long tarval_classify(tarval *tv)
1181 if (!tv || tv == tarval_bad) return 2;
1183 if (tv == get_mode_null(tv->mode)) return 0;
1184 else if (tv == get_mode_one(tv->mode)) return 1;
1185 else if ((get_mode_sort(tv->mode) == irms_int_number)
1186 && (tv == new_tarval_from_long(-1, tv->mode))) return -1;
1192 * Initialization of the tarval module: called before init_mode()
1194 void init_tarval_1(void)
1197 /* initialize the sets holding the tarvals with a comparison function and
1198 * an initial size, which is the expected number of constants */
1199 tarvals = new_set(memcmp, TUNE_NCONSTANTS);
1200 values = new_set(memcmp, TUNE_NCONSTANTS);
1201 /* init with default precision */
1203 /* init_fltcalc(0); not yet*/
1207 * default mode_info for output as HEX
1209 static const tarval_mode_info hex_output = {
1216 * Initialization of the tarval module: called after init_mode()
1218 void init_tarval_2(void)
1222 tarval_bad = (tarval*)malloc(sizeof(tarval));
1223 tarval_bad->mode = NULL;
1225 tarval_undefined = (tarval*)malloc(sizeof(tarval));
1226 tarval_undefined->mode = NULL;
1228 tarval_b_true = (tarval*)malloc(sizeof(tarval));
1229 tarval_b_true->mode = mode_b;
1231 tarval_b_false = (tarval*)malloc(sizeof(tarval));
1232 tarval_b_false->mode = mode_b;
1234 tarval_P_void = (tarval*)malloc(sizeof(tarval));
1235 tarval_P_void->mode = mode_P;
1238 * assign output modes that are compatible with the
1239 * old implementation: Hex output
1241 tarval_set_mode_output_option(mode_U, &hex_output);
1242 tarval_set_mode_output_option(mode_C, &hex_output);
1243 tarval_set_mode_output_option(mode_Bs, &hex_output);
1244 tarval_set_mode_output_option(mode_Bu, &hex_output);
1245 tarval_set_mode_output_option(mode_Hs, &hex_output);
1246 tarval_set_mode_output_option(mode_Hu, &hex_output);
1247 tarval_set_mode_output_option(mode_Hs, &hex_output);
1248 tarval_set_mode_output_option(mode_Hu, &hex_output);
1249 tarval_set_mode_output_option(mode_Is, &hex_output);
1250 tarval_set_mode_output_option(mode_Iu, &hex_output);
1251 tarval_set_mode_output_option(mode_Ls, &hex_output);
1252 tarval_set_mode_output_option(mode_Lu, &hex_output);
1255 /****************************************************************************
1257 ****************************************************************************/