[lld] r343734 - [WebAssembly] Refactor use of signatures
Derek Schuff via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 3 15:25:32 PDT 2018
Author: dschuff
Date: Wed Oct 3 15:25:32 2018
New Revision: 343734
URL: http://llvm.org/viewvc/llvm-project?rev=343734&view=rev
Log:
[WebAssembly] Refactor use of signatures
Update use of WebAssemblySignature to go along with D52580
Differential Revision: https://reviews.llvm.org/D52622
Modified:
lld/trunk/wasm/Driver.cpp
lld/trunk/wasm/Writer.cpp
lld/trunk/wasm/WriterUtils.cpp
lld/trunk/wasm/WriterUtils.h
Modified: lld/trunk/wasm/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/Driver.cpp?rev=343734&r1=343733&r2=343734&view=diff
==============================================================================
--- lld/trunk/wasm/Driver.cpp (original)
+++ lld/trunk/wasm/Driver.cpp Wed Oct 3 15:25:32 2018
@@ -458,7 +458,7 @@ void LinkerDriver::link(ArrayRef<const c
InputGlobal *StackPointer = make<InputGlobal>(Global, nullptr);
StackPointer->Live = true;
- static WasmSignature NullSignature = {{}, WASM_TYPE_NORESULT};
+ static WasmSignature NullSignature = {{}, {}};
// Add synthetic symbols before any others
WasmSym::CallCtors = Symtab->addSyntheticFunction(
Modified: lld/trunk/wasm/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/Writer.cpp?rev=343734&r1=343733&r2=343734&view=diff
==============================================================================
--- lld/trunk/wasm/Writer.cpp (original)
+++ lld/trunk/wasm/Writer.cpp Wed Oct 3 15:25:32 2018
@@ -991,7 +991,7 @@ void Writer::calculateInitFunctions() {
const WasmLinkingData &L = File->getWasmObj()->linkingData();
for (const WasmInitFunc &F : L.InitFunctions) {
FunctionSymbol *Sym = File->getFunctionSymbol(F.Symbol);
- if (*Sym->FunctionType != WasmSignature{{}, WASM_TYPE_NORESULT})
+ if (*Sym->FunctionType != WasmSignature{{}, {}})
error("invalid signature for init func: " + toString(*Sym));
InitFunctions.emplace_back(WasmInitEntry{Sym, F.Priority});
}
Modified: lld/trunk/wasm/WriterUtils.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/WriterUtils.cpp?rev=343734&r1=343733&r2=343734&view=diff
==============================================================================
--- lld/trunk/wasm/WriterUtils.cpp (original)
+++ lld/trunk/wasm/WriterUtils.cpp Wed Oct 3 15:25:32 2018
@@ -19,15 +19,15 @@ using namespace llvm;
using namespace llvm::wasm;
using namespace lld::wasm;
-static const char *valueTypeToString(uint8_t Type) {
+static const char *valueTypeToString(ValType Type) {
switch (Type) {
- case WASM_TYPE_I32:
+ case wasm::ValType::I32:
return "i32";
- case WASM_TYPE_I64:
+ case wasm::ValType::I64:
return "i64";
- case WASM_TYPE_F32:
+ case wasm::ValType::F32:
return "f32";
- case WASM_TYPE_F64:
+ case wasm::ValType::F64:
return "f64";
default:
llvm_unreachable("invalid value type");
@@ -73,21 +73,20 @@ void wasm::writeU32(raw_ostream &OS, uin
support::endian::write(OS, Number, support::little);
}
-void wasm::writeValueType(raw_ostream &OS, uint8_t Type, const Twine &Msg) {
- writeU8(OS, Type, Msg + "[type: " + valueTypeToString(Type) + "]");
+void wasm::writeValueType(raw_ostream &OS, ValType Type, const Twine &Msg) {
+ writeU8(OS, static_cast<uint8_t>(Type),
+ Msg + "[type: " + valueTypeToString(Type) + "]");
}
void wasm::writeSig(raw_ostream &OS, const WasmSignature &Sig) {
writeU8(OS, WASM_TYPE_FUNC, "signature type");
- writeUleb128(OS, Sig.ParamTypes.size(), "param Count");
- for (uint8_t ParamType : Sig.ParamTypes) {
+ writeUleb128(OS, Sig.Params.size(), "param Count");
+ for (ValType ParamType : Sig.Params) {
writeValueType(OS, ParamType, "param type");
}
- if (Sig.ReturnType == WASM_TYPE_NORESULT) {
- writeUleb128(OS, 0, "result Count");
- } else {
- writeUleb128(OS, 1, "result Count");
- writeValueType(OS, Sig.ReturnType, "result type");
+ writeUleb128(OS, Sig.Returns.size(), "result Count");
+ if (Sig.Returns.size()) {
+ writeValueType(OS, Sig.Returns[0], "result type");
}
}
@@ -117,7 +116,8 @@ void wasm::writeLimits(raw_ostream &OS,
}
void wasm::writeGlobalType(raw_ostream &OS, const WasmGlobalType &Type) {
- writeValueType(OS, Type.Type, "global type");
+ // TODO: Update WasmGlobalType to use ValType and remove this cast.
+ writeValueType(OS, ValType(Type.Type), "global type");
writeU8(OS, Type.Mutable, "global mutable");
}
@@ -195,16 +195,16 @@ std::string lld::toString(ValType Type)
std::string lld::toString(const WasmSignature &Sig) {
SmallString<128> S("(");
- for (uint32_t Type : Sig.ParamTypes) {
+ for (ValType Type : Sig.Params) {
if (S.size() != 1)
S += ", ";
- S += toString(static_cast<ValType>(Type));
+ S += toString(Type);
}
S += ") -> ";
- if (Sig.ReturnType == WASM_TYPE_NORESULT)
+ if (Sig.Returns.size() == 0)
S += "void";
else
- S += toString(static_cast<ValType>(Sig.ReturnType));
+ S += toString(Sig.Returns[0]);
return S.str();
}
Modified: lld/trunk/wasm/WriterUtils.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/WriterUtils.h?rev=343734&r1=343733&r2=343734&view=diff
==============================================================================
--- lld/trunk/wasm/WriterUtils.h (original)
+++ lld/trunk/wasm/WriterUtils.h Wed Oct 3 15:25:32 2018
@@ -35,7 +35,8 @@ void writeU8(raw_ostream &OS, uint8_t by
void writeU32(raw_ostream &OS, uint32_t Number, const Twine &Msg);
-void writeValueType(raw_ostream &OS, uint8_t Type, const Twine &Msg);
+void writeValueType(raw_ostream &OS, llvm::wasm::ValType Type,
+ const Twine &Msg);
void writeSig(raw_ostream &OS, const llvm::wasm::WasmSignature &Sig);
More information about the llvm-commits
mailing list