view python/c3/builder.py @ 225:1c7364bd74c7

Fixed pointer deref
author Windel Bouwman
date Thu, 11 Jul 2013 07:42:30 +0200
parents c1ccb1cb4cef
children 240111e0456f
line wrap: on
line source

import ppci
from . import Parser, TypeChecker, Analyzer, CodeGenerator
from . astprinter import 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()
    def build(self, src):
      """ Create IR-code from sources """
      pkg = self.parser.parseSource(src)
      if not pkg:
            return
      self.pkg = pkg
      # TODO: merge the two below?
      #AstPrinter().printAst(pkg)
      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