view python/c3/builder.py @ 207:8b2f20aae086

cleaning of files
author Windel Bouwman
date Sat, 29 Jun 2013 10:05:42 +0200
parents b01429a5d695
children 003c8a976fff
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)
      self.pkg = pkg
      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