void if_block_create_input_placeholders_for_outer_pointers(Term* ifCall) { Branch* contents = nested_contents(ifCall); TermList outerTerms; // Find outer pointers across each case for (CaseIterator it(contents); it.unfinished(); it.advance()) { list_outer_pointers(nested_contents(it.current()), &outerTerms); } ca_assert(ifCall->numInputs() == 0); // Create input placeholders and add inputs for all outer pointers for (int i=0; i < outerTerms.length(); i++) { Term* outer = outerTerms[i]; set_input(ifCall, i, outer); Term* placeholder = append_input_placeholder(nested_contents(ifCall)); rename(placeholder, outer->name); // Go through each case and repoint to this new placeholder for (CaseIterator it(contents); it.unfinished(); it.advance()) { remap_pointers_quick(nested_contents(it.current()), outer, placeholder); } } }
Term* find_accessor_head_term(Term* accessor) { TermList chain; trace_accessor_chain(accessor, &chain); if (chain.length() == 0) return NULL; return chain[0]; }
Term* branch_add_pack_state(Branch* branch) { TermList inputs; get_list_of_state_outputs(branch, branch->length(), &inputs); // Don't create anything if there are no state outputs if (inputs.length() == 0) return NULL; return apply(branch, FUNCS.pack_state, inputs); }
Term* block_add_pack_state(Block* block) { TermList inputs; list_inputs_to_pack_state(block, block->length(), &inputs); // Don't create anything if there are no state outputs if (inputs.length() == 0) return NULL; return apply(block, FUNCS.pack_state, inputs); }
void test_equals_function(TermList const& a, TermList const& b, const char* aText, const char* bText, int line, const char* file) { if (a.length() != b.length()) { std::cout << "List equality fail in " << file << ", line " << line << std::endl; std::cout << " " << aText << " has " << a.length() << " items, "; std::cout << bText << " has " << b.length() << " items." << std::endl; declare_current_test_failed(); return; } for (int i=0; i < a.length(); i++) { if (a[i] != b[i]) { std::cout << "List equality fail in " << file << ", line " << line << std::endl; std::cout << " " << aText << " != " << bText << " (index " << i << " differs)" << std::endl; declare_current_test_failed(); return; } } }
void block_update_pack_state_calls(Block* block) { if (block->stateType == NULL) { // No state type, make sure there's no pack_state call. // TODO: Handle this case properly (should search and destroy an existing pack_state call) return; } int stateOutputIndex = block->length() - 1 - find_state_output(block)->index; for (int i=0; i < block->length(); i++) { Term* term = block->get(i); if (term == NULL) continue; if (term->function == FUNCS.pack_state) { // Update the inputs for this pack_state call TermList inputs; list_inputs_to_pack_state(block, i, &inputs); set_inputs(term, inputs); } else if (should_have_preceeding_pack_state(term)) { // Check if we need to insert a pack_state call Term* existing = term->input(stateOutputIndex); if (existing == NULL || existing->function != FUNCS.pack_state) { TermList inputs; list_inputs_to_pack_state(block, i, &inputs); if (inputs.length() != 0) { Term* pack_state = apply(block, FUNCS.pack_state, inputs); move_before(pack_state, term); // Only set as an input for a non-minor block. if (term->nestedContents == NULL || !is_minor_block(term->nestedContents)) { set_input(term, stateOutputIndex, pack_state); set_input_hidden(term, stateOutputIndex, true); set_input_implicit(term, stateOutputIndex, true); } // Advance i to compensate for the term just added i++; } } } } }
void branch_update_existing_pack_state_calls(Branch* branch) { if (branch->stateType == NULL) { // No state type, make sure there's no pack_state call. // TODO: Handle this case properly (should search and destroy an existing pack_state call) return; } int stateOutputIndex = branch->length() - 1 - find_state_output(branch)->index; for (int i=0; i < branch->length(); i++) { Term* term = branch->get(i); if (term == NULL) continue; if (term->function == FUNCS.pack_state) { // Update the inputs for this pack_state call TermList inputs; get_list_of_state_outputs(branch, i, &inputs); set_inputs(term, inputs); } if (term->function == FUNCS.exit_point) { // Check if we need to insert a pack_state call Term* existing = term->input(stateOutputIndex); if (existing == NULL || existing->function != FUNCS.pack_state) { TermList inputs; get_list_of_state_outputs(branch, i, &inputs); if (inputs.length() != 0) { Term* pack_state = apply(branch, FUNCS.pack_state, inputs); move_before(pack_state, term); set_input(term, stateOutputIndex + 1, pack_state); // Advance i to compensate for the term just added i++; } } } } }