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