LLVM  14.0.0git
ARMUnwindOpAsm.h
Go to the documentation of this file.
1 //===-- ARMUnwindOpAsm.h - ARM Unwind Opcodes Assembler ---------*- 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 declares the unwind opcode assembler for ARM exception handling
10 // table.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_LIB_TARGET_ARM_MCTARGETDESC_ARMUNWINDOPASM_H
15 #define LLVM_LIB_TARGET_ARM_MCTARGETDESC_ARMUNWINDOPASM_H
16 
17 #include "llvm/ADT/SmallVector.h"
18 #include <cstddef>
19 #include <cstdint>
20 
21 namespace llvm {
22 
23 class MCSymbol;
24 
26 private:
28  SmallVector<unsigned, 8> OpBegins;
29  bool HasPersonality = false;
30 
31 public:
33  OpBegins.push_back(0);
34  }
35 
36  /// Reset the unwind opcode assembler.
37  void Reset() {
38  Ops.clear();
39  OpBegins.clear();
40  OpBegins.push_back(0);
41  HasPersonality = false;
42  }
43 
44  /// Set the personality
45  void setPersonality(const MCSymbol *Per) {
46  HasPersonality = true;
47  }
48 
49  /// Emit unwind opcodes for .save directives
50  void EmitRegSave(uint32_t RegSave);
51 
52  /// Emit unwind opcodes for .vsave directives
53  void EmitVFPRegSave(uint32_t VFPRegSave);
54 
55  /// Emit unwind opcodes to copy address from source register to $sp.
56  void EmitSetSP(uint16_t Reg);
57 
58  /// Emit unwind opcodes to add $sp with an offset.
59  void EmitSPOffset(int64_t Offset);
60 
61  /// Emit unwind raw opcodes
62  void EmitRaw(const SmallVectorImpl<uint8_t> &Opcodes) {
63  Ops.insert(Ops.end(), Opcodes.begin(), Opcodes.end());
64  OpBegins.push_back(OpBegins.back() + Opcodes.size());
65  }
66 
67  /// Finalize the unwind opcode sequence for emitBytes()
68  void Finalize(unsigned &PersonalityIndex,
69  SmallVectorImpl<uint8_t> &Result);
70 
71 private:
72  void EmitInt8(unsigned Opcode) {
73  Ops.push_back(Opcode & 0xff);
74  OpBegins.push_back(OpBegins.back() + 1);
75  }
76 
77  void EmitInt16(unsigned Opcode) {
78  Ops.push_back((Opcode >> 8) & 0xff);
79  Ops.push_back(Opcode & 0xff);
80  OpBegins.push_back(OpBegins.back() + 2);
81  }
82 
83  void emitBytes(const uint8_t *Opcode, size_t Size) {
84  Ops.insert(Ops.end(), Opcode, Opcode + Size);
85  OpBegins.push_back(OpBegins.back() + Size);
86  }
87 };
88 
89 } // end namespace llvm
90 
91 #endif // LLVM_LIB_TARGET_ARM_MCTARGETDESC_ARMUNWINDOPASM_H
llvm::Check::Size
@ Size
Definition: FileCheck.h:73
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
Reg
unsigned Reg
Definition: MachineSink.cpp:1566
llvm::MCSymbol
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
llvm::UnwindOpcodeAssembler
Definition: ARMUnwindOpAsm.h:25
llvm::SmallVector< uint8_t, 32 >
Offset
uint64_t Offset
Definition: ELFObjHandler.cpp:81
llvm::UnwindOpcodeAssembler::setPersonality
void setPersonality(const MCSymbol *Per)
Set the personality.
Definition: ARMUnwindOpAsm.h:45
llvm::UnwindOpcodeAssembler::EmitRaw
void EmitRaw(const SmallVectorImpl< uint8_t > &Opcodes)
Emit unwind raw opcodes.
Definition: ARMUnwindOpAsm.h:62
llvm::UnwindOpcodeAssembler::Finalize
void Finalize(unsigned &PersonalityIndex, SmallVectorImpl< uint8_t > &Result)
Finalize the unwind opcode sequence for emitBytes()
Definition: ARMUnwindOpAsm.cpp:155
llvm::UnwindOpcodeAssembler::UnwindOpcodeAssembler
UnwindOpcodeAssembler()
Definition: ARMUnwindOpAsm.h:32
llvm::UnwindOpcodeAssembler::EmitSetSP
void EmitSetSP(uint16_t Reg)
Emit unwind opcodes to copy address from source register to $sp.
Definition: ARMUnwindOpAsm.cpp:127
llvm::UnwindOpcodeAssembler::EmitSPOffset
void EmitSPOffset(int64_t Offset)
Emit unwind opcodes to add $sp with an offset.
Definition: ARMUnwindOpAsm.cpp:132
uint32_t
llvm::UnwindOpcodeAssembler::EmitRegSave
void EmitRegSave(uint32_t RegSave)
Emit unwind opcodes for .save directives.
Definition: ARMUnwindOpAsm.cpp:66
uint16_t
llvm::SmallVectorImpl::clear
void clear()
Definition: SmallVector.h:585
llvm::UnwindOpcodeAssembler::EmitVFPRegSave
void EmitVFPRegSave(uint32_t VFPRegSave)
Emit unwind opcodes for .vsave directives.
Definition: ARMUnwindOpAsm.cpp:104
SmallVector.h
llvm::SmallVectorImpl< uint8_t >
llvm::UnwindOpcodeAssembler::Reset
void Reset()
Reset the unwind opcode assembler.
Definition: ARMUnwindOpAsm.h:37
llvm::ISD::MCSymbol
@ MCSymbol
Definition: ISDOpcodes.h:172
llvm::SmallVectorImpl::insert
iterator insert(iterator I, T &&Elt)
Definition: SmallVector.h:773