brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.4 KiB · d7b0546 Raw
63 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9#include "llvm/MC/MCParser/MCTargetAsmParser.h"10#include "llvm/MC/MCContext.h"11#include "llvm/MC/MCObjectStreamer.h"12#include "llvm/MC/MCRegister.h"13 14using namespace llvm;15 16MCTargetAsmParser::MCTargetAsmParser(MCTargetOptions const &MCOptions,17                                     const MCSubtargetInfo &STI,18                                     const MCInstrInfo &MII)19    : MCOptions(MCOptions), STI(&STI), MII(MII) {}20 21MCTargetAsmParser::~MCTargetAsmParser() = default;22 23MCSubtargetInfo &MCTargetAsmParser::copySTI() {24  MCSubtargetInfo &STICopy = getContext().getSubtargetCopy(getSTI());25  STI = &STICopy;26  // The returned STI will likely be modified. Create a new fragment to prevent27  // mixing STI values within a fragment.28  auto &S = getStreamer();29  if (S.isObj() && S.getCurrentFragment())30    static_cast<MCObjectStreamer &>(S).newFragment();31  return STICopy;32}33 34const MCSubtargetInfo &MCTargetAsmParser::getSTI() const {35  return *STI;36}37 38ParseStatus MCTargetAsmParser::parseDirective(AsmToken DirectiveID) {39  SMLoc StartTokLoc = getTok().getLoc();40  // Delegate to ParseDirective by default for transition period. Once the41  // transition is over, this method should just return NoMatch.42  bool Res = ParseDirective(DirectiveID);43 44  // Some targets erroneously report success after emitting an error.45  if (getParser().hasPendingError())46    return ParseStatus::Failure;47 48  // ParseDirective returns true if there was an error or if the directive is49  // not target-specific. Disambiguate the two cases by comparing position of50  // the lexer before and after calling the method: if no tokens were consumed,51  // there was no match, otherwise there was a failure.52  if (!Res)53    return ParseStatus::Success;54  if (getTok().getLoc() != StartTokLoc)55    return ParseStatus::Failure;56  return ParseStatus::NoMatch;57}58 59bool MCTargetAsmParser::areEqualRegs(const MCParsedAsmOperand &Op1,60                                     const MCParsedAsmOperand &Op2) const {61  return Op1.isReg() && Op2.isReg() && Op1.getReg() == Op2.getReg();62}63