libFirm
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
Target Machine Values

Tarvals only represent values of mode_sort: More...

Typedefs

typedef struct ir_tarval ir_tarval
 Target Machine Value. More...
 

Functions

ir_tarvalnew_tarval_from_str (const char *str, size_t len, ir_mode *mode)
 Constructor function for new tarvals. More...
 
ir_tarvalnew_integer_tarval_from_str (const char *str, size_t len, int negative, unsigned char base, ir_mode *mode)
 Construct a new tarval from a given string. More...
 
ir_tarvalnew_tarval_from_long (long l, ir_mode *mode)
 Constructor function for new tarvals. More...
 
ir_tarvalnew_tarval_from_bytes (unsigned char const *buf, ir_mode *mode)
 Construct a new tarval from a sequence of bytes. More...
 
ir_tarvalnew_tarval_nan (ir_mode *mode, int signaling, ir_tarval *payload)
 Construct a new floating point quiet NaN value. More...
 
void tarval_to_bytes (unsigned char *buffer, ir_tarval *tv)
 Write tarval to a sequence of bytes. More...
 
long get_tarval_long (const ir_tarval *tv)
 Returns value as long if possible. More...
 
int tarval_is_long (const ir_tarval *tv)
 This validates if get_tarval_long() will return something sensible. More...
 
ir_tarvalnew_tarval_from_double (double d, ir_mode *mode)
 Constructor function for new tarvals. More...
 
ir_tarvalnew_tarval_from_long_double (long double d, ir_mode *mode)
 same as new_tarval_from_double(), but with a long double argument More...
 
double get_tarval_double (const ir_tarval *tv)
 This returns a double with the value represented value, or gibberish, depending on the size of double and the size of the stored value. More...
 
long double get_tarval_long_double (const ir_tarval *tv)
 same as get_tarval_double but returns a long double value More...
 
int tarval_is_double (const ir_tarval *tv)
 This validates if tarval_to_double() will return a satisfying result. More...
 
ir_modeget_tarval_mode (const ir_tarval *tv)
 Returns the mode of the tarval. More...
 
int tarval_is_negative (const ir_tarval *tv)
 Returns 1 if tv is negative. More...
 
int tarval_is_null (const ir_tarval *tv)
 Returns 1 if tv is null. More...
 
int tarval_is_one (const ir_tarval *tv)
 Returns 1 if tv is the "one". More...
 
int tarval_is_all_one (const ir_tarval *tv)
 returns non-zero if all bits in the tarval are set. More...
 
