nand7400/assembler/
config.rs1use super::parser::ast::{Argument, ArgumentKind};
2use serde::{Deserialize, Serialize};
3
4#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
6pub struct AssemblerConfig {
7    pub opcodes: Vec<Opcode>,
9}
10
11impl AssemblerConfig {
13    pub fn get_opcode(&self, mnemonic: &str) -> Option<&Opcode> {
15        self.opcodes
16            .iter()
17            .find(|opcode| opcode.mnemonic == mnemonic)
18    }
19}
20
21#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
23pub struct Opcode {
24    pub mnemonic: String,
26
27    pub binary: u8,
29
30    pub args: Vec<OpcodeArg>,
34}
35
36#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
38pub enum OpcodeArg {
39    Indirect,
41
42    Immediate,
44}
45
46impl<T> From<&Argument<T>> for OpcodeArg {
47    fn from(arg: &Argument<T>) -> Self {
48        match arg.kind {
49            ArgumentKind::IndirectNumber(_) => Self::Indirect,
50            ArgumentKind::ImmediateNumber(_) | ArgumentKind::Label(_) => Self::Immediate,
51        }
52    }
53}