use std::fmt;
use std::ops::Index;
use std::slice::SliceIndex;
use crate::compiler::instr::flow::Element;
use crate::microcode::Microcode;
use crate::opcode::{CBOpcode, InternalFetch, Opcode};
pub mod builder;
pub mod flow;
#[derive(Debug, Copy, Clone, PartialEq, Eq, Ord, PartialOrd)]
pub enum InstrId {
InternalFetch,
Opcode(Opcode),
CBOpcode(CBOpcode),
}
impl fmt::Display for InstrId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Opcode(opcode) => write!(f, "{}", opcode),
Self::CBOpcode(cbopcode) => write!(f, "{}", cbopcode),
Self::InternalFetch => write!(f, "{}", InternalFetch),
}
}
}
#[derive(Debug, Clone)]
pub struct InstrDef {
id: InstrId,
microcode: Vec<Microcode>,
flow: Element,
}
impl InstrDef {
pub fn len(&self) -> usize {
self.microcode.len()
}
pub fn id(&self) -> InstrId {
self.id
}
pub fn flow(&self) -> &Element {
&self.flow
}
}
impl<T> Index<T> for InstrDef
where
T: SliceIndex<[Microcode]>,
{
type Output = <T as SliceIndex<[Microcode]>>::Output;
fn index(&self, index: T) -> &Self::Output {
&self.microcode[index]
}
}