mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 23:31:12 +00:00
Add tail_call to ASM trait
This commit is contained in:
parent
595c704e88
commit
2909c06e72
3 changed files with 17 additions and 3 deletions
|
@ -315,6 +315,13 @@ impl Assembler<AArch64GeneralReg, AArch64FloatReg> for AArch64Assembler {
|
||||||
fn jmp_imm32(_buf: &mut Vec<'_, u8>, _offset: i32) -> usize {
|
fn jmp_imm32(_buf: &mut Vec<'_, u8>, _offset: i32) -> usize {
|
||||||
unimplemented!("jump instructions not yet implemented for AArch64");
|
unimplemented!("jump instructions not yet implemented for AArch64");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
|
fn tail_call(buf: &mut Vec<'_, u8>) -> u64 {
|
||||||
|
Self::jmp_imm32(buf, 0);
|
||||||
|
buf.len() as u64 - 4 // TODO is 4 the correct offset in ARM?
|
||||||
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn jne_reg64_imm64_imm32(
|
fn jne_reg64_imm64_imm32(
|
||||||
_buf: &mut Vec<'_, u8>,
|
_buf: &mut Vec<'_, u8>,
|
||||||
|
|
|
@ -99,6 +99,8 @@ pub trait Assembler<GeneralReg: RegTrait, FloatReg: RegTrait> {
|
||||||
// It returns the base offset to calculate the jump from (generally the instruction after the jump).
|
// It returns the base offset to calculate the jump from (generally the instruction after the jump).
|
||||||
fn jmp_imm32(buf: &mut Vec<'_, u8>, offset: i32) -> usize;
|
fn jmp_imm32(buf: &mut Vec<'_, u8>, offset: i32) -> usize;
|
||||||
|
|
||||||
|
fn tail_call(buf: &mut Vec<'_, u8>) -> u64;
|
||||||
|
|
||||||
// Jumps by an offset of offset bytes if reg is not equal to imm.
|
// Jumps by an offset of offset bytes if reg is not equal to imm.
|
||||||
// It should always generate the same number of bytes to enable replacement if offset changes.
|
// It should always generate the same number of bytes to enable replacement if offset changes.
|
||||||
// It returns the base offset to calculate the jump from (generally the instruction after the jump).
|
// It returns the base offset to calculate the jump from (generally the instruction after the jump).
|
||||||
|
@ -344,10 +346,8 @@ impl<
|
||||||
/// Used for generating wrappers for malloc/realloc/free
|
/// Used for generating wrappers for malloc/realloc/free
|
||||||
fn build_wrapped_jmp(&mut self) -> Result<(&'a [u8], u64), String> {
|
fn build_wrapped_jmp(&mut self) -> Result<(&'a [u8], u64), String> {
|
||||||
let mut out = bumpalo::vec![in self.env.arena];
|
let mut out = bumpalo::vec![in self.env.arena];
|
||||||
|
let offset = ASM::tail_call(&mut out);
|
||||||
|
|
||||||
ASM::jmp_imm32(&mut out, 0);
|
|
||||||
|
|
||||||
let offset = out.len() as u64 - 4;
|
|
||||||
Ok((out.into_bump_slice(), offset))
|
Ok((out.into_bump_slice(), offset))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -834,6 +834,13 @@ impl Assembler<X86_64GeneralReg, X86_64FloatReg> for X86_64Assembler {
|
||||||
jmp_imm32(buf, offset);
|
jmp_imm32(buf, offset);
|
||||||
buf.len()
|
buf.len()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
|
fn tail_call(buf: &mut Vec<'_, u8>) -> u64 {
|
||||||
|
Self::jmp_imm32(buf, 0);
|
||||||
|
buf.len() as u64 - 4
|
||||||
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn jne_reg64_imm64_imm32(
|
fn jne_reg64_imm64_imm32(
|
||||||
buf: &mut Vec<'_, u8>,
|
buf: &mut Vec<'_, u8>,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue