Path: blob/main/contrib/llvm-project/llvm/lib/ObjCopy/wasm/WasmReader.cpp
35266 views
//===- WasmReader.cpp -----------------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "WasmReader.h"910namespace llvm {11namespace objcopy {12namespace wasm {1314using namespace object;15using namespace llvm::wasm;1617Expected<std::unique_ptr<Object>> Reader::create() const {18auto Obj = std::make_unique<Object>();19Obj->Header = WasmObj.getHeader();20std::vector<Section> Sections;21Obj->Sections.reserve(WasmObj.getNumSections());22for (const SectionRef &Sec : WasmObj.sections()) {23const WasmSection &WS = WasmObj.getWasmSection(Sec);24Obj->Sections.push_back({static_cast<uint8_t>(WS.Type),25WS.HeaderSecSizeEncodingLen, WS.Name, WS.Content});26// Give known sections standard names to allow them to be selected. (Custom27// sections already have their names filled in by the parser).28Section &ReaderSec = Obj->Sections.back();29if (ReaderSec.SectionType > WASM_SEC_CUSTOM &&30ReaderSec.SectionType <= WASM_SEC_LAST_KNOWN)31ReaderSec.Name = sectionTypeToString(ReaderSec.SectionType);32}33return std::move(Obj);34}3536} // end namespace wasm37} // end namespace objcopy38} // end namespace llvm394041