1#! /usr/bin/perl -w 2 3# Copyright 2001, 2003 Free Software Foundation, Inc. 4# 5# This file is part of the GNU MP Library. 6# 7# The GNU MP Library is free software; you can redistribute it and/or modify 8# it under the terms of either: 9# 10# * the GNU Lesser General Public License as published by the Free 11# Software Foundation; either version 3 of the License, or (at your 12# option) any later version. 13# 14# or 15# 16# * the GNU General Public License as published by the Free Software 17# Foundation; either version 2 of the License, or (at your option) any 18# later version. 19# 20# or both in parallel, as here. 21# 22# The GNU MP Library is distributed in the hope that it will be useful, but 23# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 24# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 25# for more details. 26# 27# You should have received copies of the GNU General Public License and the 28# GNU Lesser General Public License along with the GNU MP Library. If not, 29# see https://www.gnu.org/licenses/. 30 31 32# Usage: perl t-m68k-defs.pl [-t] 33# 34# Run this in the mpn/m68k source directory to check that m68k-defs.m4 has 35# m68k_defbranch()s or m68k_definsn()s for each instruction used in *.asm 36# and */*.asm. Print nothing if everything is ok. The -t option prints 37# some diagnostic traces. 38 39use strict; 40use Getopt::Std; 41 42my %opt; 43getopts('t', \%opt); 44 45my %branch; 46my %insn; 47 48open(FD, "<m68k-defs.m4") 49 or die "Cannot open m68k-defs.m4: $!\nIs this the mpn/m68k source directory?\n"; 50my ($srcdir, $top_srcdir); 51while (<FD>) { 52 if (/^m68k_defbranch\(\s*(.*)\)/) { $branch{"b".$1} = 1; } 53 if (/^m68k_definsn\(\s*(.*),\s*(.*)\)/) { $insn{$1.$2} = 1; } 54} 55close(FD); 56 57print "branches: ", join(" ",keys(%branch)), "\n" if $opt{'t'}; 58print "insns: ", join(" ",keys(%insn)), "\n" if $opt{'t'}; 59 60 61foreach my $file (glob("*.asm"), glob("*/*.asm")) { 62 print "file $file\n" if $opt{'t'}; 63 64 open(FD, "<$file") or die "Cannot open $file: $!"; 65 while (<FD>) { 66 if (/^[ \t]*C/) { next; }; 67 if (/^\t([a-z0-9]+)/) { 68 my $opcode = $1; 69 print "opcode $1\n" if $opt{'t'}; 70 71 # instructions with an l, w or b suffix should have a definsn 72 # (unless they're already a defbranch) 73 if ($opcode =~ /[lwb]$/ 74 && ! defined $insn{$opcode} 75 && ! defined $branch{$opcode}) 76 { 77 print "$file: $.: missing m68k_definsn: $opcode\n"; 78 } 79 80 # instructions bXX should have a defbranch (unless they're 81 # already a definsn) 82 if ($opcode =~ /^b/ 83 && ! defined $insn{$opcode} 84 && ! defined $branch{$opcode}) 85 { 86 print "$file: $.: missing m68k_defbranch: $opcode\n"; 87 } 88 } 89 } 90 close(FD); 91} 92