|
|
|
use crate::data::{
|
|
|
|
Wr, Rd,
|
|
|
|
literal::Label,
|
|
|
|
literal::RoutineName,
|
|
|
|
literal::DebugMsg,
|
|
|
|
};
|
|
|
|
use crate::instr::{Cond};
|
|
|
|
|
|
|
|
/// A higher level simple opration
|
|
|
|
#[derive(Clone, Debug, Eq, PartialEq)]
|
|
|
|
pub enum HLOp {
|
|
|
|
/// Mark a jump target.
|
|
|
|
Label(Label),
|
|
|
|
/// Jump to a label
|
|
|
|
Jump(Label),
|
|
|
|
/// Jump to a label if a flag is set
|
|
|
|
JumpIf(Cond, Label),
|
|
|
|
/// Low level op
|
|
|
|
L(Op),
|
|
|
|
}
|
|
|
|
|
|
|
|
/// A low level instruction
|
|
|
|
#[derive(Clone, Debug, Eq, PartialEq)]
|
|
|
|
pub enum Op {
|
|
|
|
/// Do nothing
|
|
|
|
Nop,
|
|
|
|
/// Mark a far jump target (can be jumped to from another routine).
|
|
|
|
/// This label is preserved in optimized code.
|
|
|
|
FarLabel(Label),
|
|
|
|
/// Jump to a label that can be in another function
|
|
|
|
FarJump(Label),
|
|
|
|
/// Call a routine with arguments.
|
|
|
|
/// The arguments are passed as argX. Return values are stored in resX registers.
|
|
|
|
Call(RoutineName, Vec<Rd>),
|
|
|
|
/// Exit the current routine with return values
|
|
|
|
Ret(Vec<Rd>),
|
|
|
|
/// Mark a routine entry point (call target).
|
|
|
|
/// Kept in the low level instruction file for position-independent code
|
|
|
|
Routine(RoutineName),
|
|
|
|
/// Skip backward or forward
|
|
|
|
Skip(Rd),
|
|
|
|
/// Skip if a flag is set
|
|
|
|
SkipIf(Cond, Rd),
|
|
|
|
/// Deny jumps, skips and run across this address, producing a run-time fault with a message.
|
|
|
|
Barrier(Option<DebugMsg>),
|
|
|
|
/// Generate a run-time fault with a debugger message
|
|
|
|
Fault(Option<DebugMsg>),
|
|
|
|
|
|
|
|
/* Arithmetic */
|
|
|
|
|
|
|
|
/// Copy a value
|
|
|
|
Mov(Wr, Rd),
|
|
|
|
/// Compare two values and set conditional flags.
|
|
|
|
/// If the values are identical, evaluate if they are zero, positive, or negative (the "tst" op)
|
|
|
|
Cmp(Rd, Rd),
|
|
|
|
|
|
|
|
// Arithmetic
|
|
|
|
Inc(Wr),
|
|
|
|
Dec(Wr),
|
|
|
|
Add(Wr, Rd),
|
|
|
|
Sub(Wr, Rd),
|
|
|
|
Mul(Wr, Rd),
|
|
|
|
Div(Wr, Rd),
|
|
|
|
Mod(Wr, /*rem*/Wr, Rd),
|
|
|
|
|
|
|
|
// /// Bitwise
|
|
|
|
And(Wr, Rd),
|
|
|
|
Or(Wr, Rd),
|
|
|
|
Xor(Wr, Rd),
|
|
|
|
Cpl(Wr),
|
|
|
|
Rol(Wr, Rd), // Rotate (with wrap-around)
|
|
|
|
Ror(Wr, Rd),
|
|
|
|
Lsl(Wr, Rd), // Shift
|
|
|
|
Lsr(Wr, Rd),
|
|
|
|
Asr(Wr, Rd),
|
|
|
|
|
|
|
|
// TODO arithmetics, bit manipulation, byte operations
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Make "into" work
|
|
|
|
impl From<Op> for HLOp {
|
|
|
|
fn from(op: Op) -> Self {
|
|
|
|
HLOp::L(op)
|
|
|
|
}
|
|
|
|
}
|