Mercurial > lcfOS
changeset 156:1b4a85bdd99c
change types
author | Windel Bouwman |
---|---|
date | Sun, 03 Mar 2013 15:50:34 +0100 |
parents | b28a11c01dbe |
children | 8f3924b6076e |
files | python/c3/codegenerator.py python/ir/__init__.py python/ir/llvmtype.py python/ir/module.py |
diffstat | 4 files changed, 22 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- a/python/c3/codegenerator.py Sun Mar 03 13:20:03 2013 +0100 +++ b/python/c3/codegenerator.py Sun Mar 03 15:50:34 2013 +0100 @@ -4,9 +4,12 @@ def genModule(pkg): m = ir.Module(pkg.name) for s in pkg.scope: - print(s) if type(s) is astnodes.Variable: genGlobal(m, s) + elif type(s) is astnodes.Function: + genFunction(m, s) + else: + print(s) return m def genGlobal(m, var): @@ -14,6 +17,10 @@ v.name = var.name m.Globals.append(v) +def genFunction(m, fnc): + f = ir.Function() + m.Globals.append(f) + class CodeGenerator: """ Generates intermediate code """ def gencode(self, ast):
--- a/python/ir/__init__.py Sun Mar 03 13:20:03 2013 +0100 +++ b/python/ir/__init__.py Sun Mar 03 15:50:34 2013 +0100 @@ -1,3 +1,4 @@ from .module import Module, Function, BasicBlock from .value import Value +from .types import Type, i8, i16, i32, void
--- a/python/ir/llvmtype.py Sun Mar 03 13:20:03 2013 +0100 +++ b/python/ir/llvmtype.py Sun Mar 03 15:50:34 2013 +0100 @@ -1,30 +1,27 @@ -def Enum(**enums): - return type('Enum', (), enums) - -typeID = Enum(Void=0, Double=3, Integer=10, Function=11, Struct=12, Array=13, Pointer=14, Vector=15) - -class llvmType: - def __init__(self, tid): - self.tid = tid +class Type: + def __init__(self): + pass -class IntegerType(llvmType): +class IntegerType(Type): def __init__(self, bits): - super().__init__(typeID.Integer) + super().__init__() self.bits = bits -class FunctionType(llvmType): +class VoidType(Type): + pass + +class FunctionType(Type): def __init__(self, resultType, parameterTypes): - super().__init__(typeID.Function) + super().__init__() assert type(parameterTypes) is list self.resultType = resultType - self.returnType = resultType self.parameterTypes = parameterTypes # Default types: i8 = IntegerType(8) i16 = IntegerType(16) i32 = IntegerType(32) -void = llvmType(typeID.Void) +void = VoidType()
--- a/python/ir/module.py Sun Mar 03 13:20:03 2013 +0100 +++ b/python/ir/module.py Sun Mar 03 15:50:34 2013 +0100 @@ -7,7 +7,6 @@ self.functions = [] # Do functions come out of symbol table? self.globals_ = [] # TODO: are globals in symbol table? self.symtable = SymbolTable() - Globals = property(lambda self: self.globals_) Functions = property(lambda self: self.functions) Identifier = property(lambda self: self.identifier) @@ -19,17 +18,15 @@ self.function = function class Function: - def __init__(self, functiontype, name, module): + def __init__(self, name, functiontype): super().__init__() + self.name = name self.functiontype = functiontype - self.name = name - self.module = module self.module.Functions.append(self) self.basicblocks = [] self.arguments = [] # Construct formal arguments depending on function type - BasicBlocks = property(lambda self: self.basicblocks) Arguments = property(lambda self: self.arguments) ReturnType = property(lambda self: self.functiontype.returnType)