libxas 0.1.0

Extendable Assembler library
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
// SPDX-License-Identifier: GPL-2.0-or-later
/*
 * libxas: Extendable Assembler Library
 * Copyright (C) 2022 Amy Parker <apark0006@student.cerritos.edu>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA or visit
 * the GNU Project at <https://gnu.org/licenses>. The GNU General Public
 * License version 2 is available at, for your convenience,
 * <https://gnu.org/licenses/old-licenses/gpl-2.0.html>.
 */

use crate::errors::lpanic;

// TODO: Code organization and cleanup

use std::str::FromStr;

// TODO: make all arches (including chip8_raw) under features
// same with a lot of other parts

// TODO: better error handling
// TODO: reduce repetition of this
//use crate::bbu::ArchMacro;
use crate::bbu::ArchMcrInst;
use crate::bbu::DatSize;
use crate::bbu::PtrSize;
use crate::bbu::RcSym;
use crate::bbu::SymConv;
use crate::bbu::ArgSymbol;

pub type Chip8DatSize = crate::bbu::GenScal<u8>;
// TODO: generic displacement size for types without one
// (@u8 for size)
pub type Chip8DisSize = crate::bbu::GenScal<u8>;
pub type Chip8PtrSize = crate::bbu::Gen12;

pub type Chip8SymAlias = ArgSymbol<Chip8PtrSize, Chip8DatSize>;

//pub type CHIP8_Symbol = crate::bbu::ArgSymbol<CHIP8_PTR_SIZE, CHIP8_DAT_SIZE>;
pub struct Chip8Symbol {
    pub i: Chip8SymAlias,
}

// TODO: make this, other parts of ArgSymbol construction a macro
impl SymConv for Chip8Symbol {
    // FIXME FIXME FIXME: into_dat
    fn from_ptr<T: PtrSize>(a: T) -> Self {
        Self {
            i: ArgSymbol::Pointer(Box::new(
                <Chip8PtrSize as PtrSize>::from_int::<u16>(a.extract_int::<u16>()),
            )),
        }
    }
    fn from_dat<T: DatSize>(a: T) -> Self {
        Self {
            i: ArgSymbol::Data(Box::new(<Chip8DatSize as DatSize>::from_int::<u8>(
                a.extract_int::<u8>(),
            ))),
        }
    }
    fn into_ptr<T: PtrSize, E: crate::bbu::Integral>(&self) -> T {
        T::from_int(PtrSize::extract_int::<E>(
            &**self.i.unwrap_ptr().unwrap(),
        ))
    }
}

impl<T: SymConv> crate::bbu::ArchSym<T> for Chip8Symbol {
    fn get_uk_sym(&self) -> Option<RcSym> {
        match &self.i {
            ArgSymbol::UnknownPointer(i) | ArgSymbol::UnknownData(i) => {
                Some(i.clone())
            }
            _ => None,
        }
    }
    fn set_sym(&mut self, _a: T) -> () {
        unimplemented!()
    }
}

macro_rules! gim {
    ($n:ident,$i:ident) => {{
        Box::new(<$n as ArchMcrInst<Chip8Symbol>>::get_lex($i.args))
    }};
}

pub fn get_instruction<T: SymConv>(
    i: crate::parser::ParsedInstruction,
) -> Box<dyn ArchMcrInst<T>> {
    match i.instr.to_lowercase().as_str() {
        // TODO: reduce code dup, tie into the macros beforehand??
        "0nnn" => gim!(Chip8_0NNN, i),
        "00e0" => gim!(Chip8_00E0, i),
        "00ee" => gim!(Chip8_00EE, i),
        "1nnn" => gim!(Chip8_1NNN, i),
        "2nnn" => gim!(Chip8_2NNN, i),
        "3xnn" => gim!(Chip8_3XNN, i),
        "4xnn" => gim!(Chip8_4XNN, i),
        "5xy0" => gim!(Chip8_5XY0, i),
        "6xnn" => gim!(Chip8_6XNN, i),
        "7xnn" => gim!(Chip8_7XNN, i),
        "8xy0" => gim!(Chip8_8XY0, i),
        "8xy1" => gim!(Chip8_8XY1, i),
        "8xy2" => gim!(Chip8_8XY2, i),
        "8xy3" => gim!(Chip8_8XY3, i),
        "8xy4" => gim!(Chip8_8XY4, i),
        "8xy5" => gim!(Chip8_8XY5, i),
        "8xy6" => gim!(Chip8_8XY6, i),
        "8xy7" => gim!(Chip8_8XY7, i),
        "8xye" => gim!(Chip8_8XYE, i),
        "9xy0" => gim!(Chip8_9XY0, i),
        "annn" => gim!(Chip8_ANNN, i),
        "bnnn" => gim!(Chip8_BNNN, i),
        "cxnn" => gim!(Chip8_CXNN, i),
        "dxyn" => gim!(Chip8_DXYN, i),
        "ex9e" => gim!(Chip8_EX9E, i),
        "exa1" => gim!(Chip8_EXA1, i),
        "fx07" => gim!(Chip8_FX07, i),
        "fx0a" => gim!(Chip8_FX0A, i),
        "fx15" => gim!(Chip8_FX15, i),
        "fx18" => gim!(Chip8_FX18, i),
        "fx1e" => gim!(Chip8_FX1E, i),
        "fx29" => gim!(Chip8_FX29, i),
        "fx33" => gim!(Chip8_FX33, i),
        "fx55" => gim!(Chip8_FX55, i),
        "fx65" => gim!(Chip8_FX65, i),
        _ => lpanic("unknown instruction error"),
    }
}

