Daniel Carvalho has submitted this change. ( https://gem5-review.googlesource.com/c/public/gem5/+/38743 )

Change subject: base: Move Named class to its own file
......................................................................

base: Move Named class to its own file

Named can be useful in instances where trace is not required.
Because of that it has been moved to its own file.

Named is intended for public inheritance; thus it should have
a virtual destructor.

Added a unit test for the Named class.

Change-Id: I314e850b4fafd7804d919fd3fe6dec44822e1f48
Signed-off-by: Daniel R. Carvalho <oda...@yahoo.com.br>
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/38743
Reviewed-by: Gabe Black <gabe.bl...@gmail.com>
Maintainer: Bobby R. Bruce <bbr...@ucdavis.edu>
Tested-by: kokoro <noreply+kok...@google.com>
---
A src/base/named.hh
A src/base/named.test.cc
M src/base/trace.hh
M src/cpu/minor/buffers.hh
M src/cpu/minor/decode.hh
M src/cpu/minor/dyn_inst.hh
M src/cpu/minor/execute.hh
M src/cpu/minor/fetch1.hh
M src/cpu/minor/fetch2.hh
M src/cpu/minor/func_unit.cc
M src/cpu/minor/lsq.hh
M src/cpu/minor/scoreboard.hh
M src/mem/mem_checker.hh
13 files changed, 95 insertions(+), 14 deletions(-)

Approvals:
  Gabe Black: Looks good to me, approved
  Bobby R. Bruce: Looks good to me, approved
  kokoro: Regressions pass



diff --git a/src/base/named.hh b/src/base/named.hh
new file mode 100644
index 0000000..7e73310
--- /dev/null
+++ b/src/base/named.hh
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2021 Daniel R. Carvalho
+ * All rights reserved
+ *
+ * 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.
+ */
+
+#ifndef __BASE_NAMED_HH__
+#define __BASE_NAMED_HH__
+
+#include <string>
+
+/** Interface for things with names. This is useful when using DPRINTF. */
+class Named
+{
+  private:
+    const std::string _name;
+
+  public:
+    Named(const std::string &name_) : _name(name_) { }
+    virtual ~Named() = default;
+
+    const std::string &name() const { return _name; }
+};
+
+#endif // __BASE_NAMED_HH__
diff --git a/src/base/named.test.cc b/src/base/named.test.cc
new file mode 100644
index 0000000..3cc6951
--- /dev/null
+++ b/src/base/named.test.cc
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2021 Daniel R. Carvalho
+ * All rights reserved
+ *
+ * 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.
+ */
+
+#include <gtest/gtest.h>
+
+#include "base/named.hh"
+
+/** Test if a Named instance has the name it is assigned. */
+TEST(NamedTest, Name)
+{
+    Named named("Named class");
+    ASSERT_EQ("Named class", named.name());
+}
diff --git a/src/base/trace.hh b/src/base/trace.hh
index b5d579d..86dec09 100644
--- a/src/base/trace.hh
+++ b/src/base/trace.hh
@@ -145,20 +145,6 @@
// the DPRINTF macros are used in a context without a visible name() function
 const std::string &name();

-// Interface for things with names. (cf. SimObject but without other
-// functionality).  This is useful when using DPRINTF
-class Named
-{
-  protected:
-    const std::string _name;
-
-  public:
-    Named(const std::string &name_) : _name(name_) { }
-
-  public:
-    const std::string &name() const { return _name; }
-};
-
 /**
  * DPRINTF is a debugging trace facility that allows one to
  * selectively enable tracing statements.  To use DPRINTF, there must
diff --git a/src/cpu/minor/buffers.hh b/src/cpu/minor/buffers.hh
index 90ab694..11ae83a 100644
--- a/src/cpu/minor/buffers.hh
+++ b/src/cpu/minor/buffers.hh
@@ -50,6 +50,7 @@
 #include <string>

 #include "base/logging.hh"
+#include "base/named.hh"
 #include "base/types.hh"
 #include "cpu/activity.hh"
 #include "cpu/minor/trace.hh"
diff --git a/src/cpu/minor/decode.hh b/src/cpu/minor/decode.hh
index 636d53f..e4430eb 100644
--- a/src/cpu/minor/decode.hh
+++ b/src/cpu/minor/decode.hh
@@ -47,6 +47,7 @@

 #include <vector>

+#include "base/named.hh"
 #include "cpu/minor/buffers.hh"
 #include "cpu/minor/cpu.hh"
 #include "cpu/minor/dyn_inst.hh"
diff --git a/src/cpu/minor/dyn_inst.hh b/src/cpu/minor/dyn_inst.hh
index e84ae63..7dcf64e 100644
--- a/src/cpu/minor/dyn_inst.hh
+++ b/src/cpu/minor/dyn_inst.hh
@@ -48,6 +48,7 @@

 #include <iostream>

+#include "base/named.hh"
 #include "base/refcnt.hh"
 #include "base/types.hh"
 #include "cpu/inst_seq.hh"
diff --git a/src/cpu/minor/execute.hh b/src/cpu/minor/execute.hh
index 4d36a5d..3a42f08 100644
--- a/src/cpu/minor/execute.hh
+++ b/src/cpu/minor/execute.hh
@@ -47,6 +47,7 @@

 #include <vector>

+#include "base/named.hh"
 #include "base/types.hh"
 #include "cpu/minor/buffers.hh"
 #include "cpu/minor/cpu.hh"
diff --git a/src/cpu/minor/fetch1.hh b/src/cpu/minor/fetch1.hh
index cb68611..4a6bb6f 100644
--- a/src/cpu/minor/fetch1.hh
+++ b/src/cpu/minor/fetch1.hh
@@ -47,6 +47,7 @@

 #include <vector>

+#include "base/named.hh"
 #include "cpu/base.hh"
 #include "cpu/minor/buffers.hh"
 #include "cpu/minor/cpu.hh"
diff --git a/src/cpu/minor/fetch2.hh b/src/cpu/minor/fetch2.hh
index 2a7814a..bc25e69 100644
--- a/src/cpu/minor/fetch2.hh
+++ b/src/cpu/minor/fetch2.hh
@@ -47,6 +47,7 @@

 #include <vector>

+#include "base/named.hh"
 #include "cpu/minor/buffers.hh"
 #include "cpu/minor/cpu.hh"
 #include "cpu/minor/pipe_data.hh"
diff --git a/src/cpu/minor/func_unit.cc b/src/cpu/minor/func_unit.cc
index 8c5e3a6..b5024c3 100644
--- a/src/cpu/minor/func_unit.cc
+++ b/src/cpu/minor/func_unit.cc
@@ -41,6 +41,7 @@
 #include <sstream>
 #include <typeinfo>

+#include "base/named.hh"
 #include "base/trace.hh"
 #include "debug/MinorTiming.hh"
 #include "enums/OpClass.hh"
diff --git a/src/cpu/minor/lsq.hh b/src/cpu/minor/lsq.hh
index 1174883..a16fd3a 100644
--- a/src/cpu/minor/lsq.hh
+++ b/src/cpu/minor/lsq.hh
@@ -48,6 +48,7 @@
 #include <string>
 #include <vector>

+#include "base/named.hh"
 #include "cpu/minor/buffers.hh"
 #include "cpu/minor/cpu.hh"
 #include "cpu/minor/pipe_data.hh"
diff --git a/src/cpu/minor/scoreboard.hh b/src/cpu/minor/scoreboard.hh
index 1e4b1f1..cbff250 100644
--- a/src/cpu/minor/scoreboard.hh
+++ b/src/cpu/minor/scoreboard.hh
@@ -46,6 +46,7 @@

 #include <vector>

+#include "base/named.hh"
 #include "base/types.hh"
 #include "cpu/minor/cpu.hh"
 #include "cpu/minor/dyn_inst.hh"
diff --git a/src/mem/mem_checker.hh b/src/mem/mem_checker.hh
index c924b1d..101da4f 100644
--- a/src/mem/mem_checker.hh
+++ b/src/mem/mem_checker.hh
@@ -47,6 +47,7 @@
 #include <vector>

 #include "base/cprintf.hh"
+#include "base/named.hh"
 #include "base/trace.hh"
 #include "base/types.hh"
 #include "debug/MemChecker.hh"

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/38743
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: I314e850b4fafd7804d919fd3fe6dec44822e1f48
Gerrit-Change-Number: 38743
Gerrit-PatchSet: 5
Gerrit-Owner: Daniel Carvalho <oda...@yahoo.com.br>
Gerrit-Reviewer: Bobby R. Bruce <bbr...@ucdavis.edu>
Gerrit-Reviewer: Daniel Carvalho <oda...@yahoo.com.br>
Gerrit-Reviewer: Gabe Black <gabe.bl...@gmail.com>
Gerrit-Reviewer: kokoro <noreply+kok...@google.com>
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