Gabe Black has submitted this change. ( https://gem5-review.googlesource.com/c/public/gem5/+/67511?usp=email )

Change subject: sim: Add some helpers for setting up Signal*Ports in python.
......................................................................

sim: Add some helpers for setting up Signal*Ports in python.

The only difference between these types in python are the compatibility
strings which restrict what can connect to what. For ports which are
generally useful like interrupts or resets, they should have port types
with special names and even more restrictive compatibility. For other
ports which are one off signals between components, that would be
overkill, and these helpers will let you make a signal port which is
only restricted to ports which carry the same type of data.

The helpers are intended to look similar to their C++ counterpart
templates, and are functions which take a type signature as a string
as their argument, and return a class which is specialized to use that
type signature. The class itself can be stored, or used immediately.

foo = SignalSourcePort('bool')('A port for the foo signal')

Change-Id: If6359b2c69f34ff775cd9aa01272ac487db08bf7
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/67511
Maintainer: Gabe Black <gabe.bl...@gmail.com>
Tested-by: kokoro <noreply+kok...@google.com>
Reviewed-by: Yu-hsin Wang <yuhsi...@google.com>
---
M src/sim/SConscript
A src/sim/SignalPort.py
2 files changed, 106 insertions(+), 0 deletions(-)

Approvals:
  kokoro: Regressions pass
  Yu-hsin Wang: Looks good to me, approved
  Gabe Black: Looks good to me, approved




diff --git a/src/sim/SConscript b/src/sim/SConscript
index 75b595b..e26676c 100644
--- a/src/sim/SConscript
+++ b/src/sim/SConscript
@@ -42,6 +42,7 @@
 SimObject('RedirectPath.py', sim_objects=['RedirectPath'])
 SimObject('PowerState.py', sim_objects=['PowerState'], enums=['PwrState'])
 SimObject('PowerDomain.py', sim_objects=['PowerDomain'])
+SimObject('SignalPort.py', sim_objects=[])

 Source('async.cc')
 Source('backtrace_%s.cc' % env['BACKTRACE_IMPL'], add_tags='gem5 trace')
diff --git a/src/sim/SignalPort.py b/src/sim/SignalPort.py
new file mode 100644
index 0000000..fc529a8
--- /dev/null
+++ b/src/sim/SignalPort.py
@@ -0,0 +1,77 @@
+# Copyright 2023 Google, Inc.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met: redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer;
+# redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution;
+# neither the name of the copyright holders nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+from m5.params import Port, VectorPort
+
+SIGNAL_SOURCE_ROLE_TEMPLATE = "Signal source <%s>"
+SIGNAL_SINK_ROLE_TEMPLATE = "Signal sink <%s>"
+
+
+def SignalSourcePort(type_signature):
+    source_role = SIGNAL_SOURCE_ROLE_TEMPLATE % type_signature
+    sink_role = SIGNAL_SINK_ROLE_TEMPLATE % type_signature
+    Port.compat(source_role, sink_role)
+
+    class SignalSourcePort(Port):
+        def __init__(self, desc):
+            super().__init__(source_role, desc, is_source=True)
+
+    return SignalSourcePort
+
+
+def VectorSignalSourcePort(type_signature):
+    source_role = SIGNAL_SOURCE_ROLE_TEMPLATE % type_signature
+    sink_role = SIGNAL_SINK_ROLE_TEMPLATE % type_signature
+    Port.compat(source_role, sink_role)
+
+    class VectorSignalSourcePort(VectorPort):
+        def __init__(self, desc):
+            super().__init__(source_role, desc, is_source=True)
+
+    return VectorSignalSourcePort
+
+
+def SignalSinkPort(type_signature):
+    source_role = SIGNAL_SOURCE_ROLE_TEMPLATE % type_signature
+    sink_role = SIGNAL_SINK_ROLE_TEMPLATE % type_signature
+    Port.compat(source_role, sink_role)
+
+    class SignalSinkPort(Port):
+        def __init__(self, desc):
+            super().__init__(sink_role, desc)
+
+    return SignalSinkPort
+
+
+def VectorSignalSinkPort(type_signature):
+    source_role = SIGNAL_SOURCE_ROLE_TEMPLATE % type_signature
+    sink_role = SIGNAL_SINK_ROLE_TEMPLATE % type_signature
+    Port.compat(source_role, sink_role)
+
+    class VectorSignalSinkPort(VectorPort):
+        def __init__(self, desc):
+            super().__init__(sink_role, desc)
+
+    return VectorSignalSinkPort

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/67511?usp=email 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: If6359b2c69f34ff775cd9aa01272ac487db08bf7
Gerrit-Change-Number: 67511
Gerrit-PatchSet: 3
Gerrit-Owner: Gabe Black <gabe.bl...@gmail.com>
Gerrit-Reviewer: Gabe Black <gabe.bl...@gmail.com>
Gerrit-Reviewer: Jason Lowe-Power <ja...@lowepower.com>
Gerrit-Reviewer: Yu-hsin Wang <yuhsi...@google.com>
Gerrit-Reviewer: kokoro <noreply+kok...@google.com>
Gerrit-CC: Gabe Black <gabebl...@google.com>
Gerrit-MessageType: merged
_______________________________________________
gem5-dev mailing list -- gem5-dev@gem5.org
To unsubscribe send an email to gem5-dev-le...@gem5.org

Reply via email to