Gabe Black has uploaded this change for review. ( https://gem5-review.googlesource.com/c/public/gem5/+/49385 )

Change subject: scons: Create a namedtuple for debug flag info.
......................................................................

scons: Create a namedtuple for debug flag info.

This avoids having to rely on certain bits of information being in
certain positions, and also makes it more obvious which piece of
information you're referring to when manipulating the objects.

Change-Id: I93799d00261002996a42a62a7de34c4c275847c5
---
M src/SConscript
1 file changed, 31 insertions(+), 19 deletions(-)



diff --git a/src/SConscript b/src/SConscript
index 397e8e8..4d03f14 100644
--- a/src/SConscript
+++ b/src/SConscript
@@ -38,6 +38,7 @@
 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

 import bisect
+import collections
 import distutils.spawn
 import importlib
 import importlib.machinery
@@ -399,15 +400,17 @@
 #

 def makeDebugFlagHH(target, source, env):
-    assert len(target) == 1 and len(source) == 1
+    assert len(target) == 1

-    name, components, desc, fmt = FromValue(source[0])
+    flag = env['DEBUG_FLAG'][0]
+    name, desc, components, fmt = \
+            flag.name, flag.desc, flag.components, flag.fmt

     code = code_formatter()

-    typename = "CompoundFlag" if components else "SimpleFlag"
-    component_flag_decls = \
- ''.join('extern SimpleFlag& %s;\n' % flag for flag in components)
+    typename = "CompoundFlag" if flag.components else "SimpleFlag"
+    component_flag_decls = ''.join('extern SimpleFlag& %s;\n' % simple for
+            simple in components)

     # file header boilerplate
     code('''\
@@ -436,19 +439,23 @@

     code.write(str(target[0]))

+DebugFlagInfo = collections.namedtuple('DebugFlag',
+        ['name', 'desc', 'components', 'fmt'],
+        defaults=[(), False])
 def DebugFlag(name, desc=None, fmt=False):
     if name == "All":
         raise AttributeError('The "All" flag name is reserved')
     debug_flags = env.get('DEBUG_FLAGS', [])
-    if any(name == flag[0] for flag in debug_flags):
+    if any(name == flag.name for flag in debug_flags):
         raise AttributeError(f'Flag {name} already specified')

-    flag = (name, (), desc, fmt)
+    flag = DebugFlagInfo(name, desc, fmt=fmt)
     env.Append(DEBUG_FLAGS=[flag])

     hh_file = Dir(env['BUILDDIR']).Dir('debug').File(f'{name}.hh')
-    env.Command(hh_file, ToValue(flag),
-            MakeAction(makeDebugFlagHH, Transform("TRACING", 0)))
+    env.Command(hh_file, [], DEBUG_FLAG=[flag],
+            action=MakeAction(makeDebugFlagHH, Transform("TRACING", 0),
+                varlist=['DEBUG_FLAG']))

 def CompoundFlag(name, flags, desc=None):
     if name == "All":
@@ -457,12 +464,13 @@
     if any(name == flag[0] for flag in debug_flags):
         raise AttributeError(f'Flag {name} already specified')

-    flag = (name, flags, desc, False)
+    flag = DebugFlagInfo(name, desc, components=flags)
     env.Append(DEBUG_FLAGS=[flag])

-    env.Command(Dir(env['BUILDDIR']).Dir('debug').File(f'{name}.hh'),
-            ToValue(flag),
-            MakeAction(makeDebugFlagHH, Transform("TRACING", 0)))
+    hh_file = Dir(env['BUILDDIR']).Dir('debug').File(f'{name}.hh')
+    env.Command(hh_file, [], DEBUG_FLAG=[flag],
+            action=MakeAction(makeDebugFlagHH, Transform("TRACING", 0),
+                varlist=['DEBUG_FLAG']))

 def DebugFormatFlag(name, desc=None):
     DebugFlag(name, desc, True)
@@ -910,8 +918,8 @@
 ''')

     all_flags = env.get('DEBUG_FLAGS', [])
-    simple_flags = sorted(filter(lambda f: not f[1], all_flags))
-    compound_flags = sorted(filter(lambda f: f[1], all_flags))
+    simple_flags = sorted(filter(lambda f: not f.components, all_flags))
+    compound_flags = sorted(filter(lambda f: f.components, all_flags))

     # We intentionally make flag a reference to a heap allocated object so
     # (1) It has a similar interface to a global object like before
@@ -919,16 +927,20 @@
     # The second property is desirable as global objects from different
     # translation units do not have a defined destruction order, so it'll
     # be unsafe to access debug flags in their destructor in such cases.
-    for name, _, desc, fmt in simple_flags:
-        fmt = 'true' if fmt else 'false'
+    for flag in simple_flags:
+        name, desc, components, fmt = \
+                flag.name, flag.desc, flag.components, flag.fmt
+        fmt = 'true' if flag.fmt else 'false'
         code('''
 SimpleFlag& $name = *(
     new SimpleFlag("$name", "$desc", $fmt));''')

-    for name, compound, desc, _ in compound_flags:
+    for flag in compound_flags:
+        name, desc, components, fmt = \
+                flag.name, flag.desc, flag.components, flag.fmt
         code('''
 CompoundFlag& $name = *(new CompoundFlag("$name", "$desc", {
-    ${{', '.join('&' + flag for flag in compound)}}
+    ${{', '.join('&' + simple for simple in components)}}
 }));''')

     code('''

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/49385
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: I93799d00261002996a42a62a7de34c4c275847c5
Gerrit-Change-Number: 49385
Gerrit-PatchSet: 1
Gerrit-Owner: Gabe Black <gabe.bl...@gmail.com>
Gerrit-MessageType: newchange
_______________________________________________
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