Add clusters for modules
This commit is contained in:
+24
-4
@@ -1,5 +1,5 @@
|
||||
#!/usr/bin/python
|
||||
"""graphdeps V0.07
|
||||
"""graphdeps V0.08
|
||||
Copyright (c) 2011 Michael P. Hayes, UC ECE, NZ
|
||||
|
||||
Usage: graphdeps Makefile
|
||||
@@ -28,12 +28,16 @@ def parse_rules (filename):
|
||||
|
||||
# Look for targets ignoring targets starting with dot (.PHONY, etc).
|
||||
# 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 = []
|
||||
for match in matches:
|
||||
# Target, dependencies, command.
|
||||
rule = (match[0], match[1].strip().split (' '), match[2].strip ())
|
||||
target = match[0]
|
||||
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)
|
||||
|
||||
return rules
|
||||
@@ -227,6 +231,22 @@ def main(argv = None):
|
||||
for target in wantedtargets:
|
||||
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.close ()
|
||||
|
||||
|
||||
+14
-10
@@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env python
|
||||
"""makemake V0.06
|
||||
"""makemake V0.07
|
||||
Copyright (c) 2010 Michael P. Hayes, UC ECE, NZ
|
||||
|
||||
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]
|
||||
|
||||
|
||||
def functions_find (gcc, filepath, functiondeps = {}):
|
||||
def functions_find (gcc, filepath, functiondeps = {}, functions = {}):
|
||||
|
||||
command = gcc + ' -c ' + filepath + ' -fdump-tree-cfg-raw > /dev/null'
|
||||
# print >> sys.stderr, command
|
||||
@@ -248,6 +248,7 @@ def functions_find (gcc, filepath, functiondeps = {}):
|
||||
if matches:
|
||||
function = matches[0]
|
||||
functiondeps[function] = []
|
||||
functions[function] = filepath
|
||||
# print >> sys.stderr, 'DEF', function
|
||||
matches = re.findall (r'.*gimple_call <([\w]*),', line)
|
||||
if matches:
|
||||
@@ -362,14 +363,14 @@ def deps_print (target, depsdir, options, record = {}):
|
||||
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):
|
||||
return
|
||||
if not depsdir.has_key (target):
|
||||
if not functiondeps.has_key (target):
|
||||
return
|
||||
|
||||
deps = depsdir[target]
|
||||
deps = functiondeps[target]
|
||||
|
||||
# print >> sys.stderr, target + ': ', deps
|
||||
|
||||
@@ -382,11 +383,13 @@ def callgraph_print (target, depsdir, options, record = {}):
|
||||
if dep[0] == '@':
|
||||
dep = dep[1:]
|
||||
|
||||
deps_print (dep, depsdir, options, record)
|
||||
callgraph_print (dep, functiondeps, functions, options, record)
|
||||
|
||||
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 = {}
|
||||
moduledeps = {}
|
||||
functiondeps = {}
|
||||
files_find (gcc, maincfilename, search_path, filedeps, moduledeps, '', options.debug)
|
||||
|
||||
cfilelist = cfiles_get (filedeps)
|
||||
@@ -524,9 +526,11 @@ def main(argv = None):
|
||||
# print >> sys.stderr, filedeps
|
||||
|
||||
if options.calls:
|
||||
functiondeps = {}
|
||||
functions = {}
|
||||
for cfile in cfilelist:
|
||||
functions_find (gcc, cfile, functiondeps)
|
||||
callgraph_print ('main', functiondeps, options)
|
||||
functions_find (gcc, cfile, functiondeps, functions)
|
||||
callgraph_print ('main', functiondeps, functions, options)
|
||||
|
||||
if options.files:
|
||||
deps_print (outfile, filedeps, options)
|
||||
|
||||
Reference in New Issue
Block a user