Merge ktlim@zizzer:/bk/m5

into  zamp.eecs.umich.edu:/z/ktlim2/clean/m5-o3

--HG--
extra : convert_revision : 804302a5edb9d908808861f7f54a4f3cbb22830c
This commit is contained in:
Kevin Lim 2006-05-23 18:19:04 -04:00
commit 16df8221ff
2 changed files with 64 additions and 64 deletions

View file

@ -418,31 +418,31 @@ def format BasicOperateWithNopCheck(code, *opt_args) {{
}}; }};
// Integer instruction templates, formats, etc. // Integer instruction templates, formats, etc.
##include "m5/arch/alpha/isa/int.isa" ##include "int.isa"
// Floating-point instruction templates, formats, etc. // Floating-point instruction templates, formats, etc.
##include "m5/arch/alpha/isa/fp.isa" ##include "fp.isa"
// Memory instruction templates, formats, etc. // Memory instruction templates, formats, etc.
##include "m5/arch/alpha/isa/mem.isa" ##include "mem.isa"
// Branch/jump instruction templates, formats, etc. // Branch/jump instruction templates, formats, etc.
##include "m5/arch/alpha/isa/branch.isa" ##include "branch.isa"
// PAL instruction templates, formats, etc. // PAL instruction templates, formats, etc.
##include "m5/arch/alpha/isa/pal.isa" ##include "pal.isa"
// Opcdec fault instruction templates, formats, etc. // Opcdec fault instruction templates, formats, etc.
##include "m5/arch/alpha/isa/opcdec.isa" ##include "opcdec.isa"
// Unimplemented instruction templates, formats, etc. // Unimplemented instruction templates, formats, etc.
##include "m5/arch/alpha/isa/unimp.isa" ##include "unimp.isa"
// Unknown instruction templates, formats, etc. // Unknown instruction templates, formats, etc.
##include "m5/arch/alpha/isa/unknown.isa" ##include "unknown.isa"
// Execution utility functions // Execution utility functions
##include "m5/arch/alpha/isa/util.isa" ##include "util.isa"
// The actual decoder // The actual decoder
##include "m5/arch/alpha/isa/decoder.isa" ##include "decoder.isa"

View file

