| OLD | NEW | 
|---|
| 1 //===- BitcodeReader.h - Internal BitcodeReader impl ------------*- C++ -*-===// | 1 //===- NaClBitcodeReader.h ------------------------------------*- C++ -*-===// | 
|  | 2 //     Internal NaClBitcodeReader implementation | 
| 2 // | 3 // | 
| 3 //                     The LLVM Compiler Infrastructure | 4 //                     The LLVM Compiler Infrastructure | 
| 4 // | 5 // | 
| 5 // This file is distributed under the University of Illinois Open Source | 6 // This file is distributed under the University of Illinois Open Source | 
| 6 // License. See LICENSE.TXT for details. | 7 // License. See LICENSE.TXT for details. | 
| 7 // | 8 // | 
| 8 //===----------------------------------------------------------------------===// | 9 //===----------------------------------------------------------------------===// | 
| 9 // | 10 // | 
| 10 // This header defines the BitcodeReader class. | 11 // This header defines the NaClBitcodeReader class. | 
| 11 // | 12 // | 
| 12 //===----------------------------------------------------------------------===// | 13 //===----------------------------------------------------------------------===// | 
| 13 | 14 | 
| 14 #ifndef BITCODE_READER_H | 15 #ifndef NACL_BITCODE_READER_H | 
| 15 #define BITCODE_READER_H | 16 #define NACL_BITCODE_READER_H | 
| 16 | 17 | 
| 17 #include "llvm/ADT/DenseMap.h" | 18 #include "llvm/ADT/DenseMap.h" | 
| 18 #include "llvm/Bitcode/BitstreamReader.h" | 19 #include "llvm/Bitcode/NaCl/NaClBitstreamReader.h" | 
| 19 #include "llvm/Bitcode/LLVMBitCodes.h" | 20 #include "llvm/Bitcode/NaCl/NaClLLVMBitCodes.h" | 
| 20 #include "llvm/GVMaterializer.h" | 21 #include "llvm/GVMaterializer.h" | 
| 21 #include "llvm/IR/Attributes.h" | 22 #include "llvm/IR/Attributes.h" | 
| 22 #include "llvm/IR/OperandTraits.h" | 23 #include "llvm/IR/OperandTraits.h" | 
| 23 #include "llvm/IR/Type.h" | 24 #include "llvm/IR/Type.h" | 
| 24 #include "llvm/Support/ValueHandle.h" | 25 #include "llvm/Support/ValueHandle.h" | 
| 25 #include <vector> | 26 #include <vector> | 
| 26 | 27 | 
| 27 namespace llvm { | 28 namespace llvm { | 
| 28   class MemoryBuffer; | 29   class MemoryBuffer; | 
| 29   class LLVMContext; | 30   class LLVMContext; | 
| 30 | 31 | 
| 31 //===----------------------------------------------------------------------===// | 32 //===----------------------------------------------------------------------===// | 
| 32 //                          BitcodeReaderValueList Class | 33 //                          NaClBitcodeReaderValueList Class | 
| 33 //===----------------------------------------------------------------------===// | 34 //===----------------------------------------------------------------------===// | 
| 34 | 35 | 
| 35 class BitcodeReaderValueList { | 36 class NaClBitcodeReaderValueList { | 
| 36   std::vector<WeakVH> ValuePtrs; | 37   std::vector<WeakVH> ValuePtrs; | 
| 37 | 38 | 
| 38   /// ResolveConstants - As we resolve forward-referenced constants, we add | 39   /// ResolveConstants - As we resolve forward-referenced constants, we add | 
| 39   /// information about them to this vector.  This allows us to resolve them in | 40   /// information about them to this vector.  This allows us to resolve them in | 
| 40   /// bulk instead of resolving each reference at a time.  See the code in | 41   /// bulk instead of resolving each reference at a time.  See the code in | 
| 41   /// ResolveConstantForwardRefs for more information about this. | 42   /// ResolveConstantForwardRefs for more information about this. | 
| 42   /// | 43   /// | 
| 43   /// The key of this vector is the placeholder constant, the value is the slot | 44   /// The key of this vector is the placeholder constant, the value is the slot | 
| 44   /// number that holds the resolved value. | 45   /// number that holds the resolved value. | 
| 45   typedef std::vector<std::pair<Constant*, unsigned> > ResolveConstantsTy; | 46   typedef std::vector<std::pair<Constant*, unsigned> > ResolveConstantsTy; | 
| 46   ResolveConstantsTy ResolveConstants; | 47   ResolveConstantsTy ResolveConstants; | 
| 47   LLVMContext &Context; | 48   LLVMContext &Context; | 
| 48 public: | 49 public: | 
| 49   BitcodeReaderValueList(LLVMContext &C) : Context(C) {} | 50   NaClBitcodeReaderValueList(LLVMContext &C) : Context(C) {} | 
| 50   ~BitcodeReaderValueList() { | 51   ~NaClBitcodeReaderValueList() { | 
| 51     assert(ResolveConstants.empty() && "Constants not resolved?"); | 52     assert(ResolveConstants.empty() && "Constants not resolved?"); | 
| 52   } | 53   } | 
| 53 | 54 | 
| 54   // vector compatibility methods | 55   // vector compatibility methods | 
| 55   unsigned size() const { return ValuePtrs.size(); } | 56   unsigned size() const { return ValuePtrs.size(); } | 
| 56   void resize(unsigned N) { ValuePtrs.resize(N); } | 57   void resize(unsigned N) { ValuePtrs.resize(N); } | 
| 57   void push_back(Value *V) { | 58   void push_back(Value *V) { | 
| 58     ValuePtrs.push_back(V); | 59     ValuePtrs.push_back(V); | 
| 59   } | 60   } | 
| 60 | 61 | 
| (...skipping 20 matching lines...) Expand all  Loading... | 
| 81 | 82 | 
| 82   void AssignValue(Value *V, unsigned Idx); | 83   void AssignValue(Value *V, unsigned Idx); | 
| 83 | 84 | 
| 84   /// ResolveConstantForwardRefs - Once all constants are read, this method bulk | 85   /// ResolveConstantForwardRefs - Once all constants are read, this method bulk | 
| 85   /// resolves any forward references. | 86   /// resolves any forward references. | 
| 86   void ResolveConstantForwardRefs(); | 87   void ResolveConstantForwardRefs(); | 
| 87 }; | 88 }; | 
| 88 | 89 | 
| 89 | 90 | 
| 90 //===----------------------------------------------------------------------===// | 91 //===----------------------------------------------------------------------===// | 
| 91 //                          BitcodeReaderMDValueList Class | 92 //                          NaClBitcodeReaderMDValueList Class | 
| 92 //===----------------------------------------------------------------------===// | 93 //===----------------------------------------------------------------------===// | 
| 93 | 94 | 
| 94 class BitcodeReaderMDValueList { | 95 class NaClBitcodeReaderMDValueList { | 
| 95   std::vector<WeakVH> MDValuePtrs; | 96   std::vector<WeakVH> MDValuePtrs; | 
| 96 | 97 | 
| 97   LLVMContext &Context; | 98   LLVMContext &Context; | 
| 98 public: | 99 public: | 
| 99   BitcodeReaderMDValueList(LLVMContext& C) : Context(C) {} | 100   NaClBitcodeReaderMDValueList(LLVMContext& C) : Context(C) {} | 
| 100 | 101 | 
| 101   // vector compatibility methods | 102   // vector compatibility methods | 
| 102   unsigned size() const       { return MDValuePtrs.size(); } | 103   unsigned size() const       { return MDValuePtrs.size(); } | 
| 103   void resize(unsigned N)     { MDValuePtrs.resize(N); } | 104   void resize(unsigned N)     { MDValuePtrs.resize(N); } | 
| 104   void push_back(Value *V)    { MDValuePtrs.push_back(V);  } | 105   void push_back(Value *V)    { MDValuePtrs.push_back(V);  } | 
| 105   void clear()                { MDValuePtrs.clear();  } | 106   void clear()                { MDValuePtrs.clear();  } | 
| 106   Value *back() const         { return MDValuePtrs.back(); } | 107   Value *back() const         { return MDValuePtrs.back(); } | 
| 107   void pop_back()             { MDValuePtrs.pop_back(); } | 108   void pop_back()             { MDValuePtrs.pop_back(); } | 
| 108   bool empty() const          { return MDValuePtrs.empty(); } | 109   bool empty() const          { return MDValuePtrs.empty(); } | 
| 109 | 110 | 
| 110   Value *operator[](unsigned i) const { | 111   Value *operator[](unsigned i) const { | 
| 111     assert(i < MDValuePtrs.size()); | 112     assert(i < MDValuePtrs.size()); | 
| 112     return MDValuePtrs[i]; | 113     return MDValuePtrs[i]; | 
| 113   } | 114   } | 
| 114 | 115 | 
| 115   void shrinkTo(unsigned N) { | 116   void shrinkTo(unsigned N) { | 
| 116     assert(N <= size() && "Invalid shrinkTo request!"); | 117     assert(N <= size() && "Invalid shrinkTo request!"); | 
| 117     MDValuePtrs.resize(N); | 118     MDValuePtrs.resize(N); | 
| 118   } | 119   } | 
| 119 | 120 | 
| 120   Value *getValueFwdRef(unsigned Idx); | 121   Value *getValueFwdRef(unsigned Idx); | 
| 121   void AssignValue(Value *V, unsigned Idx); | 122   void AssignValue(Value *V, unsigned Idx); | 
| 122 }; | 123 }; | 
| 123 | 124 | 
| 124 class BitcodeReader : public GVMaterializer { | 125 class NaClBitcodeReader : public GVMaterializer { | 
| 125   LLVMContext &Context; | 126   LLVMContext &Context; | 
| 126   Module *TheModule; | 127   Module *TheModule; | 
| 127   MemoryBuffer *Buffer; | 128   MemoryBuffer *Buffer; | 
| 128   bool BufferOwned; | 129   bool BufferOwned; | 
| 129   OwningPtr<BitstreamReader> StreamFile; | 130   OwningPtr<NaClBitstreamReader> StreamFile; | 
| 130   BitstreamCursor Stream; | 131   NaClBitstreamCursor Stream; | 
| 131   DataStreamer *LazyStreamer; | 132   DataStreamer *LazyStreamer; | 
| 132   uint64_t NextUnreadBit; | 133   uint64_t NextUnreadBit; | 
| 133   bool SeenValueSymbolTable; | 134   bool SeenValueSymbolTable; | 
| 134 | 135 | 
| 135   const char *ErrorString; | 136   const char *ErrorString; | 
| 136 | 137 | 
| 137   std::vector<Type*> TypeList; | 138   std::vector<Type*> TypeList; | 
| 138   BitcodeReaderValueList ValueList; | 139   NaClBitcodeReaderValueList ValueList; | 
| 139   BitcodeReaderMDValueList MDValueList; | 140   NaClBitcodeReaderMDValueList MDValueList; | 
| 140   SmallVector<Instruction *, 64> InstructionList; | 141   SmallVector<Instruction *, 64> InstructionList; | 
| 141   SmallVector<SmallVector<uint64_t, 64>, 64> UseListRecords; | 142   SmallVector<SmallVector<uint64_t, 64>, 64> UseListRecords; | 
| 142 | 143 | 
| 143   std::vector<std::pair<GlobalVariable*, unsigned> > GlobalInits; | 144   std::vector<std::pair<GlobalVariable*, unsigned> > GlobalInits; | 
| 144   std::vector<std::pair<GlobalAlias*, unsigned> > AliasInits; | 145   std::vector<std::pair<GlobalAlias*, unsigned> > AliasInits; | 
| 145 | 146 | 
| 146   /// MAttributes - The set of attributes by index.  Index zero in the | 147   /// MAttributes - The set of attributes by index.  Index zero in the | 
| 147   /// file is for null, and is thus not represented here.  As such all indices | 148   /// file is for null, and is thus not represented here.  As such all indices | 
| 148   /// are off by one. | 149   /// are off by one. | 
| 149   std::vector<AttributeSet> MAttributes; | 150   std::vector<AttributeSet> MAttributes; | 
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 185   /// UseRelativeIDs - Indicates that we are using a new encoding for | 186   /// UseRelativeIDs - Indicates that we are using a new encoding for | 
| 186   /// instruction operands where most operands in the current | 187   /// instruction operands where most operands in the current | 
| 187   /// FUNCTION_BLOCK are encoded relative to the instruction number, | 188   /// FUNCTION_BLOCK are encoded relative to the instruction number, | 
| 188   /// for a more compact encoding.  Some instruction operands are not | 189   /// for a more compact encoding.  Some instruction operands are not | 
| 189   /// relative to the instruction ID: basic block numbers, and types. | 190   /// relative to the instruction ID: basic block numbers, and types. | 
| 190   /// Once the old style function blocks have been phased out, we would | 191   /// Once the old style function blocks have been phased out, we would | 
| 191   /// not need this flag. | 192   /// not need this flag. | 
| 192   bool UseRelativeIDs; | 193   bool UseRelativeIDs; | 
| 193 | 194 | 
| 194 public: | 195 public: | 
| 195   explicit BitcodeReader(MemoryBuffer *buffer, LLVMContext &C) | 196   explicit NaClBitcodeReader(MemoryBuffer *buffer, LLVMContext &C) | 
| 196     : Context(C), TheModule(0), Buffer(buffer), BufferOwned(false), | 197     : Context(C), TheModule(0), Buffer(buffer), BufferOwned(false), | 
| 197       LazyStreamer(0), NextUnreadBit(0), SeenValueSymbolTable(false), | 198       LazyStreamer(0), NextUnreadBit(0), SeenValueSymbolTable(false), | 
| 198       ErrorString(0), ValueList(C), MDValueList(C), | 199       ErrorString(0), ValueList(C), MDValueList(C), | 
| 199       SeenFirstFunctionBody(false), UseRelativeIDs(false) { | 200       SeenFirstFunctionBody(false), UseRelativeIDs(false) { | 
| 200   } | 201   } | 
| 201   explicit BitcodeReader(DataStreamer *streamer, LLVMContext &C) | 202   explicit NaClBitcodeReader(DataStreamer *streamer, LLVMContext &C) | 
| 202     : Context(C), TheModule(0), Buffer(0), BufferOwned(false), | 203     : Context(C), TheModule(0), Buffer(0), BufferOwned(false), | 
| 203       LazyStreamer(streamer), NextUnreadBit(0), SeenValueSymbolTable(false), | 204       LazyStreamer(streamer), NextUnreadBit(0), SeenValueSymbolTable(false), | 
| 204       ErrorString(0), ValueList(C), MDValueList(C), | 205       ErrorString(0), ValueList(C), MDValueList(C), | 
| 205       SeenFirstFunctionBody(false), UseRelativeIDs(false) { | 206       SeenFirstFunctionBody(false), UseRelativeIDs(false) { | 
| 206   } | 207   } | 
| 207   ~BitcodeReader() { | 208   ~NaClBitcodeReader() { | 
| 208     FreeState(); | 209     FreeState(); | 
| 209   } | 210   } | 
| 210 | 211 | 
| 211   void materializeForwardReferencedFunctions(); | 212   void materializeForwardReferencedFunctions(); | 
| 212 | 213 | 
| 213   void FreeState(); | 214   void FreeState(); | 
| 214 | 215 | 
| 215   /// setBufferOwned - If this is true, the reader will destroy the MemoryBuffer | 216   /// setBufferOwned - If this is true, the reader will destroy the MemoryBuffer | 
| 216   /// when the reader is destroyed. | 217   /// when the reader is destroyed. | 
| 217   void setBufferOwned(bool Owned) { BufferOwned = Owned; } | 218   void setBufferOwned(bool Owned) { BufferOwned = Owned; } | 
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 340   bool InitStream(); | 341   bool InitStream(); | 
| 341   bool InitStreamFromBuffer(); | 342   bool InitStreamFromBuffer(); | 
| 342   bool InitLazyStream(); | 343   bool InitLazyStream(); | 
| 343   bool FindFunctionInStream(Function *F, | 344   bool FindFunctionInStream(Function *F, | 
| 344          DenseMap<Function*, uint64_t>::iterator DeferredFunctionInfoIterator); | 345          DenseMap<Function*, uint64_t>::iterator DeferredFunctionInfoIterator); | 
| 345 }; | 346 }; | 
| 346 | 347 | 
| 347 } // End llvm namespace | 348 } // End llvm namespace | 
| 348 | 349 | 
| 349 #endif | 350 #endif | 
| OLD | NEW | 
|---|