mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-16 14:31:59 +00:00
Remove sys::identifyFileType.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@183763 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
0262db3b55
commit
af2c42e3d2
@ -533,7 +533,7 @@ file_magic identify_magic(StringRef magic);
|
||||
/// @brief Get and identify \a path's type based on its content.
|
||||
///
|
||||
/// @param path Input path.
|
||||
/// @param result Set to the type of file, or LLVMFileType::Unknown_FileType.
|
||||
/// @param result Set to the type of file, or file_magic::unknown.
|
||||
/// @returns errc::success if result has been successfully set, otherwise a
|
||||
/// platform specific error_code.
|
||||
error_code identify_magic(const Twine &path, file_magic &result);
|
||||
|
@ -701,32 +701,6 @@ namespace sys {
|
||||
/// @}
|
||||
};
|
||||
|
||||
/// This enumeration delineates the kinds of files that LLVM knows about.
|
||||
enum LLVMFileType {
|
||||
Unknown_FileType = 0, ///< Unrecognized file
|
||||
Bitcode_FileType, ///< Bitcode file
|
||||
Archive_FileType, ///< ar style archive file
|
||||
ELF_Relocatable_FileType, ///< ELF Relocatable object file
|
||||
ELF_Executable_FileType, ///< ELF Executable image
|
||||
ELF_SharedObject_FileType, ///< ELF dynamically linked shared lib
|
||||
ELF_Core_FileType, ///< ELF core image
|
||||
Mach_O_Object_FileType, ///< Mach-O Object file
|
||||
Mach_O_Executable_FileType, ///< Mach-O Executable
|
||||
Mach_O_FixedVirtualMemorySharedLib_FileType, ///< Mach-O Shared Lib, FVM
|
||||
Mach_O_Core_FileType, ///< Mach-O Core File
|
||||
Mach_O_PreloadExecutable_FileType, ///< Mach-O Preloaded Executable
|
||||
Mach_O_DynamicallyLinkedSharedLib_FileType, ///< Mach-O dynlinked shared lib
|
||||
Mach_O_DynamicLinker_FileType, ///< The Mach-O dynamic linker
|
||||
Mach_O_Bundle_FileType, ///< Mach-O Bundle file
|
||||
Mach_O_DynamicallyLinkedSharedLibStub_FileType, ///< Mach-O Shared lib stub
|
||||
Mach_O_DSYMCompanion_FileType, ///< Mach-O dSYM companion file
|
||||
COFF_FileType ///< COFF object file or lib
|
||||
};
|
||||
|
||||
/// This utility function allows any memory block to be examined in order
|
||||
/// to determine its file type.
|
||||
LLVMFileType identifyFileType(StringRef Magic);
|
||||
|
||||
/// This function can be used to copy the file specified by Src to the
|
||||
/// file specified by Dest. If an error occurs, Dest is removed.
|
||||
/// @returns true if an error occurs, false otherwise
|
||||
|
@ -37,123 +37,6 @@ bool Path::operator<(const Path& that) const {
|
||||
return path < that.path;
|
||||
}
|
||||
|
||||
LLVMFileType
|
||||
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 &&
|
||||
Magic[3] == (char)0x0B)
|
||||
return Bitcode_FileType;
|
||||
break;
|
||||
case 'B':
|
||||
if (Magic[1] == 'C' && Magic[2] == (char)0xC0 && Magic[3] == (char)0xDE)
|
||||
return Bitcode_FileType;
|
||||
break;
|
||||
case '!':
|
||||
if (Length >= 8)
|
||||
if (memcmp(Magic.data(),"!<arch>\n",8) == 0)
|
||||
return Archive_FileType;
|
||||
break;
|
||||
|
||||
case '\177':
|
||||
if (Length >= 18 && Magic[1] == 'E' && Magic[2] == 'L' &&
|
||||
Magic[3] == 'F') {
|
||||
bool Data2MSB = Magic[5] == 2;
|
||||
unsigned high = Data2MSB ? 16 : 17;
|
||||
unsigned low = Data2MSB ? 17 : 16;
|
||||
if (Magic[high] == 0)
|
||||
switch (Magic[low]) {
|
||||
default: break;
|
||||
case 1: return ELF_Relocatable_FileType;
|
||||
case 2: return ELF_Executable_FileType;
|
||||
case 3: return ELF_SharedObject_FileType;
|
||||
case 4: return ELF_Core_FileType;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 0xCA:
|
||||
if (Magic[1] == char(0xFE) && Magic[2] == char(0xBA) &&
|
||||
Magic[3] == char(0xBE)) {
|
||||
// This is complicated by an overlap with Java class files.
|
||||
// See the Mach-O section in /usr/share/file/magic for details.
|
||||
if (Length >= 8 && Magic[7] < 43)
|
||||
// FIXME: Universal Binary of any type.
|
||||
return Mach_O_DynamicallyLinkedSharedLib_FileType;
|
||||
}
|
||||
break;
|
||||
|
||||
// The two magic numbers for mach-o are:
|
||||
// 0xfeedface - 32-bit mach-o
|
||||
// 0xfeedfacf - 64-bit mach-o
|
||||
case 0xFE:
|
||||
case 0xCE:
|
||||
case 0xCF: {
|
||||
uint16_t type = 0;
|
||||
if (Magic[0] == char(0xFE) && Magic[1] == char(0xED) &&
|
||||
Magic[2] == char(0xFA) &&
|
||||
(Magic[3] == char(0xCE) || Magic[3] == char(0xCF))) {
|
||||
/* Native endian */
|
||||
if (Length >= 16) type = Magic[14] << 8 | Magic[15];
|
||||
} else if ((Magic[0] == char(0xCE) || Magic[0] == char(0xCF)) &&
|
||||
Magic[1] == char(0xFA) && Magic[2] == char(0xED) &&
|
||||
Magic[3] == char(0xFE)) {
|
||||
/* Reverse endian */
|
||||
if (Length >= 14) type = Magic[13] << 8 | Magic[12];
|
||||
}
|
||||
switch (type) {
|
||||
default: break;
|
||||
case 1: return Mach_O_Object_FileType;
|
||||
case 2: return Mach_O_Executable_FileType;
|
||||
case 3: return Mach_O_FixedVirtualMemorySharedLib_FileType;
|
||||
case 4: return Mach_O_Core_FileType;
|
||||
case 5: return Mach_O_PreloadExecutable_FileType;
|
||||
case 6: return Mach_O_DynamicallyLinkedSharedLib_FileType;
|
||||
case 7: return Mach_O_DynamicLinker_FileType;
|
||||
case 8: return Mach_O_Bundle_FileType;
|
||||
case 9: return Mach_O_DynamicallyLinkedSharedLibStub_FileType;
|
||||
case 10: return Mach_O_DSYMCompanion_FileType;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 0xF0: // PowerPC Windows
|
||||
case 0x83: // Alpha 32-bit
|
||||
case 0x84: // Alpha 64-bit
|
||||
case 0x66: // MPS R4000 Windows
|
||||
case 0x50: // mc68K
|
||||
case 0x4c: // 80386 Windows
|
||||
if (Magic[1] == 0x01)
|
||||
return COFF_FileType;
|
||||
|
||||
case 0x90: // PA-RISC Windows
|
||||
case 0x68: // mc68K Windows
|
||||
if (Magic[1] == 0x02)
|
||||
return COFF_FileType;
|
||||
break;
|
||||
|
||||
case 0x4d: // Possible MS-DOS stub on Windows PE file
|
||||
if (Magic[1] == 0x5a) {
|
||||
uint32_t off =
|
||||
*reinterpret_cast<const ulittle32_t *>(Magic.data() + 0x3c);
|
||||
// PE/COFF file, either EXE or DLL.
|
||||
if (off < Length && memcmp(Magic.data() + off, "PE\0\0",4) == 0)
|
||||
return COFF_FileType;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x64: // x86-64 Windows.
|
||||
if (Magic[1] == char(0x86))
|
||||
return COFF_FileType;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return Unknown_FileType;
|
||||
}
|
||||
|
||||
bool
|
||||
Path::isArchive() const {
|
||||
fs::file_magic type;
|
||||
|
Loading…
x
Reference in New Issue
Block a user