2 * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved.
4 * This file is part of libFirm.
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.
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.
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
22 * @brief Provides basic mathematical operations on values represented as strings.
24 * @author Mathias Heil
28 * The module uses a string to represent values, and provides operations
29 * to perform calculations with these values.
30 * Results are stored in an internal buffer, so you have to make a copy
31 * of them if you need to store the result.
34 #ifndef FIRM_TV_STRCALC_H
35 #define FIRM_TV_STRCALC_H
39 #ifdef STRCALC_DEBUG_ALL /* switch on all debug options */
40 # ifndef STRCALC_DEBUG
41 # define STRCALC_DEBUG /* switch on debug output */
43 # ifndef STRCALC_DEBUG_PRINTCOMP /* print arguments and result of each computation */
44 # define STRCALC_DEBUG_PRINTCOMP
46 # ifndef STRCALC_DEBUG_FULLPRINT
47 # define STRCALC_DEBUG_FULLPRINT /* print full length of values (e.g. 128 bit instead of 64 bit using default init) */
49 # ifndef STRCALC_DEBUG_GROUPPRINT
50 # define STRCALC_DEBUG_GROUPPRINT /* print spaces after each 8 bits */
55 * constants, typedefs, enums
58 #define SC_DEFAULT_PRECISION 64
80 * The output mode for integer values.
83 SC_hex, /**< hexadecimal output with small letters */
84 SC_HEX, /**< hexadecimal output with BIG letters */
85 SC_DEC, /**< decimal output */
86 SC_OCT, /**< octal output */
87 SC_BIN /**< binary output */
93 void sc_add(const void *value1, const void *value2, void *buffer);
94 void sc_sub(const void *value1, const void *value2, void *buffer);
95 void sc_neg(const void *value, void *buffer);
96 void sc_and(const void *value1, const void *value2, void *buffer);
97 void sc_or(const void *value1, const void *value2, void *buffer);
98 void sc_xor(const void *value1, const void *value2, void *buffer);
99 void sc_not(const void *value1, void *buffer);
100 void sc_mul(const void *value1, const void *value2, void *buffer);
101 void sc_div(const void *value1, const void *value2, void *buffer);
102 void sc_mod(const void *value1, const void *value2, void *buffer);
103 void sc_shl(const void *val1, const void *val2, int radius, int sign, void *buffer);
104 void sc_shr(const void *val1, const void *val2, int radius, int sign, void *buffer);
105 void sc_shrs(const void *val1, const void *val2, int radius, int sign, void *buffer);
106 void sc_rot(const void *val1, const void *val2, int radius, int sign, void *buffer);
109 * function declarations
111 const void *sc_get_buffer(void);
112 int sc_get_buffer_length(void);
114 void sign_extend(char *calc_buffer, ir_mode *mode);
116 /** create an value form a string representation */
117 void sc_val_from_str(const char *str, unsigned int len, void *buffer, ir_mode *mode);
119 /** create a value from a long */
120 void sc_val_from_long(long l, void *buffer);
122 /** create a value form an unsigned long */
123 void sc_val_from_ulong(unsigned long l, void *buffer);
125 /** converts a value to a long */
126 long sc_val_to_long(const void *val);
127 void sc_min_from_bits(unsigned int num_bits, unsigned int sign, void *buffer);
128 void sc_max_from_bits(unsigned int num_bits, unsigned int sign, void *buffer);
130 int sc_comp(const void *val1, const void *val2);
132 int sc_get_highest_set_bit(const void *value);
133 int sc_get_lowest_set_bit(const void *value);
134 int sc_is_zero(const void *value);
135 int sc_is_negative(const void *value);
136 int sc_had_carry(void);
137 unsigned char sc_sub_bits(const void *value, int len, unsigned byte_ofs);
140 * Converts a tarval into a string.
142 * @param val1 the value pointer
143 * @param bits number of valid bits in this value
144 * @param base output base
145 * @param signed_mode print it signed (only decimal mode supported
147 const char *sc_print(const void *val1, unsigned bits, enum base_t base, int signed_mode);
149 /** Initialize the strcalc module.
150 * Sets up internal data structures and constants
151 * After the first call subsequent calls have no effect
153 * @param precision_in_bytes Specifies internal precision to be used
154 * for calculations. The reason for being multiples of 8 eludes me
156 void init_strcalc(int precision_in_bytes);
157 void finish_strcalc(void);
158 int sc_get_precision(void);
160 #endif /* FIRM_TV_STRCALC_H */