Skip to content

Commit

Permalink
[ARM] Use new assembler diags for ARM
Browse files Browse the repository at this point in the history
This converts the ARM AsmParser to use the new assembly matcher error
reporting mechanism, which allows errors to be reported for multiple
instruction encodings when it is ambiguous which one the user intended
to use.

By itself this doesn't improve many error messages, because we don't have
diagnostic text for most operand types, but as we add that then this will allow
more of those diagnostic strings to be used when they are relevant.

Differential revision: https://reviews.llvm.org/D31530

llvm-svn: 314779
  • Loading branch information
ostannard committed Oct 3, 2017
1 parent d87af9a commit e093bad
Show file tree
Hide file tree
Showing 43 changed files with 2,465 additions and 2,134 deletions.
5 changes: 5 additions & 0 deletions llvm/lib/Target/ARM/ARM.td
Expand Up @@ -1022,6 +1022,10 @@ def ARMAsmWriter : AsmWriter {
bit isMCAsmWriter = 1;
}

def ARMAsmParser : AsmParser {
bit ReportMultipleNearMisses = 1;
}

def ARMAsmParserVariant : AsmParserVariant {
int Variant = 0;
string Name = "ARM";
Expand All @@ -1032,5 +1036,6 @@ def ARM : Target {
// Pull in Instruction Info.
let InstructionSet = ARMInstrInfo;
let AssemblyWriters = [ARMAsmWriter];
let AssemblyParsers = [ARMAsmParser];
let AssemblyParserVariants = [ARMAsmParserVariant];
}
417 changes: 284 additions & 133 deletions llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp

Large diffs are not rendered by default.

12 changes: 9 additions & 3 deletions llvm/test/MC/ARM/arm-branch-errors.s
Expand Up @@ -8,9 +8,15 @@
bl #2
beq #2

@ CHECK: error: instruction requires: thumb
@ CHECK: error: invalid instruction, any one of the following would fix this:
@ CHECK: b #2
@ CHECK: error: instruction requires: thumb
@ CHECK: note: instruction requires: thumb
@ CHECK: note: invalid operand for instruction
@ CHECK: error: invalid instruction, any one of the following would fix this:
@ CHECK: bl #2
@ CHECK: error: instruction requires: thumb
@ CHECK: note: instruction requires: thumb
@ CHECK: note: invalid operand for instruction
@ CHECK: error: invalid instruction, any one of the following would fix this:
@ CHECK: beq #2
@ CHECK: note: instruction requires: thumb
@ CHECK: note: invalid operand for instruction
28 changes: 16 additions & 12 deletions llvm/test/MC/ARM/basic-arm-instructions-v8.1a.s
Expand Up @@ -27,18 +27,18 @@
//CHECK-ERROR: error: invalid operand for instruction
//CHECK-ERROR: vqrdmlsh.f64 d3, d5, d5
//CHECK-ERROR: ^
//CHECK-V8: error: invalid operand for instruction
//CHECK-V8: error: invalid instruction
//CHECK-V8: vqrdmlah.i8 q0, q1, q2
//CHECK-V8: ^
//CHECK-V8: error: invalid operand for instruction
//CHECK-V8: ^
//CHECK-V8: error: invalid instruction
//CHECK-V8: vqrdmlah.u16 d0, d1, d2
//CHECK-V8: ^
//CHECK-V8: error: invalid operand for instruction
//CHECK-V8: ^
//CHECK-V8: error: invalid instruction
//CHECK-V8: vqrdmlsh.f32 q3, q4, q5
//CHECK-V8: ^
//CHECK-V8: error: invalid operand for instruction
//CHECK-V8: ^
//CHECK-V8: error: invalid instruction
//CHECK-V8: vqrdmlsh.f64 d3, d5, d5
//CHECK-V8: ^
//CHECK-V8: ^

vqrdmlah.s16 d0, d1, d2
//CHECK-V81aARM: vqrdmlah.s16 d0, d1, d2 @ encoding: [0x12,0x0b,0x11,0xf3]
Expand Down Expand Up @@ -98,15 +98,19 @@
//CHECK-V8: ^


vqrdmlah.i8 q0, q1, d9[7]
vqrdmlah.i8 q0, q1, d9[0]
vqrdmlah.s32 q0, q1, d9[7]
vqrdmlah.u16 d0, d1, d2[3]
vqrdmlsh.f32 q3, q4, d5[1]
vqrdmlsh.f64 d3, d5, d5[0]

//CHECK-ERROR: error: invalid operand for instruction
//CHECK-ERROR: vqrdmlah.i8 q0, q1, d9[7]
//CHECK-ERROR: vqrdmlah.i8 q0, q1, d9[0]
//CHECK-ERROR: ^
//CHECK-ERROR: error: invalid operand for instruction
//CHECK-ERROR: vqrdmlah.s32 q0, q1, d9[7]
//CHECK-ERROR: ^
//CHECK-ERROR: error: invalid operand for instruction
//CHECK-ERROR: vqrdmlah.u16 d0, d1, d2[3]
//CHECK-ERROR: ^
//CHECK-ERROR: error: invalid operand for instruction
Expand Down Expand Up @@ -176,14 +180,14 @@
setpan #0
//CHECK-V81aTHUMB: setpan #0 @ encoding: [0x10,0xb6]
//CHECK-V81aARM: setpan #0 @ encoding: [0x00,0x00,0x10,0xf1]
//CHECK-V8: error: instruction requires: armv8.1a
//CHECK-V8: instruction requires: armv8.1a
//CHECK-V8: setpan #0
//CHECK-V8: ^

setpan #1
//CHECK-V81aTHUMB: setpan #1 @ encoding: [0x18,0xb6]
//CHECK-V81aARM: setpan #1 @ encoding: [0x00,0x02,0x10,0xf1]
//CHECK-V8: error: instruction requires: armv8.1a
//CHECK-V8: instruction requires: armv8.1a
//CHECK-V8: setpan #1
//CHECK-V8: ^
setpan
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/MC/ARM/basic-arm-instructions-v8.s
Expand Up @@ -56,4 +56,4 @@
sevl

@ CHECK-V8: sevl @ encoding: [0x05,0xf0,0x20,0xe3]
@ CHECK-V7: error: instruction requires: armv8
@ CHECK-V7: instruction requires: armv8
8 changes: 6 additions & 2 deletions llvm/test/MC/ARM/basic-thumb2-instructions-v8.s
Expand Up @@ -31,8 +31,12 @@
@ CHECK-V8: sbc.w r6, r3, sp, asr #16 @ encoding: [0x63,0xeb,0x2d,0x46]
@ CHECK-V8: and.w r6, r3, sp, asr #16 @ encoding: [0x03,0xea,0x2d,0x46]
@ CHECK-V8: and sp, r0, #0 @ encoding: [0x00,0xf0,0x00,0x0d]
@ CHECK-V7: error: instruction variant requires ARMv8 or later
@ CHECK-V7: error: instruction variant requires ARMv8 or later
@ CHECK-V7: error: invalid instruction, any one of the following would fix this:
@ CHECk-V7: note: instruction variant requires ARMv8 or later
@ CHECk-V7: note: invalid operand for instruction
@ CHECK-V7: error: invalid instruction, any one of the following would fix this:
@ CHECk-V7: note: instruction variant requires ARMv8 or later
@ CHECk-V7: note: invalid operand for instruction
@ CHECK-V7: error: invalid operand for instruction

@ DCPS{1,2,3} (in ARMv8 only)
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/MC/ARM/cps.s
Expand Up @@ -13,5 +13,5 @@
@ CHECK: cps #0 @ encoding: [0xaf,0xf3,0x00,0x81]

@ UNDEF-DAG: cpsie f @ encoding: [0x61,0xb6]
@ UNDEF-DAG: error: instruction requires:
@ UNDEF-DAG: instruction requires:
@ UNDEF-DAG: error: instruction 'cps' requires effect for M-class
62 changes: 36 additions & 26 deletions llvm/test/MC/ARM/diagnostics.s
Expand Up @@ -93,17 +93,21 @@
@ Out of range 16-bit immediate on BKPT
bkpt #65536

@ CHECK-ERRORS: error: immediate operand must be in the range [0,65535]
@ CHECK-ERRORS: error: invalid instruction, any one of the following would fix this:
@ CHECK-ERRORS: note: immediate operand must be in the range [0,65535]
@ CHECK-ERRORS: note: too many operands for instruction
@ CHECK-ERRORS: bkpt #65536
@ CHECK-ERRORS: ^

@ Out of range immediates for v8 HLT instruction.
hlt #65536
hlt #-1
@CHECK-ERRORS: error: immediate operand must be in the range [0,65535]
@CHECK-ERRORS-V7: error: invalid instruction
@CHECK-ERRORS-V8: error: immediate operand must be in the range [0,65535]
@CHECK-ERRORS: hlt #65536
@CHECK-ERRORS: ^
@CHECK-ERRORS: error: immediate operand must be in the range [0,65535]
@CHECK-ERRORS: ^
@CHECK-ERRORS-V7: error: invalid instruction
@CHECK-ERRORS-V8: error: immediate operand must be in the range [0,65535]
@CHECK-ERRORS: hlt #-1
@CHECK-ERRORS: ^

Expand All @@ -129,17 +133,19 @@
@ CHECK-ERRORS-V7: error: immediate operand must be in the range [0,7]
@ CHECK-ERRORS-V7: error: immediate operand must be in the range [0,7]
@ CHECK-ERRORS-V7: error: immediate operand must be in the range [0,7]
@ CHECK-ERRORS-V8: error: invalid operand for instruction
@ CHECK-ERRORS-V8: error: invalid operand for instruction
@ CHECK-ERRORS-V8: error: invalid operand for instruction
@ CHECK-ERRORS-V8: error: invalid operand for instruction
@ CHECK-ERRORS-V8: error: invalid instruction
@ CHECK-ERRORS-V8: error: invalid instruction
@ CHECK-ERRORS-V8: error: invalid instruction
@ CHECK-ERRORS-V8: error: invalid instruction

@ Out of range immediates for DBG
dbg #-1
dbg #16

@ CHECK-ERRORS: error: immediate operand must be in the range [0,15]
@ CHECK-ERRORS: error: immediate operand must be in the range [0,15]
@ CHECK-ERRORS-V7: error: immediate operand must be in the range [0,15]
@ CHECK-ERRORS-V7: error: immediate operand must be in the range [0,15]
@ CHECK-ERRORS-V8: error: immediate operand must be in the range [0,15]
@ CHECK-ERRORS-V8: error: immediate operand must be in the range [0,15]
@ Double-check that we're synced up with the right diagnostics.
@ CHECK-ERRORS: dbg #16
@ CHECK-ERRORS: ^
Expand All @@ -151,13 +157,15 @@
mcr2 p7, #1, r5, c1, c1, #8
mcrr p7, #16, r5, r4, c1
mcrr2 p7, #16, r5, r4, c1
@ CHECK-ERRORS: error: immediate operand must be in the range [0,7]
@ CHECK-ERRORS: error: immediate operand must be in the range [0,7]
@ CHECK-ERRORS: error: immediate operand must be in the range [0,7]
@ CHECK-ERRORS: error: immediate operand must be in the range [0,7]
@ CHECK-ERRORS: error: immediate operand must be in the range [0,15]
@ CHECK-ERRORS-V7: error: immediate operand must be in the range [0,15]
@ CHECK-ERRORS-V8: error: invalid operand for instruction
@ CHECK-ERRORS: immediate operand must be in the range [0,7]
@ CHECK-ERRORS: immediate operand must be in the range [0,7]
@ CHECK-ERRORS-V7: immediate operand must be in the range [0,7]
@ CHECK-ERRORS-V7: immediate operand must be in the range [0,7]
@ CHECK-ERRORS-V8: invalid instruction
@ CHECK-ERRORS-V8: too many operands for instruction
@ CHECK-ERRORS: immediate operand must be in the range [0,15]
@ CHECK-ERRORS-V7: immediate operand must be in the range [0,15]
@ CHECK-ERRORS-V8: invalid instruction

@ p10 and p11 are reserved for NEON
mcr p10, #2, r5, c1, c1, #4
Expand All @@ -174,7 +182,7 @@
@ Invalid 's' bit usage for MOVW
movs r6, #0xffff
movwseq r9, #0xffff
@ CHECK-ERRORS: error: immediate operand must be in the range [0,255]
@ CHECK-ERRORS: error: invalid operand for instruction
@ CHECK-ERRORS: error: instruction 'movw' can not set flags, but 's' suffix specified

@ Out of range immediate for MOVT
Expand All @@ -190,13 +198,15 @@
mrc2 p14, #0, r1, c1, c2, #9
mrrc p7, #16, r5, r4, c1
mrrc2 p7, #17, r5, r4, c1
@ CHECK-ERRORS: error: immediate operand must be in the range [0,7]
@ CHECK-ERRORS: error: immediate operand must be in the range [0,7]
@ CHECK-ERRORS: error: immediate operand must be in the range [0,7]
@ CHECK-ERRORS: error: immediate operand must be in the range [0,7]
@ CHECK-ERRORS: error: immediate operand must be in the range [0,15]
@ CHECK-ERRORS-V7: error: immediate operand must be in the range [0,15]
@ CHECK-ERRORS-V8: error: invalid operand for instruction
@ CHECK-ERRORS: immediate operand must be in the range [0,7]
@ CHECK-ERRORS: immediate operand must be in the range [0,7]
@ CHECK-ERRORS-V7: immediate operand must be in the range [0,7]
@ CHECK-ERRORS-V8: invalid instruction
@ CHECK-ERRORS-V7: immediate operand must be in the range [0,7]
@ CHECK-ERRORS-V8: too many operands for instruction
@ CHECK-ERRORS: immediate operand must be in the range [0,15]
@ CHECK-ERRORS-V7: immediate operand must be in the range [0,15]
@ CHECK-ERRORS-V8: invalid instruction

@ Shifter operand validation for PKH instructions.
pkhbt r2, r2, r3, lsl #-1
Expand Down Expand Up @@ -418,7 +428,7 @@

@ Bad CPS instruction format.
cps f,#1
@ CHECK-ERRORS: error: immediate operand must be in the range [0,31]
@ CHECK-ERRORS: error: invalid operand for instruction
@ CHECK-ERRORS: cps f,#1
@ CHECK-ERRORS: ^

Expand Down

0 comments on commit e093bad

Please sign in to comment.