summaryrefslogtreecommitdiff
path: root/src/mem/slicc/ast
diff options
context:
space:
mode:
authorBrad Beckmann <Brad.Beckmann@amd.com>2015-07-20 09:15:18 -0500
committerBrad Beckmann <Brad.Beckmann@amd.com>2015-07-20 09:15:18 -0500
commit8a54adc2a55c9858cb536fac3a9cd92bc47ce778 (patch)
treead482d891914407192f8aa568711baecfe92e83c /src/mem/slicc/ast
parent0d00cbc97b47344e12e9eb943efb9ca29db66898 (diff)
downloadgem5-8a54adc2a55c9858cb536fac3a9cd92bc47ce778.tar.xz
slicc: enable overloading in functions not in classes
For many years the slicc symbol table has supported overloaded functions in external classes. This patch extends that support to functions that are not part of classes (a.k.a. no parent). For example, this support allows slicc to understand that mapAddressToRange is overloaded and the NodeID is an optional parameter.
Diffstat (limited to 'src/mem/slicc/ast')
-rw-r--r--src/mem/slicc/ast/EnumDeclAST.py3
-rw-r--r--src/mem/slicc/ast/FuncCallExprAST.py12
-rw-r--r--src/mem/slicc/ast/FuncDeclAST.py15
-rw-r--r--src/mem/slicc/ast/InPortDeclAST.py11
-rw-r--r--src/mem/slicc/ast/StateDeclAST.py6
5 files changed, 35 insertions, 12 deletions
diff --git a/src/mem/slicc/ast/EnumDeclAST.py b/src/mem/slicc/ast/EnumDeclAST.py
index acddcb91f..d97c13483 100644
--- a/src/mem/slicc/ast/EnumDeclAST.py
+++ b/src/mem/slicc/ast/EnumDeclAST.py
@@ -65,7 +65,8 @@ class EnumDeclAST(DeclAST):
func_id = "%s_to_string" % t.c_ident
pairs = { "external" : "yes" }
- func = Func(self.symtab, func_id, self.location,
+ func = Func(self.symtab, func_id + "_" + t.c_ident,
+ func_id, self.location,
self.symtab.find("std::string", Type), [ t ], [], "",
pairs)
self.symtab.newSymbol(func)
diff --git a/src/mem/slicc/ast/FuncCallExprAST.py b/src/mem/slicc/ast/FuncCallExprAST.py
index 8aebad336..9336a2297 100644
--- a/src/mem/slicc/ast/FuncCallExprAST.py
+++ b/src/mem/slicc/ast/FuncCallExprAST.py
@@ -80,12 +80,18 @@ class FuncCallExprAST(ExprAST):
code("APPEND_TRANSITION_COMMENT($0)", self.exprs[0].inline())
return self.symtab.find("void", Type)
+ func_name_args = self.proc_name
+
+ for expr in self.exprs:
+ actual_type,param_code = expr.inline(True)
+ func_name_args += "_" + str(actual_type.ident)
+
# Look up the function in the symbol table
- func = self.symtab.find(self.proc_name, Func)
+ func = self.symtab.find(func_name_args, Func)
# Check the types and get the code for the parameters
if func is None:
- self.error("Unrecognized function name: '%s'", self.proc_name)
+ self.error("Unrecognized function name: '%s'", func_name_args)
if len(self.exprs) != len(func.param_types):
self.error("Wrong number of arguments passed to function : '%s'" +\
@@ -193,7 +199,7 @@ if (!(${{cvec[0]}})) {
params += str(param_code);
fix = code.nofix()
- code('(${{func.c_ident}}($params))')
+ code('(${{func.c_name}}($params))')
code.fix(fix)
return func.return_type
diff --git a/src/mem/slicc/ast/FuncDeclAST.py b/src/mem/slicc/ast/FuncDeclAST.py
index 052d9f05e..47ae7076e 100644
--- a/src/mem/slicc/ast/FuncDeclAST.py
+++ b/src/mem/slicc/ast/FuncDeclAST.py
@@ -74,9 +74,20 @@ class FuncDeclAST(DeclAST):
self.symtab.popFrame()
+ func_name_args = self.ident
+
+ if parent is None:
+ for arg in self.formals:
+ from slicc.ast import FormalParamAST
+ if isinstance(arg, FormalParamAST):
+ arg_name = arg.type_ast.ident
+ else:
+ arg_name = arg
+ func_name_args += "_" + str(arg_name)
+
machine = self.state_machine
- func = Func(self.symtab, self.ident, self.location, return_type,
- types, params, str(body), self.pairs)
+ func = Func(self.symtab, func_name_args, self.ident, self.location,
+ 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 c5a1435eb..da7357580 100644
--- a/src/mem/slicc/ast/InPortDeclAST.py
+++ b/src/mem/slicc/ast/InPortDeclAST.py
@@ -85,14 +85,17 @@ class InPortDeclAST(DeclAST):
# Add the trigger method - FIXME, this is a bit dirty
pairs = { "external" : "yes" }
- func = Func(self.symtab, "trigger", self.location, void_type,
- param_types, [], "", pairs)
+ trigger_func_name = "trigger"
+ 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)
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", self.location, void_type, [],
- [], "", pairs)
+ func = Func(self.symtab, "stallPort", "stallPort", self.location,
+ void_type, [], [], "", pairs)
symtab.newSymbol(func)
param_types = []
diff --git a/src/mem/slicc/ast/StateDeclAST.py b/src/mem/slicc/ast/StateDeclAST.py
index 2bca54d09..f0a0b97d3 100644
--- a/src/mem/slicc/ast/StateDeclAST.py
+++ b/src/mem/slicc/ast/StateDeclAST.py
@@ -64,7 +64,8 @@ class StateDeclAST(DeclAST):
func_id = "%s_to_string" % t.c_ident
pairs = { "external" : "yes" }
- func = Func(self.symtab, func_id, self.location,
+ func = Func(self.symtab, func_id + "_" +
+ t.ident, func_id, self.location,
self.symtab.find("std::string", Type), [ t ], [], "",
pairs)
self.symtab.newSymbol(func)
@@ -73,7 +74,8 @@ class StateDeclAST(DeclAST):
func_id = "%s_to_permission" % t.c_ident
pairs = { "external" : "yes" }
- func = Func(self.symtab, func_id, self.location,
+ func = Func(self.symtab, func_id + "_" +
+ t.ident, func_id, self.location,
self.symtab.find("AccessPermission", Type), [ t ], [], "",
pairs)
self.symtab.newSymbol(func)