aboutsummaryrefslogtreecommitdiffstats
path: root/tools/gccas
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2003-04-16 17:49:18 +0000
committerChris Lattner <sabre@nondot.org>2003-04-16 17:49:18 +0000
commit8c7b0551f4a23759509ae84c53b05b498401ebf7 (patch)
tree7c142467dd012c5b19b5567ff1a87bf9a77b0177 /tools/gccas
parent2c1d2f21fd9e3abee2a1ccce2cb5fd27a7146091 (diff)
downloadexternal_llvm-8c7b0551f4a23759509ae84c53b05b498401ebf7.zip
external_llvm-8c7b0551f4a23759509ae84c53b05b498401ebf7.tar.gz
external_llvm-8c7b0551f4a23759509ae84c53b05b498401ebf7.tar.bz2
Improve compatibility with system AS further by allowing input from stdin
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@5780 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/gccas')
-rw-r--r--tools/gccas/gccas.cpp46
1 files changed, 30 insertions, 16 deletions
diff --git a/tools/gccas/gccas.cpp b/tools/gccas/gccas.cpp
index 2e418a3..bd266f0 100644
--- a/tools/gccas/gccas.cpp
+++ b/tools/gccas/gccas.cpp
@@ -27,7 +27,7 @@ namespace {
TargetData TD("gccas target");
cl::opt<std::string>
- InputFilename(cl::Positional, cl::desc("<input llvm assembly>"),cl::Required);
+ InputFilename(cl::Positional,cl::desc("<input llvm assembly>"),cl::init("-"));
cl::opt<std::string>
OutputFilename("o", cl::desc("Override output filename"),
@@ -116,29 +116,41 @@ int main(int argc, char **argv) {
std::cerr << argv[0] << ": assembly didn't read correctly.\n";
return 1;
}
-
+
+ std::ostream *Out = 0;
if (OutputFilename == "") { // Didn't specify an output filename?
- std::string IFN = InputFilename;
- int Len = IFN.length();
- if (IFN[Len-2] == '.' && IFN[Len-1] == 's') { // Source ends in .s?
- OutputFilename = std::string(IFN.begin(), IFN.end()-2);
+ if (InputFilename == "-") {
+ OutputFilename = "-";
} else {
- OutputFilename = IFN; // Append a .o to it
+ std::string IFN = InputFilename;
+ int Len = IFN.length();
+ if (IFN[Len-2] == '.' && IFN[Len-1] == 's') { // Source ends in .s?
+ OutputFilename = std::string(IFN.begin(), IFN.end()-2);
+ } else {
+ OutputFilename = IFN; // Append a .o to it
+ }
+ OutputFilename += ".o";
}
- OutputFilename += ".o";
}
- std::ofstream Out(OutputFilename.c_str(), std::ios::out);
- if (!Out.good()) {
+ if (OutputFilename == "-")
+ Out = &std::cout;
+ else {
+ Out = new std::ofstream(OutputFilename.c_str(), std::ios::out);
+
+ // Make sure that the Out file gets unlink'd from the disk if we get a
+ // signal
+ RemoveFileOnSignal(OutputFilename);
+ }
+
+
+ if (!Out->good()) {
std::cerr << argv[0] << ": error opening " << OutputFilename << "!\n";
return 1;
}
- // Make sure that the Out file gets unlink'd from the disk if we get a SIGINT
- RemoveFileOnSignal(OutputFilename);
-
- if (PrintVersion)
- std::cerr << "LLVM GCCAS version xx\n"; /* For GNU compatibility */
+ if (PrintVersion) /* For GNU compatibility */
+ std::cerr << "LLVM GCCAS version xx\n" << std::flush;
// In addition to just parsing the input from GCC, we also want to spiff it up
// a little bit. Do this now.
@@ -151,9 +163,11 @@ int main(int argc, char **argv) {
AddConfiguredTransformationPasses(Passes);
// Write bytecode to file...
- Passes.add(new WriteBytecodePass(&Out));
+ Passes.add(new WriteBytecodePass(Out));
// Run our queue of passes all at once now, efficiently.
Passes.run(*M.get());
+
+ if (Out != &std::cout) delete Out;
return 0;
}