summaryrefslogtreecommitdiff
path: root/src/mem/slicc/ast
diff options
context:
space:
mode:
authorNilay Vaish <nilay@cs.wisc.edu>2014-09-01 16:55:44 -0500
committerNilay Vaish <nilay@cs.wisc.edu>2014-09-01 16:55:44 -0500
commitb1d3873ec52692b0442666718da4175379697bb2 (patch)
treecff299c0befcef4f843272e1e9f633060fa8c815 /src/mem/slicc/ast
parent3202ec98e713d3f997e6b47f06451236c565f706 (diff)
downloadgem5-b1d3873ec52692b0442666718da4175379697bb2.tar.xz
ruby: slicc: improve the grammar
This patch changes the grammar for SLICC so as to remove some of the redundant / duplicate rules. In particular rules for object/variable declaration and class member declaration have been unified. Similarly, the rules for a general function and a class method have been unified. One more change is in the priority of two rules. The first rule is on declaring a function with all the params typed and named. The second rule is on declaring a function with all the params only typed. Earlier the second rule had a higher priority. Now the first rule has a higher priority.
Diffstat (limited to 'src/mem/slicc/ast')
-rw-r--r--src/mem/slicc/ast/FuncDeclAST.py11
-rw-r--r--src/mem/slicc/ast/ObjDeclAST.py28
-rw-r--r--src/mem/slicc/ast/TypeFieldMemberAST.py57
-rw-r--r--src/mem/slicc/ast/TypeFieldMethodAST.py52
-rw-r--r--src/mem/slicc/ast/__init__.py2
5 files changed, 30 insertions, 120 deletions
diff --git a/src/mem/slicc/ast/FuncDeclAST.py b/src/mem/slicc/ast/FuncDeclAST.py
index 1d7e2c3ff..052d9f05e 100644
--- a/src/mem/slicc/ast/FuncDeclAST.py
+++ b/src/mem/slicc/ast/FuncDeclAST.py
@@ -57,9 +57,14 @@ class FuncDeclAST(DeclAST):
# Generate function header
for formal in self.formals:
# Lookup parameter types
- type, ident = formal.generate()
- types.append(type)
- params.append(ident)
+ try:
+ type, ident = formal.generate()
+ types.append(type)
+ params.append(ident)
+
+ except AttributeError:
+ types.append(formal.type)
+ params.append(None)
body = self.slicc.codeFormatter()
if self.statements is None:
diff --git a/src/mem/slicc/ast/ObjDeclAST.py b/src/mem/slicc/ast/ObjDeclAST.py
index 5cb662fc0..ffd71bbb1 100644
--- a/src/mem/slicc/ast/ObjDeclAST.py
+++ b/src/mem/slicc/ast/ObjDeclAST.py
@@ -29,21 +29,23 @@ from slicc.ast.DeclAST import DeclAST
from slicc.symbols import Var
class ObjDeclAST(DeclAST):
- def __init__(self, slicc, type_ast, ident, pairs):
+ def __init__(self, slicc, type_ast, ident, pairs, rvalue):
super(ObjDeclAST, self).__init__(slicc, pairs)
self.type_ast = type_ast
self.ident = ident
+ self.rvalue = rvalue
def __repr__(self):
return "[ObjDecl: %r]" % self.ident
- def generate(self):
+ def generate(self, parent = None):
if "network" in self and not ("virtual_network" in self or
"physical_network" in self) :
self.error("Network queues require a 'virtual_network' attribute")
type = self.type_ast.type
+
if type.isBuffer and "ordered" not in self:
self.error("Buffer object decls require an 'ordered' attribute")
@@ -60,8 +62,6 @@ class ObjDeclAST(DeclAST):
self.error("The 'random' attribute is '%s' " + \
"must be 'true' or 'false'.", value)
- machine = self.symtab.state_machine
-
# FIXME : should all use accessors here to avoid public member
# variables
if self.ident == "version":
@@ -73,10 +73,26 @@ class ObjDeclAST(DeclAST):
else:
c_code = "(*m_%s_ptr)" % (self.ident)
+ # check type if this is a initialization
+ init_code = ""
+ if self.rvalue:
+ rvalue_type,init_code = self.rvalue.inline(True)
+ if type != rvalue_type:
+ self.error("Initialization type mismatch '%s' and '%s'" % \
+ (type, rvalue_type))
+
+ machine = self.symtab.state_machine
+
v = Var(self.symtab, self.ident, self.location, type, c_code,
self.pairs, machine)
- if machine:
+ # Add data member to the parent type
+ if parent:
+ if not parent.addDataMember(self.ident, type, self.pairs, init_code):
+ self.error("Duplicate data member: %s:%s" % (parent, self.ident))
+
+ elif machine:
machine.addObject(v)
- self.symtab.newSymbol(v)
+ else:
+ self.symtab.newSymbol(v)
diff --git a/src/mem/slicc/ast/TypeFieldMemberAST.py b/src/mem/slicc/ast/TypeFieldMemberAST.py
deleted file mode 100644
index 30e2fcda5..000000000
--- a/src/mem/slicc/ast/TypeFieldMemberAST.py
+++ /dev/null
@@ -1,57 +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.TypeFieldAST import TypeFieldAST
-
-class TypeFieldMemberAST(TypeFieldAST):
- def __init__(self, slicc, type_ast, field_id, pairs, rvalue):
- super(TypeFieldMemberAST, self).__init__(slicc, pairs)
-
- self.type_ast = type_ast
- self.field_id = field_id
- self.rvalue = rvalue
-
- def __repr__(self):
- return "[TypeFieldMember: %r]" % self.field_id
-
- def generate(self, type):
- # Lookup type
- field_type = self.type_ast.type
-
- # check type if this is a initialization
- init_code = ""
- if self.rvalue:
- rvalue_type,init_code = self.rvalue.inline(True)
- if field_type != rvalue_type:
- self.error("Initialization type mismatch '%s' and '%s'" % \
- (field_type, rvalue_type))
-
- # Add data member to the parent type
- if not type.addDataMember(self.field_id, field_type, self.pairs,
- init_code):
-
- self.error("Duplicate data member: %s:%s" % (field_type, self.field_id))
diff --git a/src/mem/slicc/ast/TypeFieldMethodAST.py b/src/mem/slicc/ast/TypeFieldMethodAST.py
deleted file mode 100644
index b89f7f97e..000000000
--- a/src/mem/slicc/ast/TypeFieldMethodAST.py
+++ /dev/null
@@ -1,52 +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.TypeFieldAST import TypeFieldAST
-
-class TypeFieldMethodAST(TypeFieldAST):
- def __init__(self, slicc, return_type_ast, ident, type_asts, pairs,
- statements = None):
- super(TypeFieldMethodAST, self).__init__(slicc, pairs)
-
- self.return_type_ast = return_type_ast
- self.ident = ident
- self.type_asts = type_asts
- self.statements = statements
-
- def __repr__(self):
- return ""
-
- def generate(self, type):
- # Lookup return type
- return_type = self.return_type_ast.type
-
- # Lookup parameter types
- types = [ t.type for t in self.type_asts ]
-
- # Add method
- if not type.addMethod(self.ident, return_type, types):
- self.error("Duplicate method: %s:%s()" % (type, self.ident))
diff --git a/src/mem/slicc/ast/__init__.py b/src/mem/slicc/ast/__init__.py
index 98472cdf2..9fc52eff8 100644
--- a/src/mem/slicc/ast/__init__.py
+++ b/src/mem/slicc/ast/__init__.py
@@ -67,7 +67,5 @@ from slicc.ast.TypeAST import *
from slicc.ast.TypeDeclAST import *
from slicc.ast.TypeFieldAST import *
from slicc.ast.TypeFieldEnumAST import *
-from slicc.ast.TypeFieldMemberAST import *
-from slicc.ast.TypeFieldMethodAST import *
from slicc.ast.TypeFieldStateAST import *
from slicc.ast.VarExprAST import *