Add clusters for modules

main
Michael Hayes 15 years ago
parent 5fdbdf984b
commit e07b57fb26

@ -1,5 +1,5 @@
#!/usr/bin/python #!/usr/bin/python
"""graphdeps V0.07 """graphdeps V0.08
Copyright (c) 2011 Michael P. Hayes, UC ECE, NZ Copyright (c) 2011 Michael P. Hayes, UC ECE, NZ
Usage: graphdeps Makefile Usage: graphdeps Makefile
@ -28,12 +28,16 @@ def parse_rules (filename):
# Look for targets ignoring targets starting with dot (.PHONY, etc). # Look for targets ignoring targets starting with dot (.PHONY, etc).
# This expects the command to be a single line. # This expects the command to be a single line.
matches = re.findall (r'^([a-z0-9._/\-]*):\s(.*)\n(.*)', text, re.MULTILINE) matches = re.findall (r'^([@a-z0-9._/\-]*):\s(.*)\n(.*)', text, re.MULTILINE)
rules = [] rules = []
for match in matches: for match in matches:
# Target, dependencies, command. target = match[0]
rule = (match[0], match[1].strip().split (' '), match[2].strip ()) filename = None
if '@' in target:
(target, filename) = target.split ('@')
# Target, dependencies, command, filename.
rule = (target, match[1].strip().split (' '), match[2].strip (), filename)
rules.append (rule) rules.append (rule)
return rules return rules
@ -227,6 +231,22 @@ def main(argv = None):
for target in wantedtargets: for target in wantedtargets:
target_output (dotfile, target, targets, modules, options) target_output (dotfile, target, targets, modules, options)
if options.calls and options.modules:
modules = {}
for rule in rules:
filename = rule[3]
if not filename:
continue
if not modules.has_key (filename):
modules[filename] = []
modules[filename].append (rule[0])
for module in modules.keys ():
dotfile.write ('\tsubgraph "cluster_' + module + '" {label = "' + module + '";')
for function in modules[module]:
dotfile.write (function + ';')
dotfile.write ('}\n')
dotfile.write ('}\n') dotfile.write ('}\n')
dotfile.close () dotfile.close ()

@ -1,5 +1,5 @@
#!/usr/bin/env python #!/usr/bin/env python
"""makemake V0.06 """makemake V0.07
Copyright (c) 2010 Michael P. Hayes, UC ECE, NZ Copyright (c) 2010 Michael P. Hayes, UC ECE, NZ
This program tries to make a Makefile from a template. Given a C file This program tries to make a Makefile from a template. Given a C file
@ -224,7 +224,7 @@ def maincfilename_find (dirname):
return filelist[0] return filelist[0]
def functions_find (gcc, filepath, functiondeps = {}): def functions_find (gcc, filepath, functiondeps = {}, functions = {}):
command = gcc + ' -c ' + filepath + ' -fdump-tree-cfg-raw > /dev/null' command = gcc + ' -c ' + filepath + ' -fdump-tree-cfg-raw > /dev/null'
# print >> sys.stderr, command # print >> sys.stderr, command
@ -248,6 +248,7 @@ def functions_find (gcc, filepath, functiondeps = {}):
if matches: if matches:
function = matches[0] function = matches[0]
functiondeps[function] = [] functiondeps[function] = []
functions[function] = filepath
# print >> sys.stderr, 'DEF', function # print >> sys.stderr, 'DEF', function
matches = re.findall (r'.*gimple_call <([\w]*),', line) matches = re.findall (r'.*gimple_call <([\w]*),', line)
if matches: if matches:
@ -362,14 +363,14 @@ def deps_print (target, depsdir, options, record = {}):
print os.path.relpath (target) + ': ' + ' '.join (deps) + '\n' print os.path.relpath (target) + ': ' + ' '.join (deps) + '\n'
def callgraph_print (target, depsdir, options, record = {}): def callgraph_print (target, functiondeps, functions, options, record = {}):
if record.has_key (target): if record.has_key (target):
return return
if not depsdir.has_key (target): if not functiondeps.has_key (target):
return return
deps = depsdir[target] deps = functiondeps[target]
# print >> sys.stderr, target + ': ', deps # print >> sys.stderr, target + ': ', deps
@ -382,11 +383,13 @@ def callgraph_print (target, depsdir, options, record = {}):
if dep[0] == '@': if dep[0] == '@':
dep = dep[1:] dep = dep[1:]
deps_print (dep, depsdir, options, record) callgraph_print (dep, functiondeps, functions, options, record)
record[target] = True record[target] = True
print os.path.relpath (target) + ': ' + ' '.join (deps) + '\n' # print os.path.relpath (target) + ': ' + ' '.join (deps) + '\n' + '\t' + os.path.basename (functions[target]) + '\n'
print os.path.relpath (target) + '@' + os.path.basename (functions[target]) + ': ' + ' '.join (deps) + '\n'
@ -508,7 +511,6 @@ def main(argv = None):
filedeps = {} filedeps = {}
moduledeps = {} moduledeps = {}
functiondeps = {}
files_find (gcc, maincfilename, search_path, filedeps, moduledeps, '', options.debug) files_find (gcc, maincfilename, search_path, filedeps, moduledeps, '', options.debug)
cfilelist = cfiles_get (filedeps) cfilelist = cfiles_get (filedeps)
@ -524,9 +526,11 @@ def main(argv = None):
# print >> sys.stderr, filedeps # print >> sys.stderr, filedeps
if options.calls: if options.calls:
functiondeps = {}
functions = {}
for cfile in cfilelist: for cfile in cfilelist:
functions_find (gcc, cfile, functiondeps) functions_find (gcc, cfile, functiondeps, functions)
callgraph_print ('main', functiondeps, options) callgraph_print ('main', functiondeps, functions, options)
if options.files: if options.files:
deps_print (outfile, filedeps, options) deps_print (outfile, filedeps, options)

Loading…
Cancel
Save