]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - sim/igen/compare_igen_models
Copyright updates for 2007.
[thirdparty/binutils-gdb.git] / sim / igen / compare_igen_models
1 #!/bin/sh
2
3 # Script to compare functions and instructions used by different igen models.
4 # Copyright (C) 2002, 2007 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 2, or (at your option)
12 # 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 along
20 # with this program; if not, write to the Free Software Foundation, Inc.,
21 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22
23 # This is a simple-minded script to compare the functions and instructions
24 # listed for two different models in one or more .igen files.
25 #
26 # It was intended to be useful to help factor models into common subsets.
27 #
28 # Things to note:
29 #
30 # * igen include directives are not processed!
31 #
32 # * functions and instructions with multiple definitions (e.g., based
33 # on model names) are treated as being different. In other words,
34 # if two models have different functions named 'foo', this
35 # script will say that one has one of the function definitions, and
36 # the other has the other.
37
38 if [ "$#" -lt 2 ]; then
39 echo "usage: $0 model1 model2 [file ...]" 1>&2
40 exit 1
41 fi
42 model1="$1"
43 model2="$2"
44 shift; shift
45
46 gawk -v model1="$model1" -v model2="$model2" -F: -- '
47 BEGIN {
48 thang_count = 0
49 }
50 function thang_has_model(t, m) {
51 # printf("thang_has_model(%s, %s) (@ %s:%d)\n", t, m,
52 # thangs[t,"file"], thangs[t,"line"]);
53 if (thangs[t,"nmodels"] == 0) return 1;
54
55 for (j = 0; j < thangs[t,"nmodels"]; j++) {
56 # printf("\tmodel \"%s\"\n", thangs[t,"models",j]);
57 if (thangs[t,"models",j] == m) return 1;
58 }
59 # printf("\t-> 0\n");
60 return 0
61 }
62 function compare_models(m1, m2) {
63 # printf("compare_models(%s, %s)\n", m1, m2);
64 seen_any=0
65 for (i = 0; i < thang_count; i++) {
66 if (thang_has_model(i, m1) && !thang_has_model(i, m2)) {
67 if (!seen_any) {
68 printf("Things in %s but not in %s:\n", m1, m2);
69 seen_any = 1
70 }
71 printf("%s:%d: %s\n", thangs[i,"file"],
72 thangs[i,"line"], thangs[i,"contents"]);
73 }
74 }
75 }
76 $0 ~ /^:/ && $2 == "model" {
77 # ignore.
78 # print "model " $0
79 }
80 ($0 ~ /^:/ && $2 == "function") || \
81 ($0 ~ /^:/ && $2 == "internal") || \
82 ($0 ~ /^[0-9]/) {
83 # a function, internal, or instruction.
84
85 current_thang = thang_count
86 thang_count++
87
88 thangs[current_thang,"file"] = FILENAME
89 thangs[current_thang,"line"] = NR
90 thangs[current_thang,"contents"] = $0
91 thangs[current_thang,"nmodels"] = 0
92
93 if ($0 ~ /^:/) {
94 thangs[current_thang,"type"] = $2
95 } else {
96 thangs[current_thang,"type"] = "instruction"
97 }
98 }
99 $0 ~ /^\*/ {
100 split(substr($1, 2), tmp_models, /,/)
101 for (key in tmp_models) {
102 current_model = thangs[current_thang,"nmodels"]
103 thangs[current_thang,"nmodels"]++
104 thangs[current_thang,"models",current_model] = tmp_models[key]
105 }
106 }
107 END {
108 compare_models(model1, model2)
109 if (seen_any) printf("\n");
110 compare_models(model2, model1)
111 }' "$@"
112
113 exit "$?"