1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
const std = @import("std");
/// place uninitialized global variables in a common block
common: bool,
/// Place each function into its own section in the output file if the target supports arbitrary sections
func_sections: bool,
/// Place each data item into its own section in the output file if the target supports arbitrary sections
data_sections: bool,
pic_level: PicLevel,
/// Generate position-independent code that can only be linked into executables
is_pie: bool,
optimization_level: OptimizationLevel,
/// Generate debug information
debug: DebugFormat,
dwarf_version: DwarfVersion,
pub const DebugFormat = union(enum) {
strip,
dwarf: std.dwarf.Format,
code_view,
};
pub const DwarfVersion = enum(u3) {
@"0" = 0,
@"2" = 2,
@"3" = 3,
@"4" = 4,
@"5" = 5,
};
pub const PicLevel = enum(u8) {
/// Do not generate position-independent code
none = 0,
/// Generate position-independent code (PIC) suitable for use in a shared library, if supported for the target machine.
one = 1,
/// If supported for the target machine, emit position-independent code, suitable for dynamic linking and avoiding
/// any limit on the size of the global offset table.
two = 2,
};
pub const OptimizationLevel = enum {
@"0",
@"1",
@"2",
@"3",
/// Optimize for size
s,
/// Disregard strict standards compliance
fast,
/// Optimize debugging experience
g,
/// Optimize aggressively for size rather than speed
z,
const level_map = std.StaticStringMap(OptimizationLevel).initComptime(.{
.{ "0", .@"0" },
.{ "1", .@"1" },
.{ "2", .@"2" },
.{ "3", .@"3" },
.{ "s", .s },
.{ "fast", .fast },
.{ "g", .g },
.{ "z", .z },
});
pub fn fromString(str: []const u8) ?OptimizationLevel {
return level_map.get(str);
}
pub fn isSizeOptimized(self: OptimizationLevel) bool {
return switch (self) {
.s, .z => true,
.@"0", .@"1", .@"2", .@"3", .fast, .g => false,
};
}
pub fn hasAnyOptimizations(self: OptimizationLevel) bool {
return switch (self) {
.@"0" => false,
.@"1", .@"2", .@"3", .s, .fast, .g, .z => true,
};
}
};
pub const default: @This() = .{
.common = false,
.func_sections = false,
.data_sections = false,
.pic_level = .none,
.is_pie = false,
.optimization_level = .@"0",
.debug = .strip,
.dwarf_version = .@"0",
};
|