Lint: remove some warnings
This commit is contained in:
@ -2,35 +2,6 @@ use crate::Machine;
|
||||
use std::fs;
|
||||
use std::io::Read;
|
||||
|
||||
/// load a 32-bits binary file into the machine
|
||||
///
|
||||
/// ### Parameters
|
||||
///
|
||||
/// - **path** path of the file to load
|
||||
/// - **machine** the machine where the bin file will be loaded
|
||||
/// - **start_index** at which index of machine memory you want to start to load the program
|
||||
///
|
||||
/// Returns in a Result any io error
|
||||
pub fn load(path: &str, machine: &mut Machine, start_index: usize) -> Result<(), std::io::Error> {
|
||||
let mut file = fs::File::open(path)?;
|
||||
let mut instructions: Vec<u32> = Default::default();
|
||||
loop {
|
||||
let mut buf: [u8; 4] = [0; 4];
|
||||
let res = file.read(&mut buf)?;
|
||||
if res == 0 {
|
||||
break; // eof
|
||||
} else {
|
||||
instructions.push(u32::from_le_bytes(buf));
|
||||
}
|
||||
}
|
||||
for (i, inst) in instructions.iter().enumerate() {
|
||||
machine.write_memory(4, 4 * i + start_index, inst.to_owned() as u64);
|
||||
}
|
||||
// #[cfg(debug_assertions)]
|
||||
// println!("{:04x?}", instructions); // only print loaded program in debug build
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// The elf header defines principes aspects of the binary files, it's place at the start of the file
|
||||
/// see <https://en.wikipedia.org/wiki/Executable_and_Linkable_Format#File_header> for more informations
|
||||
pub struct ElfHeader {
|
||||
|
Reference in New Issue
Block a user