aboutsummaryrefslogtreecommitdiff
path: root/lib/std
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2022-01-04 18:12:45 -0700
committerAndrew Kelley <andrew@ziglang.org>2022-01-04 18:12:45 -0700
commit1c24ef0d0b09a12a1fe98056f2fc04de78a82df3 (patch)
treeb80e1fe8fe801541f962c1965cb84c3167a68feb /lib/std
parent5087ec6f41ba928e14596e00822dc117aeb90a12 (diff)
downloadzig-1c24ef0d0b09a12a1fe98056f2fc04de78a82df3.tar.gz
zig-1c24ef0d0b09a12a1fe98056f2fc04de78a82df3.zip
stage2: introduce std.builtin.CompilerBackend
This allows Zig code to perform conditional compilation based on a tag by which a Zig compiler implementation identifies itself. See the doc comment in this commit for more details.
Diffstat (limited to 'lib/std')
-rw-r--r--lib/std/builtin.zig55
1 files changed, 55 insertions, 0 deletions
diff --git a/lib/std/builtin.zig b/lib/std/builtin.zig
index 44b86af985..d8dbbfb068 100644
--- a/lib/std/builtin.zig
+++ b/lib/std/builtin.zig
@@ -694,6 +694,61 @@ pub const ExternOptions = struct {
is_thread_local: bool = false,
};
+/// This enum is set by the compiler and communicates which compiler backend is
+/// used to produce machine code.
+/// Think carefully before deciding to observe this value. Nearly all code should
+/// be agnostic to the backend that implements the language. The use case
+/// to use this value is to **work around problems with compiler implementations.**
+///
+/// Avoid failing the compilation if the compiler backend does not match a
+/// whitelist of backends; rather one should detect that a known problem would
+/// occur in a blacklist of backends.
+///
+/// The enum is nonexhaustive so that alternate Zig language implementations may
+/// choose a number as their tag (please use a random number generator rather
+/// than a "cute" number) and codebases can interact with these values even if
+/// this upstream enum does not have a name for the number. Of course, upstream
+/// is happy to accept pull requests to add Zig implementations to this enum.
+///
+/// This data structure is part of the Zig language specification.
+pub const CompilerBackend = enum(u64) {
+ /// It is allowed for a compiler implementation to not reveal its identity,
+ /// in which case this value is appropriate. Be cool and make sure your
+ /// code supports `other` Zig compilers!
+ other = 0,
+ /// The original Zig compiler created in 2015 by Andrew Kelley.
+ /// Implemented in C++. Uses LLVM.
+ stage1 = 1,
+ /// The reference implementation self-hosted compiler of Zig, using the
+ /// LLVM backend.
+ stage2_llvm = 2,
+ /// The reference implementation self-hosted compiler of Zig, using the
+ /// backend that generates C source code.
+ /// Note that one can observe whether the compilation will output C code
+ /// directly with `object_format` value rather than the `compiler_backend` value.
+ stage2_c = 3,
+ /// The reference implementation self-hosted compiler of Zig, using the
+ /// WebAssembly backend.
+ stage2_wasm = 4,
+ /// The reference implementation self-hosted compiler of Zig, using the
+ /// arm backend.
+ stage2_arm = 5,
+ /// The reference implementation self-hosted compiler of Zig, using the
+ /// x86_64 backend.
+ stage2_x86_64 = 6,
+ /// The reference implementation self-hosted compiler of Zig, using the
+ /// aarch64 backend.
+ stage2_aarch64 = 7,
+ /// The reference implementation self-hosted compiler of Zig, using the
+ /// x86 backend.
+ stage2_x86 = 8,
+ /// The reference implementation self-hosted compiler of Zig, using the
+ /// riscv64 backend.
+ stage2_riscv64 = 9,
+
+ _,
+};
+
/// This function type is used by the Zig language code generation and
/// therefore must be kept in sync with the compiler implementation.
pub const TestFn = struct {