2 # SPDX-License-Identifier: GPL-2.0-only
10 def parse_of_declare_macros(data):
11 """ Find all compatible strings in OF_DECLARE() style macros """
13 # CPU_METHOD_OF_DECLARE does not have a compatible string
14 for m in re.finditer(r'(?<!CPU_METHOD_)(IRQCHIP|OF)_(DECLARE|MATCH)(_DRIVER)?\(.*?\)', data):
16 compat = re.search(r'"(.*?)"', m[0])[1]
18 # Fails on compatible strings in #define, so just skip
20 compat_list += [compat]
25 def parse_of_device_id(data):
26 """ Find all compatible strings in of_device_id structs """
28 for m in re.finditer(r'of_device_id(\s+\S+)?\s+\S+\[\](\s+\S+)?\s*=\s*({.*?);', data):
29 compat_list += re.findall(r'\.compatible\s+=\s+"(\S+)"', m[3])
34 def parse_compatibles(file):
35 with open(file, 'r', encoding='utf-8') as f:
36 data = f.read().replace('\n', '')
38 compat_list = parse_of_declare_macros(data)
39 compat_list += parse_of_device_id(data)
43 def print_compat(filename, compatibles):
47 compat_str = ' '.join(compatibles)
48 print(filename + ": compatible(s): " + compat_str)
50 print(*compatibles, sep='\n')
54 if __name__ == "__main__":
55 ap = argparse.ArgumentParser()
56 ap.add_argument("cfile", type=str, nargs='*', help="C source files or directories to parse")
57 ap.add_argument('-H', '--with-filename', help="Print filename with compatibles", action="store_true")
58 args = ap.parse_args()
60 show_filename = args.with_filename
64 for filename in glob.iglob(f + "/**/*.c", recursive=True):
65 compat_list = parse_compatibles(filename)
66 print_compat(filename, compat_list)
68 compat_list = parse_compatibles(f)
69 print_compat(f, compat_list)