annotate python/ppci/frontends/ks/__init__.py @ 106:f2d980eef509

improved code generation
author Windel Bouwman
date Mon, 31 Dec 2012 18:26:56 +0100
parents 6a303f835c6d
children 9e552d34bd60
rev   line source
100
fe145e42259d Fixes after movage
windel
parents: 99
diff changeset
1
fe145e42259d Fixes after movage
windel
parents: 99
diff changeset
2 from .parser import KsParser
102
63937c8d1478 Fixes and start with ir generator
windel
parents: 101
diff changeset
3 from .irgenerator import KsIrGenerator
100
fe145e42259d Fixes after movage
windel
parents: 99
diff changeset
4
101
af0d7913677a Fixes and splitting into 3 stage
windel
parents: 100
diff changeset
5 class KsFrontend:
105
6a303f835c6d Removed compilers directory
Windel Bouwman
parents: 102
diff changeset
6 """
6a303f835c6d Removed compilers directory
Windel Bouwman
parents: 102
diff changeset
7 Frontend for the K# language.
101
af0d7913677a Fixes and splitting into 3 stage
windel
parents: 100
diff changeset
8
105
6a303f835c6d Removed compilers directory
Windel Bouwman
parents: 102
diff changeset
9 This module can parse K# code and create LLVM intermediate code.
6a303f835c6d Removed compilers directory
Windel Bouwman
parents: 102
diff changeset
10 """
6a303f835c6d Removed compilers directory
Windel Bouwman
parents: 102
diff changeset
11 def __init__(self, context):
6a303f835c6d Removed compilers directory
Windel Bouwman
parents: 102
diff changeset
12 self.context = context
6a303f835c6d Removed compilers directory
Windel Bouwman
parents: 102
diff changeset
13 def compilesource(self, src):
6a303f835c6d Removed compilers directory
Windel Bouwman
parents: 102
diff changeset
14 """ Front end that handles parsing and Module generation """
6a303f835c6d Removed compilers directory
Windel Bouwman
parents: 102
diff changeset
15 self.errorlist = []
6a303f835c6d Removed compilers directory
Windel Bouwman
parents: 102
diff changeset
16 # Pass 1: parsing and type checking
6a303f835c6d Removed compilers directory
Windel Bouwman
parents: 102
diff changeset
17 p = KsParser(src)
6a303f835c6d Removed compilers directory
Windel Bouwman
parents: 102
diff changeset
18 ast = p.parseModule() # Parse source into an AST
6a303f835c6d Removed compilers directory
Windel Bouwman
parents: 102
diff changeset
19
6a303f835c6d Removed compilers directory
Windel Bouwman
parents: 102
diff changeset
20 # Store ast:
6a303f835c6d Removed compilers directory
Windel Bouwman
parents: 102
diff changeset
21 self.ast = ast
6a303f835c6d Removed compilers directory
Windel Bouwman
parents: 102
diff changeset
22
6a303f835c6d Removed compilers directory
Windel Bouwman
parents: 102
diff changeset
23 # Generate ir (a core.Module):
106
f2d980eef509 improved code generation
Windel Bouwman
parents: 105
diff changeset
24 ir = KsIrGenerator().generateIr(self.context, ast)
105
6a303f835c6d Removed compilers directory
Windel Bouwman
parents: 102
diff changeset
25
6a303f835c6d Removed compilers directory
Windel Bouwman
parents: 102
diff changeset
26 return ir
6a303f835c6d Removed compilers directory
Windel Bouwman
parents: 102
diff changeset
27