1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 18:54:02 +01:00

[WebAssembly] MC: Improve debug output

llvm-svn: 331220
This commit is contained in:
Sam Clegg 2018-04-30 19:40:57 +00:00
parent 4a7333a0ad
commit 235d87db3d
2 changed files with 34 additions and 8 deletions

View File

@ -45,6 +45,7 @@ public:
bool isFunction() const { return Type == wasm::WASM_SYMBOL_TYPE_FUNCTION; }
bool isData() const { return Type == wasm::WASM_SYMBOL_TYPE_DATA; }
bool isGlobal() const { return Type == wasm::WASM_SYMBOL_TYPE_GLOBAL; }
bool isSection() const { return Type == wasm::WASM_SYMBOL_TYPE_SECTION; }
wasm::WasmSymbolType getType() const { return Type; }
void setType(wasm::WasmSymbolType type) { Type = type; }

View File

@ -37,6 +37,29 @@ using namespace llvm;
#define DEBUG_TYPE "mc"
static std::string toString(wasm::WasmSymbolType type) {
switch (type) {
case wasm::WASM_SYMBOL_TYPE_FUNCTION:
return "WASM_SYMBOL_TYPE_FUNCTION";
case wasm::WASM_SYMBOL_TYPE_GLOBAL:
return "WASM_SYMBOL_TYPE_GLOBAL";
case wasm::WASM_SYMBOL_TYPE_DATA:
return "WASM_SYMBOL_TYPE_DATA";
case wasm::WASM_SYMBOL_TYPE_SECTION:
return "WASM_SYMBOL_TYPE_SECTION";
}
}
static std::string relocTypetoString(uint32_t type) {
switch (type) {
#define WASM_RELOC(NAME, VALUE) case VALUE: return #NAME;
#include "llvm/BinaryFormat/WasmRelocs.def"
#undef WASM_RELOC
default:
llvm_unreachable("uknown reloc type");
}
}
namespace {
// Went we ceate the indirect function table we start at 1, so that there is
@ -163,8 +186,8 @@ struct WasmRelocationEntry {
}
void print(raw_ostream &Out) const {
Out << "Off=" << Offset << ", Sym=" << *Symbol << ", Addend=" << Addend
<< ", Type=" << Type
Out << relocTypetoString(Type)
<< " Off=" << Offset << ", Sym=" << *Symbol << ", Addend=" << Addend
<< ", FixupSection=" << FixupSection->getSectionName();
}
@ -214,7 +237,7 @@ class WasmObjectWriter : public MCObjectWriter {
DenseMap<const MCSymbolWasm *, uint32_t> TableIndices;
// Maps function/global symbols to the (shared) Symbol index space.
DenseMap<const MCSymbolWasm *, uint32_t> SymbolIndices;
// Maps function/global symbols to the function/global Wasm index space.
// Maps function/global symbols to the function/global/section index space.
DenseMap<const MCSymbolWasm *, uint32_t> WasmIndices;
// Maps data symbols to the Wasm segment and offset/size with the segment.
DenseMap<const MCSymbolWasm *, wasm::WasmDataReference> DataLocations;
@ -1235,11 +1258,11 @@ void WasmObjectWriter::writeObject(MCAssembler &Asm,
continue;
const auto &WS = static_cast<const MCSymbolWasm &>(S);
DEBUG(dbgs() << "MCSymbol: '" << S << "'"
DEBUG(dbgs() << "MCSymbol: " << toString(WS.getType())
<< " '" << S << "'"
<< " isDefined=" << S.isDefined()
<< " isExternal=" << S.isExternal()
<< " isTemporary=" << S.isTemporary()
<< " isFunction=" << WS.isFunction()
<< " isWeak=" << WS.isWeak()
<< " isHidden=" << WS.isHidden()
<< " isVariable=" << WS.isVariable() << "\n");
@ -1284,7 +1307,7 @@ void WasmObjectWriter::writeObject(MCAssembler &Asm,
continue;
if (!WS.isDefined()) {
DEBUG(dbgs() << " -> segment index: -1");
DEBUG(dbgs() << " -> segment index: -1" << "\n");
continue;
}
@ -1306,8 +1329,8 @@ void WasmObjectWriter::writeObject(MCAssembler &Asm,
static_cast<uint32_t>(Layout.getSymbolOffset(WS)),
static_cast<uint32_t>(Size)};
DataLocations[&WS] = Ref;
DEBUG(dbgs() << " -> segment index: " << Ref.Segment);
} else {
DEBUG(dbgs() << " -> segment index: " << Ref.Segment << "\n");
} else if (WS.isGlobal()) {
// A "true" Wasm global (currently just __stack_pointer)
if (WS.isDefined())
report_fatal_error("don't yet support defined globals");
@ -1315,6 +1338,8 @@ void WasmObjectWriter::writeObject(MCAssembler &Asm,
// An import; the index was assigned above
DEBUG(dbgs() << " -> global index: " << WasmIndices.find(&WS)->second
<< "\n");
} else {
assert(WS.isSection());
}
}