From d75066545afdc9b5d0a52bd2518e43f683c671a5 Mon Sep 17 00:00:00 2001 From: Josh Ferrell Date: Thu, 13 Jun 2024 14:13:11 -0400 Subject: Apply stack variables from DWARF --- rust/src/types.rs | 61 +++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 44 insertions(+), 17 deletions(-) (limited to 'rust/src/types.rs') diff --git a/rust/src/types.rs b/rust/src/types.rs index b42c7039..9b2271d5 100644 --- a/rust/src/types.rs +++ b/rust/src/types.rs @@ -181,6 +181,20 @@ impl Display for Conf { } } +impl PartialEq for Conf { + fn eq(&self, other: &Self) -> bool { + self.contents.eq(&other.contents) + } +} + +impl Eq for Conf {} + +impl Hash for Conf { + fn hash(&self, state: &mut H) { + self.contents.hash(state); + } +} + impl<'a, T> From<&'a Conf> for Conf<&'a T> { fn from(c: &'a Conf) -> Self { Conf::new(&c.contents, c.confidence) @@ -1500,21 +1514,40 @@ unsafe impl CoreArrayProviderInner for Array { /////////////// // NamedVariable +#[derive(Clone, Debug, Hash, Eq, PartialEq)] pub struct NamedTypedVariable { - var: BNVariable, - auto_defined: bool, - type_confidence: u8, - name: *mut c_char, - ty: *mut BNType, + pub name: String, + pub ty: Conf>, + pub var: Variable, + pub auto_defined: bool, } impl NamedTypedVariable { + + pub fn new(var: Variable, name: String, ty: Conf>, auto_defined: bool) -> Self { + Self { + name, + ty, + var, + auto_defined, + } + } + + pub(crate) unsafe fn from_raw(var: &BNVariableNameAndType) -> Self { + Self { + var: Variable::from_raw(var.var), + auto_defined: var.autoDefined, + name: CStr::from_ptr(var.name).to_str().unwrap().to_string(), + ty: Conf::new(Type::ref_from_raw(var.type_), var.typeConfidence) + } + } + pub fn name(&self) -> &str { - unsafe { CStr::from_ptr(self.name).to_str().unwrap() } + &self.name } pub fn var(&self) -> Variable { - unsafe { Variable::from_raw(self.var) } + self.var } pub fn auto_defined(&self) -> bool { @@ -1522,18 +1555,18 @@ impl NamedTypedVariable { } pub fn type_confidence(&self) -> u8 { - self.type_confidence + self.ty.confidence } pub fn var_type(&self) -> Ref { - unsafe { Ref::new(Type::from_raw(self.ty)) } + self.ty.contents.clone() } } impl CoreArrayProvider for NamedTypedVariable { type Raw = BNVariableNameAndType; type Context = (); - type Wrapped<'a> = ManuallyDrop; + type Wrapped<'a> = Guard<'a, NamedTypedVariable>; } unsafe impl CoreArrayProviderInner for NamedTypedVariable { @@ -1541,13 +1574,7 @@ unsafe impl CoreArrayProviderInner for NamedTypedVariable { BNFreeVariableNameAndTypeList(raw, count) } unsafe fn wrap_raw<'a>(raw: &'a Self::Raw, _context: &'a Self::Context) -> Self::Wrapped<'a> { - ManuallyDrop::new(NamedTypedVariable { - var: raw.var, - ty: raw.type_, - name: raw.name, - auto_defined: raw.autoDefined, - type_confidence: raw.typeConfidence, - }) + unsafe { Guard::new(NamedTypedVariable::from_raw(raw), raw) } } } -- cgit v1.3.1