summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/llvm/Support/MemoryBuffer.h6
-rw-r--r--lib/Archive/Archive.cpp5
-rw-r--r--lib/Archive/ArchiveWriter.cpp6
-rw-r--r--lib/AsmParser/Parser.cpp3
-rw-r--r--lib/Debugger/Debugger.cpp2
-rw-r--r--lib/Linker/Linker.cpp6
-rw-r--r--lib/Support/FileUtilities.cpp6
-rw-r--r--lib/Support/MemoryBuffer.cpp21
-rw-r--r--lib/VMCore/Core.cpp2
-rw-r--r--tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp6
-rw-r--r--tools/lto2/LTOCodeGenerator.cpp3
-rw-r--r--tools/lto2/LTOModule.cpp15
-rw-r--r--utils/TableGen/TGLexer.cpp4
-rw-r--r--utils/TableGen/TableGen.cpp3
14 files changed, 35 insertions, 53 deletions
diff --git a/include/llvm/Support/MemoryBuffer.h b/include/llvm/Support/MemoryBuffer.h
index ffe1bf6d2f4..8c36791be53 100644
--- a/include/llvm/Support/MemoryBuffer.h
+++ b/include/llvm/Support/MemoryBuffer.h
@@ -52,7 +52,7 @@ public:
/// MemoryBuffer if successful, otherwise returning null. If FileSize is
/// specified, this means that the client knows that the file exists and that
/// it has the specified size.
- static MemoryBuffer *getFile(const char *FilenameStart, unsigned FnSize,
+ static MemoryBuffer *getFile(const char *Filename,
std::string *ErrStr = 0,
int64_t FileSize = -1);
@@ -90,7 +90,7 @@ public:
/// if the Filename is "-". If an error occurs, this returns null and fills
/// in *ErrStr with a reason. If stdin is empty, this API (unlike getSTDIN)
/// returns an empty buffer.
- static MemoryBuffer *getFileOrSTDIN(const char *FilenameStart,unsigned FnSize,
+ static MemoryBuffer *getFileOrSTDIN(const char *Filename,
std::string *ErrStr = 0,
int64_t FileSize = -1);
@@ -100,7 +100,7 @@ public:
static MemoryBuffer *getFileOrSTDIN(const std::string &FN,
std::string *ErrStr = 0,
int64_t FileSize = -1) {
- return getFileOrSTDIN(&FN[0], FN.size(), ErrStr, FileSize);
+ return getFileOrSTDIN(FN.c_str(), ErrStr, FileSize);
}
};
diff --git a/lib/Archive/Archive.cpp b/lib/Archive/Archive.cpp
index e32c7164bd1..a0e5eedc9c9 100644
--- a/lib/Archive/Archive.cpp
+++ b/lib/Archive/Archive.cpp
@@ -145,7 +145,7 @@ Archive::Archive(const sys::Path& filename)
bool
Archive::mapToMemory(std::string* ErrMsg) {
- mapfile = MemoryBuffer::getFile(archPath.c_str(), archPath.size(), ErrMsg);
+ mapfile = MemoryBuffer::getFile(archPath.c_str(), ErrMsg);
if (mapfile == 0)
return true;
base = mapfile->getBufferStart();
@@ -211,8 +211,7 @@ bool llvm::GetBitcodeSymbols(const sys::Path& fName,
std::vector<std::string>& symbols,
std::string* ErrMsg) {
std::auto_ptr<MemoryBuffer> Buffer(
- MemoryBuffer::getFileOrSTDIN(&fName.toString()[0],
- fName.toString().size()));
+ MemoryBuffer::getFileOrSTDIN(fName.c_str()));
if (!Buffer.get()) {
if (ErrMsg) *ErrMsg = "Could not open file '" + fName.toString() + "'";
return true;
diff --git a/lib/Archive/ArchiveWriter.cpp b/lib/Archive/ArchiveWriter.cpp
index afe9819deea..d3861f32cbe 100644
--- a/lib/Archive/ArchiveWriter.cpp
+++ b/lib/Archive/ArchiveWriter.cpp
@@ -212,8 +212,7 @@ Archive::writeMember(
const char *data = (const char*)member.getData();
MemoryBuffer *mFile = 0;
if (!data) {
- mFile = MemoryBuffer::getFile(member.getPath().c_str(),
- member.getPath().size(), ErrMsg);
+ mFile = MemoryBuffer::getFile(member.getPath().c_str(), ErrMsg);
if (mFile == 0)
return true;
data = mFile->getBufferStart();
@@ -407,8 +406,7 @@ Archive::writeToDisk(bool CreateSymbolTable, bool TruncateNames, bool Compress,
// Map in the archive we just wrote.
{
- OwningPtr<MemoryBuffer> arch(MemoryBuffer::getFile(TmpArchive.c_str(),
- TmpArchive.size()));
+ OwningPtr<MemoryBuffer> arch(MemoryBuffer::getFile(TmpArchive.c_str()));
if (arch == 0) return true;
const char* base = arch->getBufferStart();
diff --git a/lib/AsmParser/Parser.cpp b/lib/AsmParser/Parser.cpp
index 157a43b1aa2..0005e11737b 100644
--- a/lib/AsmParser/Parser.cpp
+++ b/lib/AsmParser/Parser.cpp
@@ -22,8 +22,7 @@ ParseError* TheParseError = 0; /// FIXME: Not threading friendly
Module *llvm::ParseAssemblyFile(const std::string &Filename, ParseError* Err) {
std::string ErrorStr;
- MemoryBuffer *F = MemoryBuffer::getFileOrSTDIN(&Filename[0], Filename.size(),
- &ErrorStr);
+ MemoryBuffer *F = MemoryBuffer::getFileOrSTDIN(Filename.c_str(), &ErrorStr);
if (F == 0) {
if (Err)
Err->setError(Filename, "Could not open input file '" + Filename + "'");
diff --git a/lib/Debugger/Debugger.cpp b/lib/Debugger/Debugger.cpp
index e8194d941f0..78f48f6f731 100644
--- a/lib/Debugger/Debugger.cpp
+++ b/lib/Debugger/Debugger.cpp
@@ -47,7 +47,7 @@ std::string Debugger::getProgramPath() const {
static Module *
getMaterializedModuleProvider(const std::string &Filename) {
std::auto_ptr<MemoryBuffer> Buffer;
- Buffer.reset(MemoryBuffer::getFileOrSTDIN(&Filename[0], Filename.size()));
+ Buffer.reset(MemoryBuffer::getFileOrSTDIN(Filename.c_str()));
if (Buffer.get())
return ParseBitcodeFile(Buffer.get());
return 0;
diff --git a/lib/Linker/Linker.cpp b/lib/Linker/Linker.cpp
index 64327e143ba..ef242e5c798 100644
--- a/lib/Linker/Linker.cpp
+++ b/lib/Linker/Linker.cpp
@@ -19,7 +19,8 @@
#include "llvm/Support/Streams.h"
using namespace llvm;
-Linker::Linker(const std::string& progname, const std::string& modname, unsigned flags)
+Linker::Linker(const std::string& progname, const std::string& modname,
+ unsigned flags)
: Composite(0)
, LibPaths()
, Flags(flags)
@@ -103,8 +104,7 @@ Linker::LoadObject(const sys::Path &FN) {
Module *Result = 0;
const std::string &FNS = FN.toString();
- std::auto_ptr<MemoryBuffer> Buffer(
- MemoryBuffer::getFileOrSTDIN(&FNS[0], FNS.size()));
+ std::auto_ptr<MemoryBuffer> Buffer(MemoryBuffer::getFileOrSTDIN(FNS.c_str()));
if (Buffer.get())
Result = ParseBitcodeFile(Buffer.get(), &ParseErrorMessage);
else
diff --git a/lib/Support/FileUtilities.cpp b/lib/Support/FileUtilities.cpp
index a765643b26d..3340e8b2eb8 100644
--- a/lib/Support/FileUtilities.cpp
+++ b/lib/Support/FileUtilities.cpp
@@ -189,10 +189,8 @@ int llvm::DiffFilesWithTolerance(const sys::PathWithStatus &FileA,
// Now its safe to mmap the files into memory becasue both files
// have a non-zero size.
- OwningPtr<MemoryBuffer> F1(MemoryBuffer::getFile(FileA.c_str(), FileA.size(),
- Error));
- OwningPtr<MemoryBuffer> F2(MemoryBuffer::getFile(FileB.c_str(), FileB.size(),
- Error));
+ OwningPtr<MemoryBuffer> F1(MemoryBuffer::getFile(FileA.c_str(), Error));
+ OwningPtr<MemoryBuffer> F2(MemoryBuffer::getFile(FileB.c_str(), Error));
if (F1 == 0 || F2 == 0)
return 2;
diff --git a/lib/Support/MemoryBuffer.cpp b/lib/Support/MemoryBuffer.cpp
index 4e4dabc5e73..7a60b85b91e 100644
--- a/lib/Support/MemoryBuffer.cpp
+++ b/lib/Support/MemoryBuffer.cpp
@@ -132,12 +132,11 @@ MemoryBuffer *MemoryBuffer::getNewMemBuffer(unsigned Size,
/// if the Filename is "-". If an error occurs, this returns null and fills
/// in *ErrStr with a reason. If stdin is empty, this API (unlike getSTDIN)
/// returns an empty buffer.
-MemoryBuffer *MemoryBuffer::getFileOrSTDIN(const char *FilenameStart,
- unsigned FnSize,
+MemoryBuffer *MemoryBuffer::getFileOrSTDIN(const char *Filename,
std::string *ErrStr,
int64_t FileSize) {
- if (FnSize != 1 || FilenameStart[0] != '-')
- return getFile(FilenameStart, FnSize, ErrStr, FileSize);
+ if (Filename[0] != '-' || Filename[1] != 0)
+ return getFile(Filename, ErrStr, FileSize);
MemoryBuffer *M = getSTDIN();
if (M) return M;
@@ -172,17 +171,13 @@ public:
};
}
-MemoryBuffer *MemoryBuffer::getFile(const char *FilenameStart, unsigned FnSize,
- std::string *ErrStr, int64_t FileSize) {
- // Null terminate the filename.
- SmallString<1000> Filename(FilenameStart, FilenameStart+FnSize);
- Filename.push_back(0);
-
+MemoryBuffer *MemoryBuffer::getFile(const char *Filename, std::string *ErrStr,
+ int64_t FileSize) {
int OpenFlags = 0;
#ifdef O_BINARY
Flags |= O_BINARY; // Open input file in binary mode on win32.
#endif
- int FD = ::open(&Filename[0], O_RDONLY|OpenFlags);
+ int FD = ::open(Filename, O_RDONLY|OpenFlags);
if (FD == -1) {
if (ErrStr) *ErrStr = "could not open file";
return 0;
@@ -211,12 +206,12 @@ MemoryBuffer *MemoryBuffer::getFile(const char *FilenameStart, unsigned FnSize,
if (const char *Pages = sys::Path::MapInFilePages(FD, FileSize)) {
// Close the file descriptor, now that the whole file is in memory.
::close(FD);
- return new MemoryBufferMMapFile(&Filename[0], Pages, FileSize);
+ return new MemoryBufferMMapFile(Filename, Pages, FileSize);
}
}
OwningPtr<MemoryBuffer> SB;
- SB.reset(MemoryBuffer::getNewUninitMemBuffer(FileSize, &Filename[0]));
+ SB.reset(MemoryBuffer::getNewUninitMemBuffer(FileSize, Filename));
char *BufPtr = const_cast<char*>(SB->getBufferStart());
unsigned BytesLeft = FileSize;
diff --git a/lib/VMCore/Core.cpp b/lib/VMCore/Core.cpp
index 59b9b1ab69a..c35c85dcc0f 100644
--- a/lib/VMCore/Core.cpp
+++ b/lib/VMCore/Core.cpp
@@ -1307,7 +1307,7 @@ int LLVMCreateMemoryBufferWithContentsOfFile(const char *Path,
LLVMMemoryBufferRef *OutMemBuf,
char **OutMessage) {
std::string Error;
- if (MemoryBuffer *MB = MemoryBuffer::getFile(Path, strlen(Path), &Error)) {
+ if (MemoryBuffer *MB = MemoryBuffer::getFile(Path, &Error)) {
*OutMemBuf = wrap(MB);
return 0;
}
diff --git a/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp b/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp
index c6518a24f43..a7e27e3e08a 100644
--- a/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp
+++ b/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp
@@ -374,11 +374,7 @@ static void PrintSize(double Bits) {
/// AnalyzeBitcode - Analyze the bitcode file specified by InputFilename.
static int AnalyzeBitcode() {
// Read the input file.
- MemoryBuffer *Buffer;
- if (InputFilename == "-")
- Buffer = MemoryBuffer::getSTDIN();
- else
- Buffer = MemoryBuffer::getFile(&InputFilename[0], InputFilename.size());
+ MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(InputFilename.c_str());
if (Buffer == 0)
return Error("Error reading '" + InputFilename + "'.");
diff --git a/tools/lto2/LTOCodeGenerator.cpp b/tools/lto2/LTOCodeGenerator.cpp
index 024db24b476..429d6c4f59d 100644
--- a/tools/lto2/LTOCodeGenerator.cpp
+++ b/tools/lto2/LTOCodeGenerator.cpp
@@ -186,8 +186,7 @@ const void* LTOCodeGenerator::compile(size_t* length, std::string& errMsg)
delete _nativeObjectFile;
// read .o file into memory buffer
- _nativeObjectFile = MemoryBuffer::getFile(&uniqueObjStr[0],
- uniqueObjStr.size(), &errMsg);
+ _nativeObjectFile = MemoryBuffer::getFile(uniqueObjStr.c_str(),&errMsg);
}
// remove temp files
diff --git a/tools/lto2/LTOModule.cpp b/tools/lto2/LTOModule.cpp
index aad173ccb8a..87126e71dc2 100644
--- a/tools/lto2/LTOModule.cpp
+++ b/tools/lto2/LTOModule.cpp
@@ -43,11 +43,11 @@ bool LTOModule::isBitcodeFile(const char* path)
return llvm::sys::Path(path).isBitcodeFile();
}
-bool LTOModule::isBitcodeFileForTarget(const void* mem,
- size_t length, const char* triplePrefix)
+bool LTOModule::isBitcodeFileForTarget(const void* mem, size_t length,
+ const char* triplePrefix)
{
MemoryBuffer* buffer = MemoryBuffer::getMemBuffer((char*)mem,
- (char*)mem+length);
+ (char*)mem+length);
if ( buffer == NULL )
return false;
return isTargetMatch(buffer, triplePrefix);
@@ -55,10 +55,10 @@ bool LTOModule::isBitcodeFileForTarget(const void* mem,
bool LTOModule::isBitcodeFileForTarget(const char* path,
- const char* triplePrefix)
+ const char* triplePrefix)
{
- MemoryBuffer* buffer = MemoryBuffer::getFile(path, strlen(path));
- if ( buffer == NULL )
+ MemoryBuffer *buffer = MemoryBuffer::getFile(path);
+ if (buffer == NULL)
return false;
return isTargetMatch(buffer, triplePrefix);
}
@@ -85,8 +85,7 @@ LTOModule::LTOModule(Module* m, TargetMachine* t)
LTOModule* LTOModule::makeLTOModule(const char* path, std::string& errMsg)
{
- OwningPtr<MemoryBuffer> buffer(MemoryBuffer::getFile(
- path, strlen(path), &errMsg));
+ OwningPtr<MemoryBuffer> buffer(MemoryBuffer::getFile(path, &errMsg));
if ( !buffer )
return NULL;
return makeLTOModule(buffer.get(), errMsg);
diff --git a/utils/TableGen/TGLexer.cpp b/utils/TableGen/TGLexer.cpp
index 2af35b05d6d..a6de239e6f6 100644
--- a/utils/TableGen/TGLexer.cpp
+++ b/utils/TableGen/TGLexer.cpp
@@ -256,12 +256,12 @@ bool TGLexer::LexInclude() {
std::string Filename = CurStrVal;
// Try to find the file.
- MemoryBuffer *NewBuf = MemoryBuffer::getFile(&Filename[0], Filename.size());
+ MemoryBuffer *NewBuf = MemoryBuffer::getFile(Filename.c_str());
// If the file didn't exist directly, see if it's in an include path.
for (unsigned i = 0, e = IncludeDirectories.size(); i != e && !NewBuf; ++i) {
std::string IncFile = IncludeDirectories[i] + "/" + Filename;
- NewBuf = MemoryBuffer::getFile(&IncFile[0], IncFile.size());
+ NewBuf = MemoryBuffer::getFile(IncFile.c_str());
}
if (NewBuf == 0) {
diff --git a/utils/TableGen/TableGen.cpp b/utils/TableGen/TableGen.cpp
index 7f8987d5e68..cc996c58466 100644
--- a/utils/TableGen/TableGen.cpp
+++ b/utils/TableGen/TableGen.cpp
@@ -107,8 +107,7 @@ RecordKeeper llvm::Records;
static bool ParseFile(const std::string &Filename,
const std::vector<std::string> &IncludeDirs) {
std::string ErrorStr;
- MemoryBuffer *F = MemoryBuffer::getFileOrSTDIN(&Filename[0], Filename.size(),
- &ErrorStr);
+ MemoryBuffer *F = MemoryBuffer::getFileOrSTDIN(Filename.c_str(), &ErrorStr);
if (F == 0) {
cerr << "Could not open input file '" + Filename + "': " << ErrorStr <<"\n";
return true;