BitcodeReader.h revision cbd40f8357437a15c653cb8cccd7124a1bb55ae2
1caee0dccffb77a003681345ab3281bcf8684526cChris Lattner//===- BitcodeReader.h - Internal BitcodeReader impl ------------*- C++ -*-===// 2caee0dccffb77a003681345ab3281bcf8684526cChris Lattner// 3caee0dccffb77a003681345ab3281bcf8684526cChris Lattner// The LLVM Compiler Infrastructure 4caee0dccffb77a003681345ab3281bcf8684526cChris Lattner// 54ee451de366474b9c228b4e5fa573795a715216dChris Lattner// This file is distributed under the University of Illinois Open Source 64ee451de366474b9c228b4e5fa573795a715216dChris Lattner// License. See LICENSE.TXT for details. 7caee0dccffb77a003681345ab3281bcf8684526cChris Lattner// 8caee0dccffb77a003681345ab3281bcf8684526cChris Lattner//===----------------------------------------------------------------------===// 9caee0dccffb77a003681345ab3281bcf8684526cChris Lattner// 10caee0dccffb77a003681345ab3281bcf8684526cChris Lattner// This header defines the BitcodeReader class. 11caee0dccffb77a003681345ab3281bcf8684526cChris Lattner// 12caee0dccffb77a003681345ab3281bcf8684526cChris Lattner//===----------------------------------------------------------------------===// 13caee0dccffb77a003681345ab3281bcf8684526cChris Lattner 14caee0dccffb77a003681345ab3281bcf8684526cChris Lattner#ifndef BITCODE_READER_H 15caee0dccffb77a003681345ab3281bcf8684526cChris Lattner#define BITCODE_READER_H 16caee0dccffb77a003681345ab3281bcf8684526cChris Lattner 17f0356fe140af1a30587b9a86bcfb1b2c51b8ce20Jeffrey Yasskin#include "llvm/GVMaterializer.h" 18eaf42abab6d465c38891345d999255871cf03943Devang Patel#include "llvm/Attributes.h" 19522b7b104c864da81c19d8b16c43b7a1f6a2fc40Chris Lattner#include "llvm/Type.h" 20efe65369a74871c3140a540a6c95ce5d1f080954Gabor Greif#include "llvm/OperandTraits.h" 2148f848716e80d01619b239111db48bfac77baad1Chris Lattner#include "llvm/Bitcode/BitstreamReader.h" 2247f96bf24687b5068aec7166cb8b3ac33ae964aeChris Lattner#include "llvm/Bitcode/LLVMBitCodes.h" 2346e7740a4433383e6e5561f089a091c22125bd07Chris Lattner#include "llvm/Support/ValueHandle.h" 2448f848716e80d01619b239111db48bfac77baad1Chris Lattner#include "llvm/ADT/DenseMap.h" 25caee0dccffb77a003681345ab3281bcf8684526cChris Lattner#include <vector> 26caee0dccffb77a003681345ab3281bcf8684526cChris Lattner 27caee0dccffb77a003681345ab3281bcf8684526cChris Lattnernamespace llvm { 28c453f76e2b4d7fd1e042b5b6d4c20556779186dfChris Lattner class MemoryBuffer; 2912ddd409535b52a7fa5157ded9a4cedd161fedb6Benjamin Kramer class LLVMContext; 30522b7b104c864da81c19d8b16c43b7a1f6a2fc40Chris Lattner 31efe65369a74871c3140a540a6c95ce5d1f080954Gabor Greif//===----------------------------------------------------------------------===// 32efe65369a74871c3140a540a6c95ce5d1f080954Gabor Greif// BitcodeReaderValueList Class 33efe65369a74871c3140a540a6c95ce5d1f080954Gabor Greif//===----------------------------------------------------------------------===// 34efe65369a74871c3140a540a6c95ce5d1f080954Gabor Greif 3546e7740a4433383e6e5561f089a091c22125bd07Chris Lattnerclass BitcodeReaderValueList { 3646e7740a4433383e6e5561f089a091c22125bd07Chris Lattner std::vector<WeakVH> ValuePtrs; 37ea693dfab48ee6fc07cc21abc20f487df5057a6bChris Lattner 38ea693dfab48ee6fc07cc21abc20f487df5057a6bChris Lattner /// ResolveConstants - As we resolve forward-referenced constants, we add 39ea693dfab48ee6fc07cc21abc20f487df5057a6bChris Lattner /// information about them to this vector. This allows us to resolve them in 40ea693dfab48ee6fc07cc21abc20f487df5057a6bChris Lattner /// bulk instead of resolving each reference at a time. See the code in 41ea693dfab48ee6fc07cc21abc20f487df5057a6bChris Lattner /// ResolveConstantForwardRefs for more information about this. 42ea693dfab48ee6fc07cc21abc20f487df5057a6bChris Lattner /// 43ea693dfab48ee6fc07cc21abc20f487df5057a6bChris Lattner /// The key of this vector is the placeholder constant, the value is the slot 44ea693dfab48ee6fc07cc21abc20f487df5057a6bChris Lattner /// number that holds the resolved value. 45ea693dfab48ee6fc07cc21abc20f487df5057a6bChris Lattner typedef std::vector<std::pair<Constant*, unsigned> > ResolveConstantsTy; 46ea693dfab48ee6fc07cc21abc20f487df5057a6bChris Lattner ResolveConstantsTy ResolveConstants; 477af453a3bdc069ef769c3d3ba02f57b4271c56d0Chris Lattner LLVMContext &Context; 48522b7b104c864da81c19d8b16c43b7a1f6a2fc40Chris Lattnerpublic: 497af453a3bdc069ef769c3d3ba02f57b4271c56d0Chris Lattner BitcodeReaderValueList(LLVMContext &C) : Context(C) {} 50ea693dfab48ee6fc07cc21abc20f487df5057a6bChris Lattner ~BitcodeReaderValueList() { 51ea693dfab48ee6fc07cc21abc20f487df5057a6bChris Lattner assert(ResolveConstants.empty() && "Constants not resolved?"); 52ea693dfab48ee6fc07cc21abc20f487df5057a6bChris Lattner } 53efe65369a74871c3140a540a6c95ce5d1f080954Gabor Greif 54522b7b104c864da81c19d8b16c43b7a1f6a2fc40Chris Lattner // vector compatibility methods 5546e7740a4433383e6e5561f089a091c22125bd07Chris Lattner unsigned size() const { return ValuePtrs.size(); } 5646e7740a4433383e6e5561f089a091c22125bd07Chris Lattner void resize(unsigned N) { ValuePtrs.resize(N); } 57522b7b104c864da81c19d8b16c43b7a1f6a2fc40Chris Lattner void push_back(Value *V) { 5846e7740a4433383e6e5561f089a091c22125bd07Chris Lattner ValuePtrs.push_back(V); 59522b7b104c864da81c19d8b16c43b7a1f6a2fc40Chris Lattner } 60522b7b104c864da81c19d8b16c43b7a1f6a2fc40Chris Lattner 61b348bb81253a1105d23ab1a1771f8d2a6546aa1bChris Lattner void clear() { 62ea693dfab48ee6fc07cc21abc20f487df5057a6bChris Lattner assert(ResolveConstants.empty() && "Constants not resolved?"); 6346e7740a4433383e6e5561f089a091c22125bd07Chris Lattner ValuePtrs.clear(); 64b348bb81253a1105d23ab1a1771f8d2a6546aa1bChris Lattner } 65b348bb81253a1105d23ab1a1771f8d2a6546aa1bChris Lattner 6646e7740a4433383e6e5561f089a091c22125bd07Chris Lattner Value *operator[](unsigned i) const { 6746e7740a4433383e6e5561f089a091c22125bd07Chris Lattner assert(i < ValuePtrs.size()); 6846e7740a4433383e6e5561f089a091c22125bd07Chris Lattner return ValuePtrs[i]; 6946e7740a4433383e6e5561f089a091c22125bd07Chris Lattner } 70522b7b104c864da81c19d8b16c43b7a1f6a2fc40Chris Lattner 7146e7740a4433383e6e5561f089a091c22125bd07Chris Lattner Value *back() const { return ValuePtrs.back(); } 7246e7740a4433383e6e5561f089a091c22125bd07Chris Lattner void pop_back() { ValuePtrs.pop_back(); } 7346e7740a4433383e6e5561f089a091c22125bd07Chris Lattner bool empty() const { return ValuePtrs.empty(); } 74198f34ac359c48018c6e1f784cf3770ead63b253Chris Lattner void shrinkTo(unsigned N) { 7546e7740a4433383e6e5561f089a091c22125bd07Chris Lattner assert(N <= size() && "Invalid shrinkTo request!"); 7646e7740a4433383e6e5561f089a091c22125bd07Chris Lattner ValuePtrs.resize(N); 77198f34ac359c48018c6e1f784cf3770ead63b253Chris Lattner } 78522b7b104c864da81c19d8b16c43b7a1f6a2fc40Chris Lattner 79522b7b104c864da81c19d8b16c43b7a1f6a2fc40Chris Lattner Constant *getConstantFwdRef(unsigned Idx, const Type *Ty); 80a7c49aac984fafa5dfdfcc2762d4d51b26788e38Chris Lattner Value *getValueFwdRef(unsigned Idx, const Type *Ty); 81a7c49aac984fafa5dfdfcc2762d4d51b26788e38Chris Lattner 8246e7740a4433383e6e5561f089a091c22125bd07Chris Lattner void AssignValue(Value *V, unsigned Idx); 83a7c49aac984fafa5dfdfcc2762d4d51b26788e38Chris Lattner 84ea693dfab48ee6fc07cc21abc20f487df5057a6bChris Lattner /// ResolveConstantForwardRefs - Once all constants are read, this method bulk 85ea693dfab48ee6fc07cc21abc20f487df5057a6bChris Lattner /// resolves any forward references. 86ea693dfab48ee6fc07cc21abc20f487df5057a6bChris Lattner void ResolveConstantForwardRefs(); 87efe65369a74871c3140a540a6c95ce5d1f080954Gabor Greif}; 88efe65369a74871c3140a540a6c95ce5d1f080954Gabor Greif 89d5ac40457b62f37f0abfb1d61064f7c7300e91eeDevang Patel 90d5ac40457b62f37f0abfb1d61064f7c7300e91eeDevang Patel//===----------------------------------------------------------------------===// 91d5ac40457b62f37f0abfb1d61064f7c7300e91eeDevang Patel// BitcodeReaderMDValueList Class 92d5ac40457b62f37f0abfb1d61064f7c7300e91eeDevang Patel//===----------------------------------------------------------------------===// 93d5ac40457b62f37f0abfb1d61064f7c7300e91eeDevang Patel 94d5ac40457b62f37f0abfb1d61064f7c7300e91eeDevang Patelclass BitcodeReaderMDValueList { 95d5ac40457b62f37f0abfb1d61064f7c7300e91eeDevang Patel std::vector<WeakVH> MDValuePtrs; 96d5ac40457b62f37f0abfb1d61064f7c7300e91eeDevang Patel 9750b136dae90eb37f9fc9517a8638020db4f04f9cChris Lattner LLVMContext &Context; 98d5ac40457b62f37f0abfb1d61064f7c7300e91eeDevang Patelpublic: 99d5ac40457b62f37f0abfb1d61064f7c7300e91eeDevang Patel BitcodeReaderMDValueList(LLVMContext& C) : Context(C) {} 100d5ac40457b62f37f0abfb1d61064f7c7300e91eeDevang Patel 101d5ac40457b62f37f0abfb1d61064f7c7300e91eeDevang Patel // vector compatibility methods 102d5ac40457b62f37f0abfb1d61064f7c7300e91eeDevang Patel unsigned size() const { return MDValuePtrs.size(); } 103d5ac40457b62f37f0abfb1d61064f7c7300e91eeDevang Patel void resize(unsigned N) { MDValuePtrs.resize(N); } 104d5ac40457b62f37f0abfb1d61064f7c7300e91eeDevang Patel void push_back(Value *V) { MDValuePtrs.push_back(V); } 105d5ac40457b62f37f0abfb1d61064f7c7300e91eeDevang Patel void clear() { MDValuePtrs.clear(); } 106d5ac40457b62f37f0abfb1d61064f7c7300e91eeDevang Patel Value *back() const { return MDValuePtrs.back(); } 107d5ac40457b62f37f0abfb1d61064f7c7300e91eeDevang Patel void pop_back() { MDValuePtrs.pop_back(); } 108d5ac40457b62f37f0abfb1d61064f7c7300e91eeDevang Patel bool empty() const { return MDValuePtrs.empty(); } 109d5ac40457b62f37f0abfb1d61064f7c7300e91eeDevang Patel 110d5ac40457b62f37f0abfb1d61064f7c7300e91eeDevang Patel Value *operator[](unsigned i) const { 111d5ac40457b62f37f0abfb1d61064f7c7300e91eeDevang Patel assert(i < MDValuePtrs.size()); 112d5ac40457b62f37f0abfb1d61064f7c7300e91eeDevang Patel return MDValuePtrs[i]; 113d5ac40457b62f37f0abfb1d61064f7c7300e91eeDevang Patel } 114d5ac40457b62f37f0abfb1d61064f7c7300e91eeDevang Patel 115d5ac40457b62f37f0abfb1d61064f7c7300e91eeDevang Patel void shrinkTo(unsigned N) { 116d5ac40457b62f37f0abfb1d61064f7c7300e91eeDevang Patel assert(N <= size() && "Invalid shrinkTo request!"); 117d5ac40457b62f37f0abfb1d61064f7c7300e91eeDevang Patel MDValuePtrs.resize(N); 118d5ac40457b62f37f0abfb1d61064f7c7300e91eeDevang Patel } 119d5ac40457b62f37f0abfb1d61064f7c7300e91eeDevang Patel 120d5ac40457b62f37f0abfb1d61064f7c7300e91eeDevang Patel Value *getValueFwdRef(unsigned Idx); 121d5ac40457b62f37f0abfb1d61064f7c7300e91eeDevang Patel void AssignValue(Value *V, unsigned Idx); 122d5ac40457b62f37f0abfb1d61064f7c7300e91eeDevang Patel}; 123d5ac40457b62f37f0abfb1d61064f7c7300e91eeDevang Patel 124f0356fe140af1a30587b9a86bcfb1b2c51b8ce20Jeffrey Yasskinclass BitcodeReader : public GVMaterializer { 12550b136dae90eb37f9fc9517a8638020db4f04f9cChris Lattner LLVMContext &Context; 126f0356fe140af1a30587b9a86bcfb1b2c51b8ce20Jeffrey Yasskin Module *TheModule; 127c453f76e2b4d7fd1e042b5b6d4c20556779186dfChris Lattner MemoryBuffer *Buffer; 128f0356fe140af1a30587b9a86bcfb1b2c51b8ce20Jeffrey Yasskin bool BufferOwned; 129962dde3cef3184f1683d5070c298c9a29509d62eChris Lattner BitstreamReader StreamFile; 130962dde3cef3184f1683d5070c298c9a29509d62eChris Lattner BitstreamCursor Stream; 13148f848716e80d01619b239111db48bfac77baad1Chris Lattner 132caee0dccffb77a003681345ab3281bcf8684526cChris Lattner const char *ErrorString; 133caee0dccffb77a003681345ab3281bcf8684526cChris Lattner 134caee0dccffb77a003681345ab3281bcf8684526cChris Lattner std::vector<PATypeHolder> TypeList; 135522b7b104c864da81c19d8b16c43b7a1f6a2fc40Chris Lattner BitcodeReaderValueList ValueList; 136d5ac40457b62f37f0abfb1d61064f7c7300e91eeDevang Patel BitcodeReaderMDValueList MDValueList; 137e8e0213cc3daa2d0457c22e4c12e6973f21fc942Devang Patel SmallVector<Instruction *, 64> InstructionList; 138e8e0213cc3daa2d0457c22e4c12e6973f21fc942Devang Patel 139e16504eb4ef8f09611cdf6e9a0be9eb886b4ed89Chris Lattner std::vector<std::pair<GlobalVariable*, unsigned> > GlobalInits; 14007d98b4afbdcbb4eed048400d9116de1ec83e866Chris Lattner std::vector<std::pair<GlobalAlias*, unsigned> > AliasInits; 14148f848716e80d01619b239111db48bfac77baad1Chris Lattner 14219c874638d9478a5d5028854817a5ee72293bb2bDevang Patel /// MAttributes - The set of attributes by index. Index zero in the 14348c85b84c1b66fb6a1b0d2afddf33da5bd82960dChris Lattner /// file is for null, and is thus not represented here. As such all indices 14448c85b84c1b66fb6a1b0d2afddf33da5bd82960dChris Lattner /// are off by one. 14519c874638d9478a5d5028854817a5ee72293bb2bDevang Patel std::vector<AttrListPtr> MAttributes; 14648c85b84c1b66fb6a1b0d2afddf33da5bd82960dChris Lattner 147980e5aad4cfaa32e13b297f4201eb1088ca96cc4Chris Lattner /// FunctionBBs - While parsing a function body, this is a list of the basic 148980e5aad4cfaa32e13b297f4201eb1088ca96cc4Chris Lattner /// blocks for the function. 149980e5aad4cfaa32e13b297f4201eb1088ca96cc4Chris Lattner std::vector<BasicBlock*> FunctionBBs; 150980e5aad4cfaa32e13b297f4201eb1088ca96cc4Chris Lattner 15148f848716e80d01619b239111db48bfac77baad1Chris Lattner // When reading the module header, this list is populated with functions that 15248f848716e80d01619b239111db48bfac77baad1Chris Lattner // have bodies later in the file. 15348f848716e80d01619b239111db48bfac77baad1Chris Lattner std::vector<Function*> FunctionsWithBodies; 1546994040a952e5fb27605eb3cf29ed86c4e59cf62Chandler Carruth 1556994040a952e5fb27605eb3cf29ed86c4e59cf62Chandler Carruth // When intrinsic functions are encountered which require upgrading they are 1566994040a952e5fb27605eb3cf29ed86c4e59cf62Chandler Carruth // stored here with their replacement function. 1576994040a952e5fb27605eb3cf29ed86c4e59cf62Chandler Carruth typedef std::vector<std::pair<Function*, Function*> > UpgradedIntrinsicMap; 1586994040a952e5fb27605eb3cf29ed86c4e59cf62Chandler Carruth UpgradedIntrinsicMap UpgradedIntrinsics; 15919538d1e9fb4f8198b94f8450c6fc43528d8b868Dan Gohman 16019538d1e9fb4f8198b94f8450c6fc43528d8b868Dan Gohman // Map the bitcode's custom MDKind ID to the Module's MDKind ID. 16119538d1e9fb4f8198b94f8450c6fc43528d8b868Dan Gohman DenseMap<unsigned, unsigned> MDKindMap; 16248f848716e80d01619b239111db48bfac77baad1Chris Lattner 16348f848716e80d01619b239111db48bfac77baad1Chris Lattner // After the module header has been read, the FunctionsWithBodies list is 16448f848716e80d01619b239111db48bfac77baad1Chris Lattner // reversed. This keeps track of whether we've done this yet. 16548f848716e80d01619b239111db48bfac77baad1Chris Lattner bool HasReversedFunctionsWithBodies; 16648f848716e80d01619b239111db48bfac77baad1Chris Lattner 16748f848716e80d01619b239111db48bfac77baad1Chris Lattner /// DeferredFunctionInfo - When function bodies are initially scanned, this 168f0356fe140af1a30587b9a86bcfb1b2c51b8ce20Jeffrey Yasskin /// map contains info about where to find deferred function body in the 169f0356fe140af1a30587b9a86bcfb1b2c51b8ce20Jeffrey Yasskin /// stream. 170f0356fe140af1a30587b9a86bcfb1b2c51b8ce20Jeffrey Yasskin DenseMap<Function*, uint64_t> DeferredFunctionInfo; 17150b136dae90eb37f9fc9517a8638020db4f04f9cChris Lattner 17250b136dae90eb37f9fc9517a8638020db4f04f9cChris Lattner /// BlockAddrFwdRefs - These are blockaddr references to basic blocks. These 17350b136dae90eb37f9fc9517a8638020db4f04f9cChris Lattner /// are resolved lazily when functions are loaded. 17450b136dae90eb37f9fc9517a8638020db4f04f9cChris Lattner typedef std::pair<unsigned, GlobalVariable*> BlockAddrRefTy; 17550b136dae90eb37f9fc9517a8638020db4f04f9cChris Lattner DenseMap<Function*, std::vector<BlockAddrRefTy> > BlockAddrFwdRefs; 1769b10dfb7d6ffb0e4466f908cd7d18212a45cfdacDan Gohman 177caee0dccffb77a003681345ab3281bcf8684526cChris Lattnerpublic: 178081134741b40b342fb2f85722c9cea5d412489a8Chris Lattner explicit BitcodeReader(MemoryBuffer *buffer, LLVMContext &C) 179f0356fe140af1a30587b9a86bcfb1b2c51b8ce20Jeffrey Yasskin : Context(C), TheModule(0), Buffer(buffer), BufferOwned(false), 180020a5a449f297ced1f0fed08fb81c5da87fb7c9aChris Lattner ErrorString(0), ValueList(C), MDValueList(C) { 18148f848716e80d01619b239111db48bfac77baad1Chris Lattner HasReversedFunctionsWithBodies = false; 18248f848716e80d01619b239111db48bfac77baad1Chris Lattner } 183b348bb81253a1105d23ab1a1771f8d2a6546aa1bChris Lattner ~BitcodeReader() { 184b348bb81253a1105d23ab1a1771f8d2a6546aa1bChris Lattner FreeState(); 185b348bb81253a1105d23ab1a1771f8d2a6546aa1bChris Lattner } 186caee0dccffb77a003681345ab3281bcf8684526cChris Lattner 187b348bb81253a1105d23ab1a1771f8d2a6546aa1bChris Lattner void FreeState(); 188c453f76e2b4d7fd1e042b5b6d4c20556779186dfChris Lattner 189f0356fe140af1a30587b9a86bcfb1b2c51b8ce20Jeffrey Yasskin /// setBufferOwned - If this is true, the reader will destroy the MemoryBuffer 190f0356fe140af1a30587b9a86bcfb1b2c51b8ce20Jeffrey Yasskin /// when the reader is destroyed. 191f0356fe140af1a30587b9a86bcfb1b2c51b8ce20Jeffrey Yasskin void setBufferOwned(bool Owned) { BufferOwned = Owned; } 192caee0dccffb77a003681345ab3281bcf8684526cChris Lattner 193f0356fe140af1a30587b9a86bcfb1b2c51b8ce20Jeffrey Yasskin virtual bool isMaterializable(const GlobalValue *GV) const; 194f0356fe140af1a30587b9a86bcfb1b2c51b8ce20Jeffrey Yasskin virtual bool isDematerializable(const GlobalValue *GV) const; 195f0356fe140af1a30587b9a86bcfb1b2c51b8ce20Jeffrey Yasskin virtual bool Materialize(GlobalValue *GV, std::string *ErrInfo = 0); 196f0356fe140af1a30587b9a86bcfb1b2c51b8ce20Jeffrey Yasskin virtual bool MaterializeModule(Module *M, std::string *ErrInfo = 0); 197f0356fe140af1a30587b9a86bcfb1b2c51b8ce20Jeffrey Yasskin virtual void Dematerialize(GlobalValue *GV); 198d67c632d968157e228cf42b588f8759059730ec0Chris Lattner 199caee0dccffb77a003681345ab3281bcf8684526cChris Lattner bool Error(const char *Str) { 200caee0dccffb77a003681345ab3281bcf8684526cChris Lattner ErrorString = Str; 201caee0dccffb77a003681345ab3281bcf8684526cChris Lattner return true; 202caee0dccffb77a003681345ab3281bcf8684526cChris Lattner } 203caee0dccffb77a003681345ab3281bcf8684526cChris Lattner const char *getErrorString() const { return ErrorString; } 204caee0dccffb77a003681345ab3281bcf8684526cChris Lattner 205caee0dccffb77a003681345ab3281bcf8684526cChris Lattner /// @brief Main interface to parsing a bitcode buffer. 206caee0dccffb77a003681345ab3281bcf8684526cChris Lattner /// @returns true if an error occurred. 207f0356fe140af1a30587b9a86bcfb1b2c51b8ce20Jeffrey Yasskin bool ParseBitcodeInto(Module *M); 20834711747a1d2c8713e69333bacef1c880810e371Bill Wendling 20934711747a1d2c8713e69333bacef1c880810e371Bill Wendling /// @brief Cheap mechanism to just extract module triple 21034711747a1d2c8713e69333bacef1c880810e371Bill Wendling /// @returns true if an error occurred. 21134711747a1d2c8713e69333bacef1c880810e371Bill Wendling bool ParseTriple(std::string &Triple); 212caee0dccffb77a003681345ab3281bcf8684526cChris Lattnerprivate: 213caee0dccffb77a003681345ab3281bcf8684526cChris Lattner const Type *getTypeByID(unsigned ID, bool isTypeTable = false); 214a7c49aac984fafa5dfdfcc2762d4d51b26788e38Chris Lattner Value *getFnValueByID(unsigned ID, const Type *Ty) { 215cbd40f8357437a15c653cb8cccd7124a1bb55ae2Chris Lattner if (Ty && Ty->isMetadataTy()) 216d5ac40457b62f37f0abfb1d61064f7c7300e91eeDevang Patel return MDValueList.getValueFwdRef(ID); 2177af453a3bdc069ef769c3d3ba02f57b4271c56d0Chris Lattner return ValueList.getValueFwdRef(ID, Ty); 218a7c49aac984fafa5dfdfcc2762d4d51b26788e38Chris Lattner } 219f4c8e5243376af58e52c4a0930d838509bbbea2fChris Lattner BasicBlock *getBasicBlock(unsigned ID) const { 220f4c8e5243376af58e52c4a0930d838509bbbea2fChris Lattner if (ID >= FunctionBBs.size()) return 0; // Invalid ID 221f4c8e5243376af58e52c4a0930d838509bbbea2fChris Lattner return FunctionBBs[ID]; 222f4c8e5243376af58e52c4a0930d838509bbbea2fChris Lattner } 2230598866c052147c31b808391f58434ce3dbfb838Devang Patel AttrListPtr getAttributes(unsigned i) const { 22419c874638d9478a5d5028854817a5ee72293bb2bDevang Patel if (i-1 < MAttributes.size()) 22519c874638d9478a5d5028854817a5ee72293bb2bDevang Patel return MAttributes[i-1]; 2260598866c052147c31b808391f58434ce3dbfb838Devang Patel return AttrListPtr(); 22748c85b84c1b66fb6a1b0d2afddf33da5bd82960dChris Lattner } 2287337ab9e929a4a787f90d37ee0ed8f4cc27170abChris Lattner 2297337ab9e929a4a787f90d37ee0ed8f4cc27170abChris Lattner /// getValueTypePair - Read a value/type pair out of the specified record from 2307337ab9e929a4a787f90d37ee0ed8f4cc27170abChris Lattner /// slot 'Slot'. Increment Slot past the number of slots used in the record. 2317337ab9e929a4a787f90d37ee0ed8f4cc27170abChris Lattner /// Return true on failure. 2327337ab9e929a4a787f90d37ee0ed8f4cc27170abChris Lattner bool getValueTypePair(SmallVector<uint64_t, 64> &Record, unsigned &Slot, 2337337ab9e929a4a787f90d37ee0ed8f4cc27170abChris Lattner unsigned InstNum, Value *&ResVal) { 2347337ab9e929a4a787f90d37ee0ed8f4cc27170abChris Lattner if (Slot == Record.size()) return true; 235650c938c41adc95e0935c75d7ed4349c46d280d1Jeff Cohen unsigned ValNo = (unsigned)Record[Slot++]; 2367337ab9e929a4a787f90d37ee0ed8f4cc27170abChris Lattner if (ValNo < InstNum) { 2377337ab9e929a4a787f90d37ee0ed8f4cc27170abChris Lattner // If this is not a forward reference, just return the value we already 2387337ab9e929a4a787f90d37ee0ed8f4cc27170abChris Lattner // have. 2397337ab9e929a4a787f90d37ee0ed8f4cc27170abChris Lattner ResVal = getFnValueByID(ValNo, 0); 2407337ab9e929a4a787f90d37ee0ed8f4cc27170abChris Lattner return ResVal == 0; 2417337ab9e929a4a787f90d37ee0ed8f4cc27170abChris Lattner } else if (Slot == Record.size()) { 2427337ab9e929a4a787f90d37ee0ed8f4cc27170abChris Lattner return true; 2437337ab9e929a4a787f90d37ee0ed8f4cc27170abChris Lattner } 2447337ab9e929a4a787f90d37ee0ed8f4cc27170abChris Lattner 245650c938c41adc95e0935c75d7ed4349c46d280d1Jeff Cohen unsigned TypeNo = (unsigned)Record[Slot++]; 2467337ab9e929a4a787f90d37ee0ed8f4cc27170abChris Lattner ResVal = getFnValueByID(ValNo, getTypeByID(TypeNo)); 2477337ab9e929a4a787f90d37ee0ed8f4cc27170abChris Lattner return ResVal == 0; 2487337ab9e929a4a787f90d37ee0ed8f4cc27170abChris Lattner } 2497337ab9e929a4a787f90d37ee0ed8f4cc27170abChris Lattner bool getValue(SmallVector<uint64_t, 64> &Record, unsigned &Slot, 2507337ab9e929a4a787f90d37ee0ed8f4cc27170abChris Lattner const Type *Ty, Value *&ResVal) { 2517337ab9e929a4a787f90d37ee0ed8f4cc27170abChris Lattner if (Slot == Record.size()) return true; 252650c938c41adc95e0935c75d7ed4349c46d280d1Jeff Cohen unsigned ValNo = (unsigned)Record[Slot++]; 2537337ab9e929a4a787f90d37ee0ed8f4cc27170abChris Lattner ResVal = getFnValueByID(ValNo, Ty); 2547337ab9e929a4a787f90d37ee0ed8f4cc27170abChris Lattner return ResVal == 0; 2557337ab9e929a4a787f90d37ee0ed8f4cc27170abChris Lattner } 25648c85b84c1b66fb6a1b0d2afddf33da5bd82960dChris Lattner 257caee0dccffb77a003681345ab3281bcf8684526cChris Lattner 258f0356fe140af1a30587b9a86bcfb1b2c51b8ce20Jeffrey Yasskin bool ParseModule(); 2590598866c052147c31b808391f58434ce3dbfb838Devang Patel bool ParseAttributeBlock(); 260866971474ced63f725bd3dbf10fdb9e3badb7d9eChris Lattner bool ParseTypeTable(); 261866971474ced63f725bd3dbf10fdb9e3badb7d9eChris Lattner bool ParseTypeSymbolTable(); 262866971474ced63f725bd3dbf10fdb9e3badb7d9eChris Lattner bool ParseValueSymbolTable(); 263866971474ced63f725bd3dbf10fdb9e3badb7d9eChris Lattner bool ParseConstants(); 264980e5aad4cfaa32e13b297f4201eb1088ca96cc4Chris Lattner bool RememberAndSkipFunctionBody(); 265980e5aad4cfaa32e13b297f4201eb1088ca96cc4Chris Lattner bool ParseFunctionBody(Function *F); 26607d98b4afbdcbb4eed048400d9116de1ec83e866Chris Lattner bool ResolveGlobalAndAliasInits(); 267e54abc90fe9942ef3902040a7ac475ce0c369dc9Devang Patel bool ParseMetadata(); 268e8e0213cc3daa2d0457c22e4c12e6973f21fc942Devang Patel bool ParseMetadataAttachment(); 26934711747a1d2c8713e69333bacef1c880810e371Bill Wendling bool ParseModuleTriple(std::string &Triple); 270caee0dccffb77a003681345ab3281bcf8684526cChris Lattner}; 271caee0dccffb77a003681345ab3281bcf8684526cChris Lattner 272caee0dccffb77a003681345ab3281bcf8684526cChris Lattner} // End llvm namespace 273caee0dccffb77a003681345ab3281bcf8684526cChris Lattner 274caee0dccffb77a003681345ab3281bcf8684526cChris Lattner#endif 275