[gem5-dev] Change in gem5/gem5[develop]: util: c++-ify the call type in the m5 utility.

2020-06-25 Thread Gabe Black (Gerrit) via gem5-dev
Gabe Black has submitted this change. (  
https://gem5-review.googlesource.com/c/public/gem5/+/27549 )


Change subject: util: c++-ify the call type in the m5 utility.
..

util: c++-ify the call type in the m5 utility.

Use a class to track call type information, and mostly avoid having to
use ifdefs to include or not include support for individual call types.

Change-Id: I731c99e67ea1c511d53431df3f77b4a959919a59
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/27549
Tested-by: kokoro 
Reviewed-by: Gabe Black 
Reviewed-by: Daniel Carvalho 
Maintainer: Gabe Black 
---
M util/m5/src/SConscript
M util/m5/src/addr_call_type.cc
D util/m5/src/addr_call_type.hh
M util/m5/src/call_type.cc
M util/m5/src/call_type.hh
M util/m5/src/commands.cc
M util/m5/src/commands.hh
M util/m5/src/inst_call_type.cc
D util/m5/src/inst_call_type.hh
M util/m5/src/m5.cc
M util/m5/src/semi_call_type.cc
D util/m5/src/semi_call_type.hh
M util/m5/src/usage.cc
13 files changed, 233 insertions(+), 262 deletions(-)

Approvals:
  Gabe Black: Looks good to me, approved; Looks good to me, approved
  Daniel Carvalho: Looks good to me, approved
  kokoro: Regressions pass



diff --git a/util/m5/src/SConscript b/util/m5/src/SConscript
index 0961f2f..176f4c2 100644
--- a/util/m5/src/SConscript
+++ b/util/m5/src/SConscript
@@ -51,13 +51,6 @@
 static_env = env.Clone()
 static_env.Append(LINKFLAGS=[ '-no-pie', '-static' ])

-for ct in all_call_types:
-static_env.Append(CXXFLAGS='-DENABLE_CT_%s=%d' %
-(ct.name, 1 if ct.enabled else 0))
-static_env.Append(CXXFLAGS='-DDEFAULT_CT_%s=%d' %
-(ct.name, 1 if ct.default else 0))
-static_env.Append(CXXFLAGS='-DDEFAULT_CALL_TYPE=%s' %  
default_call_type.name)

-
 #
 # The m5 library for use in other C/C++ programs.
 #
@@ -67,7 +60,12 @@
 #
 # The m5 stand alone command line utility.
 #
-ct_support = list([ File('%s_call_type.cc' % ct.name) for ct in call_types  
])

+ct_support = []
+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))
 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
index cdf5e5d..3a10ffa 100644
--- a/util/m5/src/addr_call_type.cc
+++ b/util/m5/src/addr_call_type.cc
@@ -27,10 +27,11 @@

 #include 

-#include "addr_call_type.hh"
-#include "args.hh"
 #include "m5_mmap.h"

+#include "call_type.hh"
+#include "usage.hh"
+
 extern "C"
 {
 #define M5OP(name, func) __typeof__(name) M5OP_MERGE_TOKENS(name, _addr);
@@ -38,54 +39,88 @@
 #undef M5OP
 }

