diff python/zcc.py @ 105:6a303f835c6d

Removed compilers directory
author Windel Bouwman
date Mon, 31 Dec 2012 17:35:17 +0100
parents ed230e947dc6
children f2d980eef509
line wrap: on
line diff
--- a/python/zcc.py	Sun Dec 30 22:31:55 2012 +0100
+++ b/python/zcc.py	Mon Dec 31 17:35:17 2012 +0100
@@ -1,26 +1,35 @@
 #!/usr/bin/python
 
 import sys, os, argparse
-from ppci.compilers import KsCompiler
-from ppci.core import BitcodeWriter
+from ppci import core
+
+parser = argparse.ArgumentParser(description='K# to bitcode compiler')
+parser.add_argument('source', type=str, help='the source file to build')
+args = parser.parse_args()
 
-if __name__ == '__main__':
-   parser = argparse.ArgumentParser(description='K# to bitcode compiler')
-   parser.add_argument('source', type=str, help='the source file to build')
-   args = parser.parse_args()
+try:
+   with open(args.source, 'r') as f:
+      src = f.read()
+except IOError:
+   print('Failed to load {0}'.format(args.source))
+   sys.exit(1)
 
-   print(args)
-   try:
-      with open(args.source, 'r') as f:
-         src = f.read()
-   except IOError:
-      print('Failed to load {0}'.format(args.project))
-      sys.exit(3)
-   c = KsCompiler()
-   module = c.compilesource(src)
+# Create a context and a frontend:
+context = core.Context()
+frontend = core.frontends.ks.KsFrontend(context)
+try:
+   module = frontend.compilesource(src)
+except core.CompilerException as e:
+   print(e)
+   sys.exit(2)
 
-   with open('sjaak.bc', 'wb') as f:
-      BitcodeWriter().WriteModuleToFile(module, f)
+# optionally run passes here:
+# TODO
+
+# Generate code:
+bitcodeWriter = core.BitcodeWriter()
+with open(args.source + '.bc', 'wb') as f:
+   bitcodeWriter.WriteModuleToFile(module, f)