Skip to content

Commit a2e3576

Browse files
committed
move code for emitting zir up so even if semantic analysis fails, zir will be emitted
1 parent 8697ae8 commit a2e3576

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

src/main.zig

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1947,6 +1947,20 @@ const AfterUpdateHook = union(enum) {
19471947
fn updateModule(gpa: *Allocator, comp: *Compilation, zir_out_path: ?[]const u8, hook: AfterUpdateHook) !void {
19481948
try comp.update();
19491949

1950+
if (zir_out_path) |zop| {
1951+
const module = comp.bin_file.options.module orelse
1952+
fatal("-femit-zir with no zig source code", .{});
1953+
var new_zir_module = try zir.emit(gpa, module);
1954+
defer new_zir_module.deinit(gpa);
1955+
1956+
const baf = try io.BufferedAtomicFile.create(gpa, fs.cwd(), zop, .{});
1957+
defer baf.destroy();
1958+
1959+
try new_zir_module.writeToStream(gpa, baf.stream());
1960+
1961+
try baf.finish();
1962+
}
1963+
19501964
var errors = try comp.getAllErrorsAlloc();
19511965
defer errors.deinit(comp.gpa);
19521966

@@ -1966,19 +1980,7 @@ fn updateModule(gpa: *Allocator, comp: *Compilation, zir_out_path: ?[]const u8,
19661980
),
19671981
}
19681982

1969-
if (zir_out_path) |zop| {
1970-
const module = comp.bin_file.options.module orelse
1971-
fatal("-femit-zir with no zig source code", .{});
1972-
var new_zir_module = try zir.emit(gpa, module);
1973-
defer new_zir_module.deinit(gpa);
19741983

1975-
const baf = try io.BufferedAtomicFile.create(gpa, fs.cwd(), zop, .{});
1976-
defer baf.destroy();
1977-
1978-
try new_zir_module.writeToStream(gpa, baf.stream());
1979-
1980-
try baf.finish();
1981-
}
19821984
}
19831985

19841986
fn cmdTranslateC(comp: *Compilation, arena: *Allocator, enable_cache: bool) !void {

0 commit comments

Comments
 (0)