OLD | NEW |
1 //===-- llvm/Bitcode/ReaderWriter.h - Bitcode reader/writers ----*- C++ -*-===// | 1 //===-- llvm/Bitcode/ReaderWriter.h - Bitcode reader/writers ----*- C++ -*-===// |
2 // | 2 // |
3 // The LLVM Compiler Infrastructure | 3 // The LLVM Compiler Infrastructure |
4 // | 4 // |
5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
7 // | 7 // |
8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
9 // | 9 // |
10 // This header defines interfaces to read and write LLVM bitcode files/streams. | 10 // This header defines interfaces to read and write LLVM bitcode files/streams. |
11 // | 11 // |
12 //===----------------------------------------------------------------------===// | 12 //===----------------------------------------------------------------------===// |
13 | 13 |
14 #ifndef LLVM_BITCODE_H | 14 #ifndef LLVM_BITCODE_H |
15 #define LLVM_BITCODE_H | 15 #define LLVM_BITCODE_H |
16 | 16 |
| 17 #include "llvm/Bitcode/BitcodeStream.h" |
17 #include <string> | 18 #include <string> |
18 | 19 |
19 namespace llvm { | 20 namespace llvm { |
20 class Module; | 21 class Module; |
21 class MemoryBuffer; | 22 class MemoryBuffer; |
22 class ModulePass; | 23 class ModulePass; |
23 class BitstreamWriter; | 24 class BitstreamWriter; |
24 class LLVMContext; | 25 class LLVMContext; |
25 class raw_ostream; | 26 class raw_ostream; |
26 | 27 |
27 /// getLazyBitcodeModule - Read the header of the specified bitcode buffer | 28 /// getLazyBitcodeModule - Read the header of the specified bitcode buffer |
28 /// and prepare for lazy deserialization of function bodies. If successful, | 29 /// and prepare for lazy deserialization of function bodies. If successful, |
29 /// this takes ownership of 'buffer' and returns a non-null pointer. On | 30 /// this takes ownership of 'buffer' and returns a non-null pointer. On |
30 /// error, this returns null, *does not* take ownership of Buffer, and fills | 31 /// error, this returns null, *does not* take ownership of Buffer, and fills |
31 /// in *ErrMsg with an error description if ErrMsg is non-null. | 32 /// in *ErrMsg with an error description if ErrMsg is non-null. |
32 Module *getLazyBitcodeModule(MemoryBuffer *Buffer, | 33 Module *getLazyBitcodeModule(MemoryBuffer *Buffer, |
33 LLVMContext& Context, | 34 LLVMContext& Context, |
34 std::string *ErrMsg = 0); | 35 std::string *ErrMsg = 0); |
35 | 36 |
| 37 /// Like getLazyBitcodeModule, except it calls cb to get chunks of the |
| 38 /// bitcode instead of needing the whole buffer ahead of time. |
| 39 Module *getLazyBitcodeStreamModule(const std::string &name, |
| 40 StreamChunkCallback cb, |
| 41 LLVMContext& Context, |
| 42 std::string *ErrMsg = 0); |
| 43 |
36 /// getBitcodeTargetTriple - Read the header of the specified bitcode | 44 /// getBitcodeTargetTriple - Read the header of the specified bitcode |
37 /// buffer and extract just the triple information. If successful, | 45 /// buffer and extract just the triple information. If successful, |
38 /// this returns a string and *does not* take ownership | 46 /// this returns a string and *does not* take ownership |
39 /// of 'buffer'. On error, this returns "", and fills in *ErrMsg | 47 /// of 'buffer'. On error, this returns "", and fills in *ErrMsg |
40 /// if ErrMsg is non-null. | 48 /// if ErrMsg is non-null. |
41 std::string getBitcodeTargetTriple(MemoryBuffer *Buffer, | 49 std::string getBitcodeTargetTriple(MemoryBuffer *Buffer, |
42 LLVMContext& Context, | 50 LLVMContext& Context, |
43 std::string *ErrMsg = 0); | 51 std::string *ErrMsg = 0); |
44 | 52 |
45 /// ParseBitcodeFile - Read the specified bitcode file, returning the module. | 53 /// ParseBitcodeFile - Read the specified bitcode file, returning the module. |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 /// uint32_t Magic; // 0x0B17C0DE | 114 /// uint32_t Magic; // 0x0B17C0DE |
107 /// uint32_t Version; // Version, currently always 0. | 115 /// uint32_t Version; // Version, currently always 0. |
108 /// uint32_t BitcodeOffset; // Offset to traditional bitcode file. | 116 /// uint32_t BitcodeOffset; // Offset to traditional bitcode file. |
109 /// uint32_t BitcodeSize; // Size of traditional bitcode file. | 117 /// uint32_t BitcodeSize; // Size of traditional bitcode file. |
110 /// ... potentially other gunk ... | 118 /// ... potentially other gunk ... |
111 /// }; | 119 /// }; |
112 /// | 120 /// |
113 /// This function is called when we find a file with a matching magic number. | 121 /// This function is called when we find a file with a matching magic number. |
114 /// In this case, skip down to the subsection of the file that is actually a | 122 /// In this case, skip down to the subsection of the file that is actually a |
115 /// BC file. | 123 /// BC file. |
116 static inline bool SkipBitcodeWrapperHeader(unsigned char *&BufPtr, | 124 /// If 'verify' is true, check that the file fits in the buffer. |
117 unsigned char *&BufEnd) { | 125 static inline bool SkipBitcodeWrapperHeader(const unsigned char *&BufPtr, |
| 126 const unsigned char *&BufEnd, |
| 127 bool Verify) { |
118 enum { | 128 enum { |
119 KnownHeaderSize = 4*4, // Size of header we read. | 129 KnownHeaderSize = 4*4, // Size of header we read. |
120 OffsetField = 2*4, // Offset in bytes to Offset field. | 130 OffsetField = 2*4, // Offset in bytes to Offset field. |
121 SizeField = 3*4 // Offset in bytes to Size field. | 131 SizeField = 3*4 // Offset in bytes to Size field. |
122 }; | 132 }; |
123 | 133 |
124 // Must contain the header! | 134 // Must contain the header! |
125 if (BufEnd-BufPtr < KnownHeaderSize) return true; | 135 if (BufEnd-BufPtr < KnownHeaderSize) return true; |
126 | 136 |
127 unsigned Offset = ( BufPtr[OffsetField ] | | 137 unsigned Offset = ( BufPtr[OffsetField ] | |
128 (BufPtr[OffsetField+1] << 8) | | 138 (BufPtr[OffsetField+1] << 8) | |
129 (BufPtr[OffsetField+2] << 16) | | 139 (BufPtr[OffsetField+2] << 16) | |
130 (BufPtr[OffsetField+3] << 24)); | 140 (BufPtr[OffsetField+3] << 24)); |
131 unsigned Size = ( BufPtr[SizeField ] | | 141 unsigned Size = ( BufPtr[SizeField ] | |
132 (BufPtr[SizeField +1] << 8) | | 142 (BufPtr[SizeField +1] << 8) | |
133 (BufPtr[SizeField +2] << 16) | | 143 (BufPtr[SizeField +2] << 16) | |
134 (BufPtr[SizeField +3] << 24)); | 144 (BufPtr[SizeField +3] << 24)); |
135 | 145 |
136 // Verify that Offset+Size fits in the file. | 146 // Verify that Offset+Size fits in the file. |
137 if (Offset+Size > unsigned(BufEnd-BufPtr)) | 147 if (Verify && Offset+Size > unsigned(BufEnd-BufPtr)) |
138 return true; | 148 return true; |
139 BufPtr += Offset; | 149 BufPtr += Offset; |
140 BufEnd = BufPtr+Size; | 150 BufEnd = BufPtr+Size; |
141 return false; | 151 return false; |
142 } | 152 } |
143 } // End llvm namespace | 153 } // End llvm namespace |
144 | 154 |
145 #endif | 155 #endif |
OLD | NEW |