168f29dacSPuyan Lotfi //===--- InterfaceStubFunctionsConsumer.cpp -------------------------------===//
268f29dacSPuyan Lotfi //
368f29dacSPuyan Lotfi // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
468f29dacSPuyan Lotfi // See https://llvm.org/LICENSE.txt for license information.
568f29dacSPuyan Lotfi // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
668f29dacSPuyan Lotfi //
768f29dacSPuyan Lotfi //===----------------------------------------------------------------------===//
868f29dacSPuyan Lotfi
968f29dacSPuyan Lotfi #include "clang/AST/Mangle.h"
1068f29dacSPuyan Lotfi #include "clang/AST/RecursiveASTVisitor.h"
11d7c5037eSReid Kleckner #include "clang/Basic/TargetInfo.h"
1268f29dacSPuyan Lotfi #include "clang/Frontend/CompilerInstance.h"
1368f29dacSPuyan Lotfi #include "clang/Frontend/FrontendActions.h"
1468f29dacSPuyan Lotfi #include "clang/Sema/TemplateInstCallback.h"
1568f29dacSPuyan Lotfi #include "llvm/BinaryFormat/ELF.h"
1668f29dacSPuyan Lotfi
1768f29dacSPuyan Lotfi using namespace clang;
1868f29dacSPuyan Lotfi
19dc5f805dSBenjamin Kramer namespace {
2068f29dacSPuyan Lotfi class InterfaceStubFunctionsConsumer : public ASTConsumer {
2168f29dacSPuyan Lotfi CompilerInstance &Instance;
2268f29dacSPuyan Lotfi StringRef InFile;
2368f29dacSPuyan Lotfi StringRef Format;
2468f29dacSPuyan Lotfi std::set<std::string> ParsedTemplates;
2568f29dacSPuyan Lotfi
2668f29dacSPuyan Lotfi enum RootDeclOrigin { TopLevel = 0, FromTU = 1, IsLate = 2 };
2768f29dacSPuyan Lotfi struct MangledSymbol {
2868f29dacSPuyan Lotfi std::string ParentName;
2968f29dacSPuyan Lotfi uint8_t Type;
3068f29dacSPuyan Lotfi uint8_t Binding;
3168f29dacSPuyan Lotfi std::vector<std::string> Names;
3268f29dacSPuyan Lotfi MangledSymbol() = delete;
3368f29dacSPuyan Lotfi
MangledSymbol__anon176fdc0d0111::InterfaceStubFunctionsConsumer::MangledSymbol3468f29dacSPuyan Lotfi MangledSymbol(const std::string &ParentName, uint8_t Type, uint8_t Binding,
3568f29dacSPuyan Lotfi std::vector<std::string> Names)
3668f29dacSPuyan Lotfi : ParentName(ParentName), Type(Type), Binding(Binding), Names(Names) {}
3768f29dacSPuyan Lotfi };
3868f29dacSPuyan Lotfi using MangledSymbols = std::map<const NamedDecl *, MangledSymbol>;
3968f29dacSPuyan Lotfi
WriteNamedDecl(const NamedDecl * ND,MangledSymbols & Symbols,int RDO)4068f29dacSPuyan Lotfi bool WriteNamedDecl(const NamedDecl *ND, MangledSymbols &Symbols, int RDO) {
4168f29dacSPuyan Lotfi // Here we filter out anything that's not set to DefaultVisibility.
4268f29dacSPuyan Lotfi // DefaultVisibility is set on a decl when -fvisibility is not specified on
4368f29dacSPuyan Lotfi // the command line (or specified as default) and the decl does not have
4468f29dacSPuyan Lotfi // __attribute__((visibility("hidden"))) set or when the command line
4568f29dacSPuyan Lotfi // argument is set to hidden but the decl explicitly has
4668f29dacSPuyan Lotfi // __attribute__((visibility ("default"))) set. We do this so that the user
4768f29dacSPuyan Lotfi // can have fine grain control of what they want to expose in the stub.
4868f29dacSPuyan Lotfi auto isVisible = [](const NamedDecl *ND) -> bool {
4968f29dacSPuyan Lotfi return ND->getVisibility() == DefaultVisibility;
5068f29dacSPuyan Lotfi };
5168f29dacSPuyan Lotfi
5268f29dacSPuyan Lotfi auto ignoreDecl = [this, isVisible](const NamedDecl *ND) -> bool {
5368f29dacSPuyan Lotfi if (!isVisible(ND))
5468f29dacSPuyan Lotfi return true;
5568f29dacSPuyan Lotfi
56b7526cc2SPuyan Lotfi if (const VarDecl *VD = dyn_cast<VarDecl>(ND)) {
57bd8c8827SPuyan Lotfi if (const auto *Parent = VD->getParentFunctionOrMethod())
58bd8c8827SPuyan Lotfi if (isa<BlockDecl>(Parent) || isa<CXXMethodDecl>(Parent))
59bd8c8827SPuyan Lotfi return true;
60bd8c8827SPuyan Lotfi
612fd11e0bSThorsten Schütt if ((VD->getStorageClass() == StorageClass::SC_Extern) ||
622fd11e0bSThorsten Schütt (VD->getStorageClass() == StorageClass::SC_Static &&
6368f29dacSPuyan Lotfi VD->getParentFunctionOrMethod() == nullptr))
6468f29dacSPuyan Lotfi return true;
65b7526cc2SPuyan Lotfi }
6668f29dacSPuyan Lotfi
6768f29dacSPuyan Lotfi if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(ND)) {
6868f29dacSPuyan Lotfi if (FD->isInlined() && !isa<CXXMethodDecl>(FD) &&
6968f29dacSPuyan Lotfi !Instance.getLangOpts().GNUInline)
7068f29dacSPuyan Lotfi return true;
7168f29dacSPuyan Lotfi if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) {
7268f29dacSPuyan Lotfi if (const auto *RC = dyn_cast<CXXRecordDecl>(MD->getParent()))
7368f29dacSPuyan Lotfi if (isa<ClassTemplateDecl>(RC->getParent()) || !isVisible(RC))
7468f29dacSPuyan Lotfi return true;
7568f29dacSPuyan Lotfi if (MD->isDependentContext() || !MD->hasBody())
7668f29dacSPuyan Lotfi return true;
7768f29dacSPuyan Lotfi }
782fd11e0bSThorsten Schütt if (FD->getStorageClass() == StorageClass::SC_Static)
7968f29dacSPuyan Lotfi return true;
8068f29dacSPuyan Lotfi }
8168f29dacSPuyan Lotfi return false;
8268f29dacSPuyan Lotfi };
8368f29dacSPuyan Lotfi
8468f29dacSPuyan Lotfi auto getParentFunctionDecl = [](const NamedDecl *ND) -> const NamedDecl * {
8568f29dacSPuyan Lotfi if (const VarDecl *VD = dyn_cast<VarDecl>(ND))
8668f29dacSPuyan Lotfi if (const auto *FD =
8768f29dacSPuyan Lotfi dyn_cast_or_null<FunctionDecl>(VD->getParentFunctionOrMethod()))
8868f29dacSPuyan Lotfi return FD;
8968f29dacSPuyan Lotfi return nullptr;
9068f29dacSPuyan Lotfi };
9168f29dacSPuyan Lotfi
9268f29dacSPuyan Lotfi auto getMangledNames = [](const NamedDecl *ND) -> std::vector<std::string> {
9368f29dacSPuyan Lotfi if (!ND)
9468f29dacSPuyan Lotfi return {""};
9568f29dacSPuyan Lotfi ASTNameGenerator NameGen(ND->getASTContext());
9668f29dacSPuyan Lotfi std::vector<std::string> MangledNames = NameGen.getAllManglings(ND);
9768f29dacSPuyan Lotfi if (isa<CXXConstructorDecl>(ND) || isa<CXXDestructorDecl>(ND))
9868f29dacSPuyan Lotfi return MangledNames;
9968f29dacSPuyan Lotfi #ifdef EXPENSIVE_CHECKS
10068f29dacSPuyan Lotfi assert(MangledNames.size() <= 1 && "Expected only one name mangling.");
10168f29dacSPuyan Lotfi #endif
10268f29dacSPuyan Lotfi return {NameGen.getName(ND)};
10368f29dacSPuyan Lotfi };
10468f29dacSPuyan Lotfi
10568f29dacSPuyan Lotfi if (!(RDO & FromTU))
10668f29dacSPuyan Lotfi return true;
10768f29dacSPuyan Lotfi if (Symbols.find(ND) != Symbols.end())
10868f29dacSPuyan Lotfi return true;
10968f29dacSPuyan Lotfi // - Currently have not figured out how to produce the names for FieldDecls.
11068f29dacSPuyan Lotfi // - Do not want to produce symbols for function paremeters.
11168f29dacSPuyan Lotfi if (isa<FieldDecl>(ND) || isa<ParmVarDecl>(ND))
11268f29dacSPuyan Lotfi return true;
11368f29dacSPuyan Lotfi
11468f29dacSPuyan Lotfi const NamedDecl *ParentDecl = getParentFunctionDecl(ND);
11568f29dacSPuyan Lotfi if ((ParentDecl && ignoreDecl(ParentDecl)) || ignoreDecl(ND))
11668f29dacSPuyan Lotfi return true;
11768f29dacSPuyan Lotfi
11868f29dacSPuyan Lotfi if (RDO & IsLate) {
11968f29dacSPuyan Lotfi Instance.getDiagnostics().Report(diag::err_asm_invalid_type_in_input)
12068f29dacSPuyan Lotfi << "Generating Interface Stubs is not supported with "
12168f29dacSPuyan Lotfi "delayed template parsing.";
12268f29dacSPuyan Lotfi } else {
12368f29dacSPuyan Lotfi if (const auto *FD = dyn_cast<FunctionDecl>(ND))
12468f29dacSPuyan Lotfi if (FD->isDependentContext())
12568f29dacSPuyan Lotfi return true;
12668f29dacSPuyan Lotfi
12768f29dacSPuyan Lotfi const bool IsWeak = (ND->hasAttr<WeakAttr>() ||
12868f29dacSPuyan Lotfi ND->hasAttr<WeakRefAttr>() || ND->isWeakImported());
12968f29dacSPuyan Lotfi
13068f29dacSPuyan Lotfi Symbols.insert(std::make_pair(
13168f29dacSPuyan Lotfi ND,
13268f29dacSPuyan Lotfi MangledSymbol(getMangledNames(ParentDecl).front(),
13368f29dacSPuyan Lotfi // Type:
13468f29dacSPuyan Lotfi isa<VarDecl>(ND) ? llvm::ELF::STT_OBJECT
13568f29dacSPuyan Lotfi : llvm::ELF::STT_FUNC,
13668f29dacSPuyan Lotfi // Binding:
13768f29dacSPuyan Lotfi IsWeak ? llvm::ELF::STB_WEAK : llvm::ELF::STB_GLOBAL,
13868f29dacSPuyan Lotfi getMangledNames(ND))));
13968f29dacSPuyan Lotfi }
14068f29dacSPuyan Lotfi return true;
14168f29dacSPuyan Lotfi }
14268f29dacSPuyan Lotfi
14368f29dacSPuyan Lotfi void
HandleDecls(const llvm::iterator_range<DeclContext::decl_iterator> & Decls,MangledSymbols & Symbols,int RDO)14468f29dacSPuyan Lotfi HandleDecls(const llvm::iterator_range<DeclContext::decl_iterator> &Decls,
14568f29dacSPuyan Lotfi MangledSymbols &Symbols, int RDO) {
14668f29dacSPuyan Lotfi for (const auto *D : Decls)
14768f29dacSPuyan Lotfi HandleNamedDecl(dyn_cast<NamedDecl>(D), Symbols, RDO);
14868f29dacSPuyan Lotfi }
14968f29dacSPuyan Lotfi
HandleTemplateSpecializations(const FunctionTemplateDecl & FTD,MangledSymbols & Symbols,int RDO)15068f29dacSPuyan Lotfi void HandleTemplateSpecializations(const FunctionTemplateDecl &FTD,
15168f29dacSPuyan Lotfi MangledSymbols &Symbols, int RDO) {
15268f29dacSPuyan Lotfi for (const auto *D : FTD.specializations())
15368f29dacSPuyan Lotfi HandleNamedDecl(dyn_cast<NamedDecl>(D), Symbols, RDO);
15468f29dacSPuyan Lotfi }
15568f29dacSPuyan Lotfi
HandleTemplateSpecializations(const ClassTemplateDecl & CTD,MangledSymbols & Symbols,int RDO)15668f29dacSPuyan Lotfi void HandleTemplateSpecializations(const ClassTemplateDecl &CTD,
15768f29dacSPuyan Lotfi MangledSymbols &Symbols, int RDO) {
15868f29dacSPuyan Lotfi for (const auto *D : CTD.specializations())
15968f29dacSPuyan Lotfi HandleNamedDecl(dyn_cast<NamedDecl>(D), Symbols, RDO);
16068f29dacSPuyan Lotfi }
16168f29dacSPuyan Lotfi
HandleNamedDecl(const NamedDecl * ND,MangledSymbols & Symbols,int RDO)16268f29dacSPuyan Lotfi bool HandleNamedDecl(const NamedDecl *ND, MangledSymbols &Symbols, int RDO) {
16368f29dacSPuyan Lotfi if (!ND)
16468f29dacSPuyan Lotfi return false;
16568f29dacSPuyan Lotfi
16668f29dacSPuyan Lotfi switch (ND->getKind()) {
16768f29dacSPuyan Lotfi default:
16868f29dacSPuyan Lotfi break;
16968f29dacSPuyan Lotfi case Decl::Kind::Namespace:
17068f29dacSPuyan Lotfi HandleDecls(cast<NamespaceDecl>(ND)->decls(), Symbols, RDO);
17168f29dacSPuyan Lotfi return true;
17268f29dacSPuyan Lotfi case Decl::Kind::CXXRecord:
17368f29dacSPuyan Lotfi HandleDecls(cast<CXXRecordDecl>(ND)->decls(), Symbols, RDO);
17468f29dacSPuyan Lotfi return true;
17568f29dacSPuyan Lotfi case Decl::Kind::ClassTemplateSpecialization:
17668f29dacSPuyan Lotfi HandleDecls(cast<ClassTemplateSpecializationDecl>(ND)->decls(), Symbols,
17768f29dacSPuyan Lotfi RDO);
17868f29dacSPuyan Lotfi return true;
17968f29dacSPuyan Lotfi case Decl::Kind::ClassTemplate:
18068f29dacSPuyan Lotfi HandleTemplateSpecializations(*cast<ClassTemplateDecl>(ND), Symbols, RDO);
18168f29dacSPuyan Lotfi return true;
18268f29dacSPuyan Lotfi case Decl::Kind::FunctionTemplate:
18368f29dacSPuyan Lotfi HandleTemplateSpecializations(*cast<FunctionTemplateDecl>(ND), Symbols,
18468f29dacSPuyan Lotfi RDO);
18568f29dacSPuyan Lotfi return true;
186e3388c42SPuyan Lotfi case Decl::Kind::Record:
187e3388c42SPuyan Lotfi case Decl::Kind::Typedef:
188e3388c42SPuyan Lotfi case Decl::Kind::Enum:
189e3388c42SPuyan Lotfi case Decl::Kind::EnumConstant:
19068f29dacSPuyan Lotfi case Decl::Kind::TemplateTypeParm:
19179e345fbSPuyan Lotfi case Decl::Kind::NonTypeTemplateParm:
19279e345fbSPuyan Lotfi case Decl::Kind::CXXConversion:
19379e345fbSPuyan Lotfi case Decl::Kind::UnresolvedUsingValue:
19479e345fbSPuyan Lotfi case Decl::Kind::Using:
19579e345fbSPuyan Lotfi case Decl::Kind::UsingShadow:
19679e345fbSPuyan Lotfi case Decl::Kind::TypeAliasTemplate:
19779e345fbSPuyan Lotfi case Decl::Kind::TypeAlias:
19879e345fbSPuyan Lotfi case Decl::Kind::VarTemplate:
19979e345fbSPuyan Lotfi case Decl::Kind::VarTemplateSpecialization:
20079e345fbSPuyan Lotfi case Decl::Kind::UsingDirective:
20179e345fbSPuyan Lotfi case Decl::Kind::TemplateTemplateParm:
20279e345fbSPuyan Lotfi case Decl::Kind::ClassTemplatePartialSpecialization:
20379e345fbSPuyan Lotfi case Decl::Kind::IndirectField:
20407e44510SPuyan Lotfi case Decl::Kind::ConstructorUsingShadow:
20507e44510SPuyan Lotfi case Decl::Kind::CXXDeductionGuide:
20607e44510SPuyan Lotfi case Decl::Kind::NamespaceAlias:
20707e44510SPuyan Lotfi case Decl::Kind::UnresolvedUsingTypename:
20868f29dacSPuyan Lotfi return true;
20979e345fbSPuyan Lotfi case Decl::Kind::Var: {
21079e345fbSPuyan Lotfi // Bail on any VarDecl that either has no named symbol.
21179e345fbSPuyan Lotfi if (!ND->getIdentifier())
21279e345fbSPuyan Lotfi return true;
21379e345fbSPuyan Lotfi const auto *VD = cast<VarDecl>(ND);
21479e345fbSPuyan Lotfi // Bail on any VarDecl that is a dependent or templated type.
21579e345fbSPuyan Lotfi if (VD->isTemplated() || VD->getType()->isDependentType())
21679e345fbSPuyan Lotfi return true;
21779e345fbSPuyan Lotfi if (WriteNamedDecl(ND, Symbols, RDO))
21879e345fbSPuyan Lotfi return true;
21979e345fbSPuyan Lotfi break;
22079e345fbSPuyan Lotfi }
22168f29dacSPuyan Lotfi case Decl::Kind::ParmVar:
22268f29dacSPuyan Lotfi case Decl::Kind::CXXMethod:
22368f29dacSPuyan Lotfi case Decl::Kind::CXXConstructor:
22468f29dacSPuyan Lotfi case Decl::Kind::CXXDestructor:
22568f29dacSPuyan Lotfi case Decl::Kind::Function:
22668f29dacSPuyan Lotfi case Decl::Kind::Field:
22768f29dacSPuyan Lotfi if (WriteNamedDecl(ND, Symbols, RDO))
22868f29dacSPuyan Lotfi return true;
22968f29dacSPuyan Lotfi }
23068f29dacSPuyan Lotfi
23168f29dacSPuyan Lotfi // While interface stubs are in the development stage, it's probably best to
23268f29dacSPuyan Lotfi // catch anything that's not a VarDecl or Template/FunctionDecl.
23368f29dacSPuyan Lotfi Instance.getDiagnostics().Report(diag::err_asm_invalid_type_in_input)
23468f29dacSPuyan Lotfi << "Expected a function or function template decl.";
23568f29dacSPuyan Lotfi return false;
23668f29dacSPuyan Lotfi }
23768f29dacSPuyan Lotfi
23868f29dacSPuyan Lotfi public:
InterfaceStubFunctionsConsumer(CompilerInstance & Instance,StringRef InFile,StringRef Format)23968f29dacSPuyan Lotfi InterfaceStubFunctionsConsumer(CompilerInstance &Instance, StringRef InFile,
24068f29dacSPuyan Lotfi StringRef Format)
24168f29dacSPuyan Lotfi : Instance(Instance), InFile(InFile), Format(Format) {}
24268f29dacSPuyan Lotfi
HandleTranslationUnit(ASTContext & context)24368f29dacSPuyan Lotfi void HandleTranslationUnit(ASTContext &context) override {
24468f29dacSPuyan Lotfi struct Visitor : public RecursiveASTVisitor<Visitor> {
24568f29dacSPuyan Lotfi bool VisitNamedDecl(NamedDecl *ND) {
24668f29dacSPuyan Lotfi if (const auto *FD = dyn_cast<FunctionDecl>(ND))
24768f29dacSPuyan Lotfi if (FD->isLateTemplateParsed()) {
24868f29dacSPuyan Lotfi LateParsedDecls.insert(FD);
24968f29dacSPuyan Lotfi return true;
25068f29dacSPuyan Lotfi }
25168f29dacSPuyan Lotfi
25268f29dacSPuyan Lotfi if (const auto *VD = dyn_cast<ValueDecl>(ND)) {
25368f29dacSPuyan Lotfi ValueDecls.insert(VD);
25468f29dacSPuyan Lotfi return true;
25568f29dacSPuyan Lotfi }
25668f29dacSPuyan Lotfi
25768f29dacSPuyan Lotfi NamedDecls.insert(ND);
25868f29dacSPuyan Lotfi return true;
25968f29dacSPuyan Lotfi }
26068f29dacSPuyan Lotfi
26168f29dacSPuyan Lotfi std::set<const NamedDecl *> LateParsedDecls;
26268f29dacSPuyan Lotfi std::set<NamedDecl *> NamedDecls;
26368f29dacSPuyan Lotfi std::set<const ValueDecl *> ValueDecls;
26468f29dacSPuyan Lotfi } v;
26568f29dacSPuyan Lotfi
26668f29dacSPuyan Lotfi v.TraverseDecl(context.getTranslationUnitDecl());
26768f29dacSPuyan Lotfi
26868f29dacSPuyan Lotfi MangledSymbols Symbols;
26968f29dacSPuyan Lotfi auto OS = Instance.createDefaultOutputFile(/*Binary=*/false, InFile, "ifs");
27068f29dacSPuyan Lotfi if (!OS)
27168f29dacSPuyan Lotfi return;
27268f29dacSPuyan Lotfi
27368f29dacSPuyan Lotfi if (Instance.getLangOpts().DelayedTemplateParsing) {
27468f29dacSPuyan Lotfi clang::Sema &S = Instance.getSema();
27568f29dacSPuyan Lotfi for (const auto *FD : v.LateParsedDecls) {
27668f29dacSPuyan Lotfi clang::LateParsedTemplate &LPT =
27768f29dacSPuyan Lotfi *S.LateParsedTemplateMap.find(cast<FunctionDecl>(FD))->second;
27868f29dacSPuyan Lotfi S.LateTemplateParser(S.OpaqueParser, LPT);
27968f29dacSPuyan Lotfi HandleNamedDecl(FD, Symbols, (FromTU | IsLate));
28068f29dacSPuyan Lotfi }
28168f29dacSPuyan Lotfi }
28268f29dacSPuyan Lotfi
28368f29dacSPuyan Lotfi for (const NamedDecl *ND : v.ValueDecls)
28468f29dacSPuyan Lotfi HandleNamedDecl(ND, Symbols, FromTU);
28568f29dacSPuyan Lotfi for (const NamedDecl *ND : v.NamedDecls)
28668f29dacSPuyan Lotfi HandleNamedDecl(ND, Symbols, FromTU);
28768f29dacSPuyan Lotfi
28879e345fbSPuyan Lotfi auto writeIfsV1 = [this](const llvm::Triple &T,
28979e345fbSPuyan Lotfi const MangledSymbols &Symbols,
290d2418459SPuyan Lotfi const ASTContext &context, StringRef Format,
291d2418459SPuyan Lotfi raw_ostream &OS) -> void {
292d2418459SPuyan Lotfi OS << "--- !" << Format << "\n";
293*61fa9afeSHaowei Wu OS << "IfsVersion: 3.0\n";
294*61fa9afeSHaowei Wu OS << "Target: " << T.str() << "\n";
295d2418459SPuyan Lotfi OS << "Symbols:\n";
296d2418459SPuyan Lotfi for (const auto &E : Symbols) {
297d2418459SPuyan Lotfi const MangledSymbol &Symbol = E.second;
298d2418459SPuyan Lotfi for (auto Name : Symbol.Names) {
299e3033c0cSPuyan Lotfi OS << " - { Name: \""
300d2418459SPuyan Lotfi << (Symbol.ParentName.empty() || Instance.getLangOpts().CPlusPlus
301d2418459SPuyan Lotfi ? ""
302d2418459SPuyan Lotfi : (Symbol.ParentName + "."))
303e3033c0cSPuyan Lotfi << Name << "\", Type: ";
304d2418459SPuyan Lotfi switch (Symbol.Type) {
305d2418459SPuyan Lotfi default:
306d2418459SPuyan Lotfi llvm_unreachable(
30717bde36aSPuyan Lotfi "clang -emit-interface-stubs: Unexpected symbol type.");
308d2418459SPuyan Lotfi case llvm::ELF::STT_NOTYPE:
309d2418459SPuyan Lotfi OS << "NoType";
310d2418459SPuyan Lotfi break;
311d2418459SPuyan Lotfi case llvm::ELF::STT_OBJECT: {
312d2418459SPuyan Lotfi auto VD = cast<ValueDecl>(E.first)->getType();
313d2418459SPuyan Lotfi OS << "Object, Size: "
314d2418459SPuyan Lotfi << context.getTypeSizeInChars(VD).getQuantity();
315d2418459SPuyan Lotfi break;
316d2418459SPuyan Lotfi }
317d2418459SPuyan Lotfi case llvm::ELF::STT_FUNC:
318d2418459SPuyan Lotfi OS << "Func";
319d2418459SPuyan Lotfi break;
320d2418459SPuyan Lotfi }
321d2418459SPuyan Lotfi if (Symbol.Binding == llvm::ELF::STB_WEAK)
322d2418459SPuyan Lotfi OS << ", Weak: true";
323d2418459SPuyan Lotfi OS << " }\n";
324d2418459SPuyan Lotfi }
325d2418459SPuyan Lotfi }
326d2418459SPuyan Lotfi OS << "...\n";
327d2418459SPuyan Lotfi OS.flush();
328d2418459SPuyan Lotfi };
329d2418459SPuyan Lotfi
330*61fa9afeSHaowei Wu assert(Format == "ifs-v1" && "Unexpected IFS Format.");
331926f4f76SPuyan Lotfi writeIfsV1(Instance.getTarget().getTriple(), Symbols, context, Format, *OS);
33268f29dacSPuyan Lotfi }
33368f29dacSPuyan Lotfi };
334dc5f805dSBenjamin Kramer } // namespace
33568f29dacSPuyan Lotfi
33668f29dacSPuyan Lotfi std::unique_ptr<ASTConsumer>
CreateASTConsumer(CompilerInstance & CI,StringRef InFile)337e3033c0cSPuyan Lotfi GenerateInterfaceStubsAction::CreateASTConsumer(CompilerInstance &CI,
338d2418459SPuyan Lotfi StringRef InFile) {
339*61fa9afeSHaowei Wu return std::make_unique<InterfaceStubFunctionsConsumer>(CI, InFile, "ifs-v1");
340d2418459SPuyan Lotfi }
341