llvm.org GIT mirror llvm / 333fb04
Support/MemoryBuffer: Replace all uses of std::string *ErrMsg with error_code &ec. And fix clients. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@121379 91177308-0d34-0410-b5e6-96231b3b80d8 Michael J. Spencer 9 years ago
23 changed file(s) with 179 addition(s) and 123 deletion(s). Raw diff Collapse all Expand all
2222 #include "llvm/Bitcode/ReaderWriter.h"
2323 #include "llvm/Support/MemoryBuffer.h"
2424 #include "llvm/Support/SourceMgr.h"
25 #include "llvm/Support/system_error.h"
2526
2627 namespace llvm {
2728
5556 inline Module *getLazyIRFileModule(const std::string &Filename,
5657 SMDiagnostic &Err,
5758 LLVMContext &Context) {
58 std::string ErrMsg;
59 MemoryBuffer *F = MemoryBuffer::getFileOrSTDIN(Filename.c_str(), &ErrMsg);
59 error_code ec;
60 MemoryBuffer *F = MemoryBuffer::getFileOrSTDIN(Filename.c_str(), ec);
6061 if (F == 0) {
61 Err = SMDiagnostic(Filename,
62 "Could not open input file: " + ErrMsg);
62 Err = SMDiagnostic(Filename,
63 "Could not open input file: " + ec.message());
6364 return 0;
6465 }
6566
9394 inline Module *ParseIRFile(const std::string &Filename,
9495 SMDiagnostic &Err,
9596 LLVMContext &Context) {
96 std::string ErrMsg;
97 MemoryBuffer *F = MemoryBuffer::getFileOrSTDIN(Filename.c_str(), &ErrMsg);
97 error_code ec;
98 MemoryBuffer *F = MemoryBuffer::getFileOrSTDIN(Filename.c_str(), ec);
9899 if (F == 0) {
99 Err = SMDiagnostic(Filename,
100 "Could not open input file: " + ErrMsg);
100 Err = SMDiagnostic(Filename,
101 "Could not open input file: " + ec.message());
101102 return 0;
102103 }
103104
1515
1616 #include "llvm/ADT/StringRef.h"
1717 #include "llvm/Support/DataTypes.h"
18 #include
1918
2019 namespace llvm {
20
21 class error_code;
2122
2223 /// MemoryBuffer - This interface provides simple read-only access to a block
2324 /// of memory, and provides simple methods for reading files and standard input
4546 const char *getBufferEnd() const { return BufferEnd; }
4647 size_t getBufferSize() const { return BufferEnd-BufferStart; }
4748
48 StringRef getBuffer() const {
49 return StringRef(BufferStart, getBufferSize());
49 StringRef getBuffer() const {
50 return StringRef(BufferStart, getBufferSize());
5051 }
5152
5253 /// getBufferIdentifier - Return an identifier for this buffer, typically the
5960 /// MemoryBuffer if successful, otherwise returning null. If FileSize is
6061 /// specified, this means that the client knows that the file exists and that
6162 /// it has the specified size.
62 static MemoryBuffer *getFile(StringRef Filename, std::string *ErrStr = 0,
63 static MemoryBuffer *getFile(StringRef Filename, error_code &ec,
6364 int64_t FileSize = -1);
64 static MemoryBuffer *getFile(const char *Filename, std::string *ErrStr = 0,
65 static MemoryBuffer *getFile(const char *Filename, error_code &ec,
6566 int64_t FileSize = -1);
6667
6768 /// getOpenFile - Given an already-open file descriptor, read the file and
6869 /// return a MemoryBuffer. This takes ownership of the descriptor,
6970 /// immediately closing it after reading the file.
7071 static MemoryBuffer *getOpenFile(int FD, const char *Filename,
71 std::string *ErrStr = 0,
72 error_code &ec,
7273 int64_t FileSize = -1);
7374
7475 /// getMemBuffer - Open the specified memory range as a MemoryBuffer. Note
9697 StringRef BufferName = "");
9798
9899 /// getSTDIN - Read all of stdin into a file buffer, and return it.
99 /// If an error occurs, this returns null and fills in *ErrStr with a reason.
100 static MemoryBuffer *getSTDIN(std::string *ErrStr = 0);
100 /// If an error occurs, this returns null and sets ec.
101 static MemoryBuffer *getSTDIN(error_code &ec);
101102
102103
103104 /// getFileOrSTDIN - Open the specified file as a MemoryBuffer, or open stdin
104 /// if the Filename is "-". If an error occurs, this returns null and fills
105 /// in *ErrStr with a reason.
105 /// if the Filename is "-". If an error occurs, this returns null and sets
106 /// ec.
106107 static MemoryBuffer *getFileOrSTDIN(StringRef Filename,
107 std::string *ErrStr = 0,
108 error_code &ec,
108109 int64_t FileSize = -1);
109110 static MemoryBuffer *getFileOrSTDIN(const char *Filename,
110 std::string *ErrStr = 0,
111 error_code &ec,
111112 int64_t FileSize = -1);
112113 };
113114
667667 const error_category& generic_category();
668668 const error_category& system_category();
669669
670 /// Get the error_category used for errno values from POSIX functions. This is
671 /// the same as the system_category on POISIX systems, but is the same as the
672 /// generic_category on Windows.
673 const error_category& posix_category();
674
670675 class error_condition
671676 {
672677 int _val_;
1616 #include "llvm/Module.h"
1717 #include "llvm/Support/MemoryBuffer.h"
1818 #include "llvm/Support/Process.h"
19 #include "llvm/Support/system_error.h"
1920 #include
2021 #include
2122 using namespace llvm;
146147
147148 bool
148149 Archive::mapToMemory(std::string* ErrMsg) {
149 mapfile = MemoryBuffer::getFile(archPath.c_str(), ErrMsg);
150 if (mapfile == 0)
151 return true;
150 error_code ec;
151 mapfile = MemoryBuffer::getFile(archPath.c_str(), ec);
152 if (mapfile == 0) {
153 if (ErrMsg)
154 *ErrMsg = ec.message();
155 return true;
156 }
152157 base = mapfile->getBufferStart();
153158 return false;
154159 }
212217 LLVMContext& Context,
213218 std::vector& symbols,
214219 std::string* ErrMsg) {
220 error_code ec;
215221 std::auto_ptr Buffer(
216 MemoryBuffer::getFileOrSTDIN(fName.c_str()));
222 MemoryBuffer::getFileOrSTDIN(fName.c_str(), ec));
217223 if (!Buffer.get()) {
218 if (ErrMsg) *ErrMsg = "Could not open file '" + fName.str() + "'";
224 if (ErrMsg) *ErrMsg = "Could not open file '" + fName.str() + "'" + ": "
225 + ec.message();
219226 return true;
220227 }
221228
1717 #include "llvm/Support/MemoryBuffer.h"
1818 #include "llvm/Support/Process.h"
1919 #include "llvm/Support/Signals.h"
20 #include "llvm/Support/system_error.h"
2021 #include
2122 #include
2223 #include
211212 const char *data = (const char*)member.getData();
212213 MemoryBuffer *mFile = 0;
213214 if (!data) {
214 mFile = MemoryBuffer::getFile(member.getPath().c_str(), ErrMsg);
215 if (mFile == 0)
216 return true;
215 error_code ec;
216 mFile = MemoryBuffer::getFile(member.getPath().c_str(), ec);
217 if (mFile == 0) {
218 if (ErrMsg)
219 *ErrMsg = ec.message();
220 return true;
221 }
217222 data = mFile->getBufferStart();
218223 fSize = mFile->getBufferSize();
219224 }
405410
406411 // Map in the archive we just wrote.
407412 {
408 OwningPtr arch(MemoryBuffer::getFile(TmpArchive.c_str()));
409 if (arch == 0) return true;
413 error_code ec;
414 OwningPtr arch(MemoryBuffer::getFile(TmpArchive.c_str(), ec));
415 if (arch == 0) {
416 if (ErrMsg)
417 *ErrMsg = ec.message();
418 return true;
419 }
410420 const char* base = arch->getBufferStart();
411421
412422 // Open another temporary file in order to avoid invalidating the
1717 #include "llvm/Support/SourceMgr.h"
1818 #include "llvm/Support/MemoryBuffer.h"
1919 #include "llvm/Support/raw_ostream.h"
20 #include "llvm/Support/system_error.h"
2021 #include
2122 using namespace llvm;
2223
4041
4142 Module *llvm::ParseAssemblyFile(const std::string &Filename, SMDiagnostic &Err,
4243 LLVMContext &Context) {
43 std::string ErrorStr;
44 MemoryBuffer *F = MemoryBuffer::getFileOrSTDIN(Filename.c_str(), &ErrorStr);
44 error_code ec;
45 MemoryBuffer *F = MemoryBuffer::getFileOrSTDIN(Filename.c_str(), ec);
4546 if (F == 0) {
4647 Err = SMDiagnostic(Filename,
47 "Could not open input file: " + ErrorStr);
48 "Could not open input file: " + ec.message());
4849 return 0;
4950 }
5051
1717 #include "llvm/Support/Path.h"
1818 #include "llvm/Support/ErrorHandling.h"
1919 #include "llvm/Support/MemoryBuffer.h"
20 #include "llvm/Support/system_error.h"
2021 using namespace llvm;
2122
2223 // LinkItems - This function is the main entry point into linking. It takes a
159160 // Check for a file of name "-", which means "read standard input"
160161 if (File.str() == "-") {
161162 std::auto_ptr M;
162 if (MemoryBuffer *Buffer = MemoryBuffer::getSTDIN(&Error)) {
163 error_code ec;
164 if (MemoryBuffer *Buffer = MemoryBuffer::getSTDIN(ec)) {
163165 if (!Buffer->getBufferSize()) {
164166 delete Buffer;
165167 Error = "standard input is empty";
171173 return false;
172174 }
173175 }
174 return error("Cannot link stdin: " + Error);
176 return error("Cannot link stdin: " + ec.message());
175177 }
176178
177179 // Determine what variety of file it is.
1717 #include "llvm/Support/MemoryBuffer.h"
1818 #include "llvm/Support/raw_ostream.h"
1919 #include "llvm/Config/config.h"
20 #include "llvm/Support/system_error.h"
2021 using namespace llvm;
2122
2223 Linker::Linker(StringRef progname, StringRef modname,
9798 std::string ParseErrorMessage;
9899 Module *Result = 0;
99100
100 std::auto_ptr Buffer(MemoryBuffer::getFileOrSTDIN(FN.c_str()));
101 error_code ec;
102 std::auto_ptr Buffer(
103 MemoryBuffer::getFileOrSTDIN(FN.c_str(), ec));
101104 if (Buffer.get())
102105 Result = ParseBitcodeFile(Buffer.get(), Context, &ParseErrorMessage);
103106 else
104 ParseErrorMessage = "Error reading file '" + FN.str() + "'";
107 ParseErrorMessage = "Error reading file '" + FN.str() + "'" + ": "
108 + ec.message();
105109
106110 if (Result)
107111 return std::auto_ptr(Result);
1414 #include "llvm/Support/ErrorHandling.h"
1515 #include "llvm/Support/MemoryBuffer.h"
1616 #include "llvm/Support/Path.h"
17 #include "llvm/Support/system_error.h"
1718
1819 using namespace llvm;
1920 using namespace object;
6162 }
6263
6364 ObjectFile *ObjectFile::createObjectFile(StringRef ObjectPath) {
64 return createObjectFile(MemoryBuffer::getFile(ObjectPath));
65 error_code ec;
66 return createObjectFile(MemoryBuffer::getFile(ObjectPath, ec));
6567 }
2121 #include "llvm/Support/MemoryBuffer.h"
2222 #include "llvm/Support/ManagedStatic.h"
2323 #include "llvm/Support/raw_ostream.h"
24 #include "llvm/Support/system_error.h"
2425 #include "llvm/Target/TargetRegistry.h"
2526 #include "llvm/Support/Host.h"
2627 #include "llvm/Support/Path.h"
463464 if (FileStat && FileStat->getSize() != 0) {
464465
465466 // Mmap the response file into memory.
467 error_code ec;
466468 OwningPtr
467 respFilePtr(MemoryBuffer::getFile(respFile.c_str()));
469 respFilePtr(MemoryBuffer::getFile(respFile.c_str(), ec));
468470
469471 // If we could open the file, parse its contents, otherwise
470472 // pass the @file option verbatim.
1515 #include "llvm/Support/MemoryBuffer.h"
1616 #include "llvm/Support/raw_ostream.h"
1717 #include "llvm/Support/Path.h"
18 #include "llvm/Support/system_error.h"
1819 #include "llvm/ADT/OwningPtr.h"
1920 #include "llvm/ADT/SmallString.h"
2021 #include
198199
199200 // Now its safe to mmap the files into memory becasue both files
200201 // have a non-zero size.
201 OwningPtr F1(MemoryBuffer::getFile(FileA.c_str(), Error));
202 OwningPtr F2(MemoryBuffer::getFile(FileB.c_str(), Error));
203 if (F1 == 0 || F2 == 0)
204 return 2;
205
202 error_code ec;
203 OwningPtr F1(MemoryBuffer::getFile(FileA.c_str(), ec));
204 if (F1 == 0) {
205 if (Error)
206 *Error = ec.message();
207 return 2;
208 }
209 OwningPtr F2(MemoryBuffer::getFile(FileB.c_str(), ec));
210 if (F2 == 0) {
211 if (Error)
212 *Error = ec.message();
213 return 2;
214 }
215
206216 // Okay, now that we opened the files, scan them for the first difference.
207217 const char *File1Start = F1->getBufferStart();
208218 const char *File2Start = F2->getBufferStart();
1818 #include "llvm/Support/Path.h"
1919 #include "llvm/Support/Process.h"
2020 #include "llvm/Support/Program.h"
21 #include "llvm/Support/system_error.h"
2122 #include
2223 #include
2324 #include
142143 /// in *ErrStr with a reason. If stdin is empty, this API (unlike getSTDIN)
143144 /// returns an empty buffer.
144145 MemoryBuffer *MemoryBuffer::getFileOrSTDIN(StringRef Filename,
145 std::string *ErrStr,
146 error_code &ec,
146147 int64_t FileSize) {
147148 if (Filename == "-")
148 return getSTDIN(ErrStr);
149 return getFile(Filename, ErrStr, FileSize);
149 return getSTDIN(ec);
150 return getFile(Filename, ec, FileSize);
150151 }
151152
152153 MemoryBuffer *MemoryBuffer::getFileOrSTDIN(const char *Filename,
153 std::string *ErrStr,
154 error_code &ec,
154155 int64_t FileSize) {
155156 if (strcmp(Filename, "-") == 0)
156 return getSTDIN(ErrStr);
157 return getFile(Filename, ErrStr, FileSize);
157 return getSTDIN(ec);
158 return getFile(Filename, ec, FileSize);
158159 }
159160
160161 //===----------------------------------------------------------------------===//
184185 };
185186 }
186187
187 MemoryBuffer *MemoryBuffer::getFile(StringRef Filename, std::string *ErrStr,
188 MemoryBuffer *MemoryBuffer::getFile(StringRef Filename, error_code &ec,
188189 int64_t FileSize) {
189190 // Ensure the path is null terminated.
190191 SmallString<256> PathBuf(Filename.begin(), Filename.end());
191 return MemoryBuffer::getFile(PathBuf.c_str(), ErrStr, FileSize);
192 }
193
194 MemoryBuffer *MemoryBuffer::getFile(const char *Filename, std::string *ErrStr,
192 return MemoryBuffer::getFile(PathBuf.c_str(), ec, FileSize);
193 }
194
195 MemoryBuffer *MemoryBuffer::getFile(const char *Filename, error_code &ec,
195196 int64_t FileSize) {
196197 int OpenFlags = O_RDONLY;
197198 #ifdef O_BINARY
199200 #endif
200201 int FD = ::open(Filename, OpenFlags);
201202 if (FD == -1) {
202 if (ErrStr) *ErrStr = sys::StrError();
203 ec = error_code(errno, posix_category());
203204 return 0;
204205 }
205206
206 return getOpenFile(FD, Filename, ErrStr, FileSize);
207 return getOpenFile(FD, Filename, ec, FileSize);
207208 }
208209
209210 MemoryBuffer *MemoryBuffer::getOpenFile(int FD, const char *Filename,
210 std::string *ErrStr, int64_t FileSize) {
211 error_code &ec, int64_t FileSize) {
211212 FileCloser FC(FD); // Close FD on return.
212213
213214 // If we don't know the file size, use fstat to find out. fstat on an open
216217 struct stat FileInfo;
217218 // TODO: This should use fstat64 when available.
218219 if (fstat(FD, &FileInfo) == -1) {
219 if (ErrStr) *ErrStr = sys::StrError();
220 ec = error_code(errno, posix_category());
220221 return 0;
221222 }
222223 FileSize = FileInfo.st_size;
239240
240241 MemoryBuffer *Buf = MemoryBuffer::getNewUninitMemBuffer(FileSize, Filename);
241242 if (!Buf) {
242 // Failed to create a buffer.
243 if (ErrStr) *ErrStr = "could not allocate buffer";
243 // Failed to create a buffer. The only way it can fail is if
244 // new(std::nothrow) returns 0.
245 ec = make_error_code(errc::not_enough_memory);
244246 return 0;
245247 }
246248
254256 if (errno == EINTR)
255257 continue;
256258 // Error while reading.
257 if (ErrStr) *ErrStr = sys::StrError();
259 ec = error_code(errno, posix_category());
258260 return 0;
259261 } else if (NumRead == 0) {
260262 // We hit EOF early, truncate and terminate buffer.
273275 // MemoryBuffer::getSTDIN implementation.
274276 //===----------------------------------------------------------------------===//
275277
276 MemoryBuffer *MemoryBuffer::getSTDIN(std::string *ErrStr) {
278 MemoryBuffer *MemoryBuffer::getSTDIN(error_code &ec) {
277279 // Read in all of the data from stdin, we cannot mmap stdin.
278280 //
279281 // FIXME: That isn't necessarily true, we should try to mmap stdin and
289291 ReadBytes = read(0, Buffer.end(), ChunkSize);
290292 if (ReadBytes == -1) {
291293 if (errno == EINTR) continue;
292 if (ErrStr) *ErrStr = sys::StrError();
294 ec = error_code(errno, posix_category());
293295 return 0;
294296 }
295297 Buffer.set_size(Buffer.size() + ReadBytes);
1616 #include "llvm/Support/SourceMgr.h"
1717 #include "llvm/Support/MemoryBuffer.h"
1818 #include "llvm/Support/raw_ostream.h"
19 #include "llvm/Support/system_error.h"
1920 using namespace llvm;
2021
2122 namespace {
4748 /// ~0, otherwise it returns the buffer ID of the stacked file.
4849 unsigned SourceMgr::AddIncludeFile(const std::string &Filename,
4950 SMLoc IncludeLoc) {
50
51 MemoryBuffer *NewBuf = MemoryBuffer::getFile(Filename.c_str());
51 error_code ec;
52 MemoryBuffer *NewBuf = MemoryBuffer::getFile(Filename.c_str(), ec);
5253
5354 // If the file didn't exist directly, see if it's in an include path.
5455 for (unsigned i = 0, e = IncludeDirectories.size(); i != e && !NewBuf; ++i) {
5556 std::string IncFile = IncludeDirectories[i] + "/" + Filename;
56 NewBuf = MemoryBuffer::getFile(IncFile.c_str());
57 NewBuf = MemoryBuffer::getFile(IncFile.c_str(), ec);
5758 }
5859
5960 if (NewBuf == 0) return ~0U;
9595 return s;
9696 }
9797
98 const error_category&
99 posix_category() {
100 #ifdef LLVM_ON_WIN32
101 return generic_category();
102 #else
103 return system_category();
104 #endif
105 }
106
98107 // error_condition
99108
100109 std::string
2727 #include "llvm/Support/ErrorHandling.h"
2828 #include "llvm/Support/MemoryBuffer.h"
2929 #include "llvm/Support/raw_ostream.h"
30 #include "llvm/Support/system_error.h"
3031 #include
3132 #include
3233 #include
22192220 LLVMMemoryBufferRef *OutMemBuf,
22202221 char **OutMessage) {
22212222
2222 std::string Error;
2223 if (MemoryBuffer *MB = MemoryBuffer::getFile(Path, &Error)) {
2223 error_code ec;
2224 if (MemoryBuffer *MB = MemoryBuffer::getFile(Path, ec)) {
22242225 *OutMemBuf = wrap(MB);
22252226 return 0;
22262227 }
2227
2228 *OutMessage = strdup(Error.c_str());
2228
2229 *OutMessage = strdup(ec.message().c_str());
22292230 return 1;
22302231 }
22312232
22322233 LLVMBool LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
22332234 char **OutMessage) {
2234 std::string Error;
2235 if (MemoryBuffer *MB = MemoryBuffer::getSTDIN(&Error)) {
2235 error_code ec;
2236 if (MemoryBuffer *MB = MemoryBuffer::getSTDIN(ec)) {
22362237 *OutMemBuf = wrap(MB);
22372238 return 0;
22382239 }
22392240
2240 *OutMessage = strdup(Error.c_str());
2241 *OutMessage = strdup(ec.message().c_str());
22412242 return 1;
22422243 }
22432244
3737 #include "llvm/Support/PrettyStackTrace.h"
3838 #include "llvm/Support/raw_ostream.h"
3939 #include "llvm/Support/Signals.h"
40 #include "llvm/Support/system_error.h"
4041 #include
4142 #include
4243 #include
472473 /// AnalyzeBitcode - Analyze the bitcode file specified by InputFilename.
473474 static int AnalyzeBitcode() {
474475 // Read the input file.
475 MemoryBuffer *MemBuf = MemoryBuffer::getFileOrSTDIN(InputFilename.c_str());
476 error_code ec;
477 MemoryBuffer *MemBuf =
478 MemoryBuffer::getFileOrSTDIN(InputFilename.c_str(), ec);
476479
477480 if (MemBuf == 0)
478 return Error("Error reading '" + InputFilename + "'.");
481 return Error("Error reading '" + InputFilename + "': " + ec.message());
479482
480483 if (MemBuf->getBufferSize() & 3)
481484 return Error("Bitcode stream should be a multiple of 4 bytes in length");
2727 #include "llvm/Support/PrettyStackTrace.h"
2828 #include "llvm/Support/ToolOutputFile.h"
2929 #include "llvm/Support/Signals.h"
30 #include "llvm/Support/system_error.h"
3031 using namespace llvm;
3132
3233 static cl::opt
7778 cl::ParseCommandLineOptions(argc, argv, "llvm .bc -> .ll disassembler\n");
7879
7980 std::string ErrorMessage;
81 error_code ec;
8082 std::auto_ptr M;
81
82 if (MemoryBuffer *Buffer
83 = MemoryBuffer::getFileOrSTDIN(InputFilename, &ErrorMessage)) {
83
84 if (MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(InputFilename, ec)) {
8485 M.reset(ParseBitcodeFile(Buffer, Context, &ErrorMessage));
8586 delete Buffer;
86 }
87 } else
88 ErrorMessage = ec.message();
8789
8890 if (M.get() == 0) {
8991 errs() << argv[0] << ": ";
3636 #include "llvm/Support/ToolOutputFile.h"
3737 #include "llvm/Support/Host.h"
3838 #include "llvm/Support/Signals.h"
39 #include "llvm/Support/system_error.h"
3940 #include "Disassembler.h"
4041 using namespace llvm;
4142
163164 }
164165
165166 static int AsLexInput(const char *ProgName) {
166 std::string ErrorMessage;
167 MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(InputFilename,
168 &ErrorMessage);
167 error_code ec;
168 MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(InputFilename, ec);
169169 if (Buffer == 0) {
170 errs() << ProgName << ": ";
171 if (ErrorMessage.size())
172 errs() << ErrorMessage << "\n";
173 else
174 errs() << "input file didn't read correctly.\n";
170 errs() << ProgName << ": " << ec.message() << '\n';
175171 return 1;
176172 }
177173
281277 if (!TheTarget)
282278 return 1;
283279
284 std::string Error;
285 MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(InputFilename, &Error);
280 error_code ec;
281 MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(InputFilename, ec);
286282 if (Buffer == 0) {
287 errs() << ProgName << ": ";
288 if (Error.size())
289 errs() << Error << "\n";
290 else
291 errs() << "input file didn't read correctly.\n";
283 errs() << ProgName << ": " << ec.message() << '\n';
292284 return 1;
293285 }
294286
382374 const Target *TheTarget = GetTarget(ProgName);
383375 if (!TheTarget)
384376 return 0;
385
386 std::string ErrorMessage;
387
388 MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(InputFilename,
389 &ErrorMessage);
390
377
378 error_code ec;
379 MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(InputFilename, ec);
391380 if (Buffer == 0) {
392 errs() << ProgName << ": ";
393 if (ErrorMessage.size())
394 errs() << ErrorMessage << "\n";
395 else
396 errs() << "input file didn't read correctly.\n";
381 errs() << ProgName << ": " << ec.message() << '\n';
397382 return 1;
398383 }
399384
2525 #include "llvm/Support/PrettyStackTrace.h"
2626 #include "llvm/Support/raw_ostream.h"
2727 #include "llvm/Support/Signals.h"
28 #include "llvm/Support/system_error.h"
2829 #include
2930 #include
3031 #include
142143 sys::Path aPath(Filename);
143144 // Note: Currently we do not support reading an archive from stdin.
144145 if (Filename == "-" || aPath.isBitcodeFile()) {
146 error_code ec;
145147 std::auto_ptr Buffer(
146 MemoryBuffer::getFileOrSTDIN(Filename, &ErrorMessage));
148 MemoryBuffer::getFileOrSTDIN(Filename, ec));
149 if (Buffer.get() == 0)
150 ErrorMessage = ec.message();
147151 Module *Result = 0;
148152 if (Buffer.get())
149153 Result = ParseBitcodeFile(Buffer.get(), Context, &ErrorMessage);
2929 #include "llvm/Support/raw_ostream.h"
3030 #include "llvm/Support/Format.h"
3131 #include "llvm/Support/Signals.h"
32 #include "llvm/Support/system_error.h"
3233 #include
3334 #include
3435 #include
262263
263264 // Read in the bitcode file...
264265 std::string ErrorMessage;
266 error_code ec;
265267 Module *M = 0;
266 if (MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(BitcodeFile,
267 &ErrorMessage)) {
268 if (MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(BitcodeFile, ec)) {
268269 M = ParseBitcodeFile(Buffer, Context, &ErrorMessage);
269270 delete Buffer;
270 }
271 } else
272 ErrorMessage = ec.message();
271273 if (M == 0) {
272274 errs() << argv[0] << ": " << BitcodeFile << ": "
273275 << ErrorMessage << "\n";
1818 #include "llvm/Support/ManagedStatic.h"
1919 #include "llvm/Support/MemoryBuffer.h"
2020 #include "llvm/Support/raw_ostream.h"
21 #include "llvm/Support/system_error.h"
2122 using namespace llvm;
2223 using namespace llvm::object;
2324
364365
365366 // Load the input file.
366367 std::string ErrorStr;
368 error_code ec;
367369 OwningPtr InputBuffer(
368 MemoryBuffer::getFileOrSTDIN(InputFile, &ErrorStr));
370 MemoryBuffer::getFileOrSTDIN(InputFile, ec));
369371 if (!InputBuffer)
370 return Error("unable to read input: '" + ErrorStr + "'");
372 return Error("unable to read input: '" + ec.message() + "'");
371373
372374 // Construct the Mach-O wrapper object.
373375 OwningPtr InputObject(
2222 #include "llvm/Support/SourceMgr.h"
2323 #include "llvm/Support/raw_ostream.h"
2424 #include "llvm/Support/Signals.h"
25 #include "llvm/Support/system_error.h"
2526 #include "llvm/ADT/SmallString.h"
2627 #include "llvm/ADT/StringMap.h"
2728 #include
487488 static bool ReadCheckFile(SourceMgr &SM,
488489 std::vector &CheckStrings) {
489490 // Open the check file, and tell SourceMgr about it.
490 std::string ErrorStr;
491 MemoryBuffer *F =
492 MemoryBuffer::getFileOrSTDIN(CheckFilename.c_str(), &ErrorStr);
491 error_code ec;
492 MemoryBuffer *F = MemoryBuffer::getFileOrSTDIN(CheckFilename.c_str(), ec);
493493 if (F == 0) {
494494 errs() << "Could not open check file '" << CheckFilename << "': "
495 << ErrorStr << '\n';
495 << ec.message() << '\n';
496496 return true;
497497 }
498498
647647 return 2;
648648
649649 // Open the file to check and add it to SourceMgr.
650 std::string ErrorStr;
651 MemoryBuffer *F =
652 MemoryBuffer::getFileOrSTDIN(InputFilename.c_str(), &ErrorStr);
650 error_code ec;
651 MemoryBuffer *F = MemoryBuffer::getFileOrSTDIN(InputFilename.c_str(), ec);
653652 if (F == 0) {
654653 errs() << "Could not open input file '" << InputFilename << "': "
655 << ErrorStr << '\n';
654 << ec.message() << '\n';
656655 return true;
657656 }
658657
4141 #include "llvm/Support/PrettyStackTrace.h"
4242 #include "llvm/Support/ToolOutputFile.h"
4343 #include "llvm/Support/Signals.h"
44 #include "llvm/Support/system_error.h"
4445 #include
4546 #include
4647 using namespace llvm;
187188 static bool ParseFile(const std::string &Filename,
188189 const std::vector &IncludeDirs,
189190 SourceMgr &SrcMgr) {
190 std::string ErrorStr;
191 MemoryBuffer *F = MemoryBuffer::getFileOrSTDIN(Filename.c_str(), &ErrorStr);
191 error_code ec;
192 MemoryBuffer *F = MemoryBuffer::getFileOrSTDIN(Filename.c_str(), ec);
192193 if (F == 0) {
193194 errs() << "Could not open input file '" << Filename << "': "
194 << ErrorStr <<"\n";
195 << ec.message() <<"\n";
195196 return true;
196197 }
197198