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/MCExpr.h"
12 #include "llvm/MC/MCParser/MCAsmLexer.h"
13 #include "llvm/MC/MCStreamer.h"
17 MCAsmParserExtension::MCAsmParserExtension() = default;
19 MCAsmParserExtension::~MCAsmParserExtension() = default;
21 void MCAsmParserExtension::Initialize(MCAsmParser
&Parser
) {
22 this->Parser
= &Parser
;
25 /// ParseDirectiveCGProfile
26 /// ::= .cg_profile identifier, identifier, <number>
27 bool MCAsmParserExtension::ParseDirectiveCGProfile(StringRef
, SMLoc
) {
29 SMLoc FromLoc
= getLexer().getLoc();
30 if (getParser().parseIdentifier(From
))
31 return TokError("expected identifier in directive");
33 if (getLexer().isNot(AsmToken::Comma
))
34 return TokError("expected a comma");
38 SMLoc ToLoc
= getLexer().getLoc();
39 if (getParser().parseIdentifier(To
))
40 return TokError("expected identifier in directive");
42 if (getLexer().isNot(AsmToken::Comma
))
43 return TokError("expected a comma");
47 if (getParser().parseIntToken(
48 Count
, "expected integer count in '.cg_profile' directive"))
51 if (getLexer().isNot(AsmToken::EndOfStatement
))
52 return TokError("unexpected token in directive");
54 MCSymbol
*FromSym
= getContext().getOrCreateSymbol(From
);
55 MCSymbol
*ToSym
= getContext().getOrCreateSymbol(To
);
57 getStreamer().emitCGProfileEntry(
58 MCSymbolRefExpr::create(FromSym
, MCSymbolRefExpr::VK_None
, getContext(),
60 MCSymbolRefExpr::create(ToSym
, MCSymbolRefExpr::VK_None
, getContext(),