Debian Codegraph @

third_party/rust/macho-unwind-info/src/opcodes/bitfield.rs

raw
1 use crate::num_display::BinNum;
2 use std::fmt::Debug;
3
4 pub struct OpcodeBitfield(pub u32);
5
6 impl OpcodeBitfield {
7 pub fn new(value: u32) -> Self {
8 Self(value)
9 }
10
11 /// Whether this instruction is the start of a function.
12 pub fn is_function_start(&self) -> bool {
13 self.0 >> 31 == 1
14 }
15
16 /// Whether there is an lsda entry for this instruction.
17 pub fn has_lsda(&self) -> bool {
18 (self.0 >> 30) & 0b1 == 1
19 }
20
21 /// An index into the global personalities array
22 /// (TODO: ignore if has_lsda() == false?)
23 pub fn personality_index(&self) -> u8 {
24 ((self.0 >> 28) & 0b11) as u8
25 }
26
27 /// The architecture-specific kind of opcode this is, specifying how to
28 /// interpret the remaining 24 bits of the opcode.
29 pub fn kind(&self) -> u8 {
30 ((self.0 >> 24) & 0b1111) as u8
31 }
32
33 /// The architecture-specific remaining 24 bits.
34 pub fn specific_bits(&self) -> u32 {
35 self.0 & 0xffffff
36 }
37 }
38
39 impl From<u32> for OpcodeBitfield {
40 fn from(opcode: u32) -> OpcodeBitfield {
41 OpcodeBitfield::new(opcode)
42 }
43 }
44
45 impl Debug for OpcodeBitfield {
46 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
47 f.debug_struct("Opcode")
48 .field("kind", &self.kind())
49 .field("is_function_start", &self.is_function_start())
50 .field("has_lsda", &self.has_lsda())
51 .field("personality_index", &self.personality_index())
52 .field("specific_bits", &BinNum(self.specific_bits()))
53 .finish()
54 }
55 }