summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorOwen Anderson <resistor@mac.com>2008-08-21 00:14:44 +0000
committerOwen Anderson <resistor@mac.com>2008-08-21 00:14:44 +0000
commitcb3718832375a581c5ea23f15918f3ea447a446c (patch)
treea72c740cc8590cd63825fcf08f71c5e2f625ca55 /tools
parentf4a97da4072a2ee4aca3c668a9fa113c06fdef8d (diff)
downloadllvm-cb3718832375a581c5ea23f15918f3ea447a446c.tar.gz
llvm-cb3718832375a581c5ea23f15918f3ea447a446c.tar.bz2
llvm-cb3718832375a581c5ea23f15918f3ea447a446c.tar.xz
Use raw_ostream throughout the AsmPrinter.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@55092 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools')
-rw-r--r--tools/llc/llc.cpp27
-rw-r--r--tools/lto/LTOCodeGenerator.cpp13
-rw-r--r--tools/lto/LTOCodeGenerator.h6
3 files changed, 28 insertions, 18 deletions
diff --git a/tools/llc/llc.cpp b/tools/llc/llc.cpp
index dfd1f6b073..2c725e8a2f 100644
--- a/tools/llc/llc.cpp
+++ b/tools/llc/llc.cpp
@@ -31,6 +31,7 @@
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/PluginLoader.h"
#include "llvm/Support/FileUtilities.h"
+#include "llvm/Support/raw_ostream.h"
#include "llvm/Analysis/Verifier.h"
#include "llvm/System/Signals.h"
#include "llvm/Config/config.h"
@@ -106,10 +107,10 @@ GetFileNameRoot(const std::string &InputFilename) {
return outputFilename;
}
-static std::ostream *GetOutputStream(const char *ProgName) {
+static raw_ostream *GetOutputStream(const char *ProgName) {
if (OutputFilename != "") {
if (OutputFilename == "-")
- return &std::cout;
+ return &outs();
// Specified an output filename?
if (!Force && std::ifstream(OutputFilename.c_str())) {
@@ -123,12 +124,13 @@ static std::ostream *GetOutputStream(const char *ProgName) {
// SIGINT
sys::RemoveFileOnSignal(sys::Path(OutputFilename));
- return new std::ofstream(OutputFilename.c_str());
+ std::string error;
+ return new raw_fd_ostream(OutputFilename.c_str(), error);
}
if (InputFilename == "-") {
OutputFilename = "-";
- return &std::cout;
+ return &outs();
}
OutputFilename = GetFileNameRoot(InputFilename);
@@ -165,9 +167,10 @@ static std::ostream *GetOutputStream(const char *ProgName) {
// SIGINT
sys::RemoveFileOnSignal(sys::Path(OutputFilename));
- std::ostream *Out = new std::ofstream(OutputFilename.c_str());
- if (!Out->good()) {
- std::cerr << ProgName << ": error opening " << OutputFilename << "!\n";
+ std::string error;
+ raw_ostream *Out = new raw_fd_ostream(OutputFilename.c_str(), error);
+ if (!error.empty()) {
+ std::cerr << error;
delete Out;
return 0;
}
@@ -229,7 +232,7 @@ int main(int argc, char **argv) {
TargetMachine &Target = *target.get();
// Figure out where we are going to send the output...
- std::ostream *Out = GetOutputStream(argv[0]);
+ raw_ostream *Out = GetOutputStream(argv[0]);
if (Out == 0) return 1;
// If this target requires addPassesToEmitWholeFile, do it now. This is
@@ -244,7 +247,7 @@ int main(int argc, char **argv) {
if (Target.addPassesToEmitWholeFile(PM, *Out, FileType, Fast)) {
std::cerr << argv[0] << ": target does not support generation of this"
<< " file type!\n";
- if (Out != &std::cout) delete Out;
+ if (Out != &outs()) delete Out;
// And the Out file is empty and useless, so remove it now.
sys::Path(OutputFilename).eraseFromDisk();
return 1;
@@ -271,7 +274,7 @@ int main(int argc, char **argv) {
case FileModel::Error:
std::cerr << argv[0] << ": target does not support generation of this"
<< " file type!\n";
- if (Out != &std::cout) delete Out;
+ if (Out != &outs()) delete Out;
// And the Out file is empty and useless, so remove it now.
sys::Path(OutputFilename).eraseFromDisk();
return 1;
@@ -288,7 +291,7 @@ int main(int argc, char **argv) {
if (Target.addPassesToEmitFileFinish(Passes, MCE, Fast)) {
std::cerr << argv[0] << ": target does not support generation of this"
<< " file type!\n";
- if (Out != &std::cout) delete Out;
+ if (Out != &outs()) delete Out;
// And the Out file is empty and useless, so remove it now.
sys::Path(OutputFilename).eraseFromDisk();
return 1;
@@ -306,7 +309,7 @@ int main(int argc, char **argv) {
}
// Delete the ostream if it's not a stdout stream
- if (Out != &std::cout) delete Out;
+ if (Out != &outs()) delete Out;
return 0;
}
diff --git a/tools/lto/LTOCodeGenerator.cpp b/tools/lto/LTOCodeGenerator.cpp
index ad3964d3f7..275aac208f 100644
--- a/tools/lto/LTOCodeGenerator.cpp
+++ b/tools/lto/LTOCodeGenerator.cpp
@@ -27,6 +27,7 @@
#include "llvm/Support/SystemUtils.h"
#include "llvm/Support/Mangler.h"
#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/raw_ostream.h"
#include "llvm/System/Signals.h"
#include "llvm/Analysis/Passes.h"
#include "llvm/Analysis/LoopPass.h"
@@ -162,9 +163,12 @@ const void* LTOCodeGenerator::compile(size_t* length, std::string& errMsg)
sys::RemoveFileOnSignal(uniqueAsmPath);
// generate assembly code
- std::ofstream asmFile(uniqueAsmPath.c_str());
- bool genResult = this->generateAssemblyCode(asmFile, errMsg);
- asmFile.close();
+ std::string error;
+ bool genResult = false;
+ {
+ raw_fd_ostream asmFile(uniqueAsmPath.c_str(), error);
+ genResult = this->generateAssemblyCode(asmFile, errMsg);
+ }
if ( genResult ) {
if ( uniqueAsmPath.exists() )
uniqueAsmPath.eraseFromDisk();
@@ -309,7 +313,8 @@ void LTOCodeGenerator::applyScopeRestrictions()
}
/// Optimize merged modules using various IPO passes
-bool LTOCodeGenerator::generateAssemblyCode(std::ostream& out, std::string& errMsg)
+bool LTOCodeGenerator::generateAssemblyCode(raw_ostream& out,
+ std::string& errMsg)
{
if ( this->determineTarget(errMsg) )
return true;
diff --git a/tools/lto/LTOCodeGenerator.h b/tools/lto/LTOCodeGenerator.h
index d3a2b6b294..7a931526b7 100644
--- a/tools/lto/LTOCodeGenerator.h
+++ b/tools/lto/LTOCodeGenerator.h
@@ -25,6 +25,8 @@
//
// C++ class which implements the opaque lto_code_gen_t
//
+
+class llvm::raw_ostream;
class LTOCodeGenerator {
public:
static const char* getVersionString();
@@ -41,8 +43,8 @@ public:
const void* compile(size_t* length, std::string& errMsg);
void setCodeGenDebugOptions(const char *opts);
private:
- bool generateAssemblyCode(std::ostream& out,
- std::string& errMsg);
+ bool generateAssemblyCode(llvm::raw_ostream& out,
+ std::string& errMsg);
bool assemble(const std::string& asmPath,
const std::string& objPath, std::string& errMsg);
void applyScopeRestrictions();