Mercurial > codeOptimizer
comparison codeOptimizer.py @ 4:3a56cd936c59
Cleanup some code.
Add code for breaking loops in the dependency tree.
| author | Tom Fredrik Blenning Klaussen <bfg@blenning.no> |
|---|---|
| date | Mon, 24 Sep 2012 01:16:43 +0200 |
| parents | f65c2d63ab66 |
| children | 94b1959b0108 |
comparison
equal
deleted
inserted
replaced
| 3:f65c2d63ab66 | 4:3a56cd936c59 |
|---|---|
| 5 from Compilable import Compilable | 5 from Compilable import Compilable |
| 6 from DepGraph import DepGraph | 6 from DepGraph import DepGraph |
| 7 from Config import Config | 7 from Config import Config |
| 8 | 8 |
| 9 | 9 |
| 10 def usage(name): | |
| 11 print "Usage is:\n\t%s <xml configuration file> [files for analysis]" % name | |
| 10 | 12 |
| 11 def isHppfile(name): | 13 if len(sys.argv) < 2: |
| 12 if name.endswith(".hpp"): | 14 usage(sys.argv[0]) |
| 13 return True | 15 sys.exit(1) |
| 14 if name.endswith(".h"): | |
| 15 return True | |
| 16 return False | |
| 17 | |
| 18 def isCppfile(name): | |
| 19 if name.endswith(".cpp"): | |
| 20 return True | |
| 21 return False | |
| 22 | 16 |
| 23 try: | 17 try: |
| 24 options = Config(sys.argv[1]) | 18 options = Config(sys.argv[1]) |
| 25 except: | 19 except: |
| 26 print sys.argv[1] + ' is not a valid xml file' | 20 print sys.argv[1] + ' is not a valid xml file' |
| 21 sys.exit(1) | |
| 22 | |
| 27 infiles = sys.argv[2:] | 23 infiles = sys.argv[2:] |
| 24 | |
| 25 if not infiles: | |
| 26 infiles = options.getFiles() | |
| 28 | 27 |
| 29 files = {} | 28 files = {} |
| 30 unknown = [] | 29 unknown = [] |
| 31 | 30 |
| 32 for file in infiles: | 31 for file in infiles: |
| 33 if isHppfile(file) or isCppfile(file): | 32 if Compilable.acceptsFile(file): |
| 34 c = Compilable(file) | 33 c = Compilable(file) |
| 35 c.setFlags(options.getCxxflags(file)) | 34 c.setFlags(options.getCxxflags(file)) |
| 36 files[file] = c | 35 files[file] = c |
| 37 else: | 36 else: |
| 38 unknown.append(file) | 37 unknown.append(file) |
| 45 | 44 |
| 46 for file in files: | 45 for file in files: |
| 47 depgraph.add(files[file]) | 46 depgraph.add(files[file]) |
| 48 | 47 |
| 49 for file in files: | 48 for file in files: |
| 50 depgraph.addDependency(files[file], files[file].dependencies()) | 49 depgraph.addDependency(files[file], |
| 50 list(files[dep] | |
| 51 for dep in files[file].dependencies())) | |
| 51 | 52 |
| 52 files = depgraph.directedGraph() | 53 files = depgraph.directedGraph() |
| 54 print files | |
| 53 | 55 |
| 54 for file in files: | 56 for file in files: |
| 55 if not file.worksWithoutModifications(): | 57 if not file.worksWithoutModifications(): |
| 56 print file.path | 58 print files[file].path |
| 57 raise SystemExit(file.path + " does not compile at all") | 59 raise SystemExit(file.path + " does not compile at all") |
| 58 | 60 |
| 59 for file in files: | 61 for file in files: |
| 60 removable = file.removeRemovableIncludes() | 62 removable = file.removeRemovableIncludes() |
| 61 if removable: | 63 if removable: |
