sim: Add a typetraits style mechanism to test for VarArgs.

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>
This commit is contained in:
Gabe Black
2019-12-16 21:48:36 -08:00
parent 4d039064b0
commit 206aa5b280
2 changed files with 17 additions and 0 deletions

View 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)

View 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);
}