aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib/Module
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Module')
-rw-r--r--lib/Module/InstructionInfoTable.cpp11
-rw-r--r--lib/Module/KModule.cpp26
-rw-r--r--lib/Module/ModuleUtil.cpp1
3 files changed, 22 insertions, 16 deletions
diff --git a/lib/Module/InstructionInfoTable.cpp b/lib/Module/InstructionInfoTable.cpp
index 82874406..7573f51c 100644
--- a/lib/Module/InstructionInfoTable.cpp
+++ b/lib/Module/InstructionInfoTable.cpp
@@ -18,12 +18,10 @@
#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 +37,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 37e869c8..55eb4b8a 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 dae6ffc5..adfc5cfd 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>