/rust/registry/src/index.crates.io-6f17d22bba15001f/cranelift-codegen-0.91.1/src/ir/heap.rs
Line | Count | Source (jump to first uncovered line) |
1 | | //! Heaps. |
2 | | |
3 | | use crate::ir::immediates::Uimm64; |
4 | | use crate::ir::{GlobalValue, Type}; |
5 | | use core::fmt; |
6 | | |
7 | | #[cfg(feature = "enable-serde")] |
8 | | use serde::{Deserialize, Serialize}; |
9 | | |
10 | | /// Information about a heap declaration. |
11 | | #[derive(Clone, PartialEq, Hash)] |
12 | | #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] |
13 | | pub struct HeapData { |
14 | | /// The address of the start of the heap's storage. |
15 | | pub base: GlobalValue, |
16 | | |
17 | | /// Guaranteed minimum heap size in bytes. Heap accesses before `min_size` don't need bounds |
18 | | /// checking. |
19 | | pub min_size: Uimm64, |
20 | | |
21 | | /// Size in bytes of the offset-guard pages following the heap. |
22 | | pub offset_guard_size: Uimm64, |
23 | | |
24 | | /// Heap style, with additional style-specific info. |
25 | | pub style: HeapStyle, |
26 | | |
27 | | /// The index type for the heap. |
28 | | pub index_type: Type, |
29 | | } |
30 | | |
31 | | /// Style of heap including style-specific information. |
32 | | #[derive(Clone, PartialEq, Hash)] |
33 | | #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] |
34 | | pub enum HeapStyle { |
35 | | /// A dynamic heap can be relocated to a different base address when it is grown. |
36 | | Dynamic { |
37 | | /// Global value providing the current bound of the heap in bytes. |
38 | | bound_gv: GlobalValue, |
39 | | }, |
40 | | |
41 | | /// A static heap has a fixed base address and a number of not-yet-allocated pages before the |
42 | | /// offset-guard pages. |
43 | | Static { |
44 | | /// Heap bound in bytes. The offset-guard pages are allocated after the bound. |
45 | | bound: Uimm64, |
46 | | }, |
47 | | } |
48 | | |
49 | | impl fmt::Display for HeapData { |
50 | 0 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
51 | 0 | f.write_str(match self.style { |
52 | 0 | HeapStyle::Dynamic { .. } => "dynamic", |
53 | 0 | HeapStyle::Static { .. } => "static", |
54 | 0 | })?; |
55 | | |
56 | 0 | write!(f, " {}, min {}", self.base, self.min_size)?; |
57 | 0 | match self.style { |
58 | 0 | HeapStyle::Dynamic { bound_gv } => write!(f, ", bound {}", bound_gv)?, |
59 | 0 | HeapStyle::Static { bound } => write!(f, ", bound {}", bound)?, |
60 | | } |
61 | 0 | write!( |
62 | 0 | f, |
63 | 0 | ", offset_guard {}, index_type {}", |
64 | 0 | self.offset_guard_size, self.index_type |
65 | 0 | ) |
66 | 0 | } |
67 | | } |