Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(920)

Side by Side Diff: include/llvm/Bitcode/ReaderWriter.h

Issue 8393017: Bitcode streaming (Closed)
Patch Set: put destructors back, fix trailing whitespace Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « include/llvm/Bitcode/BitstreamReader.h ('k') | include/llvm/Support/BitcodeStream.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/Support/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 /// getStreamedBitcodeModule - Read the header of the specified stream
38 /// and prepare for lazy deserialization and streaming of function bodies.
39 /// On error, this returns null, and fills in *ErrMsg with an error
40 /// description if ErrMsg is non-null.
41 Module *getStreamedBitcodeModule(const std::string &name,
42 BitcodeStreamer *streamer,
43 LLVMContext &Context,
44 std::string *ErrMsg = 0);
45
36 /// getBitcodeTargetTriple - Read the header of the specified bitcode 46 /// getBitcodeTargetTriple - Read the header of the specified bitcode
37 /// buffer and extract just the triple information. If successful, 47 /// buffer and extract just the triple information. If successful,
38 /// this returns a string and *does not* take ownership 48 /// this returns a string and *does not* take ownership
39 /// of 'buffer'. On error, this returns "", and fills in *ErrMsg 49 /// of 'buffer'. On error, this returns "", and fills in *ErrMsg
40 /// if ErrMsg is non-null. 50 /// if ErrMsg is non-null.
41 std::string getBitcodeTargetTriple(MemoryBuffer *Buffer, 51 std::string getBitcodeTargetTriple(MemoryBuffer *Buffer,
42 LLVMContext& Context, 52 LLVMContext &Context,
43 std::string *ErrMsg = 0); 53 std::string *ErrMsg = 0);
44 54
45 /// ParseBitcodeFile - Read the specified bitcode file, returning the module. 55 /// ParseBitcodeFile - Read the specified bitcode file, returning the module.
46 /// If an error occurs, this returns null and fills in *ErrMsg if it is 56 /// If an error occurs, this returns null and fills in *ErrMsg if it is
47 /// non-null. This method *never* takes ownership of Buffer. 57 /// non-null. This method *never* takes ownership of Buffer.
48 Module *ParseBitcodeFile(MemoryBuffer *Buffer, LLVMContext& Context, 58 Module *ParseBitcodeFile(MemoryBuffer *Buffer, LLVMContext &Context,
49 std::string *ErrMsg = 0); 59 std::string *ErrMsg = 0);
50 60
51 /// WriteBitcodeToFile - Write the specified module to the specified 61 /// WriteBitcodeToFile - Write the specified module to the specified
52 /// raw output stream. For streams where it matters, the given stream 62 /// raw output stream. For streams where it matters, the given stream
53 /// should be in "binary" mode. 63 /// should be in "binary" mode.
54 void WriteBitcodeToFile(const Module *M, raw_ostream &Out); 64 void WriteBitcodeToFile(const Module *M, raw_ostream &Out);
55 65
56 /// WriteBitcodeToStream - Write the specified module to the specified 66 /// WriteBitcodeToStream - Write the specified module to the specified
57 /// raw output stream. 67 /// raw output stream.
58 void WriteBitcodeToStream(const Module *M, BitstreamWriter &Stream); 68 void WriteBitcodeToStream(const Module *M, BitstreamWriter &Stream);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 /// uint32_t Magic; // 0x0B17C0DE 116 /// uint32_t Magic; // 0x0B17C0DE
107 /// uint32_t Version; // Version, currently always 0. 117 /// uint32_t Version; // Version, currently always 0.
108 /// uint32_t BitcodeOffset; // Offset to traditional bitcode file. 118 /// uint32_t BitcodeOffset; // Offset to traditional bitcode file.
109 /// uint32_t BitcodeSize; // Size of traditional bitcode file. 119 /// uint32_t BitcodeSize; // Size of traditional bitcode file.
110 /// ... potentially other gunk ... 120 /// ... potentially other gunk ...
111 /// }; 121 /// };
112 /// 122 ///
113 /// This function is called when we find a file with a matching magic number. 123 /// 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 124 /// In this case, skip down to the subsection of the file that is actually a
115 /// BC file. 125 /// BC file.
116 static inline bool SkipBitcodeWrapperHeader(unsigned char *&BufPtr, 126 /// If 'verify' is true, check that the file fits in the buffer.
117 unsigned char *&BufEnd) { 127 static inline bool SkipBitcodeWrapperHeader(const unsigned char *&BufPtr,
128 const unsigned char *&BufEnd,
129 bool Verify) {
118 enum { 130 enum {
119 KnownHeaderSize = 4*4, // Size of header we read. 131 KnownHeaderSize = 4*4, // Size of header we read.
120 OffsetField = 2*4, // Offset in bytes to Offset field. 132 OffsetField = 2*4, // Offset in bytes to Offset field.
121 SizeField = 3*4 // Offset in bytes to Size field. 133 SizeField = 3*4 // Offset in bytes to Size field.
122 }; 134 };
123 135
124 // Must contain the header! 136 // Must contain the header!
125 if (BufEnd-BufPtr < KnownHeaderSize) return true; 137 if (BufEnd-BufPtr < KnownHeaderSize) return true;
126 138
127 unsigned Offset = ( BufPtr[OffsetField ] | 139 unsigned Offset = ( BufPtr[OffsetField ] |
128 (BufPtr[OffsetField+1] << 8) | 140 (BufPtr[OffsetField+1] << 8) |
129 (BufPtr[OffsetField+2] << 16) | 141 (BufPtr[OffsetField+2] << 16) |
130 (BufPtr[OffsetField+3] << 24)); 142 (BufPtr[OffsetField+3] << 24));
131 unsigned Size = ( BufPtr[SizeField ] | 143 unsigned Size = ( BufPtr[SizeField ] |
132 (BufPtr[SizeField +1] << 8) | 144 (BufPtr[SizeField +1] << 8) |
133 (BufPtr[SizeField +2] << 16) | 145 (BufPtr[SizeField +2] << 16) |
134 (BufPtr[SizeField +3] << 24)); 146 (BufPtr[SizeField +3] << 24));
135 147
136 // Verify that Offset+Size fits in the file. 148 // Verify that Offset+Size fits in the file.
137 if (Offset+Size > unsigned(BufEnd-BufPtr)) 149 if (Verify && Offset+Size > unsigned(BufEnd-BufPtr))
138 return true; 150 return true;
139 BufPtr += Offset; 151 BufPtr += Offset;
140 BufEnd = BufPtr+Size; 152 BufEnd = BufPtr+Size;
141 return false; 153 return false;
142 } 154 }
143 } // End llvm namespace 155 } // End llvm namespace
144 156
145 #endif 157 #endif
OLDNEW
« no previous file with comments | « include/llvm/Bitcode/BitstreamReader.h ('k') | include/llvm/Support/BitcodeStream.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698