master
1const std = @import("std");
2
3const ast = @import("ast.zig");
4
5/// All builtins need to have a source so that macros can reference them
6/// but for some it is possible to directly call an equivalent Zig builtin
7/// which is preferrable.
8pub const Builtin = struct {
9 /// The name of the builtin in `c_builtins.zig`.
10 name: []const u8,
11 tag: ?ast.Node.Tag = null,
12};
13
14pub const map = std.StaticStringMap(Builtin).initComptime([_]struct { []const u8, Builtin }{
15 .{ "__builtin_abs", .{ .name = "abs" } },
16 .{ "__builtin_assume", .{ .name = "assume" } },
17 .{ "__builtin_bswap16", .{ .name = "bswap16", .tag = .byte_swap } },
18 .{ "__builtin_bswap32", .{ .name = "bswap32", .tag = .byte_swap } },
19 .{ "__builtin_bswap64", .{ .name = "bswap64", .tag = .byte_swap } },
20 .{ "__builtin_ceilf", .{ .name = "ceilf", .tag = .ceil } },
21 .{ "__builtin_ceil", .{ .name = "ceil", .tag = .ceil } },
22 .{ "__builtin_clz", .{ .name = "clz" } },
23 .{ "__builtin_constant_p", .{ .name = "constant_p" } },
24 .{ "__builtin_cosf", .{ .name = "cosf", .tag = .cos } },
25 .{ "__builtin_cos", .{ .name = "cos", .tag = .cos } },
26 .{ "__builtin_ctz", .{ .name = "ctz" } },
27 .{ "__builtin_exp2f", .{ .name = "exp2f", .tag = .exp2 } },
28 .{ "__builtin_exp2", .{ .name = "exp2", .tag = .exp2 } },
29 .{ "__builtin_expf", .{ .name = "expf", .tag = .exp } },
30 .{ "__builtin_exp", .{ .name = "exp", .tag = .exp } },
31 .{ "__builtin_expect", .{ .name = "expect" } },
32 .{ "__builtin_fabsf", .{ .name = "fabsf", .tag = .abs } },
33 .{ "__builtin_fabs", .{ .name = "fabs", .tag = .abs } },
34 .{ "__builtin_floorf", .{ .name = "floorf", .tag = .floor } },
35 .{ "__builtin_floor", .{ .name = "floor", .tag = .floor } },
36 .{ "__builtin_huge_valf", .{ .name = "huge_valf" } },
37 .{ "__builtin_inff", .{ .name = "inff" } },
38 .{ "__builtin_isinf_sign", .{ .name = "isinf_sign" } },
39 .{ "__builtin_isinf", .{ .name = "isinf" } },
40 .{ "__builtin_isnan", .{ .name = "isnan" } },
41 .{ "__builtin_labs", .{ .name = "labs" } },
42 .{ "__builtin_llabs", .{ .name = "llabs" } },
43 .{ "__builtin_log10f", .{ .name = "log10f", .tag = .log10 } },
44 .{ "__builtin_log10", .{ .name = "log10", .tag = .log10 } },
45 .{ "__builtin_log2f", .{ .name = "log2f", .tag = .log2 } },
46 .{ "__builtin_log2", .{ .name = "log2", .tag = .log2 } },
47 .{ "__builtin_logf", .{ .name = "logf", .tag = .log } },
48 .{ "__builtin_log", .{ .name = "log", .tag = .log } },
49 .{ "__builtin___memcpy_chk", .{ .name = "memcpy_chk" } },
50 .{ "__builtin_memcpy", .{ .name = "memcpy" } },
51 .{ "__builtin___memset_chk", .{ .name = "memset_chk" } },
52 .{ "__builtin_memset", .{ .name = "memset" } },
53 .{ "__builtin_mul_overflow", .{ .name = "mul_overflow" } },
54 .{ "__builtin_nanf", .{ .name = "nanf" } },
55 .{ "__builtin_object_size", .{ .name = "object_size" } },
56 .{ "__builtin_popcount", .{ .name = "popcount" } },
57 .{ "__builtin_roundf", .{ .name = "roundf", .tag = .round } },
58 .{ "__builtin_round", .{ .name = "round", .tag = .round } },
59 .{ "__builtin_signbitf", .{ .name = "signbitf" } },
60 .{ "__builtin_signbit", .{ .name = "signbit" } },
61 .{ "__builtin_sinf", .{ .name = "sinf", .tag = .sin } },
62 .{ "__builtin_sin", .{ .name = "sin", .tag = .sin } },
63 .{ "__builtin_sqrtf", .{ .name = "sqrtf", .tag = .sqrt } },
64 .{ "__builtin_sqrt", .{ .name = "sqrt", .tag = .sqrt } },
65 .{ "__builtin_strcmp", .{ .name = "strcmp" } },
66 .{ "__builtin_strlen", .{ .name = "strlen" } },
67 .{ "__builtin_truncf", .{ .name = "truncf", .tag = .trunc } },
68 .{ "__builtin_trunc", .{ .name = "trunc", .tag = .trunc } },
69 .{ "__builtin_unreachable", .{ .name = "unreachable", .tag = .@"unreachable" } },
70 .{ "__has_builtin", .{ .name = "has_builtin" } },
71
72 // __builtin_alloca_with_align is not currently implemented.
73 // It is used in a run and a translate test to ensure that non-implemented
74 // builtins are correctly demoted. If you implement __builtin_alloca_with_align,
75 // please update the tests to use a different non-implemented builtin.
76});