Convert the MC test to use asm rather than bitcode.
This is a precursor to https://reviews.llvm.org/D70520.
Differential Revision: https://reviews.llvm.org/D70877
def WebAssemblyImportModuleDocs : Documentation {
let Category = DocCatFunction;
let Content = [{
-Clang supports the ``__attribute__((import_module(<module_name>)))``
+Clang supports the ``__attribute__((import_module(<module_name>)))``
attribute for the WebAssembly target. This attribute may be attached to a
function declaration, where it modifies how the symbol is to be imported
within the WebAssembly linking environment.
name, which typically identifies a field from that module to import. By
default, module names for C/C++ symbols are assigned automatically by the
linker. This attribute can be used to override the default behavior, and
-reuqest a specific module name be used instead.
+request a specific module name be used instead.
}];
}
def WebAssemblyImportNameDocs : Documentation {
let Category = DocCatFunction;
let Content = [{
-Clang supports the ``__attribute__((import_name(<name>)))``
+Clang supports the ``__attribute__((import_name(<name>)))``
attribute for the WebAssembly target. This attribute may be attached to a
function declaration, where it modifies how the symbol is to be imported
within the WebAssembly linking environment.
name, which typically identifies a field from that module to import. By
default, field names for C/C++ symbols are the same as their C/C++ symbol
names. This attribute can be used to override the default behavior, and
-reuqest a specific field name be used instead.
+request a specific field name be used instead.
}];
}
}
void setImportModule(StringRef Name) { ImportModule = Name; }
+ bool hasImportName() const { return ImportName.hasValue(); }
const StringRef getImportName() const {
if (ImportName.hasValue()) {
return ImportName.getValue();
Flags |= wasm::WASM_SYMBOL_EXPORTED;
}
}
- if (WS.getName() != WS.getImportName())
+ if (WS.hasImportName())
Flags |= wasm::WASM_SYMBOL_EXPLICIT_NAME;
wasm::WasmSymbolInfo Info;
return expect(AsmToken::EndOfStatement, "EOL");
}
+ if (DirectiveID.getString() == ".import_module") {
+ auto SymName = expectIdent();
+ if (SymName.empty())
+ return true;
+ if (expect(AsmToken::Comma, ","))
+ return true;
+ auto ImportModule = expectIdent();
+ auto WasmSym = cast<MCSymbolWasm>(Ctx.getOrCreateSymbol(SymName));
+ WasmSym->setImportModule(ImportModule);
+ TOut.emitImportModule(WasmSym, ImportModule);
+ }
+
+ if (DirectiveID.getString() == ".import_name") {
+ auto SymName = expectIdent();
+ if (SymName.empty())
+ return true;
+ if (expect(AsmToken::Comma, ","))
+ return true;
+ auto ImportName = expectIdent();
+ auto WasmSym = cast<MCSymbolWasm>(Ctx.getOrCreateSymbol(SymName));
+ WasmSym->setImportName(ImportName);
+ TOut.emitImportName(WasmSym, ImportName);
+ }
+
if (DirectiveID.getString() == ".eventtype") {
auto SymName = expectIdent();
if (SymName.empty())
+++ /dev/null
-; RUN: llc -filetype=obj %s -o - | obj2yaml | FileCheck %s
-
-target triple = "wasm32-unknown-unknown"
-
-define void @test() {
- call void @foo()
- call void @plain()
- ret void
-}
-
-declare void @foo() #0
-declare void @plain()
-
-attributes #0 = { "wasm-import-module"="bar" "wasm-import-name"="qux" }
-
-; CHECK: - Type: IMPORT
-; CHECK-NEXT: Imports:
-; CHECK: - Module: bar
-; CHECK-NEXT: Field: qux
-; CHECK-NEXT: Kind: FUNCTION
-
-; CHECK: - Module: env
-; CHECK-NEXT: Field: plain
-; CHECK-NEXT: Kind: FUNCTION
-
-; CHECK: - Type: CUSTOM
-; CHECK: Name: foo
-; CHECK-NEXT: Flags: [ UNDEFINED, EXPLICIT_NAME ]
-
-; CHECK: Name: plain
-; CHECK-NEXT: Flags: [ UNDEFINED ]
--- /dev/null
+# RUN: llvm-mc -triple=wasm32 < %s | FileCheck %s -check-prefix=CHECK-ASM
+# RUN: llvm-mc -triple=wasm32 -filetype=obj -o - < %s | obj2yaml | FileCheck %s
+
+test:
+ .functype test () -> ()
+ call foo
+ call plain
+ end_function
+
+ .functype foo () -> ()
+ .functype plain () -> ()
+ .import_module foo, bar
+ .import_name foo, qux
+
+# CHECK-ASM: .import_module foo, bar
+# CHECK-ASM: .import_name foo, qux
+
+# CHECK: - Type: IMPORT
+# CHECK-NEXT: Imports:
+# CHECK: - Module: bar
+# CHECK-NEXT: Field: qux
+# CHECK-NEXT: Kind: FUNCTION
+
+# CHECK: - Module: env
+# CHECK-NEXT: Field: plain
+# CHECK-NEXT: Kind: FUNCTION
+
+# CHECK: - Type: CUSTOM
+# CHECK: Name: foo
+# CHECK-NEXT: Flags: [ UNDEFINED, EXPLICIT_NAME ]
+
+# CHECK: Name: plain
+# CHECK-NEXT: Flags: [ UNDEFINED ]