LLVM  16.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 
11 namespace llvm {
12 namespace objcopy {
13 namespace wasm {
14 
15 using namespace object;
16 using namespace llvm::wasm;
17 
19  auto Obj = std::make_unique<Object>();
20  Obj->Header = WasmObj.getHeader();
21  std::vector<Section> Sections;
22  Obj->Sections.reserve(WasmObj.getNumSections());
23  for (const SectionRef &Sec : WasmObj.sections()) {
24  const WasmSection &WS = WasmObj.getWasmSection(Sec);
25  Obj->Sections.push_back(
26  {static_cast<uint8_t>(WS.Type), WS.Name, WS.Content});
27  // Give known sections standard names to allow them to be selected. (Custom
28  // sections already have their names filled in by the parser).
29  Section &ReaderSec = Obj->Sections.back();
30  if (ReaderSec.SectionType > WASM_SEC_CUSTOM &&
31  ReaderSec.SectionType <= WASM_SEC_LAST_KNOWN)
32  ReaderSec.Name = sectionTypeToString(ReaderSec.SectionType);
33  }
34  return std::move(Obj);
35 }
36 
37 } // end namespace wasm
38 } // end namespace objcopy
39 } // end namespace llvm
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
llvm::object::WasmSection::Content
ArrayRef< uint8_t > Content
Definition: Wasm.h:111
llvm::object::WasmSection
Definition: Wasm.h:104
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:41
llvm::object::WasmSection::Name
StringRef Name
Definition: Wasm.h:109
llvm::object::WasmSection::Type
uint32_t Type
Definition: Wasm.h:107
llvm::object::SectionRef
This is a value type class that represents a single section in the list of sections in the object fil...
Definition: ObjectFile.h:80
llvm::objcopy::wasm::Section
Definition: WasmObject.h:22
object
bar al al movzbl eax ret Missed when stored in a memory object
Definition: README.txt:1411
move
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
Definition: README.txt:546
llvm::objcopy::wasm::Reader::create
Expected< std::unique_ptr< Object > > create() const
Definition: WasmReader.cpp:18
llvm::objcopy::wasm::Section::SectionType
uint8_t SectionType
Definition: WasmObject.h:25
WasmReader.h
llvm::wasm
Definition: Wasm.h:23
llvm::wasm::WASM_SEC_CUSTOM
@ WASM_SEC_CUSTOM
Definition: Wasm.h:242
llvm::wasm::sectionTypeToString
llvm::StringRef sectionTypeToString(uint32_t type)
Definition: Wasm.cpp:41
llvm::objcopy::wasm::Section::Name
StringRef Name
Definition: WasmObject.h:26
llvm::wasm::WASM_SEC_LAST_KNOWN
@ WASM_SEC_LAST_KNOWN
Definition: Wasm.h:256