mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-26 21:39:07 +00:00
NumIntCast
This commit is contained in:
parent
af2ab24525
commit
b663db56f0
2 changed files with 44 additions and 0 deletions
|
@ -2716,6 +2716,28 @@ impl<
|
|||
FloatWidth::F64 => ASM::sqrt_freg64_freg64(buf, dst_reg, src_reg),
|
||||
}
|
||||
}
|
||||
|
||||
fn build_num_int_cast(
|
||||
&mut self,
|
||||
dst: &Symbol,
|
||||
src: &Symbol,
|
||||
source: IntWidth,
|
||||
target: IntWidth,
|
||||
) {
|
||||
let buf = &mut self.buf;
|
||||
|
||||
let dst_reg = self.storage_manager.claim_general_reg(buf, &dst);
|
||||
let src_reg = self.storage_manager.load_to_general_reg(buf, &src);
|
||||
|
||||
if source.stack_size() == target.stack_size() {
|
||||
match source.stack_size() {
|
||||
8 => ASM::mov_reg64_reg64(buf, dst_reg, src_reg),
|
||||
_ => todo!("int cast from {source:?} to {target:?}"),
|
||||
}
|
||||
} else {
|
||||
todo!("int cast from {source:?} to {target:?}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// This impl block is for ir related instructions that need backend specific information.
|
||||
|
|
|
@ -1141,6 +1141,19 @@ trait Backend<'a> {
|
|||
let intrinsic = bitcode::STR_IS_EMPTY.to_string();
|
||||
self.build_fn_call(sym, intrinsic, args, arg_layouts, ret_layout);
|
||||
}
|
||||
LowLevel::NumIntCast => {
|
||||
let source_width = match self.interner().get(arg_layouts[0]) {
|
||||
Layout::Builtin(Builtin::Int(width)) => width,
|
||||
_ => unreachable!(),
|
||||
};
|
||||
|
||||
let target_width = match self.interner().get(*ret_layout) {
|
||||
Layout::Builtin(Builtin::Int(width)) => width,
|
||||
_ => unreachable!(),
|
||||
};
|
||||
|
||||
self.build_num_int_cast(sym, &args[0], source_width, target_width)
|
||||
}
|
||||
x => todo!("low level, {:?}", x),
|
||||
}
|
||||
}
|
||||
|
@ -1254,6 +1267,15 @@ trait Backend<'a> {
|
|||
/// Move a returned value into `dst`
|
||||
fn move_return_value(&mut self, dst: &Symbol, ret_layout: &InLayout<'a>);
|
||||
|
||||
/// build_num_abs stores the absolute value of src into dst.
|
||||
fn build_num_int_cast(
|
||||
&mut self,
|
||||
dst: &Symbol,
|
||||
src: &Symbol,
|
||||
source: IntWidth,
|
||||
target: IntWidth,
|
||||
);
|
||||
|
||||
/// build_num_abs stores the absolute value of src into dst.
|
||||
fn build_num_abs(&mut self, dst: &Symbol, src: &Symbol, layout: &InLayout<'a>);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue