aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2010-05-20 18:15:20 +0000
committerDaniel Dunbar <daniel@zuster.org>2010-05-20 18:15:20 +0000
commitc673af7fe67e5db4d10dd414237df247d35dd9d9 (patch)
tree7bb0a7e3ad2f2550087cc150f147640e38f335ce
parent41b5b17445ab3bdf957ebd4be6c8670f09a212a8 (diff)
clang -cc1as: Add -help, -version, and -mllvm support.
Also, fix output defaulting to match llvm-mc. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@104246 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/Driver/CC1AsOptions.td13
-rw-r--r--tools/driver/cc1as_main.cpp40
2 files changed, 52 insertions, 1 deletions
diff --git a/include/clang/Driver/CC1AsOptions.td b/include/clang/Driver/CC1AsOptions.td
index 18b2d69541..5c08dc6305 100644
--- a/include/clang/Driver/CC1AsOptions.td
+++ b/include/clang/Driver/CC1AsOptions.td
@@ -39,6 +39,19 @@ def o : Separate<"-o">, MetaVarName<"<path>">, HelpText<"Specify output file">;
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
//===----------------------------------------------------------------------===//
diff --git a/tools/driver/cc1as_main.cpp b/tools/driver/cc1as_main.cpp
index 742a484438..5f1ee092ba 100644
--- a/tools/driver/cc1as_main.cpp
+++ b/tools/driver/cc1as_main.cpp
@@ -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 @@ struct AssemblerInvocation {
/// @{
std::string InputFile;
+ std::vector<std::string> LLVMArgs;
std::string OutputPath;
enum FileType {
FT_Asm, ///< Assembly (.s) output, transliterate mode.
@@ -77,6 +79,8 @@ struct AssemblerInvocation {
FT_Obj ///< Object file output.
};
FileType OutputType;
+ unsigned ShowHelp : 1;
+ unsigned ShowVersion : 1;
/// @}
/// @name Transliterate Options
@@ -99,7 +103,7 @@ public:
Triple = "";
NoInitialTextSection = 0;
InputFile = "-";
- OutputPath = "a.out";
+ OutputPath = "-";
OutputType = FT_Asm;
OutputAsmVariant = 0;
ShowInst = 0;
@@ -156,6 +160,7 @@ void AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts,
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 @@ void AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts,
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 @@ void AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts,
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 @@ int cc1as_main(const char **ArgBegin, const char **ArgEnd,
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())