LLVM 22.0.0git
MCAsmParserExtension.cpp
Go to the documentation of this file.
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
10#include "llvm/MC/MCContext.h"
11#include "llvm/MC/MCExpr.h"
13#include "llvm/MC/MCStreamer.h"
14
15using namespace llvm;
16
18
20
22 this->Parser = &Parser;
23}
24
25/// parseDirectiveCGProfile
26/// ::= .cg_profile identifier, identifier, <number>
28 StringRef From;
29 SMLoc FromLoc = getLexer().getLoc();
30 if (getParser().parseIdentifier(From))
31 return TokError("expected identifier in directive");
32
34 return TokError("expected a comma");
35 Lex();
36
37 StringRef To;
38 SMLoc ToLoc = getLexer().getLoc();
39 if (getParser().parseIdentifier(To))
40 return TokError("expected identifier in directive");
41
43 return TokError("expected a comma");
44 Lex();
45
46 int64_t Count;
47 if (getParser().parseIntToken(Count))
48 return true;
49
51 return TokError("unexpected token in directive");
52
53 MCSymbol *FromSym = getContext().parseSymbol(From);
54 MCSymbol *ToSym = getContext().parseSymbol(To);
55
57 MCSymbolRefExpr::create(FromSym, getContext(), FromLoc),
58 MCSymbolRefExpr::create(ToSym, getContext(), ToLoc), Count);
59 return false;
60}
61
63 AsmLexer &L = getLexer();
64 if (L.isNot(AsmToken::Comma))
65 return false;
66 Lex();
67 StringRef UniqueStr;
68 if (getParser().parseIdentifier(UniqueStr))
69 return TokError("expected identifier");
70 if (UniqueStr != "unique")
71 return TokError("expected 'unique'");
72 if (L.isNot(AsmToken::Comma))
73 return TokError("expected commma");
74 Lex();
75 if (getParser().parseAbsoluteExpression(UniqueID))
76 return true;
77 if (UniqueID < 0)
78 return TokError("unique id must be positive");
79 if (!isUInt<32>(UniqueID) || UniqueID == ~0U)
80 return TokError("unique id is too large");
81 return false;
82}
static bool isNot(const MachineRegisterInfo &MRI, const MachineInstr &MI)
SMLoc getLoc() const
Get the current source location.
Definition AsmLexer.h:115
virtual void Initialize(MCAsmParser &Parser)
Initialize the extension for parsing using the given Parser.
bool maybeParseUniqueID(int64_t &UniqueID)
bool TokError(const Twine &Msg)
bool parseDirectiveCGProfile(StringRef, SMLoc)
parseDirectiveCGProfile ::= .cg_profile identifier, identifier, <number>
Generic assembler parser interface, for use by target specific assembly parsers.
LLVM_ABI MCSymbol * parseSymbol(const Twine &Name)
Variant of getOrCreateSymbol that handles backslash-escaped symbols.
virtual void emitCGProfileEntry(const MCSymbolRefExpr *From, const MCSymbolRefExpr *To, uint64_t Count)
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx, SMLoc Loc=SMLoc())
Definition MCExpr.h:214
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition MCSymbol.h:42
Represents a location in source code.
Definition SMLoc.h:23
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
This is an optimization pass for GlobalISel generic memory operations.
FunctionAddr VTableAddr Count
Definition InstrProf.h:139
constexpr bool isUInt(uint64_t x)
Checks if an unsigned integer fits into the given bit width.
Definition MathExtras.h:198