100
|
1
|
|
2 from .parser import KsParser
|
102
|
3 from .irgenerator import KsIrGenerator
|
100
|
4
|
101
|
5 class KsFrontend:
|
105
|
6 """
|
|
7 Frontend for the K# language.
|
101
|
8
|
105
|
9 This module can parse K# code and create LLVM intermediate code.
|
|
10 """
|
|
11 def __init__(self, context):
|
|
12 self.context = context
|
|
13 def compilesource(self, src):
|
|
14 """ Front end that handles parsing and Module generation """
|
|
15 self.errorlist = []
|
|
16 # Pass 1: parsing and type checking
|
|
17 p = KsParser(src)
|
|
18 ast = p.parseModule() # Parse source into an AST
|
110
|
19 print(ast)
|
105
|
20
|
|
21 # Store ast:
|
|
22 self.ast = ast
|
|
23
|
|
24 # Generate ir (a core.Module):
|
106
|
25 ir = KsIrGenerator().generateIr(self.context, ast)
|
105
|
26
|
|
27 return ir
|
|
28
|