2 * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved.
4 * This file is part of libFirm.
6 * This file may be distributed and/or modified under the terms of the
7 * GNU General Public License version 2 as published by the Free Software
8 * Foundation and appearing in the file LICENSE.GPL included in the
9 * packaging of this file.
11 * Licensees holding valid libFirm Professional Edition licenses may use
12 * this file in accordance with the libFirm Commercial License.
13 * Agreement provided with the Software.
15 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * @brief Representation of and static computations on target machine
25 * @author Mathias Heil
29 * Values are stored in a format depending upon chosen arithmetic
30 * module. Default uses strcalc and fltcalc.
31 * This implementation assumes:
32 * - target has IEEE-754 floating-point arithmetic.
38 #include <assert.h> /* assertions */
39 #include <stdlib.h> /* atoi() */
41 # include <string.h> /* nice things for strings */
44 #include <strings.h> /* strings.h also includes bsd only function strcasecmp */
51 #include "set.h" /* to store tarvals in */
52 #include "entity_t.h" /* needed to store pointers to entities */
54 #include "irnode.h" /* defines boolean return values (pnc_number)*/
59 #include "firm_common.h"
62 /** Size of hash tables. Should correspond to average number of distinct constant
64 #define N_CONSTANTS 2048
66 /* get the integer overflow mode */
67 #define GET_OVERFLOW_MODE() int_overflow_mode
69 /* unused, float to int doesn't work yet */
70 enum float_to_int_mode {
75 #define GET_FLOAT_TO_INT_MODE() TRUNCATE
77 #define SWITCH_NOINFINITY 0
78 #define SWITCH_NODENORMALS 0
80 /****************************************************************************
81 * local definitions and macros
82 ****************************************************************************/
84 # define TARVAL_VERIFY(a) tarval_verify((a))
86 # define TARVAL_VERIFY(a) ((void)0)
89 #define INSERT_TARVAL(tv) ((tarval*)set_insert(tarvals, (tv), sizeof(tarval), hash_tv((tv))))
90 #define FIND_TARVAL(tv) ((tarval*)set_find(tarvals, (tv), sizeof(tarval), hash_tv((tv))))
92 #define INSERT_VALUE(val, size) (set_insert(values, (val), size, hash_val((val), size)))
93 #define FIND_VALUE(val, size) (set_find(values, (val), size, hash_val((val), size)))
95 #define fail_verify(a) _fail_verify((a), __FILE__, __LINE__)
97 /****************************************************************************
99 ****************************************************************************/
100 static struct set *tarvals = NULL; /* container for tarval structs */
101 static struct set *values = NULL; /* container for values */
102 static tarval_int_overflow_mode_t int_overflow_mode = TV_OVERFLOW_WRAP;
104 /** if this is set non-zero, the constant folding for floating point is OFF */
105 static int no_float = 0;
107 static const ieee_descriptor_t single_desc = { 8, 23, 0, NORMAL };
108 static const ieee_descriptor_t double_desc = { 11, 52, 0, NORMAL };
109 static const ieee_descriptor_t extended_desc = { 15, 63, 1, NORMAL };
111 /****************************************************************************
113 ****************************************************************************/
115 static int hash_val(const void *value, unsigned int length);
116 static int hash_tv(tarval *tv);
117 static void _fail_verify(tarval *tv, const char* file, int line)
119 /* print a memory image of the tarval and throw an assertion */
121 printf("%s:%d: Invalid tarval:\n mode: %s\n value: [%p]\n", file, line, get_mode_name(tv->mode), tv->value);
123 printf("%s:%d: Invalid tarval (null)", file, line);
127 INLINE static void tarval_verify(tarval *tv) __attribute__ ((unused));
130 INLINE static void tarval_verify(tarval *tv)
136 if ((tv == tarval_bad) || (tv == tarval_undefined)) return;
137 if ((tv == tarval_b_true) || (tv == tarval_b_false)) return;
139 if (!FIND_TARVAL(tv)) fail_verify(tv);
140 if (tv->length > 0 && !FIND_VALUE(tv->value, tv->length)) fail_verify(tv);
144 /** Hash a tarval. */
145 static int hash_tv(tarval *tv) {
146 return (PTR_TO_INT(tv->value) ^ PTR_TO_INT(tv->mode)) + tv->length;
149 /** Hash a value. Treat it as a byte array. */
150 static int hash_val(const void *value, unsigned int length) {
152 unsigned int hash = 0;
154 /* scramble the byte - array */
155 for (i = 0; i < length; ++i) {
156 hash += (hash << 5) ^ (hash >> 27) ^ ((char*)value)[i];
157 hash += (hash << 11) ^ (hash >> 17);
163 static int cmp_tv(const void *p1, const void *p2, size_t n) {
164 const tarval *tv1 = p1;
165 const tarval *tv2 = p2;
168 assert(tv1->kind == k_tarval);
169 assert(tv2->kind == k_tarval);
170 if(tv1->mode < tv2->mode)
172 if(tv1->mode > tv2->mode)
174 if(tv1->length < tv2->length)
176 if(tv1->length > tv2->length)
178 if(tv1->value < tv2->value)
180 if(tv1->value > tv2->value)
186 /** finds tarval with value/mode or creates new tarval */
187 static tarval *get_tarval(const void *value, int length, ir_mode *mode) {
194 /* if there already is such a value, it is returned, else value
195 * is copied into the set */
196 char *temp = alloca(length);
197 memcpy(temp, value, length);
198 if (get_mode_arithmetic(mode) == irma_twos_complement) {
199 sign_extend(temp, mode);
201 tv.value = INSERT_VALUE(temp, length);
205 /* if there is such a tarval, it is returned, else tv is copied
207 return (tarval *)INSERT_TARVAL(&tv);
213 static tarval *get_tarval_overflow(const void *value, int length, ir_mode *mode)
217 switch (get_mode_sort(mode)) {
219 /* addresses always wrap around */
220 temp = alloca(sc_get_buffer_length());
221 memcpy(temp, value, sc_get_buffer_length());
222 sc_truncate(get_mode_size_bits(mode), temp);
223 /* the sc_ module expects that all bits are set ... */
224 sign_extend(temp, mode);
225 return get_tarval(temp, length, mode);
227 case irms_int_number:
228 if (sc_comp(value, get_mode_max(mode)->value) == 1) {
229 switch (GET_OVERFLOW_MODE()) {
230 case TV_OVERFLOW_SATURATE:
231 return get_mode_max(mode);
232 case TV_OVERFLOW_WRAP:
233 temp = alloca(sc_get_buffer_length());
234 memcpy(temp, value, sc_get_buffer_length());
235 sc_truncate(get_mode_size_bits(mode), temp);
236 /* the sc_ module expects that all bits are set ... */
237 sign_extend(temp, mode);
238 return get_tarval(temp, length, mode);
239 case TV_OVERFLOW_BAD:
242 return get_tarval(value, length, mode);
245 if (sc_comp(value, get_mode_min(mode)->value) == -1) {
246 switch (GET_OVERFLOW_MODE()) {
247 case TV_OVERFLOW_SATURATE:
248 return get_mode_min(mode);
249 case TV_OVERFLOW_WRAP: {
250 char *temp = alloca(sc_get_buffer_length());
251 memcpy(temp, value, sc_get_buffer_length());
252 sc_truncate(get_mode_size_bits(mode), temp);
253 return get_tarval(temp, length, mode);
255 case TV_OVERFLOW_BAD:
258 return get_tarval(value, length, mode);
263 case irms_float_number:
264 if (SWITCH_NOINFINITY && fc_is_inf(value)) {
265 /* clip infinity to maximum value */
266 return fc_is_negative(value) ? get_mode_min(mode) : get_mode_max(mode);
269 if (SWITCH_NODENORMALS && fc_is_subnormal(value)) {
270 /* clip denormals to zero */
271 return get_mode_null(mode);
278 return get_tarval(value, length, mode);
282 * public variables declared in tv.h
284 static tarval reserved_tv[6];
286 tarval *tarval_b_false = &reserved_tv[0];
287 tarval *tarval_b_true = &reserved_tv[1];
288 tarval *tarval_bad = &reserved_tv[2];
289 tarval *tarval_undefined = &reserved_tv[3];
290 tarval *tarval_reachable = &reserved_tv[4];
291 tarval *tarval_unreachable = &reserved_tv[5];
294 * public functions declared in tv.h
298 * Constructors =============================================================
300 tarval *new_tarval_from_str(const char *str, size_t len, ir_mode *mode)
306 switch (get_mode_sort(mode)) {
307 case irms_control_flow:
313 case irms_internal_boolean:
314 /* match [tT][rR][uU][eE]|[fF][aA][lL][sS][eE] */
315 if (strcasecmp(str, "true"))
316 return tarval_b_true;
317 else if (strcasecmp(str, "false"))
318 return tarval_b_true;
320 /* XXX This is C semantics */
321 return atoi(str) ? tarval_b_true : tarval_b_false;
323 case irms_float_number:
324 switch (get_mode_size_bits(mode)) {
326 fc_val_from_str(str, len, &single_desc, NULL);
329 fc_val_from_str(str, len, &double_desc, NULL);
333 fc_val_from_str(str, len, &extended_desc, NULL);
336 panic("Unsupported mode in new_tarval_from_str()");
338 return get_tarval(fc_get_buffer(), fc_get_buffer_length(), mode);
341 /* same as integer modes */
342 case irms_int_number:
343 sc_val_from_str(str, len, NULL, mode);
344 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), mode);
347 assert(0); /* can't be reached, can it? */
352 * helper function, create a tarval from long
354 tarval *new_tarval_from_long(long l, ir_mode *mode) {
357 switch (get_mode_sort(mode)) {
358 case irms_internal_boolean:
359 /* XXX C semantics ! */
360 return l ? tarval_b_true : tarval_b_false ;
363 /* same as integer modes */
364 case irms_int_number:
365 sc_val_from_long(l, NULL);
366 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), mode);
368 case irms_float_number:
369 return new_tarval_from_double((long double)l, mode);
372 assert(0 && "unsupported mode sort");
377 /* returns non-zero if can be converted to long */
378 int tarval_is_long(tarval *tv) {
379 if (!mode_is_int(tv->mode) && !mode_is_reference(tv->mode))
382 if (get_mode_size_bits(tv->mode) > (int) (sizeof(long) << 3)) {
383 /* the value might be too big to fit in a long */
384 sc_max_from_bits(sizeof(long) << 3, 0, NULL);
385 if (sc_comp(sc_get_buffer(), tv->value) == -1) {
386 /* really doesn't fit */
393 /* this might overflow the machine's long, so use only with small values */
394 long get_tarval_long(tarval* tv) {
395 assert(tarval_is_long(tv) && "tarval too big to fit in long");
397 return sc_val_to_long(tv->value);
400 tarval *new_tarval_from_double(long double d, ir_mode *mode) {
401 assert(mode && (get_mode_sort(mode) == irms_float_number));
403 switch (get_mode_size_bits(mode)) {
405 fc_val_from_ieee754(d, &single_desc, NULL);
408 fc_val_from_ieee754(d, &double_desc, NULL);
412 fc_val_from_ieee754(d, &extended_desc, NULL);
415 panic("Unsupported mode in new_tarval_from_double()");
417 return get_tarval(fc_get_buffer(), fc_get_buffer_length(), mode);
420 /* returns non-zero if can be converted to double */
421 int tarval_is_double(tarval *tv) {
424 return (get_mode_sort(tv->mode) == irms_float_number);
427 long double get_tarval_double(tarval *tv) {
428 assert(tarval_is_double(tv));
430 return fc_val_to_ieee754(tv->value);
435 * Access routines for tarval fields ========================================
438 /* get the mode of the tarval */
439 ir_mode *(get_tarval_mode)(const tarval *tv) {
440 return _get_tarval_mode(tv);
444 * Special value query functions ============================================
446 * These functions calculate and return a tarval representing the requested
448 * The functions get_mode_{Max,Min,...} return tarvals retrieved from these
449 * functions, but these are stored on initialization of the irmode module and
450 * therefore the irmode functions should be preferred to the functions below.
453 tarval *(get_tarval_bad)(void) {
454 return _get_tarval_bad();
457 tarval *(get_tarval_undefined)(void) {
458 return _get_tarval_undefined();
461 tarval *(get_tarval_b_false)(void) {
462 return _get_tarval_b_false();
465 tarval *(get_tarval_b_true)(void) {
466 return _get_tarval_b_true();
469 tarval *(get_tarval_reachable)(void) {
470 return _get_tarval_reachable();
473 tarval *(get_tarval_unreachable)(void) {
474 return _get_tarval_unreachable();
477 tarval *get_tarval_max(ir_mode *mode) {
480 if (get_mode_n_vector_elems(mode) > 1) {
481 /* vector arithmetic not implemented yet */
485 switch(get_mode_sort(mode)) {
486 case irms_control_flow:
492 case irms_internal_boolean:
493 return tarval_b_true;
495 case irms_float_number:
496 switch(get_mode_size_bits(mode)) {
498 fc_get_max(&single_desc, NULL);
501 fc_get_max(&double_desc, NULL);
505 fc_get_max(&extended_desc, NULL);
508 panic("Unsupported mode in get_tarval_max()");
510 return get_tarval(fc_get_buffer(), fc_get_buffer_length(), mode);
513 case irms_int_number:
514 sc_max_from_bits(get_mode_size_bits(mode), mode_is_signed(mode), NULL);
515 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), mode);
520 tarval *get_tarval_min(ir_mode *mode) {
521 ieee_descriptor_t desc;
525 if (get_mode_n_vector_elems(mode) > 1) {
526 /* vector arithmetic not implemented yet */
530 switch (get_mode_sort(mode)) {
531 case irms_control_flow:
537 case irms_internal_boolean:
538 return tarval_b_false;
540 case irms_float_number:
541 switch(get_mode_size_bits(mode)) {
543 desc.exponent_size = 8;
544 desc.mantissa_size = 23;
545 desc.explicit_one = 0;
547 fc_get_min(&desc, NULL);
550 desc.exponent_size = 11;
551 desc.mantissa_size = 52;
552 desc.explicit_one = 0;
554 fc_get_min(&desc, NULL);
558 desc.exponent_size = 15;
559 desc.mantissa_size = 64;
560 desc.explicit_one = 1;
562 fc_get_min(&desc, NULL);
565 panic("Unsupported mode in get_tarval_min()");
567 return get_tarval(fc_get_buffer(), fc_get_buffer_length(), mode);
570 case irms_int_number:
571 sc_min_from_bits(get_mode_size_bits(mode), mode_is_signed(mode), NULL);
572 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), mode);
577 /** The bit pattern for the pointer NULL */
578 static long _null_value = 0;
580 tarval *get_tarval_null(ir_mode *mode) {
583 if (get_mode_n_vector_elems(mode) > 1) {
584 /* vector arithmetic not implemented yet */
588 switch(get_mode_sort(mode)) {
589 case irms_control_flow:
595 case irms_float_number:
596 return new_tarval_from_double(0.0, mode);
598 case irms_internal_boolean:
599 case irms_int_number:
600 return new_tarval_from_long(0l, mode);
603 return new_tarval_from_long(_null_value, mode);
608 tarval *get_tarval_one(ir_mode *mode) {
611 if (get_mode_n_vector_elems(mode) > 1) {
612 /* vector arithmetic not implemented yet */
617 switch(get_mode_sort(mode)) {
618 case irms_control_flow:
624 case irms_internal_boolean:
625 return tarval_b_true;
627 case irms_float_number:
628 return new_tarval_from_double(1.0, mode);
631 case irms_int_number:
632 return new_tarval_from_long(1l, mode);
637 tarval *get_tarval_all_one(ir_mode *mode) {
640 if (get_mode_n_vector_elems(mode) > 1) {
641 /* vector arithmetic not implemented yet */
646 switch(get_mode_sort(mode)) {
647 case irms_control_flow:
653 case irms_int_number:
654 case irms_internal_boolean:
656 return tarval_not(get_mode_null(mode));
659 case irms_float_number:
660 return new_tarval_from_double(1.0, mode);
665 int tarval_is_constant(tarval *tv) {
666 int num_res = sizeof(reserved_tv) / sizeof(reserved_tv[0]);
668 /* reserved tarvals are NOT constants. Note that although
669 tarval_b_true and tarval_b_false are reserved, they are constants of course. */
670 return (tv < &reserved_tv[2] || tv > &reserved_tv[num_res - 1]);
673 tarval *get_tarval_minus_one(ir_mode *mode) {
676 if (get_mode_n_vector_elems(mode) > 1) {
677 /* vector arithmetic not implemented yet */
681 switch(get_mode_sort(mode)) {
682 case irms_control_flow:
685 case irms_internal_boolean:
692 case irms_float_number:
693 return mode_is_signed(mode) ? new_tarval_from_double(-1.0, mode) : tarval_bad;
695 case irms_int_number:
696 return new_tarval_from_long(-1l, mode);
701 tarval *get_tarval_nan(ir_mode *mode) {
702 ieee_descriptor_t desc;
706 if (get_mode_n_vector_elems(mode) > 1) {
707 /* vector arithmetic not implemented yet */
711 if (get_mode_sort(mode) == irms_float_number) {
712 switch(get_mode_size_bits(mode)) {
714 desc.exponent_size = 8;
715 desc.mantissa_size = 23;
716 desc.explicit_one = 0;
718 fc_get_qnan(&desc, NULL);
721 desc.exponent_size = 11;
722 desc.mantissa_size = 52;
723 desc.explicit_one = 0;
725 fc_get_qnan(&desc, NULL);
729 desc.exponent_size = 15;
730 desc.mantissa_size = 64;
731 desc.explicit_one = 1;
733 fc_get_qnan(&desc, NULL);
736 panic("Unsupported mode in get_tarval_nan()");
738 return get_tarval(fc_get_buffer(), fc_get_buffer_length(), mode);
740 assert(0 && "tarval is not floating point");
745 tarval *get_tarval_plus_inf(ir_mode *mode) {
746 ieee_descriptor_t desc;
750 if (get_mode_n_vector_elems(mode) > 1) {
751 /* vector arithmetic not implemented yet */
755 if (get_mode_sort(mode) == irms_float_number) {
756 switch(get_mode_size_bits(mode)) {
758 desc.exponent_size = 8;
759 desc.mantissa_size = 23;
760 desc.explicit_one = 0;
762 fc_get_plusinf(&desc, NULL);
765 desc.exponent_size = 11;
766 desc.mantissa_size = 52;
767 desc.explicit_one = 0;
769 fc_get_plusinf(&desc, NULL);
773 desc.exponent_size = 15;
774 desc.mantissa_size = 64;
775 desc.explicit_one = 1;
777 fc_get_plusinf(&desc, NULL);
780 panic("Unsupported mode in get_tarval_plus_inf()");
782 return get_tarval(fc_get_buffer(), fc_get_buffer_length(), mode);
784 assert(0 && "tarval is not floating point");
789 tarval *get_tarval_minus_inf(ir_mode *mode) {
792 if (get_mode_n_vector_elems(mode) > 1) {
793 /* vector arithmetic not implemented yet */
797 if (get_mode_sort(mode) == irms_float_number) {
798 switch(get_mode_size_bits(mode)) {
800 fc_get_minusinf(&single_desc, NULL);
803 fc_get_minusinf(&double_desc, NULL);
807 fc_get_minusinf(&extended_desc, NULL);
810 panic("Unsupported mode in get_tarval_minus_inf()");
812 return get_tarval(fc_get_buffer(), fc_get_buffer_length(), mode);
814 assert(0 && "tarval is not floating point");
820 * Arithmethic operations on tarvals ========================================
824 * test if negative number, 1 means 'yes'
826 int tarval_is_negative(tarval *a) {
829 if (get_mode_n_vector_elems(a->mode) > 1) {
830 /* vector arithmetic not implemented yet */
831 assert(0 && "tarval_is_negative is not allowed for vector modes");
835 switch (get_mode_sort(a->mode)) {
836 case irms_int_number:
837 if (!mode_is_signed(a->mode)) return 0;
839 return sc_comp(a->value, get_mode_null(a->mode)->value) == -1 ? 1 : 0;
841 case irms_float_number:
842 return fc_is_negative(a->value);
845 assert(0 && "not implemented");
851 * test if null, 1 means 'yes'
853 int tarval_is_null(tarval *a) {
856 a == get_mode_null(get_tarval_mode(a));
860 * test if one, 1 means 'yes'
862 int tarval_is_one(tarval *a) {
865 a == get_mode_one(get_tarval_mode(a));
868 int tarval_is_all_one(tarval *tv) {
871 tv == get_mode_all_one(get_tarval_mode(tv));
875 * test if one, 1 means 'yes'
877 int tarval_is_minus_one(tarval *a) {
880 a == get_mode_minus_one(get_tarval_mode(a));
886 pn_Cmp tarval_cmp(tarval *a, tarval *b) {
890 if (a == tarval_bad || b == tarval_bad) {
891 assert(0 && "Comparison with tarval_bad");
895 if (a == tarval_undefined || b == tarval_undefined)
898 if (a->mode != b->mode)
901 if (get_mode_n_vector_elems(a->mode) > 1) {
902 /* vector arithmetic not implemented yet */
903 assert(0 && "cmp not implemented for vector modes");
906 /* Here the two tarvals are unequal and of the same mode */
907 switch (get_mode_sort(a->mode)) {
908 case irms_control_flow:
915 case irms_float_number:
916 /* it should be safe to enable this even if other arithmetic is disabled */
918 return pn_Cmp_False;*/
920 * BEWARE: we cannot compare a == b here, because
921 * a NaN is always Unordered to any other value, even to itself!
923 switch (fc_comp(a->value, b->value)) {
924 case -1: return pn_Cmp_Lt;
925 case 0: return pn_Cmp_Eq;
926 case 1: return pn_Cmp_Gt;
927 case 2: return pn_Cmp_Uo;
928 default: return pn_Cmp_False;
931 case irms_int_number:
934 return sc_comp(a->value, b->value) == 1 ? pn_Cmp_Gt : pn_Cmp_Lt;
936 case irms_internal_boolean:
939 return a == tarval_b_true ? pn_Cmp_Gt : pn_Cmp_Lt;
945 * convert to other mode
947 tarval *tarval_convert_to(tarval *src, ir_mode *dst_mode) {
954 if (src->mode == dst_mode)
957 if (get_mode_n_vector_elems(src->mode) > 1) {
958 /* vector arithmetic not implemented yet */
962 switch (get_mode_sort(src->mode)) {
963 case irms_control_flow:
968 /* cast float to something */
969 case irms_float_number:
970 switch (get_mode_sort(dst_mode)) {
971 case irms_float_number:
972 switch (get_mode_size_bits(dst_mode)) {
974 fc_cast(src->value, &single_desc, NULL);
977 fc_cast(src->value, &double_desc, NULL);
981 fc_cast(src->value, &extended_desc, NULL);
984 panic("Unsupported mode in tarval_convert_to()");
986 return get_tarval(fc_get_buffer(), fc_get_buffer_length(), dst_mode);
988 case irms_int_number:
989 switch (GET_FLOAT_TO_INT_MODE()) {
991 res = fc_int(src->value, NULL);
994 res = fc_rnd(src->value, NULL);
997 panic("Unsupported float to int conversion mode in tarval_convert_to()");
1000 buffer = alloca(sc_get_buffer_length());
1001 if (! fc_flt2int(res, buffer, dst_mode))
1003 return get_tarval(buffer, sc_get_buffer_length(), dst_mode);
1006 /* the rest can't be converted */
1011 /* cast int/characters to something */
1012 case irms_int_number:
1013 switch (get_mode_sort(dst_mode)) {
1015 case irms_reference:
1016 case irms_int_number:
1017 buffer = alloca(sc_get_buffer_length());
1018 memcpy(buffer, src->value, sc_get_buffer_length());
1019 sign_extend(buffer, dst_mode);
1020 return get_tarval_overflow(buffer, src->length, dst_mode);
1022 case irms_internal_boolean:
1023 /* XXX C semantics */
1024 if (src == get_mode_null(src->mode)) return tarval_b_false;
1025 else return tarval_b_true;
1027 case irms_float_number:
1028 /* XXX floating point unit does not understand internal integer
1029 * representation, convert to string first, then create float from
1031 buffer = alloca(100);
1032 /* decimal string representation because hexadecimal output is
1033 * interpreted unsigned by fc_val_from_str, so this is a HACK */
1034 snprintf(buffer, 100, "%s",
1035 sc_print(src->value, get_mode_size_bits(src->mode), SC_DEC, mode_is_signed(src->mode)));
1036 buffer[100 - 1] = '\0';
1037 switch (get_mode_size_bits(dst_mode)) {
1039 fc_val_from_str(buffer, 0, &single_desc, NULL);
1042 fc_val_from_str(buffer, 0, &double_desc, NULL);
1046 fc_val_from_str(buffer, 0, &extended_desc, NULL);
1049 panic("Unsupported mode in tarval_convert_to()");
1051 return get_tarval(fc_get_buffer(), fc_get_buffer_length(), dst_mode);
1058 case irms_internal_boolean:
1059 /* beware: this is C semantic for the INTERNAL boolean mode */
1060 if (get_mode_sort(dst_mode) == irms_int_number)
1061 return src == tarval_b_true ? get_mode_one(dst_mode) : get_mode_null(dst_mode);
1064 case irms_reference:
1065 if (get_mode_sort(dst_mode) == irms_int_number) {
1066 buffer = alloca(sc_get_buffer_length());
1067 memcpy(buffer, src->value, sc_get_buffer_length());
1068 sign_extend(buffer, src->mode);
1069 return get_tarval_overflow(buffer, src->length, dst_mode);
1080 tarval *tarval_not(tarval *a) {
1085 /* works for vector mode without changes */
1087 switch (get_mode_sort(a->mode)) {
1088 case irms_reference:
1089 case irms_int_number:
1090 buffer = alloca(sc_get_buffer_length());
1091 sc_not(a->value, buffer);
1092 return get_tarval(buffer, a->length, a->mode);
1094 case irms_internal_boolean:
1095 if (a == tarval_b_true)
1096 return tarval_b_false;
1097 if (a == tarval_b_false)
1098 return tarval_b_true;
1102 assert(0 && "bitwise negation is only allowed for integer and boolean");
1108 * arithmetic negation
1110 tarval *tarval_neg(tarval *a) {
1114 assert(mode_is_num(a->mode)); /* negation only for numerical values */
1116 /* note: negation is allowed even for unsigned modes. */
1118 if (get_mode_n_vector_elems(a->mode) > 1) {
1119 /* vector arithmetic not implemented yet */
1123 switch (get_mode_sort(a->mode)) {
1124 case irms_int_number:
1125 buffer = alloca(sc_get_buffer_length());
1126 sc_neg(a->value, buffer);
1127 return get_tarval_overflow(buffer, a->length, a->mode);
1129 case irms_float_number:
1130 /* it should be safe to enable this even if other arithmetic is disabled */
1132 return tarval_bad;*/
1134 fc_neg(a->value, NULL);
1135 return get_tarval_overflow(fc_get_buffer(), fc_get_buffer_length(), a->mode);
1145 tarval *tarval_add(tarval *a, tarval *b) {
1148 ir_mode *imm_mode, *dst_mode = NULL;
1153 if (get_mode_n_vector_elems(a->mode) > 1 || get_mode_n_vector_elems(b->mode) > 1) {
1154 /* vector arithmetic not implemented yet */
1158 if (mode_is_reference(a->mode)) {
1160 imm_mode = find_unsigned_mode(a->mode);
1162 if (imm_mode == NULL)
1165 a = tarval_convert_to(a, imm_mode);
1166 b = tarval_convert_to(b, imm_mode);
1168 if (mode_is_reference(b->mode)) {
1170 imm_mode = find_unsigned_mode(b->mode);
1175 a = tarval_convert_to(a, imm_mode);
1176 b = tarval_convert_to(b, imm_mode);
1179 assert(a->mode == b->mode);
1181 switch (get_mode_sort(a->mode)) {
1182 case irms_int_number:
1183 /* modes of a,b are equal, so result has mode of a as this might be the character */
1184 buffer = alloca(sc_get_buffer_length());
1185 sc_add(a->value, b->value, buffer);
1186 res = get_tarval_overflow(buffer, a->length, a->mode);
1189 case irms_float_number:
1193 fc_add(a->value, b->value, NULL);
1194 res = get_tarval_overflow(fc_get_buffer(), fc_get_buffer_length(), a->mode);
1200 if (dst_mode != NULL)
1201 return tarval_convert_to(res, dst_mode);
1208 tarval *tarval_sub(tarval *a, tarval *b, ir_mode *dst_mode) {
1214 if (get_mode_n_vector_elems(a->mode) > 1 || get_mode_n_vector_elems(b->mode) > 1) {
1215 /* vector arithmetic not implemented yet */
1219 if (dst_mode != NULL) {
1220 if (mode_is_reference(a->mode)) {
1221 a = tarval_convert_to(a, dst_mode);
1223 if (mode_is_reference(b->mode)) {
1224 b = tarval_convert_to(b, dst_mode);
1226 assert(a->mode == dst_mode);
1228 assert(a->mode == b->mode);
1230 switch (get_mode_sort(a->mode)) {
1231 case irms_int_number:
1232 /* modes of a,b are equal, so result has mode of a as this might be the character */
1233 buffer = alloca(sc_get_buffer_length());
1234 sc_sub(a->value, b->value, buffer);
1235 return get_tarval_overflow(buffer, a->length, a->mode);
1237 case irms_float_number:
1241 fc_sub(a->value, b->value, NULL);
1242 return get_tarval_overflow(fc_get_buffer(), fc_get_buffer_length(), a->mode);
1252 tarval *tarval_mul(tarval *a, tarval *b) {
1257 assert(a->mode == b->mode);
1259 if (get_mode_n_vector_elems(a->mode) > 1) {
1260 /* vector arithmetic not implemented yet */
1264 switch (get_mode_sort(a->mode)) {
1265 case irms_int_number:
1266 /* modes of a,b are equal */
1267 buffer = alloca(sc_get_buffer_length());
1268 sc_mul(a->value, b->value, buffer);
1269 return get_tarval_overflow(buffer, a->length, a->mode);
1271 case irms_float_number:
1275 fc_mul(a->value, b->value, NULL);
1276 return get_tarval_overflow(fc_get_buffer(), fc_get_buffer_length(), a->mode);
1284 * floating point division
1286 tarval *tarval_quo(tarval *a, tarval *b) {
1289 assert((a->mode == b->mode) && mode_is_float(a->mode));
1294 if (get_mode_n_vector_elems(a->mode) > 1) {
1295 /* vector arithmetic not implemented yet */
1299 fc_div(a->value, b->value, NULL);
1300 return get_tarval_overflow(fc_get_buffer(), fc_get_buffer_length(), a->mode);
1305 * overflow is impossible, but look out for division by zero
1307 tarval *tarval_div(tarval *a, tarval *b) {
1310 assert((a->mode == b->mode) && mode_is_int(a->mode));
1312 if (get_mode_n_vector_elems(a->mode) > 1) {
1313 /* vector arithmetic not implemented yet */
1318 if (b == get_mode_null(b->mode)) return tarval_bad;
1319 /* modes of a,b are equal */
1320 sc_div(a->value, b->value, NULL);
1321 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
1326 * overflow is impossible, but look out for division by zero
1328 tarval *tarval_mod(tarval *a, tarval *b) {
1331 assert((a->mode == b->mode) && mode_is_int(a->mode));
1333 if (get_mode_n_vector_elems(a->mode) > 1) {
1334 /* vector arithmetic not implemented yet */
1339 if (b == get_mode_null(b->mode)) return tarval_bad;
1340 /* modes of a,b are equal */
1341 sc_mod(a->value, b->value, NULL);
1342 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
1346 * integer division AND remainder
1347 * overflow is impossible, but look out for division by zero
1349 tarval *tarval_divmod(tarval *a, tarval *b, tarval **mod) {
1350 int len = sc_get_buffer_length();
1351 char *div_res = alloca(len);
1352 char *mod_res = alloca(len);
1356 assert((a->mode == b->mode) && mode_is_int(a->mode));
1358 if (get_mode_n_vector_elems(a->mode) > 1) {
1359 /* vector arithmetic not implemented yet */
1365 if (b == get_mode_null(b->mode)) return tarval_bad;
1366 /* modes of a,b are equal */
1367 sc_divmod(a->value, b->value, div_res, mod_res);
1368 *mod = get_tarval(mod_res, len, a->mode);
1369 return get_tarval(div_res, len, a->mode);
1375 tarval *tarval_abs(tarval *a) {
1379 assert(mode_is_num(a->mode));
1381 if (get_mode_n_vector_elems(a->mode) > 1) {
1382 /* vector arithmetic not implemented yet */
1386 switch (get_mode_sort(a->mode)) {
1387 case irms_int_number:
1388 if (sc_comp(a->value, get_mode_null(a->mode)->value) == -1) {
1389 buffer = alloca(sc_get_buffer_length());
1390 sc_neg(a->value, buffer);
1391 return get_tarval_overflow(buffer, a->length, a->mode);
1395 case irms_float_number:
1396 /* it should be safe to enable this even if other arithmetic is disabled */
1398 return tarval_bad;*/
1400 if (fc_comp(a->value, get_mode_null(a->mode)->value) == -1) {
1401 fc_neg(a->value, NULL);
1402 return get_tarval_overflow(fc_get_buffer(), fc_get_buffer_length(), a->mode);
1415 tarval *tarval_and(tarval *a, tarval *b) {
1418 assert(a->mode == b->mode);
1420 /* works even for vector modes */
1422 switch(get_mode_sort(a->mode)) {
1423 case irms_internal_boolean:
1424 return (a == tarval_b_false) ? a : b;
1426 case irms_int_number:
1427 sc_and(a->value, b->value, NULL);
1428 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
1431 assert(0 && "operation not defined on mode");
1439 tarval *tarval_or(tarval *a, tarval *b) {
1442 assert(a->mode == b->mode);
1444 /* works even for vector modes */
1446 switch (get_mode_sort(a->mode)) {
1447 case irms_internal_boolean:
1448 return (a == tarval_b_true) ? a : b;
1450 case irms_int_number:
1451 sc_or(a->value, b->value, NULL);
1452 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
1455 assert(0 && "operation not defined on mode");
1461 * bitwise exclusive or (xor)
1463 tarval *tarval_eor(tarval *a, tarval *b) {
1466 assert((a->mode == b->mode));
1468 /* works even for vector modes */
1470 switch (get_mode_sort(a->mode)) {
1471 case irms_internal_boolean:
1472 return (a == b)? tarval_b_false : tarval_b_true;
1474 case irms_int_number:
1475 sc_xor(a->value, b->value, NULL);
1476 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
1479 assert(0 && "operation not defined on mode");
1485 * bitwise left shift
1487 tarval *tarval_shl(tarval *a, tarval *b) {
1488 char *temp_val = NULL;
1492 assert(mode_is_int(a->mode) && mode_is_int(b->mode));
1494 if (get_mode_n_vector_elems(a->mode) > 1 || get_mode_n_vector_elems(a->mode) > 1) {
1495 /* vector arithmetic not implemented yet */
1499 if (get_mode_modulo_shift(a->mode) != 0) {
1500 temp_val = alloca(sc_get_buffer_length());
1502 sc_val_from_ulong(get_mode_modulo_shift(a->mode), temp_val);
1503 sc_mod(b->value, temp_val, temp_val);
1505 temp_val = (char*)b->value;
1507 sc_shl(a->value, temp_val, get_mode_size_bits(a->mode), mode_is_signed(a->mode), NULL);
1508 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
1512 * bitwise unsigned right shift
1514 tarval *tarval_shr(tarval *a, tarval *b) {
1515 char *temp_val = NULL;
1519 assert(mode_is_int(a->mode) && mode_is_int(b->mode));
1521 if (get_mode_n_vector_elems(a->mode) > 1 || get_mode_n_vector_elems(a->mode) > 1) {
1522 /* vector arithmetic not implemented yet */
1526 if (get_mode_modulo_shift(a->mode) != 0) {
1527 temp_val = alloca(sc_get_buffer_length());
1529 sc_val_from_ulong(get_mode_modulo_shift(a->mode), temp_val);
1530 sc_mod(b->value, temp_val, temp_val);
1532 temp_val = (char*)b->value;
1534 sc_shr(a->value, temp_val, get_mode_size_bits(a->mode), mode_is_signed(a->mode), NULL);
1535 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
1539 * bitwise signed right shift
1541 tarval *tarval_shrs(tarval *a, tarval *b) {
1542 char *temp_val = NULL;
1546 assert(mode_is_int(a->mode) && mode_is_int(b->mode));
1548 if (get_mode_n_vector_elems(a->mode) > 1 || get_mode_n_vector_elems(a->mode) > 1) {
1549 /* vector arithmetic not implemented yet */
1553 if (get_mode_modulo_shift(a->mode) != 0) {
1554 temp_val = alloca(sc_get_buffer_length());
1556 sc_val_from_ulong(get_mode_modulo_shift(a->mode), temp_val);
1557 sc_mod(b->value, temp_val, temp_val);
1559 temp_val = (char*)b->value;
1561 sc_shrs(a->value, temp_val, get_mode_size_bits(a->mode), mode_is_signed(a->mode), NULL);
1562 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
1566 * bitwise rotation to left
1568 tarval *tarval_rotl(tarval *a, tarval *b) {
1569 char *temp_val = NULL;
1573 assert(mode_is_int(a->mode) && mode_is_int(b->mode));
1575 if (get_mode_n_vector_elems(a->mode) > 1 || get_mode_n_vector_elems(a->mode) > 1) {
1576 /* vector arithmetic not implemented yet */
1580 if (get_mode_modulo_shift(a->mode) != 0) {
1581 temp_val = alloca(sc_get_buffer_length());
1583 sc_val_from_ulong(get_mode_modulo_shift(a->mode), temp_val);
1584 sc_mod(b->value, temp_val, temp_val);
1586 temp_val = (char*)b->value;
1588 sc_rotl(a->value, temp_val, get_mode_size_bits(a->mode), mode_is_signed(a->mode), NULL);
1589 return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode);
1593 * carry flag of the last operation
1595 int tarval_carry(void) {
1596 panic("tarval_carry() requetsed: not implemented on all operations");
1597 return sc_had_carry();
1603 int tarval_snprintf(char *buf, size_t len, tarval *tv) {
1604 static const tarval_mode_info default_info = { TVO_NATIVE, NULL, NULL };
1608 const tarval_mode_info *mode_info;
1609 const char *prefix, *suffix;
1611 mode_info = tv->mode->tv_priv;
1613 mode_info = &default_info;
1614 prefix = mode_info->mode_prefix ? mode_info->mode_prefix : "";
1615 suffix = mode_info->mode_suffix ? mode_info->mode_suffix : "";
1617 switch (get_mode_sort(tv->mode)) {
1618 case irms_reference:
1619 if (tv == tv->mode->null) return snprintf(buf, len, "NULL");
1621 case irms_int_number:
1622 switch (mode_info->mode_output) {
1625 str = sc_print(tv->value, get_mode_size_bits(tv->mode), SC_DEC, mode_is_signed(tv->mode));
1629 str = sc_print(tv->value, get_mode_size_bits(tv->mode), SC_OCT, 0);
1635 str = sc_print(tv->value, get_mode_size_bits(tv->mode), SC_HEX, 0);
1638 return snprintf(buf, len, "%s%s%s", prefix, str, suffix);
1640 case irms_float_number:
1641 switch (mode_info->mode_output) {
1643 return snprintf(buf, len, "%s%s%s", prefix, fc_print(tv->value, tv_buf, sizeof(tv_buf), FC_PACKED), suffix);
1646 return snprintf(buf, len, "%s%s%s", prefix, fc_print(tv->value, tv_buf, sizeof(tv_buf), FC_HEX), suffix);
1651 return snprintf(buf, len, "%s%s%s", prefix, fc_print(tv->value, tv_buf, sizeof(tv_buf), FC_DEC), suffix);
1655 case irms_internal_boolean:
1656 switch (mode_info->mode_output) {
1662 return snprintf(buf, len, "%s%c%s", prefix, (tv == tarval_b_true) ? '1' : '0', suffix);
1666 return snprintf(buf, len, "%s%s%s", prefix, (tv == tarval_b_true) ? "true" : "false", suffix);
1669 case irms_control_flow:
1671 case irms_auxiliary:
1672 if (tv == tarval_bad)
1673 return snprintf(buf, len, "<TV_BAD>");
1674 if (tv == tarval_undefined)
1675 return snprintf(buf, len, "<TV_UNDEF>");
1676 if (tv == tarval_unreachable)
1677 return snprintf(buf, len, "<TV_UNREACHABLE>");
1678 if (tv == tarval_reachable)
1679 return snprintf(buf, len, "<TV_REACHABLE>");
1680 return snprintf(buf, len, "<TV_??""?>");
1687 * Output of tarvals to stdio.
1689 int tarval_printf(tarval *tv) {
1693 res = tarval_snprintf(buf, sizeof(buf), tv);
1694 assert(res < (int) sizeof(buf) && "buffer to small for tarval_snprintf");
1699 char *get_tarval_bitpattern(tarval *tv) {
1701 int n = get_mode_size_bits(tv->mode);
1702 int bytes = (n + 7) / 8;
1703 char *res = xmalloc((n + 1) * sizeof(char));
1706 for(i = 0; i < bytes; i++) {
1707 byte = get_tarval_sub_bits(tv, i);
1708 for(j = 1; j < 256; j <<= 1)
1710 res[pos++] = j & byte ? '1' : '0';
1719 * access to the bitpattern
1721 unsigned char get_tarval_sub_bits(tarval *tv, unsigned byte_ofs) {
1722 switch (get_mode_arithmetic(tv->mode)) {
1723 case irma_twos_complement:
1724 return sc_sub_bits(tv->value, get_mode_size_bits(tv->mode), byte_ofs);
1726 return fc_sub_bits(tv->value, get_mode_size_bits(tv->mode), byte_ofs);
1728 panic("get_tarval_sub_bits(): arithmetic mode not supported");
1733 * Specify the output options of one mode.
1735 * This functions stores the modinfo, so DO NOT DESTROY it.
1737 * Returns zero on success.
1739 int set_tarval_mode_output_option(ir_mode *mode, const tarval_mode_info *modeinfo) {
1742 mode->tv_priv = modeinfo;
1747 * Returns the output options of one mode.
1749 * This functions returns the mode info of a given mode.
1751 const tarval_mode_info *get_tarval_mode_output_option(ir_mode *mode) {
1754 return mode->tv_priv;
1758 * Returns non-zero if a given (integer) tarval has only one single bit
1761 int tarval_is_single_bit(tarval *tv) {
1765 if (!tv || tv == tarval_bad) return 0;
1766 if (! mode_is_int(tv->mode)) return 0;
1768 l = get_mode_size_bytes(tv->mode);
1769 for (bits = 0, i = l - 1; i >= 0; --i) {
1770 unsigned char v = get_tarval_sub_bits(tv, (unsigned)i);
1772 /* check for more than one bit in these */
1784 * Returns non-zero if the mantissa of a floating point IEEE-754
1785 * tarval is zero (i.e. 1.0Exxx)
1787 int tarval_ieee754_zero_mantissa(tarval *tv) {
1788 assert(get_mode_arithmetic(tv->mode) == irma_ieee754);
1789 return fc_zero_mantissa(tv->value);
1792 /* Returns the exponent of a floating point IEEE-754 tarval. */
1793 int tarval_ieee754_get_exponent(tarval *tv) {
1794 assert(get_mode_arithmetic(tv->mode) == irma_ieee754);
1795 return fc_get_exponent(tv->value);
1799 * Check if the tarval can be converted to the given mode without
1802 int tarval_ieee754_can_conv_lossless(tarval *tv, ir_mode *mode) {
1803 char exp_size, mant_size;
1804 switch (get_mode_size_bits(mode)) {
1806 exp_size = 8; mant_size = 23;
1809 exp_size = 11; mant_size = 52;
1813 exp_size = 15; mant_size = 64;
1816 panic("Unsupported mode in tarval_ieee754_can_conv_lossless()");
1819 return fc_can_lossless_conv_to(tv->value, exp_size, mant_size);
1822 /* Set the immediate precision for IEEE-754 results. */
1823 unsigned tarval_ieee754_set_immediate_precision(unsigned bits) {
1824 return fc_set_immediate_precision(bits);
1827 /* Returns non-zero if the result of the last IEEE-754 operation was exact. */
1828 unsigned tarval_ieee754_get_exact(void) {
1829 return fc_is_exact();
1832 /* check if its the a floating point NaN */
1833 int tarval_is_NaN(tarval *tv) {
1834 if (! mode_is_float(tv->mode))
1836 return fc_is_nan(tv->value);
1839 /* check if its the a floating point +inf */
1840 int tarval_is_plus_inf(tarval *tv) {
1841 if (! mode_is_float(tv->mode))
1843 return fc_is_inf(tv->value) && !fc_is_negative(tv->value);
1846 /* check if its the a floating point -inf */
1847 int tarval_is_minus_inf(tarval *tv) {
1848 if (! mode_is_float(tv->mode))
1850 return fc_is_inf(tv->value) && fc_is_negative(tv->value);
1853 /* check if the tarval represents a finite value */
1854 int tarval_is_finite(tarval *tv) {
1855 if (mode_is_float(tv->mode))
1856 return !fc_is_nan(tv->value) && !fc_is_inf(tv->value);
1861 * Sets the overflow mode for integer operations.
1863 void tarval_set_integer_overflow_mode(tarval_int_overflow_mode_t ov_mode) {
1864 int_overflow_mode = ov_mode;
1867 /* Get the overflow mode for integer operations. */
1868 tarval_int_overflow_mode_t tarval_get_integer_overflow_mode(void) {
1869 return int_overflow_mode;
1872 /* Enable/Disable floating point constant folding. */
1873 int tarval_enable_fp_ops(int enable) {
1874 int old = !no_float;
1881 * default mode_info for output as HEX
1883 static const tarval_mode_info hex_output = {
1890 * Initialization of the tarval module: called before init_mode()
1892 void init_tarval_1(long null_value) {
1893 /* if these assertion fail, tarval_is_constant() will follow ... */
1894 assert(tarval_b_false == &reserved_tv[0] && "b_false MUST be the first reserved tarval!");
1895 assert(tarval_b_true == &reserved_tv[1] && "b_true MUST be the second reserved tarval!");
1897 _null_value = null_value;
1899 /* initialize the sets holding the tarvals with a comparison function and
1900 * an initial size, which is the expected number of constants */
1901 tarvals = new_set(cmp_tv, N_CONSTANTS);
1902 values = new_set(memcmp, N_CONSTANTS);
1903 /* init strcalc with precision of 68 to support floating point values with 64
1904 * bit mantissa (needs extra bits for rounding and overflow) */
1910 * Initialization of the tarval module: called after init_mode()
1912 void init_tarval_2(void) {
1913 tarval_bad->kind = k_tarval;
1914 tarval_bad->mode = mode_BAD;
1915 tarval_bad->value = INT_TO_PTR(resid_tarval_bad);
1917 tarval_undefined->kind = k_tarval;
1918 tarval_undefined->mode = mode_ANY;
1919 tarval_undefined->value = INT_TO_PTR(resid_tarval_undefined);
1921 tarval_b_true->kind = k_tarval;
1922 tarval_b_true->mode = mode_b;
1923 tarval_b_true->value = INT_TO_PTR(resid_tarval_b_true);
1925 tarval_b_false->kind = k_tarval;
1926 tarval_b_false->mode = mode_b;
1927 tarval_b_false->value = INT_TO_PTR(resid_tarval_b_false);
1929 tarval_unreachable->kind = k_tarval;
1930 tarval_unreachable->mode = mode_X;
1931 tarval_unreachable->value = INT_TO_PTR(resid_tarval_unreachable);
1933 tarval_reachable->kind = k_tarval;
1934 tarval_reachable->mode = mode_X;
1935 tarval_reachable->value = INT_TO_PTR(resid_tarval_reachable);
1938 * assign output modes that are compatible with the
1939 * old implementation: Hex output
1941 set_tarval_mode_output_option(mode_Bs, &hex_output);
1942 set_tarval_mode_output_option(mode_Bu, &hex_output);
1943 set_tarval_mode_output_option(mode_Hs, &hex_output);
1944 set_tarval_mode_output_option(mode_Hu, &hex_output);
1945 set_tarval_mode_output_option(mode_Is, &hex_output);
1946 set_tarval_mode_output_option(mode_Iu, &hex_output);
1947 set_tarval_mode_output_option(mode_Ls, &hex_output);
1948 set_tarval_mode_output_option(mode_Lu, &hex_output);
1949 set_tarval_mode_output_option(mode_P, &hex_output);
1952 /* free all memory occupied by tarval. */
1953 void finish_tarval(void) {
1956 del_set(tarvals); tarvals = NULL;
1957 del_set(values); values = NULL;
1960 int (is_tarval)(const void *thing) {
1961 return _is_tarval(thing);
1964 /****************************************************************************
1966 ****************************************************************************/