#[derive(Copy, Clone)]
pub struct Chip8ArchReg {
    n: u8,
}

impl FromStr for Chip8ArchReg {
    type Err = std::num::ParseIntError;
    fn from_str(s: &str) -> Result<Self, Self::Err> {
        if s.len() > 3 || s.len() < 2 {
            lpanic("chip8_raw: unknown register")
        } else {
            // NOTE: consider full UTF-8 support
            let a: char = s.chars().nth(2).unwrap();
            Ok(Chip8ArchReg {
                n: char::to_digit(
                    if a == 'v' {
                        s.chars().nth(3).unwrap()
                    } else {
                        a
                    },
                    16,
                )
                .unwrap() as u8,
            })
        }
    }
}

impl crate::bbu::ArchReg for Chip8ArchReg {}

pub type Chip8Arg = crate::bbu::ArchArg<Chip8PtrSize, Chip8DatSize, Chip8DisSize, Chip8ArchReg>;

// TODO: is vec![] best here?
fn chip8_placeholder() -> Vec<u8> {
    vec![0u8, 0u8]
}

// TODO: review of public vs pub(crate) vs private api
// TODO: refactor to Chip8InstrLen
const CHIP8_INSTR_LEN: crate::bbu::SymbolPosition = 0x2;

// lots of code duplication with get_output_bytes TODO FIXME NOTE, somen with get_lex

macro_rules! make_std_const {
    ($nm:ident,$offs:expr) => {
        #[allow(non_camel_case_types)]
        pub struct $nm {}
        impl<T: SymConv> ArchMcrInst<T> for $nm {
            fn get_output_bytes(&self) -> Vec<u8> {
                Vec::from($offs.to_be_bytes())
            }
            fn get_lex(_a: Option<Vec<String>>) -> Self {
                Self {}
            }
            fn check_symbols(&self) -> bool {
                false
            }
            // TODO: replace tuple with UnresSymInfo
            fn get_symbols(&self) -> crate::bbu::USIWrap {
                None
            }
            fn get_length(&self) -> crate::bbu::SymbolPosition {
                CHIP8_INSTR_LEN
            }
            fn get_placeholder(&self) -> Vec<u8> {
                chip8_placeholder()
            }
            fn fulfill_symbol(&mut self, _s: &T, _p: crate::bbu::SymbolPosition) -> () {}
        }
    };
}

macro_rules! make_std_nnn {
    ($nm:ident,$offs:expr) => {
        #[allow(non_camel_case_types)]
        pub struct $nm {
            addr: Chip8SymAlias,
        }
        impl<T: SymConv> ArchMcrInst<T> for $nm {
            fn get_output_bytes(&self) -> Vec<u8> {
                Vec::from(($offs | self.addr.unwrap_ptr().unwrap().i).to_be_bytes())
            }
            fn get_lex(a: Option<Vec<String>>) -> Self {
                Self { addr: get_nnn(a) }
            }
            fn check_symbols(&self) -> bool {
                match self.addr {
                    ArgSymbol::UnknownPointer(_) => true,
                    _ => false,
                }
            }
            fn get_symbols(&self) -> crate::bbu::USIWrap {
                let r = match self.addr {
                    ArgSymbol::UnknownPointer(ref a) => Some(vec![(a.clone(), 0)]),
                    _ => None,
                };
                r
            }
            fn get_length(&self) -> crate::bbu::SymbolPosition {
                CHIP8_INSTR_LEN
            }
            fn get_placeholder(&self) -> Vec<u8> {
                chip8_placeholder()
            }
            fn fulfill_symbol(&mut self, s: &T, p: crate::bbu::SymbolPosition) -> () {
                match p {
                    0 => {
                        self.addr = ArgSymbol::Pointer(Box::new(
                            s.into_ptr::<Chip8PtrSize, u16>(),
                        ))
                    }
                    _ => lpanic("c8r: unknown positional"),
                }
            }
        }
    };
}

