1 | // Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file |
---|---|
2 | // for details. All rights reserved. Use of this source code is governed by a |
3 | // BSD-style license that can be found in the LICENSE file. |
4 | |
5 | #include "vm/compiler/ffi/recognized_method.h" |
6 | |
7 | #include "vm/symbols.h" |
8 | |
9 | namespace dart { |
10 | |
11 | namespace compiler { |
12 | |
13 | namespace ffi { |
14 | |
15 | classid_t ElementTypedDataCid(classid_t class_id) { |
16 | ASSERT(class_id >= kFfiPointerCid); |
17 | ASSERT(class_id < kFfiVoidCid); |
18 | ASSERT(class_id != kFfiNativeFunctionCid); |
19 | switch (class_id) { |
20 | case kFfiInt8Cid: |
21 | return kTypedDataInt8ArrayCid; |
22 | case kFfiUint8Cid: |
23 | return kTypedDataUint8ArrayCid; |
24 | case kFfiInt16Cid: |
25 | return kTypedDataInt16ArrayCid; |
26 | case kFfiUint16Cid: |
27 | return kTypedDataUint16ArrayCid; |
28 | case kFfiInt32Cid: |
29 | return kTypedDataInt32ArrayCid; |
30 | case kFfiUint32Cid: |
31 | return kTypedDataUint32ArrayCid; |
32 | case kFfiInt64Cid: |
33 | return kTypedDataInt64ArrayCid; |
34 | case kFfiUint64Cid: |
35 | return kTypedDataUint64ArrayCid; |
36 | case kFfiIntPtrCid: |
37 | return target::kWordSize == 4 ? kTypedDataInt32ArrayCid |
38 | : kTypedDataInt64ArrayCid; |
39 | case kFfiPointerCid: |
40 | return target::kWordSize == 4 ? kTypedDataUint32ArrayCid |
41 | : kTypedDataUint64ArrayCid; |
42 | case kFfiFloatCid: |
43 | return kTypedDataFloat32ArrayCid; |
44 | case kFfiDoubleCid: |
45 | return kTypedDataFloat64ArrayCid; |
46 | default: |
47 | UNREACHABLE(); |
48 | } |
49 | } |
50 | |
51 | classid_t RecognizedMethodTypeArgCid(MethodRecognizer::Kind kind) { |
52 | switch (kind) { |
53 | #define LOAD_STORE(type) \ |
54 | case MethodRecognizer::kFfiLoad##type: \ |
55 | case MethodRecognizer::kFfiStore##type: \ |
56 | return kFfi##type##Cid; |
57 | CLASS_LIST_FFI_NUMERIC(LOAD_STORE) |
58 | LOAD_STORE(Pointer) |
59 | #undef LOAD_STORE |
60 | default: |
61 | UNREACHABLE(); |
62 | } |
63 | } |
64 | |
65 | } // namespace ffi |
66 | |
67 | } // namespace compiler |
68 | |
69 | } // namespace dart |
70 |