annotate python/c3c.py @ 400:0374c65cb437

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