diff options
author | Andrew Burgess <andrew.burgess@embecosm.com> | 2016-03-14 22:17:47 +0000 |
---|---|---|
committer | Andrew Burgess <andrew.burgess@embecosm.com> | 2016-03-21 16:44:50 +0000 |
commit | 1ae8ab4714eaab3d98fd906cfd6a5fedc469643a (patch) | |
tree | 43c5f10a1becd114a6c5f61ac8a43713a7127026 /gas/config | |
parent | 8699fc3e88de47be12401fd366fbe1ee0c4294c7 (diff) | |
download | gdb-1ae8ab4714eaab3d98fd906cfd6a5fedc469643a.zip gdb-1ae8ab4714eaab3d98fd906cfd6a5fedc469643a.tar.gz gdb-1ae8ab4714eaab3d98fd906cfd6a5fedc469643a.tar.bz2 |
arc/opcodes: Use flag operand class to handle multiple flag matches
When parsing the operand instruction flags we don't currently detect the
case where multiple flags are provided from the same class set, these
will be accepted and the bit values merged together, resulting in the
wrong instruction being assembled. For example:
adc.n.eq r0,r0,r2
Will assemble without error, yet, upon disassembly, the instruction will
actually be:
adc.c r0,r0,r2
In a later commit the concept of required flags will be introduced.
Required flags are just like normal instruction flags, except that they
must be present for the instruction to match. Adding this will allow
for simpler instructions in the instruction table, and allow for more
sharing of operand extraction and insertion functions.
To solve both of the above issues (multiple flags being invalid, and
required flags), this commit reworks the flag class mechanism.
Currently the flag class is never used. Each instruction can reference
multiple flag classes, each flag class has a class type and a set of
flags. However, at present, the class type is never used. The current
values identify the type of instruction that the flag will be used in,
but this is not required information.
Instead, this commit discards the old flag classes, and introduces 3 new
classes. The first F_CLASS_NONE, is just a NULL marker value, and is
only used in the NULL marker flag class. The other two flag classes are
F_FLAG_OPTIONAL, and F_FLAG_REQUIRED.
The class F_FLAG_OPTIONAL has the property that at most one of the flags
in the flag set for that class must be present in the instruction. The
"at most" one means that no flags being present is fine.
The class F_FLAG_REQUIRED is not currently used, but will be soon. With
this class, exactly one of the flags from this class must be present in
the instruction. If the flag class contains a single flag, then of
course that flag must be present. However, if the flag class contained
two or more, then one, and only one of them must be present.
gas/ChangeLog:
* config/tc-arc.c (find_opcode_match): Move lnflg, and i
declarations to start of block. Reset code on all flags before
attempting to match them. Handle multiple hits on the same flag.
Handle flag class.
* testsuite/gas/arc/asm-errors.d: New file.
* testsuite/gas/arc/asm-errors.err: New file.
* testsuite/gas/arc/asm-errors.s: New file.
include/ChangeLog:
* opcode/arc.h (flag_class_t): Remove all old flag classes, add 3
new classes instead.
opcodes/ChangeLog:
* arc-opc.c (arc_flag_classes): Convert all flag classes to use
the new class enum values.
Diffstat (limited to 'gas/config')
-rw-r--r-- | gas/config/tc-arc.c | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/gas/config/tc-arc.c b/gas/config/tc-arc.c index 2bf7f13..736143e 100644 --- a/gas/config/tc-arc.c +++ b/gas/config/tc-arc.c @@ -1370,7 +1370,7 @@ find_opcode_match (const struct arc_opcode *first_opcode, { const unsigned char *opidx; const unsigned char *flgidx; - int tokidx = 0; + int tokidx = 0, lnflg, i; const expressionS *t = &emptyE; pr_debug ("%s:%d: find_opcode_match: trying opcode 0x%08X ", @@ -1596,20 +1596,23 @@ find_opcode_match (const struct arc_opcode *first_opcode, } pr_debug ("opr "); - /* Check the flags. Iterate over the valid flag classes. */ - int lnflg = nflgs; + /* Setup ready for flag parsing. */ + lnflg = nflgs; + for (i = 0; i < nflgs; i++) + first_pflag [i].code = 0; - for (flgidx = opcode->flags; *flgidx && lnflg; ++flgidx) + /* Check the flags. Iterate over the valid flag classes. */ + for (flgidx = opcode->flags; *flgidx; ++flgidx) { /* Get a valid flag class. */ const struct arc_flag_class *cl_flags = &arc_flag_classes[*flgidx]; const unsigned *flgopridx; + int cl_matches = 0; for (flgopridx = cl_flags->flags; *flgopridx; ++flgopridx) { const struct arc_flag_operand *flg_operand; struct arc_flags *pflag = first_pflag; - int i; flg_operand = &arc_flag_operands[*flgopridx]; for (i = 0; i < nflgs; i++, pflag++) @@ -1617,13 +1620,20 @@ find_opcode_match (const struct arc_opcode *first_opcode, /* Match against the parsed flags. */ if (!strcmp (flg_operand->name, pflag->name)) { - /*TODO: Check if it is duplicated. */ + if (pflag->code != 0) + goto match_failed; + cl_matches++; pflag->code = *flgopridx; lnflg--; break; /* goto next flag class and parsed flag. */ } } } + + if (cl_flags->class == F_CLASS_REQUIRED && cl_matches == 0) + goto match_failed; + if (cl_flags->class == F_CLASS_OPTIONAL && cl_matches > 1) + goto match_failed; } /* Did I check all the parsed flags? */ if (lnflg) |