[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

@@ -11,6 +11,7 @@
//===----------------------------------------------------------------------===//
#include "Serialization.h"
#include "ModuleFormat.h"
#include "SILFormat.h"
#include "swift/AST/ASTContext.h"
#include "swift/AST/ASTMangler.h"
@@ -3112,6 +3113,18 @@ class Serializer::DeclSerializer : public DeclVisitor<DeclSerializer> {
return;
}
case DAK_Extern: {
auto *theAttr = cast<ExternAttr>(DA);
auto abbrCode = S.DeclTypeAbbrCodes[ExternDeclAttrLayout::Code];
llvm::SmallString<32> blob;
blob.append(theAttr->ModuleName);
blob.append(theAttr->Name);
ExternDeclAttrLayout::emitRecord(
S.Out, S.ScratchRecord, abbrCode, theAttr->isImplicit(),
theAttr->ModuleName.size(), theAttr->Name.size(), blob);
return;
}
case DAK_Section: {
auto *theAttr = cast<SectionAttr>(DA);
auto abbrCode = S.DeclTypeAbbrCodes[SectionDeclAttrLayout::Code];