From d934d983692c8952cdb887cbcd59f2df0001b9c0 Mon Sep 17 00:00:00 2001 From: Martin Nowack Date: Thu, 29 May 2014 23:15:59 +0200 Subject: Refactoring from std::ostream to llvm::raw_ostream According to LLVM: lightweight and simpler implementation of streams. --- tools/kleaver/main.cpp | 77 +++++++++++++++++++++++++------------------------- 1 file changed, 39 insertions(+), 38 deletions(-) (limited to 'tools/kleaver/main.cpp') diff --git a/tools/kleaver/main.cpp b/tools/kleaver/main.cpp index abc37d4b..e31140e8 100644 --- a/tools/kleaver/main.cpp +++ b/tools/kleaver/main.cpp @@ -124,9 +124,11 @@ static std::string getQueryLogPath(const char filename[]) struct stat s; if( !(stat(directoryToWriteQueryLogs.c_str(),&s) == 0 && S_ISDIR(s.st_mode)) ) { - std::cerr << "Directory to log queries \"" << directoryToWriteQueryLogs << "\" does not exist!" << std::endl; - exit(1); - } + llvm::errs() << "Directory to log queries \"" + << directoryToWriteQueryLogs << "\" does not exist!" + << "\n"; + exit(1); + } //check permissions okay if( !( (s.st_mode & S_IWUSR) && getuid() == s.st_uid) && @@ -134,9 +136,11 @@ static std::string getQueryLogPath(const char filename[]) !( s.st_mode & S_IWOTH) ) { - std::cerr << "Directory to log queries \"" << directoryToWriteQueryLogs << "\" is not writable!" << std::endl; - exit(1); - } + llvm::errs() << "Directory to log queries \"" + << directoryToWriteQueryLogs << "\" is not writable!" + << "\n"; + exit(1); + } std::string path=directoryToWriteQueryLogs; path+="/"; @@ -167,10 +171,9 @@ static void PrintInputTokens(const MemoryBuffer *MB) { Token T; do { L.Lex(T); - std::cout << "(Token \"" << T.getKindName() << "\" " - << "\"" << escapedString(T.start, T.length) << "\" " - << T.length << " " - << T.line << " " << T.column << ")\n"; + llvm::outs() << "(Token \"" << T.getKindName() << "\" " + << "\"" << escapedString(T.start, T.length) << "\" " + << T.length << " " << T.line << " " << T.column << ")\n"; } while (T.kind != Token::EndOfFile); } @@ -185,7 +188,7 @@ static bool PrintInputAST(const char *Filename, while (Decl *D = P->ParseTopLevelDecl()) { if (!P->GetNumErrors()) { if (isa(D)) - std::cout << "# Query " << ++NumQueries << "\n"; + llvm::outs() << "# Query " << ++NumQueries << "\n"; D->dump(); } @@ -194,8 +197,7 @@ static bool PrintInputAST(const char *Filename, bool success = true; if (unsigned N = P->GetNumErrors()) { - std::cerr << Filename << ": parse failure: " - << N << " errors.\n"; + llvm::errs() << Filename << ": parse failure: " << N << " errors.\n"; success = false; } @@ -220,8 +222,7 @@ static bool EvaluateInputAST(const char *Filename, bool success = true; if (unsigned N = P->GetNumErrors()) { - std::cerr << Filename << ": parse failure: " - << N << " errors.\n"; + llvm::errs() << Filename << ": parse failure: " << N << " errors.\n"; success = false; } @@ -253,7 +254,7 @@ static bool EvaluateInputAST(const char *Filename, assert(false); break; }; - std::cerr << "Starting MetaSMTSolver(" << backend << ") ...\n"; + llvm::errs() << "Starting MetaSMTSolver(" << backend << ") ...\n"; } else { coreSolver = UseDummySolver ? createDummySolver() : new STPSolver(UseForkedCoreSolver); @@ -280,16 +281,16 @@ static bool EvaluateInputAST(const char *Filename, ie = Decls.end(); it != ie; ++it) { Decl *D = *it; if (QueryCommand *QC = dyn_cast(D)) { - std::cout << "Query " << Index << ":\t"; + llvm::outs() << "Query " << Index << ":\t"; assert("FIXME: Support counterexample query commands!"); if (QC->Values.empty() && QC->Objects.empty()) { bool result; if (S->mustBeTrue(Query(ConstraintManager(QC->Constraints), QC->Query), result)) { - std::cout << (result ? "VALID" : "INVALID"); + llvm::outs() << (result ? "VALID" : "INVALID"); } else { - std::cout << "FAIL (reason: " + llvm::outs() << "FAIL (reason: " << SolverImpl::getOperationStatusString(S->impl->getOperationStatusCode()) << ")"; } @@ -304,10 +305,10 @@ static bool EvaluateInputAST(const char *Filename, if (S->getValue(Query(ConstraintManager(QC->Constraints), QC->Values[0]), result)) { - std::cout << "INVALID\n"; - std::cout << "\tExpr 0:\t" << result; + llvm::outs() << "INVALID\n"; + llvm::outs() << "\tExpr 0:\t" << result; } else { - std::cout << "FAIL (reason: " + llvm::outs() << "FAIL (reason: " << SolverImpl::getOperationStatusString(S->impl->getOperationStatusCode()) << ")"; } @@ -317,35 +318,35 @@ static bool EvaluateInputAST(const char *Filename, if (S->getInitialValues(Query(ConstraintManager(QC->Constraints), QC->Query), QC->Objects, result)) { - std::cout << "INVALID\n"; + llvm::outs() << "INVALID\n"; for (unsigned i = 0, e = result.size(); i != e; ++i) { - std::cout << "\tArray " << i << ":\t" + llvm::outs() << "\tArray " << i << ":\t" << QC->Objects[i]->name << "["; for (unsigned j = 0; j != QC->Objects[i]->size; ++j) { - std::cout << (unsigned) result[i][j]; + llvm::outs() << (unsigned) result[i][j]; if (j + 1 != QC->Objects[i]->size) - std::cout << ", "; + llvm::outs() << ", "; } - std::cout << "]"; + llvm::outs() << "]"; if (i + 1 != e) - std::cout << "\n"; + llvm::outs() << "\n"; } } else { SolverImpl::SolverRunStatus retCode = S->impl->getOperationStatusCode(); if (SolverImpl::SOLVER_RUN_STATUS_TIMEOUT == retCode) { - std::cout << " FAIL (reason: " + llvm::outs() << " FAIL (reason: " << SolverImpl::getOperationStatusString(retCode) << ")"; } else { - std::cout << "VALID (counterexample request ignored)"; + llvm::outs() << "VALID (counterexample request ignored)"; } } } - std::cout << "\n"; + llvm::outs() << "\n"; ++Index; } } @@ -358,7 +359,7 @@ static bool EvaluateInputAST(const char *Filename, delete S; if (uint64_t queries = *theStatisticManager->getStatisticByName("Queries")) { - std::cout + llvm::outs() << "--\n" << "total queries = " << queries << "\n" << "total queries constructs = " @@ -390,7 +391,7 @@ static bool printInputAsSMTLIBv2(const char *Filename, bool success = true; if (unsigned N = P->GetNumErrors()) { - std::cerr << Filename << ": parse failure: " + llvm::errs() << Filename << ": parse failure: " << N << " errors.\n"; success = false; } @@ -399,7 +400,7 @@ static bool printInputAsSMTLIBv2(const char *Filename, return false; ExprSMTLIBPrinter* printer = createSMTLIBPrinter(); - printer->setOutput(std::cout); + printer->setOutput(llvm::outs()); unsigned int queryNumber = 0; //Loop over the declarations @@ -409,10 +410,10 @@ static bool printInputAsSMTLIBv2(const char *Filename, if (QueryCommand *QC = dyn_cast(D)) { //print line break to separate from previous query - if(queryNumber!=0) std::cout << std::endl; + if(queryNumber!=0) llvm::outs() << "\n"; //Output header for this query as a SMT-LIBv2 comment - std::cout << ";SMTLIBv2 Query " << queryNumber << std::endl; + llvm::outs() << ";SMTLIBv2 Query " << queryNumber << "\n"; /* Can't pass ConstraintManager constructor directly * as argument to Query object. Like... @@ -458,7 +459,7 @@ int main(int argc, char **argv) { OwningPtr MB; error_code ec=MemoryBuffer::getFileOrSTDIN(InputFile.c_str(), MB); if (ec) { - std::cerr << argv[0] << ": error: " << ec.message() << "\n"; + llvm::errs() << argv[0] << ": error: " << ec.message() << "\n"; return 1; } @@ -494,7 +495,7 @@ int main(int argc, char **argv) { success = printInputAsSMTLIBv2(InputFile=="-"? "" : InputFile.c_str(), MB.get(),Builder); break; default: - std::cerr << argv[0] << ": error: Unknown program action!\n"; + llvm::errs() << argv[0] << ": error: Unknown program action!\n"; } delete Builder; -- cgit 1.4.1 From 3b35ffed89405e7ba3059664dfbdc165b5d8625d Mon Sep 17 00:00:00 2001 From: Martin Nowack Date: Thu, 29 May 2014 23:21:33 +0200 Subject: Remove #include to avoid static constructors iostream injects static constructor function into every compilation unit. Remove this to avoid it. --- include/klee/Internal/ADT/TreeStream.h | 1 - lib/Core/ExecutorUtil.cpp | 1 - lib/Core/ExternalDispatcher.cpp | 1 - lib/Core/ImpliedValue.cpp | 1 - lib/Core/Memory.cpp | 1 - lib/Core/PTree.cpp | 1 - lib/Core/PTree.h | 4 ---- lib/Core/Searcher.h | 4 +--- lib/Core/SpecialFunctionHandler.cpp | 5 +++-- lib/Core/StatsTracker.cpp | 2 -- lib/Core/StatsTracker.h | 1 - lib/Expr/Constraints.cpp | 1 - lib/Expr/Expr.cpp | 1 - lib/Expr/ExprPPrinter.cpp | 3 --- lib/Expr/ExprSMTLIBLetPrinter.cpp | 2 +- lib/Expr/ExprSMTLIBPrinter.cpp | 2 -- lib/Expr/Lexer.cpp | 1 - lib/Expr/Parser.cpp | 1 - lib/Module/Checks.cpp | 1 - lib/Module/ModuleUtil.cpp | 2 -- lib/Module/Optimize.cpp | 1 - lib/SMT/SMTParser.cpp | 1 - lib/SMT/SMTParser.h | 2 -- lib/SMT/main.cpp | 1 - lib/Solver/FastCexSolver.cpp | 1 - lib/Solver/IndependentSolver.cpp | 1 - lib/Solver/STPBuilder.cpp | 1 - lib/Solver/Solver.cpp | 1 - lib/Support/TreeStream.cpp | 1 - tools/kleaver/main.cpp | 2 -- tools/klee/Debug.cpp | 1 - tools/klee/main.cpp | 1 - 32 files changed, 5 insertions(+), 45 deletions(-) (limited to 'tools/kleaver/main.cpp') diff --git a/include/klee/Internal/ADT/TreeStream.h b/include/klee/Internal/ADT/TreeStream.h index 63e49dbb..1494aa76 100644 --- a/include/klee/Internal/ADT/TreeStream.h +++ b/include/klee/Internal/ADT/TreeStream.h @@ -11,7 +11,6 @@ #define __UTIL_TREESTREAM_H__ #include -#include #include namespace klee { diff --git a/lib/Core/ExecutorUtil.cpp b/lib/Core/ExecutorUtil.cpp index 79d1707e..f6b3dd5e 100644 --- a/lib/Core/ExecutorUtil.cpp +++ b/lib/Core/ExecutorUtil.cpp @@ -41,7 +41,6 @@ #include "llvm/Support/CallSite.h" -#include #include using namespace klee; diff --git a/lib/Core/ExternalDispatcher.cpp b/lib/Core/ExternalDispatcher.cpp index bbe1c42e..4c1e2b86 100644 --- a/lib/Core/ExternalDispatcher.cpp +++ b/lib/Core/ExternalDispatcher.cpp @@ -42,7 +42,6 @@ #endif #include #include -#include using namespace llvm; using namespace klee; diff --git a/lib/Core/ImpliedValue.cpp b/lib/Core/ImpliedValue.cpp index f20259fb..c8342df1 100644 --- a/lib/Core/ImpliedValue.cpp +++ b/lib/Core/ImpliedValue.cpp @@ -18,7 +18,6 @@ #include "klee/util/ExprUtil.h" -#include #include #include diff --git a/lib/Core/Memory.cpp b/lib/Core/Memory.cpp index 7f5d024e..b6f225d1 100644 --- a/lib/Core/Memory.cpp +++ b/lib/Core/Memory.cpp @@ -32,7 +32,6 @@ #include "llvm/Support/CommandLine.h" #include "llvm/Support/raw_ostream.h" -#include #include #include diff --git a/lib/Core/PTree.cpp b/lib/Core/PTree.cpp index a435cd5e..f0e7ab51 100644 --- a/lib/Core/PTree.cpp +++ b/lib/Core/PTree.cpp @@ -13,7 +13,6 @@ #include #include -#include using namespace klee; diff --git a/lib/Core/PTree.h b/lib/Core/PTree.h index 2ac688bd..11d3f48c 100644 --- a/lib/Core/PTree.h +++ b/lib/Core/PTree.h @@ -12,10 +12,6 @@ #include -#include -#include -#include - namespace klee { class ExecutionState; diff --git a/lib/Core/Searcher.h b/lib/Core/Searcher.h index 3c077636..d866f521 100644 --- a/lib/Core/Searcher.h +++ b/lib/Core/Searcher.h @@ -10,14 +10,12 @@ #ifndef KLEE_SEARCHER_H #define KLEE_SEARCHER_H +#include "llvm/Support/raw_ostream.h" #include #include #include #include -// FIXME: Move out of header, use llvm streams. -#include - namespace llvm { class BasicBlock; class Function; diff --git a/lib/Core/SpecialFunctionHandler.cpp b/lib/Core/SpecialFunctionHandler.cpp index dcba5436..a7a1b32e 100644 --- a/lib/Core/SpecialFunctionHandler.cpp +++ b/lib/Core/SpecialFunctionHandler.cpp @@ -27,6 +27,7 @@ #include "llvm/Module.h" #endif #include "llvm/ADT/Twine.h" +#include "llvm/Support/Debug.h" #include @@ -279,8 +280,8 @@ void SpecialFunctionHandler::handleAliasFunction(ExecutionState &state, "invalid number of arguments to klee_alias_function"); std::string old_fn = readStringAtAddress(state, arguments[0]); std::string new_fn = readStringAtAddress(state, arguments[1]); - DEBUG_WITH_TYPE("alias_handling", errs() << "Replacing " << old_fn - << "() with " << new_fn << "()\n";); + DEBUG_WITH_TYPE("alias_handling", llvm::errs() << "Replacing " << old_fn + << "() with " << new_fn << "()\n"); if (old_fn == new_fn) state.removeFnAlias(old_fn); else state.addFnAlias(old_fn, new_fn); diff --git a/lib/Core/StatsTracker.cpp b/lib/Core/StatsTracker.cpp index 4f4552e7..0946d2ba 100644 --- a/lib/Core/StatsTracker.cpp +++ b/lib/Core/StatsTracker.cpp @@ -46,12 +46,10 @@ #endif #include "llvm/Support/CommandLine.h" #include "llvm/Support/CFG.h" -#include "llvm/Support/raw_os_ostream.h" #include "llvm/Support/Process.h" #include "llvm/Support/Path.h" #include "llvm/Support/FileSystem.h" -#include #include #include diff --git a/lib/Core/StatsTracker.h b/lib/Core/StatsTracker.h index f06decdc..629a723d 100644 --- a/lib/Core/StatsTracker.h +++ b/lib/Core/StatsTracker.h @@ -12,7 +12,6 @@ #include "CallPathManager.h" -#include #include namespace llvm { diff --git a/lib/Expr/Constraints.cpp b/lib/Expr/Constraints.cpp index 90d9bcd4..ae4563f4 100644 --- a/lib/Expr/Constraints.cpp +++ b/lib/Expr/Constraints.cpp @@ -19,7 +19,6 @@ #include "llvm/Support/CommandLine.h" #include "klee/Internal/Module/KModule.h" -#include #include using namespace klee; diff --git a/lib/Expr/Expr.cpp b/lib/Expr/Expr.cpp index 14737e8c..d54b8f4d 100644 --- a/lib/Expr/Expr.cpp +++ b/lib/Expr/Expr.cpp @@ -21,7 +21,6 @@ #include "klee/util/ExprPPrinter.h" -#include #include using namespace klee; diff --git a/lib/Expr/ExprPPrinter.cpp b/lib/Expr/ExprPPrinter.cpp index a7ad5ddc..ddcc57a1 100644 --- a/lib/Expr/ExprPPrinter.cpp +++ b/lib/Expr/ExprPPrinter.cpp @@ -17,9 +17,6 @@ #include #include -#include -#include -#include using namespace klee; diff --git a/lib/Expr/ExprSMTLIBLetPrinter.cpp b/lib/Expr/ExprSMTLIBLetPrinter.cpp index 2ea5c4e0..bcdaab32 100644 --- a/lib/Expr/ExprSMTLIBLetPrinter.cpp +++ b/lib/Expr/ExprSMTLIBLetPrinter.cpp @@ -8,7 +8,7 @@ // //===----------------------------------------------------------------------===// -#include +#include "llvm/Support/raw_ostream.h" #include "llvm/Support/CommandLine.h" #include "klee/util/ExprSMTLIBLetPrinter.h" diff --git a/lib/Expr/ExprSMTLIBPrinter.cpp b/lib/Expr/ExprSMTLIBPrinter.cpp index 2dbf3634..1cdab762 100644 --- a/lib/Expr/ExprSMTLIBPrinter.cpp +++ b/lib/Expr/ExprSMTLIBPrinter.cpp @@ -7,8 +7,6 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#include - #include "llvm/Support/Casting.h" #include "llvm/Support/CommandLine.h" #include "klee/util/ExprSMTLIBPrinter.h" diff --git a/lib/Expr/Lexer.cpp b/lib/Expr/Lexer.cpp index 9859ff36..e250a968 100644 --- a/lib/Expr/Lexer.cpp +++ b/lib/Expr/Lexer.cpp @@ -13,7 +13,6 @@ #include "llvm/Support/raw_ostream.h" #include -#include #include using namespace llvm; diff --git a/lib/Expr/Parser.cpp b/lib/Expr/Parser.cpp index 6b346648..aebce666 100644 --- a/lib/Expr/Parser.cpp +++ b/lib/Expr/Parser.cpp @@ -22,7 +22,6 @@ #include "llvm/Support/raw_ostream.h" #include -#include #include #include diff --git a/lib/Module/Checks.cpp b/lib/Module/Checks.cpp index 80b6b245..e1076d43 100644 --- a/lib/Module/Checks.cpp +++ b/lib/Module/Checks.cpp @@ -46,7 +46,6 @@ #include "llvm/Transforms/Scalar.h" #include "llvm/Transforms/Utils/BasicBlockUtils.h" #include "llvm/Support/CallSite.h" -#include using namespace llvm; using namespace klee; diff --git a/lib/Module/ModuleUtil.cpp b/lib/Module/ModuleUtil.cpp index 4f65d0e7..d00cf574 100644 --- a/lib/Module/ModuleUtil.cpp +++ b/lib/Module/ModuleUtil.cpp @@ -28,7 +28,6 @@ #include "llvm/Object/ObjectFile.h" #include "llvm/Object/Error.h" #include "llvm/Support/FileSystem.h" -#include "llvm/Support/raw_os_ostream.h" #include "llvm/IR/ValueSymbolTable.h" #include "llvm/Support/SourceMgr.h" #include "llvm/Support/DataStream.h" @@ -51,7 +50,6 @@ #include #include -#include #include #include #include diff --git a/lib/Module/Optimize.cpp b/lib/Module/Optimize.cpp index 6f060edd..ed1e0e34 100644 --- a/lib/Module/Optimize.cpp +++ b/lib/Module/Optimize.cpp @@ -40,7 +40,6 @@ #include "llvm/Transforms/Scalar.h" #include "llvm/Support/PassNameParser.h" #include "llvm/Support/PluginLoader.h" -#include using namespace llvm; #if 0 diff --git a/lib/SMT/SMTParser.cpp b/lib/SMT/SMTParser.cpp index d16e1edb..5622f048 100644 --- a/lib/SMT/SMTParser.cpp +++ b/lib/SMT/SMTParser.cpp @@ -14,7 +14,6 @@ #include "klee/Constraints.h" #include "expr/Parser.h" -#include #include #include #include diff --git a/lib/SMT/SMTParser.h b/lib/SMT/SMTParser.h index fd1ec044..ac84e74c 100644 --- a/lib/SMT/SMTParser.h +++ b/lib/SMT/SMTParser.h @@ -13,8 +13,6 @@ #include "expr/Parser.h" -#include -#include #include #include #include diff --git a/lib/SMT/main.cpp b/lib/SMT/main.cpp index 034c4ce4..6b66e279 100644 --- a/lib/SMT/main.cpp +++ b/lib/SMT/main.cpp @@ -2,7 +2,6 @@ #include "klee/ExprBuilder.h" -#include using namespace std; using namespace klee; diff --git a/lib/Solver/FastCexSolver.cpp b/lib/Solver/FastCexSolver.cpp index a488db2a..5c0cf8d0 100644 --- a/lib/Solver/FastCexSolver.cpp +++ b/lib/Solver/FastCexSolver.cpp @@ -19,7 +19,6 @@ #include "klee/Internal/Support/IntEvaluation.h" #include "llvm/Support/raw_ostream.h" -#include #include #include #include diff --git a/lib/Solver/IndependentSolver.cpp b/lib/Solver/IndependentSolver.cpp index 3c0b9b26..2cb4b2c6 100644 --- a/lib/Solver/IndependentSolver.cpp +++ b/lib/Solver/IndependentSolver.cpp @@ -19,7 +19,6 @@ #include #include #include -#include using namespace klee; using namespace llvm; diff --git a/lib/Solver/STPBuilder.cpp b/lib/Solver/STPBuilder.cpp index e4a21f74..34ce0ede 100644 --- a/lib/Solver/STPBuilder.cpp +++ b/lib/Solver/STPBuilder.cpp @@ -34,7 +34,6 @@ #include // max, min #include -#include #include #include #include diff --git a/lib/Solver/Solver.cpp b/lib/Solver/Solver.cpp index 025c70f2..229fa234 100644 --- a/lib/Solver/Solver.cpp +++ b/lib/Solver/Solver.cpp @@ -771,7 +771,6 @@ static SolverImpl::SolverRunStatus runAndGetCexForked(::VC vc, } } } -#include bool STPSolverImpl::computeInitialValues(const Query &query, const std::vector diff --git a/lib/Support/TreeStream.cpp b/lib/Support/TreeStream.cpp index e95fc582..0d5e4568 100644 --- a/lib/Support/TreeStream.cpp +++ b/lib/Support/TreeStream.cpp @@ -10,7 +10,6 @@ #include "klee/Internal/ADT/TreeStream.h" #include -#include #include #include #include diff --git a/tools/kleaver/main.cpp b/tools/kleaver/main.cpp index e31140e8..b19e2ea6 100644 --- a/tools/kleaver/main.cpp +++ b/tools/kleaver/main.cpp @@ -1,5 +1,3 @@ -#include - #include "expr/Lexer.h" #include "expr/Parser.h" diff --git a/tools/klee/Debug.cpp b/tools/klee/Debug.cpp index ad264045..fbabed9d 100644 --- a/tools/klee/Debug.cpp +++ b/tools/klee/Debug.cpp @@ -1,5 +1,4 @@ #include -#include void kdb_printExpr(klee::Expr *e) { llvm::errs() << "expr: " << e << " -- "; diff --git a/tools/klee/main.cpp b/tools/klee/main.cpp index 6abb1569..0292376c 100644 --- a/tools/klee/main.cpp +++ b/tools/klee/main.cpp @@ -62,7 +62,6 @@ #include #include #include -#include #include #include -- cgit 1.4.1