LLVM 23.0.0git
LFIAsmParser.cpp
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
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/// \file
10/// LFI assembly parser.
11///
12//===----------------------------------------------------------------------===//
13
16
17using namespace llvm;
18
19namespace {
20class LFIAsmParser : public MCAsmParserExtension {
21 MCLFIRewriter *Rewriter;
22 template <bool (LFIAsmParser::*HandlerMethod)(StringRef, SMLoc)>
23 void addDirectiveHandler(StringRef Directive) {
25 std::make_pair(this, HandleDirective<LFIAsmParser, HandlerMethod>);
26
27 getParser().addDirectiveHandler(Directive, Handler);
28 }
29
30public:
31 LFIAsmParser(MCLFIRewriter *Exp) : Rewriter(Exp) {}
32 void Initialize(MCAsmParser &Parser) override {
33 // Call the base implementation.
35 addDirectiveHandler<&LFIAsmParser::parseRewriteDisable>(
36 ".lfi_rewrite_disable");
37 addDirectiveHandler<&LFIAsmParser::parseRewriteEnable>(
38 ".lfi_rewrite_enable");
39 }
40
41 /// ::= {.lfi_rewrite_disable}
42 bool parseRewriteDisable(StringRef Directive, SMLoc Loc) {
43 getParser().checkForValidSection();
44 if (getLexer().isNot(AsmToken::EndOfStatement))
45 return TokError("unexpected token");
46 Lex();
47
48 Rewriter->disable();
49
50 return false;
51 }
52
53 /// ::= {.lfi_rewrite_enable}
54 bool parseRewriteEnable(StringRef Directive, SMLoc Loc) {
55 getParser().checkForValidSection();
56 if (getLexer().isNot(AsmToken::EndOfStatement))
57 return TokError("unexpected token");
58 Lex();
59
60 Rewriter->enable();
61
62 return false;
63 }
64};
65} // namespace
66
68 return new LFIAsmParser(Exp);
69}
static bool isNot(const MachineRegisterInfo &MRI, const MachineInstr &MI)
This file declares the MCLFIRewriter class, an abstract class that encapsulates the rewriting logic f...
Generic interface for extending the MCAsmParser, which is implemented by target and object file assem...
virtual void Initialize(MCAsmParser &Parser)
Initialize the extension for parsing using the given Parser.
std::pair< MCAsmParserExtension *, DirectiveHandler > ExtensionDirectiveHandler
This is an optimization pass for GlobalISel generic memory operations.
Definition Types.h:26
LLVM_ABI MCAsmParserExtension * createLFIAsmParser(MCLFIRewriter *Exp)