+ std::vector<char> Values;
+
+ MCCFIInstruction(OpType Op, MCSymbol *L, unsigned R, int O, StringRef V)
+ : Operation(Op), Label(L), Register(R), Offset(O),
+ Values(V.begin(), V.end()) {
+ assert(Op != OpRegister);
+ }
+
+ MCCFIInstruction(OpType Op, MCSymbol *L, unsigned R1, unsigned R2)
+ : Operation(Op), Label(L), Register(R1), Register2(R2) {
+ assert(Op == OpRegister);
+ }
+
+public:
+ /// \brief .cfi_def_cfa defines a rule for computing CFA as: take address from
+ /// Register and add Offset to it.
+ static MCCFIInstruction createDefCfa(MCSymbol *L, unsigned Register,
+ int Offset) {
+ return MCCFIInstruction(OpDefCfa, L, Register, -Offset, "");
+ }
+
+ /// \brief .cfi_def_cfa_register modifies a rule for computing CFA. From now
+ /// on Register will be used instead of the old one. Offset remains the same.
+ static MCCFIInstruction createDefCfaRegister(MCSymbol *L, unsigned Register) {
+ return MCCFIInstruction(OpDefCfaRegister, L, Register, 0, "");
+ }
+
+ /// \brief .cfi_def_cfa_offset modifies a rule for computing CFA. Register
+ /// remains the same, but offset is new. Note that it is the absolute offset
+ /// that will be added to a defined register to the compute CFA address.
+ static MCCFIInstruction createDefCfaOffset(MCSymbol *L, int Offset) {
+ return MCCFIInstruction(OpDefCfaOffset, L, 0, -Offset, "");
+ }
+
+ /// \brief .cfi_adjust_cfa_offset Same as .cfi_def_cfa_offset, but
+ /// Offset is a relative value that is added/subtracted from the previous
+ /// offset.
+ static MCCFIInstruction createAdjustCfaOffset(MCSymbol *L, int Adjustment) {
+ return MCCFIInstruction(OpAdjustCfaOffset, L, 0, Adjustment, "");
+ }
+
+ /// \brief .cfi_offset Previous value of Register is saved at offset Offset
+ /// from CFA.
+ static MCCFIInstruction createOffset(MCSymbol *L, unsigned Register,
+ int Offset) {
+ return MCCFIInstruction(OpOffset, L, Register, Offset, "");
+ }
+
+ /// \brief .cfi_rel_offset Previous value of Register is saved at offset
+ /// Offset from the current CFA register. This is transformed to .cfi_offset
+ /// using the known displacement of the CFA register from the CFA.
+ static MCCFIInstruction createRelOffset(MCSymbol *L, unsigned Register,
+ int Offset) {
+ return MCCFIInstruction(OpRelOffset, L, Register, Offset, "");
+ }
+
+ /// \brief .cfi_register Previous value of Register1 is saved in
+ /// register Register2.
+ static MCCFIInstruction createRegister(MCSymbol *L, unsigned Register1,
+ unsigned Register2) {
+ return MCCFIInstruction(OpRegister, L, Register1, Register2);
+ }
+
+ /// \brief .cfi_window_save SPARC register window is saved.
+ static MCCFIInstruction createWindowSave(MCSymbol *L) {
+ return MCCFIInstruction(OpWindowSave, L, 0, 0, "");
+ }
+
+ /// \brief .cfi_restore says that the rule for Register is now the same as it
+ /// was at the beginning of the function, after all initial instructions added
+ /// by .cfi_startproc were executed.
+ static MCCFIInstruction createRestore(MCSymbol *L, unsigned Register) {
+ return MCCFIInstruction(OpRestore, L, Register, 0, "");
+ }
+
+ /// \brief .cfi_undefined From now on the previous value of Register can't be
+ /// restored anymore.
+ static MCCFIInstruction createUndefined(MCSymbol *L, unsigned Register) {
+ return MCCFIInstruction(OpUndefined, L, Register, 0, "");
+ }
+
+ /// \brief .cfi_same_value Current value of Register is the same as in the
+ /// previous frame. I.e., no restoration is needed.
+ static MCCFIInstruction createSameValue(MCSymbol *L, unsigned Register) {
+ return MCCFIInstruction(OpSameValue, L, Register, 0, "");
+ }
+
+ /// \brief .cfi_remember_state Save all current rules for all registers.
+ static MCCFIInstruction createRememberState(MCSymbol *L) {
+ return MCCFIInstruction(OpRememberState, L, 0, 0, "");
+ }
+
+ /// \brief .cfi_restore_state Restore the previously saved state.
+ static MCCFIInstruction createRestoreState(MCSymbol *L) {
+ return MCCFIInstruction(OpRestoreState, L, 0, 0, "");
+ }
+
+ /// \brief .cfi_escape Allows the user to add arbitrary bytes to the unwind
+ /// info.
+ static MCCFIInstruction createEscape(MCSymbol *L, StringRef Vals) {
+ return MCCFIInstruction(OpEscape, L, 0, 0, Vals);
+ }
+
+ OpType getOperation() const { return Operation; }
+ MCSymbol *getLabel() const { return Label; }
+
+ unsigned getRegister() const {
+ assert(Operation == OpDefCfa || Operation == OpOffset ||
+ Operation == OpRestore || Operation == OpUndefined ||
+ Operation == OpSameValue || Operation == OpDefCfaRegister ||
+ Operation == OpRelOffset || Operation == OpRegister);
+ return Register;
+ }
+
+ unsigned getRegister2() const {
+ assert(Operation == OpRegister);
+ return Register2;
+ }
+
+ int getOffset() const {
+ assert(Operation == OpDefCfa || Operation == OpOffset ||
+ Operation == OpRelOffset || Operation == OpDefCfaOffset ||
+ Operation == OpAdjustCfaOffset);
+ return Offset;
+ }
+
+ StringRef getValues() const {
+ assert(Operation == OpEscape);
+ return StringRef(&Values[0], Values.size());
+ }
+};
+
+struct MCDwarfFrameInfo {
+ MCDwarfFrameInfo()
+ : Begin(nullptr), End(nullptr), Personality(nullptr), Lsda(nullptr),
+ Instructions(), CurrentCfaRegister(0), PersonalityEncoding(),
+ LsdaEncoding(0), CompactUnwindEncoding(0), IsSignalFrame(false),
+ IsSimple(false) {}
+ MCSymbol *Begin;
+ MCSymbol *End;
+ const MCSymbol *Personality;
+ const MCSymbol *Lsda;
+ std::vector<MCCFIInstruction> Instructions;
+ unsigned CurrentCfaRegister;
+ unsigned PersonalityEncoding;
+ unsigned LsdaEncoding;
+ uint32_t CompactUnwindEncoding;
+ bool IsSignalFrame;
+ bool IsSimple;
+};
+
+class MCDwarfFrameEmitter {
+public:
+ //
+ // This emits the frame info section.
+ //
+ static void Emit(MCObjectStreamer &streamer, MCAsmBackend *MAB, bool isEH);
+ static void EmitAdvanceLoc(MCObjectStreamer &Streamer, uint64_t AddrDelta);
+ static void EncodeAdvanceLoc(MCContext &Context, uint64_t AddrDelta,
+ raw_ostream &OS);
+};