David Srbecky | 1109fb3 | 2015-04-07 20:21:06 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef ART_COMPILER_DEX_QUICK_LAZY_DEBUG_FRAME_OPCODE_WRITER_H_ |
| 18 | #define ART_COMPILER_DEX_QUICK_LAZY_DEBUG_FRAME_OPCODE_WRITER_H_ |
| 19 | |
| 20 | #include "base/arena_allocator.h" |
| 21 | #include "base/arena_containers.h" |
| 22 | #include "dwarf/debug_frame_opcode_writer.h" |
| 23 | |
| 24 | namespace art { |
| 25 | struct LIR; |
| 26 | namespace dwarf { |
| 27 | |
| 28 | // When we are generating the CFI code, we do not know the instuction offsets, |
| 29 | // this class stores the LIR references and patches the instruction stream later. |
| 30 | class LazyDebugFrameOpCodeWriter FINAL |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 31 | : public DebugFrameOpCodeWriter<ArenaAllocatorAdapter<uint8_t>> { |
David Srbecky | 1109fb3 | 2015-04-07 20:21:06 +0100 | [diff] [blame] | 32 | typedef DebugFrameOpCodeWriter<ArenaAllocatorAdapter<uint8_t>> Base; |
| 33 | public: |
| 34 | // This method is implicitely called the by opcode writers. |
| 35 | virtual void ImplicitlyAdvancePC() OVERRIDE { |
| 36 | DCHECK_EQ(patched_, false); |
| 37 | DCHECK_EQ(this->current_pc_, 0); |
| 38 | advances_.push_back({this->data()->size(), *last_lir_insn_}); |
| 39 | } |
| 40 | |
David Srbecky | 1109fb3 | 2015-04-07 20:21:06 +0100 | [diff] [blame] | 41 | const ArenaVector<uint8_t>* Patch(size_t code_size); |
| 42 | |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 43 | LazyDebugFrameOpCodeWriter(LIR** last_lir_insn, bool enable_writes, ArenaAllocator* allocator) |
| 44 | : Base(enable_writes, allocator->Adapter()), |
| 45 | last_lir_insn_(last_lir_insn), |
| 46 | advances_(allocator->Adapter()), |
| 47 | patched_(false) { |
David Srbecky | 1109fb3 | 2015-04-07 20:21:06 +0100 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | private: |
| 51 | typedef struct { |
| 52 | size_t pos; |
| 53 | LIR* last_lir_insn; |
| 54 | } Advance; |
| 55 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 56 | using Base::data; // Hidden. Use Patch method instead. |
| 57 | |
David Srbecky | 1109fb3 | 2015-04-07 20:21:06 +0100 | [diff] [blame] | 58 | LIR** last_lir_insn_; |
David Srbecky | 1109fb3 | 2015-04-07 20:21:06 +0100 | [diff] [blame] | 59 | ArenaVector<Advance> advances_; |
| 60 | bool patched_; |
| 61 | |
| 62 | DISALLOW_COPY_AND_ASSIGN(LazyDebugFrameOpCodeWriter); |
| 63 | }; |
| 64 | |
| 65 | } // namespace dwarf |
| 66 | } // namespace art |
| 67 | |
| 68 | #endif // ART_COMPILER_DEX_QUICK_LAZY_DEBUG_FRAME_OPCODE_WRITER_H_ |