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
13using namespace llvm;
14
15MCTargetAsmParser::MCTargetAsmParser(MCTargetOptions const &MCOptions,
16 const MCSubtargetInfo &STI,
17 const MCInstrInfo &MII)
18 : MCOptions(MCOptions), STI(&STI), MII(MII) {}
19
20MCTargetAsmParser::~MCTargetAsmParser() = default;
21
22MCSubtargetInfo &MCTargetAsmParser::copySTI() {
23 MCSubtargetInfo &STICopy = getContext().getSubtargetCopy(STI: getSTI());
24 STI = &STICopy;
25 return STICopy;
26}
27
28const MCSubtargetInfo &MCTargetAsmParser::getSTI() const {
29 return *STI;
30}
31
32ParseStatus 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
53bool MCTargetAsmParser::areEqualRegs(const MCParsedAsmOperand &Op1,
54 const MCParsedAsmOperand &Op2) const {
55 return Op1.isReg() && Op2.isReg() && Op1.getReg() == Op2.getReg();
56}
57