[all-commits] [llvm/llvm-project] af20c1: [MC] Add three-state parseDirective as a replaceme...

Sergei Barannikov via All-commits all-commits at lists.llvm.org
Fri Jun 30 18:33:48 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: af20c1c1298d15f36470cd9d5b2cccb3b9b59c30
      https://github.com/llvm/llvm-project/commit/af20c1c1298d15f36470cd9d5b2cccb3b9b59c30
  Author: Sergei Barannikov <barannikov88 at gmail.com>
  Date:   2023-07-01 (Sat, 01 Jul 2023)

  Changed paths:
    M llvm/include/llvm/MC/MCParser/MCTargetAsmParser.h
    M llvm/lib/MC/MCParser/AsmParser.cpp
    M llvm/lib/MC/MCParser/MCTargetAsmParser.cpp
    M llvm/lib/MC/MCParser/MasmParser.cpp
    M llvm/lib/Target/AVR/AsmParser/AVRAsmParser.cpp
    M llvm/lib/Target/BPF/AsmParser/BPFAsmParser.cpp
    M llvm/lib/Target/CSKY/AsmParser/CSKYAsmParser.cpp
    M llvm/lib/Target/Lanai/AsmParser/LanaiAsmParser.cpp
    M llvm/lib/Target/LoongArch/AsmParser/LoongArchAsmParser.cpp
    M llvm/lib/Target/M68k/AsmParser/M68kAsmParser.cpp
    M llvm/lib/Target/MSP430/AsmParser/MSP430AsmParser.cpp
    M llvm/lib/Target/Sparc/AsmParser/SparcAsmParser.cpp
    M llvm/lib/Target/SystemZ/AsmParser/SystemZAsmParser.cpp
    M llvm/lib/Target/VE/AsmParser/VEAsmParser.cpp
    M llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
    M llvm/lib/Target/Xtensa/AsmParser/XtensaAsmParser.cpp
    M llvm/test/MC/CSKY/invalid-attribute.s
    A llvm/test/MC/MSP430/directive-byte-word-long-invalid.s
    A llvm/test/MC/MSP430/refsym-invalid.s
    M llvm/test/MC/Sparc/sparc-directives.s
    A llvm/test/MC/SystemZ/gnu-attributes-invalid.s
    A llvm/test/MC/SystemZ/machine-directive-invalid.s
    M llvm/test/MC/VE/data-size-error.s
    A llvm/test/MC/WebAssembly/export-name-invalid.s
    A llvm/test/MC/WebAssembly/functype-invalid.s
    A llvm/test/MC/WebAssembly/globaltype-invalid.s
    A llvm/test/MC/WebAssembly/import-module-invalid.s
    A llvm/test/MC/WebAssembly/import-name-invalid.s
    A llvm/test/MC/WebAssembly/tabletype-invalid.s
    A llvm/test/MC/WebAssembly/tagtype-invalid.s

  Log Message:
  -----------
  [MC] Add three-state parseDirective as a replacement for ParseDirective

Conventionally, parsing methods return false on success and true on
error. However, directive parsing methods need a third state: the
directive is not target specific. AsmParser::parseStatement detected
this case by using a fragile heuristic: if the target parser did not
consume any tokens, the directive is assumed to be not target-specific.

Some targets fail to follow the convention: they return success after
emitting an error or do not consume the entire line and return failure
on successful parsing. This was partially worked around by checking for
pending errors in parseStatement.

This patch tries to improve the situation by introducing parseDirective
method that returns ParseStatus -- three-state class. The new method
should eventually replace the old one returning bool.

ParseStatus is intentionally implicitly constructible from bool to allow
uses like `return Error(Loc, "message")`. It also has a potential to
replace OperandMatchResulTy as it is more convenient to use due to the
implicit construction from bool and more type safe.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D154101




More information about the All-commits mailing list