mod elf;
mod instruction;
pub use elf::*;
pub use instruction::*;
use std::{collections::BTreeMap, fs::File, io::Read};
use crate::runtime::{Instruction, Program};
impl Program {
pub const fn new(instructions: Vec<Instruction>, pc_start: u32, pc_base: u32) -> Self {
Self {
instructions,
pc_start,
pc_base,
memory_image: BTreeMap::new(),
}
}
pub fn from(input: &[u8]) -> Self {
let elf = Elf::decode(input);
let instructions = transpile(&elf.instructions);
Program {
instructions,
pc_start: elf.pc_start,
pc_base: elf.pc_base,
memory_image: elf.memory_image,
}
}
pub fn from_elf(path: &str) -> Self {
let mut elf_code = Vec::new();
File::open(path)
.expect("failed to open input file")
.read_to_end(&mut elf_code)
.expect("failed to read from input file");
Program::from(&elf_code)
}
}