ImmutableInstructionFactory.java revision 42627b850c8f68a594f105e04b97c512b292b698
1/*
2 * Copyright 2013, Google Inc.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met:
8 *
9 *     * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *     * Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following disclaimer
13 * in the documentation and/or other materials provided with the
14 * distribution.
15 *     * Neither the name of Google Inc. nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32package org.jf.dexlib2.immutable.instruction;
33
34import org.jf.dexlib2.Opcode;
35import org.jf.dexlib2.iface.instruction.SwitchElement;
36import org.jf.dexlib2.iface.reference.Reference;
37import org.jf.dexlib2.writer.InstructionFactory;
38
39import javax.annotation.Nonnull;
40import javax.annotation.Nullable;
41import java.util.List;
42
43public class ImmutableInstructionFactory implements InstructionFactory<ImmutableInstruction, Reference> {
44    public static final ImmutableInstructionFactory INSTANCE = new ImmutableInstructionFactory();
45
46    private ImmutableInstructionFactory() {
47    }
48
49    public ImmutableInstruction10t makeInstruction10t(@Nonnull Opcode opcode,
50                                                      int codeOffset) {
51        return new ImmutableInstruction10t(opcode, codeOffset);
52    }
53
54    public ImmutableInstruction10x makeInstruction10x(@Nonnull Opcode opcode) {
55        return new ImmutableInstruction10x(opcode);
56    }
57
58    public ImmutableInstruction11n makeInstruction11n(@Nonnull Opcode opcode,
59                                                      int registerA,
60                                                      int literal) {
61        return new ImmutableInstruction11n(opcode, registerA, literal);
62    }
63
64    public ImmutableInstruction11x makeInstruction11x(@Nonnull Opcode opcode,
65                                                      int registerA) {
66        return new ImmutableInstruction11x(opcode, registerA);
67    }
68
69    public ImmutableInstruction12x makeInstruction12x(@Nonnull Opcode opcode,
70                                                      int registerA,
71                                                      int registerB) {
72        return new ImmutableInstruction12x(opcode, registerA, registerB);
73    }
74
75    public ImmutableInstruction20bc makeInstruction20bc(@Nonnull Opcode opcode,
76                                                        int verificationError,
77                                                        @Nonnull Reference reference) {
78        return new ImmutableInstruction20bc(opcode, verificationError, reference);
79    }
80
81    public ImmutableInstruction20t makeInstruction20t(@Nonnull Opcode opcode,
82                                                      int codeOffset) {
83        return new ImmutableInstruction20t(opcode, codeOffset);
84    }
85
86    public ImmutableInstruction21c makeInstruction21c(@Nonnull Opcode opcode,
87                                                      int registerA,
88                                                      @Nonnull Reference reference) {
89        return new ImmutableInstruction21c(opcode, registerA, reference);
90    }
91
92    public ImmutableInstruction21ih makeInstruction21ih(@Nonnull Opcode opcode,
93                                                        int registerA,
94                                                        int literal) {
95        return new ImmutableInstruction21ih(opcode, registerA, literal);
96    }
97
98    public ImmutableInstruction21lh makeInstruction21lh(@Nonnull Opcode opcode,
99                                                        int registerA,
100                                                        long literal) {
101        return new ImmutableInstruction21lh(opcode, registerA, literal);
102    }
103
104    public ImmutableInstruction21s makeInstruction21s(@Nonnull Opcode opcode,
105                                                      int registerA,
106                                                      int literal) {
107        return new ImmutableInstruction21s(opcode, registerA, literal);
108    }
109
110    public ImmutableInstruction21t makeInstruction21t(@Nonnull Opcode opcode,
111                                                      int registerA,
112                                                      int codeOffset) {
113        return new ImmutableInstruction21t(opcode, registerA, codeOffset);
114    }
115
116    public ImmutableInstruction22b makeInstruction22b(@Nonnull Opcode opcode,
117                                                      int registerA,
118                                                      int registerB,
119                                                      int literal) {
120        return new ImmutableInstruction22b(opcode, registerA, registerB, literal);
121    }
122
123    public ImmutableInstruction22c makeInstruction22c(@Nonnull Opcode opcode,
124                                                      int registerA,
125                                                      int registerB,
126                                                      @Nonnull Reference reference) {
127        return new ImmutableInstruction22c(opcode, registerA, registerB, reference);
128    }
129
130    public ImmutableInstruction22s makeInstruction22s(@Nonnull Opcode opcode,
131                                                      int registerA,
132                                                      int registerB,
133                                                      int literal) {
134        return new ImmutableInstruction22s(opcode, registerA, registerB, literal);
135    }
136
137    public ImmutableInstruction22t makeInstruction22t(@Nonnull Opcode opcode,
138                                                      int registerA,
139                                                      int registerB,
140                                                      int codeOffset) {
141        return new ImmutableInstruction22t(opcode, registerA, registerB, codeOffset);
142    }
143
144    public ImmutableInstruction22x makeInstruction22x(@Nonnull Opcode opcode,
145                                                      int registerA,
146                                                      int registerB) {
147        return new ImmutableInstruction22x(opcode, registerA, registerB);
148    }
149
150    public ImmutableInstruction23x makeInstruction23x(@Nonnull Opcode opcode,
151                                                      int registerA,
152                                                      int registerB,
153                                                      int registerC) {
154        return new ImmutableInstruction23x(opcode, registerA, registerB, registerC);
155    }
156
157    public ImmutableInstruction30t makeInstruction30t(@Nonnull Opcode opcode,
158                                                      int codeOffset) {
159        return new ImmutableInstruction30t(opcode, codeOffset);
160    }
161
162    public ImmutableInstruction31c makeInstruction31c(@Nonnull Opcode opcode,
163                                                      int registerA,
164                                                      @Nonnull Reference reference) {
165        return new ImmutableInstruction31c(opcode, registerA, reference);
166    }
167
168    public ImmutableInstruction31i makeInstruction31i(@Nonnull Opcode opcode,
169                                                      int registerA,
170                                                      int literal) {
171        return new ImmutableInstruction31i(opcode, registerA, literal);
172    }
173
174    public ImmutableInstruction31t makeInstruction31t(@Nonnull Opcode opcode,
175                                                      int registerA,
176                                                      int codeOffset) {
177        return new ImmutableInstruction31t(opcode, registerA, codeOffset);
178    }
179
180    public ImmutableInstruction32x makeInstruction32x(@Nonnull Opcode opcode,
181                                                      int registerA,
182                                                      int registerB) {
183        return new ImmutableInstruction32x(opcode, registerA, registerB);
184    }
185
186    public ImmutableInstruction35c makeInstruction35c(@Nonnull Opcode opcode,
187                                                      int registerCount,
188                                                      int registerC,
189                                                      int registerD,
190                                                      int registerE,
191                                                      int registerF,
192                                                      int registerG,
193                                                      @Nonnull Reference reference) {
194        return new ImmutableInstruction35c(opcode, registerCount, registerC, registerD, registerE, registerF, registerG,
195                reference);
196    }
197
198    public ImmutableInstruction3rc makeInstruction3rc(@Nonnull Opcode opcode,
199                                                      int startRegister,
200                                                      int registerCount,
201                                                      @Nonnull Reference reference) {
202        return new ImmutableInstruction3rc(opcode, startRegister, registerCount, reference);
203    }
204
205    public ImmutableInstruction51l makeInstruction51l(@Nonnull Opcode opcode,
206                                                      int registerA,
207                                                      long literal) {
208        return new ImmutableInstruction51l(opcode, registerA, literal);
209    }
210
211    public ImmutableSparseSwitchPayload makeSparseSwitchPayload(@Nullable List<? extends SwitchElement> switchElements) {
212        return new ImmutableSparseSwitchPayload(switchElements);
213    }
214
215    public ImmutablePackedSwitchPayload makePackedSwitchPayload(@Nullable List<? extends SwitchElement> switchElements) {
216        return new ImmutablePackedSwitchPayload(switchElements);
217    }
218
219    public ImmutableArrayPayload makeArrayPayload(int elementWidth,
220                                                @Nullable List<Number> arrayElements) {
221        return new ImmutableArrayPayload(elementWidth, arrayElements);
222    }
223}
224