source: buchla-68k/misc/valid.py@ 7c5def4

Last change on this file since 7c5def4 was 83ea432, checked in by Thomas Lopatic <thomas@…>, 7 years ago

Script for consistency check.

  • Property mode set to 100755
File size: 1.2 KB
Line 
1#!/usr/bin/env python3
2
3from sys import stdout
4from pycparser import c_ast, parse_file, c_generator
5
6cross_gcc = "/opt/cross-m68k/bin/m68k-none-elf-gcc"
7
8gen = c_generator.CGenerator()
9decls = {}
10
11with open("misc/c-files.txt", "r") as f:
12 for path in f:
13 path = path.rstrip()
14
15 stdout.write("parsing {} \r".format(path))
16 stdout.flush()
17
18 ast = parse_file(path, use_cpp = True, cpp_path = cross_gcc,
19 cpp_args = ["-E", "-D", "PYCP", "-I", "include"])
20 # ast.show()
21
22 for node in ast.ext:
23 decl = None
24
25 if type(node) is c_ast.Decl and \
26 node.name is not None:
27 decl = node
28
29 elif type(node) is c_ast.FuncDef:
30 decl = node.decl
31
32 else:
33 continue
34
35 decl.storage = [x for x in decl.storage if x != "extern"]
36 decl.init = None
37
38 text = gen.visit(decl)
39
40 if decl.name in decls:
41 if decls[decl.name] != text:
42 print("Inconsistency: {} vs. {}".format(text, decls[decl.name]))
43
44 else:
45 decls[decl.name] = text
46
47print("")
Note: See TracBrowser for help on using the repository browser.