1#!/bin/sh 2 3# Script to compare functions and instructions used by different igen models. 4# Copyright (C) 2002-2024 Free Software Foundation, Inc. 5# Contributed by Chris Demetriou of Broadcom Corporation (SiByte). 6# 7# This file is part of GDB, the GNU debugger. 8# 9# This program is free software; you can redistribute it and/or modify 10# it under the terms of the GNU General Public License as published by 11# the Free Software Foundation; either version 3 of the License, or 12# (at your option) any later version. 13# 14# This program is distributed in the hope that it will be useful, 15# but WITHOUT ANY WARRANTY; without even the implied warranty of 16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17# GNU General Public License for more details. 18# 19# You should have received a copy of the GNU General Public License 20# along with this program. If not, see <http://www.gnu.org/licenses/>. 21 22# This is a simple-minded script to compare the functions and instructions 23# listed for two different models in one or more .igen files. 24# 25# It was intended to be useful to help factor models into common subsets. 26# 27# Things to note: 28# 29# * igen include directives are not processed! 30# 31# * functions and instructions with multiple definitions (e.g., based 32# on model names) are treated as being different. In other words, 33# if two models have different functions named 'foo', this 34# script will say that one has one of the function definitions, and 35# the other has the other. 36 37if [ "$#" -lt 2 ]; then 38 echo "usage: $0 model1 model2 [file ...]" 1>&2 39 exit 1 40fi 41model1="$1" 42model2="$2" 43shift; shift 44 45gawk -v model1="$model1" -v model2="$model2" -F: -- ' 46BEGIN { 47 thang_count = 0 48} 49function thang_has_model(t, m) { 50# printf("thang_has_model(%s, %s) (@ %s:%d)\n", t, m, 51# thangs[t,"file"], thangs[t,"line"]); 52 if (thangs[t,"nmodels"] == 0) return 1; 53 54 for (j = 0; j < thangs[t,"nmodels"]; j++) { 55# printf("\tmodel \"%s\"\n", thangs[t,"models",j]); 56 if (thangs[t,"models",j] == m) return 1; 57 } 58# printf("\t-> 0\n"); 59 return 0 60} 61function compare_models(m1, m2) { 62# printf("compare_models(%s, %s)\n", m1, m2); 63 seen_any=0 64 for (i = 0; i < thang_count; i++) { 65 if (thang_has_model(i, m1) && !thang_has_model(i, m2)) { 66 if (!seen_any) { 67 printf("Things in %s but not in %s:\n", m1, m2); 68 seen_any = 1 69 } 70 printf("%s:%d: %s\n", thangs[i,"file"], 71 thangs[i,"line"], thangs[i,"contents"]); 72 } 73 } 74} 75$0 ~ /^:/ && $2 == "model" { 76 # ignore. 77 # print "model " $0 78} 79($0 ~ /^:/ && $2 == "function") || \ 80($0 ~ /^:/ && $2 == "internal") || \ 81($0 ~ /^[0-9]/) { 82 # a function, internal, or instruction. 83 84 current_thang = thang_count 85 thang_count++ 86 87 thangs[current_thang,"file"] = FILENAME 88 thangs[current_thang,"line"] = NR 89 thangs[current_thang,"contents"] = $0 90 thangs[current_thang,"nmodels"] = 0 91 92 if ($0 ~ /^:/) { 93 thangs[current_thang,"type"] = $2 94 } else { 95 thangs[current_thang,"type"] = "instruction" 96 } 97} 98$0 ~ /^\*/ { 99 split(substr($1, 2), tmp_models, /,/) 100 for (key in tmp_models) { 101 current_model = thangs[current_thang,"nmodels"] 102 thangs[current_thang,"nmodels"]++ 103 thangs[current_thang,"models",current_model] = tmp_models[key] 104 } 105} 106END { 107 compare_models(model1, model2) 108 if (seen_any) printf("\n"); 109 compare_models(model2, model1) 110}' "$@" 111 112exit "$?" 113