This commit is contained in:
agra
2026-02-11 21:22:03 +02:00
parent 9d96f05d3b
commit 9a2501f662
5 changed files with 449 additions and 56 deletions

View File

@@ -7,12 +7,15 @@ const codegen = @import("codegen.zig");
const errors = @import("errors.zig");
const Node = ast.Node;
pub const TargetConfig = codegen.TargetConfig;
pub const Compilation = struct {
allocator: std.mem.Allocator,
io: std.Io,
file_path: []const u8,
source: [:0]const u8,
diagnostics: errors.DiagnosticList,
target_config: TargetConfig,
// Pipeline results
root: ?*Node = null,
@@ -21,7 +24,7 @@ pub const Compilation = struct {
sema_result: ?sema.SemaResult = null,
cg: ?codegen.CodeGen = null,
pub fn init(allocator: std.mem.Allocator, io: std.Io, file_path: []const u8, source: [:0]const u8) Compilation {
pub fn init(allocator: std.mem.Allocator, io: std.Io, file_path: []const u8, source: [:0]const u8, target_config: TargetConfig) Compilation {
return .{
.allocator = allocator,
.io = io,
@@ -29,6 +32,7 @@ pub const Compilation = struct {
.source = source,
.diagnostics = errors.DiagnosticList.init(allocator, source, file_path),
.import_sources = std.StringHashMap([:0]const u8).init(allocator),
.target_config = target_config,
};
}
@@ -83,7 +87,7 @@ pub const Compilation = struct {
pub fn generateCode(self: *Compilation) !void {
const root = self.resolved_root orelse self.root orelse return error.CompileError;
var cg = codegen.CodeGen.init(self.allocator, "sx_module");
var cg = codegen.CodeGen.init(self.allocator, "sx_module", self.target_config);
cg.diagnostics = &self.diagnostics;
if (self.sema_result) |*sr| {
cg.sema_result = sr;