cleanup
This commit is contained in:
22
src/main.zig
22
src/main.zig
@@ -115,11 +115,11 @@ fn readSource(allocator: std.mem.Allocator, io: std.Io, input_path: []const u8)
|
||||
return try allocator.dupeZ(u8, source_bytes);
|
||||
}
|
||||
|
||||
fn emitIR(allocator: std.mem.Allocator, io: std.Io, input_path: []const u8) !void {
|
||||
fn compilePipeline(allocator: std.mem.Allocator, io: std.Io, input_path: []const u8) !sx.core.Compilation {
|
||||
const source = try readSource(allocator, io, input_path);
|
||||
|
||||
var comp = sx.core.Compilation.init(allocator, io, input_path, source);
|
||||
defer comp.deinit();
|
||||
errdefer comp.deinit();
|
||||
|
||||
comp.parse() catch { comp.renderErrors(); return error.CompileError; };
|
||||
comp.resolveImports() catch { comp.renderErrors(); return error.CompileError; };
|
||||
@@ -127,21 +127,21 @@ fn emitIR(allocator: std.mem.Allocator, io: std.Io, input_path: []const u8) !voi
|
||||
|
||||
var cg = &comp.cg.?;
|
||||
cg.verify() catch { comp.renderErrors(); return error.CompileError; };
|
||||
cg.printIR();
|
||||
|
||||
return comp;
|
||||
}
|
||||
|
||||
fn emitIR(allocator: std.mem.Allocator, io: std.Io, input_path: []const u8) !void {
|
||||
var comp = try compilePipeline(allocator, io, input_path);
|
||||
defer comp.deinit();
|
||||
comp.cg.?.printIR();
|
||||
}
|
||||
|
||||
fn compile(allocator: std.mem.Allocator, io: std.Io, input_path: []const u8, output_path: []const u8) !void {
|
||||
const source = try readSource(allocator, io, input_path);
|
||||
|
||||
var comp = sx.core.Compilation.init(allocator, io, input_path, source);
|
||||
var comp = try compilePipeline(allocator, io, input_path);
|
||||
defer comp.deinit();
|
||||
|
||||
comp.parse() catch { comp.renderErrors(); return error.CompileError; };
|
||||
comp.resolveImports() catch { comp.renderErrors(); return error.CompileError; };
|
||||
comp.generateCode() catch { comp.renderErrors(); return error.CompileError; };
|
||||
|
||||
var cg = &comp.cg.?;
|
||||
cg.verify() catch { comp.renderErrors(); return error.CompileError; };
|
||||
|
||||
// Emit object file
|
||||
const obj_path = try std.fmt.allocPrintSentinel(allocator, "{s}.o", .{output_path}, 0);
|
||||
|
||||
Reference in New Issue
Block a user