MCAsmParserExtension.cpp 2.0 KB

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