changeset 17240f381d6a in /z/repo/gem5
details: http://repo.gem5.org/gem5?cmd=changeset;node=17240f381d6a
description:
        ruby: slicc: use default argument value
        Before this patch, while one could declare / define a function with 
default
        argument values, but the actual function call would require one to 
specify
        all the arguments.  This patch changes the check for  function 
arguments.
        Now a function call needs to specify arguments that are at least as 
much as
        those with default values and at most the total number of arguments 
taken
        as input by the function.

diffstat:

 src/mem/ruby/structures/AbstractReplacementPolicy.cc |   2 +-
 src/mem/ruby/structures/AbstractReplacementPolicy.hh |   6 ++--
 src/mem/ruby/structures/LRUPolicy.cc                 |   8 +++---
 src/mem/ruby/structures/LRUPolicy.hh                 |   4 +-
 src/mem/ruby/structures/PseudoLRUPolicy.cc           |  12 +++++-----
 src/mem/ruby/structures/PseudoLRUPolicy.hh           |   6 ++--
 src/mem/slicc/ast/EnumDeclAST.py                     |   2 +-
 src/mem/slicc/ast/FormalParamAST.py                  |  22 ++++++++++++++++++-
 src/mem/slicc/ast/FuncDeclAST.py                     |  17 ++++++++++----
 src/mem/slicc/ast/InPortDeclAST.py                   |   4 +-
 src/mem/slicc/ast/StateDeclAST.py                    |   4 +-
 src/mem/slicc/symbols/Func.py                        |  22 +++++++++++--------
 12 files changed, 69 insertions(+), 40 deletions(-)

diffs (truncated from 334 to 300 lines):

diff -r 32604f9e190b -r 17240f381d6a 
src/mem/ruby/structures/AbstractReplacementPolicy.cc
--- a/src/mem/ruby/structures/AbstractReplacementPolicy.cc      Fri Aug 14 
19:28:43 2015 -0500
+++ b/src/mem/ruby/structures/AbstractReplacementPolicy.cc      Fri Aug 14 
19:28:43 2015 -0500
@@ -66,7 +66,7 @@
 }
 
 Tick
-AbstractReplacementPolicy::getLastAccess(int64 set, int64 way)
+AbstractReplacementPolicy::getLastAccess(int64_t set, int64_t way)
 {
     return m_last_ref_ptr[set][way];
 }
diff -r 32604f9e190b -r 17240f381d6a 
src/mem/ruby/structures/AbstractReplacementPolicy.hh
--- a/src/mem/ruby/structures/AbstractReplacementPolicy.hh      Fri Aug 14 
19:28:43 2015 -0500
+++ b/src/mem/ruby/structures/AbstractReplacementPolicy.hh      Fri Aug 14 
19:28:43 2015 -0500
@@ -44,13 +44,13 @@
     virtual ~AbstractReplacementPolicy();
 
     /* touch a block. a.k.a. update timestamp */
-    virtual void touch(int64 set, int64 way, Tick time) = 0;
+    virtual void touch(int64_t set, int64_t way, Tick time) = 0;
 
     /* returns the way to replace */
-    virtual int64 getVictim(int64 set) const = 0;
+    virtual int64_t getVictim(int64_t set) const = 0;
 
     /* get the time of the last access */
-    Tick getLastAccess(int64 set, int64 way);
+    Tick getLastAccess(int64_t set, int64_t way);
 
     virtual bool useOccupancy() const { return false; }
 
diff -r 32604f9e190b -r 17240f381d6a src/mem/ruby/structures/LRUPolicy.cc
--- a/src/mem/ruby/structures/LRUPolicy.cc      Fri Aug 14 19:28:43 2015 -0500
+++ b/src/mem/ruby/structures/LRUPolicy.cc      Fri Aug 14 19:28:43 2015 -0500
@@ -50,7 +50,7 @@
 
 
 void
-LRUPolicy::touch(int64 set, int64 index, Tick time)
+LRUPolicy::touch(int64_t set, int64_t index, Tick time)
 {
     assert(index >= 0 && index < m_assoc);
     assert(set >= 0 && set < m_num_sets);
@@ -58,11 +58,11 @@
     m_last_ref_ptr[set][index] = time;
 }
 
