mirror of
https://github.com/hsoft/collapseos.git
synced 2024-11-27 14:18:06 +11:00
zasm: begin erroring out reliably
Up until now, invalid source input had undefined behavior. We're now beginning to define that behavior so that zasm can be a bit more usable.
This commit is contained in:
parent
976a93971c
commit
af2c561c6b
@ -15,6 +15,10 @@
|
|||||||
.equ ZASM_ORG ZASM_CTX_PC+2
|
.equ ZASM_ORG ZASM_CTX_PC+2
|
||||||
.equ ZASM_RAMEND ZASM_ORG+2
|
.equ ZASM_RAMEND ZASM_ORG+2
|
||||||
|
|
||||||
|
; *** Errors ***
|
||||||
|
; Unknown instruction or directive
|
||||||
|
.equ ERR_UNKWN 0x01
|
||||||
|
|
||||||
; Read file through blockdev ID in H and outputs its upcodes through blockdev
|
; Read file through blockdev ID in H and outputs its upcodes through blockdev
|
||||||
; ID in L.
|
; ID in L.
|
||||||
zasmMain:
|
zasmMain:
|
||||||
@ -98,7 +102,7 @@ zasmParseFile:
|
|||||||
; resulting opcode(s) through ioPutC and increases (IO_PC) by the number of
|
; resulting opcode(s) through ioPutC and increases (IO_PC) by the number of
|
||||||
; bytes written. BC is set to the result of the call to tokenize.
|
; bytes written. BC is set to the result of the call to tokenize.
|
||||||
; Sets Z if parse was successful, unset if there was an error. EOF is not an
|
; Sets Z if parse was successful, unset if there was an error. EOF is not an
|
||||||
; error.
|
; error. If there is an error, A is set to the corresponding error code (ERR_*).
|
||||||
parseLine:
|
parseLine:
|
||||||
call tokenize
|
call tokenize
|
||||||
ld a, b ; TOK_*
|
ld a, b ; TOK_*
|
||||||
@ -109,9 +113,10 @@ parseLine:
|
|||||||
cp TOK_LABEL
|
cp TOK_LABEL
|
||||||
jr z, _parseLabel
|
jr z, _parseLabel
|
||||||
cp TOK_EOF
|
cp TOK_EOF
|
||||||
ret ; Z is correct. If EOF, Z is set and not an
|
ret z ; We're finished, no error.
|
||||||
; error, otherwise, it means bad token and
|
; Bad token
|
||||||
; errors out.
|
ld a, ERR_UNKWN
|
||||||
|
jp unsetZ ; return with Z unset
|
||||||
|
|
||||||
_parseInstr:
|
_parseInstr:
|
||||||
ld a, c ; I_*
|
ld a, c ; I_*
|
||||||
|
Binary file not shown.
@ -188,9 +188,10 @@ int main()
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
#ifdef DEBUG
|
int res = cpu.R1.br.A;
|
||||||
fprintf(stderr, "Ended with A=%d DE=%d\n", cpu.R1.br.A, cpu.R1.wr.DE);
|
if (res != 0) {
|
||||||
#endif
|
fprintf(stderr, "Error %d\n", res);
|
||||||
return 0;
|
}
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
20
tools/tests/zasm/errtests.sh
Executable file
20
tools/tests/zasm/errtests.sh
Executable file
@ -0,0 +1,20 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# no "set -e" because we test errors
|
||||||
|
|
||||||
|
ZASM=../../emul/zasm/zasm
|
||||||
|
|
||||||
|
chkerr() {
|
||||||
|
echo "Check that '$1' results in error $2"
|
||||||
|
${ZASM} <<< $1 > /dev/null
|
||||||
|
local res=$?
|
||||||
|
if [[ $res == $2 ]]; then
|
||||||
|
echo "Good!"
|
||||||
|
else
|
||||||
|
echo "$res != $2"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
chkerr "foo" 1
|
||||||
|
|
@ -23,7 +23,7 @@ cmpas() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
for fn in *.asm; do
|
for fn in test*.asm; do
|
||||||
echo "Comparing ${fn}"
|
echo "Comparing ${fn}"
|
||||||
cmpas $fn
|
cmpas $fn
|
||||||
done
|
done
|
||||||
@ -34,3 +34,4 @@ while read line; do
|
|||||||
cmpas ${TMPFILE}
|
cmpas ${TMPFILE}
|
||||||
done
|
done
|
||||||
|
|
||||||
|
./errtests.sh
|
||||||
|
Loading…
Reference in New Issue
Block a user