-/* #include <gmp.h> Eli can't find gmp.h if it's available in a local
- search path but not in a standard one known to gcc. */
-#include "gmp.h"
-#undef __need_size_t /* erroneously defined by 1.3.2's gmp.h */
-/* #include "deftab.h" */
-
-/* how to represent target types on host */
-typedef float tarval_f;
-typedef double tarval_d;
-typedef long tarval_chil;
-typedef unsigned long tarval_CHIL;
-typedef MP_INT tarval_Z;
-typedef struct {
- /* if ent then xname is missing or mangled from ent,
- else if xname then xname is a linker symbol that is not mangled
- from an entity,
- else this is tarval_p_void.
- if this tarval describes a symbolic address of another tarval, tv points
- to this val */
- const char *xname;
- entity *ent;
- tarval *tv;
-} tarval_p;
-typedef struct {
- unsigned char *p; /* may contain embedded 0, not 0-terminated */
- size_t n;
-} tarval_s;
-typedef tarval_s tarval_B;
-
-struct tarval {
- union {
- tarval_f f; /* float */
- tarval_d d; /* double */
- tarval_chil chil; /* signed integral */
- tarval_CHIL CHIL; /* unsigned integral */
- tarval_Z Z; /* universal int */
- tarval_p p; /* pointer */
- bool b; /* boolean */
- tarval_B B; /* universal bits */
- tarval_s s; /* string */
- } u;
- ir_mode *mode;
-};
+/* ************************ Constructors for tarvals ************************ */
+
+/**
+ * Constructor function for new tarvals.
+ *
+ * @param str The string representing the target value
+ * @param len The length of the string
+ * @param mode The 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(x|X)[0-9a-fA-F]+ (hexadecimal representation)
+ * - 0[0-7]* (octal representation)
+ * - (+|-)?[1-9][0-9]* (decimal representation)
+ *
+ * if mode if float_number:
+ * - (+|-)?(decimal int) (. (decimal int))? ((e|E)(+|-)?(decimal int))?
+ *
+ * if mode is boolean: true, True, TRUE ... False... 0, 1,
+ *
+ * if mode is reference: hexadecimal of decimal number as int
+ *
+ * if mode is character: hex or dec
+ *
+ * Leading and/or trailing spaces are ignored
+ *
+ * @return
+ * 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 string is not representable in the given mode an assertion is
+ * thrown in assert build.
+ *
+ * @sa
+ * irmode.h for predefined modes
+ * new_tarval_from_long()
+ * new_tarval_from_double()
+ */
+tarval *new_tarval_from_str(const char *str, size_t len, ir_mode *mode);
+
+/**
+ * Constructor function for new tarvals
+ *
+ * @param l The long representing the value
+ * @param mode The mode requested for the result tarval
+ *
+ * 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.
+ *
+ * @return
+ * 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.
+ *
+ * @sa
+ * irmode.h for predefined modes
+ * new_tarval_from_str()
+ * new_tarval_from_double()
+ *
+ */
+tarval *new_tarval_from_long(long l, ir_mode *mode);
+
+/** Return value as long if possible.
+ *
+ * This returns a long int with the value represented value, or
+ * gibberish, depending on the size of long int and the size of the
+ * stored value. It works for e.g. 1 as mode_Ls, but might not work for
+ * get_mode_max(mode_Ls).
+ * This will overflow silently, so use only if you know what
+ * you are doing! (better check with tarval_is_long()...)
+ * Works only for int modes, even not for character modes!
+ */
+long get_tarval_long(tarval *tv);
+
+/**
+ * This validates if get_tarval_long() will return a satisfying
+ * result. I.e. if tv is an int_number and between min, max
+ * of long int (signed!)
+ */
+int tarval_is_long(tarval *tv);
+
+/**
+ * Constructor function for new tarvals.
+ *
+ * @param d The (long) double representing the value
+ * @param mode The 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.
+ *
+ * @return
+ * 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.
+ *
+ * @sa
+ * irmode.h for predefined values
+ * new_tarval_from_str()
+ * new_tarval_from_long()
+ */
+tarval *new_tarval_from_double(long double d, ir_mode *mode);
+
+/**
+ * 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...)
+ */
+long double get_tarval_double(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
+ */
+int tarval_is_double(tarval *tv);
+
+
+/** ********** Access routines for tarval fields ********** **/
+
+/*
+ * NAME
+ * get_tarval_mode
+ * get_tarval_ ...
+ *
+ * SYNOPSIS
+ * ir_mode *get_tarval_mode(tarval *tv)
+ * ...
+ *
+ * DESCRIPTION
+ * These are access function for tarval struct members. It is encouraged
+ * to use them instead of direct access to the struct fields.
+ *
+ * PARAMETERS
+ * tv - The tarval to access fields of
+ *
+ * RESULT
+ * get_tv_mode: The mode of the tarval
+ *
+ * SEE ALSO
+ * the struct tarval
+ */
+
+/** Returns the mode of the tarval. */
+ir_mode *get_tarval_mode (const tarval *tv);
+
+/** Returns the contents of the 'link' field of the tarval */
+/* void *get_tarval_link (tarval*); */
+
+/* Testing properties of the represented values */
+
+/**
+ * Returns 1 if tv is negative
+ *
+ * @param a the tarval
+ */
+int tarval_is_negative(tarval *a);
+
+/**
+ * Returns 1 if tv is null
+ *
+ * @param a the tarval
+ */
+int tarval_is_null(tarval *a);