aboutsummaryrefslogtreecommitdiff
path: root/sim/igen/compare_igen_models
blob: 32dc0a9b81bb5e9eed5353b0a56371c334b3f8b7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/bin/sh

# Script to compare functions and instructions used by different igen models.
# Copyright (C) 2002-2019 Free Software Foundation, Inc.
# Contributed by Chris Demetriou of Broadcom Corporation (SiByte).
#
# This file is part of GDB, the GNU debugger.
# 
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# This is a simple-minded script to compare the functions and instructions
# listed for two different models in one or more .igen files.
#
# It was intended to be useful to help factor models into common subsets.
#
# Things to note:
#
#    * igen include directives are not processed!
#
#    * functions and instructions with multiple definitions (e.g., based
#      on model names) are treated as being different.  In other words,
#      if two models have different functions named 'foo', this
#      script will say that one has one of the function definitions, and
#      the other has the other.

if [ "$#" -lt 2 ]; then
	echo "usage: $0 model1 model2 [file ...]" 1>&2
	exit 1
fi
model1="$1"
model2="$2"
shift; shift

gawk -v model1="$model1" -v model2="$model2" -F: -- '
BEGIN {
	thang_count = 0
}
function thang_has_model(t, m) {
#	printf("thang_has_model(%s, %s) (@ %s:%d)\n", t, m,
#	       thangs[t,"file"], thangs[t,"line"]);
	if (thangs[t,"nmodels"] == 0) return 1;

	for (j = 0; j < thangs[t,"nmodels"]; j++) {
#		printf("\tmodel \"%s\"\n", thangs[t,"models",j]);
		if (thangs[t,"models",j] == m) return 1;
	}
#	printf("\t-> 0\n");
	return 0
}
function compare_models(m1, m2) {
#	printf("compare_models(%s, %s)\n", m1, m2);
	seen_any=0
	for (i = 0; i < thang_count; i++) {
		if (thang_has_model(i, m1) && !thang_has_model(i, m2)) {
			if (!seen_any) {
				printf("Things in %s but not in %s:\n", m1, m2);
				seen_any = 1
			}
			printf("%s:%d: %s\n", thangs[i,"file"],
			       thangs[i,"line"], thangs[i,"contents"]);
		}
	}
}
$0 ~ /^:/ && $2 == "model" {
	# ignore.
	# print "model " $0
}
($0 ~ /^:/ && $2 == "function") || \
($0 ~ /^:/ && $2 == "internal") || \
($0 ~ /^[0-9]/) {
	# a function, internal, or instruction.

	current_thang = thang_count
	thang_count++

	thangs[current_thang,"file"] = FILENAME
	thangs[current_thang,"line"] = NR
	thangs[current_thang,"contents"] = $0
	thangs[current_thang,"nmodels"] = 0

	if ($0 ~ /^:/) {
		thangs[current_thang,"type"] = $2
	} else {
		thangs[current_thang,"type"] = "instruction"
	}
}
$0 ~ /^\*/ {
	split(substr($1, 2), tmp_models, /,/)
	for (key in tmp_models) {
		current_model = thangs[current_thang,"nmodels"]
		thangs[current_thang,"nmodels"]++
		thangs[current_thang,"models",current_model] = tmp_models[key]
	}
}
END {
	compare_models(model1, model2)
	if (seen_any) printf("\n");
	compare_models(model2, model1)
}' "$@"

exit "$?"