]>
Commit | Line | Data |
---|---|---|
f035d41b XL |
1 | #![allow(missing_docs)] |
2 | ||
3 | use crate::Format; | |
4 | use test_assembler::{Label, Section}; | |
5 | ||
6 | pub trait GimliSectionMethods { | |
7 | fn sleb(self, val: i64) -> Self; | |
8 | fn uleb(self, val: u64) -> Self; | |
9 | fn initial_length(self, format: Format, length: &Label, start: &Label) -> Self; | |
10 | fn word(self, size: u8, val: u64) -> Self; | |
11 | fn word_label(self, size: u8, val: &Label) -> Self; | |
12 | } | |
13 | ||
14 | impl GimliSectionMethods for Section { | |
15 | fn sleb(mut self, mut val: i64) -> Self { | |
16 | while val & !0x3f != 0 && val | 0x3f != -1 { | |
17 | self = self.D8(val as u8 | 0x80); | |
18 | val >>= 7; | |
19 | } | |
20 | self.D8(val as u8 & 0x7f) | |
21 | } | |
22 | ||
23 | fn uleb(mut self, mut val: u64) -> Self { | |
24 | while val & !0x7f != 0 { | |
25 | self = self.D8(val as u8 | 0x80); | |
26 | val >>= 7; | |
27 | } | |
28 | self.D8(val as u8) | |
29 | } | |
30 | ||
31 | fn initial_length(self, format: Format, length: &Label, start: &Label) -> Self { | |
32 | match format { | |
33 | Format::Dwarf32 => self.D32(length).mark(start), | |
34 | Format::Dwarf64 => self.D32(0xffff_ffff).D64(length).mark(start), | |
35 | } | |
36 | } | |
37 | ||
38 | fn word(self, size: u8, val: u64) -> Self { | |
39 | match size { | |
40 | 4 => self.D32(val as u32), | |
41 | 8 => self.D64(val), | |
42 | _ => panic!("unsupported word size"), | |
43 | } | |
44 | } | |
45 | ||
46 | fn word_label(self, size: u8, val: &Label) -> Self { | |
47 | match size { | |
48 | 4 => self.D32(val), | |
49 | 8 => self.D64(val), | |
50 | _ => panic!("unsupported word size"), | |
51 | } | |
52 | } | |
53 | } |