Skip to content

Commit

Permalink
[CODE GEN] fixed x64 register selection (now the type will be taken i…
Browse files Browse the repository at this point in the history
…nto account)
  • Loading branch information
Cr0a3 committed Aug 29, 2024
1 parent 9c72869 commit 1f50b83
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
8 changes: 6 additions & 2 deletions src/CodeGen/compilation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ impl CompilationHelper {
/// allocates resources for a new variable
pub(crate) fn alloc(&mut self, var: &Var) -> VarLocation {
let location = if let Some(reg) = self.regs.pop(self.arch) {
VarLocation::Reg(reg)
VarLocation::Reg(match reg {
Reg::x64(x64) => Reg::x64(x64.sub_ty(var.ty)),
})
} else {
todo!("Registers ran out. And memory variables are currently not implemented")
};
Expand All @@ -62,7 +64,9 @@ impl CompilationHelper {

let location = {
if let Some(reg) = self.call.args(self.arch).get(*num) {
VarLocation::Reg(*reg)
VarLocation::Reg(match reg {
Reg::x64(x64) => Reg::x64(x64.sub_ty(*ty)),
})
} else {
todo!("The new system currently doesn't support memory")
}
Expand Down
11 changes: 4 additions & 7 deletions src/IR/typ.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,10 @@ impl TypeMetadata {
/// Returns the size of the type in bits
pub fn bitSize(&self) -> usize {
match self {
TypeMetadata::u16 => 2,
TypeMetadata::u32 => 4,
TypeMetadata::u64 => 8,
TypeMetadata::i16 => 2,
TypeMetadata::i32 => 4,
TypeMetadata::i64 => 8,
TypeMetadata::ptr => 8,
TypeMetadata::u16 | TypeMetadata::i16 => 16,
TypeMetadata::u32 | TypeMetadata::i32 => 32,
TypeMetadata::u64 | TypeMetadata::i64 => 64,
TypeMetadata::ptr => 64,
TypeMetadata::Void => 0,
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/Target/x64/reg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,10 @@ impl x64Reg {
pub fn sub8(&self) -> x64Reg {
use x64Reg::*;
match self {
Rax | Eax | Ax | Al => Ax,
Rbx | Ebx | Bx | Bl => Bx,
Rcx | Ecx | Cx | Cl => Cx,
Rdx | Edx | Dx | Dl => Dx,
Rax | Eax | Ax | Al => Al,
Rbx | Ebx | Bx | Bl => Bl,
Rcx | Ecx | Cx | Cl => Cl,
Rdx | Edx | Dx | Dl => Dl,
Rsi | Esi | Si | Sil => Sil,
Rdi | Edi | Di | Dil => Dil,

Expand All @@ -178,7 +178,7 @@ impl x64Reg {
2 => self.sub16(),
1 | 0 => self.sub8(),

_ => todo!("the type {} is to big for a single register", ty),
_ => todo!("the type {} is to big/small for a single register", ty),
}
}

Expand Down

0 comments on commit 1f50b83

Please sign in to comment.