| 89 | } |
| 90 | |
| 91 | StatementArrayOp * |
| 92 | StatementArrayOp::make_random_array_init(CGContext &cg_context) |
| 93 | { |
| 94 | // select the array to initialize |
| 95 | //static int g = 0; |
| 96 | //int h = g++; |
| 97 | ArrayVariable* av = VariableSelector::select_array(cg_context); |
| 98 | ERROR_GUARD(NULL); |
| 99 | cg_context.get_effect_stm().clear(); |
| 100 | // Select the loop control variable. |
| 101 | vector<const Variable*> invalid_vars; |
| 102 | vector<const Variable*> cvs; |
| 103 | ERROR_GUARD(NULL); |
| 104 | // the iteration settings are simple: start from index 0, step through all members |
| 105 | vector<int> inits, incrs; |
| 106 | size_t i; |
| 107 | cg_context.get_effect_stm().clear(); |
| 108 | FactMgr* fm = get_fact_mgr(&cg_context); |
| 109 | int vol_count = 0; |
| 110 | if (av->is_volatile()) |
| 111 | vol_count++; |
| 112 | |
| 113 | for (i=0; i<av->get_dimension(); i++) { |
| 114 | inits.push_back(0); |
| 115 | incrs.push_back(1); |
| 116 | Variable *cv = NULL; |
| 117 | do { |
| 118 | cv = VariableSelector::SelectLoopCtrlVar(cg_context, invalid_vars); |
| 119 | if (cv->type->is_float()) { |
| 120 | invalid_vars.push_back(cv); |
| 121 | continue; |
| 122 | } |
| 123 | if (cv->is_volatile()) |
| 124 | vol_count++; |
| 125 | if ((CGOptions::strict_volatile_rule() && (vol_count > 1) && cv->is_volatile()) |
| 126 | || (CGOptions::ccomp() && cv->is_packed_aggregate_field_var()) |
| 127 | || (!CGOptions::signed_char_index() && cv->type->is_signed_char())) { |
| 128 | invalid_vars.push_back(cv); |
| 129 | continue; |
| 130 | } |
| 131 | else { |
| 132 | break; |
| 133 | } |
| 134 | } while (true); |
| 135 | invalid_vars.push_back(cv); |
| 136 | cvs.push_back(cv); |
| 137 | bool read = cg_context.read_indices(cv, fm->global_facts); |
| 138 | assert(read); |
| 139 | cg_context.write_var(cv); |
| 140 | // put in induction variable list so that later indices have no write-write conflict |
| 141 | cg_context.iv_bounds[cv] = av->get_sizes()[i]; |
| 142 | } |
| 143 | cg_context.write_var(av); |
| 144 | |
| 145 | // JYTODO: initialize only field(s) of array members if they are of type struct |
| 146 | Block* b = cg_context.get_current_block()->random_parent_block(); |
| 147 | Expression* init = VariableSelector::make_init_value(Effect::READ, cg_context, av->type, &av->qfer, b); |
| 148 | assert(init->visit_facts(fm->global_facts, cg_context)); |
nothing calls this directly
no test coverage detected