[WebAssembly] Improve libObject support for wasm imports and exports
Previously we had only supported the importing and
exporting of functions and globals.
Also, add usefull overload of getWasmSymbol() and
getNumberOfSymbols() in support of lld port.
Differential Revision: https://reviews.llvm.org/D33011
llvm-svn: 302601
diff --git a/llvm/tools/obj2yaml/wasm2yaml.cpp b/llvm/tools/obj2yaml/wasm2yaml.cpp
index cc04b99..6efa2ac 100644
--- a/llvm/tools/obj2yaml/wasm2yaml.cpp
+++ b/llvm/tools/obj2yaml/wasm2yaml.cpp
@@ -25,6 +25,23 @@
ErrorOr<WasmYAML::Object *> dump();
};
+WasmYAML::Table make_table(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;
+ return T;
+}
+
+WasmYAML::Limits make_limits(const wasm::WasmLimits &Limits) {
+ WasmYAML::Limits L;
+ L.Flags = Limits.Flags;
+ L.Initial = Limits.Initial;
+ L.Maximum = Limits.Maximum;
+ return L;
+}
+
ErrorOr<WasmYAML::Object *> WasmDumper::dump() {
auto Y = make_unique<WasmYAML::Object>();
@@ -82,17 +99,26 @@
case wasm::WASM_SEC_IMPORT: {
auto ImportSec = make_unique<WasmYAML::ImportSection>();
for (auto &Import : Obj.imports()) {
- WasmYAML::Import Ex;
- Ex.Module = Import.Module;
- Ex.Field = Import.Field;
- Ex.Kind = Import.Kind;
- if (Ex.Kind == wasm::WASM_EXTERNAL_FUNCTION) {
- Ex.SigIndex = Import.SigIndex;
- } else if (Ex.Kind == wasm::WASM_EXTERNAL_GLOBAL) {
- Ex.GlobalType = Import.GlobalType;
- Ex.GlobalMutable = Import.GlobalMutable;
+ WasmYAML::Import Im;
+ Im.Module = Import.Module;
+ Im.Field = Import.Field;
+ Im.Kind = Import.Kind;
+ switch (Im.Kind) {
+ case wasm::WASM_EXTERNAL_FUNCTION:
+ Im.SigIndex = Import.SigIndex;
+ break;
+ case wasm::WASM_EXTERNAL_GLOBAL:
+ Im.Global.Type = Import.Global.Type;
+ Im.Global.Mutable = Import.Global.Mutable;
+ break;
+ case wasm::WASM_EXTERNAL_TABLE:
+ Im.Table = make_table(Import.Table);
+ break;
+ case wasm::WASM_EXTERNAL_MEMORY:
+ Im.Memory = make_limits(Import.Memory);
+ break;
}
- ImportSec->Imports.push_back(Ex);
+ ImportSec->Imports.push_back(Im);
}
S = std::move(ImportSec);
break;
@@ -107,25 +133,16 @@
}
case wasm::WASM_SEC_TABLE: {
auto TableSec = make_unique<WasmYAML::TableSection>();
- for (auto &Table : Obj.tables()) {
- 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;
- TableSec->Tables.push_back(T);
+ for (const wasm::WasmTable &Table : Obj.tables()) {
+ TableSec->Tables.push_back(make_table(Table));
}
S = std::move(TableSec);
break;
}
case wasm::WASM_SEC_MEMORY: {
auto MemorySec = make_unique<WasmYAML::MemorySection>();
- for (auto &Memory : Obj.memories()) {
- WasmYAML::Limits L;
- L.Flags = Memory.Flags;
- L.Initial = Memory.Initial;
- L.Maximum = Memory.Maximum;
- MemorySec->Memories.push_back(L);
+ for (const wasm::WasmLimits &Memory : Obj.memories()) {
+ MemorySec->Memories.push_back(make_limits(Memory));
}
S = std::move(MemorySec);
break;