| 1 | const std = @import("std"); |
| 2 | |
| 3 | /// place uninitialized global variables in a common block |
| 4 | common: bool, |
| 5 | /// Place each function into its own section in the output file if the target supports arbitrary sections |
| 6 | func_sections: bool, |
| 7 | /// Place each data item into its own section in the output file if the target supports arbitrary sections |
| 8 | data_sections: bool, |
| 9 | pic_level: PicLevel, |
| 10 | /// Generate position-independent code that can only be linked into executables |
| 11 | is_pie: bool, |
| 12 | optimization_level: OptimizationLevel, |
| 13 | /// Generate debug information |
| 14 | debug: DebugFormat, |
| 15 | dwarf_version: DwarfVersion, |
| 16 | |
| 17 | pub const DebugFormat = union(enum) { |
| 18 | strip, |
| 19 | dwarf: std.dwarf.Format, |
| 20 | code_view, |
| 21 | }; |
| 22 | |
| 23 | pub const DwarfVersion = enum(u3) { |
| 24 | @"0" = 0, |
| 25 | @"2" = 2, |
| 26 | @"3" = 3, |
| 27 | @"4" = 4, |
| 28 | @"5" = 5, |
| 29 | }; |
| 30 | |
| 31 | pub 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 | |
| 41 | pub 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 | |
| 85 | pub 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 | }; |