|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import sys |
|
|
|
|
|
|
|
sys.path.extend(['.', '..']) |
|
|
|
from pycparser import c_ast, parse_file |
|
|
|
|
|
class FuncCallVisitor(c_ast.NodeVisitor): |
|
def __init__(self, funcname): |
|
self.funcname = funcname |
|
|
|
def visit_FuncCall(self, node): |
|
if node.name.name == self.funcname: |
|
print('%s called at %s' % (self.funcname, node.name.coord)) |
|
|
|
if node.args: |
|
self.visit(node.args) |
|
|
|
|
|
def show_func_calls(filename, funcname): |
|
ast = parse_file(filename, use_cpp=True) |
|
v = FuncCallVisitor(funcname) |
|
v.visit(ast) |
|
|
|
|
|
if __name__ == "__main__": |
|
if len(sys.argv) > 2: |
|
filename = sys.argv[1] |
|
func = sys.argv[2] |
|
else: |
|
filename = 'examples/c_files/basic.c' |
|
func = 'foo' |
|
|
|
show_func_calls(filename, func) |
|
|