From 59a7abff29aa5a687e1693f003c20d7e2000c40a Mon Sep 17 00:00:00 2001 From: "Nilay Vaish ext:(%2C%20Malek%20Musleh%20%3Cmalek.musleh%40gmail.com%3E)" Date: Tue, 21 May 2013 11:31:31 -0500 Subject: ruby: add stats to .sm files, remove cache profiler This patch changes the way cache statistics are collected in ruby. As of now, there is separate entity called CacheProfiler which holds statistical variables for caches. The CacheMemory class defines different functions for accessing the CacheProfiler. These functions are then invoked in the .sm files. I find this approach opaque and prone to error. Secondly, we probably should not be paying the cost of a function call for recording statistics. Instead, this patch allows for accessing statistical variables in the .sm files. The collection would become transparent. Secondly, it would happen in place, so no function calls. The patch also removes the CacheProfiler class. --HG-- rename : src/mem/slicc/ast/InfixOperatorExprAST.py => src/mem/slicc/ast/OperatorExprAST.py --- src/mem/slicc/ast/InfixOperatorExprAST.py | 91 ------------------------ src/mem/slicc/ast/OperatorExprAST.py | 112 ++++++++++++++++++++++++++++++ src/mem/slicc/ast/__init__.py | 2 +- src/mem/slicc/parser.py | 8 ++- src/mem/slicc/symbols/StateMachine.py | 6 +- 5 files changed, 122 insertions(+), 97 deletions(-) delete mode 100644 src/mem/slicc/ast/InfixOperatorExprAST.py create mode 100644 src/mem/slicc/ast/OperatorExprAST.py (limited to 'src/mem/slicc') diff --git a/src/mem/slicc/ast/InfixOperatorExprAST.py b/src/mem/slicc/ast/InfixOperatorExprAST.py deleted file mode 100644 index 31bf9bd1a..000000000 --- a/src/mem/slicc/ast/InfixOperatorExprAST.py +++ /dev/null @@ -1,91 +0,0 @@ -# Copyright (c) 1999-2008 Mark D. Hill and David A. Wood -# Copyright (c) 2009 The Hewlett-Packard Development Company -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are -# met: redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer; -# redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution; -# neither the name of the copyright holders nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -from slicc.ast.ExprAST import ExprAST -from slicc.symbols import Type - -class InfixOperatorExprAST(ExprAST): - def __init__(self, slicc, left, op, right): - super(InfixOperatorExprAST, self).__init__(slicc) - - self.left = left - self.op = op - self.right = right - - def __repr__(self): - return "[InfixExpr: %r %s %r]" % (self.left, self.op, self.right) - - def generate(self, code): - lcode = self.slicc.codeFormatter() - rcode = self.slicc.codeFormatter() - - ltype = self.left.generate(lcode) - rtype = self.right.generate(rcode) - - # Figure out what the input and output types should be - if self.op in ("==", "!=", ">=", "<=", ">", "<"): - output = "bool" - if (ltype != rtype): - self.error("Type mismatch: left and right operands of " + - "operator '%s' must be the same type. " + - "left: '%s', right: '%s'", - self.op, ltype, rtype) - else: - expected_types = [] - output = None - - if self.op in ("&&", "||"): - # boolean inputs and output - expected_types = [("bool", "bool", "bool")] - elif self.op in ("<<", ">>"): - expected_types = [("int", "int", "int"), - ("Cycles", "int", "Cycles")] - elif self.op in ("+", "-", "*", "/"): - expected_types = [("int", "int", "int"), - ("Cycles", "Cycles", "Cycles"), - ("Cycles", "int", "Cycles"), - ("int", "Cycles", "Cycles")] - else: - self.error("No operator matched with {0}!" .format(self.op)) - - for expected_type in expected_types: - left_input_type = self.symtab.find(expected_type[0], Type) - right_input_type = self.symtab.find(expected_type[1], Type) - - if (left_input_type == ltype) and (right_input_type == rtype): - output = expected_type[2] - - if output == None: - self.error("Type mismatch: operands ({0}, {1}) for operator " \ - "'{2}' failed to match with the expected types" . - format(ltype, rtype, self.op)) - - # All is well - fix = code.nofix() - code("($lcode ${{self.op}} $rcode)") - code.fix(fix) - return self.symtab.find(output, Type) diff --git a/src/mem/slicc/ast/OperatorExprAST.py b/src/mem/slicc/ast/OperatorExprAST.py new file mode 100644 index 000000000..df074b9f0 --- /dev/null +++ b/src/mem/slicc/ast/OperatorExprAST.py @@ -0,0 +1,112 @@ +# Copyright (c) 1999-2008 Mark D. Hill and David A. Wood +# Copyright (c) 2009 The Hewlett-Packard Development Company +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer; +# redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution; +# neither the name of the copyright holders nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +from slicc.ast.ExprAST import ExprAST +from slicc.symbols import Type + +class InfixOperatorExprAST(ExprAST): + def __init__(self, slicc, left, op, right): + super(InfixOperatorExprAST, self).__init__(slicc) + + self.left = left + self.op = op + self.right = right + + def __repr__(self): + return "[InfixExpr: %r %s %r]" % (self.left, self.op, self.right) + + def generate(self, code): + lcode = self.slicc.codeFormatter() + rcode = self.slicc.codeFormatter() + + ltype = self.left.generate(lcode) + rtype = self.right.generate(rcode) + + # Figure out what the input and output types should be + if self.op in ("==", "!=", ">=", "<=", ">", "<"): + output = "bool" + if (ltype != rtype): + self.error("Type mismatch: left and right operands of " + + "operator '%s' must be the same type. " + + "left: '%s', right: '%s'", + self.op, ltype, rtype) + else: + expected_types = [] + output = None + + if self.op in ("&&", "||"): + # boolean inputs and output + expected_types = [("bool", "bool", "bool")] + elif self.op in ("<<", ">>"): + expected_types = [("int", "int", "int"), + ("Cycles", "int", "Cycles")] + elif self.op in ("+", "-", "*", "/"): + expected_types = [("int", "int", "int"), + ("Cycles", "Cycles", "Cycles"), + ("Cycles", "int", "Cycles"), + ("Scalar", "int", "Scalar"), + ("int", "Cycles", "Cycles")] + else: + self.error("No operator matched with {0}!" .format(self.op)) + + for expected_type in expected_types: + left_input_type = self.symtab.find(expected_type[0], Type) + right_input_type = self.symtab.find(expected_type[1], Type) + + if (left_input_type == ltype) and (right_input_type == rtype): + output = expected_type[2] + + if output == None: + self.error("Type mismatch: operands ({0}, {1}) for operator " \ + "'{2}' failed to match with the expected types" . + format(ltype, rtype, self.op)) + + # All is well + fix = code.nofix() + code("($lcode ${{self.op}} $rcode)") + code.fix(fix) + return self.symtab.find(output, Type) + +class PrefixOperatorExprAST(ExprAST): + def __init__(self, slicc, op, operand): + super(PrefixOperatorExprAST, self).__init__(slicc) + + self.op = op + self.operand = operand + + def __repr__(self): + return "[PrefixExpr: %s %r]" % (self.op, self.operand) + + def generate(self, code): + opcode = self.slicc.codeFormatter() + optype = self.operand.generate(opcode) + + fix = code.nofix() + code("(${{self.op}} $opcode)") + code.fix(fix) + + return self.symtab.find("void", Type) diff --git a/src/mem/slicc/ast/__init__.py b/src/mem/slicc/ast/__init__.py index c2baea8df..bd9de52d0 100644 --- a/src/mem/slicc/ast/__init__.py +++ b/src/mem/slicc/ast/__init__.py @@ -43,7 +43,6 @@ from slicc.ast.FuncCallExprAST import * from slicc.ast.FuncDeclAST import * from slicc.ast.IfStatementAST import * from slicc.ast.InPortDeclAST import * -from slicc.ast.InfixOperatorExprAST import * from slicc.ast.IsValidPtrExprAST import * from slicc.ast.LiteralExprAST import * from slicc.ast.LocalVariableAST import * @@ -53,6 +52,7 @@ from slicc.ast.MethodCallExprAST import * from slicc.ast.NewExprAST import * from slicc.ast.OodAST import * from slicc.ast.ObjDeclAST import * +from slicc.ast.OperatorExprAST import * from slicc.ast.OutPortDeclAST import * from slicc.ast.PairAST import * from slicc.ast.PairListAST import * diff --git a/src/mem/slicc/parser.py b/src/mem/slicc/parser.py index 78b842f74..96e029ecf 100644 --- a/src/mem/slicc/parser.py +++ b/src/mem/slicc/parser.py @@ -132,6 +132,7 @@ class SLICC(Grammar): 'LEFTSHIFT', 'RIGHTSHIFT', 'NOT', 'AND', 'OR', 'PLUS', 'DASH', 'STAR', 'SLASH', + 'INCR', 'DECR', 'DOUBLE_COLON', 'SEMI', 'ASSIGN', 'DOT', 'IDENT', 'LIT_BOOL', 'FLOATNUMBER', 'NUMBER', 'STRING' ] @@ -156,8 +157,11 @@ class SLICC(Grammar): t_SEMI = r';' t_ASSIGN = r':=' t_DOT = r'\.' + t_INCR = r'\+\+' + t_DECR = r'--' precedence = ( + ('left', 'INCR', 'DECR'), ('left', 'AND', 'OR'), ('left', 'EQ', 'NE'), ('left', 'LT', 'GT', 'LE', 'GE'), @@ -670,8 +674,10 @@ class SLICC(Grammar): # FIXME - unary not def p_expr__unary_op(self, p): """expr : NOT expr + | INCR expr + | DECR expr | DASH expr %prec UMINUS""" - p[0] = PrefixOperatorExpr(p[1], p[2]) + p[0] = ast.PrefixOperatorExprAST(self, p[1], p[2]) def p_expr__parens(self, p): "aexpr : '(' expr ')'" diff --git a/src/mem/slicc/symbols/StateMachine.py b/src/mem/slicc/symbols/StateMachine.py index f650f5809..c2ee42553 100644 --- a/src/mem/slicc/symbols/StateMachine.py +++ b/src/mem/slicc/symbols/StateMachine.py @@ -768,8 +768,7 @@ $c_ident::printStats(ostream& out) const # them. Print out these stats before dumping state transition stats. # for param in self.config_parameters: - if param.type_ast.type.ident == "CacheMemory" or \ - param.type_ast.type.ident == "DirectoryMemory" or \ + if param.type_ast.type.ident == "DirectoryMemory" or \ param.type_ast.type.ident == "MemoryControl": assert(param.pointer) code(' m_${{param.ident}}_ptr->printStats(out);') @@ -787,8 +786,7 @@ void $c_ident::clearStats() { # them. These stats must be cleared too. # for param in self.config_parameters: - if param.type_ast.type.ident == "CacheMemory" or \ - param.type_ast.type.ident == "MemoryControl": + if param.type_ast.type.ident == "MemoryControl": assert(param.pointer) code(' m_${{param.ident}}_ptr->clearStats();') -- cgit v1.2.3