1
|
1 import hashlib
|
|
2 # Import compiler components:
|
|
3 from . import lexer
|
|
4 from . import parser
|
|
5 from .codegenerator import CodeGenerator
|
|
6 from .nodes import ExportedSymbol
|
|
7
|
|
8 class Compiler:
|
|
9 versie = '0.9.3'
|
|
10
|
|
11 def __repr__(self):
|
|
12 return 'LCFOS compiler {0}'.format(self.versie)
|
|
13
|
|
14 def generateSignature(self, src):
|
|
15 return hashlib.md5(bytes(src,encoding='ascii')).hexdigest()
|
|
16
|
|
17 def compilesource(self, src):
|
|
18 """ Front end that handles the stages: """
|
|
19 tokens = lexer.tokenize(src) # Lexical stage
|
|
20 ast = parser.Parser(tokens).parseModule() # Parse a module
|
|
21 CodeGenerator().generatecode(ast)
|
|
22 # Attach a signature:
|
|
23 ast.signature = self.generateSignature(src)
|
|
24 # Generate exported symbols:
|
|
25 ast.exports = []
|
|
26 for proc in ast.procs:
|
|
27 if proc.public:
|
|
28 sym = ExportedSymbol(proc.name, proc.typ)
|
|
29 sym.imageoffset = proc.entrypoint
|
|
30 ast.exports.append(sym)
|
|
31
|
|
32 return ast
|
|
33
|