annotate python/ppci/frontends/ks/__init__.py @ 110:9e552d34bd60

Work on compiler
author Windel Bouwman
date Fri, 04 Jan 2013 15:25:58 +0100
parents f2d980eef509
children
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
110
9e552d34bd60 Work on compiler
Windel Bouwman
parents: 106
diff changeset
19 print(ast)
105
6a303f835c6d Removed compilers directory
Windel Bouwman
parents: 102
diff changeset
20
6a303f835c6d Removed compilers directory
Windel Bouwman
parents: 102
diff changeset
21 # Store ast:
6a303f835c6d Removed compilers directory
Windel Bouwman
parents: 102
diff changeset
22 self.ast = ast
6a303f835c6d Removed compilers directory
Windel Bouwman
parents: 102
diff changeset
23
6a303f835c6d Removed compilers directory
Windel Bouwman
parents: 102
diff changeset
24 # Generate ir (a core.Module):
106
f2d980eef509 improved code generation
Windel Bouwman
parents: 105
diff changeset
25 ir = KsIrGenerator().generateIr(self.context, ast)
105
6a303f835c6d Removed compilers directory
Windel Bouwman
parents: 102
diff changeset
26
6a303f835c6d Removed compilers directory
Windel Bouwman
parents: 102
diff changeset
27 return ir
6a303f835c6d Removed compilers directory
Windel Bouwman
parents: 102
diff changeset
28