e2c440081444638d1bf500f1c3294b1fcc5b1445
[oota-llvm.git] / lib / Target / ARM / MCTargetDesc / ARMUnwindOpAsm.h
1 //===-- ARMUnwindOpAsm.h - ARM Unwind Opcodes Assembler ---------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file declares the unwind opcode assmebler for ARM exception handling
11 // table.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef ARM_UNWIND_OP_ASM_H
16 #define ARM_UNWIND_OP_ASM_H
17
18 #include "llvm/ADT/SmallVector.h"
19 #include "llvm/ADT/StringRef.h"
20 #include "llvm/Support/ARMEHABI.h"
21 #include "llvm/Support/DataTypes.h"
22
23 namespace llvm {
24
25 class MCSymbol;
26
27 class UnwindOpcodeAssembler {
28 private:
29   llvm::SmallVector<uint8_t, 32> Ops;
30   llvm::SmallVector<unsigned, 8> OpBegins;
31   bool HasPersonality;
32
33 public:
34   UnwindOpcodeAssembler()
35       : HasPersonality(0) {
36     OpBegins.push_back(0);
37   }
38
39   /// Reset the unwind opcode assembler.
40   void Reset() {
41     Ops.clear();
42     OpBegins.clear();
43     OpBegins.push_back(0);
44     HasPersonality = 0;
45   }
46
47   /// Set the personality
48   void setPersonality(const MCSymbol *Per) {
49     HasPersonality = 1;
50   }
51
52   /// Emit unwind opcodes for .save directives
53   void EmitRegSave(uint32_t RegSave);
54
55   /// Emit unwind opcodes for .vsave directives
56   void EmitVFPRegSave(uint32_t VFPRegSave);
57
58   /// Emit unwind opcodes to copy address from source register to $sp.
59   void EmitSetSP(uint16_t Reg);
60
61   /// Emit unwind opcodes to add $sp with an offset.
62   void EmitSPOffset(int64_t Offset);
63
64   /// Emit unwind raw opcodes
65   void EmitRaw(const SmallVectorImpl<uint8_t> &Opcodes) {
66     Ops.insert(Ops.end(), Opcodes.begin(), Opcodes.end());
67     OpBegins.push_back(OpBegins.back() + Opcodes.size());
68   }
69
70   /// Finalize the unwind opcode sequence for EmitBytes()
71   void Finalize(unsigned &PersonalityIndex,
72                 SmallVectorImpl<uint8_t> &Result);
73
74 private:
75   void EmitInt8(unsigned Opcode) {
76     Ops.push_back(Opcode & 0xff);
77     OpBegins.push_back(OpBegins.back() + 1);
78   }
79
80   void EmitInt16(unsigned Opcode) {
81     Ops.push_back((Opcode >> 8) & 0xff);
82     Ops.push_back(Opcode & 0xff);
83     OpBegins.push_back(OpBegins.back() + 2);
84   }
85
86   void EmitBytes(const uint8_t *Opcode, size_t Size) {
87     Ops.insert(Ops.end(), Opcode, Opcode + Size);
88     OpBegins.push_back(OpBegins.back() + Size);
89   }
90 };
91
92 } // namespace llvm
93
94 #endif // ARM_UNWIND_OP_ASM_H