Minor cleanup of include-handling code in isa_parser.py.
authorSteve Reinhardt <stever@eecs.umich.edu>
Fri, 10 Feb 2006 03:27:41 +0000 (22:27 -0500)
committerSteve Reinhardt <stever@eecs.umich.edu>
Fri, 10 Feb 2006 03:27:41 +0000 (22:27 -0500)
arch/isa_parser.py:
    Clean up ##include code a bit.
arch/sparc/isa/formats.isa:
arch/sparc/isa/main.isa:
    Fix include paths.

--HG--
extra : convert_revision : 0689963c2948e5f1088ecbf2cf6018d29bdaceff

arch/isa_parser.py
arch/sparc/isa/formats.isa
arch/sparc/isa/main.isa

index fc68808770d82280a210701247f3f62f1e9e0cf7..b12329ebb2f068b5c3ebb6987638e50ba1d98bc1 100755 (executable)
@@ -162,7 +162,7 @@ def t_CPPDIRECTIVE(t):
     return t
 
 def t_NEWFILE(t):
-    r'^\#\#newfile[ /t]*\"[A-Za-z0-9\\/-_.]*\"'
+    r'^\#\#newfile\s+"[\w/.-]*"'
     global fileNameStack
     fileNameStack.append((t.value[11:-1], t.lineno))
     t.lineno = 0
@@ -841,7 +841,7 @@ defaultStack = Stack( None )
 # Used to make nested code blocks look pretty.
 #
 def indent(s):
-    return re.sub(r'(?m)^(?!\#)', '  ', s)
+    return re.sub(r'(?m)^(?!#)', '  ', s)
 
 #
 # Munge a somewhat arbitrarily formatted piece of Python code
@@ -870,7 +870,6 @@ def fixPythonIndentation(s):
 # Error handler.  Just call exit.  Output formatted to work under
 # Emacs compile-mode.
 def error(lineno, string):
-    global fileNameStack
     spaces = ""
     for (filename, line) in fileNameStack[0:-1]:
         print spaces + "In file included from " + filename
@@ -1622,24 +1621,29 @@ def update_if_needed(file, contents):
         f.close()
 
 # This regular expression matches include directives
-regExp = re.compile('(?P<include>^[ \t]*##include[ \t]*\"[ \t]*(?P<filename>[A-Za-z0-9\\/-_.]*)[ \t]*\"[ \t]*\n)', re.MULTILINE)
+includeRE = re.compile(r'^\s*##include\s+"(?P<filename>[\w/.-]*)".*$',
+                       re.MULTILINE)
 
 def preprocess_isa_desc(isa_desc):
     # Find any includes and include them
-
-    # Look for an include
-    m = re.search(regExp, isa_desc)
-    while m:
+    pos = 0
+    while 1:
+        m = includeRE.search(isa_desc, pos)
+        if not m:
+            break
         filename = m.group('filename')
         print 'Including file "%s"' % filename
-        includeFile = open(filename)
-        includecontents = includeFile.read()
-        isa_desc = isa_desc[:m.start('include')] + '##newfile "' + filename + '"\n' + includecontents + '##endfile\n' + isa_desc[m.end('include'):]
-        # Look for the next include
-        m = re.search(regExp, isa_desc)
+        try:
+            isa_desc = isa_desc[:m.start()] + \
+                       '##newfile "' + filename + '"\n' + \
+                       open(filename).read() + \
+                       '##endfile\n' + \
+                       isa_desc[m.end():]
+        except IOError:
+            error(0, 'Error including file "%s"' % (filename))
+        pos = m.start()
     return isa_desc
 
-
 #
 # Read in and parse the ISA description.
 #
index a21e1c110bf610a20eb1a9ca2a990f3dd6a35cd5..547f8be487eff2289f7c40154f7768a4942314f4 100644 (file)
@@ -1,19 +1,19 @@
 //Include the basic format
 //Templates from this format are used later
-##include "m5/arch/sparc/isa_desc/formats/basic.isa"
+##include "m5/arch/sparc/isa/formats/basic.isa"
 
 //Include the integerOp and integerOpCc format
-##include "m5/arch/sparc/isa_desc/formats/integerop.isa"
+##include "m5/arch/sparc/isa/formats/integerop.isa"
 
 //Include the mem format
-##include "m5/arch/sparc/isa_desc/formats/mem.isa"
+##include "m5/arch/sparc/isa/formats/mem.isa"
 
 //Include the trap format
-##include "m5/arch/sparc/isa_desc/formats/trap.isa"
+##include "m5/arch/sparc/isa/formats/trap.isa"
 
 //Include the branch format
-##include "m5/arch/sparc/isa_desc/formats/branch.isa"
+##include "m5/arch/sparc/isa/formats/branch.isa"
 
 //Include the noop format
-##include "m5/arch/sparc/isa_desc/formats/noop.isa"
+##include "m5/arch/sparc/isa/formats/noop.isa"
 
index 8b6166d34c9ed0b4b31e398b287e8af7325c6a2c..ab0290d58fdf7fd11586a2d61a04fadf84ec9647 100644 (file)
@@ -26,7 +26,7 @@
 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
-##include "m5/arch/sparc/isa_desc/includes.isa"
+##include "m5/arch/sparc/isa/includes.isa"
 
 ////////////////////////////////////////////////////////////////////
 //
 namespace SparcISA;
 
 //Include the bitfield definitions
-##include "m5/arch/sparc/isa_desc/bitfields.isa"
+##include "m5/arch/sparc/isa/bitfields.isa"
 
 //Include the operand_types and operand definitions
-##include "m5/arch/sparc/isa_desc/operands.isa"
+##include "m5/arch/sparc/isa/operands.isa"
 
 //Include the base class for sparc instructions, and some support code
-##include "m5/arch/sparc/isa_desc/base.isa"
+##include "m5/arch/sparc/isa/base.isa"
 
 //Include the definitions for the instruction formats
-##include "m5/arch/sparc/isa_desc/formats.isa"
+##include "m5/arch/sparc/isa/formats.isa"
 
 //Include the decoder definition
-##include "m5/arch/sparc/isa_desc/decoder.isa"
+##include "m5/arch/sparc/isa/decoder.isa"