limits = {0, tableSize, 0};
else
limits = {WASM_LIMITS_FLAG_HAS_MAX, tableSize, tableSize};
- writeTableType(os, WasmTable{0, WASM_TYPE_FUNCREF, limits});
+ writeTableType(os, WasmTableType{WASM_TYPE_FUNCREF, limits});
}
void MemorySection::writeBody() {
writeEventType(os, event.Type);
}
-void writeTableType(raw_ostream &os, const llvm::wasm::WasmTable &type) {
+void writeTableType(raw_ostream &os, const WasmTableType &type) {
writeU8(os, WASM_TYPE_FUNCREF, "table type");
writeLimits(os, type.Limits);
}
void writeEvent(raw_ostream &os, const llvm::wasm::WasmEvent &event);
-void writeTableType(raw_ostream &os, const llvm::wasm::WasmTable &type);
+void writeTableType(raw_ostream &os, const llvm::wasm::WasmTableType &type);
void writeImport(raw_ostream &os, const llvm::wasm::WasmImport &import);
uint64_t Maximum;
};
-struct WasmTable {
- uint32_t Index;
+struct WasmTableType {
uint8_t ElemType;
WasmLimits Limits;
};
+struct WasmTable {
+ uint32_t Index;
+ WasmTableType Type;
+ StringRef SymbolName; // from the "linking" section
+};
+
struct WasmInitExpr {
uint8_t Opcode;
union {
union {
uint32_t SigIndex;
WasmGlobalType Global;
- WasmTable Table;
+ WasmTableType Table;
WasmLimits Memory;
WasmEventType Event;
};
encodeULEB128(Tables.size(), W->OS);
for (const wasm::WasmTable &Table : Tables) {
- encodeULEB128(Table.ElemType, W->OS);
- encodeULEB128(Table.Limits.Flags, W->OS);
- encodeULEB128(Table.Limits.Initial, W->OS);
- if (Table.Limits.Flags & wasm::WASM_LIMITS_FLAG_HAS_MAX)
- encodeULEB128(Table.Limits.Maximum, W->OS);
+ encodeULEB128(Table.Type.ElemType, W->OS);
+ encodeULEB128(Table.Type.Limits.Flags, W->OS);
+ encodeULEB128(Table.Type.Limits.Initial, W->OS);
+ if (Table.Type.Limits.Flags & wasm::WASM_LIMITS_FLAG_HAS_MAX)
+ encodeULEB128(Table.Type.Limits.Maximum, W->OS);
}
endSection(Section);
}
if (WS.isDefined()) {
assert(WasmIndices.count(&WS) == 0);
wasm::WasmTable Table;
- Table.ElemType = static_cast<uint8_t>(WS.getTableType());
Table.Index = NumTableImports + Tables.size();
+ Table.Type.ElemType = static_cast<uint8_t>(WS.getTableType());
// FIXME: Work on custom limits is ongoing
- Table.Limits = {wasm::WASM_LIMITS_FLAG_NONE, 0, 0};
+ Table.Type.Limits = {wasm::WASM_LIMITS_FLAG_NONE, 0, 0};
WasmIndices[&WS] = Table.Index;
Tables.push_back(Table);
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,
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);
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 &&
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",
} // namespace
-static WasmYAML::Table makeTable(const wasm::WasmTable &Table) {
- WasmYAML::Table T;
- T.ElemType = Table.ElemType;
- T.TableLimits.Flags = Table.Limits.Flags;
- T.TableLimits.Initial = Table.Limits.Initial;
- T.TableLimits.Maximum = Table.Limits.Maximum;
- T.Index = Table.Index;
- return T;
-}
-
static WasmYAML::Limits makeLimits(const wasm::WasmLimits &Limits) {
WasmYAML::Limits L;
L.Flags = Limits.Flags;
return L;
}
+static WasmYAML::Table makeTable(uint32_t Index,
+ const wasm::WasmTableType &Type) {
+ WasmYAML::Table T;
+ T.Index = Index;
+ T.ElemType = Type.ElemType;
+ T.TableLimits = makeLimits(Type.Limits);
+ return T;
+}
+
std::unique_ptr<WasmYAML::CustomSection>
WasmDumper::dumpCustomSection(const WasmSection &WasmSec) {
std::unique_ptr<WasmYAML::CustomSection> CustomSec;
Im.EventImport.SigIndex = Import.Event.SigIndex;
break;
case wasm::WASM_EXTERNAL_TABLE:
- Im.TableImport = makeTable(Import.Table);
+ // FIXME: Currently we always output an index of 0 for any imported
+ // table.
+ Im.TableImport = makeTable(0, Import.Table);
break;
case wasm::WASM_EXTERNAL_MEMORY:
Im.Memory = makeLimits(Import.Memory);
case wasm::WASM_SEC_TABLE: {
auto TableSec = std::make_unique<WasmYAML::TableSection>();
for (const wasm::WasmTable &Table : Obj.tables()) {
- TableSec->Tables.push_back(makeTable(Table));
+ TableSec->Tables.push_back(makeTable(Table.Index, Table.Type));
}
S = std::move(TableSec);
break;