1181254a7Smrg#!/usr/bin/env python3 2181254a7Smrg# 3181254a7Smrg# Find missing and extra parameters in documentation compared to 4181254a7Smrg# output of: gcc --help=params. 5181254a7Smrg# 6181254a7Smrg# This file is part of GCC. 7181254a7Smrg# 8181254a7Smrg# GCC is free software; you can redistribute it and/or modify it under 9181254a7Smrg# the terms of the GNU General Public License as published by the Free 10181254a7Smrg# Software Foundation; either version 3, or (at your option) any later 11181254a7Smrg# version. 12181254a7Smrg# 13181254a7Smrg# GCC is distributed in the hope that it will be useful, but WITHOUT ANY 14181254a7Smrg# WARRANTY; without even the implied warranty of MERCHANTABILITY or 15181254a7Smrg# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 16181254a7Smrg# for more details. 17181254a7Smrg# 18181254a7Smrg# You should have received a copy of the GNU General Public License 19181254a7Smrg# along with GCC; see the file COPYING3. If not see 20181254a7Smrg# <http://www.gnu.org/licenses/>. */ 21181254a7Smrg# 22181254a7Smrg# 23181254a7Smrg# 24181254a7Smrg 25181254a7Smrgimport argparse 26*b1e83836Smrgimport sys 27*b1e83836Smrgfrom itertools import dropwhile, takewhile 28181254a7Smrg 29181254a7Smrg 30181254a7Smrgdef get_param_tuple(line): 31*b1e83836Smrg line = line.strip().replace('--param=', '') 32181254a7Smrg i = line.find(' ') 33*b1e83836Smrg name = line[:i] 34*b1e83836Smrg if '=' in name: 35*b1e83836Smrg name = name[:name.find('=')] 36*b1e83836Smrg description = line[i:].strip() 37*b1e83836Smrg return (name, description) 38*b1e83836Smrg 39181254a7Smrg 40181254a7Smrgparser = argparse.ArgumentParser() 41181254a7Smrgparser.add_argument('texi_file') 42181254a7Smrgparser.add_argument('params_output') 43181254a7Smrg 44181254a7Smrgargs = parser.parse_args() 45181254a7Smrg 46*b1e83836Smrgignored = {'logical-op-non-short-circuit'} 47181254a7Smrgparams = {} 48181254a7Smrg 49181254a7Smrgfor line in open(args.params_output).readlines(): 50*b1e83836Smrg if line.startswith(' ' * 2) and not line.startswith(' ' * 8): 51181254a7Smrg r = get_param_tuple(line) 52181254a7Smrg params[r[0]] = r[1] 53181254a7Smrg 54181254a7Smrg# Find section in .texi manual with parameters 55181254a7Smrgtexi = ([x.strip() for x in open(args.texi_file).readlines()]) 56*b1e83836Smrgtexi = dropwhile(lambda x: 'item --param' not in x, texi) 57*b1e83836Smrgtexi = takewhile(lambda x: '@node Instrumentation Options' not in x, texi) 58181254a7Smrgtexi = list(texi)[1:] 59181254a7Smrg 60*b1e83836Smrgtexi_params = [] 61*b1e83836Smrgfor line in texi: 62*b1e83836Smrg for token in ('@item ', '@itemx '): 63*b1e83836Smrg if line.startswith(token): 64*b1e83836Smrg texi_params.append(line[len(token):]) 65*b1e83836Smrg break 66181254a7Smrg 67*b1e83836Smrg# skip digits 68*b1e83836Smrgtexi_params = [x for x in texi_params if not x[0].isdigit()] 69*b1e83836Smrg# skip aarch64 params 70*b1e83836Smrgtexi_params = [x for x in texi_params if not x.startswith('aarch64')] 71*b1e83836Smrgsorted_params = sorted(texi_params) 72*b1e83836Smrg 73*b1e83836Smrgtexi_set = set(texi_params) - ignored 74181254a7Smrgparams_set = set(params.keys()) - ignored 75181254a7Smrg 76*b1e83836Smrgsuccess = True 77181254a7Smrgextra = texi_set - params_set 78181254a7Smrgif len(extra): 79181254a7Smrg print('Extra:') 80181254a7Smrg print(extra) 81*b1e83836Smrg success = False 82181254a7Smrg 83181254a7Smrgmissing = params_set - texi_set 84181254a7Smrgif len(missing): 85181254a7Smrg print('Missing:') 86181254a7Smrg for m in missing: 87181254a7Smrg print('@item ' + m) 88181254a7Smrg print(params[m]) 89181254a7Smrg print() 90*b1e83836Smrg success = False 91181254a7Smrg 92*b1e83836Smrgsys.exit(0 if success else 1) 93