diff --git a/analyze.py b/analyze.py index 263d64d..ddf7e5e 100644 --- a/analyze.py +++ b/analyze.py @@ -1,7 +1,8 @@ from __future__ import print_function import argparse -import sys +import os,sys,io from pycparser import parse_file, c_ast, CParser +from pcpp import Preprocessor import graphviz as gv from modelbuilder import * @@ -26,15 +27,27 @@ if __name__ == "__main__": #read whole file to a string source = f.read() + p = Preprocessor() + p.add_path('/usr/lib/gcc/x86_64-linux-gnu/12/include/') + + p.parse(source) + oh = io.StringIO() + p.write(oh) + prep_source = oh.getvalue() + + #print(prep_source) + #exit() + parser = CParser() - ast = parser.parse(comment_remover(source)) + ast = parser.parse(prep_source) #ast = parse_file(args.filename, use_cpp=False) assign_table = [] state_enums = [] func_table = {} enum_table = {} - + state_asmts = [] + fdv = FuncDefVisitor() fdv.visit(ast) func_table = fdv.func_table @@ -43,7 +56,8 @@ if __name__ == "__main__": etv.visit(ast) enum_table = etv.enums - state_asmts = [] + if not(args.func in func_table): + raise Exception(f"Function name '{args.func}' not found!") if args.enum in enum_table: ev = EnumVisitor() diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..8d35481 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +pycparser +graphviz +pcpp>=1.30