xref: /freebsd/contrib/llvm-project/llvm/include/llvm/DWARFCFIChecker/DWARFCFIFunctionFrameAnalyzer.h (revision 700637cbb5e582861067a11aaca4d053546871d2)
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 /// This file declares CFIFunctionFrameAnalyzer class.
11 ///
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_DWARFCFICHECKER_DWARFCFIFUNCTIONFRAMEANALYZER_H
15 #define LLVM_DWARFCFICHECKER_DWARFCFIFUNCTIONFRAMEANALYZER_H
16 
17 #include "DWARFCFIAnalysis.h"
18 #include "DWARFCFIFunctionFrameReceiver.h"
19 #include "llvm/ADT/ArrayRef.h"
20 #include "llvm/ADT/SmallVector.h"
21 #include "llvm/Support/Compiler.h"
22 
23 namespace llvm {
24 
25 /// This class implements the `CFIFunctionFrameReceiver` interface to validate
26 /// Call Frame Information in a stream of function frames. For validation, it
27 /// instantiates a `DWARFCFIAnalysis` for each frame. The errors/warnings are
28 /// emitted through the `MCContext` instance to the constructor. If a frame
29 /// finishes without being started or if all the frames are not finished before
30 /// this classes is destructed, the program fails through an assertion.
31 class LLVM_ABI CFIFunctionFrameAnalyzer : public CFIFunctionFrameReceiver {
32 public:
CFIFunctionFrameAnalyzer(MCContext & Context,const MCInstrInfo & MCII)33   CFIFunctionFrameAnalyzer(MCContext &Context, const MCInstrInfo &MCII)
34       : CFIFunctionFrameReceiver(Context), MCII(MCII) {}
35   ~CFIFunctionFrameAnalyzer();
36 
37   void startFunctionFrame(bool IsEH,
38                           ArrayRef<MCCFIInstruction> Prologue) override;
39   void
40   emitInstructionAndDirectives(const MCInst &Inst,
41                                ArrayRef<MCCFIInstruction> Directives) override;
42   void finishFunctionFrame() override;
43 
44 private:
45   MCInstrInfo const &MCII;
46   SmallVector<DWARFCFIAnalysis> UIAs;
47 };
48 
49 } // namespace llvm
50 
51 #endif
52