-static DispatchTable addr_dispatch = {
+namespace
+{
+
+DispatchTable addr_dispatch = {
 #define M5OP(name, func) .name = &::M5OP_MERGE_TOKENS(name, _addr),
 M5OP_FOREACH
 #undef M5OP
 };

-int
-addr_call_type_detect(Args *args)
-{
-static const char *prefix = "--addr";
-const size_t prefix_len = strlen(prefix);
-uint64_t addr_override;
+#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

-// If the first argument starts with --addr...
-if (args->argc && memcmp(args->argv[0], prefix, prefix_len) == 0) {
-const char *argv0 = pop_arg(args);
+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 char *prefix = "--addr";
+const size_t prefix_len = strlen(prefix);
+uint64_t addr_override;
+
+// If the first argument doesn't start with --addr...
+if (!args.argc || memcmp(args.argv[0], prefix, prefix_len) != 0)
+return false;
+
+const char *argv0 = pop_arg(&args);

 // If there's more text in this argument...
 if (strlen(argv0) != prefix_len) {
 // If it doesn't start with '=', it's malformed.
 if (argv0[prefix_len] != '=')
-return -1;
+usage();
 // Attempt to ex

[gem5-dev] Change in gem5/gem5[develop]: util: c++-ify the call type in the m5 utility.

2020-04-07 Thread Gabe Black (Gerrit)
Gabe Black has uploaded this change for review. (  
https://gem5-review.googlesource.com/c/public/gem5/+/27549 )



Change subject: util: c++-ify the call type in the m5 utility.
..

util: c++-ify the call type in the m5 utility.

Use a class to track call type information, and mostly avoid having to
use ifdefs to include or not include support for individual call types.

Change-Id: I731c99e67ea1c511d53431df3f77b4a959919a59
---
M util/m5/src/SConscript
M util/m5/src/addr_call_type.cc
D util/m5/src/addr_call_type.hh
M util/m5/src/call_type.cc
M util/m5/src/call_type.hh
M util/m5/src/commands.cc
M util/m5/src/commands.hh
M util/m5/src/inst_call_type.cc
D util/m5/src/inst_call_type.hh
M util/m5/src/m5.cc
M util/m5/src/semi_call_type.cc
D util/m5/src/semi_call_type.hh
M util/m5/src/usage.cc
13 files changed, 233 insertions(+), 261 deletions(-)



diff --git a/util/m5/src/SConscript b/util/m5/src/SConscript
index 0961f2f..176f4c2 100644
--- a/util/m5/src/SConscript
+++ b/util/m5/src/SConscript
@@ -51,13 +51,6 @@
 static_env = env.Clone()
 static_env.Append(LINKFLAGS=[ '-no-pie', '-static' ])

-for ct in all_call_types:
-static_env.Append(CXXFLAGS='-DENABLE_CT_%s=%d' %
-(ct.name, 1 if ct.enabled else 0))
-static_env.Append(CXXFLAGS='-DDEFAULT_CT_%s=%d' %
-(ct.name, 1 if ct.default else 0))
-static_env.Append(CXXFLAGS='-DDEFAULT_CALL_TYPE=%s' %  
default_call_type.name)

-
 #
 # The m5 library for use in other C/C++ programs.
 #
@@ -67,7 +60,12 @@
 #
 # The m5 stand alone command line utility.
 #
-ct_support = list([ File('%s_call_type.cc' % ct.name) for ct in call_types  
])

+ct_support = []
+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))
 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
index af210c3..b1c4f8a 100644
--- a/util/m5/src/addr_call_type.cc
+++ b/util/m5/src/addr_call_type.cc
@@ -27,10 +27,11 @@

 #include 

-#include "addr_call_type.hh"
-#include "args.hh"
 #include "m5_mmap.h"

+#include "call_type.hh"
+#include "usage.hh"
+
 extern "C"
 {
 #define M5OP(name, func) __typeof__(name) M5OP_MERGE_TOKENS(name, _addr);
@@ -38,54 +39,88 @@
 #undef M5OP
 }

-static DispatchTable addr_dispatch = {
+namespace
+{
+
+DispatchTable addr_dispatch = {
 #define M5OP(name, func) .name = &::M5OP_MERGE_TOKENS(name, _addr),
 M5OP_FOREACH
 #undef M5OP
 };

-int
-addr_call_type_detect(Args *args)
-{
-static const char *prefix = "--addr";
-size_t prefix_len = strlen(prefix);
-uint64_t addr_override;
+#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

-// If the first argument starts with --addr...
-if (args->argc && memcmp(args->argv[0], prefix, prefix_len) == 0) {
-const char *argv0 = pop_arg(args);
+class AddrCallType : public CallType
+{
+  private:
+  public:
+bool isDefault() override { return CALL_TYPE_IS_DEFAULT; }
+const DispatchTable &getDispatch() override { return addr_dispatch; }
+
+void
+printBrief(std::ostream &os)
+{
+os << "--addr " << (DefaultAddrDefined ? "[address override]" :
+ "");
+}
+
+void
+printDesc(std::ostream &os)
+{
+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 char *prefix = "--addr";
+size_t prefix_len = strlen(prefix);
+uint64_t addr_override;
+
+// If the first argument doesn't start with --addr...
+if (!args.argc || memcmp(args.argv[0], prefix, prefix_len) != 0)
+return false;
+
+const char *argv0 = pop_arg(&args);

 // If there's more text in this argument...
 if (strlen(argv0) != prefix_len) {
 // If it doesn't start with '=', it's malformed.
 if (argv0[prefix_len] != '=')
-return -1;
+usage();
 // Attempt to extract an address after the '='.
 const char *temp_argv[] = { &argv0[prefix_len + 1] };
 Args temp_args = { 1, temp_argv };
 if (!parse_int_args(&temp_args, &addr_override, 1))
-return -1;
+usage();
 // If we found an address, use it to override m5op_addr.
 m5op_addr = addr_over