Derek Schuff | f2af060 | 2020-01-29 17:30:57 -0800 | [diff] [blame] | 1 | //===- Object.h -------------------------------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #ifndef LLVM_TOOLS_LLVM_OBJCOPY_WASM_OBJECT_H |
| 10 | #define LLVM_TOOLS_LLVM_OBJCOPY_WASM_OBJECT_H |
| 11 | |
| 12 | #include "llvm/ADT/ArrayRef.h" |
| 13 | #include "llvm/ADT/StringRef.h" |
| 14 | #include "llvm/Object/Wasm.h" |
Derek Schuff | b2c44de | 2020-02-11 15:13:40 -0800 | [diff] [blame] | 15 | #include "llvm/Support/MemoryBuffer.h" |
Derek Schuff | f2af060 | 2020-01-29 17:30:57 -0800 | [diff] [blame] | 16 | #include <vector> |
| 17 | |
| 18 | namespace llvm { |
| 19 | namespace objcopy { |
| 20 | namespace wasm { |
| 21 | |
| 22 | struct Section { |
| 23 | // For now, each section is only an opaque binary blob with no distinction |
| 24 | // between custom and known sections. |
| 25 | uint8_t SectionType; |
| 26 | StringRef Name; |
| 27 | ArrayRef<uint8_t> Contents; |
| 28 | }; |
| 29 | |
| 30 | struct Object { |
| 31 | llvm::wasm::WasmObjectHeader Header; |
| 32 | // For now don't discriminate between kinds of sections. |
| 33 | std::vector<Section> Sections; |
Derek Schuff | b2c44de | 2020-02-11 15:13:40 -0800 | [diff] [blame] | 34 | |
| 35 | void addSectionWithOwnedContents(Section NewSection, |
| 36 | std::unique_ptr<MemoryBuffer> &&Content); |
| 37 | void removeSections(function_ref<bool(const Section &)> ToRemove); |
| 38 | |
| 39 | private: |
| 40 | std::vector<std::unique_ptr<MemoryBuffer>> OwnedContents; |
Derek Schuff | f2af060 | 2020-01-29 17:30:57 -0800 | [diff] [blame] | 41 | }; |
| 42 | |
| 43 | } // end namespace wasm |
| 44 | } // end namespace objcopy |
| 45 | } // end namespace llvm |
| 46 | |
| 47 | #endif // LLVM_TOOLS_LLVM_OBJCOPY_WASM_OBJECT_H |