[cfe-commits] r95849 - in /cfe/trunk: include/clang/Basic/DiagnosticDriverKinds.td include/clang/Driver/Options.td include/clang/Driver/Types.def lib/Driver/Driver.cpp lib/Driver/Tools.cpp test/Driver/rewrite-objc.m

Daniel Dunbar daniel at zuster.org
Wed Feb 10 19:16:21 PST 2010


Author: ddunbar
Date: Wed Feb 10 21:16:21 2010
New Revision: 95849

URL: http://llvm.org/viewvc/llvm-project?rev=95849&view=rev
Log:
Driver: Add -rewrite-objc, which is an interface to clang -cc1 -rewrite-objc.

Added:
    cfe/trunk/test/Driver/rewrite-objc.m
Modified:
    cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
    cfe/trunk/include/clang/Driver/Options.td
    cfe/trunk/include/clang/Driver/Types.def
    cfe/trunk/lib/Driver/Driver.cpp
    cfe/trunk/lib/Driver/Tools.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td?rev=95849&r1=95848&r2=95849&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td Wed Feb 10 21:16:21 2010
@@ -62,6 +62,8 @@
 def err_drv_invalid_int_value : Error<"invalid integral value '%1' in '%0'">;
 def err_drv_invalid_remap_file : Error<
     "invalid option '%0' not of the form <from-file>;<to-file>">;
+def err_drv_invalid_gcc_output_type : Error<
+    "invalid output type '%0' for use with gcc tool">;
 
 def warn_drv_input_file_unused : Warning<
   "%0: '%1' input unused when '%2' is present">;

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=95849&r1=95848&r2=95849&view=diff

==============================================================================
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Wed Feb 10 21:16:21 2010
@@ -492,6 +492,8 @@
 def p : Flag<"-p">;
 def read__only__relocs : Separate<"-read_only_relocs">;
 def remap : Flag<"-remap">;
+def rewrite_objc : Flag<"-rewrite-objc">, Flags<[DriverOption]>,
+  HelpText<"Rewrite Objective-C source to C++">;
 def rpath : Separate<"-rpath">, Flags<[LinkerInput]>;
 def r : Flag<"-r">;
 def save_temps : Flag<"-save-temps">, Flags<[DriverOption]>,

Modified: cfe/trunk/include/clang/Driver/Types.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Types.def?rev=95849&r1=95848&r2=95849&view=diff

==============================================================================
--- cfe/trunk/include/clang/Driver/Types.def (original)
+++ cfe/trunk/include/clang/Driver/Types.def Wed Feb 10 21:16:21 2010
@@ -72,6 +72,7 @@
 TYPE("llvm-asm",                 LLVMAsm,      INVALID,         "s",     "")
 TYPE("llvm-bc",                  LLVMBC,       INVALID,         "o",     "")
 TYPE("plist",                    Plist,        INVALID,         "plist", "")
+TYPE("rewritten-objc",           RewrittenObjC,INVALID,         "cpp",   "")
 TYPE("precompiled-header",       PCH,          INVALID,         "gch",   "A")
 TYPE("object",                   Object,       INVALID,         "o",     "")
 TYPE("treelang",                 Treelang,     INVALID,         0,       "u")

Modified: cfe/trunk/lib/Driver/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Driver.cpp?rev=95849&r1=95848&r2=95849&view=diff

