Path: blob/main/contrib/llvm-project/llvm/lib/MC/MCParser/MCAsmParserExtension.cpp
35269 views
//===- MCAsmParserExtension.cpp - Asm Parser Hooks ------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "llvm/MC/MCParser/MCAsmParserExtension.h"9#include "llvm/MC/MCContext.h"10#include "llvm/MC/MCExpr.h"11#include "llvm/MC/MCParser/MCAsmLexer.h"12#include "llvm/MC/MCStreamer.h"1314using namespace llvm;1516MCAsmParserExtension::MCAsmParserExtension() = default;1718MCAsmParserExtension::~MCAsmParserExtension() = default;1920void MCAsmParserExtension::Initialize(MCAsmParser &Parser) {21this->Parser = &Parser;22}2324/// ParseDirectiveCGProfile25/// ::= .cg_profile identifier, identifier, <number>26bool MCAsmParserExtension::ParseDirectiveCGProfile(StringRef, SMLoc) {27StringRef From;28SMLoc FromLoc = getLexer().getLoc();29if (getParser().parseIdentifier(From))30return TokError("expected identifier in directive");3132if (getLexer().isNot(AsmToken::Comma))33return TokError("expected a comma");34Lex();3536StringRef To;37SMLoc ToLoc = getLexer().getLoc();38if (getParser().parseIdentifier(To))39return TokError("expected identifier in directive");4041if (getLexer().isNot(AsmToken::Comma))42return TokError("expected a comma");43Lex();4445int64_t Count;46if (getParser().parseIntToken(47Count, "expected integer count in '.cg_profile' directive"))48return true;4950if (getLexer().isNot(AsmToken::EndOfStatement))51return TokError("unexpected token in directive");5253MCSymbol *FromSym = getContext().getOrCreateSymbol(From);54MCSymbol *ToSym = getContext().getOrCreateSymbol(To);5556getStreamer().emitCGProfileEntry(57MCSymbolRefExpr::create(FromSym, MCSymbolRefExpr::VK_None, getContext(),58FromLoc),59MCSymbolRefExpr::create(ToSym, MCSymbolRefExpr::VK_None, getContext(),60ToLoc),61Count);62return false;63}646566