blob: 3e9fb96bfa923b611feb833c9f3e4ead2ce833db [file] [log] [blame]
David Srbecky1109fb32015-04-07 20:21:06 +01001/*
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
24namespace art {
25struct LIR;
26namespace 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.
30class LazyDebugFrameOpCodeWriter FINAL
David Srbeckyc6b4dd82015-04-07 20:32:43 +010031 : public DebugFrameOpCodeWriter<ArenaAllocatorAdapter<uint8_t>> {
David Srbecky1109fb32015-04-07 20:21:06 +010032 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 Srbecky1109fb32015-04-07 20:21:06 +010041 const ArenaVector<uint8_t>* Patch(size_t code_size);
42
Roland Levillain3887c462015-08-12 18:15:42 +010043 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 Srbecky1109fb32015-04-07 20:21:06 +010048 }
49
50 private:
51 typedef struct {
52 size_t pos;
53 LIR* last_lir_insn;
54 } Advance;
55
David Srbeckyc6b4dd82015-04-07 20:32:43 +010056 using Base::data; // Hidden. Use Patch method instead.
57
David Srbecky1109fb32015-04-07 20:21:06 +010058 LIR** last_lir_insn_;
David Srbecky1109fb32015-04-07 20:21:06 +010059 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_