Commit 1933c9d4 authored by Andy Wingo's avatar Andy Wingo Committed by Sam Clegg
Browse files

[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
parent edd67564
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -223,7 +223,7 @@ void TableSection::writeBody() {
    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() {
+1 −1
Original line number Diff line number Diff line
@@ -195,7 +195,7 @@ void writeEvent(raw_ostream &os, const WasmEvent &event) {
  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);
}
+1 −1
Original line number Diff line number Diff line
@@ -54,7 +54,7 @@ void writeEventType(raw_ostream &os, const llvm::wasm::WasmEventType &type);

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);

+8 −3
Original line number Diff line number Diff line
@@ -67,12 +67,17 @@ struct WasmLimits {
  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 {
@@ -115,7 +120,7 @@ struct WasmImport {
  union {
    uint32_t SigIndex;
    WasmGlobalType Global;
    WasmTable Table;
    WasmTableType Table;
    WasmLimits Memory;
    WasmEventType Event;
  };
+7 −7
Original line number Diff line number Diff line
@@ -848,11 +848,11 @@ void WasmObjectWriter::writeTableSection(ArrayRef<wasm::WasmTable> Tables) {

  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);
}
@@ -1527,10 +1527,10 @@ uint64_t WasmObjectWriter::writeOneObject(MCAssembler &Asm,
      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);
Loading