MCAsmParserExtension.cpp 2.0 KB

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