diff ide/compiler/compiler.py @ 1:92df07bc2081

Initial import of compiler
author windel
date Sun, 18 Sep 2011 19:00:29 +0200
parents
children 818f80afa78b
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ide/compiler/compiler.py	Sun Sep 18 19:00:29 2011 +0200
@@ -0,0 +1,33 @@
+import hashlib
+# Import compiler components:
+from . import lexer
+from . import parser
+from .codegenerator import CodeGenerator
+from .nodes import ExportedSymbol
+
+class Compiler:
+   versie = '0.9.3'
+
+   def __repr__(self):
+      return 'LCFOS compiler {0}'.format(self.versie)
+
+   def generateSignature(self, src):
+      return hashlib.md5(bytes(src,encoding='ascii')).hexdigest()
+
+   def compilesource(self, src):
+      """ Front end that handles the stages: """
+      tokens = lexer.tokenize(src) # Lexical stage
+      ast = parser.Parser(tokens).parseModule() # Parse a module
+      CodeGenerator().generatecode(ast)
+      # Attach a signature:
+      ast.signature = self.generateSignature(src)
+      # Generate exported symbols:
+      ast.exports = []
+      for proc in ast.procs:
+         if proc.public:
+            sym = ExportedSymbol(proc.name, proc.typ)
+            sym.imageoffset = proc.entrypoint
+            ast.exports.append(sym)
+
+      return ast
+