0
0
mirror of https://github.com/netwide-assembler/nasm.git synced 2025-10-10 00:25:06 -04:00

asm: better error messages for missing instructions

The assembler can't know if something is a colonless label or a
misspelled instruction, so print both when complaining about a missing
instruction.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
This commit is contained in:
H. Peter Anvin
2025-09-29 16:09:04 -07:00
parent fec865e75e
commit 12f6270124
6 changed files with 26 additions and 16 deletions

View File

@@ -755,6 +755,7 @@ insn *parse_line(char *buffer, insn *result, const int bits)
int opnum;
bool critical;
bool first;
bool colonless_label;
bool recover;
bool far_jmp_ok;
bool have_prefixes;
@@ -764,6 +765,7 @@ insn *parse_line(char *buffer, insn *result, const int bits)
restart_parse:
first = true;
colonless_label = false;
stdscan_reset(buffer);
i = stdscan(NULL, &tokval);
@@ -785,6 +787,7 @@ restart_parse:
first = false;
result->label = tokval.t_charptr;
i = stdscan(NULL, &tokval);
colonless_label = i != ':';
if (i == ':') { /* skip over the optional colon */
i = stdscan(NULL, &tokval);
} else if (i == 0) {
@@ -864,7 +867,14 @@ restart_parse:
set_imm_flags(&result->oprs[0], result->opt);
}
} else if (!first) {
nasm_nonfatal("instruction expected, found `%.*s'",
/*
* What was meant to be an instruction may very well have
* been mistaken for a label here, so print out both, unless
* it is unambiguous.
*/
nasm_nonfatal("instruction expected, found `%s%s%.*s'",
colonless_label ? result->label : "",
colonless_label ? " " : "",
tokval.t_len, tokval.t_start);
} else if (!result->label) {
nasm_nonfatal("label, instruction or prefix expected at start of line, found `%.*s'",

View File

@@ -2,5 +2,5 @@
bits 64
vpternlogd zmm3, zmm4, zmm5, (A|b)&C
vptermlogd zmm3, zmm4, zmm5, (A|b)&C
vpternlogq zmm3, zmm4, zmm5, (a|B)&c

View File

@@ -113,7 +113,7 @@ if args.cmd == None:
def read_stdfile(path):
with open(path, "rb") as f:
data = f.read().decode("utf-8")
data = f.read().decode("utf-8","replace")
f.close()
return data
@@ -178,7 +178,7 @@ def read_json(path):
try:
with open(path, "rb") as f:
try:
desc = json.loads(f.read().decode("utf-8"))
desc = json.loads(f.read().decode("utf-8","replace"))
except:
desc = None
finally:
@@ -376,8 +376,8 @@ def exec_nasm(desc):
#
# FIXME: For now 4M buffer is enough but
# better provide reading in a cycle.
stderr = pnasm.stderr.read(4194304).decode("utf-8")
stdout = pnasm.stdout.read(4194304).decode("utf-8")
stderr = pnasm.stderr.read(4194304).decode("utf-8","replace")
stdout = pnasm.stdout.read(4194304).decode("utf-8","replace")
pnasm.stdout.close()
pnasm.stderr.close()

View File

@@ -4,24 +4,24 @@
./travis/test/br3392531.asm:5: error: instruction expected, found `&'
./travis/test/br3392531.asm:7: error: `%macro' expects a parameter count
./travis/test/br3392531.asm:11: warning: unterminated string (missing ``') [-w+pp-open-string]
./travis/test/br3392531.asm:14: error: instruction expected, found `%'
./travis/test/br3392531.asm:14: error: instruction expected, found `<EFBFBD> %'
./travis/test/br3392531.asm:17: error: `%$LRG': context stack is empty
./travis/test/br3392531.asm:17: error: `%$LRG': context stack is empty
./travis/test/br3392531.asm:17: error: label, instruction or prefix expected at start of line, found `%'
./travis/test/br3392531.asm:18: error: label, instruction or prefix expected at start of line, found `'
./travis/test/br3392531.asm:19: error: instruction expected, found `a'
./travis/test/br3392531.asm:19: error: instruction expected, found `is a'
./travis/test/br3392531.asm:20: error: `%1': not in a macro call
./travis/test/br3392531.asm:20: error: label, instruction or prefix expected at start of line, found `>'
./travis/test/br3392531.asm:21: error: label, instruction or prefix expected at start of line, found `1'
./travis/test/br3392531.asm:8: ... from macro `section' defined here
./travis/test/br3392531.asm:21: error: instruction expected, found `/'
./travis/test/br3392531.asm:21: error: instruction expected, found `J /'
./travis/test/br3392531.asm:9: ... from macro `section' defined here
./travis/test/br3392531.asm:21: error: label, instruction or prefix expected at start of line, found `?'
./travis/test/br3392531.asm:10: ... from macro `section' defined here
./travis/test/br3392531.asm:21: error: invalid macro parameter: `%4stru@namB'
./travis/test/br3392531.asm:11: ... from macro `section' defined here
./travis/test/br3392531.asm:21: error: instruction expected, found `&'
./travis/test/br3392531.asm:21: error: instruction expected, found `gesb &'
./travis/test/br3392531.asm:11: ... from macro `section' defined here
./travis/test/br3392531.asm:21: error: `%unmacro' expects a parameter count
./travis/test/br3392531.asm:12: ... from macro `section' defined here
./travis/test/br3392531.asm:22: error: instruction expected, found `pOo'
./travis/test/br3392531.asm:22: error: instruction expected, found `epush pOo'

View File

@@ -8,7 +8,7 @@
./travis/test/br3392716.asm:15: warning: unterminated string (missing `'') [-w+pp-open-string]
./travis/test/br3392716.asm:20: warning: unterminated string (missing `'') [-w+pp-open-string]
./travis/test/br3392716.asm:20: warning: multi-line macro `sst' exists, but not taking 1 parameter [-w+pp-macro-params-multi]
./travis/test/br3392716.asm:20: error: instruction expected, found `1'
./travis/test/br3392716.asm:20: error: instruction expected, found `sst 1'
./travis/test/br3392716.asm:21: error: `%%cTo': not in a macro call
./travis/test/br3392716.asm:21: error: label, instruction or prefix expected at start of line, found `%'
./travis/test/br3392716.asm:6: ... from macro `sst' defined here
@@ -16,7 +16,7 @@
./travis/test/br3392716.asm:7: ... from macro `sst' defined here
./travis/test/br3392716.asm:21: error: label, instruction or prefix expected at start of line, found `%'
./travis/test/br3392716.asm:8: ... from macro `sst' defined here
./travis/test/br3392716.asm:21: error: instruction expected, found `sst'
./travis/test/br3392716.asm:21: error: instruction expected, found `s sst'
./travis/test/br3392716.asm:10: ... from macro `sst' defined here
./travis/test/br3392716.asm:21: error: label, instruction or prefix expected at start of line, found `%'
./travis/test/br3392716.asm:11: ... from macro `sst' defined here
@@ -24,10 +24,10 @@
./travis/test/br3392716.asm:12: ... from macro `sst' defined here
./travis/test/br3392716.asm:21: error: label, instruction or prefix expected at start of line, found `%'
./travis/test/br3392716.asm:13: ... from macro `sst' defined here
./travis/test/br3392716.asm:21: error: instruction expected, found `1'
./travis/test/br3392716.asm:21: error: instruction expected, found `sst 1'
./travis/test/br3392716.asm:15: ... from macro `sst' defined here
./travis/test/br3392716.asm:21: error: `%macro' expects a macro name
./travis/test/br3392716.asm:16: ... from macro `sst' defined here
./travis/test/br3392716.asm:21: error: instruction expected, found `'
./travis/test/br3392716.asm:21: error: instruction expected, found `s '
./travis/test/br3392716.asm:17: ... from macro `sst' defined here
./travis/test/br3392716.asm:22: error: label, instruction or prefix expected at start of line, found `%'

View File

@@ -1 +1 @@
./travis/test/org.asm:5: error: instruction expected, found `0xffffffffffff0000'
./travis/test/org.asm:5: error: instruction expected, found `org 0xffffffffffff0000'