2019-12-31 20:15:40 +03:00
|
|
|
use rustc_span::symbol::{sym, Symbol};
|
2019-07-19 00:24:58 +03:00
|
|
|
|
2021-05-11 22:05:54 +02:00
|
|
|
#[derive(Clone, Debug, Copy, HashStable_Generic)]
|
2019-07-16 21:06:17 +03:00
|
|
|
pub enum AllocatorKind {
|
|
|
|
Global,
|
2019-11-24 14:37:46 +03:00
|
|
|
Default,
|
2019-07-16 21:06:17 +03:00
|
|
|
}
|
2017-06-03 14:54:08 -07:00
|
|
|
|
2019-07-16 21:06:17 +03:00
|
|
|
impl AllocatorKind {
|
2020-07-08 11:04:10 +10:00
|
|
|
pub fn fn_name(&self, base: Symbol) -> String {
|
2019-07-16 21:06:17 +03:00
|
|
|
match *self {
|
|
|
|
AllocatorKind::Global => format!("__rg_{}", base),
|
2019-11-24 14:37:46 +03:00
|
|
|
AllocatorKind::Default => format!("__rdl_{}", base),
|
2019-07-16 21:06:17 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-06-03 14:54:08 -07:00
|
|
|
|
2019-07-16 21:06:17 +03:00
|
|
|
pub enum AllocatorTy {
|
|
|
|
Layout,
|
|
|
|
Ptr,
|
|
|
|
ResultPtr,
|
|
|
|
Unit,
|
|
|
|
Usize,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct AllocatorMethod {
|
2020-07-08 11:04:10 +10:00
|
|
|
pub name: Symbol,
|
2019-07-16 21:06:17 +03:00
|
|
|
pub inputs: &'static [AllocatorTy],
|
|
|
|
pub output: AllocatorTy,
|
|
|
|
}
|
2017-06-03 14:54:08 -07:00
|
|
|
|
|
|
|
pub static ALLOCATOR_METHODS: &[AllocatorMethod] = &[
|
|
|
|
AllocatorMethod {
|
2020-07-08 11:04:10 +10:00
|
|
|
name: sym::alloc,
|
2017-06-03 14:54:08 -07:00
|
|
|
inputs: &[AllocatorTy::Layout],
|
|
|
|
output: AllocatorTy::ResultPtr,
|
|
|
|
},
|
|
|
|
AllocatorMethod {
|
2020-07-08 11:04:10 +10:00
|
|
|
name: sym::dealloc,
|
2017-06-03 14:54:08 -07:00
|
|
|
inputs: &[AllocatorTy::Ptr, AllocatorTy::Layout],
|
|
|
|
output: AllocatorTy::Unit,
|
|
|
|
},
|
|
|
|
AllocatorMethod {
|
2020-07-08 11:04:10 +10:00
|
|
|
name: sym::realloc,
|
2018-04-03 17:12:57 +02:00
|
|
|
inputs: &[AllocatorTy::Ptr, AllocatorTy::Layout, AllocatorTy::Usize],
|
2017-06-03 14:54:08 -07:00
|
|
|
output: AllocatorTy::ResultPtr,
|
|
|
|
},
|
|
|
|
AllocatorMethod {
|
2020-07-08 11:04:10 +10:00
|
|
|
name: sym::alloc_zeroed,
|
2017-06-03 14:54:08 -07:00
|
|
|
inputs: &[AllocatorTy::Layout],
|
|
|
|
output: AllocatorTy::ResultPtr,
|
|
|
|
},
|
|
|
|
];
|