diff options
author | Hau Hsu <hau.hsu@sifive.com> | 2024-02-23 14:17:28 +0800 |
---|---|---|
committer | Nelson Chu <nelson@rivosinc.com> | 2024-03-13 13:47:34 +0800 |
commit | 90840a86569c32f63feb549f87507a7b6c84e070 (patch) | |
tree | 1de7eafba1ddddcfae8e1a68d3cd5a016d69d55f /bfd/elfxx-riscv.c | |
parent | ef11c1eaffeda578985b2b28f1e64db67bf3b224 (diff) | |
download | binutils-90840a86569c32f63feb549f87507a7b6c84e070.zip binutils-90840a86569c32f63feb549f87507a7b6c84e070.tar.gz binutils-90840a86569c32f63feb549f87507a7b6c84e070.tar.bz2 |
RISC-V: Add -march=help for gas
Use -march=help for gas to print all supported extensions and versions.
Here is part of the output of `as -march=help`:
All available -march extensions for RISC-V:
e 1.9
i 2.1, 2.0
m 2.0
a 2.1, 2.0
f 2.2, 2.0
d 2.2, 2.0
q 2.2, 2.0
c 2.0
v 1.0
h 1.0
zicbom 1.0
zicbop 1.0
...
This patch assumes that the supported extensions with the same versions
are listed together. For example:
static struct riscv_supported_ext riscv_supported_std_ext[] =
{
...
{"i", ISA_SPEC_CLASS_20191213, 2, 1, 0 },
{"i", ISA_SPEC_CLASS_20190608, 2, 1, 0 },
{"i", ISA_SPEC_CLASS_2P2, 2, 0, 0 },
...
};
For the "i" extension, 2.1.0 with different spec class are listed together.
This patch records the previous printed extension and version. If the
current extension and version are the same as the previous one, skip
printing.
bfd/
* elfxx-riscv.c (riscv_print_extensions): New function. Print
available extensions and versions.
* elfxx-riscv.h (riscv_print_extensions): New declaration.
gas/
* gas/config/tc-riscv.c (md_parse_option): Parse 'help' keyword in
-march option to print available extensions and versions.
* testsuite/gas/riscv/march-help.l: New testcase for -march=help.
* testsuite/gas/riscv/riscv.exp: Updated.
Diffstat (limited to 'bfd/elfxx-riscv.c')
-rw-r--r-- | bfd/elfxx-riscv.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/bfd/elfxx-riscv.c b/bfd/elfxx-riscv.c index 7313666..28be665 100644 --- a/bfd/elfxx-riscv.c +++ b/bfd/elfxx-riscv.c @@ -2941,3 +2941,49 @@ riscv_multi_subset_supports_ext (riscv_parse_subset_t *rps, return NULL; } } + +/* Print supported extensions with versions if -march=help. */ + +void +riscv_print_extensions (void) +{ + /* Record the previous printed extension. + Print the current one if they are not the same. */ + const struct riscv_supported_ext *cur = NULL, *prev = NULL; + int i, j; + + printf ("All available -march extensions for RISC-V:"); + + for (i = 0; riscv_all_supported_ext[i] != NULL; i++) + { + const struct riscv_supported_ext *exts = riscv_all_supported_ext[i]; + prev = NULL; + for (j = 0; exts[j].name != NULL; j++) + { + cur = &exts[j]; + /* Unclear version information, skip. */ + if (cur->isa_spec_class == ISA_SPEC_CLASS_NONE + || cur->major_version == RISCV_UNKNOWN_VERSION + || cur->minor_version == RISCV_UNKNOWN_VERSION) + continue; + + /* Same extension. */ + if (prev && strcmp (prev->name, cur->name) == 0) + { + /* Same version, skip. */ + if (prev->major_version == cur->major_version + && prev->minor_version == cur->minor_version) + continue; + /* Different version, print version with comma. */ + else + printf (", %d.%d", cur->major_version, cur->minor_version); + } + /* Different extension, print extension and version with newline. */ + else + printf ("\n\t%-40s%d.%d", cur->name, cur->major_version, + cur->minor_version); + prev = &exts[j]; + } + } + printf ("\n"); +} |