Skip to content

Commit

Permalink
Driver: make default optimization level -O0
Browse files Browse the repository at this point in the history
  • Loading branch information
ehaas committed Nov 9, 2024
1 parent 22f2ad6 commit e71d9ee
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
8 changes: 7 additions & 1 deletion src/aro/Driver.zig
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ aro_name: []const u8 = "",
/// Value of --triple= passed via CLI
raw_target_triple: ?[]const u8 = null,

/// Non-optimizing assembly backend is currently selected by passing `-O0`
use_assembly_backend: bool = false,

// linker options
use_linker: ?[]const u8 = null,
linker_path: ?[]const u8 = null,
Expand Down Expand Up @@ -284,11 +287,14 @@ pub fn parseArgs(
macro = args[i];
}
try macro_buf.print("#undef {s}\n", .{macro});
} else if (mem.eql(u8, arg, "-O")) {
d.comp.code_gen_options.optimization_level = .@"0";
} else if (mem.startsWith(u8, arg, "-O")) {
d.comp.code_gen_options.optimization_level = backend.CodeGenOptions.OptimizationLevel.fromString(arg["-O".len..]) orelse {
try d.comp.addDiagnostic(.{ .tag = .cli_invalid_optimization, .extra = .{ .str = arg } }, &.{});
continue;
};
d.use_assembly_backend = d.comp.code_gen_options.optimization_level == .@"0";
} else if (mem.eql(u8, arg, "-undef")) {
d.system_defines = .no_system_defines;
} else if (mem.eql(u8, arg, "-c") or mem.eql(u8, arg, "--compile")) {
Expand Down Expand Up @@ -882,7 +888,7 @@ fn processSource(
var name_buf: [std.fs.max_name_bytes]u8 = undefined;
const out_file_name = try d.getOutFileName(source, &name_buf);

if (d.comp.code_gen_options.optimization_level == .@"0") {
if (d.use_assembly_backend) {
const assembly = asm_gen_fn(d.comp.target, tree) catch |er| switch (er) {
error.CodegenFailed => {
d.renderErrors();
Expand Down
3 changes: 1 addition & 2 deletions src/backend/CodeGenOptions.zig
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ pub const PicLevel = enum(u8) {
};

pub const OptimizationLevel = enum {
unspecified,
@"0",
@"1",
@"2",
Expand Down Expand Up @@ -60,6 +59,6 @@ pub const default: @This() = .{
.data_sections = false,
.pic_level = .none,
.is_pie = false,
.optimization_level = .unspecified,
.optimization_level = .@"0",
.debug = false,
};

0 comments on commit e71d9ee

Please sign in to comment.