Blame mpn/m68k/t-m68k-defs.pl

Packit 5c3484
#! /usr/bin/perl -w
Packit 5c3484
Packit 5c3484
# Copyright 2001, 2003 Free Software Foundation, Inc.
Packit 5c3484
#
Packit 5c3484
#  This file is part of the GNU MP Library.
Packit 5c3484
#
Packit 5c3484
#  The GNU MP Library is free software; you can redistribute it and/or modify
Packit 5c3484
#  it under the terms of either:
Packit 5c3484
#
Packit 5c3484
#    * the GNU Lesser General Public License as published by the Free
Packit 5c3484
#      Software Foundation; either version 3 of the License, or (at your
Packit 5c3484
#      option) any later version.
Packit 5c3484
#
Packit 5c3484
#  or
Packit 5c3484
#
Packit 5c3484
#    * the GNU General Public License as published by the Free Software
Packit 5c3484
#      Foundation; either version 2 of the License, or (at your option) any
Packit 5c3484
#      later version.
Packit 5c3484
#
Packit 5c3484
#  or both in parallel, as here.
Packit 5c3484
#
Packit 5c3484
#  The GNU MP Library is distributed in the hope that it will be useful, but
Packit 5c3484
#  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
Packit 5c3484
#  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
Packit 5c3484
#  for more details.
Packit 5c3484
#
Packit 5c3484
#  You should have received copies of the GNU General Public License and the
Packit 5c3484
#  GNU Lesser General Public License along with the GNU MP Library.  If not,
Packit 5c3484
#  see https://www.gnu.org/licenses/.
Packit 5c3484
Packit 5c3484
Packit 5c3484
# Usage:  perl t-m68k-defs.pl [-t]
Packit 5c3484
#
Packit 5c3484
# Run this in the mpn/m68k source directory to check that m68k-defs.m4 has
Packit 5c3484
# m68k_defbranch()s or m68k_definsn()s for each instruction used in *.asm
Packit 5c3484
# and */*.asm.  Print nothing if everything is ok.  The -t option prints
Packit 5c3484
# some diagnostic traces.
Packit 5c3484
Packit 5c3484
use strict;
Packit 5c3484
use Getopt::Std;
Packit 5c3484
Packit 5c3484
my %opt;
Packit 5c3484
getopts('t', \%opt);
Packit 5c3484
Packit 5c3484
my %branch;
Packit 5c3484
my %insn;
Packit 5c3484
Packit 5c3484
open(FD, "
Packit 5c3484
    or die "Cannot open m68k-defs.m4: $!\nIs this the mpn/m68k source directory?\n";
Packit 5c3484
my ($srcdir, $top_srcdir);
Packit 5c3484
while (<FD>) {
Packit 5c3484
    if (/^m68k_defbranch\(\s*(.*)\)/) { $branch{"b".$1} = 1; }
Packit 5c3484
    if (/^m68k_definsn\(\s*(.*),\s*(.*)\)/) { $insn{$1.$2} = 1; }
Packit 5c3484
}
Packit 5c3484
close(FD);
Packit 5c3484
Packit 5c3484
print "branches: ", join(" ",keys(%branch)), "\n" if $opt{'t'};
Packit 5c3484
print "insns: ", join(" ",keys(%insn)), "\n" if $opt{'t'};
Packit 5c3484
Packit 5c3484
Packit 5c3484
foreach my $file (glob("*.asm"), glob("*/*.asm")) {
Packit 5c3484
    print "file $file\n" if $opt{'t'};
Packit 5c3484
Packit 5c3484
    open(FD, "<$file") or die "Cannot open $file: $!";
Packit 5c3484
    while (<FD>) {
Packit 5c3484
	if (/^[ \t]*C/) { next; };
Packit 5c3484
	if (/^\t([a-z0-9]+)/) {
Packit 5c3484
	    my $opcode = $1;
Packit 5c3484
	    print "opcode $1\n" if $opt{'t'};
Packit 5c3484
Packit 5c3484
	    # instructions with an l, w or b suffix should have a definsn
Packit 5c3484
	    # (unless they're already a defbranch)
Packit 5c3484
	    if ($opcode =~ /[lwb]$/
Packit 5c3484
		&& ! defined $insn{$opcode}
Packit 5c3484
		&& ! defined $branch{$opcode})
Packit 5c3484
	    {
Packit 5c3484
		print "$file: $.: missing m68k_definsn: $opcode\n";
Packit 5c3484
	    }
Packit 5c3484
Packit 5c3484
	    # instructions bXX should have a defbranch (unless they're
Packit 5c3484
	    # already a definsn)
Packit 5c3484
	    if ($opcode =~ /^b/
Packit 5c3484
		&& ! defined $insn{$opcode}
Packit 5c3484
		&& ! defined $branch{$opcode})
Packit 5c3484
	    {
Packit 5c3484
		print "$file: $.: missing m68k_defbranch: $opcode\n";
Packit 5c3484
	    }
Packit 5c3484
	}
Packit 5c3484
    }
Packit 5c3484
    close(FD);
Packit 5c3484
}