track global inits
[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/Type.h"
18 #include "llvm/ModuleProvider.h"
19 #include "llvm/Bitcode/LLVMBitCodes.h"
20 #include <vector>
21
22 namespace llvm {
23   class BitstreamReader;
24   class Value;
25   class GlobalValue;
26
27 class BitcodeReader : public ModuleProvider {
28   const char *ErrorString;
29   
30   std::vector<PATypeHolder> TypeList;
31   std::vector<Value*> ValueList;
32   std::vector<std::pair<GlobalValue*, unsigned> > GlobalInits;
33 public:
34   virtual ~BitcodeReader() {}
35   
36   virtual void FreeState() {}
37   
38   virtual bool materializeFunction(Function *F, std::string *ErrInfo = 0) {
39     // FIXME: TODO
40     return false;
41   }
42   
43   virtual Module *materializeModule(std::string *ErrInfo = 0) {
44     // FIXME: TODO
45     //if (ParseAllFunctionBodies(ErrMsg))
46     //  return 0;
47     return TheModule;
48   }
49   
50   bool Error(const char *Str) {
51     ErrorString = Str;
52     return true;
53   }
54   const char *getErrorString() const { return ErrorString; }
55   
56   /// @brief Main interface to parsing a bitcode buffer.
57   /// @returns true if an error occurred.
58   bool ParseBitcode(unsigned char *Buf, unsigned Length,
59                     const std::string &ModuleID);
60 private:
61   const Type *getTypeByID(unsigned ID, bool isTypeTable = false);
62   
63   bool ParseModule(BitstreamReader &Stream, const std::string &ModuleID);
64   bool ParseTypeTable(BitstreamReader &Stream);
65   bool ParseTypeSymbolTable(BitstreamReader &Stream);
66   bool ParseValueSymbolTable(BitstreamReader &Stream);
67 };
68   
69 } // End llvm namespace
70
71 #endif