Skip to content

Commit

Permalink
expand mir a tad
Browse files Browse the repository at this point in the history
  • Loading branch information
Lokathor committed Jan 11, 2025
1 parent 3c0d540 commit 90af87a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/mir/binary_op.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::*;

/// Performs math using the A register along with some other value.
/// Performs a two-input operation, with the output placed into `a`.
#[derive(Debug, Clone, Copy)]
pub enum BinaryOp {
/// `adc`
Expand Down
23 changes: 21 additions & 2 deletions src/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ pub enum Mir {
/// `[imm16] = a`
AssignImm16tA(u16),

/// `a = [label]`
AssignALabelT(u16),

/// `[label] = a`
AssignLabelTA(u16),

/// `reg8 = imm8`
AssignReg8Imm8(Reg8, u8),

Expand All @@ -74,6 +80,9 @@ pub enum Mir {
/// This is necessary to load the address of an item, since we don't know the
/// address of an item until after linking.
AssignReg16Label(Reg16, StrID),

/// Does `a = op(arg0, arg1)` for any binary op.
BinOp(BinaryOp, Reg8, Reg8),
}
impl Mir {
#[inline]
Expand All @@ -89,11 +98,16 @@ impl Mir {
| Mir::AssignImm16tA(_)
| Mir::AssignReg8Imm8(_, _)
| Mir::AssignReg16Imm16(_, _)
| Mir::AssignReg16Label(_, _) => FlagEffect::NoEffect,
| Mir::AssignReg16Label(_, _)
| Mir::AssignALabelT(_)
| Mir::AssignLabelTA(_) => FlagEffect::NoEffect,
Mir::Inc8(_) | Mir::Dec8(_) => FlagEffect::ByOutput,
Mir::Loop(_) | Mir::If(_) | Mir::JumpLabel(_) | Mir::Call(_) => {
FlagEffect::Unknown
}
// TODO: With some ops we statically know the answer is actually going to
// be `FlagEffect::AlwaysTrue` if both input registers are `a`.
Mir::BinOp(binary_op, _, _) => FlagEffect::ByOutput,
}
}

Expand All @@ -112,10 +126,15 @@ impl Mir {
| Mir::AssignReg16Imm16(_, _)
| Mir::AssignReg16Label(_, _)
| Mir::Inc8(_)
| Mir::Dec8(_) => FlagEffect::NoEffect,
| Mir::Dec8(_)
| Mir::AssignALabelT(_)
| Mir::AssignLabelTA(_) => FlagEffect::NoEffect,
Mir::Loop(_) | Mir::If(_) | Mir::JumpLabel(_) | Mir::Call(_) => {
FlagEffect::Unknown
}
// TODO: some ops actually always set carry to 0, or even don't touch the
// flag.
Mir::BinOp(binary_op, _, _) => FlagEffect::ByOutput,
}
}
}
Expand Down

0 comments on commit 90af87a

Please sign in to comment.