[PATCH] D43717: [WebAssembly] Make getWasmType a non-member function.
Rui Ueyama via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 23 20:37:10 PST 2018
ruiu created this revision.
ruiu added a reviewer: sbc100.
Herald added subscribers: sunfish, aheejin, jgravelle-google, dschuff, jfb.
A function that doesn't use any private member should be defined as
a non-member function, so that it is obvious that it uses only public
interfaces of a given object.
https://reviews.llvm.org/D43717
Files:
lld/wasm/SymbolTable.cpp
lld/wasm/Symbols.cpp
lld/wasm/Symbols.h
lld/wasm/Writer.cpp
Index: lld/wasm/Writer.cpp
===================================================================
--- lld/wasm/Writer.cpp
+++ lld/wasm/Writer.cpp
@@ -405,7 +405,7 @@
writeUleb128(SubSection.getStream(), SymtabEntries.size(), "num symbols");
for (const Symbol *Sym : SymtabEntries) {
assert(Sym->isDefined() || Sym->isUndefined());
- WasmSymbolType Kind = Sym->getWasmType();
+ WasmSymbolType Kind = getWasmType(Sym);
uint32_t Flags = getWasmFlags(Sym);
writeUleb128(SubSection.getStream(), Kind, "sym kind");
Index: lld/wasm/Symbols.h
===================================================================
--- lld/wasm/Symbols.h
+++ lld/wasm/Symbols.h
@@ -91,8 +91,6 @@
uint32_t getOutputSymbolIndex() const;
void setOutputSymbolIndex(uint32_t Index);
- WasmSymbolType getWasmType() const;
-
protected:
Symbol(StringRef Name, Kind K, uint32_t Flags, InputFile *F)
: Name(Name), SymbolKind(K), Flags(Flags), File(F) {}
@@ -315,6 +313,8 @@
return new (S) T(std::forward<ArgT>(Arg)...);
}
+WasmSymbolType getWasmType(const Symbol *Sym);
+
} // namespace wasm
// Returns a symbol name for an error message.
Index: lld/wasm/Symbols.cpp
===================================================================
--- lld/wasm/Symbols.cpp
+++ lld/wasm/Symbols.cpp
@@ -29,22 +29,6 @@
DefinedData *WasmSym::HeapBase;
DefinedGlobal *WasmSym::StackPointer;
-WasmSymbolType Symbol::getWasmType() const {
- switch (SymbolKind) {
- case Symbol::DefinedFunctionKind:
- case Symbol::UndefinedFunctionKind:
- return llvm::wasm::WASM_SYMBOL_TYPE_FUNCTION;
- case Symbol::DefinedDataKind:
- case Symbol::UndefinedDataKind:
- return llvm::wasm::WASM_SYMBOL_TYPE_DATA;
- case Symbol::DefinedGlobalKind:
- case Symbol::UndefinedGlobalKind:
- return llvm::wasm::WASM_SYMBOL_TYPE_GLOBAL;
- default:
- llvm_unreachable("invalid symbol kind");
- }
-}
-
bool Symbol::hasOutputIndex() const {
if (auto *F = dyn_cast<DefinedFunction>(this))
if (F->Function)
@@ -182,6 +166,16 @@
Global ? &Global->getType() : nullptr),
Global(Global) {}
+WasmSymbolType lld::wasm::getWasmType(const Symbol *Sym) {
+ if (isa<FunctionSymbol>(Sym))
+ return llvm::wasm::WASM_SYMBOL_TYPE_FUNCTION;
+ if (isa<DataSymbol>(Sym))
+ return llvm::wasm::WASM_SYMBOL_TYPE_DATA;
+ if (isa<GlobalSymbol>(Sym))
+ return llvm::wasm::WASM_SYMBOL_TYPE_GLOBAL;
+ llvm_unreachable("invalid symbol kind");
+}
+
std::string lld::toString(const wasm::Symbol &Sym) {
if (Config->Demangle)
if (Optional<std::string> S = demangleItanium(Sym.getName()))
Index: lld/wasm/SymbolTable.cpp
===================================================================
--- lld/wasm/SymbolTable.cpp
+++ lld/wasm/SymbolTable.cpp
@@ -74,7 +74,7 @@
static void reportTypeError(const Symbol *Existing, const InputFile *File,
StringRef Type) {
error("symbol type mismatch: " + toString(*Existing) + "\n>>> defined as " +
- toString(Existing->getWasmType()) + " in " +
+ toString(getWasmType(Existing)) + " in " +
toString(Existing->getFile()) + "\n>>> defined as " + Type + " in " +
toString(File));
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D43717.135774.patch
Type: text/x-patch
Size: 3218 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180224/e879563f/attachment.bin>
More information about the llvm-commits
mailing list