summaryrefslogtreecommitdiffhomepage
path: root/ir/be/beasm.c
diff options
context:
space:
mode:
authorChristoph Mallon <christoph.mallon@gmx.de>2017-01-02 12:48:31 +0100
committerChristoph Mallon <christoph.mallon@gmx.de>2017-01-02 17:17:45 +0100
commit0ef4ba0904d9c98f06983ed3ce19f31e9c33ff2f (patch)
tree481c95b9db778948d4386488ef36a906da622717 /ir/be/beasm.c
parent322b94204215bd737557e069882c173840c8227e (diff)
be: Factor out code to check, whether the kind of an asm constraint is valid of the given modifier.
Diffstat (limited to 'ir/be/beasm.c')
-rw-r--r--ir/be/beasm.c24
1 files changed, 23 insertions, 1 deletions
diff --git a/ir/be/beasm.c b/ir/be/beasm.c
index dee9676..400aa73 100644
--- a/ir/be/beasm.c
+++ b/ir/be/beasm.c
@@ -360,7 +360,7 @@ void be_emit_asm(ir_node const *const asmn, be_emit_asm_operand_func *const emit
be_emit_write_line();
}
-char const *be_get_constraint_name(be_asm_operand_kind_t const kind)
+static char const *be_get_constraint_name(be_asm_operand_kind_t const kind)
{
switch (kind) {
case BE_ASM_OPERAND_INVALID: return "invalid";
@@ -371,3 +371,25 @@ char const *be_get_constraint_name(be_asm_operand_kind_t const kind)
}
panic("invalid constraint kind");
}
+
+bool be_is_valid_asm_operand_kind(ir_node const *const node, char const modifier, unsigned const pos, be_asm_operand_kind_t const have, char const *const mod_any, char const *const mod_imm, char const *const mod_mem)
+{
+ be_asm_operand_kind_t want;
+ if (strchr(mod_any, modifier)) {
+ return true;
+ } else if (strchr(mod_imm, modifier)) {
+ want = BE_ASM_OPERAND_IMMEDIATE;
+ } else if (strchr(mod_mem, modifier)) {
+ want = BE_ASM_OPERAND_MEMORY;
+ } else {
+ be_errorf(node, "asm contains unknown modifier '%c'", modifier);
+ return false;
+ }
+ if (want != have) {
+ char const *const name_want = be_get_constraint_name(want);
+ char const *const name_have = be_get_constraint_name(have);
+ be_errorf(node, "modifier of operand '%%%c%u' requires an operand of type '%s', but got '%s'", modifier, pos, name_want, name_have);
+ return false;
+ }
+ return true;
+}