From 91a12fd2a8fa6379508541875c44b2d96df40589 Mon Sep 17 00:00:00 2001 From: Anton Lydike Date: Sun, 18 Apr 2021 20:36:13 +0200 Subject: [PATCH] fixed tokenizer hanging on unknown instruction --- README.md | 1 - riscemu/Tokenizer.py | 6 ++---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 744febe..e96f807 100644 --- a/README.md +++ b/README.md @@ -63,7 +63,6 @@ See [docs/debugging.md](docs/debugging.md) for more info. * RISC-V reference card: https://www.cl.cam.ac.uk/teaching/1617/ECAD+Arch/files/docs/RISCVGreenCardv8-20151013.pdf ## TODO: - * Prevent tokenizer infinite loop on unknown instructions * Move cpu instructions to different file, allow for instruction set selection and composition * Add a cycle limit to the options and CPU to catch infinite loops * Move away from `print` and use `logging.logger` instead diff --git a/riscemu/Tokenizer.py b/riscemu/Tokenizer.py index 8ba9fe3..ec6e0dd 100644 --- a/riscemu/Tokenizer.py +++ b/riscemu/Tokenizer.py @@ -3,6 +3,7 @@ from enum import IntEnum from typing import List from .CPU import CPU, Registers +from .Exceptions import ParseException REGISTERS = list(Registers.all_registers()) @@ -130,7 +131,6 @@ class RiscVInput: regex = re.compile(regex) match = regex.match(self.content[at:]) if match is None: - print("Regex matched none at {}!".format(self.context())) return None if regex_group != 0 and not match.group(0).startswith(match.group(regex_group)): @@ -272,9 +272,7 @@ class RiscVTokenizer: self.parse_instruction() else: token = self.input.peek(size=5) - print("Unknown token around {} at: {}".format(repr(token), repr(self.input.context()))) - self.input.consume_whitespace() - print("After whitespace at: {}".format(repr(self.input.context()))) + raise ParseException("Unknown token around {} at: {}".format(repr(token), repr(self.input.context()))) self.input.consume_whitespace() def parse_pseudo_op(self):