[WebAssembly] Added .tabletype to asm and multiple table support in obj files

Adds more testing in basic-assembly.s and a new test tables.s.
Adds support to yaml reading and writing of tables as well.

Differential Revision: https://reviews.llvm.org/D88815
This commit is contained in:
Paulo Matos 2020-10-13 07:13:10 -07:00 committed by Sam Clegg
parent a8f1790fdb
commit 388fb67b0d
50 changed files with 279 additions and 33 deletions

View File

@ -24,7 +24,8 @@ _start:
# CHECK-NEXT: FunctionTypes: [ 0 ] # CHECK-NEXT: FunctionTypes: [ 0 ]
# CHECK-NEXT: - Type: TABLE # CHECK-NEXT: - Type: TABLE
# CHECK-NEXT: Tables: # CHECK-NEXT: Tables:
# CHECK-NEXT: - ElemType: FUNCREF # CHECK-NEXT: - Index: 0
# CHECK-NEXT: ElemType: FUNCREF
# CHECK-NEXT: Limits: # CHECK-NEXT: Limits:
# CHECK-NEXT: Flags: [ HAS_MAX ] # CHECK-NEXT: Flags: [ HAS_MAX ]
# CHECK-NEXT: Initial: 0x00000001 # CHECK-NEXT: Initial: 0x00000001

View File

@ -63,7 +63,8 @@ define void @call_ptr(i64 (i64)* %arg) {
; CHECK-NEXT: FunctionTypes: [ 0, 3, 1, 3, 4 ] ; CHECK-NEXT: FunctionTypes: [ 0, 3, 1, 3, 4 ]
; CHECK-NEXT: - Type: TABLE ; CHECK-NEXT: - Type: TABLE
; CHECK-NEXT: Tables: ; CHECK-NEXT: Tables:
; CHECK-NEXT: - ElemType: FUNCREF ; CHECK-NEXT: - Index: 0
; CHECK-NEXT: ElemType: FUNCREF
; CHECK-NEXT: Limits: ; CHECK-NEXT: Limits:
; CHECK-NEXT: Flags: [ HAS_MAX ] ; CHECK-NEXT: Flags: [ HAS_MAX ]
; CHECK-NEXT: Initial: 0x00000003 ; CHECK-NEXT: Initial: 0x00000003

View File

@ -6,7 +6,8 @@
# CHECK: - Type: TABLE # CHECK: - Type: TABLE
# CHECK-NEXT: Tables: # CHECK-NEXT: Tables:
# CHECK-NEXT: - ElemType: FUNCREF # CHECK-NEXT: - Index: 0
# CHECK-NEXT: ElemType: FUNCREF
# CHECK-NEXT: Limits: # CHECK-NEXT: Limits:
# CHECK-NEXT: Flags: [ HAS_MAX ] # CHECK-NEXT: Flags: [ HAS_MAX ]
# CHECK-NEXT: Initial: 0x00000001 # CHECK-NEXT: Initial: 0x00000001

View File

@ -6,7 +6,8 @@
# CHECK: - Type: TABLE # CHECK: - Type: TABLE
# CHECK-NEXT: Tables: # CHECK-NEXT: Tables:
# CHECK-NEXT: - ElemType: FUNCREF # CHECK-NEXT: - Index: 0
# CHECK-NEXT: ElemType: FUNCREF
# CHECK-NEXT: Limits: # CHECK-NEXT: Limits:
# CHECK-NEXT: Initial: 0x00000001 # CHECK-NEXT: Initial: 0x00000001
# CHECK-NEXT: - Type: # CHECK-NEXT: - Type:

View File

@ -10,6 +10,7 @@
# CHECK-NEXT: Field: __indirect_function_table # CHECK-NEXT: Field: __indirect_function_table
# CHECK-NEXT: Kind: TABLE # CHECK-NEXT: Kind: TABLE
# CHECK-NEXT: Table: # CHECK-NEXT: Table:
# CHECK-NEXT: Index: 0
# CHECK-NEXT: ElemType: FUNCREF # CHECK-NEXT: ElemType: FUNCREF
# CHECK-NEXT: Limits: # CHECK-NEXT: Limits:
# CHECK-NEXT: Initial: 0x00000001 # CHECK-NEXT: Initial: 0x00000001

View File

@ -37,7 +37,8 @@ entry:
; CHECK-NEXT: FunctionTypes: [ 0, 1 ] ; CHECK-NEXT: FunctionTypes: [ 0, 1 ]
; CHECK-NEXT: - Type: TABLE ; CHECK-NEXT: - Type: TABLE
; CHECK-NEXT: Tables: ; CHECK-NEXT: Tables:
; CHECK-NEXT: - ElemType: FUNCREF ; CHECK-NEXT: - Index: 0
; CHECK-NEXT: ElemType: FUNCREF
; CHECK-NEXT: Limits: ; CHECK-NEXT: Limits:
; CHECK-NEXT: Flags: [ HAS_MAX ] ; CHECK-NEXT: Flags: [ HAS_MAX ]
; CHECK-NEXT: Initial: 0x00000001 ; CHECK-NEXT: Initial: 0x00000001

View File

@ -18,7 +18,8 @@
; CHECK-NEXT: 0, 0 ] ; CHECK-NEXT: 0, 0 ]
; CHECK-NEXT: - Type: TABLE ; CHECK-NEXT: - Type: TABLE
; CHECK-NEXT: Tables: ; CHECK-NEXT: Tables:
; CHECK-NEXT: - ElemType: FUNCREF ; CHECK-NEXT: - Index: 0
; CHECK-NEXT: ElemType: FUNCREF
; CHECK-NEXT: Limits: ; CHECK-NEXT: Limits:
; CHECK-NEXT: Flags: [ HAS_MAX ] ; CHECK-NEXT: Flags: [ HAS_MAX ]
; CHECK-NEXT: Initial: 0x00000007 ; CHECK-NEXT: Initial: 0x00000007
@ -229,7 +230,8 @@
; RELOC-NEXT: 0, 0 ] ; RELOC-NEXT: 0, 0 ]
; RELOC-NEXT: - Type: TABLE ; RELOC-NEXT: - Type: TABLE
; RELOC-NEXT: Tables: ; RELOC-NEXT: Tables:
; RELOC-NEXT: - ElemType: FUNCREF ; RELOC-NEXT: - Index: 0
; RELOC-NEXT: ElemType: FUNCREF
; RELOC-NEXT: Limits: ; RELOC-NEXT: Limits:
; RELOC-NEXT: Flags: [ HAS_MAX ] ; RELOC-NEXT: Flags: [ HAS_MAX ]
; RELOC-NEXT: Initial: 0x00000007 ; RELOC-NEXT: Initial: 0x00000007

View File

