Skip to content

Commit 28c3d48

Browse files
committedJul 14, 2018
rename Module to Compilation
and CompilationUnit to ObjectFile
·
0.15.10.3.0
1 parent 69e50ad commit 28c3d48

File tree

9 files changed

+387
-389
lines changed

9 files changed

+387
-389
lines changed
 

‎src-self-hosted/codegen.zig‎

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
const std = @import("std");
2-
// TODO codegen pretends that Module is renamed to Build because I plan to
3-
// do that refactor at some point
4-
const Build = @import("module.zig").Module;
2+
const Compilation = @import("compilation.zig").Compilation;
53
// we go through llvm instead of c for 2 reasons:
64
// 1. to avoid accidentally calling the non-thread-safe functions
75
// 2. patch up some of the types to remove nullability
@@ -11,51 +9,51 @@ const Value = @import("value.zig").Value;
119
const Type = @import("type.zig").Type;
1210
const event = std.event;
1311

14-
pub async fn renderToLlvm(build: *Build, fn_val: *Value.Fn, code: *ir.Code) !void {
12+
pub async fn renderToLlvm(comp: *Compilation, fn_val: *Value.Fn, code: *ir.Code) !void {
1513
fn_val.base.ref();
16-
defer fn_val.base.deref(build);
17-
defer code.destroy(build.a());
14+
defer fn_val.base.deref(comp);
15+
defer code.destroy(comp.a());
1816

19-
const llvm_handle = try build.event_loop_local.getAnyLlvmContext();
20-
defer llvm_handle.release(build.event_loop_local);
17+
const llvm_handle = try comp.event_loop_local.getAnyLlvmContext();
18+
defer llvm_handle.release(comp.event_loop_local);
2119

2220
const context = llvm_handle.node.data;
2321

24-
const module = llvm.ModuleCreateWithNameInContext(build.name.ptr(), context) orelse return error.OutOfMemory;
22+
const module = llvm.ModuleCreateWithNameInContext(comp.name.ptr(), context) orelse return error.OutOfMemory;
2523
defer llvm.DisposeModule(module);
2624

2725
const builder = llvm.CreateBuilderInContext(context) orelse return error.OutOfMemory;
2826
defer llvm.DisposeBuilder(builder);
2927

30-
var cunit = CompilationUnit{
31-
.build = build,
28+
var ofile = ObjectFile{
29+
.comp = comp,
3230
.module = module,
3331
.builder = builder,
3432
.context = context,
35-
.lock = event.Lock.init(build.loop),
33+
.lock = event.Lock.init(comp.loop),
3634
};
3735

38-
try renderToLlvmModule(&cunit, fn_val, code);
36+
try renderToLlvmModule(&ofile, fn_val, code);
3937

40-
if (build.verbose_llvm_ir) {
41-
llvm.DumpModule(cunit.module);
38+
if (comp.verbose_llvm_ir) {
39+
llvm.DumpModule(ofile.module);
4240
}
4341
}
4442

45-
pub const CompilationUnit = struct {
46-
build: *Build,
43+
pub const ObjectFile = struct {
44+
comp: *Compilation,
4745
module: llvm.ModuleRef,
4846
builder: llvm.BuilderRef,
4947
context: llvm.ContextRef,
5048
lock: event.Lock,
5149

52-
fn a(self: *CompilationUnit) *std.mem.Allocator {
53-
return self.build.a();
50+
fn a(self: *ObjectFile) *std.mem.Allocator {
51+
return self.comp.a();
5452
}
5553
};
5654

57-
pub fn renderToLlvmModule(cunit: *CompilationUnit, fn_val: *Value.Fn, code: *ir.Code) !void {
55+
pub fn renderToLlvmModule(ofile: *ObjectFile, fn_val: *Value.Fn, code: *ir.Code) !void {
5856
// TODO audit more of codegen.cpp:fn_llvm_value and port more logic
59-
const llvm_fn_type = try fn_val.base.typeof.getLlvmType(cunit);
60-
const llvm_fn = llvm.AddFunction(cunit.module, fn_val.symbol_name.ptr(), llvm_fn_type);
57+
const llvm_fn_type = try fn_val.base.typeof.getLlvmType(ofile);
58+
const llvm_fn = llvm.AddFunction(ofile.module, fn_val.symbol_name.ptr(), llvm_fn_type);
6159
}

0 commit comments

Comments
 (0)
Please sign in to comment.