blob: ed11692391c26849786232621df0ed75a24fe071 [file] [log] [blame]
Chris Lattnercaee0dc2007-04-22 06:23:29 +00001//===- 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
Jeff Cohencb403d62007-04-22 18:49:32 +000017#include "llvm/Type.h"
Chris Lattnercaee0dc2007-04-22 06:23:29 +000018#include "llvm/ModuleProvider.h"
Chris Lattner47f96bf2007-04-23 01:01:37 +000019#include "llvm/Bitcode/LLVMBitCodes.h"
Chris Lattnercaee0dc2007-04-22 06:23:29 +000020#include <vector>
21
22namespace llvm {
23 class BitstreamReader;
Chris Lattner0b2482a2007-04-23 21:26:05 +000024 class Value;
Chris Lattner6dbfd7b2007-04-24 00:18:21 +000025 class GlobalValue;
Chris Lattnercaee0dc2007-04-22 06:23:29 +000026
27class BitcodeReader : public ModuleProvider {
28 const char *ErrorString;
29
30 std::vector<PATypeHolder> TypeList;
Chris Lattner0b2482a2007-04-23 21:26:05 +000031 std::vector<Value*> ValueList;
Chris Lattner6dbfd7b2007-04-24 00:18:21 +000032 std::vector<std::pair<GlobalValue*, unsigned> > GlobalInits;
Chris Lattnercaee0dc2007-04-22 06:23:29 +000033public:
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);
60private:
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);
Chris Lattner0b2482a2007-04-23 21:26:05 +000066 bool ParseValueSymbolTable(BitstreamReader &Stream);
Chris Lattnercaee0dc2007-04-22 06:23:29 +000067};
68
69} // End llvm namespace
70
71#endif