diff options
author | Zachary Turner <zturner@google.com> | 2017-10-06 21:52:15 +0000 |
---|---|---|
committer | Zachary Turner <zturner@google.com> | 2017-10-06 21:52:15 +0000 |
commit | 9d8b358a49bec7cbd225062962d7959854d04338 (patch) | |
tree | 0ad67c49d228aa0624cb8c1f0cc7fadb976806d3 /llvm/tools/llvm-rc/ResourceFileWriter.cpp | |
parent | accab5908d4137f8e49ae653d14d37ea46132f28 (diff) | |
download | bcm5719-llvm-9d8b358a49bec7cbd225062962d7959854d04338.tar.gz bcm5719-llvm-9d8b358a49bec7cbd225062962d7959854d04338.zip |
[llvm-rc] Serialize user-defined resources to .res files.
This allows rc to serialize user-defined resources, as
documented at:
msdn.microsoft.com/en-us/library/windows/desktop/aa381054.aspx
Escape sequences are yet unavailable, and are to be added in one of
child patches.
Patch by: Marek Sokolowski
Differential Revision: https://reviews.llvm.org/D38423
llvm-svn: 315117
Diffstat (limited to 'llvm/tools/llvm-rc/ResourceFileWriter.cpp')
-rw-r--r-- | llvm/tools/llvm-rc/ResourceFileWriter.cpp | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/llvm/tools/llvm-rc/ResourceFileWriter.cpp b/llvm/tools/llvm-rc/ResourceFileWriter.cpp index f41ffcc8ac5..1d23fb966f6 100644 --- a/llvm/tools/llvm-rc/ResourceFileWriter.cpp +++ b/llvm/tools/llvm-rc/ResourceFileWriter.cpp @@ -298,6 +298,10 @@ Error ResourceFileWriter::visitStringTableResource(const RCResource *Base) { return Error::success(); } +Error ResourceFileWriter::visitUserDefinedResource(const RCResource *Res) { + return writeResource(Res, &ResourceFileWriter::writeUserDefinedBody); +} + Error ResourceFileWriter::visitVersionInfoResource(const RCResource *Res) { return writeResource(Res, &ResourceFileWriter::writeVersionInfoBody); } @@ -1048,6 +1052,43 @@ Error ResourceFileWriter::dumpAllStringTables() { return Error::success(); } +// --- UserDefinedResource helpers. --- // + +Error ResourceFileWriter::writeUserDefinedBody(const RCResource *Base) { + auto *Res = cast<UserDefinedResource>(Base); + + if (Res->IsFileResource) + return appendFile(Res->FileLoc); + + for (auto &Elem : Res->Contents) { + if (Elem.isInt()) { + RETURN_IF_ERROR( + checkRCInt(Elem.getInt(), "Number in user-defined resource")); + writeRCInt(Elem.getInt()); + continue; + } + + SmallVector<UTF16, 128> ProcessedString; + bool IsLongString; + RETURN_IF_ERROR(processString(Elem.getString(), + NullHandlingMethod::UserResource, + IsLongString, ProcessedString)); + + for (auto Ch : ProcessedString) { + if (IsLongString) { + writeObject(ulittle16_t(Ch)); + continue; + } + + RETURN_IF_ERROR(checkNumberFits<uint8_t>( + Ch, "Character in narrow string in user-defined resoutce")); + writeObject(uint8_t(Ch)); + } + } + + return Error::success(); +} + // --- VersionInfoResourceResource helpers. --- // Error ResourceFileWriter::writeVersionInfoBlock(const VersionInfoBlock &Blk) { |