* check if a variable is eligible to be selected based on current context and * read/write + volatile + const rules */
| 233 | * read/write + volatile + const rules |
| 234 | */ |
| 235 | bool |
| 236 | VariableSelector::is_eligible_var(const Variable* var, int deref_level, Effect::Access access, const CGContext& cg_context) |
| 237 | { |
| 238 | const Variable* coll = var->get_collective(); |
| 239 | FactMgr* fm = get_fact_mgr(&cg_context); |
| 240 | if (coll != var) { |
| 241 | CGContext cg_tmp(cg_context); |
| 242 | if (!cg_tmp.read_indices(var, fm->global_facts)) { |
| 243 | return false; |
| 244 | } |
| 245 | var = coll; |
| 246 | } |
| 247 | const Effect &effect_context = cg_context.get_effect_context(); |
| 248 | bool is_const = var->is_const_after_deref(deref_level); |
| 249 | bool is_volatile = var->is_volatile_after_deref(deref_level) || var->is_volatile(); |
| 250 | |
| 251 | // ISSUE: generating "strictly conforming" programs. |
| 252 | // |
| 253 | // We cannot read or write a volatile if the current effect context |
| 254 | // already has a side-effect. |
| 255 | // |
| 256 | // TODO: is this too strong for what we want? Need a cmd-line option? |
| 257 | if (is_volatile && !effect_context.is_side_effect_free()) { |
| 258 | return false; |
| 259 | } |
| 260 | // ISSUE: generating "strictly conforming" programs. |
| 261 | // |
| 262 | // We can neither read nor write a variable that is being written in |
| 263 | // the current effect context. |
| 264 | if (((access == Effect::READ) || (access == Effect::WRITE)) |
| 265 | && (effect_context.is_written_partially(var))) { |
| 266 | return false; |
| 267 | } |
| 268 | // ISSUE: generating "strictly conforming" programs. |
| 269 | // |
| 270 | // We cannot write a variable that is being read in the current effect context. |
| 271 | // JYTODO: this is too restrictive, with dereference, var is not the variable |
| 272 | // being written, but the pointed variable. Nevertheless, we excluded var here |
| 273 | if ((access == Effect::WRITE && deref_level==0) && effect_context.is_read_partially(var)) { |
| 274 | return false; |
| 275 | } |
| 276 | // ISSUE: generating correct C programs. |
| 277 | // |
| 278 | // We cannot write `const' variables. |
| 279 | if ((access == Effect::WRITE) && is_const) { |
| 280 | return false; |
| 281 | } |
| 282 | // ISSUE: generating "interesting" C programs. |
| 283 | // |
| 284 | // We cannot read a variable if the current code-generation context |
| 285 | // says that we should not. |
| 286 | if ((access == Effect::READ) && |
| 287 | (cg_context.is_nonreadable(var) || |
| 288 | (FactUnion::is_nonreadable_field(var, fm->global_facts)))) { |
| 289 | return false; |
| 290 | } |
| 291 | // ISSUE: generating "interesting" C programs. |
| 292 | // |
nothing calls this directly
no test coverage detected