@ -1,5 +1,3 @@
#! /usr/bin/env python
# Copyright (c) 2003-2005 The Regents of The University of Michigan # Copyright (c) 2003-2005 The Regents of The University of Michigan
# All rights reserved. # All rights reserved.
# #
@ -162,13 +160,12 @@ def t_CPPDIRECTIVE(t):
def t_NEWFILE(t): def t_NEWFILE(t):
r'^\#\#newfile\s+"[\w/.-]*"' r'^\#\#newfile\s+"[\w/.-]*"'
global fileNameStack fileNameStack.push((t.value[11:-1], t.lineno))
fileNameStack.append((t.value[11:-1], t.lineno))
t.lineno = 0 t.lineno = 0
def t_ENDFILE(t): def t_ENDFILE(t):
r'^\#\#endfile' r'^\#\#endfile'
(filename, t.lineno) = fileNameStack.pop() (old_filename, t.lineno) = fileNameStack.pop()
# #
# The functions t_NEWLINE, t_ignore, and t_error are # The functions t_NEWLINE, t_ignore, and t_error are
@ -698,7 +695,7 @@ def p_error(t):
if t: if t:
error(t.lineno, "syntax error at '%s'" % t.value) error(t.lineno, "syntax error at '%s'" % t.value)
else: else:
error_bt(0, "unknown syntax error") error(0, "unknown syntax error", True)
# END OF GRAMMAR RULES # END OF GRAMMAR RULES
# #
@ -896,6 +893,12 @@ formatStack = Stack(NoFormat())
# The global default case stack. # The global default case stack.
defaultStack = Stack( None ) defaultStack = Stack( None )
# Global stack that tracks current file and line number.
# Each element is a tuple (filename, lineno) that records the
# *current* filename and the line number in the *previous* file where
# it was included.
fileNameStack = Stack()
################### ###################
# Utility functions # Utility functions
@ -932,25 +935,22 @@ def fixPythonIndentation(s):
return s return s
# Error handler. Just call exit. Output formatted to work under # Error handler. Just call exit. Output formatted to work under
# Emacs compile-mode. This function should be called when errors due # Emacs compile-mode. Optional 'print_traceback' arg, if set to True,
# to user input are detected (as opposed to parser bugs). # prints a Python stack backtrace too (can be handy when trying to
def error(lineno, string): # debug the parser itself).
def error(lineno, string, print_traceback = False):
spaces = "" spaces = ""
for (filename, line) in fileNameStack[0:-1]: for (filename, line) in fileNameStack[0:-1]:
print spaces + "In file included from " + filename print spaces + "In file included from " + filename + ":"
spaces += " " spaces += " "
# Uncomment the following line to get a Python stack backtrace for # Print a Python stack backtrace if requested.
# these errors too. Can be handy when trying to debug the parser. if (print_traceback):
# traceback.print_exc()
sys.exit(spaces + "%s:%d: %s" % (fileNameStack[-1][0], lineno, string))
# Like error(), but include a Python stack backtrace (for processing
# Python exceptions). This function should be called for errors that
# appear to be bugs in the parser itself.
def error_bt(lineno, string):
traceback.print_exc() traceback.print_exc()
print >> sys.stderr, "%s:%d: %s" % (input_filename, lineno, string) if lineno != 0:
sys.exit(1) line_str = "%d:" % lineno
else:
line_str = ""
sys.exit(spaces + "%s:%s %s" % (fileNameStack[-1][0], line_str, string))
##################################################################### #####################################################################
@ -1070,7 +1070,7 @@ def buildOperandTypeMap(userDict, lineno):
elif size == 64: elif size == 64:
ctype = 'double' ctype = 'double'
if ctype == '': if ctype == '':
error(0, 'Unrecognized type description "%s" in userDict') error(lineno, 'Unrecognized type description "%s" in userDict')
operandTypeMap[ext] = (size, ctype, is_signed) operandTypeMap[ext] = (size, ctype, is_signed)
# #
@ -1687,47 +1687,47 @@ def update_if_needed(file, contents):
f.write(contents) f.write(contents)
f.close() f.close()
# This regular expression matches include directives # This regular expression matches '##include' directives
includeRE = re.compile(r'^\s*##include\s+"(?P<filename>[\w/.-]*)".*$', includeRE = re.compile(r'^\s*##include\s+"(?P<filename>[\w/.-]*)".*$',
re.MULTILINE) re.MULTILINE)
def preprocess_isa_desc(isa_desc): # Function to replace a matched '##include' directive with the
# Find any includes and include them # contents of the specified file (with nested ##includes replaced
pos = 0 # recursively). 'matchobj' is an re match object (from a match of
while 1: # includeRE) and 'dirname' is the directory relative to which the file
m = includeRE.search(isa_desc, pos) # path should be resolved.
if not m: def replace_include(matchobj, dirname):
break fname = matchobj.group('filename')
filename = m.group('filename') full_fname = os.path.normpath(os.path.join(dirname, fname))
print 'Including file "%s"' % filename contents = '##newfile "%s"\n%s\n##endfile\n' % \
(full_fname, read_and_flatten(full_fname))
return contents
# Read a file and recursively flatten nested '##include' files.
def read_and_flatten(filename):
current_dir = os.path.dirname(filename)
try: try:
isa_desc = isa_desc[:m.start()] + \ contents = open(filename).read()
'##newfile "' + filename + '"\n' + \
open(filename).read() + \
'##endfile\n' + \
isa_desc[m.end():]
except IOError: except IOError:
error(0, 'Error including file "%s"' % (filename)) error(0, 'Error including file "%s"' % filename)
pos = m.start() fileNameStack.push((filename, 0))
return isa_desc # Find any includes and include them
contents = includeRE.sub(lambda m: replace_include(m, current_dir),
contents)
fileNameStack.pop()
return contents
# #
# Read in and parse the ISA description. # Read in and parse the ISA description.
# #
def parse_isa_desc(isa_desc_file, output_dir): def parse_isa_desc(isa_desc_file, output_dir):
# set a global var for the input filename... used in error messages # Read file and (recursively) all included files into a string.
global input_filename # PLY requires that the input be in a single string so we have to
input_filename = isa_desc_file # do this up front.
global fileNameStack isa_desc = read_and_flatten(isa_desc_file)
fileNameStack = [(input_filename, 1)]
# Suck the ISA description file in. # Initialize filename stack with outer file.
input = open(isa_desc_file) fileNameStack.push((isa_desc_file, 0))
isa_desc = input.read()
input.close()
# Perform Preprocessing
isa_desc = preprocess_isa_desc(isa_desc)
# Parse it. # Parse it.
(isa_name, namespace, global_code, namespace_code) = yacc.parse(isa_desc) (isa_name, namespace, global_code, namespace_code) = yacc.parse(isa_desc)