Skip to content

Commit 43283fa

Browse files
Tommy McMichenbcardosolopes
authored andcommitted
[CIR][Interfaces] Added method to get mangled name from an ASTFunctionDeclInterface
This will be used in functionality coming soon.
1 parent 405ed86 commit 43283fa

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

clang/include/clang/CIR/Interfaces/ASTAttrInterfaces.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#ifndef MLIR_INTERFACES_CIR_AST_ATTR_INTERFACES_H_
1010
#define MLIR_INTERFACES_CIR_AST_ATTR_INTERFACES_H_
1111

12+
#include "llvm/Support/raw_ostream.h"
1213
#include "mlir/IR/Attributes.h"
1314

1415
#include "clang/AST/Attr.h"

clang/include/clang/CIR/Interfaces/ASTAttrInterfaces.td

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,21 @@ let cppNamespace = "::cir" in {
9191
/*defaultImplementation=*/ [{
9292
return $_attr.getAst()->isStatic();
9393
}]
94+
>,
95+
InterfaceMethod<"", "std::string", "getMangledName", (ins), [{}],
96+
/*defaultImplementation=*/ [{
97+
std::string out;
98+
llvm::raw_string_ostream os(out);
99+
std::unique_ptr<clang::MangleContext> mangleCtx(
100+
$_attr.getAst()->getASTContext().createMangleContext());
101+
if (auto *ctor = mlir::dyn_cast<clang::CXXConstructorDecl>($_attr.getAst()))
102+
mangleCtx->mangleCXXName(clang::GlobalDecl(ctor, clang::CXXCtorType::Ctor_Base), os);
103+
else if (auto *dtor = mlir::dyn_cast<clang::CXXDestructorDecl>($_attr.getAst()))
104+
mangleCtx->mangleCXXName(clang::GlobalDecl(dtor, clang::CXXDtorType::Dtor_Base), os);
105+
else
106+
mangleCtx->mangleName(clang::GlobalDecl($_attr.getAst()), os);
107+
return out;
108+
}]
94109
>
95110
];
96111
}

0 commit comments

Comments
 (0)