14e98e3e1Schristos#!/bin/sh 24e98e3e1Schristos 34e98e3e1Schristos# Script to compare functions and instructions used by different igen models. 4*71f62182Schristos# Copyright (C) 2002-2024 Free Software Foundation, Inc. 54e98e3e1Schristos# Contributed by Chris Demetriou of Broadcom Corporation (SiByte). 64e98e3e1Schristos# 74e98e3e1Schristos# This file is part of GDB, the GNU debugger. 84e98e3e1Schristos# 94e98e3e1Schristos# This program is free software; you can redistribute it and/or modify 104e98e3e1Schristos# it under the terms of the GNU General Public License as published by 114e98e3e1Schristos# the Free Software Foundation; either version 3 of the License, or 124e98e3e1Schristos# (at your option) any later version. 134e98e3e1Schristos# 144e98e3e1Schristos# This program is distributed in the hope that it will be useful, 154e98e3e1Schristos# but WITHOUT ANY WARRANTY; without even the implied warranty of 164e98e3e1Schristos# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 174e98e3e1Schristos# GNU General Public License for more details. 184e98e3e1Schristos# 194e98e3e1Schristos# You should have received a copy of the GNU General Public License 204e98e3e1Schristos# along with this program. If not, see <http://www.gnu.org/licenses/>. 214e98e3e1Schristos 224e98e3e1Schristos# This is a simple-minded script to compare the functions and instructions 234e98e3e1Schristos# listed for two different models in one or more .igen files. 244e98e3e1Schristos# 254e98e3e1Schristos# It was intended to be useful to help factor models into common subsets. 264e98e3e1Schristos# 274e98e3e1Schristos# Things to note: 284e98e3e1Schristos# 294e98e3e1Schristos# * igen include directives are not processed! 304e98e3e1Schristos# 314e98e3e1Schristos# * functions and instructions with multiple definitions (e.g., based 324e98e3e1Schristos# on model names) are treated as being different. In other words, 334e98e3e1Schristos# if two models have different functions named 'foo', this 344e98e3e1Schristos# script will say that one has one of the function definitions, and 354e98e3e1Schristos# the other has the other. 364e98e3e1Schristos 374e98e3e1Schristosif [ "$#" -lt 2 ]; then 384e98e3e1Schristos echo "usage: $0 model1 model2 [file ...]" 1>&2 394e98e3e1Schristos exit 1 404e98e3e1Schristosfi 414e98e3e1Schristosmodel1="$1" 424e98e3e1Schristosmodel2="$2" 434e98e3e1Schristosshift; shift 444e98e3e1Schristos 454e98e3e1Schristosgawk -v model1="$model1" -v model2="$model2" -F: -- ' 464e98e3e1SchristosBEGIN { 474e98e3e1Schristos thang_count = 0 484e98e3e1Schristos} 494e98e3e1Schristosfunction thang_has_model(t, m) { 504e98e3e1Schristos# printf("thang_has_model(%s, %s) (@ %s:%d)\n", t, m, 514e98e3e1Schristos# thangs[t,"file"], thangs[t,"line"]); 524e98e3e1Schristos if (thangs[t,"nmodels"] == 0) return 1; 534e98e3e1Schristos 544e98e3e1Schristos for (j = 0; j < thangs[t,"nmodels"]; j++) { 554e98e3e1Schristos# printf("\tmodel \"%s\"\n", thangs[t,"models",j]); 564e98e3e1Schristos if (thangs[t,"models",j] == m) return 1; 574e98e3e1Schristos } 584e98e3e1Schristos# printf("\t-> 0\n"); 594e98e3e1Schristos return 0 604e98e3e1Schristos} 614e98e3e1Schristosfunction compare_models(m1, m2) { 624e98e3e1Schristos# printf("compare_models(%s, %s)\n", m1, m2); 634e98e3e1Schristos seen_any=0 644e98e3e1Schristos for (i = 0; i < thang_count; i++) { 654e98e3e1Schristos if (thang_has_model(i, m1) && !thang_has_model(i, m2)) { 664e98e3e1Schristos if (!seen_any) { 674e98e3e1Schristos printf("Things in %s but not in %s:\n", m1, m2); 684e98e3e1Schristos seen_any = 1 694e98e3e1Schristos } 704e98e3e1Schristos printf("%s:%d: %s\n", thangs[i,"file"], 714e98e3e1Schristos thangs[i,"line"], thangs[i,"contents"]); 724e98e3e1Schristos } 734e98e3e1Schristos } 744e98e3e1Schristos} 754e98e3e1Schristos$0 ~ /^:/ && $2 == "model" { 764e98e3e1Schristos # ignore. 774e98e3e1Schristos # print "model " $0 784e98e3e1Schristos} 794e98e3e1Schristos($0 ~ /^:/ && $2 == "function") || \ 804e98e3e1Schristos($0 ~ /^:/ && $2 == "internal") || \ 814e98e3e1Schristos($0 ~ /^[0-9]/) { 824e98e3e1Schristos # a function, internal, or instruction. 834e98e3e1Schristos 844e98e3e1Schristos current_thang = thang_count 854e98e3e1Schristos thang_count++ 864e98e3e1Schristos 874e98e3e1Schristos thangs[current_thang,"file"] = FILENAME 884e98e3e1Schristos thangs[current_thang,"line"] = NR 894e98e3e1Schristos thangs[current_thang,"contents"] = $0 904e98e3e1Schristos thangs[current_thang,"nmodels"] = 0 914e98e3e1Schristos 924e98e3e1Schristos if ($0 ~ /^:/) { 934e98e3e1Schristos thangs[current_thang,"type"] = $2 944e98e3e1Schristos } else { 954e98e3e1Schristos thangs[current_thang,"type"] = "instruction" 964e98e3e1Schristos } 974e98e3e1Schristos} 984e98e3e1Schristos$0 ~ /^\*/ { 994e98e3e1Schristos split(substr($1, 2), tmp_models, /,/) 1004e98e3e1Schristos for (key in tmp_models) { 1014e98e3e1Schristos current_model = thangs[current_thang,"nmodels"] 1024e98e3e1Schristos thangs[current_thang,"nmodels"]++ 1034e98e3e1Schristos thangs[current_thang,"models",current_model] = tmp_models[key] 1044e98e3e1Schristos } 1054e98e3e1Schristos} 1064e98e3e1SchristosEND { 1074e98e3e1Schristos compare_models(model1, model2) 1084e98e3e1Schristos if (seen_any) printf("\n"); 1094e98e3e1Schristos compare_models(model2, model1) 1104e98e3e1Schristos}' "$@" 1114e98e3e1Schristos 1124e98e3e1Schristosexit "$?" 113