[vm/ffi] Cleanup FFI class_id methods

Moved to class_id.h and made all implementations with multiple matches
work with the FFI CLASS_LIST macros.

TEST=tests/{ffi,ffi_2}/*_test.dart
TEST=runtime/vm/compiler/ffi/*_test.cc

Change-Id: Ie6d50cd3b555647692e8b629eca6573828b88afa
Cq-Include-Trybots: luci.dart.try:vm-precomp-ffi-qemu-linux-release-arm-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/172963
Reviewed-by: Clement Skau <cskau@google.com>
Commit-Queue: Daco Harkes <dacoharkes@google.com>
This commit is contained in:
Daco Harkes
2020-11-19 13:29:09 +00:00
committed by commit-bot@chromium.org
parent b52113314b
commit dc5f88a24c
2 changed files with 25 additions and 29 deletions
+23 -15
View File
@@ -352,21 +352,29 @@ inline bool IsFfiNativeTypeTypeClassId(intptr_t index) {
}
inline bool IsFfiTypeClassId(intptr_t index) {
// Make sure this is updated when new Ffi types are added.
COMPILE_ASSERT(kFfiNativeFunctionCid == kFfiPointerCid + 1 &&
kFfiInt8Cid == kFfiPointerCid + 2 &&
kFfiInt16Cid == kFfiPointerCid + 3 &&
kFfiInt32Cid == kFfiPointerCid + 4 &&
kFfiInt64Cid == kFfiPointerCid + 5 &&
kFfiUint8Cid == kFfiPointerCid + 6 &&
kFfiUint16Cid == kFfiPointerCid + 7 &&
kFfiUint32Cid == kFfiPointerCid + 8 &&
kFfiUint64Cid == kFfiPointerCid + 9 &&
kFfiIntPtrCid == kFfiPointerCid + 10 &&
kFfiFloatCid == kFfiPointerCid + 11 &&
kFfiDoubleCid == kFfiPointerCid + 12 &&
kFfiVoidCid == kFfiPointerCid + 13);
return (index >= kFfiPointerCid && index <= kFfiVoidCid);
switch (index) {
case kFfiPointerCid:
case kFfiNativeFunctionCid:
#define CASE_FFI_CID(name) case kFfi##name##Cid:
CLASS_LIST_FFI_TYPE_MARKER(CASE_FFI_CID)
#undef CASE_FFI_CID
return true;
default:
return false;
}
UNREACHABLE();
}
inline bool IsFfiPredefinedClassId(classid_t class_id) {
switch (class_id) {
#define CASE_FFI_CID(name) case kFfi##name##Cid:
CLASS_LIST_FFI(CASE_FFI_CID)
#undef CASE_FFI_CID
return true;
default:
return false;
}
UNREACHABLE();
}
inline bool IsFfiTypeIntClassId(intptr_t index) {
+2 -14
View File
@@ -337,20 +337,8 @@ static PrimitiveType TypeRepresentation(classid_t class_id) {
}
}
static bool IsPredefinedFfiCid(classid_t class_id) {
switch (class_id) {
#define CASE_FFI_CID_TRUE(name) \
case kFfi##name##Cid: \
return true;
CLASS_LIST_FFI(CASE_FFI_CID_TRUE)
default:
return false;
}
UNREACHABLE();
}
NativeType& NativeType::FromTypedDataClassId(Zone* zone, classid_t class_id) {
ASSERT(IsPredefinedFfiCid(class_id));
ASSERT(IsFfiPredefinedClassId(class_id));
const auto fundamental_rep = TypeRepresentation(class_id);
return *new (zone) NativePrimitiveType(fundamental_rep);
}
@@ -358,7 +346,7 @@ NativeType& NativeType::FromTypedDataClassId(Zone* zone, classid_t class_id) {
#if !defined(FFI_UNIT_TESTS)
NativeType& NativeType::FromAbstractType(Zone* zone, const AbstractType& type) {
const classid_t class_id = type.type_class_id();
if (IsPredefinedFfiCid(class_id)) {
if (IsFfiPredefinedClassId(class_id)) {
return NativeType::FromTypedDataClassId(zone, class_id);
}