LCOV - code coverage report
Current view: top level - src/dwarf/types - base.rs (source / functions) Coverage Total Hit
Test: lief.lcov Lines: 0.0 % 37 0
Test Date: 2024-10-27:00:00:00 Functions: 0.0 % 9 0

            Line data    Source code
       1              : use lief_ffi as ffi;
       2              : 
       3              : use crate::common::FromFFI;
       4              : use std::marker::PhantomData;
       5              : use crate::dwarf::types::DwarfType;
       6              : 
       7              : /// This class wraps the `DW_TAG_base_type` type which can be used -- for
       8              : /// instance -- to represent integers or primitive types.
       9              : pub struct Base<'a> {
      10              :     ptr: cxx::UniquePtr<ffi::DWARF_types_Base>,
      11              :     _owner: PhantomData<&'a ()>,
      12              : }
      13              : 
      14              : 
      15              : #[allow(non_camel_case_types)]
      16            0 : #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
      17              : pub enum Encoding {
      18              :     NONE,
      19              : 
      20              :     /// Mirror `DW_ATE_signed`
      21              :     SIGNED,
      22              : 
      23              :     /// Mirror `DW_ATE_signed_char`
      24              :     SIGNED_CHAR,
      25              : 
      26              :     /// Mirror `DW_ATE_unsigned`
      27              :     UNSIGNED,
      28              : 
      29              :     /// Mirror `DW_ATE_unsigned_char`
      30              :     UNSIGNED_CHAR,
      31              : 
      32              :     /// Mirror `DW_ATE_float`
      33              :     FLOAT,
      34              : 
      35              :     /// Mirror `DW_ATE_boolean`
      36              :     BOOLEAN,
      37              : 
      38              :     /// Mirror `DW_ATE_address`
      39              :     ADDRESS,
      40              : 
      41              :     UNKNOWN(u32),
      42              : }
      43              : 
      44              : impl From<u32> for Encoding {
      45            0 :     fn from(value: u32) -> Self {
      46            0 :         match value {
      47            0 :             0x00000000 => Encoding::NONE,
      48            0 :             0x00000001 => Encoding::SIGNED,
      49            0 :             0x00000002 => Encoding::SIGNED_CHAR,
      50            0 :             0x00000003 => Encoding::UNSIGNED,
      51            0 :             0x00000004 => Encoding::UNSIGNED_CHAR,
      52            0 :             0x00000005 => Encoding::FLOAT,
      53            0 :             0x00000006 => Encoding::BOOLEAN,
      54            0 :             0x00000007 => Encoding::ADDRESS,
      55            0 :             _ => Encoding::UNKNOWN(value),
      56              : 
      57              :         }
      58            0 :     }
      59              : }
      60              : impl From<Encoding> for u32 {
      61            0 :     fn from(value: Encoding) -> u32 {
      62            0 :         match value {
      63            0 :             Encoding::NONE => 0x00000000,
      64            0 :             Encoding::SIGNED => 0x00000001,
      65            0 :             Encoding::SIGNED_CHAR => 0x00000002,
      66            0 :             Encoding::UNSIGNED => 0x00000003,
      67            0 :             Encoding::UNSIGNED_CHAR => 0x00000004,
      68            0 :             Encoding::FLOAT => 0x00000005,
      69            0 :             Encoding::BOOLEAN => 0x00000006,
      70            0 :             Encoding::ADDRESS => 0x00000007,
      71            0 :             Encoding::UNKNOWN(_) => 0,
      72              : 
      73              :         }
      74            0 :     }
      75              : }
      76              : 
      77              : impl FromFFI<ffi::DWARF_types_Base> for Base<'_> {
      78            0 :     fn from_ffi(cmd: cxx::UniquePtr<ffi::DWARF_types_Base>) -> Self {
      79            0 :         Self {
      80            0 :             ptr: cmd,
      81            0 :             _owner: PhantomData,
      82            0 :         }
      83            0 :     }
      84              : }
      85              : 
      86              : impl Base<'_> {
      87              :     /// Describe how the base type is encoded and should be interpreted
      88            0 :     pub fn encoding(&self) -> Encoding {
      89            0 :         Encoding::from(self.ptr.encoding())
      90            0 :     }
      91              : }
      92              : 
      93              : impl DwarfType for Base<'_> {
      94            0 :     fn get_base(&self) -> &ffi::DWARF_Type {
      95            0 :         self.ptr.as_ref().unwrap().as_ref()
      96            0 :     }
      97              : }
        

Generated by: LCOV version 2.1-1