LLVM  14.0.0git
Magic.h
Go to the documentation of this file.
1 //===- llvm/BinaryFormat/Magic.h - File magic identification ----*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLVM_BINARYFORMAT_MAGIC_H
10 #define LLVM_BINARYFORMAT_MAGIC_H
11 
12 #include <system_error>
13 
14 namespace llvm {
15 class StringRef;
16 class Twine;
17 
18 /// file_magic - An "enum class" enumeration of file types based on magic (the
19 /// first N bytes of the file).
20 struct file_magic {
21  enum Impl {
22  unknown = 0, ///< Unrecognized file
23  bitcode, ///< Bitcode file
24  archive, ///< ar style archive file
25  elf, ///< ELF Unknown type
26  elf_relocatable, ///< ELF Relocatable object file
27  elf_executable, ///< ELF Executable image
28  elf_shared_object, ///< ELF dynamically linked shared lib
29  elf_core, ///< ELF core image
30  goff_object, ///< GOFF object file
31  macho_object, ///< Mach-O Object file
32  macho_executable, ///< Mach-O Executable
33  macho_fixed_virtual_memory_shared_lib, ///< Mach-O Shared Lib, FVM
34  macho_core, ///< Mach-O Core File
35  macho_preload_executable, ///< Mach-O Preloaded Executable
36  macho_dynamically_linked_shared_lib, ///< Mach-O dynlinked shared lib
37  macho_dynamic_linker, ///< The Mach-O dynamic linker
38  macho_bundle, ///< Mach-O Bundle file
39  macho_dynamically_linked_shared_lib_stub, ///< Mach-O Shared lib stub
40  macho_dsym_companion, ///< Mach-O dSYM companion file
41  macho_kext_bundle, ///< Mach-O kext bundle file
42  macho_universal_binary, ///< Mach-O universal binary
43  minidump, ///< Windows minidump file
44  coff_cl_gl_object, ///< Microsoft cl.exe's intermediate code file
45  coff_object, ///< COFF object file
46  coff_import_library, ///< COFF import library
47  pecoff_executable, ///< PECOFF executable file
48  windows_resource, ///< Windows compiled resource file (.res)
49  xcoff_object_32, ///< 32-bit XCOFF object file
50  xcoff_object_64, ///< 64-bit XCOFF object file
51  wasm_object, ///< WebAssembly Object file
52  pdb, ///< Windows PDB debug info file
53  tapi_file, ///< Text-based Dynamic Library Stub file
54  };
55 
56  bool is_object() const { return V != unknown; }
57 
58  file_magic() = default;
59  file_magic(Impl V) : V(V) {}
60  operator Impl() const { return V; }
61 
62 private:
63  Impl V = unknown;
64 };
65 
66 /// Identify the type of a binary file based on how magical it is.
67 file_magic identify_magic(StringRef magic);
68 
69 /// Get and identify \a path's type based on its content.
70 ///
71 /// @param path Input path.
72 /// @param result Set to the type of file, or file_magic::unknown.
73 /// @returns errc::success if result has been successfully set, otherwise a
74 /// platform-specific error_code.
75 std::error_code identify_magic(const Twine &path, file_magic &result);
76 } // namespace llvm
77 
78 #endif
llvm::file_magic::unknown
@ unknown
Unrecognized file.
Definition: Magic.h:22
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::file_magic
file_magic - An "enum class" enumeration of file types based on magic (the first N bytes of the file)...
Definition: Magic.h:20
llvm::file_magic::Impl
Impl
Definition: Magic.h:21
llvm::file_magic::elf_core
@ elf_core
ELF core image.
Definition: Magic.h:29
llvm::file_magic::pdb
@ pdb
Windows PDB debug info file.
Definition: Magic.h:52
llvm::file_magic::macho_dynamic_linker
@ macho_dynamic_linker
The Mach-O dynamic linker.
Definition: Magic.h:37
llvm::file_magic::elf_shared_object
@ elf_shared_object
ELF dynamically linked shared lib.
Definition: Magic.h:28
llvm::file_magic::goff_object
@ goff_object
GOFF object file.
Definition: Magic.h:30
llvm::file_magic::minidump
@ minidump
Windows minidump file.
Definition: Magic.h:43
llvm::file_magic::file_magic
file_magic()=default
result
It looks like we only need to define PPCfmarto for these because according to these instructions perform RTO on fma s result
Definition: README_P9.txt:256
llvm::file_magic::bitcode
@ bitcode
Bitcode file.
Definition: Magic.h:23
llvm::file_magic::xcoff_object_64
@ xcoff_object_64
64-bit XCOFF object file
Definition: Magic.h:50
llvm::file_magic::macho_preload_executable
@ macho_preload_executable
Mach-O Preloaded Executable.
Definition: Magic.h:35
llvm::file_magic::macho_bundle
@ macho_bundle
Mach-O Bundle file.
Definition: Magic.h:38
llvm::file_magic::macho_core
@ macho_core
Mach-O Core File.
Definition: Magic.h:34
llvm::file_magic::macho_dsym_companion
@ macho_dsym_companion
Mach-O dSYM companion file.
Definition: Magic.h:40
llvm::file_magic::is_object
bool is_object() const
Definition: Magic.h:56
llvm::file_magic::elf_relocatable
@ elf_relocatable
ELF Relocatable object file.
Definition: Magic.h:26
llvm::file_magic::coff_import_library
@ coff_import_library
COFF import library.
Definition: Magic.h:46
llvm::file_magic::pecoff_executable
@ pecoff_executable
PECOFF executable file.
Definition: Magic.h:47
llvm::file_magic::macho_universal_binary
@ macho_universal_binary
Mach-O universal binary.
Definition: Magic.h:42
llvm::file_magic::macho_dynamically_linked_shared_lib
@ macho_dynamically_linked_shared_lib
Mach-O dynlinked shared lib.
Definition: Magic.h:36
llvm::file_magic::macho_dynamically_linked_shared_lib_stub
@ macho_dynamically_linked_shared_lib_stub
Mach-O Shared lib stub.
Definition: Magic.h:39
llvm::file_magic::coff_object
@ coff_object
COFF object file.
Definition: Magic.h:45
llvm::file_magic::macho_kext_bundle
@ macho_kext_bundle
Mach-O kext bundle file.
Definition: Magic.h:41
magic
static ms magic(const APInt &d)
Calculate the magic numbers required to implement a signed integer division by a constant as a sequen...
Definition: TargetLowering.cpp:5192
llvm::file_magic::macho_fixed_virtual_memory_shared_lib
@ macho_fixed_virtual_memory_shared_lib
Mach-O Shared Lib, FVM.
Definition: Magic.h:33
llvm::file_magic::elf
@ elf
ELF Unknown type.
Definition: Magic.h:25
llvm::file_magic::archive
@ archive
ar style archive file
Definition: Magic.h:24
llvm::file_magic::elf_executable
@ elf_executable
ELF Executable image.
Definition: Magic.h:27
llvm::file_magic::wasm_object
@ wasm_object
WebAssembly Object file.
Definition: Magic.h:51
llvm::file_magic::file_magic
file_magic(Impl V)
Definition: Magic.h:59
llvm::file_magic::coff_cl_gl_object
@ coff_cl_gl_object
Microsoft cl.exe's intermediate code file.
Definition: Magic.h:44
llvm::file_magic::macho_executable
@ macho_executable
Mach-O Executable.
Definition: Magic.h:32
llvm::file_magic::tapi_file
@ tapi_file
Text-based Dynamic Library Stub file.
Definition: Magic.h:53
llvm::identify_magic
file_magic identify_magic(StringRef magic)
Identify the type of a binary file based on how magical it is.
Definition: Magic.cpp:35
llvm::file_magic::windows_resource
@ windows_resource
Windows compiled resource file (.res)
Definition: Magic.h:48
llvm::file_magic::macho_object
@ macho_object
Mach-O Object file.
Definition: Magic.h:31
llvm::file_magic::xcoff_object_32
@ xcoff_object_32
32-bit XCOFF object file
Definition: Magic.h:49