sbc100 created this revision. Herald added subscribers: llvm-commits, cfe-commits, aheejin, hiraditya, jgravelle-google, dschuff. Herald added projects: clang, LLVM.
Convert the MC test to use asm rather than bitcode. This is a precursor to https://reviews.llvm.org/D70520. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D70877 Files: clang/include/clang/Basic/AttrDocs.td lld/test/wasm/import-name.ll lld/test/wasm/import-names.ll llvm/include/llvm/MC/MCSymbolWasm.h llvm/lib/MC/WasmObjectWriter.cpp llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp llvm/test/MC/WebAssembly/import-module.ll llvm/test/MC/WebAssembly/import-module.s
Index: llvm/test/MC/WebAssembly/import-module.s =================================================================== --- /dev/null +++ llvm/test/MC/WebAssembly/import-module.s @@ -0,0 +1,33 @@ +# 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 ] Index: llvm/test/MC/WebAssembly/import-module.ll =================================================================== --- llvm/test/MC/WebAssembly/import-module.ll +++ /dev/null @@ -1,31 +0,0 @@ -; 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 ] Index: llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp =================================================================== --- llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp +++ llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp @@ -712,6 +712,30 @@ 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()) Index: llvm/lib/MC/WasmObjectWriter.cpp =================================================================== --- llvm/lib/MC/WasmObjectWriter.cpp +++ llvm/lib/MC/WasmObjectWriter.cpp @@ -1452,7 +1452,7 @@ Flags |= wasm::WASM_SYMBOL_EXPORTED; } } - if (WS.getName() != WS.getImportName()) + if (WS.hasImportName()) Flags |= wasm::WASM_SYMBOL_EXPLICIT_NAME; wasm::WasmSymbolInfo Info; Index: llvm/include/llvm/MC/MCSymbolWasm.h =================================================================== --- llvm/include/llvm/MC/MCSymbolWasm.h +++ llvm/include/llvm/MC/MCSymbolWasm.h @@ -78,6 +78,7 @@ } void setImportModule(StringRef Name) { ImportModule = Name; } + bool hasImportName() const { return ImportName.hasValue(); } const StringRef getImportName() const { if (ImportName.hasValue()) { return ImportName.getValue(); Index: lld/test/wasm/import-names.ll =================================================================== --- /dev/null +++ lld/test/wasm/import-names.ll @@ -1,27 +0,0 @@ -; RUN: llc -filetype=obj %s -o %t.o -; RUN: wasm-ld --allow-undefined -o %t.wasm %t.o -; RUN: obj2yaml %t.wasm | FileCheck %s - -target triple = "wasm32-unknown-unknown" - -declare void @f0() #0 - -define void @_start() { - call void @f0() - ret void -} - -attributes #0 = { "wasm-import-module"="somewhere" "wasm-import-name"="something" } - -; CHECK: - Type: IMPORT -; CHECK-NEXT: Imports: -; CHECK-NEXT: - Module: somewhere -; CHECK-NEXT: Field: something -; CHECK-NEXT: Kind: FUNCTION -; CHECK-NEXT: SigIndex: 0 - -; CHECK: - Type: CUSTOM -; CHECK-NEXT: Name: name -; CHECK-NEXT: FunctionNames: -; CHECK-NEXT: - Index: 0 -; CHECK-NEXT: Name: f0 Index: clang/include/clang/Basic/AttrDocs.td =================================================================== --- clang/include/clang/Basic/AttrDocs.td +++ clang/include/clang/Basic/AttrDocs.td @@ -4026,7 +4026,7 @@ 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. @@ -4036,14 +4036,14 @@ 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. @@ -4053,7 +4053,7 @@ 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. }]; }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits