| author | |
| committer | |
| log | 5bc4690d85bfaade48393c182b2b3aa207ebebc7 |
| tree | 5ab2de0fba2b7b20601d99a1effb9da69f8db750 |
| parent | 21908e100e42c5630e1e4253167496fb76238670 |
| signature |
4 files changed, 139 insertions(+), 2 deletions(-)
src-self-hosted/stage1.zig+99| ... | ... | @@ -6,9 +6,12 @@ const io = std.io; |
| 6 | 6 | const mem = std.mem; |
| 7 | 7 | const fs = std.fs; |
| 8 | 8 | const process = std.process; |
| 9 | const feature = std.target.feature; | |
| 10 | const cpu = std.target.cpu; | |
| 9 | 11 | const Allocator = mem.Allocator; |
| 10 | 12 | const ArrayList = std.ArrayList; |
| 11 | 13 | const Buffer = std.Buffer; |
| 14 | const Target = std.Target; | |
| 12 | 15 | const self_hosted_main = @import("main.zig"); |
| 13 | 16 | const errmsg = @import("errmsg.zig"); |
| 14 | 17 | const DepTokenizer = @import("dep_tokenizer.zig").Tokenizer; |
| ... | ... | @@ -527,3 +530,99 @@ export fn stage2_progress_update_node(node: *std.Progress.Node, done_count: usiz |
| 527 | 530 | node.activate(); |
| 528 | 531 | node.context.maybeRefresh(); |
| 529 | 532 | } |
| 533 | ||
| 534 | // ABI warning | |
| 535 | export fn stage2_list_features_for_arch(arch_name_ptr: [*]const u8, arch_name_len: usize, show_subfeatures: bool) void { | |
| 536 | print_features_for_arch(arch_name_ptr[0..arch_name_len], show_subfeatures) catch |err| { | |
| 537 | std.debug.warn("Failed to list features: {}\n", .{ @errorName(err) }); | |
| 538 | }; | |
| 539 | } | |
| 540 | ||
| 541 | fn print_features_for_arch(arch_name: []const u8, show_subfeatures: bool) !void { | |
| 542 | const stdout_stream = &std.io.getStdOut().outStream().stream; | |
| 543 | ||
| 544 | const arch = Target.parseArchTag(arch_name) catch { | |
| 545 | std.debug.warn("Failed to parse arch '{}'\nInvoke 'zig targets' for a list of valid architectures\n", .{ arch_name }); | |
| 546 | return; | |
| 547 | }; | |
| 548 | ||
| 549 | inline for (@typeInfo(@TagType(Target.Arch)).Enum.fields) |arch_enum_field| { | |
| 550 | if (@enumToInt(arch) == arch_enum_field.value) { | |
| 551 | const enum_arch = @intToEnum(@TagType(Target.Arch), arch_enum_field.value); | |
| 552 | ||
| 553 | const feature_infos = feature.ArchFeature(enum_arch).feature_infos; | |
| 554 | ||
| 555 | try stdout_stream.print("Available features for {}:\n", .{ arch_enum_field.name }); | |
| 556 | ||
| 557 | var longest_len: usize = 0; | |
| 558 | for (feature_infos) |feature_info| { | |
| 559 | if (feature_info.name.len > longest_len) longest_len = feature_info.name.len; | |
| 560 | } | |
| 561 | ||
| 562 | for (feature_infos) |feature_info| { | |
| 563 | try stdout_stream.print(" {}", .{ feature_info.name }); | |
| 564 | ||
| 565 | var i: usize = 0; | |
| 566 | while (i < longest_len - feature_info.name.len) : (i += 1) { | |
| 567 | try stdout_stream.write(" "); | |
| 568 | } | |
| 569 | ||
| 570 | try stdout_stream.print(" - {}\n", .{ feature_info.description }); | |
| 571 | ||
| 572 | if (show_subfeatures and feature_info.subfeatures.len > 0) { | |
| 573 | for (feature_info.subfeatures) |subfeature| { | |
| 574 | try stdout_stream.print(" {}\n", .{ subfeature.getInfo().name }); | |
| 575 | } | |
| 576 | } | |
| 577 | } | |
| 578 | } | |
| 579 | } | |
| 580 | } | |
| 581 | ||
| 582 | // ABI warning | |
| 583 | export fn stage2_list_cpus_for_arch(arch_name_ptr: [*]const u8, arch_name_len: usize, show_subfeatures: bool) void { | |
| 584 | print_cpus_for_arch(arch_name_ptr[0..arch_name_len], show_subfeatures) catch |err| { | |
| 585 | std.debug.warn("Failed to list features: {}\n", .{ @errorName(err) }); | |
| 586 | }; | |
| 587 | } | |
| 588 | ||
| 589 | fn print_cpus_for_arch(arch_name: []const u8, show_subfeatures: bool) !void { | |
| 590 | const stdout_stream = &std.io.getStdOut().outStream().stream; | |
| 591 | ||
| 592 | const arch = Target.parseArchTag(arch_name) catch { | |
| 593 | std.debug.warn("Failed to parse arch '{}'\nInvoke 'zig targets' for a list of valid architectures\n", .{ arch_name }); | |
| 594 | return; | |
| 595 | }; | |
| 596 | ||
| 597 | inline for (@typeInfo(@TagType(Target.Arch)).Enum.fields) |arch_enum_field| { | |
| 598 | if (@enumToInt(arch) == arch_enum_field.value) { | |
| 599 | const enum_arch = @intToEnum(@TagType(Target.Arch), arch_enum_field.value); | |
| 600 | ||
| 601 | const cpu_infos = cpu.ArchCpu(enum_arch).cpu_infos; | |
| 602 | ||
| 603 | try stdout_stream.print("Available cpus for {}:\n", .{ arch_enum_field.name }); | |
| 604 | ||
| 605 | var longest_len: usize = 0; | |
| 606 | for (cpu_infos) |cpu_info| { | |
| 607 | if (cpu_info.name.len > longest_len) longest_len = cpu_info.name.len; | |
| 608 | } | |
| 609 | ||
| 610 | for (cpu_infos) |cpu_info| { | |
| 611 | try stdout_stream.print(" {}", .{ cpu_info.name }); | |
| 612 | ||
| 613 | var i: usize = 0; | |
| 614 | while (i < longest_len - cpu_info.name.len) : (i += 1) { | |
| 615 | try stdout_stream.write(" "); | |
| 616 | } | |
| 617 | ||
| 618 | try stdout_stream.write("\n"); | |
| 619 | ||
| 620 | if (show_subfeatures and cpu_info.features.len > 0) { | |
| 621 | for (cpu_info.features) |subfeature| { | |
| 622 | try stdout_stream.print(" {}\n", .{ subfeature.getInfo().name }); | |
| 623 | } | |
| 624 | } | |
| 625 | } | |
| 626 | } | |
| 627 | } | |
| 628 | } |
src/main.cpp+31-2| ... | ... | @@ -129,6 +129,11 @@ static int print_full_usage(const char *arg0, FILE *file, int return_code) { |
| 129 | 129 | " --test-name-prefix [text] add prefix to all tests\n" |
| 130 | 130 | " --test-cmd [arg] specify test execution command one arg at a time\n" |
| 131 | 131 | " --test-cmd-bin appends test binary path to test cmd args\n" |
| 132 | "\n" | |
| 133 | "Targets Options:\n" | |
| 134 | " --list-features [arch] list available features for the given architecture\n" | |
| 135 | " --list-cpus [arch] list available cpus for the given architecture\n" | |
| 136 | " --show-subfeatures list subfeatures for each entry from --list-features or --list-cpus\n" | |
| 132 | 137 | , arg0); |
| 133 | 138 | return return_code; |
| 134 | 139 | } |
| ... | ... | @@ -529,6 +534,10 @@ int main(int argc, char **argv) { |
| 529 | 534 | WantCSanitize want_sanitize_c = WantCSanitizeAuto; |
| 530 | 535 | bool function_sections = false; |
| 531 | 536 | |
| 537 | const char *targets_list_features_arch = nullptr; | |
| 538 | const char *targets_list_cpus_arch = nullptr; | |
| 539 | bool targets_show_subfeatures = false; | |
| 540 | ||
| 532 | 541 | ZigList<const char *> llvm_argv = {0}; |
| 533 | 542 | llvm_argv.append("zig (LLVM option parsing)"); |
| 534 | 543 | |
| ... | ... | @@ -779,6 +788,8 @@ int main(int argc, char **argv) { |
| 779 | 788 | cur_pkg = cur_pkg->parent; |
| 780 | 789 | } else if (strcmp(arg, "-ffunction-sections") == 0) { |
| 781 | 790 | function_sections = true; |
| 791 | } else if (strcmp(arg, "--show-subfeatures") == 0) { | |
| 792 | targets_show_subfeatures = true; | |
| 782 | 793 | } else if (i + 1 >= argc) { |
| 783 | 794 | fprintf(stderr, "Expected another argument after %s\n", arg); |
| 784 | 795 | return print_error_usage(arg0); |
| ... | ... | @@ -936,7 +947,11 @@ int main(int argc, char **argv) { |
| 936 | 947 | , argv[i]); |
| 937 | 948 | return EXIT_FAILURE; |
| 938 | 949 | } |
| 939 | } else { | |
| 950 | } else if (strcmp(arg, "--list-features") == 0) { | |
| 951 | targets_list_features_arch = argv[i]; | |
| 952 | } else if (strcmp(arg, "--list-cpus") == 0) { | |
| 953 | targets_list_cpus_arch = argv[i]; | |
| 954 | }else { | |
| 940 | 955 | fprintf(stderr, "Invalid argument: %s\n", arg); |
| 941 | 956 | return print_error_usage(arg0); |
| 942 | 957 | } |
| ... | ... | @@ -1413,7 +1428,21 @@ int main(int argc, char **argv) { |
| 1413 | 1428 | return main_exit(root_progress_node, EXIT_SUCCESS); |
| 1414 | 1429 | } |
| 1415 | 1430 | case CmdTargets: |
| 1416 | return print_target_list(stdout); | |
| 1431 | if (targets_list_features_arch != nullptr) { | |
| 1432 | stage2_list_features_for_arch( | |
| 1433 | targets_list_features_arch, | |
| 1434 | strlen(targets_list_features_arch), | |
| 1435 | targets_show_subfeatures); | |
| 1436 | return 0; | |
| 1437 | } else if (targets_list_cpus_arch != nullptr) { | |
| 1438 | stage2_list_cpus_for_arch( | |
| 1439 | targets_list_cpus_arch, | |
| 1440 | strlen(targets_list_cpus_arch), | |
| 1441 | targets_show_subfeatures); | |
| 1442 | return 0; | |
| 1443 | } else { | |
| 1444 | return print_target_list(stdout); | |
| 1445 | } | |
| 1417 | 1446 | case CmdNone: |
| 1418 | 1447 | return print_full_usage(arg0, stderr, EXIT_FAILURE); |
| 1419 | 1448 | } |
src/userland.cpp+3| ... | ... | @@ -88,3 +88,6 @@ void stage2_progress_end(Stage2ProgressNode *node) {} |
| 88 | 88 | void stage2_progress_complete_one(Stage2ProgressNode *node) {} |
| 89 | 89 | void stage2_progress_disable_tty(Stage2Progress *progress) {} |
| 90 | 90 | void stage2_progress_update_node(Stage2ProgressNode *node, size_t completed_count, size_t estimated_total_items){} |
| 91 | ||
| 92 | void stage2_list_features_for_arch(const char *arch_name_ptr, size_t arch_name_len, bool show_subfeatures) {} | |
| 93 | void stage2_list_cpus_for_arch(const char *arch_name_ptr, size_t arch_name_len, bool show_subfeatures) {} |
src/userland.h+6| ... | ... | @@ -174,4 +174,10 @@ ZIG_EXTERN_C void stage2_progress_complete_one(Stage2ProgressNode *node); |
| 174 | 174 | ZIG_EXTERN_C void stage2_progress_update_node(Stage2ProgressNode *node, |
| 175 | 175 | size_t completed_count, size_t estimated_total_items); |
| 176 | 176 | |
| 177 | // ABI warning | |
| 178 | ZIG_EXTERN_C void stage2_list_features_for_arch(const char *arch_name_ptr, size_t arch_name_len, bool show_subfeatures); | |
| 179 | ||
| 180 | // ABI warning | |
| 181 | ZIG_EXTERN_C void stage2_list_cpus_for_arch(const char *arch_name_ptr, size_t arch_name_len, bool show_subfeatures); | |
| 182 | ||
| 177 | 183 | #endif |