Reader.cpp 1.0 KB

123456789101112131415161718192021222324252627282930313233
  1. //===- Reader.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. #include "Reader.h"
  9. namespace llvm {
  10. namespace objcopy {
  11. namespace wasm {
  12. using namespace object;
  13. using namespace llvm::wasm;
  14. Expected<std::unique_ptr<Object>> Reader::create() const {
  15. auto Obj = std::make_unique<Object>();
  16. Obj->Header = WasmObj.getHeader();
  17. std::vector<Section> Sections;
  18. Obj->Sections.reserve(WasmObj.getNumSections());
  19. for (const SectionRef &Sec : WasmObj.sections()) {
  20. const WasmSection &WS = WasmObj.getWasmSection(Sec);
  21. Obj->Sections.push_back(
  22. {static_cast<uint8_t>(WS.Type), WS.Name, WS.Content});
  23. }
  24. return std::move(Obj);
  25. }
  26. } // end namespace wasm
  27. } // end namespace objcopy
  28. } // end namespace llvm