Giacomo Travaglini has submitted this change. (
https://gem5-review.googlesource.com/c/public/gem5/+/39898 )
Change subject: sim: Define PARAMS macro utility
......................................................................
sim: Define PARAMS macro utility
To reduce code duplication and to ensure that the result of [1] will not
deteriorate, define a macro to be used in every descendant of SimObject
that needs its own params().
[1] 91d83cc8a12883f2d7493b37f50487cd7f03a9e6
Change-Id: I1a1a0dedf91ae228ea27b8ed324577ee3439ea68
Signed-off-by: Alexander Klimov <[email protected]>
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/39898
Reviewed-by: Daniel Carvalho <[email protected]>
Reviewed-by: Jason Lowe-Power <[email protected]>
Maintainer: Jason Lowe-Power <[email protected]>
Tested-by: kokoro <[email protected]>
---
M src/sim/sim_object.hh
1 file changed, 36 insertions(+), 1 deletion(-)
Approvals:
Jason Lowe-Power: Looks good to me, approved; Looks good to me, approved
Daniel Carvalho: Looks good to me, but someone else must approve
kokoro: Regressions pass
diff --git a/src/sim/sim_object.hh b/src/sim/sim_object.hh
index a75f8dd..9bab952 100644
--- a/src/sim/sim_object.hh
+++ b/src/sim/sim_object.hh
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015 ARM Limited
+ * Copyright (c) 2015, 2021 ARM Limited
* All rights reserved
*
* The license below extends only to copyright in the software and shall
@@ -117,6 +117,26 @@
* If you don't have a constructor with that signature at all, then you
must
* implement the create method with that signature which will build your
* object in some other way.
+ *
+ * A reference to the SimObjectParams will be returned via the params()
+ * API. It is quite common for a derived class (DerivSimObject) to access
its
+ * derived parameters by downcasting the SimObjectParam to
DerivSimObjectParams
+ *
+ * \code{.cpp}
+ * using Params = DerivSimObjectParams;
+ * const Params &
+ * params() const
+ * {
+ * return reinterpret_cast<const Params&>(_params);
+ * }
+ * \endcode
+ *
+ * We provide the PARAMS(..) macro as syntactic sugar to replace the code
+ * above with a much simpler:
+ *
+ * \code{.cpp}
+ * PARAMS(DerivSimObject);
+ * \endcode
*/
class SimObject : public EventManager, public Serializable, public
Drainable,
public Stats::Group
@@ -314,6 +334,21 @@
static SimObject *find(const char *name);
};
+/* Add PARAMS(ClassName) to every descendant of SimObject that needs
+ * params.
+ *
+ * Strictly speaking, we need static_cast here, because the types are
+ * related by inheritance, but since the target type may be
+ * incomplete, the compiler does not know the relation.
+ */
+#define PARAMS(type) \
+ using Params = type ## Params; \
+ const Params & \
+ params() const \
+ { \
+ return reinterpret_cast<const Params&>(_params); \
+ }
+
/**
* Base class to wrap object resolving functionality.
*
--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/39898
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: I1a1a0dedf91ae228ea27b8ed324577ee3439ea68
Gerrit-Change-Number: 39898
Gerrit-PatchSet: 3
Gerrit-Owner: Giacomo Travaglini <[email protected]>
Gerrit-Reviewer: Boris Shingarov <[email protected]>
Gerrit-Reviewer: Daniel Carvalho <[email protected]>
Gerrit-Reviewer: Gabe Black <[email protected]>
Gerrit-Reviewer: Giacomo Travaglini <[email protected]>
Gerrit-Reviewer: Jason Lowe-Power <[email protected]>
Gerrit-Reviewer: Jason Lowe-Power <[email protected]>
Gerrit-Reviewer: Matthew Poremba <[email protected]>
Gerrit-Reviewer: kokoro <[email protected]>
Gerrit-MessageType: merged
_______________________________________________
gem5-dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s