forked from OSchip/llvm-project
[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
This commit is contained in:
parent
0c2edf27a2
commit
601ec17d54
|
@ -59,6 +59,9 @@ enum ImageKind : uint16_t {
|
|||
/// offsets from the beginning of the file.
|
||||
class OffloadBinary : public Binary {
|
||||
public:
|
||||
using string_iterator = StringMap<StringRef>::const_iterator;
|
||||
using string_iterator_range = iterator_range<string_iterator>;
|
||||
|
||||
/// 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(); }
|
||||
|
|
Loading…
Reference in New Issue