* */
| 121 | * |
| 122 | */ |
| 123 | Block * |
| 124 | Block::make_random(CGContext &cg_context, bool looping) |
| 125 | { |
| 126 | //static int bid = 0; |
| 127 | DEPTH_GUARD_BY_TYPE_RETURN(dtBlock, NULL); |
| 128 | |
| 129 | Function *curr_func = cg_context.get_current_func(); |
| 130 | assert(curr_func); |
| 131 | |
| 132 | Block *b = new Block(cg_context.get_current_block(), CGOptions::max_block_size()); |
| 133 | b->func = curr_func; |
| 134 | b->looping = looping; |
| 135 | // if there are induction variables, we are in a loop that traverses array(s) |
| 136 | b->in_array_loop = !(cg_context.iv_bounds.empty()); |
| 137 | //b->stm_id = bid++; |
| 138 | |
| 139 | // Push this block onto the variable scope stack. |
| 140 | curr_func->stack.push_back(b); |
| 141 | curr_func->blocks.push_back(b); |
| 142 | |
| 143 | // record global facts at this moment so that subsequent statement |
| 144 | // inside the block doesn't ruin it |
| 145 | FactMgr* fm = get_fact_mgr_for_func(curr_func); |
| 146 | fm->set_fact_in(b, fm->global_facts); |
| 147 | Effect pre_effect = cg_context.get_accum_effect(); |
| 148 | |
| 149 | unsigned int max = BlockProbability(*b); |
| 150 | if (Error::get_error() != SUCCESS) { |
| 151 | curr_func->stack.pop_back(); |
| 152 | delete b; |
| 153 | return NULL; |
| 154 | } |
| 155 | unsigned int i; |
| 156 | if (b->stm_id == 1) |
| 157 | BREAK_NOP; // for debugging |
| 158 | for (i = 0; i <= max; ++i) { |
| 159 | Statement *s = Statement::make_random(cg_context); |
| 160 | // In the exhaustive mode, Statement::make_random could return NULL; |
| 161 | if (!s) |
| 162 | break; |
| 163 | b->stms.push_back(s); |
| 164 | if (s->must_return()) { |
| 165 | break; |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | if (Error::get_error() != SUCCESS) { |
| 170 | curr_func->stack.pop_back(); |
| 171 | delete b; |
| 172 | return NULL; |
| 173 | } |
| 174 | |
| 175 | // append nested loop if some must-read/write variables hasn't been accessed |
| 176 | if (b->need_nested_loop(cg_context) && cg_context.blk_depth < CGOptions::max_blk_depth()) { |
| 177 | b->append_nested_loop(cg_context); |
| 178 | } |
| 179 | |
| 180 | // perform DFA analysis after creation |
nothing calls this directly
no test coverage detected