-int64
-LRUPolicy::getVictim(int64 set) const
+int64_t
+LRUPolicy::getVictim(int64_t set) const
 {
     Tick time, smallest_time;
-    int64 smallest_index;
+    int64_t smallest_index;
 
     smallest_index = 0;
     smallest_time = m_last_ref_ptr[set][0];
diff -r 32604f9e190b -r 17240f381d6a src/mem/ruby/structures/LRUPolicy.hh
--- a/src/mem/ruby/structures/LRUPolicy.hh      Fri Aug 14 19:28:43 2015 -0500
+++ b/src/mem/ruby/structures/LRUPolicy.hh      Fri Aug 14 19:28:43 2015 -0500
@@ -41,8 +41,8 @@
     LRUPolicy(const Params * p);
     ~LRUPolicy();
 
-    void touch(int64 set, int64 way, Tick time);
-    int64 getVictim(int64 set) const;
+    void touch(int64_t set, int64_t way, Tick time);
+    int64_t getVictim(int64_t set) const;
 };
 
 #endif // __MEM_RUBY_STRUCTURES_LRUPOLICY_HH__
diff -r 32604f9e190b -r 17240f381d6a src/mem/ruby/structures/PseudoLRUPolicy.cc
--- a/src/mem/ruby/structures/PseudoLRUPolicy.cc        Fri Aug 14 19:28:43 
2015 -0500
+++ b/src/mem/ruby/structures/PseudoLRUPolicy.cc        Fri Aug 14 19:28:43 
2015 -0500
@@ -38,7 +38,7 @@
     // associativity cannot exceed capacity of tree representation
     assert(m_num_sets > 0 &&
            m_assoc > 1 &&
-           m_assoc <= (int64) sizeof(uint64)*4);
+           m_assoc <= (int64_t) sizeof(uint64_t)*4);
 
     m_trees = NULL;
     m_num_levels = 0;
@@ -55,7 +55,7 @@
         m_num_levels++;
     }
     assert(m_num_levels < sizeof(unsigned int)*4);
-    m_trees = new uint64[m_num_sets];
+    m_trees = new uint64_t[m_num_sets];
     for (unsigned i = 0; i < m_num_sets; i++) {
         m_trees[i] = 0;
     }
@@ -75,7 +75,7 @@
 }
 
 void
-PseudoLRUPolicy::touch(int64 set, int64 index, Tick time)
+PseudoLRUPolicy::touch(int64_t set, int64_t index, Tick time)
 {
     assert(index >= 0 && index < m_assoc);
     assert(set >= 0 && set < m_num_sets);
@@ -93,10 +93,10 @@
     m_last_ref_ptr[set][index] = time;
 }
 
-int64
-PseudoLRUPolicy::getVictim(int64 set) const
+int64_t
+PseudoLRUPolicy::getVictim(int64_t set) const
 {
-    int64 index = 0;
+    int64_t index = 0;
 
     int tree_index = 0;
     int node_val;
diff -r 32604f9e190b -r 17240f381d6a src/mem/ruby/structures/PseudoLRUPolicy.hh
--- a/src/mem/ruby/structures/PseudoLRUPolicy.hh        Fri Aug 14 19:28:43 
2015 -0500
+++ b/src/mem/ruby/structures/PseudoLRUPolicy.hh        Fri Aug 14 19:28:43 
2015 -0500
@@ -53,13 +53,13 @@
     PseudoLRUPolicy(const Params * p);
     ~PseudoLRUPolicy();
 
-    void touch(int64 set, int64 way, Tick time);
-    int64 getVictim(int64 set) const;
+    void touch(int64_t set, int64_t way, Tick time);
+    int64_t getVictim(int64_t set) const;
 
   private:
     unsigned int m_effective_assoc;    /** nearest (to ceiling) power of 2 */
     unsigned int m_num_levels;         /** number of levels in the tree */
-    uint64* m_trees;                   /** bit representation of the
+    uint64_t *m_trees;                   /** bit representation of the
                                         * trees, one for each set */
 };
 
diff -r 32604f9e190b -r 17240f381d6a src/mem/slicc/ast/EnumDeclAST.py
--- a/src/mem/slicc/ast/EnumDeclAST.py  Fri Aug 14 19:28:43 2015 -0500
+++ b/src/mem/slicc/ast/EnumDeclAST.py  Fri Aug 14 19:28:43 2015 -0500
@@ -67,6 +67,6 @@
         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 -r 32604f9e190b -r 17240f381d6a src/mem/slicc/ast/FormalParamAST.py
