authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2025-07-28 14:37:57+03:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-09-24 20:01:18-07:00
loge7a622fb3331987c2b2128fb2657a5dea1b8aa33
tree2cf7543818aaaf64bf969fddac93416580d26808
parente8e8d7e5c8eee5fe29add5aac0c07bf08a2debad

update aro and translate-c sources


24 files changed, 1577 insertions(+), 141 deletions(-)

build.zig-1
...@@ -1144,7 +1144,6 @@ fn toNativePathSep(b: *std.Build, s: []const u8) []u8 {...@@ -1144,7 +1144,6 @@ fn toNativePathSep(b: *std.Build, s: []const u8) []u8 {
1144const zig_cpp_sources = [_][]const u8{1144const zig_cpp_sources = [_][]const u8{
1145 // These are planned to stay even when we are self-hosted.1145 // These are planned to stay even when we are self-hosted.
1146 "src/zig_llvm.cpp",1146 "src/zig_llvm.cpp",
1147 "src/zig_clang.cpp",
1148 "src/zig_llvm-ar.cpp",1147 "src/zig_llvm-ar.cpp",
1149 "src/zig_clang_driver.cpp",1148 "src/zig_clang_driver.cpp",
1150 "src/zig_clang_cc1_main.cpp",1149 "src/zig_clang_cc1_main.cpp",
lib/compiler/aro/aro/Compilation.zig+329-28
...@@ -10,6 +10,7 @@ const CodeGenOptions = @import("../backend.zig").CodeGenOptions;...@@ -10,6 +10,7 @@ const CodeGenOptions = @import("../backend.zig").CodeGenOptions;
10const Builtins = @import("Builtins.zig");10const Builtins = @import("Builtins.zig");
11const Builtin = Builtins.Builtin;11const Builtin = Builtins.Builtin;
12const Diagnostics = @import("Diagnostics.zig");12const Diagnostics = @import("Diagnostics.zig");
13const DepFile = @import("DepFile.zig");
13const LangOpts = @import("LangOpts.zig");14const LangOpts = @import("LangOpts.zig");
14const Pragma = @import("Pragma.zig");15const Pragma = @import("Pragma.zig");
15const record_layout = @import("record_layout.zig");16const record_layout = @import("record_layout.zig");
...@@ -140,6 +141,7 @@ system_framework_dirs: std.ArrayListUnmanaged([]const u8) = .empty,...@@ -140,6 +141,7 @@ system_framework_dirs: std.ArrayListUnmanaged([]const u8) = .empty,
140/// Allocated into `gpa`, but keys are externally managed.141/// Allocated into `gpa`, but keys are externally managed.
141embed_dirs: std.ArrayListUnmanaged([]const u8) = .empty,142embed_dirs: std.ArrayListUnmanaged([]const u8) = .empty,
142target: std.Target = @import("builtin").target,143target: std.Target = @import("builtin").target,
144cmodel: std.builtin.CodeModel = .default,
143pragma_handlers: std.StringArrayHashMapUnmanaged(*Pragma) = .{},145pragma_handlers: std.StringArrayHashMapUnmanaged(*Pragma) = .{},
144langopts: LangOpts = .{},146langopts: LangOpts = .{},
145generated_buf: std.ArrayListUnmanaged(u8) = .{},147generated_buf: std.ArrayListUnmanaged(u8) = .{},
...@@ -349,30 +351,206 @@ fn generateSystemDefines(comp: *Compilation, w: *std.Io.Writer) !void {...@@ -349,30 +351,206 @@ fn generateSystemDefines(comp: *Compilation, w: *std.Io.Writer) !void {
349351
350 // architecture macros352 // architecture macros
351 switch (comp.target.cpu.arch) {353 switch (comp.target.cpu.arch) {
352 .x86_64 => {354 .x86, .x86_64 => {
353 try define(w, "__amd64__");355 try w.print("#define __code_model_{s}__ 1\n", .{switch (comp.cmodel) {
354 try define(w, "__amd64");356 .default => "small",
355 try define(w, "__x86_64__");357 else => @tagName(comp.cmodel),
356 try define(w, "__x86_64");358 }});
359
360 if (comp.target.cpu.arch == .x86_64) {
361 try define(w, "__amd64__");
362 try define(w, "__amd64");
363 try define(w, "__x86_64__");
364 try define(w, "__x86_64");
365
366 if (comp.target.os.tag == .windows and comp.target.abi == .msvc) {
367 try w.writeAll(
368 \\#define _M_X64 100
369 \\#define _M_AMD64 100
370 \\
371 );
372 }
373 } else {
374 try defineStd(w, "i386", is_gnu);
375
376 if (comp.target.os.tag == .windows and comp.target.abi == .msvc) {
377 try w.print("#define _M_IX86 {d}\n", .{blk: {
378 if (comp.target.cpu.model == &std.Target.x86.cpu.i386) break :blk 300;
379 if (comp.target.cpu.model == &std.Target.x86.cpu.i486) break :blk 400;
380 if (comp.target.cpu.model == &std.Target.x86.cpu.i586) break :blk 500;
381 break :blk @as(u32, 600);
382 }});
383 }
384 }
385 try define(w, "__SEG_GS");
386 try define(w, "__SEG_FS");
387 try w.writeAll(
388 \\#define __seg_gs __attribute__((address_space(256)))
389 \\#define __seg_fs __attribute__((address_space(257)))
390 \\
391 );
357392
358 if (comp.target.os.tag == .windows and comp.target.abi == .msvc) {393 if (comp.target.cpu.has(.x86, .sahf) or (comp.langopts.emulate == .clang and comp.target.cpu.arch == .x86)) {
359 try w.writeAll(394 try define(w, "__LAHF_SAHF__");
360 \\#define _M_X64 100
361 \\#define _M_AMD64 100
362 \\
363 );
364 }395 }
365 },
366 .x86 => {
367 try defineStd(w, "i386", is_gnu);
368396
369 if (comp.target.os.tag == .windows and comp.target.abi == .msvc) {397 const features = comp.target.cpu.features;
370 try w.print("#define _M_IX86 {d}\n", .{blk: {398 for ([_]struct { std.Target.x86.Feature, []const u8 }{
371 if (comp.target.cpu.model == &std.Target.x86.cpu.i386) break :blk 300;399 .{ .aes, "__AES__" },
372 if (comp.target.cpu.model == &std.Target.x86.cpu.i486) break :blk 400;400 .{ .vaes, "__VAES__" },
373 if (comp.target.cpu.model == &std.Target.x86.cpu.i586) break :blk 500;401 .{ .pclmul, "__PCLMUL__" },
374 break :blk @as(u32, 600);402 .{ .vpclmulqdq, "__VPCLMULQDQ__" },
375 }});403 .{ .lzcnt, "__LZCNT__" },
404 .{ .rdrnd, "__RDRND__" },
405 .{ .fsgsbase, "__FSGSBASE__" },
406 .{ .bmi, "__BMI__" },
407 .{ .bmi2, "__BMI2__" },
408 .{ .popcnt, "__POPCNT__" },
409 .{ .rtm, "__RTM__" },
410 .{ .prfchw, "__PRFCHW__" },
411 .{ .rdseed, "__RDSEED__" },
412 .{ .adx, "__ADX__" },
413 .{ .tbm, "__TBM__" },
414 .{ .lwp, "__LWP__" },
415 .{ .mwaitx, "__MWAITX__" },
416 .{ .movbe, "__MOVBE__" },
417
418 .{ .xop, "__XOP__" },
419 .{ .fma4, "__FMA4__" },
420 .{ .sse4a, "__SSE4A__" },
421
422 .{ .fma, "__FMA__" },
423 .{ .f16c, "__F16C__" },
424 .{ .gfni, "__GFNI__" },
425 .{ .evex512, "__EVEX512__" },
426 .{ .avx10_1_256, "__AVX10_1__" },
427 .{ .avx10_1_512, "__AVX10_1_512__" },
428 .{ .avx10_2_256, "__AVX10_2__" },
429 .{ .avx10_2_512, "__AVX10_2_512__" },
430 .{ .avx512cd, "__AVX512CD__" },
431 .{ .avx512vpopcntdq, "__AVX512VPOPCNTDQ__" },
432 .{ .avx512vnni, "__AVX512VNNI__" },
433 .{ .avx512bf16, "__AVX512BF16__" },
434 .{ .avx512fp16, "__AVX512FP16__" },
435 .{ .avx512dq, "__AVX512DQ__" },
436 .{ .avx512bitalg, "__AVX512BITALG__" },
437 .{ .avx512bw, "__AVX512BW__" },
438
439 .{ .avx512vl, "__AVX512VL__" },
440 .{ .avx512vl, "__EVEX256__" },
441
442 .{ .avx512vbmi, "__AVX512VBMI__" },
443 .{ .avx512vbmi2, "__AVX512VBMI2__" },
444 .{ .avx512ifma, "__AVX512IFMA__" },
445 .{ .avx512vp2intersect, "__AVX512VP2INTERSECT__" },
446 .{ .sha, "__SHA__" },
447 .{ .sha512, "__SHA512__" },
448 .{ .fxsr, "__FXSR__" },
449 .{ .xsave, "__XSAVE__" },
450 .{ .xsaveopt, "__XSAVEOPT__" },
451 .{ .xsavec, "__XSAVEC__" },
452 .{ .xsaves, "__XSAVES__" },
453 .{ .pku, "__PKU__" },
454 .{ .clflushopt, "__CLFLUSHOPT__" },
455 .{ .clwb, "__CLWB__" },
456 .{ .wbnoinvd, "__WBNOINVD__" },
457 .{ .shstk, "__SHSTK__" },
458 .{ .sgx, "__SGX__" },
459 .{ .sm3, "__SM3__" },
460 .{ .sm4, "__SM4__" },
461 .{ .prefetchi, "__PREFETCHI__" },
462 .{ .clzero, "__CLZERO__" },
463 .{ .kl, "__KL__" },
464 .{ .widekl, "__WIDEKL__" },
465 .{ .rdpid, "__RDPID__" },
466 .{ .rdpru, "__RDPRU__" },
467 .{ .cldemote, "__CLDEMOTE__" },
468 .{ .waitpkg, "__WAITPKG__" },
469 .{ .movdiri, "__MOVDIRI__" },
470 .{ .movdir64b, "__MOVDIR64B__" },
471 .{ .movrs, "__MOVRS__" },
472 .{ .pconfig, "__PCONFIG__" },
473 .{ .ptwrite, "__PTWRITE__" },
474 .{ .invpcid, "__INVPCID__" },
475 .{ .enqcmd, "__ENQCMD__" },
476 .{ .hreset, "__HRESET__" },
477 .{ .amx_tile, "__AMX_TILE__" },
478 .{ .amx_int8, "__AMX_INT8__" },
479 .{ .amx_bf16, "__AMX_BF16__" },
480 .{ .amx_fp16, "__AMX_FP16__" },
481 .{ .amx_complex, "__AMX_COMPLEX__" },
482 .{ .amx_fp8, "__AMX_FP8__" },
483 .{ .amx_movrs, "__AMX_MOVRS__" },
484 .{ .amx_transpose, "__AMX_TRANSPOSE__" },
485 .{ .amx_avx512, "__AMX_AVX512__" },
486 .{ .amx_tf32, "__AMX_TF32__" },
487 .{ .cmpccxadd, "__CMPCCXADD__" },
488 .{ .raoint, "__RAOINT__" },
489 .{ .avxifma, "__AVXIFMA__" },
490 .{ .avxneconvert, "__AVXNECONVERT__" },
491 .{ .avxvnni, "__AVXVNNI__" },
492 .{ .avxvnniint16, "__AVXVNNIINT16__" },
493 .{ .avxvnniint8, "__AVXVNNIINT8__" },
494 .{ .serialize, "__SERIALIZE__" },
495 .{ .tsxldtrk, "__TSXLDTRK__" },
496 .{ .uintr, "__UINTR__" },
497 .{ .usermsr, "__USERMSR__" },
498 .{ .crc32, "__CRC32__" },
499 .{ .egpr, "__EGPR__" },
500 .{ .push2pop2, "__PUSH2POP2__" },
501 .{ .ppx, "__PPX__" },
502 .{ .ndd, "__NDD__" },
503 .{ .ccmp, "__CCMP__" },
504 .{ .nf, "__NF__" },
505 .{ .cf, "__CF__" },
506 .{ .zu, "__ZU__" },
507
508 .{ .avx512f, "__AVX512F__" },
509 .{ .avx2, "__AVX2__" },
510 .{ .avx, "__AVX__" },
511 .{ .sse4_2, "__SSE4_2__" },
512 .{ .sse4_1, "__SSE4_1__" },
513 .{ .ssse3, "__SSSE3__" },
514 .{ .sse3, "__SSE3__" },
515 .{ .sse2, "__SSE2__" },
516 .{ .sse, "__SSE__" },
517 .{ .sse, "__SSE_MATH__" },
518
519 .{ .mmx, "__MMX__" },
520 }) |fs| {
521 if (features.isEnabled(@intFromEnum(fs[0]))) {
522 try define(w, fs[1]);
523 }
524 }
525
526 if (comp.langopts.ms_extensions and comp.target.cpu.arch == .x86) {
527 const level = if (comp.target.cpu.has(.x86, .sse2))
528 "2"
529 else if (comp.target.cpu.has(.x86, .sse))
530 "1"
531 else
532 "0";
533
534 try w.print("#define _M_IX86_FP {s}\n", .{level});
535 }
536
537 if (comp.target.cpu.hasAll(.x86, &.{ .egpr, .push2pop2, .ppx, .ndd, .ccmp, .nf, .cf, .zu })) {
538 try define(w, "__APX_F__");
539 }
540
541 if (comp.target.cpu.hasAll(.x86, &.{ .egpr, .inline_asm_use_gpr32 })) {
542 try define(w, "__APX_INLINE_ASM_USE_GPR32__");
543 }
544
545 if (comp.target.cpu.has(.x86, .cx8)) {
546 try define(w, "__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8");
547 }
548 if (comp.target.cpu.has(.x86, .cx16) and comp.target.cpu.arch == .x86_64) {
549 try define(w, "__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8");
550 }
551
552 if (comp.hasFloat128()) {
553 try w.writeAll("#define __SIZEOF_FLOAT128__ 16\n");
376 }554 }
377 },555 },
378 .mips,556 .mips,
...@@ -443,13 +621,132 @@ fn generateSystemDefines(comp: *Compilation, w: *std.Io.Writer) !void {...@@ -443,13 +621,132 @@ fn generateSystemDefines(comp: *Compilation, w: *std.Io.Writer) !void {
443 try define(w, "__arm64__");621 try define(w, "__arm64__");
444 }622 }
445 if (comp.target.os.tag == .windows and comp.target.abi == .msvc) {623 if (comp.target.os.tag == .windows and comp.target.abi == .msvc) {
446 try w.writeAll("#define _M_ARM64 100\n");624 try w.writeAll("#define _M_ARM64 1\n");
625 }
626
627 {
628 const cmodel = switch (comp.cmodel) {
629 .default => "small",
630 else => @tagName(comp.cmodel),
631 };
632 try w.writeAll("#define __AARCH64_CMODEL_");
633 for (cmodel) |c| {
634 try w.writeByte(std.ascii.toUpper(c));
635 }
636 try w.writeAll("__ 1\n");
637 }
638
639 if (comp.target.cpu.has(.aarch64, .fp_armv8)) {
640 try w.writeAll("#define __ARM_FP 0xE\n");
641 }
642 if (comp.target.cpu.has(.aarch64, .neon)) {
643 try define(w, "__ARM_NEON");
644 try w.writeAll("#define __ARM_NEON_FP 0xE\n");
645 }
646 if (comp.target.cpu.has(.aarch64, .bf16)) {
647 try define(w, "__ARM_FEATURE_BF16");
648 try define(w, "__ARM_FEATURE_BF16_VECTOR_ARITHMETIC");
649 try define(w, "__ARM_BF16_FORMAT_ALTERNATIVE");
650 try define(w, "__ARM_FEATURE_BF16_SCALAR_ARITHMETIC");
651 if (comp.target.cpu.has(.aarch64, .sve)) {
652 try define(w, "__ARM_FEATURE_SVE_BF16");
653 }
654 }
655 if (comp.target.cpu.hasAll(.aarch64, &.{ .sve2, .sve_aes })) {
656 try define(w, "__ARM_FEATURE_SVE2_AES");
657 }
658 if (comp.target.cpu.hasAll(.aarch64, &.{ .sve2, .sve_bitperm })) {
659 try define(w, "__ARM_FEATURE_SVE2_BITPERM");
660 }
661 if (comp.target.cpu.has(.aarch64, .sme)) {
662 try define(w, "__ARM_FEATURE_SME");
663 try define(w, "__ARM_FEATURE_LOCALLY_STREAMING");
664 }
665 if (comp.target.cpu.has(.aarch64, .fmv)) {
666 try define(w, "__HAVE_FUNCTION_MULTI_VERSIONING");
667 }
668 if (comp.target.cpu.has(.aarch64, .sha3)) {
669 try define(w, "__ARM_FEATURE_SHA3");
670 try define(w, "__ARM_FEATURE_SHA512");
671 }
672 if (comp.target.cpu.has(.aarch64, .sm4)) {
673 try define(w, "__ARM_FEATURE_SM3");
674 try define(w, "__ARM_FEATURE_SM4");
675 }
676 if (!comp.target.cpu.has(.aarch64, .strict_align)) {
677 try define(w, "__ARM_FEATURE_UNALIGNED");
678 }
679 if (comp.target.cpu.hasAll(.aarch64, &.{ .neon, .fullfp16 })) {
680 try define(w, "__ARM_FEATURE_FP16_VECTOR_ARITHMETIC");
681 }
682 if (comp.target.cpu.has(.aarch64, .rcpc3)) {
683 try w.writeAll("#define __ARM_FEATURE_RCPC 3\n");
684 } else if (comp.target.cpu.has(.aarch64, .rcpc)) {
685 try define(w, "__ARM_FEATURE_RCPC");
686 }
687
688 const features = comp.target.cpu.features;
689 for ([_]struct { std.Target.aarch64.Feature, []const u8 }{
690 .{ .sve, "SVE" },
691 .{ .sve2, "SVE2" },
692 .{ .sve2p1, "SVE2p1" },
693 .{ .sve2_sha3, "SVE2_SHA3" },
694 .{ .sve2_sm4, "SVE2_SM4" },
695 .{ .sve_b16b16, "SVE_B16B16" },
696 .{ .sme2, "SME2" },
697 .{ .sme2p1, "SME2p1" },
698 .{ .sme_f16f16, "SME_F16F16" },
699 .{ .sme_b16b16, "SME_B16B16" },
700 .{ .crc, "CRC32" },
701 .{ .aes, "AES" },
702 .{ .sha2, "SHA2" },
703 .{ .pauth, "PAUTH" },
704 .{ .pauth_lr, "PAUTH_LR" },
705 .{ .bti, "BTI" },
706 .{ .fullfp16, "FP16_SCALAR_ARITHMETIC" },
707 .{ .dotprod, "DOTPROD" },
708 .{ .mte, "MEMORY_TAGGING" },
709 .{ .tme, "TME" },
710 .{ .i8mm, "MATMUL_INT8" },
711 .{ .lse, "ATOMICS" },
712 .{ .f64mm, "SVE_MATMUL_FP64" },
713 .{ .f32mm, "SVE_MATMUL_FP32" },
714 .{ .i8mm, "SVE_MATMUL_INT8" },
715 .{ .fp16fml, "FP16_FML" },
716 .{ .ls64, "LS64" },
717 .{ .rand, "RNG" },
718 .{ .mops, "MOPS" },
719 .{ .d128, "SYSREG128" },
720 .{ .gcs, "GCS" },
721 }) |fs| {
722 if (features.isEnabled(@intFromEnum(fs[0]))) {
723 try w.print("#define __ARM_FEATURE_{s} 1\n", .{fs[1]});
724 }
447 }725 }
448 },726 },
449 .msp430 => {727 .msp430 => {
450 try define(w, "MSP430");728 try define(w, "MSP430");
451 try define(w, "__MSP430__");729 try define(w, "__MSP430__");
452 },730 },
731 .arc => {
732 try define(w, "__arc__");
733 },
734 .wasm32, .wasm64 => {
735 try define(w, "__wasm");
736 try define(w, "__wasm__");
737 if (comp.target.cpu.arch == .wasm32) {
738 try define(w, "__wasm32");
739 try define(w, "__wasm32__");
740 } else {
741 try define(w, "__wasm64");
742 try define(w, "__wasm64__");
743 }
744
745 for (comp.target.cpu.arch.allFeaturesList()) |feature| {
746 if (!comp.target.cpu.features.isEnabled(feature.index)) continue;
747 try w.print("#define __wasm_{s}__ 1\n", .{feature.name});
748 }
749 },
453 else => {},750 else => {},
454 }751 }
455752
...@@ -1477,7 +1774,7 @@ fn getFileContents(comp: *Compilation, path: []const u8, limit: std.Io.Limit) ![...@@ -1477,7 +1774,7 @@ fn getFileContents(comp: *Compilation, path: []const u8, limit: std.Io.Limit) ![
14771774
1478 var file_buf: [4096]u8 = undefined;1775 var file_buf: [4096]u8 = undefined;
1479 var file_reader = file.reader(&file_buf);1776 var file_reader = file.reader(&file_buf);
1480 if (limit.minInt(try file_reader.getSize()) > std.math.maxInt(u32)) return error.FileTooBig;1777 if (limit.minInt64(try file_reader.getSize()) > std.math.maxInt(u32)) return error.FileTooBig;
14811778
1482 _ = allocating.writer.sendFileAll(&file_reader, limit) catch |err| switch (err) {1779 _ = allocating.writer.sendFileAll(&file_reader, limit) catch |err| switch (err) {
1483 error.WriteFailed => return error.OutOfMemory,1780 error.WriteFailed => return error.OutOfMemory,
...@@ -1494,14 +1791,16 @@ pub fn findEmbed(...@@ -1494,14 +1791,16 @@ pub fn findEmbed(
1494 /// angle bracket vs quotes1791 /// angle bracket vs quotes
1495 include_type: IncludeType,1792 include_type: IncludeType,
1496 limit: std.Io.Limit,1793 limit: std.Io.Limit,
1794 opt_dep_file: ?*DepFile,
1497) !?[]const u8 {1795) !?[]const u8 {
1498 if (std.fs.path.isAbsolute(filename)) {1796 if (std.fs.path.isAbsolute(filename)) {
1499 return if (comp.getFileContents(filename, limit)) |some|1797 if (comp.getFileContents(filename, limit)) |some| {
1500 some1798 if (opt_dep_file) |dep_file| try dep_file.addDependencyDupe(comp.gpa, comp.arena, filename);
1501 else |err| switch (err) {1799 return some;
1800 } else |err| switch (err) {
1502 error.OutOfMemory => |e| return e,1801 error.OutOfMemory => |e| return e,
1503 else => null,1802 else => return null,
1504 };1803 }
1505 }1804 }
15061805
1507 var stack_fallback = std.heap.stackFallback(path_buf_stack_limit, comp.gpa);1806 var stack_fallback = std.heap.stackFallback(path_buf_stack_limit, comp.gpa);
...@@ -1516,6 +1815,7 @@ pub fn findEmbed(...@@ -1516,6 +1815,7 @@ pub fn findEmbed(
1516 std.mem.replaceScalar(u8, path, '\\', '/');1815 std.mem.replaceScalar(u8, path, '\\', '/');
1517 }1816 }
1518 if (comp.getFileContents(path, limit)) |some| {1817 if (comp.getFileContents(path, limit)) |some| {
1818 if (opt_dep_file) |dep_file| try dep_file.addDependencyDupe(comp.gpa, comp.arena, filename);
1519 return some;1819 return some;
1520 } else |err| switch (err) {1820 } else |err| switch (err) {
1521 error.OutOfMemory => return error.OutOfMemory,1821 error.OutOfMemory => return error.OutOfMemory,
...@@ -1531,6 +1831,7 @@ pub fn findEmbed(...@@ -1531,6 +1831,7 @@ pub fn findEmbed(
1531 std.mem.replaceScalar(u8, path, '\\', '/');1831 std.mem.replaceScalar(u8, path, '\\', '/');
1532 }1832 }
1533 if (comp.getFileContents(path, limit)) |some| {1833 if (comp.getFileContents(path, limit)) |some| {
1834 if (opt_dep_file) |dep_file| try dep_file.addDependencyDupe(comp.gpa, comp.arena, filename);
1534 return some;1835 return some;
1535 } else |err| switch (err) {1836 } else |err| switch (err) {
1536 error.OutOfMemory => return error.OutOfMemory,1837 error.OutOfMemory => return error.OutOfMemory,
lib/compiler/aro/aro/DepFile.zig created+78
...@@ -0,0 +1,78 @@
1const std = @import("std");
2const Allocator = std.mem.Allocator;
3
4pub const Format = enum { make, nmake };
5
6const DepFile = @This();
7
8target: []const u8,
9deps: std.StringArrayHashMapUnmanaged(void) = .empty,
10format: Format,
11
12pub fn deinit(d: *DepFile, gpa: Allocator) void {
13 d.deps.deinit(gpa);
14 d.* = undefined;
15}
16
17pub fn addDependency(d: *DepFile, gpa: Allocator, path: []const u8) !void {
18 try d.deps.put(gpa, path, {});
19}
20
21pub fn addDependencyDupe(d: *DepFile, gpa: Allocator, arena: Allocator, path: []const u8) !void {
22 const gop = try d.deps.getOrPut(gpa, path);
23 if (gop.found_existing) return;
24 gop.key_ptr.* = try arena.dupe(u8, path);
25}
26
27pub fn write(d: *const DepFile, w: *std.Io.Writer) std.Io.Writer.Error!void {
28 const max_columns = 75;
29 var columns: usize = 0;
30
31 try w.writeAll(d.target);
32 columns += d.target.len;
33 try w.writeByte(':');
34 columns += 1;
35
36 for (d.deps.keys()) |path| {
37 if (std.mem.eql(u8, path, "<stdin>")) continue;
38
39 if (columns + path.len + " \\\n".len > max_columns) {
40 try w.writeAll(" \\\n ");
41 columns = 1;
42 }
43 try w.writeByte(' ');
44 try d.writePath(path, w);
45 columns += path.len + 1;
46 }
47 try w.writeByte('\n');
48 try w.flush();
49}
50
51fn writePath(d: *const DepFile, path: []const u8, w: *std.Io.Writer) !void {
52 switch (d.format) {
53 .nmake => {
54 if (std.mem.indexOfAny(u8, path, " #${}^!")) |_|
55 try w.print("\"{s}\"", .{path})
56 else
57 try w.writeAll(path);
58 },
59 .make => {
60 for (path, 0..) |c, i| {
61 if (c == '#') {
62 try w.writeByte('\\');
63 } else if (c == '$') {
64 try w.writeByte('$');
65 } else if (c == ' ') {
66 try w.writeByte('\\');
67 var j = i;
68 while (j != 0) {
69 j -= 1;
70 if (path[j] != '\\') break;
71 try w.writeByte('\\');
72 }
73 }
74 try w.writeByte(c);
75 }
76 },
77 }
78}
lib/compiler/aro/aro/Diagnostics.zig+55-46
...@@ -23,6 +23,52 @@ pub const Message = struct {...@@ -23,6 +23,52 @@ pub const Message = struct {
23 @"error",23 @"error",
24 @"fatal error",24 @"fatal error",
25 };25 };
26
27 pub fn write(msg: Message, w: *std.Io.Writer, config: std.Io.tty.Config, details: bool) std.Io.tty.Config.SetColorError!void {
28 try config.setColor(w, .bold);
29 if (msg.location) |loc| {
30 try w.print("{s}:{d}:{d}: ", .{ loc.path, loc.line_no, loc.col });
31 }
32 switch (msg.effective_kind) {
33 .@"fatal error", .@"error" => try config.setColor(w, .bright_red),
34 .note => try config.setColor(w, .bright_cyan),
35 .warning => try config.setColor(w, .bright_magenta),
36 .off => unreachable,
37 }
38 try w.print("{s}: ", .{@tagName(msg.effective_kind)});
39
40 try config.setColor(w, .white);
41 try w.writeAll(msg.text);
42 if (msg.opt) |some| {
43 if (msg.effective_kind == .@"error" and msg.kind != .@"error") {
44 try w.print(" [-Werror,-W{s}]", .{@tagName(some)});
45 } else if (msg.effective_kind != .note) {
46 try w.print(" [-W{s}]", .{@tagName(some)});
47 }
48 } else if (msg.extension) {
49 if (msg.effective_kind == .@"error") {
50 try w.writeAll(" [-Werror,-Wpedantic]");
51 } else if (msg.effective_kind != msg.kind) {
52 try w.writeAll(" [-Wpedantic]");
53 }
54 }
55
56 if (!details or msg.location == null) {
57 try w.writeAll("\n");
58 try config.setColor(w, .reset);
59 } else {
60 const loc = msg.location.?;
61 const trailer = if (loc.end_with_splice) "\\ " else "";
62 try config.setColor(w, .reset);
63 try w.print("\n{s}{s}\n", .{ loc.line, trailer });
64 try w.splatByteAll(' ', loc.width);
65 try config.setColor(w, .bold);
66 try config.setColor(w, .bright_green);
67 try w.writeAll("^\n");
68 try config.setColor(w, .reset);
69 }
70 try w.flush();
71 }
26};72};
2773
28pub const Option = enum {74pub const Option = enum {
...@@ -247,6 +293,11 @@ output: union(enum) {...@@ -247,6 +293,11 @@ output: union(enum) {
247 },293 },
248 ignore,294 ignore,
249},295},
296/// Force usage of color in output.
297color: ?bool = null,
298/// Include line of code in output.
299details: bool = true,
300
250state: State = .{},301state: State = .{},
251/// Amount of error or fatal error messages that have been sent to `output`.302/// Amount of error or fatal error messages that have been sent to `output`.
252errors: u32 = 0,303errors: u32 = 0,
...@@ -468,7 +519,10 @@ fn addMessage(d: *Diagnostics, msg: Message) Compilation.Error!void {...@@ -468,7 +519,10 @@ fn addMessage(d: *Diagnostics, msg: Message) Compilation.Error!void {
468 switch (d.output) {519 switch (d.output) {
469 .ignore => {},520 .ignore => {},
470 .to_writer => |writer| {521 .to_writer => |writer| {
471 writeToWriter(msg, writer.writer, writer.color) catch {522 var config = writer.color;
523 if (d.color == false) config = .no_color;
524 if (d.color == true and config == .no_color) config = .escape_codes;
525 msg.write(writer.writer, config, d.details) catch {
472 return error.FatalError;526 return error.FatalError;
473 };527 };
474 },528 },
...@@ -485,48 +539,3 @@ fn addMessage(d: *Diagnostics, msg: Message) Compilation.Error!void {...@@ -485,48 +539,3 @@ fn addMessage(d: *Diagnostics, msg: Message) Compilation.Error!void {
485 },539 },
486 }540 }
487}541}
488
489pub fn writeToWriter(msg: Message, w: *std.Io.Writer, config: std.Io.tty.Config) !void {
490 try config.setColor(w, .bold);
491 if (msg.location) |loc| {
492 try w.print("{s}:{d}:{d}: ", .{ loc.path, loc.line_no, loc.col });
493 }
494 switch (msg.effective_kind) {
495 .@"fatal error", .@"error" => try config.setColor(w, .bright_red),
496 .note => try config.setColor(w, .bright_cyan),
497 .warning => try config.setColor(w, .bright_magenta),
498 .off => unreachable,
499 }
500 try w.print("{s}: ", .{@tagName(msg.effective_kind)});
501
502 try config.setColor(w, .white);
503 try w.writeAll(msg.text);
504 if (msg.opt) |some| {
505 if (msg.effective_kind == .@"error" and msg.kind != .@"error") {
506 try w.print(" [-Werror,-W{s}]", .{@tagName(some)});
507 } else if (msg.effective_kind != .note) {
508 try w.print(" [-W{s}]", .{@tagName(some)});
509 }
510 } else if (msg.extension) {
511 if (msg.effective_kind == .@"error") {
512 try w.writeAll(" [-Werror,-Wpedantic]");
513 } else if (msg.effective_kind != msg.kind) {
514 try w.writeAll(" [-Wpedantic]");
515 }
516 }
517
518 if (msg.location) |loc| {
519 const trailer = if (loc.end_with_splice) "\\ " else "";
520 try config.setColor(w, .reset);
521 try w.print("\n{s}{s}\n", .{ loc.line, trailer });
522 try w.splatByteAll(' ', loc.width);
523 try config.setColor(w, .bold);
524 try config.setColor(w, .bright_green);
525 try w.writeAll("^\n");
526 try config.setColor(w, .reset);
527 } else {
528 try w.writeAll("\n");
529 try config.setColor(w, .reset);
530 }
531 try w.flush();
532}
lib/compiler/aro/aro/Driver.zig+242-43
...@@ -10,6 +10,7 @@ const Object = backend.Object;...@@ -10,6 +10,7 @@ const Object = backend.Object;
1010
11const Compilation = @import("Compilation.zig");11const Compilation = @import("Compilation.zig");
12const Diagnostics = @import("Diagnostics.zig");12const Diagnostics = @import("Diagnostics.zig");
13const DepFile = @import("DepFile.zig");
13const GCCVersion = @import("Driver/GCCVersion.zig");14const GCCVersion = @import("Driver/GCCVersion.zig");
14const LangOpts = @import("LangOpts.zig");15const LangOpts = @import("LangOpts.zig");
15const Preprocessor = @import("Preprocessor.zig");16const Preprocessor = @import("Preprocessor.zig");
...@@ -63,7 +64,6 @@ verbose_ast: bool = false,...@@ -63,7 +64,6 @@ verbose_ast: bool = false,
63verbose_pp: bool = false,64verbose_pp: bool = false,
64verbose_ir: bool = false,65verbose_ir: bool = false,
65verbose_linker_args: bool = false,66verbose_linker_args: bool = false,
66color: ?bool = null,
67nobuiltininc: bool = false,67nobuiltininc: bool = false,
68nostdinc: bool = false,68nostdinc: bool = false,
69nostdlibinc: bool = false,69nostdlibinc: bool = false,
...@@ -73,7 +73,6 @@ mabicalls: ?bool = null,...@@ -73,7 +73,6 @@ mabicalls: ?bool = null,
73dynamic_nopic: ?bool = null,73dynamic_nopic: ?bool = null,
74ropi: bool = false,74ropi: bool = false,
75rwpi: bool = false,75rwpi: bool = false,
76cmodel: std.builtin.CodeModel = .default,
77debug_dump_letters: packed struct(u3) {76debug_dump_letters: packed struct(u3) {
78 d: bool = false,77 d: bool = false,
79 m: bool = false,78 m: bool = false,
...@@ -88,17 +87,27 @@ debug_dump_letters: packed struct(u3) {...@@ -88,17 +87,27 @@ debug_dump_letters: packed struct(u3) {
88 return .result_only;87 return .result_only;
89 }88 }
90} = .{},89} = .{},
90dependencies: struct {
91 m: bool = false,
92 md: bool = false,
93 format: DepFile.Format = .make,
94 file: ?[]const u8 = null,
95} = .{},
9196
92/// Full path to the aro executable97/// Full path to the aro executable
93aro_name: []const u8 = "",98aro_name: []const u8 = "",
9499
95/// Value of --triple= passed via CLI100/// Value of -target passed via CLI
96raw_target_triple: ?[]const u8 = null,101raw_target_triple: ?[]const u8 = null,
97102
103/// Value of -mcpu passed via CLI
104raw_cpu: ?[]const u8 = null,
105
98/// Non-optimizing assembly backend is currently selected by passing `-O0`106/// Non-optimizing assembly backend is currently selected by passing `-O0`
99use_assembly_backend: bool = false,107use_assembly_backend: bool = false,
100108
101// linker options109// linker options
110use_linker: ?[]const u8 = null,
102linker_path: ?[]const u8 = null,111linker_path: ?[]const u8 = null,
103nodefaultlibs: bool = false,112nodefaultlibs: bool = false,
104nolibc: bool = false,113nolibc: bool = false,
...@@ -133,13 +142,26 @@ pub const usage =...@@ -133,13 +142,26 @@ pub const usage =
133 \\ --help Print this message142 \\ --help Print this message
134 \\ --version Print aro version143 \\ --version Print aro version
135 \\144 \\
136 \\Compile options:145 \\Preprocessor options:
137 \\ -c, --compile Only run preprocess, compile, and assemble steps146 \\ -C Do not discard comments
147 \\ -CC Do not discard comments, including in macro expansions
138 \\ -dM Output #define directives for all the macros defined during the execution of the preprocessor148 \\ -dM Output #define directives for all the macros defined during the execution of the preprocessor
139 \\ -dD Like -dM except that it outputs both the #define directives and the result of preprocessing149 \\ -dD Like -dM except that it outputs both the #define directives and the result of preprocessing
140 \\ -dN Like -dD, but emit only the macro names, not their expansions.150 \\ -dN Like -dD, but emit only the macro names, not their expansions.
141 \\ -D <macro>=<value> Define <macro> to <value> (defaults to 1)151 \\ -D <macro>=<value> Define <macro> to <value> (defaults to 1)
142 \\ -E Only run the preprocessor152 \\ -E Only run the preprocessor
153 \\ -fdollars-in-identifiers
154 \\ Allow '$' in identifiers
155 \\ -fno-dollars-in-identifiers
156 \\ Disallow '$' in identifiers
157 \\ -M Output dependency file instead of preprocessing result
158 \\ -MD Like -M except -E is not implied
159 \\ -MF <file> Write dependency file to <file>
160 \\ -MV Use NMake/Jom format for dependency file
161 \\ -P, --no-line-commands Disable linemarker output in -E mode
162 \\
163 \\Compile options:
164 \\ -c, --compile Only run preprocess, compile, and assemble steps
143 \\ -fapple-kext Use Apple's kernel extensions ABI165 \\ -fapple-kext Use Apple's kernel extensions ABI
144 \\ -fchar8_t Enable char8_t (enabled by default in C23 and later)166 \\ -fchar8_t Enable char8_t (enabled by default in C23 and later)
145 \\ -fno-char8_t Disable char8_t (disabled by default for pre-C23)167 \\ -fno-char8_t Disable char8_t (disabled by default for pre-C23)
...@@ -158,10 +180,6 @@ pub const usage =...@@ -158,10 +180,6 @@ pub const usage =
158 \\ -fhosted Compilation in a hosted environment180 \\ -fhosted Compilation in a hosted environment
159 \\ -fms-extensions Enable support for Microsoft extensions181 \\ -fms-extensions Enable support for Microsoft extensions
160 \\ -fno-ms-extensions Disable support for Microsoft extensions182 \\ -fno-ms-extensions Disable support for Microsoft extensions
161 \\ -fdollars-in-identifiers
162 \\ Allow '$' in identifiers
163 \\ -fno-dollars-in-identifiers
164 \\ Disallow '$' in identifiers
165 \\ -g Generate debug information183 \\ -g Generate debug information
166 \\ -fmacro-backtrace-limit=<limit>184 \\ -fmacro-backtrace-limit=<limit>
167 \\ Set limit on how many macro expansion traces are shown in errors (default 6)185 \\ Set limit on how many macro expansion traces are shown in errors (default 6)
...@@ -197,6 +215,7 @@ pub const usage =...@@ -197,6 +215,7 @@ pub const usage =
197 \\ -mabicalls Enable SVR4-style position-independent code (Mips only)215 \\ -mabicalls Enable SVR4-style position-independent code (Mips only)
198 \\ -mno-abicalls Disable SVR4-style position-independent code (Mips only)216 \\ -mno-abicalls Disable SVR4-style position-independent code (Mips only)
199 \\ -mcmodel=<code-model> Generate code for the given code model217 \\ -mcmodel=<code-model> Generate code for the given code model
218 \\ -mcpu [cpu] Specify target CPU and feature set
200 \\ -mkernel Enable kernel development mode219 \\ -mkernel Enable kernel development mode
201 \\ -nobuiltininc Do not search the compiler's builtin directory for include files220 \\ -nobuiltininc Do not search the compiler's builtin directory for include files
202 \\ -resource-dir <dir> Override the path to the compiler's builtin resource directory221 \\ -resource-dir <dir> Override the path to the compiler's builtin resource directory
...@@ -204,7 +223,6 @@ pub const usage =...@@ -204,7 +223,6 @@ pub const usage =
204 \\ Do not search the standard system directories or compiler builtin directories for include files.223 \\ Do not search the standard system directories or compiler builtin directories for include files.
205 \\ -nostdlibinc Do not search the standard system directories for include files, but do search compiler builtin include directories224 \\ -nostdlibinc Do not search the standard system directories for include files, but do search compiler builtin include directories
206 \\ -o <file> Write output to <file>225 \\ -o <file> Write output to <file>
207 \\ -P, --no-line-commands Disable linemarker output in -E mode
208 \\ -pedantic Warn on language extensions226 \\ -pedantic Warn on language extensions
209 \\ -pedantic-errors Error on language extensions227 \\ -pedantic-errors Error on language extensions
210 \\ --rtlib=<arg> Compiler runtime library to use (libgcc or compiler-rt)228 \\ --rtlib=<arg> Compiler runtime library to use (libgcc or compiler-rt)
...@@ -262,9 +280,12 @@ pub fn parseArgs(...@@ -262,9 +280,12 @@ pub fn parseArgs(
262 var pic_arg: []const u8 = "";280 var pic_arg: []const u8 = "";
263 var declspec_attrs: ?bool = null;281 var declspec_attrs: ?bool = null;
264 var ms_extensions: ?bool = null;282 var ms_extensions: ?bool = null;
283 var strip = true;
284 var debug: ?backend.CodeGenOptions.DebugFormat = null;
285 var emulate: ?LangOpts.Compiler = null;
265 while (i < args.len) : (i += 1) {286 while (i < args.len) : (i += 1) {
266 const arg = args[i];287 const arg = args[i];
267 if (mem.startsWith(u8, arg, "-") and arg.len > 1) {288 if (arg.len > 1 and arg[0] == '-') {
268 if (mem.eql(u8, arg, "--help")) {289 if (mem.eql(u8, arg, "--help")) {
269 try stdout.print(usage, .{args[0]});290 try stdout.print(usage, .{args[0]});
270 try stdout.flush();291 try stdout.flush();
...@@ -329,7 +350,7 @@ pub fn parseArgs(...@@ -329,7 +350,7 @@ pub fn parseArgs(
329 } else if (mem.eql(u8, arg, "-fapple-kext")) {350 } else if (mem.eql(u8, arg, "-fapple-kext")) {
330 d.apple_kext = true;351 d.apple_kext = true;
331 } else if (option(arg, "-mcmodel=")) |cmodel| {352 } else if (option(arg, "-mcmodel=")) |cmodel| {
332 d.cmodel = std.meta.stringToEnum(std.builtin.CodeModel, cmodel) orelse353 d.comp.cmodel = std.meta.stringToEnum(std.builtin.CodeModel, cmodel) orelse
333 return d.fatal("unsupported machine code model: '{s}'", .{arg});354 return d.fatal("unsupported machine code model: '{s}'", .{arg});
334 } else if (mem.eql(u8, arg, "-mkernel")) {355 } else if (mem.eql(u8, arg, "-mkernel")) {
335 d.mkernel = true;356 d.mkernel = true;
...@@ -339,14 +360,47 @@ pub fn parseArgs(...@@ -339,14 +360,47 @@ pub fn parseArgs(
339 d.mabicalls = true;360 d.mabicalls = true;
340 } else if (mem.eql(u8, arg, "-mno-abicalls")) {361 } else if (mem.eql(u8, arg, "-mno-abicalls")) {
341 d.mabicalls = false;362 d.mabicalls = false;
363 } else if (mem.eql(u8, arg, "-mcpu")) {
364 i += 1;
365 if (i >= args.len) {
366 try d.err("expected argument after -mcpu", .{});
367 continue;
368 }
369 d.raw_cpu = args[i];
370 } else if (option(arg, "-mcpu=")) |cpu| {
371 d.raw_cpu = cpu;
372 } else if (mem.eql(u8, arg, "-M") or mem.eql(u8, arg, "--dependencies")) {
373 d.dependencies.m = true;
374 // -M implies -w and -E
375 d.diagnostics.state.ignore_warnings = true;
376 d.only_preprocess = true;
377 } else if (mem.eql(u8, arg, "-MD") or mem.eql(u8, arg, "--write-dependencies")) {
378 d.dependencies.md = true;
379 } else if (mem.startsWith(u8, arg, "-MF")) {
380 var path = arg["-MF".len..];
381 if (path.len == 0) {
382 i += 1;
383 if (i >= args.len) {
384 try d.err("expected argument after -MF", .{});
385 continue;
386 }
387 path = args[i];
388 }
389 d.dependencies.file = path;
390 } else if (mem.eql(u8, arg, "-MV")) {
391 d.dependencies.format = .nmake;
342 } else if (mem.eql(u8, arg, "-fchar8_t")) {392 } else if (mem.eql(u8, arg, "-fchar8_t")) {
343 d.comp.langopts.has_char8_t_override = true;393 d.comp.langopts.has_char8_t_override = true;
344 } else if (mem.eql(u8, arg, "-fno-char8_t")) {394 } else if (mem.eql(u8, arg, "-fno-char8_t")) {
345 d.comp.langopts.has_char8_t_override = false;395 d.comp.langopts.has_char8_t_override = false;
346 } else if (mem.eql(u8, arg, "-fcolor-diagnostics")) {396 } else if (mem.eql(u8, arg, "-fcolor-diagnostics")) {
347 d.color = true;397 d.diagnostics.color = true;
348 } else if (mem.eql(u8, arg, "-fno-color-diagnostics")) {398 } else if (mem.eql(u8, arg, "-fno-color-diagnostics")) {
349 d.color = false;399 d.diagnostics.color = false;
400 } else if (mem.eql(u8, arg, "-fcaret-diagnostics")) {
401 d.diagnostics.details = true;
402 } else if (mem.eql(u8, arg, "-fno-caret-diagnostics")) {
403 d.diagnostics.details = false;
350 } else if (mem.eql(u8, arg, "-fcommon")) {404 } else if (mem.eql(u8, arg, "-fcommon")) {
351 d.comp.code_gen_options.common = true;405 d.comp.code_gen_options.common = true;
352 } else if (mem.eql(u8, arg, "-fno-common")) {406 } else if (mem.eql(u8, arg, "-fno-common")) {
...@@ -356,9 +410,31 @@ pub fn parseArgs(...@@ -356,9 +410,31 @@ pub fn parseArgs(
356 } else if (mem.eql(u8, arg, "-fno-dollars-in-identifiers")) {410 } else if (mem.eql(u8, arg, "-fno-dollars-in-identifiers")) {
357 d.comp.langopts.dollars_in_identifiers = false;411 d.comp.langopts.dollars_in_identifiers = false;
358 } else if (mem.eql(u8, arg, "-g")) {412 } else if (mem.eql(u8, arg, "-g")) {
359 d.comp.code_gen_options.debug = true;413 strip = false;
360 } else if (mem.eql(u8, arg, "-g0")) {414 } else if (mem.eql(u8, arg, "-g0")) {
361 d.comp.code_gen_options.debug = false;415 strip = true;
416 } else if (mem.eql(u8, arg, "-gcodeview")) {
417 debug = .code_view;
418 } else if (mem.eql(u8, arg, "-gdwarf32")) {
419 debug = .{ .dwarf = .@"32" };
420 } else if (mem.eql(u8, arg, "-gdwarf64")) {
421 debug = .{ .dwarf = .@"64" };
422 } else if (mem.eql(u8, arg, "-gdwarf") or
423 mem.eql(u8, arg, "-gdwarf-2") or
424 mem.eql(u8, arg, "-gdwarf-3") or
425 mem.eql(u8, arg, "-gdwarf-4") or
426 mem.eql(u8, arg, "-gdwarf-5"))
427 {
428 d.comp.code_gen_options.dwarf_version = switch (arg[arg.len - 1]) {
429 '2' => .@"2",
430 '3' => .@"3",
431 '4' => .@"4",
432 '5' => .@"5",
433 else => .@"0",
434 };
435 if (debug == null or debug.? != .dwarf) {
436 debug = .{ .dwarf = .@"32" };
437 }
362 } else if (mem.eql(u8, arg, "-fdigraphs")) {438 } else if (mem.eql(u8, arg, "-fdigraphs")) {
363 d.comp.langopts.digraphs = true;439 d.comp.langopts.digraphs = true;
364 } else if (mem.eql(u8, arg, "-fno-digraphs")) {440 } else if (mem.eql(u8, arg, "-fno-digraphs")) {
...@@ -413,9 +489,9 @@ pub fn parseArgs(...@@ -413,9 +489,9 @@ pub fn parseArgs(
413 ms_extensions = true;489 ms_extensions = true;
414 } else if (mem.eql(u8, arg, "-fno-ms-extensions")) {490 } else if (mem.eql(u8, arg, "-fno-ms-extensions")) {
415 ms_extensions = false;491 ms_extensions = false;
416 } else if (mem.startsWith(u8, arg, "-fsyntax-only")) {492 } else if (mem.eql(u8, arg, "-fsyntax-only")) {
417 d.only_syntax = true;493 d.only_syntax = true;
418 } else if (mem.startsWith(u8, arg, "-fno-syntax-only")) {494 } else if (mem.eql(u8, arg, "-fno-syntax-only")) {
419 d.only_syntax = false;495 d.only_syntax = false;
420 } else if (mem.eql(u8, arg, "-fgnuc-version=")) {496 } else if (mem.eql(u8, arg, "-fgnuc-version=")) {
421 gnuc_version = "0";497 gnuc_version = "0";
...@@ -483,12 +559,7 @@ pub fn parseArgs(...@@ -483,12 +559,7 @@ pub fn parseArgs(
483 try d.err("invalid compiler '{s}'", .{arg});559 try d.err("invalid compiler '{s}'", .{arg});
484 continue;560 continue;
485 };561 };
486 d.comp.langopts.setEmulatedCompiler(compiler);562 emulate = compiler;
487 switch (d.comp.langopts.emulate) {
488 .clang => try d.diagnostics.set("clang", .off),
489 .gcc => try d.diagnostics.set("gnu", .off),
490 .msvc => try d.diagnostics.set("microsoft", .off),
491 }
492 } else if (option(arg, "-ffp-eval-method=")) |fp_method_str| {563 } else if (option(arg, "-ffp-eval-method=")) |fp_method_str| {
493 const fp_eval_method = std.meta.stringToEnum(LangOpts.FPEvalMethod, fp_method_str) orelse .indeterminate;564 const fp_eval_method = std.meta.stringToEnum(LangOpts.FPEvalMethod, fp_method_str) orelse .indeterminate;
494 if (fp_eval_method == .indeterminate) {565 if (fp_eval_method == .indeterminate) {
...@@ -554,8 +625,10 @@ pub fn parseArgs(...@@ -554,8 +625,10 @@ pub fn parseArgs(
554 continue;625 continue;
555 }626 }
556 d.raw_target_triple = args[i];627 d.raw_target_triple = args[i];
628 emulate = null;
557 } else if (option(arg, "--target=")) |triple| {629 } else if (option(arg, "--target=")) |triple| {
558 d.raw_target_triple = triple;630 d.raw_target_triple = triple;
631 emulate = null;
559 } else if (mem.eql(u8, arg, "--verbose-ast")) {632 } else if (mem.eql(u8, arg, "--verbose-ast")) {
560 d.verbose_ast = true;633 d.verbose_ast = true;
561 } else if (mem.eql(u8, arg, "--verbose-pp")) {634 } else if (mem.eql(u8, arg, "--verbose-pp")) {
...@@ -571,6 +644,10 @@ pub fn parseArgs(...@@ -571,6 +644,10 @@ pub fn parseArgs(
571 d.comp.langopts.preserve_comments = true;644 d.comp.langopts.preserve_comments = true;
572 d.comp.langopts.preserve_comments_in_macros = true;645 d.comp.langopts.preserve_comments_in_macros = true;
573 comment_arg = arg;646 comment_arg = arg;
647 } else if (option(arg, "-fuse-ld=")) |linker_name| {
648 d.use_linker = linker_name;
649 } else if (mem.eql(u8, arg, "-fuse-ld=")) {
650 d.use_linker = null;
574 } else if (option(arg, "--ld-path=")) |linker_path| {651 } else if (option(arg, "--ld-path=")) |linker_path| {
575 d.linker_path = linker_path;652 d.linker_path = linker_path;
576 } else if (mem.eql(u8, arg, "-r")) {653 } else if (mem.eql(u8, arg, "-r")) {
...@@ -624,6 +701,33 @@ pub fn parseArgs(...@@ -624,6 +701,33 @@ pub fn parseArgs(
624 } else {701 } else {
625 try d.err("invalid unwind library name '{s}'", .{unwindlib});702 try d.err("invalid unwind library name '{s}'", .{unwindlib});
626 }703 }
704 } else if (mem.startsWith(u8, arg, "-x")) {
705 var lang = arg["-x".len..];
706 if (lang.len == 0) {
707 i += 1;
708 if (i >= args.len) {
709 try d.err("expected argument after -x", .{});
710 continue;
711 }
712 lang = args[i];
713 }
714 if (!mem.eql(u8, lang, "none") and !mem.eql(u8, lang, "c")) {
715 try d.err("language not recognized: '{s}'", .{lang});
716 }
717 } else if (mem.startsWith(u8, arg, "-flto")) {
718 const rest = arg["-flto".len..];
719 if (rest.len == 0 or
720 mem.eql(u8, rest, "=auto") or
721 mem.eql(u8, rest, "=full") or
722 mem.eql(u8, rest, "=jobserver") or
723 mem.eql(u8, rest, "=thin"))
724 {
725 try d.warn("lto not supported", .{});
726 } else {
727 return d.fatal("invalid lto mode: '{s}'", .{arg});
728 }
729 } else if (mem.eql(u8, arg, "-fno-lto")) {
730 // nothing to do
627 } else {731 } else {
628 try d.warn("unknown argument '{s}'", .{arg});732 try d.warn("unknown argument '{s}'", .{arg});
629 }733 }
...@@ -636,17 +740,33 @@ pub fn parseArgs(...@@ -636,17 +740,33 @@ pub fn parseArgs(
636 try d.inputs.append(d.comp.gpa, source);740 try d.inputs.append(d.comp.gpa, source);
637 }741 }
638 }742 }
639 if (d.raw_target_triple) |triple| triple: {743 {
640 const query = std.Target.Query.parse(.{ .arch_os_abi = triple }) catch {744 var diags: std.Target.Query.ParseOptions.Diagnostics = .{};
641 try d.err("invalid target '{s}'", .{triple});745 const opts: std.Target.Query.ParseOptions = .{
642 d.raw_target_triple = null;746 .arch_os_abi = d.raw_target_triple orelse "native",
643 break :triple;747 .cpu_features = d.raw_cpu,
748 .diagnostics = &diags,
749 };
750 const query = std.Target.Query.parse(opts) catch |er| switch (er) {
751 error.UnknownCpuModel => {
752 return d.fatal("unknown CPU: '{s}'", .{diags.cpu_name.?});
753 },
754 error.UnknownCpuFeature => {
755 return d.fatal("unknown CPU feature: '{s}'", .{diags.unknown_feature_name.?});
756 },
757 error.UnknownArchitecture => {
758 return d.fatal("unknown architecture: '{s}'", .{diags.unknown_architecture_name.?});
759 },
760 else => |e| return d.fatal("unable to parse target query '{s}': {s}", .{
761 opts.arch_os_abi, @errorName(e),
762 }),
644 };763 };
645 const target = std.zig.system.resolveTargetQuery(query) catch |e| {764 d.comp.target = std.zig.system.resolveTargetQuery(query) catch |e| {
646 return d.fatal("unable to resolve target: {s}", .{errorDescription(e)});765 return d.fatal("unable to resolve target: {s}", .{errorDescription(e)});
647 };766 };
648 d.comp.target = target;767 }
649 d.comp.langopts.setEmulatedCompiler(target_util.systemCompiler(target));768 if (emulate != null or d.raw_target_triple != null) {
769 d.comp.langopts.setEmulatedCompiler(emulate orelse target_util.systemCompiler(d.comp.target));
650 switch (d.comp.langopts.emulate) {770 switch (d.comp.langopts.emulate) {
651 .clang => try d.diagnostics.set("clang", .off),771 .clang => try d.diagnostics.set("clang", .off),
652 .gcc => try d.diagnostics.set("gnu", .off),772 .gcc => try d.diagnostics.set("gnu", .off),
...@@ -673,6 +793,19 @@ pub fn parseArgs(...@@ -673,6 +793,19 @@ pub fn parseArgs(
673 const pic_level, const is_pie = try d.getPICMode(pic_arg);793 const pic_level, const is_pie = try d.getPICMode(pic_arg);
674 d.comp.code_gen_options.pic_level = pic_level;794 d.comp.code_gen_options.pic_level = pic_level;
675 d.comp.code_gen_options.is_pie = is_pie;795 d.comp.code_gen_options.is_pie = is_pie;
796 d.comp.code_gen_options.debug = debug: {
797 if (strip) break :debug .strip;
798 if (debug) |explicit| break :debug explicit;
799 break :debug switch (d.comp.target.ofmt) {
800 .elf, .goff, .macho, .wasm, .xcoff => .{ .dwarf = .@"32" },
801 .coff => .code_view,
802 .c => switch (d.comp.target.os.tag) {
803 .windows, .uefi => .code_view,
804 else => .{ .dwarf = .@"32" },
805 },
806 .spirv, .hex, .raw, .plan9 => .strip,
807 };
808 };
676 if (declspec_attrs) |some| d.comp.langopts.declspec_attrs = some;809 if (declspec_attrs) |some| d.comp.langopts.declspec_attrs = some;
677 if (ms_extensions) |some| d.comp.langopts.setMSExtensions(some);810 if (ms_extensions) |some| d.comp.langopts.setMSExtensions(some);
678 return false;811 return false;
...@@ -728,6 +861,7 @@ pub fn fatal(d: *Driver, comptime fmt: []const u8, args: anytype) error{ FatalEr...@@ -728,6 +861,7 @@ pub fn fatal(d: *Driver, comptime fmt: []const u8, args: anytype) error{ FatalEr
728}861}
729862
730pub fn printDiagnosticsStats(d: *Driver) void {863pub fn printDiagnosticsStats(d: *Driver) void {
864 if (!d.diagnostics.details) return;
731 const warnings = d.diagnostics.warnings;865 const warnings = d.diagnostics.warnings;
732 const errors = d.diagnostics.errors;866 const errors = d.diagnostics.errors;
733867
...@@ -743,14 +877,14 @@ pub fn printDiagnosticsStats(d: *Driver) void {...@@ -743,14 +877,14 @@ pub fn printDiagnosticsStats(d: *Driver) void {
743}877}
744878
745pub fn detectConfig(d: *Driver, file: std.fs.File) std.Io.tty.Config {879pub fn detectConfig(d: *Driver, file: std.fs.File) std.Io.tty.Config {
746 if (d.color == true) return .escape_codes;880 if (d.diagnostics.color == false) return .no_color;
747 if (d.color == false) return .no_color;881 const force_color = d.diagnostics.color == true;
748882
749 if (file.supportsAnsiEscapeCodes()) return .escape_codes;883 if (file.supportsAnsiEscapeCodes()) return .escape_codes;
750 if (@import("builtin").os.tag == .windows and file.isTty()) {884 if (@import("builtin").os.tag == .windows and file.isTty()) {
751 var info: std.os.windows.CONSOLE_SCREEN_BUFFER_INFO = undefined;885 var info: std.os.windows.CONSOLE_SCREEN_BUFFER_INFO = undefined;
752 if (std.os.windows.kernel32.GetConsoleScreenBufferInfo(file.handle, &info) != std.os.windows.TRUE) {886 if (std.os.windows.kernel32.GetConsoleScreenBufferInfo(file.handle, &info) == std.os.windows.FALSE) {
753 return .no_color;887 return if (force_color) .escape_codes else .no_color;
754 }888 }
755 return .{ .windows_api = .{889 return .{ .windows_api = .{
756 .handle = file.handle,890 .handle = file.handle,
...@@ -758,7 +892,7 @@ pub fn detectConfig(d: *Driver, file: std.fs.File) std.Io.tty.Config {...@@ -758,7 +892,7 @@ pub fn detectConfig(d: *Driver, file: std.fs.File) std.Io.tty.Config {
758 } };892 } };
759 }893 }
760894
761 return .no_color;895 return if (force_color) .escape_codes else .no_color;
762}896}
763897
764pub fn errorDescription(e: anyerror) []const u8 {898pub fn errorDescription(e: anyerror) []const u8 {
...@@ -851,6 +985,47 @@ pub fn main(d: *Driver, tc: *Toolchain, args: []const []const u8, comptime fast_...@@ -851,6 +985,47 @@ pub fn main(d: *Driver, tc: *Toolchain, args: []const []const u8, comptime fast_
851 if (fast_exit) std.process.exit(0);985 if (fast_exit) std.process.exit(0);
852}986}
853987
988/// Initializes a DepFile if requested by driver options.
989pub fn initDepFile(d: *Driver, source: Source, buf: *[std.fs.max_name_bytes]u8) Compilation.Error!?DepFile {
990 if (!d.dependencies.m and !d.dependencies.md) return null;
991 var dep_file: DepFile = .{
992 .target = undefined,
993 .format = d.dependencies.format,
994 };
995
996 if (d.dependencies.md and d.output_name != null) {
997 dep_file.target = d.output_name.?;
998 } else {
999 const args = .{
1000 std.fs.path.stem(source.path),
1001 d.comp.target.ofmt.fileExt(d.comp.target.cpu.arch),
1002 };
1003 dep_file.target = std.fmt.bufPrint(buf, "{s}{s}", args) catch
1004 return d.fatal("dependency file name too long for filesystem '{s}{s}'", args);
1005 }
1006
1007 try dep_file.addDependency(d.comp.gpa, source.path);
1008 errdefer comptime unreachable;
1009
1010 return dep_file;
1011}
1012
1013/// Returns name requested for the dependency file or null for stdout.
1014pub fn getDepFileName(d: *Driver, source: Source, buf: *[std.fs.max_name_bytes]u8) Compilation.Error!?[]const u8 {
1015 if (d.dependencies.file) |file| {
1016 if (std.mem.eql(u8, file, "-")) return null;
1017 return file;
1018 }
1019 if (!d.dependencies.md) {
1020 if (d.output_name) |name| return name;
1021 return null;
1022 }
1023
1024 const base_name = std.fs.path.stem(d.output_name orelse source.path);
1025 return std.fmt.bufPrint(buf, "{s}.d", .{base_name}) catch
1026 return d.fatal("dependency file name too long for filesystem: {s}.d", .{base_name});
1027}
1028
854fn getRandomFilename(d: *Driver, buf: *[std.fs.max_name_bytes]u8, extension: []const u8) ![]const u8 {1029fn getRandomFilename(d: *Driver, buf: *[std.fs.max_name_bytes]u8, extension: []const u8) ![]const u8 {
855 const random_bytes_count = 12;1030 const random_bytes_count = 12;
856 const sub_path_len = comptime std.fs.base64_encoder.calcSize(random_bytes_count);1031 const sub_path_len = comptime std.fs.base64_encoder.calcSize(random_bytes_count);
...@@ -925,6 +1100,12 @@ fn processSource(...@@ -925,6 +1100,12 @@ fn processSource(
925 var pp = try Preprocessor.initDefault(d.comp);1100 var pp = try Preprocessor.initDefault(d.comp);
926 defer pp.deinit();1101 defer pp.deinit();
9271102
1103 var name_buf: [std.fs.max_name_bytes]u8 = undefined;
1104 var opt_dep_file = try d.initDepFile(source, &name_buf);
1105 defer if (opt_dep_file) |*dep_file| dep_file.deinit(pp.gpa);
1106
1107 if (opt_dep_file) |*dep_file| pp.dep_file = dep_file;
1108
928 if (d.comp.langopts.ms_extensions) {1109 if (d.comp.langopts.ms_extensions) {
929 d.comp.ms_cwd_source_id = source.id;1110 d.comp.ms_cwd_source_id = source.id;
930 }1111 }
...@@ -943,6 +1124,22 @@ fn processSource(...@@ -943,6 +1124,22 @@ fn processSource(
9431124
944 try pp.preprocessSources(&.{ source, builtin, user_macros });1125 try pp.preprocessSources(&.{ source, builtin, user_macros });
9451126
1127 var writer_buf: [4096]u8 = undefined;
1128 if (opt_dep_file) |dep_file| {
1129 const dep_file_name = try d.getDepFileName(source, writer_buf[0..std.fs.max_name_bytes]);
1130
1131 const file = if (dep_file_name) |path|
1132 d.comp.cwd.createFile(path, .{}) catch |er|
1133 return d.fatal("unable to create dependency file '{s}': {s}", .{ path, errorDescription(er) })
1134 else
1135 std.fs.File.stdout();
1136 defer if (dep_file_name != null) file.close();
1137
1138 var file_writer = file.writer(&writer_buf);
1139 dep_file.write(&file_writer.interface) catch
1140 return d.fatal("unable to write dependency file: {s}", .{errorDescription(file_writer.err.?)});
1141 }
1142
946 if (d.only_preprocess) {1143 if (d.only_preprocess) {
947 d.printDiagnosticsStats();1144 d.printDiagnosticsStats();
9481145
...@@ -951,6 +1148,11 @@ fn processSource(...@@ -951,6 +1148,11 @@ fn processSource(
951 return;1148 return;
952 }1149 }
9531150
1151 if (d.dependencies.m and !d.dependencies.md) {
1152 if (fast_exit) std.process.exit(1); // Not linking, no need for cleanup.
1153 return;
1154 }
1155
954 const file = if (d.output_name) |some|1156 const file = if (d.output_name) |some|
955 d.comp.cwd.createFile(some, .{}) catch |er|1157 d.comp.cwd.createFile(some, .{}) catch |er|
956 return d.fatal("unable to create output file '{s}': {s}", .{ some, errorDescription(er) })1158 return d.fatal("unable to create output file '{s}': {s}", .{ some, errorDescription(er) })
...@@ -997,7 +1199,6 @@ fn processSource(...@@ -997,7 +1199,6 @@ fn processSource(
997 );1199 );
998 }1200 }
9991201
1000 var name_buf: [std.fs.max_name_bytes]u8 = undefined;
1001 const out_file_name = try d.getOutFileName(source, &name_buf);1202 const out_file_name = try d.getOutFileName(source, &name_buf);
10021203
1003 if (d.use_assembly_backend) {1204 if (d.use_assembly_backend) {
...@@ -1039,8 +1240,7 @@ fn processSource(...@@ -1039,8 +1240,7 @@ fn processSource(
1039 defer ir.deinit(d.comp.gpa);1240 defer ir.deinit(d.comp.gpa);
10401241
1041 if (d.verbose_ir) {1242 if (d.verbose_ir) {
1042 var stdout_buf: [4096]u8 = undefined;1243 var stdout = std.fs.File.stdout().writer(&writer_buf);
1043 var stdout = std.fs.File.stdout().writer(&stdout_buf);
1044 ir.dump(d.comp.gpa, d.detectConfig(stdout.file), &stdout.interface) catch {};1244 ir.dump(d.comp.gpa, d.detectConfig(stdout.file), &stdout.interface) catch {};
1045 }1245 }
10461246
...@@ -1065,8 +1265,7 @@ fn processSource(...@@ -1065,8 +1265,7 @@ fn processSource(
1065 return d.fatal("unable to create output file '{s}': {s}", .{ out_file_name, errorDescription(er) });1265 return d.fatal("unable to create output file '{s}': {s}", .{ out_file_name, errorDescription(er) });
1066 defer out_file.close();1266 defer out_file.close();
10671267
1068 var file_buf: [4096]u8 = undefined;1268 var file_writer = out_file.writer(&writer_buf);
1069 var file_writer = out_file.writer(&file_buf);
1070 obj.finish(&file_writer.interface) catch1269 obj.finish(&file_writer.interface) catch
1071 return d.fatal("could not output to object file '{s}': {s}", .{ out_file_name, errorDescription(file_writer.err.?) });1270 return d.fatal("could not output to object file '{s}': {s}", .{ out_file_name, errorDescription(file_writer.err.?) });
1072 }1271 }
...@@ -1236,7 +1435,7 @@ pub fn getPICMode(d: *Driver, lastpic: []const u8) Compilation.Error!struct { ba...@@ -1236,7 +1435,7 @@ pub fn getPICMode(d: *Driver, lastpic: []const u8) Compilation.Error!struct { ba
1236 } else {1435 } else {
1237 pic, pie = .{ false, false };1436 pic, pie = .{ false, false };
1238 if (target_util.isPS(target)) {1437 if (target_util.isPS(target)) {
1239 if (d.cmodel != .kernel) {1438 if (d.comp.cmodel != .kernel) {
1240 pic = true;1439 pic = true;
1241 try d.warn(1440 try d.warn(
1242 "option '{s}' was ignored by the {s} toolchain, using '-fPIC'",1441 "option '{s}' was ignored by the {s} toolchain, using '-fPIC'",
lib/compiler/aro/aro/Parser.zig+6-1
...@@ -6904,6 +6904,9 @@ pub const Result = struct {...@@ -6904,6 +6904,9 @@ pub const Result = struct {
6904 try p.err(l_paren, .invalid_union_cast, .{res.qt});6904 try p.err(l_paren, .invalid_union_cast, .{res.qt});
6905 return error.ParsingFailed;6905 return error.ParsingFailed;
6906 }6906 }
6907 } else if (dest_qt.eql(res.qt, p.comp)) {
6908 try p.err(l_paren, .cast_to_same_type, .{dest_qt});
6909 cast_kind = .no_op;
6907 } else {6910 } else {
6908 try p.err(l_paren, .invalid_cast_type, .{dest_qt});6911 try p.err(l_paren, .invalid_cast_type, .{dest_qt});
6909 return error.ParsingFailed;6912 return error.ParsingFailed;
...@@ -8720,7 +8723,9 @@ fn fieldAccess(...@@ -8720,7 +8723,9 @@ fn fieldAccess(
8720 };8723 };
87218724
8722 if (record_ty.layout == null) {8725 if (record_ty.layout == null) {
8723 std.debug.assert(is_ptr);8726 // Invalid use of incomplete type, error reported elsewhere.
8727 if (!is_ptr) return error.ParsingFailed;
8728
8724 try p.err(field_name_tok - 2, .deref_incomplete_ty_ptr, .{expr_base_qt});8729 try p.err(field_name_tok - 2, .deref_incomplete_ty_ptr, .{expr_base_qt});
8725 return error.ParsingFailed;8730 return error.ParsingFailed;
8726 }8731 }
lib/compiler/aro/aro/Parser/Diagnostic.zig+9-2
...@@ -694,6 +694,12 @@ pub const invalid_cast_type: Diagnostic = .{...@@ -694,6 +694,12 @@ pub const invalid_cast_type: Diagnostic = .{
694 .kind = .@"error",694 .kind = .@"error",
695};695};
696696
697pub const cast_to_same_type: Diagnostic = .{
698 .fmt = "C99 forbids casting nonscalar type {qt} to the same type",
699 .kind = .off,
700 .extension = true,
701};
702
697pub const invalid_cast_operand_type: Diagnostic = .{703pub const invalid_cast_operand_type: Diagnostic = .{
698 .fmt = "operand of type {qt} where arithmetic or pointer type is required",704 .fmt = "operand of type {qt} where arithmetic or pointer type is required",
699 .kind = .@"error",705 .kind = .@"error",
...@@ -1484,9 +1490,10 @@ pub const duplicate_member: Diagnostic = .{...@@ -1484,9 +1490,10 @@ pub const duplicate_member: Diagnostic = .{
1484};1490};
14851491
1486pub const binary_integer_literal: Diagnostic = .{1492pub const binary_integer_literal: Diagnostic = .{
1487 .fmt = "binary integer literals are a GNU extension",1493 .fmt = "binary integer literals are a C23 extension",
1494 .opt = .@"c23-extensions",
1488 .kind = .off,1495 .kind = .off,
1489 .opt = .@"gnu-binary-literal",1496 .suppress_version = .c23,
1490 .extension = true,1497 .extension = true,
1491};1498};
14921499
lib/compiler/aro/aro/Preprocessor.zig+20-10
...@@ -7,6 +7,7 @@ const Attribute = @import("Attribute.zig");...@@ -7,6 +7,7 @@ const Attribute = @import("Attribute.zig");
7const Compilation = @import("Compilation.zig");7const Compilation = @import("Compilation.zig");
8const Error = Compilation.Error;8const Error = Compilation.Error;
9const Diagnostics = @import("Diagnostics.zig");9const Diagnostics = @import("Diagnostics.zig");
10const DepFile = @import("DepFile.zig");
10const features = @import("features.zig");11const features = @import("features.zig");
11const Hideset = @import("Hideset.zig");12const Hideset = @import("Hideset.zig");
12const Parser = @import("Parser.zig");13const Parser = @import("Parser.zig");
...@@ -157,6 +158,9 @@ hideset: Hideset,...@@ -157,6 +158,9 @@ hideset: Hideset,
157source_epoch: SourceEpoch,158source_epoch: SourceEpoch,
158m_times: std.AutoHashMapUnmanaged(Source.Id, u64) = .{},159m_times: std.AutoHashMapUnmanaged(Source.Id, u64) = .{},
159160
161/// The dependency file tracking all includes and embeds.
162dep_file: ?*DepFile = null,
163
160pub const parse = Parser.parse;164pub const parse = Parser.parse;
161165
162pub const Linemarkers = enum {166pub const Linemarkers = enum {
...@@ -169,7 +173,7 @@ pub const Linemarkers = enum {...@@ -169,7 +173,7 @@ pub const Linemarkers = enum {
169};173};
170174
171pub fn init(comp: *Compilation, source_epoch: SourceEpoch) Preprocessor {175pub fn init(comp: *Compilation, source_epoch: SourceEpoch) Preprocessor {
172 const pp = Preprocessor{176 const pp: Preprocessor = .{
173 .comp = comp,177 .comp = comp,
174 .diagnostics = comp.diagnostics,178 .diagnostics = comp.diagnostics,
175 .gpa = comp.gpa,179 .gpa = comp.gpa,
...@@ -1614,13 +1618,18 @@ fn handleBuiltinMacro(pp: *Preprocessor, builtin: RawToken.Id, param_toks: []con...@@ -1614,13 +1618,18 @@ fn handleBuiltinMacro(pp: *Preprocessor, builtin: RawToken.Id, param_toks: []con
1614 else => unreachable,1618 else => unreachable,
1615 };1619 };
1616 const filename = include_str[1 .. include_str.len - 1];1620 const filename = include_str[1 .. include_str.len - 1];
1617 if (builtin == .macro_param_has_include or pp.include_depth == 0) {1621 const res = res: {
1618 if (builtin == .macro_param_has_include_next) {1622 if (builtin == .macro_param_has_include or pp.include_depth == 0) {
1619 try pp.err(src_loc, .include_next_outside_header, .{});1623 if (builtin == .macro_param_has_include_next) {
1624 try pp.err(src_loc, .include_next_outside_header, .{});
1625 }
1626 break :res try pp.comp.hasInclude(filename, src_loc.id, include_type, .first);
1620 }1627 }
1621 return pp.comp.hasInclude(filename, src_loc.id, include_type, .first);1628 break :res try pp.comp.hasInclude(filename, src_loc.id, include_type, .next);
1622 }1629 };
1623 return pp.comp.hasInclude(filename, src_loc.id, include_type, .next);1630
1631 if (res) if (pp.dep_file) |dep_file| try dep_file.addDependencyDupe(pp.gpa, pp.comp.arena, filename);
1632 return res;
1624 },1633 },
1625 else => unreachable,1634 else => unreachable,
1626 }1635 }
...@@ -1929,7 +1938,7 @@ fn expandFuncMacro(...@@ -1929,7 +1938,7 @@ fn expandFuncMacro(
1929 else => unreachable,1938 else => unreachable,
1930 };1939 };
1931 const filename = include_str[1 .. include_str.len - 1];1940 const filename = include_str[1 .. include_str.len - 1];
1932 const contents = (try pp.comp.findEmbed(filename, arg[0].loc.id, include_type, .limited(1))) orelse1941 const contents = (try pp.comp.findEmbed(filename, arg[0].loc.id, include_type, .limited(1), pp.dep_file)) orelse
1933 break :res not_found;1942 break :res not_found;
19341943
1935 defer pp.comp.gpa.free(contents);1944 defer pp.comp.gpa.free(contents);
...@@ -2537,7 +2546,7 @@ fn expandedSliceExtra(pp: *const Preprocessor, tok: anytype, macro_ws_handling:...@@ -2537,7 +2546,7 @@ fn expandedSliceExtra(pp: *const Preprocessor, tok: anytype, macro_ws_handling:
2537 if (tok.id.lexeme()) |some| {2546 if (tok.id.lexeme()) |some| {
2538 if (!tok.id.allowsDigraphs(pp.comp.langopts) and !(tok.id == .macro_ws and macro_ws_handling == .preserve_macro_ws)) return some;2547 if (!tok.id.allowsDigraphs(pp.comp.langopts) and !(tok.id == .macro_ws and macro_ws_handling == .preserve_macro_ws)) return some;
2539 }2548 }
2540 var tmp_tokenizer = Tokenizer{2549 var tmp_tokenizer: Tokenizer = .{
2541 .buf = pp.comp.getSource(tok.loc.id).buf,2550 .buf = pp.comp.getSource(tok.loc.id).buf,
2542 .langopts = pp.comp.langopts,2551 .langopts = pp.comp.langopts,
2543 .index = tok.loc.byte_offset,2552 .index = tok.loc.byte_offset,
...@@ -3087,7 +3096,7 @@ fn embed(pp: *Preprocessor, tokenizer: *Tokenizer) MacroError!void {...@@ -3087,7 +3096,7 @@ fn embed(pp: *Preprocessor, tokenizer: *Tokenizer) MacroError!void {
3087 }3096 }
3088 }3097 }
30893098
3090 const embed_bytes = (try pp.comp.findEmbed(filename, first.source, include_type, limit orelse .unlimited)) orelse3099 const embed_bytes = (try pp.comp.findEmbed(filename, first.source, include_type, limit orelse .unlimited, pp.dep_file)) orelse
3091 return pp.fatalNotFound(filename_tok, filename);3100 return pp.fatalNotFound(filename_tok, filename);
3092 defer pp.comp.gpa.free(embed_bytes);3101 defer pp.comp.gpa.free(embed_bytes);
30933102
...@@ -3143,6 +3152,7 @@ fn include(pp: *Preprocessor, tokenizer: *Tokenizer, which: Compilation.WhichInc...@@ -3143,6 +3152,7 @@ fn include(pp: *Preprocessor, tokenizer: *Tokenizer, which: Compilation.WhichInc
3143 if (pp.defines.contains(guard)) return;3152 if (pp.defines.contains(guard)) return;
3144 }3153 }
31453154
3155 if (pp.dep_file) |dep| try dep.addDependency(pp.gpa, new_source.path);
3146 if (pp.verbose) {3156 if (pp.verbose) {
3147 pp.verboseLog(first, "include file {s}", .{new_source.path});3157 pp.verboseLog(first, "include file {s}", .{new_source.path});
3148 }3158 }
lib/compiler/aro/backend/CodeGenOptions.zig+18-2
...@@ -11,7 +11,22 @@ pic_level: PicLevel,...@@ -11,7 +11,22 @@ pic_level: PicLevel,
11is_pie: bool,11is_pie: bool,
12optimization_level: OptimizationLevel,12optimization_level: OptimizationLevel,
13/// Generate debug information13/// Generate debug information
14debug: bool,14debug: DebugFormat,
15dwarf_version: DwarfVersion,
16
17pub const DebugFormat = union(enum) {
18 strip,
19 dwarf: std.dwarf.Format,
20 code_view,
21};
22
23pub const DwarfVersion = enum(u3) {
24 @"0" = 0,
25 @"2" = 2,
26 @"3" = 3,
27 @"4" = 4,
28 @"5" = 5,
29};
1530
16pub const PicLevel = enum(u8) {31pub const PicLevel = enum(u8) {
17 /// Do not generate position-independent code32 /// Do not generate position-independent code
...@@ -60,5 +75,6 @@ pub const default: @This() = .{...@@ -60,5 +75,6 @@ pub const default: @This() = .{
60 .pic_level = .none,75 .pic_level = .none,
61 .is_pie = false,76 .is_pie = false,
62 .optimization_level = .@"0",77 .optimization_level = .@"0",
63 .debug = false,78 .debug = .strip,
79 .dwarf_version = .@"0",
64};80};
lib/compiler/aro/include/float.h created+126
...@@ -0,0 +1,126 @@
1/* <float.h> for the Aro C compiler */
2
3#pragma once
4
5#undef FLT_RADIX
6#define FLT_RADIX __FLT_RADIX__
7
8#undef FLT_MANT_DIG
9#define FLT_MANT_DIG __FLT_MANT_DIG__
10
11#undef DBL_MANT_DIG
12#define DBL_MANT_DIG __DBL_MANT_DIG__
13
14#undef LDBL_MANT_DIG
15#define LDBL_MANT_DIG __LDBL_MANT_DIG__
16
17#if __STDC_VERSION__ >= 199901L
18#undef FLT_EVAL_METHOD
19#define FLT_EVAL_METHOD __FLT_EVAL_METHOD__
20
21#undef DECIMAL_DIG
22#define DECIMAL_DIG __DECIMAL_DIG__
23#endif /* __STDC_VERSION__ >= 199901L */
24
25#undef FLT_DIG
26#define FLT_DIG __FLT_DIG__
27
28#undef DBL_DIG
29#define DBL_DIG __DBL_DIG__
30
31#undef LDBL_DIG
32#define LDBL_DIG __LDBL_DIG__
33
34#undef FLT_MIN_EXP
35#define FLT_MIN_EXP __FLT_MIN_EXP__
36
37#undef DBL_MIN_EXP
38#define DBL_MIN_EXP __DBL_MIN_EXP__
39
40#undef LDBL_MIN_EXP
41#define LDBL_MIN_EXP __LDBL_MIN_EXP__
42
43#undef FLT_MIN_10_EXP
44#define FLT_MIN_10_EXP __FLT_MIN_10_EXP__
45
46#undef DBL_MIN_10_EXP
47#define DBL_MIN_10_EXP __DBL_MIN_10_EXP__
48
49#undef LDBL_MIN_10_EXP
50#define LDBL_MIN_10_EXP __LDBL_MIN_10_EXP__
51
52#undef FLT_MAX_EXP
53#define FLT_MAX_EXP __FLT_MAX_EXP__
54
55#undef DBL_MAX_EXP
56#define DBL_MAX_EXP __DBL_MAX_EXP__
57
58#undef LDBL_MAX_EXP
59#define LDBL_MAX_EXP __LDBL_MAX_EXP__
60
61#undef FLT_MAX_10_EXP
62#define FLT_MAX_10_EXP __FLT_MAX_10_EXP__
63
64#undef DBL_MAX_10_EXP
65#define DBL_MAX_10_EXP __DBL_MAX_10_EXP__
66
67#undef LDBL_MAX_10_EXP
68#define LDBL_MAX_10_EXP __LDBL_MAX_10_EXP__
69
70#undef FLT_MAX
71#define FLT_MAX __FLT_MAX__
72
73#undef DBL_MAX
74#define DBL_MAX __DBL_MAX__
75
76#undef LDBL_MAX
77#define LDBL_MAX __LDBL_MAX__
78
79#undef FLT_EPSILON
80#define FLT_EPSILON __FLT_EPSILON__
81
82#undef DBL_EPSILON
83#define DBL_EPSILON __DBL_EPSILON__
84
85#undef LDBL_EPSILON
86#define LDBL_EPSILON __LDBL_EPSILON__
87
88#undef FLT_MIN
89#define FLT_MIN __FLT_MIN__
90
91#undef DBL_MIN
92#define DBL_MIN __DBL_MIN__
93
94#undef LDBL_MIN
95#define LDBL_MIN __LDBL_MIN__
96
97#if __STDC_VERSION__ >= 201112L
98
99#undef FLT_TRUE_MIN
100#define FLT_TRUE_MIN __FLT_DENORM_MIN__
101
102#undef DBL_TRUE_MIN
103#define DBL_TRUE_MIN __DBL_DENORM_MIN__
104
105#undef LDBL_TRUE_MIN
106#define LDBL_TRUE_MIN __LDBL_DENORM_MIN__
107
108#undef FLT_DECIMAL_DIG
109#define FLT_DECIMAL_DIG __FLT_DECIMAL_DIG__
110
111#undef DBL_DECIMAL_DIG
112#define DBL_DECIMAL_DIG __DBL_DECIMAL_DIG__
113
114#undef LDBL_DECIMAL_DIG
115#define LDBL_DECIMAL_DIG __LDBL_DECIMAL_DIG__
116
117#undef FLT_HAS_SUBNORM
118#define FLT_HAS_SUBNORM __FLT_HAS_DENORM__
119
120#undef DBL_HAS_SUBNORM
121#define DBL_HAS_SUBNORM __DBL_HAS_DENORM__
122
123#undef LDBL_HAS_SUBNORM
124#define LDBL_HAS_SUBNORM __LDBL_HAS_DENORM__
125
126#endif /* __STDC_VERSION__ >= 201112L */
lib/compiler/aro/include/iso646.h created+15
...@@ -0,0 +1,15 @@
1/* <iso646.h> for the Aro C compiler */
2
3#pragma once
4
5#define and &&
6#define and_eq &=
7#define bitand &
8#define bitor |
9#define compl ~
10#define not !
11#define not_eq !=
12#define or ||
13#define or_eq |=
14#define xor ^
15#define xor_eq ^=
lib/compiler/aro/include/limits.h created+124
...@@ -0,0 +1,124 @@
1/* <limits.h> for the Aro C compiler */
2
3#pragma once
4
5/* GlibC will try to include_next GCC's limits.h which will fail.
6 Define _GCC_LIMITS_H_ to prevent it. */
7#if defined __GNUC__ && !defined _GCC_LIMITS_H_
8#define _GCC_LIMITS_H_
9#endif
10
11/* Include the system's limits.h */
12#if __STDC_HOSTED__ && __has_include_next(<limits.h>)
13#include_next <limits.h>
14#endif
15
16#undef SCHAR_MAX
17#define SCHAR_MAX __SCHAR_MAX__
18
19#undef SHRT_MAX
20#define SHRT_MAX __SHRT_MAX__
21
22#undef INT_MAX
23#define INT_MAX __INT_MAX__
24
25#undef LONG_MAX
26#define LONG_MAX __LONG_MAX__
27
28#undef SCHAR_MIN
29#define SCHAR_MIN (-__SCHAR_MAX__-1)
30
31#undef SHRT_MIN
32#define SHRT_MIN (-__SHRT_MAX__ -1)
33
34#undef INT_MIN
35#define INT_MIN (-__INT_MAX__ -1)
36
37#undef LONG_MIN
38#define LONG_MIN (-__LONG_MAX__ -1L)
39
40#undef UCHAR_MAX
41#define UCHAR_MAX (__SCHAR_MAX__*2 +1)
42
43#undef USHRT_MAX
44#define USHRT_MAX (__SHRT_MAX__ *2 +1)
45
46#undef UINT_MAX
47#define UINT_MAX (__INT_MAX__ *2U +1U)
48
49#undef ULONG_MAX
50#define ULONG_MAX (__LONG_MAX__ *2UL+1UL)
51
52#ifndef MB_LEN_MAX
53#define MB_LEN_MAX 1
54#endif
55
56#undef CHAR_BIT
57#define CHAR_BIT __CHAR_BIT__
58
59#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
60
61#undef BOOL_WIDTH
62#define BOOL_WIDTH __BOOL_WIDTH__
63
64#undef CHAR_WIDTH
65#define CHAR_WIDTH CHAR_BIT
66
67#undef SCHAR_WIDTH
68#define SCHAR_WIDTH CHAR_BIT
69
70#undef UCHAR_WIDTH
71#define UCHAR_WIDTH CHAR_BIT
72
73#undef USHRT_WIDTH
74#define USHRT_WIDTH __SHRT_WIDTH__
75
76#undef SHRT_WIDTH
77#define SHRT_WIDTH __SHRT_WIDTH__
78
79#undef UINT_WIDTH
80#define UINT_WIDTH __INT_WIDTH__
81
82#undef INT_WIDTH
83#define INT_WIDTH __INT_WIDTH__
84
85#undef ULONG_WIDTH
86#define ULONG_WIDTH __LONG_WIDTH__
87
88#undef LONG_WIDTH
89#define LONG_WIDTH __LONG_WIDTH__
90
91#undef ULLONG_WIDTH
92#define ULLONG_WIDTH __LLONG_WIDTH__
93
94#undef LLONG_WIDTH
95#define LLONG_WIDTH __LLONG_WIDTH__
96
97#undef BITINT_MAXWIDTH
98#define BITINT_MAXWIDTH __BITINT_MAXWIDTH__
99
100#endif /* defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L */
101
102#undef CHAR_MIN
103#undef CHAR_MAX
104#ifdef __CHAR_UNSIGNED__
105#define CHAR_MIN 0
106#define CHAR_MAX UCHAR_MAX
107#else
108#define CHAR_MIN SCHAR_MIN
109#define CHAR_MAX __SCHAR_MAX__
110#endif
111
112#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
113
114#undef LLONG_MIN
115#define LLONG_MIN (-__LONG_LONG_MAX__-1LL)
116
117#undef LLONG_MAX
118#define LLONG_MAX __LONG_LONG_MAX__
119
120#undef ULLONG_MAX
121#define ULLONG_MAX (__LONG_LONG_MAX__*2ULL+1ULL)
122
123#endif
124
lib/compiler/aro/include/stdalign.h created+11
...@@ -0,0 +1,11 @@
1/* <stdalign.h> for the Aro C compiler */
2
3#pragma once
4#if __STDC_VERSION__ < 202311L
5
6#define alignas _Alignas
7#define alignof _Alignof
8
9#define __alignas_is_defined 1
10#define __alignof_is_defined 1
11#endif
lib/compiler/aro/include/stdarg.h created+28
...@@ -0,0 +1,28 @@
1/* <stdarg.h> for the Aro C compiler */
2
3#pragma once
4/* Todo: Set to 202311L once header is compliant with C23 */
5#define __STDC_VERSION_STDARG_H__ 0
6
7typedef __builtin_va_list va_list;
8#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202000L
9/* C23 no longer requires the second parameter */
10#define va_start(ap, ...) __builtin_va_start(ap, __VA_ARGS__)
11#else
12#define va_start(ap, param) __builtin_va_start(ap, param)
13#endif
14#define va_end(ap) __builtin_va_end(ap)
15#define va_arg(ap, type) __builtin_va_arg(ap, type)
16
17/* GCC and Clang always define __va_copy */
18#define __va_copy(d, s) __builtin_va_copy(d, s)
19
20/* but va_copy only on c99+ or when strict ansi mode is turned off */
21#if __STDC_VERSION__ >= 199901L || !defined(__STRICT_ANSI__)
22#define va_copy(d, s) __builtin_va_copy(d, s)
23#endif
24
25#ifndef __GNUC_VA_LIST
26#define __GNUC_VA_LIST 1
27typedef __builtin_va_list __gnuc_va_list;
28#endif
lib/compiler/aro/include/stdatomic.h created+138
...@@ -0,0 +1,138 @@
1/* <stdatomic.h> for the Aro C compiler */
2
3#pragma once
4
5#define __STDC_VERSION_STDATOMIC_H__ 202311L
6
7#if __STDC_HOSTED__ && __has_include_next(<stdatomic.h>)
8#include_next <stdatomic.h>
9#else
10
11#include <stddef.h>
12#include <stdint.h>
13
14#define ATOMIC_BOOL_LOCK_FREE __ATOMIC_BOOL_LOCK_FREE
15#define ATOMIC_CHAR_LOCK_FREE __ATOMIC_CHAR_LOCK_FREE
16#define ATOMIC_CHAR16_T_LOCK_FREE __ATOMIC_CHAR16_T_LOCK_FREE
17#define ATOMIC_CHAR32_T_LOCK_FREE __ATOMIC_CHAR32_T_LOCK_FREE
18#define ATOMIC_WCHAR_T_LOCK_FREE __ATOMIC_WCHAR_T_LOCK_FREE
19#define ATOMIC_SHORT_LOCK_FREE __ATOMIC_SHORT_LOCK_FREE
20#define ATOMIC_INT_LOCK_FREE __ATOMIC_INT_LOCK_FREE
21#define ATOMIC_LONG_LOCK_FREE __ATOMIC_LONG_LOCK_FREE
22#define ATOMIC_LLONG_LOCK_FREE __ATOMIC_LLONG_LOCK_FREE
23#define ATOMIC_POINTER_LOCK_FREE __ATOMIC_POINTER_LOCK_FREE
24#if defined(__ATOMIC_CHAR8_T_LOCK_FREE)
25#define ATOMIC_CHAR8_T_LOCK_FREE __ATOMIC_CHAR8_T_LOCK_FREE
26#endif
27
28#if __STDC_VERSION__ < 202311L
29/* ATOMIC_VAR_INIT was removed in C23 */
30#define ATOMIC_VAR_INIT(value) (value)
31#endif
32
33#define atomic_init __c11_atomic_init
34
35typedef enum memory_order {
36 memory_order_relaxed = __ATOMIC_RELAXED,
37 memory_order_consume = __ATOMIC_CONSUME,
38 memory_order_acquire = __ATOMIC_ACQUIRE,
39 memory_order_release = __ATOMIC_RELEASE,
40 memory_order_acq_rel = __ATOMIC_ACQ_REL,
41 memory_order_seq_cst = __ATOMIC_SEQ_CST
42} memory_order;
43
44#define kill_dependency(y) (y)
45
46void atomic_thread_fence(memory_order);
47void atomic_signal_fence(memory_order);
48
49#define atomic_thread_fence(order) __c11_atomic_thread_fence(order)
50#define atomic_signal_fence(order) __c11_atomic_signal_fence(order)
51
52#define atomic_is_lock_free(obj) __c11_atomic_is_lock_free(sizeof(*(obj)))
53
54typedef _Atomic(_Bool) atomic_bool;
55typedef _Atomic(char) atomic_char;
56typedef _Atomic(signed char) atomic_schar;
57typedef _Atomic(unsigned char) atomic_uchar;
58typedef _Atomic(short) atomic_short;
59typedef _Atomic(unsigned short) atomic_ushort;
60typedef _Atomic(int) atomic_int;
61typedef _Atomic(unsigned int) atomic_uint;
62typedef _Atomic(long) atomic_long;
63typedef _Atomic(unsigned long) atomic_ulong;
64typedef _Atomic(long long) atomic_llong;
65typedef _Atomic(unsigned long long) atomic_ullong;
66typedef _Atomic(uint_least16_t) atomic_char16_t;
67typedef _Atomic(uint_least32_t) atomic_char32_t;
68typedef _Atomic(wchar_t) atomic_wchar_t;
69typedef _Atomic(int_least8_t) atomic_int_least8_t;
70typedef _Atomic(uint_least8_t) atomic_uint_least8_t;
71typedef _Atomic(int_least16_t) atomic_int_least16_t;
72typedef _Atomic(uint_least16_t) atomic_uint_least16_t;
73typedef _Atomic(int_least32_t) atomic_int_least32_t;
74typedef _Atomic(uint_least32_t) atomic_uint_least32_t;
75typedef _Atomic(int_least64_t) atomic_int_least64_t;
76typedef _Atomic(uint_least64_t) atomic_uint_least64_t;
77typedef _Atomic(int_fast8_t) atomic_int_fast8_t;
78typedef _Atomic(uint_fast8_t) atomic_uint_fast8_t;
79typedef _Atomic(int_fast16_t) atomic_int_fast16_t;
80typedef _Atomic(uint_fast16_t) atomic_uint_fast16_t;
81typedef _Atomic(int_fast32_t) atomic_int_fast32_t;
82typedef _Atomic(uint_fast32_t) atomic_uint_fast32_t;
83typedef _Atomic(int_fast64_t) atomic_int_fast64_t;
84typedef _Atomic(uint_fast64_t) atomic_uint_fast64_t;
85typedef _Atomic(intptr_t) atomic_intptr_t;
86typedef _Atomic(uintptr_t) atomic_uintptr_t;
87typedef _Atomic(size_t) atomic_size_t;
88typedef _Atomic(ptrdiff_t) atomic_ptrdiff_t;
89typedef _Atomic(intmax_t) atomic_intmax_t;
90typedef _Atomic(uintmax_t) atomic_uintmax_t;
91
92#define atomic_store(object, desired) __c11_atomic_store(object, desired, __ATOMIC_SEQ_CST)
93#define atomic_store_explicit __c11_atomic_store
94
95#define atomic_load(object) __c11_atomic_load(object, __ATOMIC_SEQ_CST)
96#define atomic_load_explicit __c11_atomic_load
97
98#define atomic_exchange(object, desired) __c11_atomic_exchange(object, desired, __ATOMIC_SEQ_CST)
99#define atomic_exchange_explicit __c11_atomic_exchange
100
101#define atomic_compare_exchange_strong(object, expected, desired) __c11_atomic_compare_exchange_strong(object, expected, desired, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)
102#define atomic_compare_exchange_strong_explicit __c11_atomic_compare_exchange_strong
103
104#define atomic_compare_exchange_weak(object, expected, desired) __c11_atomic_compare_exchange_weak(object, expected, desired, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)
105#define atomic_compare_exchange_weak_explicit __c11_atomic_compare_exchange_weak
106
107#define atomic_fetch_add(object, operand) __c11_atomic_fetch_add(object, operand, __ATOMIC_SEQ_CST)
108#define atomic_fetch_add_explicit __c11_atomic_fetch_add
109
110#define atomic_fetch_sub(object, operand) __c11_atomic_fetch_sub(object, operand, __ATOMIC_SEQ_CST)
111#define atomic_fetch_sub_explicit __c11_atomic_fetch_sub
112
113#define atomic_fetch_or(object, operand) __c11_atomic_fetch_or(object, operand, __ATOMIC_SEQ_CST)
114#define atomic_fetch_or_explicit __c11_atomic_fetch_or
115
116#define atomic_fetch_xor(object, operand) __c11_atomic_fetch_xor(object, operand, __ATOMIC_SEQ_CST)
117#define atomic_fetch_xor_explicit __c11_atomic_fetch_xor
118
119#define atomic_fetch_and(object, operand) __c11_atomic_fetch_and(object, operand, __ATOMIC_SEQ_CST)
120#define atomic_fetch_and_explicit __c11_atomic_fetch_and
121
122typedef struct atomic_flag { atomic_bool _Value; } atomic_flag;
123
124#define ATOMIC_FLAG_INIT { 0 }
125
126_Bool atomic_flag_test_and_set(volatile atomic_flag *);
127_Bool atomic_flag_test_and_set_explicit(volatile atomic_flag *, memory_order);
128void atomic_flag_clear(volatile atomic_flag *);
129void atomic_flag_clear_explicit(volatile atomic_flag *, memory_order);
130
131#define atomic_flag_test_and_set(object) __c11_atomic_exchange(&(object)->_Value, 1, __ATOMIC_SEQ_CST)
132#define atomic_flag_test_and_set_explicit(object, order) __c11_atomic_exchange(&(object)->_Value, 1, order)
133
134#define atomic_flag_clear(object) __c11_atomic_store(&(object)->_Value, 0, __ATOMIC_SEQ_CST)
135#define atomic_flag_clear_explicit(object, order) __c11_atomic_store(&(object)->_Value, 0, order)
136
137
138#endif
lib/compiler/aro/include/stdbool.h created+13
...@@ -0,0 +1,13 @@
1/* <stdbool.h> for the Aro C compiler */
2
3#pragma once
4
5#if __STDC_VERSION__ < 202311L
6#define bool _Bool
7
8#define true 1
9#define false 0
10
11#define __bool_true_false_are_defined 1
12
13#endif
lib/compiler/aro/include/stdckdint.h created+9
...@@ -0,0 +1,9 @@
1/* <stdckdint.h> for the Aro C compiler */
2
3#pragma once
4
5#define __STDC_VERSION_STDCKDINT_H__ 202311L
6
7#define ckd_add(result, a, b) __builtin_add_overflow(a, b, result)
8#define ckd_sub(result, a, b) __builtin_sub_overflow(a, b, result)
9#define ckd_mul(result, a, b) __builtin_mul_overflow(a, b, result)
lib/compiler/aro/include/stddef.h created+31
...@@ -0,0 +1,31 @@
1/* <stddef.h> for the Aro C compiler */
2
3#pragma once
4
5#define __STDC_VERSION_STDDEF_H__ 202311L
6
7typedef __PTRDIFF_TYPE__ ptrdiff_t;
8typedef __SIZE_TYPE__ size_t;
9typedef __WCHAR_TYPE__ wchar_t;
10
11/* define max_align_t to match GCC and Clang */
12typedef struct {
13 long long __aro_max_align_ll;
14 long double __aro_max_align_ld;
15} max_align_t;
16
17#define NULL ((void*)0)
18#define offsetof(T, member) __builtin_offsetof(T, member)
19
20#if __STDC_VERSION__ >= 202311L
21# pragma GCC diagnostic push
22# pragma GCC diagnostic ignored "-Wpre-c23-compat"
23 typedef typeof(nullptr) nullptr_t;
24# pragma GCC diagnostic pop
25
26# if defined unreachable
27# error unreachable() is a standard macro in C23
28# else
29# define unreachable() __builtin_unreachable()
30# endif
31#endif
lib/compiler/aro/include/stdint.h created+289
...@@ -0,0 +1,289 @@
1/* <stdint.h> for the Aro C compiler */
2
3#pragma once
4
5
6#if __STDC_HOSTED__ && __has_include_next(<stdint.h>)
7
8# include_next <stdint.h>
9
10#else
11
12#define __stdint_int_c_cat(X, Y) X ## Y
13#define __stdint_int_c(V, SUFFIX) __stdint_int_c_cat(V, SUFFIX)
14#define __stdint_uint_c(V, SUFFIX) __stdint_int_c_cat(V##U, SUFFIX)
15
16#define INTPTR_MIN (-__INTPTR_MAX__-1)
17#define INTPTR_MAX __INTPTR_MAX__
18#define UINTPTR_MAX __UINTPTR_MAX__
19#define PTRDIFF_MIN (-__PTRDIFF_MAX__-1)
20#define PTRDIFF_MAX __PTRDIFF_MAX__
21#define SIZE_MAX __SIZE_MAX__
22#define INTMAX_MIN (-__INTMAX_MAX__-1)
23#define INTMAX_MAX __INTMAX_MAX__
24#define UINTMAX_MAX __UINTMAX_MAX__
25#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
26# define INTPTR_WIDTH __INTPTR_WIDTH__
27# define UINTPTR_WIDTH __UINTPTR_WIDTH__
28# define INTMAX_WIDTH __INTMAX_WIDTH__
29# define UINTMAX_WIDTH __UINTMAX_WIDTH__
30# define PTRDIFF_WIDTH __PTRDIFF_WIDTH__
31# define SIZE_WIDTH __SIZE_WIDTH__
32# define WCHAR_WIDTH __WCHAR_WIDTH__
33#endif
34
35typedef __INTMAX_TYPE__ intmax_t;
36typedef __UINTMAX_TYPE__ uintmax_t;
37
38#ifndef _INTPTR_T
39# ifndef __intptr_t_defined
40 typedef __INTPTR_TYPE__ intptr_t;
41# define __intptr_t_defined
42# define _INTPTR_T
43# endif
44#endif
45
46#ifndef _UINTPTR_T
47 typedef __UINTPTR_TYPE__ uintptr_t;
48# define _UINTPTR_T
49#endif
50
51
52#ifdef __INT64_TYPE__
53# ifndef __int8_t_defined /* glibc sys/types.h also defines int64_t*/
54 typedef __INT64_TYPE__ int64_t;
55# endif /* __int8_t_defined */
56 typedef __UINT64_TYPE__ uint64_t;
57
58# undef __int64_c_suffix
59# undef __int32_c_suffix
60# undef __int16_c_suffix
61# undef __int8_c_suffix
62# ifdef __INT64_C_SUFFIX__
63# define __int64_c_suffix __INT64_C_SUFFIX__
64# define __int32_c_suffix __INT64_C_SUFFIX__
65# define __int16_c_suffix __INT64_C_SUFFIX__
66# define __int8_c_suffix __INT64_C_SUFFIX__
67# endif /* __INT64_C_SUFFIX__ */
68
69# ifdef __int64_c_suffix
70# define INT64_C(v) (__stdint_int_c(v, __int64_c_suffix))
71# define UINT64_C(v) (__stdint_uint_c(v, __int64_c_suffix))
72# else
73# define INT64_C(v) (v)
74# define UINT64_C(v) (v ## U)
75# endif /* __int64_c_suffix */
76
77# define INT64_MAX INT64_C( 9223372036854775807)
78# define INT64_MIN (-INT64_C( 9223372036854775807)-1)
79# define UINT64_MAX UINT64_C(18446744073709551615)
80# if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
81# define UINT64_WIDTH 64
82# define INT64_WIDTH UINT64_WIDTH
83# endif /* __STDC_VERSION__ */
84
85#endif /* __INT64_TYPE__ */
86
87#ifdef __INT32_TYPE__
88# ifndef __int8_t_defined /* glibc sys/types.h also defines int32_t*/
89 typedef __INT32_TYPE__ int32_t;
90# endif /* __int8_t_defined */
91 typedef __UINT32_TYPE__ uint32_t;
92
93# undef __int32_c_suffix
94# undef __int16_c_suffix
95# undef __int8_c_suffix
96# ifdef __INT32_C_SUFFIX__
97# define __int32_c_suffix __INT32_C_SUFFIX__
98# define __int16_c_suffix __INT32_C_SUFFIX__
99# define __int8_c_suffix __INT32_C_SUFFIX__
100# endif /* __INT32_C_SUFFIX__ */
101
102# ifdef __int32_c_suffix
103# define INT32_C(v) (__stdint_int_c(v, __int32_c_suffix))
104# define UINT32_C(v) (__stdint_uint_c(v, __int32_c_suffix))
105# else
106# define INT32_C(v) (v)
107# define UINT32_C(v) (v ## U)
108# endif /* __int32_c_suffix */
109
110# define INT32_MAX INT32_C( 2147483647)
111# define INT32_MIN (-INT32_C( 2147483647)-1)
112# define UINT32_MAX UINT32_C(4294967295)
113# if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
114# define UINT32_WIDTH 32
115# define INT32_WIDTH UINT32_WIDTH
116# endif /* __STDC_VERSION__ */
117
118#endif /* __INT32_TYPE__ */
119
120#ifdef __INT16_TYPE__
121# ifndef __int8_t_defined /* glibc sys/types.h also defines int16_t*/
122 typedef __INT16_TYPE__ int16_t;
123# endif /* __int8_t_defined */
124 typedef __UINT16_TYPE__ uint16_t;
125
126# undef __int16_c_suffix
127# undef __int8_c_suffix
128# ifdef __INT16_C_SUFFIX__
129# define __int16_c_suffix __INT16_C_SUFFIX__
130# define __int8_c_suffix __INT16_C_SUFFIX__
131# endif /* __INT16_C_SUFFIX__ */
132
133# ifdef __int16_c_suffix
134# define INT16_C(v) (__stdint_int_c(v, __int16_c_suffix))
135# define UINT16_C(v) (__stdint_uint_c(v, __int16_c_suffix))
136# else
137# define INT16_C(v) (v)
138# define UINT16_C(v) (v ## U)
139# endif /* __int16_c_suffix */
140
141# define INT16_MAX INT16_C( 32767)
142# define INT16_MIN (-INT16_C( 32767)-1)
143# define UINT16_MAX UINT16_C(65535)
144# if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
145# define UINT16_WIDTH 16
146# define INT16_WIDTH UINT16_WIDTH
147# endif /* __STDC_VERSION__ */
148
149#endif /* __INT16_TYPE__ */
150
151#ifdef __INT8_TYPE__
152# ifndef __int8_t_defined /* glibc sys/types.h also defines int8_t*/
153 typedef __INT8_TYPE__ int8_t;
154# endif /* __int8_t_defined */
155 typedef __UINT8_TYPE__ uint8_t;
156
157# undef __int8_c_suffix
158# ifdef __INT8_C_SUFFIX__
159# define __int8_c_suffix __INT8_C_SUFFIX__
160# endif /* __INT8_C_SUFFIX__ */
161
162# ifdef __int8_c_suffix
163# define INT8_C(v) (__stdint_int_c(v, __int8_c_suffix))
164# define UINT8_C(v) (__stdint_uint_c(v, __int8_c_suffix))
165# else
166# define INT8_C(v) (v)
167# define UINT8_C(v) (v ## U)
168# endif /* __int8_c_suffix */
169
170# define INT8_MAX INT8_C(127)
171# define INT8_MIN (-INT8_C(127)-1)
172# define UINT8_MAX UINT8_C(255)
173# if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
174# define UINT8_WIDTH 8
175# define INT8_WIDTH UINT8_WIDTH
176# endif /* __STDC_VERSION__ */
177
178#endif /* __INT8_TYPE__ */
179
180typedef __INT_LEAST64_TYPE__ int_least64_t;
181typedef __INT_LEAST32_TYPE__ int_least32_t;
182typedef __INT_LEAST16_TYPE__ int_least16_t;
183typedef __INT_LEAST8_TYPE__ int_least8_t;
184
185typedef __UINT_LEAST64_TYPE__ uint_least64_t;
186typedef __UINT_LEAST32_TYPE__ uint_least32_t;
187typedef __UINT_LEAST16_TYPE__ uint_least16_t;
188typedef __UINT_LEAST8_TYPE__ uint_least8_t;
189
190#define INT_LEAST8_MAX __INT_LEAST8_MAX__
191#define INT_LEAST8_MIN (-__INT_LEAST8_MAX__-1)
192#define UINT_LEAST8_MAX __UINT_LEAST8_MAX__
193
194#define INT_LEAST16_MAX __INT_LEAST16_MAX__
195#define INT_LEAST16_MIN (-__INT_LEAST16_MAX__-1)
196#define UINT_LEAST16_MAX __UINT_LEAST16_MAX__
197
198#define INT_LEAST32_MAX __INT_LEAST32_MAX__
199#define INT_LEAST32_MIN (-__INT_LEAST32_MAX__-1)
200#define UINT_LEAST32_MAX __UINT_LEAST32_MAX__
201
202#define INT_LEAST64_MAX __INT_LEAST64_MAX__
203#define INT_LEAST64_MIN (-__INT_LEAST64_MAX__-1)
204#define UINT_LEAST64_MAX __UINT_LEAST64_MAX__
205
206
207typedef __INT_FAST64_TYPE__ int_fast64_t;
208typedef __INT_FAST32_TYPE__ int_fast32_t;
209typedef __INT_FAST16_TYPE__ int_fast16_t;
210typedef __INT_FAST8_TYPE__ int_fast8_t;
211
212typedef __UINT_FAST64_TYPE__ uint_fast64_t;
213typedef __UINT_FAST32_TYPE__ uint_fast32_t;
214typedef __UINT_FAST16_TYPE__ uint_fast16_t;
215typedef __UINT_FAST8_TYPE__ uint_fast8_t;
216
217#define INT_FAST8_MAX __INT_FAST8_MAX__
218#define INT_FAST8_MIN (-__INT_FAST8_MAX__-1)
219#define UINT_FAST8_MAX __UINT_FAST8_MAX__
220
221#define INT_FAST16_MAX __INT_FAST16_MAX__
222#define INT_FAST16_MIN (-__INT_FAST16_MAX__-1)
223#define UINT_FAST16_MAX __UINT_FAST16_MAX__
224
225#define INT_FAST32_MAX __INT_FAST32_MAX__
226#define INT_FAST32_MIN (-__INT_FAST32_MAX__-1)
227#define UINT_FAST32_MAX __UINT_FAST32_MAX__
228
229#define INT_FAST64_MAX __INT_FAST64_MAX__
230#define INT_FAST64_MIN (-__INT_FAST64_MAX__-1)
231#define UINT_FAST64_MAX __UINT_FAST64_MAX__
232
233
234#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
235
236#define INT_FAST8_WIDTH __INT_FAST8_WIDTH__
237#define UINT_FAST8_WIDTH __INT_FAST8_WIDTH__
238#define INT_LEAST8_WIDTH __INT_LEAST8_WIDTH__
239#define UINT_LEAST8_WIDTH __INT_LEAST8_WIDTH__
240
241#define INT_FAST16_WIDTH __INT_FAST16_WIDTH__
242#define UINT_FAST16_WIDTH __INT_FAST16_WIDTH__
243#define INT_LEAST16_WIDTH __INT_LEAST16_WIDTH__
244#define UINT_LEAST16_WIDTH __INT_LEAST16_WIDTH__
245
246#define INT_FAST32_WIDTH __INT_FAST32_WIDTH__
247#define UINT_FAST32_WIDTH __INT_FAST32_WIDTH__
248#define INT_LEAST32_WIDTH __INT_LEAST32_WIDTH__
249#define UINT_LEAST32_WIDTH __INT_LEAST32_WIDTH__
250
251#define INT_FAST64_WIDTH __INT_FAST64_WIDTH__
252#define UINT_FAST64_WIDTH __INT_FAST64_WIDTH__
253#define INT_LEAST64_WIDTH __INT_LEAST64_WIDTH__
254#define UINT_LEAST64_WIDTH __INT_LEAST64_WIDTH__
255
256#endif
257
258#ifdef __SIZEOF_INT128__
259typedef signed __int128 int128_t;
260typedef unsigned __int128 uint128_t;
261typedef signed __int128 int_fast128_t;
262typedef unsigned __int128 uint_fast128_t;
263typedef signed __int128 int_least128_t;
264typedef unsigned __int128 uint_least128_t;
265# define UINT128_MAX ((uint128_t)-1)
266# define INT128_MAX ((int128_t)+(UINT128_MAX/2))
267# define INT128_MIN (-INT128_MAX-1)
268# define UINT_LEAST128_MAX UINT128_MAX
269# define INT_LEAST128_MAX INT128_MAX
270# define INT_LEAST128_MIN INT128_MIN
271# define UINT_FAST128_MAX UINT128_MAX
272# define INT_FAST128_MAX INT128_MAX
273# define INT_FAST128_MIN INT128_MIN
274# define INT128_WIDTH 128
275# define UINT128_WIDTH 128
276# define INT_LEAST128_WIDTH 128
277# define UINT_LEAST128_WIDTH 128
278# define INT_FAST128_WIDTH 128
279# define UINT_FAST128_WIDTH 128
280# if UINT128_WIDTH > __LLONG_WIDTH__
281# define INT128_C(N) ((int_least128_t)+N ## WB)
282# define UINT128_C(N) ((uint_least128_t)+N ## WBU)
283# else
284# define INT128_C(N) ((int_least128_t)+N ## LL)
285# define UINT128_C(N) ((uint_least128_t)+N ## LLU)
286# endif
287#endif
288
289#endif /* __STDC_HOSTED__ && __has_include_next(<stdint.h>) */
lib/compiler/aro/include/stdnoreturn.h created+6
...@@ -0,0 +1,6 @@
1/* <stdnoreturn.h> for the Aro C compiler */
2
3#pragma once
4
5#define noreturn _Noreturn
6#define __noreturn_is_defined 1
lib/compiler/aro/include/varargs.h created+3
...@@ -0,0 +1,3 @@
1/* <varargs.h> for the Aro C compiler */
2#pragma once
3#error please use <stdarg.h> instead of <varargs.h>
lib/compiler/translate-c/Translator.zig+4-4
...@@ -171,7 +171,7 @@ pub const Options = struct {...@@ -171,7 +171,7 @@ pub const Options = struct {
171 tree: *const aro.Tree,171 tree: *const aro.Tree,
172};172};
173173
174pub fn translate(options: Options) ![]u8 {174pub fn translate(options: Options) mem.Allocator.Error![]u8 {
175 const gpa = options.gpa;175 const gpa = options.gpa;
176 var arena_allocator = std.heap.ArenaAllocator.init(gpa);176 var arena_allocator = std.heap.ArenaAllocator.init(gpa);
177 defer arena_allocator.deinit();177 defer arena_allocator.deinit();
...@@ -219,19 +219,19 @@ pub fn translate(options: Options) ![]u8 {...@@ -219,19 +219,19 @@ pub fn translate(options: Options) ![]u8 {
219 var aw: std.Io.Writer.Allocating = .init(gpa);219 var aw: std.Io.Writer.Allocating = .init(gpa);
220 defer aw.deinit();220 defer aw.deinit();
221221
222 try aw.writer.writeAll(222 aw.writer.writeAll(
223 \\pub const __builtin = @import("std").zig.c_translation.builtins;223 \\pub const __builtin = @import("std").zig.c_translation.builtins;
224 \\pub const __helpers = @import("std").zig.c_translation.helpers;224 \\pub const __helpers = @import("std").zig.c_translation.helpers;
225 \\225 \\
226 \\226 \\
227 );227 ) catch return error.OutOfMemory;
228228
229 var zig_ast = try ast.render(gpa, translator.global_scope.nodes.items);229 var zig_ast = try ast.render(gpa, translator.global_scope.nodes.items);
230 defer {230 defer {
231 gpa.free(zig_ast.source);231 gpa.free(zig_ast.source);
232 zig_ast.deinit(gpa);232 zig_ast.deinit(gpa);
233 }233 }
234 try zig_ast.render(gpa, &aw.writer, .{});234 zig_ast.render(gpa, &aw.writer, .{}) catch return error.OutOfMemory;
235 return aw.toOwnedSlice();235 return aw.toOwnedSlice();
236}236}
237237
lib/compiler/translate-c/main.zig+22-3
...@@ -109,8 +109,6 @@ fn translate(d: *aro.Driver, tc: *aro.Toolchain, args: [][:0]u8) !void {...@@ -109,8 +109,6 @@ fn translate(d: *aro.Driver, tc: *aro.Toolchain, args: [][:0]u8) !void {
109 var macro_buf: std.ArrayListUnmanaged(u8) = .empty;109 var macro_buf: std.ArrayListUnmanaged(u8) = .empty;
110 defer macro_buf.deinit(gpa);110 defer macro_buf.deinit(gpa);
111111
112 try macro_buf.appendSlice(gpa, "#define __TRANSLATE_C__ 1\n");
113
114 var discard_buf: [256]u8 = undefined;112 var discard_buf: [256]u8 = undefined;
115 var discarding: std.io.Writer.Discarding = .init(&discard_buf);113 var discarding: std.io.Writer.Discarding = .init(&discard_buf);
116 assert(!try d.parseArgs(&discarding.writer, &macro_buf, aro_args));114 assert(!try d.parseArgs(&discarding.writer, &macro_buf, aro_args));
...@@ -146,6 +144,12 @@ fn translate(d: *aro.Driver, tc: *aro.Toolchain, args: [][:0]u8) !void {...@@ -146,6 +144,12 @@ fn translate(d: *aro.Driver, tc: *aro.Toolchain, args: [][:0]u8) !void {
146 var pp = try aro.Preprocessor.initDefault(d.comp);144 var pp = try aro.Preprocessor.initDefault(d.comp);
147 defer pp.deinit();145 defer pp.deinit();
148146
147 var name_buf: [std.fs.max_name_bytes]u8 = undefined;
148 var opt_dep_file = try d.initDepFile(source, &name_buf);
149 defer if (opt_dep_file) |*dep_file| dep_file.deinit(pp.gpa);
150
151 if (opt_dep_file) |*dep_file| pp.dep_file = dep_file;
152
149 try pp.preprocessSources(&.{ source, builtin_macros, user_macros });153 try pp.preprocessSources(&.{ source, builtin_macros, user_macros });
150154
151 var c_tree = try pp.parse();155 var c_tree = try pp.parse();
...@@ -156,6 +160,22 @@ fn translate(d: *aro.Driver, tc: *aro.Toolchain, args: [][:0]u8) !void {...@@ -156,6 +160,22 @@ fn translate(d: *aro.Driver, tc: *aro.Toolchain, args: [][:0]u8) !void {
156 return error.FatalError;160 return error.FatalError;
157 }161 }
158162
163 var out_buf: [4096]u8 = undefined;
164 if (opt_dep_file) |dep_file| {
165 const dep_file_name = try d.getDepFileName(source, out_buf[0..std.fs.max_name_bytes]);
166
167 const file = if (dep_file_name) |path|
168 d.comp.cwd.createFile(path, .{}) catch |er|
169 return d.fatal("unable to create dependency file '{s}': {s}", .{ path, aro.Driver.errorDescription(er) })
170 else
171 std.fs.File.stdout();
172 defer if (dep_file_name != null) file.close();
173
174 var file_writer = file.writer(&out_buf);
175 dep_file.write(&file_writer.interface) catch
176 return d.fatal("unable to write dependency file: {s}", .{aro.Driver.errorDescription(file_writer.err.?)});
177 }
178
159 const rendered_zig = try Translator.translate(.{179 const rendered_zig = try Translator.translate(.{
160 .gpa = gpa,180 .gpa = gpa,
161 .comp = d.comp,181 .comp = d.comp,
...@@ -182,7 +202,6 @@ fn translate(d: *aro.Driver, tc: *aro.Toolchain, args: [][:0]u8) !void {...@@ -182,7 +202,6 @@ fn translate(d: *aro.Driver, tc: *aro.Toolchain, args: [][:0]u8) !void {
182 out_file_path = path;202 out_file_path = path;
183 }203 }
184204
185 var out_buf: [4096]u8 = undefined;
186 var out_writer = out_file.writer(&out_buf);205 var out_writer = out_file.writer(&out_buf);
187 out_writer.interface.writeAll(rendered_zig) catch206 out_writer.interface.writeAll(rendered_zig) catch
188 return d.fatal("failed to write result to '{s}': {s}", .{ out_file_path, aro.Driver.errorDescription(out_writer.err.?) });207 return d.fatal("failed to write result to '{s}': {s}", .{ out_file_path, aro.Driver.errorDescription(out_writer.err.?) });
src/libs/mingw.zig+1-1
...@@ -333,7 +333,7 @@ pub fn buildImportLib(comp: *Compilation, lib_name: []const u8) !void {...@@ -333,7 +333,7 @@ pub fn buildImportLib(comp: *Compilation, lib_name: []const u8) !void {
333 defer std.debug.unlockStderrWriter();333 defer std.debug.unlockStderrWriter();
334 for (aro_comp.diagnostics.output.to_list.messages.items) |msg| {334 for (aro_comp.diagnostics.output.to_list.messages.items) |msg| {
335 if (msg.kind == .@"fatal error" or msg.kind == .@"error") {335 if (msg.kind == .@"fatal error" or msg.kind == .@"error") {
336 aro.Diagnostics.writeToWriter(msg, w, std.io.tty.detectConfig(std.fs.File.stderr())) catch {};336 msg.write(w, .detect(std.fs.File.stderr()), true) catch {};
337 return error.AroPreprocessorFailed;337 return error.AroPreprocessorFailed;
338 }338 }
339 }339 }