1#!/bin/sh 2 3# Script to compare functions and instructions used by different igen models. 4# Copyright (C) 2002, 2007, 2008, 2009, 2010, 2011 5# Free Software Foundation, Inc. 6# Contributed by Chris Demetriou of Broadcom Corporation (SiByte). 7# 8# This file is part of GDB, the GNU debugger. 9# 10# This program is free software; you can redistribute it and/or modify 11# it under the terms of the GNU General Public License as published by 12# the Free Software Foundation; either version 3 of the License, or 13# (at your option) any later version. 14# 15# This program is distributed in the hope that it will be useful, 16# but WITHOUT ANY WARRANTY; without even the implied warranty of 17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18# GNU General Public License for more details. 19# 20# You should have received a copy of the GNU General Public License 21# along with this program. If not, see <http://www.gnu.org/licenses/>. 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 38if [ "$#" -lt 2 ]; then 39 echo "usage: $0 model1 model2 [file ...]" 1>&2 40 exit 1 41fi 42model1="$1" 43model2="$2" 44shift; shift 45 46gawk -v model1="$model1" -v model2="$model2" -F: -- ' 47BEGIN { 48 thang_count = 0 49} 50function 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} 62function 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} 107END { 108 compare_models(model1, model2) 109 if (seen_any) printf("\n"); 110 compare_models(model2, model1) 111}' "$@" 112 113exit "$?" 114