clang-tools  8.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/Optional.h"
23 #include "llvm/ADT/SmallVector.h"
24 #include "llvm/Bitcode/BitstreamReader.h"
25 #include "llvm/Support/Error.h"
26 
27 namespace clang {
28 namespace doc {
29 
30 // Class to read bitstream into an InfoSet collection
32 public:
33  ClangDocBitcodeReader(llvm::BitstreamCursor &Stream) : Stream(Stream) {}
34 
35  // Main entry point, calls readBlock to read each block in the given stream.
36  llvm::Expected<std::vector<std::unique_ptr<Info>>> readBitcode();
37 
38 private:
39  enum class Cursor { BadBlock = 1, Record, BlockEnd, BlockBegin };
40 
41  // Top level parsing
42  llvm::Error validateStream();
43  llvm::Error readVersion();
44  llvm::Error readBlockInfoBlock();
45 
46  // Read a block of records into a single Info struct, calls readRecord on each
47  // record found.
48  template <typename T> llvm::Error readBlock(unsigned ID, T I);
49 
50  // Step through a block of records to find the next data field.
51  template <typename T> llvm::Error readSubBlock(unsigned ID, T I);
52 
53  // Read record data into the given Info data field, calling the appropriate
54  // parseRecord functions to parse and store the data.
55  template <typename T> llvm::Error readRecord(unsigned ID, T I);
56 
57  // Allocate the relevant type of info and add read data to the object.
58  template <typename T>
59  llvm::Expected<std::unique_ptr<Info>> createInfo(unsigned ID);
60 
61  // Helper function to step through blocks to find and dispatch the next record
62  // or block to be read.
63  Cursor skipUntilRecordOrBlock(unsigned &BlockOrRecordID);
64 
65  // Helper function to set up the approriate type of Info.
66  llvm::Expected<std::unique_ptr<Info>> readBlockToInfo(unsigned ID);
67 
68  llvm::BitstreamCursor &Stream;
69  Optional<llvm::BitstreamBlockInfo> BlockInfo;
70  FieldId CurrentReferenceField;
71 };
72 
73 } // namespace doc
74 } // namespace clang
75 
76 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_DOC_BITCODEREADER_H
ClangDocBitcodeReader(llvm::BitstreamCursor &Stream)
Definition: BitcodeReader.h:33
llvm::SmallVector< uint64_t, 1024 > Record
llvm::Expected< std::vector< std::unique_ptr< Info > > > readBitcode()
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//