forked from OSchip/llvm-project
Eliminate some redundancy by relying on raw_fd_ostream to handle "-"
properly. llvm-svn: 111373
This commit is contained in:
parent
083330a8f2
commit
7ba6f22b47
|
@ -127,36 +127,13 @@ GetFileNameRoot(const std::string &InputFilename) {
|
||||||
static formatted_raw_ostream *GetOutputStream(const char *TargetName,
|
static formatted_raw_ostream *GetOutputStream(const char *TargetName,
|
||||||
Triple::OSType OS,
|
Triple::OSType OS,
|
||||||
const char *ProgName) {
|
const char *ProgName) {
|
||||||
if (!OutputFilename.empty()) {
|
// If we don't yet have an output filename, make one.
|
||||||
// Make sure that the Out file gets unlinked from the disk if we get a
|
if (OutputFilename.empty()) {
|
||||||
// SIGINT
|
if (InputFilename == "-")
|
||||||
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;
|
|
||||||
}
|
|
||||||
formatted_raw_ostream *Out =
|
|
||||||
new formatted_raw_ostream(*FDOut, formatted_raw_ostream::DELETE_STREAM);
|
|
||||||
|
|
||||||
return Out;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (InputFilename == "-") {
|
|
||||||
OutputFilename = "-";
|
OutputFilename = "-";
|
||||||
return new formatted_raw_ostream(outs(),
|
else {
|
||||||
formatted_raw_ostream::PRESERVE_STREAM);
|
|
||||||
}
|
|
||||||
|
|
||||||
OutputFilename = GetFileNameRoot(InputFilename);
|
OutputFilename = GetFileNameRoot(InputFilename);
|
||||||
|
|
||||||
bool Binary = false;
|
|
||||||
switch (FileType) {
|
switch (FileType) {
|
||||||
default: assert(0 && "Unknown file type");
|
default: assert(0 && "Unknown file type");
|
||||||
case TargetMachine::CGFT_AssemblyFile:
|
case TargetMachine::CGFT_AssemblyFile:
|
||||||
|
@ -175,18 +152,32 @@ static formatted_raw_ostream *GetOutputStream(const char *TargetName,
|
||||||
OutputFilename += ".obj";
|
OutputFilename += ".obj";
|
||||||
else
|
else
|
||||||
OutputFilename += ".o";
|
OutputFilename += ".o";
|
||||||
Binary = true;
|
|
||||||
break;
|
break;
|
||||||
case TargetMachine::CGFT_Null:
|
case TargetMachine::CGFT_Null:
|
||||||
OutputFilename += ".null";
|
OutputFilename += ".null";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Decide if we need "binary" output.
|
||||||
|
bool Binary = false;
|
||||||
|
switch (FileType) {
|
||||||
|
default: assert(0 && "Unknown file type");
|
||||||
|
case TargetMachine::CGFT_AssemblyFile:
|
||||||
|
break;
|
||||||
|
case TargetMachine::CGFT_ObjectFile:
|
||||||
|
case TargetMachine::CGFT_Null:
|
||||||
Binary = true;
|
Binary = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure that the Out file gets unlinked from the disk if we get a
|
// Make sure that the Out file gets unlinked from the disk if we get a
|
||||||
// SIGINT
|
// SIGINT
|
||||||
|
if (OutputFilename != "-")
|
||||||
sys::RemoveFileOnSignal(sys::Path(OutputFilename));
|
sys::RemoveFileOnSignal(sys::Path(OutputFilename));
|
||||||
|
|
||||||
|
// Open the file.
|
||||||
std::string error;
|
std::string error;
|
||||||
unsigned OpenFlags = 0;
|
unsigned OpenFlags = 0;
|
||||||
if (Binary) OpenFlags |= raw_fd_ostream::F_Binary;
|
if (Binary) OpenFlags |= raw_fd_ostream::F_Binary;
|
||||||
|
|
Loading…
Reference in New Issue