*
* @author Christian Schaefer, Matthias Heil
*
- * This module specifies the modes that type the firm nodes.
+ * This module specifies the modes that type the firm nodes. It defines
+ * a datasturcture that describes a mode and implements constructors and
+ * access routines to this datastructure. Further it defines a set of
+ * predefined modes.
*
* SEE ALSO:
* UKA tech report 1999-44 for more information about modes.
* Contains relevant information about a mode.
*
* Neccessary information about a mode is stored in this struct
- * which is used by the tarval modul to perform calculations
+ * which is used by the tarval module to perform calculations
* and comparisons of values of a such described mode.
*
* ATTRIBUTES:
- * - modecode code: An unambigous int for the mode
- * - ident *name: Name of this mode
+ * - modecode code: An unambigous int (enum) for the mode
+ * - ident *name: Name of this mode. Two modes are different if the name is different.
* - mode_sort sort: sort of mode specifying possible usage kategories
* - int size: size of the mode in Bits.
* - int align: byte alignment
irm_max /**< maximum value for modecode */
} modecode;
-/** These values represent the different arithmetics used to
- * manipulate values.
+/** These values represent the different mode classes of value representations.
*/
typedef enum {
/* Predefined sorts of modes */
- auxiliary, /**< Only for Firm use, predefined. */
- internal_boolean, /**< Internal boolean representation.
- Storing to memory impossible, convert first. */
+ irms_auxiliary, /**< Only for Firm use, predefined. (irm_BB, irm_X, irm_T, irm_M) */
+ irms_internal_boolean, /**< Internal boolean representation.
+ Storing to memory impossible, convert first. */
/** user-extensible sorts of modes **/
- int_number, /**< A mode to represent int numbers.
- Integer computations can be performed. */
- float_number, /**< A mode to represent float numbers.
- Floating point computations can be performed. */
- reference, /**< A mode to represent entities.
- Restricted int computations can be performed */
- character /**< A mode to represent characters/symbols
- ?? Are computations allowed? as int?? */
+ irms_int_number, /**< A mode to represent int numbers.
+ Integer computations can be performed. */
+ irms_float_number, /**< A mode to represent float numbers.
+ Floating point computations can be performed. */
+ irms_reference, /**< A mode to represent entities.
+ Restricted int computations can be performed */
+ irms_character /**< A mode to represent characters/symbols
+ ?? Are computations allowed? as int?? */
} mode_sort;
+/** These values represent the different arithmetic operations possible with a mode.
+ Further arithmetics can be defined, e.g., for @@@ modes.
+ */
+typedef enum {
+ irma_uninitialized = 0,
+ irma_none = 1, /**< For modes for which no representation is specified.
+ These are modes of sort auxiliary, internal_boolean and
+ character. */
+ irma_twos_complement = 2, /**< Values of the mode are represented as two's complement.
+ Only legal for modes of sort int_number and reference. */
+ irma_ones_complement, /**< Values of the mode are represented as one's complement.
+ Only legal for modes of sort int_number and reference. */
+ irma_int_BCD, /**< Values of the mode are represented as binary coded decimals.
+ Only legal for modes of sort int_number and reference. */
+ irma_ieee754 = 256, /**< Values of the mode are represented according to ieee754
+ floatingpoint standard. Only legal for modes of sort float_number. */
+ irma_float_BCD, /**< Values of the mode are represented as binary coded decimals
+ according to @@@ which standars??? Only legal for modes of
+ sort float_number. */
+ irma_max
+} mode_arithmetic;
+
+
/* ********** Constructor for user defined modes **************** */
/**
- * Registers a new mode.
- * Must be called BEFORE init_mode2() !!!
+ * Creates a new mode.
*
- * The information for new mode is retrieved from the mode
- * struct passed as parameter, the code field is ignored.
- * The struct is copied into the internal mode array and the code
- * field will be set to a unique integer.
+ * @param name the name of the mode to be created
+ * @param sort the mode_sort of the mode to be created
+ * @param bit_size number of bits this mode allocate
+ * @param align the byte alignment for an entity of this mode (in bits)
+ * @param sign non-zero if this is a signed mode
+ *
+ * This function constructs a new mode given by the parameters.
+ * If the parameters match an already defined mode, this mode is returned
+ * (including the default modes).
+ * If the mode is newly allocated, a new unique mode_code is choosen.
* Also, special value tarvals will be calculated such as null,
* min, max and can be retrieved using the get_mode_* fuctions
*
- * If a mode with the given characteristics already exists,
- * it will be returned instead of creating a new one.
+ * @return
+ * The new mode or NULL on error.
*
- * The passed struct can be safely deallocated after the function
- * returns.
- * To access the new mode the returned mode pointer must be used!
+ * @note
+ * It is allowed to construct the default modes. So, a call
+ * new_ir_mode("Is", irms_int_number, 32, 4, 1) will return mode_Is.
*/
-ir_mode *register_mode(ir_mode* new_mode);
+ir_mode *new_ir_mode(const char *name, mode_sort sort, int bit_size, int align, int sign);
/* ********** Access methods to read mode information *********** */
-#ifdef MODE_ACCESS_DEFINES
-# include "irmode_t.h"
-# define get_mode_modecode(mode) (mode)->code
-# define get_mode_ident(mode) (mode)->name
-# define get_mode_name(mode) id_to_str((mode)->name)
-# define get_mode_sort(mode) (mode)->sort
-# define get_mode_size_bits(mode) (mode)->size
-# define get_mode_align(mode) (mode)->align
-#else
/** Returns the classification of the mode */
modecode get_mode_modecode(ir_mode *mode);
/** Returns the alignment of values of the mode in bytes. */
int get_mode_align(ir_mode *mode);
-#endif
+
+/** Returns the signess of a mode */
+int get_mode_sign (ir_mode *mode);
/**
* Returns the smallest representable value of a given mode.
datab or dataM.
For more exact definitions read the corresponding pages
- in the firm documentation or the followingenumeration
+ in the firm documentation or the following enumeration
The set of "float" is defined as:
float = {irm_F, irm_D, irm_E}
*/
/*@}*/
/* Test for a certain class of modes. */
-#ifdef MODE_ACCESS_DEFINES
-# define mode_is_signed(mode) (mode)->sign
-# define mode_is_float(mode) ((mode)->sort == float_number)
-# define mode_is_int(mode) ((mode)->sort == int_number)
-# define mode_is_num(mode) (((mode)->sort == float_number) || ((mode)->sort == int_number))
-# define mode_is_data(mode) (((mode)->sort == float_number) || ((mode)->sort == int_number) || ((mode)->sort == character) || ((mode)->sort == reference))
-# define mode_is_datab(mode) (((mode)->sort == float_number) || ((mode)->sort == int_number) || ((mode)->sort == character) || ((mode)->sort == reference) || ((mode)->sort == internal_boolean))
-# define mode_is_dataM(mode) (((mode)->sort == float_number) || ((mode)->sort == int_number) || ((mode)->sort == character) || ((mode)->sort == reference) || ((mode)->code == irm_M))
-#else
int mode_is_signed (ir_mode *mode);
int mode_is_float (ir_mode *mode);
int mode_is_int (ir_mode *mode);
+int mode_is_character (ir_mode *mode);
+int mode_is_reference (ir_mode *mode);
int mode_is_num (ir_mode *mode);
int mode_is_data (ir_mode *mode);
int mode_is_datab (ir_mode *mode);
int mode_is_dataM (ir_mode *mode);
-#endif
/** Returns true if sm can be converted to lm without loss
according to firm definiton */
int smaller_mode(ir_mode *sm, ir_mode *lm);