diff mbox series

[13/18] asm: use parse_asm_constraint() to verify constraints

Message ID 20190927234322.5157-16-luc.vanoostenryck@gmail.com (mailing list archive)
State Mainlined, archived
Headers show
Series add missing expansion of ASM operands | expand

Commit Message

Luc Van Oostenryck Sept. 27, 2019, 11:43 p.m. UTC
In extended ASM statements, output constraints need to be
prefixed with "=" or "+" and input constraints must not. This
is checked in verify_{output,input}_constraint() where the
constraint string is analyzed to look after these two chars.

However, the needed information is now already available thanks
to parse_asm_constraint().

So, use the result of the parsing of the constraint strings to
avoid to analyze again these strings during their verification.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 evaluate.c | 35 +++++++++++++++--------------------
 1 file changed, 15 insertions(+), 20 deletions(-)
diff mbox series

Patch

diff --git a/evaluate.c b/evaluate.c
index 4c5c2c255..f0f9b4b34 100644
--- a/evaluate.c
+++ b/evaluate.c
@@ -3561,24 +3561,22 @@  static void parse_asm_constraint(struct asm_operand *op)
 		op->is_memory = 0;
 }
 
-static void verify_output_constraint(struct expression *expr, const char *constraint)
+static void verify_output_constraint(struct asm_operand *op)
 {
-	switch (*constraint) {
-	case '=':	/* Assignment */
-	case '+':	/* Update */
-		break;
-	default:
+	struct expression *expr = op->constraint;
+	const char *constraint = expr->string->data;
+
+	if (!op->is_assign)
 		expression_error(expr, "output constraint is not an assignment constraint (\"%s\")", constraint);
-	}
 }
 
-static void verify_input_constraint(struct expression *expr, const char *constraint)
+static void verify_input_constraint(struct asm_operand *op)
 {
-	switch (*constraint) {
-	case '=':	/* Assignment */
-	case '+':	/* Update */
+	struct expression *expr = op->constraint;
+	const char *constraint = expr->string->data;
+
+	if (op->is_assign)
 		expression_error(expr, "input constraint with assignment (\"%s\")", constraint);
-	}
 }
 
 static void evaluate_asm_statement(struct statement *stmt)
@@ -3587,18 +3585,16 @@  static void evaluate_asm_statement(struct statement *stmt)
 	struct asm_operand *op;
 	struct symbol *sym;
 
-	expr = stmt->asm_string;
-	if (!expr)
+	if (!stmt->asm_string)
 		return;
 
 	FOR_EACH_PTR(stmt->asm_outputs, op) {
 		/* Identifier */
 
 		/* Constraint */
-		expr = op->constraint;
-		if (expr) {
+		if (op->constraint) {
 			parse_asm_constraint(op);
-			verify_output_constraint(expr, expr->string->data);
+			verify_output_constraint(op);
 		}
 
 		/* Expression */
@@ -3614,10 +3610,9 @@  static void evaluate_asm_statement(struct statement *stmt)
 		/* Identifier */
 
 		/* Constraint */
-		expr = op->constraint;
-		if (expr) {
+		if (op->constraint) {
 			parse_asm_constraint(op);
-			verify_input_constraint(expr, expr->string->data);
+			verify_input_constraint(op);
 		}
 
 		/* Expression */