Coverage Report

Created: 2018-01-17 17:22

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/lld/wasm/Symbols.h
Line
Count
Source (jump to first uncovered line)
1
//===- Symbols.h ------------------------------------------------*- C++ -*-===//
2
//
3
//                             The LLVM Linker
4
//
5
// This file is distributed under the University of Illinois Open Source
6
// License. See LICENSE.TXT for details.
7
//
8
//===----------------------------------------------------------------------===//
9
10
#ifndef LLD_WASM_SYMBOLS_H
11
#define LLD_WASM_SYMBOLS_H
12
13
#include "lld/Common/LLVM.h"
14
#include "llvm/Object/Archive.h"
15
#include "llvm/Object/Wasm.h"
16
17
using llvm::object::Archive;
18
using llvm::wasm::WasmSignature;
19
20
namespace lld {
21
namespace wasm {
22
23
class InputFile;
24
class InputSegment;
25
class InputFunction;
26
27
class Symbol {
28
public:
29
  enum Kind {
30
    DefinedFunctionKind,
31
    DefinedGlobalKind,
32
33
    LazyKind,
34
    UndefinedFunctionKind,
35
    UndefinedGlobalKind,
36
37
    LastDefinedKind = DefinedGlobalKind,
38
    InvalidKind,
39
  };
40
41
0
  Symbol(StringRef Name, uint32_t Flags) : Flags(Flags), Name(Name) {}
42
43
0
  Kind getKind() const { return SymbolKind; }
44
45
0
  bool isLazy() const { return SymbolKind == LazyKind; }
46
0
  bool isDefined() const { return SymbolKind <= LastDefinedKind; }
47
0
  bool isUndefined() const {
48
0
    return SymbolKind == UndefinedGlobalKind ||
49
0
           SymbolKind == UndefinedFunctionKind;
50
0
  }
51
0
  bool isFunction() const {
52
0
    return SymbolKind == DefinedFunctionKind ||
53
0
           SymbolKind == UndefinedFunctionKind;
54
0
  }
55
0
  bool isGlobal() const { return !isFunction(); }
56
  bool isLocal() const;
57
  bool isWeak() const;
58
  bool isHidden() const;
59
60
  // Returns the symbol name.
61
0
  StringRef getName() const { return Name; }
62
63
  // Returns the file from which this symbol was created.
64
0
  InputFile *getFile() const { return File; }
65
66
0
  bool hasFunctionType() const { return FunctionType != nullptr; }
67
  const WasmSignature &getFunctionType() const;
68
  void setFunctionType(const WasmSignature *Type);
69
  void setHidden(bool IsHidden);
70
71
  uint32_t getOutputIndex() const;
72
73
  // Returns true if an output index has been set for this symbol
74
  bool hasOutputIndex() const;
75
76
  // Set the output index of the symbol (in the function or global index
77
  // space of the output object.
78
  void setOutputIndex(uint32_t Index);
79
80
0
  uint32_t getTableIndex() const { return TableIndex.getValue(); }
81
82
  // Returns true if a table index has been set for this symbol
83
0
  bool hasTableIndex() const { return TableIndex.hasValue(); }
84
85
  // Set the table index of the symbol
86
  void setTableIndex(uint32_t Index);
87
88
  // Returns the virtual address of a defined global.
89
  // Only works for globals, not functions.
90
  uint32_t getVirtualAddress() const;
91
92
  void setVirtualAddress(uint32_t VA);
93
94
  void update(Kind K, InputFile *F = nullptr, uint32_t Flags = 0,
95
              const InputSegment *Segment = nullptr,
96
              InputFunction *Function = nullptr, uint32_t Address = UINT32_MAX);
97
98
0
  void setArchiveSymbol(const Archive::Symbol &Sym) { ArchiveSymbol = Sym; }
99
0
  const Archive::Symbol &getArchiveSymbol() { return ArchiveSymbol; }
100
0
  InputFunction *getFunction() { return Function; }
101
102
protected:
103
  uint32_t Flags;
104
  uint32_t VirtualAddress = 0;
105
106
  StringRef Name;
107
  Archive::Symbol ArchiveSymbol = {nullptr, 0, 0};
108
  Kind SymbolKind = InvalidKind;
109
  InputFile *File = nullptr;
110
  const InputSegment *Segment = nullptr;
111
  InputFunction *Function = nullptr;
112
  llvm::Optional<uint32_t> OutputIndex;
113
  llvm::Optional<uint32_t> TableIndex;
114
  const WasmSignature *FunctionType = nullptr;
115
};
116
117
} // namespace wasm
118
119
// Returns a symbol name for an error message.
120
std::string toString(const wasm::Symbol &Sym);
121
std::string toString(wasm::Symbol::Kind Kind);
122
123
} // namespace lld
124
125
#endif