Coverage Report

Created: 2018-01-17 17:22

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/lld/wasm/Symbols.cpp
Line
Count
Source (jump to first uncovered line)
1
//===- Symbols.cpp --------------------------------------------------------===//
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
#include "Symbols.h"
11
12
#include "Config.h"
13
#include "InputChunks.h"
14
#include "InputFiles.h"
15
#include "lld/Common/ErrorHandler.h"
16
#include "lld/Common/Strings.h"
17
18
#define DEBUG_TYPE "lld"
19
20
using namespace llvm;
21
using namespace llvm::wasm;
22
using namespace lld;
23
using namespace lld::wasm;
24
25
0
const WasmSignature &Symbol::getFunctionType() const {
26
0
  if (Function != nullptr)
27
0
    return Function->Signature;
28
0
29
0
  assert(FunctionType != nullptr);
30
0
  return *FunctionType;
31
0
}
32
33
0
void Symbol::setFunctionType(const WasmSignature *Type) {
34
0
  assert(FunctionType == nullptr);
35
0
  assert(Function == nullptr);
36
0
  FunctionType = Type;
37
0
}
38
39
0
uint32_t Symbol::getVirtualAddress() const {
40
0
  assert(isGlobal());
41
0
  DEBUG(dbgs() << "getVirtualAddress: " << getName() << "\n");
42
0
  return Segment ? Segment->translateVA(VirtualAddress) : VirtualAddress;
43
0
}
44
45
0
bool Symbol::hasOutputIndex() const {
46
0
  if (Function)
47
0
    return Function->hasOutputIndex();
48
0
  return OutputIndex.hasValue();
49
0
}
50
51
0
uint32_t Symbol::getOutputIndex() const {
52
0
  if (Function)
53
0
    return Function->getOutputIndex();
54
0
  return OutputIndex.getValue();
55
0
}
56
57
0
void Symbol::setVirtualAddress(uint32_t Value) {
58
0
  DEBUG(dbgs() << "setVirtualAddress " << Name << " -> " << Value << "\n");
59
0
  assert(isGlobal());
60
0
  VirtualAddress = Value;
61
0
}
62
63
0
void Symbol::setOutputIndex(uint32_t Index) {
64
0
  DEBUG(dbgs() << "setOutputIndex " << Name << " -> " << Index << "\n");
65
0
  assert(!Function);
66
0
  assert(!OutputIndex.hasValue());
67
0
  OutputIndex = Index;
68
0
}
69
70
0
void Symbol::setTableIndex(uint32_t Index) {
71
0
  DEBUG(dbgs() << "setTableIndex " << Name << " -> " << Index << "\n");
72
0
  assert(!TableIndex.hasValue());
73
0
  TableIndex = Index;
74
0
}
75
76
void Symbol::update(Kind K, InputFile *F, uint32_t Flags_,
77
                    const InputSegment *Seg, InputFunction *Func,
78
0
                    uint32_t Address) {
79
0
  SymbolKind = K;
80
0
  File = F;
81
0
  Flags = Flags_;
82
0
  Segment = Seg;
83
0
  Function = Func;
84
0
  if (Address != UINT32_MAX)
85
0
    setVirtualAddress(Address);
86
0
}
87
88
0
bool Symbol::isWeak() const {
89
0
  return (Flags & WASM_SYMBOL_BINDING_MASK) == WASM_SYMBOL_BINDING_WEAK;
90
0
}
91
92
0
bool Symbol::isLocal() const {
93
0
  return (Flags & WASM_SYMBOL_BINDING_MASK) == WASM_SYMBOL_BINDING_LOCAL;
94
0
}
95
96
0
bool Symbol::isHidden() const {
97
0
  return (Flags & WASM_SYMBOL_VISIBILITY_MASK) == WASM_SYMBOL_VISIBILITY_HIDDEN;
98
0
}
99
100
0
void Symbol::setHidden(bool IsHidden) {
101
0
  Flags &= ~WASM_SYMBOL_VISIBILITY_MASK;
102
0
  if (IsHidden)
103
0
    Flags |= WASM_SYMBOL_VISIBILITY_HIDDEN;
104
0
  else
105
0
    Flags |= WASM_SYMBOL_VISIBILITY_DEFAULT;
106
0
}
107
108
0
std::string lld::toString(const wasm::Symbol &Sym) {
109
0
  if (Config->Demangle)
110
0
    if (Optional<std::string> S = demangleItanium(Sym.getName()))
111
0
      return "`" + *S + "'";
112
0
  return Sym.getName();
113
0
}
114
115
0
std::string lld::toString(wasm::Symbol::Kind Kind) {
116
0
  switch (Kind) {
117
0
  case wasm::Symbol::DefinedFunctionKind:
118
0
    return "DefinedFunction";
119
0
  case wasm::Symbol::DefinedGlobalKind:
120
0
    return "DefinedGlobal";
121
0
  case wasm::Symbol::UndefinedFunctionKind:
122
0
    return "UndefinedFunction";
123
0
  case wasm::Symbol::UndefinedGlobalKind:
124
0
    return "UndefinedGlobal";
125
0
  case wasm::Symbol::LazyKind:
126
0
    return "LazyKind";
127
0
  }
128
0
  llvm_unreachable("Invalid symbol kind!");
129
0
}