diff --git a/bench/pp_bench.zig b/bench/pp_bench.zig index bce586e..e631461 100644 --- a/bench/pp_bench.zig +++ b/bench/pp_bench.zig @@ -10,7 +10,7 @@ const Io = std.Io; const zdxc = @import("zdxc"); const front = zdxc.front; -const Mode = enum { lex, pp, print }; +const Mode = enum { lex, load, pp, print }; /// Serves each path from memory after the first read. const CachedFs = struct { @@ -98,6 +98,10 @@ fn runOne(gpa: std.mem.Allocator, cfs: *CachedFs, path: []const u8, mode: Mode) } var sm = front.source.SourceManager.init(arena, cfs.fileSystem()); + if (mode == .load) { + const id = try sm.load(path) orelse return 0; + return sm.file(id).line_starts.len; + } var diags = zdxc.Diagnostics.init(arena); var pp = front.preproc.Preprocessor.init(arena, &sm, &diags, .{}); if (!try pp.enterMainFile(path)) return 0; diff --git a/src/front/preproc.zig b/src/front/preproc.zig index c515ed1..7863f89 100644 --- a/src/front/preproc.zig +++ b/src/front/preproc.zig @@ -282,7 +282,7 @@ pub const Preprocessor = struct { } while (pp.includes.items.len > 0) { const frame = &pp.includes.items[pp.includes.items.len - 1]; - const t = frame.lex.next(); + const t = @call(.always_inline, lexer.Lexer.next, .{&frame.lex}); if (t.kind != .eof) return .{ .tok = t, .from_file = true }; // End of file: diagnose unterminated conditionals, pop. while (pp.conds.items.len > frame.cond_base) { @@ -316,7 +316,7 @@ pub const Preprocessor = struct { const r = try pp.lexRawSkipDirectives(); const t = r.tok; if (t.kind != .identifier or t.flags.no_expand) return t; - if (std.mem.eql(u8, t.text, "_Pragma")) { + if (t.text.len == 7 and t.text[0] == '_' and std.mem.eql(u8, t.text, "_Pragma")) { if (try pp.pragmaOperator(t)) |pragma| return pragma; continue; }