Commit 6b8d28312c

Timon Kruiper <timonkruiper@gmail.com>
2020-12-21 10:21:30
stage2: fix building self-hosted without llvm-backend enabled.
1 parent b059bb8
Changed files (2)
src/link/Coff.zig
@@ -125,7 +125,7 @@ pub const SrcFn = void;
 pub fn openPath(allocator: *Allocator, sub_path: []const u8, options: link.Options) !*Coff {
     assert(options.object_format == .coff);
 
-    if (options.use_llvm) {
+    if (build_options.have_llvm and options.use_llvm) {
         const self = try createEmpty(allocator, options);
         errdefer self.base.destroy();
 
@@ -657,10 +657,8 @@ pub fn updateDecl(self: *Coff, module: *Module, decl: *Module.Decl) !void {
     const tracy = trace(@src());
     defer tracy.end();
 
-    if (self.llvm_ir_module) |llvm_ir_module| {
-        try llvm_ir_module.updateDecl(module, decl);
-        return;
-    }
+    if (build_options.have_llvm)
+        if (self.llvm_ir_module) |llvm_ir_module| return try llvm_ir_module.updateDecl(module, decl);
 
     var code_buffer = std.ArrayList(u8).init(self.base.allocator);
     defer code_buffer.deinit();
@@ -760,10 +758,8 @@ pub fn flushModule(self: *Coff, comp: *Compilation) !void {
     const tracy = trace(@src());
     defer tracy.end();
 
-    if (self.llvm_ir_module) |llvm_ir_module| {
-        try llvm_ir_module.flushModule(comp);
-        return;
-    }
+    if (build_options.have_llvm)
+        if (self.llvm_ir_module) |llvm_ir_module| return try llvm_ir_module.flushModule(comp);
 
     if (self.text_section_size_dirty) {
         // Write the new raw size in the .text header
@@ -1257,7 +1253,9 @@ pub fn updateDeclLineNumber(self: *Coff, module: *Module, decl: *Module.Decl) !v
 }
 
 pub fn deinit(self: *Coff) void {
-    if (self.llvm_ir_module) |ir_module| ir_module.deinit(self.base.allocator);
+    if (build_options.have_llvm)
+        if (self.llvm_ir_module) |ir_module| ir_module.deinit(self.base.allocator);
+
     self.text_block_free_list.deinit(self.base.allocator);
     self.offset_table.deinit(self.base.allocator);
     self.offset_table_free_list.deinit(self.base.allocator);
src/link/Elf.zig
@@ -228,7 +228,7 @@ pub const SrcFn = struct {
 pub fn openPath(allocator: *Allocator, sub_path: []const u8, options: link.Options) !*Elf {
     assert(options.object_format == .elf);
 
-    if (options.use_llvm) {
+    if (build_options.have_llvm and options.use_llvm) {
         const self = try createEmpty(allocator, options);
         errdefer self.base.destroy();
 
@@ -298,7 +298,10 @@ pub fn createEmpty(gpa: *Allocator, options: link.Options) !*Elf {
 }
 
 pub fn deinit(self: *Elf) void {
-    if (self.llvm_ir_module) |ir_module| ir_module.deinit(self.base.allocator);
+    if (build_options.have_llvm)
+        if (self.llvm_ir_module) |ir_module|
+            ir_module.deinit(self.base.allocator);
+
     self.sections.deinit(self.base.allocator);
     self.program_headers.deinit(self.base.allocator);
     self.shstrtab.deinit(self.base.allocator);
@@ -740,10 +743,8 @@ pub fn flushModule(self: *Elf, comp: *Compilation) !void {
     const tracy = trace(@src());
     defer tracy.end();
 
-    if (self.llvm_ir_module) |llvm_ir_module| {
-        try llvm_ir_module.flushModule(comp);
-        return;
-    }
+    if (build_options.have_llvm)
+        if (self.llvm_ir_module) |llvm_ir_module| return try llvm_ir_module.flushModule(comp);
 
     // TODO This linker code currently assumes there is only 1 compilation unit and it corresponds to the
     // Zig source code.
@@ -2149,10 +2150,8 @@ pub fn updateDecl(self: *Elf, module: *Module, decl: *Module.Decl) !void {
     const tracy = trace(@src());
     defer tracy.end();
 
-    if (self.llvm_ir_module) |llvm_ir_module| {
-        try llvm_ir_module.updateDecl(module, decl);
-        return;
-    }
+    if (build_options.have_llvm)
+        if (self.llvm_ir_module) |llvm_ir_module| return try llvm_ir_module.updateDecl(module, decl);
 
     var code_buffer = std.ArrayList(u8).init(self.base.allocator);
     defer code_buffer.deinit();