================
@@ -106,39 +159,27 @@ class OffloadBinary : public Binary {
 
   static bool classof(const Binary *V) { return V->isOffloadFile(); }
 
-  struct Header {
-    uint8_t Magic[4] = {0x10, 0xFF, 0x10, 0xAD}; // 0x10FF10AD magic bytes.
-    uint32_t Version = OffloadBinary::Version;   // Version identifier.
-    uint64_t Size;        // Size in bytes of this entire binary.
-    uint64_t EntryOffset; // Offset of the metadata entry in bytes.
-    uint64_t EntrySize;   // Size of the metadata entry in bytes.
-  };
-
-  struct Entry {
-    ImageKind TheImageKind;     // The kind of the image stored.
-    OffloadKind TheOffloadKind; // The producer of this image.
-    uint32_t Flags;             // Additional flags associated with the image.
-    uint64_t StringOffset;      // Offset in bytes to the string map.
-    uint64_t NumStrings;        // Number of entries in the string map.
-    uint64_t ImageOffset;       // Offset in bytes of the actual binary image.
-    uint64_t ImageSize;         // Size in bytes of the binary image.
-  };
-
-  struct StringEntry {
-    uint64_t KeyOffset;
-    uint64_t ValueOffset;
-  };
-
 private:
   OffloadBinary(MemoryBufferRef Source, const Header *TheHeader,
-                const Entry *TheEntry)
+                const Entry *TheEntry, const uint64_t Index = 0)
       : Binary(Binary::ID_Offload, Source), Buffer(Source.getBufferStart()),
-        TheHeader(TheHeader), TheEntry(TheEntry) {
+        TheHeader(TheHeader), TheEntry(TheEntry), Index(Index) {
+    if (TheHeader->Version == 1) {
+      const StringEntryV1 *StringMapBegin =
+          reinterpret_cast<const StringEntryV1 *>(
+              &Buffer[TheEntry->StringOffset]);
+      for (uint64_t I = 0, E = TheEntry->NumStrings; I != E; ++I) {
----------------
jhuber6 wrote:

Could we unify these loops? The value offset and key offset are ABI compatible, 
we only need to check the version for whether or not we get the size from 
`ValueSize` through a longer struct or just `strlen`.

https://github.com/llvm/llvm-project/pull/169425
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to