comparison codeOptimizer.py @ 0:28b636105ed6

Working version of codeOptimizer. -Still needs to implement more finegrained control per file basis. -CXXFLAGS are hardcoded.
author Tom Fredrik Blenning Klaussen <bfg@blenning.no>
date Sat, 15 Sep 2012 20:34:39 +0200
parents
children a1224150b8f6
comparison
equal deleted inserted replaced
-1:000000000000 0:28b636105ed6
1 #!/usr/bin/env python -O
2
3 import sys, string, os, subprocess
4
5 from Compilable import Compilable
6 from DepGraph import DepGraph
7
8
9
10 def isHppfile(name):
11 if name.endswith(".hpp"):
12 return True
13 if name.endswith(".h"):
14 return True
15 return False
16
17 def isCppfile(name):
18 if name.endswith(".cpp"):
19 return True
20 return False
21
22
23 infiles = sys.argv[1:]
24
25 cppfiles = {}
26 unknown = []
27
28 flags = '-DHAS_BOOST -DQT_NO_DEBUG -DQT_OPENGL_LIB -DQT_XML_LIB -DQT_SQL_LIB -O3 -Wall -I/opt/local/include -I/Users/bfg/QtSDK/Desktop/Qt/4.8.1/gcc/include -F/Users/bfg/QtSDK/Desktop/Qt/4.8.1/gcc/lib -I/Users/bfg/QtSDK/Desktop/Qt/4.8.1/gcc/include/QtOpenGL -I/Users/bfg/QtSDK/Desktop/Qt/4.8.1/gcc/include/QtXml -I/Users/bfg/QtSDK/Desktop/Qt/4.8.1/gcc/include/QtSql -I/Users/bfg/projects/dedupe'
29
30 for file in infiles:
31 if isHppfile(file) or isCppfile(file):
32 c = Compilable(file)
33 c.setFlags(flags)
34 cppfiles[file] = c
35 else:
36 unknown.append(file)
37
38 if len(unknown) > 0:
39 str = ", "
40 raise SystemExit(str.join(unknown) + " are of unknown filetype")
41
42 files = cppfiles
43
44 depgraph = DepGraph()
45
46 for file in files:
47 depgraph.add(files[file])
48
49 for file in files:
50 depgraph.addDependency(files[file], files[file].dependencies())
51
52 files = depgraph.directedGraph()
53
54 for file in files:
55 if not file.worksWithoutModifications():
56 print file.path
57 raise SystemExit(str.join(file.path) + " does not compile at all")
58
59 for file in files:
60 removable = file.removeRemovableIncludes()
61 if removable:
62 print 'Removable lines in ' + file.path
63 for r in removable:
64 print str(r) + ' : ' + file.lines[r].rstrip()
65
66 replacable = file.replaceIncludes()
67 if replacable:
68 print 'Replacable lines in ' + file.path
69 for r in replacable:
70 print str(r) + ' : ' + file.lines[r].rstrip()