stage3/constant_folding.cc
changeset 648 5ca2aabb8bcb
parent 643 1cc0e1ca2aad
child 661 f537c3315f83
equal deleted inserted replaced
647:99b45154eb2c 648:5ca2aabb8bcb
   180 #define SET_OVFLOW(dtype, symbol)             ((symbol)->const_value._##dtype.status) = symbol_c::cs_overflow
   180 #define SET_OVFLOW(dtype, symbol)             ((symbol)->const_value._##dtype.status) = symbol_c::cs_overflow
   181 #define SET_NONCONST(dtype, symbol)           ((symbol)->const_value._##dtype.status) = symbol_c::cs_non_const
   181 #define SET_NONCONST(dtype, symbol)           ((symbol)->const_value._##dtype.status) = symbol_c::cs_non_const
   182 
   182 
   183 #define VALID_CVALUE(dtype, symbol)           (symbol_c::cs_const_value == (symbol)->const_value._##dtype.status)
   183 #define VALID_CVALUE(dtype, symbol)           (symbol_c::cs_const_value == (symbol)->const_value._##dtype.status)
   184 #define IS_OVFLOW(dtype, symbol)              (symbol_c::cs_overflow    == (symbol)->const_value._##dtype.status)
   184 #define IS_OVFLOW(dtype, symbol)              (symbol_c::cs_overflow    == (symbol)->const_value._##dtype.status)
       
   185 #define IS_NONCONST(dtype, symbol)            (symbol_c::cs_non_const   == (symbol)->const_value._##dtype.status)
   185 #define ISZERO_CVALUE(dtype, symbol)          ((VALID_CVALUE(dtype, symbol)) && (GET_CVALUE(dtype, symbol) == 0))
   186 #define ISZERO_CVALUE(dtype, symbol)          ((VALID_CVALUE(dtype, symbol)) && (GET_CVALUE(dtype, symbol) == 0))
   186 
   187 
   187 #define ISEQUAL_CVALUE(dtype, symbol1, symbol2) \
   188 #define ISEQUAL_CVALUE(dtype, symbol1, symbol2) \
   188 	(VALID_CVALUE(dtype, symbol1) && VALID_CVALUE(dtype, symbol2) && (GET_CVALUE(dtype, symbol1) == GET_CVALUE(dtype, symbol2))) 
   189 	(VALID_CVALUE(dtype, symbol1) && VALID_CVALUE(dtype, symbol2) && (GET_CVALUE(dtype, symbol1) == GET_CVALUE(dtype, symbol2))) 
   189 
   190 
   190 #define DO_BINARY_OPER(oper_type, operation, res_type, operand1, operand2) {                                             \
   191 #define DO_BINARY_OPER(oper_type, operation, res_type, operand1, operand2) {                                              \
   191 	if (VALID_CVALUE(oper_type, operand1) && VALID_CVALUE(oper_type, operand2))                                       \
   192 	if      (VALID_CVALUE(oper_type, operand1) && VALID_CVALUE(oper_type, operand2))                                  \
   192 		SET_CVALUE(res_type, symbol, GET_CVALUE(oper_type, operand1) operation GET_CVALUE(oper_type, operand2));  \
   193 		{SET_CVALUE(res_type, symbol, GET_CVALUE(oper_type, operand1) operation GET_CVALUE(oper_type, operand2));}\
       
   194 	else if (IS_OVFLOW   (oper_type, operand1) || IS_OVFLOW   (oper_type, operand2))                                  \
       
   195 		{SET_OVFLOW(res_type, symbol);}  /* does it really make sense to set OVFLOW when restype is boolean??  */ \
       
   196 	else if (IS_NONCONST (oper_type, operand1) || IS_NONCONST (oper_type, operand2))                                  \
       
   197 		{SET_NONCONST(res_type, symbol);}                                                                         \
   193 }
   198 }
   194 
   199 
   195 #define DO_UNARY_OPER(dtype, operation, operand) {                                                                        \
   200 #define DO_UNARY_OPER(dtype, operation, operand) {                                                                        \
   196 	if (VALID_CVALUE(dtype, operand))                                                                                 \
   201 	if      (VALID_CVALUE(dtype, operand))                                                                            \
   197 		SET_CVALUE(dtype, symbol, operation GET_CVALUE(dtype, operand));                                          \
   202 		{SET_CVALUE(dtype, symbol, operation GET_CVALUE(dtype, operand));}                                        \
       
   203 	else if (IS_OVFLOW   (dtype, operand))                                                                            \
       
   204 		{SET_OVFLOW(dtype, symbol);}                                                                              \
       
   205 	else if (IS_NONCONST (dtype, operand))                                                                            \
       
   206 		{SET_NONCONST(dtype, symbol);}                                                                            \
   198 }
   207 }
   199 
   208 
   200 
   209 
   201 
   210 
   202 
   211