isa_parser: add a debug variable that changes how errors are reported.
authorNathan Binkert <nate@binkert.org>
Sat, 27 Feb 2010 02:14:48 +0000 (18:14 -0800)
committerNathan Binkert <nate@binkert.org>
Sat, 27 Feb 2010 02:14:48 +0000 (18:14 -0800)
This allows us to get tracebacks in certain cases where they're more
useful than our error message.

src/arch/isa_parser.py

index a8f9852ea76cf6c3487cd88021e338887932a41b..0ec30ef4b2dd92989d396cfa583bc6247f5ab19a 100755 (executable)
@@ -36,6 +36,8 @@ from types import *
 
 from m5.util.grammar import Grammar
 
+debug=False
+
 ###################
 # Utility functions
 
@@ -83,7 +85,7 @@ class ISAParserError(Exception):
             self.lineno = first
             self.string = second
 
-    def display(self, filename_stack, print_traceback=False):
+    def display(self, filename_stack, print_traceback=debug):
         # Output formatted to work under Emacs compile-mode.  Optional
         # 'print_traceback' arg, if set to True, prints a Python stack
         # backtrace too (can be handy when trying to debug the parser
@@ -104,7 +106,7 @@ class ISAParserError(Exception):
 
         return "%s%s %s" % (spaces, line_str, self.string)
 
-    def exit(self, filename_stack, print_traceback=False):
+    def exit(self, filename_stack, print_traceback=debug):
         # Just call exit.
 
         sys.exit(self.display(filename_stack, print_traceback))
@@ -247,6 +249,8 @@ class Format(object):
         try:
             vars = self.func(self.user_code, context, *args[0], **args[1])
         except Exception, exc:
+            if debug:
+                raise
             error(lineno, 'error defining "%s": %s.' % (name, exc))
         for k in vars.keys():
             if k not in ('header_output', 'decoder_output',
@@ -882,6 +886,8 @@ def buildOperandNameMap(user_dict, lineno):
         try:
             base_cls = eval(base_cls_name + 'Operand')
         except NameError:
+            if debug:
+                raise
             error(lineno,
                   'error: unknown operand base class "%s"' % base_cls_name)
         # The following statement creates a new class called
@@ -1518,6 +1524,8 @@ StaticInstPtr
         try:
             exec fixPythonIndentation(t[2]) in exportContext
         except Exception, exc:
+            if debug:
+                raise
             error(t, 'error: %s in global let block "%s".' % (exc, t[2]))
         t[0] = GenCode(header_output = exportContext["header_output"],
                        decoder_output = exportContext["decoder_output"],
@@ -1531,6 +1539,8 @@ StaticInstPtr
         try:
             user_dict = eval('{' + t[3] + '}')
         except Exception, exc:
+            if debug:
+                raise
             error(t,
                   'error: %s in def operand_types block "%s".' % (exc, t[3]))
         buildOperandTypeMap(user_dict, t.lexer.lineno)
@@ -1545,6 +1555,8 @@ StaticInstPtr
         try:
             user_dict = eval('{' + t[3] + '}', exportContext)
         except Exception, exc:
+            if debug:
+                raise
             error(t, 'error: %s in def operands block "%s".' % (exc, t[3]))
         buildOperandNameMap(user_dict, t.lexer.lineno)
         t[0] = GenCode() # contributes nothing to the output C++ file