[wasm] add @_extern(wasm) attribute support

This attribute instructs the compiler that this function declaration
should be "import"ed from host environment. It's equivalent of Clang's
`__attribute__((import_module("module"), import_name("field")))`
This commit is contained in:
Yuta Saito
2023-08-31 20:29:16 +00:00
parent 356bfd56db
commit bd898b0e7e
21 changed files with 311 additions and 3 deletions

View File

@@ -303,6 +303,9 @@ private:
/// empty.
StringRef WasmExportName;
/// Name of a Wasm import module and field if @_extern(wasm) attribute
llvm::Optional<std::pair<StringRef, StringRef>> WasmImportModuleAndField;
/// Has value if there's a profile for this function
/// Contains Function Entry Count
ProfileCounter EntryCount;
@@ -1278,6 +1281,24 @@ public:
StringRef wasmExportName() const { return WasmExportName; }
void setWasmExportName(StringRef value) { WasmExportName = value; }
/// Return Wasm import module name if @_extern(wasm) was used otherwise empty
StringRef wasmImportModuleName() const {
if (WasmImportModuleAndField)
return WasmImportModuleAndField->first;
return StringRef();
}
/// Return Wasm import field name if @_extern(wasm) was used otherwise empty
StringRef wasmImportFieldName() const {
if (WasmImportModuleAndField)
return WasmImportModuleAndField->second;
return StringRef();
}
void setWasmImportModuleAndField(StringRef module, StringRef field) {
WasmImportModuleAndField = std::make_pair(module, field);
}
/// Returns true if this function belongs to a declaration that returns
/// an opaque result type with one or more availability conditions that are
/// allowed to produce a different underlying type at runtime.