-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[TextAPI] Add support to convert RecordSlices -> InterfaceFile #75007
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
//===- llvm/TextAPI/RecordSlice.h - TAPI RecordSlice ------------*- C++ -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
/// | ||
/// Defines the TAPI Record Visitor. | ||
/// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_TEXTAPI_RECORDVISITOR_H | ||
#define LLVM_TEXTAPI_RECORDVISITOR_H | ||
|
||
#include "llvm/TextAPI/Record.h" | ||
#include "llvm/TextAPI/SymbolSet.h" | ||
|
||
namespace llvm { | ||
namespace MachO { | ||
|
||
/// Base class for any usage of traversing over collected Records. | ||
class RecordVisitor { | ||
public: | ||
virtual ~RecordVisitor(); | ||
|
||
virtual void visitGlobal(const GlobalRecord &) = 0; | ||
virtual void visitObjCInterface(const ObjCInterfaceRecord &); | ||
virtual void visitObjCCategory(const ObjCCategoryRecord &); | ||
}; | ||
|
||
/// Specialized RecordVisitor for collecting exported symbols | ||
/// and undefined symbols if RecordSlice being visited represents a | ||
/// flat-namespaced library. | ||
class SymbolConverter : public RecordVisitor { | ||
public: | ||
SymbolConverter(SymbolSet *Symbols, const Target &T, | ||
const bool RecordUndefs = false) | ||
: Symbols(Symbols), Targ(T), RecordUndefs(RecordUndefs) {} | ||
void visitGlobal(const GlobalRecord &) override; | ||
void visitObjCInterface(const ObjCInterfaceRecord &) override; | ||
void visitObjCCategory(const ObjCCategoryRecord &) override; | ||
|
||
private: | ||
void addIVars(const ArrayRef<ObjCIVarRecord *>, StringRef ContainerName); | ||
SymbolSet *Symbols; | ||
const Target Targ; | ||
const bool RecordUndefs; | ||
}; | ||
|
||
} // end namespace MachO. | ||
} // end namespace llvm. | ||
|
||
#endif // LLVM_TEXTAPI_RECORDVISITOR_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
//===- RecordVisitor.cpp --------------------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
/// | ||
/// Implements the TAPI Record Visitor. | ||
/// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "llvm/TextAPI/RecordVisitor.h" | ||
|
||
using namespace llvm; | ||
using namespace llvm::MachO; | ||
|
||
RecordVisitor::~RecordVisitor() {} | ||
void RecordVisitor::visitObjCInterface(const ObjCInterfaceRecord &) {} | ||
void RecordVisitor::visitObjCCategory(const ObjCCategoryRecord &) {} | ||
|
||
static bool shouldSkipRecord(const Record &R, const bool RecordUndefs) { | ||
if (R.isExported()) | ||
return false; | ||
|
||
// Skip non exported symbols unless for flat namespace libraries. | ||
return !(RecordUndefs && R.isUndefined()); | ||
} | ||
|
||
void SymbolConverter::visitGlobal(const GlobalRecord &GR) { | ||
auto [SymName, SymKind] = parseSymbol(GR.getName(), GR.getFlags()); | ||
if (shouldSkipRecord(GR, RecordUndefs)) | ||
return; | ||
Symbols->addGlobal(SymKind, SymName, GR.getFlags(), Targ); | ||
} | ||
|
||
void SymbolConverter::addIVars(const ArrayRef<ObjCIVarRecord *> IVars, | ||
StringRef ContainerName) { | ||
for (auto *IV : IVars) { | ||
if (shouldSkipRecord(*IV, RecordUndefs)) | ||
continue; | ||
std::string Name = | ||
ObjCIVarRecord::createScopedName(ContainerName, IV->getName()); | ||
Symbols->addGlobal(SymbolKind::ObjectiveCInstanceVariable, Name, | ||
IV->getFlags(), Targ); | ||
} | ||
} | ||
|
||
void SymbolConverter::visitObjCInterface(const ObjCInterfaceRecord &ObjCR) { | ||
if (!shouldSkipRecord(ObjCR, RecordUndefs)) { | ||
Symbols->addGlobal(SymbolKind::ObjectiveCClass, ObjCR.getName(), | ||
ObjCR.getFlags(), Targ); | ||
if (ObjCR.hasExceptionAttribute()) | ||
Symbols->addGlobal(SymbolKind::ObjectiveCClassEHType, ObjCR.getName(), | ||
ObjCR.getFlags(), Targ); | ||
} | ||
|
||
addIVars(ObjCR.getObjCIVars(), ObjCR.getName()); | ||
for (const auto *Cat : ObjCR.getObjCCategories()) | ||
addIVars(Cat->getObjCIVars(), ObjCR.getName()); | ||
} | ||
|
||
void SymbolConverter::visitObjCCategory(const ObjCCategoryRecord &Cat) { | ||
addIVars(Cat.getObjCIVars(), Cat.getName()); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this include needed in the header file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it was transitively included before in
RecordSlice.h
but is actually used in this file, so I moved it.