Andreas Sandberg has submitted this change. ( https://gem5-review.googlesource.com/c/public/gem5/+/34115 )

Change subject: base: Cleanup Debug::CompoundFlag
......................................................................

base: Cleanup Debug::CompoundFlag

Compound flags are currently constructed using a constructor with a
finite set of arguments that default to nullptr that refer to child
flags. C++11 introduces two cleaner ways to achieve the same thing,
variadic templates and initializer_list. Use an initializer list to
pass dependent flags.

Change-Id: Iadcd04986ab20efccfae9b92b26c079b9612262e
Signed-off-by: Andreas Sandberg <andreas.sandb...@arm.com>
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/34115
Reviewed-by: Jason Lowe-Power <power...@gmail.com>
Reviewed-by: Gabe Black <gabebl...@google.com>
Maintainer: Jason Lowe-Power <power...@gmail.com>
Tested-by: kokoro <noreply+kok...@google.com>
---
M src/SConscript
M src/base/debug.hh
2 files changed, 9 insertions(+), 29 deletions(-)

Approvals:
  Jason Lowe-Power: Looks good to me, approved; Looks good to me, approved
  Gabe Black: Looks good to me, approved
  kokoro: Regressions pass



diff --git a/src/SConscript b/src/SConscript
index d9cde28..4b6db44 100644
--- a/src/SConscript
+++ b/src/SConscript
@@ -1071,15 +1071,12 @@
         if not compound:
             code('SimpleFlag $name("$name", "$desc");')
         else:
-            comp_code('CompoundFlag $name("$name", "$desc",')
+            comp_code('CompoundFlag $name("$name", "$desc", {')
             comp_code.indent()
-            last = len(compound) - 1
-            for i,flag in enumerate(compound):
-                if i != last:
-                    comp_code('&$flag,')
-                else:
-                    comp_code('&$flag);')
+            for flag in compound:
+                comp_code('&$flag,')
             comp_code.dedent()
+            comp_code('});')

     code.append(comp_code)
     code()
diff --git a/src/base/debug.hh b/src/base/debug.hh
index 7c9834c..479a830 100644
--- a/src/base/debug.hh
+++ b/src/base/debug.hh
@@ -30,6 +30,7 @@
 #ifndef __BASE_DEBUG_HH__
 #define __BASE_DEBUG_HH__

+#include <initializer_list>
 #include <map>
 #include <string>
 #include <vector>
@@ -87,31 +88,13 @@
   protected:
     std::vector<Flag *> _kids;

-    void
-    addFlag(Flag *f)
-    {
-        if (f != nullptr)
-            _kids.push_back(f);
-    }
-
   public:
+    template<typename... Args>
     CompoundFlag(const char *name, const char *desc,
-        Flag *f00 = nullptr, Flag *f01 = nullptr,
-        Flag *f02 = nullptr, Flag *f03 = nullptr,
-        Flag *f04 = nullptr, Flag *f05 = nullptr,
-        Flag *f06 = nullptr, Flag *f07 = nullptr,
-        Flag *f08 = nullptr, Flag *f09 = nullptr,
-        Flag *f10 = nullptr, Flag *f11 = nullptr,
-        Flag *f12 = nullptr, Flag *f13 = nullptr,
-        Flag *f14 = nullptr, Flag *f15 = nullptr,
-        Flag *f16 = nullptr, Flag *f17 = nullptr,
-        Flag *f18 = nullptr, Flag *f19 = nullptr)
-        : Flag(name, desc)
+                 std::initializer_list<Flag *> flags)
+        : Flag(name, desc),
+          _kids(flags)
     {
- addFlag(f00); addFlag(f01); addFlag(f02); addFlag(f03); addFlag(f04); - addFlag(f05); addFlag(f06); addFlag(f07); addFlag(f08); addFlag(f09); - addFlag(f10); addFlag(f11); addFlag(f12); addFlag(f13); addFlag(f14); - addFlag(f15); addFlag(f16); addFlag(f17); addFlag(f18); addFlag(f19);
     }

     std::vector<Flag *> kids() { return _kids; }

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/34115
To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: Iadcd04986ab20efccfae9b92b26c079b9612262e
Gerrit-Change-Number: 34115
Gerrit-PatchSet: 2
Gerrit-Owner: Andreas Sandberg <andreas.sandb...@arm.com>
Gerrit-Assignee: Bobby R. Bruce <bbr...@ucdavis.edu>
Gerrit-Reviewer: Andreas Sandberg <andreas.sandb...@arm.com>
Gerrit-Reviewer: Gabe Black <gabebl...@google.com>
Gerrit-Reviewer: Jason Lowe-Power <power...@gmail.com>
Gerrit-Reviewer: kokoro <noreply+kok...@google.com>
Gerrit-CC: Bobby R. Bruce <bbr...@ucdavis.edu>
Gerrit-MessageType: merged
_______________________________________________
gem5-dev mailing list -- gem5-dev@gem5.org
To unsubscribe send an email to gem5-dev-le...@gem5.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

Reply via email to