1 /*
2  * Copyright (C) 2011 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 package com.android.dex;
18 
19 public final class Code {
20     private final int registersSize;
21     private final int insSize;
22     private final int outsSize;
23     private final int debugInfoOffset;
24     private final short[] instructions;
25     private final Try[] tries;
26     private final CatchHandler[] catchHandlers;
27 
Code(int registersSize, int insSize, int outsSize, int debugInfoOffset, short[] instructions, Try[] tries, CatchHandler[] catchHandlers)28     public Code(int registersSize, int insSize, int outsSize, int debugInfoOffset,
29             short[] instructions, Try[] tries, CatchHandler[] catchHandlers) {
30         this.registersSize = registersSize;
31         this.insSize = insSize;
32         this.outsSize = outsSize;
33         this.debugInfoOffset = debugInfoOffset;
34         this.instructions = instructions;
35         this.tries = tries;
36         this.catchHandlers = catchHandlers;
37     }
38 
getRegistersSize()39     public int getRegistersSize() {
40         return registersSize;
41     }
42 
getInsSize()43     public int getInsSize() {
44         return insSize;
45     }
46 
getOutsSize()47     public int getOutsSize() {
48         return outsSize;
49     }
50 
getDebugInfoOffset()51     public int getDebugInfoOffset() {
52         return debugInfoOffset;
53     }
54 
getInstructions()55     public short[] getInstructions() {
56         return instructions;
57     }
58 
getTries()59     public Try[] getTries() {
60         return tries;
61     }
62 
getCatchHandlers()63     public CatchHandler[] getCatchHandlers() {
64         return catchHandlers;
65     }
66 
67     public static class Try {
68         final int startAddress;
69         final int instructionCount;
70         final int catchHandlerIndex;
71 
Try(int startAddress, int instructionCount, int catchHandlerIndex)72         Try(int startAddress, int instructionCount, int catchHandlerIndex) {
73             this.startAddress = startAddress;
74             this.instructionCount = instructionCount;
75             this.catchHandlerIndex = catchHandlerIndex;
76         }
77 
getStartAddress()78         public int getStartAddress() {
79             return startAddress;
80         }
81 
getInstructionCount()82         public int getInstructionCount() {
83             return instructionCount;
84         }
85 
86         /**
87          * Returns this try's catch handler <strong>index</strong>. Note that
88          * this is distinct from the its catch handler <strong>offset</strong>.
89          */
getCatchHandlerIndex()90         public int getCatchHandlerIndex() {
91             return catchHandlerIndex;
92         }
93     }
94 
95     public static class CatchHandler {
96         final int[] typeIndexes;
97         final int[] addresses;
98         final int catchAllAddress;
99         final int offset;
100 
CatchHandler(int[] typeIndexes, int[] addresses, int catchAllAddress, int offset)101         public CatchHandler(int[] typeIndexes, int[] addresses, int catchAllAddress, int offset) {
102             this.typeIndexes = typeIndexes;
103             this.addresses = addresses;
104             this.catchAllAddress = catchAllAddress;
105             this.offset = offset;
106         }
107 
getTypeIndexes()108         public int[] getTypeIndexes() {
109             return typeIndexes;
110         }
111 
getAddresses()112         public int[] getAddresses() {
113             return addresses;
114         }
115 
getCatchAllAddress()116         public int getCatchAllAddress() {
117             return catchAllAddress;
118         }
119 
getOffset()120         public int getOffset() {
121             return offset;
122         }
123     }
124 }
125