3 # Script to compare functions and instructions used by different igen models.
4 # Copyright (C) 2002-2013 Free Software Foundation, Inc.
5 # Contributed by Chris Demetriou of Broadcom Corporation (SiByte).
7 # This file is part of GDB, the GNU debugger.
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.
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.
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/>.
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.
25 # It was intended to be useful to help factor models into common subsets.
29 # * igen include directives are not processed!
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.
37 if [ "$#" -lt 2 ]; then
38 echo "usage: $0 model1 model2 [file ...]" 1>&2
45 gawk -v model1="$model1" -v model2="$model2" -F: -- '
49 function 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;
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;
61 function compare_models(m1, m2) {
62 # printf("compare_models(%s, %s)\n", m1, m2);
64 for (i = 0; i < thang_count; i++) {
65 if (thang_has_model(i, m1) && !thang_has_model(i, m2)) {
67 printf("Things in %s but not in %s:\n", m1, m2);
70 printf("%s:%d: %s\n", thangs[i,"file"],
71 thangs[i,"line"], thangs[i,"contents"]);
75 $0 ~ /^:/ && $2 == "model" {
79 ($0 ~ /^:/ && $2 == "function") || \
80 ($0 ~ /^:/ && $2 == "internal") || \
82 # a function, internal, or instruction.
84 current_thang = thang_count
87 thangs[current_thang,"file"] = FILENAME
88 thangs[current_thang,"line"] = NR
89 thangs[current_thang,"contents"] = $0
90 thangs[current_thang,"nmodels"] = 0
93 thangs[current_thang,"type"] = $2
95 thangs[current_thang,"type"] = "instruction"
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]
107 compare_models(model1, model2)
108 if (seen_any) printf("\n");
109 compare_models(model2, model1)