void EmitJumpTableInfo() override;
void EmitConstantPool() override;
void EmitFunctionBodyStart() override;
-
void EmitInstruction(const MachineInstr *MI) override;
+ void EmitEndOfAsmFile(Module &M) override;
std::string getRegTypeName(unsigned RegNo) const;
static std::string toString(const APFloat &APF);
}
}
+void WebAssemblyAsmPrinter::EmitEndOfAsmFile(Module &M) {
+ SmallString<128> Str;
+ raw_svector_ostream OS(Str);
+ for (const Function &F : M)
+ if (F.isDeclarationForLinker()) {
+ assert(F.hasName() && "imported functions must have a name");
+ if (F.getName().startswith("llvm."))
+ continue;
+ if (Str.empty())
+ OS << "\t.imports\n";
+ Type *Rt = F.getReturnType();
+ OS << "\t.import " << toSymbol(F.getName()) << " \"\" \"" << F.getName()
+ << "\"";
+ for (const Argument &A : F.args())
+ OS << " (param " << toString(A.getType()) << ')';
+ if (!Rt->isVoidTy())
+ OS << " (result " << toString(Rt) << ')';
+ OS << '\n';
+ }
+ OutStreamer->EmitRawText(OS.str());
+}
+
// Force static initialization.
extern "C" void LLVMInitializeWebAssemblyAsmPrinter() {
RegisterAsmPrinter<WebAssemblyAsmPrinter> X(TheWebAssemblyTarget32);
--- /dev/null
+; RUN: llc < %s -asm-verbose=false | FileCheck %s
+
+target datalayout = "e-p:32:32-i64:64-n32:64-S128"
+target triple = "wasm32-unknown-unknown"
+
+; CHECK-LABEL: .text
+; CHECK-LABEL: f:
+define void @f(i32 %a, float %b) {
+ tail call i32 @printi(i32 %a)
+ tail call float @printf(float %b)
+ tail call void @printv()
+ ret void
+}
+
+; CHECK-LABEL: .imports
+; CHECK-NEXT: .import $printi "" "printi" (param i32) (result i32)
+; CHECK-NEXT: .import $printf "" "printf" (param f32) (result f32)
+; CHECK-NEXT: .import $printv "" "printv"
+declare i32 @printi(i32)
+declare float @printf(float)
+declare void @printv()