1 //===-- ARMUnwindOpAsm.h - ARM Unwind Opcodes Assembler ---------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file declares the unwind opcode assmebler for ARM exception handling
13 //===----------------------------------------------------------------------===//
15 #ifndef ARM_UNWIND_OP_ASM_H
16 #define ARM_UNWIND_OP_ASM_H
18 #include "ARMUnwindOp.h"
20 #include "llvm/ADT/SmallVector.h"
21 #include "llvm/ADT/StringRef.h"
22 #include "llvm/Support/DataTypes.h"
28 class UnwindOpcodeAssembler {
30 llvm::SmallVector<uint8_t, 8> Ops;
33 unsigned PersonalityIndex;
37 // The number of bytes to be preserved for the size and personality index
38 // prefix of unwind opcodes.
39 NUM_PRESERVED_PREFIX_BUF = 2
43 UnwindOpcodeAssembler()
44 : Ops(NUM_PRESERVED_PREFIX_BUF), Offset(NUM_PRESERVED_PREFIX_BUF),
45 PersonalityIndex(NUM_PERSONALITY_INDEX), HasPersonality(0) {
48 /// Reset the unwind opcode assembler.
50 Ops.resize(NUM_PRESERVED_PREFIX_BUF);
51 Offset = NUM_PRESERVED_PREFIX_BUF;
52 PersonalityIndex = NUM_PERSONALITY_INDEX;
56 /// Get the size of the payload (including the size byte)
58 return Ops.size() - Offset;
61 /// Get the beginning of the payload
62 const uint8_t *begin() const {
63 return Ops.begin() + Offset;
67 StringRef data() const {
68 return StringRef(reinterpret_cast<const char *>(begin()), size());
71 /// Set the personality index
72 void setPersonality(const MCSymbol *Per) {
76 /// Get the personality index
77 unsigned getPersonalityIndex() const {
78 return PersonalityIndex;
81 /// Emit unwind opcodes for .save directives
82 void EmitRegSave(uint32_t RegSave);
84 /// Emit unwind opcodes for .vsave directives
85 void EmitVFPRegSave(uint32_t VFPRegSave);
87 /// Emit unwind opcodes for .setfp directives
88 void EmitSetFP(uint16_t FPReg);
90 /// Emit unwind opcodes to update stack pointer
91 void EmitSPOffset(int64_t Offset);
93 /// Finalize the unwind opcode sequence for EmitBytes()
97 /// Get the size of the opcodes in bytes.
98 size_t getOpcodeSize() const {
99 return Ops.size() - NUM_PRESERVED_PREFIX_BUF;
102 /// Add the length prefix to the payload
103 void AddOpcodeSizePrefix(size_t Pos);
105 /// Add personality index prefix in some compact format
106 void AddPersonalityIndexPrefix(size_t Pos, unsigned PersonalityIndex);
108 /// Fill the words with finish opcode if it is not aligned
109 void EmitFinishOpcodes();
114 #endif // ARM_UNWIND_OP_ASM_H