Index: lib/Target/WebAssembly/MCTargetDesc/WebAssemblyTargetStreamer.h =================================================================== --- lib/Target/WebAssembly/MCTargetDesc/WebAssemblyTargetStreamer.h +++ lib/Target/WebAssembly/MCTargetDesc/WebAssemblyTargetStreamer.h @@ -36,15 +36,16 @@ /// .endfunc virtual void emitEndFunc() = 0; /// .functype - virtual void emitFunctionType(MCSymbolWasm *Symbol) = 0; + virtual void emitFunctionType(const MCSymbolWasm *Sym) = 0; /// .indidx virtual void emitIndIdx(const MCExpr *Value) = 0; /// .globaltype - virtual void emitGlobalType(MCSymbolWasm *Sym) = 0; + virtual void emitGlobalType(const MCSymbolWasm *Sym) = 0; /// .eventtype - virtual void emitEventType(MCSymbolWasm *Sym) = 0; + virtual void emitEventType(const MCSymbolWasm *Sym) = 0; /// .import_module - virtual void emitImportModule(MCSymbolWasm *Sym, StringRef ModuleName) = 0; + virtual void emitImportModule(const MCSymbolWasm *Sym, + StringRef ModuleName) = 0; protected: void emitValueType(wasm::ValType Type); @@ -59,11 +60,11 @@ void emitLocal(ArrayRef Types) override; void emitEndFunc() override; - void emitFunctionType(MCSymbolWasm *Symbol) override; + void emitFunctionType(const MCSymbolWasm *Sym) override; void emitIndIdx(const MCExpr *Value) override; - void emitGlobalType(MCSymbolWasm *Sym) override; - void emitEventType(MCSymbolWasm *Sym) override; - void emitImportModule(MCSymbolWasm *Sym, StringRef ModuleName) override; + void emitGlobalType(const MCSymbolWasm *Sym) override; + void emitEventType(const MCSymbolWasm *Sym) override; + void emitImportModule(const MCSymbolWasm *Sym, StringRef ModuleName) override; }; /// This part is for Wasm object output @@ -73,11 +74,12 @@ void emitLocal(ArrayRef Types) override; void emitEndFunc() override; - void emitFunctionType(MCSymbolWasm *Symbol) override; + void emitFunctionType(const MCSymbolWasm *Sym) override {} void emitIndIdx(const MCExpr *Value) override; - void emitGlobalType(MCSymbolWasm *Sym) override; - void emitEventType(MCSymbolWasm *Sym) override; - void emitImportModule(MCSymbolWasm *Sym, StringRef ModuleName) override; + void emitGlobalType(const MCSymbolWasm *Sym) override {} + void emitEventType(const MCSymbolWasm *Sym) override {} + void emitImportModule(const MCSymbolWasm *Sym, + StringRef ModuleName) override {} }; /// This part is for null output @@ -88,11 +90,11 @@ void emitLocal(ArrayRef) override {} void emitEndFunc() override {} - void emitFunctionType(MCSymbolWasm *) override {} + void emitFunctionType(const MCSymbolWasm *) override {} void emitIndIdx(const MCExpr *) override {} - void emitGlobalType(MCSymbolWasm *) override {} - void emitEventType(MCSymbolWasm *) override {} - void emitImportModule(MCSymbolWasm *, StringRef) override {} + void emitGlobalType(const MCSymbolWasm *) override {} + void emitEventType(const MCSymbolWasm *) override {} + void emitImportModule(const MCSymbolWasm *, StringRef) override {} }; } // end namespace llvm Index: lib/Target/WebAssembly/MCTargetDesc/WebAssemblyTargetStreamer.cpp =================================================================== --- lib/Target/WebAssembly/MCTargetDesc/WebAssemblyTargetStreamer.cpp +++ lib/Target/WebAssembly/MCTargetDesc/WebAssemblyTargetStreamer.cpp @@ -39,7 +39,8 @@ WebAssemblyTargetWasmStreamer::WebAssemblyTargetWasmStreamer(MCStreamer &S) : WebAssemblyTargetStreamer(S) {} -static void PrintTypes(formatted_raw_ostream &OS, ArrayRef Types) { +static void PrintTypes(formatted_raw_ostream &OS, + ArrayRef Types) { bool First = true; for (auto Type : Types) { if (First) @@ -60,15 +61,17 @@ void WebAssemblyTargetAsmStreamer::emitEndFunc() { OS << "\t.endfunc\n"; } -void WebAssemblyTargetAsmStreamer::emitFunctionType(MCSymbolWasm *Symbol) { - OS << "\t.functype\t" << Symbol->getName() << " ("; - auto &Params = Symbol->getSignature()->Params; +void WebAssemblyTargetAsmStreamer::emitFunctionType( + const MCSymbolWasm *Sym) { + assert(Sym->isFunction()); + OS << "\t.functype\t" << Sym->getName() << " ("; + auto &Params = Sym->getSignature()->Params; for (auto &Ty : Params) { if (&Ty != &Params[0]) OS << ", "; OS << WebAssembly::TypeToString(Ty); } OS << ") -> ("; - auto &Returns = Symbol->getSignature()->Returns; + auto &Returns = Sym->getSignature()->Returns; for (auto &Ty : Returns) { if (&Ty != &Returns[0]) OS << ", "; OS << WebAssembly::TypeToString(Ty); @@ -76,7 +79,7 @@ OS << ")\n"; } -void WebAssemblyTargetAsmStreamer::emitGlobalType(MCSymbolWasm *Sym) { +void WebAssemblyTargetAsmStreamer::emitGlobalType(const MCSymbolWasm *Sym) { assert(Sym->isGlobal()); OS << "\t.globaltype\t" << Sym->getName() << ", " << WebAssembly::TypeToString( @@ -84,7 +87,7 @@ '\n'; } -void WebAssemblyTargetAsmStreamer::emitEventType(MCSymbolWasm *Sym) { +void WebAssemblyTargetAsmStreamer::emitEventType(const MCSymbolWasm *Sym) { assert(Sym->isEvent()); OS << "\t.eventtype\t" << Sym->getName(); if (Sym->getSignature()->Returns.empty()) @@ -99,7 +102,7 @@ OS << '\n'; } -void WebAssemblyTargetAsmStreamer::emitImportModule(MCSymbolWasm *Sym, +void WebAssemblyTargetAsmStreamer::emitImportModule(const MCSymbolWasm *Sym, StringRef ModuleName) { OS << "\t.import_module\t" << Sym->getName() << ", " << ModuleName << '\n'; } @@ -131,20 +134,3 @@ void WebAssemblyTargetWasmStreamer::emitIndIdx(const MCExpr *Value) { llvm_unreachable(".indidx encoding not yet implemented"); } - -void WebAssemblyTargetWasmStreamer::emitFunctionType(MCSymbolWasm *Symbol) { - // Symbol already has its arguments and result set. - Symbol->setType(wasm::WASM_SYMBOL_TYPE_FUNCTION); -} - -void WebAssemblyTargetWasmStreamer::emitGlobalType(MCSymbolWasm *Sym) { - // Not needed. -} - -void WebAssemblyTargetWasmStreamer::emitEventType(MCSymbolWasm *Sym) { - // Not needed. -} -void WebAssemblyTargetWasmStreamer::emitImportModule(MCSymbolWasm *Sym, - StringRef ModuleName) { - Sym->setModuleName(ModuleName); -} Index: lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp =================================================================== --- lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp +++ lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp @@ -94,6 +94,7 @@ SmallVector Params; ComputeSignatureVTs(F.getFunctionType(), F, TM, Params, Results); auto *Sym = cast(getSymbol(&F)); + Sym->setType(wasm::WASM_SYMBOL_TYPE_FUNCTION); if (!Sym->getSignature()) { auto Signature = SignatureFromMVTs(Results, Params); Sym->setSignature(Signature.get()); @@ -110,6 +111,7 @@ F.hasFnAttribute("wasm-import-module")) { StringRef Name = F.getFnAttribute("wasm-import-module").getValueAsString(); + Sym->setModuleName(Name); getTargetStreamer()->emitImportModule(Sym, Name); } } @@ -164,6 +166,7 @@ auto *WasmSym = cast(CurrentFnSym); WasmSym->setSignature(Signature.get()); addSignature(std::move(Signature)); + WasmSym->setType(wasm::WASM_SYMBOL_TYPE_FUNCTION); // FIXME: clean up how params and results are emitted (use signatures) getTargetStreamer()->emitFunctionType(WasmSym);