| ... | ... | @@ -727,18 +727,47 @@ pub const Target = union(enum) { |
| 727 | 727 | /// are examples of CPU features to add to the set, and "c" and "d" are examples of CPU features |
| 728 | 728 | /// to remove from the set. |
| 729 | 729 | cpu_features: []const u8 = "baseline", |
| 730 | |
| 731 | /// If this is provided, the function will populate some information about parsing failures, |
| 732 | /// so that user-friendly error messages can be delivered. |
| 733 | diagnostics: ?*Diagnostics = null, |
| 734 | |
| 735 | pub const Diagnostics = struct { |
| 736 | /// If the architecture was determined, this will be populated. |
| 737 | arch: ?Cpu.Arch = null, |
| 738 | |
| 739 | /// If the OS was determined, this will be populated. |
| 740 | os: ?Os = null, |
| 741 | |
| 742 | /// If the ABI was determined, this will be populated. |
| 743 | abi: ?Abi = null, |
| 744 | |
| 745 | /// If the CPU name was determined, this will be populated. |
| 746 | cpu_name: ?[]const u8 = null, |
| 747 | |
| 748 | /// If error.UnknownCpuFeature is returned, this will be populated. |
| 749 | unknown_feature_name: ?[]const u8 = null, |
| 750 | }; |
| 730 | 751 | }; |
| 731 | 752 | |
| 732 | 753 | pub fn parse(args: ParseOptions) !Target { |
| 754 | var dummy_diags: ParseOptions.Diagnostics = undefined; |
| 755 | var diags = args.diagnostics orelse &dummy_diags; |
| 756 | |
| 733 | 757 | var it = mem.separate(args.arch_os_abi, "-"); |
| 734 | 758 | const arch_name = it.next() orelse return error.MissingArchitecture; |
| 735 | | const os_name = it.next() orelse return error.MissingOperatingSystem; |
| 736 | | const abi_name = it.next(); |
| 737 | | if (it.next() != null) return error.UnexpectedExtraField; |
| 738 | | |
| 739 | 759 | const arch = try Cpu.Arch.parse(arch_name); |
| 760 | diags.arch = arch; |
| 761 | |
| 762 | const os_name = it.next() orelse return error.MissingOperatingSystem; |
| 740 | 763 | const os = try Os.parse(os_name); |
| 764 | diags.os = os; |
| 765 | |
| 766 | const abi_name = it.next(); |
| 741 | 767 | const abi = if (abi_name) |n| try Abi.parse(n) else Abi.default(arch, os); |
| 768 | diags.abi = abi; |
| 769 | |
| 770 | if (it.next() != null) return error.UnexpectedExtraField; |
| 742 | 771 | |
| 743 | 772 | const all_features = arch.allFeaturesList(); |
| 744 | 773 | var index: usize = 0; |
| ... | ... | @@ -749,6 +778,8 @@ pub const Target = union(enum) { |
| 749 | 778 | index += 1; |
| 750 | 779 | } |
| 751 | 780 | const cpu_name = args.cpu_features[0..index]; |
| 781 | diags.cpu_name = cpu_name; |
| 782 | |
| 752 | 783 | const cpu: Cpu = if (mem.eql(u8, cpu_name, "baseline")) Cpu.baseline(arch) else blk: { |
| 753 | 784 | const cpu_model = try arch.parseCpuModel(cpu_name); |
| 754 | 785 | |
| ... | ... | @@ -775,6 +806,7 @@ pub const Target = union(enum) { |
| 775 | 806 | break; |
| 776 | 807 | } |
| 777 | 808 | } else { |
| 809 | diags.unknown_feature_name = feature_name; |
| 778 | 810 | return error.UnknownCpuFeature; |
| 779 | 811 | } |
| 780 | 812 | } |