changeset a86f453a7caa in /z/repo/gem5
details: http://repo.gem5.org/gem5?cmd=changeset;node=a86f453a7caa
description:
        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:

 src/mem/protocol/RubySlicc_ComponentMapping.sm |   2 ++
 src/mem/slicc/ast/EnumDeclAST.py               |   3 ++-
 src/mem/slicc/ast/FuncCallExprAST.py           |  12 +++++++++---
 src/mem/slicc/ast/FuncDeclAST.py               |  15 +++++++++++++--
 src/mem/slicc/ast/InPortDeclAST.py             |  11 +++++++----
 src/mem/slicc/ast/StateDeclAST.py              |   6 ++++--
 src/mem/slicc/symbols/Func.py                  |   7 ++++---
 src/mem/slicc/symbols/Transition.py            |   2 +-
 8 files changed, 42 insertions(+), 16 deletions(-)

diffs (182 lines):

diff -r 6036e4555eda -r a86f453a7caa 
src/mem/protocol/RubySlicc_ComponentMapping.sm
--- a/src/mem/protocol/RubySlicc_ComponentMapping.sm    Mon Jul 20 09:15:18 
2015 -0500
+++ b/src/mem/protocol/RubySlicc_ComponentMapping.sm    Mon Jul 20 09:15:18 
2015 -0500
@@ -31,6 +31,8 @@
 
 int machineCount(MachineType machType);
 MachineID mapAddressToRange(Address addr, MachineType type,
+                            int low, int high);
+MachineID mapAddressToRange(Address addr, MachineType type,
                             int low, int high, NodeID n);
 NetDest broadcast(MachineType type);
 MachineID map_Address_to_DMA(Address addr);
diff -r 6036e4555eda -r a86f453a7caa src/mem/slicc/ast/EnumDeclAST.py
--- a/src/mem/slicc/ast/EnumDeclAST.py  Mon Jul 20 09:15:18 2015 -0500
+++ b/src/mem/slicc/ast/EnumDeclAST.py  Mon Jul 20 09:15:18 2015 -0500
@@ -65,7 +65,8 @@
         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 -r 6036e4555eda -r a86f453a7caa src/mem/slicc/ast/FuncCallExprAST.py
--- a/src/mem/slicc/ast/FuncCallExprAST.py      Mon Jul 20 09:15:18 2015 -0500
+++ b/src/mem/slicc/ast/FuncCallExprAST.py      Mon Jul 20 09:15:18 2015 -0500
@@ -80,12 +80,18 @@
             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 @@
                     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 -r 6036e4555eda -r a86f453a7caa src/mem/slicc/ast/FuncDeclAST.py
--- a/src/mem/slicc/ast/FuncDeclAST.py  Mon Jul 20 09:15:18 2015 -0500
+++ b/src/mem/slicc/ast/FuncDeclAST.py  Mon Jul 20 09:15:18 2015 -0500
@@ -74,9 +74,20 @@
 
         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 -r 6036e4555eda -r a86f453a7caa src/mem/slicc/ast/InPortDeclAST.py
--- a/src/mem/slicc/ast/InPortDeclAST.py        Mon Jul 20 09:15:18 2015 -0500
+++ b/src/mem/slicc/ast/InPortDeclAST.py        Mon Jul 20 09:15:18 2015 -0500
@@ -85,14 +85,17 @@
 
         # 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 -r 6036e4555eda -r a86f453a7caa src/mem/slicc/ast/StateDeclAST.py
--- a/src/mem/slicc/ast/StateDeclAST.py Mon Jul 20 09:15:18 2015 -0500
+++ b/src/mem/slicc/ast/StateDeclAST.py Mon Jul 20 09:15:18 2015 -0500
@@ -64,7 +64,8 @@
         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 @@
         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)
diff -r 6036e4555eda -r a86f453a7caa src/mem/slicc/symbols/Func.py
--- a/src/mem/slicc/symbols/Func.py     Mon Jul 20 09:15:18 2015 -0500
+++ b/src/mem/slicc/symbols/Func.py     Mon Jul 20 09:15:18 2015 -0500
@@ -29,7 +29,7 @@
 from slicc.symbols.Type import Type
 
 class Func(Symbol):
-    def __init__(self, table, ident, location, return_type, param_types,
+    def __init__(self, table, ident, name, location, return_type, param_types,
                  param_strings, body, pairs):
         super(Func, self).__init__(table, ident, location, pairs)
         self.return_type = return_type
@@ -38,6 +38,7 @@
         self.body = body
         self.isInternalMachineFunc = False
         self.c_ident = ident
+        self.c_name = name
         self.class_name = ""
 
     def __repr__(self):
@@ -55,7 +56,7 @@
         elif "return_by_pointer" in self and self.return_type != void_type:
             return_type += "*"
 
-        return "%s %s(%s);" % (return_type, self.c_ident,
+        return "%s %s(%s);" % (return_type, self.c_name,
                                ", ".join(self.param_strings))
 
     def writeCodeFiles(self, path, includes):
@@ -80,7 +81,7 @@
 
         code('''
 $return_type
-${{self.class_name}}::${{self.c_ident}}($params)
+${{self.class_name}}::${{self.c_name}}($params)
 {
 ${{self.body}}
 }
diff -r 6036e4555eda -r a86f453a7caa src/mem/slicc/symbols/Transition.py
--- a/src/mem/slicc/symbols/Transition.py       Mon Jul 20 09:15:18 2015 -0500
+++ b/src/mem/slicc/symbols/Transition.py       Mon Jul 20 09:15:18 2015 -0500
@@ -40,7 +40,7 @@
             # check to make sure there is a getNextState function declared
             found = False
             for func in machine.functions:
-                if func.c_ident == 'getNextState':
+                if func.c_ident == 'getNextState_Address':
                     found = True
                     break
             if found == False:
_______________________________________________
gem5-dev mailing list
gem5-dev@gem5.org
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to