Gabe Black has uploaded this change for review. ( https://gem5-review.googlesource.com/c/public/gem5/+/57020 )

Change subject: arch: Improve error reporting from the microcode assembler.
......................................................................

arch: Improve error reporting from the microcode assembler.

Automatically include a filename and line number.

Unfortunately the line number is wherever the parser is, which might be
past the point of the actual error. For instance, macroops are parsed in
their entirity before being processed. These error messages could be
improved further by recording what line microops, labels, directives,
etc, were on so that can be printed later.

Change-Id: I72c0e4ef0442080e382987dda15470de920daa62
---
M src/arch/ucasmlib/assembler.py
M src/arch/ucasmlib/block.py
M src/arch/ucasmlib/parser.py
3 files changed, 30 insertions(+), 10 deletions(-)



diff --git a/src/arch/ucasmlib/assembler.py b/src/arch/ucasmlib/assembler.py
index dcf77b7..e3d4d1b 100644
--- a/src/arch/ucasmlib/assembler.py
+++ b/src/arch/ucasmlib/assembler.py
@@ -47,8 +47,8 @@
         try:
text = eval(f'(lambda {self.params} : f{repr(self.body)})({args})',
                         {}, assembler.symbols)
-        except Exception as e:
-            assembler.print_error(f'Failed to expand macro: {e}')
+        except BaseException as err:
+            assembler.print_error(f'Failed to expand macro: {err}')
             raise
         return text

@@ -316,8 +316,8 @@
         'macroop_def : DEF MACROOP ID block SEMI'
         try:
             curop = self.macro_type(t[3])
-        except TypeError:
-            self.print_error("Error creating macroop object.")
+        except BaseException as err:
+            self.print_error(f'Error creating macroop object: {err}')
             raise
         for statement in t[4]:
             statement.handle(self, curop)
@@ -361,6 +361,6 @@
     def assemble(self, asm, path=None):
         if path is not None:
             # Update the path of the first level lexer.
-            self.lexers[-1] = (os.path.dirname(path), self.lexer)
+            self.lexers[-1] = (os.path.dirname(path), self.lexer, path)
         self.parser.parse(asm, lexer=self)
         return self.macroops
diff --git a/src/arch/ucasmlib/block.py b/src/arch/ucasmlib/block.py
index e6f1cad..0f49d59 100644
--- a/src/arch/ucasmlib/block.py
+++ b/src/arch/ucasmlib/block.py
@@ -55,8 +55,9 @@
         try:
             microop = eval(f'_cls({self.params})',
                     {'_cls': microop}, assembler.symbols)
-        except:
- assembler.print_error(f'Error instantiating microop "{self.name}"')
+        except BaseException as err:
+            assembler.print_error(
+                    f'Error instantiating microop "{self.name}": {err}')
             raise

         container.add_microop(self.name, microop)
@@ -74,8 +75,9 @@
         try:
             eval(f'_dir({self.params})',
                     {'_dir': directive}, assembler.symbols)
-        except:
- assembler.print_error(f'Error executing directive "{self.name}"')
+        except BaseException as err:
+            assembler.print_error(
+                    f'Error executing directive "{self.name}": {err}')
             raise

 class Label(Statement):
diff --git a/src/arch/ucasmlib/parser.py b/src/arch/ucasmlib/parser.py
index 1ee18e8..0feee11 100644
--- a/src/arch/ucasmlib/parser.py
+++ b/src/arch/ucasmlib/parser.py
@@ -30,7 +30,8 @@
 class ParserBase:
     def print_error(self, message):
         print()
-        print("*** %s" % message)
+        print(f'*** "{self.lexers[-1][2]}", line {self.lexer.lineno}: '
+              f'{message}')
         print()

     ######################################################################

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/57020
To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: I72c0e4ef0442080e382987dda15470de920daa62
Gerrit-Change-Number: 57020
Gerrit-PatchSet: 1
Gerrit-Owner: Gabe Black <gabe.bl...@gmail.com>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list -- gem5-dev@gem5.org
To unsubscribe send an email to gem5-dev-le...@gem5.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

Reply via email to