jaroslav@106
|
1 |
/**
|
jaroslav@106
|
2 |
* Back 2 Browser Bytecode Translator
|
jaroslav@106
|
3 |
* Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
|
jaroslav@106
|
4 |
*
|
jaroslav@106
|
5 |
* This program is free software: you can redistribute it and/or modify
|
jaroslav@106
|
6 |
* it under the terms of the GNU General Public License as published by
|
jaroslav@106
|
7 |
* the Free Software Foundation, version 2 of the License.
|
jaroslav@106
|
8 |
*
|
jaroslav@106
|
9 |
* This program is distributed in the hope that it will be useful,
|
jaroslav@106
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
jaroslav@106
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
jaroslav@106
|
12 |
* GNU General Public License for more details.
|
jaroslav@106
|
13 |
*
|
jaroslav@106
|
14 |
* You should have received a copy of the GNU General Public License
|
jaroslav@106
|
15 |
* along with this program. Look for COPYING file in the top folder.
|
jaroslav@106
|
16 |
* If not, see http://opensource.org/licenses/GPL-2.0.
|
jaroslav@106
|
17 |
*/
|
jaroslav@22
|
18 |
package org.apidesign.vm4brwsr;
|
jaroslav@0
|
19 |
|
jaroslav@0
|
20 |
import java.io.IOException;
|
jaroslav@0
|
21 |
import java.io.InputStream;
|
jtulach@167
|
22 |
import org.apidesign.javap.AnnotationParser;
|
jtulach@167
|
23 |
import org.apidesign.javap.ClassData;
|
jtulach@167
|
24 |
import org.apidesign.javap.FieldData;
|
jtulach@167
|
25 |
import org.apidesign.javap.MethodData;
|
lubomir@221
|
26 |
import org.apidesign.javap.StackMapIterator;
|
jtulach@167
|
27 |
import static org.apidesign.javap.RuntimeConstants.*;
|
jaroslav@0
|
28 |
|
jaroslav@0
|
29 |
/** Translator of the code inside class files to JavaScript.
|
jaroslav@0
|
30 |
*
|
jaroslav@0
|
31 |
* @author Jaroslav Tulach <jtulach@netbeans.org>
|
jaroslav@0
|
32 |
*/
|
jtulach@162
|
33 |
public abstract class ByteCodeToJavaScript {
|
jtulach@162
|
34 |
private ClassData jc;
|
jaroslav@272
|
35 |
final Appendable out;
|
jaroslav@0
|
36 |
|
jtulach@162
|
37 |
protected ByteCodeToJavaScript(Appendable out) {
|
jaroslav@0
|
38 |
this.out = out;
|
jaroslav@0
|
39 |
}
|
jtulach@162
|
40 |
|
jtulach@162
|
41 |
/* Collects additional required resources.
|
jtulach@162
|
42 |
*
|
jtulach@162
|
43 |
* @param internalClassName classes that were referenced and should be loaded in order the
|
jtulach@162
|
44 |
* generated JavaScript code works properly. The names are in internal
|
jtulach@162
|
45 |
* JVM form so String is <code>java/lang/String</code>.
|
jtulach@162
|
46 |
*/
|
jtulach@162
|
47 |
protected abstract boolean requireReference(String internalClassName);
|
jtulach@162
|
48 |
|
jtulach@162
|
49 |
/*
|
jtulach@162
|
50 |
* @param resourcePath name of resources to read
|
jtulach@162
|
51 |
*/
|
jtulach@162
|
52 |
protected abstract void requireScript(String resourcePath);
|
jaroslav@213
|
53 |
|
jaroslav@213
|
54 |
/** Allows subclasses to redefine what field a function representing a
|
jaroslav@213
|
55 |
* class gets assigned. By default it returns the suggested name followed
|
jaroslav@213
|
56 |
* by <code>" = "</code>;
|
jaroslav@213
|
57 |
*
|
jaroslav@213
|
58 |
* @param className suggested name of the class
|
jaroslav@213
|
59 |
*/
|
jaroslav@213
|
60 |
protected String assignClass(String className) {
|
jaroslav@213
|
61 |
return className + " = ";
|
jaroslav@213
|
62 |
}
|
jaroslav@18
|
63 |
|
jaroslav@18
|
64 |
/**
|
jaroslav@18
|
65 |
* Converts a given class file to a JavaScript version.
|
jaroslav@18
|
66 |
*
|
jaroslav@0
|
67 |
* @param classFile input stream with code of the .class file
|
jaroslav@97
|
68 |
* @return the initialization code for this class, if any. Otherwise <code>null</code>
|
jaroslav@91
|
69 |
*
|
jaroslav@0
|
70 |
* @throws IOException if something goes wrong during read or write or translating
|
jaroslav@0
|
71 |
*/
|
jaroslav@18
|
72 |
|
jtulach@162
|
73 |
public String compile(InputStream classFile) throws IOException {
|
jtulach@162
|
74 |
this.jc = new ClassData(classFile);
|
jaroslav@152
|
75 |
byte[] arrData = jc.findAnnotationData(true);
|
jaroslav@170
|
76 |
String[] arr = findAnnotation(arrData, jc,
|
jaroslav@170
|
77 |
"org.apidesign.bck2brwsr.core.ExtraJavaScript",
|
jaroslav@170
|
78 |
"resource", "processByteCode"
|
jaroslav@170
|
79 |
);
|
jaroslav@152
|
80 |
if (arr != null) {
|
jtulach@162
|
81 |
requireScript(arr[0]);
|
jaroslav@152
|
82 |
if ("0".equals(arr[1])) {
|
jaroslav@97
|
83 |
return null;
|
jaroslav@91
|
84 |
}
|
jaroslav@91
|
85 |
}
|
jaroslav@239
|
86 |
String[] proto = findAnnotation(arrData, jc,
|
jaroslav@239
|
87 |
"org.apidesign.bck2brwsr.core.JavaScriptPrototype",
|
jaroslav@239
|
88 |
"container", "prototype"
|
jaroslav@239
|
89 |
);
|
jtulach@162
|
90 |
StringArray toInitilize = new StringArray();
|
jaroslav@151
|
91 |
final String className = className(jc);
|
jaroslav@213
|
92 |
out.append("\n\n").append(assignClass(className));
|
jaroslav@213
|
93 |
out.append("function CLS() {");
|
jaroslav@213
|
94 |
out.append("\n if (!CLS.prototype.$instOf_").append(className).append(") {");
|
jtulach@191
|
95 |
for (FieldData v : jc.getFields()) {
|
jtulach@191
|
96 |
if (v.isStatic()) {
|
jaroslav@213
|
97 |
out.append("\n CLS.").append(v.getName()).append(initField(v));
|
jtulach@191
|
98 |
}
|
jtulach@191
|
99 |
}
|
jaroslav@239
|
100 |
if (proto == null) {
|
jaroslav@239
|
101 |
String sc = jc.getSuperClassName(); // with _
|
jaroslav@230
|
102 |
out.append("\n var pp = ").
|
jaroslav@205
|
103 |
append(sc.replace('/', '_')).append("(true);");
|
jaroslav@230
|
104 |
out.append("\n var p = CLS.prototype = pp;");
|
jaroslav@239
|
105 |
out.append("\n var c = p;");
|
jaroslav@230
|
106 |
out.append("\n var sprcls = pp.constructor.$class;");
|
jtulach@130
|
107 |
} else {
|
jaroslav@240
|
108 |
out.append("\n var p = CLS.prototype = ").append(proto[1]).append(";");
|
jaroslav@239
|
109 |
out.append("\n var c = ").append(proto[0]).append(";");
|
jaroslav@230
|
110 |
out.append("\n var sprcls = null;");
|
jaroslav@13
|
111 |
}
|
jaroslav@151
|
112 |
for (MethodData m : jc.getMethods()) {
|
jaroslav@240
|
113 |
byte[] onlyArr = m.findAnnotationData(true);
|
jaroslav@240
|
114 |
String[] only = findAnnotation(onlyArr, jc,
|
jaroslav@240
|
115 |
"org.apidesign.bck2brwsr.core.JavaScriptOnly",
|
jaroslav@240
|
116 |
"name", "value"
|
jaroslav@240
|
117 |
);
|
jaroslav@240
|
118 |
if (only != null) {
|
jaroslav@240
|
119 |
if (only[0] != null && only[1] != null) {
|
jaroslav@240
|
120 |
out.append("\n p.").append(only[0]).append(" = ")
|
jaroslav@240
|
121 |
.append(only[1]).append(";");
|
jaroslav@240
|
122 |
}
|
jaroslav@240
|
123 |
continue;
|
jaroslav@240
|
124 |
}
|
jaroslav@266
|
125 |
String mn;
|
jaroslav@203
|
126 |
if (m.isStatic()) {
|
jaroslav@266
|
127 |
mn = generateStaticMethod("\n c.", m, toInitilize);
|
jaroslav@203
|
128 |
} else {
|
jaroslav@266
|
129 |
mn = generateInstanceMethod("\n c.", m);
|
jaroslav@266
|
130 |
}
|
jaroslav@266
|
131 |
byte[] runAnno = m.findAnnotationData(false);
|
jaroslav@266
|
132 |
if (runAnno != null) {
|
jaroslav@266
|
133 |
out.append("\n c.").append(mn).append(".anno = {");
|
jaroslav@266
|
134 |
generateAnno(jc, out, runAnno);
|
jaroslav@266
|
135 |
out.append("\n };");
|
jaroslav@38
|
136 |
}
|
jaroslav@38
|
137 |
}
|
jaroslav@239
|
138 |
out.append("\n c.constructor = CLS;");
|
jaroslav@239
|
139 |
out.append("\n c.$instOf_").append(className).append(" = true;");
|
jaroslav@151
|
140 |
for (String superInterface : jc.getSuperInterfaces()) {
|
jaroslav@239
|
141 |
out.append("\n c.$instOf_").append(superInterface.replace('/', '_')).append(" = true;");
|
jaroslav@40
|
142 |
}
|
jaroslav@225
|
143 |
out.append("\n CLS.$class = java_lang_Class(true);");
|
jaroslav@225
|
144 |
out.append("\n CLS.$class.jvmName = '").append(jc.getClassName()).append("';");
|
jaroslav@230
|
145 |
out.append("\n CLS.$class.superclass = sprcls;");
|
jaroslav@231
|
146 |
out.append("\n CLS.$class.cnstr = CLS;");
|
jaroslav@235
|
147 |
byte[] classAnno = jc.findAnnotationData(false);
|
jaroslav@235
|
148 |
if (classAnno != null) {
|
jaroslav@235
|
149 |
out.append("\n CLS.$class.anno = {");
|
jaroslav@235
|
150 |
generateAnno(jc, out, classAnno);
|
jaroslav@235
|
151 |
out.append("\n };");
|
jaroslav@235
|
152 |
}
|
jaroslav@204
|
153 |
out.append("\n }");
|
jaroslav@205
|
154 |
out.append("\n if (arguments.length === 0) {");
|
jaroslav@226
|
155 |
out.append("\n if (!(this instanceof CLS)) {");
|
jaroslav@226
|
156 |
out.append("\n return new CLS();");
|
jaroslav@226
|
157 |
out.append("\n }");
|
jaroslav@205
|
158 |
for (FieldData v : jc.getFields()) {
|
jaroslav@240
|
159 |
byte[] onlyArr = v.findAnnotationData(true);
|
jaroslav@240
|
160 |
String[] only = findAnnotation(onlyArr, jc,
|
jaroslav@240
|
161 |
"org.apidesign.bck2brwsr.core.JavaScriptOnly",
|
jaroslav@240
|
162 |
"name", "value"
|
jaroslav@240
|
163 |
);
|
jaroslav@240
|
164 |
if (only != null) {
|
jaroslav@240
|
165 |
if (only[0] != null && only[1] != null) {
|
jaroslav@240
|
166 |
out.append("\n p.").append(only[0]).append(" = ")
|
jaroslav@240
|
167 |
.append(only[1]).append(";");
|
jaroslav@240
|
168 |
}
|
jaroslav@240
|
169 |
continue;
|
jaroslav@240
|
170 |
}
|
jaroslav@205
|
171 |
if (!v.isStatic()) {
|
jaroslav@205
|
172 |
out.append("\n this.fld_").
|
jaroslav@205
|
173 |
append(v.getName()).append(initField(v));
|
jaroslav@205
|
174 |
}
|
jaroslav@205
|
175 |
}
|
jaroslav@205
|
176 |
out.append("\n return this;");
|
jaroslav@205
|
177 |
out.append("\n }");
|
jaroslav@224
|
178 |
out.append("\n return arguments[0] ? new CLS() : CLS.prototype;");
|
jaroslav@98
|
179 |
out.append("\n}");
|
jaroslav@97
|
180 |
StringBuilder sb = new StringBuilder();
|
jtulach@162
|
181 |
for (String init : toInitilize.toArray()) {
|
jaroslav@97
|
182 |
sb.append("\n").append(init).append("();");
|
jaroslav@21
|
183 |
}
|
jaroslav@97
|
184 |
return sb.toString();
|
jaroslav@0
|
185 |
}
|
jaroslav@266
|
186 |
private String generateStaticMethod(String prefix, MethodData m, StringArray toInitilize) throws IOException {
|
jaroslav@266
|
187 |
String jsb = javaScriptBody(prefix, m, true);
|
jaroslav@266
|
188 |
if (jsb != null) {
|
jaroslav@266
|
189 |
return jsb;
|
jaroslav@94
|
190 |
}
|
lubomir@307
|
191 |
final String mn = findMethodName(m, new StringBuilder());
|
jaroslav@248
|
192 |
if (mn.equals("class__V")) {
|
jaroslav@224
|
193 |
toInitilize.add(className(jc) + "(false)." + mn);
|
jaroslav@21
|
194 |
}
|
lubomir@307
|
195 |
generateMethod(prefix, mn, m);
|
jaroslav@266
|
196 |
return mn;
|
jaroslav@10
|
197 |
}
|
lubomir@307
|
198 |
|
jaroslav@266
|
199 |
private String generateInstanceMethod(String prefix, MethodData m) throws IOException {
|
jaroslav@266
|
200 |
String jsb = javaScriptBody(prefix, m, false);
|
jaroslav@266
|
201 |
if (jsb != null) {
|
jaroslav@266
|
202 |
return jsb;
|
jaroslav@94
|
203 |
}
|
lubomir@307
|
204 |
final String mn = findMethodName(m, new StringBuilder());
|
lubomir@307
|
205 |
generateMethod(prefix, mn, m);
|
jaroslav@266
|
206 |
return mn;
|
jaroslav@0
|
207 |
}
|
jaroslav@0
|
208 |
|
lubomir@307
|
209 |
private void generateMethod(String prefix, String name, MethodData m)
|
lubomir@307
|
210 |
throws IOException {
|
lubomir@307
|
211 |
final StackMapIterator stackMapIterator = m.createStackMapIterator();
|
lubomir@307
|
212 |
final LocalsMapper lmapper =
|
lubomir@307
|
213 |
new LocalsMapper(stackMapIterator.getArguments());
|
lubomir@307
|
214 |
|
lubomir@307
|
215 |
out.append(prefix).append(name).append(" = function(");
|
lubomir@307
|
216 |
lmapper.outputArguments(out);
|
lubomir@307
|
217 |
out.append(") {").append("\n");
|
lubomir@307
|
218 |
|
lubomir@221
|
219 |
final byte[] byteCodes = m.getCode();
|
lubomir@307
|
220 |
if (byteCodes == null) {
|
lubomir@307
|
221 |
out.append(" throw 'no code found for ")
|
lubomir@307
|
222 |
.append(m.getInternalSig()).append("';\n");
|
lubomir@307
|
223 |
out.append("};");
|
lubomir@307
|
224 |
return;
|
lubomir@307
|
225 |
}
|
lubomir@307
|
226 |
|
lubomir@307
|
227 |
final StackMapper smapper = new StackMapper();
|
lubomir@307
|
228 |
|
lubomir@307
|
229 |
final int maxLocals = m.getMaxLocals();
|
lubomir@307
|
230 |
if (maxLocals > 0) {
|
lubomir@307
|
231 |
// TODO: generate only used local variables
|
lubomir@307
|
232 |
for (int j = 0; j <= VarType.LAST; ++j) {
|
lubomir@307
|
233 |
out.append("\n var ").append(Variable.getLocalVariable(j, 0));
|
lubomir@307
|
234 |
for (int i = 1; i < maxLocals; ++i) {
|
lubomir@307
|
235 |
out.append(", ");
|
lubomir@307
|
236 |
out.append(Variable.getLocalVariable(j, i));
|
lubomir@307
|
237 |
}
|
lubomir@307
|
238 |
out.append(';');
|
lubomir@307
|
239 |
}
|
lubomir@307
|
240 |
}
|
lubomir@221
|
241 |
|
lubomir@221
|
242 |
// maxStack includes two stack positions for every pushed long / double
|
lubomir@221
|
243 |
// so this might generate more stack variables than we need
|
lubomir@221
|
244 |
final int maxStack = m.getMaxStack();
|
lubomir@221
|
245 |
if (maxStack > 0) {
|
lubomir@281
|
246 |
// TODO: generate only used stack variables
|
lubomir@307
|
247 |
for (int j = 0; j <= VarType.LAST; ++j) {
|
lubomir@281
|
248 |
out.append("\n var ").append(Variable.getStackVariable(j, 0));
|
lubomir@281
|
249 |
for (int i = 1; i < maxStack; ++i) {
|
lubomir@281
|
250 |
out.append(", ");
|
lubomir@281
|
251 |
out.append(Variable.getStackVariable(j, i));
|
lubomir@281
|
252 |
}
|
lubomir@281
|
253 |
out.append(';');
|
lubomir@221
|
254 |
}
|
lubomir@221
|
255 |
}
|
lubomir@221
|
256 |
|
lubomir@221
|
257 |
int lastStackFrame = -1;
|
lubomir@221
|
258 |
|
jaroslav@10
|
259 |
out.append("\n var gt = 0;\n for(;;) switch(gt) {\n");
|
jaroslav@0
|
260 |
for (int i = 0; i < byteCodes.length; i++) {
|
jaroslav@0
|
261 |
int prev = i;
|
lubomir@221
|
262 |
stackMapIterator.advanceTo(i);
|
lubomir@221
|
263 |
if (lastStackFrame != stackMapIterator.getFrameIndex()) {
|
lubomir@221
|
264 |
lastStackFrame = stackMapIterator.getFrameIndex();
|
lubomir@307
|
265 |
lmapper.syncWithFrameLocals(stackMapIterator.getFrameLocals());
|
lubomir@307
|
266 |
smapper.syncWithFrameStack(stackMapIterator.getFrameStack());
|
lubomir@221
|
267 |
out.append(" case " + i).append(": ");
|
lubomir@221
|
268 |
} else {
|
lubomir@221
|
269 |
out.append(" /* " + i).append(" */ ");
|
lubomir@221
|
270 |
}
|
jtulach@128
|
271 |
final int c = readByte(byteCodes, i);
|
jaroslav@0
|
272 |
switch (c) {
|
jaroslav@151
|
273 |
case opc_aload_0:
|
lubomir@307
|
274 |
emit(out, "@1 = @2;", smapper.pushA(), lmapper.getA(0));
|
lubomir@281
|
275 |
break;
|
jaroslav@151
|
276 |
case opc_iload_0:
|
lubomir@307
|
277 |
emit(out, "@1 = @2;", smapper.pushI(), lmapper.getI(0));
|
lubomir@281
|
278 |
break;
|
jaroslav@151
|
279 |
case opc_lload_0:
|
lubomir@307
|
280 |
emit(out, "@1 = @2;", smapper.pushL(), lmapper.getL(0));
|
lubomir@281
|
281 |
break;
|
jaroslav@151
|
282 |
case opc_fload_0:
|
lubomir@307
|
283 |
emit(out, "@1 = @2;", smapper.pushF(), lmapper.getF(0));
|
lubomir@281
|
284 |
break;
|
jaroslav@151
|
285 |
case opc_dload_0:
|
lubomir@307
|
286 |
emit(out, "@1 = @2;", smapper.pushD(), lmapper.getD(0));
|
jaroslav@0
|
287 |
break;
|
jaroslav@151
|
288 |
case opc_aload_1:
|
lubomir@307
|
289 |
emit(out, "@1 = @2;", smapper.pushA(), lmapper.getA(1));
|
lubomir@281
|
290 |
break;
|
jaroslav@151
|
291 |
case opc_iload_1:
|
lubomir@307
|
292 |
emit(out, "@1 = @2;", smapper.pushI(), lmapper.getI(1));
|
lubomir@281
|
293 |
break;
|
jaroslav@151
|
294 |
case opc_lload_1:
|
lubomir@307
|
295 |
emit(out, "@1 = @2;", smapper.pushL(), lmapper.getL(1));
|
lubomir@281
|
296 |
break;
|
jaroslav@151
|
297 |
case opc_fload_1:
|
lubomir@307
|
298 |
emit(out, "@1 = @2;", smapper.pushF(), lmapper.getF(1));
|
lubomir@281
|
299 |
break;
|
jaroslav@151
|
300 |
case opc_dload_1:
|
lubomir@307
|
301 |
emit(out, "@1 = @2;", smapper.pushD(), lmapper.getD(1));
|
jaroslav@0
|
302 |
break;
|
jaroslav@151
|
303 |
case opc_aload_2:
|
lubomir@307
|
304 |
emit(out, "@1 = @2;", smapper.pushA(), lmapper.getA(2));
|
lubomir@281
|
305 |
break;
|
jaroslav@151
|
306 |
case opc_iload_2:
|
lubomir@307
|
307 |
emit(out, "@1 = @2;", smapper.pushI(), lmapper.getI(2));
|
lubomir@281
|
308 |
break;
|
jaroslav@151
|
309 |
case opc_lload_2:
|
lubomir@307
|
310 |
emit(out, "@1 = @2;", smapper.pushL(), lmapper.getL(2));
|
lubomir@281
|
311 |
break;
|
jaroslav@151
|
312 |
case opc_fload_2:
|
lubomir@307
|
313 |
emit(out, "@1 = @2;", smapper.pushF(), lmapper.getF(2));
|
lubomir@281
|
314 |
break;
|
jaroslav@151
|
315 |
case opc_dload_2:
|
lubomir@307
|
316 |
emit(out, "@1 = @2;", smapper.pushD(), lmapper.getD(2));
|
jaroslav@2
|
317 |
break;
|
jaroslav@151
|
318 |
case opc_aload_3:
|
lubomir@307
|
319 |
emit(out, "@1 = @2;", smapper.pushA(), lmapper.getA(3));
|
lubomir@281
|
320 |
break;
|
jaroslav@151
|
321 |
case opc_iload_3:
|
lubomir@307
|
322 |
emit(out, "@1 = @2;", smapper.pushI(), lmapper.getI(3));
|
lubomir@281
|
323 |
break;
|
jaroslav@151
|
324 |
case opc_lload_3:
|
lubomir@307
|
325 |
emit(out, "@1 = @2;", smapper.pushL(), lmapper.getL(3));
|
lubomir@281
|
326 |
break;
|
jaroslav@151
|
327 |
case opc_fload_3:
|
lubomir@307
|
328 |
emit(out, "@1 = @2;", smapper.pushF(), lmapper.getF(3));
|
lubomir@281
|
329 |
break;
|
jaroslav@151
|
330 |
case opc_dload_3:
|
lubomir@307
|
331 |
emit(out, "@1 = @2;", smapper.pushD(), lmapper.getD(3));
|
jaroslav@3
|
332 |
break;
|
lubomir@281
|
333 |
case opc_iload: {
|
lubomir@281
|
334 |
final int indx = readByte(byteCodes, ++i);
|
lubomir@307
|
335 |
emit(out, "@1 = @2;", smapper.pushI(), lmapper.getI(indx));
|
lubomir@281
|
336 |
break;
|
lubomir@281
|
337 |
}
|
lubomir@281
|
338 |
case opc_lload: {
|
lubomir@281
|
339 |
final int indx = readByte(byteCodes, ++i);
|
lubomir@307
|
340 |
emit(out, "@1 = @2;", smapper.pushL(), lmapper.getL(indx));
|
lubomir@281
|
341 |
break;
|
lubomir@281
|
342 |
}
|
lubomir@281
|
343 |
case opc_fload: {
|
lubomir@281
|
344 |
final int indx = readByte(byteCodes, ++i);
|
lubomir@307
|
345 |
emit(out, "@1 = @2;", smapper.pushF(), lmapper.getF(indx));
|
lubomir@281
|
346 |
break;
|
lubomir@281
|
347 |
}
|
lubomir@281
|
348 |
case opc_dload: {
|
lubomir@281
|
349 |
final int indx = readByte(byteCodes, ++i);
|
lubomir@307
|
350 |
emit(out, "@1 = @2;", smapper.pushD(), lmapper.getD(indx));
|
lubomir@281
|
351 |
break;
|
lubomir@281
|
352 |
}
|
jaroslav@151
|
353 |
case opc_aload: {
|
jtulach@128
|
354 |
final int indx = readByte(byteCodes, ++i);
|
lubomir@307
|
355 |
emit(out, "@1 = @2;", smapper.pushA(), lmapper.getA(indx));
|
jaroslav@3
|
356 |
break;
|
jaroslav@3
|
357 |
}
|
lubomir@281
|
358 |
case opc_istore: {
|
lubomir@281
|
359 |
final int indx = readByte(byteCodes, ++i);
|
lubomir@307
|
360 |
emit(out, "@1 = @2;", lmapper.setI(indx), smapper.popI());
|
lubomir@281
|
361 |
break;
|
lubomir@281
|
362 |
}
|
lubomir@281
|
363 |
case opc_lstore: {
|
lubomir@281
|
364 |
final int indx = readByte(byteCodes, ++i);
|
lubomir@307
|
365 |
emit(out, "@1 = @2;", lmapper.setL(indx), smapper.popL());
|
lubomir@281
|
366 |
break;
|
lubomir@281
|
367 |
}
|
lubomir@281
|
368 |
case opc_fstore: {
|
lubomir@281
|
369 |
final int indx = readByte(byteCodes, ++i);
|
lubomir@307
|
370 |
emit(out, "@1 = @2;", lmapper.setF(indx), smapper.popF());
|
lubomir@281
|
371 |
break;
|
lubomir@281
|
372 |
}
|
lubomir@281
|
373 |
case opc_dstore: {
|
lubomir@281
|
374 |
final int indx = readByte(byteCodes, ++i);
|
lubomir@307
|
375 |
emit(out, "@1 = @2;", lmapper.setD(indx), smapper.popD());
|
lubomir@281
|
376 |
break;
|
lubomir@281
|
377 |
}
|
jaroslav@151
|
378 |
case opc_astore: {
|
jtulach@128
|
379 |
final int indx = readByte(byteCodes, ++i);
|
lubomir@307
|
380 |
emit(out, "@1 = @2;", lmapper.setA(indx), smapper.popA());
|
jaroslav@31
|
381 |
break;
|
jaroslav@31
|
382 |
}
|
jaroslav@151
|
383 |
case opc_astore_0:
|
lubomir@307
|
384 |
emit(out, "@1 = @2;", lmapper.setA(0), smapper.popA());
|
lubomir@281
|
385 |
break;
|
jaroslav@151
|
386 |
case opc_istore_0:
|
lubomir@307
|
387 |
emit(out, "@1 = @2;", lmapper.setI(0), smapper.popI());
|
lubomir@281
|
388 |
break;
|
jaroslav@151
|
389 |
case opc_lstore_0:
|
lubomir@307
|
390 |
emit(out, "@1 = @2;", lmapper.setL(0), smapper.popL());
|
lubomir@281
|
391 |
break;
|
jaroslav@151
|
392 |
case opc_fstore_0:
|
lubomir@307
|
393 |
emit(out, "@1 = @2;", lmapper.setF(0), smapper.popF());
|
lubomir@281
|
394 |
break;
|
jaroslav@151
|
395 |
case opc_dstore_0:
|
lubomir@307
|
396 |
emit(out, "@1 = @2;", lmapper.setD(0), smapper.popD());
|
jaroslav@5
|
397 |
break;
|
jaroslav@151
|
398 |
case opc_astore_1:
|
lubomir@307
|
399 |
emit(out, "@1 = @2;", lmapper.setA(1), smapper.popA());
|
lubomir@281
|
400 |
break;
|
jaroslav@151
|
401 |
case opc_istore_1:
|
lubomir@307
|
402 |
emit(out, "@1 = @2;", lmapper.setI(1), smapper.popI());
|
lubomir@281
|
403 |
break;
|
jaroslav@151
|
404 |
case opc_lstore_1:
|
lubomir@307
|
405 |
emit(out, "@1 = @2;", lmapper.setL(1), smapper.popL());
|
lubomir@281
|
406 |
break;
|
jaroslav@151
|
407 |
case opc_fstore_1:
|
lubomir@307
|
408 |
emit(out, "@1 = @2;", lmapper.setF(1), smapper.popF());
|
lubomir@281
|
409 |
break;
|
jaroslav@151
|
410 |
case opc_dstore_1:
|
lubomir@307
|
411 |
emit(out, "@1 = @2;", lmapper.setD(1), smapper.popD());
|
jaroslav@5
|
412 |
break;
|
jaroslav@151
|
413 |
case opc_astore_2:
|
lubomir@307
|
414 |
emit(out, "@1 = @2;", lmapper.setA(2), smapper.popA());
|
lubomir@281
|
415 |
break;
|
jaroslav@151
|
416 |
case opc_istore_2:
|
lubomir@307
|
417 |
emit(out, "@1 = @2;", lmapper.setI(2), smapper.popI());
|
lubomir@281
|
418 |
break;
|
jaroslav@151
|
419 |
case opc_lstore_2:
|
lubomir@307
|
420 |
emit(out, "@1 = @2;", lmapper.setL(2), smapper.popL());
|
lubomir@281
|
421 |
break;
|
jaroslav@151
|
422 |
case opc_fstore_2:
|
lubomir@307
|
423 |
emit(out, "@1 = @2;", lmapper.setF(2), smapper.popF());
|
lubomir@281
|
424 |
break;
|
jaroslav@151
|
425 |
case opc_dstore_2:
|
lubomir@307
|
426 |
emit(out, "@1 = @2;", lmapper.setD(2), smapper.popD());
|
jaroslav@5
|
427 |
break;
|
jaroslav@151
|
428 |
case opc_astore_3:
|
lubomir@307
|
429 |
emit(out, "@1 = @2;", lmapper.setA(3), smapper.popA());
|
lubomir@281
|
430 |
break;
|
jaroslav@151
|
431 |
case opc_istore_3:
|
lubomir@307
|
432 |
emit(out, "@1 = @2;", lmapper.setI(3), smapper.popI());
|
lubomir@281
|
433 |
break;
|
jaroslav@151
|
434 |
case opc_lstore_3:
|
lubomir@307
|
435 |
emit(out, "@1 = @2;", lmapper.setL(3), smapper.popL());
|
lubomir@281
|
436 |
break;
|
jaroslav@151
|
437 |
case opc_fstore_3:
|
lubomir@307
|
438 |
emit(out, "@1 = @2;", lmapper.setF(3), smapper.popF());
|
lubomir@281
|
439 |
break;
|
jaroslav@151
|
440 |
case opc_dstore_3:
|
lubomir@307
|
441 |
emit(out, "@1 = @2;", lmapper.setD(3), smapper.popD());
|
jaroslav@5
|
442 |
break;
|
jaroslav@151
|
443 |
case opc_iadd:
|
lubomir@307
|
444 |
emit(out, "@1 += @2;", smapper.getI(1), smapper.popI());
|
lubomir@281
|
445 |
break;
|
jaroslav@151
|
446 |
case opc_ladd:
|
lubomir@307
|
447 |
emit(out, "@1 += @2;", smapper.getL(1), smapper.popL());
|
lubomir@281
|
448 |
break;
|
jaroslav@151
|
449 |
case opc_fadd:
|
lubomir@307
|
450 |
emit(out, "@1 += @2;", smapper.getF(1), smapper.popF());
|
lubomir@281
|
451 |
break;
|
jaroslav@151
|
452 |
case opc_dadd:
|
lubomir@307
|
453 |
emit(out, "@1 += @2;", smapper.getD(1), smapper.popD());
|
jaroslav@0
|
454 |
break;
|
jaroslav@151
|
455 |
case opc_isub:
|
lubomir@307
|
456 |
emit(out, "@1 -= @2;", smapper.getI(1), smapper.popI());
|
lubomir@281
|
457 |
break;
|
jaroslav@151
|
458 |
case opc_lsub:
|
lubomir@307
|
459 |
emit(out, "@1 -= @2;", smapper.getL(1), smapper.popL());
|
lubomir@281
|
460 |
break;
|
jaroslav@151
|
461 |
case opc_fsub:
|
lubomir@307
|
462 |
emit(out, "@1 -= @2;", smapper.getF(1), smapper.popF());
|
lubomir@281
|
463 |
break;
|
jaroslav@151
|
464 |
case opc_dsub:
|
lubomir@307
|
465 |
emit(out, "@1 -= @2;", smapper.getD(1), smapper.popD());
|
jaroslav@2
|
466 |
break;
|
jaroslav@151
|
467 |
case opc_imul:
|
lubomir@307
|
468 |
emit(out, "@1 *= @2;", smapper.getI(1), smapper.popI());
|
lubomir@281
|
469 |
break;
|
jaroslav@151
|
470 |
case opc_lmul:
|
lubomir@307
|
471 |
emit(out, "@1 *= @2;", smapper.getL(1), smapper.popL());
|
lubomir@281
|
472 |
break;
|
jaroslav@151
|
473 |
case opc_fmul:
|
lubomir@307
|
474 |
emit(out, "@1 *= @2;", smapper.getF(1), smapper.popF());
|
lubomir@281
|
475 |
break;
|
jaroslav@151
|
476 |
case opc_dmul:
|
lubomir@307
|
477 |
emit(out, "@1 *= @2;", smapper.getD(1), smapper.popD());
|
jaroslav@1
|
478 |
break;
|
jaroslav@151
|
479 |
case opc_idiv:
|
lubomir@283
|
480 |
emit(out, "@1 = Math.floor(@1 / @2);",
|
lubomir@307
|
481 |
smapper.getI(1), smapper.popI());
|
lubomir@281
|
482 |
break;
|
jaroslav@151
|
483 |
case opc_ldiv:
|
lubomir@283
|
484 |
emit(out, "@1 = Math.floor(@1 / @2);",
|
lubomir@307
|
485 |
smapper.getL(1), smapper.popL());
|
jaroslav@3
|
486 |
break;
|
jaroslav@151
|
487 |
case opc_fdiv:
|
lubomir@307
|
488 |
emit(out, "@1 /= @2;", smapper.getF(1), smapper.popF());
|
lubomir@281
|
489 |
break;
|
jaroslav@151
|
490 |
case opc_ddiv:
|
lubomir@307
|
491 |
emit(out, "@1 /= @2;", smapper.getD(1), smapper.popD());
|
jaroslav@3
|
492 |
break;
|
jaroslav@178
|
493 |
case opc_irem:
|
lubomir@307
|
494 |
emit(out, "@1 %= @2;", smapper.getI(1), smapper.popI());
|
lubomir@281
|
495 |
break;
|
jaroslav@178
|
496 |
case opc_lrem:
|
lubomir@307
|
497 |
emit(out, "@1 %= @2;", smapper.getL(1), smapper.popL());
|
lubomir@281
|
498 |
break;
|
jaroslav@178
|
499 |
case opc_frem:
|
lubomir@307
|
500 |
emit(out, "@1 %= @2;", smapper.getF(1), smapper.popF());
|
lubomir@281
|
501 |
break;
|
jaroslav@178
|
502 |
case opc_drem:
|
lubomir@307
|
503 |
emit(out, "@1 %= @2;", smapper.getD(1), smapper.popD());
|
jaroslav@178
|
504 |
break;
|
jaroslav@151
|
505 |
case opc_iand:
|
lubomir@307
|
506 |
emit(out, "@1 &= @2;", smapper.getI(1), smapper.popI());
|
lubomir@281
|
507 |
break;
|
jaroslav@151
|
508 |
case opc_land:
|
lubomir@307
|
509 |
emit(out, "@1 &= @2;", smapper.getL(1), smapper.popL());
|
jaroslav@7
|
510 |
break;
|
jaroslav@151
|
511 |
case opc_ior:
|
lubomir@307
|
512 |
emit(out, "@1 |= @2;", smapper.getI(1), smapper.popI());
|
lubomir@281
|
513 |
break;
|
jaroslav@151
|
514 |
case opc_lor:
|
lubomir@307
|
515 |
emit(out, "@1 |= @2;", smapper.getL(1), smapper.popL());
|
jaroslav@7
|
516 |
break;
|
jaroslav@151
|
517 |
case opc_ixor:
|
lubomir@307
|
518 |
emit(out, "@1 ^= @2;", smapper.getI(1), smapper.popI());
|
lubomir@281
|
519 |
break;
|
jaroslav@151
|
520 |
case opc_lxor:
|
lubomir@307
|
521 |
emit(out, "@1 ^= @2;", smapper.getL(1), smapper.popL());
|
jaroslav@6
|
522 |
break;
|
jaroslav@151
|
523 |
case opc_ineg:
|
lubomir@307
|
524 |
emit(out, "@1 = -@1;", smapper.getI(0));
|
lubomir@281
|
525 |
break;
|
jaroslav@151
|
526 |
case opc_lneg:
|
lubomir@307
|
527 |
emit(out, "@1 = -@1;", smapper.getL(0));
|
lubomir@281
|
528 |
break;
|
jaroslav@151
|
529 |
case opc_fneg:
|
lubomir@307
|
530 |
emit(out, "@1 = -@1;", smapper.getF(0));
|
lubomir@281
|
531 |
break;
|
jaroslav@151
|
532 |
case opc_dneg:
|
lubomir@307
|
533 |
emit(out, "@1 = -@1;", smapper.getD(0));
|
jaroslav@93
|
534 |
break;
|
jaroslav@151
|
535 |
case opc_ishl:
|
lubomir@307
|
536 |
emit(out, "@1 <<= @2;", smapper.getI(1), smapper.popI());
|
lubomir@281
|
537 |
break;
|
jaroslav@151
|
538 |
case opc_lshl:
|
lubomir@307
|
539 |
emit(out, "@1 <<= @2;", smapper.getL(1), smapper.popI());
|
jaroslav@93
|
540 |
break;
|
jaroslav@151
|
541 |
case opc_ishr:
|
lubomir@307
|
542 |
emit(out, "@1 >>= @2;", smapper.getI(1), smapper.popI());
|
lubomir@281
|
543 |
break;
|
jaroslav@151
|
544 |
case opc_lshr:
|
lubomir@307
|
545 |
emit(out, "@1 >>= @2;", smapper.getL(1), smapper.popI());
|
jaroslav@93
|
546 |
break;
|
jaroslav@151
|
547 |
case opc_iushr:
|
lubomir@307
|
548 |
emit(out, "@1 >>>= @2;", smapper.getI(1), smapper.popI());
|
lubomir@281
|
549 |
break;
|
jaroslav@151
|
550 |
case opc_lushr:
|
lubomir@307
|
551 |
emit(out, "@1 >>>= @2;", smapper.getL(1), smapper.popI());
|
jaroslav@93
|
552 |
break;
|
jaroslav@151
|
553 |
case opc_iinc: {
|
jtulach@128
|
554 |
final int varIndx = readByte(byteCodes, ++i);
|
jaroslav@104
|
555 |
final int incrBy = byteCodes[++i];
|
jaroslav@5
|
556 |
if (incrBy == 1) {
|
lubomir@307
|
557 |
emit(out, "@1++;", lmapper.getI(varIndx));
|
jaroslav@5
|
558 |
} else {
|
lubomir@307
|
559 |
emit(out, "@1 += @2;",
|
lubomir@307
|
560 |
lmapper.getI(varIndx),
|
lubomir@283
|
561 |
Integer.toString(incrBy));
|
jaroslav@5
|
562 |
}
|
jaroslav@5
|
563 |
break;
|
jaroslav@5
|
564 |
}
|
jaroslav@151
|
565 |
case opc_return:
|
lubomir@283
|
566 |
emit(out, "return;");
|
jaroslav@10
|
567 |
break;
|
jaroslav@151
|
568 |
case opc_ireturn:
|
lubomir@307
|
569 |
emit(out, "return @1;", smapper.popI());
|
lubomir@281
|
570 |
break;
|
jaroslav@151
|
571 |
case opc_lreturn:
|
lubomir@307
|
572 |
emit(out, "return @1;", smapper.popL());
|
lubomir@281
|
573 |
break;
|
jaroslav@151
|
574 |
case opc_freturn:
|
lubomir@307
|
575 |
emit(out, "return @1;", smapper.popF());
|
lubomir@281
|
576 |
break;
|
jaroslav@151
|
577 |
case opc_dreturn:
|
lubomir@307
|
578 |
emit(out, "return @1;", smapper.popD());
|
lubomir@281
|
579 |
break;
|
jaroslav@151
|
580 |
case opc_areturn:
|
lubomir@307
|
581 |
emit(out, "return @1;", smapper.popA());
|
jaroslav@1
|
582 |
break;
|
lubomir@283
|
583 |
case opc_i2l:
|
lubomir@307
|
584 |
emit(out, "@2 = @1;", smapper.popI(), smapper.pushL());
|
lubomir@281
|
585 |
break;
|
lubomir@283
|
586 |
case opc_i2f:
|
lubomir@307
|
587 |
emit(out, "@2 = @1;", smapper.popI(), smapper.pushF());
|
lubomir@281
|
588 |
break;
|
lubomir@283
|
589 |
case opc_i2d:
|
lubomir@307
|
590 |
emit(out, "@2 = @1;", smapper.popI(), smapper.pushD());
|
lubomir@281
|
591 |
break;
|
lubomir@283
|
592 |
case opc_l2i:
|
lubomir@307
|
593 |
emit(out, "@2 = @1;", smapper.popL(), smapper.pushI());
|
lubomir@281
|
594 |
break;
|
jaroslav@3
|
595 |
// max int check?
|
lubomir@283
|
596 |
case opc_l2f:
|
lubomir@307
|
597 |
emit(out, "@2 = @1;", smapper.popL(), smapper.pushF());
|
jaroslav@3
|
598 |
break;
|
lubomir@283
|
599 |
case opc_l2d:
|
lubomir@307
|
600 |
emit(out, "@2 = @1;", smapper.popL(), smapper.pushD());
|
jaroslav@3
|
601 |
break;
|
lubomir@283
|
602 |
case opc_f2d:
|
lubomir@307
|
603 |
emit(out, "@2 = @1;", smapper.popF(), smapper.pushD());
|
lubomir@281
|
604 |
break;
|
lubomir@283
|
605 |
case opc_d2f:
|
lubomir@307
|
606 |
emit(out, "@2 = @1;", smapper.popD(), smapper.pushF());
|
lubomir@281
|
607 |
break;
|
lubomir@283
|
608 |
case opc_f2i:
|
lubomir@283
|
609 |
emit(out, "@2 = Math.floor(@1);",
|
lubomir@307
|
610 |
smapper.popF(), smapper.pushI());
|
lubomir@281
|
611 |
break;
|
lubomir@283
|
612 |
case opc_f2l:
|
lubomir@283
|
613 |
emit(out, "@2 = Math.floor(@1);",
|
lubomir@307
|
614 |
smapper.popF(), smapper.pushL());
|
lubomir@281
|
615 |
break;
|
lubomir@283
|
616 |
case opc_d2i:
|
lubomir@283
|
617 |
emit(out, "@2 = Math.floor(@1);",
|
lubomir@307
|
618 |
smapper.popD(), smapper.pushI());
|
lubomir@281
|
619 |
break;
|
lubomir@283
|
620 |
case opc_d2l:
|
lubomir@283
|
621 |
emit(out, "@2 = Math.floor(@1);",
|
lubomir@307
|
622 |
smapper.popD(), smapper.pushL());
|
lubomir@281
|
623 |
break;
|
jaroslav@151
|
624 |
case opc_i2b:
|
jaroslav@151
|
625 |
case opc_i2c:
|
jaroslav@151
|
626 |
case opc_i2s:
|
jaroslav@2
|
627 |
out.append("/* number conversion */");
|
jaroslav@2
|
628 |
break;
|
jaroslav@151
|
629 |
case opc_aconst_null:
|
lubomir@307
|
630 |
emit(out, "@1 = null;", smapper.pushA());
|
jaroslav@46
|
631 |
break;
|
jaroslav@151
|
632 |
case opc_iconst_m1:
|
lubomir@307
|
633 |
emit(out, "@1 = -1;", smapper.pushI());
|
jaroslav@48
|
634 |
break;
|
jaroslav@151
|
635 |
case opc_iconst_0:
|
lubomir@307
|
636 |
emit(out, "@1 = 0;", smapper.pushI());
|
lubomir@281
|
637 |
break;
|
jaroslav@151
|
638 |
case opc_dconst_0:
|
lubomir@307
|
639 |
emit(out, "@1 = 0;", smapper.pushD());
|
lubomir@281
|
640 |
break;
|
jaroslav@151
|
641 |
case opc_lconst_0:
|
lubomir@307
|
642 |
emit(out, "@1 = 0;", smapper.pushL());
|
lubomir@281
|
643 |
break;
|
jaroslav@151
|
644 |
case opc_fconst_0:
|
lubomir@307
|
645 |
emit(out, "@1 = 0;", smapper.pushF());
|
jaroslav@4
|
646 |
break;
|
jaroslav@151
|
647 |
case opc_iconst_1:
|
lubomir@307
|
648 |
emit(out, "@1 = 1;", smapper.pushI());
|
lubomir@281
|
649 |
break;
|
jaroslav@151
|
650 |
case opc_lconst_1:
|
lubomir@307
|
651 |
emit(out, "@1 = 1;", smapper.pushL());
|
lubomir@281
|
652 |
break;
|
jaroslav@151
|
653 |
case opc_fconst_1:
|
lubomir@307
|
654 |
emit(out, "@1 = 1;", smapper.pushF());
|
lubomir@281
|
655 |
break;
|
jaroslav@151
|
656 |
case opc_dconst_1:
|
lubomir@307
|
657 |
emit(out, "@1 = 1;", smapper.pushD());
|
jaroslav@4
|
658 |
break;
|
jaroslav@151
|
659 |
case opc_iconst_2:
|
lubomir@307
|
660 |
emit(out, "@1 = 2;", smapper.pushI());
|
lubomir@281
|
661 |
break;
|
jaroslav@151
|
662 |
case opc_fconst_2:
|
lubomir@307
|
663 |
emit(out, "@1 = 2;", smapper.pushF());
|
jaroslav@4
|
664 |
break;
|
jaroslav@151
|
665 |
case opc_iconst_3:
|
lubomir@307
|
666 |
emit(out, "@1 = 3;", smapper.pushI());
|
jaroslav@4
|
667 |
break;
|
jaroslav@151
|
668 |
case opc_iconst_4:
|
lubomir@307
|
669 |
emit(out, "@1 = 4;", smapper.pushI());
|
jaroslav@4
|
670 |
break;
|
jaroslav@151
|
671 |
case opc_iconst_5:
|
lubomir@307
|
672 |
emit(out, "@1 = 5;", smapper.pushI());
|
jaroslav@4
|
673 |
break;
|
jaroslav@151
|
674 |
case opc_ldc: {
|
jtulach@128
|
675 |
int indx = readByte(byteCodes, ++i);
|
jaroslav@151
|
676 |
String v = encodeConstant(indx);
|
lubomir@307
|
677 |
int type = VarType.fromConstantType(jc.getTag(indx));
|
lubomir@307
|
678 |
emit(out, "@1 = @2;", smapper.pushT(type), v);
|
jaroslav@20
|
679 |
break;
|
jaroslav@20
|
680 |
}
|
jaroslav@151
|
681 |
case opc_ldc_w:
|
jaroslav@151
|
682 |
case opc_ldc2_w: {
|
jaroslav@8
|
683 |
int indx = readIntArg(byteCodes, i);
|
jaroslav@8
|
684 |
i += 2;
|
jaroslav@151
|
685 |
String v = encodeConstant(indx);
|
lubomir@307
|
686 |
int type = VarType.fromConstantType(jc.getTag(indx));
|
lubomir@307
|
687 |
emit(out, "@1 = @2;", smapper.pushT(type), v);
|
jaroslav@8
|
688 |
break;
|
jaroslav@8
|
689 |
}
|
jaroslav@151
|
690 |
case opc_lcmp:
|
lubomir@283
|
691 |
emit(out, "@3 = (@2 == @1) ? 0 : ((@2 < @1) ? -1 : 1);",
|
lubomir@307
|
692 |
smapper.popL(), smapper.popL(), smapper.pushI());
|
lubomir@281
|
693 |
break;
|
jaroslav@151
|
694 |
case opc_fcmpl:
|
jaroslav@151
|
695 |
case opc_fcmpg:
|
lubomir@283
|
696 |
emit(out, "@3 = (@2 == @1) ? 0 : ((@2 < @1) ? -1 : 1);",
|
lubomir@307
|
697 |
smapper.popF(), smapper.popF(), smapper.pushI());
|
lubomir@281
|
698 |
break;
|
jaroslav@151
|
699 |
case opc_dcmpl:
|
lubomir@281
|
700 |
case opc_dcmpg:
|
lubomir@283
|
701 |
emit(out, "@3 = (@2 == @1) ? 0 : ((@2 < @1) ? -1 : 1);",
|
lubomir@307
|
702 |
smapper.popD(), smapper.popD(), smapper.pushI());
|
jaroslav@20
|
703 |
break;
|
jaroslav@151
|
704 |
case opc_if_acmpeq:
|
lubomir@307
|
705 |
i = generateIf(byteCodes, i, smapper.popA(), smapper.popA(),
|
lubomir@281
|
706 |
"===");
|
jaroslav@104
|
707 |
break;
|
jaroslav@151
|
708 |
case opc_if_acmpne:
|
lubomir@307
|
709 |
i = generateIf(byteCodes, i, smapper.popA(), smapper.popA(),
|
lubomir@281
|
710 |
"!=");
|
jaroslav@104
|
711 |
break;
|
lubomir@283
|
712 |
case opc_if_icmpeq:
|
lubomir@307
|
713 |
i = generateIf(byteCodes, i, smapper.popI(), smapper.popI(),
|
lubomir@281
|
714 |
"==");
|
jaroslav@4
|
715 |
break;
|
jaroslav@151
|
716 |
case opc_ifeq: {
|
jaroslav@7
|
717 |
int indx = i + readIntArg(byteCodes, i);
|
lubomir@283
|
718 |
emit(out, "if (@1 == 0) { gt = @2; continue; }",
|
lubomir@307
|
719 |
smapper.popI(), Integer.toString(indx));
|
jaroslav@7
|
720 |
i += 2;
|
jaroslav@7
|
721 |
break;
|
jaroslav@7
|
722 |
}
|
jaroslav@151
|
723 |
case opc_ifne: {
|
jaroslav@20
|
724 |
int indx = i + readIntArg(byteCodes, i);
|
lubomir@283
|
725 |
emit(out, "if (@1 != 0) { gt = @2; continue; }",
|
lubomir@307
|
726 |
smapper.popI(), Integer.toString(indx));
|
jaroslav@20
|
727 |
i += 2;
|
jaroslav@20
|
728 |
break;
|
jaroslav@20
|
729 |
}
|
jaroslav@151
|
730 |
case opc_iflt: {
|
jaroslav@20
|
731 |
int indx = i + readIntArg(byteCodes, i);
|
lubomir@283
|
732 |
emit(out, "if (@1 < 0) { gt = @2; continue; }",
|
lubomir@307
|
733 |
smapper.popI(), Integer.toString(indx));
|
jaroslav@20
|
734 |
i += 2;
|
jaroslav@20
|
735 |
break;
|
jaroslav@20
|
736 |
}
|
jaroslav@151
|
737 |
case opc_ifle: {
|
jaroslav@20
|
738 |
int indx = i + readIntArg(byteCodes, i);
|
lubomir@283
|
739 |
emit(out, "if (@1 <= 0) { gt = @2; continue; }",
|
lubomir@307
|
740 |
smapper.popI(), Integer.toString(indx));
|
jaroslav@20
|
741 |
i += 2;
|
jaroslav@20
|
742 |
break;
|
jaroslav@20
|
743 |
}
|
jaroslav@151
|
744 |
case opc_ifgt: {
|
jaroslav@20
|
745 |
int indx = i + readIntArg(byteCodes, i);
|
lubomir@283
|
746 |
emit(out, "if (@1 > 0) { gt = @2; continue; }",
|
lubomir@307
|
747 |
smapper.popI(), Integer.toString(indx));
|
jaroslav@20
|
748 |
i += 2;
|
jaroslav@20
|
749 |
break;
|
jaroslav@20
|
750 |
}
|
jaroslav@151
|
751 |
case opc_ifge: {
|
jaroslav@20
|
752 |
int indx = i + readIntArg(byteCodes, i);
|
lubomir@283
|
753 |
emit(out, "if (@1 >= 0) { gt = @2; continue; }",
|
lubomir@307
|
754 |
smapper.popI(), Integer.toString(indx));
|
jaroslav@20
|
755 |
i += 2;
|
jaroslav@20
|
756 |
break;
|
jaroslav@20
|
757 |
}
|
jaroslav@151
|
758 |
case opc_ifnonnull: {
|
jaroslav@16
|
759 |
int indx = i + readIntArg(byteCodes, i);
|
lubomir@283
|
760 |
emit(out, "if (@1 !== null) { gt = @2; continue; }",
|
lubomir@307
|
761 |
smapper.popA(), Integer.toString(indx));
|
jaroslav@16
|
762 |
i += 2;
|
jaroslav@16
|
763 |
break;
|
jaroslav@16
|
764 |
}
|
jaroslav@151
|
765 |
case opc_ifnull: {
|
jaroslav@16
|
766 |
int indx = i + readIntArg(byteCodes, i);
|
lubomir@283
|
767 |
emit(out, "if (@1 === null) { gt = @2; continue; }",
|
lubomir@307
|
768 |
smapper.popA(), Integer.toString(indx));
|
jaroslav@16
|
769 |
i += 2;
|
jaroslav@16
|
770 |
break;
|
jaroslav@16
|
771 |
}
|
jaroslav@151
|
772 |
case opc_if_icmpne:
|
lubomir@307
|
773 |
i = generateIf(byteCodes, i, smapper.popI(), smapper.popI(),
|
lubomir@281
|
774 |
"!=");
|
jaroslav@4
|
775 |
break;
|
jaroslav@151
|
776 |
case opc_if_icmplt:
|
lubomir@307
|
777 |
i = generateIf(byteCodes, i, smapper.popI(), smapper.popI(),
|
lubomir@281
|
778 |
"<");
|
jaroslav@4
|
779 |
break;
|
jaroslav@151
|
780 |
case opc_if_icmple:
|
lubomir@307
|
781 |
i = generateIf(byteCodes, i, smapper.popI(), smapper.popI(),
|
lubomir@281
|
782 |
"<=");
|
jaroslav@4
|
783 |
break;
|
jaroslav@151
|
784 |
case opc_if_icmpgt:
|
lubomir@307
|
785 |
i = generateIf(byteCodes, i, smapper.popI(), smapper.popI(),
|
lubomir@281
|
786 |
">");
|
jaroslav@4
|
787 |
break;
|
jaroslav@151
|
788 |
case opc_if_icmpge:
|
lubomir@307
|
789 |
i = generateIf(byteCodes, i, smapper.popI(), smapper.popI(),
|
lubomir@281
|
790 |
">=");
|
jaroslav@4
|
791 |
break;
|
jaroslav@151
|
792 |
case opc_goto: {
|
jaroslav@5
|
793 |
int indx = i + readIntArg(byteCodes, i);
|
lubomir@283
|
794 |
emit(out, "gt = @1; continue;", Integer.toString(indx));
|
jaroslav@5
|
795 |
i += 2;
|
jaroslav@5
|
796 |
break;
|
jaroslav@5
|
797 |
}
|
jaroslav@151
|
798 |
case opc_lookupswitch: {
|
jtulach@128
|
799 |
int table = i / 4 * 4 + 4;
|
jaroslav@115
|
800 |
int dflt = i + readInt4(byteCodes, table);
|
jaroslav@115
|
801 |
table += 4;
|
jaroslav@115
|
802 |
int n = readInt4(byteCodes, table);
|
jaroslav@115
|
803 |
table += 4;
|
lubomir@307
|
804 |
out.append("switch (").append(smapper.popI()).append(") {\n");
|
jaroslav@115
|
805 |
while (n-- > 0) {
|
jaroslav@115
|
806 |
int cnstnt = readInt4(byteCodes, table);
|
jaroslav@115
|
807 |
table += 4;
|
jaroslav@115
|
808 |
int offset = i + readInt4(byteCodes, table);
|
jaroslav@115
|
809 |
table += 4;
|
jaroslav@115
|
810 |
out.append(" case " + cnstnt).append(": gt = " + offset).append("; continue;\n");
|
jaroslav@115
|
811 |
}
|
jaroslav@115
|
812 |
out.append(" default: gt = " + dflt).append("; continue;\n}");
|
jaroslav@115
|
813 |
i = table - 1;
|
jaroslav@115
|
814 |
break;
|
jaroslav@115
|
815 |
}
|
jaroslav@151
|
816 |
case opc_tableswitch: {
|
jtulach@128
|
817 |
int table = i / 4 * 4 + 4;
|
jaroslav@115
|
818 |
int dflt = i + readInt4(byteCodes, table);
|
jaroslav@115
|
819 |
table += 4;
|
jaroslav@115
|
820 |
int low = readInt4(byteCodes, table);
|
jaroslav@115
|
821 |
table += 4;
|
jaroslav@115
|
822 |
int high = readInt4(byteCodes, table);
|
jaroslav@115
|
823 |
table += 4;
|
lubomir@307
|
824 |
out.append("switch (").append(smapper.popI()).append(") {\n");
|
jaroslav@115
|
825 |
while (low <= high) {
|
jaroslav@115
|
826 |
int offset = i + readInt4(byteCodes, table);
|
jaroslav@115
|
827 |
table += 4;
|
jaroslav@115
|
828 |
out.append(" case " + low).append(": gt = " + offset).append("; continue;\n");
|
jaroslav@115
|
829 |
low++;
|
jaroslav@115
|
830 |
}
|
jaroslav@115
|
831 |
out.append(" default: gt = " + dflt).append("; continue;\n}");
|
jaroslav@115
|
832 |
i = table - 1;
|
jaroslav@115
|
833 |
break;
|
jaroslav@115
|
834 |
}
|
jaroslav@151
|
835 |
case opc_invokeinterface: {
|
lubomir@307
|
836 |
i = invokeVirtualMethod(byteCodes, i, smapper) + 2;
|
jaroslav@46
|
837 |
break;
|
jaroslav@46
|
838 |
}
|
jaroslav@151
|
839 |
case opc_invokevirtual:
|
lubomir@307
|
840 |
i = invokeVirtualMethod(byteCodes, i, smapper);
|
jaroslav@12
|
841 |
break;
|
jaroslav@151
|
842 |
case opc_invokespecial:
|
lubomir@307
|
843 |
i = invokeStaticMethod(byteCodes, i, smapper, false);
|
jaroslav@4
|
844 |
break;
|
jaroslav@151
|
845 |
case opc_invokestatic:
|
lubomir@307
|
846 |
i = invokeStaticMethod(byteCodes, i, smapper, true);
|
jaroslav@10
|
847 |
break;
|
jaroslav@151
|
848 |
case opc_new: {
|
jaroslav@8
|
849 |
int indx = readIntArg(byteCodes, i);
|
jaroslav@151
|
850 |
String ci = jc.getClassName(indx);
|
lubomir@283
|
851 |
emit(out, "@1 = new @2;",
|
lubomir@307
|
852 |
smapper.pushA(), ci.replace('/', '_'));
|
jaroslav@151
|
853 |
addReference(ci);
|
jaroslav@8
|
854 |
i += 2;
|
jaroslav@8
|
855 |
break;
|
jaroslav@8
|
856 |
}
|
lubomir@283
|
857 |
case opc_newarray:
|
lubomir@221
|
858 |
++i; // skip type of array
|
lubomir@283
|
859 |
emit(out, "@2 = new Array(@1).fillNulls();",
|
lubomir@307
|
860 |
smapper.popI(), smapper.pushA());
|
jaroslav@21
|
861 |
break;
|
lubomir@283
|
862 |
case opc_anewarray:
|
jaroslav@21
|
863 |
i += 2; // skip type of array
|
lubomir@283
|
864 |
emit(out, "@2 = new Array(@1).fillNulls();",
|
lubomir@307
|
865 |
smapper.popI(), smapper.pushA());
|
jaroslav@21
|
866 |
break;
|
jaroslav@151
|
867 |
case opc_multianewarray: {
|
jtulach@128
|
868 |
i += 2;
|
jtulach@128
|
869 |
int dim = readByte(byteCodes, ++i);
|
lubomir@307
|
870 |
out.append("{ var a0 = new Array(").append(smapper.popI())
|
lubomir@221
|
871 |
.append(").fillNulls();");
|
jtulach@128
|
872 |
for (int d = 1; d < dim; d++) {
|
lubomir@221
|
873 |
out.append("\n var l" + d).append(" = ")
|
lubomir@307
|
874 |
.append(smapper.popI()).append(';');
|
jtulach@128
|
875 |
out.append("\n for (var i" + d).append (" = 0; i" + d).
|
jtulach@128
|
876 |
append(" < a" + (d - 1)).
|
jtulach@128
|
877 |
append(".length; i" + d).append("++) {");
|
jtulach@128
|
878 |
out.append("\n var a" + d).
|
jaroslav@172
|
879 |
append (" = new Array(l" + d).append(").fillNulls();");
|
jtulach@128
|
880 |
out.append("\n a" + (d - 1)).append("[i" + d).append("] = a" + d).
|
jtulach@128
|
881 |
append(";");
|
jtulach@128
|
882 |
}
|
jtulach@128
|
883 |
for (int d = 1; d < dim; d++) {
|
jtulach@128
|
884 |
out.append("\n }");
|
jtulach@128
|
885 |
}
|
lubomir@307
|
886 |
out.append("\n").append(smapper.pushA()).append(" = a0; }");
|
jtulach@128
|
887 |
break;
|
jtulach@128
|
888 |
}
|
lubomir@283
|
889 |
case opc_arraylength:
|
lubomir@307
|
890 |
emit(out, "@2 = @1.length;", smapper.popA(), smapper.pushI());
|
jaroslav@21
|
891 |
break;
|
lubomir@283
|
892 |
case opc_lastore:
|
lubomir@283
|
893 |
emit(out, "@3[@2] = @1;",
|
lubomir@307
|
894 |
smapper.popL(), smapper.popI(), smapper.popA());
|
lubomir@281
|
895 |
break;
|
lubomir@283
|
896 |
case opc_fastore:
|
lubomir@283
|
897 |
emit(out, "@3[@2] = @1;",
|
lubomir@307
|
898 |
smapper.popF(), smapper.popI(), smapper.popA());
|
lubomir@281
|
899 |
break;
|
lubomir@283
|
900 |
case opc_dastore:
|
lubomir@283
|
901 |
emit(out, "@3[@2] = @1;",
|
lubomir@307
|
902 |
smapper.popD(), smapper.popI(), smapper.popA());
|
lubomir@281
|
903 |
break;
|
lubomir@283
|
904 |
case opc_aastore:
|
lubomir@283
|
905 |
emit(out, "@3[@2] = @1;",
|
lubomir@307
|
906 |
smapper.popA(), smapper.popI(), smapper.popA());
|
lubomir@281
|
907 |
break;
|
jaroslav@151
|
908 |
case opc_iastore:
|
jaroslav@151
|
909 |
case opc_bastore:
|
jaroslav@151
|
910 |
case opc_castore:
|
lubomir@283
|
911 |
case opc_sastore:
|
lubomir@283
|
912 |
emit(out, "@3[@2] = @1;",
|
lubomir@307
|
913 |
smapper.popI(), smapper.popI(), smapper.popA());
|
jaroslav@240
|
914 |
break;
|
lubomir@283
|
915 |
case opc_laload:
|
lubomir@283
|
916 |
emit(out, "@3 = @2[@1];",
|
lubomir@307
|
917 |
smapper.popI(), smapper.popA(), smapper.pushL());
|
lubomir@281
|
918 |
break;
|
lubomir@283
|
919 |
case opc_faload:
|
lubomir@283
|
920 |
emit(out, "@3 = @2[@1];",
|
lubomir@307
|
921 |
smapper.popI(), smapper.popA(), smapper.pushF());
|
lubomir@281
|
922 |
break;
|
lubomir@283
|
923 |
case opc_daload:
|
lubomir@283
|
924 |
emit(out, "@3 = @2[@1];",
|
lubomir@307
|
925 |
smapper.popI(), smapper.popA(), smapper.pushD());
|
lubomir@281
|
926 |
break;
|
lubomir@283
|
927 |
case opc_aaload:
|
lubomir@283
|
928 |
emit(out, "@3 = @2[@1];",
|
lubomir@307
|
929 |
smapper.popI(), smapper.popA(), smapper.pushA());
|
jaroslav@21
|
930 |
break;
|
jaroslav@151
|
931 |
case opc_iaload:
|
jaroslav@151
|
932 |
case opc_baload:
|
jaroslav@151
|
933 |
case opc_caload:
|
lubomir@283
|
934 |
case opc_saload:
|
lubomir@283
|
935 |
emit(out, "@3 = @2[@1];",
|
lubomir@307
|
936 |
smapper.popI(), smapper.popA(), smapper.pushI());
|
jaroslav@21
|
937 |
break;
|
lubomir@221
|
938 |
case opc_pop:
|
jaroslav@151
|
939 |
case opc_pop2:
|
lubomir@307
|
940 |
smapper.pop(1);
|
lubomir@221
|
941 |
out.append("/* pop */");
|
jaroslav@93
|
942 |
break;
|
lubomir@281
|
943 |
case opc_dup: {
|
lubomir@307
|
944 |
final Variable v = smapper.get(0);
|
lubomir@307
|
945 |
emit(out, "@1 = @2;", smapper.pushT(v.getType()), v);
|
jaroslav@8
|
946 |
break;
|
lubomir@281
|
947 |
}
|
lubomir@281
|
948 |
case opc_dup2: {
|
lubomir@307
|
949 |
if (smapper.get(0).isCategory2()) {
|
lubomir@307
|
950 |
final Variable v = smapper.get(0);
|
lubomir@307
|
951 |
emit(out, "@1 = @2;", smapper.pushT(v.getType()), v);
|
lubomir@281
|
952 |
} else {
|
lubomir@307
|
953 |
final Variable v1 = smapper.get(0);
|
lubomir@307
|
954 |
final Variable v2 = smapper.get(1);
|
lubomir@283
|
955 |
emit(out, "{ @1 = @2; @3 = @4; }",
|
lubomir@307
|
956 |
smapper.pushT(v2.getType()), v2,
|
lubomir@307
|
957 |
smapper.pushT(v1.getType()), v1);
|
lubomir@281
|
958 |
}
|
jaroslav@170
|
959 |
break;
|
lubomir@281
|
960 |
}
|
lubomir@281
|
961 |
case opc_dup_x1: {
|
lubomir@307
|
962 |
final Variable vi1 = smapper.pop();
|
lubomir@307
|
963 |
final Variable vi2 = smapper.pop();
|
lubomir@307
|
964 |
final Variable vo3 = smapper.pushT(vi1.getType());
|
lubomir@307
|
965 |
final Variable vo2 = smapper.pushT(vi2.getType());
|
lubomir@307
|
966 |
final Variable vo1 = smapper.pushT(vi1.getType());
|
lubomir@281
|
967 |
|
lubomir@283
|
968 |
emit(out, "{ @1 = @2; @3 = @4; @5 = @6; }",
|
lubomir@283
|
969 |
vo1, vi1, vo2, vi2, vo3, vo1);
|
jaroslav@170
|
970 |
break;
|
lubomir@281
|
971 |
}
|
lubomir@281
|
972 |
case opc_dup_x2: {
|
lubomir@307
|
973 |
if (smapper.get(1).isCategory2()) {
|
lubomir@307
|
974 |
final Variable vi1 = smapper.pop();
|
lubomir@307
|
975 |
final Variable vi2 = smapper.pop();
|
lubomir@307
|
976 |
final Variable vo3 = smapper.pushT(vi1.getType());
|
lubomir@307
|
977 |
final Variable vo2 = smapper.pushT(vi2.getType());
|
lubomir@307
|
978 |
final Variable vo1 = smapper.pushT(vi1.getType());
|
lubomir@281
|
979 |
|
lubomir@283
|
980 |
emit(out, "{ @1 = @2; @3 = @4; @5 = @6; }",
|
lubomir@283
|
981 |
vo1, vi1, vo2, vi2, vo3, vo1);
|
lubomir@281
|
982 |
} else {
|
lubomir@307
|
983 |
final Variable vi1 = smapper.pop();
|
lubomir@307
|
984 |
final Variable vi2 = smapper.pop();
|
lubomir@307
|
985 |
final Variable vi3 = smapper.pop();
|
lubomir@307
|
986 |
final Variable vo4 = smapper.pushT(vi1.getType());
|
lubomir@307
|
987 |
final Variable vo3 = smapper.pushT(vi3.getType());
|
lubomir@307
|
988 |
final Variable vo2 = smapper.pushT(vi2.getType());
|
lubomir@307
|
989 |
final Variable vo1 = smapper.pushT(vi1.getType());
|
lubomir@281
|
990 |
|
lubomir@283
|
991 |
emit(out, "{ @1 = @2; @3 = @4; @5 = @6; @7 = @8; }",
|
lubomir@283
|
992 |
vo1, vi1, vo2, vi2, vo3, vi3, vo4, vo1);
|
lubomir@281
|
993 |
}
|
jaroslav@240
|
994 |
break;
|
lubomir@281
|
995 |
}
|
jaroslav@151
|
996 |
case opc_bipush:
|
lubomir@283
|
997 |
emit(out, "@1 = @2;",
|
lubomir@307
|
998 |
smapper.pushI(), Integer.toString(byteCodes[++i]));
|
jaroslav@8
|
999 |
break;
|
jaroslav@151
|
1000 |
case opc_sipush:
|
lubomir@283
|
1001 |
emit(out, "@1 = @2;",
|
lubomir@307
|
1002 |
smapper.pushI(),
|
lubomir@283
|
1003 |
Integer.toString(readIntArg(byteCodes, i)));
|
jaroslav@31
|
1004 |
i += 2;
|
jaroslav@31
|
1005 |
break;
|
jaroslav@151
|
1006 |
case opc_getfield: {
|
jaroslav@8
|
1007 |
int indx = readIntArg(byteCodes, i);
|
jaroslav@151
|
1008 |
String[] fi = jc.getFieldInfoName(indx);
|
lubomir@307
|
1009 |
final int type = VarType.fromFieldType(fi[2].charAt(0));
|
lubomir@283
|
1010 |
emit(out, "@2 = @1.fld_@3;",
|
lubomir@307
|
1011 |
smapper.popA(), smapper.pushT(type), fi[1]);
|
jaroslav@8
|
1012 |
i += 2;
|
jaroslav@8
|
1013 |
break;
|
jaroslav@8
|
1014 |
}
|
jaroslav@151
|
1015 |
case opc_getstatic: {
|
jaroslav@9
|
1016 |
int indx = readIntArg(byteCodes, i);
|
jaroslav@151
|
1017 |
String[] fi = jc.getFieldInfoName(indx);
|
lubomir@307
|
1018 |
final int type = VarType.fromFieldType(fi[2].charAt(0));
|
lubomir@283
|
1019 |
emit(out, "@1 = @2.@3;",
|
lubomir@307
|
1020 |
smapper.pushT(type), fi[0].replace('/', '_'), fi[1]);
|
jaroslav@9
|
1021 |
i += 2;
|
jaroslav@151
|
1022 |
addReference(fi[0]);
|
jaroslav@9
|
1023 |
break;
|
jaroslav@9
|
1024 |
}
|
jaroslav@151
|
1025 |
case opc_putfield: {
|
jaroslav@10
|
1026 |
int indx = readIntArg(byteCodes, i);
|
jaroslav@151
|
1027 |
String[] fi = jc.getFieldInfoName(indx);
|
lubomir@307
|
1028 |
final int type = VarType.fromFieldType(fi[2].charAt(0));
|
lubomir@283
|
1029 |
emit(out, "@2.fld_@3 = @1;",
|
lubomir@307
|
1030 |
smapper.popT(type), smapper.popA(), fi[1]);
|
jaroslav@10
|
1031 |
i += 2;
|
jaroslav@10
|
1032 |
break;
|
jaroslav@10
|
1033 |
}
|
lubomir@281
|
1034 |
case opc_putstatic: {
|
lubomir@281
|
1035 |
int indx = readIntArg(byteCodes, i);
|
lubomir@281
|
1036 |
String[] fi = jc.getFieldInfoName(indx);
|
lubomir@307
|
1037 |
final int type = VarType.fromFieldType(fi[2].charAt(0));
|
lubomir@283
|
1038 |
emit(out, "@1.@2 = @3;",
|
lubomir@307
|
1039 |
fi[0].replace('/', '_'), fi[1], smapper.popT(type));
|
lubomir@281
|
1040 |
i += 2;
|
lubomir@281
|
1041 |
addReference(fi[0]);
|
lubomir@281
|
1042 |
break;
|
lubomir@281
|
1043 |
}
|
jaroslav@151
|
1044 |
case opc_checkcast: {
|
jaroslav@30
|
1045 |
int indx = readIntArg(byteCodes, i);
|
jaroslav@151
|
1046 |
final String type = jc.getClassName(indx);
|
jaroslav@42
|
1047 |
if (!type.startsWith("[")) {
|
jaroslav@42
|
1048 |
// no way to check arrays right now
|
lubomir@283
|
1049 |
// XXX proper exception
|
lubomir@283
|
1050 |
emit(out, "if (@1.$instOf_@2 != 1) throw {};",
|
lubomir@307
|
1051 |
smapper.getA(0), type.replace('/', '_'));
|
jaroslav@42
|
1052 |
}
|
jaroslav@30
|
1053 |
i += 2;
|
jaroslav@30
|
1054 |
break;
|
jaroslav@30
|
1055 |
}
|
jaroslav@151
|
1056 |
case opc_instanceof: {
|
jaroslav@17
|
1057 |
int indx = readIntArg(byteCodes, i);
|
jaroslav@151
|
1058 |
final String type = jc.getClassName(indx);
|
lubomir@283
|
1059 |
emit(out, "@2 = @1.$instOf_@3 ? 1 : 0;",
|
lubomir@307
|
1060 |
smapper.popA(), smapper.pushI(), type.replace('/', '_'));
|
jaroslav@17
|
1061 |
i += 2;
|
jaroslav@30
|
1062 |
break;
|
jaroslav@17
|
1063 |
}
|
jaroslav@151
|
1064 |
case opc_athrow: {
|
lubomir@307
|
1065 |
final Variable v = smapper.popA();
|
lubomir@307
|
1066 |
smapper.clear();
|
lubomir@281
|
1067 |
|
lubomir@283
|
1068 |
emit(out, "{ @1 = @2; throw @2; }",
|
lubomir@307
|
1069 |
smapper.pushA(), v);
|
jaroslav@104
|
1070 |
break;
|
jaroslav@104
|
1071 |
}
|
lubomir@221
|
1072 |
|
lubomir@221
|
1073 |
case opc_monitorenter: {
|
lubomir@221
|
1074 |
out.append("/* monitor enter */");
|
lubomir@307
|
1075 |
smapper.popA();
|
lubomir@221
|
1076 |
break;
|
lubomir@221
|
1077 |
}
|
lubomir@221
|
1078 |
|
lubomir@221
|
1079 |
case opc_monitorexit: {
|
lubomir@221
|
1080 |
out.append("/* monitor exit */");
|
lubomir@307
|
1081 |
smapper.popA();
|
lubomir@221
|
1082 |
break;
|
lubomir@221
|
1083 |
}
|
lubomir@221
|
1084 |
|
jaroslav@104
|
1085 |
default: {
|
lubomir@283
|
1086 |
emit(out, "throw 'unknown bytecode @1';",
|
lubomir@283
|
1087 |
Integer.toString(c));
|
jaroslav@104
|
1088 |
}
|
jaroslav@0
|
1089 |
}
|
jaroslav@39
|
1090 |
out.append(" //");
|
jaroslav@0
|
1091 |
for (int j = prev; j <= i; j++) {
|
jaroslav@0
|
1092 |
out.append(" ");
|
jtulach@128
|
1093 |
final int cc = readByte(byteCodes, j);
|
jaroslav@0
|
1094 |
out.append(Integer.toString(cc));
|
jaroslav@0
|
1095 |
}
|
jaroslav@39
|
1096 |
out.append("\n");
|
jaroslav@0
|
1097 |
}
|
jaroslav@10
|
1098 |
out.append(" }\n");
|
lubomir@307
|
1099 |
out.append("};");
|
jaroslav@4
|
1100 |
}
|
jaroslav@4
|
1101 |
|
lubomir@281
|
1102 |
private int generateIf(byte[] byteCodes, int i,
|
lubomir@281
|
1103 |
final Variable v2, final Variable v1,
|
lubomir@281
|
1104 |
final String test) throws IOException {
|
jaroslav@4
|
1105 |
int indx = i + readIntArg(byteCodes, i);
|
lubomir@281
|
1106 |
out.append("if (").append(v1)
|
lubomir@221
|
1107 |
.append(' ').append(test).append(' ')
|
lubomir@281
|
1108 |
.append(v2).append(") { gt = " + indx)
|
lubomir@221
|
1109 |
.append("; continue; }");
|
jaroslav@4
|
1110 |
return i + 2;
|
jaroslav@4
|
1111 |
}
|
jaroslav@4
|
1112 |
|
jaroslav@4
|
1113 |
private int readIntArg(byte[] byteCodes, int offsetInstruction) {
|
jaroslav@5
|
1114 |
final int indxHi = byteCodes[offsetInstruction + 1] << 8;
|
jaroslav@5
|
1115 |
final int indxLo = byteCodes[offsetInstruction + 2];
|
jaroslav@5
|
1116 |
return (indxHi & 0xffffff00) | (indxLo & 0xff);
|
jaroslav@4
|
1117 |
}
|
jaroslav@115
|
1118 |
private int readInt4(byte[] byteCodes, int offsetInstruction) {
|
jaroslav@115
|
1119 |
final int d = byteCodes[offsetInstruction + 0] << 24;
|
jaroslav@115
|
1120 |
final int c = byteCodes[offsetInstruction + 1] << 16;
|
jaroslav@115
|
1121 |
final int b = byteCodes[offsetInstruction + 2] << 8;
|
jaroslav@115
|
1122 |
final int a = byteCodes[offsetInstruction + 3];
|
jaroslav@115
|
1123 |
return (d & 0xff000000) | (c & 0xff0000) | (b & 0xff00) | (a & 0xff);
|
jaroslav@115
|
1124 |
}
|
jtulach@128
|
1125 |
private int readByte(byte[] byteCodes, int offsetInstruction) {
|
lubomir@221
|
1126 |
return byteCodes[offsetInstruction] & 0xff;
|
jtulach@128
|
1127 |
}
|
jaroslav@4
|
1128 |
|
lubomir@281
|
1129 |
private static void countArgs(String descriptor, char[] returnType, StringBuilder sig, StringBuilder cnt) {
|
jaroslav@4
|
1130 |
int i = 0;
|
jaroslav@4
|
1131 |
Boolean count = null;
|
jaroslav@32
|
1132 |
boolean array = false;
|
jaroslav@248
|
1133 |
sig.append("__");
|
jaroslav@10
|
1134 |
int firstPos = sig.length();
|
jaroslav@4
|
1135 |
while (i < descriptor.length()) {
|
jaroslav@4
|
1136 |
char ch = descriptor.charAt(i++);
|
jaroslav@4
|
1137 |
switch (ch) {
|
jaroslav@4
|
1138 |
case '(':
|
jaroslav@4
|
1139 |
count = true;
|
jaroslav@4
|
1140 |
continue;
|
jaroslav@4
|
1141 |
case ')':
|
jaroslav@4
|
1142 |
count = false;
|
jaroslav@4
|
1143 |
continue;
|
jaroslav@4
|
1144 |
case 'B':
|
jaroslav@4
|
1145 |
case 'C':
|
jaroslav@4
|
1146 |
case 'D':
|
jaroslav@4
|
1147 |
case 'F':
|
jaroslav@4
|
1148 |
case 'I':
|
jaroslav@4
|
1149 |
case 'J':
|
jaroslav@4
|
1150 |
case 'S':
|
jaroslav@4
|
1151 |
case 'Z':
|
jaroslav@4
|
1152 |
if (count) {
|
jaroslav@32
|
1153 |
if (array) {
|
jaroslav@248
|
1154 |
sig.append("_3");
|
jaroslav@32
|
1155 |
}
|
jaroslav@4
|
1156 |
sig.append(ch);
|
jtulach@156
|
1157 |
if (ch == 'J' || ch == 'D') {
|
jtulach@156
|
1158 |
cnt.append('1');
|
jtulach@156
|
1159 |
} else {
|
jtulach@156
|
1160 |
cnt.append('0');
|
jtulach@156
|
1161 |
}
|
jaroslav@4
|
1162 |
} else {
|
jaroslav@10
|
1163 |
sig.insert(firstPos, ch);
|
jaroslav@32
|
1164 |
if (array) {
|
lubomir@281
|
1165 |
returnType[0] = '[';
|
jaroslav@248
|
1166 |
sig.insert(firstPos, "_3");
|
lubomir@281
|
1167 |
} else {
|
lubomir@281
|
1168 |
returnType[0] = ch;
|
jaroslav@32
|
1169 |
}
|
jaroslav@4
|
1170 |
}
|
jaroslav@93
|
1171 |
array = false;
|
jaroslav@4
|
1172 |
continue;
|
jaroslav@4
|
1173 |
case 'V':
|
jaroslav@4
|
1174 |
assert !count;
|
lubomir@281
|
1175 |
returnType[0] = 'V';
|
jaroslav@10
|
1176 |
sig.insert(firstPos, 'V');
|
jaroslav@4
|
1177 |
continue;
|
jaroslav@4
|
1178 |
case 'L':
|
jaroslav@16
|
1179 |
int next = descriptor.indexOf(';', i);
|
jaroslav@248
|
1180 |
String realSig = mangleSig(descriptor, i - 1, next + 1);
|
jaroslav@4
|
1181 |
if (count) {
|
jaroslav@32
|
1182 |
if (array) {
|
jaroslav@248
|
1183 |
sig.append("_3");
|
jaroslav@32
|
1184 |
}
|
jaroslav@248
|
1185 |
sig.append(realSig);
|
jtulach@156
|
1186 |
cnt.append('0');
|
jaroslav@4
|
1187 |
} else {
|
jaroslav@248
|
1188 |
sig.insert(firstPos, realSig);
|
jaroslav@32
|
1189 |
if (array) {
|
jaroslav@248
|
1190 |
sig.insert(firstPos, "_3");
|
jaroslav@32
|
1191 |
}
|
lubomir@281
|
1192 |
returnType[0] = 'L';
|
jaroslav@4
|
1193 |
}
|
jaroslav@16
|
1194 |
i = next + 1;
|
jaroslav@4
|
1195 |
continue;
|
jaroslav@4
|
1196 |
case '[':
|
jaroslav@248
|
1197 |
array = true;
|
jaroslav@4
|
1198 |
continue;
|
jaroslav@4
|
1199 |
default:
|
jaroslav@248
|
1200 |
throw new IllegalStateException("Invalid char: " + ch);
|
jaroslav@4
|
1201 |
}
|
jaroslav@4
|
1202 |
}
|
jaroslav@0
|
1203 |
}
|
jaroslav@248
|
1204 |
|
jaroslav@248
|
1205 |
private static String mangleSig(String txt, int first, int last) {
|
jaroslav@248
|
1206 |
StringBuilder sb = new StringBuilder();
|
jaroslav@248
|
1207 |
for (int i = first; i < last; i++) {
|
jaroslav@248
|
1208 |
final char ch = txt.charAt(i);
|
jaroslav@248
|
1209 |
switch (ch) {
|
jaroslav@248
|
1210 |
case '/': sb.append('_'); break;
|
jaroslav@248
|
1211 |
case '_': sb.append("_1"); break;
|
jaroslav@248
|
1212 |
case ';': sb.append("_2"); break;
|
jaroslav@248
|
1213 |
case '[': sb.append("_3"); break;
|
jaroslav@248
|
1214 |
default: sb.append(ch); break;
|
jaroslav@248
|
1215 |
}
|
jaroslav@248
|
1216 |
}
|
jaroslav@248
|
1217 |
return sb.toString();
|
jaroslav@248
|
1218 |
}
|
jaroslav@9
|
1219 |
|
jaroslav@248
|
1220 |
private static String findMethodName(MethodData m, StringBuilder cnt) {
|
jaroslav@42
|
1221 |
StringBuilder name = new StringBuilder();
|
jaroslav@10
|
1222 |
if ("<init>".equals(m.getName())) { // NOI18N
|
jaroslav@42
|
1223 |
name.append("cons"); // NOI18N
|
jaroslav@19
|
1224 |
} else if ("<clinit>".equals(m.getName())) { // NOI18N
|
jaroslav@42
|
1225 |
name.append("class"); // NOI18N
|
jaroslav@10
|
1226 |
} else {
|
jaroslav@42
|
1227 |
name.append(m.getName());
|
jaroslav@10
|
1228 |
}
|
jaroslav@42
|
1229 |
|
lubomir@282
|
1230 |
countArgs(m.getInternalSig(), new char[1], name, cnt);
|
jaroslav@42
|
1231 |
return name.toString();
|
jaroslav@10
|
1232 |
}
|
jaroslav@10
|
1233 |
|
lubomir@282
|
1234 |
static String findMethodName(String[] mi, StringBuilder cnt, char[] returnType) {
|
jaroslav@10
|
1235 |
StringBuilder name = new StringBuilder();
|
jaroslav@151
|
1236 |
String descr = mi[2];//mi.getDescriptor();
|
jaroslav@151
|
1237 |
String nm= mi[1];
|
jaroslav@151
|
1238 |
if ("<init>".equals(nm)) { // NOI18N
|
jaroslav@10
|
1239 |
name.append("cons"); // NOI18N
|
jaroslav@10
|
1240 |
} else {
|
jaroslav@151
|
1241 |
name.append(nm);
|
jaroslav@10
|
1242 |
}
|
lubomir@282
|
1243 |
countArgs(descr, returnType, name, cnt);
|
jaroslav@10
|
1244 |
return name.toString();
|
jaroslav@10
|
1245 |
}
|
jaroslav@10
|
1246 |
|
lubomir@307
|
1247 |
private int invokeStaticMethod(byte[] byteCodes, int i, final StackMapper mapper, boolean isStatic)
|
jaroslav@10
|
1248 |
throws IOException {
|
jaroslav@10
|
1249 |
int methodIndex = readIntArg(byteCodes, i);
|
jaroslav@151
|
1250 |
String[] mi = jc.getFieldInfoName(methodIndex);
|
lubomir@281
|
1251 |
char[] returnType = { 'V' };
|
jtulach@156
|
1252 |
StringBuilder cnt = new StringBuilder();
|
lubomir@281
|
1253 |
String mn = findMethodName(mi, cnt, returnType);
|
lubomir@221
|
1254 |
|
lubomir@221
|
1255 |
final int numArguments = isStatic ? cnt.length() : cnt.length() + 1;
|
lubomir@281
|
1256 |
final Variable[] vars = new Variable[numArguments];
|
lubomir@221
|
1257 |
|
lubomir@281
|
1258 |
for (int j = numArguments - 1; j >= 0; --j) {
|
lubomir@281
|
1259 |
vars[j] = mapper.pop();
|
jaroslav@11
|
1260 |
}
|
lubomir@281
|
1261 |
|
lubomir@281
|
1262 |
if (returnType[0] != 'V') {
|
lubomir@307
|
1263 |
out.append(mapper.pushT(VarType.fromFieldType(returnType[0])))
|
lubomir@281
|
1264 |
.append(" = ");
|
jaroslav@10
|
1265 |
}
|
lubomir@221
|
1266 |
|
jaroslav@151
|
1267 |
final String in = mi[0];
|
jaroslav@18
|
1268 |
out.append(in.replace('/', '_'));
|
jaroslav@224
|
1269 |
out.append("(false).");
|
jaroslav@10
|
1270 |
out.append(mn);
|
jaroslav@10
|
1271 |
out.append('(');
|
lubomir@221
|
1272 |
if (numArguments > 0) {
|
lubomir@281
|
1273 |
out.append(vars[0]);
|
lubomir@281
|
1274 |
for (int j = 1; j < numArguments; ++j) {
|
lubomir@221
|
1275 |
out.append(", ");
|
lubomir@281
|
1276 |
out.append(vars[j]);
|
lubomir@221
|
1277 |
}
|
jaroslav@10
|
1278 |
}
|
lubomir@221
|
1279 |
out.append(");");
|
jaroslav@10
|
1280 |
i += 2;
|
jaroslav@18
|
1281 |
addReference(in);
|
jaroslav@10
|
1282 |
return i;
|
jaroslav@10
|
1283 |
}
|
lubomir@307
|
1284 |
private int invokeVirtualMethod(byte[] byteCodes, int i, final StackMapper mapper)
|
jaroslav@12
|
1285 |
throws IOException {
|
jaroslav@12
|
1286 |
int methodIndex = readIntArg(byteCodes, i);
|
jaroslav@151
|
1287 |
String[] mi = jc.getFieldInfoName(methodIndex);
|
lubomir@281
|
1288 |
char[] returnType = { 'V' };
|
jtulach@156
|
1289 |
StringBuilder cnt = new StringBuilder();
|
lubomir@281
|
1290 |
String mn = findMethodName(mi, cnt, returnType);
|
lubomir@221
|
1291 |
|
lubomir@281
|
1292 |
final int numArguments = cnt.length() + 1;
|
lubomir@281
|
1293 |
final Variable[] vars = new Variable[numArguments];
|
lubomir@221
|
1294 |
|
lubomir@281
|
1295 |
for (int j = numArguments - 1; j >= 0; --j) {
|
lubomir@281
|
1296 |
vars[j] = mapper.pop();
|
jaroslav@12
|
1297 |
}
|
lubomir@221
|
1298 |
|
lubomir@281
|
1299 |
if (returnType[0] != 'V') {
|
lubomir@307
|
1300 |
out.append(mapper.pushT(VarType.fromFieldType(returnType[0])))
|
lubomir@281
|
1301 |
.append(" = ");
|
jaroslav@12
|
1302 |
}
|
lubomir@281
|
1303 |
|
lubomir@281
|
1304 |
out.append(vars[0]).append('.');
|
jaroslav@12
|
1305 |
out.append(mn);
|
jaroslav@12
|
1306 |
out.append('(');
|
lubomir@281
|
1307 |
out.append(vars[0]);
|
lubomir@281
|
1308 |
for (int j = 1; j < numArguments; ++j) {
|
jaroslav@12
|
1309 |
out.append(", ");
|
lubomir@281
|
1310 |
out.append(vars[j]);
|
jaroslav@12
|
1311 |
}
|
lubomir@221
|
1312 |
out.append(");");
|
jaroslav@12
|
1313 |
i += 2;
|
jaroslav@12
|
1314 |
return i;
|
jaroslav@12
|
1315 |
}
|
lubomir@221
|
1316 |
|
jaroslav@103
|
1317 |
private void addReference(String cn) throws IOException {
|
jtulach@162
|
1318 |
if (requireReference(cn)) {
|
jtulach@162
|
1319 |
out.append(" /* needs ").append(cn).append(" */");
|
jaroslav@18
|
1320 |
}
|
jaroslav@18
|
1321 |
}
|
jaroslav@16
|
1322 |
|
jaroslav@33
|
1323 |
private void outType(String d, StringBuilder out) {
|
jaroslav@33
|
1324 |
int arr = 0;
|
jaroslav@33
|
1325 |
while (d.charAt(0) == '[') {
|
jaroslav@33
|
1326 |
out.append('A');
|
jaroslav@33
|
1327 |
d = d.substring(1);
|
jaroslav@33
|
1328 |
}
|
jaroslav@16
|
1329 |
if (d.charAt(0) == 'L') {
|
jaroslav@16
|
1330 |
assert d.charAt(d.length() - 1) == ';';
|
jaroslav@16
|
1331 |
out.append(d.replace('/', '_').substring(0, d.length() - 1));
|
jaroslav@16
|
1332 |
} else {
|
jaroslav@16
|
1333 |
out.append(d);
|
jaroslav@16
|
1334 |
}
|
jaroslav@16
|
1335 |
}
|
jaroslav@21
|
1336 |
|
jaroslav@230
|
1337 |
private String encodeConstant(int entryIndex) throws IOException {
|
jaroslav@230
|
1338 |
String[] classRef = { null };
|
jaroslav@230
|
1339 |
String s = jc.stringValue(entryIndex, classRef);
|
jaroslav@230
|
1340 |
if (classRef[0] != null) {
|
jaroslav@230
|
1341 |
addReference(classRef[0]);
|
jaroslav@230
|
1342 |
}
|
jaroslav@151
|
1343 |
return s;
|
jaroslav@21
|
1344 |
}
|
jaroslav@32
|
1345 |
|
jaroslav@266
|
1346 |
private String javaScriptBody(String prefix, MethodData m, boolean isStatic) throws IOException {
|
jaroslav@152
|
1347 |
byte[] arr = m.findAnnotationData(true);
|
jaroslav@152
|
1348 |
if (arr == null) {
|
jaroslav@266
|
1349 |
return null;
|
jaroslav@152
|
1350 |
}
|
jaroslav@200
|
1351 |
final String jvmType = "Lorg/apidesign/bck2brwsr/core/JavaScriptBody;";
|
jaroslav@152
|
1352 |
class P extends AnnotationParser {
|
jaroslav@237
|
1353 |
public P() {
|
jaroslav@237
|
1354 |
super(false);
|
jaroslav@237
|
1355 |
}
|
jaroslav@237
|
1356 |
|
jaroslav@152
|
1357 |
int cnt;
|
jaroslav@152
|
1358 |
String[] args = new String[30];
|
jaroslav@152
|
1359 |
String body;
|
jaroslav@94
|
1360 |
|
jaroslav@152
|
1361 |
@Override
|
jaroslav@236
|
1362 |
protected void visitAttr(String type, String attr, String at, String value) {
|
jaroslav@152
|
1363 |
if (type.equals(jvmType)) {
|
jaroslav@152
|
1364 |
if ("body".equals(attr)) {
|
jaroslav@152
|
1365 |
body = value;
|
jaroslav@152
|
1366 |
} else if ("args".equals(attr)) {
|
jaroslav@152
|
1367 |
args[cnt++] = value;
|
jaroslav@152
|
1368 |
} else {
|
jaroslav@152
|
1369 |
throw new IllegalArgumentException(attr);
|
jaroslav@152
|
1370 |
}
|
jaroslav@152
|
1371 |
}
|
jaroslav@94
|
1372 |
}
|
jaroslav@94
|
1373 |
}
|
jaroslav@152
|
1374 |
P p = new P();
|
jaroslav@152
|
1375 |
p.parse(arr, jc);
|
jaroslav@152
|
1376 |
if (p.body == null) {
|
jaroslav@266
|
1377 |
return null;
|
jaroslav@152
|
1378 |
}
|
jtulach@156
|
1379 |
StringBuilder cnt = new StringBuilder();
|
jaroslav@266
|
1380 |
final String mn = findMethodName(m, cnt);
|
jaroslav@266
|
1381 |
out.append(prefix).append(mn);
|
jaroslav@203
|
1382 |
out.append(" = function(");
|
jaroslav@152
|
1383 |
String space;
|
jaroslav@152
|
1384 |
int index;
|
jaroslav@152
|
1385 |
if (!isStatic) {
|
jaroslav@152
|
1386 |
out.append(p.args[0]);
|
jaroslav@152
|
1387 |
space = ",";
|
jaroslav@152
|
1388 |
index = 1;
|
jaroslav@152
|
1389 |
} else {
|
jaroslav@152
|
1390 |
space = "";
|
jaroslav@152
|
1391 |
index = 0;
|
jaroslav@152
|
1392 |
}
|
jtulach@156
|
1393 |
for (int i = 0; i < cnt.length(); i++) {
|
jaroslav@152
|
1394 |
out.append(space);
|
jaroslav@152
|
1395 |
out.append(p.args[index]);
|
jaroslav@152
|
1396 |
index++;
|
jaroslav@152
|
1397 |
space = ",";
|
jaroslav@152
|
1398 |
}
|
jaroslav@152
|
1399 |
out.append(") {").append("\n");
|
jaroslav@152
|
1400 |
out.append(p.body);
|
jaroslav@152
|
1401 |
out.append("\n}\n");
|
jaroslav@266
|
1402 |
return mn;
|
jaroslav@151
|
1403 |
}
|
jaroslav@151
|
1404 |
private static String className(ClassData jc) {
|
jaroslav@151
|
1405 |
//return jc.getName().getInternalName().replace('/', '_');
|
jaroslav@151
|
1406 |
return jc.getClassName().replace('/', '_');
|
jaroslav@94
|
1407 |
}
|
jaroslav@152
|
1408 |
|
jaroslav@152
|
1409 |
private static String[] findAnnotation(
|
jaroslav@152
|
1410 |
byte[] arr, ClassData cd, final String className,
|
jaroslav@152
|
1411 |
final String... attrNames
|
jaroslav@152
|
1412 |
) throws IOException {
|
jaroslav@152
|
1413 |
if (arr == null) {
|
jaroslav@152
|
1414 |
return null;
|
jaroslav@152
|
1415 |
}
|
jaroslav@152
|
1416 |
final String[] values = new String[attrNames.length];
|
jaroslav@152
|
1417 |
final boolean[] found = { false };
|
jaroslav@152
|
1418 |
final String jvmType = "L" + className.replace('.', '/') + ";";
|
jaroslav@237
|
1419 |
AnnotationParser ap = new AnnotationParser(false) {
|
jaroslav@152
|
1420 |
@Override
|
jaroslav@236
|
1421 |
protected void visitAttr(String type, String attr, String at, String value) {
|
jaroslav@152
|
1422 |
if (type.equals(jvmType)) {
|
jaroslav@152
|
1423 |
found[0] = true;
|
jaroslav@152
|
1424 |
for (int i = 0; i < attrNames.length; i++) {
|
jaroslav@152
|
1425 |
if (attrNames[i].equals(attr)) {
|
jaroslav@152
|
1426 |
values[i] = value;
|
jaroslav@152
|
1427 |
}
|
jaroslav@152
|
1428 |
}
|
jaroslav@152
|
1429 |
}
|
jaroslav@152
|
1430 |
}
|
jaroslav@152
|
1431 |
|
jaroslav@152
|
1432 |
};
|
jaroslav@152
|
1433 |
ap.parse(arr, cd);
|
jaroslav@152
|
1434 |
return found[0] ? values : null;
|
jaroslav@152
|
1435 |
}
|
jaroslav@173
|
1436 |
|
jaroslav@173
|
1437 |
private CharSequence initField(FieldData v) {
|
jaroslav@173
|
1438 |
final String is = v.getInternalSig();
|
jaroslav@173
|
1439 |
if (is.length() == 1) {
|
jaroslav@173
|
1440 |
switch (is.charAt(0)) {
|
jaroslav@173
|
1441 |
case 'S':
|
jaroslav@173
|
1442 |
case 'J':
|
jaroslav@173
|
1443 |
case 'B':
|
jaroslav@173
|
1444 |
case 'Z':
|
jaroslav@173
|
1445 |
case 'C':
|
jaroslav@173
|
1446 |
case 'I': return " = 0;";
|
jaroslav@173
|
1447 |
case 'F':
|
jaroslav@180
|
1448 |
case 'D': return " = 0.0;";
|
jaroslav@173
|
1449 |
default:
|
jaroslav@173
|
1450 |
throw new IllegalStateException(is);
|
jaroslav@173
|
1451 |
}
|
jaroslav@173
|
1452 |
}
|
jaroslav@173
|
1453 |
return " = null;";
|
jaroslav@173
|
1454 |
}
|
jaroslav@235
|
1455 |
|
jaroslav@235
|
1456 |
private static void generateAnno(ClassData cd, final Appendable out, byte[] data) throws IOException {
|
jaroslav@237
|
1457 |
AnnotationParser ap = new AnnotationParser(true) {
|
jaroslav@237
|
1458 |
int anno;
|
jaroslav@235
|
1459 |
int cnt;
|
jaroslav@235
|
1460 |
|
jaroslav@235
|
1461 |
@Override
|
jaroslav@235
|
1462 |
protected void visitAnnotationStart(String type) throws IOException {
|
jaroslav@237
|
1463 |
if (anno++ > 0) {
|
jaroslav@237
|
1464 |
out.append(",");
|
jaroslav@237
|
1465 |
}
|
jaroslav@235
|
1466 |
out.append('"').append(type).append("\" : {\n");
|
jaroslav@235
|
1467 |
cnt = 0;
|
jaroslav@235
|
1468 |
}
|
jaroslav@235
|
1469 |
|
jaroslav@235
|
1470 |
@Override
|
jaroslav@235
|
1471 |
protected void visitAnnotationEnd(String type) throws IOException {
|
jaroslav@235
|
1472 |
out.append("\n}\n");
|
jaroslav@235
|
1473 |
}
|
jaroslav@235
|
1474 |
|
jaroslav@235
|
1475 |
@Override
|
jaroslav@236
|
1476 |
protected void visitAttr(String type, String attr, String attrType, String value)
|
jaroslav@235
|
1477 |
throws IOException {
|
jaroslav@266
|
1478 |
if (attr == null) {
|
jaroslav@266
|
1479 |
return;
|
jaroslav@266
|
1480 |
}
|
jaroslav@235
|
1481 |
if (cnt++ > 0) {
|
jaroslav@235
|
1482 |
out.append(",\n");
|
jaroslav@235
|
1483 |
}
|
jaroslav@250
|
1484 |
out.append(attr).append("__").append(attrType).append(" : ").append(value);
|
jaroslav@235
|
1485 |
}
|
jaroslav@235
|
1486 |
};
|
jaroslav@235
|
1487 |
ap.parse(data, cd);
|
jaroslav@235
|
1488 |
}
|
lubomir@282
|
1489 |
|
lubomir@283
|
1490 |
private static void emit(final Appendable out,
|
lubomir@283
|
1491 |
final String format,
|
lubomir@283
|
1492 |
final CharSequence... params) throws IOException {
|
lubomir@283
|
1493 |
final int length = format.length();
|
lubomir@283
|
1494 |
|
lubomir@283
|
1495 |
int processed = 0;
|
lubomir@283
|
1496 |
int paramOffset = format.indexOf('@');
|
lubomir@283
|
1497 |
while ((paramOffset != -1) && (paramOffset < (length - 1))) {
|
lubomir@283
|
1498 |
final char paramChar = format.charAt(paramOffset + 1);
|
lubomir@283
|
1499 |
if ((paramChar >= '1') && (paramChar <= '9')) {
|
lubomir@283
|
1500 |
final int paramIndex = paramChar - '0' - 1;
|
lubomir@283
|
1501 |
|
lubomir@283
|
1502 |
out.append(format, processed, paramOffset);
|
lubomir@283
|
1503 |
out.append(params[paramIndex]);
|
lubomir@283
|
1504 |
|
lubomir@283
|
1505 |
++paramOffset;
|
lubomir@283
|
1506 |
processed = paramOffset + 1;
|
lubomir@283
|
1507 |
}
|
lubomir@283
|
1508 |
|
lubomir@283
|
1509 |
paramOffset = format.indexOf('@', paramOffset + 1);
|
lubomir@283
|
1510 |
}
|
lubomir@283
|
1511 |
|
lubomir@283
|
1512 |
out.append(format, processed, length);
|
lubomir@283
|
1513 |
}
|
lubomir@283
|
1514 |
|
jaroslav@0
|
1515 |
}
|