LLVM 20.0.0git
WasmReader.cpp
Go to the documentation of this file.
1//===- WasmReader.cpp -----------------------------------------------------===//
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#include "WasmReader.h"
10
11namespace llvm {
12namespace objcopy {
13namespace wasm {
14
15using namespace object;
16using namespace llvm::wasm;
17
19 auto Obj = std::make_unique<Object>();
20 Obj->Header = WasmObj.getHeader();
21 Obj->isRelocatableObject = WasmObj.isRelocatableObject();
22 std::vector<Section> Sections;
23 Obj->Sections.reserve(WasmObj.getNumSections());
24 for (const SectionRef &Sec : WasmObj.sections()) {
25 const WasmSection &WS = WasmObj.getWasmSection(Sec);
26 Obj->Sections.push_back({static_cast<uint8_t>(WS.Type),
28 // Give known sections standard names to allow them to be selected. (Custom
29 // sections already have their names filled in by the parser).
30 Section &ReaderSec = Obj->Sections.back();
31 if (ReaderSec.SectionType > WASM_SEC_CUSTOM &&
33 ReaderSec.Name = sectionTypeToString(ReaderSec.SectionType);
34 }
35 return std::move(Obj);
36}
37
38} // end namespace wasm
39} // end namespace objcopy
40} // end namespace llvm
Tagged union holding either a T or a Error.
Definition: Error.h:481
Expected< std::unique_ptr< Object > > create() const
Definition: WasmReader.cpp:18
section_iterator_range sections() const
Definition: ObjectFile.h:329
This is a value type class that represents a single section in the list of sections in the object fil...
Definition: ObjectFile.h:81
bool isRelocatableObject() const override
True if this is a relocatable object (.o/.obj).
const WasmSection & getWasmSection(const SectionRef &Section) const
const wasm::WasmObjectHeader & getHeader() const
uint32_t getNumSections() const
Definition: Wasm.h:162
@ WASM_SEC_LAST_KNOWN
Definition: Wasm.h:49
@ WASM_SEC_CUSTOM
Definition: Wasm.h:35
llvm::StringRef sectionTypeToString(uint32_t type)
Definition: Wasm.cpp:41
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
ArrayRef< uint8_t > Content
Definition: Wasm.h:115
std::optional< uint8_t > HeaderSecSizeEncodingLen
Definition: Wasm.h:118