armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 1 | #!/usr/bin/perl |
| 2 | |
armvixl | 5289c59 | 2015-03-02 13:52:04 +0000 | [diff] [blame] | 3 | # Copyright 2015, ARM Limited |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 4 | # All rights reserved. |
| 5 | # |
| 6 | # Redistribution and use in source and binary forms, with or without |
| 7 | # modification, are permitted provided that the following conditions are met: |
| 8 | # |
| 9 | # * Redistributions of source code must retain the above copyright notice, |
| 10 | # this list of conditions and the following disclaimer. |
| 11 | # * Redistributions in binary form must reproduce the above copyright notice, |
| 12 | # this list of conditions and the following disclaimer in the documentation |
| 13 | # and/or other materials provided with the distribution. |
| 14 | # * Neither the name of ARM Limited nor the names of its contributors may be |
| 15 | # used to endorse or promote products derived from this software without |
| 16 | # specific prior written permission. |
| 17 | # |
| 18 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS CONTRIBUTORS "AS IS" AND |
| 19 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 20 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 21 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE |
| 22 | # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 23 | # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 24 | # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 25 | # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 26 | # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 27 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | |
armvixl | 0f35e36 | 2016-05-10 13:57:58 +0100 | [diff] [blame] | 29 | use v5.10.1; |
| 30 | no warnings 'experimental::smartmatch'; |
| 31 | |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 32 | # Assembler header file. |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 33 | my $hfile = "src/vixl/a64/assembler-a64.h"; |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 34 | |
| 35 | # Extra pseudo instructions added to AArch64. |
armvixl | c68cb64 | 2014-09-25 18:49:30 +0100 | [diff] [blame] | 36 | my @extras = qw/bind debug dci dc32 dc64 place/; |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 37 | |
| 38 | my %inst = (); # Global hash of instructions. |
| 39 | |
| 40 | $/ = ''; |
armvixl | 0f35e36 | 2016-05-10 13:57:58 +0100 | [diff] [blame] | 41 | open(IN, "<$hfile") or die("Can't open header file $hfile.\n"); |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 42 | while(<IN>) |
| 43 | { |
| 44 | # Find a function formatted like an instruction. |
armvixl | 5289c59 | 2015-03-02 13:52:04 +0000 | [diff] [blame] | 45 | if(my($t) = /^ ((?:void|inline void) [a-z][a-z0-9]{0,8}_?)\(/mgp) |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 46 | { |
| 47 | my $before = ${^PREMATCH}; |
| 48 | my $after = ${^POSTMATCH}; |
| 49 | |
| 50 | # Extract the instruction. |
armvixl | 5289c59 | 2015-03-02 13:52:04 +0000 | [diff] [blame] | 51 | my($i) = $t =~ /(?:void|inline void) ([a-z][a-z0-9]{0,8})/; |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 52 | |
| 53 | # Extract the comment from before the function. |
| 54 | my($d) = $before =~ /.* \/\/ ([A-Z].+?\.)$/; |
| 55 | |
| 56 | # Extract and tidy up the function prototype. |
| 57 | my($p) = $after =~ /(.*?\))/ms; |
| 58 | $p =~ s/\n/\n /g; |
| 59 | $p = "$t(".$p; |
| 60 | |
| 61 | # Establish the type of the instruction. |
| 62 | my $type = 'integer'; |
armvixl | 5289c59 | 2015-03-02 13:52:04 +0000 | [diff] [blame] | 63 | ($p =~ /VRegister/) and $type = 'float'; |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 64 | ($i ~~ @extras) and $type = 'pseudo'; |
| 65 | |
| 66 | # Push the results into a hash keyed by prototype string. |
| 67 | $inst{$p}->{'type'} = $type; |
| 68 | $inst{$p}->{'mnemonic'} = $i; |
| 69 | $inst{$p}->{'description'} = $d; |
| 70 | } |
| 71 | } |
| 72 | close(IN); |
| 73 | |
| 74 | print <<HEADER; |
| 75 | VIXL Supported Instruction List |
| 76 | =============================== |
| 77 | |
| 78 | This is a list of the AArch64 instructions supported by the VIXL assembler, |
| 79 | disassembler and simulator. The simulator may not support all floating point |
| 80 | operations to the precision required by AArch64 - please check the simulator |
| 81 | source code for details. |
| 82 | |
| 83 | HEADER |
| 84 | |
| 85 | print describe_insts('AArch64 integer instructions', 'integer'); |
armvixl | 5289c59 | 2015-03-02 13:52:04 +0000 | [diff] [blame] | 86 | print describe_insts('AArch64 floating point and NEON instructions', 'float'); |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 87 | print describe_insts('Additional or pseudo instructions', 'pseudo'); |
| 88 | |
| 89 | # Sort instructions by mnemonic and then description. |
| 90 | sub inst_sort |
| 91 | { |
| 92 | $inst{$a}->{'mnemonic'} cmp $inst{$b}->{'mnemonic'} || |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 93 | $inst{$a}->{'description'} cmp $inst{$b}->{'description'} || |
| 94 | $a cmp $b; |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | # Return a Markdown formatted list of instructions of a particular type. |
| 98 | sub describe_insts |
| 99 | { |
| 100 | my($title, $type) = @_; |
| 101 | my $result = ''; |
| 102 | $result .= "$title\n"; |
| 103 | $result .= '-' x length($title); |
| 104 | $result .= "\n\n"; |
| 105 | |
| 106 | foreach my $i (sort inst_sort keys(%inst)) |
| 107 | { |
| 108 | next if($inst{$i}->{'type'} ne $type); |
armvixl | 5289c59 | 2015-03-02 13:52:04 +0000 | [diff] [blame] | 109 | $result .= sprintf("### %s ###\n\n%s\n\n", |
| 110 | uc($inst{$i}->{'mnemonic'}), |
| 111 | $inst{$i}->{'description'}); |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 112 | $result .= " $i\n\n\n"; |
| 113 | } |
| 114 | $result .= "\n"; |
| 115 | return $result |
| 116 | } |
| 117 | |
| 118 | |