This revision was automatically updated to reflect the committed changes.
Closed by commit rGb4f4e370b59a: [WebAssebmly][MC] Support
.import_name/.import_field asm directives (authored by sbc100).
Changed prior to commit:
https://reviews.llvm.org/D70877?vs=231619&id=232660#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D70877/new/
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: clang/include/clang/Basic/AttrDocs.td
===================================================================
--- clang/include/clang/Basic/AttrDocs.td
+++ clang/include/clang/Basic/AttrDocs.td
@@ -4104,7 +4104,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.
@@ -4114,14 +4114,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.
@@ -4131,7 +4131,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
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits