[llvm] r308940 - Add an empty shell of llvm-rc.

Marek Sokolowski via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 24 17:25:18 PDT 2017


Author: mnbvmar
Date: Mon Jul 24 17:25:18 2017
New Revision: 308940

URL: http://llvm.org/viewvc/llvm-project?rev=308940&view=rev
Log:
Add an empty shell of llvm-rc.

This starts the development on one of MS Visual Studio binutils,
Resource Converter. The tool compiles resource scripts (.rc)
into binary resource files (.res).

The current implementation does nothing but parse the command
line arguments. It is going to be extended in the future.

Differential Revision: https://reviews.llvm.org/D35810

Added:
    llvm/trunk/test/tools/llvm-rc/
    llvm/trunk/test/tools/llvm-rc/helpmsg.test
    llvm/trunk/tools/llvm-rc/
    llvm/trunk/tools/llvm-rc/CMakeLists.txt
    llvm/trunk/tools/llvm-rc/LLVMBuild.txt
    llvm/trunk/tools/llvm-rc/Opts.td
    llvm/trunk/tools/llvm-rc/llvm-rc.cpp
Modified:
    llvm/trunk/tools/LLVMBuild.txt

Added: llvm/trunk/test/tools/llvm-rc/helpmsg.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-rc/helpmsg.test?rev=308940&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-rc/helpmsg.test (added)
+++ llvm/trunk/test/tools/llvm-rc/helpmsg.test Mon Jul 24 17:25:18 2017
@@ -0,0 +1,20 @@
+; RUN: llvm-rc /h > %t1
+; RUN: llvm-rc /? > %t2
+; RUN: diff %t1 %t2
+; RUN: FileCheck -input-file=%t1 %s
+
+; CHECK:  OVERVIEW: Resource Converter
+; CHECK-DAG:  USAGE: rc [options] <inputs>
+; CHECK-DAG:  OPTIONS:
+; CHECK-NEXT:    /?          Display this help and exit.
+; CHECK-NEXT:    /D <value>  Define a symbol for the C preprocessor.
+; CHECK-NEXT:    /FO <value> Change the output file location.
+; CHECK-NEXT:    /H          Display this help and exit.
+; CHECK-NEXT:    /I <value>  Add an include path.
+; CHECK-NEXT:    /LN <value> Set the default language name.
+; CHECK-NEXT:    /L <value>  Set the default language identifier.
+; CHECK-NEXT:    /N          Null-terminate all strings in the string table.
+; CHECK-NEXT:    /U <value>  Undefine a symbol for the C preprocessor.
+; CHECK-NEXT:    /V          Be verbose.
+; CHECK-NEXT:    /X          Ignore 'include' variable.
+; CHECK-NEXT:    /Y          Suppress warnings on duplicate resource IDs.

Modified: llvm/trunk/tools/LLVMBuild.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/LLVMBuild.txt?rev=308940&r1=308939&r2=308940&view=diff
==============================================================================
--- llvm/trunk/tools/LLVMBuild.txt (original)
+++ llvm/trunk/tools/LLVMBuild.txt Mon Jul 24 17:25:18 2017
@@ -43,6 +43,7 @@ subdirectories =
  llvm-objdump
  llvm-pdbutil
  llvm-profdata
+ llvm-rc
  llvm-rtdyld
  llvm-size
  llvm-split

Added: llvm/trunk/tools/llvm-rc/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-rc/CMakeLists.txt?rev=308940&view=auto
==============================================================================
--- llvm/trunk/tools/llvm-rc/CMakeLists.txt (added)
+++ llvm/trunk/tools/llvm-rc/CMakeLists.txt Mon Jul 24 17:25:18 2017
@@ -0,0 +1,12 @@
+set(LLVM_LINK_COMPONENTS
+  Option
+  )
+
+set(LLVM_TARGET_DEFINITIONS Opts.td)
+
+tablegen(LLVM Opts.inc -gen-opt-parser-defs)
+add_public_tablegen_target(RcTableGen)
+
+add_llvm_tool(llvm-rc
+  llvm-rc.cpp
+  )

Added: llvm/trunk/tools/llvm-rc/LLVMBuild.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-rc/LLVMBuild.txt?rev=308940&view=auto
==============================================================================
--- llvm/trunk/tools/llvm-rc/LLVMBuild.txt (added)
+++ llvm/trunk/tools/llvm-rc/LLVMBuild.txt Mon Jul 24 17:25:18 2017
@@ -0,0 +1,22 @@
+;===- ./tools/llvm-rc/LLVMBuild.txt ----------------------------*- Conf -*--===;
+;
+;                     The LLVM Compiler Infrastructure
+;
+; This file is distributed under the University of Illinois Open Source
+; License. See LICENSE.TXT for details.
+;
+;===------------------------------------------------------------------------===;
+;
+; This is an LLVMBuild description file for the components in this subdirectory.
+;
+; For more information on the LLVMBuild system, please see:
+;
+;   http://llvm.org/docs/LLVMBuild.html
+;
+;===------------------------------------------------------------------------===;
+
+[component_0]
+type = Tool
+name = llvm-rc
+parent = Tools
+required_libraries = Option

