asmkit/core/target.rs
1use super::arch_traits::Arch;
2
3/// Object format.
4#[repr(u8)]
5#[derive(Debug, Clone, Copy, PartialEq, Eq)]
6pub enum ObjectFormat {
7 /// Unknown or uninitialized object format.
8 Unknown = 0,
9 /// JIT code generation object.
10 JIT,
11 /// Executable and linkable format (ELF).
12 ELF,
13 /// Common object file format.
14 COFF,
15 /// Extended COFF object format.
16 XCOFF,
17 /// Mach object file format.
18 MachO,
19 /// Maximum value of `ObjectFormat`.
20 MaxValue,
21}
22
23/// Platform ABI (application binary interface).
24#[repr(u8)]
25#[derive(Debug, Clone, Copy, PartialEq, Eq)]
26pub enum PlatformABI {
27 /// Unknown or uninitialized environment.
28 Unknown = 0,
29 /// Microsoft ABI.
30 MSVC,
31 /// GNU ABI.
32 GNU,
33 /// Android Environment / ABI.
34 Android,
35 /// Cygwin ABI.
36 Cygwin,
37 /// Darwin ABI.
38 Darwin,
39 /// Maximum value of `PlatformABI`.
40 MaxValue,
41}
42
43#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Default)]
44pub struct Environment {
45 arch: Arch,
46 is_pic: bool,
47}
48
49impl Environment {
50 pub const fn new(arch: Arch) -> Self {
51 Self {
52 arch,
53 is_pic: false,
54 }
55 }
56
57 pub const fn host() -> Self {
58 Self {
59 arch: Arch::HOST,
60 is_pic: false,
61 }
62 }
63
64 /// Enable or disable PIC (Position independent code).
65 ///
66 /// If enabled code for calls and jumps to symbols will emit near relocations
67 pub fn set_pic(&mut self, value: bool) {
68 self.is_pic = value;
69 }
70
71 pub fn pic(&self) -> bool {
72 self.is_pic
73 }
74}