summaryrefslogtreecommitdiff
path: root/src/mem/slicc/symbols/Func.py
diff options
context:
space:
mode:
authorNilay Vaish <nilay@cs.wisc.edu>2015-08-14 19:28:43 -0500
committerNilay Vaish <nilay@cs.wisc.edu>2015-08-14 19:28:43 -0500
commit7fc725fdb55e192520c148c87ec44f75f5d07ad0 (patch)
tree077503f95730d91127d88bcd0101c38096f8aadb /src/mem/slicc/symbols/Func.py
parentf391cee5e1f9192bc35978df236e15f921a690cf (diff)
downloadgem5-7fc725fdb55e192520c148c87ec44f75f5d07ad0.tar.xz
ruby: slicc: avoid duplicate code for function argument check
Both FuncCallExprAST and MethodCallExprAST had code for checking the arguments with which a function is being called. The patch does away with this duplication. Now the code for checking function call arguments resides in the Func class.
Diffstat (limited to 'src/mem/slicc/symbols/Func.py')
-rw-r--r--src/mem/slicc/symbols/Func.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/mem/slicc/symbols/Func.py b/src/mem/slicc/symbols/Func.py
index d50d0309f..6da74002a 100644
--- a/src/mem/slicc/symbols/Func.py
+++ b/src/mem/slicc/symbols/Func.py
@@ -62,6 +62,27 @@ class Func(Symbol):
def writeCodeFiles(self, path, includes):
return
+ def checkArguments(self, args):
+ if len(args) != len(self.param_types):
+ self.error("Wrong number of arguments passed to function : '%s'" +\
+ " Expected %d, got %d", self.c_ident,
+ len(self.param_types), len(args))
+
+ cvec = []
+ type_vec = []
+ for expr,expected_type in zip(args, self.param_types):
+ # Check the types of the parameter
+ actual_type,param_code = expr.inline(True)
+ if str(actual_type) != 'OOD' and \
+ str(actual_type) != str(expected_type) and \
+ str(actual_type["interface"]) != str(expected_type):
+ expr.error("Type mismatch: expected: %s actual: %s" % \
+ (expected_type, actual_type))
+ cvec.append(param_code)
+ type_vec.append(expected_type)
+
+ return cvec, type_vec
+
def generateCode(self):
'''This write a function of object Chip'''
if "external" in self: