]>
Commit | Line | Data |
---|---|---|
dfeec247 | 1 | use rustc_span::symbol::{sym, Symbol}; |
416331ca | 2 | |
136023e0 | 3 | #[derive(Clone, Debug, Copy, HashStable_Generic)] |
416331ca XL |
4 | pub enum AllocatorKind { |
5 | Global, | |
60c5eb7d | 6 | Default, |
416331ca XL |
7 | } |
8 | ||
9 | impl AllocatorKind { | |
3dfed10e | 10 | pub fn fn_name(&self, base: Symbol) -> String { |
416331ca XL |
11 | match *self { |
12 | AllocatorKind::Global => format!("__rg_{}", base), | |
60c5eb7d | 13 | AllocatorKind::Default => format!("__rdl_{}", base), |
416331ca XL |
14 | } |
15 | } | |
16 | } | |
17 | ||
18 | pub enum AllocatorTy { | |
19 | Layout, | |
20 | Ptr, | |
21 | ResultPtr, | |
22 | Unit, | |
23 | Usize, | |
24 | } | |
25 | ||
26 | pub struct AllocatorMethod { | |
3dfed10e | 27 | pub name: Symbol, |
416331ca XL |
28 | pub inputs: &'static [AllocatorTy], |
29 | pub output: AllocatorTy, | |
30 | } | |
31 | ||
32 | pub static ALLOCATOR_METHODS: &[AllocatorMethod] = &[ | |
33 | AllocatorMethod { | |
3dfed10e | 34 | name: sym::alloc, |
416331ca XL |
35 | inputs: &[AllocatorTy::Layout], |
36 | output: AllocatorTy::ResultPtr, | |
37 | }, | |
38 | AllocatorMethod { | |
3dfed10e | 39 | name: sym::dealloc, |
416331ca XL |
40 | inputs: &[AllocatorTy::Ptr, AllocatorTy::Layout], |
41 | output: AllocatorTy::Unit, | |
42 | }, | |
43 | AllocatorMethod { | |
3dfed10e | 44 | name: sym::realloc, |
416331ca XL |
45 | inputs: &[AllocatorTy::Ptr, AllocatorTy::Layout, AllocatorTy::Usize], |
46 | output: AllocatorTy::ResultPtr, | |
47 | }, | |
48 | AllocatorMethod { | |
3dfed10e | 49 | name: sym::alloc_zeroed, |
416331ca XL |
50 | inputs: &[AllocatorTy::Layout], |
51 | output: AllocatorTy::ResultPtr, | |
52 | }, | |
53 | ]; |