view python/codegen.py @ 215:c1ccb1cb4cef

Major changes in c3 frontend
author Windel Bouwman
date Fri, 05 Jul 2013 13:00:03 +0200
parents 67b0feafe5ae
children 8786811a5a59
line wrap: on
line source

import ir, target
from ppci import CompilerError

class CodeGenerator:
    """ Target independent code generator """
    def __init__(self, tg):
        assert isinstance(tg, target.Target)
        self.tg = tg

    def tryMap(self, ii):
        for mi in self.tg.instructions:
            if mi.irpattern is ii:
                return mi.FromIr(ii)
        raise CompilerError('Cannot map {0}'.format(ii))
        
    def generate(self, ircode):
        assert isinstance(ircode, ir.Module)
        obj = object()
        for gvar in ircode.Variables:
            print(gvar)
            print('TODO')
        for f in ircode.Functions:
            for bb in f.BasicBlocks:
                print(bb)
                for ins in bb.Instructions:
                    # Instruction selection:
                    print(ins)
                    #mi = self.tryMap(ins)
        return obj