Expand support numeric types

This commit is contained in:
Brendan Hansknecht 2021-09-20 23:28:57 -07:00
parent 16d098da5e
commit 91057ed8b5
2 changed files with 102 additions and 46 deletions

View file

@ -191,7 +191,14 @@ impl CallConv<X86_64GeneralReg, X86_64FloatReg> for X86_64SystemV {
} }
for (layout, sym) in args.iter() { for (layout, sym) in args.iter() {
match layout { match layout {
Layout::Builtin(Builtin::Int64) => { Layout::Builtin(
Builtin::Int1
| Builtin::Int8
| Builtin::Int16
| Builtin::Int32
| Builtin::Int64
| Builtin::Usize,
) => {
if general_i < Self::GENERAL_PARAM_REGS.len() { if general_i < Self::GENERAL_PARAM_REGS.len() {
symbol_map.insert( symbol_map.insert(
*sym, *sym,
@ -210,7 +217,7 @@ impl CallConv<X86_64GeneralReg, X86_64FloatReg> for X86_64SystemV {
); );
} }
} }
Layout::Builtin(Builtin::Float64) => { Layout::Builtin(Builtin::Float32 | Builtin::Float64) => {
if float_i < Self::FLOAT_PARAM_REGS.len() { if float_i < Self::FLOAT_PARAM_REGS.len() {
symbol_map.insert( symbol_map.insert(
*sym, *sym,
@ -229,6 +236,7 @@ impl CallConv<X86_64GeneralReg, X86_64FloatReg> for X86_64SystemV {
); );
} }
} }
Layout::Struct(&[]) => {}
x => { x => {
return Err(format!( return Err(format!(
"Loading args with layout {:?} not yet implementd", "Loading args with layout {:?} not yet implementd",
@ -254,8 +262,16 @@ impl CallConv<X86_64GeneralReg, X86_64FloatReg> for X86_64SystemV {
// For most return layouts we will do nothing. // For most return layouts we will do nothing.
// In some cases, we need to put the return address as the first arg. // In some cases, we need to put the return address as the first arg.
match ret_layout { match ret_layout {
Layout::Builtin(Builtin::Int64) => {} Layout::Builtin(
Layout::Builtin(Builtin::Float64) => {} Builtin::Int1
| Builtin::Int8
| Builtin::Int16
| Builtin::Int32
| Builtin::Int64
| Builtin::Usize
| Builtin::Float32
| Builtin::Float64,
) => {}
x => { x => {
return Err(format!( return Err(format!(
"receiving return type, {:?}, is not yet implemented", "receiving return type, {:?}, is not yet implemented",
@ -265,7 +281,14 @@ impl CallConv<X86_64GeneralReg, X86_64FloatReg> for X86_64SystemV {
} }
for (i, layout) in arg_layouts.iter().enumerate() { for (i, layout) in arg_layouts.iter().enumerate() {
match layout { match layout {
Layout::Builtin(Builtin::Int64) => { Layout::Builtin(
Builtin::Int1
| Builtin::Int8
| Builtin::Int16
| Builtin::Int32
| Builtin::Int64
| Builtin::Usize,
) => {
if general_i < Self::GENERAL_PARAM_REGS.len() { if general_i < Self::GENERAL_PARAM_REGS.len() {
// Load the value to the param reg. // Load the value to the param reg.
let dst = Self::GENERAL_PARAM_REGS[general_i]; let dst = Self::GENERAL_PARAM_REGS[general_i];
@ -319,7 +342,7 @@ impl CallConv<X86_64GeneralReg, X86_64FloatReg> for X86_64SystemV {
stack_offset += 8; stack_offset += 8;
} }
} }
Layout::Builtin(Builtin::Float64) => { Layout::Builtin(Builtin::Float32 | Builtin::Float64) => {
if float_i < Self::FLOAT_PARAM_REGS.len() { if float_i < Self::FLOAT_PARAM_REGS.len() {
// Load the value to the param reg. // Load the value to the param reg.
let dst = Self::FLOAT_PARAM_REGS[float_i]; let dst = Self::FLOAT_PARAM_REGS[float_i];
@ -371,6 +394,7 @@ impl CallConv<X86_64GeneralReg, X86_64FloatReg> for X86_64SystemV {
stack_offset += 8; stack_offset += 8;
} }
} }
Layout::Struct(&[]) => {}
x => { x => {
return Err(format!( return Err(format!(
"calling with arg type, {:?}, is not yet implemented", "calling with arg type, {:?}, is not yet implemented",
@ -529,13 +553,21 @@ impl CallConv<X86_64GeneralReg, X86_64FloatReg> for X86_64WindowsFastcall {
for (layout, sym) in args.iter() { for (layout, sym) in args.iter() {
if i < Self::GENERAL_PARAM_REGS.len() { if i < Self::GENERAL_PARAM_REGS.len() {
match layout { match layout {
Layout::Builtin(Builtin::Int64) => { Layout::Builtin(
Builtin::Int1
| Builtin::Int8
| Builtin::Int16
| Builtin::Int32
| Builtin::Int64
| Builtin::Usize,
) => {
symbol_map symbol_map
.insert(*sym, SymbolStorage::GeneralReg(Self::GENERAL_PARAM_REGS[i])); .insert(*sym, SymbolStorage::GeneralReg(Self::GENERAL_PARAM_REGS[i]));
} }
Layout::Builtin(Builtin::Float64) => { Layout::Builtin(Builtin::Float32 | Builtin::Float64) => {
symbol_map.insert(*sym, SymbolStorage::FloatReg(Self::FLOAT_PARAM_REGS[i])); symbol_map.insert(*sym, SymbolStorage::FloatReg(Self::FLOAT_PARAM_REGS[i]));
} }
Layout::Struct(&[]) => {}
x => { x => {
return Err(format!( return Err(format!(
"Loading args with layout {:?} not yet implementd", "Loading args with layout {:?} not yet implementd",
@ -546,8 +578,16 @@ impl CallConv<X86_64GeneralReg, X86_64FloatReg> for X86_64WindowsFastcall {
i += 1; i += 1;
} else { } else {
base_offset += match layout { base_offset += match layout {
Layout::Builtin(Builtin::Int64) => 8, Layout::Builtin(
Layout::Builtin(Builtin::Float64) => 8, Builtin::Int1
| Builtin::Int8
| Builtin::Int16
| Builtin::Int32
| Builtin::Int64
| Builtin::Usize
| Builtin::Float32
| Builtin::Float64,
) => 8,
x => { x => {
return Err(format!( return Err(format!(
"Loading args with layout {:?} not yet implemented", "Loading args with layout {:?} not yet implemented",
@ -581,8 +621,16 @@ impl CallConv<X86_64GeneralReg, X86_64FloatReg> for X86_64WindowsFastcall {
// For most return layouts we will do nothing. // For most return layouts we will do nothing.
// In some cases, we need to put the return address as the first arg. // In some cases, we need to put the return address as the first arg.
match ret_layout { match ret_layout {
Layout::Builtin(Builtin::Int64) => {} Layout::Builtin(
Layout::Builtin(Builtin::Float64) => {} Builtin::Int1
| Builtin::Int8
| Builtin::Int16
| Builtin::Int32
| Builtin::Int64
| Builtin::Usize
| Builtin::Float32
| Builtin::Float64,
) => {}
x => { x => {
return Err(format!( return Err(format!(
"receiving return type, {:?}, is not yet implemented", "receiving return type, {:?}, is not yet implemented",
@ -592,7 +640,14 @@ impl CallConv<X86_64GeneralReg, X86_64FloatReg> for X86_64WindowsFastcall {
} }
for (i, layout) in arg_layouts.iter().enumerate() { for (i, layout) in arg_layouts.iter().enumerate() {
match layout { match layout {
Layout::Builtin(Builtin::Int64) => { Layout::Builtin(
Builtin::Int1
| Builtin::Int8
| Builtin::Int16
| Builtin::Int32
| Builtin::Int64
| Builtin::Usize,
) => {
if i < Self::GENERAL_PARAM_REGS.len() { if i < Self::GENERAL_PARAM_REGS.len() {
// Load the value to the param reg. // Load the value to the param reg.
let dst = Self::GENERAL_PARAM_REGS[reg_i]; let dst = Self::GENERAL_PARAM_REGS[reg_i];
@ -646,7 +701,7 @@ impl CallConv<X86_64GeneralReg, X86_64FloatReg> for X86_64WindowsFastcall {
stack_offset += 8; stack_offset += 8;
} }
} }
Layout::Builtin(Builtin::Float64) => { Layout::Builtin(Builtin::Float32 | Builtin::Float64) => {
if i < Self::FLOAT_PARAM_REGS.len() { if i < Self::FLOAT_PARAM_REGS.len() {
// Load the value to the param reg. // Load the value to the param reg.
let dst = Self::FLOAT_PARAM_REGS[reg_i]; let dst = Self::FLOAT_PARAM_REGS[reg_i];
@ -698,6 +753,7 @@ impl CallConv<X86_64GeneralReg, X86_64FloatReg> for X86_64WindowsFastcall {
stack_offset += 8; stack_offset += 8;
} }
} }
Layout::Struct(&[]) => {}
x => { x => {
return Err(format!( return Err(format!(
"calling with arg type, {:?}, is not yet implemented", "calling with arg type, {:?}, is not yet implemented",

View file

@ -624,41 +624,41 @@ mod dev_num {
// ); // );
// } // }
// #[test] #[test]
// fn if_guard_bind_variable_false() { fn if_guard_bind_variable_false() {
// assert_evals_to!( assert_evals_to!(
// indoc!( indoc!(
// r#" r#"
// wrapper = \{} -> wrapper = \{} ->
// when 10 is when 10 is
// x if x == 5 -> 0 x if x == 5 -> 0
// _ -> 42 _ -> 42
// wrapper {} wrapper {}
// "# "#
// ), ),
// 42, 42,
// i64 i64
// ); );
// } }
// #[test] #[test]
// fn if_guard_bind_variable_true() { fn if_guard_bind_variable_true() {
// assert_evals_to!( assert_evals_to!(
// indoc!( indoc!(
// r#" r#"
// wrapper = \{} -> wrapper = \{} ->
// when 10 is when 10 is
// x if x == 10 -> 42 x if x == 10 -> 42
// _ -> 0 _ -> 0
// wrapper {} wrapper {}
// "# "#
// ), ),
// 42, 42,
// i64 i64
// ); );
// } }
#[test] #[test]
fn tail_call_elimination() { fn tail_call_elimination() {