diff --git a/src/base/named.hh b/src/base/named.hh new file mode 100644 index 0000000000..7e733107fb --- /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 + +/** 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 0000000000..3cc6951ed2 --- /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 + +#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 b5d579d2af..86dec09773 100644 --- a/src/base/trace.hh +++ b/src/base/trace.hh @@ -145,20 +145,6 @@ struct StringWrap // 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 90ab694975..11ae83aedd 100644 --- a/src/cpu/minor/buffers.hh +++ b/src/cpu/minor/buffers.hh @@ -50,6 +50,7 @@ #include #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 636d53ffdf..e4430eb7a9 100644 --- a/src/cpu/minor/decode.hh +++ b/src/cpu/minor/decode.hh @@ -47,6 +47,7 @@ #include +#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 e84ae63f8e..7dcf64eab5 100644 --- a/src/cpu/minor/dyn_inst.hh +++ b/src/cpu/minor/dyn_inst.hh @@ -48,6 +48,7 @@ #include +#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 4d36a5d888..3a42f08a35 100644 --- a/src/cpu/minor/execute.hh +++ b/src/cpu/minor/execute.hh @@ -47,6 +47,7 @@ #include +#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 cb68611a54..4a6bb6fe8d 100644 --- a/src/cpu/minor/fetch1.hh +++ b/src/cpu/minor/fetch1.hh @@ -47,6 +47,7 @@ #include +#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 2a7814aed4..bc25e693ad 100644 --- a/src/cpu/minor/fetch2.hh +++ b/src/cpu/minor/fetch2.hh @@ -47,6 +47,7 @@ #include +#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 8c5e3a6bb4..b5024c315b 100644 --- a/src/cpu/minor/func_unit.cc +++ b/src/cpu/minor/func_unit.cc @@ -41,6 +41,7 @@ #include #include +#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 11748835fd..a16fd3a2d2 100644 --- a/src/cpu/minor/lsq.hh +++ b/src/cpu/minor/lsq.hh @@ -48,6 +48,7 @@ #include #include +#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 1e4b1f1ef5..cbff2509e3 100644 --- a/src/cpu/minor/scoreboard.hh +++ b/src/cpu/minor/scoreboard.hh @@ -46,6 +46,7 @@ #include +#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 c924b1db46..101da4fe78 100644 --- a/src/mem/mem_checker.hh +++ b/src/mem/mem_checker.hh @@ -47,6 +47,7 @@ #include #include "base/cprintf.hh" +#include "base/named.hh" #include "base/trace.hh" #include "base/types.hh" #include "debug/MemChecker.hh"