bool CexCachingSolver::getAssignment(const Query& query, Assignment *&result) { KeyType key; if (lookupAssignment(query, key, result)) return true; std::vector<const Array*> objects; findSymbolicObjects(key.begin(), key.end(), objects); std::vector< std::vector<unsigned char> > values; bool hasSolution; if (!solver->impl->computeInitialValues(query, objects, values, hasSolution)) return false; AssignmentCacheWrapper *bindingWrapper; Assignment *binding; if (hasSolution) { binding = new Assignment(objects, values); // Memoize the result. std::pair<assignmentsTable_ty::iterator, bool> res = assignmentsTable.insert(binding); if (!res.second) { delete binding; binding = *res.first; } if (DebugCexCacheCheckBinding) if (!binding->satisfies(key.begin(), key.end())) { query.dump(); binding->dump(); klee_error("Generated assignment doesn't match query"); } bindingWrapper = new AssignmentCacheWrapper(binding); } else { unsatCore = solver->impl->getUnsatCore(); binding = (Assignment *) 0; bindingWrapper = new AssignmentCacheWrapper(unsatCore); } result = binding; cache.insert(key, bindingWrapper); return true; }
bool CexCachingSolver::getAssignment(const Query& query, Assignment *&result) { KeyType key; if (lookupAssignment(query, key, result)) return true; std::vector<const Array*> objects; findSymbolicObjects(key.begin(), key.end(), objects); std::vector< std::vector<unsigned char> > values; bool hasSolution; if (!solver->impl->computeInitialValues(query, objects, values, hasSolution)) return false; Assignment *binding; if (hasSolution) { binding = new Assignment(objects, values); // Memoize the result. std::pair<assignmentsTable_ty::iterator, bool> res = assignmentsTable.insert(binding); if (!res.second) { delete binding; binding = *res.first; } if (DebugCexCacheCheckBinding) assert(binding->satisfies(key.begin(), key.end())); } else { binding = (Assignment*) 0; } result = binding; cache.insert(key, binding); return true; }