-
-
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] implementing all ir instructions (call has #8 but i know t…
…hat)
- Loading branch information
Showing
7 changed files
with
104 additions
and
11 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
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,11 +1,60 @@ | ||
use crate::prelude::Call; | ||
use crate::{prelude::{Call, Ir}, CodeGen::{MachineMnemonic, MachineOperand}}; | ||
use crate::IR::{Block, Function, Var}; | ||
use super::CompilationHelper; | ||
use super::{CompilationHelper, VarLocation}; | ||
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!() | ||
let boxed: Box<dyn Ir> = Box::new(node.clone()); | ||
|
||
let mut reg_args = 0; | ||
|
||
let args = self.call.args(self.arch); | ||
|
||
for arg in &node.inner2 { | ||
let mut instr = MachineInstr::new(MachineMnemonic::Move); | ||
|
||
|
||
let arg_reg = args.get(reg_args); | ||
|
||
if let Some(arg) = arg_reg { | ||
instr.set_out(MachineOperand::Reg(*arg)); | ||
} else { | ||
todo!("implemt arguments which are passed over the stack"); | ||
} | ||
|
||
let src = self.vars.get(arg).expect("expected valid variable"); | ||
|
||
match src { | ||
VarLocation::Reg(reg) => instr.add_operand(MachineOperand::Reg(*reg)), | ||
} | ||
|
||
mc_sink.push( instr ); | ||
|
||
reg_args += 1; | ||
} | ||
|
||
mc_sink.push(MachineInstr::new( | ||
MachineMnemonic::Call(node.inner1.name.to_string()) | ||
)); | ||
|
||
if block.isVarUsedAfterNode(&boxed, &node.inner3) { | ||
let mut instr = MachineInstr::new(MachineMnemonic::Move); | ||
|
||
let loc = self.alloc(&node.inner3); | ||
|
||
instr.add_operand( | ||
MachineOperand::Reg( | ||
self.call.return_reg(self.arch, node.inner1.ty.ret) | ||
) | ||
); | ||
|
||
match loc { | ||
VarLocation::Reg(reg) => instr.set_out(MachineOperand::Reg(reg)), | ||
} | ||
|
||
mc_sink.push(instr); | ||
} | ||
} | ||
} |
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,10 +1,46 @@ | ||
use crate::prelude::Cast; | ||
use crate::prelude::{Cast, Ir}; | ||
use crate::IR::{Block, TypeMetadata, Var}; | ||
use super::CompilationHelper; | ||
use crate::CodeGen::MachineInstr; | ||
use super::{CompilationHelper, VarLocation}; | ||
use crate::CodeGen::{MachineInstr, MachineMnemonic, MachineOperand}; | ||
|
||
impl CompilationHelper { | ||
#[allow(missing_docs)] | ||
pub fn compile_cast(&mut self, node: &Cast<Var, TypeMetadata, Var>, mc_sink: &mut Vec<MachineInstr>, block: &Block) { | ||
todo!() | ||
let src1 = *self.vars.get(&node.inner1).expect("expected valid variable"); | ||
|
||
let boxed: Box<dyn Ir> = Box::new(node.clone()); | ||
|
||
if !block.isVarUsedAfterNode(&boxed, &node.inner1) { | ||
self.free(&node.inner1) | ||
} | ||
if !block.isVarUsedAfterNode(&boxed, &node.inner3) { | ||
return; | ||
} | ||
|
||
let out = self.alloc(&node.inner3); | ||
|
||
let op = { | ||
|
||
if node.inner1.ty.bitSize() > node.inner2.bitSize() { | ||
MachineMnemonic::Zext | ||
} else if node.inner1.ty.bitSize() < node.inner2.bitSize(){ | ||
MachineMnemonic::Downcast | ||
} else { | ||
return; | ||
} | ||
|
||
}; | ||
|
||
let mut instr = MachineInstr::new(op); | ||
|
||
match src1 { | ||
VarLocation::Reg(reg) => instr.add_operand(MachineOperand::Reg(reg)), | ||
} | ||
|
||
match out { | ||
VarLocation::Reg(reg) => instr.set_out(MachineOperand::Reg(reg)), | ||
} | ||
|
||
mc_sink.push(instr); | ||
} | ||
} |
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