* Randomly determine the parameters for an array-travering loop */
| 130 | * Randomly determine the parameters for an array-travering loop |
| 131 | */ |
| 132 | static unsigned int |
| 133 | make_random_array_control(unsigned int bound, int &init, int &limit, int &incr, eBinaryOps &test_op, eAssignOps &incr_op, bool is_signed) |
| 134 | { |
| 135 | // choose either increment or decrement |
| 136 | test_op = is_signed ? (rnd_flipcoin(50) ? eCmpLe : eCmpGe) : eCmpLe; |
| 137 | if (test_op == eCmpLe) { |
| 138 | // increment, start near index 0 |
| 139 | init = pure_rnd_flipcoin(50) ? 0 : pure_rnd_upto(bound/2); |
| 140 | limit = bound; |
| 141 | incr_op = eAddAssign; |
| 142 | incr = pure_rnd_flipcoin(50) ? 1 : pure_rnd_upto(bound/4); |
| 143 | if (incr == 0) incr = 1; |
| 144 | bound = ((bound - init) / incr) * incr + init; |
| 145 | } else { |
| 146 | // decrement, start near last index |
| 147 | init = pure_rnd_flipcoin(50) ? (bound) : (bound - pure_rnd_upto(bound/2)); |
| 148 | limit = pure_rnd_flipcoin(50) ? 0 : pure_rnd_upto(bound/2); |
| 149 | incr_op = eSubAssign; |
| 150 | incr = pure_rnd_flipcoin(50) ? 1 : pure_rnd_upto(bound/4); |
| 151 | if (incr == 0) incr = 1; |
| 152 | bound = init; |
| 153 | } |
| 154 | return bound; |
| 155 | } |
| 156 | |
| 157 | const Variable* |
| 158 | StatementFor::make_iteration(CGContext& cg_context, StatementAssign*& init, Expression*& test, StatementAssign*& incr, unsigned int& bound) |
no test coverage detected