[PATCH] D127774: [Binary] Add iterator to the OffloadBinary string maps
Joseph Huber via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 14 12:39:33 PDT 2022
jhuber6 created this revision.
jhuber6 added reviewers: jdoerfert, tra, yaxunl, JonChesterfield.
Herald added a project: All.
jhuber6 requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
The offload binary contains internally a string map of all the key and
value pairs identified in the binary itself. Normally users query these
values from the `getString` function, but this makes it difficult to
identify which strings are availible. This patch adds a simple const
iterator range to the offload binary allowing users to iterate through
the strings.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D127774
Files:
llvm/include/llvm/Object/OffloadBinary.h
Index: llvm/include/llvm/Object/OffloadBinary.h
===================================================================
--- llvm/include/llvm/Object/OffloadBinary.h
+++ llvm/include/llvm/Object/OffloadBinary.h
@@ -58,6 +58,13 @@
/// that may exist in the same section. All offsets are given as absolute byte
/// offsets from the beginning of the file.
class OffloadBinary : public Binary {
+
+ using string_iterator = StringMap<StringRef>::const_iterator;
+ using string_iterator_range = iterator_range<string_iterator>;
+
+ string_iterator data_begin() const { return StringData.begin(); }
+ string_iterator data_end() const { return StringData.end(); }
+
public:
/// The offloading metadata that will be serialized to a memory buffer.
struct OffloadingImage {
@@ -88,6 +95,11 @@
return StringRef(&Buffer[TheEntry->ImageOffset], TheEntry->ImageSize);
}
+ // Iterator over all the key and value pairs in the binary.
+ string_iterator_range strings() const {
+ return string_iterator_range(data_begin(), data_end());
+ }
+
StringRef getString(StringRef Key) const { return StringData.lookup(Key); }
static bool classof(const Binary *V) { return V->isOffloadFile(); }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D127774.436892.patch
Type: text/x-patch
Size: 1200 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220614/1d1169ee/attachment.bin>
More information about the llvm-commits
mailing list