view python/c3/builder.py @ 194:b01429a5d695

Fixed test
author Windel Bouwman
date Wed, 29 May 2013 22:36:37 +0200
parents 46d62dadd61b
children 8b2f20aae086
line wrap: on
line source

import ppci
from . import Parser, Semantics, TypeChecker, Analyzer, CodeGenerator, AstPrinter

class Builder:
    """ 
        Generates IR-code from c3 source.
        Reports errors to the diagnostics system
    """
    def __init__(self, diag):
      self.diag = diag
      self.parser = Parser(diag)
      self.tc = TypeChecker(diag)
      self.al = Analyzer(diag)
      self.cg = CodeGenerator()
      self.ap = AstPrinter()
    def build(self, src):
      """ Create IR-code from sources """
      pkg = self.parser.parseSource(src)
      if not pkg:
            return
      if not self.al.analyzePackage(pkg):
            return
      if not self.tc.checkPackage(pkg):
            return

      # Only return ircode when everything is OK
      ircode = self.cg.gencode(pkg)
      return ircode