linker: add link_relative()

This commit is contained in:
Michael Sippel 2024-05-12 04:20:45 +02:00
parent 949f354c22
commit 7efee58c4d
Signed by: senvas
GPG key ID: F96CF119C34B64A6

View file

@ -47,6 +47,20 @@ impl Linker {
Ok(bytecode) Ok(bytecode)
} }
pub fn link_relative(self, symbol: &String) -> Result<Vec<AssemblyWord>, LinkError> {
Ok(self.link_partial()?
.into_iter()
.map(|w| match w {
AssemblyWord::Symbol(LinkAddr::Absolute(addr)) =>
AssemblyWord::Symbol(LinkAddr::Relative {
symbol: symbol.clone(),
offset: addr
}),
w => w
})
.collect())
}
pub fn link_total(self) -> Result<Vec<VM_Word>, LinkError> { pub fn link_total(self) -> Result<Vec<VM_Word>, LinkError> {
self.link_partial()? self.link_partial()?
.into_iter() .into_iter()