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