| 657 | } |
| 658 | |
| 659 | int |
| 660 | Reducer::reduce_const_binary_op(const FunctionInvocationBinary* fib) |
| 661 | { |
| 662 | const Expression* op1 = fib->param_value[0]; |
| 663 | const Expression* op2 = fib->param_value[1]; |
| 664 | if (op1->get_invoke() != NULL && map_reduced_invocations.find(op1->get_invoke()) != map_reduced_invocations.end()) { |
| 665 | op1 = map_reduced_invocations[op1->get_invoke()]; |
| 666 | } |
| 667 | if (op2->get_invoke() != NULL && map_reduced_invocations.find(op2->get_invoke()) != map_reduced_invocations.end()) { |
| 668 | op2 = map_reduced_invocations[op2->get_invoke()]; |
| 669 | } |
| 670 | if (op1->term_type == eConstant || map_reduced_vars.find(op1) != map_reduced_vars.end()) { |
| 671 | string str1 = (op1->term_type == eConstant) ? ((const Constant*)op1)->get_value() : map_reduced_vars[op1]; |
| 672 | if (op2->term_type == eConstant || map_reduced_vars.find(op2) != map_reduced_vars.end()) { |
| 673 | string str2 = (op2->term_type == eConstant) ? ((const Constant*)op2)->get_value() : map_reduced_vars[op2]; |
| 674 | INT64 result = 0; |
| 675 | INT64 v1 = StringUtils::str2longlong(str1); |
| 676 | INT64 v2 = StringUtils::str2longlong(str2); |
| 677 | switch (fib->get_operation()) { |
| 678 | case eAdd: result = v1 + v2; break; |
| 679 | case eSub: result = v1 - v2; break; |
| 680 | case eMul: result = v1 * v2; break; |
| 681 | case eDiv: result = v2 ? v1 / v2 : v1; break; |
| 682 | case eMod: result = v2 ? v1 % v2 : v1; break; |
| 683 | case eCmpGt: result = v1 > v2; break; |
| 684 | case eCmpLt: result = v1 < v2; break; |
| 685 | case eCmpGe: result = v1 >= v2; break; |
| 686 | case eCmpLe: result = v1 <= v2; break; |
| 687 | case eCmpEq: result = v1 == v2; break; |
| 688 | case eCmpNe: result = v1 != v2; break; |
| 689 | case eAnd: result = v1 && v2; break; |
| 690 | case eOr: result = v1 || v2; break; |
| 691 | case eBitXor: result = v1 ^ v2; break; |
| 692 | case eBitAnd: result = v1 & v2; break; |
| 693 | case eBitOr: result = v1 | v2; break; |
| 694 | case eRShift: result = (v2 > 0) ? v1 >> v2 : v1; break; |
| 695 | case eLShift: result = (v2 > 0) ? v1 << v2 : v1; break; |
| 696 | } |
| 697 | Constant* cst = new Constant(&fib->get_type(), StringUtils::longlong2str(result)); |
| 698 | map_reduced_invocations[fib] = cst; |
| 699 | return 1; |
| 700 | } |
| 701 | } |
| 702 | return 0; |
| 703 | } |
| 704 | |
| 705 | void |
| 706 | Reducer::reduce_const_binary_ops(vector<const FunctionInvocationBinary*>& ops) |
nothing calls this directly
no test coverage detected