aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Object/WasmObjectFile.cpp
diff options
context:
space:
mode:
authorAndy Wingo <wingo@igalia.com>2020-11-25 07:54:31 -0800
committerSam Clegg <sbc@chromium.org>2020-11-25 08:00:08 -0800
commit1933c9d41a08cfc4c5c0ae80eedf466b5ae7ef01 (patch)
treeb478a92508bba5d812a4a5f00e0497b101004d97 /llvm/lib/Object/WasmObjectFile.cpp
parentedd675643d5ff49e6ea01af2a2a9b40498b3226c (diff)
downloadllvm-1933c9d41a08cfc4c5c0ae80eedf466b5ae7ef01.zip
llvm-1933c9d41a08cfc4c5c0ae80eedf466b5ae7ef01.tar.gz
llvm-1933c9d41a08cfc4c5c0ae80eedf466b5ae7ef01.tar.bz2
[WebAssembly] Factor out WasmTableType in binary format
This commit factors out a WasmTableType definition from WasmTable, as is the case for WasmGlobal and other data types. Also add support for extracting the SymbolName for a table from the linking section's symbol table. Differential Revision: https://reviews.llvm.org/D91849
Diffstat (limited to 'llvm/lib/Object/WasmObjectFile.cpp')
-rw-r--r--llvm/lib/Object/WasmObjectFile.cpp23
1 files changed, 12 insertions, 11 deletions
diff --git a/llvm/lib/Object/WasmObjectFile.cpp b/llvm/lib/Object/WasmObjectFile.cpp
index 2504fda..a9a0ad5 100644
--- a/llvm/lib/Object/WasmObjectFile.cpp
+++ b/llvm/lib/Object/WasmObjectFile.cpp
@@ -214,12 +214,11 @@ static wasm::WasmLimits readLimits(WasmObjectFile::ReadContext &Ctx) {
return Result;
}
-static wasm::WasmTable readTable(WasmObjectFile::ReadContext &Ctx) {
- wasm::WasmTable Table;
- Table.ElemType = readUint8(Ctx);
- Table.Limits = readLimits(Ctx);
- // The caller needs to set Table.Index field for Table
- return Table;
+static wasm::WasmTableType readTableType(WasmObjectFile::ReadContext &Ctx) {
+ wasm::WasmTableType TableType;
+ TableType.ElemType = readUint8(Ctx);
+ TableType.Limits = readLimits(Ctx);
+ return TableType;
}
static Error readSection(WasmSection &Section, WasmObjectFile::ReadContext &Ctx,
@@ -597,7 +596,9 @@ Error WasmObjectFile::parseLinkingSectionSymtab(ReadContext &Ctx) {
Info.Name = readString(Ctx);
unsigned TableIndex = Info.ElementIndex - NumImportedTables;
wasm::WasmTable &Table = Tables[TableIndex];
- TableType = Table.ElemType;
+ TableType = Table.Type.ElemType;
+ if (Table.SymbolName.empty())
+ Table.SymbolName = Info.Name;
} else {
return make_error<GenericBinaryError>("undefined table symbol",
object_error::parse_failed);
@@ -1014,8 +1015,7 @@ Error WasmObjectFile::parseImportSection(ReadContext &Ctx) {
HasMemory64 = true;
break;
case wasm::WASM_EXTERNAL_TABLE: {
- Im.Table = readTable(Ctx);
- Im.Table.Index = NumImportedTables + Tables.size();
+ Im.Table = readTableType(Ctx);
NumImportedTables++;
auto ElemType = Im.Table.ElemType;
if (ElemType != wasm::WASM_TYPE_FUNCREF &&
@@ -1063,10 +1063,11 @@ Error WasmObjectFile::parseTableSection(ReadContext &Ctx) {
uint32_t Count = readVaruint32(Ctx);
Tables.reserve(Count);
while (Count--) {
- wasm::WasmTable T = readTable(Ctx);
+ wasm::WasmTable T;
+ T.Type = readTableType(Ctx);
T.Index = NumImportedTables + Tables.size();
Tables.push_back(T);
- auto ElemType = Tables.back().ElemType;
+ auto ElemType = Tables.back().Type.ElemType;
if (ElemType != wasm::WASM_TYPE_FUNCREF &&
ElemType != wasm::WASM_TYPE_EXTERNREF) {
return make_error<GenericBinaryError>("Invalid table element type",