diff options
Diffstat (limited to 'src/mem/slicc/ast')
-rw-r--r-- | src/mem/slicc/ast/EnumDeclAST.py | 2 | ||||
-rw-r--r-- | src/mem/slicc/ast/FormalParamAST.py | 22 | ||||
-rw-r--r-- | src/mem/slicc/ast/FuncCallExprAST.py | 17 | ||||
-rw-r--r-- | src/mem/slicc/ast/FuncDeclAST.py | 17 | ||||
-rw-r--r-- | src/mem/slicc/ast/InPortDeclAST.py | 4 | ||||
-rw-r--r-- | src/mem/slicc/ast/MethodCallExprAST.py | 21 | ||||
-rw-r--r-- | src/mem/slicc/ast/StateDeclAST.py | 4 |
7 files changed, 45 insertions, 42 deletions
diff --git a/src/mem/slicc/ast/EnumDeclAST.py b/src/mem/slicc/ast/EnumDeclAST.py index bc0c1c224..d97c13483 100644 --- a/src/mem/slicc/ast/EnumDeclAST.py +++ b/src/mem/slicc/ast/EnumDeclAST.py @@ -67,6 +67,6 @@ class EnumDeclAST(DeclAST): pairs = { "external" : "yes" } func = Func(self.symtab, func_id + "_" + t.c_ident, func_id, self.location, - self.symtab.find("std::string", Type), [ t ], [], [], "", + self.symtab.find("std::string", Type), [ t ], [], "", pairs) self.symtab.newSymbol(func) diff --git a/src/mem/slicc/ast/FormalParamAST.py b/src/mem/slicc/ast/FormalParamAST.py index ef39b40f0..ce73304f1 100644 --- a/src/mem/slicc/ast/FormalParamAST.py +++ b/src/mem/slicc/ast/FormalParamAST.py @@ -46,9 +46,6 @@ class FormalParamAST(AST): def generate(self): type = self.type_ast.type param = "param_%s" % self.ident - proto = "" - body = "" - default = False # Add to symbol table v = Var(self.symtab, self.ident, self.location, type, param, @@ -59,21 +56,6 @@ class FormalParamAST(AST): "interface" in type and ( type["interface"] == "AbstractCacheEntry" or type["interface"] == "AbstractEntry")): - proto = "%s* %s" % (type.c_ident, param) - body = proto - elif self.default != None: - value = "" - if self.default == True: - value = "true" - elif self.default == False: - value = "false" - else: - value = "%s" % self.default - proto = "const %s& %s = %s" % (type.c_ident, param, value) - body = "const %s& %s" % (type.c_ident, param) - default = True + return type, "%s* %s" % (type.c_ident, param) else: - proto = "const %s& %s" % (type.c_ident, param) - body = proto - - return type, proto, body, default + return type, "const %s& %s" % (type.c_ident, param) diff --git a/src/mem/slicc/ast/FuncCallExprAST.py b/src/mem/slicc/ast/FuncCallExprAST.py index 0c9880d6d..9336a2297 100644 --- a/src/mem/slicc/ast/FuncCallExprAST.py +++ b/src/mem/slicc/ast/FuncCallExprAST.py @@ -93,7 +93,22 @@ class FuncCallExprAST(ExprAST): if func is None: self.error("Unrecognized function name: '%s'", func_name_args) - cvec, type_vec = func.checkArguments(self.exprs) + if len(self.exprs) != len(func.param_types): + self.error("Wrong number of arguments passed to function : '%s'" +\ + " Expected %d, got %d", self.proc_name, + len(func.param_types), len(self.exprs)) + + cvec = [] + type_vec = [] + for expr,expected_type in zip(self.exprs, func.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): + expr.error("Type mismatch: expected: %s actual: %s" % \ + (expected_type, actual_type)) + cvec.append(param_code) + type_vec.append(expected_type) # OK, the semantics of "trigger" here is that, ports in the # machine have different priorities. We always check the first diff --git a/src/mem/slicc/ast/FuncDeclAST.py b/src/mem/slicc/ast/FuncDeclAST.py index 4e64c0ba5..47ae7076e 100644 --- a/src/mem/slicc/ast/FuncDeclAST.py +++ b/src/mem/slicc/ast/FuncDeclAST.py @@ -45,9 +45,7 @@ class FuncDeclAST(DeclAST): def generate(self, parent = None): types = [] - proto_params = [] - body_params = [] - default_count = 0 + params = [] void_type = self.symtab.find("void", Type) # Generate definition code @@ -60,17 +58,13 @@ class FuncDeclAST(DeclAST): for formal in self.formals: # Lookup parameter types try: - type, proto, body, default = formal.generate() + type, ident = formal.generate() types.append(type) - proto_params.append(proto) - body_params.append(body) - if default: - default_count += 1 + params.append(ident) except AttributeError: types.append(formal.type) - proto_params.append(None) - body_params.append(None) + params.append(None) body = self.slicc.codeFormatter() if self.statements is None: @@ -93,8 +87,7 @@ class FuncDeclAST(DeclAST): machine = self.state_machine func = Func(self.symtab, func_name_args, self.ident, self.location, - return_type, types, proto_params, - body_params, str(body), self.pairs, default_count) + return_type, types, params, str(body), self.pairs) if parent is not None: if not parent.addFunc(func): diff --git a/src/mem/slicc/ast/InPortDeclAST.py b/src/mem/slicc/ast/InPortDeclAST.py index 2ef043151..7a019a0e0 100644 --- a/src/mem/slicc/ast/InPortDeclAST.py +++ b/src/mem/slicc/ast/InPortDeclAST.py @@ -89,13 +89,13 @@ class InPortDeclAST(DeclAST): for param in param_types: trigger_func_name += "_" + param.ident func = Func(self.symtab, trigger_func_name, "trigger", self.location, - void_type, param_types, [], [], "", pairs) + void_type, param_types, [], "", pairs) symtab.newSymbol(func) # Add the stallPort method - this hacks reschedules the controller # for stalled messages that don't trigger events func = Func(self.symtab, "stallPort", "stallPort", self.location, - void_type, [], [], [], "", pairs) + void_type, [], [], "", pairs) symtab.newSymbol(func) param_types = [] diff --git a/src/mem/slicc/ast/MethodCallExprAST.py b/src/mem/slicc/ast/MethodCallExprAST.py index 104d6f8df..8be319a40 100644 --- a/src/mem/slicc/ast/MethodCallExprAST.py +++ b/src/mem/slicc/ast/MethodCallExprAST.py @@ -56,8 +56,20 @@ class MethodCallExprAST(ExprAST): self.error("Invalid method call: Type '%s' does not have a method '%s'", obj_type, methodId) - func = obj_type.methods[methodId] - func.checkArguments(self.expr_ast_vec) + if len(self.expr_ast_vec) != \ + len(obj_type.methods[methodId].param_types): + # Right number of parameters + self.error("Wrong number of parameters for function name: '%s', " + \ + "expected: , actual: ", proc_name, + len(obj_type.methods[methodId].param_types), + len(self.expr_ast_vec)) + + for actual_type, expected_type in \ + zip(paramTypes, obj_type.methods[methodId].param_types): + if actual_type != expected_type and \ + str(actual_type["interface"]) != str(expected_type): + self.error("Type mismatch: expected: %s actual: %s", + expected_type, actual_type) # Return the return type of the method return obj_type.methods[methodId].return_type @@ -66,9 +78,10 @@ class MethodCallExprAST(ExprAST): pass class MemberMethodCallExprAST(MethodCallExprAST): - def __init__(self, slicc, obj_expr_ast, func_call): + def __init__(self, slicc, obj_expr_ast, proc_name, expr_ast_vec): s = super(MemberMethodCallExprAST, self) - s.__init__(slicc, func_call.proc_name, func_call.exprs) + s.__init__(slicc, proc_name, expr_ast_vec) + self.obj_expr_ast = obj_expr_ast def __repr__(self): diff --git a/src/mem/slicc/ast/StateDeclAST.py b/src/mem/slicc/ast/StateDeclAST.py index a33ea9245..f0a0b97d3 100644 --- a/src/mem/slicc/ast/StateDeclAST.py +++ b/src/mem/slicc/ast/StateDeclAST.py @@ -66,7 +66,7 @@ class StateDeclAST(DeclAST): pairs = { "external" : "yes" } func = Func(self.symtab, func_id + "_" + t.ident, func_id, self.location, - self.symtab.find("std::string", Type), [ t ], [], [], "", + self.symtab.find("std::string", Type), [ t ], [], "", pairs) self.symtab.newSymbol(func) @@ -76,6 +76,6 @@ class StateDeclAST(DeclAST): pairs = { "external" : "yes" } func = Func(self.symtab, func_id + "_" + t.ident, func_id, self.location, - self.symtab.find("AccessPermission", Type), [ t ], [], [], "", + self.symtab.find("AccessPermission", Type), [ t ], [], "", pairs) self.symtab.newSymbol(func) |