Generally speaking, this consists of three sorts of fix:
a) instantiating llvm::cout and llvm::cerr in various compile units,
b) adding missing includes, and
c) using the llvm::raw_ostream API where needed.
---
lib/Core/Executor.cpp | 3 ++-
lib/Core/Memory.cpp | 5 +++--
lib/Module/InstructionInfoTable.cpp | 9 +++++----
lib/Module/KModule.cpp | 26 ++++++++++++++++----------
lib/Module/ModuleUtil.cpp | 1 +
lib/Solver/IndependentSolver.cpp | 1 +
tools/kleaver/main.cpp | 7 +++++++
tools/klee/main.cpp | 6 +++++-
unittests/Expr/ExprTest.cpp | 6 ++++++
unittests/Solver/SolverTest.cpp | 6 ++++++
10 files changed, 52 insertions(+), 18 deletions(-)
diff --git a/lib/Core/Executor.cpp b/lib/Core/Executor.cpp
index 3523879..d82f44d 100644
--- a/lib/Core/Executor.cpp
+++ b/lib/Core/Executor.cpp
@@ -1074,7 +1074,8 @@ void Executor::executeGetValue(ExecutionState &state,
void Executor::stepInstruction(ExecutionState &state) {
if (DebugPrintInstructions) {
printFileLine(state, state.pc);
- llvm::cerr << std::setw(10) << stats::instructions << " " <<
*state.pc->inst;
+ llvm::cerr << std::setw(10) << stats::instructions << " ";
+ llvm::errs() << *(state.pc->inst);
}
if (statsTracker)
diff --git a/lib/Core/Memory.cpp b/lib/Core/Memory.cpp
index aa170ce..a707325 100644
--- a/lib/Core/Memory.cpp
+++ b/lib/Core/Memory.cpp
@@ -22,6 +22,7 @@
#include <llvm/Instruction.h>
#include <llvm/Value.h>
#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/raw_ostream.h"
#include <iostream>
#include <cassert>
@@ -65,7 +66,7 @@ MemoryObject::~MemoryObject() {
}
void MemoryObject::getAllocInfo(std::string &result) const {
- std::ostringstream info;
+ llvm::raw_string_ostream info(result);
info << "MO" << id << "[" << size << "]";
@@ -83,7 +84,7 @@ void MemoryObject::getAllocInfo(std::string &result) const {
info << " (no allocation info)";
}
- result = info.str();
+ info.flush();
}
/***/
diff --git a/lib/Module/InstructionInfoTable.cpp
b/lib/Module/InstructionInfoTable.cpp
index 8287440..8ac65a7 100644
--- a/lib/Module/InstructionInfoTable.cpp
+++ b/lib/Module/InstructionInfoTable.cpp
@@ -18,12 +18,12 @@
#include "llvm/Support/CFG.h"
#include "llvm/Support/InstIterator.h"
#include "llvm/Support/raw_ostream.h"
+#include "llvm/Support/raw_os_ostream.h"
#include "llvm/Analysis/ValueTracking.h"
#include <map>
#include <iostream>
#include <fstream>
-#include <sstream>
#include <string>
using namespace llvm;
@@ -39,9 +39,10 @@ public:
static void buildInstructionToLineMap(Module *m,
std::map<const Instruction*, unsigned>
&out) {
InstructionToLineAnnotator a;
- std::ostringstream buffer;
- m->print(buffer, &a);
- std::string str = buffer.str();
+ std::string str;
+ llvm::raw_string_ostream os(str);
+ m->print(os, &a);
+ os.flush();
const char *s;
unsigned line = 1;
diff --git a/lib/Module/KModule.cpp b/lib/Module/KModule.cpp
index 37e869c..55eb4b8 100644
--- a/lib/Module/KModule.cpp
+++ b/lib/Module/KModule.cpp
@@ -27,6 +27,7 @@
#include "llvm/ValueSymbolTable.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/raw_ostream.h"
+#include "llvm/Support/raw_os_ostream.h"
#include "llvm/System/Path.h"
#include "llvm/Target/TargetData.h"
#include "llvm/Transforms/Scalar.h"
@@ -326,42 +327,47 @@ void KModule::prepare(const Interpreter::ModuleOptions
&opts,
std::ostream *os = ih->openOutputFile("assembly.ll");
assert(os && os->good() && "unable to open source output");
+ llvm::raw_os_ostream *ros = new llvm::raw_os_ostream(*os);
+
// We have an option for this in case the user wants a .ll they
// can compile.
if (NoTruncateSourceLines) {
- *os << *module;
+ *ros << *module;
} else {
bool truncated = false;
- std::stringstream buffer;
- buffer << *module;
- std::string string = buffer.str();
+ std::string string;
+ llvm::raw_string_ostream rss(string);
+ rss << *module;
+ rss.flush();
const char *position = string.c_str();
for (;;) {
const char *end = index(position, '\n');
if (!end) {
- *os << position;
+ *ros << position;
break;
} else {
unsigned count = (end - position) + 1;
if (count<255) {
- os->write(position, count);
+ ros->write(position, count);
} else {
- os->write(position, 254);
- *os << "\n";
+ ros->write(position, 254);
+ *ros << "\n";
truncated = true;
}
position = end+1;
}
}
}
-
+ delete ros;
delete os;
}
if (OutputModule) {
std::ostream *f = ih->openOutputFile("final.bc");
- WriteBitcodeToFile(module, *f);
+ llvm::raw_os_ostream* rfs = new llvm::raw_os_ostream(*f);
+ WriteBitcodeToFile(module, *rfs);
+ delete rfs;
delete f;
}
diff --git a/lib/Module/ModuleUtil.cpp b/lib/Module/ModuleUtil.cpp
index dae6ffc..adfc5cf 100644
--- a/lib/Module/ModuleUtil.cpp
+++ b/lib/Module/ModuleUtil.cpp
@@ -19,6 +19,7 @@
#include "llvm/Support/InstIterator.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Analysis/ValueTracking.h"
+#include "llvm/System/Path.h"
#include <map>
#include <iostream>
diff --git a/lib/Solver/IndependentSolver.cpp b/lib/Solver/IndependentSolver.cpp
index 3e19dbc..d293176 100644
--- a/lib/Solver/IndependentSolver.cpp
+++ b/lib/Solver/IndependentSolver.cpp
@@ -19,6 +19,7 @@
#include <map>
#include <vector>
+#include <ostream>
using namespace klee;
using namespace llvm;
diff --git a/tools/kleaver/main.cpp b/tools/kleaver/main.cpp
index 07de278..52235e6 100644
--- a/tools/kleaver/main.cpp
+++ b/tools/kleaver/main.cpp
@@ -1,3 +1,5 @@
+#include <iostream>
+
#include "expr/Lexer.h"
#include "expr/Parser.h"
@@ -76,6 +78,11 @@ namespace {
cl::init(false));
}
+namespace llvm {
+ OStream cout(::std::cout);
+ OStream cerr(::std::cerr);
+}
+
static std::string escapedString(const char *start, unsigned length) {
std::string Str;
llvm::raw_string_ostream s(Str);
diff --git a/tools/klee/main.cpp b/tools/klee/main.cpp
index f7a8f0b..cd459f1 100644
--- a/tools/klee/main.cpp
+++ b/tools/klee/main.cpp
@@ -188,6 +188,10 @@ namespace {
extern bool WriteTraces;
extern cl::opt<double> MaxTime;
+namespace llvm {
+ OStream cerr(::std::cerr);
+}
+
/***/
class KleeHandler : public InterpreterHandler {
@@ -523,7 +527,7 @@ void KleeHandler::getOutFiles(std::string path,
}
for (std::set<llvm::sys::Path>::iterator it = contents.begin(),
ie = contents.end(); it != ie; ++it) {
- std::string f = it->toString();
+ std::string f = it->str();
if (f.substr(f.size()-6,f.size()) == ".ktest") {
results.push_back(f);
}
diff --git a/unittests/Expr/ExprTest.cpp b/unittests/Expr/ExprTest.cpp
index 4b56f47..24cd21e 100644
--- a/unittests/Expr/ExprTest.cpp
+++ b/unittests/Expr/ExprTest.cpp
@@ -7,12 +7,18 @@
//
//===----------------------------------------------------------------------===//
+#include <iostream>
#include "gtest/gtest.h"
#include "klee/Expr.h"
using namespace klee;
+namespace llvm {
+ OStream cout(::std::cout);
+ OStream cerr(::std::cerr);
+}
+
namespace {
ref<Expr> getConstant(int value, Expr::Width width) {
diff --git a/unittests/Solver/SolverTest.cpp b/unittests/Solver/SolverTest.cpp
index cda0cf9..39b971d 100644
--- a/unittests/Solver/SolverTest.cpp
+++ b/unittests/Solver/SolverTest.cpp
@@ -7,6 +7,7 @@
//
//===----------------------------------------------------------------------===//
+#include <iostream>
#include "gtest/gtest.h"
#include "klee/Constraints.h"
@@ -16,6 +17,11 @@
using namespace klee;
+namespace llvm {
+ OStream cout(::std::cout);
+ OStream cerr(::std::cerr);
+}
+
namespace {
const int g_constants[] = { -1, 1, 4, 17, 0 };
--
1.5.6.5
--SLDf9lqlvOQaIe6s--