--- a/src/mem/slicc/ast/FormalParamAST.py       Fri Aug 14 19:28:43 2015 -0500
+++ b/src/mem/slicc/ast/FormalParamAST.py       Fri Aug 14 19:28:43 2015 -0500
@@ -46,6 +46,9 @@
     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,
@@ -56,6 +59,21 @@
            "interface" in type and (
                type["interface"] == "AbstractCacheEntry" or
                type["interface"] == "AbstractEntry")):
-            return type, "%s* %s" % (type.c_ident, param)
+            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
         else:
-            return type, "const %s& %s" % (type.c_ident, param)
+            proto = "const %s& %s" % (type.c_ident, param)
+            body = proto
+
+        return type, proto, body, default
diff -r 32604f9e190b -r 17240f381d6a src/mem/slicc/ast/FuncDeclAST.py
--- a/src/mem/slicc/ast/FuncDeclAST.py  Fri Aug 14 19:28:43 2015 -0500
+++ b/src/mem/slicc/ast/FuncDeclAST.py  Fri Aug 14 19:28:43 2015 -0500
@@ -45,7 +45,9 @@
 
     def generate(self, parent = None):
         types = []
-        params = []
+        proto_params = []
+        body_params = []
+        default_count = 0
         void_type = self.symtab.find("void", Type)
 
         # Generate definition code
@@ -58,13 +60,17 @@
         for formal in self.formals:
             # Lookup parameter types
             try:
-                type, ident = formal.generate()
+                type, proto, body, default = formal.generate()
                 types.append(type)
-                params.append(ident)
+                proto_params.append(proto)
+                body_params.append(body)
+                if default:
+                    default_count += 1
 
             except AttributeError:
                 types.append(formal.type)
-                params.append(None)
+                proto_params.append(None)
+                body_params.append(None)
 
         body = self.slicc.codeFormatter()
         if self.statements is None:
@@ -87,7 +93,8 @@
 
         machine = self.state_machine
         func = Func(self.symtab, func_name_args, self.ident, self.location,
-                    return_type, types, params, str(body), self.pairs)
+                    return_type, types, proto_params,
+                    body_params, str(body), self.pairs, default_count)
 
         if parent is not None:
             if not parent.addFunc(func):
diff -r 32604f9e190b -r 17240f381d6a src/mem/slicc/ast/InPortDeclAST.py
--- a/src/mem/slicc/ast/InPortDeclAST.py        Fri Aug 14 19:28:43 2015 -0500
+++ b/src/mem/slicc/ast/InPortDeclAST.py        Fri Aug 14 19:28:43 2015 -0500
@@ -89,13 +89,13 @@
         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 -r 32604f9e190b -r 17240f381d6a src/mem/slicc/ast/StateDeclAST.py
--- a/src/mem/slicc/ast/StateDeclAST.py Fri Aug 14 19:28:43 2015 -0500
+++ b/src/mem/slicc/ast/StateDeclAST.py Fri Aug 14 19:28:43 2015 -0500
@@ -66,7 +66,7 @@
         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 @@
         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)
diff -r 32604f9e190b -r 17240f381d6a src/mem/slicc/symbols/Func.py
--- a/src/mem/slicc/symbols/Func.py     Fri Aug 14 19:28:43 2015 -0500
+++ b/src/mem/slicc/symbols/Func.py     Fri Aug 14 19:28:43 2015 -0500
@@ -30,16 +30,19 @@
 
 class Func(Symbol):
     def __init__(self, table, ident, name, location, return_type, param_types,
-                 param_strings, body, pairs):
+                 proto_param_strings, body_param_strings, body,
+                 pairs, default_count = 0):
         super(Func, self).__init__(table, ident, location, pairs)
         self.return_type = return_type
         self.param_types = param_types
-        self.param_strings = param_strings
+        self.proto_param_strings = proto_param_strings
+        self.body_param_strings = body_param_strings
         self.body = body
         self.isInternalMachineFunc = False
         self.c_ident = ident
         self.c_name = name
         self.class_name = ""
+        self.default_count = default_count
 
     def __repr__(self):
         return ""
@@ -57,16 +60,17 @@
             return_type += "*"
 
         return "%s %s(%s);" % (return_type, self.c_name,
-                               ", ".join(self.param_strings))
+                               ", ".join(self.proto_param_strings))
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to