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