// TODO: would it be more space-efficient to split the formation
//       and vec creation instructions into a function, so there's
//       only one copy of it in the code?
// NOTE: optimize
macro_rules! make_std_xnn {
    ($nm:ident,$offs:expr) => {
        #[allow(non_camel_case_types)]
        pub struct $nm {
            x: Chip8ArchReg,
            d: Chip8SymAlias,
        }
        impl<T: SymConv> ArchMcrInst<T> for $nm {
            fn get_output_bytes(&self) -> Vec<u8> {
                Vec::from(
                    ($offs | ((self.x.n as u16) << 8) | (self.d.unwrap_data().unwrap().i as u16))
                        .to_be_bytes(),
                )
            }
            fn get_lex(a: Option<Vec<String>>) -> Self {
                let b: (Chip8ArchReg, Chip8SymAlias) = get_xnn(a);
                Self { x: b.0, d: b.1 }
            }
            // TODO: better optimize this
            fn check_symbols(&self) -> bool {
                match self.d {
                    ArgSymbol::UnknownData(_) => true,
                    _ => false,
                }
            }
            fn get_symbols(&self) -> crate::bbu::USIWrap {
                match self.d {
                    ArgSymbol::UnknownData(ref a) => Some(vec![(a.clone(), 0)]),
                    _ => None,
                }
            }
            fn get_length(&self) -> crate::bbu::SymbolPosition {
                CHIP8_INSTR_LEN
            }
            fn get_placeholder(&self) -> Vec<u8> {
                chip8_placeholder()
            }
            fn fulfill_symbol(&mut self, s: &T, p: crate::bbu::SymbolPosition) -> () {
                match p {
                    0 => {
                        self.d =
                            ArgSymbol::Data(Box::new(s.into_ptr::<Chip8DatSize, u8>()))
                    }
                    _ => lpanic("c8r: unknown positional"),
                }
            }
        }
    };
}

// TODO: general for archinstruction, is vec best? could boxed slice work better?
macro_rules! make_std_xy {
    ($nm:ident,$offs:expr) => {
        #[allow(non_camel_case_types)]
        pub struct $nm {
            s: Chip8ArchReg,
            d: Chip8ArchReg,
        }
        impl<T: SymConv> ArchMcrInst<T> for $nm {
            fn get_output_bytes(&self) -> Vec<u8> {
                Vec::from(
                    ($offs | ((self.d.n as u16) << 8) | ((self.s.n as u16) << 4)).to_be_bytes(),
                )
            }
            fn get_lex(a: Option<Vec<String>>) -> Self {
                let b: (Chip8ArchReg, Chip8ArchReg) = get_xy(a);
                Self { s: b.0, d: b.1 }
            }
            // implementation is the same as for make_std_const
            fn check_symbols(&self) -> bool {
                false
            }
            fn get_symbols(&self) -> crate::bbu::USIWrap {
                None
            }
            fn get_length(&self) -> crate::bbu::SymbolPosition {
                CHIP8_INSTR_LEN
            }
            fn get_placeholder(&self) -> Vec<u8> {
                chip8_placeholder()
            }
            fn fulfill_symbol(&mut self, _s: &T, _p: crate::bbu::SymbolPosition) -> () {}
        }
    };
}

