You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
967 B
Rust

use std::fmt::Display;
use crate::{
common::{Output, Relocatable},
error::Error,
};
pub struct Linker<'data> {
relocatables: Vec<Box<dyn Relocatable + 'data>>,
}
impl<'data> Linker<'data> {
pub fn new(relocatables: Vec<Box<dyn Relocatable + 'data>>) -> Self {
Self { relocatables }
}
pub fn add_relocatable(&mut self, relocatable: Box<dyn Relocatable + 'data>) {
self.relocatables.push(relocatable);
}
pub fn link(&'data self, output: &mut dyn Output<'data>) -> Result<u64, Error> {
for r in self.relocatables.iter() {
for s in r.sections() {
output.append_section(s?)?;
}
}
Ok(0)
}
}
impl Display for Linker<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
writeln!(f, "===Relocatables===")?;
for r in self.relocatables.iter() {
write!(f, "{}", r)?;
}
Ok(())
}
}