aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2001-09-19 16:52:09 +0000
committerChris Lattner <sabre@nondot.org>2001-09-19 16:52:09 +0000
commit78f7e1a9cdc9a373c9a18598cd5e47ac5476bfe6 (patch)
tree96c486749764c853caa2f13e979dbcb0341aa389
parentca269e4327488b61be95da3fd45a55e4fb05f5aa (diff)
downloadexternal_llvm-78f7e1a9cdc9a373c9a18598cd5e47ac5476bfe6.zip
external_llvm-78f7e1a9cdc9a373c9a18598cd5e47ac5476bfe6.tar.gz
external_llvm-78f7e1a9cdc9a373c9a18598cd5e47ac5476bfe6.tar.bz2
Add proper support to send output to the right place
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@649 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--tools/llc/llc.cpp39
1 files changed, 36 insertions, 3 deletions
diff --git a/tools/llc/llc.cpp b/tools/llc/llc.cpp
index b8bcb1d..c4bdc45 100644
--- a/tools/llc/llc.cpp
+++ b/tools/llc/llc.cpp
@@ -12,15 +12,17 @@
#include "llvm/Module.h"
#include "llvm/Method.h"
#include <memory>
+#include <fstream>
cl::String InputFilename ("", "Input filename", cl::NoFlags, "-");
cl::String OutputFilename("o", "Output filename", cl::NoFlags, "");
+cl::Flag Force ("f", "Overwrite output files", cl::NoFlags, false);
//-------------------------- Internal Functions -----------------------------//
-static void NormalizeMethod(Method* method) {
- NormalizePhiConstantArgs(method);
+static void NormalizeMethod(Method *M) {
+ NormalizePhiConstantArgs(M);
}
@@ -57,7 +59,38 @@ int main(int argc, char **argv) {
}
}
- Target->emitAssembly(M.get(), cout);
+ // Figure out where we are going to send the output...
+ ostream *Out = 0;
+ if (OutputFilename != "") { // Specified an output filename?
+ Out = new ofstream(OutputFilename.c_str(),
+ (Force ? 0 : ios::noreplace)|ios::out);
+ } else {
+ if (InputFilename == "-") {
+ OutputFilename = "-";
+ Out = &cout;
+ } else {
+ string IFN = InputFilename;
+ int Len = IFN.length();
+ if (IFN[Len-3] == '.' && IFN[Len-2] == 'b' && IFN[Len-1] == 'c') {
+ OutputFilename = string(IFN.begin(), IFN.end()-3); // s/.bc/.s/
+ } else {
+ OutputFilename = IFN; // Append a .s to it
+ }
+ OutputFilename += ".s";
+ Out = new ofstream(OutputFilename.c_str(),
+ (Force ? 0 : ios::noreplace)|ios::out);
+ if (!Out->good()) {
+ cerr << "Error opening " << OutputFilename << "!\n";
+ delete Out;
+ return 1;
+ }
+ }
+ }
+
+ // Emit the output...
+ Target->emitAssembly(M.get(), *Out);
+
+ if (Out != &cout) delete Out;
return 0;
}