[WebAssembly] Fix import statement
authorJF Bastien <jfb@google.com>
Fri, 30 Oct 2015 16:41:21 +0000 (16:41 +0000)
committerJF Bastien <jfb@google.com>
Fri, 30 Oct 2015 16:41:21 +0000 (16:41 +0000)
Summary:
Imports should be generated like (param i32 f32...) not (param i32) (param f32) ...

Author: binji
Reviewers: jfb
Subscribers: jfb, dschuff

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@251714 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
test/CodeGen/WebAssembly/import.ll

index 7ee452efe1d3505df4de4c57a3d4b7562befdb49..59c1ff381a011c0502392e191a8a746f0ce2c0d7 100644 (file)
@@ -339,24 +339,25 @@ void WebAssemblyAsmPrinter::EmitInstruction(const MachineInstr *MI) {
 }
 
 void WebAssemblyAsmPrinter::EmitEndOfAsmFile(Module &M) {
-    SmallString<128> Str;
-    raw_svector_ostream OS(Str);
+  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;
+        continue;
       if (Str.empty())
-       OS << "\t.imports\n";
+        OS << "\t.imports\n";
       Type *Rt = F.getReturnType();
-      OS << "\t.import " <<  toSymbol(F.getName()) << " \"\" \"" << F.getName()
-        << "\"";
+      OS << "\t.import " << toSymbol(F.getName()) << " \"\" \"" << F.getName()
+         << "\" (param";
       for (const Argument &A : F.args())
-       OS << " (param " << toString(A.getType()) << ')';
+        OS << ' ' << toString(A.getType());
+      OS << ')';
       if (!Rt->isVoidTy())
-       OS << " (result " << toString(Rt) << ')';
+        OS << " (result " << toString(Rt) << ')';
       OS << '\n';
-  }
+    }
   OutStreamer->EmitRawText(OS.str());
 }
 
index d1dca7fa8bbd207c3107724e7bc8caa7f824b5c1..6f1f8e0c3aee5d09afa93b66bc885561a3e0ee00 100644 (file)
@@ -15,7 +15,9 @@ define void @f(i32 %a, float %b) {
 ; 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"
+; CHECK-NEXT:  .import $printv "" "printv" (param)
+; CHECK-NEXT:  .import $add2 "" "add2" (param i32 i32) (result i32)
 declare i32 @printi(i32)
 declare float @printf(float)
 declare void @printv()
+declare i32 @add2(i32, i32)