LLVM  4.0.0
Object/Wasm.h
Go to the documentation of this file.
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 
23 namespace llvm {
24 namespace object {
25 
26 class WasmObjectFile : public ObjectFile {
27 public:
28  WasmObjectFile(MemoryBufferRef Object, Error &Err);
29  const wasm::WasmObjectHeader &getHeader() const;
31  static bool classof(const Binary *v) { return v->isWasm(); }
32 
33 protected:
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;
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;
71 
72  // Overrides from RelocationRef.
73  void moveRelocationNext(DataRefImpl &Rel) const override;
74  uint64_t getRelocationOffset(DataRefImpl Rel) const override;
76  uint64_t getRelocationType(DataRefImpl Rel) const override;
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 
88 private:
89  const uint8_t *getPtr(size_t Offset) const;
90  Error parseUserSection(wasm::WasmSection &Sec, const uint8_t *Ptr,
91  size_t Length);
92 
94  std::vector<wasm::WasmSection> Sections;
95 };
96 }
97 }
98 
99 #endif
uint64_t getRelocationType(DataRefImpl Rel) const override
std::error_code getSectionName(DataRefImpl Sec, StringRef &Res) const override
unsigned getArch() const override
section_iterator section_end() const override
uint64_t getSectionAddress(DataRefImpl Sec) const override
This class is the base class for all object file types.
Definition: ObjectFile.h:178
bool isSectionCompressed(DataRefImpl Sec) const override
void moveSymbolNext(DataRefImpl &Symb) const override
std::error_code getSectionContents(DataRefImpl Sec, StringRef &Res) const override
relocation_iterator section_rel_end(DataRefImpl Sec) const override
bool isSectionVirtual(DataRefImpl Sec) const override
uint8_t getBytesInAddress() const override
The number of bytes used to represent an address in this object file format.
Tagged union holding either a T or a Error.
relocation_iterator section_rel_begin(DataRefImpl Sec) const override
StringRef getFileFormatName() const override
static bool classof(const Binary *v)
Definition: Object/Wasm.h:31
bool isSectionText(DataRefImpl Sec) const override
basic_symbol_iterator symbol_begin() const override
symbol_iterator getRelocationSymbol(DataRefImpl Rel) const override
Expected< uint64_t > getSymbolAddress(DataRefImpl Symb) const override
void moveRelocationNext(DataRefImpl &Rel) const override
uint64_t getSymbolValueImpl(DataRefImpl Symb) const override
uint64_t getSectionAlignment(DataRefImpl Sec) const override
WasmObjectFile(MemoryBufferRef Object, Error &Err)
uint32_t getSymbolAlignment(DataRefImpl Symb) const override
void moveSectionNext(DataRefImpl &Sec) const override
Expected< SymbolRef::Type > getSymbolType(DataRefImpl Symb) const override
Expected< section_iterator > getSymbolSection(DataRefImpl Symb) const override
const wasm::WasmSection * getWasmSection(const SectionRef &Section) const
uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const override
uint32_t Offset
SubtargetFeatures getFeatures() const override
Expected< StringRef > getSymbolName(DataRefImpl Symb) const override
uint64_t getSectionSize(DataRefImpl Sec) const override
basic_symbol_iterator symbol_end() const override
const wasm::WasmObjectHeader & getHeader() const
section_iterator section_begin() const override
std::error_code printSymbolName(raw_ostream &OS, DataRefImpl Symb) const override
SubtargetFeatures - Manages the enabling and disabling of subtarget specific features.
bool isSectionData(DataRefImpl Sec) const override
section_iterator getRelocatedSection(DataRefImpl Sec) const override
void getRelocationTypeName(DataRefImpl Rel, SmallVectorImpl< char > &Result) const override
bool isRelocatableObject() const override
True if this is a relocatable object (.o/.obj).
bool isSectionBitcode(DataRefImpl Sec) const override
uint32_t getSymbolFlags(DataRefImpl Symb) const override
Lightweight error class with error context and mandatory checking.
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:44
bool isWasm() const
Definition: Binary.h:120
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:47
int * Ptr
bool isSectionBSS(DataRefImpl Sec) const override
This is a value type class that represents a single section in the list of sections in the object fil...
Definition: ObjectFile.h:70
uint64_t getRelocationOffset(DataRefImpl Rel) const override