Added: llvm/trunk/tools/llvm-rc/Opts.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-rc/Opts.td?rev=308940&view=auto
==============================================================================
--- llvm/trunk/tools/llvm-rc/Opts.td (added)
+++ llvm/trunk/tools/llvm-rc/Opts.td Mon Jul 24 17:25:18 2017
@@ -0,0 +1,53 @@
+include "llvm/Option/OptParser.td"
+
+// All the switches can be preceded by either '/' or '-'.
+// These options seem to be important for the tool
+// and should be implemented.
+
+def FILEOUT : Separate<[ "/", "-" ], "FO">,
+              HelpText<"Change the output file location.">;
+
+def DEFINE : Separate<[ "/", "-" ], "D">,
+             HelpText<"Define a symbol for the C preprocessor.">;
+def UNDEF : Separate<[ "/", "-" ], "U">,
+            HelpText<"Undefine a symbol for the C preprocessor.">;
+
+def LANG_ID : Separate<[ "/", "-" ], "L">,
+              HelpText<"Set the default language identifier.">;
+def LANG_NAME : Separate<[ "/", "-" ], "LN">,
+                HelpText<"Set the default language name.">;
+
+def INCLUDE : Separate<[ "/", "-" ], "I">, HelpText<"Add an include path.">;
+def NOINCLUDE : Flag<[ "/", "-" ], "X">, HelpText<"Ignore 'include' variable.">;
+
+def ADD_NULL : Flag<[ "/", "-" ], "N">,
+               HelpText<"Null-terminate all strings in the string table.">;
+
+def DUPID_NOWARN : Flag<[ "/", "-" ], "Y">,
+                   HelpText<"Suppress warnings on duplicate resource IDs.">;
+
+def VERBOSE : Flag<[ "/", "-" ], "V">, HelpText<"Be verbose.">;
+def HELP : Flag<[ "/", "-" ], "?">, HelpText<"Display this help and exit.">;
+def H : Flag<[ "/", "-" ], "H">,
+        Alias<HELP>,
+        HelpText<"Display this help and exit.">;
+
+// Unused switches (at least for now). These will stay unimplemented
+// in an early stage of development and can be ignored. However, we need to
+// parse them in order to preserve the compatibility with the original tool.
+
+def NOLOGO : Flag<[ "/", "-" ], "NOLOGO">;
+def R : Flag<[ "/", "-" ], "R">;
+def SL : Flag<[ "/", "-" ], "SL">;
+
+// (Codepages support.)
+def C : Flag<[ "/", "-" ], "C">;
+def W : Flag<[ "/", "-" ], "W">;
+
+// (Support of MUI and similar.)
+def FM : Separate<[ "/", "-" ], "FM">;
+def Q : Separate<[ "/", "-" ], "Q">;
+def G : Flag<[ "/", "-" ], "G">;
+def GN : Flag<[ "/", "-" ], "GN">;
+def G1 : Flag<[ "/", "-" ], "G1">;
+def G2 : Flag<[ "/", "-" ], "G2">;

Added: llvm/trunk/tools/llvm-rc/llvm-rc.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-rc/llvm-rc.cpp?rev=308940&view=auto
==============================================================================
--- llvm/trunk/tools/llvm-rc/llvm-rc.cpp (added)
+++ llvm/trunk/tools/llvm-rc/llvm-rc.cpp Mon Jul 24 17:25:18 2017
@@ -0,0 +1,88 @@
+//===- llvm-rc.cpp - Compile .rc scripts into .res -------------*- C++ -*--===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// Compile .rc scripts into .res files. This is intended to be a
+// platform-independent port of Microsoft's rc.exe tool.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/Option/Arg.h"
+#include "llvm/Option/ArgList.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/ManagedStatic.h"
+#include "llvm/Support/PrettyStackTrace.h"
+#include "llvm/Support/Process.h"
+#include "llvm/Support/Signals.h"
+#include "llvm/Support/raw_ostream.h"
+
+#include <system_error>
+
+using namespace llvm;
+
+namespace {
+
+// Input options tables.
+
+enum ID {
+  OPT_INVALID = 0, // This is not a correct option ID.
+#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,  \
+               HELPTEXT, METAVAR, VALUES)                                      \
+  OPT_##ID,
+#include "Opts.inc"
+#undef OPTION
+};
+
+#define PREFIX(NAME, VALUE) const char *const NAME[] = VALUE;
+#include "Opts.inc"
+#undef PREFIX
+
+static const opt::OptTable::Info InfoTable[] = {
+#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,  \
+               HELPTEXT, METAVAR, VALUES)                                      \
+  {                                                                            \
+      PREFIX,      NAME,      HELPTEXT,                                        \
+      METAVAR,     OPT_##ID,  opt::Option::KIND##Class,                        \
+      PARAM,       FLAGS,     OPT_##GROUP,                                     \
+      OPT_##ALIAS, ALIASARGS, VALUES},
+#include "Opts.inc"
+#undef OPTION
+};
+
+class RcOptTable : public opt::OptTable {
+public:
+  RcOptTable() : OptTable(InfoTable, /* IgnoreCase = */ true) {}
+};
+
+static ExitOnError ExitOnErr;
+} // anonymous namespace
+
+int main(int argc_, const char *argv_[]) {
+  sys::PrintStackTraceOnErrorSignal(argv_[0]);
+  PrettyStackTraceProgram X(argc_, argv_);
+
+  ExitOnErr.setBanner("llvm-rc: ");
+
+  SmallVector<const char *, 256> argv;
+  SpecificBumpPtrAllocator<char> ArgAllocator;
+  ExitOnErr(errorCodeToError(sys::Process::GetArgumentVector(
+      argv, makeArrayRef(argv_, argc_), ArgAllocator)));
+
+  llvm_shutdown_obj Y;
+
+  RcOptTable T;
+  unsigned MAI, MAC;
+  ArrayRef<const char *> ArgsArr = makeArrayRef(argv_ + 1, argc_);
+  opt::InputArgList InputArgs = T.ParseArgs(ArgsArr, MAI, MAC);
+
+  // The tool prints nothing when invoked with no command-line arguments.
+  if (InputArgs.hasArg(OPT_HELP))
+    T.PrintHelp(outs(), "rc", "Resource Converter", false);
+
+  return 0;
+}




More information about the llvm-commits mailing list