[llvm] r183669 - Pass a StringRef to sys::identifyFileType.
Rafael Espindola
rafael.espindola at gmail.com
Mon Jun 10 08:27:40 PDT 2013
Author: rafael
Date: Mon Jun 10 10:27:39 2013
New Revision: 183669
URL: http://llvm.org/viewvc/llvm-project?rev=183669&view=rev
Log:
Pass a StringRef to sys::identifyFileType.
Modified:
llvm/trunk/include/llvm/ExecutionEngine/ObjectBuffer.h
llvm/trunk/include/llvm/Support/PathV1.h
llvm/trunk/lib/Archive/Archive.cpp
llvm/trunk/lib/Archive/ArchiveReader.cpp
llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp
llvm/trunk/lib/Object/Binary.cpp
llvm/trunk/lib/Object/ObjectFile.cpp
llvm/trunk/lib/Support/Path.cpp
llvm/trunk/tools/lto/LTOModule.cpp
Modified: llvm/trunk/include/llvm/ExecutionEngine/ObjectBuffer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ExecutionEngine/ObjectBuffer.h?rev=183669&r1=183668&r2=183669&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ExecutionEngine/ObjectBuffer.h (original)
+++ llvm/trunk/include/llvm/ExecutionEngine/ObjectBuffer.h Mon Jun 10 10:27:39 2013
@@ -44,6 +44,7 @@ public:
const char *getBufferStart() const { return Buffer->getBufferStart(); }
size_t getBufferSize() const { return Buffer->getBufferSize(); }
+ StringRef getBuffer() const { return Buffer->getBuffer(); }
protected:
// The memory contained in an ObjectBuffer
Modified: llvm/trunk/include/llvm/Support/PathV1.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/PathV1.h?rev=183669&r1=183668&r2=183669&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/PathV1.h (original)
+++ llvm/trunk/include/llvm/Support/PathV1.h Mon Jun 10 10:27:39 2013
@@ -725,9 +725,9 @@ namespace sys {
/// This utility function allows any memory block to be examined in order
/// to determine its file type.
- LLVMFileType identifyFileType(const char *Magic, unsigned Length);
+ LLVMFileType identifyFileType(StringRef Magic);
inline LLVMFileType IdentifyFileType(const char *Magic, unsigned Length) {
- return identifyFileType(Magic, Length);
+ return identifyFileType(StringRef(Magic, Length));
}
/// This function can be used to copy the file specified by Src to the
Modified: llvm/trunk/lib/Archive/Archive.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Archive/Archive.cpp?rev=183669&r1=183668&r2=183669&view=diff
==============================================================================
--- llvm/trunk/lib/Archive/Archive.cpp (original)
+++ llvm/trunk/lib/Archive/Archive.cpp Mon Jun 10 10:27:39 2013
@@ -129,7 +129,7 @@ bool ArchiveMember::replaceWith(const sy
}
// Determine what kind of file it is.
- switch (sys::IdentifyFileType(signature,4)) {
+ switch (sys::identifyFileType(StringRef(signature, 4))) {
case sys::Bitcode_FileType:
flags |= BitcodeFlag;
break;
Modified: llvm/trunk/lib/Archive/ArchiveReader.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Archive/ArchiveReader.cpp?rev=183669&r1=183668&r2=183669&view=diff
==============================================================================
--- llvm/trunk/lib/Archive/ArchiveReader.cpp (original)
+++ llvm/trunk/lib/Archive/ArchiveReader.cpp Mon Jun 10 10:27:39 2013
@@ -205,7 +205,7 @@ Archive::parseMemberHeader(const char*&
}
// Determine if this is a bitcode file
- switch (sys::IdentifyFileType(At, 4)) {
+ switch (sys::identifyFileType(StringRef(At, 4))) {
case sys::Bitcode_FileType:
flags |= ArchiveMember::BitcodeFlag;
break;
Modified: llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp?rev=183669&r1=183668&r2=183669&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp Mon Jun 10 10:27:39 2013
@@ -501,9 +501,7 @@ RuntimeDyld::~RuntimeDyld() {
ObjectImage *RuntimeDyld::loadObject(ObjectBuffer *InputBuffer) {
if (!Dyld) {
- sys::LLVMFileType type = sys::IdentifyFileType(
- InputBuffer->getBufferStart(),
- static_cast<unsigned>(InputBuffer->getBufferSize()));
+ sys::LLVMFileType type = sys::identifyFileType(InputBuffer->getBuffer());
switch (type) {
case sys::ELF_Relocatable_FileType:
case sys::ELF_Executable_FileType:
Modified: llvm/trunk/lib/Object/Binary.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/Binary.cpp?rev=183669&r1=183668&r2=183669&view=diff
==============================================================================
--- llvm/trunk/lib/Object/Binary.cpp (original)
+++ llvm/trunk/lib/Object/Binary.cpp Mon Jun 10 10:27:39 2013
@@ -45,8 +45,7 @@ error_code object::createBinary(MemoryBu
OwningPtr<MemoryBuffer> scopedSource(Source);
if (!Source)
return make_error_code(errc::invalid_argument);
- sys::LLVMFileType type = sys::IdentifyFileType(Source->getBufferStart(),
- static_cast<unsigned>(Source->getBufferSize()));
+ sys::LLVMFileType type = sys::identifyFileType(Source->getBuffer());
error_code ec;
switch (type) {
case sys::Archive_FileType: {
Modified: llvm/trunk/lib/Object/ObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/ObjectFile.cpp?rev=183669&r1=183668&r2=183669&view=diff
==============================================================================
--- llvm/trunk/lib/Object/ObjectFile.cpp (original)
+++ llvm/trunk/lib/Object/ObjectFile.cpp Mon Jun 10 10:27:39 2013
@@ -40,8 +40,7 @@ section_iterator ObjectFile::getRelocate
ObjectFile *ObjectFile::createObjectFile(MemoryBuffer *Object) {
if (!Object || Object->getBufferSize() < 64)
return 0;
- sys::LLVMFileType type = sys::IdentifyFileType(Object->getBufferStart(),
- static_cast<unsigned>(Object->getBufferSize()));
+ sys::LLVMFileType type = sys::identifyFileType(Object->getBuffer());
switch (type) {
case sys::Unknown_FileType:
return 0;
Modified: llvm/trunk/lib/Support/Path.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Path.cpp?rev=183669&r1=183668&r2=183669&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Path.cpp (original)
+++ llvm/trunk/lib/Support/Path.cpp Mon Jun 10 10:27:39 2013
@@ -38,9 +38,9 @@ bool Path::operator<(const Path& that) c
}
LLVMFileType
-sys::identifyFileType(const char *Magic, unsigned Length) {
- assert(Magic && "Invalid magic number string");
- assert(Length >=4 && "Invalid magic number length");
+sys::identifyFileType(StringRef Magic) {
+ unsigned Length = Magic.size();
+ assert(Length >= 4 && "Invalid magic number length");
switch ((unsigned char)Magic[0]) {
case 0xDE: // 0x0B17C0DE = BC wraper
if (Magic[1] == (char)0xC0 && Magic[2] == (char)0x17 &&
@@ -53,7 +53,7 @@ sys::identifyFileType(const char *Magic,
break;
case '!':
if (Length >= 8)
- if (memcmp(Magic,"!<arch>\n",8) == 0)
+ if (memcmp(Magic.data(),"!<arch>\n",8) == 0)
return Archive_FileType;
break;
@@ -136,9 +136,9 @@ sys::identifyFileType(const char *Magic,
case 0x4d: // Possible MS-DOS stub on Windows PE file
if (Magic[1] == 0x5a) {
uint32_t off =
- *reinterpret_cast<const ulittle32_t *>(Magic + 0x3c);
+ *reinterpret_cast<const ulittle32_t *>(Magic.data() + 0x3c);
// PE/COFF file, either EXE or DLL.
- if (off < Length && memcmp(Magic + off, "PE\0\0",4) == 0)
+ if (off < Length && memcmp(Magic.data() + off, "PE\0\0",4) == 0)
return COFF_FileType;
}
break;
Modified: llvm/trunk/tools/lto/LTOModule.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/lto/LTOModule.cpp?rev=183669&r1=183668&r2=183669&view=diff
==============================================================================
--- llvm/trunk/tools/lto/LTOModule.cpp (original)
+++ llvm/trunk/tools/lto/LTOModule.cpp Mon Jun 10 10:27:39 2013
@@ -163,7 +163,7 @@ LTOModule::LTOModule(llvm::Module *m, ll
/// isBitcodeFile - Returns 'true' if the file (or memory contents) is LLVM
/// bitcode.
bool LTOModule::isBitcodeFile(const void *mem, size_t length) {
- return llvm::sys::IdentifyFileType((const char*)mem, length)
+ return llvm::sys::identifyFileType(StringRef((const char*)mem, length))
== llvm::sys::Bitcode_FileType;
}
More information about the llvm-commits
mailing list