| ... | @@ -117,10 +117,7 @@ const WorkItem = union(enum) { | ... | @@ -117,10 +117,7 @@ const WorkItem = union(enum) { |
| 117 | | 117 | |
| 118 | pub const CObject = struct { | 118 | pub const CObject = struct { |
| 119 | /// Relative to cwd. Owned by arena. | 119 | /// Relative to cwd. Owned by arena. |
| 120 | src_path: []const u8, | 120 | src: CSourceFile, |
| 121 | /// Owned by arena. | | |
| 122 | extra_flags: []const []const u8, | | |
| 123 | arena: std.heap.ArenaAllocator.State, | | |
| 124 | status: union(enum) { | 121 | status: union(enum) { |
| 125 | new, | 122 | new, |
| 126 | success: struct { | 123 | success: struct { |
| ... | @@ -154,7 +151,7 @@ pub const CObject = struct { | ... | @@ -154,7 +151,7 @@ pub const CObject = struct { |
| 154 | | 151 | |
| 155 | pub fn destroy(self: *CObject, gpa: *Allocator) void { | 152 | pub fn destroy(self: *CObject, gpa: *Allocator) void { |
| 156 | _ = self.clearStatus(gpa); | 153 | _ = self.clearStatus(gpa); |
| 157 | self.arena.promote(gpa).deinit(); | 154 | gpa.destroy(self); |
| 158 | } | 155 | } |
| 159 | }; | 156 | }; |
| 160 | | 157 | |
| ... | @@ -627,17 +624,12 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { | ... | @@ -627,17 +624,12 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { |
| 627 | // Add a `CObject` for each `c_source_files`. | 624 | // Add a `CObject` for each `c_source_files`. |
| 628 | try comp.c_object_table.ensureCapacity(gpa, options.c_source_files.len); | 625 | try comp.c_object_table.ensureCapacity(gpa, options.c_source_files.len); |
| 629 | for (options.c_source_files) |c_source_file| { | 626 | for (options.c_source_files) |c_source_file| { |
| 630 | var local_arena = std.heap.ArenaAllocator.init(gpa); | 627 | const c_object = try gpa.create(CObject); |
| 631 | errdefer local_arena.deinit(); | 628 | errdefer gpa.destroy(c_object); |
| 632 | | | |
| 633 | const c_object = try local_arena.allocator.create(CObject); | | |
| 634 | | 629 | |
| 635 | c_object.* = .{ | 630 | c_object.* = .{ |
| 636 | .status = .{ .new = {} }, | 631 | .status = .{ .new = {} }, |
| 637 | // TODO look into refactoring to turn these 2 fields simply into a CSourceFile | 632 | .src = c_source_file, |
| 638 | .src_path = try local_arena.allocator.dupe(u8, c_source_file.src_path), | | |
| 639 | .extra_flags = try local_arena.allocator.dupe([]const u8, c_source_file.extra_flags), | | |
| 640 | .arena = local_arena.state, | | |
| 641 | }; | 633 | }; |
| 642 | comp.c_object_table.putAssumeCapacityNoClobber(c_object, {}); | 634 | comp.c_object_table.putAssumeCapacityNoClobber(c_object, {}); |
| 643 | } | 635 | } |
| ... | @@ -798,7 +790,7 @@ pub fn getAllErrorsAlloc(self: *Compilation) !AllErrors { | ... | @@ -798,7 +790,7 @@ pub fn getAllErrorsAlloc(self: *Compilation) !AllErrors { |
| 798 | for (self.failed_c_objects.items()) |entry| { | 790 | for (self.failed_c_objects.items()) |entry| { |
| 799 | const c_object = entry.key; | 791 | const c_object = entry.key; |
| 800 | const err_msg = entry.value; | 792 | const err_msg = entry.value; |
| 801 | try AllErrors.add(&arena, &errors, c_object.src_path, "", err_msg.*); | 793 | try AllErrors.add(&arena, &errors, c_object.src.src_path, "", err_msg.*); |
| 802 | } | 794 | } |
| 803 | if (self.bin_file.options.module) |module| { | 795 | if (self.bin_file.options.module) |module| { |
| 804 | for (module.failed_files.items()) |entry| { | 796 | for (module.failed_files.items()) |entry| { |
| ... | @@ -981,13 +973,13 @@ fn updateCObject(comp: *Compilation, c_object: *CObject) !void { | ... | @@ -981,13 +973,13 @@ fn updateCObject(comp: *Compilation, c_object: *CObject) !void { |
| 981 | // TODO this logic can likely be improved by utilizing clang_options_data.zig. | 973 | // TODO this logic can likely be improved by utilizing clang_options_data.zig. |
| 982 | const file_args = [_][]const u8{"-include"}; | 974 | const file_args = [_][]const u8{"-include"}; |
| 983 | var arg_i: usize = 0; | 975 | var arg_i: usize = 0; |
| 984 | while (arg_i < c_object.extra_flags.len) : (arg_i += 1) { | 976 | while (arg_i < c_object.src.extra_flags.len) : (arg_i += 1) { |
| 985 | const arg = c_object.extra_flags[arg_i]; | 977 | const arg = c_object.src.extra_flags[arg_i]; |
| 986 | ch.hash.addBytes(arg); | 978 | ch.hash.addBytes(arg); |
| 987 | for (file_args) |file_arg| { | 979 | for (file_args) |file_arg| { |
| 988 | if (mem.eql(u8, file_arg, arg) and arg_i + 1 < c_object.extra_flags.len) { | 980 | if (mem.eql(u8, file_arg, arg) and arg_i + 1 < c_object.src.extra_flags.len) { |
| 989 | arg_i += 1; | 981 | arg_i += 1; |
| 990 | _ = try ch.addFile(c_object.extra_flags[arg_i], null); | 982 | _ = try ch.addFile(c_object.src.extra_flags[arg_i], null); |
| 991 | } | 983 | } |
| 992 | } | 984 | } |
| 993 | } | 985 | } |
| ... | @@ -1028,7 +1020,7 @@ fn updateCObject(comp: *Compilation, c_object: *CObject) !void { | ... | @@ -1028,7 +1020,7 @@ fn updateCObject(comp: *Compilation, c_object: *CObject) !void { |
| 1028 | try argv.append(out_obj_path); | 1020 | try argv.append(out_obj_path); |
| 1029 | | 1021 | |
| 1030 | try argv.append(c_object.src_path); | 1022 | try argv.append(c_object.src_path); |
| 1031 | try argv.appendSlice(c_object.extra_flags); | 1023 | try argv.appendSlice(c_object.src.extra_flags); |
| 1032 | | 1024 | |
| 1033 | if (comp.debug_cc) { | 1025 | if (comp.debug_cc) { |
| 1034 | for (argv.items[0 .. argv.items.len - 1]) |arg| { | 1026 | for (argv.items[0 .. argv.items.len - 1]) |arg| { |