view python/ir/function.py @ 266:649884d9dc61 Working chain 1

Test
author Windel Bouwman
date Fri, 09 Aug 2013 16:49:29 +0200
parents 225f444019b1
children 5ec7580976d9
line wrap: on
line source

from .basicblock import BasicBlock

class Function:
    def __init__(self, name):
      self.name = name
      self.bbs = []
      self.entry = None

    def __repr__(self):
        return 'Function {0}'.format(self.name)

    def addBB(self, bb):
        self.bbs.append(bb)
        bb.parent = self
    addBasicBlock = addBB

    def removeBasicBlock(self, bb):
        self.bbs.remove(bb)
        bb.parent = None

    def getBBs(self):
        return self.bbs

    def findBasicBlock(self, name):
        for bb in self.bbs:
            if bb.name == name:
                return bb
        raise KeyError(name)

    BasicBlocks = property(getBBs)

    @property
    def Entry(self):
        return self.BasicBlocks[0]

    def check(self):
        for bb in self.BasicBlocks:
            bb.check()

    def call(self, *args):
        varmap = {}
        bb = self.Entry
        ip = 0
        while True:
            i = bb.Instructions[ip]
            ip += 1
            return