[llvm] f36f8b4 - [llvm-rc] Implement the language id option

Martin Storsjö via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 23 01:14:16 PDT 2020


Author: Martin Storsjö
Date: 2020-06-23T11:14:07+03:00
New Revision: f36f8b41beb9cc0353d5624934406d39b78753e0

URL: https://github.com/llvm/llvm-project/commit/f36f8b41beb9cc0353d5624934406d39b78753e0
DIFF: https://github.com/llvm/llvm-project/commit/f36f8b41beb9cc0353d5624934406d39b78753e0.diff

LOG: [llvm-rc] Implement the language id option

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

Added: 
    llvm/test/tools/llvm-rc/Inputs/language.rc
    llvm/test/tools/llvm-rc/language.test

Modified: 
    llvm/tools/llvm-rc/Opts.td
    llvm/tools/llvm-rc/llvm-rc.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/test/tools/llvm-rc/Inputs/language.rc b/llvm/test/tools/llvm-rc/Inputs/language.rc
new file mode 100644
index 000000000000..caacdf0174ce
--- /dev/null
+++ b/llvm/test/tools/llvm-rc/Inputs/language.rc
@@ -0,0 +1,15 @@
+1 MENU
+LANGUAGE 1, 2
+{
+  MENUITEM "foo", 1
+}
+
+2 MENU {
+  MENUITEM "bar", 2
+}
+
+LANGUAGE 3, 4
+
+3 MENU {
+  MENUITEM "baz", 3
+}

diff  --git a/llvm/test/tools/llvm-rc/language.test b/llvm/test/tools/llvm-rc/language.test
new file mode 100644
index 000000000000..e764cde05e7b
--- /dev/null
+++ b/llvm/test/tools/llvm-rc/language.test
@@ -0,0 +1,19 @@
+; RUN: llvm-rc /l 40A /FO %t.res -- %p/Inputs/language.rc
+; RUN: llvm-readobj %t.res | FileCheck %s
+; RUN: llvm-rc /l40A /FO %t.res -- %p/Inputs/language.rc
+; RUN: llvm-readobj %t.res | FileCheck %s
+
+; CHECK:      Resource name (int): 1
+; CHECK-NEXT: Data version:
+; CHECK-NEXT: Memory flags:
+; CHECK-NEXT: Language ID: 2049
+
+; CHECK:      Resource name (int): 2
+; CHECK-NEXT: Data version:
+; CHECK-NEXT: Memory flags:
+; CHECK-NEXT: Language ID: 1034
+
+; CHECK:      Resource name (int): 3
+; CHECK-NEXT: Data version:
+; CHECK-NEXT: Memory flags:
+; CHECK-NEXT: Language ID: 4099

diff  --git a/llvm/tools/llvm-rc/Opts.td b/llvm/tools/llvm-rc/Opts.td
index 3ff5ac2d4980..873dd785b12b 100644
--- a/llvm/tools/llvm-rc/Opts.td
+++ b/llvm/tools/llvm-rc/Opts.td
@@ -12,7 +12,7 @@ def DEFINE : Separate<[ "/", "-" ], "D">,
 def UNDEF : Separate<[ "/", "-" ], "U">,
             HelpText<"Undefine a symbol for the C preprocessor.">;
 
-def LANG_ID : Separate<[ "/", "-" ], "L">,
+def LANG_ID : JoinedOrSeparate<[ "/", "-" ], "L">,
               HelpText<"Set the default language identifier.">;
 def LANG_NAME : Separate<[ "/", "-" ], "LN">,
                 HelpText<"Set the default language name.">;

diff  --git a/llvm/tools/llvm-rc/llvm-rc.cpp b/llvm/tools/llvm-rc/llvm-rc.cpp
index a09960de4185..71954804f255 100644
--- a/llvm/tools/llvm-rc/llvm-rc.cpp
+++ b/llvm/tools/llvm-rc/llvm-rc.cpp
@@ -187,7 +187,16 @@ int main(int Argc, const char **Argv) {
     ExitOnErr(NullResource().visit(Visitor.get()));
 
     // Set the default language; choose en-US arbitrarily.
-    ExitOnErr(LanguageResource(0x09, 0x01).visit(Visitor.get()));
+    unsigned PrimaryLangId = 0x09, SubLangId = 0x01;
+    if (InputArgs.hasArg(OPT_LANG_ID)) {
+      unsigned LangId;
+      if (InputArgs.getLastArgValue(OPT_LANG_ID).getAsInteger(16, LangId))
+        fatalError("Invalid language id: " +
+                   InputArgs.getLastArgValue(OPT_LANG_ID));
+      PrimaryLangId = LangId & 0x3ff;
+      SubLangId = LangId >> 10;
+    }
+    ExitOnErr(LanguageResource(PrimaryLangId, SubLangId).visit(Visitor.get()));
   }
 
   rc::RCParser Parser{std::move(Tokens)};


        


More information about the llvm-commits mailing list