| 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 DWARFCFIState class. |
| 11 | /// |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #ifndef LLVM_DWARFCFICHECKER_UNWINDINFOSTATE_H |
| 15 | #define LLVM_DWARFCFICHECKER_UNWINDINFOSTATE_H |
| 16 | |
| 17 | #include "llvm/DebugInfo/DWARF/LowLevel/DWARFUnwindTable.h" |
| 18 | #include "llvm/MC/MCContext.h" |
| 19 | #include "llvm/MC/MCDwarf.h" |
| 20 | #include "llvm/Support/Compiler.h" |
| 21 | #include <optional> |
| 22 | |
| 23 | namespace llvm { |
| 24 | |
| 25 | using DWARFRegNum = uint32_t; |
| 26 | |
| 27 | /// This class is used to maintain a CFI state, referred to as an unwinding row, |
| 28 | /// during CFI analysis. The only way to modify the state is by updating it with |
| 29 | /// a CFI directive. |
| 30 | class DWARFCFIState { |
| 31 | public: |
| 32 | DWARFCFIState(MCContext *Context) : Context(Context), IsInitiated(false) {}; |
| 33 | |
| 34 | LLVM_ABI std::optional<dwarf::UnwindRow> getCurrentUnwindRow() const; |
| 35 | |
| 36 | /// This method updates the state by applying \p Directive to the current |
| 37 | /// state. If the directive is not supported by the checker or any error |
| 38 | /// happens while applying the CFI directive, a warning or error is reported |
| 39 | /// to the user, and the directive is ignored, leaving the state unchanged. |
| 40 | LLVM_ABI void update(const MCCFIInstruction &Directive); |
| 41 | |
| 42 | private: |
| 43 | dwarf::CFIProgram convert(MCCFIInstruction Directive); |
| 44 | |
| 45 | private: |
| 46 | dwarf::UnwindRow Row; |
| 47 | MCContext *Context; |
| 48 | bool IsInitiated; |
| 49 | }; |
| 50 | |
| 51 | } // namespace llvm |
| 52 | |
| 53 | #endif |
| 54 | |