int tarval_is_constant (const ir_tarval *tv)
 Returns non-zero if the tarval is a constant (i.e. More...
 
ir_tarvalget_tarval_bad (void)
 Returns the 'bad' tarval. More...
 
ir_tarvalget_tarval_unknown (void)
 Returns the 'unknown' tarval. More...
 
ir_tarvalget_tarval_b_false (void)
 Returns the mode_b tarval 'false'. More...
 
ir_tarvalget_tarval_b_true (void)
 Returns the mode_b tarval 'true'. More...
 
void tarval_set_wrap_on_overflow (int wrap_on_overflow)
 Sets whether values should wrap on overflow or return the bad value. More...
 
int tarval_get_wrap_on_overflow (void)
 Returns 0 if operations return bad on overflow, != 0 if they wrap around. More...
 
ir_relation tarval_cmp (const ir_tarval *a, const ir_tarval *b)
 Compares two tarvals. More...
 
ir_tarvaltarval_convert_to (ir_tarval *src, ir_mode *mode)
 Converts a tarval to another mode. More...
 
ir_tarvaltarval_bitcast (ir_tarval *src, ir_mode *mode)
 Converts a tarval to another mode by reinterpreting the contained bits. More...
 
ir_tarvaltarval_not (ir_tarval *a)
 Bitwise Negation of a tarval. More...
 
ir_tarvaltarval_neg (ir_tarval *a)
 Arithmetic Negation of a tarval. More...
 
ir_tarvaltarval_add (ir_tarval *a, ir_tarval *b)
 Addition of two tarvals. More...
 
ir_tarvaltarval_sub (ir_tarval *a, ir_tarval *b)
 Subtraction from a tarval. More...
 
ir_tarvaltarval_mul (ir_tarval *a, ir_tarval *b)
 Multiplication of tarvals. More...
 
ir_tarvaltarval_div (ir_tarval *a, ir_tarval *b)
 Integer division of two tarvals. More...
 
ir_tarvaltarval_mod (ir_tarval *a, ir_tarval *b)
 Remainder of integer division. More...
 
ir_tarvaltarval_divmod (ir_tarval *a, ir_tarval *b, ir_tarval **mod_res)
 Integer division AND remainder. More...
 
ir_tarvaltarval_abs (ir_tarval *a)
 Absolute value of a tarval. More...
 
ir_tarvaltarval_and (ir_tarval *a, ir_tarval *b)
 Bitwise and of two integer tarvals. More...
 
ir_tarvaltarval_andnot (ir_tarval *a, ir_tarval *b)
 Bitwise and not of two integer tarvals. More...
 
ir_tarvaltarval_or (ir_tarval *a, ir_tarval *b)
 Bitwise or of two integer tarvals. More...
 
ir_tarvaltarval_ornot (ir_tarval *a, ir_tarval *b)
 Bitwise or not of two integer tarvals. More...
 
ir_tarvaltarval_eor (ir_tarval *a, ir_tarval *b)
 Bitwise exclusive or of two integer tarvals. More...
 
ir_tarvaltarval_shl (ir_tarval *a, ir_tarval *b)
 Logical Left shift. More...
 
ir_tarvaltarval_shl_unsigned (ir_tarval *a, unsigned b)
 logical left shift (variant with unsigned argument). More...
 
ir_tarvaltarval_shr (ir_tarval *a, ir_tarval *b)
 Unsigned (logical) right shift. More...
 
ir_tarvaltarval_shr_unsigned (ir_tarval *a, unsigned b)
 unsigned (logical) right shift (variant with unsigned argument). More...
 
ir_tarvaltarval_shrs (ir_tarval *a, ir_tarval *b)
 Signed (arithmetic) right shift. More...
 
ir_tarvaltarval_shrs_unsigned (ir_tarval *a, unsigned b)
 signed (arithmetic) right shift (variant with unsigned argument). More...
 
unsigned char get_tarval_sub_bits (const ir_tarval *tv, unsigned byte_ofs)
 Returns the bitpattern of the bytes_ofs byte. More...
 
int get_tarval_popcount (const ir_tarval *tv)
 Returns the number of set bits in a given (integer) tarval. More...
 
int get_tarval_lowest_bit (const ir_tarval *tv)
 Returns the number of the lowest set bit in a given (integer) tarval. More...
 
int get_tarval_highest_bit (const ir_tarval *tv)
 Return the number of the highest set bit in a given (integer) tarval. More...
 
int tarval_zero_mantissa (const ir_tarval *tv)
 Returns non-zero if the mantissa of a floating point tarval is zero (i.e. More...
 
int tarval_get_exponent (const ir_tarval *tv)
 Returns the exponent of a floating point IEEE-754 tarval. More...
 
int tarval_ieee754_can_conv_lossless (const ir_tarval *tv, const ir_mode *mode)
 Check if the tarval can be converted to the given mode without precision loss. More...
 
unsigned tarval_ieee754_get_exact (void)
 Returns non-zero if the result of the last IEEE-754 operation was exact. More...
 
int tarval_is_nan (const ir_tarval *tv)
 Check if tv is a floating point NaN. More...
 
int tarval_is_quiet_nan (const ir_tarval *tv)
 Check if tv is a floating point quiet NaN. More...
 
int tarval_is_signaling_nan (const ir_tarval *tv)
 Check if tv is a floating point signaling NaN. More...
 
int tarval_is_finite (const ir_tarval *tv)
 Check if the tarval represents a finite value, ie neither NaN nor inf. More...
 

Variables

ir_tarval *const tarval_bad
 The 'bad' tarval. More...
 
ir_tarval *const tarval_unknown
 The 'unknown' tarval. More...
 
ir_tarvaltarval_b_false
 The mode_b tarval 'false'. More...
 
ir_tarvaltarval_b_true
 The mode_b tarval 'true'. More...
 

Detailed Description

Tarvals only represent values of mode_sort:

In case of references the module accepts an entity to represent the value. Furthermore, computations and conversions of these values can be performed.

See Also
Techreport 1999-14 irmode.h for the modes definitions

Typedef Documentation

typedef struct ir_tarval ir_tarval

Target Machine Value.

Definition at line 68 of file firm_types.h.

Function Documentation

ir_tarval* get_tarval_b_false ( void  )

Returns the mode_b tarval 'false'.

ir_tarval* get_tarval_b_true ( void  )

Returns the mode_b tarval 'true'.

ir_tarval* get_tarval_bad ( void  )

Returns the 'bad' tarval.

double get_tarval_double ( const ir_tarval tv)

This returns a double with the value represented value, or gibberish, depending on the size of double and the size of the stored value.

This will overflow silently, so use only if you know what you are doing! (better check with tarval_is_long...)

Parameters
tvthe tarval
int get_tarval_highest_bit ( const ir_tarval tv)

Return the number of the highest set bit in a given (integer) tarval.

Parameters
tvthe tarval
Returns
number of highest set bit or -1 on error
long get_tarval_long ( const ir_tarval tv)

Returns value as long if possible.

long double get_tarval_long_double ( const ir_tarval tv)

same as get_tarval_double but returns a long double value

int get_tarval_lowest_bit ( const ir_tarval tv)

Returns the number of the lowest set bit in a given (integer) tarval.

Parameters
tvthe tarval
Returns
number of lowest set bit or -1 on error
ir_mode* get_tarval_mode ( const ir_tarval tv)

Returns the mode of the tarval.

Parameters
tvthe tarval

Referenced by new_rd_Const().

int get_tarval_popcount ( const ir_tarval tv)

Returns the number of set bits in a given (integer) tarval.

Parameters
tvthe tarval
Returns
number of set bits or -1 on error
unsigned char get_tarval_sub_bits ( const ir_tarval tv,
unsigned  byte_ofs 
)

Returns the bitpattern of the bytes_ofs byte.

This function succeeds even if the mode of the tarval uses fewer bits than requested, in that case the bitpattern is filled with zero bits.

To query a 32bit value the following code can be used:

val0 = tarval_sub_bits(tv, 0); <- lowest bits val1 = tarval_sub_bits(tv, 1); val2 = tarval_sub_bits(tv, 2); val3 = tarval_sub_bits(tv, 3); <- highest bits

Because this is the bit representation of the target machine, only the following operations are legal on the result:

  • concatenation (endian dependence MUST be handled by the CALLER)
  • bitwise logical operations to select/mask bits
Parameters
tvthe tarval
byte_ofsthe byte offset from lower to higher
Note
The result of this function is undefined if the mode is neither integer nor float.
ir_tarval* get_tarval_unknown ( void  )

Returns the 'unknown' tarval.

ir_tarval* new_integer_tarval_from_str ( const char *  str,
size_t  len,
int  negative,
unsigned char  base,
ir_mode mode 
)

Construct a new tarval from a given string.

Parameters
strThe string representing the target value
lenThe length of the string
negative!= 0 if number should be negative
basenumber system base. binary(2), octal(8), decimal(10) and hexadecimal(16) numbers are supported.
modeThe mode requested for the result tarval
Returns
A tarval with the given mode. If overflow settings are set to TV_OVERFLOW_BAD then a tarval_bad is returned if the number can't be represented in the given mode. Returns bad if the number couldn't successfully be parsed.
ir_tarval* new_tarval_from_bytes ( unsigned char const *  buf,
ir_mode mode 
)

Construct a new tarval from a sequence of bytes.

The bytes are interpreted in a "little endian" fashion which means less significant bytes come first.

Parameters
bufpointer to a buffer holding at least get_ir_mode_size_bytes(mode) bytes.
modemode for the resulting tarval
Returns
A newly created (or cached) tarval representing the value.
ir_tarval* new_tarval_from_double ( double  d,
ir_mode mode 
)

Constructor function for new tarvals.

Parameters
dThe (long) double representing the value
modeThe mode requested for the result tarval

This function creates a new tarval representing the value represented by a (long) double. If a tarval representing this value already exists, this tarval is returned instead of a new one. So tarvals are directly comparable since their representation is unique. Only modes of sort float_number can be constructed this way.

Returns
A tarval of proper type representing the requested value is returned. Tarvals are unique, so for any value/mode pair at most one tarval will exist, which will be returned upon further requests with an identical value/mode pair.
Note
If the (long) double is not representable in the given mode an assertion is thrown. This will happen for any mode not of sort float_number.
See Also
irmode.h for predefined values new_tarval_from_str() new_tarval_from_long()
ir_tarval* new_tarval_from_long ( long  l,
ir_mode mode 
)

Constructor function for new tarvals.

Parameters
lThe long representing the value
modeThe mode requested for the result tarval must be a twos_complement mode.

This function creates a new tarval representing the value represented by a long integer. If a tarval representing this value already exists, this tarval is returned instead of a new one. So tarvals are directly comparable since their representation is unique.

Returns
A tarval of proper type representing the requested value is returned. Tarvals are unique, so for any value/mode pair at most one tarval will exist, which will be returned upon further requests with an identical value/mode pair.
Note
If the long is not representable in the given mode an assertion is thrown in assert build.
See Also
irmode.h for predefined modes new_tarval_from_str() new_tarval_from_double()
ir_tarval* new_tarval_from_long_double ( long double  d,
ir_mode mode 
)

same as new_tarval_from_double(), but with a long double argument

ir_tarval* new_tarval_from_str ( const char *  str,
size_t  len,
ir_mode mode 
)

Constructor function for new tarvals.

Parameters
strThe string representing the target value
lenThe length of the string
modeThe mode requested for the result tarval

This function creates a new tarval representing the value represented by a CString, aka char array. If a tarval representing this value already exists, this tarval is returned instead of a new one. So tarvals are directly comparable since their representation is unique.

This function accepts the following strings:

if mode is int_number:

  • [+-]?0[xX][0-9a-fA-F]+ (hexadecimal representation)
  • [+-]?0[0-7]* (octal representation)
  • [+-]?0[bB][01]+ (binary representation)
  • [+-]?[1-9][0-9]* (decimal representation)

if mode is float_number:

  • [+-]?(decimal int) (. (decimal int))? ([eE][+-]?(decimal int))?

if mode is boolean: true, True, TRUE ... False... 0, 1,

if mode is reference: "null" and the same as for int_number

Leading and/or trailing spaces are ignored

Returns
A tarval of proper type representing the requested value is returned. Tarvals are unique, so for any value/mode pair at most one tarval will exist, which will be returned upon further requests with an identical value/mode pair.
Note
Behaviour is undefined if the number in str is malformed. Debug builds should fail assertions in these cases.
See Also
irmode.h for predefined modes new_tarval_from_long() new_tarval_from_double()
ir_tarval* new_tarval_nan ( ir_mode mode,
int  signaling,
ir_tarval payload 
)

Construct a new floating point quiet NaN value.

Parameters
modefloating point mode for the resulting value
signalingif != 0 produces a signaling NaN else a quiet one.
payloadif != NULL puts the integer tarval into the mantissa.
ir_tarval* tarval_abs ( ir_tarval a)

Absolute value of a tarval.

Parameters
athe first tarval
Returns
|a| or tarval_bad
ir_tarval* tarval_add ( ir_tarval a,
ir_tarval b 
)

Addition of two tarvals.

Parameters
athe first tarval
bthe second tarval
Returns
a + b or tarval_bad
ir_tarval* tarval_and ( ir_tarval a,
ir_tarval b 
)

Bitwise and of two integer tarvals.

Parameters
athe first tarval
bthe second tarval
Returns
a & b or tarval_bad
ir_tarval* tarval_andnot ( ir_tarval a,
ir_tarval b 
)

Bitwise and not of two integer tarvals.

Parameters
athe first tarval
bthe second tarval
Returns
a & ~b or tarval_bad
ir_tarval* tarval_bitcast ( ir_tarval src,
ir_mode mode 
)

Converts a tarval to another mode by reinterpreting the contained bits.

This is only allowed if the source and destination mode have the same number of bits.

ir_relation tarval_cmp ( const ir_tarval a,
const ir_tarval b 
)

Compares two tarvals.

Compare a with b and return their relation. This is either ir_rel_unordered, ir_rel_less, ir_rel_greater, ir_rel_equal or ir_rel_false if a or b are symbolic pointers which can not be compared at all.

Parameters
athe first tarval to be compared
bthe second tarval to be compared
ir_tarval* tarval_convert_to ( ir_tarval src,
ir_mode mode 
)

Converts a tarval to another mode.

Convert tarval 'src' to mode 'mode', this will succeed if and only if mode 'mode' is wider than the mode of src, as defined in the firm documentation and as returned by the function mode_is_smaller defined in irmode.h.

Parameters
srcThe tarval to convert
modeTho mode to convert to
Returns
If a tarval of mode 'mode' with the result of the conversion of the 'src' tarvals value already exists, it will be returned, else a new tarval is constructed and returned
Note
Illegal conversions will trigger a panic
See Also
FIRM documentation for conversion rules mode_is_smaller defined in irmode.h
ir_tarval* tarval_div ( ir_tarval a,
ir_tarval b 
)

Integer division of two tarvals.

Parameters
athe first tarval
bthe second tarval
Returns
a / b or tarval_bad
ir_tarval* tarval_divmod ( ir_tarval a,
ir_tarval b,
ir_tarval **  mod_res 
)

Integer division AND remainder.

Parameters
athe first tarval
bthe second tarval
mod_resafter return, contains the remainder result, a % b or tarval_bad
Returns
a / b or tarval_bad
ir_tarval* tarval_eor ( ir_tarval a,
ir_tarval b 
)

Bitwise exclusive or of two integer tarvals.

Parameters
athe first tarval
bthe second tarval
Returns
a ^ b or tarval_bad
int tarval_get_exponent ( const ir_tarval tv)

Returns the exponent of a floating point IEEE-754 tarval.

Parameters
tvthe tarval
int tarval_get_wrap_on_overflow ( void  )

Returns 0 if operations return bad on overflow, != 0 if they wrap around.

int tarval_ieee754_can_conv_lossless ( const ir_tarval tv,
const ir_mode mode 
)

Check if the tarval can be converted to the given mode without precision loss.

Parameters
tvthe tarval
modethe mode to convert to
unsigned tarval_ieee754_get_exact ( void  )

Returns non-zero if the result of the last IEEE-754 operation was exact.

int tarval_is_all_one ( const ir_tarval tv)

returns non-zero if all bits in the tarval are set.

This means the value is -1 for signed modes with irma_twos_complement.

int tarval_is_constant ( const ir_tarval tv)

Returns non-zero if the tarval is a constant (i.e.

NOT a reserved tarval like bad, undef, reachable etc.)

int tarval_is_double ( const ir_tarval tv)

This validates if tarval_to_double() will return a satisfying result.

I.e. if tv is an float_number and between min, max of double

Parameters
tvthe tarval
int tarval_is_finite ( const ir_tarval tv)

Check if the tarval represents a finite value, ie neither NaN nor inf.

Parameters
tvthe tarval
int tarval_is_long ( const ir_tarval tv)

This validates if get_tarval_long() will return something sensible.

This is the case if the value is a two_complement (integer/reference) mode and converting it to a mode equivalent to "long" would not result in information loss. So ULONGMAX in an unsigned mode is fine, ULONG_MAX in a signed mode not.

Parameters
tvthe tarval
int tarval_is_nan ( const ir_tarval tv)

Check if tv is a floating point NaN.

Parameters
tvthe tarval
int tarval_is_negative ( const ir_tarval tv)

Returns 1 if tv is negative.

Parameters
tvthe tarval
int tarval_is_null ( const ir_tarval tv)

Returns 1 if tv is null.

Parameters
tvthe tarval
int tarval_is_one ( const ir_tarval tv)

Returns 1 if tv is the "one".

Parameters
tvthe tarval
int tarval_is_quiet_nan ( const ir_tarval tv)

Check if tv is a floating point quiet NaN.

Parameters
tvthe tarval
int tarval_is_signaling_nan ( const ir_tarval tv)

Check if tv is a floating point signaling NaN.

Parameters
tvthe tarval
ir_tarval* tarval_mod ( ir_tarval a,
ir_tarval b 
)

Remainder of integer division.

Parameters
athe first tarval
bthe second tarval
Returns
a % b or tarval_bad
ir_tarval* tarval_mul ( ir_tarval a,
ir_tarval b 
)

Multiplication of tarvals.

Parameters
athe first tarval
bthe second tarval
Returns
a * b or tarval_bad
ir_tarval* tarval_neg ( ir_tarval a)

Arithmetic Negation of a tarval.

Parameters
athe first tarval
Returns
-a or tarval_bad
ir_tarval* tarval_not ( ir_tarval a)

Bitwise Negation of a tarval.

Parameters
athe first tarval
Returns
~a or tarval_bad
ir_tarval* tarval_or ( ir_tarval a,
ir_tarval b 
)

Bitwise or of two integer tarvals.

Parameters
athe first tarval
bthe second tarval
Returns
a | b or tarval_bad
ir_tarval* tarval_ornot ( ir_tarval a,
ir_tarval b 
)

Bitwise or not of two integer tarvals.

Parameters
athe first tarval
bthe second tarval
Returns
a | ~b or tarval_bad
void tarval_set_wrap_on_overflow ( int  wrap_on_overflow)

Sets whether values should wrap on overflow or return the bad value.

ir_tarval* tarval_shl ( ir_tarval a,
ir_tarval b 
)

Logical Left shift.

Parameters
athe first tarval
bthe second tarval
Returns
a << b or tarval_bad
ir_tarval* tarval_shl_unsigned ( ir_tarval a,
unsigned  b 
)

logical left shift (variant with unsigned argument).

See Also
tarval_shl()
ir_tarval* tarval_shr ( ir_tarval a,
ir_tarval b 
)

Unsigned (logical) right shift.

Parameters
athe first tarval
bthe second tarval
Returns
a >>u b or tarval_bad
ir_tarval* tarval_shr_unsigned ( ir_tarval a,
unsigned  b 
)

unsigned (logical) right shift (variant with unsigned argument).

See Also
tarval_shr()
ir_tarval* tarval_shrs ( ir_tarval a,
ir_tarval b 
)

Signed (arithmetic) right shift.

Parameters
athe first tarval
bthe second tarval
Returns
a >>s b or tarval_bad
ir_tarval* tarval_shrs_unsigned ( ir_tarval a,
unsigned  b 
)

signed (arithmetic) right shift (variant with unsigned argument).

See Also
tarval_shrs()
ir_tarval* tarval_sub ( ir_tarval a,
ir_tarval b 
)

Subtraction from a tarval.

Parameters
athe first tarval
bthe second tarval
Returns
a - b or tarval_bad
void tarval_to_bytes ( unsigned char *  buffer,
ir_tarval tv 
)

Write tarval to a sequence of bytes.

The value is written in a "little endian" fashion which means the less significant bytes come first.

int tarval_zero_mantissa ( const ir_tarval tv)

Returns non-zero if the mantissa of a floating point tarval is zero (i.e.

1.0Exxx)

Parameters
tvthe tarval

Variable Documentation

ir_tarval* tarval_b_false

The mode_b tarval 'false'.

Definition at line 296 of file tv.h.

ir_tarval* tarval_b_true

The mode_b tarval 'true'.

Definition at line 301 of file tv.h.

ir_tarval* const tarval_bad

The 'bad' tarval.

Representing "no value", do not confuse this with tarval_unknown.

Definition at line 285 of file tv.h.

ir_tarval* const tarval_unknown

The 'unknown' tarval.

Representing an unknown (but legal) value, do not confuse this with tarval_bad.

Definition at line 291 of file tv.h.