Skip to content

Commit b7f0911

Browse files
JinkelaLFsWang
authored andcommitted
[CodeGen] implement '.metadata' for Yul.
1 parent 9a8c237 commit b7f0911

File tree

4 files changed

+25
-5
lines changed

4 files changed

+25
-5
lines changed

include/soll/Basic/DiagnosticParseKinds.inc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,3 @@ DIAG(err_multiple_fallbacks, CLASS_ERROR, (unsigned)diag::Severity::Error, "mult
3333
DIAG(warn_virtual_already_specified, CLASS_WARNING, (unsigned)diag::Severity::Warning, "Virtual already specified.", 0, false, 1)
3434
DIAG(warn_override_already_specified, CLASS_WARNING, (unsigned)diag::Severity::Warning, "Override already specified.", 0, false, 1)
3535
DIAG(err_multiinherited_unsupport, CLASS_ERROR, (unsigned)diag::Severity::Error, "Multinherited overrided is not supported!", 0, false, 1)
36-
DIAG(warn_yul_metadata, CLASS_WARNING, (unsigned)diag::Severity::Warning, "soll currently does not attach '.metadata' to wasm bytecode.", 0, false, 1)

lib/CodeGen/CodeGenModule.cpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1619,7 +1619,10 @@ void CodeGenModule::emitYulObject(const YulObject *YO) {
16191619
}
16201620
assert(nullptr != YO->getCode());
16211621
if (YO->getName() == ".metadata") {
1622-
// TODO: attach '.metadata' to wasm bytecode.
1622+
// ignore sub-object and code
1623+
for (const auto *D : YO->getDataList()) {
1624+
emitYulDataInMetadata(D);
1625+
}
16231626
return;
16241627
}
16251628
for (const auto *O : YO->getObjectList()) {
@@ -1659,11 +1662,31 @@ void CodeGenModule::emitYulCode(const YulCode *YC, llvm::StringRef Name) {
16591662
void CodeGenModule::emitYulData(const YulData *YD) {
16601663
llvm::StringRef Name = YD->getUniqueName();
16611664
std::string Data = YD->getBody()->getValue();
1665+
if (YD->getName() == ".metadata") {
1666+
llvm::SmallVector<llvm::Metadata *, 8> Ops;
1667+
llvm::StringRef Name = YD->getName();
1668+
std::string Data = YD->getBody()->getValue();
1669+
Ops.push_back(llvm::MDString::get(VMContext, Name));
1670+
Ops.push_back(llvm::MDString::get(VMContext, Data));
1671+
auto MD = getModule().getOrInsertNamedMetadata("wasm.custom_sections");
1672+
MD->addOperand(llvm::MDTuple::get(VMContext, Ops));
1673+
return;
1674+
}
16621675
llvm::GlobalVariable *Variable =
16631676
createGlobalString(VMContext, getModule(), Data, Name);
16641677
YulDataMap.try_emplace(YD, Variable);
16651678
}
16661679

1680+
void CodeGenModule::emitYulDataInMetadata(const YulData *YD) {
1681+
llvm::SmallVector<llvm::Metadata *, 8> Ops;
1682+
std::string Name = ".metadata." + YD->getName().str();
1683+
std::string Data = YD->getBody()->getValue();
1684+
Ops.push_back(llvm::MDString::get(VMContext, Name));
1685+
Ops.push_back(llvm::MDString::get(VMContext, Data));
1686+
auto MD = getModule().getOrInsertNamedMetadata("wasm.custom_sections");
1687+
MD->addOperand(llvm::MDTuple::get(VMContext, Ops));
1688+
}
1689+
16671690
std::string CodeGenModule::getMangledName(const CallableVarDecl *CVD) {
16681691
// XXX: Implement mangling
16691692
std::string Name = CVD->getUniqueName().str() + '(';

lib/CodeGen/CodeGenModule.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ class CodeGenModule : public CodeGenTypeCache {
254254

255255
void emitYulCode(const YulCode *YC, llvm::StringRef Name);
256256
void emitYulData(const YulData *YD);
257+
void emitYulDataInMetadata(const YulData *YD);
257258
void emitAsmVarDecl(const AsmVarDecl *VD);
258259

259260
void emitABILoad(const FunctionDecl *FD, llvm::BasicBlock *Loader,

lib/Parse/ParseYul.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,6 @@ unique_ptr<YulObject> Parser::parseYulObject() {
5353
ConsumeToken();
5454

5555
auto Name = stringUnquote(std::string(Tok.getLiteralData(), Tok.getLength()));
56-
if (Name == ".metadata") {
57-
Diag(diag::warn_yul_metadata);
58-
}
5956

6057
ConsumeStringToken();
6158
ExpectAndConsume(tok::l_brace);

0 commit comments

Comments
 (0)