summaryrefslogtreecommitdiff
path: root/src/mem/slicc/symbols/Type.py
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/Type.py
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/Type.py')
-rw-r--r--src/mem/slicc/symbols/Type.py28
1 files changed, 25 insertions, 3 deletions
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):