1#!/usr/bin/perl
2
3# Copyright 2015, VIXL authors
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
29use v5.10.1;
30no warnings 'experimental::smartmatch';
31
32# Assembler header file.
33my $hfile = "src/aarch64/assembler-aarch64.h";
34
35# Extra pseudo instructions added to AArch64.
36my @extras = qw/bind debug dci dc32 dc64 place/;
37
38my %inst = ();  # Global hash of instructions.
39
40$/ = '';
41open(IN, "<$hfile") or die("Can't open header file $hfile.\n");
42while(<IN>)
43{
44  # Find a function formatted like an instruction.
45  if(my($t) = /^  ((?:void|inline void) [a-z][a-z0-9]{0,8}_?)\(/mgp)
46  {
47    my $before = ${^PREMATCH};
48    my $after = ${^POSTMATCH};
49
50    # Extract the instruction.
51    my($i) = $t =~ /(?:void|inline void) ([a-z][a-z0-9]{0,8})/;
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';
63    ($p =~ /VRegister/) and $type = 'float';
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}
72close(IN);
73
74print <<HEADER;
75VIXL Supported Instruction List
76===============================
77
78This is a list of the AArch64 instructions supported by the VIXL assembler,
79disassembler and simulator. The simulator may not support all floating point
80operations to the precision required by AArch64 - please check the simulator
81source code for details.
82
83HEADER
84
85print describe_insts('AArch64 integer instructions', 'integer');
86print describe_insts('AArch64 floating point and NEON instructions', 'float');
87print describe_insts('Additional or pseudo instructions', 'pseudo');
88
89# Sort instructions by mnemonic and then description.
90sub inst_sort
91{
92  $inst{$a}->{'mnemonic'} cmp $inst{$b}->{'mnemonic'} ||
93  $inst{$a}->{'description'} cmp $inst{$b}->{'description'} ||
94  $a cmp $b;
95}
96
97# Return a Markdown formatted list of instructions of a particular type.
98sub 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);
109    $result .= sprintf("### %s ###\n\n%s\n\n",
110                       uc($inst{$i}->{'mnemonic'}),
111                       $inst{$i}->{'description'});
112    $result .= "    $i\n\n\n";
113  }
114  $result .= "\n";
115  return $result
116}
117
118
119