[PATCH] D33128: [AsmParser] Mnemonic Spell Corrector

Sjoerd Meijer via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri May 12 06:53:12 PDT 2017


SjoerdMeijer created this revision.
Herald added subscribers: javed.absar, aemerson.

This implements a simple spell corrector to suggest another mnemonic when an invalid one is specified. For example, the idea is to give this error message and suggestion:

$ echo "adXd r1,r2,#3" | llvm-mc -triple arm -show-encoding
<stdin>:1:1: error: invalid instruction, did you mean: add?
adXd r1,r2,#3
^

This is a very simple implementation of the Levenshtein distance calculation. It is target agnostic, but as a first exercise I have added it only to the ARM backend.

I let tablegen generate another mnemonic table. There is already one, but this is one big string with offsets in it indicating where the next string starts. I found this really inconvenient, as all I want is to iterator over all the available mnemonics. As the mnemonics are short strings, I thought it would be okay to add another table (and not change the existing).

I have not changed any existing tests, and am not sure if I need to. The suggestion is appended to the error string, and as the first bit still matches, this does not give any problems in the regression tests. I probably do need to add some new tests, will do so when we think this is a nice addition.


https://reviews.llvm.org/D33128

Files:
  include/llvm/AsmParser/MnemonicSpellCheck.h
  include/llvm/TableGen/StringToOffsetTable.h
  lib/Target/ARM/AsmParser/ARMAsmParser.cpp
  utils/TableGen/AsmMatcherEmitter.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D33128.98755.patch
Type: text/x-patch
Size: 4210 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170512/aafdf79a/attachment.bin>


More information about the llvm-commits mailing list