721 SET_CVALUE(real64, symbol, pow(GET_CVALUE(real64, oper1), GET_CVALUE( int64, oper2))); |
723 SET_CVALUE(real64, symbol, pow(GET_CVALUE(real64, oper1), GET_CVALUE( int64, oper2))); |
722 if (VALID_CVALUE(real64, oper1) && VALID_CVALUE(uint64, oper2)) |
724 if (VALID_CVALUE(real64, oper1) && VALID_CVALUE(uint64, oper2)) |
723 SET_CVALUE(real64, symbol, pow(GET_CVALUE(real64, oper1), GET_CVALUE(uint64, oper2))); |
725 SET_CVALUE(real64, symbol, pow(GET_CVALUE(real64, oper1), GET_CVALUE(uint64, oper2))); |
724 CHECK_OVERFLOW_real64(symbol); |
726 CHECK_OVERFLOW_real64(symbol); |
725 return NULL; |
727 return NULL; |
|
728 } |
|
729 |
|
730 static map_values_t inner_left_join_values(map_values_t m1, map_values_t m2) { |
|
731 map_values_t::const_iterator itr; |
|
732 map_values_t ret; |
|
733 |
|
734 itr = m1.begin(); |
|
735 for ( ; itr != m1.end(); ++itr) { |
|
736 std::string name = itr->first; |
|
737 symbol_c::const_value_t value; |
|
738 |
|
739 if (m2.count(name) > 0) { |
|
740 symbol_c::const_value_t c1 = itr->second; |
|
741 symbol_c::const_value_t c2 = m2[name]; |
|
742 COMPUTE_MEET_SEMILATTICE (real64, c1, c2, value); |
|
743 COMPUTE_MEET_SEMILATTICE (uint64, c1, c2, value); |
|
744 COMPUTE_MEET_SEMILATTICE ( int64, c1, c2, value); |
|
745 COMPUTE_MEET_SEMILATTICE ( bool, c1, c2, value); |
|
746 } else |
|
747 value = m1[name]; |
|
748 ret[name] = value; |
|
749 } |
|
750 |
|
751 return ret; |
726 } |
752 } |
727 |
753 |
728 /***********************************************************************/ |
754 /***********************************************************************/ |
729 /***********************************************************************/ |
755 /***********************************************************************/ |
730 /***********************************************************************/ |
756 /***********************************************************************/ |
1287 values = values_incoming; |
1319 values = values_incoming; |
1288 symbol->else_statement_list->accept(*this); |
1320 symbol->else_statement_list->accept(*this); |
1289 values_elsestatement_result = values; |
1321 values_elsestatement_result = values; |
1290 } else |
1322 } else |
1291 values_elsestatement_result = values_incoming; |
1323 values_elsestatement_result = values_incoming; |
1292 values.clear(); |
1324 values = inner_left_join_values(values_statement_result, values_elsestatement_result); |
1293 itr = values_statement_result.begin(); |
|
1294 for ( ; itr != values_statement_result.end(); ++itr) { |
|
1295 std::string name = itr->first; |
|
1296 symbol_c::const_value_t value; |
|
1297 |
|
1298 if (values_elsestatement_result.count(name) > 0) { |
|
1299 symbol_c::const_value_t c1 = itr->second; |
|
1300 symbol_c::const_value_t c2 = values_elsestatement_result[name]; |
|
1301 COMPUTE_MEET_SEMILATTICE (real64, c1, c2, value); |
|
1302 COMPUTE_MEET_SEMILATTICE (uint64, c1, c2, value); |
|
1303 COMPUTE_MEET_SEMILATTICE ( int64, c1, c2, value); |
|
1304 COMPUTE_MEET_SEMILATTICE ( bool, c1, c2, value); |
|
1305 } else |
|
1306 value = values_statement_result[name]; |
|
1307 values[name] = value; |
|
1308 } |
|
1309 |
1325 |
1310 return NULL; |
1326 return NULL; |
1311 } |
1327 } |
1312 |
1328 |
1313 /********************************/ |
1329 /********************************/ |
1314 /* B 3.2.4 Iteration Statements */ |
1330 /* B 3.2.4 Iteration Statements */ |
1315 /********************************/ |
1331 /********************************/ |
1316 void *constant_folding_c::visit(for_statement_c *symbol) { |
1332 void *constant_folding_c::visit(for_statement_c *symbol) { |
1317 std::map <std::string, symbol_c::const_value_t> values_incoming; |
1333 map_values_t values_incoming; |
1318 std::map <std::string, symbol_c::const_value_t> values_statement_result; |
1334 map_values_t values_statement_result; |
1319 std::map <std::string, symbol_c::const_value_t>::iterator itr; |
|
1320 std::string varName; |
1335 std::string varName; |
1321 |
1336 |
1322 values_incoming = values; /* save incoming status */ |
1337 values_incoming = values; /* save incoming status */ |
1323 symbol->beg_expression->accept(*this); |
1338 symbol->beg_expression->accept(*this); |
1324 symbol->end_expression->accept(*this); |
1339 symbol->end_expression->accept(*this); |
1325 varName = get_var_name_c::get_name(symbol->control_variable)->value; |
1340 varName = get_var_name_c::get_name(symbol->control_variable)->value; |
1326 values[varName] = symbol->beg_expression->const_value; |
1341 values[varName]._int64.status = symbol_c::cs_non_const; |
1327 |
1342 |
1328 /* Optimize dead code */ |
1343 /* Optimize dead code */ |
1329 if (VALID_CVALUE(int64, symbol->beg_expression) && VALID_CVALUE(int64, symbol->end_expression) && |
1344 if (NULL != symbol->by_expression) { |
1330 GET_CVALUE(int64, symbol->beg_expression) > GET_CVALUE(int64, symbol->end_expression)) |
1345 symbol->by_expression->accept(*this); |
1331 return NULL; |
1346 if (VALID_CVALUE(int64, symbol->by_expression ) && GET_CVALUE(int64, symbol->by_expression ) > 0 && |
|
1347 VALID_CVALUE(int64, symbol->beg_expression) && VALID_CVALUE(int64, symbol->end_expression) && |
|
1348 GET_CVALUE(int64, symbol->beg_expression) > GET_CVALUE(int64, symbol->end_expression)) |
|
1349 return NULL; |
|
1350 |
|
1351 if (VALID_CVALUE(int64, symbol->by_expression ) && GET_CVALUE(int64, symbol->by_expression ) < 0 && |
|
1352 VALID_CVALUE(int64, symbol->beg_expression) && VALID_CVALUE(int64, symbol->end_expression) && |
|
1353 GET_CVALUE(int64, symbol->beg_expression) < GET_CVALUE(int64, symbol->end_expression)) |
|
1354 return NULL; |
|
1355 |
|
1356 } else { |
|
1357 if (VALID_CVALUE(int64, symbol->beg_expression) && VALID_CVALUE(int64, symbol->end_expression) && |
|
1358 GET_CVALUE(int64, symbol->beg_expression) > GET_CVALUE(int64, symbol->end_expression)) |
|
1359 return NULL; |
|
1360 |
|
1361 } |
|
1362 |
1332 |
1363 |
1333 symbol->statement_list->accept(*this); |
1364 symbol->statement_list->accept(*this); |
1334 values_statement_result = values; |
1365 values_statement_result = values; |
1335 values.clear(); |
1366 values = inner_left_join_values(values_statement_result, values_incoming); |
1336 itr = values_statement_result.begin(); |
|
1337 for ( ; itr != values_statement_result.end(); ++itr) { |
|
1338 std::string name = itr->first; |
|
1339 symbol_c::const_value_t value; |
|
1340 |
|
1341 if (values_incoming.count(name) > 0) { |
|
1342 symbol_c::const_value_t c1 = itr->second; |
|
1343 symbol_c::const_value_t c2 = values_incoming[name]; |
|
1344 COMPUTE_MEET_SEMILATTICE (real64, c1, c2, value); |
|
1345 COMPUTE_MEET_SEMILATTICE (uint64, c1, c2, value); |
|
1346 COMPUTE_MEET_SEMILATTICE ( int64, c1, c2, value); |
|
1347 COMPUTE_MEET_SEMILATTICE ( bool, c1, c2, value); |
|
1348 } else |
|
1349 value = values_statement_result[name]; |
|
1350 values[name] = value; |
|
1351 } |
|
1352 |
1367 |
1353 return NULL; |
1368 return NULL; |
1354 } |
1369 } |
1355 |
1370 |
1356 void *constant_folding_c::visit(while_statement_c *symbol) { |
1371 void *constant_folding_c::visit(while_statement_c *symbol) { |
1357 std::map <std::string, symbol_c::const_value_t> values_incoming; |
1372 map_values_t values_incoming; |
1358 std::map <std::string, symbol_c::const_value_t> values_statement_result; |
1373 map_values_t values_statement_result; |
1359 std::map <std::string, symbol_c::const_value_t>::iterator itr; |
|
1360 |
1374 |
1361 /* Optimize dead code */ |
1375 /* Optimize dead code */ |
1362 symbol->expression->accept(*this); |
1376 symbol->expression->accept(*this); |
1363 if (VALID_CVALUE(bool, symbol->expression) && GET_CVALUE(bool, symbol->expression) == false) |
1377 if (VALID_CVALUE(bool, symbol->expression) && GET_CVALUE(bool, symbol->expression) == false) |
1364 return NULL; |
1378 return NULL; |
1365 |
1379 |
1366 values_incoming = values; /* save incoming status */ |
1380 values_incoming = values; /* save incoming status */ |
1367 symbol->statement_list->accept(*this); |
1381 symbol->statement_list->accept(*this); |
1368 values_statement_result = values; |
1382 values_statement_result = values; |
1369 values.clear(); |
1383 values = inner_left_join_values(values_statement_result, values_incoming); |
1370 itr = values_statement_result.begin(); |
|
1371 for ( ; itr != values_statement_result.end(); ++itr) { |
|
1372 std::string name = itr->first; |
|
1373 symbol_c::const_value_t value; |
|
1374 |
|
1375 if (values_incoming.count(name) > 0) { |
|
1376 symbol_c::const_value_t c1 = itr->second; |
|
1377 symbol_c::const_value_t c2 = values_incoming[name]; |
|
1378 COMPUTE_MEET_SEMILATTICE (real64, c1, c2, value); |
|
1379 COMPUTE_MEET_SEMILATTICE (uint64, c1, c2, value); |
|
1380 COMPUTE_MEET_SEMILATTICE ( int64, c1, c2, value); |
|
1381 COMPUTE_MEET_SEMILATTICE ( bool, c1, c2, value); |
|
1382 } else |
|
1383 value = values_statement_result[name]; |
|
1384 values[name] = value; |
|
1385 } |
|
1386 |
|
1387 |
1384 |
1388 return NULL; |
1385 return NULL; |
1389 } |
1386 } |
1390 |
1387 |
1391 void *constant_folding_c::visit(repeat_statement_c *symbol) { |
1388 void *constant_folding_c::visit(repeat_statement_c *symbol) { |
1392 std::map <std::string, symbol_c::const_value_t> values_incoming; |
1389 map_values_t values_incoming; |
1393 std::map <std::string, symbol_c::const_value_t> values_statement_result; |
1390 map_values_t values_statement_result; |
1394 std::map <std::string, symbol_c::const_value_t>::iterator itr; |
1391 |
|
1392 values_incoming = values; /* save incoming status */ |
|
1393 symbol->statement_list->accept(*this); |
1395 |
1394 |
1396 /* Optimize dead code */ |
1395 /* Optimize dead code */ |
1397 symbol->expression->accept(*this); |
1396 symbol->expression->accept(*this); |
1398 if (VALID_CVALUE(bool, symbol->expression) && GET_CVALUE(bool, symbol->expression) == false) |
1397 if (VALID_CVALUE(bool, symbol->expression) && GET_CVALUE(bool, symbol->expression) == true) |
1399 return NULL; |
1398 return NULL; |
1400 |
1399 |
1401 values_incoming = values; /* save incoming status */ |
|
1402 symbol->statement_list->accept(*this); |
|
1403 values_statement_result = values; |
1400 values_statement_result = values; |
1404 values.clear(); |
1401 values = inner_left_join_values(values_statement_result, values_incoming); |
1405 itr = values_statement_result.begin(); |
1402 |
1406 for ( ; itr != values_statement_result.end(); ++itr) { |
1403 return NULL; |
1407 std::string name = itr->first; |
1404 } |
1408 symbol_c::const_value_t value; |
1405 |
1409 |
1406 #endif // DO_CONSTANT_PROPAGATION__ |
1410 if (values_incoming.count(name) > 0) { |
1407 |
1411 symbol_c::const_value_t c1 = itr->second; |
1408 |
1412 symbol_c::const_value_t c2 = values_incoming[name]; |
|
1413 COMPUTE_MEET_SEMILATTICE (real64, c1, c2, value); |
|
1414 COMPUTE_MEET_SEMILATTICE (uint64, c1, c2, value); |
|
1415 COMPUTE_MEET_SEMILATTICE ( int64, c1, c2, value); |
|
1416 COMPUTE_MEET_SEMILATTICE ( bool, c1, c2, value); |
|
1417 } else |
|
1418 value = values_statement_result[name]; |
|
1419 values[name] = value; |
|
1420 } |
|
1421 |
|
1422 |
|
1423 return NULL; |
|
1424 } |
|
1425 |
|
1426 |
|
1427 |
|