1 /*
2  * Copyright (C) 2017 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 #pragma once
18 
19 #include "common.h"
20 #include "code_ir.h"
21 #include "dex_ir.h"
22 #include "buffer.h"
23 #include "chronometer.h"
24 
25 namespace lir {
26 
27 // Generates try/catch blocks from code IR
28 class TryBlocksEncoder : public Visitor {
29  private:
30   virtual bool Visit(TryBlockEnd* try_end) override;
31 
32  public:
TryBlocksEncoder(const InstructionsList & instructions)33   explicit TryBlocksEncoder(const InstructionsList& instructions)
34     : instructions_(instructions) {
35   }
36 
37   ~TryBlocksEncoder() = default;
38 
39   void Encode(ir::Code* ir_code, std::shared_ptr<ir::DexFile> dex_ir);
40 
41  private:
42   slicer::Buffer handlers_;
43   slicer::Buffer tries_;
44   const InstructionsList& instructions_;
45 };
46 
47 } // namespace lir
48 
49