Wasm.h revision 311116
1//===- WasmObjectFile.h - Wasm object file implementation -------*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9// 10// This file declares the WasmObjectFile class, which implements the ObjectFile 11// interface for Wasm files. 12// 13// See: https://github.com/WebAssembly/design/blob/master/BinaryEncoding.md 14// 15//===----------------------------------------------------------------------===// 16 17#ifndef LLVM_OBJECT_WASM_H 18#define LLVM_OBJECT_WASM_H 19 20#include "llvm/Object/ObjectFile.h" 21#include "llvm/Support/Wasm.h" 22 23namespace llvm { 24namespace object { 25 26class WasmObjectFile : public ObjectFile { 27public: 28 WasmObjectFile(MemoryBufferRef Object, Error &Err); 29 const wasm::WasmObjectHeader &getHeader() const; 30 const wasm::WasmSection *getWasmSection(const SectionRef &Section) const; 31 static bool classof(const Binary *v) { return v->isWasm(); } 32 33protected: 34 void moveSymbolNext(DataRefImpl &Symb) const override; 35 36 std::error_code printSymbolName(raw_ostream &OS, 37 DataRefImpl Symb) const override; 38 39 uint32_t getSymbolFlags(DataRefImpl Symb) const override; 40 41 basic_symbol_iterator symbol_begin() const override; 42 43 basic_symbol_iterator symbol_end() const override; 44 Expected<StringRef> getSymbolName(DataRefImpl Symb) const override; 45 46 Expected<uint64_t> getSymbolAddress(DataRefImpl Symb) const override; 47 uint64_t getSymbolValueImpl(DataRefImpl Symb) const override; 48 uint32_t getSymbolAlignment(DataRefImpl Symb) const override; 49 uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const override; 50 Expected<SymbolRef::Type> getSymbolType(DataRefImpl Symb) const override; 51 Expected<section_iterator> getSymbolSection(DataRefImpl Symb) const override; 52 53 // Overrides from SectionRef. 54 void moveSectionNext(DataRefImpl &Sec) const override; 55 std::error_code getSectionName(DataRefImpl Sec, 56 StringRef &Res) const override; 57 uint64_t getSectionAddress(DataRefImpl Sec) const override; 58 uint64_t getSectionSize(DataRefImpl Sec) const override; 59 std::error_code getSectionContents(DataRefImpl Sec, 60 StringRef &Res) const override; 61 uint64_t getSectionAlignment(DataRefImpl Sec) const override; 62 bool isSectionCompressed(DataRefImpl Sec) const override; 63 bool isSectionText(DataRefImpl Sec) const override; 64 bool isSectionData(DataRefImpl Sec) const override; 65 bool isSectionBSS(DataRefImpl Sec) const override; 66 bool isSectionVirtual(DataRefImpl Sec) const override; 67 bool isSectionBitcode(DataRefImpl Sec) const override; 68 relocation_iterator section_rel_begin(DataRefImpl Sec) const override; 69 relocation_iterator section_rel_end(DataRefImpl Sec) const override; 70 section_iterator getRelocatedSection(DataRefImpl Sec) const override; 71 72 // Overrides from RelocationRef. 73 void moveRelocationNext(DataRefImpl &Rel) const override; 74 uint64_t getRelocationOffset(DataRefImpl Rel) const override; 75 symbol_iterator getRelocationSymbol(DataRefImpl Rel) const override; 76 uint64_t getRelocationType(DataRefImpl Rel) const override; 77 void getRelocationTypeName(DataRefImpl Rel, 78 SmallVectorImpl<char> &Result) const override; 79 80 section_iterator section_begin() const override; 81 section_iterator section_end() const override; 82 uint8_t getBytesInAddress() const override; 83 StringRef getFileFormatName() const override; 84 unsigned getArch() const override; 85 SubtargetFeatures getFeatures() const override; 86 bool isRelocatableObject() const override; 87 88private: 89 const uint8_t *getPtr(size_t Offset) const; 90 Error parseUserSection(wasm::WasmSection &Sec, const uint8_t *Ptr, 91 size_t Length); 92 93 wasm::WasmObjectHeader Header; 94 std::vector<wasm::WasmSection> Sections; 95}; 96} 97} 98 99#endif 100