Mercurial > lcfOS
comparison python/c3c.py @ 400:0374c65cb437
Move compiler to seperate repo
author | Windel Bouwman |
---|---|
date | Mon, 14 Jul 2014 22:23:55 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
399:a7c444404df9 | 400:0374c65cb437 |
---|---|
1 #!/usr/bin/env python | |
2 | |
3 import sys | |
4 import argparse | |
5 import logging | |
6 | |
7 from ppci.buildfunctions import c3toir | |
8 import ppci.buildtasks # Include not used, but it registers build tasks. | |
9 import ppci | |
10 from zcc import logLevel | |
11 | |
12 | |
13 def make_parser(): | |
14 parser = argparse.ArgumentParser(description='c3 Compiler') | |
15 | |
16 parser.add_argument('--log', help='Log level (INFO,DEBUG,[WARN])', | |
17 type=logLevel, default='INFO') | |
18 | |
19 parser.add_argument('--target', help='target machine', default="arm") | |
20 parser.add_argument('-o', '--output', help='target machine', | |
21 type=argparse.FileType('w'), default=sys.stdout) | |
22 parser.add_argument('-i', '--include', action='append', | |
23 help='include file', default=[]) | |
24 parser.add_argument('sources', metavar='source', | |
25 help='source file', nargs='+') | |
26 return parser | |
27 | |
28 | |
29 def main(args): | |
30 # Configure some logging: | |
31 logging.getLogger().setLevel(logging.DEBUG) | |
32 ch = logging.StreamHandler() | |
33 ch.setFormatter(logging.Formatter(ppci.logformat)) | |
34 ch.setLevel(args.log) | |
35 logging.getLogger().addHandler(ch) | |
36 | |
37 res = c3toir(args.sources, args.include, args.target) | |
38 writer = ppci.irutils.Writer() | |
39 for ir_module in res: | |
40 writer.write(ir_module, args.output) | |
41 | |
42 logging.getLogger().removeHandler(ch) | |
43 return res | |
44 | |
45 | |
46 if __name__ == '__main__': | |
47 parser = make_parser() | |
48 arguments = parser.parse_args() | |
49 sys.exit(main(arguments)) |