1 use rustc_span::symbol::{sym, Symbol};
2
3 #[derive(Clone, Debug, Copy, Eq, PartialEq, HashStable_Generic)]
4 pub enum AllocatorKind {
5 Global,
6 Default,
7 }
8
global_fn_name(base: Symbol) -> String9 pub fn global_fn_name(base: Symbol) -> String {
10 format!("__rust_{base}")
11 }
12
default_fn_name(base: Symbol) -> String13 pub fn default_fn_name(base: Symbol) -> String {
14 format!("__rdl_{base}")
15 }
16
alloc_error_handler_name(alloc_error_handler_kind: AllocatorKind) -> &'static str17 pub fn alloc_error_handler_name(alloc_error_handler_kind: AllocatorKind) -> &'static str {
18 match alloc_error_handler_kind {
19 AllocatorKind::Global => "__rg_oom",
20 AllocatorKind::Default => "__rdl_oom",
21 }
22 }
23
24 pub const NO_ALLOC_SHIM_IS_UNSTABLE: &str = "__rust_no_alloc_shim_is_unstable";
25
26 pub enum AllocatorTy {
27 Layout,
28 Ptr,
29 ResultPtr,
30 Unit,
31 Usize,
32 }
33
34 pub struct AllocatorMethod {
35 pub name: Symbol,
36 pub inputs: &'static [AllocatorTy],
37 pub output: AllocatorTy,
38 }
39
40 pub static ALLOCATOR_METHODS: &[AllocatorMethod] = &[
41 AllocatorMethod {
42 name: sym::alloc,
43 inputs: &[AllocatorTy::Layout],
44 output: AllocatorTy::ResultPtr,
45 },
46 AllocatorMethod {
47 name: sym::dealloc,
48 inputs: &[AllocatorTy::Ptr, AllocatorTy::Layout],
49 output: AllocatorTy::Unit,
50 },
51 AllocatorMethod {
52 name: sym::realloc,
53 inputs: &[AllocatorTy::Ptr, AllocatorTy::Layout, AllocatorTy::Usize],
54 output: AllocatorTy::ResultPtr,
55 },
56 AllocatorMethod {
57 name: sym::alloc_zeroed,
58 inputs: &[AllocatorTy::Layout],
59 output: AllocatorTy::ResultPtr,
60 },
61 ];
62