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

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

Issue 939073008: Rebased PNaCl localmods in LLVM to 223109 (Closed)
Patch Set: undo localmod Created 5 years, 9 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/IR/NaClAtomicIntrinsics.cpp ('k') | lib/IRReader/LLVMBuild.txt » ('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"
11 #include "llvm-c/Core.h" 11 #include "llvm-c/Core.h"
12 #include "llvm-c/IRReader.h" 12 #include "llvm-c/IRReader.h"
13 #include "llvm/AsmParser/Parser.h" 13 #include "llvm/AsmParser/Parser.h"
14 #include "llvm/Bitcode/NaCl/NaClReaderWriter.h"
14 #include "llvm/Bitcode/ReaderWriter.h" 15 #include "llvm/Bitcode/ReaderWriter.h"
15 #include "llvm/IR/LLVMContext.h" 16 #include "llvm/IR/LLVMContext.h"
16 #include "llvm/IR/Module.h" 17 #include "llvm/IR/Module.h"
17 #include "llvm/Support/MemoryBuffer.h" 18 #include "llvm/Support/MemoryBuffer.h"
18 #include "llvm/Support/SourceMgr.h" 19 #include "llvm/Support/SourceMgr.h"
19 #include "llvm/Support/Timer.h" 20 #include "llvm/Support/Timer.h"
20 #include "llvm/Support/raw_ostream.h" 21 #include "llvm/Support/raw_ostream.h"
21 #include <system_error> 22 #include <system_error>
22 23
23 using namespace llvm; 24 using namespace llvm;
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 MemoryBuffer::getFileOrSTDIN(Filename); 86 MemoryBuffer::getFileOrSTDIN(Filename);
86 if (std::error_code EC = FileOrErr.getError()) { 87 if (std::error_code EC = FileOrErr.getError()) {
87 Err = SMDiagnostic(Filename, SourceMgr::DK_Error, 88 Err = SMDiagnostic(Filename, SourceMgr::DK_Error,
88 "Could not open input file: " + EC.message()); 89 "Could not open input file: " + EC.message());
89 return nullptr; 90 return nullptr;
90 } 91 }
91 92
92 return parseIR(FileOrErr.get()->getMemBufferRef(), Err, Context); 93 return parseIR(FileOrErr.get()->getMemBufferRef(), Err, Context);
93 } 94 }
94 95
96 // @LOCALMOD-BEGIN
97 static NaClFileFormat NaClDoAutodetectFileFormat(
98 NaClFileFormat Format, const char unsigned *StartBuffer,
99 const char unsigned *EndBuffer) {
100 if (Format != AutodetectFileFormat)
101 return Format;
102 if (isNaClBitcode(StartBuffer, EndBuffer))
103 return PNaClFormat;
104 return LLVMFormat;
105 }
106
107 std::unique_ptr<Module> llvm::NaClParseIR(MemoryBufferRef Buffer,
108 NaClFileFormat Format,
109 SMDiagnostic &Err,
110 raw_ostream *Verbose,
111 LLVMContext &Context) {
112 NamedRegionTimer T(TimeIRParsingName, TimeIRParsingGroupName,
113 TimePassesIsEnabled);
114 Format = NaClDoAutodetectFileFormat(
115 Format, (const unsigned char *)Buffer.getBufferStart(),
116 (const unsigned char *)Buffer.getBufferEnd());
117 if ((Format == PNaClFormat) &&
118 isNaClBitcode((const unsigned char *)Buffer.getBufferStart(),
119 (const unsigned char *)Buffer.getBufferEnd())) {
120 ErrorOr<Module *> ModuleOrErr =
121 NaClParseBitcodeFile(Buffer, Context, Verbose);
122 if (std::error_code EC = ModuleOrErr.getError()) {
123 Err = SMDiagnostic(Buffer.getBufferIdentifier(), SourceMgr::DK_Error,
124 EC.message());
125 return nullptr;
126 }
127 return std::unique_ptr<Module>(ModuleOrErr.get());
128 } else if (Format == LLVMFormat) {
129 if (isBitcode((const unsigned char *)Buffer.getBufferStart(),
130 (const unsigned char *)Buffer.getBufferEnd())) {
131 ErrorOr<Module *> ModuleOrErr = parseBitcodeFile(Buffer, Context);
132 if (std::error_code EC = ModuleOrErr.getError()) {
133 Err = SMDiagnostic(Buffer.getBufferIdentifier(), SourceMgr::DK_Error,
134 EC.message());
135 return nullptr;
136 }
137 return std::unique_ptr<Module>(ModuleOrErr.get());
138 }
139
140 return parseAssembly(Buffer, Err, Context);
141 } else {
142 Err = SMDiagnostic(Buffer.getBufferIdentifier(), SourceMgr::DK_Error,
143 "Did not specify correct format for file");
144 return nullptr;
145 }
146 }
147
148 std::unique_ptr<Module> llvm::NaClParseIRFile(StringRef Filename,
149 NaClFileFormat Format,
150 SMDiagnostic &Err,
151 raw_ostream *Verbose,
152 LLVMContext &Context) {
153 ErrorOr<std::unique_ptr<MemoryBuffer>> FileOrErr =
154 MemoryBuffer::getFileOrSTDIN(Filename);
155 if (std::error_code EC = FileOrErr.getError()) {
156 Err = SMDiagnostic(Filename, SourceMgr::DK_Error,
157 "Could not open input file: " + EC.message());
158 return nullptr;
159 }
160
161 return NaClParseIR(FileOrErr.get()->getMemBufferRef(), Format, Err, Verbose,
162 Context);
163 }
164
165 // @LOCALMOD-END
166
95 //===----------------------------------------------------------------------===// 167 //===----------------------------------------------------------------------===//
96 // C API. 168 // C API.
97 //===----------------------------------------------------------------------===// 169 //===----------------------------------------------------------------------===//
98 170
99 LLVMBool LLVMParseIRInContext(LLVMContextRef ContextRef, 171 LLVMBool LLVMParseIRInContext(LLVMContextRef ContextRef,
100 LLVMMemoryBufferRef MemBuf, LLVMModuleRef *OutM, 172 LLVMMemoryBufferRef MemBuf, LLVMModuleRef *OutM,
101 char **OutMessage) { 173 char **OutMessage) {
102 SMDiagnostic Diag; 174 SMDiagnostic Diag;
103 175
104 std::unique_ptr<MemoryBuffer> MB(unwrap(MemBuf)); 176 std::unique_ptr<MemoryBuffer> MB(unwrap(MemBuf));
105 *OutM = 177 *OutM =
106 wrap(parseIR(MB->getMemBufferRef(), Diag, *unwrap(ContextRef)).release()); 178 wrap(parseIR(MB->getMemBufferRef(), Diag, *unwrap(ContextRef)).release());
107 179
108 if(!*OutM) { 180 if(!*OutM) {
109 if (OutMessage) { 181 if (OutMessage) {
110 std::string buf; 182 std::string buf;
111 raw_string_ostream os(buf); 183 raw_string_ostream os(buf);
112 184
113 Diag.print(nullptr, os, false); 185 Diag.print(nullptr, os, false);
114 os.flush(); 186 os.flush();
115 187
116 *OutMessage = strdup(buf.c_str()); 188 *OutMessage = strdup(buf.c_str());
117 } 189 }
118 return 1; 190 return 1;
119 } 191 }
120 192
121 return 0; 193 return 0;
122 } 194 }
OLDNEW
« no previous file with comments | « lib/IR/NaClAtomicIntrinsics.cpp ('k') | lib/IRReader/LLVMBuild.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698