192 #define SET_NONCONST(dtype, symbol) ((symbol)->const_value._##dtype.set_nonconst()) |
192 #define SET_NONCONST(dtype, symbol) ((symbol)->const_value._##dtype.set_nonconst()) |
193 |
193 |
194 #define VALID_CVALUE(dtype, symbol) ((symbol)->const_value._##dtype.is_valid()) |
194 #define VALID_CVALUE(dtype, symbol) ((symbol)->const_value._##dtype.is_valid()) |
195 #define IS_OVFLOW(dtype, symbol) ((symbol)->const_value._##dtype.is_overflow()) |
195 #define IS_OVFLOW(dtype, symbol) ((symbol)->const_value._##dtype.is_overflow()) |
196 #define IS_NONCONST(dtype, symbol) ((symbol)->const_value._##dtype.is_nonconst()) |
196 #define IS_NONCONST(dtype, symbol) ((symbol)->const_value._##dtype.is_nonconst()) |
|
197 #define IS_UNDEFINED(dtype, symbol) ((symbol)->const_value._##dtype.is_undefined()) |
197 #define ISZERO_CVALUE(dtype, symbol) ((symbol)->const_value._##dtype.is_zero()) |
198 #define ISZERO_CVALUE(dtype, symbol) ((symbol)->const_value._##dtype.is_zero()) |
198 |
199 |
199 |
200 |
200 #define ISEQUAL_CVALUE(dtype, symbol1, symbol2) \ |
201 #define ISEQUAL_CVALUE(dtype, symbol1, symbol2) \ |
201 (VALID_CVALUE(dtype, symbol1) && VALID_CVALUE(dtype, symbol2) && (GET_CVALUE(dtype, symbol1) == GET_CVALUE(dtype, symbol2))) |
202 (VALID_CVALUE(dtype, symbol1) && VALID_CVALUE(dtype, symbol2) && (GET_CVALUE(dtype, symbol1) == GET_CVALUE(dtype, symbol2))) |
1252 void *constant_folding_c::visit(external_declaration_c *symbol) { |
1253 void *constant_folding_c::visit(external_declaration_c *symbol) { |
1253 // The syntax does not allow VAR_EXTERN to be initialized. We must get the initial value from the corresponding VAR_GLOBAL declaration |
1254 // The syntax does not allow VAR_EXTERN to be initialized. We must get the initial value from the corresponding VAR_GLOBAL declaration |
1254 /* However, we only do this is if the visit() method for the Program/FB in which this VAR_EXTERN is found was called from the visit(configurtion/resource) visitor! |
1255 /* However, we only do this is if the visit() method for the Program/FB in which this VAR_EXTERN is found was called from the visit(configurtion/resource) visitor! |
1255 * When we are called from the visit(library_c) visitor, we do not have the required information to do this! |
1256 * When we are called from the visit(library_c) visitor, we do not have the required information to do this! |
1256 */ |
1257 */ |
1257 if (NULL != current_configuration) |
1258 if (NULL != current_configuration) { |
|
1259 /* before copying the constant value from the VAR_GLOBAL declaration (which is stored in the var_global_values[] map) |
|
1260 * we check to see if the VAR_EXTERN constant values has already been set by a previous call to constant fold the POU |
|
1261 * in which this VAR_EXTERN is found we simply check to see if any const value of this VAR_EXTERN variable has already |
|
1262 * been set previously! |
|
1263 */ |
|
1264 if ( !IS_UNDEFINED( int64, symbol->specification) || !IS_UNDEFINED(uint64, symbol->specification) |
|
1265 || !IS_UNDEFINED(real64, symbol->specification) || !IS_UNDEFINED( bool, symbol->specification)) { |
|
1266 /* The const_value for this VAR_EXTERN has already been previously set. Lets check to see if it is the exact |
|
1267 * same const value - if not we produce an error message! |
|
1268 * |
|
1269 * NOTE: comparison is inverted with '!' |
|
1270 */ |
|
1271 if (! (symbol->specification->const_value == var_global_values[get_var_name_c::get_name(symbol->global_var_name)->value])) |
|
1272 STAGE3_ERROR(0, symbol, symbol, "The initial value of this external variable is ambiguous (the Program/FB in which " |
|
1273 "this external variable is declared has been used to instantiate a Program/FB in more " |
|
1274 "than one configuration and/or resource - and each resource sets the corresponding global " |
|
1275 "variable to a distinct constant initial value)."); |
|
1276 } |
|
1277 |
|
1278 // only now do we copy the const value from the var_global to the var_external. |
1258 symbol->specification->const_value = var_global_values[get_var_name_c::get_name(symbol->global_var_name)->value]; |
1279 symbol->specification->const_value = var_global_values[get_var_name_c::get_name(symbol->global_var_name)->value]; |
|
1280 } |
1259 |
1281 |
1260 symbol->global_var_name->const_value = symbol->specification->const_value; |
1282 symbol->global_var_name->const_value = symbol->specification->const_value; |
1261 if (fixed_init_value_) { |
1283 if (fixed_init_value_) { |
1262 // values[symbol->global_var_name->get_value()] = symbol->specification->const_value; |
1284 // values[symbol->global_var_name->get_value()] = symbol->specification->const_value; |
1263 values[get_var_name_c::get_name(symbol->global_var_name)->value] = symbol->specification->const_value; |
1285 values[get_var_name_c::get_name(symbol->global_var_name)->value] = symbol->specification->const_value; |