Index: wasm/Writer.cpp =================================================================== --- wasm/Writer.cpp +++ wasm/Writer.cpp @@ -279,31 +279,24 @@ writeUleb128(OS, NumExports, "export count"); - if (ExportMemory) { - WasmExport MemoryExport; - MemoryExport.Name = "memory"; - MemoryExport.Kind = WASM_EXTERNAL_MEMORY; - MemoryExport.Index = 0; - writeExport(OS, MemoryExport); - } + if (ExportMemory) + writeExport(OS, {"memory", WASM_EXTERNAL_MEMORY, 0}); unsigned FakeGlobalIndex = NumImportedGlobals + InputGlobals.size(); + for (const Symbol *Sym : ExportedSymbols) { - DEBUG(dbgs() << "Export: " << Sym->getName() << "\n"); + StringRef Name = Sym->getName(); WasmExport Export; - Export.Name = Sym->getName(); - if (isa(Sym)) { - Export.Index = Sym->getOutputIndex(); - Export.Kind = WASM_EXTERNAL_FUNCTION; - } else if (isa(Sym)) { - Export.Index = Sym->getOutputIndex(); - Export.Kind = WASM_EXTERNAL_GLOBAL; - } else if (isa(Sym)) { - Export.Index = FakeGlobalIndex++; - Export.Kind = WASM_EXTERNAL_GLOBAL; - } else { + DEBUG(dbgs() << "Export: " << Name << "\n"); + + if (isa(Sym)) + Export = {Name, WASM_EXTERNAL_FUNCTION, Sym->getOutputIndex()}; + else if (isa(Sym)) + Export = {Name, WASM_EXTERNAL_GLOBAL, Sym->getOutputIndex()}; + else if (isa(Sym)) + Export = {Name, WASM_EXTERNAL_GLOBAL, FakeGlobalIndex++}; + else llvm_unreachable("unexpected symbol type"); - } writeExport(OS, Export); } }