1 // Written in the D programming language.
2 
3 /**
4  * Information about the target operating system, environment, and CPU.
5  *
6  *  Copyright: Copyright The D Language Foundation 2000 - 2011
7  *  License:   $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0).
8  *  Authors:   $(HTTP digitalmars.com, Walter Bright) and
9                $(HTTP jmdavisprog.com, Jonathan M Davis)
10  *  Source:    $(PHOBOSSRC phobos/sys/system.d)
11  */
12 module phobos.sys.system;
13 
14 immutable
15 {
16     /++
17         Operating system.
18 
19         Note:
20             This is for cases where you need a value representing the OS at
21             runtime. If you're doing something which should compile differently
22             on different OSes, then please use `version (Windows)`,
23             `version (linux)`, etc.
24 
25         See_Also:
26             $(DDSUBLINK spec/version,PredefinedVersions, Predefined Versions)
27       +/
28     enum OS
29     {
30         win32 = 1, /// Microsoft 32 bit Windows systems
31         win64,     /// Microsoft 64 bit Windows systems
32         linux,     /// All Linux Systems, except for Android
33         osx,       /// Mac OS X
34         iOS,       /// iOS
35         tvOS,      /// tvOS
36         watchOS,   /// watchOS
37         freeBSD,   /// FreeBSD
38         netBSD,    /// NetBSD
39         openBSD,   /// OpenBSD
40         dragonFlyBSD, /// DragonFlyBSD
41         solaris,   /// Solaris
42         haiku, /// HaikuOS
43         android,   /// Android
44         otherPosix, /// Other Posix Systems
45         unknown,   /// Unknown
46     }
47 
48     /// The OS that the program was compiled for.
49     version (Win32)        OS os = OS.win32;
50     else version (Win64)   OS os = OS.win64;
51     else version (Android) OS os = OS.android;
52     else version (linux)   OS os = OS.linux;
53     else version (OSX)     OS os = OS.osx;
54     else version (iOS)     OS os = OS.iOS;
55     else version (tvOS)    OS os = OS.tvOS;
56     else version (watchOS) OS os = OS.watchOS;
57     else version (FreeBSD) OS os = OS.freeBSD;
58     else version (NetBSD)  OS os = OS.netBSD;
59     else version (OpenBSD) OS os = OS.openBSD;
60     else version (DragonFlyBSD) OS os = OS.dragonFlyBSD;
61     else version (Solaris) OS os = OS.solaris;
62     else version (Haiku) OS os = OS.haiku;
63     else version (Posix)   OS os = OS.otherPosix;
64     else OS os = OS.unknown;
65 
66     /++
67         Byte order endianness.
68 
69         Note:
70             This is intended for cases where you need to deal with endianness at
71             runtime. If you're doing something which should compile differently
72             depending on whether you're compiling on a big endian or little
73             endian machine, then please use `version (BigEndian)` and
74             `version (LittleEndian)`.
75 
76         See_Also:
77             $(DDSUBLINK spec/version,PredefinedVersions, Predefined Versions)
78       +/
79     enum Endian
80     {
81         bigEndian,   /// Big endian byte order
82         littleEndian /// Little endian byte order
83     }
84 
85     /// The endianness that the program was compiled for.
86     version (LittleEndian) Endian endian = Endian.littleEndian;
87     else                  Endian endian = Endian.bigEndian;
88     /++
89         Instruction Set Architecture.
90 
91         Note:
92             This is intended for cases where you need a value representing the
93             instruction set architecture at runtime. If you're doing something
94             which should compile differently depending on instruction set
95             architecture, then please use `version (X86_64)`, `version (ARM)`,
96             etc.
97 
98         See_Also:
99             $(DDSUBLINK spec/version,PredefinedVersions, Predefined Versions)
100       +/
101     enum ISA
102     {
103         x86,   /// Intel and AMD 32-bit processors
104         x86_64, /// Intel and AMD 64-bit processors
105         arm, /// The ARM architecture (32-bit) (AArch32 et al)
106         aarch64, /// The Advanced RISC Machine architecture (64-bit)
107         asmJS, /// The asm.js intermediate programming language
108         avr, /// 8-bit Atmel AVR Microcontrollers
109         epiphany, /// The Epiphany architecture
110         ppc, /// The PowerPC architecture, 32-bit
111         ppc64, /// The PowerPC architecture, 64-bit
112         ia64, /// The Itanium architecture (64-bit)
113         mips32, /// The MIPS architecture, 32-bit
114         mips64, /// The MIPS architecture, 64-bit
115         msp430, /// The MSP430 architecture
116         nvptx, /// The Nvidia Parallel Thread Execution (PTX) architecture, 32-bit
117         nvptx64, /// The Nvidia Parallel Thread Execution (PTX) architecture, 64-bit
118         riscv32, /// The RISC-V architecture, 32-bit
119         riscv64, /// The RISC-V architecture, 64-bit
120         sparc, /// The SPARC architecture, 32-bit
121         sparc64, /// The SPARC architecture, 64-bit
122         s390, /// The System/390 architecture, 32-bit
123         systemZ, /// The System Z architecture, 64-bit
124         hppa, /// The HP PA-RISC architecture, 32-bit
125         hppa64, /// The HP PA-RISC architecture, 64-bit
126         sh, /// The SuperH architecture, 32-bit
127         webAssembly, /// The WebAssembly virtual ISA (instruction set architecture), 32-bit
128         alpha, /// The Alpha architecture
129         unknown, /// Unknown
130     }
131 
132     /// The instruction set architecture that the program was compiled for.
133     version (X86) ISA instructionSetArchitecture = ISA.x86;
134     else version (X86_64)   ISA instructionSetArchitecture = ISA.x86_64;
135     else version (ARM)      ISA instructionSetArchitecture = ISA.arm;
136     else version (AArch64)  ISA instructionSetArchitecture = ISA.aarch64;
137     else version (AsmJS)    ISA instructionSetArchitecture = ISA.asmJS;
138     else version (AVR)      ISA instructionSetArchitecture = ISA.avr;
139     else version (Epiphany) ISA instructionSetArchitecture = ISA.epiphany;
140     else version (PPC)      ISA instructionSetArchitecture = ISA.ppc;
141     else version (PPC64)    ISA instructionSetArchitecture = ISA.ppc64;
142     else version (IA64)     ISA instructionSetArchitecture = ISA.ia64;
143     else version (MIPS32)   ISA instructionSetArchitecture = ISA.mips32;
144     else version (MIPS64)   ISA instructionSetArchitecture = ISA.mips64;
145     else version (MSP430)   ISA instructionSetArchitecture = ISA.msp430;
146     else version (NVPTX)    ISA instructionSetArchitecture = ISA.nvptx;
147     else version (NVPTX64)  ISA instructionSetArchitecture = ISA.nvptx64;
148     else version (RISCV32)  ISA instructionSetArchitecture = ISA.riscv32;
149     else version (RISCV64)  ISA instructionSetArchitecture = ISA.riscv64;
150     else version (SPARC)    ISA instructionSetArchitecture = ISA.sparc;
151     else version (SPARC64)  ISA instructionSetArchitecture = ISA.sparc64;
152     else version (S390)     ISA instructionSetArchitecture = ISA.s390;
153     else version (SystemZ)  ISA instructionSetArchitecture = ISA.systemZ;
154     else version (HPPA)     ISA instructionSetArchitecture = ISA.hppa;
155     else version (HPPA64)   ISA instructionSetArchitecture = ISA.hppa64;
156     else version (SH)       ISA instructionSetArchitecture = ISA.sh;
157     else version (WebAssembly) ISA instructionSetArchitecture = ISA.webAssembly;
158     else version (Alpha)    ISA instructionSetArchitecture = ISA.alpha;
159     else ISA instructionSetArchitecture = ISA.unknown;
160 }