diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/codeOptimizer.py	Sat Sep 15 20:34:39 2012 +0200
@@ -0,0 +1,70 @@
+#!/usr/bin/env python -O
+
+import sys, string, os, subprocess
+
+from Compilable import Compilable
+from DepGraph import DepGraph
+
+
+
+def isHppfile(name):
+    if name.endswith(".hpp"):
+        return True
+    if name.endswith(".h"):
+        return True
+    return False
+
+def isCppfile(name):
+    if name.endswith(".cpp"):
+        return True
+    return False
+
+
+infiles = sys.argv[1:]
+
+cppfiles = {}
+unknown = []
+
+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'
+
+for file in infiles:
+    if isHppfile(file) or isCppfile(file):
+        c = Compilable(file)
+        c.setFlags(flags)
+        cppfiles[file] = c
+    else:
+        unknown.append(file)
+
+if len(unknown) > 0:
+    str = ", "
+    raise SystemExit(str.join(unknown)  + " are of unknown filetype")
+
+files = cppfiles
+
+depgraph = DepGraph()
+
+for file in files:
+    depgraph.add(files[file])
+
+for file in files:
+    depgraph.addDependency(files[file], files[file].dependencies())
+
+files = depgraph.directedGraph()
+
+for file in files:
+    if not file.worksWithoutModifications():
+        print file.path
+        raise SystemExit(str.join(file.path)  + " does not compile at all")
+
+for file in files:
+    removable = file.removeRemovableIncludes()
+    if removable:
+        print 'Removable lines in ' + file.path
+        for r in removable:
+            print str(r) + ' : ' + file.lines[r].rstrip()
+            
+    replacable = file.replaceIncludes()
+    if replacable:
+        print 'Replacable lines in ' + file.path
+        for r in replacable:
+            print str(r) + ' : ' + file.lines[r].rstrip()