summaryrefslogtreecommitdiff
path: root/src/mem/slicc/symbols
diff options
context:
space:
mode:
authorNilay Vaish <nilay@cs.wisc.edu>2012-10-15 17:27:16 -0500
committerNilay Vaish <nilay@cs.wisc.edu>2012-10-15 17:27:16 -0500
commit3e607f146f4c8acac6b42e61a0e6295f52f408a4 (patch)
treee0274a4eab977e9662a9dc22126f726518d8213f /src/mem/slicc/symbols
parentc7b0901b97a86eb2d61e4ddd96a73a9d777a57c1 (diff)
downloadgem5-3e607f146f4c8acac6b42e61a0e6295f52f408a4.tar.xz
ruby: allow function definition in slicc structs
This patch adds support for function definitions to appear in slicc structs. This is required for supporting functional accesses for different types of messages. Subsequent patches will use this to development.
Diffstat (limited to 'src/mem/slicc/symbols')
-rw-r--r--src/mem/slicc/symbols/Func.py16
-rw-r--r--src/mem/slicc/symbols/Type.py28
2 files changed, 28 insertions, 16 deletions
diff --git a/src/mem/slicc/symbols/Func.py b/src/mem/slicc/symbols/Func.py
index 8e137d044..a52b6bbcc 100644
--- a/src/mem/slicc/symbols/Func.py
+++ b/src/mem/slicc/symbols/Func.py
@@ -30,7 +30,7 @@ from slicc.symbols.Type import Type
class Func(Symbol):
def __init__(self, table, ident, location, return_type, param_types,
- param_strings, body, pairs, machine):
+ param_strings, body, pairs):
super(Func, self).__init__(table, ident, location, pairs)
self.return_type = return_type
self.param_types = param_types
@@ -38,12 +38,7 @@ class Func(Symbol):
self.body = body
self.isInternalMachineFunc = False
self.c_ident = ident
-
- if machine is None or "external" in self or "primitive" in self:
- pass
- else:
- self.machineStr = str(machine)
- self.isInternalMachineFunc = True
+ self.class_name = ""
def __repr__(self):
return ""
@@ -81,16 +76,11 @@ class Func(Symbol):
if "return_by_pointer" in self and self.return_type != void_type:
return_type += "*"
- if self.isInternalMachineFunc:
- klass = "%s_Controller" % self.machineStr
- else:
- self.error("No class found for the function %s" % self.ident)
-
params = ', '.join(self.param_strings)
code('''
$return_type
-${klass}::${{self.c_ident}}($params)
+${{self.class_name}}::${{self.c_ident}}($params)
{
${{self.body}}
}
diff --git a/src/mem/slicc/symbols/Type.py b/src/mem/slicc/symbols/Type.py
index aec05a678..383291911 100644
--- a/src/mem/slicc/symbols/Type.py
+++ b/src/mem/slicc/symbols/Type.py
@@ -107,6 +107,7 @@ class Type(Symbol):
# Methods
self.methods = {}
+ self.functions = {}
# Enums
self.enums = orderdict()
@@ -143,7 +144,7 @@ class Type(Symbol):
return "interface" in self
# Return false on error
- def dataMemberAdd(self, ident, type, pairs, init_code):
+ def addDataMember(self, ident, type, pairs, init_code):
if ident in self.data_members:
return False
@@ -164,7 +165,7 @@ class Type(Symbol):
def statePermPairAdd(self, state_name, perm_name):
self.statePermPairs.append([state_name, perm_name])
- def methodAdd(self, name, return_type, param_type_vec):
+ def addMethod(self, name, return_type, param_type_vec):
ident = self.methodId(name, param_type_vec)
if ident in self.methods:
return False
@@ -172,7 +173,18 @@ class Type(Symbol):
self.methods[ident] = Method(return_type, param_type_vec)
return True
- def enumAdd(self, ident, pairs):
+ # Ideally either this function or the one above should exist. But
+ # methods and functions have different structures right now.
+ # Hence, these are different, at least for the time being.
+ def addFunc(self, func):
+ ident = self.methodId(func.ident, func.param_types)
+ if ident in self.functions:
+ return False
+
+ self.functions[ident] = func
+ return True
+
+ def addEnum(self, ident, pairs):
if ident in self.enums:
return False
@@ -368,6 +380,12 @@ set${{dm.ident}}(const ${{dm.type.c_ident}}& local_${{dm.ident}})
code('$const${{dm.type.c_ident}} m_${{dm.ident}}$init;')
+ # Prototypes for functions defined for the Type
+ for item in self.functions:
+ proto = self.functions[item].prototype
+ if proto:
+ code('$proto')
+
code.dedent()
code('};')
@@ -423,6 +441,10 @@ ${{self.c_ident}}::print(ostream& out) const
out << "]";
}''')
+ # print the code for the functions in the type
+ for item in self.functions:
+ code(self.functions[item].generateCode())
+
code.write(path, "%s.cc" % self.c_ident)
def printEnumHH(self, path):