Skip to content

Commit 5f87ab3

Browse files
committedMay 14, 2018
[WebAssembly] Move toString helpers to BinaryFormat
Subscribers: dschuff, mgorny, jgravelle-google, aheejin, sunfish, llvm-commits Differential Revision: https://reviews.llvm.org/D46847 llvm-svn: 332305
1 parent ed5b325 commit 5f87ab3

File tree

6 files changed

+43
-30
lines changed

6 files changed

+43
-30
lines changed
 

‎llvm/include/llvm/BinaryFormat/Wasm.h

+3
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,9 @@ inline bool operator!=(const WasmGlobalType &LHS, const WasmGlobalType &RHS) {
290290
return !(LHS == RHS);
291291
}
292292

293+
std::string toString(wasm::WasmSymbolType type);
294+
std::string relocTypetoString(uint32_t type);
295+
293296
} // end namespace wasm
294297
} // end namespace llvm
295298

‎llvm/include/llvm/Object/Wasm.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ class WasmSymbol {
8989
}
9090

9191
void print(raw_ostream &Out) const {
92-
Out << "Name=" << Info.Name << ", Kind=" << int(Info.Kind)
92+
Out << "Name=" << Info.Name
93+
<< ", Kind=" << toString(wasm::WasmSymbolType(Info.Kind))
9394
<< ", Flags=" << Info.Flags;
9495
if (!isTypeData()) {
9596
Out << ", ElemIndex=" << Info.ElementIndex;

‎llvm/lib/BinaryFormat/CMakeLists.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
add_llvm_library(LLVMBinaryFormat
22
Dwarf.cpp
33
Magic.cpp
4+
Wasm.cpp
45

56
ADDITIONAL_HEADER_DIRS
67
${LLVM_MAIN_INCLUDE_DIR}/llvm/BinaryFormat
78
)
8-
9+

‎llvm/lib/BinaryFormat/Wasm.cpp

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//===-- llvm/BinaryFormat/Wasm.cpp -------------------------------*- 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+
#include "llvm/BinaryFormat/Wasm.h"
11+
12+
std::string llvm::wasm::toString(wasm::WasmSymbolType type) {
13+
switch (type) {
14+
case wasm::WASM_SYMBOL_TYPE_FUNCTION:
15+
return "WASM_SYMBOL_TYPE_FUNCTION";
16+
case wasm::WASM_SYMBOL_TYPE_GLOBAL:
17+
return "WASM_SYMBOL_TYPE_GLOBAL";
18+
case wasm::WASM_SYMBOL_TYPE_DATA:
19+
return "WASM_SYMBOL_TYPE_DATA";
20+
case wasm::WASM_SYMBOL_TYPE_SECTION:
21+
return "WASM_SYMBOL_TYPE_SECTION";
22+
}
23+
llvm_unreachable("unknown symbol type");
24+
}
25+
26+
std::string llvm::wasm::relocTypetoString(uint32_t type) {
27+
switch (type) {
28+
#define WASM_RELOC(NAME, VALUE) case VALUE: return #NAME;
29+
#include "llvm/BinaryFormat/WasmRelocs.def"
30+
#undef WASM_RELOC
31+
default:
32+
llvm_unreachable("unknown reloc type");
33+
}
34+
}

‎llvm/lib/MC/LLVMBuild.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ subdirectories = MCDisassembler MCParser
2222
type = Library
2323
name = MC
2424
parent = Libraries
25-
required_libraries = Support DebugInfoCodeView
25+
required_libraries = Support BinaryFormat DebugInfoCodeView

‎llvm/lib/MC/WasmObjectWriter.cpp

+1-27
Original file line numberDiff line numberDiff line change
@@ -37,32 +37,6 @@ using namespace llvm;
3737

3838
#define DEBUG_TYPE "mc"
3939

40-
#if !defined(NDEBUG)
41-
static std::string toString(wasm::WasmSymbolType type) {
42-
switch (type) {
43-
case wasm::WASM_SYMBOL_TYPE_FUNCTION:
44-
return "WASM_SYMBOL_TYPE_FUNCTION";
45-
case wasm::WASM_SYMBOL_TYPE_GLOBAL:
46-
return "WASM_SYMBOL_TYPE_GLOBAL";
47-
case wasm::WASM_SYMBOL_TYPE_DATA:
48-
return "WASM_SYMBOL_TYPE_DATA";
49-
case wasm::WASM_SYMBOL_TYPE_SECTION:
50-
return "WASM_SYMBOL_TYPE_SECTION";
51-
}
52-
llvm_unreachable("unknown symbol type");
53-
}
54-
#endif
55-
56-
static std::string relocTypetoString(uint32_t type) {
57-
switch (type) {
58-
#define WASM_RELOC(NAME, VALUE) case VALUE: return #NAME;
59-
#include "llvm/BinaryFormat/WasmRelocs.def"
60-
#undef WASM_RELOC
61-
default:
62-
llvm_unreachable("uknown reloc type");
63-
}
64-
}
65-
6640
namespace {
6741

6842
// Went we ceate the indirect function table we start at 1, so that there is
@@ -189,7 +163,7 @@ struct WasmRelocationEntry {
189163
}
190164

191165
void print(raw_ostream &Out) const {
192-
Out << relocTypetoString(Type)
166+
Out << wasm::relocTypetoString(Type)
193167
<< " Off=" << Offset << ", Sym=" << *Symbol << ", Addend=" << Addend
194168
<< ", FixupSection=" << FixupSection->getSectionName();
195169
}

0 commit comments

Comments
 (0)
Please sign in to comment.