summaryrefslogtreecommitdiff
path: root/tools/llc
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2010-08-18 17:55:15 +0000
committerDan Gohman <gohman@apple.com>2010-08-18 17:55:15 +0000
commit18cde6df91a33d62a334002a7b608917c07791e8 (patch)
tree9d630399b49992537bb34e8f591bd0fdc98acdb2 /tools/llc
parent4931b312c06d89b14d54fdd6c3cdd374d76af7b8 (diff)
downloadllvm-18cde6df91a33d62a334002a7b608917c07791e8.tar.gz
llvm-18cde6df91a33d62a334002a7b608917c07791e8.tar.bz2
llvm-18cde6df91a33d62a334002a7b608917c07791e8.tar.xz
Eliminate some redundancy by relying on raw_fd_ostream to handle "-"
properly. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@111373 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/llc')
-rw-r--r--tools/llc/llc.cpp77
1 files changed, 34 insertions, 43 deletions
diff --git a/tools/llc/llc.cpp b/tools/llc/llc.cpp
index 5a23b27710..a7d1fa0311 100644
--- a/tools/llc/llc.cpp
+++ b/tools/llc/llc.cpp
@@ -127,66 +127,57 @@ GetFileNameRoot(const std::string &InputFilename) {
static formatted_raw_ostream *GetOutputStream(const char *TargetName,
Triple::OSType OS,
const char *ProgName) {
- if (!OutputFilename.empty()) {
- // Make sure that the Out file gets unlinked from the disk if we get a
- // SIGINT
- if (OutputFilename != "-")
- sys::RemoveFileOnSignal(sys::Path(OutputFilename));
-
- std::string error;
- raw_fd_ostream *FDOut =
- new raw_fd_ostream(OutputFilename.c_str(), error,
- raw_fd_ostream::F_Binary);
- if (!error.empty()) {
- errs() << error << '\n';
- delete FDOut;
- return 0;
+ // If we don't yet have an output filename, make one.
+ if (OutputFilename.empty()) {
+ if (InputFilename == "-")
+ OutputFilename = "-";
+ else {
+ OutputFilename = GetFileNameRoot(InputFilename);
+
+ switch (FileType) {
+ default: assert(0 && "Unknown file type");
+ case TargetMachine::CGFT_AssemblyFile:
+ if (TargetName[0] == 'c') {
+ if (TargetName[1] == 0)
+ OutputFilename += ".cbe.c";
+ else if (TargetName[1] == 'p' && TargetName[2] == 'p')
+ OutputFilename += ".cpp";
+ else
+ OutputFilename += ".s";
+ } else
+ OutputFilename += ".s";
+ break;
+ case TargetMachine::CGFT_ObjectFile:
+ if (OS == Triple::Win32)
+ OutputFilename += ".obj";
+ else
+ OutputFilename += ".o";
+ break;
+ case TargetMachine::CGFT_Null:
+ OutputFilename += ".null";
+ break;
+ }
}
- formatted_raw_ostream *Out =
- new formatted_raw_ostream(*FDOut, formatted_raw_ostream::DELETE_STREAM);
-
- return Out;
}
- if (InputFilename == "-") {
- OutputFilename = "-";
- return new formatted_raw_ostream(outs(),
- formatted_raw_ostream::PRESERVE_STREAM);
- }
-
- OutputFilename = GetFileNameRoot(InputFilename);
-
+ // Decide if we need "binary" output.
bool Binary = false;
switch (FileType) {
default: assert(0 && "Unknown file type");
case TargetMachine::CGFT_AssemblyFile:
- if (TargetName[0] == 'c') {
- if (TargetName[1] == 0)
- OutputFilename += ".cbe.c";
- else if (TargetName[1] == 'p' && TargetName[2] == 'p')
- OutputFilename += ".cpp";
- else
- OutputFilename += ".s";
- } else
- OutputFilename += ".s";
break;
case TargetMachine::CGFT_ObjectFile:
- if (OS == Triple::Win32)
- OutputFilename += ".obj";
- else
- OutputFilename += ".o";
- Binary = true;
- break;
case TargetMachine::CGFT_Null:
- OutputFilename += ".null";
Binary = true;
break;
}
// Make sure that the Out file gets unlinked from the disk if we get a
// SIGINT
- sys::RemoveFileOnSignal(sys::Path(OutputFilename));
+ if (OutputFilename != "-")
+ sys::RemoveFileOnSignal(sys::Path(OutputFilename));
+ // Open the file.
std::string error;
unsigned OpenFlags = 0;
if (Binary) OpenFlags |= raw_fd_ostream::F_Binary;