diff options
author | Puyan Lotfi <puyan@puyan.org> | 2019-08-22 23:29:22 +0000 |
---|---|---|
committer | Puyan Lotfi <puyan@puyan.org> | 2019-08-22 23:29:22 +0000 |
commit | d24184591fb7223fe6fea724be901ee501bf1cc3 (patch) | |
tree | 87ae017316348bb0afa4d4ebd845b001dd922b6b /clang/lib/Frontend/InterfaceStubFunctionsConsumer.cpp | |
parent | d6c1c7bfb68bc4158879e64a24115042c814c07a (diff) | |
download | llvm-d24184591fb7223fe6fea724be901ee501bf1cc3.zip llvm-d24184591fb7223fe6fea724be901ee501bf1cc3.tar.gz llvm-d24184591fb7223fe6fea724be901ee501bf1cc3.tar.bz2 |
[clang][ifs] New interface stubs format (llvm triple based).
After posting llvm-ifs on phabricator, I made some progress in hardening up how
I think the format for Interface Stubs should look. There are a number of
things I think the TBE format was missing (no endianness, no info about the
Object Format because it assumes ELF), so I have added those and broken off
from being as similar to the TBE schema. In a subsequent commit I can drop the
other formats.
An example of how The format will look is as follows:
--- !experimental-ifs-v1
IfsVersion: 1.0
Triple: x86_64-unknown-linux-gnu
ObjectFileFormat: ELF
Symbols:
_Z9nothiddenv: { Type: Func }
_Z10cmdVisiblev: { Type: Func }
...
The format is still marked experimental.
Differential Revision: https://reviews.llvm.org/D66446
llvm-svn: 369715
Diffstat (limited to 'clang/lib/Frontend/InterfaceStubFunctionsConsumer.cpp')
-rw-r--r-- | clang/lib/Frontend/InterfaceStubFunctionsConsumer.cpp | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/clang/lib/Frontend/InterfaceStubFunctionsConsumer.cpp b/clang/lib/Frontend/InterfaceStubFunctionsConsumer.cpp index 970f885..cb597c4 100644 --- a/clang/lib/Frontend/InterfaceStubFunctionsConsumer.cpp +++ b/clang/lib/Frontend/InterfaceStubFunctionsConsumer.cpp @@ -354,9 +354,55 @@ public: OS.flush(); }; + auto writeIfsV1 = + [this](const llvm::Triple &T, const MangledSymbols &Symbols, + const ASTContext &context, StringRef Format, + raw_ostream &OS) -> void { + OS << "--- !" << Format << "\n"; + OS << "IfsVersion: 1.0\n"; + OS << "Triple: " << T.str() << "\n"; + OS << "ObjectFileFormat: " << "ELF" << "\n"; // TODO: For now, just ELF. + OS << "Symbols:\n"; + for (const auto &E : Symbols) { + const MangledSymbol &Symbol = E.second; + for (auto Name : Symbol.Names) { + OS << " " + << (Symbol.ParentName.empty() || Instance.getLangOpts().CPlusPlus + ? "" + : (Symbol.ParentName + ".")) + << Name << ": { Type: "; + switch (Symbol.Type) { + default: + llvm_unreachable( + "clang -emit-iterface-stubs: Unexpected symbol type."); + case llvm::ELF::STT_NOTYPE: + OS << "NoType"; + break; + case llvm::ELF::STT_OBJECT: { + auto VD = cast<ValueDecl>(E.first)->getType(); + OS << "Object, Size: " + << context.getTypeSizeInChars(VD).getQuantity(); + break; + } + case llvm::ELF::STT_FUNC: + OS << "Func"; + break; + } + if (Symbol.Binding == llvm::ELF::STB_WEAK) + OS << ", Weak: true"; + OS << " }\n"; + } + } + OS << "...\n"; + OS.flush(); + }; + if (Format == "experimental-yaml-elf-v1") writeIfoYaml(Instance.getTarget().getTriple(), Symbols, context, Format, *OS); + else if (Format == "experimental-ifs-v1") + writeIfsV1(Instance.getTarget().getTriple(), Symbols, context, Format, + *OS); else writeIfoElfAbiYaml(Instance.getTarget().getTriple(), Symbols, context, Format, *OS); @@ -376,3 +422,10 @@ GenerateInterfaceTBEExpV1Action::CreateASTConsumer(CompilerInstance &CI, return std::make_unique<InterfaceStubFunctionsConsumer>( CI, InFile, "experimental-tapi-elf-v1"); } + +std::unique_ptr<ASTConsumer> +GenerateInterfaceIfsExpV1Action::CreateASTConsumer(CompilerInstance &CI, + StringRef InFile) { + return std::make_unique<InterfaceStubFunctionsConsumer>( + CI, InFile, "experimental-ifs-v1"); +} |