xref: /aosp_15_r20/dalvik/dx/src/com/android/dex/Code.java (revision 055d459012065f78d96b68be8421640240ddf631)
1*055d4590SKeyi Gui /*
2*055d4590SKeyi Gui  * Copyright (C) 2011 The Android Open Source Project
3*055d4590SKeyi Gui  *
4*055d4590SKeyi Gui  * Licensed under the Apache License, Version 2.0 (the "License");
5*055d4590SKeyi Gui  * you may not use this file except in compliance with the License.
6*055d4590SKeyi Gui  * You may obtain a copy of the License at
7*055d4590SKeyi Gui  *
8*055d4590SKeyi Gui  *      http://www.apache.org/licenses/LICENSE-2.0
9*055d4590SKeyi Gui  *
10*055d4590SKeyi Gui  * Unless required by applicable law or agreed to in writing, software
11*055d4590SKeyi Gui  * distributed under the License is distributed on an "AS IS" BASIS,
12*055d4590SKeyi Gui  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*055d4590SKeyi Gui  * See the License for the specific language governing permissions and
14*055d4590SKeyi Gui  * limitations under the License.
15*055d4590SKeyi Gui  */
16*055d4590SKeyi Gui 
17*055d4590SKeyi Gui package com.android.dex;
18*055d4590SKeyi Gui 
19*055d4590SKeyi Gui public final class Code {
20*055d4590SKeyi Gui     private final int registersSize;
21*055d4590SKeyi Gui     private final int insSize;
22*055d4590SKeyi Gui     private final int outsSize;
23*055d4590SKeyi Gui     private final int debugInfoOffset;
24*055d4590SKeyi Gui     private final short[] instructions;
25*055d4590SKeyi Gui     private final Try[] tries;
26*055d4590SKeyi Gui     private final CatchHandler[] catchHandlers;
27*055d4590SKeyi Gui 
28*055d4590SKeyi Gui     public Code(int registersSize, int insSize, int outsSize, int debugInfoOffset,
29*055d4590SKeyi Gui             short[] instructions, Try[] tries, CatchHandler[] catchHandlers) {
30*055d4590SKeyi Gui         this.registersSize = registersSize;
31*055d4590SKeyi Gui         this.insSize = insSize;
32*055d4590SKeyi Gui         this.outsSize = outsSize;
33*055d4590SKeyi Gui         this.debugInfoOffset = debugInfoOffset;
34*055d4590SKeyi Gui         this.instructions = instructions;
35*055d4590SKeyi Gui         this.tries = tries;
36*055d4590SKeyi Gui         this.catchHandlers = catchHandlers;
37*055d4590SKeyi Gui     }
38*055d4590SKeyi Gui 
39*055d4590SKeyi Gui     public int getRegistersSize() {
40*055d4590SKeyi Gui         return registersSize;
41*055d4590SKeyi Gui     }
42*055d4590SKeyi Gui 
43*055d4590SKeyi Gui     public int getInsSize() {
44*055d4590SKeyi Gui         return insSize;
45*055d4590SKeyi Gui     }
46*055d4590SKeyi Gui 
47*055d4590SKeyi Gui     public int getOutsSize() {
48*055d4590SKeyi Gui         return outsSize;
49*055d4590SKeyi Gui     }
50*055d4590SKeyi Gui 
51*055d4590SKeyi Gui     public int getDebugInfoOffset() {
52*055d4590SKeyi Gui         return debugInfoOffset;
53*055d4590SKeyi Gui     }
54*055d4590SKeyi Gui 
55*055d4590SKeyi Gui     public short[] getInstructions() {
56*055d4590SKeyi Gui         return instructions;
57*055d4590SKeyi Gui     }
58*055d4590SKeyi Gui 
59*055d4590SKeyi Gui     public Try[] getTries() {
60*055d4590SKeyi Gui         return tries;
61*055d4590SKeyi Gui     }
62*055d4590SKeyi Gui 
63*055d4590SKeyi Gui     public CatchHandler[] getCatchHandlers() {
64*055d4590SKeyi Gui         return catchHandlers;
65*055d4590SKeyi Gui     }
66*055d4590SKeyi Gui 
67*055d4590SKeyi Gui     public static class Try {
68*055d4590SKeyi Gui         final int startAddress;
69*055d4590SKeyi Gui         final int instructionCount;
70*055d4590SKeyi Gui         final int catchHandlerIndex;
71*055d4590SKeyi Gui 
72*055d4590SKeyi Gui         Try(int startAddress, int instructionCount, int catchHandlerIndex) {
73*055d4590SKeyi Gui             this.startAddress = startAddress;
74*055d4590SKeyi Gui             this.instructionCount = instructionCount;
75*055d4590SKeyi Gui             this.catchHandlerIndex = catchHandlerIndex;
76*055d4590SKeyi Gui         }
77*055d4590SKeyi Gui 
78*055d4590SKeyi Gui         public int getStartAddress() {
79*055d4590SKeyi Gui             return startAddress;
80*055d4590SKeyi Gui         }
81*055d4590SKeyi Gui 
82*055d4590SKeyi Gui         public int getInstructionCount() {
83*055d4590SKeyi Gui             return instructionCount;
84*055d4590SKeyi Gui         }
85*055d4590SKeyi Gui 
86*055d4590SKeyi Gui         /**
87*055d4590SKeyi Gui          * Returns this try's catch handler <strong>index</strong>. Note that
88*055d4590SKeyi Gui          * this is distinct from the its catch handler <strong>offset</strong>.
89*055d4590SKeyi Gui          */
90*055d4590SKeyi Gui         public int getCatchHandlerIndex() {
91*055d4590SKeyi Gui             return catchHandlerIndex;
92*055d4590SKeyi Gui         }
93*055d4590SKeyi Gui     }
94*055d4590SKeyi Gui 
95*055d4590SKeyi Gui     public static class CatchHandler {
96*055d4590SKeyi Gui         final int[] typeIndexes;
97*055d4590SKeyi Gui         final int[] addresses;
98*055d4590SKeyi Gui         final int catchAllAddress;
99*055d4590SKeyi Gui         final int offset;
100*055d4590SKeyi Gui 
101*055d4590SKeyi Gui         public CatchHandler(int[] typeIndexes, int[] addresses, int catchAllAddress, int offset) {
102*055d4590SKeyi Gui             this.typeIndexes = typeIndexes;
103*055d4590SKeyi Gui             this.addresses = addresses;
104*055d4590SKeyi Gui             this.catchAllAddress = catchAllAddress;
105*055d4590SKeyi Gui             this.offset = offset;
106*055d4590SKeyi Gui         }
107*055d4590SKeyi Gui 
108*055d4590SKeyi Gui         public int[] getTypeIndexes() {
109*055d4590SKeyi Gui             return typeIndexes;
110*055d4590SKeyi Gui         }
111*055d4590SKeyi Gui 
112*055d4590SKeyi Gui         public int[] getAddresses() {
113*055d4590SKeyi Gui             return addresses;
114*055d4590SKeyi Gui         }
115*055d4590SKeyi Gui 
116*055d4590SKeyi Gui         public int getCatchAllAddress() {
117*055d4590SKeyi Gui             return catchAllAddress;
118*055d4590SKeyi Gui         }
119*055d4590SKeyi Gui 
120*055d4590SKeyi Gui         public int getOffset() {
121*055d4590SKeyi Gui             return offset;
122*055d4590SKeyi Gui         }
123*055d4590SKeyi Gui     }
124*055d4590SKeyi Gui }
125