Initial support for reading bitcode files. They currently only read types,
[oota-llvm.git] / lib / Bitcode / Reader / BitcodeReader.h
1 //===- BitcodeReader.h - Internal BitcodeReader impl ------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by Chris Lattner and is distributed under
6 // the University of Illinois Open Source License.  See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This header defines the BitcodeReader class.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef BITCODE_READER_H
15 #define BITCODE_READER_H
16
17 #include "llvm/AbstractTypeUser.h"
18 #include "llvm/ModuleProvider.h"
19 #include "../LLVMBitCodes.h"
20 #include <vector>
21
22 namespace llvm {
23   class BitstreamReader;
24
25 class BitcodeReader : public ModuleProvider {
26   const char *ErrorString;
27   
28   std::vector<PATypeHolder> TypeList;
29 public:
30   virtual ~BitcodeReader() {}
31   
32   virtual void FreeState() {}
33   
34   virtual bool materializeFunction(Function *F, std::string *ErrInfo = 0) {
35     // FIXME: TODO
36     return false;
37   }
38   
39   virtual Module *materializeModule(std::string *ErrInfo = 0) {
40     // FIXME: TODO
41     //if (ParseAllFunctionBodies(ErrMsg))
42     //  return 0;
43     return TheModule;
44   }
45   
46   bool Error(const char *Str) {
47     ErrorString = Str;
48     return true;
49   }
50   const char *getErrorString() const { return ErrorString; }
51   
52   /// @brief Main interface to parsing a bitcode buffer.
53   /// @returns true if an error occurred.
54   bool ParseBitcode(unsigned char *Buf, unsigned Length,
55                     const std::string &ModuleID);
56 private:
57   const Type *getTypeByID(unsigned ID, bool isTypeTable = false);
58   
59   bool ParseModule(BitstreamReader &Stream, const std::string &ModuleID);
60   bool ParseTypeTable(BitstreamReader &Stream);
61   bool ParseTypeSymbolTable(BitstreamReader &Stream);
62 };
63   
64 } // End llvm namespace
65
66 #endif