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

Side by Side Diff: include/llvm/Support/IRReader.h

Issue 8393017: Bitcode streaming (Closed)
Patch Set: Created 9 years, 1 month 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
OLDNEW
1 //===---- llvm/Support/IRReader.h - Reader for LLVM IR files ----*- C++ -*-===// 1 //===---- llvm/Support/IRReader.h - Reader for LLVM IR files ----*- 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 file defines functions for reading LLVM IR. They support both 10 // This file defines functions for reading LLVM IR. They support both
11 // Bitcode and Assembly, automatically detecting the input format. 11 // Bitcode and Assembly, automatically detecting the input format.
12 // 12 //
13 // These functions must be defined in a header file in order to avoid 13 // These functions must be defined in a header file in order to avoid
14 // library dependencies, since they reference both Bitcode and Assembly 14 // library dependencies, since they reference both Bitcode and Assembly
15 // functions. 15 // functions.
16 // 16 //
17 //===----------------------------------------------------------------------===// 17 //===----------------------------------------------------------------------===//
18 18
19 #ifndef LLVM_SUPPORT_IRREADER_H 19 #ifndef LLVM_SUPPORT_IRREADER_H
20 #define LLVM_SUPPORT_IRREADER_H 20 #define LLVM_SUPPORT_IRREADER_H
21 21
22 #include "llvm/ADT/OwningPtr.h" 22 #include "llvm/ADT/OwningPtr.h"
23 #include "llvm/Assembly/Parser.h" 23 #include "llvm/Assembly/Parser.h"
24 #include "llvm/Bitcode/BitcodeStream.h"
24 #include "llvm/Bitcode/ReaderWriter.h" 25 #include "llvm/Bitcode/ReaderWriter.h"
25 #include "llvm/Support/MemoryBuffer.h" 26 #include "llvm/Support/MemoryBuffer.h"
26 #include "llvm/Support/SourceMgr.h" 27 #include "llvm/Support/SourceMgr.h"
27 #include "llvm/Support/system_error.h" 28 #include "llvm/Support/system_error.h"
28 29
29 namespace llvm { 30 namespace llvm {
30 31
31 /// If the given MemoryBuffer holds a bitcode image, return a Module for it 32 /// If the given MemoryBuffer holds a bitcode image, return a Module for it
32 /// which does lazy deserialization of function bodies. Otherwise, attempt to 33 /// which does lazy deserialization of function bodies. Otherwise, attempt to
33 /// parse it as LLVM Assembly and return a fully populated Module. This 34 /// parse it as LLVM Assembly and return a fully populated Module. This
(...skipping 28 matching lines...) Expand all
62 OwningPtr<MemoryBuffer> File; 63 OwningPtr<MemoryBuffer> File;
63 if (error_code ec = MemoryBuffer::getFileOrSTDIN(Filename.c_str(), File)) { 64 if (error_code ec = MemoryBuffer::getFileOrSTDIN(Filename.c_str(), File)) {
64 Err = SMDiagnostic(Filename, SourceMgr::DK_Error, 65 Err = SMDiagnostic(Filename, SourceMgr::DK_Error,
65 "Could not open input file: " + ec.message()); 66 "Could not open input file: " + ec.message());
66 return 0; 67 return 0;
67 } 68 }
68 69
69 return getLazyIRModule(File.take(), Err, Context); 70 return getLazyIRModule(File.take(), Err, Context);
70 } 71 }
71 72
73 // like lazy file module but does not read the whole file at the start;
jasonwkim 2011/10/25 21:34:12 Use /// for doxygen
(google.com) Derek Schuff 2011/10/25 22:23:22 Done.
74 // instead executes a callback to get more bytes as needed by the parser.
75 // The stream must contain bitcode.
76 inline Module *getLazyIRStreamModule(const std::string &Filename,
77 SMDiagnostic &Err,
78 LLVMContext &Context,
79 StreamChunkCallback cb) {
80 std::string ErrMsg;
81 Module *M = getLazyBitcodeStreamModule(Filename, cb, Context, &ErrMsg);
82 if (M == 0) {
83 Err = SMDiagnostic(Filename, SourceMgr::DK_Error, ErrMsg);
84 return 0;
85 }
86 return M;
87 }
88
72 /// If the given MemoryBuffer holds a bitcode image, return a Module 89 /// If the given MemoryBuffer holds a bitcode image, return a Module
73 /// for it. Otherwise, attempt to parse it as LLVM Assembly and return 90 /// for it. Otherwise, attempt to parse it as LLVM Assembly and return
74 /// a Module for it. This function *always* takes ownership of the given 91 /// a Module for it. This function *always* takes ownership of the given
75 /// MemoryBuffer. 92 /// MemoryBuffer.
76 inline Module *ParseIR(MemoryBuffer *Buffer, 93 inline Module *ParseIR(MemoryBuffer *Buffer,
77 SMDiagnostic &Err, 94 SMDiagnostic &Err,
78 LLVMContext &Context) { 95 LLVMContext &Context) {
79 if (isBitcode((const unsigned char *)Buffer->getBufferStart(), 96 if (isBitcode((const unsigned char *)Buffer->getBufferStart(),
80 (const unsigned char *)Buffer->getBufferEnd())) { 97 (const unsigned char *)Buffer->getBufferEnd())) {
81 std::string ErrMsg; 98 std::string ErrMsg;
(...skipping 21 matching lines...) Expand all
103 "Could not open input file: " + ec.message()); 120 "Could not open input file: " + ec.message());
104 return 0; 121 return 0;
105 } 122 }
106 123
107 return ParseIR(File.take(), Err, Context); 124 return ParseIR(File.take(), Err, Context);
108 } 125 }
109 126
110 } 127 }
111 128
112 #endif 129 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698