xref: /llvm-project/llvm/lib/ObjCopy/wasm/WasmObject.h (revision 2a6136e552d24b6bf665c42a6e32efc0b2d88fbf)
125d7b4fbSAlexey Lapshin //===- WasmObject.h ---------------------------------------------*- C++ -*-===//
225d7b4fbSAlexey Lapshin //
325d7b4fbSAlexey Lapshin // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
425d7b4fbSAlexey Lapshin // See https://llvm.org/LICENSE.txt for license information.
525d7b4fbSAlexey Lapshin // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
625d7b4fbSAlexey Lapshin //
725d7b4fbSAlexey Lapshin //===----------------------------------------------------------------------===//
825d7b4fbSAlexey Lapshin 
925d7b4fbSAlexey Lapshin #ifndef LLVM_LIB_OBJCOPY_WASM_WASMOBJECT_H
1025d7b4fbSAlexey Lapshin #define LLVM_LIB_OBJCOPY_WASM_WASMOBJECT_H
1125d7b4fbSAlexey Lapshin 
1225d7b4fbSAlexey Lapshin #include "llvm/ADT/ArrayRef.h"
1325d7b4fbSAlexey Lapshin #include "llvm/ADT/StringRef.h"
1425d7b4fbSAlexey Lapshin #include "llvm/Object/Wasm.h"
1525d7b4fbSAlexey Lapshin #include "llvm/Support/MemoryBuffer.h"
1625d7b4fbSAlexey Lapshin #include <vector>
1725d7b4fbSAlexey Lapshin 
1825d7b4fbSAlexey Lapshin namespace llvm {
1925d7b4fbSAlexey Lapshin namespace objcopy {
2025d7b4fbSAlexey Lapshin namespace wasm {
2125d7b4fbSAlexey Lapshin 
2225d7b4fbSAlexey Lapshin struct Section {
2325d7b4fbSAlexey Lapshin   // For now, each section is only an opaque binary blob with no distinction
2425d7b4fbSAlexey Lapshin   // between custom and known sections.
2525d7b4fbSAlexey Lapshin   uint8_t SectionType;
261b21067cSDerek Schuff   std::optional<uint8_t> HeaderSecSizeEncodingLen;
2725d7b4fbSAlexey Lapshin   StringRef Name;
2825d7b4fbSAlexey Lapshin   ArrayRef<uint8_t> Contents;
2925d7b4fbSAlexey Lapshin };
3025d7b4fbSAlexey Lapshin 
3125d7b4fbSAlexey Lapshin struct Object {
3225d7b4fbSAlexey Lapshin   llvm::wasm::WasmObjectHeader Header;
3325d7b4fbSAlexey Lapshin   // For now don't discriminate between kinds of sections.
3425d7b4fbSAlexey Lapshin   std::vector<Section> Sections;
35*2a6136e5SSam Clegg   bool isRelocatableObject = false;
3625d7b4fbSAlexey Lapshin 
3725d7b4fbSAlexey Lapshin   void addSectionWithOwnedContents(Section NewSection,
3825d7b4fbSAlexey Lapshin                                    std::unique_ptr<MemoryBuffer> &&Content);
3925d7b4fbSAlexey Lapshin   void removeSections(function_ref<bool(const Section &)> ToRemove);
4025d7b4fbSAlexey Lapshin 
4125d7b4fbSAlexey Lapshin private:
4225d7b4fbSAlexey Lapshin   std::vector<std::unique_ptr<MemoryBuffer>> OwnedContents;
4325d7b4fbSAlexey Lapshin };
4425d7b4fbSAlexey Lapshin 
4525d7b4fbSAlexey Lapshin } // end namespace wasm
4625d7b4fbSAlexey Lapshin } // end namespace objcopy
4725d7b4fbSAlexey Lapshin } // end namespace llvm
4825d7b4fbSAlexey Lapshin 
4925d7b4fbSAlexey Lapshin #endif // LLVM_LIB_OBJCOPY_WASM_WASMOBJECT_H
50