2017-12-21 13:52:30 +00:00
|
|
|
"""
|
2017-12-25 15:00:25 +00:00
|
|
|
Programming Language for 6502/6510 microprocessors
|
2017-12-21 13:52:30 +00:00
|
|
|
This is the preprocessing parser of the IL65 code, that only generates a symbol table.
|
|
|
|
|
|
|
|
Written by Irmen de Jong (irmen@razorvine.net)
|
|
|
|
License: GNU GPL 3.0, see LICENSE
|
|
|
|
"""
|
|
|
|
|
|
|
|
from typing import List, Tuple
|
|
|
|
from .parse import Parser, ParseResult, SymbolTable, SymbolDefinition
|
|
|
|
|
|
|
|
|
|
|
|
class PreprocessingParser(Parser):
|
|
|
|
def __init__(self, filename: str) -> None:
|
|
|
|
super().__init__(filename, "", parsing_import=True)
|
2017-12-21 14:12:24 +00:00
|
|
|
self.print_block_parsing = False
|
2017-12-21 13:52:30 +00:00
|
|
|
|
|
|
|
def preprocess(self) -> Tuple[List[Tuple[int, str]], SymbolTable]:
|
|
|
|
def cleanup_table(symbols: SymbolTable):
|
|
|
|
symbols.owning_block = None # not needed here
|
|
|
|
for name, symbol in list(symbols.symbols.items()):
|
|
|
|
if isinstance(symbol, SymbolTable):
|
|
|
|
cleanup_table(symbol)
|
|
|
|
elif not isinstance(symbol, SymbolDefinition):
|
|
|
|
del symbols.symbols[name]
|
|
|
|
self.parse()
|
|
|
|
cleanup_table(self.root_scope)
|
|
|
|
return self.lines, self.root_scope
|
|
|
|
|
2017-12-21 14:12:24 +00:00
|
|
|
def print_warning(self, text: str) -> None:
|
|
|
|
pass
|
|
|
|
|
2017-12-21 13:52:30 +00:00
|
|
|
def load_source(self, filename: str) -> List[Tuple[int, str]]:
|
|
|
|
lines = super().load_source(filename)
|
|
|
|
# can do some additional source-level preprocessing here
|
|
|
|
return lines
|
|
|
|
|
|
|
|
def parse_file(self) -> ParseResult:
|
|
|
|
print("\npreprocessing", self.sourceref.file)
|
|
|
|
self._parse_1()
|
|
|
|
return self.result
|
|
|
|
|
|
|
|
def parse_asminclude(self, line: str) -> ParseResult.InlineAsm:
|
2017-12-27 18:01:14 +00:00
|
|
|
return ParseResult.InlineAsm([], self.sourceref.line)
|
2017-12-21 13:52:30 +00:00
|
|
|
|
2017-12-21 21:16:46 +00:00
|
|
|
def parse_statement(self, line: str) -> ParseResult._AstNode:
|
2017-12-21 13:52:30 +00:00
|
|
|
return None # type: ignore
|
|
|
|
|
|
|
|
def parse_var_def(self, line: str) -> None:
|
|
|
|
super().parse_var_def(line)
|
|
|
|
|
|
|
|
def parse_const_def(self, line: str) -> None:
|
|
|
|
super().parse_const_def(line)
|
|
|
|
|
|
|
|
def parse_memory_def(self, line: str, is_zeropage: bool=False) -> None:
|
|
|
|
super().parse_memory_def(line, is_zeropage)
|
|
|
|
|
|
|
|
def parse_label(self, line: str) -> None:
|
|
|
|
super().parse_label(line)
|
|
|
|
|
2017-12-25 18:09:10 +00:00
|
|
|
def parse_subroutine_def(self, line: str) -> None:
|
|
|
|
super().parse_subroutine_def(line)
|
2017-12-21 13:52:30 +00:00
|
|
|
|
|
|
|
def create_import_parser(self, filename: str, outputdir: str) -> 'Parser':
|
|
|
|
return PreprocessingParser(filename)
|