[llvm-rc] Add rudimentary support for codepages
Only support UTF-8 (since LLVM contains UTF-8 parsing support
already, and the code even does that already) and Windows-1252
(where most code points has the same value in unicode). Keep the
existing default as only allowing ASCII input.
Using the option type JoinedOrSeparate, since the real rc.exe
handles options in this form, even if llvm-rc uses Separate for
other similar existing options.
Rename the struct SearchParams to WriterParams since it's now used
for more than just include paths.
Add a missing getResourceTypeName method to the BundleResource class,
to fix error printing from within STRINGTABLE resources (used in
tests).
Differential Revision: https://reviews.llvm.org/D46238
llvm-svn: 331391
diff --git a/llvm/test/tools/llvm-rc/Inputs/cp1252.rc b/llvm/test/tools/llvm-rc/Inputs/cp1252.rc
new file mode 100644
index 0000000..f1dd948
--- /dev/null
+++ b/llvm/test/tools/llvm-rc/Inputs/cp1252.rc
@@ -0,0 +1,4 @@
+STRINGTABLE {
+ 1 "åäö © \xe5\xe4\366 \251 \x83"
+ 2 L"åäö © \xe5\xe4\366 \251 \x0192"
+}
diff --git a/llvm/test/tools/llvm-rc/Inputs/utf8-escape-narrow.rc b/llvm/test/tools/llvm-rc/Inputs/utf8-escape-narrow.rc
new file mode 100644
index 0000000..311968c
--- /dev/null
+++ b/llvm/test/tools/llvm-rc/Inputs/utf8-escape-narrow.rc
@@ -0,0 +1,5 @@
+STRINGTABLE {
+ // One can't pass UTF-8 sequences via multiple escaped chars - in narrow
+ // strings in UTF-8 mode, only ASCII chars can be entered via escapes.
+ 1 "åäö \xc3\xa5"
+}
diff --git a/llvm/test/tools/llvm-rc/Inputs/utf8.rc b/llvm/test/tools/llvm-rc/Inputs/utf8.rc
new file mode 100644
index 0000000..20ef991
--- /dev/null
+++ b/llvm/test/tools/llvm-rc/Inputs/utf8.rc
@@ -0,0 +1,6 @@
+STRINGTABLE {
+ // One can't pass UTF-8 sequences via multiple escaped chars - in narrow
+ // strings in UTF-8 mode, only ASCII chars can be entered via escapes.
+ 1 "åäö © \x61"
+ 2 L"åäö © \xe5\xe4\366 \251"
+}
diff --git a/llvm/test/tools/llvm-rc/codepage.test b/llvm/test/tools/llvm-rc/codepage.test
new file mode 100644
index 0000000..ce17e0a
--- /dev/null
+++ b/llvm/test/tools/llvm-rc/codepage.test
@@ -0,0 +1,44 @@
+; RUN: llvm-rc /C 65001 /FO %t.utf8.res %p/Inputs/utf8.rc
+; RUN: llvm-readobj %t.utf8.res | FileCheck %s --check-prefix=UTF8
+
+; UTF8: Resource type (int): 6
+; UTF8-NEXT: Resource name (int): 1
+; UTF8-NEXT: Data version: 0
+; UTF8-NEXT: Memory flags: 0x1030
+; UTF8-NEXT: Language ID: 1033
+; UTF8-NEXT: Version (major): 0
+; UTF8-NEXT: Version (minor): 0
+; UTF8-NEXT: Characteristics: 0
+; UTF8-NEXT: Data size: 68
+; UTF8-NEXT: Data: (
+; UTF8-NEXT: 0000: 00000700 E500E400 F6002000 A9002000 |.......... ... .|
+; UTF8-NEXT: 0010: 61000B00 E500E400 F6002000 A9002000 |a......... ... .|
+; UTF8-NEXT: 0020: E500E400 F6002000 A9000000 00000000 |...... .........|
+; UTF8-NEXT: 0030: 00000000 00000000 00000000 00000000 |................|
+; UTF8-NEXT: 0040: 00000000 |....|
+; UTF8-NEXT: )
+
+; RUN: not llvm-rc /C 65001 /FO %t.utf8-escape-narrow.res %p/Inputs/utf8-escape-narrow.rc 2>&1 | FileCheck %s --check-prefix UTF8_ESCAPE
+; UTF8_ESCAPE: llvm-rc: Error in STRINGTABLE statement (ID 1):
+; UTF8_ESCAPE-NEXT: Unable to interpret single byte (195) as UTF-8
+
+; RUN: llvm-rc /C 1252 /FO %t.cp1252.res %p/Inputs/cp1252.rc
+; RUN: llvm-readobj %t.cp1252.res | FileCheck %s --check-prefix=CP1252
+
+; CP1252: Resource type (int): 6
+; CP1252-NEXT: Resource name (int): 1
+; CP1252-NEXT: Data version: 0
+; CP1252-NEXT: Memory flags: 0x1030
+; CP1252-NEXT: Language ID: 1033
+; CP1252-NEXT: Version (major): 0
+; CP1252-NEXT: Version (minor): 0
+; CP1252-NEXT: Characteristics: 0
+; CP1252-NEXT: Data size: 92
+; CP1252-NEXT: Data: (
+; CP1252-NEXT: 0000: 00000F00 E500E400 F6002000 A9002000 |.......... ... .|
+; CP1252-NEXT: 0010: 92012000 E500E400 F6002000 A9002000 |.. ....... ... .|
+; CP1252-NEXT: 0020: 92010F00 E500E400 F6002000 A9002000 |.......... ... .|
+; CP1252-NEXT: 0030: 92012000 E500E400 F6002000 A9002000 |.. ....... ... .|
+; CP1252-NEXT: 0040: 92010000 00000000 00000000 00000000 |................|
+; CP1252-NEXT: 0050: 00000000 00000000 00000000 |............|
+; CP1252-NEXT: )
diff --git a/llvm/test/tools/llvm-rc/helpmsg.test b/llvm/test/tools/llvm-rc/helpmsg.test
index 2c2814a..e91d636 100644
--- a/llvm/test/tools/llvm-rc/helpmsg.test
+++ b/llvm/test/tools/llvm-rc/helpmsg.test
@@ -7,6 +7,7 @@
; CHECK-DAG: USAGE: rc [options] <inputs>
; CHECK-DAG: OPTIONS:
; CHECK-NEXT: /? Display this help and exit.
+; CHECK-NEXT: /C <value> Set the codepage used for input strings.
; CHECK-NEXT: /dry-run Don't compile the input; only try to parse it.
; CHECK-NEXT: /D <value> Define a symbol for the C preprocessor.
; CHECK-NEXT: /FO <value> Change the output file location.