[cfe-commits] r104246 - in /cfe/trunk: include/clang/Driver/CC1AsOptions.td tools/driver/cc1as_main.cpp

Daniel Dunbar daniel at zuster.org
Thu May 20 11:15:20 PDT 2010


Author: ddunbar
Date: Thu May 20 13:15:20 2010
New Revision: 104246

URL: http://llvm.org/viewvc/llvm-project?rev=104246&view=rev
Log:
clang -cc1as: Add -help, -version, and -mllvm support.

Also, fix output defaulting to match llvm-mc.

Modified:
    cfe/trunk/include/clang/Driver/CC1AsOptions.td
    cfe/trunk/tools/driver/cc1as_main.cpp

Modified: cfe/trunk/include/clang/Driver/CC1AsOptions.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/CC1AsOptions.td?rev=104246&r1=104245&r2=104246&view=diff
==============================================================================
--- cfe/trunk/include/clang/Driver/CC1AsOptions.td (original)
+++ cfe/trunk/include/clang/Driver/CC1AsOptions.td Thu May 20 13:15:20 2010
@@ -39,6 +39,19 @@
 def filetype : Separate<"-filetype">,
     HelpText<"Specify the output file type ('asm', 'null', or 'obj')">;
 
+def help : Flag<"-help">,
+  HelpText<"Print this help text">;
+def _help : Flag<"--help">, Alias<help>;
+
+def version : Flag<"-version">,
+  HelpText<"Print the assembler version">;
+def _version : Flag<"--version">, Alias<version>;
+
+// Generic forwarding to LLVM options. This should only be used for debugging
+// and experimental features.
+def mllvm : Separate<"-mllvm">,
+  HelpText<"Additional arguments to forward to LLVM's option processing">;
+
 //===----------------------------------------------------------------------===//
 // Transliterate Options
 //===----------------------------------------------------------------------===//

Modified: cfe/trunk/tools/driver/cc1as_main.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/driver/cc1as_main.cpp?rev=104246&r1=104245&r2=104246&view=diff
==============================================================================
--- cfe/trunk/tools/driver/cc1as_main.cpp (original)
+++ cfe/trunk/tools/driver/cc1as_main.cpp Thu May 20 13:15:20 2010
@@ -28,6 +28,7 @@
 #include "llvm/MC/MCCodeEmitter.h"
 #include "llvm/MC/MCContext.h"
 #include "llvm/MC/MCStreamer.h"
+#include "llvm/Support/CommandLine.h"
 #include "llvm/Support/FormattedStream.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/ManagedStatic.h"
@@ -70,6 +71,7 @@
   /// @{
 
   std::string InputFile;
+  std::vector<std::string> LLVMArgs;
   std::string OutputPath;
   enum FileType {
     FT_Asm,  ///< Assembly (.s) output, transliterate mode.
@@ -77,6 +79,8 @@
     FT_Obj   ///< Object file output.
   };
   FileType OutputType;
+  unsigned ShowHelp : 1;
+  unsigned ShowVersion : 1;
 
   /// @}
   /// @name Transliterate Options
@@ -99,7 +103,7 @@
     Triple = "";
     NoInitialTextSection = 0;
     InputFile = "-";
-    OutputPath = "a.out";
+    OutputPath = "-";
     OutputType = FT_Asm;
     OutputAsmVariant = 0;
     ShowInst = 0;
@@ -156,6 +160,7 @@
         Diags.Report(diag::err_drv_unknown_argument) << it->getAsString(*Args);
     }
   }
+  Opts.LLVMArgs = Args->getAllArgValues(OPT_mllvm);
   Opts.OutputPath = Args->getLastArgValue(OPT_o);
   if (Arg *A = Args->getLastArg(OPT_filetype)) {
     StringRef Name = A->getValue(*Args);
@@ -170,6 +175,8 @@
     else
       Opts.OutputType = FileType(OutputType);
   }
+  Opts.ShowHelp = Args->hasArg(OPT_help);
+  Opts.ShowVersion = Args->hasArg(OPT_version);
 
   // Transliterate Options
   Opts.OutputAsmVariant = Args->getLastArgIntValue(OPT_output_asm_variant,
@@ -184,6 +191,9 @@
 static formatted_raw_ostream *GetOutputStream(AssemblerInvocation &Opts,
                                               Diagnostic &Diags,
                                               bool Binary) {
+  if (Opts.OutputPath.empty())
+    Opts.OutputPath = "-";
+
   // Make sure that the Out file gets unlinked from the disk if we get a
   // SIGINT.
   if (Opts.OutputPath != "-")
@@ -322,6 +332,34 @@
   AssemblerInvocation Asm;
   AssemblerInvocation::CreateFromArgs(Asm, ArgBegin, ArgEnd, Diags);
 
+  // Honor -help.
+  if (Asm.ShowHelp) {
+    llvm::OwningPtr<driver::OptTable> Opts(driver::createCC1AsOptTable());
+    Opts->PrintHelp(llvm::outs(), "clang -cc1as", "Clang Integrated Assembler");
+    return 0;
+  }
+
+  // Honor -version.
+  //
+  // FIXME: Use a better -version message?
+  if (Asm.ShowVersion) {
+    llvm::cl::PrintVersionMessage();
+    return 0;
+  }
+
+  // Honor -mllvm.
+  //
+  // FIXME: Remove this, one day.
+  if (!Asm.LLVMArgs.empty()) {
+    unsigned NumArgs = Asm.LLVMArgs.size();
+    const char **Args = new const char*[NumArgs + 2];
+    Args[0] = "clang (LLVM option parsing)";
+    for (unsigned i = 0; i != NumArgs; ++i)
+      Args[i + 1] = Asm.LLVMArgs[i].c_str();
+    Args[NumArgs + 1] = 0;
+    llvm::cl::ParseCommandLineOptions(NumArgs + 1, const_cast<char **>(Args));
+  }
+
   // Execute the invocation, unless there were parsing errors.
   bool Success = false;
   if (!Diags.getNumErrors())





More information about the cfe-commits mailing list