// TODO: create type names for each arg combo type to make tuples easier
// XYN = $N,%vX,%vY
macro_rules! make_std_xyn {
    ($nm:ident,$offs:expr) => {
        // TODO: in the future, let's stray away from needing Copy and Clone
        #[allow(non_camel_case_types)]
        pub struct $nm {
            n: Chip8SymAlias,
            x: Chip8ArchReg,
            y: Chip8ArchReg,
        }
        impl<T: SymConv> ArchMcrInst<T> for $nm {
            fn get_output_bytes(&self) -> Vec<u8> {
                // TODO: warn on overflow
                Vec::from(
                    ($offs
                        | ((self.x.n as u16) << 8)
                        | ((self.y.n as u16) << 4)
                        | ((self.n.unwrap_data().unwrap().i as u16) & 0xf))
                        .to_be_bytes(),
                )
            }
            fn get_lex(a: Option<Vec<String>>) -> Self {
                let b: (Chip8SymAlias, Chip8ArchReg, Chip8ArchReg) = get_xyn(a);
                Self {
                    n: b.0,
                    x: b.1,
                    y: b.2,
                }
            }
            fn check_symbols(&self) -> bool {
                match self.n {
                    ArgSymbol::UnknownData(_) => true,
                    _ => false,
                }
            }
            fn get_symbols(&self) -> crate::bbu::USIWrap {
                match self.n {
                    ArgSymbol::UnknownData(ref a) => Some(vec![(a.clone(), 0)]),
                    _ => None,
                }
            }
            fn get_length(&self) -> crate::bbu::SymbolPosition {
                CHIP8_INSTR_LEN
            }
            fn get_placeholder(&self) -> Vec<u8> {
                chip8_placeholder()
            }
            fn fulfill_symbol(&mut self, s: &T, p: crate::bbu::SymbolPosition) -> () {
                match p {
                    0 => {
                        self.n =
                            ArgSymbol::Data(Box::new(s.into_ptr::<Chip8DatSize, u8>()))
                    }
                    _ => lpanic("c8r: unknown positional"),
                }
            }
        }
    };
}

// named efx because all efx instructions start with 0xE or 0xF
// NOTE wish I had a macro for making these macros
macro_rules! make_std_efx {
    ($nm:ident,$offs:expr) => {
        #[allow(non_camel_case_types)]
        pub struct $nm {
            x: Chip8ArchReg,
        }
        impl<T: SymConv> ArchMcrInst<T> for $nm {
            fn get_output_bytes(&self) -> Vec<u8> {
                Vec::from(($offs | ((self.x.n as u16) << 8)).to_be_bytes())
            }
            fn get_lex(a: Option<Vec<String>>) -> Self {
                Self { x: get_efx(a) }
            }
            // implementation is the same as for make_std_const as well
            fn check_symbols(&self) -> bool {
                false
            }
            fn get_symbols(&self) -> crate::bbu::USIWrap {
                None
            }
            fn get_length(&self) -> crate::bbu::SymbolPosition {
                CHIP8_INSTR_LEN
            }
            fn get_placeholder(&self) -> Vec<u8> {
                chip8_placeholder()
            }
            fn fulfill_symbol(&mut self, _s: &T, _p: crate::bbu::SymbolPosition) -> () {}
        }
    };
}

make_std_nnn!(Chip8_0NNN, 0u16);
make_std_const!(Chip8_00E0, 0xe0u16);
make_std_const!(Chip8_00EE, 0xeeu16);
make_std_nnn!(Chip8_1NNN, 0x1000u16);
make_std_nnn!(Chip8_2NNN, 0x2000u16);
make_std_xnn!(Chip8_3XNN, 0x3000u16);
make_std_xnn!(Chip8_4XNN, 0x4000u16);
make_std_xy!(Chip8_5XY0, 0x5000u16);
make_std_xnn!(Chip8_6XNN, 0x6000u16);
make_std_xnn!(Chip8_7XNN, 0x7000u16);
make_std_xy!(Chip8_8XY0, 0x8000u16);
make_std_xy!(Chip8_8XY1, 0x8001u16);
make_std_xy!(Chip8_8XY2, 0x8002u16);
make_std_xy!(Chip8_8XY3, 0x8003u16);
make_std_xy!(Chip8_8XY4, 0x8004u16);
make_std_xy!(Chip8_8XY5, 0x8005u16);
make_std_xy!(Chip8_8XY6, 0x8006u16);
make_std_xy!(Chip8_8XY7, 0x8007u16);
make_std_xy!(Chip8_8XYE, 0x800eu16);
make_std_xy!(Chip8_9XY0, 0x9000u16);
make_std_nnn!(Chip8_ANNN, 0xa000u16);
make_std_nnn!(Chip8_BNNN, 0xb000u16);
make_std_xnn!(Chip8_CXNN, 0xc000u16);
make_std_xyn!(Chip8_DXYN, 0xd000u16);
make_std_efx!(Chip8_EX9E, 0xe09eu16);
make_std_efx!(Chip8_EXA1, 0xe0a1u16);
make_std_efx!(Chip8_FX07, 0xf007u16);
make_std_efx!(Chip8_FX0A, 0xf00au16);
make_std_efx!(Chip8_FX15, 0xf015u16);
make_std_efx!(Chip8_FX18, 0xf018u16);
make_std_efx!(Chip8_FX1E, 0xf01eu16);
make_std_efx!(Chip8_FX29, 0xf029u16);
make_std_efx!(Chip8_FX33, 0xf033u16);
make_std_efx!(Chip8_FX55, 0xf055u16);
make_std_efx!(Chip8_FX65, 0xf065u16);

