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