zig 0.16.0 stable
std.time.Instant -> std.Io.Timestamp (Timing helper gets an io handle). .monotonic clock variant -> .awake. 50 tests pass.
This commit is contained in:
22
src/main.zig
22
src/main.zig
@@ -157,7 +157,7 @@ pub fn main(init: std.process.Init) !void {
|
||||
}
|
||||
// Default to -O0 for run (faster compile) unless user explicitly set --opt
|
||||
if (!explicit_opt) target_config.opt_level = .none;
|
||||
var timer = Timing.init(show_timing);
|
||||
var timer = Timing.init(io, show_timing);
|
||||
|
||||
// Phase A: read + parse + resolveImports (for cache key)
|
||||
timer.mark();
|
||||
@@ -409,14 +409,14 @@ fn dumpSxIR(allocator: std.mem.Allocator, io: std.Io, input_path: []const u8) !v
|
||||
}
|
||||
|
||||
fn emitIR(allocator: std.mem.Allocator, io: std.Io, input_path: []const u8, target_config: sx.target.TargetConfig) !void {
|
||||
var timer = Timing.init(false);
|
||||
var timer = Timing.init(io, false);
|
||||
var comp = try compilePipeline(allocator, io, input_path, target_config, &timer);
|
||||
defer comp.deinit();
|
||||
comp.ir_emitter.?.printIR();
|
||||
}
|
||||
|
||||
fn emitAsm(allocator: std.mem.Allocator, io: std.Io, input_path: []const u8, target_config: sx.target.TargetConfig) !void {
|
||||
var timer = Timing.init(false);
|
||||
var timer = Timing.init(io, false);
|
||||
var comp = try compilePipeline(allocator, io, input_path, target_config, &timer);
|
||||
defer comp.deinit();
|
||||
const asm_path = target_config.output_path orelse blk: {
|
||||
@@ -429,7 +429,7 @@ fn emitAsm(allocator: std.mem.Allocator, io: std.Io, input_path: []const u8, tar
|
||||
}
|
||||
|
||||
fn compile(allocator: std.mem.Allocator, io: std.Io, input_path: []const u8, output_path: []const u8, target_config: sx.target.TargetConfig, show_timing: bool, enable_cache: bool) !void {
|
||||
var timer = Timing.init(show_timing);
|
||||
var timer = Timing.init(io, show_timing);
|
||||
try compileWithTimer(allocator, io, input_path, output_path, target_config, &timer, enable_cache);
|
||||
timer.printAll();
|
||||
}
|
||||
@@ -752,29 +752,31 @@ const Timing = struct {
|
||||
const max_entries = 16;
|
||||
|
||||
enabled: bool,
|
||||
io: std.Io,
|
||||
names: [max_entries][]const u8,
|
||||
durations_ns: [max_entries]u64,
|
||||
count: usize,
|
||||
last: ?std.time.Instant,
|
||||
last: ?std.Io.Timestamp,
|
||||
|
||||
fn init(enabled: bool) Timing {
|
||||
fn init(io: std.Io, enabled: bool) Timing {
|
||||
return .{
|
||||
.enabled = enabled,
|
||||
.io = io,
|
||||
.names = undefined,
|
||||
.durations_ns = undefined,
|
||||
.count = 0,
|
||||
.last = if (enabled) (std.time.Instant.now() catch null) else null,
|
||||
.last = if (enabled) std.Io.Timestamp.now(io, .awake) else null,
|
||||
};
|
||||
}
|
||||
|
||||
fn mark(self: *Timing) void {
|
||||
if (self.enabled) self.last = std.time.Instant.now() catch null;
|
||||
if (self.enabled) self.last = std.Io.Timestamp.now(self.io, .awake);
|
||||
}
|
||||
|
||||
fn record(self: *Timing, name: []const u8) void {
|
||||
if (!self.enabled) return;
|
||||
const now = std.time.Instant.now() catch null;
|
||||
const elapsed_ns: u64 = if (self.last != null and now != null) now.?.since(self.last.?) else 0;
|
||||
const now = std.Io.Timestamp.now(self.io, .awake);
|
||||
const elapsed_ns: u64 = if (self.last) |prev| @intCast(prev.durationTo(now).nanoseconds) else 0;
|
||||
if (self.count < max_entries) {
|
||||
self.names[self.count] = name;
|
||||
self.durations_ns[self.count] = elapsed_ns;
|
||||
|
||||
Reference in New Issue
Block a user