summaryrefslogtreecommitdiff
path: root/vendor/gimli/src/test_util.rs
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2024-01-08 00:21:28 +0300
committerValentin Popov <valentin@popov.link>2024-01-08 00:21:28 +0300
commit1b6a04ca5504955c571d1c97504fb45ea0befee4 (patch)
tree7579f518b23313e8a9748a88ab6173d5e030b227 /vendor/gimli/src/test_util.rs
parent5ecd8cf2cba827454317368b68571df0d13d7842 (diff)
downloadfparkan-1b6a04ca5504955c571d1c97504fb45ea0befee4.tar.xz
fparkan-1b6a04ca5504955c571d1c97504fb45ea0befee4.zip
Initial vendor packages
Signed-off-by: Valentin Popov <valentin@popov.link>
Diffstat (limited to 'vendor/gimli/src/test_util.rs')
-rw-r--r--vendor/gimli/src/test_util.rs53
1 files changed, 53 insertions, 0 deletions
diff --git a/vendor/gimli/src/test_util.rs b/vendor/gimli/src/test_util.rs
new file mode 100644
index 0000000..706aaf9
--- /dev/null
+++ b/vendor/gimli/src/test_util.rs
@@ -0,0 +1,53 @@
+#![allow(missing_docs)]
+
+use crate::Format;
+use test_assembler::{Label, Section};
+
+pub trait GimliSectionMethods {
+ fn sleb(self, val: i64) -> Self;
+ fn uleb(self, val: u64) -> Self;
+ fn initial_length(self, format: Format, length: &Label, start: &Label) -> Self;
+ fn word(self, size: u8, val: u64) -> Self;
+ fn word_label(self, size: u8, val: &Label) -> Self;
+}
+
+impl GimliSectionMethods for Section {
+ fn sleb(mut self, mut val: i64) -> Self {
+ while val & !0x3f != 0 && val | 0x3f != -1 {
+ self = self.D8(val as u8 | 0x80);
+ val >>= 7;
+ }
+ self.D8(val as u8 & 0x7f)
+ }
+
+ fn uleb(mut self, mut val: u64) -> Self {
+ while val & !0x7f != 0 {
+ self = self.D8(val as u8 | 0x80);
+ val >>= 7;
+ }
+ self.D8(val as u8)
+ }
+
+ fn initial_length(self, format: Format, length: &Label, start: &Label) -> Self {
+ match format {
+ Format::Dwarf32 => self.D32(length).mark(start),
+ Format::Dwarf64 => self.D32(0xffff_ffff).D64(length).mark(start),
+ }
+ }
+
+ fn word(self, size: u8, val: u64) -> Self {
+ match size {
+ 4 => self.D32(val as u32),
+ 8 => self.D64(val),
+ _ => panic!("unsupported word size"),
+ }
+ }
+
+ fn word_label(self, size: u8, val: &Label) -> Self {
+ match size {
+ 4 => self.D32(val),
+ 8 => self.D64(val),
+ _ => panic!("unsupported word size"),
+ }
+ }
+}