annotate python/zcc.py @ 104:ed230e947dc6

Added hexviewer
author windel
date Sun, 30 Dec 2012 22:31:55 +0100
parents
children 6a303f835c6d
rev   line source
104
ed230e947dc6 Added hexviewer
windel
parents:
diff changeset
1 #!/usr/bin/python
ed230e947dc6 Added hexviewer
windel
parents:
diff changeset
2
ed230e947dc6 Added hexviewer
windel
parents:
diff changeset
3 import sys, os, argparse
ed230e947dc6 Added hexviewer
windel
parents:
diff changeset
4 from ppci.compilers import KsCompiler
ed230e947dc6 Added hexviewer
windel
parents:
diff changeset
5 from ppci.core import BitcodeWriter
ed230e947dc6 Added hexviewer
windel
parents:
diff changeset
6
ed230e947dc6 Added hexviewer
windel
parents:
diff changeset
7 if __name__ == '__main__':
ed230e947dc6 Added hexviewer
windel
parents:
diff changeset
8 parser = argparse.ArgumentParser(description='K# to bitcode compiler')
ed230e947dc6 Added hexviewer
windel
parents:
diff changeset
9 parser.add_argument('source', type=str, help='the source file to build')
ed230e947dc6 Added hexviewer
windel
parents:
diff changeset
10 args = parser.parse_args()
ed230e947dc6 Added hexviewer
windel
parents:
diff changeset
11
ed230e947dc6 Added hexviewer
windel
parents:
diff changeset
12 print(args)
ed230e947dc6 Added hexviewer
windel
parents:
diff changeset
13 try:
ed230e947dc6 Added hexviewer
windel
parents:
diff changeset
14 with open(args.source, 'r') as f:
ed230e947dc6 Added hexviewer
windel
parents:
diff changeset
15 src = f.read()
ed230e947dc6 Added hexviewer
windel
parents:
diff changeset
16 except IOError:
ed230e947dc6 Added hexviewer
windel
parents:
diff changeset
17 print('Failed to load {0}'.format(args.project))
ed230e947dc6 Added hexviewer
windel
parents:
diff changeset
18 sys.exit(3)
ed230e947dc6 Added hexviewer
windel
parents:
diff changeset
19 c = KsCompiler()
ed230e947dc6 Added hexviewer
windel
parents:
diff changeset
20 module = c.compilesource(src)
ed230e947dc6 Added hexviewer
windel
parents:
diff changeset
21
ed230e947dc6 Added hexviewer
windel
parents:
diff changeset
22 with open('sjaak.bc', 'wb') as f:
ed230e947dc6 Added hexviewer
windel
parents:
diff changeset
23 BitcodeWriter().WriteModuleToFile(module, f)
ed230e947dc6 Added hexviewer
windel
parents:
diff changeset
24
ed230e947dc6 Added hexviewer
windel
parents:
diff changeset
25
ed230e947dc6 Added hexviewer
windel
parents:
diff changeset
26