view python/c3/builder.py @ 214:6875360e8390

Remove semantics
author Windel Bouwman
date Fri, 05 Jul 2013 11:18:58 +0200
parents 003c8a976fff
children c1ccb1cb4cef
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
      self.pkg = 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