Skip to content

Commit

Permalink
Preprocessor: connect new preprocessor to parser
Browse files Browse the repository at this point in the history
  • Loading branch information
ehaas committed Jul 17, 2024
1 parent 3d1c1d2 commit f78e822
Show file tree
Hide file tree
Showing 8 changed files with 1,693 additions and 5,304 deletions.
45 changes: 0 additions & 45 deletions src/aro/Driver.zig
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const Compilation = @import("Compilation.zig");
const Diagnostics = @import("Diagnostics.zig");
const LangOpts = @import("LangOpts.zig");
const Preprocessor = @import("Preprocessor.zig");
const NewPreprocessor = @import("NewPreprocessor.zig");
const Source = @import("Source.zig");
const Toolchain = @import("Toolchain.zig");
const target_util = @import("target.zig");
Expand Down Expand Up @@ -37,7 +36,6 @@ line_commands: bool = true,
/// If true, use `#line <num>` instead of `# <num>` for line directives
use_line_directives: bool = false,
only_preprocess: bool = false,
new_preprocessor: bool = false,
only_syntax: bool = false,
only_compile: bool = false,
only_preprocess_and_compile: bool = false,
Expand Down Expand Up @@ -238,8 +236,6 @@ pub fn parseArgs(
d.only_compile = true;
} else if (mem.eql(u8, arg, "-E")) {
d.only_preprocess = true;
} else if (mem.eql(u8, arg, "-fnew-preprocessor")) {
d.new_preprocessor = true;
} else if (mem.eql(u8, arg, "-P") or mem.eql(u8, arg, "--no-line-commands")) {
d.line_commands = false;
} else if (mem.eql(u8, arg, "-fuse-line-directives")) {
Expand Down Expand Up @@ -634,47 +630,6 @@ fn processSource(
comptime fast_exit: bool,
) !void {
d.comp.generated_buf.items.len = 0;
if (d.new_preprocessor) {
var pp = try NewPreprocessor.initDefault(d.comp);
defer pp.deinit();
if (d.comp.langopts.ms_extensions) {
d.comp.ms_cwd_source_id = source.id;
}

if (d.verbose_pp) pp.verbose = true;
if (d.only_preprocess) {
pp.preserve_whitespace = true;
if (d.line_commands) {
pp.linemarkers = if (d.use_line_directives) .line_directives else .numeric_directives;
}
}

try pp.preprocessSources(&.{ source, builtin, user_macros });

d.renderErrors();

if (d.comp.diagnostics.errors != 0) {
if (fast_exit) std.process.exit(1); // Not linking, no need for cleanup.
return;
}

const file = if (d.output_name) |some|
std.fs.cwd().createFile(some, .{}) catch |er|
return d.fatal("unable to create output file '{s}': {s}", .{ some, errorDescription(er) })
else
std.io.getStdOut();
defer if (d.output_name != null) file.close();

var buf_w = std.io.bufferedWriter(file.writer());
pp.prettyPrintTokens(buf_w.writer()) catch |er|
return d.fatal("unable to write result: {s}", .{errorDescription(er)});

buf_w.flush() catch |er|
return d.fatal("unable to write result: {s}", .{errorDescription(er)});

std.process.exit(0); // Not linking, no need for cleanup.
return;
}
var pp = try Preprocessor.initDefault(d.comp);
defer pp.deinit();

Expand Down
Loading

0 comments on commit f78e822

Please sign in to comment.