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
|
|
19
|
|
20 # Store ast:
|
|
21 self.ast = ast
|
|
22
|
|
23 # Generate ir (a core.Module):
|
106
|
24 ir = KsIrGenerator().generateIr(self.context, ast)
|
105
|
25
|
|
26 return ir
|
|
27
|