Add helper proc to clean up the word/byte keyword

This commit is contained in:
Joseph Ferano 2025-03-13 17:50:32 +07:00
parent 460e1a8700
commit 3dca2254e1

View File

@ -143,6 +143,11 @@ get_i16 :: proc(data: []u8) -> i16 {
return (i16)(data[1]) << 8 | (i16)(data[0])
}
operand_is :: proc($T: typeid, opr: Operand) -> bool {
_, ok := opr.(T)
return ok
}
calculate_effective_address :: proc(r_m: u8) -> string {
val: string
switch r_m {
@ -527,13 +532,11 @@ main :: proc() {
src_opr = parse_operand(inst, inst.src, data[idx:], &processed, word, has_segment)
// TODO: This is ugly as hell
_,ok_1 := src_opr.(Immediate8)
_,ok_2 := src_opr.(Immediate16)
_,ok_3 := dst_opr.(MemoryAddr);
_,ok_4 := dst_opr.(DirectAddress);
is_imm := operand_is(Immediate8, src_opr) || operand_is(Immediate16, src_opr)
is_bracketed := operand_is(MemoryAddr, dst_opr) || operand_is(DirectAddress, dst_opr)
shiftrot := inst.src == .ShiftRotate
size_string := ""
if ((ok_1 || ok_2) && (ok_3 || ok_4)) || ((ok_3 || ok_4) && shiftrot) {
if ((is_imm && is_bracketed) || (is_bracketed && shiftrot)) {
size_string = word ? "word " : "byte "
}