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

Side by Side Diff: lib/IRReader/IRReader.cpp

Issue 1310883003: Install notion of diagnostic handler into PNaCl bitcode readers. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-llvm.git@master
Patch Set: Fix issues in patch set 2. Created 5 years, 3 months 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 | « lib/Bitcode/NaCl/TestUtils/NaClBitcodeTextReader.cpp ('k') | test/NaCl/Bitcode/invalid.test » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 //===---- IRReader.cpp - Reader for LLVM IR files -------------------------===// 1 //===---- IRReader.cpp - Reader for LLVM IR files -------------------------===//
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 #include "llvm/IRReader/IRReader.h" 10 #include "llvm/IRReader/IRReader.h"
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 static NaClFileFormat NaClDoAutodetectFileFormat( 97 static NaClFileFormat NaClDoAutodetectFileFormat(
98 NaClFileFormat Format, const char unsigned *StartBuffer, 98 NaClFileFormat Format, const char unsigned *StartBuffer,
99 const char unsigned *EndBuffer) { 99 const char unsigned *EndBuffer) {
100 if (Format != AutodetectFileFormat) 100 if (Format != AutodetectFileFormat)
101 return Format; 101 return Format;
102 if (isNaClBitcode(StartBuffer, EndBuffer)) 102 if (isNaClBitcode(StartBuffer, EndBuffer))
103 return PNaClFormat; 103 return PNaClFormat;
104 return LLVMFormat; 104 return LLVMFormat;
105 } 105 }
106 106
107 std::unique_ptr<Module> llvm::NaClParseIR(MemoryBufferRef Buffer, 107 std::unique_ptr<Module>
108 NaClFileFormat Format, 108 llvm::NaClParseIR(MemoryBufferRef Buffer, NaClFileFormat Format,
109 SMDiagnostic &Err, 109 SMDiagnostic &Err, LLVMContext &Context,
110 raw_ostream *Verbose, 110 DiagnosticHandlerFunction DiagnosticHandler) {
111 LLVMContext &Context) {
112 NamedRegionTimer T(TimeIRParsingName, TimeIRParsingGroupName, 111 NamedRegionTimer T(TimeIRParsingName, TimeIRParsingGroupName,
113 TimePassesIsEnabled); 112 TimePassesIsEnabled);
114 Format = NaClDoAutodetectFileFormat( 113 Format = NaClDoAutodetectFileFormat(
115 Format, (const unsigned char *)Buffer.getBufferStart(), 114 Format, (const unsigned char *)Buffer.getBufferStart(),
116 (const unsigned char *)Buffer.getBufferEnd()); 115 (const unsigned char *)Buffer.getBufferEnd());
117 if ((Format == PNaClFormat) && 116 if ((Format == PNaClFormat) &&
118 isNaClBitcode((const unsigned char *)Buffer.getBufferStart(), 117 isNaClBitcode((const unsigned char *)Buffer.getBufferStart(),
119 (const unsigned char *)Buffer.getBufferEnd())) { 118 (const unsigned char *)Buffer.getBufferEnd())) {
120 ErrorOr<Module *> ModuleOrErr = 119 ErrorOr<Module *> ModuleOrErr =
121 NaClParseBitcodeFile(Buffer, Context, Verbose); 120 NaClParseBitcodeFile(Buffer, Context, DiagnosticHandler);
122 if (std::error_code EC = ModuleOrErr.getError()) { 121 if (std::error_code EC = ModuleOrErr.getError()) {
123 Err = SMDiagnostic(Buffer.getBufferIdentifier(), SourceMgr::DK_Error, 122 Err = SMDiagnostic(Buffer.getBufferIdentifier(), SourceMgr::DK_Error,
124 EC.message()); 123 EC.message());
125 return nullptr; 124 return nullptr;
126 } 125 }
127 return std::unique_ptr<Module>(ModuleOrErr.get()); 126 return std::unique_ptr<Module>(ModuleOrErr.get());
128 } else if (Format == LLVMFormat) { 127 } else if (Format == LLVMFormat) {
129 if (isBitcode((const unsigned char *)Buffer.getBufferStart(), 128 if (isBitcode((const unsigned char *)Buffer.getBufferStart(),
130 (const unsigned char *)Buffer.getBufferEnd())) { 129 (const unsigned char *)Buffer.getBufferEnd())) {
131 ErrorOr<Module *> ModuleOrErr = parseBitcodeFile(Buffer, Context); 130 ErrorOr<Module *> ModuleOrErr =
131 parseBitcodeFile(Buffer, Context, DiagnosticHandler);
132 if (std::error_code EC = ModuleOrErr.getError()) { 132 if (std::error_code EC = ModuleOrErr.getError()) {
133 Err = SMDiagnostic(Buffer.getBufferIdentifier(), SourceMgr::DK_Error, 133 Err = SMDiagnostic(Buffer.getBufferIdentifier(), SourceMgr::DK_Error,
134 EC.message()); 134 EC.message());
135 return nullptr; 135 return nullptr;
136 } 136 }
137 return std::unique_ptr<Module>(ModuleOrErr.get()); 137 return std::unique_ptr<Module>(ModuleOrErr.get());
138 } 138 }
139 139
140 return parseAssembly(Buffer, Err, Context); 140 return parseAssembly(Buffer, Err, Context);
141 } else { 141 } else {
142 Err = SMDiagnostic(Buffer.getBufferIdentifier(), SourceMgr::DK_Error, 142 Err = SMDiagnostic(Buffer.getBufferIdentifier(), SourceMgr::DK_Error,
143 "Did not specify correct format for file"); 143 "Did not specify correct format for file");
144 return nullptr; 144 return nullptr;
145 } 145 }
146 } 146 }
147 147
148 std::unique_ptr<Module> llvm::NaClParseIRFile(StringRef Filename, 148 std::unique_ptr<Module>
149 NaClFileFormat Format, 149 llvm::NaClParseIRFile(StringRef Filename, NaClFileFormat Format,
150 SMDiagnostic &Err, 150 SMDiagnostic &Err, LLVMContext &Context,
151 raw_ostream *Verbose, 151 DiagnosticHandlerFunction DiagnosticHandler) {
152 LLVMContext &Context) {
153 ErrorOr<std::unique_ptr<MemoryBuffer>> FileOrErr = 152 ErrorOr<std::unique_ptr<MemoryBuffer>> FileOrErr =
154 MemoryBuffer::getFileOrSTDIN(Filename); 153 MemoryBuffer::getFileOrSTDIN(Filename);
155 if (std::error_code EC = FileOrErr.getError()) { 154 if (std::error_code EC = FileOrErr.getError()) {
156 Err = SMDiagnostic(Filename, SourceMgr::DK_Error, 155 Err = SMDiagnostic(Filename, SourceMgr::DK_Error,
157 "Could not open input file: " + EC.message()); 156 "Could not open input file: " + EC.message());
158 return nullptr; 157 return nullptr;
159 } 158 }
160 159
161 return NaClParseIR(FileOrErr.get()->getMemBufferRef(), Format, Err, Verbose, 160 return NaClParseIR(FileOrErr.get()->getMemBufferRef(), Format, Err, Context,
162 Context); 161 DiagnosticHandler);
163 } 162 }
164 163
165 // @LOCALMOD-END 164 // @LOCALMOD-END
166 165
167 //===----------------------------------------------------------------------===// 166 //===----------------------------------------------------------------------===//
168 // C API. 167 // C API.
169 //===----------------------------------------------------------------------===// 168 //===----------------------------------------------------------------------===//
170 169
171 LLVMBool LLVMParseIRInContext(LLVMContextRef ContextRef, 170 LLVMBool LLVMParseIRInContext(LLVMContextRef ContextRef,
172 LLVMMemoryBufferRef MemBuf, LLVMModuleRef *OutM, 171 LLVMMemoryBufferRef MemBuf, LLVMModuleRef *OutM,
(...skipping 12 matching lines...) Expand all
185 Diag.print(nullptr, os, false); 184 Diag.print(nullptr, os, false);
186 os.flush(); 185 os.flush();
187 186
188 *OutMessage = strdup(buf.c_str()); 187 *OutMessage = strdup(buf.c_str());
189 } 188 }
190 return 1; 189 return 1;
191 } 190 }
192 191
193 return 0; 192 return 0;
194 } 193 }
OLDNEW
« no previous file with comments | « lib/Bitcode/NaCl/TestUtils/NaClBitcodeTextReader.cpp ('k') | test/NaCl/Bitcode/invalid.test » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698