| author | |
| committer | |
| log | 2c882b2e651386399fd48c24302fd2d4ba430ef3 |
| tree | b8d3299504b4dd3dceae45a912f720e1d5461831 |
| parent | dff1ac1089dd8a7cae5c167bdb4e6269c9b84bb6 |
| signature |
5 files changed, 14 insertions(+), 11 deletions(-)
lib/std/target.zig+1| ... | @@ -435,6 +435,7 @@ pub const Target = struct { | ... | @@ -435,6 +435,7 @@ pub const Target = struct { |
| 435 | elf, | 435 | elf, |
| 436 | macho, | 436 | macho, |
| 437 | wasm, | 437 | wasm, |
| 438 | c, | ||
| 438 | }; | 439 | }; |
| 439 | 440 | ||
| 440 | pub const SubSystem = enum { | 441 | pub const SubSystem = enum { |
src-self-hosted/Module.zig-2| ... | @@ -723,7 +723,6 @@ pub const InitOptions = struct { | ... | @@ -723,7 +723,6 @@ pub const InitOptions = struct { |
| 723 | object_format: ?std.builtin.ObjectFormat = null, | 723 | object_format: ?std.builtin.ObjectFormat = null, |
| 724 | optimize_mode: std.builtin.Mode = .Debug, | 724 | optimize_mode: std.builtin.Mode = .Debug, |
| 725 | keep_source_files_loaded: bool = false, | 725 | keep_source_files_loaded: bool = false, |
| 726 | cbe: bool = false, | ||
| 727 | }; | 726 | }; |
| 728 | 727 | ||
| 729 | pub fn init(gpa: *Allocator, options: InitOptions) !Module { | 728 | pub fn init(gpa: *Allocator, options: InitOptions) !Module { |
| ... | @@ -733,7 +732,6 @@ pub fn init(gpa: *Allocator, options: InitOptions) !Module { | ... | @@ -733,7 +732,6 @@ pub fn init(gpa: *Allocator, options: InitOptions) !Module { |
| 733 | .output_mode = options.output_mode, | 732 | .output_mode = options.output_mode, |
| 734 | .link_mode = options.link_mode orelse .Static, | 733 | .link_mode = options.link_mode orelse .Static, |
| 735 | .object_format = options.object_format orelse options.target.getObjectFormat(), | 734 | .object_format = options.object_format orelse options.target.getObjectFormat(), |
| 736 | .cbe = options.cbe, | ||
| 737 | }); | 735 | }); |
| 738 | errdefer bin_file.destroy(); | 736 | errdefer bin_file.destroy(); |
| 739 | 737 |
src-self-hosted/link.zig+5-3| ... | @@ -22,7 +22,6 @@ pub const Options = struct { | ... | @@ -22,7 +22,6 @@ pub const Options = struct { |
| 22 | /// Used for calculating how much space to reserve for executable program code in case | 22 | /// Used for calculating how much space to reserve for executable program code in case |
| 23 | /// the binary file deos not already have such a section. | 23 | /// the binary file deos not already have such a section. |
| 24 | program_code_size_hint: u64 = 256 * 1024, | 24 | program_code_size_hint: u64 = 256 * 1024, |
| 25 | cbe: bool = false, | ||
| 26 | }; | 25 | }; |
| 27 | 26 | ||
| 28 | /// Attempts incremental linking, if the file already exists. | 27 | /// Attempts incremental linking, if the file already exists. |
| ... | @@ -35,10 +34,11 @@ pub fn openBinFilePath( | ... | @@ -35,10 +34,11 @@ pub fn openBinFilePath( |
| 35 | sub_path: []const u8, | 34 | sub_path: []const u8, |
| 36 | options: Options, | 35 | options: Options, |
| 37 | ) !*File { | 36 | ) !*File { |
| 38 | const file = try dir.createFile(sub_path, .{ .truncate = options.cbe, .read = true, .mode = determineMode(options) }); | 37 | const cbe = options.object_format == .c; |
| 38 | const file = try dir.createFile(sub_path, .{ .truncate = cbe, .read = true, .mode = determineMode(options) }); | ||
| 39 | errdefer file.close(); | 39 | errdefer file.close(); |
| 40 | 40 | ||
| 41 | if (options.cbe) { | 41 | if (cbe) { |
| 42 | var bin_file = try allocator.create(File.C); | 42 | var bin_file = try allocator.create(File.C); |
| 43 | errdefer allocator.destroy(bin_file); | 43 | errdefer allocator.destroy(bin_file); |
| 44 | bin_file.* = try openCFile(allocator, file, options); | 44 | bin_file.* = try openCFile(allocator, file, options); |
| ... | @@ -1573,6 +1573,7 @@ pub fn createElfFile(allocator: *Allocator, file: fs.File, options: Options) !Fi | ... | @@ -1573,6 +1573,7 @@ pub fn createElfFile(allocator: *Allocator, file: fs.File, options: Options) !Fi |
| 1573 | .Lib => return error.TODOImplementWritingLibFiles, | 1573 | .Lib => return error.TODOImplementWritingLibFiles, |
| 1574 | } | 1574 | } |
| 1575 | switch (options.object_format) { | 1575 | switch (options.object_format) { |
| 1576 | .c => unreachable, | ||
| 1576 | .unknown => unreachable, // TODO remove this tag from the enum | 1577 | .unknown => unreachable, // TODO remove this tag from the enum |
| 1577 | .coff => return error.TODOImplementWritingCOFF, | 1578 | .coff => return error.TODOImplementWritingCOFF, |
| 1578 | .elf => {}, | 1579 | .elf => {}, |
| ... | @@ -1632,6 +1633,7 @@ fn openBinFileInner(allocator: *Allocator, file: fs.File, options: Options) !Fil | ... | @@ -1632,6 +1633,7 @@ fn openBinFileInner(allocator: *Allocator, file: fs.File, options: Options) !Fil |
| 1632 | } | 1633 | } |
| 1633 | switch (options.object_format) { | 1634 | switch (options.object_format) { |
| 1634 | .unknown => unreachable, // TODO remove this tag from the enum | 1635 | .unknown => unreachable, // TODO remove this tag from the enum |
| 1636 | .c => unreachable, | ||
| 1635 | .coff => return error.IncrFailed, | 1637 | .coff => return error.IncrFailed, |
| 1636 | .elf => {}, | 1638 | .elf => {}, |
| 1637 | .macho => return error.IncrFailed, | 1639 | .macho => return error.IncrFailed, |
src-self-hosted/main.zig+7-5| ... | @@ -194,8 +194,8 @@ fn buildOutputType( | ... | @@ -194,8 +194,8 @@ fn buildOutputType( |
| 194 | var emit_zir: Emit = .no; | 194 | var emit_zir: Emit = .no; |
| 195 | var target_arch_os_abi: []const u8 = "native"; | 195 | var target_arch_os_abi: []const u8 = "native"; |
| 196 | var target_mcpu: ?[]const u8 = null; | 196 | var target_mcpu: ?[]const u8 = null; |
| 197 | var cbe: bool = false; | ||
| 198 | var target_dynamic_linker: ?[]const u8 = null; | 197 | var target_dynamic_linker: ?[]const u8 = null; |
| 198 | var object_format: ?std.builtin.ObjectFormat = null; | ||
| 199 | 199 | ||
| 200 | var system_libs = std.ArrayList([]const u8).init(gpa); | 200 | var system_libs = std.ArrayList([]const u8).init(gpa); |
| 201 | defer system_libs.deinit(); | 201 | defer system_libs.deinit(); |
| ... | @@ -283,7 +283,11 @@ fn buildOutputType( | ... | @@ -283,7 +283,11 @@ fn buildOutputType( |
| 283 | i += 1; | 283 | i += 1; |
| 284 | target_mcpu = args[i]; | 284 | target_mcpu = args[i]; |
| 285 | } else if (mem.eql(u8, arg, "--c")) { | 285 | } else if (mem.eql(u8, arg, "--c")) { |
| 286 | cbe = true; | 286 | if (object_format) |old| { |
| 287 | std.debug.print("attempted to override object format {} with C\n", .{old}); | ||
| 288 | process.exit(1); | ||
| 289 | } | ||
| 290 | object_format = .c; | ||
| 287 | } else if (mem.startsWith(u8, arg, "-mcpu=")) { | 291 | } else if (mem.startsWith(u8, arg, "-mcpu=")) { |
| 288 | target_mcpu = arg["-mcpu=".len..]; | 292 | target_mcpu = arg["-mcpu=".len..]; |
| 289 | } else if (mem.eql(u8, arg, "--dynamic-linker")) { | 293 | } else if (mem.eql(u8, arg, "--dynamic-linker")) { |
| ... | @@ -417,7 +421,6 @@ fn buildOutputType( | ... | @@ -417,7 +421,6 @@ fn buildOutputType( |
| 417 | else => |e| return e, | 421 | else => |e| return e, |
| 418 | }; | 422 | }; |
| 419 | 423 | ||
| 420 | const object_format: ?std.builtin.ObjectFormat = null; | ||
| 421 | var target_info = try std.zig.system.NativeTargetInfo.detect(gpa, cross_target); | 424 | var target_info = try std.zig.system.NativeTargetInfo.detect(gpa, cross_target); |
| 422 | if (target_info.cpu_detection_unimplemented) { | 425 | if (target_info.cpu_detection_unimplemented) { |
| 423 | // TODO We want to just use detected_info.target but implementing | 426 | // TODO We want to just use detected_info.target but implementing |
| ... | @@ -436,7 +439,7 @@ fn buildOutputType( | ... | @@ -436,7 +439,7 @@ fn buildOutputType( |
| 436 | std.debug.print("-fno-emit-bin not supported yet", .{}); | 439 | std.debug.print("-fno-emit-bin not supported yet", .{}); |
| 437 | process.exit(1); | 440 | process.exit(1); |
| 438 | }, | 441 | }, |
| 439 | .yes_default_path => if (cbe) | 442 | .yes_default_path => if (object_format != null and object_format.? == .c) |
| 440 | try std.fmt.allocPrint(arena, "{}.c", .{root_name}) | 443 | try std.fmt.allocPrint(arena, "{}.c", .{root_name}) |
| 441 | else | 444 | else |
| 442 | try std.zig.binNameAlloc(arena, root_name, target_info.target, output_mode, link_mode), | 445 | try std.zig.binNameAlloc(arena, root_name, target_info.target, output_mode, link_mode), |
| ... | @@ -470,7 +473,6 @@ fn buildOutputType( | ... | @@ -470,7 +473,6 @@ fn buildOutputType( |
| 470 | .object_format = object_format, | 473 | .object_format = object_format, |
| 471 | .optimize_mode = build_mode, | 474 | .optimize_mode = build_mode, |
| 472 | .keep_source_files_loaded = zir_out_path != null, | 475 | .keep_source_files_loaded = zir_out_path != null, |
| 473 | .cbe = cbe, | ||
| 474 | }); | 476 | }); |
| 475 | defer module.deinit(); | 477 | defer module.deinit(); |
| 476 | 478 |
src-self-hosted/test.zig+1-1| ... | @@ -444,7 +444,7 @@ pub const TestContext = struct { | ... | @@ -444,7 +444,7 @@ pub const TestContext = struct { |
| 444 | .bin_file_path = bin_name, | 444 | .bin_file_path = bin_name, |
| 445 | .root_pkg = root_pkg, | 445 | .root_pkg = root_pkg, |
| 446 | .keep_source_files_loaded = true, | 446 | .keep_source_files_loaded = true, |
| 447 | .cbe = case.cbe, | 447 | .object_format = if (case.cbe) .c else null, |
| 448 | }); | 448 | }); |
| 449 | defer module.deinit(); | 449 | defer module.deinit(); |
| 450 | 450 |