1
1
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 ;
5
3
// we go through llvm instead of c for 2 reasons:
6
4
// 1. to avoid accidentally calling the non-thread-safe functions
7
5
// 2. patch up some of the types to remove nullability
@@ -11,51 +9,51 @@ const Value = @import("value.zig").Value;
11
9
const Type = @import ("type.zig" ).Type ;
12
10
const event = std .event ;
13
11
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 {
15
13
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 ());
18
16
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 );
21
19
22
20
const context = llvm_handle .node .data ;
23
21
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 ;
25
23
defer llvm .DisposeModule (module );
26
24
27
25
const builder = llvm .CreateBuilderInContext (context ) orelse return error .OutOfMemory ;
28
26
defer llvm .DisposeBuilder (builder );
29
27
30
- var cunit = CompilationUnit {
31
- .build = build ,
28
+ var ofile = ObjectFile {
29
+ .comp = comp ,
32
30
.module = module ,
33
31
.builder = builder ,
34
32
.context = context ,
35
- .lock = event .Lock .init (build .loop ),
33
+ .lock = event .Lock .init (comp .loop ),
36
34
};
37
35
38
- try renderToLlvmModule (& cunit , fn_val , code );
36
+ try renderToLlvmModule (& ofile , fn_val , code );
39
37
40
- if (build .verbose_llvm_ir ) {
41
- llvm .DumpModule (cunit .module );
38
+ if (comp .verbose_llvm_ir ) {
39
+ llvm .DumpModule (ofile .module );
42
40
}
43
41
}
44
42
45
- pub const CompilationUnit = struct {
46
- build : * Build ,
43
+ pub const ObjectFile = struct {
44
+ comp : * Compilation ,
47
45
module : llvm.ModuleRef ,
48
46
builder : llvm.BuilderRef ,
49
47
context : llvm.ContextRef ,
50
48
lock : event.Lock ,
51
49
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 ();
54
52
}
55
53
};
56
54
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 {
58
56
// 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 );
61
59
}
0 commit comments