xref: /freebsd/contrib/llvm-project/llvm/lib/MC/MCParser/MCTargetAsmParser.cpp (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
10b57cec5SDimitry Andric //===-- MCTargetAsmParser.cpp - Target Assembly Parser --------------------===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric 
90b57cec5SDimitry Andric #include "llvm/MC/MCParser/MCTargetAsmParser.h"
100b57cec5SDimitry Andric #include "llvm/MC/MCContext.h"
11*0fca6ea1SDimitry Andric #include "llvm/MC/MCRegister.h"
120b57cec5SDimitry Andric 
130b57cec5SDimitry Andric using namespace llvm;
140b57cec5SDimitry Andric 
MCTargetAsmParser(MCTargetOptions const & MCOptions,const MCSubtargetInfo & STI,const MCInstrInfo & MII)150b57cec5SDimitry Andric MCTargetAsmParser::MCTargetAsmParser(MCTargetOptions const &MCOptions,
160b57cec5SDimitry Andric                                      const MCSubtargetInfo &STI,
170b57cec5SDimitry Andric                                      const MCInstrInfo &MII)
180b57cec5SDimitry Andric     : MCOptions(MCOptions), STI(&STI), MII(MII) {}
190b57cec5SDimitry Andric 
200b57cec5SDimitry Andric MCTargetAsmParser::~MCTargetAsmParser() = default;
210b57cec5SDimitry Andric 
copySTI()220b57cec5SDimitry Andric MCSubtargetInfo &MCTargetAsmParser::copySTI() {
230b57cec5SDimitry Andric   MCSubtargetInfo &STICopy = getContext().getSubtargetCopy(getSTI());
240b57cec5SDimitry Andric   STI = &STICopy;
250b57cec5SDimitry Andric   return STICopy;
260b57cec5SDimitry Andric }
270b57cec5SDimitry Andric 
getSTI() const280b57cec5SDimitry Andric const MCSubtargetInfo &MCTargetAsmParser::getSTI() const {
290b57cec5SDimitry Andric   return *STI;
300b57cec5SDimitry Andric }
3106c3fb27SDimitry Andric 
parseDirective(AsmToken DirectiveID)3206c3fb27SDimitry Andric ParseStatus MCTargetAsmParser::parseDirective(AsmToken DirectiveID) {
3306c3fb27SDimitry Andric   SMLoc StartTokLoc = getTok().getLoc();
3406c3fb27SDimitry Andric   // Delegate to ParseDirective by default for transition period. Once the
3506c3fb27SDimitry Andric   // transition is over, this method should just return NoMatch.
3606c3fb27SDimitry Andric   bool Res = ParseDirective(DirectiveID);
3706c3fb27SDimitry Andric 
3806c3fb27SDimitry Andric   // Some targets erroneously report success after emitting an error.
3906c3fb27SDimitry Andric   if (getParser().hasPendingError())
4006c3fb27SDimitry Andric     return ParseStatus::Failure;
4106c3fb27SDimitry Andric 
4206c3fb27SDimitry Andric   // ParseDirective returns true if there was an error or if the directive is
4306c3fb27SDimitry Andric   // not target-specific. Disambiguate the two cases by comparing position of
4406c3fb27SDimitry Andric   // the lexer before and after calling the method: if no tokens were consumed,
4506c3fb27SDimitry Andric   // there was no match, otherwise there was a failure.
4606c3fb27SDimitry Andric   if (!Res)
4706c3fb27SDimitry Andric     return ParseStatus::Success;
4806c3fb27SDimitry Andric   if (getTok().getLoc() != StartTokLoc)
4906c3fb27SDimitry Andric     return ParseStatus::Failure;
5006c3fb27SDimitry Andric   return ParseStatus::NoMatch;
5106c3fb27SDimitry Andric }
52*0fca6ea1SDimitry Andric 
areEqualRegs(const MCParsedAsmOperand & Op1,const MCParsedAsmOperand & Op2) const53*0fca6ea1SDimitry Andric bool MCTargetAsmParser::areEqualRegs(const MCParsedAsmOperand &Op1,
54*0fca6ea1SDimitry Andric                                      const MCParsedAsmOperand &Op2) const {
55*0fca6ea1SDimitry Andric   return Op1.isReg() && Op2.isReg() && Op1.getReg() == Op2.getReg();
56*0fca6ea1SDimitry Andric }
57