==============================================================================
--- cfe/trunk/lib/Driver/Driver.cpp (original)
+++ cfe/trunk/lib/Driver/Driver.cpp Wed Feb 10 21:16:21 2010
@@ -622,6 +622,7 @@
 
     // -{fsyntax-only,-analyze,emit-ast,S} only run up to the compiler.
   } else if ((FinalPhaseArg = Args.getLastArg(options::OPT_fsyntax_only)) ||
+             (FinalPhaseArg = Args.getLastArg(options::OPT_rewrite_objc)) ||
              (FinalPhaseArg = Args.getLastArg(options::OPT__analyze,
                                               options::OPT__analyze_auto)) ||
              (FinalPhaseArg = Args.getLastArg(options::OPT_emit_ast)) ||
@@ -742,6 +743,8 @@
 
     if (Args.hasArg(options::OPT_fsyntax_only)) {
       return new CompileJobAction(Input, types::TY_Nothing);
+    } else if (Args.hasArg(options::OPT_rewrite_objc)) {
+      return new CompileJobAction(Input, types::TY_RewrittenObjC);
     } else if (Args.hasArg(options::OPT__analyze, options::OPT__analyze_auto)) {
       return new AnalyzeJobAction(Input, types::TY_Plist);
     } else if (Args.hasArg(options::OPT_emit_ast)) {
@@ -1171,8 +1174,10 @@
     return false;
   }
 
-  // Always use clang for precompiling and AST generation, regardless of archs.
-  if (isa<PrecompileJobAction>(JA) || JA.getType() == types::TY_AST)
+  // Always use clang for precompiling, AST generation, and rewriting,
+  // regardless of archs.
+  if (isa<PrecompileJobAction>(JA) || JA.getType() == types::TY_AST ||
+      JA.getType() == types::TY_RewrittenObjC)
     return true;
 
   // Finally, don't use clang if this isn't one of the user specified archs to

Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=95849&r1=95848&r2=95849&view=diff

==============================================================================
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Wed Feb 10 21:16:21 2010
@@ -676,6 +676,11 @@
       CmdArgs.push_back("-S");
     } else if (JA.getType() == types::TY_AST) {
       CmdArgs.push_back("-emit-pch");
+    } else if (JA.getType() == types::TY_RewrittenObjC) {
+      CmdArgs.push_back("-rewrite-objc");
+    } else {
+      assert(JA.getType() == types::TY_PP_Asm &&
+             "Unexpected output type!");
     }
   }
 
@@ -1325,11 +1330,18 @@
 
 void gcc::Compile::RenderExtraToolArgs(const JobAction &JA,
                                        ArgStringList &CmdArgs) const {
+  const Driver &D = getToolChain().getDriver();
+
   // If -flto, etc. are present then make sure not to force assembly output.
   if (JA.getType() == types::TY_LLVMBC)
     CmdArgs.push_back("-c");
-  else
+  else {
+    if (JA.getType() != types::TY_PP_Asm)
+      D.Diag(clang::diag::err_drv_invalid_gcc_output_type)
+        << getTypeName(JA.getType());
+      
     CmdArgs.push_back("-S");
+  }
 }
 
 void gcc::Assemble::RenderExtraToolArgs(const JobAction &JA,
@@ -1734,6 +1746,9 @@
   else if (Output.getType() == types::TY_AST)
     D.Diag(clang::diag::err_drv_no_ast_support)
       << getToolChain().getTripleString();
+  else if (JA.getType() != types::TY_PP_Asm)
+    D.Diag(clang::diag::err_drv_invalid_gcc_output_type)
+      << getTypeName(JA.getType());
 
   ArgStringList OutputArgs;
   if (Output.getType() != types::TY_PCH) {

Added: cfe/trunk/test/Driver/rewrite-objc.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/rewrite-objc.m?rev=95849&view=auto

==============================================================================
--- cfe/trunk/test/Driver/rewrite-objc.m (added)
+++ cfe/trunk/test/Driver/rewrite-objc.m Wed Feb 10 21:16:21 2010
@@ -0,0 +1,11 @@
+// RUN: %clang -ccc-host-triple unknown -rewrite-objc %s -o - -### 2>&1 | \
+// RUN:   FileCheck -check-prefix=TEST0 %s
+// TEST0: clang{{.*}}" "-rewrite-objc"
+
+// RUN: not %clang -ccc-no-clang -ccc-host-triple unknown -rewrite-objc %s -o - -### 2>&1 | \
+// RUN:   FileCheck -check-prefix=TEST1 %s
+// TEST1: invalid output type 'rewritten-objc' for use with gcc
+
+// RUN: not %clang -ccc-no-clang -ccc-host-triple i386-apple-darwin10 -rewrite-objc %s -o - -### 2>&1 | \
+// RUN:   FileCheck -check-prefix=TEST2 %s
+// TEST2: invalid output type 'rewritten-objc' for use with gcc





More information about the cfe-commits mailing list