@ -36,6 +36,7 @@ define void @_start() {
; CHECK-NEXT: Field: __indirect_function_table ; CHECK-NEXT: Field: __indirect_function_table
; CHECK-NEXT: Kind: TABLE ; CHECK-NEXT: Kind: TABLE
; CHECK-NEXT: Table: ; CHECK-NEXT: Table:
; CHECK-NEXT: Index: 0
; CHECK-NEXT: ElemType: FUNCREF ; CHECK-NEXT: ElemType: FUNCREF
; CHECK-NEXT: Limits: ; CHECK-NEXT: Limits:
; CHECK-NEXT: Initial: 0x00000001 ; CHECK-NEXT: Initial: 0x00000001

View File

@ -67,7 +67,8 @@ entry:
; CHECK-NEXT: FunctionTypes: [ 2, 1, 1 ] ; CHECK-NEXT: FunctionTypes: [ 2, 1, 1 ]
; CHECK-NEXT: - Type: TABLE ; CHECK-NEXT: - Type: TABLE
; CHECK-NEXT: Tables: ; CHECK-NEXT: Tables:
; CHECK-NEXT: - ElemType: FUNCREF ; CHECK-NEXT: - Index: 0
; CHECK-NEXT: ElemType: FUNCREF
; CHECK-NEXT: Limits: ; CHECK-NEXT: Limits:
; CHECK-NEXT: Flags: [ HAS_MAX ] ; CHECK-NEXT: Flags: [ HAS_MAX ]
; CHECK-NEXT: Initial: 0x00000004 ; CHECK-NEXT: Initial: 0x00000004

View File

@ -19,6 +19,7 @@ Sections:
Field: __indirect_function_table Field: __indirect_function_table
Kind: TABLE Kind: TABLE
Table: Table:
Index: 0
ElemType: FUNCREF ElemType: FUNCREF
Limits: Limits:
Initial: 0x00000000 Initial: 0x00000000

View File

@ -27,6 +27,7 @@ Sections:
Field: __indirect_function_table Field: __indirect_function_table
Kind: TABLE Kind: TABLE
Table: Table:
Index: 0
ElemType: FUNCREF ElemType: FUNCREF
Limits: Limits:
Initial: 0x00000000 Initial: 0x00000000

View File

@ -72,6 +72,7 @@ declare void @func_external()
; CHECK-NEXT: Field: __indirect_function_table ; CHECK-NEXT: Field: __indirect_function_table
; CHECK-NEXT: Kind: TABLE ; CHECK-NEXT: Kind: TABLE
; CHECK-NEXT: Table: ; CHECK-NEXT: Table:
; CHECK-NEXT: Index: 0
; CHECK-NEXT: ElemType: FUNCREF ; CHECK-NEXT: ElemType: FUNCREF
; CHECK-NEXT: Limits: ; CHECK-NEXT: Limits:
; CHECK-NEXT: Initial: 0x00000002 ; CHECK-NEXT: Initial: 0x00000002

View File

@ -32,7 +32,8 @@ entry:
; CHECK-NEXT: FunctionTypes: [ 0 ] ; CHECK-NEXT: FunctionTypes: [ 0 ]
; CHECK-NEXT: - Type: TABLE ; CHECK-NEXT: - Type: TABLE
; CHECK-NEXT: Tables: ; CHECK-NEXT: Tables:
; CHECK-NEXT: - ElemType: FUNCREF ; CHECK-NEXT: - Index: 0
; CHECK-NEXT: ElemType: FUNCREF
; CHECK-NEXT: Limits: ; CHECK-NEXT: Limits:
; CHECK-NEXT: Flags: [ HAS_MAX ] ; CHECK-NEXT: Flags: [ HAS_MAX ]
; CHECK-NEXT: Initial: 0x00000001 ; CHECK-NEXT: Initial: 0x00000001

View File

@ -46,7 +46,8 @@ define i32 @callWeakFuncs() {
; CHECK-NEXT: FunctionTypes: [ 0, 0, 1, 2 ] ; CHECK-NEXT: FunctionTypes: [ 0, 0, 1, 2 ]
; CHECK-NEXT: - Type: TABLE ; CHECK-NEXT: - Type: TABLE
; CHECK-NEXT: Tables: ; CHECK-NEXT: Tables:
; CHECK-NEXT: - ElemType: FUNCREF ; CHECK-NEXT: - Index: 0
; CHECK-NEXT: ElemType: FUNCREF
; CHECK-NEXT: Limits: ; CHECK-NEXT: Limits:
; CHECK-NEXT: Flags: [ HAS_MAX ] ; CHECK-NEXT: Flags: [ HAS_MAX ]
; CHECK-NEXT: Initial: 0x00000001 ; CHECK-NEXT: Initial: 0x00000001

View File

@ -36,7 +36,8 @@ entry:
; CHECK-NEXT: FunctionTypes: [ 0, 1, 0, 0, 0, 0, 0 ] ; CHECK-NEXT: FunctionTypes: [ 0, 1, 0, 0, 0, 0, 0 ]
; CHECK-NEXT: - Type: TABLE ; CHECK-NEXT: - Type: TABLE
; CHECK-NEXT: Tables: ; CHECK-NEXT: Tables:
; CHECK-NEXT: - ElemType: FUNCREF ; CHECK-NEXT: - Index: 0
; CHECK-NEXT: ElemType: FUNCREF
; CHECK-NEXT: Limits: ; CHECK-NEXT: Limits:
; CHECK-NEXT: Flags: [ HAS_MAX ] ; CHECK-NEXT: Flags: [ HAS_MAX ]
; CHECK-NEXT: Initial: 0x00000003 ; CHECK-NEXT: Initial: 0x00000003

View File

@ -33,7 +33,8 @@ entry:
; CHECK-NEXT: FunctionTypes: [ 0, 1, 1, 1, 1, 1 ] ; CHECK-NEXT: FunctionTypes: [ 0, 1, 1, 1, 1, 1 ]
; CHECK-NEXT: - Type: TABLE ; CHECK-NEXT: - Type: TABLE
; CHECK-NEXT: Tables: ; CHECK-NEXT: Tables:
; CHECK-NEXT: - ElemType: FUNCREF ; CHECK-NEXT: - Index: 0
; CHECK-NEXT: ElemType: FUNCREF
; CHECK-NEXT: Limits: ; CHECK-NEXT: Limits:
; CHECK-NEXT: Flags: [ HAS_MAX ] ; CHECK-NEXT: Flags: [ HAS_MAX ]
; CHECK-NEXT: Initial: 0x00000002 ; CHECK-NEXT: Initial: 0x00000002
@ -149,7 +150,8 @@ entry:
; RELOC-NEXT: FunctionTypes: [ 0, 1, 1, 1, 1, 1 ] ; RELOC-NEXT: FunctionTypes: [ 0, 1, 1, 1, 1, 1 ]
; RELOC-NEXT: - Type: TABLE ; RELOC-NEXT: - Type: TABLE
; RELOC-NEXT: Tables: ; RELOC-NEXT: Tables:
; RELOC-NEXT: - ElemType: FUNCREF ; RELOC-NEXT: - Index: 0
; RELOC-NEXT: ElemType: FUNCREF
; RELOC-NEXT: Limits: ; RELOC-NEXT: Limits:
; RELOC-NEXT: Flags: [ HAS_MAX ] ; RELOC-NEXT: Flags: [ HAS_MAX ]
; RELOC-NEXT: Initial: 0x00000002 ; RELOC-NEXT: Initial: 0x00000002

View File

@ -33,7 +33,8 @@ entry:
; CHECK-NEXT: FunctionTypes: [ 0, 1, 1, 1 ] ; CHECK-NEXT: FunctionTypes: [ 0, 1, 1, 1 ]
; CHECK-NEXT: - Type: TABLE ; CHECK-NEXT: - Type: TABLE
; CHECK-NEXT: Tables: ; CHECK-NEXT: Tables:
; CHECK-NEXT: - ElemType: FUNCREF ; CHECK-NEXT: - Index: 0
; CHECK-NEXT: ElemType: FUNCREF
; CHECK-NEXT: Limits: ; CHECK-NEXT: Limits:
; CHECK-NEXT: Flags: [ HAS_MAX ] ; CHECK-NEXT: Flags: [ HAS_MAX ]
; CHECK-NEXT: Initial: 0x00000002 ; CHECK-NEXT: Initial: 0x00000002

View File

@ -44,7 +44,8 @@ entry:
; CHECK-NEXT: FunctionTypes: [ 0, 0, 1 ] ; CHECK-NEXT: FunctionTypes: [ 0, 0, 1 ]
; CHECK-NEXT: - Type: TABLE ; CHECK-NEXT: - Type: TABLE
; CHECK-NEXT: Tables: ; CHECK-NEXT: Tables:
; CHECK-NEXT: - ElemType: FUNCREF ; CHECK-NEXT: - Index: 0
; CHECK-NEXT: ElemType: FUNCREF
; CHECK-NEXT: Limits: ; CHECK-NEXT: Limits:
; CHECK-NEXT: Flags: [ HAS_MAX ] ; CHECK-NEXT: Flags: [ HAS_MAX ]
; CHECK-NEXT: Initial: 0x00000001 ; CHECK-NEXT: Initial: 0x00000001

View File

@ -223,7 +223,7 @@ void TableSection::writeBody() {
limits = {0, tableSize, 0}; limits = {0, tableSize, 0};
else else
limits = {WASM_LIMITS_FLAG_HAS_MAX, tableSize, tableSize}; limits = {WASM_LIMITS_FLAG_HAS_MAX, tableSize, tableSize};
writeTableType(os, WasmTable{WASM_TYPE_FUNCREF, limits}); writeTableType(os, WasmTable{0, WASM_TYPE_FUNCREF, limits});
} }
void MemorySection::writeBody() { void MemorySection::writeBody() {

View File

@ -32,6 +32,8 @@ std::string toString(ValType type) {
return "v128"; return "v128";
case ValType::EXNREF: case ValType::EXNREF:
return "exnref"; return "exnref";
case ValType::FUNCREF:
return "funcref";
case ValType::EXTERNREF: case ValType::EXTERNREF:
return "externref"; return "externref";
} }

View File

@ -41,7 +41,7 @@ struct WasmDylinkInfo {
uint32_t MemoryAlignment; // P2 alignment of memory uint32_t MemoryAlignment; // P2 alignment of memory
uint32_t TableSize; // Table size in elements uint32_t TableSize; // Table size in elements
uint32_t TableAlignment; // P2 alignment of table uint32_t TableAlignment; // P2 alignment of table
std::vector<StringRef> Needed; // Shared library depenedencies std::vector<StringRef> Needed; // Shared library dependencies
}; };
struct WasmProducerInfo { struct WasmProducerInfo {
@ -68,6 +68,7 @@ struct WasmLimits {
}; };
struct WasmTable { struct WasmTable {
uint32_t Index;
uint8_t ElemType; uint8_t ElemType;
WasmLimits Limits; WasmLimits Limits;
}; };
@ -325,6 +326,7 @@ enum WasmSymbolType : unsigned {
WASM_SYMBOL_TYPE_GLOBAL = 0x2, WASM_SYMBOL_TYPE_GLOBAL = 0x2,
WASM_SYMBOL_TYPE_SECTION = 0x3, WASM_SYMBOL_TYPE_SECTION = 0x3,
WASM_SYMBOL_TYPE_EVENT = 0x4, WASM_SYMBOL_TYPE_EVENT = 0x4,
WASM_SYMBOL_TYPE_TABLE = 0x5,
}; };
// Kinds of event attributes. // Kinds of event attributes.
@ -361,6 +363,7 @@ enum class ValType {
F64 = WASM_TYPE_F64, F64 = WASM_TYPE_F64,
V128 = WASM_TYPE_V128, V128 = WASM_TYPE_V128,
EXNREF = WASM_TYPE_EXNREF, EXNREF = WASM_TYPE_EXNREF,
FUNCREF = WASM_TYPE_FUNCREF,
EXTERNREF = WASM_TYPE_EXTERNREF, EXTERNREF = WASM_TYPE_EXTERNREF,
}; };

