1 //===- MCAsmParserExtension.cpp - Asm Parser Hooks ------------------------===// 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/MCAsmParserExtension.h" 10 #include "llvm/MC/MCContext.h" 11 #include "llvm/MC/MCStreamer.h" 12 13 using namespace llvm; 14 15 MCAsmParserExtension::MCAsmParserExtension() = default; 16 17 MCAsmParserExtension::~MCAsmParserExtension() = default; 18 19 void MCAsmParserExtension::Initialize(MCAsmParser &Parser) { 20 this->Parser = &Parser; 21 } 22 23 /// ParseDirectiveCGProfile 24 /// ::= .cg_profile identifier, identifier, <number> 25 bool MCAsmParserExtension::ParseDirectiveCGProfile(StringRef, SMLoc) { 26 StringRef From; 27 SMLoc FromLoc = getLexer().getLoc(); 28 if (getParser().parseIdentifier(From)) 29 return TokError("expected identifier in directive"); 30 31 if (getLexer().isNot(AsmToken::Comma)) 32 return TokError("expected a comma"); 33 Lex(); 34 35 StringRef To; 36 SMLoc ToLoc = getLexer().getLoc(); 37 if (getParser().parseIdentifier(To)) 38 return TokError("expected identifier in directive"); 39 40 if (getLexer().isNot(AsmToken::Comma)) 41 return TokError("expected a comma"); 42 Lex(); 43 44 int64_t Count; 45 if (getParser().parseIntToken( 46 Count, "expected integer count in '.cg_profile' directive")) 47 return true; 48 49 if (getLexer().isNot(AsmToken::EndOfStatement)) 50 return TokError("unexpected token in directive"); 51 52 MCSymbol *FromSym = getContext().getOrCreateSymbol(From); 53 MCSymbol *ToSym = getContext().getOrCreateSymbol(To); 54 55 getStreamer().emitCGProfileEntry( 56 MCSymbolRefExpr::create(FromSym, MCSymbolRefExpr::VK_None, getContext(), 57 FromLoc), 58 MCSymbolRefExpr::create(ToSym, MCSymbolRefExpr::VK_None, getContext(), 59 ToLoc), 60 Count); 61 return false; 62 } 63