1 //===-- DwarfException.h - Dwarf Exception Framework -----------*- C++ -*--===// 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 // This file contains support for writing dwarf exception info into asm files. 10 // 11 //===----------------------------------------------------------------------===// 12 13 #ifndef LLVM_LIB_CODEGEN_ASMPRINTER_DWARFEXCEPTION_H 14 #define LLVM_LIB_CODEGEN_ASMPRINTER_DWARFEXCEPTION_H 15 16 #include "EHStreamer.h" 17 #include "llvm/CodeGen/AsmPrinter.h" 18 #include "llvm/MC/MCDwarf.h" 19 20 namespace llvm { 21 class MachineFunction; 22 class ARMTargetStreamer; 23 24 class LLVM_LIBRARY_VISIBILITY DwarfCFIExceptionBase : public EHStreamer { 25 protected: 26 DwarfCFIExceptionBase(AsmPrinter *A); 27 28 /// Per-function flag to indicate if frame CFI info should be emitted. 29 bool shouldEmitCFI = false; 30 /// Per-module flag to indicate if .cfi_section has beeen emitted. 31 bool hasEmittedCFISections = false; 32 33 void markFunctionEnd() override; 34 void endFragment() override; 35 }; 36 37 class LLVM_LIBRARY_VISIBILITY DwarfCFIException : public DwarfCFIExceptionBase { 38 /// Per-function flag to indicate if .cfi_personality should be emitted. 39 bool shouldEmitPersonality = false; 40 41 /// Per-function flag to indicate if .cfi_personality must be emitted. 42 bool forceEmitPersonality = false; 43 44 /// Per-function flag to indicate if .cfi_lsda should be emitted. 45 bool shouldEmitLSDA = false; 46 47 public: 48 //===--------------------------------------------------------------------===// 49 // Main entry points. 50 // 51 DwarfCFIException(AsmPrinter *A); 52 ~DwarfCFIException() override; 53 54 /// Emit all exception information that should come after the content. 55 void endModule() override; 56 57 /// Gather pre-function exception information. Assumes being emitted 58 /// immediately after the function entry point. 59 void beginFunction(const MachineFunction *MF) override; 60 61 /// Gather and emit post-function exception information. 62 void endFunction(const MachineFunction *) override; 63 64 void beginFragment(const MachineBasicBlock *MBB, 65 ExceptionSymbolProvider ESP) override; 66 67 void beginBasicBlock(const MachineBasicBlock &MBB) override; 68 void endBasicBlock(const MachineBasicBlock &MBB) override; 69 }; 70 71 class LLVM_LIBRARY_VISIBILITY ARMException : public DwarfCFIExceptionBase { 72 void emitTypeInfos(unsigned TTypeEncoding, MCSymbol *TTBaseLabel) override; 73 ARMTargetStreamer &getTargetStreamer(); 74 75 public: 76 //===--------------------------------------------------------------------===// 77 // Main entry points. 78 // 79 ARMException(AsmPrinter *A); 80 ~ARMException() override; 81 82 /// Emit all exception information that should come after the content. 83 void endModule() override {} 84 85 /// Gather pre-function exception information. Assumes being emitted 86 /// immediately after the function entry point. 87 void beginFunction(const MachineFunction *MF) override; 88 89 /// Gather and emit post-function exception information. 90 void endFunction(const MachineFunction *) override; 91 }; 92 93 class LLVM_LIBRARY_VISIBILITY AIXException : public DwarfCFIExceptionBase { 94 /// This is AIX's compat unwind section, which unwinder would use 95 /// to find the location of LSDA area and personality rountine. 96 void emitExceptionInfoTable(const MCSymbol *LSDA, const MCSymbol *PerSym); 97 98 public: 99 AIXException(AsmPrinter *A); 100 101 void markFunctionEnd() override; 102 103 void endModule() override {} 104 void beginFunction(const MachineFunction *MF) override {} 105 106 void endFunction(const MachineFunction *MF) override; 107 }; 108 } // End of namespace llvm 109 110 #endif 111