View File

@ -25,6 +25,7 @@ class MCSymbolWasm : public MCSymbol {
Optional<StringRef> ExportName; Optional<StringRef> ExportName;
wasm::WasmSignature *Signature = nullptr; wasm::WasmSignature *Signature = nullptr;
Optional<wasm::WasmGlobalType> GlobalType; Optional<wasm::WasmGlobalType> GlobalType;
Optional<wasm::ValType> TableType;
Optional<wasm::WasmEventType> EventType; Optional<wasm::WasmEventType> EventType;
/// An expression describing how to calculate the size of a symbol. If a /// An expression describing how to calculate the size of a symbol. If a
@ -42,6 +43,7 @@ public:
bool isFunction() const { return Type == wasm::WASM_SYMBOL_TYPE_FUNCTION; } bool isFunction() const { return Type == wasm::WASM_SYMBOL_TYPE_FUNCTION; }
bool isData() const { return Type == wasm::WASM_SYMBOL_TYPE_DATA; } bool isData() const { return Type == wasm::WASM_SYMBOL_TYPE_DATA; }
bool isGlobal() const { return Type == wasm::WASM_SYMBOL_TYPE_GLOBAL; } bool isGlobal() const { return Type == wasm::WASM_SYMBOL_TYPE_GLOBAL; }
bool isTable() const { return Type == wasm::WASM_SYMBOL_TYPE_TABLE; }
bool isSection() const { return Type == wasm::WASM_SYMBOL_TYPE_SECTION; } bool isSection() const { return Type == wasm::WASM_SYMBOL_TYPE_SECTION; }
bool isEvent() const { return Type == wasm::WASM_SYMBOL_TYPE_EVENT; } bool isEvent() const { return Type == wasm::WASM_SYMBOL_TYPE_EVENT; }
wasm::WasmSymbolType getType() const { return Type; } wasm::WasmSymbolType getType() const { return Type; }
@ -109,6 +111,12 @@ public:
} }
void setGlobalType(wasm::WasmGlobalType GT) { GlobalType = GT; } void setGlobalType(wasm::WasmGlobalType GT) { GlobalType = GT; }
const wasm::ValType &getTableType() const {
assert(TableType.hasValue());
return TableType.getValue();
}
void setTableType(wasm::ValType TT) { TableType = TT; }
const wasm::WasmEventType &getEventType() const { const wasm::WasmEventType &getEventType() const {
assert(EventType.hasValue()); assert(EventType.hasValue());
return EventType.getValue(); return EventType.getValue();

View File

@ -35,14 +35,15 @@ namespace object {
class WasmSymbol { class WasmSymbol {
public: public:
WasmSymbol(const wasm::WasmSymbolInfo &Info, WasmSymbol(const wasm::WasmSymbolInfo &Info,
const wasm::WasmGlobalType *GlobalType, const wasm::WasmGlobalType *GlobalType, const uint8_t TableType,
const wasm::WasmEventType *EventType, const wasm::WasmEventType *EventType,
const wasm::WasmSignature *Signature) const wasm::WasmSignature *Signature)
: Info(Info), GlobalType(GlobalType), EventType(EventType), : Info(Info), GlobalType(GlobalType), TableType(TableType),
Signature(Signature) {} EventType(EventType), Signature(Signature) {}
const wasm::WasmSymbolInfo &Info; const wasm::WasmSymbolInfo &Info;
const wasm::WasmGlobalType *GlobalType; const wasm::WasmGlobalType *GlobalType;
const uint8_t TableType;
const wasm::WasmEventType *EventType; const wasm::WasmEventType *EventType;
const wasm::WasmSignature *Signature; const wasm::WasmSignature *Signature;
@ -149,6 +150,7 @@ public:
ArrayRef<wasm::WasmFunctionName> debugNames() const { return DebugNames; } ArrayRef<wasm::WasmFunctionName> debugNames() const { return DebugNames; }
uint32_t startFunction() const { return StartFunction; } uint32_t startFunction() const { return StartFunction; }
uint32_t getNumImportedGlobals() const { return NumImportedGlobals; } uint32_t getNumImportedGlobals() const { return NumImportedGlobals; }
uint32_t getNumImportedTables() const { return NumImportedTables; }
uint32_t getNumImportedFunctions() const { return NumImportedFunctions; } uint32_t getNumImportedFunctions() const { return NumImportedFunctions; }
uint32_t getNumImportedEvents() const { return NumImportedEvents; } uint32_t getNumImportedEvents() const { return NumImportedEvents; }
uint32_t getNumSections() const { return Sections.size(); } uint32_t getNumSections() const { return Sections.size(); }
@ -214,7 +216,9 @@ private:
bool isValidFunctionIndex(uint32_t Index) const; bool isValidFunctionIndex(uint32_t Index) const;
bool isDefinedFunctionIndex(uint32_t Index) const; bool isDefinedFunctionIndex(uint32_t Index) const;
bool isValidGlobalIndex(uint32_t Index) const; bool isValidGlobalIndex(uint32_t Index) const;
bool isValidTableIndex(uint32_t Index) const;
bool isDefinedGlobalIndex(uint32_t Index) const; bool isDefinedGlobalIndex(uint32_t Index) const;
bool isDefinedTableIndex(uint32_t Index) const;
bool isValidEventIndex(uint32_t Index) const; bool isValidEventIndex(uint32_t Index) const;
bool isDefinedEventIndex(uint32_t Index) const; bool isDefinedEventIndex(uint32_t Index) const;
bool isValidFunctionSymbol(uint32_t Index) const; bool isValidFunctionSymbol(uint32_t Index) const;
@ -285,6 +289,7 @@ private:
bool HasMemory64 = false; bool HasMemory64 = false;
wasm::WasmLinkingData LinkingData; wasm::WasmLinkingData LinkingData;
uint32_t NumImportedGlobals = 0; uint32_t NumImportedGlobals = 0;
uint32_t NumImportedTables = 0;
uint32_t NumImportedFunctions = 0; uint32_t NumImportedFunctions = 0;
uint32_t NumImportedEvents = 0; uint32_t NumImportedEvents = 0;
uint32_t CodeSection = 0; uint32_t CodeSection = 0;

View File

@ -53,6 +53,7 @@ struct Limits {
struct Table { struct Table {
TableType ElemType; TableType ElemType;
Limits TableLimits; Limits TableLimits;
uint32_t Index;
}; };
struct Export { struct Export {

View File

@ -14,6 +14,8 @@ std::string llvm::wasm::toString(wasm::WasmSymbolType Type) {
return "WASM_SYMBOL_TYPE_FUNCTION"; return "WASM_SYMBOL_TYPE_FUNCTION";
case wasm::WASM_SYMBOL_TYPE_GLOBAL: case wasm::WASM_SYMBOL_TYPE_GLOBAL:
return "WASM_SYMBOL_TYPE_GLOBAL"; return "WASM_SYMBOL_TYPE_GLOBAL";
case wasm::WASM_SYMBOL_TYPE_TABLE:
return "WASM_SYMBOL_TYPE_TABLE";
case wasm::WASM_SYMBOL_TYPE_DATA: case wasm::WASM_SYMBOL_TYPE_DATA:
return "WASM_SYMBOL_TYPE_DATA"; return "WASM_SYMBOL_TYPE_DATA";
case wasm::WASM_SYMBOL_TYPE_SECTION: case wasm::WASM_SYMBOL_TYPE_SECTION:

View File

@ -194,8 +194,8 @@ class WasmObjectWriter : public MCObjectWriter {
// Maps function symbols to the table element index space. Used // Maps function symbols to the table element index space. Used
// for TABLE_INDEX relocation types (i.e. address taken functions). // for TABLE_INDEX relocation types (i.e. address taken functions).
DenseMap<const MCSymbolWasm *, uint32_t> TableIndices; DenseMap<const MCSymbolWasm *, uint32_t> TableIndices;
// Maps function/global symbols to the function/global/event/section index // Maps function/global/table symbols to the
// space. // function/global/table/event/section index space.
DenseMap<const MCSymbolWasm *, uint32_t> WasmIndices; DenseMap<const MCSymbolWasm *, uint32_t> WasmIndices;
DenseMap<const MCSymbolWasm *, uint32_t> GOTIndices; DenseMap<const MCSymbolWasm *, uint32_t> GOTIndices;
// Maps data symbols to the Wasm segment and offset/size with the segment. // Maps data symbols to the Wasm segment and offset/size with the segment.
@ -218,6 +218,9 @@ class WasmObjectWriter : public MCObjectWriter {
SmallVector<WasmDataSegment, 4> DataSegments; SmallVector<WasmDataSegment, 4> DataSegments;
unsigned NumFunctionImports = 0; unsigned NumFunctionImports = 0;
unsigned NumGlobalImports = 0; unsigned NumGlobalImports = 0;
// NumTableImports is initialized to 1 to account for the hardcoded import of
// __indirect_function_table
unsigned NumTableImports = 1;
unsigned NumEventImports = 0; unsigned NumEventImports = 0;
uint32_t SectionCount = 0; uint32_t SectionCount = 0;
@ -267,6 +270,7 @@ private:
SectionFunctions.clear(); SectionFunctions.clear();
NumFunctionImports = 0; NumFunctionImports = 0;
NumGlobalImports = 0; NumGlobalImports = 0;
NumTableImports = 1;
MCObjectWriter::reset(); MCObjectWriter::reset();
} }
@ -316,6 +320,7 @@ private:
uint32_t writeDataSection(const MCAsmLayout &Layout); uint32_t writeDataSection(const MCAsmLayout &Layout);
void writeEventSection(ArrayRef<wasm::WasmEventType> Events); void writeEventSection(ArrayRef<wasm::WasmEventType> Events);
void writeGlobalSection(ArrayRef<wasm::WasmGlobal> Globals); void writeGlobalSection(ArrayRef<wasm::WasmGlobal> Globals);
void writeTableSection(ArrayRef<wasm::WasmTable> Tables);
void writeRelocSection(uint32_t SectionIndex, StringRef Name, void writeRelocSection(uint32_t SectionIndex, StringRef Name,
std::vector<WasmRelocationEntry> &Relocations); std::vector<WasmRelocationEntry> &Relocations);
void writeLinkingMetaDataSection( void writeLinkingMetaDataSection(
@ -827,6 +832,24 @@ void WasmObjectWriter::writeGlobalSection(ArrayRef<wasm::WasmGlobal> Globals) {
endSection(Section); endSection(Section);
} }
void WasmObjectWriter::writeTableSection(ArrayRef<wasm::WasmTable> Tables) {
if (Tables.empty())
return;
SectionBookkeeping Section;
startSection(Section, wasm::WASM_SEC_TABLE);
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);
}
endSection(Section);
}
void WasmObjectWriter::writeExportSection(ArrayRef<wasm::WasmExport> Exports) { void WasmObjectWriter::writeExportSection(ArrayRef<wasm::WasmExport> Exports) {
if (Exports.empty()) if (Exports.empty())
return; return;
@ -1003,6 +1026,7 @@ void WasmObjectWriter::writeLinkingMetaDataSection(
case wasm::WASM_SYMBOL_TYPE_FUNCTION: case wasm::WASM_SYMBOL_TYPE_FUNCTION:
case wasm::WASM_SYMBOL_TYPE_GLOBAL: case wasm::WASM_SYMBOL_TYPE_GLOBAL:
case wasm::WASM_SYMBOL_TYPE_EVENT: case wasm::WASM_SYMBOL_TYPE_EVENT:
case wasm::WASM_SYMBOL_TYPE_TABLE:
encodeULEB128(Sym.ElementIndex, W->OS); encodeULEB128(Sym.ElementIndex, W->OS);
if ((Sym.Flags & wasm::WASM_SYMBOL_UNDEFINED) == 0 || if ((Sym.Flags & wasm::WASM_SYMBOL_UNDEFINED) == 0 ||
(Sym.Flags & wasm::WASM_SYMBOL_EXPLICIT_NAME) != 0) (Sym.Flags & wasm::WASM_SYMBOL_EXPLICIT_NAME) != 0)
@ -1292,6 +1316,7 @@ uint64_t WasmObjectWriter::writeOneObject(MCAssembler &Asm,
SmallVector<wasm::WasmExport, 4> Exports; SmallVector<wasm::WasmExport, 4> Exports;
SmallVector<wasm::WasmEventType, 1> Events; SmallVector<wasm::WasmEventType, 1> Events;
SmallVector<wasm::WasmGlobal, 1> Globals; SmallVector<wasm::WasmGlobal, 1> Globals;
SmallVector<wasm::WasmTable, 1> Tables;
SmallVector<wasm::WasmSymbolInfo, 4> SymbolInfos; SmallVector<wasm::WasmSymbolInfo, 4> SymbolInfos;
SmallVector<std::pair<uint16_t, uint32_t>, 2> InitFuncs; SmallVector<std::pair<uint16_t, uint32_t>, 2> InitFuncs;
std::map<StringRef, std::vector<WasmComdatEntry>> Comdats; std::map<StringRef, std::vector<WasmComdatEntry>> Comdats;
@ -1494,6 +1519,20 @@ uint64_t WasmObjectWriter::writeOneObject(MCAssembler &Asm,
LLVM_DEBUG(dbgs() << " -> global index: " LLVM_DEBUG(dbgs() << " -> global index: "
<< WasmIndices.find(&WS)->second << "\n"); << WasmIndices.find(&WS)->second << "\n");
} }
} else if (WS.isTable()) {
if (WS.isDefined()) {
assert(WasmIndices.count(&WS) == 0);
wasm::WasmTable Table;
Table.ElemType = static_cast<uint8_t>(WS.getTableType());
Table.Index = NumTableImports + Tables.size();
// FIXME: Work on custom limits is ongoing
Table.Limits = {wasm::WASM_LIMITS_FLAG_NONE, 0, 0};
WasmIndices[&WS] = Table.Index;
Tables.push_back(Table);
}
LLVM_DEBUG(dbgs() << " -> table index: " << WasmIndices.find(&WS)->second
<< "\n");
} else if (WS.isEvent()) { } else if (WS.isEvent()) {
// C++ exception symbol (__cpp_exception) // C++ exception symbol (__cpp_exception)
unsigned Index; unsigned Index;
@ -1715,10 +1754,10 @@ uint64_t WasmObjectWriter::writeOneObject(MCAssembler &Asm,
writeTypeSection(Signatures); writeTypeSection(Signatures);
writeImportSection(Imports, DataSize, TableElems.size()); writeImportSection(Imports, DataSize, TableElems.size());
writeFunctionSection(Functions); writeFunctionSection(Functions);
// Skip the "table" section; we import the table instead.
// Skip the "memory" section; we import the memory instead. // Skip the "memory" section; we import the memory instead.
writeEventSection(Events); writeEventSection(Events);
writeGlobalSection(Globals); writeGlobalSection(Globals);
writeTableSection(Tables);
writeExportSection(Exports); writeExportSection(Exports);
writeElemSection(TableElems); writeElemSection(TableElems);
writeDataCountSection(); writeDataCountSection();

View File

@ -218,6 +218,7 @@ static wasm::WasmTable readTable(WasmObjectFile::ReadContext &Ctx) {
wasm::WasmTable Table; wasm::WasmTable Table;
Table.ElemType = readUint8(Ctx); Table.ElemType = readUint8(Ctx);
Table.Limits = readLimits(Ctx); Table.Limits = readLimits(Ctx);
// The caller needs to set Table.Index field for Table
return Table; return Table;
} }
@ -499,6 +500,7 @@ Error WasmObjectFile::parseLinkingSectionSymtab(ReadContext &Ctx) {
wasm::WasmSymbolInfo Info; wasm::WasmSymbolInfo Info;
const wasm::WasmSignature *Signature = nullptr; const wasm::WasmSignature *Signature = nullptr;
const wasm::WasmGlobalType *GlobalType = nullptr; const wasm::WasmGlobalType *GlobalType = nullptr;
uint8_t TableType = 0;
const wasm::WasmEventType *EventType = nullptr; const wasm::WasmEventType *EventType = nullptr;
Info.Kind = readUint8(Ctx); Info.Kind = readUint8(Ctx);
@ -567,6 +569,27 @@ Error WasmObjectFile::parseLinkingSectionSymtab(ReadContext &Ctx) {
} }
break; break;
case wasm::WASM_SYMBOL_TYPE_TABLE:
Info.ElementIndex = readVaruint32(Ctx);
if (!isValidTableIndex(Info.ElementIndex) ||
IsDefined != isDefinedTableIndex(Info.ElementIndex))
return make_error<GenericBinaryError>("invalid table symbol index",
object_error::parse_failed);
if (!IsDefined && (Info.Flags & wasm::WASM_SYMBOL_BINDING_MASK) ==
wasm::WASM_SYMBOL_BINDING_WEAK)
return make_error<GenericBinaryError>("undefined weak table symbol",
object_error::parse_failed);
if (IsDefined) {
Info.Name = readString(Ctx);
unsigned TableIndex = Info.ElementIndex - NumImportedTables;
wasm::WasmTable &Table = Tables[TableIndex];
TableType = Table.ElemType;
} else {
return make_error<GenericBinaryError>("undefined table symbol",
object_error::parse_failed);
}
break;
case wasm::WASM_SYMBOL_TYPE_DATA: case wasm::WASM_SYMBOL_TYPE_DATA:
Info.Name = readString(Ctx); Info.Name = readString(Ctx);
if (IsDefined) { if (IsDefined) {
@ -644,8 +667,8 @@ Error WasmObjectFile::parseLinkingSectionSymtab(ReadContext &Ctx) {
Twine(Info.Name), Twine(Info.Name),
object_error::parse_failed); object_error::parse_failed);
LinkingData.SymbolTable.emplace_back(Info); LinkingData.SymbolTable.emplace_back(Info);
Symbols.emplace_back(LinkingData.SymbolTable.back(), GlobalType, EventType, Symbols.emplace_back(LinkingData.SymbolTable.back(), GlobalType, TableType,
Signature); EventType, Signature);
LLVM_DEBUG(dbgs() << "Adding symbol: " << Symbols.back() << "\n"); LLVM_DEBUG(dbgs() << "Adding symbol: " << Symbols.back() << "\n");
} }
@ -963,12 +986,17 @@ Error WasmObjectFile::parseImportSection(ReadContext &Ctx) {
if (Im.Memory.Flags & wasm::WASM_LIMITS_FLAG_IS_64) if (Im.Memory.Flags & wasm::WASM_LIMITS_FLAG_IS_64)
HasMemory64 = true; HasMemory64 = true;
break; break;
case wasm::WASM_EXTERNAL_TABLE: case wasm::WASM_EXTERNAL_TABLE: {
Im.Table = readTable(Ctx); Im.Table = readTable(Ctx);
if (Im.Table.ElemType != wasm::WASM_TYPE_FUNCREF) Im.Table.Index = NumImportedTables + Tables.size();
NumImportedTables++;
auto ElemType = Im.Table.ElemType;
if (ElemType != wasm::WASM_TYPE_FUNCREF &&
ElemType != wasm::WASM_TYPE_EXTERNREF)
return make_error<GenericBinaryError>("Invalid table element type", return make_error<GenericBinaryError>("Invalid table element type",
object_error::parse_failed); object_error::parse_failed);
break; break;
}
case wasm::WASM_EXTERNAL_EVENT: case wasm::WASM_EXTERNAL_EVENT:
NumImportedEvents++; NumImportedEvents++;
Im.Event.Attribute = readVarint32(Ctx); Im.Event.Attribute = readVarint32(Ctx);
@ -1008,8 +1036,12 @@ Error WasmObjectFile::parseTableSection(ReadContext &Ctx) {
uint32_t Count = readVaruint32(Ctx); uint32_t Count = readVaruint32(Ctx);
Tables.reserve(Count); Tables.reserve(Count);
while (Count--) { while (Count--) {
Tables.push_back(readTable(Ctx)); wasm::WasmTable T = readTable(Ctx);
if (Tables.back().ElemType != wasm::WASM_TYPE_FUNCREF) { T.Index = NumImportedTables + Tables.size();
Tables.push_back(T);
auto ElemType = Tables.back().ElemType;
if (ElemType != wasm::WASM_TYPE_FUNCREF &&
ElemType != wasm::WASM_TYPE_EXTERNREF) {
return make_error<GenericBinaryError>("Invalid table element type", return make_error<GenericBinaryError>("Invalid table element type",
object_error::parse_failed); object_error::parse_failed);
} }
@ -1125,10 +1157,18 @@ bool WasmObjectFile::isValidGlobalIndex(uint32_t Index) const {
return Index < NumImportedGlobals + Globals.size(); return Index < NumImportedGlobals + Globals.size();
} }
bool WasmObjectFile::isValidTableIndex(uint32_t Index) const {
return Index < NumImportedTables + Tables.size();
}
bool WasmObjectFile::isDefinedGlobalIndex(uint32_t Index) const { bool WasmObjectFile::isDefinedGlobalIndex(uint32_t Index) const {
return Index >= NumImportedGlobals && isValidGlobalIndex(Index); return Index >= NumImportedGlobals && isValidGlobalIndex(Index);
} }
bool WasmObjectFile::isDefinedTableIndex(uint32_t Index) const {
return Index >= NumImportedTables && isValidTableIndex(Index);
}
bool WasmObjectFile::isValidEventIndex(uint32_t Index) const { bool WasmObjectFile::isValidEventIndex(uint32_t Index) const {
return Index < NumImportedEvents + Events.size(); return Index < NumImportedEvents + Events.size();
} }

View File

@ -60,6 +60,7 @@ private:
WasmYAML::Object &Obj; WasmYAML::Object &Obj;
uint32_t NumImportedFunctions = 0; uint32_t NumImportedFunctions = 0;
uint32_t NumImportedGlobals = 0; uint32_t NumImportedGlobals = 0;
uint32_t NumImportedTables = 0;
uint32_t NumImportedEvents = 0; uint32_t NumImportedEvents = 0;
bool HasError = false; bool HasError = false;
@ -187,6 +188,7 @@ void WasmWriter::writeSectionContent(raw_ostream &OS,
switch (Info.Kind) { switch (Info.Kind) {
case wasm::WASM_SYMBOL_TYPE_FUNCTION: case wasm::WASM_SYMBOL_TYPE_FUNCTION:
case wasm::WASM_SYMBOL_TYPE_GLOBAL: case wasm::WASM_SYMBOL_TYPE_GLOBAL:
case wasm::WASM_SYMBOL_TYPE_TABLE:
case wasm::WASM_SYMBOL_TYPE_EVENT: case wasm::WASM_SYMBOL_TYPE_EVENT:
encodeULEB128(Info.ElementIndex, SubSection.getStream()); encodeULEB128(Info.ElementIndex, SubSection.getStream());
if ((Info.Flags & wasm::WASM_SYMBOL_UNDEFINED) == 0 || if ((Info.Flags & wasm::WASM_SYMBOL_UNDEFINED) == 0 ||
@ -360,7 +362,7 @@ void WasmWriter::writeSectionContent(raw_ostream &OS,
case wasm::WASM_EXTERNAL_EVENT: case wasm::WASM_EXTERNAL_EVENT:
writeUint32(OS, Import.EventImport.Attribute); writeUint32(OS, Import.EventImport.Attribute);
writeUint32(OS, Import.EventImport.SigIndex); writeUint32(OS, Import.EventImport.SigIndex);
NumImportedGlobals++; NumImportedEvents++;
break; break;
case wasm::WASM_EXTERNAL_MEMORY: case wasm::WASM_EXTERNAL_MEMORY:
writeLimits(Import.Memory, OS); writeLimits(Import.Memory, OS);
@ -368,6 +370,7 @@ void WasmWriter::writeSectionContent(raw_ostream &OS,
case wasm::WASM_EXTERNAL_TABLE: case wasm::WASM_EXTERNAL_TABLE:
writeUint8(OS, Import.TableImport.ElemType); writeUint8(OS, Import.TableImport.ElemType);
writeLimits(Import.TableImport.TableLimits, OS); writeLimits(Import.TableImport.TableLimits, OS);
NumImportedTables++;
break; break;
default: default:
reportError("unknown import type: " +Twine(Import.Kind)); reportError("unknown import type: " +Twine(Import.Kind));
@ -401,7 +404,13 @@ void WasmWriter::writeSectionContent(raw_ostream &OS,
void WasmWriter::writeSectionContent(raw_ostream &OS, void WasmWriter::writeSectionContent(raw_ostream &OS,
WasmYAML::TableSection &Section) { WasmYAML::TableSection &Section) {
encodeULEB128(Section.Tables.size(), OS); encodeULEB128(Section.Tables.size(), OS);
uint32_t ExpectedIndex = NumImportedTables;
for (auto &Table : Section.Tables) { for (auto &Table : Section.Tables) {
if (Table.Index != ExpectedIndex) {
reportError("unexpected table index: " + Twine(Table.Index));
return;
}
++ExpectedIndex;
writeUint8(OS, Table.ElemType); writeUint8(OS, Table.ElemType);
writeLimits(Table.TableLimits, OS); writeLimits(Table.TableLimits, OS);
} }

View File

@ -300,6 +300,7 @@ void MappingTraits<WasmYAML::Signature>::mapping(
} }
void MappingTraits<WasmYAML::Table>::mapping(IO &IO, WasmYAML::Table &Table) { void MappingTraits<WasmYAML::Table>::mapping(IO &IO, WasmYAML::Table &Table) {
IO.mapRequired("Index", Table.Index);
IO.mapRequired("ElemType", Table.ElemType); IO.mapRequired("ElemType", Table.ElemType);
IO.mapRequired("Limits", Table.TableLimits); IO.mapRequired("Limits", Table.TableLimits);
} }
@ -496,6 +497,8 @@ void MappingTraits<WasmYAML::SymbolInfo>::mapping(IO &IO,
IO.mapRequired("Function", Info.ElementIndex); IO.mapRequired("Function", Info.ElementIndex);
} else if (Info.Kind == wasm::WASM_SYMBOL_TYPE_GLOBAL) { } else if (Info.Kind == wasm::WASM_SYMBOL_TYPE_GLOBAL) {
IO.mapRequired("Global", Info.ElementIndex); IO.mapRequired("Global", Info.ElementIndex);
} else if (Info.Kind == wasm::WASM_SYMBOL_TYPE_TABLE) {
IO.mapRequired("Table", Info.ElementIndex);
} else if (Info.Kind == wasm::WASM_SYMBOL_TYPE_EVENT) { } else if (Info.Kind == wasm::WASM_SYMBOL_TYPE_EVENT) {
IO.mapRequired("Event", Info.ElementIndex); IO.mapRequired("Event", Info.ElementIndex);
} else if (Info.Kind == wasm::WASM_SYMBOL_TYPE_DATA) { } else if (Info.Kind == wasm::WASM_SYMBOL_TYPE_DATA) {
@ -551,6 +554,7 @@ void ScalarEnumerationTraits<WasmYAML::SymbolKind>::enumeration(
ECase(FUNCTION); ECase(FUNCTION);
ECase(DATA); ECase(DATA);
ECase(GLOBAL); ECase(GLOBAL);
ECase(TABLE);
ECase(SECTION); ECase(SECTION);
ECase(EVENT); ECase(EVENT);
#undef ECase #undef ECase
@ -599,6 +603,7 @@ void ScalarEnumerationTraits<WasmYAML::TableType>::enumeration(
IO &IO, WasmYAML::TableType &Type) { IO &IO, WasmYAML::TableType &Type) {
#define ECase(X) IO.enumCase(Type, #X, wasm::WASM_TYPE_##X); #define ECase(X) IO.enumCase(Type, #X, wasm::WASM_TYPE_##X);
ECase(FUNCREF); ECase(FUNCREF);
ECase(EXTERNREF);
#undef ECase #undef ECase
} }

View File

@ -324,6 +324,8 @@ public:
return wasm::ValType::V128; return wasm::ValType::V128;
if (Type == "exnref") if (Type == "exnref")
return wasm::ValType::EXNREF; return wasm::ValType::EXNREF;
if (Type == "funcref")
return wasm::ValType::FUNCREF;
if (Type == "externref") if (Type == "externref")
return wasm::ValType::EXTERNREF; return wasm::ValType::EXTERNREF;
return Optional<wasm::ValType>(); return Optional<wasm::ValType>();
@ -712,6 +714,29 @@ public:
return expect(AsmToken::EndOfStatement, "EOL"); return expect(AsmToken::EndOfStatement, "EOL");
} }
if (DirectiveID.getString() == ".tabletype") {
auto SymName = expectIdent();
if (SymName.empty())
return true;
if (expect(AsmToken::Comma, ","))
return true;
auto TypeTok = Lexer.getTok();
auto TypeName = expectIdent();
if (TypeName.empty())
return true;
auto Type = parseType(TypeName);
if (!Type)
return error("Unknown type in .tabletype directive: ", TypeTok);
// Now that we have the name and table type, we can actually create the
// symbol
auto WasmSym = cast<MCSymbolWasm>(Ctx.getOrCreateSymbol(SymName));
WasmSym->setType(wasm::WASM_SYMBOL_TYPE_TABLE);
WasmSym->setTableType(Type.getValue());
TOut.emitTableType(WasmSym);
return expect(AsmToken::EndOfStatement, "EOL");
}
if (DirectiveID.getString() == ".functype") { if (DirectiveID.getString() == ".functype") {
// This code has to send things to the streamer similar to // This code has to send things to the streamer similar to
// WebAssemblyAsmPrinter::EmitFunctionBodyStart. // WebAssemblyAsmPrinter::EmitFunctionBodyStart.

View File

@ -318,6 +318,8 @@ const char *WebAssembly::anyTypeToString(unsigned Ty) {
return "v128"; return "v128";
case wasm::WASM_TYPE_FUNCREF: case wasm::WASM_TYPE_FUNCREF:
return "funcref"; return "funcref";
case wasm::WASM_TYPE_EXTERNREF:
return "externref";
case wasm::WASM_TYPE_FUNC: case wasm::WASM_TYPE_FUNC:
return "func"; return "func";
case wasm::WASM_TYPE_EXNREF: case wasm::WASM_TYPE_EXNREF:

View File

@ -77,6 +77,13 @@ void WebAssemblyTargetAsmStreamer::emitGlobalType(const MCSymbolWasm *Sym) {
OS << '\n'; OS << '\n';
} }
void WebAssemblyTargetAsmStreamer::emitTableType(const MCSymbolWasm *Sym) {
assert(Sym->isTable());
OS << "\t.tabletype\t" << Sym->getName() << ", "
<< WebAssembly::typeToString(Sym->getTableType());
OS << '\n';
}
void WebAssemblyTargetAsmStreamer::emitEventType(const MCSymbolWasm *Sym) { void WebAssemblyTargetAsmStreamer::emitEventType(const MCSymbolWasm *Sym) {
assert(Sym->isEvent()); assert(Sym->isEvent());
OS << "\t.eventtype\t" << Sym->getName() << " "; OS << "\t.eventtype\t" << Sym->getName() << " ";

View File

@ -39,6 +39,8 @@ public:
virtual void emitIndIdx(const MCExpr *Value) = 0; virtual void emitIndIdx(const MCExpr *Value) = 0;
/// .globaltype /// .globaltype
virtual void emitGlobalType(const MCSymbolWasm *Sym) = 0; virtual void emitGlobalType(const MCSymbolWasm *Sym) = 0;
/// .tabletype
virtual void emitTableType(const MCSymbolWasm *Sym) = 0;
/// .eventtype /// .eventtype
virtual void emitEventType(const MCSymbolWasm *Sym) = 0; virtual void emitEventType(const MCSymbolWasm *Sym) = 0;
/// .import_module /// .import_module
@ -67,6 +69,7 @@ public:
void emitFunctionType(const MCSymbolWasm *Sym) override; void emitFunctionType(const MCSymbolWasm *Sym) override;
void emitIndIdx(const MCExpr *Value) override; void emitIndIdx(const MCExpr *Value) override;
void emitGlobalType(const MCSymbolWasm *Sym) override; void emitGlobalType(const MCSymbolWasm *Sym) override;
void emitTableType(const MCSymbolWasm *Sym) override;
void emitEventType(const MCSymbolWasm *Sym) override; void emitEventType(const MCSymbolWasm *Sym) override;
void emitImportModule(const MCSymbolWasm *Sym, StringRef ImportModule) override; void emitImportModule(const MCSymbolWasm *Sym, StringRef ImportModule) override;
void emitImportName(const MCSymbolWasm *Sym, StringRef ImportName) override; void emitImportName(const MCSymbolWasm *Sym, StringRef ImportName) override;
@ -83,6 +86,7 @@ public:
void emitFunctionType(const MCSymbolWasm *Sym) override {} void emitFunctionType(const MCSymbolWasm *Sym) override {}
void emitIndIdx(const MCExpr *Value) override; void emitIndIdx(const MCExpr *Value) override;
void emitGlobalType(const MCSymbolWasm *Sym) override {} void emitGlobalType(const MCSymbolWasm *Sym) override {}
void emitTableType(const MCSymbolWasm *Sym) override {}
void emitEventType(const MCSymbolWasm *Sym) override {} void emitEventType(const MCSymbolWasm *Sym) override {}
void emitImportModule(const MCSymbolWasm *Sym, void emitImportModule(const MCSymbolWasm *Sym,
StringRef ImportModule) override {} StringRef ImportModule) override {}
@ -103,6 +107,7 @@ public:
void emitFunctionType(const MCSymbolWasm *) override {} void emitFunctionType(const MCSymbolWasm *) override {}
void emitIndIdx(const MCExpr *) override {} void emitIndIdx(const MCExpr *) override {}
void emitGlobalType(const MCSymbolWasm *) override {} void emitGlobalType(const MCSymbolWasm *) override {}
void emitTableType(const MCSymbolWasm *) override {}
void emitEventType(const MCSymbolWasm *) override {} void emitEventType(const MCSymbolWasm *) override {}
void emitImportModule(const MCSymbolWasm *, StringRef) override {} void emitImportModule(const MCSymbolWasm *, StringRef) override {}
void emitImportName(const MCSymbolWasm *, StringRef) override {} void emitImportName(const MCSymbolWasm *, StringRef) override {}

View File

@ -121,6 +121,8 @@ static char getInvokeSig(wasm::ValType VT) {
return 'V'; return 'V';
case wasm::ValType::EXNREF: case wasm::ValType::EXNREF:
return 'E'; return 'E';
case wasm::ValType::FUNCREF:
return 'F';
case wasm::ValType::EXTERNREF: case wasm::ValType::EXTERNREF:
return 'X'; return 'X';
} }

View File

@ -55,6 +55,7 @@ entry:
; CHECK-NEXT: Field: __indirect_function_table ; CHECK-NEXT: Field: __indirect_function_table
; CHECK-NEXT: Kind: TABLE ; CHECK-NEXT: Kind: TABLE
; CHECK-NEXT: Table: ; CHECK-NEXT: Table:
; CHECK-NEXT: Index: 0
; CHECK-NEXT: ElemType: FUNCREF ; CHECK-NEXT: ElemType: FUNCREF
; CHECK-NEXT: Limits: ; CHECK-NEXT: Limits:
; CHECK-NEXT: Initial: 0x00000000 ; CHECK-NEXT: Initial: 0x00000000

View File

@ -121,6 +121,13 @@ test0:
.ident "clang version 9.0.0 (trunk 364502) (llvm/trunk 364571)" .ident "clang version 9.0.0 (trunk 364502) (llvm/trunk 364571)"
.globaltype __stack_pointer, i32 .globaltype __stack_pointer, i32
.tabletype empty_eref_table, externref
empty_eref_table:
.tabletype empty_fref_table, funcref
empty_fref_table:
# CHECK: .text # CHECK: .text
# CHECK-LABEL: empty_func: # CHECK-LABEL: empty_func:
# CHECK-NEXT: .functype empty_func () -> () # CHECK-NEXT: .functype empty_func () -> ()
@ -228,3 +235,9 @@ test0:
# CHECK-NEXT: .int32 test0 # CHECK-NEXT: .int32 test0
# CHECK: .globaltype __stack_pointer, i32 # CHECK: .globaltype __stack_pointer, i32
# CHECK: .tabletype empty_eref_table, externref
# CHECK-NEXT: empty_eref_table:
# CHECK: .tabletype empty_fref_table, funcref
# CHECK-NEXT: empty_fref_table:

View File

@ -42,6 +42,7 @@ define linkonce_odr i32 @sharedFn() #1 comdat($sharedComdat) {
; CHECK-NEXT: Field: __indirect_function_table ; CHECK-NEXT: Field: __indirect_function_table
; CHECK-NEXT: Kind: TABLE ; CHECK-NEXT: Kind: TABLE
; CHECK-NEXT: Table: ; CHECK-NEXT: Table:
; CHECK-NEXT: Index: 0
; CHECK-NEXT: ElemType: FUNCREF ; CHECK-NEXT: ElemType: FUNCREF
; CHECK-NEXT: Limits: ; CHECK-NEXT: Limits:
; CHECK-NEXT: Initial: 0x00000000 ; CHECK-NEXT: Initial: 0x00000000

View File

@ -49,6 +49,7 @@ test0:
# BIN-NEXT: Field: __indirect_function_table # BIN-NEXT: Field: __indirect_function_table
# BIN-NEXT: Kind: TABLE # BIN-NEXT: Kind: TABLE
# BIN-NEXT: Table: # BIN-NEXT: Table:
# BIN-NEXT: Index: 0
# BIN-NEXT: ElemType: FUNCREF # BIN-NEXT: ElemType: FUNCREF
# BIN-NEXT: Limits: # BIN-NEXT: Limits:
# BIN-NEXT: Initial: 0x00000000 # BIN-NEXT: Initial: 0x00000000

View File

@ -30,6 +30,7 @@ declare void @func3()
; CHECK-NEXT: Field: __indirect_function_table ; CHECK-NEXT: Field: __indirect_function_table
; CHECK-NEXT: Kind: TABLE ; CHECK-NEXT: Kind: TABLE
; CHECK-NEXT: Table: ; CHECK-NEXT: Table:
; CHECK-NEXT: Index: 0
; CHECK-NEXT: ElemType: FUNCREF ; CHECK-NEXT: ElemType: FUNCREF
; CHECK-NEXT: Limits: ; CHECK-NEXT: Limits:
; CHECK-NEXT: Initial: 0x00000002 ; CHECK-NEXT: Initial: 0x00000002

View File

@ -66,6 +66,7 @@ hidden_func:
# CHECK-NEXT: Field: __indirect_function_table # CHECK-NEXT: Field: __indirect_function_table
# CHECK-NEXT: Kind: TABLE # CHECK-NEXT: Kind: TABLE
# CHECK-NEXT: Table: # CHECK-NEXT: Table:
# CHECK-NEXT: Index: 0
# CHECK-NEXT: ElemType: FUNCREF # CHECK-NEXT: ElemType: FUNCREF
# CHECK-NEXT: Limits: # CHECK-NEXT: Limits:
# CHECK-NEXT: Initial: 0x00000001 # CHECK-NEXT: Initial: 0x00000001

View File

@ -0,0 +1,42 @@
# RUN: llvm-mc -triple=wasm32-unknown-unknown < %s | FileCheck %s
# RUN: llvm-mc -triple=wasm32-unknown-unknown -filetype=obj < %s | obj2yaml | FileCheck -check-prefix=BIN %s
# Test creating several empty tables
.tabletype foo, externref
foo:
bar:
.tabletype bar, funcref
# CHECK: .tabletype foo, externref
# CHECK: foo:
# CHECK: bar:
# CHECK-NEXT: .tabletype bar, funcref
# BIN: - Type: TABLE
# BIN-NEXT: Tables:
# BIN-NEXT: - Index: 1
# BIN-NEXT: ElemType: EXTERNREF
# BIN-NEXT: Limits:
# BIN-NEXT: Initial: 0x00000000
# BIN-NEXT: - Index: 2
# BIN-NEXT: ElemType: FUNCREF
# BIN-NEXT: Limits:
# BIN-NEXT: Initial: 0x00000000
# BIN: - Type: CUSTOM
# BIN-NEXT: Name: linking
# BIN-NEXT: Version: 2
# BIN-NEXT: SymbolTable:
# BIN-NEXT: - Index: 0
# BIN-NEXT: Kind: TABLE
# BIN-NEXT: Name: foo
# BIN-NEXT: Flags: [ BINDING_LOCAL ]
# BIN-NEXT: Table: 1
# BIN-NEXT: - Index: 1
# BIN-NEXT: Kind: TABLE
# BIN-NEXT: Name: bar
# BIN-NEXT: Flags: [ BINDING_LOCAL ]
# BIN-NEXT: Table: 2

View File

@ -42,6 +42,7 @@ test0:
# BIN-NEXT: Field: __indirect_function_table # BIN-NEXT: Field: __indirect_function_table
# BIN-NEXT: Kind: TABLE # BIN-NEXT: Kind: TABLE
# BIN-NEXT: Table: # BIN-NEXT: Table:
# BIN-NEXT: Index: 0
# BIN-NEXT: ElemType: FUNCREF # BIN-NEXT: ElemType: FUNCREF
# BIN-NEXT: Limits: # BIN-NEXT: Limits:
# BIN-NEXT: Initial: 0x00000000 # BIN-NEXT: Initial: 0x00000000

View File

@ -153,6 +153,7 @@ test:
# BIN-NEXT: Field: __indirect_function_table # BIN-NEXT: Field: __indirect_function_table
# BIN-NEXT: Kind: TABLE # BIN-NEXT: Kind: TABLE
# BIN-NEXT: Table: # BIN-NEXT: Table:
# BIN-NEXT: Index: 0
# BIN-NEXT: ElemType: FUNCREF # BIN-NEXT: ElemType: FUNCREF
# BIN-NEXT: Limits: # BIN-NEXT: Limits:
# BIN-NEXT: Initial: 0x00000000 # BIN-NEXT: Initial: 0x00000000

View File

@ -92,6 +92,7 @@ alias_address:
# CHECK-NEXT: Field: __indirect_function_table # CHECK-NEXT: Field: __indirect_function_table
# CHECK-NEXT: Kind: TABLE # CHECK-NEXT: Kind: TABLE
# CHECK-NEXT: Table: # CHECK-NEXT: Table:
# CHECK-NEXT: Index: 0
# CHECK-NEXT: ElemType: FUNCREF # CHECK-NEXT: ElemType: FUNCREF
# CHECK-NEXT: Limits: # CHECK-NEXT: Limits:
# CHECK-NEXT: Initial: 0x00000001 # CHECK-NEXT: Initial: 0x00000001

View File

@ -29,6 +29,7 @@ Sections:
Field: __indirect_function_table Field: __indirect_function_table
Kind: TABLE Kind: TABLE
Table: Table:
Index: 0
ElemType: FUNCREF ElemType: FUNCREF
Limits: Limits:
Initial: 0x00000000 Initial: 0x00000000

View File

@ -5,7 +5,8 @@ FileHeader:
Sections: Sections:
- Type: TABLE - Type: TABLE
Tables: Tables:
- ElemType: FUNCREF - Index: 0
ElemType: FUNCREF
Limits: Limits:
Flags: [ HAS_MAX ] Flags: [ HAS_MAX ]
Initial: 0x00000010 Initial: 0x00000010

View File

@ -32,6 +32,7 @@ Sections:
Field: imported_table Field: imported_table
Kind: TABLE Kind: TABLE
Table: Table:
Index: 0
ElemType: FUNCREF ElemType: FUNCREF
Limits: Limits:
Flags: [ HAS_MAX ] Flags: [ HAS_MAX ]

View File

@ -5,7 +5,8 @@ FileHeader:
Sections: Sections:
- Type: TABLE - Type: TABLE
Tables: Tables:
- ElemType: FUNCREF - Index: 0
ElemType: FUNCREF
Limits: Limits:
Flags: [ HAS_MAX ] Flags: [ HAS_MAX ]
Initial: 0x00000010 Initial: 0x00000010
@ -17,7 +18,8 @@ Sections:
# CHECK: Sections: # CHECK: Sections:
# CHECK: - Type: TABLE # CHECK: - Type: TABLE
# CHECK: Tables: # CHECK: Tables:
# CHECK: - ElemType: FUNCREF # CHECK: - Index: 0
# CHECK: ElemType: FUNCREF
# CHECK: Limits: # CHECK: Limits:
# CHECK: Flags: [ HAS_MAX ] # CHECK: Flags: [ HAS_MAX ]
# CHECK: Initial: 0x00000010 # CHECK: Initial: 0x00000010

View File

@ -26,6 +26,7 @@ Sections:
Field: __indirect_function_table Field: __indirect_function_table
Kind: TABLE Kind: TABLE
Table: Table:
Index: 0
ElemType: FUNCREF ElemType: FUNCREF
Limits: Limits:
Initial: 0x00000000 Initial: 0x00000000

View File

@ -37,6 +37,7 @@ static WasmYAML::Table makeTable(const wasm::WasmTable &Table) {
T.TableLimits.Flags = Table.Limits.Flags; T.TableLimits.Flags = Table.Limits.Flags;
T.TableLimits.Initial = Table.Limits.Initial; T.TableLimits.Initial = Table.Limits.Initial;
T.TableLimits.Maximum = Table.Limits.Maximum; T.TableLimits.Maximum = Table.Limits.Maximum;
T.Index = Table.Index;
return T; return T;
} }
@ -116,6 +117,7 @@ WasmDumper::dumpCustomSection(const WasmSection &WasmSec) {
break; break;
case wasm::WASM_SYMBOL_TYPE_FUNCTION: case wasm::WASM_SYMBOL_TYPE_FUNCTION:
case wasm::WASM_SYMBOL_TYPE_GLOBAL: case wasm::WASM_SYMBOL_TYPE_GLOBAL:
case wasm::WASM_SYMBOL_TYPE_TABLE:
case wasm::WASM_SYMBOL_TYPE_EVENT: case wasm::WASM_SYMBOL_TYPE_EVENT:
Info.ElementIndex = Symbol.ElementIndex; Info.ElementIndex = Symbol.ElementIndex;
break; break;