From 601ec17d547bf2dc03565b541bae8ec069fbd22b Mon Sep 17 00:00:00 2001 From: Joseph Huber Date: Tue, 14 Jun 2022 14:33:32 -0400 Subject: [PATCH] [Binary] Add iterator to the OffloadBinary string maps 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. Reviewed By: tra Differential Revision: https://reviews.llvm.org/D127774 --- llvm/include/llvm/Object/OffloadBinary.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/llvm/include/llvm/Object/OffloadBinary.h b/llvm/include/llvm/Object/OffloadBinary.h index 3ff82ec..446d523 100644 --- a/llvm/include/llvm/Object/OffloadBinary.h +++ b/llvm/include/llvm/Object/OffloadBinary.h @@ -59,6 +59,9 @@ enum ImageKind : uint16_t { /// offsets from the beginning of the file. class OffloadBinary : public Binary { public: + using string_iterator = StringMap::const_iterator; + using string_iterator_range = iterator_range; + /// The offloading metadata that will be serialized to a memory buffer. struct OffloadingImage { ImageKind TheImageKind; @@ -88,6 +91,11 @@ public: 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(StringData.begin(), StringData.end()); + } + StringRef getString(StringRef Key) const { return StringData.lookup(Key); } static bool classof(const Binary *V) { return V->isOffloadFile(); } -- 2.7.4