本文整理汇总了C++中Formula::add方法的典型用法代码示例。如果您正苦于以下问题:C++ Formula::add方法的具体用法?C++ Formula::add怎么用?C++ Formula::add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Formula
的用法示例。
在下文中一共展示了Formula::add方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Formula
std::vector<SetOfFormulasPtr>
FaultLocalization::allDiagnosis(Formula *TF,
std::vector<ProgramTrace*> traces,
YicesSolver *yices) {
std::vector<SetOfFormulasPtr> MCSes;
int progress = 0;
int total = traces.size();
// Working formula
Formula *WF = new Formula(TF);
// For each E in WF, E tagged as soft do
unsigned z = 0;
std::vector<BoolVarExprPtr> AV;
std::map<BoolVarExprPtr, ExprPtr> AVMap;
std::vector<ExprPtr> clauses = WF->getExprs();
for(ExprPtr e : clauses) {
if (e->isSoft()) {
// AI is a new auxiliary var. created
std::ostringstream oss;
oss << z++;
BoolVarExprPtr ai = Expression::mkBoolVar("a_"+oss.str());
ai->setInstruction(e->getInstruction());
ai->setLine(e->getLine());
AV.push_back(ai);
AVMap[ai] = e;
ExprPtr notai = Expression::mkNot(ai);
//notai->setWeight(e->getWeight());
notai->setLine(e->getLine());
notai->setSoft();
WF->add(notai);
// Remove E and add EA as hard
ExprPtr ea = Expression::mkOr(e, ai);
WF->remove(e);
ea->setHard();
WF->add(ea);
}
}
if (AV.empty()) {
delete WF;
std::cout << "No MaxSMT solution!\n";
if (options->verbose()) {
std::cout << "==============================================\n";
}
return MCSes;
}
yices->init();
yices->addToContext(WF);
for(ProgramTrace *E : traces) {
if (options->verbose()) {
displayProgressBar(progress, total);
}
// At this point there is only WF in the context
yices->push();
// Assert as hard the error-inducing input formula
ExprPtr eiExpr = E->getProgramInputsFormula(TF);
eiExpr->setHard();
yices->addToContext(eiExpr);
if (options->dbgMsg()) {
std::cout << "-- Error-inducing Input: ";
eiExpr->dump();
std::cout << std::endl;
}
// Assert as hard the golden output (if any)
// (= return_var golden_output)
Value *goldenOutput = E->getExpectedOutput();
if (goldenOutput) {
BasicBlock *lastBB = &targetFun->back();
Instruction *lastInst = &lastBB->back();
if (ReturnInst *ret= dyn_cast<ReturnInst>(lastInst)) {
Value *retVal = ret->getReturnValue();
if (retVal) {
ExprPtr retExpr = Expression::getExprFromValue(retVal);
ExprPtr goExpr = Expression::getExprFromValue(goldenOutput);
ExprPtr eqExpr = Expression::mkEq(retExpr, goExpr);
eqExpr->setHard();
yices->addToContext(eqExpr);
if (options->dbgMsg()) {
std::cout << "-- Golden ouput: ";
eqExpr->dump();
std::cout << std::endl;
}
}
}
}
// Compute a MCS
SetOfFormulasPtr M = allMinMCS(yices, AV, AVMap);
if (!M->empty()) {
SetOfFormulasPtr M2 = avToClauses(M, AVMap);
MCSes.push_back(M2);
if (options->printMCS()) {
std::cout << "\n" << M2 << "\n" << std::endl;
}
} else {
//if (options->verbose() || options->dbgMsg()) {
std::cout << "Empty MCS!\n";
//}
}
// Backtrack to the point where there
// was no Pre/Post-conditions in the formula
yices->pop();
// Progress bar
//.........这里部分代码省略.........
示例2: makeTraceFormula
Formula* EncoderPass::makeTraceFormula() {
MSTimer timer1;
if(options->printDuration()) {
timer1.start();
}
// Create an empty trace formula
Formula *formula = new Formula();
// Prepare the CFG variables
encoder->prepareControlFlow(targetFun);
// Pre-process the global variables
initGlobalVariables();
// Save the line numbers of the call to assert
initAssertCalls();
bool isWeigted = false;
unsigned oldLine = 0;
Instruction *lastInstruction = NULL;
std::vector<ExprPtr> currentConstraits;
// Iterate through the function in Topological Order
// encode each instructions in SMT constraints
// @See: eli.thegreenplace.net/2013/09/16/analyzing-function-cfgs-with-llvm/
ReversePostOrderTraversal<Function*> RPOT(this->targetFun);
ReversePostOrderTraversal<Function*>::rpo_iterator itb;
for (itb=RPOT.begin(); itb!=RPOT.end(); ++itb) {
BasicBlock *bb = *itb;
// Propagate pointers when we enter in a new basicblock
ExprPtr e = ctx->propagatePointers(bb);
if (e) {
e->setHard();
formula->add(e);
}
// HFTF: Encode bug free blocks as hard
bool doEncodeBB = true;
if (options->htfUsed()) {
if(profile->isBugFreeBlock(bb)) {
doEncodeBB = false;
}
}
// Iterate through the basicblocks
for (BasicBlock::iterator iti=bb->begin(), eti=bb->end();
iti!=eti; ++iti) {
Instruction *i = iti;
bool doEncodeInst = doEncodeBB;
// Check the line number
unsigned line = 0;
if (MDNode *N = i->getMetadata("dbg")) {
DILocation Loc(N);
line = Loc.getLineNumber();
// Instruction related to an assert
if (ctx->isAssertCall(line)) {
isWeigted = false;
doEncodeInst = true;
} else {
// Instruction with line number
// (not related to an assert)
isWeigted = true;
}
} else {
// Instruction with no line number
isWeigted = false;
}
// Hardened Trace Formula
if (options->htfUsed() && !doEncodeInst) {
isWeigted = false;
}
// Encode the instruction in a SMT formula
ExprPtr expr = NULL;
switch (i->getOpcode()) {
case Instruction::Add:
case Instruction::FAdd:
case Instruction::Sub:
case Instruction::FSub:
case Instruction::Mul:
case Instruction::FMul:
case Instruction::UDiv:
case Instruction::SDiv:
case Instruction::FDiv:
case Instruction::URem:
case Instruction::SRem:
case Instruction::FRem:
case Instruction::And:
case Instruction::Or:
case Instruction::Xor:
case Instruction::Shl:
case Instruction::LShr:
case Instruction::AShr:
expr = encoder->encode(cast<BinaryOperator>(i));
break;
case Instruction::Select:
expr = encoder->encode(cast<SelectInst>(i));
break;
case Instruction::PHI:
expr = encoder->encode(cast<PHINode>(i));
isWeigted = false;
break;
case Instruction::Br:
expr = encoder->encode(cast<BranchInst>(i), loops);
isWeigted = false;
//.........这里部分代码省略.........