-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CODE GEN] adding more stuff (i forgot what)
- Loading branch information
Showing
20 changed files
with
300 additions
and
214 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,64 @@ | ||
use crate::Target::{x64Reg, Arch, CallConv}; | ||
use crate::{Target::{x64Reg, Arch, CallConv}, IR::TypeMetadata}; | ||
|
||
use super::Reg; | ||
|
||
/// A more machine specifc calling convention | ||
/// (Just a wrapper around the normal calling convention but with some pretty handy functions) | ||
#[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
pub struct MachineCallingConvention { | ||
pub(crate) call_conv: CallConv, | ||
} | ||
|
||
impl MachineCallingConvention { | ||
pub fn return_reg(&self, arch: Arch) -> Reg { | ||
/// returns the return register for the specific architecture and ty | ||
pub fn return_reg(&self, arch: Arch, ty: TypeMetadata) -> Reg { | ||
match self.call_conv { | ||
CallConv::WindowsFastCall => { | ||
match arch { | ||
Arch::X86_64 => Reg::x64(x64Reg::Rax), | ||
Arch::X86_64 => Reg::x64(x64Reg::Rax.sub_ty(ty)), | ||
_ => todo!() | ||
} | ||
}, | ||
CallConv::SystemV => { | ||
match arch { | ||
Arch::X86_64 => Reg::x64(x64Reg::Rax), | ||
Arch::X86_64 => Reg::x64(x64Reg::Rax.sub_ty(ty)), | ||
_ => todo!() | ||
} | ||
}, | ||
CallConv::AppleAarch64 => todo!(), | ||
CallConv::WasmBasicCAbi => todo!(), | ||
} | ||
} | ||
|
||
/// returns the args for the specifc architecture | ||
pub fn args(&self, arch: Arch) -> Vec<Reg> { | ||
match self.call_conv { | ||
CallConv::WindowsFastCall => { | ||
match arch { | ||
Arch::X86_64 => vec![ | ||
Reg::x64(x64Reg::Rcx), Reg::x64(x64Reg::Rdx), | ||
Reg::x64(x64Reg::R8), Reg::x64(x64Reg::R9) | ||
], | ||
_ => todo!() | ||
} | ||
}, | ||
CallConv::SystemV => { | ||
match arch { | ||
Arch::X86_64 => vec![ | ||
Reg::x64(x64Reg::Rsi), Reg::x64(x64Reg::Rdi), | ||
Reg::x64(x64Reg::Rcx), Reg::x64(x64Reg::Rdx), | ||
Reg::x64(x64Reg::R8), Reg::x64(x64Reg::R9) | ||
], | ||
_ => todo!() | ||
} | ||
}, | ||
CallConv::AppleAarch64 => todo!(), | ||
CallConv::WasmBasicCAbi => todo!(), | ||
} | ||
} | ||
|
||
/// returns how many arguments are stored in registers | ||
pub fn num_reg_args(&self, arch: Arch) -> usize { | ||
self.args(arch).len() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
use crate::prelude::ConstAssign; | ||
use crate::IR::{Block, Const, Type, Var}; | ||
use super::CompilationHelper; | ||
use crate::CodeGen::MachineInstr; | ||
|
||
impl CompilationHelper { | ||
#[allow(missing_docs)] | ||
pub fn compile_assign_var_type(&mut self, node: &ConstAssign<Var, Type>, mc_sink: &mut Vec<MachineInstr>, block: &Block) { | ||
todo!() | ||
} | ||
|
||
#[allow(missing_docs)] | ||
pub fn compile_assign_var_var(&mut self, node: &ConstAssign<Var, Var>, mc_sink: &mut Vec<MachineInstr>, block: &Block) { | ||
todo!() | ||
} | ||
|
||
#[allow(missing_docs)] | ||
pub fn compile_assign_var_const(&mut self, node: &ConstAssign<Var, Const>, mc_sink: &mut Vec<MachineInstr>, block: &Block) { | ||
todo!() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
use crate::prelude::Call; | ||
use crate::IR::{Block, Function, Var}; | ||
use super::CompilationHelper; | ||
use crate::CodeGen::MachineInstr; | ||
|
||
impl CompilationHelper { | ||
#[allow(missing_docs)] | ||
pub fn compile_call(&mut self, node: &Call<Function, Vec<Var>, Var>, mc_sink: &mut Vec<MachineInstr>, block: &Block) { | ||
todo!() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
use crate::prelude::Cast; | ||
use crate::IR::{Block, TypeMetadata, Var}; | ||
use super::CompilationHelper; | ||
use crate::CodeGen::MachineInstr; | ||
|
||
impl CompilationHelper { | ||
pub fn compile_cast(&mut self, node: &Cast<Var, TypeMetadata, Var>, mc_sink: &mut Vec<MachineInstr>, block: &Block) { | ||
todo!() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.