|
|
|||
File indexing completed on 2026-05-10 08:43:22
0001 //===- llvm/BinaryFormat/Magic.h - File magic identification ----*- C++ -*-===// 0002 // 0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 0004 // See https://llvm.org/LICENSE.txt for license information. 0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 0006 // 0007 //===----------------------------------------------------------------------===// 0008 0009 #ifndef LLVM_BINARYFORMAT_MAGIC_H 0010 #define LLVM_BINARYFORMAT_MAGIC_H 0011 0012 #include <system_error> 0013 0014 namespace llvm { 0015 class StringRef; 0016 class Twine; 0017 0018 /// file_magic - An "enum class" enumeration of file types based on magic (the 0019 /// first N bytes of the file). 0020 struct file_magic { 0021 enum Impl { 0022 unknown = 0, ///< Unrecognized file 0023 bitcode, ///< Bitcode file 0024 clang_ast, ///< Clang PCH or PCM 0025 archive, ///< ar style archive file 0026 elf, ///< ELF Unknown type 0027 elf_relocatable, ///< ELF Relocatable object file 0028 elf_executable, ///< ELF Executable image 0029 elf_shared_object, ///< ELF dynamically linked shared lib 0030 elf_core, ///< ELF core image 0031 goff_object, ///< GOFF object file 0032 macho_object, ///< Mach-O Object file 0033 macho_executable, ///< Mach-O Executable 0034 macho_fixed_virtual_memory_shared_lib, ///< Mach-O Shared Lib, FVM 0035 macho_core, ///< Mach-O Core File 0036 macho_preload_executable, ///< Mach-O Preloaded Executable 0037 macho_dynamically_linked_shared_lib, ///< Mach-O dynlinked shared lib 0038 macho_dynamic_linker, ///< The Mach-O dynamic linker 0039 macho_bundle, ///< Mach-O Bundle file 0040 macho_dynamically_linked_shared_lib_stub, ///< Mach-O Shared lib stub 0041 macho_dsym_companion, ///< Mach-O dSYM companion file 0042 macho_kext_bundle, ///< Mach-O kext bundle file 0043 macho_universal_binary, ///< Mach-O universal binary 0044 macho_file_set, ///< Mach-O file set binary 0045 minidump, ///< Windows minidump file 0046 coff_cl_gl_object, ///< Microsoft cl.exe's intermediate code file 0047 coff_object, ///< COFF object file 0048 coff_import_library, ///< COFF import library 0049 pecoff_executable, ///< PECOFF executable file 0050 windows_resource, ///< Windows compiled resource file (.res) 0051 xcoff_object_32, ///< 32-bit XCOFF object file 0052 xcoff_object_64, ///< 64-bit XCOFF object file 0053 wasm_object, ///< WebAssembly Object file 0054 pdb, ///< Windows PDB debug info file 0055 tapi_file, ///< Text-based Dynamic Library Stub file 0056 cuda_fatbinary, ///< CUDA Fatbinary object file 0057 offload_binary, ///< LLVM offload object file 0058 dxcontainer_object, ///< DirectX container file 0059 offload_bundle, ///< Clang offload bundle file 0060 offload_bundle_compressed, ///< Compressed clang offload bundle file 0061 spirv_object, ///< A binary SPIR-V file 0062 }; 0063 0064 bool is_object() const { return V != unknown; } 0065 0066 file_magic() = default; 0067 file_magic(Impl V) : V(V) {} 0068 operator Impl() const { return V; } 0069 0070 private: 0071 Impl V = unknown; 0072 }; 0073 0074 /// Identify the type of a binary file based on how magical it is. 0075 file_magic identify_magic(StringRef magic); 0076 0077 /// Get and identify \a path's type based on its content. 0078 /// 0079 /// @param path Input path. 0080 /// @param result Set to the type of file, or file_magic::unknown. 0081 /// @returns errc::success if result has been successfully set, otherwise a 0082 /// platform-specific error_code. 0083 std::error_code identify_magic(const Twine &path, file_magic &result); 0084 } // namespace llvm 0085 0086 #endif
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|