sim: Add a typetraits style mechanism to test for VarArgs.
authorGabe Black <gabeblack@google.com>
Tue, 17 Dec 2019 05:48:36 +0000 (21:48 -0800)
committerGabe Black <gabeblack@google.com>
Fri, 7 Feb 2020 07:36:39 +0000 (07:36 +0000)
This family of types can be cumbersome to check for when building
ABI rules. This struct template makes that a little easier.

Change-Id: Ic3a1b8424f8ca04564f8228365371b357f33276c
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/23750
Maintainer: Gabe Black <gabeblack@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Jason Lowe-Power <jason@lowepower.com>
src/sim/guest_abi.hh
src/sim/guest_abi.test.cc

index 5432af3f9219d86aba5c001a03d1656a2857eb37..9726c49db6134f029c83bf660c482a1c0fb427f0 100644 (file)
@@ -284,6 +284,12 @@ class VarArgs
     }
 };
 
+template <typename T>
+struct IsVarArgs : public std::false_type {};
+
+template <typename ...Types>
+struct IsVarArgs<VarArgs<Types...>> : public std::true_type {};
+
 template <typename ...Types>
 std::ostream &
 operator << (std::ostream &os, const VarArgs<Types...> &va)
index 506163ee65625af69632883e127df9538d2740de..bd444aa321462f32ed0353d774d83752792b7cc5 100644 (file)
@@ -362,3 +362,14 @@ TEST(GuestABI, dumpSimcall)
     std::string dump = dumpSimcall<TestABI_1D>("test", &tc, testIntVoid);
     EXPECT_EQ(dump, "test(0, 11, 2, 13, ...)");
 }
+
+TEST(GuestABI, isVarArgs)
+{
+    EXPECT_TRUE(GuestABI::IsVarArgs<GuestABI::VarArgs<int>>::value);
+    EXPECT_FALSE(GuestABI::IsVarArgs<int>::value);
+    EXPECT_FALSE(GuestABI::IsVarArgs<double>::value);
+    struct FooStruct {};
+    EXPECT_FALSE(GuestABI::IsVarArgs<FooStruct>::value);
+    union FooUnion {};
+    EXPECT_FALSE(GuestABI::IsVarArgs<FooUnion>::value);
+}