-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcc.py
49 lines (42 loc) · 1.36 KB
/
cc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import sys
import code_generator
import importer
import kind_checker
import lexer
import lower_control_flow
import monomorphize
import output
import plst_parser
import reorganize
import sort_checker
import type_checker
def parse(src):
tokens = lexer.Lexer(src).lex()
return plst_parser.Parser(tokens).parse_file()
def map_modules(f, modules):
return \
[(module_name, f(decls))
for module_name, decls in modules]
def apply_module_pass(f, modules):
output = []
output_dict = {}
for module_name, decls in modules:
module, module_interface = \
f(module_name, output_dict, decls)
output_dict[module_name] = module_interface
output.append((module_name, module))
return output
def main():
modules = importer.Importer(parse).load_all(sys.argv[1])
modules = map_modules(sort_checker.sort_check, modules)
modules = apply_module_pass(kind_checker.kind_check, modules)
modules = apply_module_pass(type_checker.type_check, modules)
things = reorganize.reorganize(modules)
things = lower_control_flow.lower_control_flow(things)
instances = monomorphize.monomorphize(things)
cg_decls = code_generator.generate(things, instances)
with open(sys.argv[2], 'w') as fd:
writer = output.LLVMWriter(fd)
writer.writeout_prelude()
writer.writeout_decls(cg_decls)
main()