From: Gabe Black Date: Sat, 4 Apr 2020 13:53:00 +0000 (-0700) Subject: util: Move the call type implementations into their own subdir. X-Git-Tag: v20.1.0.0~529 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=8e0b1d337876ae25ac01b01fb1b1e6f3ede6f90d;p=gem5.git util: Move the call type implementations into their own subdir. Change-Id: Ie94c2ef4783b6b5700beb0f0bbeb765ce9b03934 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/27551 Tested-by: kokoro Maintainer: Gabe Black Reviewed-by: Daniel Carvalho --- diff --git a/util/m5/src/SConscript b/util/m5/src/SConscript index 176f4c262..ee725fd99 100644 --- a/util/m5/src/SConscript +++ b/util/m5/src/SConscript @@ -27,6 +27,8 @@ import os Import('*') +env.Append(CPPPATH=Dir('.')) + # Raw source files. args = 'args.cc' call_type = 'call_type.cc' @@ -65,7 +67,7 @@ for ct in call_types: ct_env = static_env.Clone() is_default = 'true' if ct.default else 'false' ct_env.Append(CXXFLAGS=[ '-DCALL_TYPE_IS_DEFAULT=%s' % is_default ]) - ct_support.extend(ct_env.StaticObject('%s_call_type.cc' % ct.name)) + ct_support.extend(ct_env.StaticObject('call_type/%s.cc' % ct.name)) m5_bin = static_env.Program('out/m5', ct_support + [ args, call_type, commands, m5, m5_mmap, libm5, usage ]) diff --git a/util/m5/src/addr_call_type.cc b/util/m5/src/addr_call_type.cc deleted file mode 100644 index 963bb2e30..000000000 --- a/util/m5/src/addr_call_type.cc +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright 2020 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. - */ - -#include - -#include "m5_mmap.h" - -#include "call_type.hh" -#include "usage.hh" - -extern "C" -{ -#define M5OP(name, func) __typeof__(name) M5OP_MERGE_TOKENS(name, _addr); -M5OP_FOREACH -#undef M5OP -} - -namespace -{ - -DispatchTable addr_dispatch = { -#define M5OP(name, func) .name = &::M5OP_MERGE_TOKENS(name, _addr), -M5OP_FOREACH -#undef M5OP -}; - -#if defined(M5OP_ADDR) -const bool DefaultAddrDefined = true; -constexpr uint64_t DefaultAddress = M5OP_ADDR; -#else -const bool DefaultAddrDefined = false; -constexpr uint64_t DefaultAddress = 0; -#endif - -class AddrCallType : public CallType -{ - private: - public: - bool isDefault() const override { return CALL_TYPE_IS_DEFAULT; } - const DispatchTable &getDispatch() const override { return addr_dispatch; } - - void - printBrief(std::ostream &os) const override - { - os << "--addr " << (DefaultAddrDefined ? "[address override]" : - "
"); - } - - void - printDesc(std::ostream &os) const override - { - os << "Use the address based invocation method."; - if (DefaultAddrDefined) { - os << " The default address is 0x" << - std::hex << DefaultAddress << std::dec << "."; - } - } - - bool - checkArgs(Args &args) override - { - static const std::string prefix = "--addr"; - uint64_t addr_override; - - // If the first argument doesn't start with --addr... - if (!args.size() || args[0].substr(0, prefix.size()) != prefix) - return false; - - const std::string &arg = args.pop().substr(prefix.size()); - - // If there's more text in this argument... - if (arg.size()) { - // If it doesn't start with '=', it's malformed. - if (arg[0] != '=') - usage(); - // Attempt to extract an address after the '='. - Args temp_args({ arg.substr(1) }); - if (!parse_int_args(temp_args, &addr_override, 1)) - usage(); - // If we found an address, use it to override m5op_addr. - m5op_addr = addr_override; - return true; - } - // If an address override wasn't part of the first argument, check if - // it's the second argument. If not, then there's no override. - if (args.size() && parse_int_args(args, &addr_override, 1)) { - m5op_addr = addr_override; - return true; - } - // If the default address was not defined, an override is required. - if (!DefaultAddrDefined) - usage(); - - return true; - } - - void init() override { map_m5_mem(); } -} addr_call_type; - -} // anonymous namespace diff --git a/util/m5/src/call_type/addr.cc b/util/m5/src/call_type/addr.cc new file mode 100644 index 000000000..752d83125 --- /dev/null +++ b/util/m5/src/call_type/addr.cc @@ -0,0 +1,123 @@ +/* + * Copyright 2020 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. + */ + +#include + +#include "call_type.hh" +#include "m5_mmap.h" +#include "usage.hh" + +extern "C" +{ +#define M5OP(name, func) __typeof__(name) M5OP_MERGE_TOKENS(name, _addr); +M5OP_FOREACH +#undef M5OP +} + +namespace +{ + +DispatchTable addr_dispatch = { +#define M5OP(name, func) .name = &::M5OP_MERGE_TOKENS(name, _addr), +M5OP_FOREACH +#undef M5OP +}; + +#if defined(M5OP_ADDR) +const bool DefaultAddrDefined = true; +constexpr uint64_t DefaultAddress = M5OP_ADDR; +#else +const bool DefaultAddrDefined = false; +constexpr uint64_t DefaultAddress = 0; +#endif + +class AddrCallType : public CallType +{ + private: + public: + bool isDefault() const override { return CALL_TYPE_IS_DEFAULT; } + const DispatchTable &getDispatch() const override { return addr_dispatch; } + + void + printBrief(std::ostream &os) const override + { + os << "--addr " << (DefaultAddrDefined ? "[address override]" : + "
"); + } + + void + printDesc(std::ostream &os) const override + { + os << "Use the address based invocation method."; + if (DefaultAddrDefined) { + os << " The default address is 0x" << + std::hex << DefaultAddress << std::dec << "."; + } + } + + bool + checkArgs(Args &args) override + { + static const std::string prefix = "--addr"; + uint64_t addr_override; + + // If the first argument doesn't start with --addr... + if (!args.size() || args[0].substr(0, prefix.size()) != prefix) + return false; + + const std::string &arg = args.pop().substr(prefix.size()); + + // If there's more text in this argument... + if (arg.size()) { + // If it doesn't start with '=', it's malformed. + if (arg[0] != '=') + usage(); + // Attempt to extract an address after the '='. + Args temp_args({ arg.substr(1) }); + if (!parse_int_args(temp_args, &addr_override, 1)) + usage(); + // If we found an address, use it to override m5op_addr. + m5op_addr = addr_override; + return true; + } + // If an address override wasn't part of the first argument, check if + // it's the second argument. If not, then there's no override. + if (args.size() && parse_int_args(args, &addr_override, 1)) { + m5op_addr = addr_override; + return true; + } + // If the default address was not defined, an override is required. + if (!DefaultAddrDefined) + usage(); + + return true; + } + + void init() override { map_m5_mem(); } +} addr_call_type; + +} // anonymous namespace diff --git a/util/m5/src/call_type/inst.cc b/util/m5/src/call_type/inst.cc new file mode 100644 index 000000000..e19f6018b --- /dev/null +++ b/util/m5/src/call_type/inst.cc @@ -0,0 +1,65 @@ +/* + * Copyright 2020 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. + */ + +#include + +#include "call_type.hh" + +namespace +{ + +DispatchTable inst_dispatch = { +#define M5OP(name, func) .name = &::name, +M5OP_FOREACH +#undef M5OP +}; + +class InstCallType : public CallType +{ + public: + bool isDefault() const override { return CALL_TYPE_IS_DEFAULT; } + const DispatchTable &getDispatch() const override { return inst_dispatch; } + + bool + checkArgs(Args &args) override + { + if (args.size() && args[0] == "--inst") { + args.pop(); + return true; + } + return false; + } + + void printBrief(std::ostream &os) const override { os << "--inst"; } + void + printDesc(std::ostream &os) const override + { + os << "Use the instruction based invocation method."; + } +} inst_call_type; + +} // anonymous namespace diff --git a/util/m5/src/call_type/semi.cc b/util/m5/src/call_type/semi.cc new file mode 100644 index 000000000..25b830c2d --- /dev/null +++ b/util/m5/src/call_type/semi.cc @@ -0,0 +1,72 @@ +/* + * Copyright 2020 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. + */ + +#include + +#include "call_type.hh" + +extern "C" +{ +#define M5OP(name, func) __typeof__(name) M5OP_MERGE_TOKENS(name, _semi); +M5OP_FOREACH +#undef M5OP +} + +namespace +{ + +DispatchTable semi_dispatch = { +#define M5OP(name, func) .name = &::M5OP_MERGE_TOKENS(name, _semi), +M5OP_FOREACH +#undef M5OP +}; + +class SemiCallType : public CallType +{ + public: + bool isDefault() const override { return CALL_TYPE_IS_DEFAULT; } + const DispatchTable &getDispatch() const override { return semi_dispatch; } + + bool + checkArgs(Args &args) override + { + if (args.size() && args[0] == "--semi") { + args.pop(); + return true; + } + return false; + } + + void printBrief(std::ostream &os) const override { os << "--semi"; } + void + printDesc(std::ostream &os) const override + { + os << "Use the semi-hosting based invocation method."; + } +} semi_call_type; + +} // anonymous namespace diff --git a/util/m5/src/inst_call_type.cc b/util/m5/src/inst_call_type.cc deleted file mode 100644 index e19f6018b..000000000 --- a/util/m5/src/inst_call_type.cc +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright 2020 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. - */ - -#include - -#include "call_type.hh" - -namespace -{ - -DispatchTable inst_dispatch = { -#define M5OP(name, func) .name = &::name, -M5OP_FOREACH -#undef M5OP -}; - -class InstCallType : public CallType -{ - public: - bool isDefault() const override { return CALL_TYPE_IS_DEFAULT; } - const DispatchTable &getDispatch() const override { return inst_dispatch; } - - bool - checkArgs(Args &args) override - { - if (args.size() && args[0] == "--inst") { - args.pop(); - return true; - } - return false; - } - - void printBrief(std::ostream &os) const override { os << "--inst"; } - void - printDesc(std::ostream &os) const override - { - os << "Use the instruction based invocation method."; - } -} inst_call_type; - -} // anonymous namespace diff --git a/util/m5/src/semi_call_type.cc b/util/m5/src/semi_call_type.cc deleted file mode 100644 index 25b830c2d..000000000 --- a/util/m5/src/semi_call_type.cc +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright 2020 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. - */ - -#include - -#include "call_type.hh" - -extern "C" -{ -#define M5OP(name, func) __typeof__(name) M5OP_MERGE_TOKENS(name, _semi); -M5OP_FOREACH -#undef M5OP -} - -namespace -{ - -DispatchTable semi_dispatch = { -#define M5OP(name, func) .name = &::M5OP_MERGE_TOKENS(name, _semi), -M5OP_FOREACH -#undef M5OP -}; - -class SemiCallType : public CallType -{ - public: - bool isDefault() const override { return CALL_TYPE_IS_DEFAULT; } - const DispatchTable &getDispatch() const override { return semi_dispatch; } - - bool - checkArgs(Args &args) override - { - if (args.size() && args[0] == "--semi") { - args.pop(); - return true; - } - return false; - } - - void printBrief(std::ostream &os) const override { os << "--semi"; } - void - printDesc(std::ostream &os) const override - { - os << "Use the semi-hosting based invocation method."; - } -} semi_call_type; - -} // anonymous namespace