[gem5-dev] Change in gem5/gem5[develop]: util: Add an abstraction layer for call types in the m5 utility.
Gabe Black has submitted this change. ( https://gem5-review.googlesource.com/c/public/gem5/+/27241 ) Change subject: util: Add an abstraction layer for call types in the m5 utility. .. util: Add an abstraction layer for call types in the m5 utility. These make the calling code in m5.c a little bit more generic. Each call type will have a function to check the arguments and see if that type is being requested and/or has any additional options set in the arguments. If so, those are processed, and argc and argv are adjusted. Then another function returns the appropriate dispatch table to use for that invocation scheme. This is behind a function instead of, for instance, a global variable because it gives the call type a little bit more control over what's happening, for instance if it would use different implementations in slightly different circumstances. Change-Id: I661cf202ec657466496767cbdf331fe27995ab26 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/27241 Maintainer: Gabe Black Tested-by: kokoro Reviewed-by: Bobby R. Bruce --- A util/m5/src/addr_call_type.c A util/m5/src/addr_call_type.h A util/m5/src/call_type.h A util/m5/src/inst_call_type.c A util/m5/src/inst_call_type.h A util/m5/src/semi_call_type.c A util/m5/src/semi_call_type.h 7 files changed, 317 insertions(+), 0 deletions(-) Approvals: Bobby R. Bruce: Looks good to me, approved Gabe Black: Looks good to me, approved kokoro: Regressions pass diff --git a/util/m5/src/addr_call_type.c b/util/m5/src/addr_call_type.c new file mode 100644 index 000..d91d2ec --- /dev/null +++ b/util/m5/src/addr_call_type.c @@ -0,0 +1,57 @@ +/* + * 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 "addr_call_type.h" + +#define M5OP(name, func) __typeof__(name) M5OP_MERGE_TOKENS(name, _addr); +M5OP_FOREACH +#undef M5OP + +static DispatchTable addr_dispatch = { +#define M5OP(name, func) .name = _MERGE_TOKENS(name, _addr), +M5OP_FOREACH +#undef M5OP +}; + +int +addr_call_type_detect(int *argc, char **argv[]) +{ +if (*argc > 0 && strcmp((*argv)[0], "--addr") == 0) { +(*argc)--; +(*argv)++; +return 1; +} +return 0; +} + +DispatchTable * +addr_call_type_init() +{ +return _dispatch; +} diff --git a/util/m5/src/addr_call_type.h b/util/m5/src/addr_call_type.h new file mode 100644 index 000..d1fbfa6 --- /dev/null +++ b/util/m5/src/addr_call_type.h @@ -0,0 +1,36 @@ +/* + * 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
[gem5-dev] Change in gem5/gem5[develop]: util: Add an abstraction layer for call types in the m5 utility.
Gabe Black has uploaded this change for review. ( https://gem5-review.googlesource.com/c/public/gem5/+/27241 ) Change subject: util: Add an abstraction layer for call types in the m5 utility. .. util: Add an abstraction layer for call types in the m5 utility. These make the calling code in m5.c a little bit more generic. Each call type will have a function to check the arguments and see if that type is being requested and/or has any additional options set in the arguments. If so, those are processed, and argc and argv are adjusted. Then another function returns the appropriate dispatch table to use for that invocation scheme. This is behind a function instead of, for instance, a global variable because it gives the call type a little bit more control over what's happening, for instance if it would use different implementations in slightly different circumstances. Change-Id: I661cf202ec657466496767cbdf331fe27995ab26 --- A util/m5/src/addr_call_type.c A util/m5/src/addr_call_type.h A util/m5/src/call_type.h A util/m5/src/inst_call_type.c A util/m5/src/inst_call_type.h A util/m5/src/semi_call_type.c A util/m5/src/semi_call_type.h 7 files changed, 317 insertions(+), 0 deletions(-) diff --git a/util/m5/src/addr_call_type.c b/util/m5/src/addr_call_type.c new file mode 100644 index 000..d91d2ec --- /dev/null +++ b/util/m5/src/addr_call_type.c @@ -0,0 +1,57 @@ +/* + * 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 "addr_call_type.h" + +#define M5OP(name, func) __typeof__(name) M5OP_MERGE_TOKENS(name, _addr); +M5OP_FOREACH +#undef M5OP + +static DispatchTable addr_dispatch = { +#define M5OP(name, func) .name = _MERGE_TOKENS(name, _addr), +M5OP_FOREACH +#undef M5OP +}; + +int +addr_call_type_detect(int *argc, char **argv[]) +{ +if (*argc > 0 && strcmp((*argv)[0], "--addr") == 0) { +(*argc)--; +(*argv)++; +return 1; +} +return 0; +} + +DispatchTable * +addr_call_type_init() +{ +return _dispatch; +} diff --git a/util/m5/src/addr_call_type.h b/util/m5/src/addr_call_type.h new file mode 100644 index 000..d1fbfa6 --- /dev/null +++ b/util/m5/src/addr_call_type.h @@ -0,0 +1,36 @@ +/* + * 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, +