Debian Codegraph @

third_party/rust/objc/src/message/apple/x86.rs

raw
1 use std::any::{Any, TypeId};
2 use std::mem;
3
4 use runtime::Imp;
5
6 extern {
7 fn objc_msgSend();
8 fn objc_msgSend_fpret();
9 fn objc_msgSend_stret();
10
11 fn objc_msgSendSuper();
12 fn objc_msgSendSuper_stret();
13 }
14
15 pub fn msg_send_fn<R: Any>() -> Imp {
16 // Structures 1 or 2 bytes in size are placed in EAX.
17 // Structures 4 or 8 bytes in size are placed in: EAX and EDX.
18 // Structures of other sizes are placed at the address supplied by the caller.
19 // <https://developer.apple.com/library/mac/documentation/DeveloperTools/Conceptual/LowLevelABI/130-IA-32_Function_Calling_Conventions/IA32.html>
20
21 let type_id = TypeId::of::<R>();
22 let size = mem::size_of::<R>();
23 if type_id == TypeId::of::<f32>() ||
24 type_id == TypeId::of::<f64>() {
25 objc_msgSend_fpret
26 } else if size == 0 || size == 1 || size == 2 || size == 4 || size == 8 {
27 objc_msgSend
28 } else {
29 objc_msgSend_stret
30 }
31 }
32
33 pub fn msg_send_super_fn<R: Any>() -> Imp {
34 let size = mem::size_of::<R>();
35 if size == 0 || size == 1 || size == 2 || size == 4 || size == 8 {
36 objc_msgSendSuper
37 } else {
38 objc_msgSendSuper_stret
39 }
40 }