use crate::{
SRC_C, SRC_IMM, SRC_IND, SRC_MEM, SRC_REG, SRC_STEP, STORE_IND, STORE_MEM, STORE_NONE,
STORE_REG,
};
pub fn convert_vector(input: &[u8]) -> Vec<u16> {
if (input.len() & 0x01) != 0 {
panic!("convert_vector() found input length={} not a multiple of 2", input.len());
}
input.chunks_exact(2).map(|chunk| u16::from_le_bytes(chunk.try_into().unwrap())).collect()
}
pub fn source_to_str(source: u64) -> &'static str {
match source {
SRC_C => "SRC_C",
SRC_REG => "SRC_REG",
SRC_MEM => "SRC_MEM",
SRC_IMM => "SRC_IMM",
SRC_STEP => "SRC_STEP",
SRC_IND => "SRC_IND",
_ => panic!("source_to_str() unknown source({source})"),
}
}
pub fn store_to_str(store: u64) -> &'static str {
match store {
STORE_NONE => "STORE_NONE",
STORE_MEM => "STORE_MEM",
STORE_REG => "STORE_REG",
STORE_IND => "STORE_IND",
_ => panic!("store_to_str() unknown store({store})"),
}
}
pub fn is_elf_file(file_data: &[u8]) -> std::io::Result<bool> {
if file_data.len() < 4 {
return Err(std::io::Error::new(
std::io::ErrorKind::InvalidData,
"File data is too short to be a valid ELF file",
));
}
Ok(file_data[0..4] == [0x7F, b'E', b'L', b'F'])
}