diff --git a/assemble.c b/assemble.c index 9490aa4..111447c 100644 --- a/assemble.c +++ b/assemble.c @@ -450,6 +450,7 @@ static int assemble( { ADDR_MODE mode; int islocal; + char *error; label = get_symbol(cp, &cp, &islocal); if (label == NULL) { @@ -459,8 +460,9 @@ static int assemble( cp = skipdelim(cp); - if (!get_mode(cp, &cp, &mode)) { - report(stack->top, "Bad .NTYPE addressing mode\n"); + if (!get_mode(cp, &cp, &mode, &error)) { + report(stack->top, + "Bad .NTYPE addressing mode (%s)\n", error); free(label); return 0; } @@ -1349,9 +1351,11 @@ static int assemble( /* One general addressing mode */ { ADDR_MODE mode; unsigned word; + char *error; - if (!get_mode(cp, &cp, &mode)) { - report(stack->top, "Invalid addressing mode\n"); + if (!get_mode(cp, &cp, &mode, &error)) { + report(stack->top, + "Invalid addressing mode (%s)\n", error); return 0; } @@ -1372,9 +1376,12 @@ static int assemble( ADDR_MODE left, right; unsigned word; + char *error; - if (!get_mode(cp, &cp, &left)) { - report(stack->top, "Invalid addressing mode (1st operand)\n"); + if (!get_mode(cp, &cp, &left, &error)) { + report(stack->top, + "Invalid addressing mode (1st operand: %s)\n", + error); return 0; } @@ -1385,8 +1392,10 @@ static int assemble( return 0; } - if (!get_mode(cp, &cp, &right)) { - report(stack->top, "Invalid addressing mode (2nd operand)\n"); + if (!get_mode(cp, &cp, &right, &error)) { + report(stack->top, + "Invalid addressing mode (2nd operand: %s)\n", + error); free_addr_mode(&left); return 0; } @@ -1529,9 +1538,12 @@ static int assemble( EX_TREE *value; unsigned reg; unsigned word; + char *error; - if (!get_mode(cp, &cp, &mode)) { - report(stack->top, "Invalid addressing mode (1st operand)\n"); + if (!get_mode(cp, &cp, &mode, &error)) { + report(stack->top, + "Invalid addressing mode (1st operand: %s)\n", + error); return 0; } @@ -1566,6 +1578,7 @@ static int assemble( EX_TREE *value; unsigned reg; unsigned word; + char *error; value = parse_expr(cp, 0); cp = value->cp; @@ -1583,8 +1596,10 @@ static int assemble( return 0; } - if (!get_mode(cp, &cp, &mode)) { - report(stack->top, "Invalid addressing mode (2nd operand)\n"); + if (!get_mode(cp, &cp, &mode, &error)) { + report(stack->top, + "Invalid addressing mode (2nd operand: %s)\n", + error); free_tree(value); return 0; } @@ -1651,15 +1666,20 @@ static int assemble( EX_TREE *value; unsigned reg; unsigned word; + char *error; if ((op->flags & OC_MASK) == OC_FPP_FSRCAC) { - if (!get_fp_src_mode(cp, &cp, &mode)) { - report(stack->top, "Invalid addressing mode (1st operand, fsrc)\n"); + if (!get_fp_src_mode(cp, &cp, &mode, &error)) { + report(stack->top, + "Invalid addressing mode (1st operand, fsrc: %s)\n", + error); return 0; } } else { - if (!get_mode(cp, &cp, &mode)) { - report(stack->top, "Invalid addressing mode (1st operand)\n"); + if (!get_mode(cp, &cp, &mode, &error)) { + report(stack->top, + "Invalid addressing mode (1st operand: %s)\n", + error); return 0; } } @@ -1698,6 +1718,7 @@ static int assemble( EX_TREE *value; unsigned reg; unsigned word; + char *error; value = parse_expr(cp, 0); cp = value->cp; @@ -1715,8 +1736,10 @@ static int assemble( return 0; } - if (!get_mode(cp, &cp, &mode)) { - report(stack->top, "Invalid addressing mode (2nd operand)\n"); + if (!get_mode(cp, &cp, &mode, &error)) { + report(stack->top, + "Invalid addressing mode (2nd operand: %s)\n", + error); free_tree(value); return 0; } diff --git a/parse.c b/parse.c index 5508c27..5fcd604 100644 --- a/parse.c +++ b/parse.c @@ -188,7 +188,8 @@ SYMBOL *get_op( int get_mode( char *cp, char **endp, - ADDR_MODE *mode) + ADDR_MODE *mode, + char **error) { EX_TREE *value; @@ -211,7 +212,11 @@ int get_mode( mode->offset = parse_expr(cp, 0); if (endp) *endp = mode->offset->cp; - return expr_ok(mode->offset); + int ok = expr_ok(mode->offset); + if (!ok) { + *error = "Invalid expression after '#'"; + } + return ok; } /* Check for -(Rn) */ @@ -225,7 +230,13 @@ int get_mode( /* It's -(Rn) */ value = parse_expr(tcp, 0); reg = get_register(value); - if (reg == NO_REG || (tcp = skipwhite(value->cp), *tcp++ != ')')) { + if (reg == NO_REG) { + *error = "Register expected after '-('"; + free_tree(value); + return FALSE; + } + if (tcp = skipwhite(value->cp), *tcp++ != ')') { + *error = "')' expected after register"; free_tree(value); return FALSE; } @@ -245,7 +256,13 @@ int get_mode( value = parse_expr(cp + 1, 0); reg = get_register(value); - if (reg == NO_REG || (tcp = skipwhite(value->cp), *tcp++ != ')')) { + if (reg == NO_REG) { + *error = "Register expected after '('"; + free_tree(value); + return FALSE; + } + if (tcp = skipwhite(value->cp), *tcp++ != ')') { + *error = "')' expected after register"; free_tree(value); return FALSE; } @@ -281,8 +298,10 @@ int get_mode( mode->offset = parse_expr(cp, 0); - if (!expr_ok(mode->offset)) + if (!expr_ok(mode->offset)) { + *error = "Invalid expression"; return FALSE; + } cp = skipwhite(mode->offset->cp); @@ -292,7 +311,13 @@ int get_mode( /* indirect register plus offset */ value = parse_expr(cp + 1, 0); reg = get_register(value); - if (reg == NO_REG || (cp = skipwhite(value->cp), *cp++ != ')')) { + if (reg == NO_REG) { + *error = "Register expected after 'offset('"; + free_tree(value); + return FALSE; /* Syntax error in addressing mode */ + } + if (cp = skipwhite(value->cp), *cp++ != ')') { + *error = "')' expected after 'offset(register'"; free_tree(value); return FALSE; /* Syntax error in addressing mode */ } @@ -345,7 +370,8 @@ int get_mode( int get_fp_src_mode( char *cp, char **endp, - ADDR_MODE *mode) + ADDR_MODE *mode, + char **error) { cp = skipwhite(cp); @@ -374,7 +400,7 @@ int get_fp_src_mode( } } - int ret = get_mode(savecp, endp, mode); + int ret = get_mode(savecp, endp, mode, error); return ret; } diff --git a/parse.h b/parse.h index 62e60df..ea81f6b 100644 --- a/parse.h +++ b/parse.h @@ -39,11 +39,13 @@ char *get_symbol( int get_mode( char *cp, char **endp, - ADDR_MODE *mode); + ADDR_MODE *mode, + char **error); int get_fp_src_mode( char *cp, char **endp, - ADDR_MODE *mode); + ADDR_MODE *mode, + char **error); EX_TREE *parse_expr( char *cp, diff --git a/tests/test-float.lst.ok b/tests/test-float.lst.ok index bb1e919..c0b3904 100644 --- a/tests/test-float.lst.ok +++ b/tests/test-float.lst.ok @@ -141,12 +141,12 @@ 118 000410 172127 000001 addf #^D1,ac1 ; literally 119 000414 173027 000001 subf #<1>,ac0 ; literally 120 000420 172127 000002 addf #<1+1>,ac1 ; literally -test-float.mac:121: ***ERROR Invalid addressing mode (1st operand, fsrc) +test-float.mac:121: ***ERROR Invalid addressing mode (1st operand, fsrc: Invalid expression after '#') 121 subf #<1.0>,ac0 ; error 122 000424 172127 040300 addf #1.5,ac1 ; as float 123 000430 172127 140263 addd #-1.4,ac1 ; as float 124 000434 173027 040200 subf #<^F 1.0>,ac0 ; as float -test-float.mac:125: ***ERROR Invalid addressing mode (1st operand, fsrc) +test-float.mac:125: ***ERROR Invalid addressing mode (1st operand, fsrc: Invalid expression after '#') 125 subf #<^D 1.0>,ac0 ; error 126 000440 173027 000001 subf #<^D 1>,ac0 ; literally 127 000444 173027 000002 subf #^D<1+1>,ac0 ; literally @@ -159,7 +159,7 @@ test-float.mac:130: ***ERROR Invalid syntax (comma expected) 133 000460 173027 000001 subf #a,ac0 ; a interpreted as bit pattern 134 000464 173027 000001 subf #,ac0 ; a interpreted as bit pattern 135 000470 173027 000003 subf #e3,ac0 ; e3 is the label -test-float.mac:136: ***ERROR Invalid addressing mode (1st operand, fsrc) +test-float.mac:136: ***ERROR Invalid addressing mode (1st operand, fsrc: Invalid expression after '#') 136 subf #<1e3>,ac0 ; error N 137 test-float.mac:138: ***ERROR Junk at end of line ('5 ; bad: ') diff --git a/tests/test-operands.lst.ok b/tests/test-operands.lst.ok index bbef52f..7f410d7 100644 --- a/tests/test-operands.lst.ok +++ b/tests/test-operands.lst.ok @@ -39,11 +39,11 @@ test-operands.mac:27: ***ERROR Instruction requires simple literal operand test-operands.mac:32: ***ERROR Junk at end of line (',(r0) ; bad ') 32 000042 005700 tst r0,(r0) ; bad -test-operands.mac:33: ***ERROR Invalid addressing mode +test-operands.mac:33: ***ERROR Invalid addressing mode (Invalid expression) 33 tst @ ; bad -test-operands.mac:34: ***ERROR Invalid addressing mode +test-operands.mac:34: ***ERROR Invalid addressing mode (Invalid expression) 34 tst %77 ; bad -test-operands.mac:35: ***ERROR Invalid addressing mode +test-operands.mac:35: ***ERROR Invalid addressing mode (Invalid expression) 35 tst <> ; bad 36 37 ; OC_2GEN @@ -52,11 +52,11 @@ test-operands.mac:35: ***ERROR Invalid addressing mode test-operands.mac:40: ***ERROR Junk at end of line (',r2 ; bad ') 40 000046 060001 add r0,r1,r2 ; bad -test-operands.mac:41: ***ERROR Invalid addressing mode (1st operand) +test-operands.mac:41: ***ERROR Invalid addressing mode (1st operand: Invalid expression) 41 add @ ; bad test-operands.mac:42: ***ERROR Invalid syntax (comma expected) 42 add r0 r1 ; bad -test-operands.mac:43: ***ERROR Invalid addressing mode (2nd operand) +test-operands.mac:43: ***ERROR Invalid addressing mode (2nd operand: Invalid expression) 43 add r0,@ ; bad 44 45 ; OC_BR @@ -97,7 +97,7 @@ test-operands.mac:65: ***ERROR Invalid addressing mode (register expected) test-operands.mac:71: ***ERROR Junk at end of line (',r1 ; bad ') 71 000102 072027 000003 ash #3,r0,r1 ; bad -test-operands.mac:72: ***ERROR Invalid addressing mode (1st operand) +test-operands.mac:72: ***ERROR Invalid addressing mode (1st operand: Invalid expression) 72 ash ; bad test-operands.mac:73: ***ERROR Invalid syntax (comma expected) 73 ash #3 ; bad @@ -118,9 +118,9 @@ test-operands.mac:75: ***ERROR Invalid addressing mode (2nd operand: register ex test-operands.mac:86: ***ERROR Junk at end of line (',ac1 ; bad ') 86 000112 171111 mulf (r1),ac1,ac1 ; bad -test-operands.mac:87: ***ERROR Invalid addressing mode (1st operand, fsrc) +test-operands.mac:87: ***ERROR Invalid addressing mode (1st operand, fsrc: Invalid expression) 87 mulf ; bad -test-operands.mac:88: ***ERROR Invalid addressing mode (1st operand, fsrc) +test-operands.mac:88: ***ERROR Invalid addressing mode (1st operand, fsrc: Register expected after '(') 88 mulf ( ; bad test-operands.mac:89: ***ERROR Invalid syntax (comma expected) 89 mulf (r1) ; bad