summaryrefslogtreecommitdiffstats
path: root/llvm/tools
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/tools')
-rw-r--r--llvm/tools/llvm-rc/ResourceFileWriter.cpp41
-rw-r--r--llvm/tools/llvm-rc/ResourceFileWriter.h4
-rw-r--r--llvm/tools/llvm-rc/ResourceScriptStmt.h13
-rw-r--r--llvm/tools/llvm-rc/ResourceVisitor.h1
4 files changed, 58 insertions, 1 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) {
diff --git a/llvm/tools/llvm-rc/ResourceFileWriter.h b/llvm/tools/llvm-rc/ResourceFileWriter.h
index 905f56f5381..b4427160711 100644
--- a/llvm/tools/llvm-rc/ResourceFileWriter.h
+++ b/llvm/tools/llvm-rc/ResourceFileWriter.h
@@ -38,6 +38,7 @@ public:
Error visitMenuResource(const RCResource *) override;
Error visitVersionInfoResource(const RCResource *) override;
Error visitStringTableResource(const RCResource *) override;
+ Error visitUserDefinedResource(const RCResource *) override;
Error visitCaptionStmt(const CaptionStmt *) override;
Error visitCharacteristicsStmt(const CharacteristicsStmt *) override;
@@ -127,6 +128,9 @@ private:
Error insertStringIntoBundle(StringTableInfo::Bundle &Bundle,
uint16_t StringID, StringRef String);
+ // User defined resource
+ Error writeUserDefinedBody(const RCResource *);
+
// VersionInfoResource
Error writeVersionInfoBody(const RCResource *);
Error writeVersionInfoBlock(const VersionInfoBlock &);
diff --git a/llvm/tools/llvm-rc/ResourceScriptStmt.h b/llvm/tools/llvm-rc/ResourceScriptStmt.h
index 915d4f108b5..e44120b770f 100644
--- a/llvm/tools/llvm-rc/ResourceScriptStmt.h
+++ b/llvm/tools/llvm-rc/ResourceScriptStmt.h
@@ -591,18 +591,29 @@ public:
// * a link to the file, e.g. NAME TYPE "filename",
// * or contains a list of integers and strings, e.g. NAME TYPE {1, "a", 2}.
class UserDefinedResource : public RCResource {
+public:
IntOrString Type;
StringRef FileLoc;
std::vector<IntOrString> Contents;
bool IsFileResource;
-public:
UserDefinedResource(IntOrString ResourceType, StringRef FileLocation)
: Type(ResourceType), FileLoc(FileLocation), IsFileResource(true) {}
UserDefinedResource(IntOrString ResourceType, std::vector<IntOrString> &&Data)
: Type(ResourceType), Contents(std::move(Data)), IsFileResource(false) {}
raw_ostream &log(raw_ostream &) const override;
+ IntOrString getResourceType() const override { return Type; }
+ Twine getResourceTypeName() const override { return Type; }
+ uint16_t getMemoryFlags() const override { return MfPure | MfMoveable; }
+
+ Error visit(Visitor *V) const override {
+ return V->visitUserDefinedResource(this);
+ }
+ ResourceKind getKind() const override { return RkUser; }
+ static bool classof(const RCResource *Res) {
+ return Res->getKind() == RkUser;
+ }
};
// -- VERSIONINFO resource and its helper classes --
diff --git a/llvm/tools/llvm-rc/ResourceVisitor.h b/llvm/tools/llvm-rc/ResourceVisitor.h
index 328200bc00f..530b4a8add2 100644
--- a/llvm/tools/llvm-rc/ResourceVisitor.h
+++ b/llvm/tools/llvm-rc/ResourceVisitor.h
@@ -38,6 +38,7 @@ public:
virtual Error visitIconResource(const RCResource *) = 0;
virtual Error visitMenuResource(const RCResource *) = 0;
virtual Error visitStringTableResource(const RCResource *) = 0;
+ virtual Error visitUserDefinedResource(const RCResource *) = 0;
virtual Error visitVersionInfoResource(const RCResource *) = 0;
virtual Error visitCaptionStmt(const CaptionStmt *) = 0;
OpenPOWER on IntegriCloud