diff options
author | Steve Reinhardt <stever@eecs.umich.edu> | 2006-02-09 22:27:41 -0500 |
---|---|---|
committer | Steve Reinhardt <stever@eecs.umich.edu> | 2006-02-09 22:27:41 -0500 |
commit | fb90b1dd13fb6c0090bfe2731ca9ccee56479761 (patch) | |
tree | 96d34624975cab81d4061d4f2fb5b285e7bd9428 /arch/isa_parser.py | |
parent | 2c528d5865b47de45e0bb85fad86b0cf768ed278 (diff) | |
download | gem5-fb90b1dd13fb6c0090bfe2731ca9ccee56479761.tar.xz |
Minor cleanup of include-handling code in isa_parser.py.
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
Diffstat (limited to 'arch/isa_parser.py')
-rwxr-xr-x | arch/isa_parser.py | 32 |
1 files changed, 18 insertions, 14 deletions
diff --git a/arch/isa_parser.py b/arch/isa_parser.py index fc6880877..b12329ebb 100755 --- a/arch/isa_parser.py +++ b/arch/isa_parser.py @@ -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. # |