main: update IR locations + catch and print warnings
This commit is contained in:
parent
5ed4c55522
commit
3e59cc84a7
1 changed files with 10 additions and 3 deletions
|
|
@ -2,10 +2,11 @@ from __future__ import annotations
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import sys
|
import sys
|
||||||
|
import typing
|
||||||
from pprint import pprint
|
from pprint import pprint
|
||||||
|
|
||||||
from . import semantic
|
from . import semantic, ir, optimizations
|
||||||
from .errors import CompilationError
|
from .errors import CompilationError, CompilationWarning
|
||||||
from .lexer import Lexer, Tokens
|
from .lexer import Lexer, Tokens
|
||||||
from .logger import rootLogger, LogLevel
|
from .logger import rootLogger, LogLevel
|
||||||
from .parser import Parser
|
from .parser import Parser
|
||||||
|
|
@ -52,9 +53,11 @@ def main():
|
||||||
|
|
||||||
context.check()
|
context.check()
|
||||||
|
|
||||||
intermediate_representation = ast.intermediate_representation()
|
intermediate_representation = typing.cast(ast.intermediate_representation(), list[ir.IRAction])
|
||||||
pseudo_asm = [x.codegen() for x in intermediate_representation]
|
pseudo_asm = [x.codegen() for x in intermediate_representation]
|
||||||
for i, action in enumerate(intermediate_representation):
|
for i, action in enumerate(intermediate_representation):
|
||||||
|
action.ir_location.line = i
|
||||||
|
action.ir_location.ir = pseudo_asm
|
||||||
|
|
||||||
action.location.source = data
|
action.location.source = data
|
||||||
|
|
||||||
|
|
@ -70,6 +73,10 @@ def main():
|
||||||
raise e.__cause__
|
raise e.__cause__
|
||||||
print(f"Caused by:\n{e.__cause__.__class__.__name__}: {e.__cause__}", file=sys.stderr)
|
print(f"Caused by:\n{e.__cause__.__class__.__name__}: {e.__cause__}", file=sys.stderr)
|
||||||
|
|
||||||
|
finally:
|
||||||
|
CompilationWarning.show_warnings(data)
|
||||||
|
|
||||||
|
|
||||||
def print_ir(intermediate_representation: list[ir.IRAction]):
|
def print_ir(intermediate_representation: list[ir.IRAction]):
|
||||||
messages = []
|
messages = []
|
||||||
for i, ir_item in enumerate(intermediate_representation):
|
for i, ir_item in enumerate(intermediate_representation):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue