Skip to content

Commit

Permalink
[LoongArch] Support parsing register names in CFI instructions
Browse files Browse the repository at this point in the history
Reviewed By: MQ-mengqing, heiher, xen0n

Pull Request: llvm#117120
  • Loading branch information
wangleiat authored Nov 22, 2024
1 parent 105ecd8 commit 3f1e7ef
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 14 deletions.
24 changes: 22 additions & 2 deletions llvm/lib/Target/LoongArch/AsmParser/LoongArchAsmParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -669,13 +669,33 @@ static bool matchRegisterNameHelper(MCRegister &RegNo, StringRef Name) {

bool LoongArchAsmParser::parseRegister(MCRegister &Reg, SMLoc &StartLoc,
SMLoc &EndLoc) {
return Error(getLoc(), "invalid register number");
if (!tryParseRegister(Reg, StartLoc, EndLoc).isSuccess())
return Error(getLoc(), "invalid register name");

if (!LoongArchMCRegisterClasses[LoongArch::GPRRegClassID].contains(Reg) &&
!LoongArchMCRegisterClasses[LoongArch::FPR32RegClassID].contains(Reg))
return Error(getLoc(), "invalid register name");

return false;
}

ParseStatus LoongArchAsmParser::tryParseRegister(MCRegister &Reg,
SMLoc &StartLoc,
SMLoc &EndLoc) {
llvm_unreachable("Unimplemented function.");
const AsmToken &Tok = getParser().getTok();
StartLoc = Tok.getLoc();
EndLoc = Tok.getEndLoc();

parseOptionalToken(AsmToken::Dollar);
if (getLexer().getKind() != AsmToken::Identifier)
return ParseStatus::NoMatch;

StringRef Name = Tok.getIdentifier();
if (matchRegisterNameHelper(Reg, Name))
return ParseStatus::NoMatch;

getParser().Lex(); // Eat identifier token.
return ParseStatus::Success;
}

bool LoongArchAsmParser::classifySymbolRef(const MCExpr *Expr,
Expand Down
40 changes: 28 additions & 12 deletions llvm/test/MC/LoongArch/Directives/cfi.s
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
## Test cfi directives.

# RUN: llvm-mc %s --triple=loongarch32 | FileCheck %s
# RUN: llvm-mc %s --triple=loongarch64 | FileCheck %s
# RUN: not llvm-mc --triple=loongarch32 --defsym=ERR=1 < %s 2>&1 \
# RUN: llvm-mc %s --triple=loongarch32 --mattr=+lasx | FileCheck %s
# RUN: llvm-mc %s --triple=loongarch64 --mattr=+lasx | FileCheck %s
# RUN: not llvm-mc --triple=loongarch32 --mattr=+lasx --defsym=ERR=1 < %s 2>&1 \
# RUN: | FileCheck %s --check-prefix=CHECK-ERR
# RUN: not llvm-mc --triple=loongarch64 --defsym=ERR=1 < %s 2>&1 \
# RUN: not llvm-mc --triple=loongarch64 --mattr=+lasx --defsym=ERR=1 < %s 2>&1 \
# RUN: | FileCheck %s --check-prefix=CHECK-ERR

# CHECK: .cfi_startproc
Expand All @@ -15,20 +15,36 @@
.cfi_offset 9, 8
# CHECK-NEXT: .cfi_offset 31, 16
.cfi_offset 31, 16
# CHECK-NEXT: .cfi_offset 22, -8
.cfi_offset r22, -8
# CHECK-NEXT: .cfi_offset 22, -8
.cfi_offset $r22, -8
# CHECK-NEXT: .cfi_offset 22, -8
.cfi_offset fp, -8
# CHECK-NEXT: .cfi_offset 22, -8
.cfi_offset $fp, -8
# CHECK-NEXT: .cfi_offset 42, 8
.cfi_offset f10, 8
# CHECK-NEXT: .cfi_offset 56, 8
.cfi_offset fs0, 8
# CHECK-NEXT: .cfi_endproc
.cfi_endproc

.ifdef ERR
.cfi_startproc
# CHECK-ERR: :[[#@LINE+1]]:13: error: invalid register number
# CHECK-ERR: :[[#@LINE+1]]:13: error: invalid register name
.cfi_offset -22, -8
# CHECK-ERR: :[[#@LINE+1]]:13: error: invalid register number
.cfi_offset fp, -8
# CHECK-ERR: :[[#@LINE+1]]:13: error: invalid register number
# CHECK-ERR: :[[#@LINE+1]]:13: error: invalid register name
.cfi_offset lr, -8
# CHECK-ERR: :[[#@LINE+1]]:13: error: invalid register name
.cfi_offset r32, -8
# CHECK-ERR: :[[#@LINE+1]]:14: error: invalid register name
.cfi_offset $r32, -8
# CHECK-ERR: :[[#@LINE+1]]:14: error: invalid register name
.cfi_offset $22, -8
# CHECK-ERR: :[[#@LINE+1]]:13: error: invalid register number
.cfi_offset $r22, -8
# CHECK-ERR: :[[#@LINE+1]]:13: error: invalid register number
.cfi_offset $fp, -8
# CHECK-ERR: :[[#@LINE+1]]:16: error: invalid register name
.cfi_offset vr0, 8
# CHECK-ERR: :[[#@LINE+1]]:16: error: invalid register name
.cfi_offset xr0, 8
.cfi_endproc
.endif

0 comments on commit 3f1e7ef

Please sign in to comment.