1 //===- WasmReader.cpp -----------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "WasmReader.h"
15 using namespace object
;
16 using namespace llvm::wasm
;
18 Expected
<std::unique_ptr
<Object
>> Reader::create() const {
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
),
27 WS
.HeaderSecSizeEncodingLen
, WS
.Name
, WS
.Content
});
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
&&
32 ReaderSec
.SectionType
<= WASM_SEC_LAST_KNOWN
)
33 ReaderSec
.Name
= sectionTypeToString(ReaderSec
.SectionType
);
35 return std::move(Obj
);
38 } // end namespace wasm
39 } // end namespace objcopy
40 } // end namespace llvm