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