annotate python/c3/codegenerator.py @ 155:b28a11c01dbe

Simplified IR classes
author Windel Bouwman
date Sun, 03 Mar 2013 13:20:03 +0100
parents afc8c0207984
children 1b4a85bdd99c
rev   line source
155
b28a11c01dbe Simplified IR classes
Windel Bouwman
parents: 151
diff changeset
1 import ir
b28a11c01dbe Simplified IR classes
Windel Bouwman
parents: 151
diff changeset
2 from . import astnodes
151
afc8c0207984 Added ir code generator stub
Windel Bouwman
parents:
diff changeset
3
155
b28a11c01dbe Simplified IR classes
Windel Bouwman
parents: 151
diff changeset
4 def genModule(pkg):
b28a11c01dbe Simplified IR classes
Windel Bouwman
parents: 151
diff changeset
5 m = ir.Module(pkg.name)
b28a11c01dbe Simplified IR classes
Windel Bouwman
parents: 151
diff changeset
6 for s in pkg.scope:
b28a11c01dbe Simplified IR classes
Windel Bouwman
parents: 151
diff changeset
7 print(s)
b28a11c01dbe Simplified IR classes
Windel Bouwman
parents: 151
diff changeset
8 if type(s) is astnodes.Variable:
b28a11c01dbe Simplified IR classes
Windel Bouwman
parents: 151
diff changeset
9 genGlobal(m, s)
b28a11c01dbe Simplified IR classes
Windel Bouwman
parents: 151
diff changeset
10 return m
b28a11c01dbe Simplified IR classes
Windel Bouwman
parents: 151
diff changeset
11
b28a11c01dbe Simplified IR classes
Windel Bouwman
parents: 151
diff changeset
12 def genGlobal(m, var):
b28a11c01dbe Simplified IR classes
Windel Bouwman
parents: 151
diff changeset
13 v = ir.Value()
b28a11c01dbe Simplified IR classes
Windel Bouwman
parents: 151
diff changeset
14 v.name = var.name
b28a11c01dbe Simplified IR classes
Windel Bouwman
parents: 151
diff changeset
15 m.Globals.append(v)
151
afc8c0207984 Added ir code generator stub
Windel Bouwman
parents:
diff changeset
16
afc8c0207984 Added ir code generator stub
Windel Bouwman
parents:
diff changeset
17 class CodeGenerator:
afc8c0207984 Added ir code generator stub
Windel Bouwman
parents:
diff changeset
18 """ Generates intermediate code """
afc8c0207984 Added ir code generator stub
Windel Bouwman
parents:
diff changeset
19 def gencode(self, ast):
155
b28a11c01dbe Simplified IR classes
Windel Bouwman
parents: 151
diff changeset
20 print('Code generator')
b28a11c01dbe Simplified IR classes
Windel Bouwman
parents: 151
diff changeset
21 assert type(ast) is astnodes.Package
b28a11c01dbe Simplified IR classes
Windel Bouwman
parents: 151
diff changeset
22 return genModule(ast)
151
afc8c0207984 Added ir code generator stub
Windel Bouwman
parents:
diff changeset
23