Skip to content

Commit

Permalink
[WebAssembly] Move toString helpers to BinaryFormat
Browse files Browse the repository at this point in the history
Subscribers: dschuff, mgorny, jgravelle-google, aheejin, sunfish, llvm-commits

Differential Revision: https://reviews.llvm.org/D46847

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@332305 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
sbc100 committed May 14, 2018
1 parent 67ebb42 commit b67613e
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 30 deletions.
3 changes: 3 additions & 0 deletions include/llvm/BinaryFormat/Wasm.h
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,9 @@ inline bool operator!=(const WasmGlobalType &LHS, const WasmGlobalType &RHS) {
return !(LHS == RHS);
}

std::string toString(wasm::WasmSymbolType type);
std::string relocTypetoString(uint32_t type);

} // end namespace wasm
} // end namespace llvm

Expand Down
3 changes: 2 additions & 1 deletion include/llvm/Object/Wasm.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ class WasmSymbol {
}

void print(raw_ostream &Out) const {
Out << "Name=" << Info.Name << ", Kind=" << int(Info.Kind)
Out << "Name=" << Info.Name
<< ", Kind=" << toString(wasm::WasmSymbolType(Info.Kind))
<< ", Flags=" << Info.Flags;
if (!isTypeData()) {
Out << ", ElemIndex=" << Info.ElementIndex;
Expand Down
3 changes: 2 additions & 1 deletion lib/BinaryFormat/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
add_llvm_library(LLVMBinaryFormat
Dwarf.cpp
Magic.cpp
Wasm.cpp

ADDITIONAL_HEADER_DIRS
${LLVM_MAIN_INCLUDE_DIR}/llvm/BinaryFormat
)


34 changes: 34 additions & 0 deletions lib/BinaryFormat/Wasm.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//===-- llvm/BinaryFormat/Wasm.cpp -------------------------------*- C++-*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#include "llvm/BinaryFormat/Wasm.h"

std::string llvm::wasm::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";
}
llvm_unreachable("unknown symbol type");
}

std::string llvm::wasm::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("unknown reloc type");
}
}
2 changes: 1 addition & 1 deletion lib/MC/LLVMBuild.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ subdirectories = MCDisassembler MCParser
type = Library
name = MC
parent = Libraries
required_libraries = Support DebugInfoCodeView
required_libraries = Support BinaryFormat DebugInfoCodeView
28 changes: 1 addition & 27 deletions lib/MC/WasmObjectWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,32 +37,6 @@ using namespace llvm;

#define DEBUG_TYPE "mc"

#if !defined(NDEBUG)
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";
}
llvm_unreachable("unknown symbol type");
}
#endif

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
Expand Down Expand Up @@ -189,7 +163,7 @@ struct WasmRelocationEntry {
}

void print(raw_ostream &Out) const {
Out << relocTypetoString(Type)
Out << wasm::relocTypetoString(Type)
<< " Off=" << Offset << ", Sym=" << *Symbol << ", Addend=" << Addend
<< ", FixupSection=" << FixupSection->getSectionName();
}
Expand Down

0 comments on commit b67613e

Please sign in to comment.