Fix the -opt switch and add a test case for it.
authorMikhail Glushenkov <foldr@codedgers.com>
Fri, 30 May 2008 19:56:27 +0000 (19:56 +0000)
committerMikhail Glushenkov <foldr@codedgers.com>
Fri, 30 May 2008 19:56:27 +0000 (19:56 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@51784 91177308-0d34-0410-b5e6-96231b3b80d8

test/LLVMC/opt-test.c [new file with mode: 0644]
tools/llvmc2/CompilationGraph.cpp
tools/llvmc2/Tools.td
tools/llvmc2/llvmc.cpp

diff --git a/test/LLVMC/opt-test.c b/test/LLVMC/opt-test.c
new file mode 100644 (file)
index 0000000..25ca66a
--- /dev/null
@@ -0,0 +1,12 @@
+/*
+ * Check that the -opt switch works.
+ * RUN: llvmc2 %s -opt -o %t
+ * RUN: ./%t | grep hello
+ */
+
+#include <stdio.h>
+
+int main() {
+    printf("hello\n");
+    return 0;
+}
index 9cdcac384574ef3e2955c8b4c9e46d8480d605fc..acf391a29060f79ebf3ab9fbb59aa49a364e8130 100644 (file)
@@ -151,6 +151,10 @@ namespace {
       Out.appendComponent(BaseName);
     }
     Out.appendSuffix(Suffix);
+    // NOTE: makeUnique always *creates* a unique temporary file,
+    // which is good, since there will be no races. However, some
+    // tools do not like it when the output file already exists, so
+    // they have to be placated with -f or something like that.
     Out.makeUnique(true, NULL);
     return Out;
   }
index 28fba8d5a36097c2a46137b7c5e73b5d6bdc1cf7..852d7fea062c80f988c384c7ee4cf5c5b2280629 100644 (file)
@@ -27,9 +27,12 @@ def llvm_gcc_c : Tool<
  (output_suffix "bc"),
  (cmd_line (case
             (switch_on "E"),
-              "llvm-g++ -E -x c $INFILE",
+              (case (not_empty "o"),
+                    "llvm-gcc -E -x c++ $INFILE -o $OUTFILE",
+                    (default),
+                    "llvm-gcc -E -x c++ $INFILE"),
             (default),
-              "llvm-g++ -c -x c $INFILE -o $OUTFILE -emit-llvm")),
+              "llvm-gcc -c -x c $INFILE -o $OUTFILE -emit-llvm")),
  (switch_option "E", (stop_compilation),
    (help "Stop after the preprocessing stage, do not run the compiler")),
  (sink)
@@ -41,8 +44,10 @@ def llvm_gcc_cpp : Tool<
  (output_suffix "bc"),
  (cmd_line (case
             (switch_on "E"),
-              // TOFIX: this does not play well with -o
-              "llvm-g++ -E -x c++ $INFILE",
+              (case (not_empty "o"),
+                    "llvm-g++ -E -x c++ $INFILE -o $OUTFILE",
+                    (default),
+                    "llvm-g++ -E -x c++ $INFILE"),
             (default),
               "llvm-g++ -c -x c++ $INFILE -o $OUTFILE -emit-llvm")),
  (switch_option "E", (stop_compilation)),
@@ -54,7 +59,7 @@ def opt : Tool<
  (out_language "llvm-bitcode"),
  (switch_option "opt", (help "Enable opt")),
  (output_suffix "bc"),
- (cmd_line "opt $INFILE -o $OUTFILE")
+ (cmd_line "opt -f $INFILE -o $OUTFILE")
 ]>;
 
 def llvm_as : Tool<
index 560ee98173a4386783cad40004bb8e44529ac5eb..e073845d09e07978666672e3880cca0241012946 100644 (file)
@@ -32,8 +32,6 @@ using namespace llvmc;
 // Built-in command-line options.
 // External linkage here is intentional.
 
-// TOFIX: Write a 'driver driver' (easier to do as a separate
-// executable that drives llvmc2 proper).
 cl::list<std::string> InputFilenames(cl::Positional, cl::desc("<input file>"),
                                      cl::ZeroOrMore);
 cl::opt<std::string> OutputFilename("o", cl::desc("Output file name"),
@@ -42,7 +40,7 @@ cl::list<std::string> Languages("x",
           cl::desc("Specify the language of the following input files"),
           cl::ZeroOrMore);
 cl::opt<bool> DryRun("dry-run",
-                     cl::desc("only pretend to run commands"));
+                     cl::desc("Only pretend to run commands"));
 cl::opt<bool> VerboseMode("v",
                           cl::desc("Enable verbose mode"));
 cl::opt<bool> WriteGraph("write-graph",