Mercurial > lcfOS
diff python/zcc.py @ 287:1c7c1e619be8
File movage
author | Windel Bouwman |
---|---|
date | Thu, 21 Nov 2013 11:57:27 +0100 |
parents | 4496cae24d7f |
children | a747a45dcd78 |
line wrap: on
line diff
--- a/python/zcc.py Fri Nov 15 13:52:32 2013 +0100 +++ b/python/zcc.py Thu Nov 21 11:57:27 2013 +0100 @@ -1,12 +1,16 @@ #!/usr/bin/python -import sys, argparse -import c3, ppci, codegen +import sys +import argparse +import logging + +import c3 +import ppci +import codegen import codegenarm from optimize import optimize import outstream import hexfile -import logging logformat='%(asctime)s|%(levelname)s|%(name)s|%(message)s' @@ -18,45 +22,54 @@ # Parse arguments: parser = argparse.ArgumentParser(description='lcfos Compiler') +# Input: parser.add_argument('source', type=argparse.FileType('r'), \ - help='the source file to build') + help='the source file to build', nargs="+") +parser.add_argument('-i', '--import', type=argparse.FileType('r'), \ + help='Possible import module', action='append') + parser.add_argument('--dumpir', action='store_true', help="Dump IR-code") parser.add_argument('--dumpasm', action='store_true', help="Dump ASM-code") parser.add_argument('--optimize', action='store_true', help="Optimize") -parser.add_argument('--package_dir', help="Look in this directory for packages") +parser.add_argument('--target', help="Backend selection") parser.add_argument('-o', '--output', help='Output file', metavar='filename') parser.add_argument('--hexfile', help='Output hexfile', type=argparse.FileType('w')) parser.add_argument('--log', help='Log level (INFO,DEBUG)', type=logLevel) -def zcc(src, outs, diag, dumpir=False, do_optimize=False, pack_dir=None): +def zcc(srcs, outs, diag, dumpir=False, do_optimize=False): + """ + Compile sources into output stream. + Sources is an iterable of open files. + """ logging.info('Zcc started') # Front end: c3b = c3.Builder(diag) - ircode = c3b.build(src, pack_dir=pack_dir) - if not ircode: - return + imps = [] + for ircode in c3b.build(srcs, imps): + print(ircode) + if not ircode: + return - # Optimization passes: - if do_optimize: - optimize(ircode) + # Optimization passes: + if do_optimize: + optimize(ircode) - if dumpir: - ircode.dump() + if dumpir: + ircode.dump() - # Code generation: - cg = codegenarm.ArmCodeGenerator(outs) - obj = cg.generate(ircode) + # Code generation: + cg = codegenarm.ArmCodeGenerator(outs) + obj = cg.generate(ircode) return True def main(args): logging.basicConfig(format=logformat, level=args.log) - src = args.source.read() - args.source.close() + src = args.source diag = ppci.DiagnosticsManager() outs = outstream.TextOutputStream() # Invoke compiler: - res = zcc(src, outs, diag, dumpir=args.dumpir, do_optimize=args.optimize, pack_dir=args.package_dir) + res = zcc(src, outs, diag, dumpir=args.dumpir, do_optimize=args.optimize) if not res: diag.printErrors(src) return 1 @@ -65,14 +78,10 @@ outs.dump() code_bytes = outs.sections['code'].to_bytes() - #print('bytes:', code_bytes) if args.output: output_filename = args.output - else: - output_filename = 'b.output' - - with open(output_filename, 'wb') as f: - f.write(code_bytes) + with open(output_filename, 'wb') as f: + f.write(code_bytes) if args.hexfile: logging.info('Creating hexfile') @@ -83,5 +92,6 @@ if __name__ == '__main__': arguments = parser.parse_args() + print(arguments) sys.exit(main(arguments))