blob: 45452ba0cb359a90b48c2edc0d85439b67aa44ef [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 Lattnercaee0dc2007-04-22 06:23:29 +000025
26class BitcodeReader : public ModuleProvider {
27 const char *ErrorString;
28
29 std::vector<PATypeHolder> TypeList;
Chris Lattner0b2482a2007-04-23 21:26:05 +000030 std::vector<Value*> ValueList;
Chris Lattnercaee0dc2007-04-22 06:23:29 +000031public:
32 virtual ~BitcodeReader() {}
33
34 virtual void FreeState() {}
35
36 virtual bool materializeFunction(Function *F, std::string *ErrInfo = 0) {
37 // FIXME: TODO
38 return false;
39 }
40
41 virtual Module *materializeModule(std::string *ErrInfo = 0) {
42 // FIXME: TODO
43 //if (ParseAllFunctionBodies(ErrMsg))
44 // return 0;
45 return TheModule;
46 }
47
48 bool Error(const char *Str) {
49 ErrorString = Str;
50 return true;
51 }
52 const char *getErrorString() const { return ErrorString; }
53
54 /// @brief Main interface to parsing a bitcode buffer.
55 /// @returns true if an error occurred.
56 bool ParseBitcode(unsigned char *Buf, unsigned Length,
57 const std::string &ModuleID);
58private:
59 const Type *getTypeByID(unsigned ID, bool isTypeTable = false);
60
61 bool ParseModule(BitstreamReader &Stream, const std::string &ModuleID);
62 bool ParseTypeTable(BitstreamReader &Stream);
63 bool ParseTypeSymbolTable(BitstreamReader &Stream);
Chris Lattner0b2482a2007-04-23 21:26:05 +000064 bool ParseValueSymbolTable(BitstreamReader &Stream);
Chris Lattnercaee0dc2007-04-22 06:23:29 +000065};
66
67} // End llvm namespace
68
69#endif