1 //===- MCAsmParserExtension.cpp - Asm Parser Hooks ------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "llvm/MC/MCParser/MCAsmParserExtension.h"
10 #include "llvm/MC/MCContext.h"
11 #include "llvm/MC/MCStreamer.h"
15 MCAsmParserExtension::MCAsmParserExtension() = default;
17 MCAsmParserExtension::~MCAsmParserExtension() = default;
19 void MCAsmParserExtension::Initialize(MCAsmParser
&Parser
) {
20 this->Parser
= &Parser
;
23 /// ParseDirectiveCGProfile
24 /// ::= .cg_profile identifier, identifier, <number>
25 bool MCAsmParserExtension::ParseDirectiveCGProfile(StringRef
, SMLoc
) {
27 SMLoc FromLoc
= getLexer().getLoc();
28 if (getParser().parseIdentifier(From
))
29 return TokError("expected identifier in directive");
31 if (getLexer().isNot(AsmToken::Comma
))
32 return TokError("expected a comma");
36 SMLoc ToLoc
= getLexer().getLoc();
37 if (getParser().parseIdentifier(To
))
38 return TokError("expected identifier in directive");
40 if (getLexer().isNot(AsmToken::Comma
))
41 return TokError("expected a comma");
45 if (getParser().parseIntToken(
46 Count
, "expected integer count in '.cg_profile' directive"))
49 if (getLexer().isNot(AsmToken::EndOfStatement
))
50 return TokError("unexpected token in directive");
52 MCSymbol
*FromSym
= getContext().getOrCreateSymbol(From
);
53 MCSymbol
*ToSym
= getContext().getOrCreateSymbol(To
);
55 getStreamer().emitCGProfileEntry(
56 MCSymbolRefExpr::create(FromSym
, MCSymbolRefExpr::VK_None
, getContext(),
58 MCSymbolRefExpr::create(ToSym
, MCSymbolRefExpr::VK_None
, getContext(),