X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Ftv%2Ftv.h;h=32f28af45688e674fafd4f3d2c72b4056c6bdf9e;hb=f7898331f5ad54e43402413c1d369cefe5e95335;hp=d56ab44bdde9665c92d3402b06f0639af61c5263;hpb=1e1770d41dd5b5fdbdcc65d44d3fd6c5b05c8fc9;p=libfirm diff --git a/ir/tv/tv.h b/ir/tv/tv.h index d56ab44bd..32f28af45 100644 --- a/ir/tv/tv.h +++ b/ir/tv/tv.h @@ -16,14 +16,11 @@ * * Declarations for Target Values. */ - #ifndef _TV_H_ #define _TV_H_ -# include "irmode.h" -# include "entity.h" -# include "irnode.h" /* for pnc_number enum */ - +#include "irmode.h" +#include "irnode.h" /****h* libfirm/tv * @@ -61,7 +58,7 @@ * SEE ALSO * Techreport 1999-14 * irmode.h for the modes definitions - * irnode.h for the pnc_numbers table + * irnode.h for the pn_Cmp table * * tarval_init1 and tarval_init2 for initialization of the * module @@ -151,18 +148,20 @@ tarval *new_tarval_from_str(const char *str, size_t len, ir_mode *mode); */ 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 tarval_to_long(tarval *tv); +long get_tarval_long(tarval *tv); /** - * This validates if tarval_to_long() will return a satisfying + * 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!) */ @@ -204,7 +203,7 @@ tarval *new_tarval_from_double(long double d, ir_mode *mode); * This will overflow silently, so use only if you know what * you are doing! (better check with tarval_is_long...) */ -long double tarval_to_double(tarval *tv); +long double get_tarval_double(tarval *tv); /** * This validates if tarval_to_double() will return a satisfying @@ -213,24 +212,6 @@ long double tarval_to_double(tarval *tv); */ int tarval_is_double(tarval *tv); -/** - * Construct a tarval that represents the address of the entity. - * - * The address must be constant, the entity must have as owner the global type. - */ -tarval *new_tarval_from_entity (entity *ent, ir_mode *mode); - -/** - * Returns the associated entity of a tarval. Asserts if tarval does not - * contain an entity. - */ -#define get_tarval_entity tarval_to_entity -entity *tarval_to_entity(tarval *tv); - -/** - * Returns non-zero if a the given tarval represents an entity. - */ -int tarval_is_entity(tarval *tv); /** ********** Access routines for tarval fields ********** **/ @@ -258,28 +239,31 @@ int tarval_is_entity(tarval *tv); */ /** Returns the mode of the tarval. */ -ir_mode *get_tarval_mode (tarval *tv); +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 + * @param a the tarval */ int tarval_is_negative(tarval *a); /** * Returns 1 if tv is null * - * @param a the tarval + * @param a the tarval */ int tarval_is_null(tarval *a); /** * Returns 1 if tv is the "one" * - * @param a the tarval + * @param a the tarval */ int tarval_is_one(tarval *a); @@ -295,6 +279,7 @@ tarval *get_tarval_undefined(void); /** The mode_b tarval 'false'. */ extern tarval *tarval_b_false; + /** Returns the mode_b tarval 'false'. */ tarval *get_tarval_b_false(void); @@ -326,39 +311,62 @@ tarval *get_tarval_null(ir_mode *mode); /** Returns the 1 value (multiplicative neutral) of a given mode. */ tarval *get_tarval_one(ir_mode *mode); +/** Returns the -1 value (multiplicative neutral) of a given mode. + * Returns tarval bad for unsigned modes */ +tarval *get_tarval_minus_one(ir_mode *mode); + /** Return quite nan for float_number modes. */ tarval *get_tarval_nan(ir_mode *mode); /** Return +inf for float_number modes. */ -tarval *get_tarval_inf(ir_mode *mode); +tarval *get_tarval_plus_inf(ir_mode *mode); + +/** Return -inf for float_number modes. */ +tarval *get_tarval_minus_inf(ir_mode *mode); -/* ******************** Arithmethic operations on tarvals ******************** */ +/* ******************** Arithmetic operations on tarvals ******************** */ + +typedef enum _tarval_int_overflow_mode_t { + TV_OVERFLOW_BAD, /**< tarval module will return tarval_bad if a overflow occurs */ + TV_OVERFLOW_WRAP, /**< tarval module will overflow will be ignored, wrap around occurs */ + TV_OVERFLOW_SATURATE /**< tarval module will saturate the overflow */ +} tarval_int_overflow_mode_t; + +/** + * Sets the overflow mode for integer operations. + */ +void tarval_set_integer_overflow_mode(tarval_int_overflow_mode_t ov_mode); + +/** + * Get the overflow mode for integer operations. + */ +tarval_int_overflow_mode_t tarval_get_integer_overflow_mode(void); /** * Compares two tarvals * - * Compare a with b and return a pnc_number describing the relation - * between a and b. This is either Uo, Lt, Eq, Gt, or False if a or b - * are symbolic pointers which can not be compared at all. + * Compare a with b and return a pn_Cmp describing the relation + * between a and b. This is either pn_Cmp_Uo, pn_Cmp_Lt, pn_Cmp_Eq, pn_Cmp_Gt, + * or pn_Cmp_False if a or b are symbolic pointers which can not be compared at all. * * @param a A tarval to be compared * @param b A tarval to be compared * * @return - * The pnc_number best describing the relation between a and b is returned. + * The pn_Cmp best describing the relation between a and b is returned. * This means the mode with the least bits set is returned, e.g. if the - * tarvals are equal the pnc_number 'Eq' is returned, not 'Ge' which + * tarvals are equal the pn_Cmp 'pn_Cmp_Eq' is returned, not 'pn_Cmp_Ge' which * indicates 'greater or equal' * * @sa - * irnode.h for the definition of pnc_numbers + * irnode.h for the definition of pn_Cmp */ -pnc_number tarval_cmp(tarval *a, tarval *b); +pn_Cmp tarval_cmp(tarval *a, tarval *b); /** * Converts a tarval to another mode. * - * Convert tarval 'src' to mode 'mode', this will suceed if and only if 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. * @@ -377,7 +385,7 @@ pnc_number tarval_cmp(tarval *a, tarval *b); * FIRM documentation for conversion rules * mode_is_smaller defined in irmode.h */ -tarval *tarval_convert_to(tarval *src, ir_mode *m); +tarval *tarval_convert_to(tarval *src, ir_mode *mode); /* * These function implement basic computations representable as opcodes @@ -388,12 +396,12 @@ tarval *tarval_convert_to(tarval *src, ir_mode *m); * traval_abs: * a - the tarval to operate on * - * all oters: + * all others: * a - the first operand tarval * b - the second operand tarval * * RESULT - * If neccessary a new tarval is constructed for the resulting value, + * If necessary a new tarval is constructed for the resulting value, * or the one already carrying the computation result is retrieved and * returned as result. * @@ -452,6 +460,9 @@ tarval *tarval_shrs(tarval *a, tarval *b); /** Rotation. */ tarval *tarval_rot(tarval *a, tarval *b); +/** Carry flag of the last operation */ +int tarval_carry(void); + /* *********** Output of tarvals *********** */ /** @@ -460,16 +471,16 @@ tarval *tarval_rot(tarval *a, tarval *b); * Some modes allow more that one representation, for instance integers * can be represented hex or decimal. Of course it would be enough to have * one and let every backend convert it into the 'right' one. - * However, we can do this in the tarval much simplier... + * However, we can do this in the tarval much simpler... */ typedef enum { - TVO_NATIVE, /**< the default output mode, depends on the mode */ - TVO_HEX, /**< use hex representation, always possible */ - TVO_DECIMAL, /**< use decimal representation */ - TVO_OCTAL, /**< use octal representation */ - TVO_BINARY, /**< use binary representation */ - TVO_FLOAT, /**< use floating point representation (i.e 1.342e-2)*/ - TVO_HEXFLOAT /**< use hexadecimal floating point representation (i.e 0x1.ea32p-12)*/ + TVO_NATIVE, /**< the default output mode, depends on the mode */ + TVO_HEX, /**< use hex representation, always possible */ + TVO_DECIMAL, /**< use decimal representation */ + TVO_OCTAL, /**< use octal representation */ + TVO_BINARY, /**< use binary representation */ + TVO_FLOAT, /**< use floating point representation (i.e 1.342e-2)*/ + TVO_HEXFLOAT /**< use hexadecimal floating point representation (i.e 0x1.ea32p-12)*/ } tv_output_mode; /** @@ -477,35 +488,35 @@ typedef enum { * of a tarval of a mode. */ typedef struct tarval_mode_info { - tv_output_mode mode_output; /**< if != TVO_NATIVE select a special mode */ - const char *mode_prefix; /**< if set, this prefix will be printed - before a value of this mode */ - const char *mode_suffix; /**< if set, this suffix will be printed - after a value of this mode */ + tv_output_mode mode_output; /**< if != TVO_NATIVE select a special mode */ + const char *mode_prefix; /**< if set, this prefix will be printed + before a value of this mode */ + const char *mode_suffix; /**< if set, this suffix will be printed + after a value of this mode */ } tarval_mode_info; /** * Specify the output options of one mode. * - * This functions stores the modinfo, so DO NOT DESTROY it. + * This functions stores the mode info, so DO NOT DESTROY it. * - * @param mode a ir_mode that should be associated - * @param modeinfo the output format info + * @param mode a ir_mode that should be associated + * @param modeinfo the output format info * * @return zero on success. */ -int tarval_set_mode_output_option(ir_mode *mode, const tarval_mode_info *modeinfo); +int set_tarval_mode_output_option(ir_mode *mode, const tarval_mode_info *modeinfo); /** * Returns the output options of one mode. * - * This functions returns the modinfo of a given mode. + * This functions returns the mode info of a given mode. * - * @param mode a ir_mode that should be associated + * @param mode a ir_mode that should be associated * * @return the output option */ -const tarval_mode_info *tarval_get_mode_output_option(ir_mode *mode); +const tarval_mode_info *get_tarval_mode_output_option(ir_mode *mode); /** * Returns Bit representation of a tarval value, as string of '0' and '1' @@ -523,14 +534,14 @@ const tarval_mode_info *tarval_get_mode_output_option(ir_mode *mode); * @note * The string is allocated using malloc() and is free()ed on the next call * of this function. - * The string consists of the ascii characters '0' and '1' and is + * The string consists of the ASCII characters '0' and '1' and is * null terminated * * @sa * irmode.h for the definition of the ir_mode struct * the size member of aforementioned struct */ -char *tarval_bitpattern(tarval *tv); +char *get_tarval_bitpattern(tarval *tv); /** * Returns the bitpattern of the bytes_ofs byte. @@ -548,45 +559,37 @@ char *tarval_bitpattern(tarval *tv); * Because this is the bit representation of the target machine, only the following * operations are legal on the result: * - * - concatenation (endian dependance MUST be handled by the CALLER) + * - concatenation (endian dependence MUST be handled by the CALLER) * - bitwise logical operations to select/mask bits * - * @param tv the tarval - * @param byte_ofs the byte offset + * @param tv the tarval + * @param byte_ofs the byte offset * * @note - * The result of this funcion is undefined if the mode is neither integer nor float. + * The result of this function is undefined if the mode is neither integer nor float. */ -unsigned char tarval_sub_bits(tarval *tv, unsigned byte_ofs); +unsigned char get_tarval_sub_bits(tarval *tv, unsigned byte_ofs); /** - * Identifying some tarvals ??? - * - * @return - * - 0 for additive neutral, - * - +1 for multiplicative neutral, - * - -1 for bitwise-and neutral - * - 2 else - * - * @deprecated - * This function is deprecated and its use strongly discouraged. - * Implemented for completeness. - */ -long tarval_classify(tarval *tv); - -/** - * Initialization of the tarval module. - * - * Call before init_mode(). + * Return values of tarval classify */ -void init_tarval_1(void); +typedef enum _tarval_classification_t { + TV_CLASSIFY_NULL = 0, /**< the tarval represents the additive neutral element */ + TV_CLASSIFY_ONE = +1, /**< the tarval represents the multiplicative neutral element */ + TV_CLASSIFY_ALL_ONE = -1, /**< the tarval represents the bitwise-and neutral element */ + TV_CLASSIFY_OTHER = 2 /**< all other tarvals */ +} tarval_classification_t; /** - * Initialization of the tarval module. - * - * Call after init_mode(). + * Identifying tarvals values for algebraic simplifications. + * @param tv + * @return + * - TV_CLASSIFY_NULL for additive neutral, + * - TV_CLASSIFY_ONE for multiplicative neutral, + * - TV_CLASSIFY_ALL_ONE for bitwise-and neutral + * - TV_CLASSIFY_OTHER else */ -void init_tarval_2(void); +tarval_classification_t classify_tarval(tarval *tv); /** * Output of tarvals to a buffer.