void ExprSMTLIBPrinter::printUpdatesAndArray(const UpdateNode *un, const Array *root) { if (un != NULL) { *p << "(store "; p->pushIndent(); printSeperator(); // recurse to get the array or update that this store operations applies to printUpdatesAndArray(un->next, root); printSeperator(); // print index printExpression(un->index, SORT_BITVECTOR); printSeperator(); // print value that is assigned to this index of the array printExpression(un->value, SORT_BITVECTOR); p->popIndent(); printSeperator(); *p << ")"; } else { // The base case of the recursion *p << root->name; } }
void print_x_x_x(Disassembler& self, const Instruction& instruction, UInt8 index = 0) { printIntRegister(self, instruction.reg[index]); printSeperator(self); printIntRegister(self, instruction.reg[index+1]); printSeperator(self); printIntRegister(self, instruction.reg[index+2]); }
void ExprSMTLIBPrinter::printSelectExpr(const ref<SelectExpr> &e, ExprSMTLIBPrinter::SMTLIB_SORT s) { // This is the if-then-else expression *p << "(" << getSMTLIBKeyword(e) << " "; p->pushIndent(); // add indent for recursive call // The condition printSeperator(); printExpression(e->getKid(0), SORT_BOOL); /* This operator is special in that the remaining children * can be of any sort. */ // if true printSeperator(); printExpression(e->getKid(1), s); // if false printSeperator(); printExpression(e->getKid(2), s); p->popIndent(); // pop indent added for recursive call printSeperator(); *p << ")"; }
void ExprSMTLIBPrinter::printArrayDeclarations() { // Assume scan() has been called if (humanReadable) *o << "; Array declarations" << endl; // Declare arrays in a deterministic order. std::vector<const Array *> sortedArrays(usedArrays.begin(), usedArrays.end()); std::sort(sortedArrays.begin(), sortedArrays.end(), ArrayPtrsByName()); for (std::vector<const Array *>::iterator it = sortedArrays.begin(); it != sortedArrays.end(); it++) { *o << "(declare-fun " << (*it)->name << " () " "(Array (_ BitVec " << (*it)->getDomain() << ") " "(_ BitVec " << (*it)->getRange() << ") ) )" << endl; } // Set array values for constant values if (haveConstantArray) { if (humanReadable) *o << "; Constant Array Definitions" << endl; const Array *array; // loop over found arrays for (std::vector<const Array *>::iterator it = sortedArrays.begin(); it != sortedArrays.end(); it++) { array = *it; int byteIndex = 0; if (array->isConstantArray()) { /*loop over elements in the array and generate an assert statement for each one */ for (vector<ref<ConstantExpr> >::const_iterator ce = array->constantValues.begin(); ce != array->constantValues.end(); ce++, byteIndex++) { *p << "(assert ("; p->pushIndent(); *p << "= "; p->pushIndent(); printSeperator(); *p << "(select " << array->name << " (_ bv" << byteIndex << " " << array->getDomain() << ") )"; printSeperator(); printConstant((*ce)); p->popIndent(); printSeperator(); *p << ")"; p->popIndent(); printSeperator(); *p << ")"; p->breakLineI(); } } } } }
void ExprSMTLIBPrinter::printNotEqualExpr(const ref<NeExpr> &e) { *p << "(not ("; p->pushIndent(); *p << "=" << " "; p->pushIndent(); printSeperator(); /* The "=" operators allows both sorts. We assume * that the second argument sort should be forced to be the same sort as the * first argument */ SMTLIB_SORT s = getSort(e->getKid(0)); printExpression(e->getKid(0), s); printSeperator(); printExpression(e->getKid(1), s); p->popIndent(); printSeperator(); *p << ")"; p->popIndent(); printSeperator(); *p << ")"; }
void ExprSMTLIBPrinter::printCastExpr(const ref<CastExpr> &e) { /* sign_extend and zero_extend behave slightly unusually in SMTLIBv2 * instead of specifying of what bit-width we would like to extend to * we specify how many bits to add to the child expression * * e.g * ((_ sign_extend 64) (_ bv5 32)) * * gives a (_ BitVec 96) instead of (_ BitVec 64) * * So we must work out how many bits we need to add. * * (e->width) is the desired number of bits * (e->src->getWidth()) is the number of bits in the child */ unsigned int numExtraBits = (e->width) - (e->src->getWidth()); *p << "((_ " << getSMTLIBKeyword(e) << " " << numExtraBits << ") "; p->pushIndent(); // add indent for recursive call printSeperator(); // recurse printExpression(e->src, SORT_BITVECTOR); p->popIndent(); // pop indent added for recursive call printSeperator(); *p << ")"; }
void ExprSMTLIBPrinter::printSortArgsExpr(const ref<Expr> &e, ExprSMTLIBPrinter::SMTLIB_SORT s) { *p << "(" << getSMTLIBKeyword(e) << " "; p->pushIndent(); // add indent for recursive call // loop over children and recurse into each expecting they are of sort "s" for (unsigned int i = 0; i < e->getNumKids(); i++) { printSeperator(); printExpression(e->getKid(i), s); } p->popIndent(); // pop indent added for recursive call printSeperator(); *p << ")"; }
void ExprSMTLIBPrinter::printExtractExpr(const ref<ExtractExpr> &e) { unsigned int lowIndex = e->offset; unsigned int highIndex = lowIndex + e->width - 1; *p << "((_ " << getSMTLIBKeyword(e) << " " << highIndex << " " << lowIndex << ") "; p->pushIndent(); // add indent for recursive call printSeperator(); // recurse printExpression(e->getKid(0), SORT_BITVECTOR); p->popIndent(); // pop indent added for the recursive call printSeperator(); *p << ")"; }
void ExprSMTLIBPrinter::printReadExpr(const ref<ReadExpr> &e) { *p << "(" << getSMTLIBKeyword(e) << " "; p->pushIndent(); printSeperator(); // print array with updates recursively printUpdatesAndArray(e->updates.head, e->updates.root); // print index printSeperator(); printExpression(e->index, SORT_BITVECTOR); p->popIndent(); printSeperator(); *p << ")"; }
void ExprSMTLIBPrinter::printQuery() { if (humanReadable) { *p << "; Query from solver turned into an assert"; p->breakLineI(); } p->pushIndent(); *p << "(assert"; p->pushIndent(); printSeperator(); printExpression(queryAssert, SORT_BOOL); p->popIndent(); printSeperator(); *p << ")"; p->popIndent(); p->breakLineI(); }
int main() { float r; read r; printSeperator(); function(); print square(r); print "\n"; printSeperator(); function(); function(); return 0; }
void ExprSMTLIBPrinter::printConstraints() { if (humanReadable) *o << "; Constraints" << endl; // Generate assert statements for each constraint for (ConstraintManager::const_iterator i = query->constraints.begin(); i != query->constraints.end(); i++) { *p << "(assert "; p->pushIndent(); printSeperator(); // recurse into Expression printExpression(*i, SORT_BOOL); p->popIndent(); printSeperator(); *p << ")"; p->breakLineI(); } }
void ExprSMTLIBPrinter::printCastToSort(const ref<Expr> &e, ExprSMTLIBPrinter::SMTLIB_SORT sort) { switch (sort) { case SORT_BITVECTOR: if (humanReadable) { p->breakLineI(); *p << ";Performing implicit bool to bitvector cast"; p->breakLine(); } // We assume the e is a bool that we need to cast to a bitvector sort. *p << "(ite"; p->pushIndent(); printSeperator(); printExpression(e, SORT_BOOL); printSeperator(); *p << "(_ bv1 1)"; printSeperator(); // printing the "true" bitvector *p << "(_ bv0 1)"; p->popIndent(); printSeperator(); // printing the "false" bitvector *p << ")"; break; case SORT_BOOL: { /* We make the assumption (might be wrong) that any bitvector whos unsigned *decimal value is * is zero is interpreted as "false", otherwise it is true. * * This may not be the interpretation we actually want! */ Expr::Width bitWidth = e->getWidth(); if (humanReadable) { p->breakLineI(); *p << ";Performing implicit bitvector to bool cast"; p->breakLine(); } *p << "(bvugt"; p->pushIndent(); printSeperator(); // We assume is e is a bitvector printExpression(e, SORT_BITVECTOR); printSeperator(); *p << "(_ bv0 " << bitWidth << ")"; p->popIndent(); printSeperator(); // Zero bitvector of required width *p << ")"; if (bitWidth != Expr::Bool) std::cerr << "ExprSMTLIBPrinter : Warning. Casting a bitvector (length " << bitWidth << ") to bool!" << std::endl; } break; default: assert(0 && "Unsupported cast!"); } }
void ExprSMTLIBPrinter::printLogicalOrBitVectorExpr( const ref<Expr> &e, ExprSMTLIBPrinter::SMTLIB_SORT s) { /* For these operators it is the case that the expected sort is the same as * the sorts * of the arguments. */ *p << "("; switch (e->getKind()) { case Expr::And: *p << ((s == SORT_BITVECTOR) ? "bvand" : "and"); break; case Expr::Not: *p << ((s == SORT_BITVECTOR) ? "bvnot" : "not"); break; case Expr::Or: *p << ((s == SORT_BITVECTOR) ? "bvor" : "or"); break; case Expr::Xor: *p << ((s == SORT_BITVECTOR) ? "bvxor" : "xor"); break; default: *p << "ERROR"; // this shouldn't happen } *p << " "; p->pushIndent(); // add indent for recursive call // loop over children and recurse into each expecting they are of sort "s" for (unsigned int i = 0; i < e->getNumKids(); i++) { printSeperator(); printExpression(e->getKid(i), s); } p->popIndent(); // pop indent added for recursive call printSeperator(); *p << ")"; }
void ExprSMTLIBLetPrinter::printLetExpression() { *p << "(assert"; p->pushIndent(); printSeperator(); if (bindings.size() != 0) { // Only print let expression if we have bindings to use. *p << "(let"; p->pushIndent(); printSeperator(); *p << "( "; p->pushIndent(); // Print each binding for (map<const ref<Expr>, unsigned int>::const_iterator i = bindings.begin(); i != bindings.end(); ++i) { printSeperator(); *p << "(" << BINDING_PREFIX << i->second << " "; p->pushIndent(); // Disable abbreviations so none are used here. disablePrintedAbbreviations = true; // We can abbreviate SORT_BOOL or SORT_BITVECTOR in let expressions printExpression(i->first, getSort(i->first)); p->popIndent(); printSeperator(); *p << ")"; } p->popIndent(); printSeperator(); *p << ")"; printSeperator(); // Re-enable printing abbreviations. disablePrintedAbbreviations = false; } // print out Expressions with abbreviations. unsigned int numberOfItems = query->constraints.size() + 1; //+1 for query unsigned int itemsLeft = numberOfItems; vector<ref<Expr> >::const_iterator constraint = query->constraints.begin(); /* Produce nested (and () () statements. If the constraint set * is empty then we will only print the "queryAssert". */ for (; itemsLeft != 0; --itemsLeft) { if (itemsLeft >= 2) { *p << "(and"; p->pushIndent(); printSeperator(); printExpression(*constraint, SORT_BOOL); // We must and together bool expressions printSeperator(); ++constraint; continue; } else { // must have 1 item left (i.e. the "queryAssert") if (isHumanReadable()) { *p << "; query"; p->breakLineI(); } printExpression(queryAssert, SORT_BOOL); // The query must be a bool expression } } /* Produce closing brackets for nested "and statements". * Number of "nested ands" = numberOfItems -1 */ itemsLeft = numberOfItems - 1; for (; itemsLeft != 0; --itemsLeft) { p->popIndent(); printSeperator(); *p << ")"; } if (bindings.size() != 0) { // end let expression p->popIndent(); printSeperator(); *p << ")"; printSeperator(); } // end assert p->popIndent(); printSeperator(); *p << ")"; p->breakLineI(); }