Make remove_compound_member() an official API method.
[libfirm] / include / libfirm / tv.h
1 /*
2  * Copyright (C) 1995-2008 University of Karlsruhe.  All right reserved.
3  *
4  * This file is part of libFirm.
5  *
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.
10  *
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.
14  *
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
17  * PURPOSE.
18  */
19
20 /**
21  * @file
22  * @brief    Representation of and static computations on target machine
23  *           values.
24  * @date     2003
25  * @author   Mathias Heil
26  * @version  $Id$
27  * @brief
28  *   Tarvals represent target machine values.  They are typed by modes.
29  *   Tarvals only represent values of mode_sort:
30  *    - int_number,
31  *    - float_number,
32  *    - boolean,
33  *    - reference,
34  *    - character
35  *
36  *   In case of references the module accepts an entity to represent the
37  *   value.
38  *   Furthermore, computations and conversions of these values can
39  *   be performed.
40  *
41  * HISTORY
42  *    The original tv module originated in the fiasco compiler written ...
43  *    This is the new version, described in the tech report 1999-14 by ...
44  *
45  * @sa
46  *    Techreport 1999-14
47  *    irmode.h for the modes definitions
48  */
49 #ifndef FIRM_TV_TV_H
50 #define FIRM_TV_TV_H
51
52 #include <stddef.h>
53 #include "firm_types.h"
54
55 #include "begin.h"
56
57 /* ************************ Constructors for tarvals ************************ */
58
59 /**
60  * Constructor function for new tarvals.
61  *
62  * @param str   The string representing the target value
63  * @param len   The length of the string
64  * @param mode  The mode requested for the result tarval
65  *
66  * This function creates a new tarval representing the value represented
67  * by a CString, aka char array. If a tarval representing this value already
68  * exists, this tarval is returned instead of a new one. So tarvals are
69  * directly comparable since their representation is unique.
70  *
71  * This function accepts the following strings:
72  *
73  * if mode is int_number:
74  *  - 0(x|X)[0-9a-fA-F]+ (hexadecimal representation)
75  *  - 0[0-7]*            (octal representation)
76  *  - (+|-)?[1-9][0-9]*  (decimal representation)
77  *
78  * if mode is float_number:
79  *  - (+|-)?(decimal int) (. (decimal int))? ((e|E)(+|-)?(decimal int))?
80  *
81  * if mode is boolean: true, True, TRUE ... False... 0, 1,
82  *
83  * if mode is reference: hexadecimal of decimal number as int
84  *
85  * if mode is character: hex or dec
86  *
87  * Leading and/or trailing spaces are ignored
88  *
89  * @return
90  *   A tarval of proper type representing the requested value is returned.
91  *   Tarvals are unique, so for any value/mode pair at most one tarval will
92  *   exist, which will be returned upon further requests with an identical
93  *   value/mode pair.
94  *
95  * @note
96  *   If the string is not representable in the given mode an assertion is
97  *   thrown in assert build.
98  *
99  * @sa
100  *   irmode.h for predefined modes
101  *   new_tarval_from_long()
102  *   new_tarval_from_double()
103  */
104 FIRM_API ir_tarval *new_tarval_from_str(const char *str, size_t len,
105                                         ir_mode *mode);
106
107 /**
108  * Construct a new tarval from a given string.
109  *
110  * @param str   The string representing the target value
111  * @param len   The length of the string
112  * @param sign  is -1 or 1 depending on the numbers sign
113  * @param base  number system base.
114  *              binary(2), octal(8), decimal(10) and hexadecimal(16) numbers
115  *              are supported.
116  * @param mode  The mode requested for the result tarval
117  *
118  * @return
119  *   A tarval with the given mode. If overflow settings are set to
120  *   TV_OVERFLOW_BAD then a tarval_bad is returned if the number can't be
121  *   represented in the given mode.
122  *   Return bad if the number couldn't successfully be parsed.
123  */
124 FIRM_API ir_tarval *new_integer_tarval_from_str(const char *str, size_t len,
125                                                 char sign, unsigned char base,
126                                                 ir_mode *mode);
127
128 /**
129  * Constructor function for new tarvals
130  *
131  * @param l     The long representing the value
132  * @param mode  The mode requested for the result tarval
133  *
134  * This function creates a new tarval representing the value represented
135  * by a long integer. If a tarval representing this value already exists,
136  * this tarval is returned instead of a new one. So tarvals are directly
137  * comparable since their representation is unique.
138  *
139  * @return
140  *   A tarval of proper type representing the requested value is returned.
141  *   Tarvals are unique, so for any value/mode pair at most one tarval will
142  *   exist, which will be returned upon further requests with an identical
143  *   value/mode pair.
144  *
145  * @note
146  *   If the long is not representable in the given mode an assertion is
147  *   thrown in assert build.
148  *
149  * @sa
150  *   irmode.h for predefined modes
151  *   new_tarval_from_str()
152  *   new_tarval_from_double()
153  *
154  */
155 FIRM_API ir_tarval *new_tarval_from_long(long l, ir_mode *mode);
156
157 /** Return value as long if possible.
158  *
159  * This returns a long int with the value represented value, or
160  * gibberish, depending on the size of long int and the size of the
161  * stored value. It works for e.g. 1 as mode_Ls, but might not work for
162  * get_mode_max(mode_Ls).
163  * This will overflow silently, so use only if you know what
164  * you are doing! (better check with tarval_is_long()...)
165  * Works only for int modes, even not for character modes!
166  */
167 FIRM_API long get_tarval_long(ir_tarval *tv);
168
169 /**
170  * This validates if get_tarval_long() will return a satisfying
171  * result. I.e. if tv is an int_number and between min, max
172  * of long int (signed!)
173  *
174  * @param tv    the tarval
175  */
176 FIRM_API int tarval_is_long(ir_tarval *tv);
177
178 /**
179  * Constructor function for new tarvals.
180  *
181  * @param d     The (long) double representing the value
182  * @param mode  The mode requested for the result tarval
183  *
184  * This function creates a new tarval representing the value represented
185  * by a (long) double. If a tarval representing this value already exists,
186  * this tarval is returned instead of a new one. So tarvals are directly
187  * comparable since their representation is unique.
188  * Only modes of sort float_number can be constructed this way.
189  *
190  * @return
191  *   A tarval of proper type representing the requested value is returned.
192  *   Tarvals are unique, so for any value/mode pair at most one tarval will
193  *   exist, which will be returned upon further requests with an identical
194  *   value/mode pair.
195  *
196  * @note
197  *   If the (long) double is not representable in the given mode an assertion
198  *   is thrown. This will happen for any mode not of sort float_number.
199  *
200  * @sa
201  *   irmode.h for predefined values
202  *   new_tarval_from_str()
203  *   new_tarval_from_long()
204  */
205 FIRM_API ir_tarval *new_tarval_from_double(double d, ir_mode *mode);
206
207 /**
208  * same as new_tarval_from_double(), but with a long double argument
209  */
210 FIRM_API ir_tarval *new_tarval_from_long_double(long double d, ir_mode *mode);
211
212 /**
213  * This returns a double with the value represented value, or
214  * gibberish, depending on the size of double and the size of the
215  * stored value.
216  * This will overflow silently, so use only if you know what
217  * you are doing! (better check with tarval_is_long...)
218  *
219  * @param tv    the tarval
220  */
221 FIRM_API double get_tarval_double(ir_tarval *tv);
222
223 /**
224  * same as get_tarval_double but returns a long double value
225  */
226 FIRM_API long double get_tarval_long_double(ir_tarval *tv);
227
228 /**
229  * This validates if tarval_to_double() will return a satisfying
230  * result. I.e. if tv is an float_number and between min, max
231  * of double
232  *
233  * @param tv    the tarval
234  */
235 FIRM_API int tarval_is_double(ir_tarval *tv);
236
237
238 /** ********** Access routines for tarval fields ********** **/
239
240 /*
241  * NAME
242  *   get_tarval_mode
243  *   get_tarval_ ...
244  *
245  * SYNOPSIS
246  *   ir_mode *get_tarval_mode(tarval *tv)
247  *   ...
248  *
249  * DESCRIPTION
250  *    These are access function for tarval struct members. It is encouraged
251  *   to use them instead of direct access to the struct fields.
252  *
253  * PARAMETERS
254  *   tv - The tarval to access fields of
255  *
256  * RESULT
257  *   get_tv_mode: The mode of the tarval
258  *
259  * SEE ALSO
260  *   the struct tarval
261  */
262
263 /**
264  * Returns the mode of the tarval.
265  *
266  * @param tv    the tarval
267  */
268 FIRM_API ir_mode *get_tarval_mode(const ir_tarval *tv);
269
270 /**
271  * Returns 1 if tv is negative
272  *
273  * @param tv    the tarval
274  */
275 FIRM_API int tarval_is_negative(ir_tarval *tv);
276
277 /**
278  * Returns 1 if tv is null
279  *
280  * @param tv    the tarval
281  */
282 FIRM_API int tarval_is_null(ir_tarval *tv);
283
284 /**
285  * Returns 1 if tv is the "one"
286  *
287  * @param tv    the tarval
288  */
289 FIRM_API int tarval_is_one(ir_tarval *tv);
290
291 /**
292  * Returns 1 if tv is the "minus one"
293  *
294  * @param tv    the tarval
295  */
296 FIRM_API int tarval_is_minus_one(ir_tarval *tv);
297
298 /**
299  * returns non-zero if all bits in the tarval are set
300  */
301 FIRM_API int tarval_is_all_one(ir_tarval *tv);
302
303 /**
304  * Return non-zero if the tarval is a constant (ie. NOT
305  * a reserved tarval like bad, undef, reachable etc.)
306  */
307 FIRM_API int tarval_is_constant(ir_tarval *tv);
308
309 /** The 'bad' tarval. */
310 FIRM_API ir_tarval *tarval_bad;
311 /** Returns the 'bad' tarval. */
312 FIRM_API ir_tarval *get_tarval_bad(void);
313
314 /** The 'undefined' tarval. */
315 FIRM_API ir_tarval *tarval_undefined;
316 /** Returns the 'undefined' tarval. */
317 FIRM_API ir_tarval *get_tarval_undefined(void);
318
319 /** The mode_b tarval 'false'. */
320 FIRM_API ir_tarval *tarval_b_false;
321 /** Returns the mode_b tarval 'false'. */
322 FIRM_API ir_tarval *get_tarval_b_false(void);
323
324 /** The mode_b tarval 'true'. */
325 FIRM_API ir_tarval *tarval_b_true;
326 /** Returns the mode_b tarval 'true'. */
327 FIRM_API ir_tarval *get_tarval_b_true(void);
328
329 /** The mode_X tarval 'unreachable'. */
330 FIRM_API ir_tarval *tarval_unreachable;
331 /** Returns the mode_X tarval 'unreachable'. */
332 FIRM_API ir_tarval *get_tarval_unreachable(void);
333
334 /** The mode_X tarval 'reachable'. */
335 FIRM_API ir_tarval *tarval_reachable;
336 /** Returns the mode_X tarval 'reachable'. */
337 FIRM_API ir_tarval *get_tarval_reachable(void);
338
339 /** The 'top' tarval. This is just another name for the 'undefined' tarval. */
340 #define tarval_top          tarval_undefined
341 /** Returns the 'top' tarval. */
342 #define get_tarval_top()    get_tarval_undefined()
343
344 /** The 'bottom' tarval. This is just another name for the 'bad' tarval. */
345 #define tarval_bottom       tarval_bad
346 /** Returns the 'bottom' tarval. */
347 #define get_tarval_bottom() get_tarval_bad()
348
349 /* These functions calculate and return a tarval representing the requested
350  * value.
351  * The functions get_mode_{Max,Min,...} return tarvals retrieved from these
352  * functions, but these are stored on initialization of the irmode module and
353  * therefore the irmode functions should be preferred to the functions below. */
354
355 /** Returns the maximum value of a given mode. */
356 FIRM_API ir_tarval *get_tarval_max(ir_mode *mode);
357
358 /** Returns the minimum value of a given mode. */
359 FIRM_API ir_tarval *get_tarval_min(ir_mode *mode);
360
361 /** Returns the 0 value (additive neutral) of a given mode.
362     For reference modes, the NULL value is returned (old tarval_P_void) */
363 FIRM_API ir_tarval *get_tarval_null(ir_mode *mode);
364
365 /** Returns the 1 value (multiplicative neutral) of a given mode. */
366 FIRM_API ir_tarval *get_tarval_one(ir_mode *mode);
367
368 /** Returns the -1 value (multiplicative neutral) of a given mode.
369  *  Returns tarval bad for unsigned modes */
370 FIRM_API ir_tarval *get_tarval_minus_one(ir_mode *mode);
371
372 /** returns the value where all bits are 1 of a given mode.
373  * returns tarval_bad for float modes */
374 FIRM_API ir_tarval *get_tarval_all_one(ir_mode *mode);
375
376 /** Return quite nan for float_number modes. */
377 FIRM_API ir_tarval *get_tarval_nan(ir_mode *mode);
378
379 /** Return +inf for float_number modes. */
380 FIRM_API ir_tarval *get_tarval_plus_inf(ir_mode *mode);
381
382 /** Return -inf for float_number modes. */
383 FIRM_API ir_tarval *get_tarval_minus_inf(ir_mode *mode);
384
385 /* ******************** Arithmetic operations on tarvals ******************** */
386
387 typedef enum tarval_int_overflow_mode_t {
388         TV_OVERFLOW_BAD,      /**< tarval module will return tarval_bad if a overflow occurs */
389         TV_OVERFLOW_WRAP,     /**< tarval module will overflow will be ignored, wrap around occurs */
390         TV_OVERFLOW_SATURATE  /**< tarval module will saturate the overflow */
391 } tarval_int_overflow_mode_t;
392
393 /**
394  * Sets the overflow mode for integer operations.
395  *
396  * @param ov_mode  one of teh overflow modes
397  */
398 FIRM_API void tarval_set_integer_overflow_mode(tarval_int_overflow_mode_t ov_mode);
399
400 /**
401  * Get the overflow mode for integer operations.
402  */
403 FIRM_API tarval_int_overflow_mode_t tarval_get_integer_overflow_mode(void);
404
405 /**
406  * Compares two tarvals
407  *
408  * Compare a with b and return their relation.
409  * This is either ir_rel_unordered, ir_rel_less, ir_rel_greater, ir_rel_equal
410  * or ir_rel_false if a or b are symbolic pointers which can not be compared at
411  * all.
412  *
413  * @param a   the first tarval to be compared
414  * @param b   the second tarval to be compared
415  */
416 FIRM_API ir_relation tarval_cmp(ir_tarval *a, ir_tarval *b);
417
418 /**
419  * Converts a tarval to another mode.
420  *
421  * Convert tarval 'src' to mode 'mode', this will succeed if and only if mode
422  * 'mode' is wider than the mode of src, as defined in the firm documentation
423  * and as returned by the function mode_is_smaller defined in irmode.h.
424  *
425  * @param src    The tarval to convert
426  * @param mode   Tho mode to convert to
427  *
428  * @return
429  *   If a tarval of mode 'mode' with the result of the conversion of the 'src'
430  *   tarvals value already exists, it will be returned, else a new tarval is
431  *   constructed and returned
432  *
433  * @note
434  *    Illegal convertions will trigger a panic
435  *
436  * @sa
437  *    FIRM documentation for conversion rules
438  *    mode_is_smaller defined in irmode.h
439  */
440 FIRM_API ir_tarval *tarval_convert_to(ir_tarval *src, ir_mode *mode);
441
442 /*
443  * These function implement basic computations representable as opcodes
444  * in FIRM nodes.
445  *
446  * PARAMETERS
447  *    tarval_neg:
448  *    traval_abs:
449  *      a - the tarval to operate on
450  *
451  *    all others:
452  *      a - the first operand tarval
453  *      b - the second operand tarval
454  *
455  * RESULT
456  *    If necessary a new tarval is constructed for the resulting value,
457  *   or the one already carrying the computation result is retrieved and
458  *   returned as result.
459  *
460  * NOTES
461  *   The order the arguments are given in is important, imagine postfix
462  *   notation.
463  *   Illegal operations will trigger an assertion.
464  *   The sort member of the struct mode defines which operations are valid
465  */
466
467 /**
468  * Bitwise Negation of a tarval.
469  *
470  * @param a  the first tarval
471  *
472  * @return ~a or tarval_bad
473  */
474 FIRM_API ir_tarval *tarval_not(ir_tarval *a);
475
476 /**
477  * Arithmetic Negation of a tarval.
478  *
479  * @param a  the first tarval
480  *
481  * @return -a or tarval_bad
482  */
483 FIRM_API ir_tarval *tarval_neg(ir_tarval *a);
484
485 /**
486  * Addition of two tarvals.
487  *
488  * @param a  the first tarval
489  * @param b  the second tarval
490  *
491  * @return a + b or tarval_bad
492  */
493 FIRM_API ir_tarval *tarval_add(ir_tarval *a, ir_tarval *b);
494
495 /**
496  * Subtraction from a tarval.
497  *
498  * @param a         the first tarval
499  * @param b         the second tarval
500  * @param dst_mode  the mode of the result, needed for mode_P - mode_P, else NULL
501  *
502  * @return a - b or tarval_bad
503  */
504 FIRM_API ir_tarval *tarval_sub(ir_tarval *a, ir_tarval *b, ir_mode *dst_mode);
505
506 /**
507  * Multiplication of tarvals.
508  *
509  * @param a  the first tarval
510  * @param b  the second tarval
511  *
512  * @return a * b or tarval_bad
513  */
514 FIRM_API ir_tarval *tarval_mul(ir_tarval *a, ir_tarval *b);
515
516 /**
517  * Integer division of two tarvals.
518  *
519  * @param a  the first tarval
520  * @param b  the second tarval
521  *
522  * @return a / b or tarval_bad
523  */
524 FIRM_API ir_tarval *tarval_div(ir_tarval *a, ir_tarval *b);
525
526 /**
527  * Remainder of integer division.
528  *
529  * @param a  the first tarval
530  * @param b  the second tarval
531  *
532  * @return a % b or tarval_bad
533  */
534 FIRM_API ir_tarval *tarval_mod(ir_tarval *a, ir_tarval *b);
535
536 /**
537  * Integer division AND remainder.
538  *
539  * @param a        the first tarval
540  * @param b        the second tarval
541  * @param mod_res  after return, contains the remainder result, a % b or tarval_bad
542  *
543  * @return a / b or tarval_bad
544  */
545 FIRM_API ir_tarval *tarval_divmod(ir_tarval *a, ir_tarval *b, ir_tarval **mod_res);
546
547 /**
548  * Absolute value of a tarval.
549  *
550  * @param a  the first tarval
551  *
552  * @return |a| or tarval_bad
553  */
554 FIRM_API ir_tarval *tarval_abs(ir_tarval *a);
555
556 /**
557  * Bitwise and of two integer tarvals.
558  *
559  * @param a  the first tarval
560  * @param b  the second tarval
561  *
562  * @return a & b or tarval_bad
563  */
564 FIRM_API ir_tarval *tarval_and(ir_tarval *a, ir_tarval *b);
565
566 /**
567  * Bitwise and not of two integer tarvals.
568  *
569  * @param a  the first tarval
570  * @param b  the second tarval
571  *
572  * @return a & ~b or tarval_bad
573  */
574 FIRM_API ir_tarval *tarval_andnot(ir_tarval *a, ir_tarval *b);
575
576 /**
577  * Bitwise or of two integer tarvals.
578  *
579  * @param a  the first tarval
580  * @param b  the second tarval
581  *
582  * @return a | b or tarval_bad
583  */
584 FIRM_API ir_tarval *tarval_or(ir_tarval *a, ir_tarval *b);
585
586 /**
587  * Bitwise exclusive or of two integer tarvals.
588  *
589  * @param a  the first tarval
590  * @param b  the second tarval
591  *
592  * @return a ^ b or tarval_bad
593  */
594 FIRM_API ir_tarval *tarval_eor(ir_tarval *a, ir_tarval *b);
595
596 /**
597  * Logical Left shift.
598  *
599  * @param a  the first tarval
600  * @param b  the second tarval
601  *
602  * @return a << b or tarval_bad
603  */
604 FIRM_API ir_tarval *tarval_shl(ir_tarval *a, ir_tarval *b);
605
606 /**
607  * Unsigned (logical) right shift.
608  *
609  * @param a  the first tarval
610  * @param b  the second tarval
611  *
612  * @return a >>u b or tarval_bad
613  */
614 FIRM_API ir_tarval *tarval_shr(ir_tarval *a, ir_tarval *b);
615
616 /**
617  * Signed (arithmetic) right shift.
618  *
619  * @param a  the first tarval
620  * @param b  the second tarval
621  *
622  * @return a >>s b or tarval_bad
623  */
624 FIRM_API ir_tarval *tarval_shrs(ir_tarval *a, ir_tarval *b);
625
626 /**
627  * Rotation to left.
628  *
629  * @param a  the first tarval
630  * @param b  the second tarval
631  *
632  * @return a \<\<L\>\> b or tarval_bad
633  */
634 FIRM_API ir_tarval *tarval_rotl(ir_tarval *a, ir_tarval *b);
635
636 /**
637  * Returns the carry flag of the last operation.
638  */
639 FIRM_API int tarval_carry(void);
640
641 /* *********** Output of tarvals *********** */
642
643 /**
644  * The output mode for tarval values.
645  *
646  * Some modes allow more that one representation, for instance integers
647  * can be represented hex or decimal. Of course it would be enough to have
648  * one and let every backend convert it into the 'right' one.
649  * However, we can do this in the tarval much simpler...
650  */
651 typedef enum {
652         TVO_NATIVE,       /**< the default output mode, depends on the mode */
653         TVO_HEX,          /**< use hex representation, always possible */
654         TVO_DECIMAL,      /**< use decimal representation */
655         TVO_OCTAL,        /**< use octal representation */
656         TVO_BINARY,       /**< use binary representation */
657         TVO_FLOAT,        /**< use floating point representation (i.e 1.342e-2)*/
658         TVO_HEXFLOAT      /**< use hexadecimal floating point representation (i.e 0x1.ea32p-12)*/
659 } tv_output_mode;
660
661 /**
662  * This structure contains helper information to format the output
663  * of a tarval of a mode.
664  */
665 typedef struct tarval_mode_info {
666         tv_output_mode mode_output;  /**< if != TVO_NATIVE select a special mode */
667         const char *mode_prefix;     /**< if set, this prefix will be printed
668                                           before a value of this mode */
669         const char *mode_suffix;     /**< if set, this suffix will be printed
670                                           after a value of this mode */
671 } tarval_mode_info;
672
673 /**
674  * Specify the output options of one mode.
675  *
676  * This functions stores the mode info, so DO NOT DESTROY it.
677  *
678  * @param mode      a ir_mode that should be associated
679  * @param modeinfo  the output format info
680  *
681  * @return zero on success.
682  */
683 FIRM_API int set_tarval_mode_output_option(ir_mode *mode,
684                                            const tarval_mode_info *modeinfo);
685
686 /**
687  * Returns the output options of one mode.
688  *
689  * This functions returns the mode info of a given mode.
690  *
691  * @param mode      a ir_mode that should be associated
692  *
693  * @return the output option
694  */
695 FIRM_API const tarval_mode_info *get_tarval_mode_output_option(ir_mode *mode);
696
697 /**
698  * Returns Bit representation of a tarval value, as string of '0' and '1'
699  *
700  * @param tv   The tarval
701  *
702  * This function returns a printable bit representation of any value
703  * stored as tarval. This representation is a null terminated C string.
704  *
705  * @return
706  *   As usual in C a pointer to a char is returned. The length of the
707  *   returned string if fixed, just read as many chars as the mode defines
708  *   as size.
709  *
710  * @note
711  *   The string is allocated using malloc() and is free()ed on the next call
712  *   of this function.
713  *   The string consists of the ASCII characters '0' and '1' and is
714  *   null terminated
715  *
716  * @sa
717  *    irmode.h for the definition of the ir_mode struct
718  *    the size member of aforementioned struct
719  */
720 FIRM_API char *get_tarval_bitpattern(ir_tarval *tv);
721
722 /**
723  * Returns the bitpattern of the bytes_ofs byte.
724  *
725  * This function succeeds even if the mode of the tarval uses lesser bits
726  * than requested, in that case the bitpattern is filled with zero bits.
727  *
728  * To query a 32bit value the following code can be used:
729  *
730  * val0 = tarval_sub_bits(tv, 0);  <- lowest bits
731  * val1 = tarval_sub_bits(tv, 1);
732  * val2 = tarval_sub_bits(tv, 2);
733  * val3 = tarval_sub_bits(tv, 3);  <- highest bits
734  *
735  * Because this is the bit representation of the target machine, only the following
736  * operations are legal on the result:
737  *
738  * - concatenation (endian dependence MUST be handled by the CALLER)
739  * - bitwise logical operations to select/mask bits
740  *
741  * @param tv        the tarval
742  * @param byte_ofs  the byte offset from lower to higher
743  *
744  * @note
745  *   The result of this function is undefined if the mode is neither integer nor float.
746  */
747 FIRM_API unsigned char get_tarval_sub_bits(ir_tarval *tv, unsigned byte_ofs);
748
749 /**
750  * Returns non-zero if a given (integer) tarval has only one single bit
751  * set.
752  *
753  * @param tv    the tarval
754  */
755 FIRM_API int tarval_is_single_bit(ir_tarval *tv);
756
757 /**
758  * Return the number of set bits in a given (integer) tarval.
759  *
760  * @param tv    the tarval
761  *
762  * @return number of set bits or -1 on error
763  */
764 FIRM_API int get_tarval_popcount(ir_tarval *tv);
765
766 /**
767  * Return the number of the lowest set bit in a given (integer) tarval.
768  *
769  * @param tv    the tarval
770  *
771  * @return number of lowest set bit or -1 on error
772  */
773 FIRM_API int get_tarval_lowest_bit(ir_tarval *tv);
774
775 /**
776  * Output a tarval to a string buffer.
777  *
778  * @param buf     the output buffer
779  * @param buflen  the length of the buffer
780  * @param tv      the tarval
781  */
782 FIRM_API int tarval_snprintf(char *buf, size_t buflen, ir_tarval *tv);
783
784 /**
785  * Output a tarval to stdio.
786  *
787  * @param tv    the tarval
788  */
789 FIRM_API int tarval_printf(ir_tarval *tv);
790
791 /**
792  * Returns non-zero if the mantissa of a floating point IEEE-754
793  * tarval is zero (i.e. 1.0Exxx)
794  *
795  * @param tv    the tarval
796  */
797 FIRM_API int tarval_ieee754_zero_mantissa(ir_tarval *tv);
798
799 /**
800  * Returns the exponent of a floating point IEEE-754
801  * tarval.
802  *
803  * @param tv    the tarval
804  */
805 FIRM_API int tarval_ieee754_get_exponent(ir_tarval *tv);
806
807 /**
808  * Check if the tarval can be converted to the given mode without
809  * precision loss.
810  *
811  * @param tv    the tarval
812  * @param mode  the mode to convert to
813  */
814 FIRM_API int tarval_ieee754_can_conv_lossless(ir_tarval *tv, ir_mode *mode);
815
816 /**
817  * Set the immediate precision for IEEE-754 results. Set this to
818  * 0 to get the same precision as the operands.
819  * For x87 compatibility, set this to 80.
820  *
821  * @return the old setting
822  */
823 FIRM_API unsigned tarval_ieee754_set_immediate_precision(unsigned bits);
824
825 /**
826  *  Returns non-zero if the result of the last IEEE-754 operation was exact.
827  */
828 FIRM_API unsigned tarval_ieee754_get_exact(void);
829
830 /**
831  * Return the size of the mantissa in bits (including possible
832  * implicit bits) for the given mode.
833  */
834 FIRM_API unsigned tarval_ieee754_get_mantissa_size(const ir_mode *mode);
835
836 /**
837  * Enable/Disable floating point constant folding.
838  */
839 FIRM_API void tarval_enable_fp_ops(int enable);
840
841 /** returns 0/1 if floating point folding is enable/disabled */
842 FIRM_API int tarval_fp_ops_enabled(void);
843
844 /**
845  * Check if its the a floating point NaN.
846  *
847  * @param tv    the tarval
848  */
849 FIRM_API int tarval_is_NaN(ir_tarval *tv);
850
851 /**
852  * Check if its the a floating point +inf.
853  *
854  * @param tv    the tarval
855  */
856 FIRM_API int tarval_is_plus_inf(ir_tarval *tv);
857
858 /**
859  * Check if its the a floating point -inf.
860  *
861  * @param tv    the tarval
862  */
863 FIRM_API int tarval_is_minus_inf(ir_tarval *tv);
864
865 /**
866  * Check if the tarval represents a finite value, ie neither NaN nor inf.
867  *
868  * @param tv    the tarval
869  */
870 FIRM_API int tarval_is_finite(ir_tarval *tv);
871
872 /**
873  *   Checks whether a pointer points to a tarval.
874  *
875  *   @param thing     an arbitrary pointer
876  *
877  *   @return
878  *       true if the thing is a tarval, else false
879  */
880 FIRM_API int is_tarval(const void *thing);
881
882 #include "end.h"
883
884 #endif