summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clang-doc/BitcodeWriter.cpp
diff options
context:
space:
mode:
authorJulie Hockett <juliehockett@google.com>2018-06-04 17:22:20 +0000
committerJulie Hockett <juliehockett@google.com>2018-06-04 17:22:20 +0000
commitd0f9a87215e0a25c640229d04dcd4b806b1c2433 (patch)
tree09f9977bc9a43c3db006fe2678ed55260b507b40 /clang-tools-extra/clang-doc/BitcodeWriter.cpp
parent28624f94d5ab0f122996c7f83e2f723690395bde (diff)
downloadbcm5719-llvm-d0f9a87215e0a25c640229d04dcd4b806b1c2433.tar.gz
bcm5719-llvm-d0f9a87215e0a25c640229d04dcd4b806b1c2433.zip
[clang-doc] Implement reducer portion of the frontend framework
Implements a simple, in-memory reducer for the mapped output of the initial tool. This creates a collection object for storing the deduplicated infos on each declaration, and populates that from the mapper output. The collection object is serialized to LLVM bitstream. On reading each serialized output, it checks to see if a merge is necessary and if so, merges the new info with the existing info (prefering the existing one if conflicts exist). For a more detailed overview of the tool, see the design document on the mailing list: http://lists.llvm.org/pipermail/cfe-dev/2017-December/056203.html Differential Revision: https://reviews.llvm.org/D43341 llvm-svn: 333932
Diffstat (limited to 'clang-tools-extra/clang-doc/BitcodeWriter.cpp')
-rw-r--r--clang-tools-extra/clang-doc/BitcodeWriter.cpp61
1 files changed, 47 insertions, 14 deletions
diff --git a/clang-tools-extra/clang-doc/BitcodeWriter.cpp b/clang-tools-extra/clang-doc/BitcodeWriter.cpp
index c133d9a67d5..623ed1a2af0 100644
--- a/clang-tools-extra/clang-doc/BitcodeWriter.cpp
+++ b/clang-tools-extra/clang-doc/BitcodeWriter.cpp
@@ -214,6 +214,8 @@ static const std::vector<std::pair<BlockId, std::vector<RecordId>>>
// AbbreviationMap
+constexpr char BitCodeConstants::Signature[];
+
void ClangDocBitcodeWriter::AbbreviationMap::add(RecordId RID,
unsigned AbbrevID) {
assert(RecordIdNameMap[RID] && "Unknown RecordId.");
@@ -232,7 +234,7 @@ unsigned ClangDocBitcodeWriter::AbbreviationMap::get(RecordId RID) const {
/// \brief Emits the magic number header to check that its the right format,
/// in this case, 'DOCS'.
void ClangDocBitcodeWriter::emitHeader() {
- for (char C : llvm::StringRef("DOCS"))
+ for (char C : BitCodeConstants::Signature)
Stream.Emit((unsigned)C, BitCodeConstants::SignatureBitSize);
}
@@ -424,22 +426,24 @@ void ClangDocBitcodeWriter::emitBlock(const CommentInfo &I) {
emitBlock(*C);
}
-#define EMITINFO(X) \
- emitRecord(I.USR, X##_USR); \
- emitRecord(I.Name, X##_NAME); \
- for (const auto &N : I.Namespace) \
- emitBlock(N, FieldId::F_namespace); \
- for (const auto &CI : I.Description) \
- emitBlock(CI);
-
void ClangDocBitcodeWriter::emitBlock(const NamespaceInfo &I) {
StreamSubBlockGuard Block(Stream, BI_NAMESPACE_BLOCK_ID);
- EMITINFO(NAMESPACE)
+ emitRecord(I.USR, NAMESPACE_USR);
+ emitRecord(I.Name, NAMESPACE_NAME);
+ for (const auto &N : I.Namespace)
+ emitBlock(N, FieldId::F_namespace);
+ for (const auto &CI : I.Description)
+ emitBlock(CI);
}
void ClangDocBitcodeWriter::emitBlock(const EnumInfo &I) {
StreamSubBlockGuard Block(Stream, BI_ENUM_BLOCK_ID);
- EMITINFO(ENUM)
+ emitRecord(I.USR, ENUM_USR);
+ emitRecord(I.Name, ENUM_NAME);
+ for (const auto &N : I.Namespace)
+ emitBlock(N, FieldId::F_namespace);
+ for (const auto &CI : I.Description)
+ emitBlock(CI);
if (I.DefLoc)
emitRecord(I.DefLoc.getValue(), ENUM_DEFLOCATION);
for (const auto &L : I.Loc)
@@ -451,7 +455,12 @@ void ClangDocBitcodeWriter::emitBlock(const EnumInfo &I) {
void ClangDocBitcodeWriter::emitBlock(const RecordInfo &I) {
StreamSubBlockGuard Block(Stream, BI_RECORD_BLOCK_ID);
- EMITINFO(RECORD)
+ emitRecord(I.USR, RECORD_USR);
+ emitRecord(I.Name, RECORD_NAME);
+ for (const auto &N : I.Namespace)
+ emitBlock(N, FieldId::F_namespace);
+ for (const auto &CI : I.Description)
+ emitBlock(CI);
if (I.DefLoc)
emitRecord(I.DefLoc.getValue(), RECORD_DEFLOCATION);
for (const auto &L : I.Loc)
@@ -467,7 +476,12 @@ void ClangDocBitcodeWriter::emitBlock(const RecordInfo &I) {
void ClangDocBitcodeWriter::emitBlock(const FunctionInfo &I) {
StreamSubBlockGuard Block(Stream, BI_FUNCTION_BLOCK_ID);
- EMITINFO(FUNCTION)
+ emitRecord(I.USR, FUNCTION_USR);
+ emitRecord(I.Name, FUNCTION_NAME);
+ for (const auto &N : I.Namespace)
+ emitBlock(N, FieldId::F_namespace);
+ for (const auto &CI : I.Description)
+ emitBlock(CI);
emitRecord(I.IsMethod, FUNCTION_IS_METHOD);
if (I.DefLoc)
emitRecord(I.DefLoc.getValue(), FUNCTION_DEFLOCATION);
@@ -479,7 +493,26 @@ void ClangDocBitcodeWriter::emitBlock(const FunctionInfo &I) {
emitBlock(N);
}
-#undef EMITINFO
+bool ClangDocBitcodeWriter::dispatchInfoForWrite(Info *I) {
+ switch (I->IT) {
+ case InfoType::IT_namespace:
+ emitBlock(*static_cast<clang::doc::NamespaceInfo *>(I));
+ break;
+ case InfoType::IT_record:
+ emitBlock(*static_cast<clang::doc::RecordInfo *>(I));
+ break;
+ case InfoType::IT_enum:
+ emitBlock(*static_cast<clang::doc::EnumInfo *>(I));
+ break;
+ case InfoType::IT_function:
+ emitBlock(*static_cast<clang::doc::FunctionInfo *>(I));
+ break;
+ default:
+ llvm::errs() << "Unexpected info, unable to write.\n";
+ return true;
+ }
+ return false;
+}
} // namespace doc
} // namespace clang
OpenPOWER on IntegriCloud