Add release pseudo-instruction

This commit is contained in:
Andrew Morris
2023-06-30 10:04:08 +10:00
parent 4005510bf2
commit da94fcb947
6 changed files with 28 additions and 13 deletions

View File

@@ -142,6 +142,7 @@ impl std::fmt::Display for Function {
FnLine::Label(label) => write!(f, "{}\n", label)?,
FnLine::Empty => write!(f, "\n")?,
FnLine::Comment(message) => write!(f, " // {}\n", message)?,
FnLine::Release(reg) => write!(f, " (release {})\n", reg)?,
}
}
write!(f, "}}")
@@ -297,21 +298,17 @@ pub enum FnLine {
Label(Label),
Empty,
Comment(String),
Release(Register),
}
impl std::fmt::Display for FnLine {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
FnLine::Instruction(instruction) => {
write!(f, "{}", instruction)
}
FnLine::Label(label) => {
write!(f, "{}", label)
}
FnLine::Instruction(instruction) => write!(f, "{}", instruction),
FnLine::Label(label) => write!(f, "{}", label),
FnLine::Empty => Ok(()),
FnLine::Comment(message) => {
write!(f, "// {}", message)
}
FnLine::Comment(message) => write!(f, "// {}", message),
FnLine::Release(reg) => write!(f, "(release {})", reg),
}
}
}
@@ -890,6 +887,7 @@ impl std::fmt::Display for Lazy {
FnLine::Label(label) => write!(f, "{}\n", label)?,
FnLine::Empty => write!(f, "\n")?,
FnLine::Comment(message) => write!(f, " // {}\n", message)?,
FnLine::Release(reg) => write!(f, " (release {})\n", reg)?,
}
}

View File

@@ -102,7 +102,7 @@ impl Assembler {
FnLine::Label(label) => {
self.label(label);
}
FnLine::Empty | FnLine::Comment(..) => {}
FnLine::Empty | FnLine::Comment(..) | FnLine::Release(..) => {}
}
}
@@ -130,7 +130,7 @@ impl Assembler {
FnLine::Label(label) => {
self.label(label);
}
FnLine::Empty | FnLine::Comment(..) => {}
FnLine::Empty | FnLine::Comment(..) | FnLine::Release(..) => {}
}
}

View File

@@ -497,6 +497,19 @@ impl<'a> AssemblyParser<'a> {
continue;
}
if c == '(' {
self.parse_exact("(release");
self.parse_whitespace();
let reg = self.assemble_register();
self.parse_optional_whitespace();
self.parse_exact(")\n");
function.body.push(FnLine::Release(reg));
continue;
}
let optional_label = self.test_label();
if optional_label.is_some() {

View File

@@ -216,6 +216,7 @@ impl FunctionCompiler {
pub fn release_reg(&mut self, reg: &Register) {
self.reg_allocator.release(reg);
self.current.body.push(FnLine::Release(reg.clone()));
}
pub fn compile(

View File

@@ -123,7 +123,7 @@ impl FnState {
Instruction::Next(_, _) => {}
Instruction::UnpackIterRes(_, _, _) => {}
},
FnLine::Label(..) | FnLine::Empty | FnLine::Comment(..) => {}
FnLine::Label(..) | FnLine::Empty | FnLine::Comment(..) | FnLine::Release(..) => {}
}
}
@@ -285,6 +285,9 @@ impl FnState {
},
FnLine::Label(..) => self.clear(),
FnLine::Empty | FnLine::Comment(..) => {}
FnLine::Release(_reg) => {
// TODO
}
}
}

View File

@@ -170,7 +170,7 @@ where
FnLine::Instruction(instruction) => {
self.instruction(owner, instruction);
}
FnLine::Label(..) | FnLine::Empty | FnLine::Comment(..) => {}
FnLine::Label(..) | FnLine::Empty | FnLine::Comment(..) | FnLine::Release(..) => {}
}
}
}