// FIXME: switch to argcheck
// TODO condense similarly to get_xnn
fn get_nnn(a: Option<Vec<String>>) -> Chip8SymAlias {
    if let Some(ref i) = a {
        if i.len() != 1 {
            lpanic("c8r: wrong arg count")
        }
        let b: Chip8Arg = crate::bbu::parse_arg(&a.unwrap()[0]).unwrap();
        // TODO: avoid this clone in the future
        b.unwrap_memory().unwrap().v.clone()
    } else {
        lpanic("c8r: not enough args")
    }
}

// this logic structure is repeated a lot
// TODO consider condensing it somehow
fn get_xnn(a: Option<Vec<String>>) -> (Chip8ArchReg, Chip8SymAlias) {
    let b: Vec<Chip8Arg> = argcheck(&a, 2);
    (
        *b[1].unwrap_register().unwrap().reg,
        // TODO: also avoid this clone
        b[0].unwrap_direct().unwrap().clone(),
    )
    /*
    if let Some(ref i) = a {
        if i.len() != 2 {
            lpanic("c8r: not enough args")
        }
        // TODO: move these directly in
        // data
        let b: Chip8Arg = crate::bbu::parse_arg(&a.as_ref().unwrap()[0]).unwrap();
        // register X
        let c: Chip8Arg = crate::bbu::parse_arg(&a.as_ref().unwrap()[1]).unwrap();
        (
            *c.unwrap_register().unwrap().reg,
            // TODO: also avoid this clone
            b.unwrap_direct().unwrap().clone(),
        )
    } else {
        lpanic("c8r: not enough args")
    }*/
}

// NOTE: is tuple the best option here? Would an array be better?
fn get_xy(a: Option<Vec<String>>) -> (Chip8ArchReg, Chip8ArchReg) {
    //if let Some(ref i) = a {
    //    if i.len() != 2 {
    //        panic!("c8r: not enough args")
    //    }
    let b: Vec<Chip8Arg> = argcheck(&a, 2);
    (
        *b[0].unwrap_register().unwrap().reg,
        *b[1].unwrap_register().unwrap().reg,
    )
    //} else {
    //    panic!("c8r: not enough args")
    //}
}

// res.0 limited to 4 bits
fn get_xyn(a: Option<Vec<String>>) -> (Chip8SymAlias, Chip8ArchReg, Chip8ArchReg) {
    let b: Vec<Chip8Arg> = argcheck(&a, 3);
    (
        // TODO FIXME: get rid of the clones!!
        b[0].unwrap_direct().unwrap().clone(),
        *b[1].unwrap_register().unwrap().reg,
        *b[2].unwrap_register().unwrap().reg,
    )
}

fn get_efx(a: Option<Vec<String>>) -> Chip8ArchReg {
    let b: Vec<Chip8Arg> = argcheck(&a, 1);
    *b[0].unwrap_register().unwrap().reg
}

// TODO: make this a utility public function
// TODO: better error handling (log)
// TODO: dedup panic message
fn argcheck(a: &Option<Vec<String>>, i: usize) -> Vec<Chip8Arg> {
    if let Some(ref b) = a {
        if b.len() != i {
            lpanic("argument check failed")
        } else {
            Vec::from_iter(b.into_iter().map(|x| crate::bbu::parse_arg(&x).unwrap()))
        }
    } else {
        lpanic("argument check failed")
    }
}

// TODO genericize for LE, BE

// TODO FIXME NOTE: throw warnings when number is truncated!

macro_rules! gmm {
    ($n:ident,$i:ident) => {{
        Box::new(<crate::bbu::$n as ArchMcrInst<Chip8Symbol>>::get_lex(
            $i.args,
        ))
    }};
}

// TODO: consider putting these in lexer maybe? idk
// TODO FIXME: add symbols to macros
pub fn get_macro<T: SymConv>(i: crate::parser::ParsedMacro) -> Box<dyn ArchMcrInst<T>> {
    match i.mcr.to_lowercase().as_str() {
        "byte" => gmm!(Bu8, i),
        "word" => gmm!(Bu16, i),
        _ => lpanic("macro not supported"),
    }
}