From 26454e8072e607d54ac67c42b33355d7c94d6d60 Mon Sep 17 00:00:00 2001 From: Gabe Black Date: Fri, 27 Mar 2020 01:52:27 -0700 Subject: [PATCH] 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 --- util/m5/src/addr_call_type.c | 57 ++++++++++++++++++++++++++++++++++++ util/m5/src/addr_call_type.h | 36 +++++++++++++++++++++++ util/m5/src/call_type.h | 46 +++++++++++++++++++++++++++++ util/m5/src/inst_call_type.c | 53 +++++++++++++++++++++++++++++++++ util/m5/src/inst_call_type.h | 36 +++++++++++++++++++++++ util/m5/src/semi_call_type.c | 53 +++++++++++++++++++++++++++++++++ util/m5/src/semi_call_type.h | 36 +++++++++++++++++++++++ 7 files changed, 317 insertions(+) create mode 100644 util/m5/src/addr_call_type.c create mode 100644 util/m5/src/addr_call_type.h create mode 100644 util/m5/src/call_type.h create mode 100644 util/m5/src/inst_call_type.c create mode 100644 util/m5/src/inst_call_type.h create mode 100644 util/m5/src/semi_call_type.c create mode 100644 util/m5/src/semi_call_type.h diff --git a/util/m5/src/addr_call_type.c b/util/m5/src/addr_call_type.c new file mode 100644 index 000000000..d91d2ec66 --- /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 = &M5OP_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 &addr_dispatch; +} diff --git a/util/m5/src/addr_call_type.h b/util/m5/src/addr_call_type.h new file mode 100644 index 000000000..d1fbfa6e8 --- /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, + * 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 __ADDR_CALL_TYPE_H__ +#define __ADDR_CALL_TYPE_H__ + +#include "dispatch_table.h" + +int addr_call_type_detect(int *argc, char **argv[]); +DispatchTable *addr_call_type_init(); + +#endif // __ADDR_CALL_TYPE_H__ diff --git a/util/m5/src/call_type.h b/util/m5/src/call_type.h new file mode 100644 index 000000000..17b1165bc --- /dev/null +++ b/util/m5/src/call_type.h @@ -0,0 +1,46 @@ +/* + * 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. + */ + +#ifndef __CALL_TYPE_H__ +#define __CALL_TYPE_H__ + +#include "dispatch_table.h" + +#if ENABLE_CT_addr +#include "addr_call_type.h" +#endif +#if ENABLE_CT_inst +#include "inst_call_type.h" +#endif +#if ENABLE_CT_semi +#include "semi_call_type.h" +#endif + +#define default_call_type_init() \ + M5OP_MERGE_TOKENS(DEFAULT_CALL_TYPE, _call_type_init()) + +#endif // __CALL_TYPE_H__ diff --git a/util/m5/src/inst_call_type.c b/util/m5/src/inst_call_type.c new file mode 100644 index 000000000..f4821fca6 --- /dev/null +++ b/util/m5/src/inst_call_type.c @@ -0,0 +1,53 @@ +/* + * 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 "inst_call_type.h" + +static DispatchTable inst_dispatch = { +#define M5OP(name, func) .name = &name, +M5OP_FOREACH +#undef M5OP +}; + +int +inst_call_type_detect(int *argc, char **argv[]) +{ + if (*argc > 0 && strcmp((*argv)[0], "--inst") == 0) { + (*argc)--; + (*argv)++; + return 1; + } + return 0; +} + +DispatchTable * +inst_call_type_init() +{ + return &inst_dispatch; +} diff --git a/util/m5/src/inst_call_type.h b/util/m5/src/inst_call_type.h new file mode 100644 index 000000000..a20aee5de --- /dev/null +++ b/util/m5/src/inst_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, + * 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 __INST_CALL_TYPE_H__ +#define __INST_CALL_TYPE_H__ + +#include "dispatch_table.h" + +int inst_call_type_detect(int *argc, char **argv[]); +DispatchTable *inst_call_type_init(); + +#endif // __INST_CALL_TYPE_H__ diff --git a/util/m5/src/semi_call_type.c b/util/m5/src/semi_call_type.c new file mode 100644 index 000000000..012d63755 --- /dev/null +++ b/util/m5/src/semi_call_type.c @@ -0,0 +1,53 @@ +/* + * 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 "semi_call_type.h" + +static DispatchTable semi_dispatch = { +#define M5OP(name, func) .name = &M5OP_MERGE_TOKENS(name, _semi), +M5OP_FOREACH +#undef M5OP +}; + +int +semi_call_type_detect(int *argc, char **argv[]) +{ + if (*argc > 0 && strcmp((*argv)[0], "--semi") == 0) { + (*argc)--; + (*argv)++; + return 1; + } + return 0; +} + +DispatchTable * +semi_call_type_init() +{ + return &semi_dispatch; +} diff --git a/util/m5/src/semi_call_type.h b/util/m5/src/semi_call_type.h new file mode 100644 index 000000000..2f8f9c8ba --- /dev/null +++ b/util/m5/src/semi_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, + * 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 __SEMI_CALL_TYPE_H__ +#define __SEMI_CALL_TYPE_H__ + +#include "dispatch_table.h" + +int semi_call_type_detect(int *argc, char **argv[]); +DispatchTable *semi_call_type_init(); + +#endif // __SEMI_CALL_TYPE_H__ -- 2.30.2