1 //===-- MCTargetAsmParser.cpp - Target Assembly Parser --------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #include "llvm/MC/MCParser/MCTargetAsmParser.h" 10 #include "llvm/MC/MCContext.h" 11 #include "llvm/MC/MCRegister.h" 12 13 using namespace llvm; 14 15 MCTargetAsmParser::MCTargetAsmParser(MCTargetOptions const &MCOptions, 16 const MCSubtargetInfo &STI, 17 const MCInstrInfo &MII) 18 : MCOptions(MCOptions), STI(&STI), MII(MII) {} 19 20 MCTargetAsmParser::~MCTargetAsmParser() = default; 21 22 MCSubtargetInfo &MCTargetAsmParser::copySTI() { 23 MCSubtargetInfo &STICopy = getContext().getSubtargetCopy(getSTI()); 24 STI = &STICopy; 25 return STICopy; 26 } 27 28 const MCSubtargetInfo &MCTargetAsmParser::getSTI() const { 29 return *STI; 30 } 31 32 ParseStatus MCTargetAsmParser::parseDirective(AsmToken DirectiveID) { 33 SMLoc StartTokLoc = getTok().getLoc(); 34 // Delegate to ParseDirective by default for transition period. Once the 35 // transition is over, this method should just return NoMatch. 36 bool Res = ParseDirective(DirectiveID); 37 38 // Some targets erroneously report success after emitting an error. 39 if (getParser().hasPendingError()) 40 return ParseStatus::Failure; 41 42 // ParseDirective returns true if there was an error or if the directive is 43 // not target-specific. Disambiguate the two cases by comparing position of 44 // the lexer before and after calling the method: if no tokens were consumed, 45 // there was no match, otherwise there was a failure. 46 if (!Res) 47 return ParseStatus::Success; 48 if (getTok().getLoc() != StartTokLoc) 49 return ParseStatus::Failure; 50 return ParseStatus::NoMatch; 51 } 52 53 bool MCTargetAsmParser::areEqualRegs(const MCParsedAsmOperand &Op1, 54 const MCParsedAsmOperand &Op2) const { 55 return Op1.isReg() && Op2.isReg() && Op1.getReg() == Op2.getReg(); 56 } 57