isa_parser: Make stack objects class members instead of globals

This commit is contained in:
Nathan Binkert 2010-02-26 18:14:48 -08:00
parent b4178b1ae7
commit 4e105f6fe1

View file

@ -1195,12 +1195,6 @@ class Stack(list):
def top(self): def top(self):
return self[-1] return self[-1]
# The global format stack.
formatStack = Stack(NoFormat())
# The global default case stack.
defaultStack = Stack(None)
# Global stack that tracks current file and line number. # Global stack that tracks current file and line number.
# Each element is a tuple (filename, lineno) that records the # Each element is a tuple (filename, lineno) that records the
# *current* filename and the line number in the *previous* file where # *current* filename and the line number in the *previous* file where
@ -1256,6 +1250,12 @@ class ISAParser(Grammar):
self.templateMap = {} self.templateMap = {}
# The format stack.
self.formatStack = Stack(NoFormat())
# The default case stack.
self.defaultStack = Stack(None)
##################################################################### #####################################################################
# #
# Lexer # Lexer
@ -1690,7 +1690,7 @@ StaticInstPtr
# #
def p_decode_block(self, t): def p_decode_block(self, t):
'decode_block : DECODE ID opt_default LBRACE decode_stmt_list RBRACE' 'decode_block : DECODE ID opt_default LBRACE decode_stmt_list RBRACE'
default_defaults = defaultStack.pop() default_defaults = self.defaultStack.pop()
codeObj = t[5] codeObj = t[5]
# use the "default defaults" only if there was no explicit # use the "default defaults" only if there was no explicit
# default statement in decode_stmt_list # default statement in decode_stmt_list
@ -1707,7 +1707,7 @@ StaticInstPtr
'opt_default : empty' 'opt_default : empty'
# no default specified: reuse the one currently at the top of # no default specified: reuse the one currently at the top of
# the stack # the stack
defaultStack.push(defaultStack.top()) self.defaultStack.push(self.defaultStack.top())
# no meaningful value returned # no meaningful value returned
t[0] = None t[0] = None
@ -1716,7 +1716,7 @@ StaticInstPtr
# push the new default # push the new default
codeObj = t[2] codeObj = t[2]
codeObj.wrap_decode_block('\ndefault:\n', 'break;\n') codeObj.wrap_decode_block('\ndefault:\n', 'break;\n')
defaultStack.push(codeObj) self.defaultStack.push(codeObj)
# no meaningful value returned # no meaningful value returned
t[0] = None t[0] = None
@ -1762,7 +1762,7 @@ StaticInstPtr
# is processed (see below). Once the parser has recognized # is processed (see below). Once the parser has recognized
# the full production (though the right brace), we're done # the full production (though the right brace), we're done
# with the format, so now we can pop it. # with the format, so now we can pop it.
formatStack.pop() self.formatStack.pop()
t[0] = t[4] t[0] = t[4]
# This rule exists so we can set the current format (& push the # This rule exists so we can set the current format (& push the
@ -1771,7 +1771,7 @@ StaticInstPtr
def p_push_format_id(self, t): def p_push_format_id(self, t):
'push_format_id : ID' 'push_format_id : ID'
try: try:
formatStack.push(formatMap[t[1]]) self.formatStack.push(formatMap[t[1]])
t[0] = ('', '// format %s' % t[1]) t[0] = ('', '// format %s' % t[1])
except KeyError: except KeyError:
error(t, 'instruction format "%s" not defined.' % t[1]) error(t, 'instruction format "%s" not defined.' % t[1])
@ -1831,7 +1831,7 @@ StaticInstPtr
def p_inst_0(self, t): def p_inst_0(self, t):
'inst : ID LPAREN arg_list RPAREN' 'inst : ID LPAREN arg_list RPAREN'
# Pass the ID and arg list to the current format class to deal with. # Pass the ID and arg list to the current format class to deal with.
currentFormat = formatStack.top() currentFormat = self.formatStack.top()
codeObj = currentFormat.defineInst(t[1], t[3], t.lexer.lineno) codeObj = currentFormat.defineInst(t[1], t[3], t.lexer.lineno)
args = ','.join(map(str, t[3])) args = ','.join(map(str, t[3]))
args = re.sub('(?m)^', '//', args) args = re.sub('(?m)^', '//', args)