clang-tools  7.0.0
BitcodeReader.h
Go to the documentation of this file.
1 //===-- BitcodeReader.h - ClangDoc Bitcode Reader --------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements a reader for parsing the clang-doc internal
11 // representation from LLVM bitcode. The reader takes in a stream of bits and
12 // generates the set of infos that it represents.
13 //
14 //===----------------------------------------------------------------------===//
15 
16 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_DOC_BITCODEREADER_H
17 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_DOC_BITCODEREADER_H
18 
19 #include "BitcodeWriter.h"
20 #include "Representation.h"
21 #include "clang/AST/AST.h"
22 #include "llvm/ADT/SmallVector.h"
23 #include "llvm/Bitcode/BitstreamReader.h"
24 
25 namespace clang {
26 namespace doc {
27 
28 // Class to read bitstream into an InfoSet collection
30 public:
31  ClangDocBitcodeReader(llvm::BitstreamCursor &Stream) : Stream(Stream) {}
32 
33  // Main entry point, calls readBlock to read each block in the given stream.
34  std::vector<std::unique_ptr<Info>> readBitcode();
35 
36 private:
37  enum class Cursor { BadBlock = 1, Record, BlockEnd, BlockBegin };
38 
39  // Top level parsing
40  bool validateStream();
41  bool readVersion();
42  bool readBlockInfoBlock();
43 
44  // Read a block of records into a single Info struct, calls readRecord on each
45  // record found.
46  template <typename T> bool readBlock(unsigned ID, T I);
47 
48  // Step through a block of records to find the next data field.
49  template <typename T> bool readSubBlock(unsigned ID, T I);
50 
51  // Read record data into the given Info data field, calling the appropriate
52  // parseRecord functions to parse and store the data.
53  template <typename T> bool readRecord(unsigned ID, T I);
54 
55  // Allocate the relevant type of info and add read data to the object.
56  template <typename T> std::unique_ptr<Info> createInfo(unsigned ID);
57 
58  // Helper function to step through blocks to find and dispatch the next record
59  // or block to be read.
60  Cursor skipUntilRecordOrBlock(unsigned &BlockOrRecordID);
61 
62  // Helper function to set up the approriate type of Info.
63  std::unique_ptr<Info> readBlockToInfo(unsigned ID);
64 
65  llvm::BitstreamCursor &Stream;
66  Optional<llvm::BitstreamBlockInfo> BlockInfo;
67  FieldId CurrentReferenceField;
68 };
69 
70 } // namespace doc
71 } // namespace clang
72 
73 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_DOC_BITCODEREADER_H
ClangDocBitcodeReader(llvm::BitstreamCursor &Stream)
Definition: BitcodeReader.h:31
llvm::SmallVector< uint64_t, 1024 > Record
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
std::vector< std::unique_ptr< Info > > readBitcode()