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;
|
jaroslav@810
|
22 |
import static org.apidesign.vm4brwsr.ByteCodeParser.*;
|
jaroslav@0
|
23 |
|
jaroslav@0
|
24 |
/** Translator of the code inside class files to JavaScript.
|
jaroslav@0
|
25 |
*
|
jaroslav@0
|
26 |
* @author Jaroslav Tulach <jtulach@netbeans.org>
|
jaroslav@0
|
27 |
*/
|
jaroslav@1509
|
28 |
abstract class ByteCodeToJavaScript implements Appendable {
|
jtulach@162
|
29 |
private ClassData jc;
|
jaroslav@1509
|
30 |
private final Appendable out;
|
jaroslav@1509
|
31 |
private boolean outChanged;
|
jaroslav@1515
|
32 |
private boolean callbacks;
|
jaroslav@0
|
33 |
|
jtulach@162
|
34 |
protected ByteCodeToJavaScript(Appendable out) {
|
jaroslav@0
|
35 |
this.out = out;
|
jaroslav@0
|
36 |
}
|
jtulach@162
|
37 |
|
jaroslav@1509
|
38 |
@Override
|
jaroslav@1509
|
39 |
public final Appendable append(CharSequence csq) throws IOException {
|
jaroslav@1509
|
40 |
out.append(csq);
|
jaroslav@1509
|
41 |
outChanged = true;
|
jaroslav@1509
|
42 |
return this;
|
jaroslav@1509
|
43 |
}
|
jaroslav@1509
|
44 |
|
jaroslav@1509
|
45 |
@Override
|
jaroslav@1509
|
46 |
public final Appendable append(CharSequence csq, int start, int end) throws IOException {
|
jaroslav@1509
|
47 |
out.append(csq, start, end);
|
jaroslav@1509
|
48 |
outChanged = true;
|
jaroslav@1509
|
49 |
return this;
|
jaroslav@1509
|
50 |
}
|
jaroslav@1509
|
51 |
|
jaroslav@1509
|
52 |
@Override
|
jaroslav@1509
|
53 |
public final Appendable append(char c) throws IOException {
|
jaroslav@1509
|
54 |
out.append(c);
|
jaroslav@1509
|
55 |
outChanged = true;
|
jaroslav@1509
|
56 |
return this;
|
jaroslav@1509
|
57 |
}
|
jaroslav@1509
|
58 |
|
jtulach@162
|
59 |
/* Collects additional required resources.
|
jtulach@162
|
60 |
*
|
jtulach@162
|
61 |
* @param internalClassName classes that were referenced and should be loaded in order the
|
jtulach@162
|
62 |
* generated JavaScript code works properly. The names are in internal
|
jtulach@162
|
63 |
* JVM form so String is <code>java/lang/String</code>.
|
jtulach@162
|
64 |
*/
|
jtulach@162
|
65 |
protected abstract boolean requireReference(String internalClassName);
|
jtulach@162
|
66 |
|
jtulach@162
|
67 |
/*
|
jtulach@162
|
68 |
* @param resourcePath name of resources to read
|
jtulach@162
|
69 |
*/
|
jaroslav@503
|
70 |
protected abstract void requireScript(String resourcePath) throws IOException;
|
jaroslav@213
|
71 |
|
jaroslav@213
|
72 |
/** Allows subclasses to redefine what field a function representing a
|
jaroslav@213
|
73 |
* class gets assigned. By default it returns the suggested name followed
|
jaroslav@213
|
74 |
* by <code>" = "</code>;
|
jaroslav@213
|
75 |
*
|
jaroslav@213
|
76 |
* @param className suggested name of the class
|
jaroslav@213
|
77 |
*/
|
jaroslav@274
|
78 |
/* protected */ String assignClass(String className) {
|
jaroslav@213
|
79 |
return className + " = ";
|
jaroslav@213
|
80 |
}
|
jaroslav@274
|
81 |
/* protected */ String accessClass(String classOperation) {
|
jaroslav@274
|
82 |
return classOperation;
|
jaroslav@274
|
83 |
}
|
lubomir@869
|
84 |
|
lubomir@1085
|
85 |
protected String accessField(String object, String mangledName,
|
lubomir@1085
|
86 |
String[] fieldInfoName) throws IOException {
|
lubomir@1085
|
87 |
return object + "." + mangledName;
|
lubomir@1085
|
88 |
}
|
lubomir@1085
|
89 |
|
lubomir@1085
|
90 |
protected String accessStaticMethod(
|
lubomir@1085
|
91 |
String object,
|
lubomir@1085
|
92 |
String mangledName,
|
lubomir@1085
|
93 |
String[] fieldInfoName) throws IOException {
|
lubomir@1085
|
94 |
return object + "." + mangledName;
|
lubomir@1085
|
95 |
}
|
lubomir@1085
|
96 |
|
lubomir@1085
|
97 |
protected String accessVirtualMethod(
|
jaroslav@1613
|
98 |
String object,
|
jaroslav@1613
|
99 |
String mangledName,
|
jaroslav@1613
|
100 |
String[] fieldInfoName,
|
jaroslav@1613
|
101 |
int params
|
jaroslav@1613
|
102 |
) throws IOException {
|
jaroslav@1613
|
103 |
return object + "." + mangledName + '(';
|
lubomir@1084
|
104 |
}
|
lubomir@1084
|
105 |
|
lubomir@1029
|
106 |
protected void declaredClass(ClassData classData, String mangledName)
|
lubomir@1029
|
107 |
throws IOException {
|
lubomir@1029
|
108 |
}
|
jaroslav@962
|
109 |
|
lubomir@1083
|
110 |
protected void declaredField(FieldData fieldData,
|
lubomir@1083
|
111 |
String destObject,
|
lubomir@1083
|
112 |
String mangledName) throws IOException {
|
lubomir@1083
|
113 |
}
|
lubomir@1083
|
114 |
|
lubomir@1083
|
115 |
protected void declaredMethod(MethodData methodData,
|
lubomir@1083
|
116 |
String destObject,
|
lubomir@1083
|
117 |
String mangledName) throws IOException {
|
lubomir@1083
|
118 |
}
|
lubomir@869
|
119 |
|
jaroslav@399
|
120 |
/** Prints out a debug message.
|
jaroslav@399
|
121 |
*
|
jaroslav@399
|
122 |
* @param msg the message
|
jaroslav@399
|
123 |
* @return true if the message has been printed
|
jaroslav@399
|
124 |
* @throws IOException
|
jaroslav@399
|
125 |
*/
|
jaroslav@399
|
126 |
boolean debug(String msg) throws IOException {
|
jaroslav@1509
|
127 |
append(msg);
|
jaroslav@399
|
128 |
return true;
|
jaroslav@399
|
129 |
}
|
jaroslav@18
|
130 |
|
jaroslav@18
|
131 |
/**
|
jaroslav@18
|
132 |
* Converts a given class file to a JavaScript version.
|
jaroslav@18
|
133 |
*
|
jaroslav@0
|
134 |
* @param classFile input stream with code of the .class file
|
jaroslav@97
|
135 |
* @return the initialization code for this class, if any. Otherwise <code>null</code>
|
jaroslav@91
|
136 |
*
|
jaroslav@0
|
137 |
* @throws IOException if something goes wrong during read or write or translating
|
jaroslav@0
|
138 |
*/
|
jaroslav@18
|
139 |
|
jtulach@162
|
140 |
public String compile(InputStream classFile) throws IOException {
|
lubomir@1084
|
141 |
return compile(new ClassData(classFile));
|
lubomir@1084
|
142 |
}
|
lubomir@1084
|
143 |
|
lubomir@1084
|
144 |
protected String compile(ClassData classData) throws IOException {
|
lubomir@1084
|
145 |
this.jc = classData;
|
jaroslav@1515
|
146 |
this.callbacks = this.jc.getClassName().endsWith("/$JsCallbacks$");
|
jaroslav@324
|
147 |
if (jc.getMajor_version() < 50) {
|
jaroslav@324
|
148 |
throw new IOException("Can't compile " + jc.getClassName() + ". Class file version " + jc.getMajor_version() + "."
|
jaroslav@324
|
149 |
+ jc.getMinor_version() + " - recompile with -target 1.6 (at least)."
|
jaroslav@324
|
150 |
);
|
jaroslav@324
|
151 |
}
|
jaroslav@152
|
152 |
byte[] arrData = jc.findAnnotationData(true);
|
jaroslav@1239
|
153 |
{
|
jaroslav@1239
|
154 |
String[] arr = findAnnotation(arrData, jc,
|
jaroslav@1239
|
155 |
"org.apidesign.bck2brwsr.core.ExtraJavaScript",
|
jaroslav@1239
|
156 |
"resource", "processByteCode"
|
jaroslav@1239
|
157 |
);
|
jaroslav@1239
|
158 |
if (arr != null) {
|
jaroslav@1239
|
159 |
if (!arr[0].isEmpty()) {
|
jaroslav@1239
|
160 |
requireScript(arr[0]);
|
jaroslav@1239
|
161 |
}
|
jaroslav@1239
|
162 |
if ("0".equals(arr[1])) {
|
jaroslav@1239
|
163 |
return null;
|
jaroslav@1239
|
164 |
}
|
lubomir@848
|
165 |
}
|
jaroslav@1239
|
166 |
}
|
jaroslav@1239
|
167 |
{
|
jaroslav@1239
|
168 |
String[] arr = findAnnotation(arrData, jc,
|
jaroslav@1239
|
169 |
"net.java.html.js.JavaScriptResource",
|
jaroslav@1239
|
170 |
"value"
|
jaroslav@1239
|
171 |
);
|
jaroslav@1239
|
172 |
if (arr != null) {
|
jaroslav@1239
|
173 |
if (arr[0].startsWith("/")) {
|
jaroslav@1239
|
174 |
requireScript(arr[0]);
|
jaroslav@1239
|
175 |
} else {
|
jaroslav@1239
|
176 |
int last = jc.getClassName().lastIndexOf('/');
|
jaroslav@1239
|
177 |
requireScript(
|
jaroslav@1239
|
178 |
jc.getClassName().substring(0, last + 1).replace('.', '/') + arr[0]
|
jaroslav@1239
|
179 |
);
|
jaroslav@1239
|
180 |
}
|
jaroslav@91
|
181 |
}
|
jaroslav@91
|
182 |
}
|
jaroslav@239
|
183 |
String[] proto = findAnnotation(arrData, jc,
|
jaroslav@239
|
184 |
"org.apidesign.bck2brwsr.core.JavaScriptPrototype",
|
jaroslav@239
|
185 |
"container", "prototype"
|
jaroslav@239
|
186 |
);
|
jtulach@162
|
187 |
StringArray toInitilize = new StringArray();
|
jaroslav@151
|
188 |
final String className = className(jc);
|
jaroslav@1509
|
189 |
append("\n\n").append(assignClass(className));
|
jaroslav@1509
|
190 |
append("function ").append(className).append("() {");
|
jaroslav@1509
|
191 |
append("\n var CLS = ").append(className).append(';');
|
jaroslav@1509
|
192 |
append("\n if (!CLS.$class) {");
|
jaroslav@239
|
193 |
if (proto == null) {
|
jaroslav@239
|
194 |
String sc = jc.getSuperClassName(); // with _
|
jaroslav@1509
|
195 |
append("\n var pp = ").
|
jaroslav@1409
|
196 |
append(accessClass(mangleClassName(sc))).append("(true);");
|
jaroslav@1509
|
197 |
append("\n var p = CLS.prototype = pp;");
|
jaroslav@1509
|
198 |
append("\n var c = p;");
|
jaroslav@1509
|
199 |
append("\n var sprcls = pp.constructor.$class;");
|
jtulach@130
|
200 |
} else {
|
jaroslav@1509
|
201 |
append("\n var p = CLS.prototype = ").append(proto[1]).append(";");
|
jaroslav@316
|
202 |
if (proto[0] == null) {
|
jaroslav@316
|
203 |
proto[0] = "p";
|
jaroslav@316
|
204 |
}
|
jaroslav@1509
|
205 |
append("\n var c = ").append(proto[0]).append(";");
|
jaroslav@1509
|
206 |
append("\n var sprcls = null;");
|
jaroslav@13
|
207 |
}
|
jaroslav@592
|
208 |
for (FieldData v : jc.getFields()) {
|
jaroslav@592
|
209 |
if (v.isStatic()) {
|
jaroslav@1474
|
210 |
if ((v.access & ACC_FINAL) != 0 && v.hasConstantValue()) {
|
jaroslav@1474
|
211 |
if (v.getInternalSig().length() == 1 || v.getInternalSig().equals("Ljava/lang/String;")) {
|
jaroslav@1472
|
212 |
continue;
|
jaroslav@1472
|
213 |
}
|
jaroslav@1472
|
214 |
}
|
jaroslav@1509
|
215 |
append("\n CLS.fld_").append(v.getName()).append(initField(v));
|
jaroslav@1509
|
216 |
append("\n c._").append(v.getName()).append(" = function (v) {")
|
jaroslav@1353
|
217 |
.append(" if (arguments.length == 1) CLS.fld_").append(v.getName())
|
jaroslav@1353
|
218 |
.append(" = v; return CLS.fld_").
|
jaroslav@775
|
219 |
append(v.getName()).append("; };");
|
jaroslav@592
|
220 |
} else {
|
jaroslav@1509
|
221 |
append("\n c._").append(v.getName()).append(" = function (v) {")
|
jaroslav@592
|
222 |
.append(" if (arguments.length == 1) this.fld_").
|
jaroslav@592
|
223 |
append(className).append('_').append(v.getName())
|
jaroslav@592
|
224 |
.append(" = v; return this.fld_").
|
jaroslav@592
|
225 |
append(className).append('_').append(v.getName())
|
jaroslav@592
|
226 |
.append("; };");
|
jaroslav@592
|
227 |
}
|
lubomir@869
|
228 |
|
lubomir@1083
|
229 |
declaredField(v, "c", "_" + v.getName());
|
jaroslav@592
|
230 |
}
|
jaroslav@151
|
231 |
for (MethodData m : jc.getMethods()) {
|
jaroslav@240
|
232 |
byte[] onlyArr = m.findAnnotationData(true);
|
jaroslav@1586
|
233 |
if (javaScriptOnly(onlyArr)) continue;
|
lubomir@869
|
234 |
String destObject;
|
jaroslav@266
|
235 |
String mn;
|
jaroslav@1509
|
236 |
append("\n ");
|
jaroslav@203
|
237 |
if (m.isStatic()) {
|
lubomir@869
|
238 |
destObject = "c";
|
lubomir@869
|
239 |
mn = generateStaticMethod(destObject, m, toInitilize);
|
jaroslav@203
|
240 |
} else {
|
jaroslav@397
|
241 |
if (m.isConstructor()) {
|
lubomir@869
|
242 |
destObject = "CLS";
|
lubomir@869
|
243 |
mn = generateInstanceMethod(destObject, m);
|
jaroslav@397
|
244 |
} else {
|
lubomir@869
|
245 |
destObject = "c";
|
lubomir@869
|
246 |
mn = generateInstanceMethod(destObject, m);
|
jaroslav@397
|
247 |
}
|
jaroslav@266
|
248 |
}
|
lubomir@1083
|
249 |
declaredMethod(m, destObject, mn);
|
jaroslav@266
|
250 |
byte[] runAnno = m.findAnnotationData(false);
|
jaroslav@266
|
251 |
if (runAnno != null) {
|
jaroslav@1509
|
252 |
append("\n ").append(destObject).append(".").append(mn).append(".anno = {");
|
jaroslav@1509
|
253 |
generateAnno(jc, runAnno);
|
jaroslav@1509
|
254 |
append("\n };");
|
jaroslav@38
|
255 |
}
|
jaroslav@1509
|
256 |
append("\n ").append(destObject).append(".").append(mn).append(".access = " + m.getAccess()).append(";");
|
jaroslav@1509
|
257 |
append("\n ").append(destObject).append(".").append(mn).append(".cls = CLS;");
|
jaroslav@38
|
258 |
}
|
jaroslav@1509
|
259 |
append("\n c.constructor = CLS;");
|
jaroslav@1509
|
260 |
append("\n function fillInstOf(x) {");
|
lubomir@869
|
261 |
String instOfName = "$instOf_" + className;
|
jaroslav@1632
|
262 |
append("\n Object.defineProperty(x, '").append(instOfName).append("', { value : true });");
|
jaroslav@1256
|
263 |
for (String superInterface : jc.getSuperInterfaces()) {
|
jaroslav@1256
|
264 |
String intrfc = superInterface.replace('/', '_');
|
jaroslav@1513
|
265 |
append("\n vm.").append(intrfc).append("(false)['fillInstOf'](x);");
|
jaroslav@1256
|
266 |
requireReference(superInterface);
|
jaroslav@1256
|
267 |
}
|
jaroslav@1509
|
268 |
append("\n }");
|
jaroslav@1632
|
269 |
append("\n try {");
|
jaroslav@1632
|
270 |
append("\n Object.defineProperty(c, 'fillInstOf', { value: fillInstOf });");
|
jaroslav@1632
|
271 |
append("\n fillInstOf(c);");
|
jaroslav@1632
|
272 |
append("\n } catch (ignore) {");
|
jaroslav@1632
|
273 |
append("\n }");
|
jaroslav@1513
|
274 |
// obfuscationDelegate.exportJSProperty(this, "c", instOfName);
|
jaroslav@1509
|
275 |
append("\n CLS.$class = 'temp';");
|
jaroslav@1509
|
276 |
append("\n CLS.$class = ");
|
jaroslav@1509
|
277 |
append(accessClass("java_lang_Class(true);"));
|
jaroslav@1509
|
278 |
append("\n CLS.$class.jvmName = '").append(jc.getClassName()).append("';");
|
jaroslav@1509
|
279 |
append("\n CLS.$class.superclass = sprcls;");
|
jaroslav@1509
|
280 |
append("\n CLS.$class.access = ").append(jc.getAccessFlags()+";");
|
jaroslav@1509
|
281 |
append("\n CLS.$class.cnstr = CLS;");
|
jaroslav@235
|
282 |
byte[] classAnno = jc.findAnnotationData(false);
|
jaroslav@235
|
283 |
if (classAnno != null) {
|
jaroslav@1509
|
284 |
append("\n CLS.$class.anno = {");
|
jaroslav@1509
|
285 |
generateAnno(jc, classAnno);
|
jaroslav@1509
|
286 |
append("\n };");
|
jaroslav@235
|
287 |
}
|
jaroslav@834
|
288 |
for (String init : toInitilize.toArray()) {
|
jaroslav@1509
|
289 |
append("\n ").append(init).append("();");
|
jaroslav@834
|
290 |
}
|
jaroslav@1509
|
291 |
append("\n }");
|
jaroslav@1509
|
292 |
append("\n if (arguments.length === 0) {");
|
jaroslav@1509
|
293 |
append("\n if (!(this instanceof CLS)) {");
|
jaroslav@1509
|
294 |
append("\n return new CLS();");
|
jaroslav@1509
|
295 |
append("\n }");
|
jaroslav@205
|
296 |
for (FieldData v : jc.getFields()) {
|
jaroslav@240
|
297 |
byte[] onlyArr = v.findAnnotationData(true);
|
jaroslav@1586
|
298 |
if (javaScriptOnly(onlyArr)) continue;
|
jaroslav@205
|
299 |
if (!v.isStatic()) {
|
jaroslav@1509
|
300 |
append("\n this.fld_").
|
jaroslav@592
|
301 |
append(className).append('_').
|
jaroslav@205
|
302 |
append(v.getName()).append(initField(v));
|
jaroslav@205
|
303 |
}
|
jaroslav@205
|
304 |
}
|
jaroslav@1509
|
305 |
append("\n return this;");
|
jaroslav@1509
|
306 |
append("\n }");
|
jaroslav@1509
|
307 |
append("\n return arguments[0] ? new CLS() : CLS.prototype;");
|
jaroslav@1509
|
308 |
append("\n};");
|
lubomir@869
|
309 |
|
lubomir@1029
|
310 |
declaredClass(jc, className);
|
lubomir@869
|
311 |
|
jaroslav@834
|
312 |
// StringBuilder sb = new StringBuilder();
|
jaroslav@834
|
313 |
// for (String init : toInitilize.toArray()) {
|
jaroslav@834
|
314 |
// sb.append("\n").append(init).append("();");
|
jaroslav@834
|
315 |
// }
|
jaroslav@834
|
316 |
return "";
|
jaroslav@0
|
317 |
}
|
jaroslav@1586
|
318 |
|
jaroslav@1586
|
319 |
private boolean javaScriptOnly(byte[] anno) throws IOException {
|
jaroslav@1586
|
320 |
String[] only = findAnnotation(anno, jc,
|
jaroslav@1586
|
321 |
"org.apidesign.bck2brwsr.core.JavaScriptOnly",
|
jaroslav@1586
|
322 |
"name", "value"
|
jaroslav@1586
|
323 |
);
|
jaroslav@1586
|
324 |
if (only != null) {
|
jaroslav@1586
|
325 |
if (only[0] != null && only[1] != null) {
|
jaroslav@1586
|
326 |
append("\n p.").append(only[0]).append(" = ")
|
jaroslav@1586
|
327 |
.append(only[1]).append(";");
|
jaroslav@1586
|
328 |
}
|
jaroslav@1586
|
329 |
if (ExportedSymbols.isMarkedAsExported(anno, jc)) {
|
jaroslav@1586
|
330 |
append("\n p['").append(only[0]).append("'] = p.")
|
jaroslav@1586
|
331 |
.append(only[0]).append(";");
|
jaroslav@1586
|
332 |
}
|
jaroslav@1586
|
333 |
return true;
|
jaroslav@1586
|
334 |
}
|
jaroslav@1586
|
335 |
return false;
|
jaroslav@1586
|
336 |
}
|
lubomir@869
|
337 |
private String generateStaticMethod(String destObject, MethodData m, StringArray toInitilize) throws IOException {
|
lubomir@869
|
338 |
String jsb = javaScriptBody(destObject, m, true);
|
jaroslav@266
|
339 |
if (jsb != null) {
|
jaroslav@266
|
340 |
return jsb;
|
jaroslav@94
|
341 |
}
|
lubomir@307
|
342 |
final String mn = findMethodName(m, new StringBuilder());
|
jaroslav@248
|
343 |
if (mn.equals("class__V")) {
|
jaroslav@274
|
344 |
toInitilize.add(accessClass(className(jc)) + "(false)." + mn);
|
jaroslav@21
|
345 |
}
|
lubomir@869
|
346 |
generateMethod(destObject, mn, m);
|
jaroslav@266
|
347 |
return mn;
|
jaroslav@10
|
348 |
}
|
lubomir@307
|
349 |
|
lubomir@869
|
350 |
private String generateInstanceMethod(String destObject, MethodData m) throws IOException {
|
lubomir@869
|
351 |
String jsb = javaScriptBody(destObject, m, false);
|
jaroslav@266
|
352 |
if (jsb != null) {
|
jaroslav@266
|
353 |
return jsb;
|
jaroslav@94
|
354 |
}
|
lubomir@307
|
355 |
final String mn = findMethodName(m, new StringBuilder());
|
lubomir@869
|
356 |
generateMethod(destObject, mn, m);
|
jaroslav@266
|
357 |
return mn;
|
jaroslav@0
|
358 |
}
|
jaroslav@0
|
359 |
|
lubomir@869
|
360 |
private void generateMethod(String destObject, String name, MethodData m)
|
lubomir@307
|
361 |
throws IOException {
|
lubomir@307
|
362 |
final StackMapIterator stackMapIterator = m.createStackMapIterator();
|
jaroslav@376
|
363 |
TrapDataIterator trap = m.getTrapDataIterator();
|
lubomir@307
|
364 |
final LocalsMapper lmapper =
|
lubomir@307
|
365 |
new LocalsMapper(stackMapIterator.getArguments());
|
lubomir@307
|
366 |
|
jaroslav@1633
|
367 |
boolean obj = "java/lang/Object".equals(jc.getClassName());
|
jaroslav@1633
|
368 |
|
jaroslav@1633
|
369 |
if (obj) {
|
jaroslav@1633
|
370 |
append("Object.defineProperty(").append(destObject).
|
jaroslav@1633
|
371 |
append(", '").append(name).append("', { configurable: true, writable: true, value: function(");
|
jaroslav@1633
|
372 |
} else {
|
jaroslav@1633
|
373 |
append(destObject).append(".").append(name).append(" = function(");
|
jaroslav@1633
|
374 |
}
|
jaroslav@1509
|
375 |
lmapper.outputArguments(this, m.isStatic());
|
jaroslav@1509
|
376 |
append(") {").append("\n");
|
lubomir@307
|
377 |
|
lubomir@221
|
378 |
final byte[] byteCodes = m.getCode();
|
lubomir@307
|
379 |
if (byteCodes == null) {
|
jaroslav@1509
|
380 |
append(" throw 'no code found for ")
|
jaroslav@424
|
381 |
.append(jc.getClassName()).append('.')
|
jaroslav@424
|
382 |
.append(m.getName()).append("';\n");
|
jaroslav@1633
|
383 |
if (obj) {
|
jaroslav@1633
|
384 |
append("}");
|
jaroslav@1633
|
385 |
}
|
jaroslav@1509
|
386 |
append("};");
|
lubomir@307
|
387 |
return;
|
lubomir@307
|
388 |
}
|
lubomir@307
|
389 |
|
lubomir@307
|
390 |
final StackMapper smapper = new StackMapper();
|
lubomir@307
|
391 |
|
jaroslav@442
|
392 |
if (!m.isStatic()) {
|
jaroslav@1509
|
393 |
append(" var ").append(" lcA0 = this;\n");
|
jaroslav@442
|
394 |
}
|
lubomir@221
|
395 |
|
jaroslav@1469
|
396 |
int lastStackFrame;
|
jaroslav@398
|
397 |
TrapData[] previousTrap = null;
|
lubomir@585
|
398 |
boolean wide = false;
|
jaroslav@1469
|
399 |
boolean didBranches;
|
jaroslav@1469
|
400 |
if (stackMapIterator.isEmpty()) {
|
jaroslav@1469
|
401 |
didBranches = false;
|
jaroslav@1469
|
402 |
lastStackFrame = 0;
|
jaroslav@1469
|
403 |
} else {
|
jaroslav@1469
|
404 |
didBranches = true;
|
jaroslav@1469
|
405 |
lastStackFrame = -1;
|
jaroslav@1509
|
406 |
append("\n var gt = 0;\n");
|
jaroslav@1469
|
407 |
}
|
jaroslav@398
|
408 |
|
jaroslav@839
|
409 |
int openBraces = 0;
|
jaroslav@843
|
410 |
int topMostLabel = 0;
|
jaroslav@0
|
411 |
for (int i = 0; i < byteCodes.length; i++) {
|
jaroslav@272
|
412 |
int prev = i;
|
jaroslav@1510
|
413 |
outChanged = false;
|
lubomir@221
|
414 |
stackMapIterator.advanceTo(i);
|
jaroslav@398
|
415 |
boolean changeInCatch = trap.advanceTo(i);
|
jaroslav@398
|
416 |
if (changeInCatch || lastStackFrame != stackMapIterator.getFrameIndex()) {
|
jaroslav@398
|
417 |
if (previousTrap != null) {
|
jaroslav@843
|
418 |
generateCatch(previousTrap, i, topMostLabel);
|
jaroslav@398
|
419 |
previousTrap = null;
|
jaroslav@398
|
420 |
}
|
jaroslav@398
|
421 |
}
|
lubomir@221
|
422 |
if (lastStackFrame != stackMapIterator.getFrameIndex()) {
|
jaroslav@1509
|
423 |
smapper.flush(this);
|
jaroslav@839
|
424 |
if (i != 0) {
|
jaroslav@1509
|
425 |
append(" }\n");
|
jaroslav@839
|
426 |
}
|
jaroslav@843
|
427 |
if (openBraces > 64) {
|
jaroslav@843
|
428 |
for (int c = 0; c < 64; c++) {
|
jaroslav@1509
|
429 |
append("break;}\n");
|
jaroslav@843
|
430 |
}
|
jaroslav@843
|
431 |
openBraces = 1;
|
jaroslav@843
|
432 |
topMostLabel = i;
|
jaroslav@843
|
433 |
}
|
jaroslav@839
|
434 |
|
lubomir@221
|
435 |
lastStackFrame = stackMapIterator.getFrameIndex();
|
lubomir@307
|
436 |
lmapper.syncWithFrameLocals(stackMapIterator.getFrameLocals());
|
lubomir@307
|
437 |
smapper.syncWithFrameStack(stackMapIterator.getFrameStack());
|
jaroslav@1509
|
438 |
append(" X_" + i).append(": for (;;) { IF: if (gt <= " + i + ") {\n");
|
jaroslav@839
|
439 |
openBraces++;
|
jaroslav@398
|
440 |
changeInCatch = true;
|
lubomir@221
|
441 |
} else {
|
jaroslav@399
|
442 |
debug(" /* " + i + " */ ");
|
lubomir@221
|
443 |
}
|
jaroslav@398
|
444 |
if (changeInCatch && trap.useTry()) {
|
jaroslav@1509
|
445 |
append("try {");
|
jaroslav@398
|
446 |
previousTrap = trap.current();
|
tzezula@285
|
447 |
}
|
lubomir@585
|
448 |
final int c = readUByte(byteCodes, i);
|
jaroslav@0
|
449 |
switch (c) {
|
jaroslav@151
|
450 |
case opc_aload_0:
|
jaroslav@1509
|
451 |
smapper.assign(this, VarType.REFERENCE, lmapper.getA(0));
|
lubomir@281
|
452 |
break;
|
jaroslav@151
|
453 |
case opc_iload_0:
|
jaroslav@1509
|
454 |
smapper.assign(this, VarType.INTEGER, lmapper.getI(0));
|
lubomir@281
|
455 |
break;
|
jaroslav@151
|
456 |
case opc_lload_0:
|
jaroslav@1509
|
457 |
smapper.assign(this, VarType.LONG, lmapper.getL(0));
|
lubomir@281
|
458 |
break;
|
jaroslav@151
|
459 |
case opc_fload_0:
|
jaroslav@1509
|
460 |
smapper.assign(this, VarType.FLOAT, lmapper.getF(0));
|
lubomir@281
|
461 |
break;
|
jaroslav@151
|
462 |
case opc_dload_0:
|
jaroslav@1509
|
463 |
smapper.assign(this, VarType.DOUBLE, lmapper.getD(0));
|
jaroslav@0
|
464 |
break;
|
jaroslav@151
|
465 |
case opc_aload_1:
|
jaroslav@1509
|
466 |
smapper.assign(this, VarType.REFERENCE, lmapper.getA(1));
|
lubomir@281
|
467 |
break;
|
jaroslav@151
|
468 |
case opc_iload_1:
|
jaroslav@1509
|
469 |
smapper.assign(this, VarType.INTEGER, lmapper.getI(1));
|
lubomir@281
|
470 |
break;
|
jaroslav@151
|
471 |
case opc_lload_1:
|
jaroslav@1509
|
472 |
smapper.assign(this, VarType.LONG, lmapper.getL(1));
|
lubomir@281
|
473 |
break;
|
jaroslav@151
|
474 |
case opc_fload_1:
|
jaroslav@1509
|
475 |
smapper.assign(this, VarType.FLOAT, lmapper.getF(1));
|
lubomir@281
|
476 |
break;
|
jaroslav@151
|
477 |
case opc_dload_1:
|
jaroslav@1509
|
478 |
smapper.assign(this, VarType.DOUBLE, lmapper.getD(1));
|
jaroslav@0
|
479 |
break;
|
jaroslav@151
|
480 |
case opc_aload_2:
|
jaroslav@1509
|
481 |
smapper.assign(this, VarType.REFERENCE, lmapper.getA(2));
|
lubomir@281
|
482 |
break;
|
jaroslav@151
|
483 |
case opc_iload_2:
|
jaroslav@1509
|
484 |
smapper.assign(this, VarType.INTEGER, lmapper.getI(2));
|
lubomir@281
|
485 |
break;
|
jaroslav@151
|
486 |
case opc_lload_2:
|
jaroslav@1509
|
487 |
smapper.assign(this, VarType.LONG, lmapper.getL(2));
|
lubomir@281
|
488 |
break;
|
jaroslav@151
|
489 |
case opc_fload_2:
|
jaroslav@1509
|
490 |
smapper.assign(this, VarType.FLOAT, lmapper.getF(2));
|
lubomir@281
|
491 |
break;
|
jaroslav@151
|
492 |
case opc_dload_2:
|
jaroslav@1509
|
493 |
smapper.assign(this, VarType.DOUBLE, lmapper.getD(2));
|
jaroslav@2
|
494 |
break;
|
jaroslav@151
|
495 |
case opc_aload_3:
|
jaroslav@1509
|
496 |
smapper.assign(this, VarType.REFERENCE, lmapper.getA(3));
|
lubomir@281
|
497 |
break;
|
jaroslav@151
|
498 |
case opc_iload_3:
|
jaroslav@1509
|
499 |
smapper.assign(this, VarType.INTEGER, lmapper.getI(3));
|
lubomir@281
|
500 |
break;
|
jaroslav@151
|
501 |
case opc_lload_3:
|
jaroslav@1509
|
502 |
smapper.assign(this, VarType.LONG, lmapper.getL(3));
|
lubomir@281
|
503 |
break;
|
jaroslav@151
|
504 |
case opc_fload_3:
|
jaroslav@1509
|
505 |
smapper.assign(this, VarType.FLOAT, lmapper.getF(3));
|
lubomir@281
|
506 |
break;
|
jaroslav@151
|
507 |
case opc_dload_3:
|
jaroslav@1509
|
508 |
smapper.assign(this, VarType.DOUBLE, lmapper.getD(3));
|
jaroslav@3
|
509 |
break;
|
lubomir@281
|
510 |
case opc_iload: {
|
lubomir@585
|
511 |
++i;
|
lubomir@585
|
512 |
final int indx = wide ? readUShort(byteCodes, i++)
|
lubomir@585
|
513 |
: readUByte(byteCodes, i);
|
lubomir@585
|
514 |
wide = false;
|
jaroslav@1509
|
515 |
smapper.assign(this, VarType.INTEGER, lmapper.getI(indx));
|
lubomir@281
|
516 |
break;
|
lubomir@281
|
517 |
}
|
lubomir@281
|
518 |
case opc_lload: {
|
lubomir@585
|
519 |
++i;
|
lubomir@585
|
520 |
final int indx = wide ? readUShort(byteCodes, i++)
|
lubomir@585
|
521 |
: readUByte(byteCodes, i);
|
lubomir@585
|
522 |
wide = false;
|
jaroslav@1509
|
523 |
smapper.assign(this, VarType.LONG, lmapper.getL(indx));
|
lubomir@281
|
524 |
break;
|
lubomir@281
|
525 |
}
|
lubomir@281
|
526 |
case opc_fload: {
|
lubomir@585
|
527 |
++i;
|
lubomir@585
|
528 |
final int indx = wide ? readUShort(byteCodes, i++)
|
lubomir@585
|
529 |
: readUByte(byteCodes, i);
|
lubomir@585
|
530 |
wide = false;
|
jaroslav@1509
|
531 |
smapper.assign(this, VarType.FLOAT, lmapper.getF(indx));
|
lubomir@281
|
532 |
break;
|
lubomir@281
|
533 |
}
|
lubomir@281
|
534 |
case opc_dload: {
|
lubomir@585
|
535 |
++i;
|
lubomir@585
|
536 |
final int indx = wide ? readUShort(byteCodes, i++)
|
lubomir@585
|
537 |
: readUByte(byteCodes, i);
|
lubomir@585
|
538 |
wide = false;
|
jaroslav@1509
|
539 |
smapper.assign(this, VarType.DOUBLE, lmapper.getD(indx));
|
lubomir@281
|
540 |
break;
|
lubomir@281
|
541 |
}
|
jaroslav@151
|
542 |
case opc_aload: {
|
lubomir@585
|
543 |
++i;
|
lubomir@585
|
544 |
final int indx = wide ? readUShort(byteCodes, i++)
|
lubomir@585
|
545 |
: readUByte(byteCodes, i);
|
lubomir@585
|
546 |
wide = false;
|
jaroslav@1509
|
547 |
smapper.assign(this, VarType.REFERENCE, lmapper.getA(indx));
|
jaroslav@3
|
548 |
break;
|
jaroslav@3
|
549 |
}
|
lubomir@281
|
550 |
case opc_istore: {
|
lubomir@585
|
551 |
++i;
|
lubomir@585
|
552 |
final int indx = wide ? readUShort(byteCodes, i++)
|
lubomir@585
|
553 |
: readUByte(byteCodes, i);
|
lubomir@585
|
554 |
wide = false;
|
jaroslav@1509
|
555 |
emit(smapper, this, "var @1 = @2;",
|
lubomir@474
|
556 |
lmapper.setI(indx), smapper.popI());
|
lubomir@281
|
557 |
break;
|
lubomir@281
|
558 |
}
|
lubomir@281
|
559 |
case opc_lstore: {
|
lubomir@585
|
560 |
++i;
|
lubomir@585
|
561 |
final int indx = wide ? readUShort(byteCodes, i++)
|
lubomir@585
|
562 |
: readUByte(byteCodes, i);
|
lubomir@585
|
563 |
wide = false;
|
jaroslav@1509
|
564 |
emit(smapper, this, "var @1 = @2;",
|
lubomir@474
|
565 |
lmapper.setL(indx), smapper.popL());
|
lubomir@281
|
566 |
break;
|
lubomir@281
|
567 |
}
|
lubomir@281
|
568 |
case opc_fstore: {
|
lubomir@585
|
569 |
++i;
|
lubomir@585
|
570 |
final int indx = wide ? readUShort(byteCodes, i++)
|
lubomir@585
|
571 |
: readUByte(byteCodes, i);
|
lubomir@585
|
572 |
wide = false;
|
jaroslav@1509
|
573 |
emit(smapper, this, "var @1 = @2;",
|
lubomir@474
|
574 |
lmapper.setF(indx), smapper.popF());
|
lubomir@281
|
575 |
break;
|
lubomir@281
|
576 |
}
|
lubomir@281
|
577 |
case opc_dstore: {
|
lubomir@585
|
578 |
++i;
|
lubomir@585
|
579 |
final int indx = wide ? readUShort(byteCodes, i++)
|
lubomir@585
|
580 |
: readUByte(byteCodes, i);
|
lubomir@585
|
581 |
wide = false;
|
jaroslav@1509
|
582 |
emit(smapper, this, "var @1 = @2;",
|
lubomir@474
|
583 |
lmapper.setD(indx), smapper.popD());
|
lubomir@281
|
584 |
break;
|
lubomir@281
|
585 |
}
|
jaroslav@151
|
586 |
case opc_astore: {
|
lubomir@585
|
587 |
++i;
|
lubomir@585
|
588 |
final int indx = wide ? readUShort(byteCodes, i++)
|
lubomir@585
|
589 |
: readUByte(byteCodes, i);
|
lubomir@585
|
590 |
wide = false;
|
jaroslav@1509
|
591 |
emit(smapper, this, "var @1 = @2;",
|
lubomir@474
|
592 |
lmapper.setA(indx), smapper.popA());
|
jaroslav@31
|
593 |
break;
|
jaroslav@31
|
594 |
}
|
jaroslav@151
|
595 |
case opc_astore_0:
|
jaroslav@1509
|
596 |
emit(smapper, this, "var @1 = @2;", lmapper.setA(0), smapper.popA());
|
lubomir@281
|
597 |
break;
|
jaroslav@151
|
598 |
case opc_istore_0:
|
jaroslav@1509
|
599 |
emit(smapper, this, "var @1 = @2;", lmapper.setI(0), smapper.popI());
|
lubomir@281
|
600 |
break;
|
jaroslav@151
|
601 |
case opc_lstore_0:
|
jaroslav@1509
|
602 |
emit(smapper, this, "var @1 = @2;", lmapper.setL(0), smapper.popL());
|
lubomir@281
|
603 |
break;
|
jaroslav@151
|
604 |
case opc_fstore_0:
|
jaroslav@1509
|
605 |
emit(smapper, this, "var @1 = @2;", lmapper.setF(0), smapper.popF());
|
lubomir@281
|
606 |
break;
|
jaroslav@151
|
607 |
case opc_dstore_0:
|
jaroslav@1509
|
608 |
emit(smapper, this, "var @1 = @2;", lmapper.setD(0), smapper.popD());
|
jaroslav@5
|
609 |
break;
|
jaroslav@151
|
610 |
case opc_astore_1:
|
jaroslav@1509
|
611 |
emit(smapper, this, "var @1 = @2;", lmapper.setA(1), smapper.popA());
|
lubomir@281
|
612 |
break;
|
jaroslav@151
|
613 |
case opc_istore_1:
|
jaroslav@1509
|
614 |
emit(smapper, this, "var @1 = @2;", lmapper.setI(1), smapper.popI());
|
lubomir@281
|
615 |
break;
|
jaroslav@151
|
616 |
case opc_lstore_1:
|
jaroslav@1509
|
617 |
emit(smapper, this, "var @1 = @2;", lmapper.setL(1), smapper.popL());
|
lubomir@281
|
618 |
break;
|
jaroslav@151
|
619 |
case opc_fstore_1:
|
jaroslav@1509
|
620 |
emit(smapper, this, "var @1 = @2;", lmapper.setF(1), smapper.popF());
|
lubomir@281
|
621 |
break;
|
jaroslav@151
|
622 |
case opc_dstore_1:
|
jaroslav@1509
|
623 |
emit(smapper, this, "var @1 = @2;", lmapper.setD(1), smapper.popD());
|
jaroslav@5
|
624 |
break;
|
jaroslav@151
|
625 |
case opc_astore_2:
|
jaroslav@1509
|
626 |
emit(smapper, this, "var @1 = @2;", lmapper.setA(2), smapper.popA());
|
lubomir@281
|
627 |
break;
|
jaroslav@151
|
628 |
case opc_istore_2:
|
jaroslav@1509
|
629 |
emit(smapper, this, "var @1 = @2;", lmapper.setI(2), smapper.popI());
|
lubomir@281
|
630 |
break;
|
jaroslav@151
|
631 |
case opc_lstore_2:
|
jaroslav@1509
|
632 |
emit(smapper, this, "var @1 = @2;", lmapper.setL(2), smapper.popL());
|
lubomir@281
|
633 |
break;
|
jaroslav@151
|
634 |
case opc_fstore_2:
|
jaroslav@1509
|
635 |
emit(smapper, this, "var @1 = @2;", lmapper.setF(2), smapper.popF());
|
lubomir@281
|
636 |
break;
|
jaroslav@151
|
637 |
case opc_dstore_2:
|
jaroslav@1509
|
638 |
emit(smapper, this, "var @1 = @2;", lmapper.setD(2), smapper.popD());
|
jaroslav@5
|
639 |
break;
|
jaroslav@151
|
640 |
case opc_astore_3:
|
jaroslav@1509
|
641 |
emit(smapper, this, "var @1 = @2;", lmapper.setA(3), smapper.popA());
|
lubomir@281
|
642 |
break;
|
jaroslav@151
|
643 |
case opc_istore_3:
|
jaroslav@1509
|
644 |
emit(smapper, this, "var @1 = @2;", lmapper.setI(3), smapper.popI());
|
lubomir@281
|
645 |
break;
|
jaroslav@151
|
646 |
case opc_lstore_3:
|
jaroslav@1509
|
647 |
emit(smapper, this, "var @1 = @2;", lmapper.setL(3), smapper.popL());
|
lubomir@281
|
648 |
break;
|
jaroslav@151
|
649 |
case opc_fstore_3:
|
jaroslav@1509
|
650 |
emit(smapper, this, "var @1 = @2;", lmapper.setF(3), smapper.popF());
|
lubomir@281
|
651 |
break;
|
jaroslav@151
|
652 |
case opc_dstore_3:
|
jaroslav@1509
|
653 |
emit(smapper, this, "var @1 = @2;", lmapper.setD(3), smapper.popD());
|
jaroslav@5
|
654 |
break;
|
jaroslav@151
|
655 |
case opc_iadd:
|
jaroslav@1509
|
656 |
smapper.replace(this, VarType.INTEGER, "(@1).add32(@2)", smapper.getI(1), smapper.popI());
|
lubomir@281
|
657 |
break;
|
jaroslav@151
|
658 |
case opc_ladd:
|
jaroslav@1509
|
659 |
smapper.replace(this, VarType.LONG, "(@1).add64(@2)", smapper.getL(1), smapper.popL());
|
lubomir@281
|
660 |
break;
|
jaroslav@151
|
661 |
case opc_fadd:
|
jaroslav@1509
|
662 |
smapper.replace(this, VarType.FLOAT, "(@1 + @2)", smapper.getF(1), smapper.popF());
|
lubomir@281
|
663 |
break;
|
jaroslav@151
|
664 |
case opc_dadd:
|
jaroslav@1509
|
665 |
smapper.replace(this, VarType.DOUBLE, "(@1 + @2)", smapper.getD(1), smapper.popD());
|
jaroslav@0
|
666 |
break;
|
jaroslav@151
|
667 |
case opc_isub:
|
jaroslav@1509
|
668 |
smapper.replace(this, VarType.INTEGER, "(@1).sub32(@2)", smapper.getI(1), smapper.popI());
|
lubomir@281
|
669 |
break;
|
jaroslav@151
|
670 |
case opc_lsub:
|
jaroslav@1509
|
671 |
smapper.replace(this, VarType.LONG, "(@1).sub64(@2)", smapper.getL(1), smapper.popL());
|
lubomir@281
|
672 |
break;
|
jaroslav@151
|
673 |
case opc_fsub:
|
jaroslav@1509
|
674 |
smapper.replace(this, VarType.FLOAT, "(@1 - @2)", smapper.getF(1), smapper.popF());
|
lubomir@281
|
675 |
break;
|
jaroslav@151
|
676 |
case opc_dsub:
|
jaroslav@1509
|
677 |
smapper.replace(this, VarType.DOUBLE, "(@1 - @2)", smapper.getD(1), smapper.popD());
|
jaroslav@2
|
678 |
break;
|
jaroslav@151
|
679 |
case opc_imul:
|
jaroslav@1509
|
680 |
smapper.replace(this, VarType.INTEGER, "(@1).mul32(@2)", smapper.getI(1), smapper.popI());
|
lubomir@281
|
681 |
break;
|
jaroslav@151
|
682 |
case opc_lmul:
|
jaroslav@1509
|
683 |
smapper.replace(this, VarType.LONG, "(@1).mul64(@2)", smapper.getL(1), smapper.popL());
|
lubomir@281
|
684 |
break;
|
jaroslav@151
|
685 |
case opc_fmul:
|
jaroslav@1509
|
686 |
smapper.replace(this, VarType.FLOAT, "(@1 * @2)", smapper.getF(1), smapper.popF());
|
lubomir@281
|
687 |
break;
|
jaroslav@151
|
688 |
case opc_dmul:
|
jaroslav@1509
|
689 |
smapper.replace(this, VarType.DOUBLE, "(@1 * @2)", smapper.getD(1), smapper.popD());
|
jaroslav@1
|
690 |
break;
|
jaroslav@151
|
691 |
case opc_idiv:
|
jaroslav@1509
|
692 |
smapper.replace(this, VarType.INTEGER, "(@1).div32(@2)",
|
lubomir@307
|
693 |
smapper.getI(1), smapper.popI());
|
lubomir@281
|
694 |
break;
|
jaroslav@151
|
695 |
case opc_ldiv:
|
jaroslav@1509
|
696 |
smapper.replace(this, VarType.LONG, "(@1).div64(@2)",
|
lubomir@307
|
697 |
smapper.getL(1), smapper.popL());
|
jaroslav@3
|
698 |
break;
|
jaroslav@151
|
699 |
case opc_fdiv:
|
jaroslav@1509
|
700 |
smapper.replace(this, VarType.FLOAT, "(@1 / @2)", smapper.getF(1), smapper.popF());
|
lubomir@281
|
701 |
break;
|
jaroslav@151
|
702 |
case opc_ddiv:
|
jaroslav@1509
|
703 |
smapper.replace(this, VarType.DOUBLE, "(@1 / @2)", smapper.getD(1), smapper.popD());
|
jaroslav@3
|
704 |
break;
|
jaroslav@178
|
705 |
case opc_irem:
|
jaroslav@1509
|
706 |
smapper.replace(this, VarType.INTEGER, "(@1).mod32(@2)",
|
lubomir@737
|
707 |
smapper.getI(1), smapper.popI());
|
lubomir@281
|
708 |
break;
|
jaroslav@178
|
709 |
case opc_lrem:
|
jaroslav@1509
|
710 |
smapper.replace(this, VarType.LONG, "(@1).mod64(@2)",
|
lubomir@676
|
711 |
smapper.getL(1), smapper.popL());
|
lubomir@281
|
712 |
break;
|
jaroslav@178
|
713 |
case opc_frem:
|
jaroslav@1509
|
714 |
smapper.replace(this, VarType.FLOAT, "(@1 % @2)", smapper.getF(1), smapper.popF());
|
lubomir@281
|
715 |
break;
|
jaroslav@178
|
716 |
case opc_drem:
|
jaroslav@1509
|
717 |
smapper.replace(this, VarType.DOUBLE, "(@1 % @2)", smapper.getD(1), smapper.popD());
|
jaroslav@178
|
718 |
break;
|
jaroslav@151
|
719 |
case opc_iand:
|
jaroslav@1509
|
720 |
smapper.replace(this, VarType.INTEGER, "(@1 & @2)", smapper.getI(1), smapper.popI());
|
lubomir@281
|
721 |
break;
|
jaroslav@151
|
722 |
case opc_land:
|
jaroslav@1509
|
723 |
smapper.replace(this, VarType.LONG, "(@1).and64(@2)", smapper.getL(1), smapper.popL());
|
jaroslav@7
|
724 |
break;
|
jaroslav@151
|
725 |
case opc_ior:
|
jaroslav@1509
|
726 |
smapper.replace(this, VarType.INTEGER, "(@1 | @2)", smapper.getI(1), smapper.popI());
|
lubomir@281
|
727 |
break;
|
jaroslav@151
|
728 |
case opc_lor:
|
jaroslav@1509
|
729 |
smapper.replace(this, VarType.LONG, "(@1).or64(@2)", smapper.getL(1), smapper.popL());
|
jaroslav@7
|
730 |
break;
|
jaroslav@151
|
731 |
case opc_ixor:
|
jaroslav@1509
|
732 |
smapper.replace(this, VarType.INTEGER, "(@1 ^ @2)", smapper.getI(1), smapper.popI());
|
lubomir@281
|
733 |
break;
|
jaroslav@151
|
734 |
case opc_lxor:
|
jaroslav@1509
|
735 |
smapper.replace(this, VarType.LONG, "(@1).xor64(@2)", smapper.getL(1), smapper.popL());
|
jaroslav@6
|
736 |
break;
|
jaroslav@151
|
737 |
case opc_ineg:
|
jaroslav@1509
|
738 |
smapper.replace(this, VarType.INTEGER, "(@1).neg32()", smapper.getI(0));
|
lubomir@281
|
739 |
break;
|
jaroslav@151
|
740 |
case opc_lneg:
|
jaroslav@1509
|
741 |
smapper.replace(this, VarType.LONG, "(@1).neg64()", smapper.getL(0));
|
lubomir@281
|
742 |
break;
|
jaroslav@151
|
743 |
case opc_fneg:
|
jaroslav@1509
|
744 |
smapper.replace(this, VarType.FLOAT, "(-@1)", smapper.getF(0));
|
lubomir@281
|
745 |
break;
|
jaroslav@151
|
746 |
case opc_dneg:
|
jaroslav@1509
|
747 |
smapper.replace(this, VarType.DOUBLE, "(-@1)", smapper.getD(0));
|
jaroslav@93
|
748 |
break;
|
jaroslav@151
|
749 |
case opc_ishl:
|
jaroslav@1509
|
750 |
smapper.replace(this, VarType.INTEGER, "(@1 << @2)", smapper.getI(1), smapper.popI());
|
lubomir@281
|
751 |
break;
|
jaroslav@151
|
752 |
case opc_lshl:
|
jaroslav@1509
|
753 |
smapper.replace(this, VarType.LONG, "(@1).shl64(@2)", smapper.getL(1), smapper.popI());
|
jaroslav@93
|
754 |
break;
|
jaroslav@151
|
755 |
case opc_ishr:
|
jaroslav@1509
|
756 |
smapper.replace(this, VarType.INTEGER, "(@1 >> @2)", smapper.getI(1), smapper.popI());
|
lubomir@281
|
757 |
break;
|
jaroslav@151
|
758 |
case opc_lshr:
|
jaroslav@1509
|
759 |
smapper.replace(this, VarType.LONG, "(@1).shr64(@2)", smapper.getL(1), smapper.popI());
|
jaroslav@93
|
760 |
break;
|
jaroslav@151
|
761 |
case opc_iushr:
|
jaroslav@1509
|
762 |
smapper.replace(this, VarType.INTEGER, "(@1 >>> @2)", smapper.getI(1), smapper.popI());
|
lubomir@281
|
763 |
break;
|
jaroslav@151
|
764 |
case opc_lushr:
|
jaroslav@1509
|
765 |
smapper.replace(this, VarType.LONG, "(@1).ushr64(@2)", smapper.getL(1), smapper.popI());
|
jaroslav@93
|
766 |
break;
|
jaroslav@151
|
767 |
case opc_iinc: {
|
lubomir@585
|
768 |
++i;
|
lubomir@585
|
769 |
final int varIndx = wide ? readUShort(byteCodes, i++)
|
lubomir@585
|
770 |
: readUByte(byteCodes, i);
|
lubomir@585
|
771 |
++i;
|
lubomir@697
|
772 |
final int incrBy = wide ? readShort(byteCodes, i++)
|
lubomir@585
|
773 |
: byteCodes[i];
|
lubomir@585
|
774 |
wide = false;
|
jaroslav@5
|
775 |
if (incrBy == 1) {
|
jaroslav@1509
|
776 |
emit(smapper, this, "@1++;", lmapper.getI(varIndx));
|
jaroslav@5
|
777 |
} else {
|
jaroslav@1509
|
778 |
emit(smapper, this, "@1 += @2;",
|
lubomir@307
|
779 |
lmapper.getI(varIndx),
|
lubomir@283
|
780 |
Integer.toString(incrBy));
|
jaroslav@5
|
781 |
}
|
jaroslav@5
|
782 |
break;
|
jaroslav@5
|
783 |
}
|
jaroslav@151
|
784 |
case opc_return:
|
jaroslav@1509
|
785 |
emit(smapper, this, "return;");
|
jaroslav@10
|
786 |
break;
|
jaroslav@151
|
787 |
case opc_ireturn:
|
jaroslav@1509
|
788 |
emit(smapper, this, "return @1;", smapper.popI());
|
lubomir@281
|
789 |
break;
|
jaroslav@151
|
790 |
case opc_lreturn:
|
jaroslav@1509
|
791 |
emit(smapper, this, "return @1;", smapper.popL());
|
lubomir@281
|
792 |
break;
|
jaroslav@151
|
793 |
case opc_freturn:
|
jaroslav@1509
|
794 |
emit(smapper, this, "return @1;", smapper.popF());
|
lubomir@281
|
795 |
break;
|
jaroslav@151
|
796 |
case opc_dreturn:
|
jaroslav@1509
|
797 |
emit(smapper, this, "return @1;", smapper.popD());
|
lubomir@281
|
798 |
break;
|
jaroslav@151
|
799 |
case opc_areturn:
|
jaroslav@1509
|
800 |
emit(smapper, this, "return @1;", smapper.popA());
|
jaroslav@1
|
801 |
break;
|
jaroslav@151
|
802 |
case opc_i2l:
|
jaroslav@1509
|
803 |
smapper.replace(this, VarType.LONG, "@1", smapper.getI(0));
|
lubomir@281
|
804 |
break;
|
jaroslav@151
|
805 |
case opc_i2f:
|
jaroslav@1509
|
806 |
smapper.replace(this, VarType.FLOAT, "@1", smapper.getI(0));
|
lubomir@281
|
807 |
break;
|
jaroslav@151
|
808 |
case opc_i2d:
|
jaroslav@1509
|
809 |
smapper.replace(this, VarType.DOUBLE, "@1", smapper.getI(0));
|
lubomir@281
|
810 |
break;
|
jaroslav@151
|
811 |
case opc_l2i:
|
jaroslav@1509
|
812 |
smapper.replace(this, VarType.INTEGER, "(@1).toInt32()", smapper.getL(0));
|
lubomir@281
|
813 |
break;
|
jaroslav@3
|
814 |
// max int check?
|
jaroslav@151
|
815 |
case opc_l2f:
|
jaroslav@1509
|
816 |
smapper.replace(this, VarType.FLOAT, "(@1).toFP()", smapper.getL(0));
|
jaroslav@272
|
817 |
break;
|
jaroslav@151
|
818 |
case opc_l2d:
|
jaroslav@1509
|
819 |
smapper.replace(this, VarType.DOUBLE, "(@1).toFP()", smapper.getL(0));
|
jaroslav@272
|
820 |
break;
|
jaroslav@151
|
821 |
case opc_f2d:
|
jaroslav@1509
|
822 |
smapper.replace(this, VarType.DOUBLE, "@1",
|
jaroslav@1457
|
823 |
smapper.getF(0));
|
lubomir@281
|
824 |
break;
|
jaroslav@151
|
825 |
case opc_d2f:
|
jaroslav@1509
|
826 |
smapper.replace(this, VarType.FLOAT, "@1",
|
jaroslav@1457
|
827 |
smapper.getD(0));
|
jaroslav@3
|
828 |
break;
|
jaroslav@151
|
829 |
case opc_f2i:
|
jaroslav@1509
|
830 |
smapper.replace(this, VarType.INTEGER, "(@1).toInt32()",
|
jaroslav@1457
|
831 |
smapper.getF(0));
|
lubomir@281
|
832 |
break;
|
jaroslav@151
|
833 |
case opc_f2l:
|
jaroslav@1509
|
834 |
smapper.replace(this, VarType.LONG, "(@1).toLong()",
|
jaroslav@1457
|
835 |
smapper.getF(0));
|
lubomir@281
|
836 |
break;
|
jaroslav@151
|
837 |
case opc_d2i:
|
jaroslav@1509
|
838 |
smapper.replace(this, VarType.INTEGER, "(@1).toInt32()",
|
jaroslav@1457
|
839 |
smapper.getD(0));
|
lubomir@281
|
840 |
break;
|
jaroslav@151
|
841 |
case opc_d2l:
|
jaroslav@1509
|
842 |
smapper.replace(this, VarType.LONG, "(@1).toLong()", smapper.getD(0));
|
jaroslav@3
|
843 |
break;
|
jaroslav@151
|
844 |
case opc_i2b:
|
jaroslav@1509
|
845 |
smapper.replace(this, VarType.INTEGER, "(@1).toInt8()", smapper.getI(0));
|
Martin@440
|
846 |
break;
|
jaroslav@151
|
847 |
case opc_i2c:
|
Martin@439
|
848 |
break;
|
jaroslav@151
|
849 |
case opc_i2s:
|
jaroslav@1509
|
850 |
smapper.replace(this, VarType.INTEGER, "(@1).toInt16()", smapper.getI(0));
|
jaroslav@2
|
851 |
break;
|
jaroslav@151
|
852 |
case opc_aconst_null:
|
jaroslav@1509
|
853 |
smapper.assign(this, VarType.REFERENCE, "null");
|
jaroslav@46
|
854 |
break;
|
jaroslav@151
|
855 |
case opc_iconst_m1:
|
jaroslav@1509
|
856 |
smapper.assign(this, VarType.INTEGER, "-1");
|
jaroslav@48
|
857 |
break;
|
jaroslav@151
|
858 |
case opc_iconst_0:
|
jaroslav@1509
|
859 |
smapper.assign(this, VarType.INTEGER, "0");
|
lubomir@281
|
860 |
break;
|
jaroslav@151
|
861 |
case opc_dconst_0:
|
jaroslav@1509
|
862 |
smapper.assign(this, VarType.DOUBLE, "0");
|
lubomir@281
|
863 |
break;
|
jaroslav@151
|
864 |
case opc_lconst_0:
|
jaroslav@1509
|
865 |
smapper.assign(this, VarType.LONG, "0");
|
lubomir@281
|
866 |
break;
|
jaroslav@151
|
867 |
case opc_fconst_0:
|
jaroslav@1509
|
868 |
smapper.assign(this, VarType.FLOAT, "0");
|
jaroslav@4
|
869 |
break;
|
jaroslav@151
|
870 |
case opc_iconst_1:
|
jaroslav@1509
|
871 |
smapper.assign(this, VarType.INTEGER, "1");
|
lubomir@281
|
872 |
break;
|
jaroslav@151
|
873 |
case opc_lconst_1:
|
jaroslav@1509
|
874 |
smapper.assign(this, VarType.LONG, "1");
|
lubomir@281
|
875 |
break;
|
jaroslav@151
|
876 |
case opc_fconst_1:
|
jaroslav@1509
|
877 |
smapper.assign(this, VarType.FLOAT, "1");
|
lubomir@281
|
878 |
break;
|
jaroslav@151
|
879 |
case opc_dconst_1:
|
jaroslav@1509
|
880 |
smapper.assign(this, VarType.DOUBLE, "1");
|
jaroslav@4
|
881 |
break;
|
jaroslav@151
|
882 |
case opc_iconst_2:
|
jaroslav@1509
|
883 |
smapper.assign(this, VarType.INTEGER, "2");
|
lubomir@281
|
884 |
break;
|
jaroslav@151
|
885 |
case opc_fconst_2:
|
jaroslav@1509
|
886 |
smapper.assign(this, VarType.FLOAT, "2");
|
jaroslav@4
|
887 |
break;
|
jaroslav@151
|
888 |
case opc_iconst_3:
|
jaroslav@1509
|
889 |
smapper.assign(this, VarType.INTEGER, "3");
|
jaroslav@4
|
890 |
break;
|
jaroslav@151
|
891 |
case opc_iconst_4:
|
jaroslav@1509
|
892 |
smapper.assign(this, VarType.INTEGER, "4");
|
jaroslav@4
|
893 |
break;
|
jaroslav@151
|
894 |
case opc_iconst_5:
|
jaroslav@1509
|
895 |
smapper.assign(this, VarType.INTEGER, "5");
|
jaroslav@4
|
896 |
break;
|
jaroslav@151
|
897 |
case opc_ldc: {
|
lubomir@585
|
898 |
int indx = readUByte(byteCodes, ++i);
|
jaroslav@151
|
899 |
String v = encodeConstant(indx);
|
lubomir@307
|
900 |
int type = VarType.fromConstantType(jc.getTag(indx));
|
jaroslav@1509
|
901 |
smapper.assign(this, type, v);
|
jaroslav@20
|
902 |
break;
|
jaroslav@20
|
903 |
}
|
jaroslav@151
|
904 |
case opc_ldc_w:
|
jaroslav@151
|
905 |
case opc_ldc2_w: {
|
jaroslav@864
|
906 |
int indx = readUShortArg(byteCodes, i);
|
jaroslav@8
|
907 |
i += 2;
|
jaroslav@151
|
908 |
String v = encodeConstant(indx);
|
lubomir@307
|
909 |
int type = VarType.fromConstantType(jc.getTag(indx));
|
Martin@582
|
910 |
if (type == VarType.LONG) {
|
Martin@582
|
911 |
final Long lv = new Long(v);
|
Martin@582
|
912 |
final int low = (int)(lv.longValue() & 0xFFFFFFFF);
|
Martin@582
|
913 |
final int hi = (int)(lv.longValue() >> 32);
|
jaroslav@1462
|
914 |
if (hi == 0) {
|
jaroslav@1509
|
915 |
smapper.assign(this, VarType.LONG, "0x" + Integer.toHexString(low));
|
jaroslav@1462
|
916 |
} else {
|
jaroslav@1509
|
917 |
smapper.assign(this, VarType.LONG,
|
jaroslav@1462
|
918 |
"0x" + Integer.toHexString(hi) + ".next32(0x" +
|
jaroslav@1462
|
919 |
Integer.toHexString(low) + ")"
|
jaroslav@1462
|
920 |
);
|
jaroslav@1462
|
921 |
}
|
Martin@582
|
922 |
} else {
|
jaroslav@1509
|
923 |
smapper.assign(this, type, v);
|
Martin@582
|
924 |
}
|
jaroslav@8
|
925 |
break;
|
jaroslav@8
|
926 |
}
|
jaroslav@151
|
927 |
case opc_lcmp:
|
jaroslav@1509
|
928 |
smapper.replace(this, VarType.INTEGER, "(@2).compare64(@1)", smapper.popL(), smapper.getL(0));
|
lubomir@281
|
929 |
break;
|
jaroslav@151
|
930 |
case opc_fcmpl:
|
jaroslav@151
|
931 |
case opc_fcmpg:
|
jaroslav@1509
|
932 |
smapper.replace(this, VarType.INTEGER, "(@2).compare(@1)", smapper.popF(), smapper.getF(0));
|
lubomir@281
|
933 |
break;
|
jaroslav@151
|
934 |
case opc_dcmpl:
|
lubomir@281
|
935 |
case opc_dcmpg:
|
jaroslav@1509
|
936 |
smapper.replace(this, VarType.INTEGER, "(@2).compare(@1)", smapper.popD(), smapper.getD(0));
|
jaroslav@20
|
937 |
break;
|
jaroslav@151
|
938 |
case opc_if_acmpeq:
|
jaroslav@1468
|
939 |
i = generateIf(smapper, byteCodes, i, smapper.popA(), smapper.popA(),
|
jaroslav@843
|
940 |
"===", topMostLabel);
|
jaroslav@104
|
941 |
break;
|
jaroslav@151
|
942 |
case opc_if_acmpne:
|
jaroslav@1468
|
943 |
i = generateIf(smapper, byteCodes, i, smapper.popA(), smapper.popA(),
|
jaroslav@843
|
944 |
"!==", topMostLabel);
|
jaroslav@104
|
945 |
break;
|
lubomir@283
|
946 |
case opc_if_icmpeq:
|
jaroslav@1468
|
947 |
i = generateIf(smapper, byteCodes, i, smapper.popI(), smapper.popI(),
|
jaroslav@843
|
948 |
"==", topMostLabel);
|
jaroslav@4
|
949 |
break;
|
jaroslav@151
|
950 |
case opc_ifeq: {
|
jaroslav@864
|
951 |
int indx = i + readShortArg(byteCodes, i);
|
jaroslav@1509
|
952 |
emitIf(smapper, this, "if ((@1) == 0) ",
|
jaroslav@843
|
953 |
smapper.popI(), i, indx, topMostLabel);
|
jaroslav@7
|
954 |
i += 2;
|
jaroslav@7
|
955 |
break;
|
jaroslav@7
|
956 |
}
|
jaroslav@151
|
957 |
case opc_ifne: {
|
jaroslav@864
|
958 |
int indx = i + readShortArg(byteCodes, i);
|
jaroslav@1509
|
959 |
emitIf(smapper, this, "if ((@1) != 0) ",
|
jaroslav@843
|
960 |
smapper.popI(), i, indx, topMostLabel);
|
jaroslav@20
|
961 |
i += 2;
|
jaroslav@20
|
962 |
break;
|
jaroslav@20
|
963 |
}
|
jaroslav@151
|
964 |
case opc_iflt: {
|
jaroslav@864
|
965 |
int indx = i + readShortArg(byteCodes, i);
|
jaroslav@1509
|
966 |
emitIf(smapper, this, "if ((@1) < 0) ",
|
jaroslav@843
|
967 |
smapper.popI(), i, indx, topMostLabel);
|
jaroslav@20
|
968 |
i += 2;
|
jaroslav@20
|
969 |
break;
|
jaroslav@20
|
970 |
}
|
jaroslav@151
|
971 |
case opc_ifle: {
|
jaroslav@864
|
972 |
int indx = i + readShortArg(byteCodes, i);
|
jaroslav@1509
|
973 |
emitIf(smapper, this, "if ((@1) <= 0) ",
|
jaroslav@843
|
974 |
smapper.popI(), i, indx, topMostLabel);
|
jaroslav@20
|
975 |
i += 2;
|
jaroslav@20
|
976 |
break;
|
jaroslav@20
|
977 |
}
|
jaroslav@151
|
978 |
case opc_ifgt: {
|
jaroslav@864
|
979 |
int indx = i + readShortArg(byteCodes, i);
|
jaroslav@1509
|
980 |
emitIf(smapper, this, "if ((@1) > 0) ",
|
jaroslav@843
|
981 |
smapper.popI(), i, indx, topMostLabel);
|
jaroslav@20
|
982 |
i += 2;
|
jaroslav@20
|
983 |
break;
|
jaroslav@20
|
984 |
}
|
jaroslav@151
|
985 |
case opc_ifge: {
|
jaroslav@864
|
986 |
int indx = i + readShortArg(byteCodes, i);
|
jaroslav@1509
|
987 |
emitIf(smapper, this, "if ((@1) >= 0) ",
|
jaroslav@843
|
988 |
smapper.popI(), i, indx, topMostLabel);
|
jaroslav@20
|
989 |
i += 2;
|
jaroslav@20
|
990 |
break;
|
jaroslav@20
|
991 |
}
|
jaroslav@151
|
992 |
case opc_ifnonnull: {
|
jaroslav@864
|
993 |
int indx = i + readShortArg(byteCodes, i);
|
jaroslav@1509
|
994 |
emitIf(smapper, this, "if ((@1) !== null) ",
|
jaroslav@843
|
995 |
smapper.popA(), i, indx, topMostLabel);
|
jaroslav@16
|
996 |
i += 2;
|
jaroslav@16
|
997 |
break;
|
jaroslav@16
|
998 |
}
|
jaroslav@151
|
999 |
case opc_ifnull: {
|
jaroslav@864
|
1000 |
int indx = i + readShortArg(byteCodes, i);
|
jaroslav@1509
|
1001 |
emitIf(smapper, this, "if ((@1) === null) ",
|
jaroslav@843
|
1002 |
smapper.popA(), i, indx, topMostLabel);
|
jaroslav@16
|
1003 |
i += 2;
|
jaroslav@16
|
1004 |
break;
|
jaroslav@16
|
1005 |
}
|
jaroslav@151
|
1006 |
case opc_if_icmpne:
|
jaroslav@1468
|
1007 |
i = generateIf(smapper, byteCodes, i, smapper.popI(), smapper.popI(),
|
jaroslav@843
|
1008 |
"!=", topMostLabel);
|
jaroslav@4
|
1009 |
break;
|
jaroslav@151
|
1010 |
case opc_if_icmplt:
|
jaroslav@1468
|
1011 |
i = generateIf(smapper, byteCodes, i, smapper.popI(), smapper.popI(),
|
jaroslav@843
|
1012 |
"<", topMostLabel);
|
jaroslav@4
|
1013 |
break;
|
jaroslav@151
|
1014 |
case opc_if_icmple:
|
jaroslav@1468
|
1015 |
i = generateIf(smapper, byteCodes, i, smapper.popI(), smapper.popI(),
|
jaroslav@843
|
1016 |
"<=", topMostLabel);
|
jaroslav@4
|
1017 |
break;
|
jaroslav@151
|
1018 |
case opc_if_icmpgt:
|
jaroslav@1468
|
1019 |
i = generateIf(smapper, byteCodes, i, smapper.popI(), smapper.popI(),
|
jaroslav@843
|
1020 |
">", topMostLabel);
|
jaroslav@4
|
1021 |
break;
|
jaroslav@151
|
1022 |
case opc_if_icmpge:
|
jaroslav@1468
|
1023 |
i = generateIf(smapper, byteCodes, i, smapper.popI(), smapper.popI(),
|
jaroslav@843
|
1024 |
">=", topMostLabel);
|
jaroslav@4
|
1025 |
break;
|
jaroslav@151
|
1026 |
case opc_goto: {
|
jaroslav@1509
|
1027 |
smapper.flush(this);
|
jaroslav@864
|
1028 |
int indx = i + readShortArg(byteCodes, i);
|
jaroslav@1509
|
1029 |
goTo(this, i, indx, topMostLabel);
|
jaroslav@5
|
1030 |
i += 2;
|
jaroslav@5
|
1031 |
break;
|
jaroslav@5
|
1032 |
}
|
jaroslav@151
|
1033 |
case opc_lookupswitch: {
|
jaroslav@843
|
1034 |
i = generateLookupSwitch(i, byteCodes, smapper, topMostLabel);
|
jaroslav@115
|
1035 |
break;
|
jaroslav@115
|
1036 |
}
|
jaroslav@151
|
1037 |
case opc_tableswitch: {
|
jaroslav@843
|
1038 |
i = generateTableSwitch(i, byteCodes, smapper, topMostLabel);
|
jaroslav@115
|
1039 |
break;
|
jaroslav@115
|
1040 |
}
|
jaroslav@151
|
1041 |
case opc_invokeinterface: {
|
lubomir@307
|
1042 |
i = invokeVirtualMethod(byteCodes, i, smapper) + 2;
|
jaroslav@46
|
1043 |
break;
|
jaroslav@46
|
1044 |
}
|
jaroslav@151
|
1045 |
case opc_invokevirtual:
|
lubomir@307
|
1046 |
i = invokeVirtualMethod(byteCodes, i, smapper);
|
jaroslav@12
|
1047 |
break;
|
jaroslav@151
|
1048 |
case opc_invokespecial:
|
lubomir@307
|
1049 |
i = invokeStaticMethod(byteCodes, i, smapper, false);
|
jaroslav@4
|
1050 |
break;
|
jaroslav@151
|
1051 |
case opc_invokestatic:
|
lubomir@307
|
1052 |
i = invokeStaticMethod(byteCodes, i, smapper, true);
|
jaroslav@10
|
1053 |
break;
|
jaroslav@151
|
1054 |
case opc_new: {
|
jaroslav@864
|
1055 |
int indx = readUShortArg(byteCodes, i);
|
jaroslav@151
|
1056 |
String ci = jc.getClassName(indx);
|
jaroslav@1509
|
1057 |
emit(smapper, this, "var @1 = new @2;",
|
jaroslav@1409
|
1058 |
smapper.pushA(), accessClass(mangleClassName(ci)));
|
jaroslav@151
|
1059 |
addReference(ci);
|
jaroslav@8
|
1060 |
i += 2;
|
jaroslav@8
|
1061 |
break;
|
jaroslav@8
|
1062 |
}
|
lubomir@283
|
1063 |
case opc_newarray:
|
lubomir@585
|
1064 |
int atype = readUByte(byteCodes, ++i);
|
jaroslav@842
|
1065 |
generateNewArray(atype, smapper);
|
jaroslav@21
|
1066 |
break;
|
jaroslav@448
|
1067 |
case opc_anewarray: {
|
jaroslav@864
|
1068 |
int type = readUShortArg(byteCodes, i);
|
jaroslav@448
|
1069 |
i += 2;
|
jaroslav@842
|
1070 |
generateANewArray(type, smapper);
|
jaroslav@21
|
1071 |
break;
|
jaroslav@448
|
1072 |
}
|
jaroslav@151
|
1073 |
case opc_multianewarray: {
|
jaroslav@864
|
1074 |
int type = readUShortArg(byteCodes, i);
|
jtulach@128
|
1075 |
i += 2;
|
jaroslav@842
|
1076 |
i = generateMultiANewArray(type, byteCodes, i, smapper);
|
jtulach@128
|
1077 |
break;
|
jtulach@128
|
1078 |
}
|
jaroslav@151
|
1079 |
case opc_arraylength:
|
jaroslav@1509
|
1080 |
smapper.replace(this, VarType.INTEGER, "(@1).length", smapper.getA(0));
|
jaroslav@272
|
1081 |
break;
|
lubomir@283
|
1082 |
case opc_lastore:
|
jaroslav@1509
|
1083 |
emit(smapper, this, "Array.at(@3, @2, @1);",
|
lubomir@307
|
1084 |
smapper.popL(), smapper.popI(), smapper.popA());
|
lubomir@281
|
1085 |
break;
|
lubomir@283
|
1086 |
case opc_fastore:
|
jaroslav@1509
|
1087 |
emit(smapper, this, "Array.at(@3, @2, @1);",
|
lubomir@307
|
1088 |
smapper.popF(), smapper.popI(), smapper.popA());
|
lubomir@281
|
1089 |
break;
|
lubomir@283
|
1090 |
case opc_dastore:
|
jaroslav@1509
|
1091 |
emit(smapper, this, "Array.at(@3, @2, @1);",
|
lubomir@307
|
1092 |
smapper.popD(), smapper.popI(), smapper.popA());
|
lubomir@281
|
1093 |
break;
|
lubomir@283
|
1094 |
case opc_aastore:
|
jaroslav@1509
|
1095 |
emit(smapper, this, "Array.at(@3, @2, @1);",
|
lubomir@307
|
1096 |
smapper.popA(), smapper.popI(), smapper.popA());
|
jaroslav@21
|
1097 |
break;
|
jaroslav@151
|
1098 |
case opc_iastore:
|
jaroslav@151
|
1099 |
case opc_bastore:
|
jaroslav@151
|
1100 |
case opc_castore:
|
lubomir@283
|
1101 |
case opc_sastore:
|
jaroslav@1509
|
1102 |
emit(smapper, this, "Array.at(@3, @2, @1);",
|
lubomir@307
|
1103 |
smapper.popI(), smapper.popI(), smapper.popA());
|
jaroslav@240
|
1104 |
break;
|
lubomir@283
|
1105 |
case opc_laload:
|
jaroslav@1509
|
1106 |
smapper.replace(this, VarType.LONG, "Array.at(@2, @1)",
|
jaroslav@1477
|
1107 |
smapper.popI(), smapper.getA(0));
|
lubomir@281
|
1108 |
break;
|
lubomir@283
|
1109 |
case opc_faload:
|
jaroslav@1509
|
1110 |
smapper.replace(this, VarType.FLOAT, "Array.at(@2, @1)",
|
jaroslav@1477
|
1111 |
smapper.popI(), smapper.getA(0));
|
lubomir@281
|
1112 |
break;
|
lubomir@283
|
1113 |
case opc_daload:
|
jaroslav@1509
|
1114 |
smapper.replace(this, VarType.DOUBLE, "Array.at(@2, @1)",
|
jaroslav@1477
|
1115 |
smapper.popI(), smapper.getA(0));
|
lubomir@281
|
1116 |
break;
|
lubomir@283
|
1117 |
case opc_aaload:
|
jaroslav@1509
|
1118 |
smapper.replace(this, VarType.REFERENCE, "Array.at(@2, @1)",
|
jaroslav@1477
|
1119 |
smapper.popI(), smapper.getA(0));
|
jaroslav@272
|
1120 |
break;
|
jaroslav@272
|
1121 |
case opc_iaload:
|
jaroslav@272
|
1122 |
case opc_baload:
|
jaroslav@272
|
1123 |
case opc_caload:
|
lubomir@283
|
1124 |
case opc_saload:
|
jaroslav@1509
|
1125 |
smapper.replace(this, VarType.INTEGER, "Array.at(@2, @1)",
|
jaroslav@1477
|
1126 |
smapper.popI(), smapper.getA(0));
|
jaroslav@272
|
1127 |
break;
|
lubomir@221
|
1128 |
case opc_pop:
|
jaroslav@272
|
1129 |
case opc_pop2:
|
lubomir@307
|
1130 |
smapper.pop(1);
|
jaroslav@399
|
1131 |
debug("/* pop */");
|
jaroslav@272
|
1132 |
break;
|
lubomir@281
|
1133 |
case opc_dup: {
|
lubomir@307
|
1134 |
final Variable v = smapper.get(0);
|
jaroslav@1543
|
1135 |
if (smapper.isDirty()) {
|
jaroslav@1543
|
1136 |
emit(smapper, this, "var @1 = @2;", smapper.pushT(v.getType()), v);
|
jaroslav@1543
|
1137 |
} else {
|
jaroslav@1543
|
1138 |
smapper.assign(this, v.getType(), v);
|
jaroslav@1543
|
1139 |
}
|
jaroslav@21
|
1140 |
break;
|
jaroslav@21
|
1141 |
}
|
lubomir@281
|
1142 |
case opc_dup2: {
|
lubomir@585
|
1143 |
final Variable vi1 = smapper.get(0);
|
lubomir@585
|
1144 |
|
lubomir@585
|
1145 |
if (vi1.isCategory2()) {
|
jaroslav@1509
|
1146 |
emit(smapper, this, "var @1 = @2;",
|
lubomir@585
|
1147 |
smapper.pushT(vi1.getType()), vi1);
|
lubomir@281
|
1148 |
} else {
|
lubomir@585
|
1149 |
final Variable vi2 = smapper.get(1);
|
jaroslav@1509
|
1150 |
emit(smapper, this, "var @1 = @2, @3 = @4;",
|
lubomir@585
|
1151 |
smapper.pushT(vi2.getType()), vi2,
|
lubomir@585
|
1152 |
smapper.pushT(vi1.getType()), vi1);
|
lubomir@281
|
1153 |
}
|
jaroslav@21
|
1154 |
break;
|
jaroslav@21
|
1155 |
}
|
lubomir@281
|
1156 |
case opc_dup_x1: {
|
jaroslav@1509
|
1157 |
final Variable vi1 = smapper.pop(this);
|
jaroslav@1509
|
1158 |
final Variable vi2 = smapper.pop(this);
|
lubomir@307
|
1159 |
final Variable vo3 = smapper.pushT(vi1.getType());
|
lubomir@307
|
1160 |
final Variable vo2 = smapper.pushT(vi2.getType());
|
lubomir@307
|
1161 |
final Variable vo1 = smapper.pushT(vi1.getType());
|
lubomir@281
|
1162 |
|
jaroslav@1509
|
1163 |
emit(smapper, this, "var @1 = @2, @3 = @4, @5 = @6;",
|
lubomir@283
|
1164 |
vo1, vi1, vo2, vi2, vo3, vo1);
|
jaroslav@93
|
1165 |
break;
|
lubomir@281
|
1166 |
}
|
lubomir@585
|
1167 |
case opc_dup2_x1: {
|
jaroslav@1509
|
1168 |
final Variable vi1 = smapper.pop(this);
|
jaroslav@1509
|
1169 |
final Variable vi2 = smapper.pop(this);
|
lubomir@585
|
1170 |
|
lubomir@585
|
1171 |
if (vi1.isCategory2()) {
|
lubomir@307
|
1172 |
final Variable vo3 = smapper.pushT(vi1.getType());
|
lubomir@307
|
1173 |
final Variable vo2 = smapper.pushT(vi2.getType());
|
lubomir@307
|
1174 |
final Variable vo1 = smapper.pushT(vi1.getType());
|
lubomir@281
|
1175 |
|
jaroslav@1509
|
1176 |
emit(smapper, this, "var @1 = @2, @3 = @4, @5 = @6;",
|
lubomir@283
|
1177 |
vo1, vi1, vo2, vi2, vo3, vo1);
|
lubomir@281
|
1178 |
} else {
|
jaroslav@1509
|
1179 |
final Variable vi3 = smapper.pop(this);
|
lubomir@585
|
1180 |
final Variable vo5 = smapper.pushT(vi2.getType());
|
lubomir@585
|
1181 |
final Variable vo4 = smapper.pushT(vi1.getType());
|
lubomir@585
|
1182 |
final Variable vo3 = smapper.pushT(vi3.getType());
|
lubomir@585
|
1183 |
final Variable vo2 = smapper.pushT(vi2.getType());
|
lubomir@585
|
1184 |
final Variable vo1 = smapper.pushT(vi1.getType());
|
lubomir@585
|
1185 |
|
jaroslav@1509
|
1186 |
emit(smapper, this, "var @1 = @2, @3 = @4, @5 = @6,",
|
lubomir@585
|
1187 |
vo1, vi1, vo2, vi2, vo3, vi3);
|
jaroslav@1509
|
1188 |
emit(smapper, this, " @1 = @2, @3 = @4;",
|
lubomir@585
|
1189 |
vo4, vo1, vo5, vo2);
|
lubomir@585
|
1190 |
}
|
lubomir@585
|
1191 |
break;
|
lubomir@585
|
1192 |
}
|
lubomir@585
|
1193 |
case opc_dup_x2: {
|
jaroslav@1509
|
1194 |
final Variable vi1 = smapper.pop(this);
|
jaroslav@1509
|
1195 |
final Variable vi2 = smapper.pop(this);
|
lubomir@585
|
1196 |
|
lubomir@585
|
1197 |
if (vi2.isCategory2()) {
|
lubomir@585
|
1198 |
final Variable vo3 = smapper.pushT(vi1.getType());
|
lubomir@585
|
1199 |
final Variable vo2 = smapper.pushT(vi2.getType());
|
lubomir@585
|
1200 |
final Variable vo1 = smapper.pushT(vi1.getType());
|
lubomir@585
|
1201 |
|
jaroslav@1509
|
1202 |
emit(smapper, this, "var @1 = @2, @3 = @4, @5 = @6;",
|
lubomir@585
|
1203 |
vo1, vi1, vo2, vi2, vo3, vo1);
|
lubomir@585
|
1204 |
} else {
|
jaroslav@1509
|
1205 |
final Variable vi3 = smapper.pop(this);
|
lubomir@307
|
1206 |
final Variable vo4 = smapper.pushT(vi1.getType());
|
lubomir@307
|
1207 |
final Variable vo3 = smapper.pushT(vi3.getType());
|
lubomir@307
|
1208 |
final Variable vo2 = smapper.pushT(vi2.getType());
|
lubomir@307
|
1209 |
final Variable vo1 = smapper.pushT(vi1.getType());
|
lubomir@281
|
1210 |
|
jaroslav@1509
|
1211 |
emit(smapper, this, "var @1 = @2, @3 = @4, @5 = @6, @7 = @8;",
|
lubomir@283
|
1212 |
vo1, vi1, vo2, vi2, vo3, vi3, vo4, vo1);
|
lubomir@281
|
1213 |
}
|
jaroslav@8
|
1214 |
break;
|
lubomir@281
|
1215 |
}
|
lubomir@585
|
1216 |
case opc_dup2_x2: {
|
jaroslav@1509
|
1217 |
final Variable vi1 = smapper.pop(this);
|
jaroslav@1509
|
1218 |
final Variable vi2 = smapper.pop(this);
|
lubomir@585
|
1219 |
|
lubomir@585
|
1220 |
if (vi1.isCategory2()) {
|
lubomir@585
|
1221 |
if (vi2.isCategory2()) {
|
lubomir@585
|
1222 |
final Variable vo3 = smapper.pushT(vi1.getType());
|
lubomir@585
|
1223 |
final Variable vo2 = smapper.pushT(vi2.getType());
|
lubomir@585
|
1224 |
final Variable vo1 = smapper.pushT(vi1.getType());
|
lubomir@585
|
1225 |
|
jaroslav@1509
|
1226 |
emit(smapper, this, "var @1 = @2, @3 = @4, @5 = @6;",
|
lubomir@585
|
1227 |
vo1, vi1, vo2, vi2, vo3, vo1);
|
lubomir@585
|
1228 |
} else {
|
jaroslav@1509
|
1229 |
final Variable vi3 = smapper.pop(this);
|
lubomir@585
|
1230 |
final Variable vo4 = smapper.pushT(vi1.getType());
|
lubomir@585
|
1231 |
final Variable vo3 = smapper.pushT(vi3.getType());
|
lubomir@585
|
1232 |
final Variable vo2 = smapper.pushT(vi2.getType());
|
lubomir@585
|
1233 |
final Variable vo1 = smapper.pushT(vi1.getType());
|
lubomir@585
|
1234 |
|
jaroslav@1509
|
1235 |
emit(smapper, this, "var @1 = @2, @3 = @4, @5 = @6, @7 = @8;",
|
lubomir@585
|
1236 |
vo1, vi1, vo2, vi2, vo3, vi3, vo4, vo1);
|
lubomir@585
|
1237 |
}
|
lubomir@585
|
1238 |
} else {
|
jaroslav@1509
|
1239 |
final Variable vi3 = smapper.pop(this);
|
lubomir@585
|
1240 |
|
lubomir@585
|
1241 |
if (vi3.isCategory2()) {
|
lubomir@585
|
1242 |
final Variable vo5 = smapper.pushT(vi2.getType());
|
lubomir@585
|
1243 |
final Variable vo4 = smapper.pushT(vi1.getType());
|
lubomir@585
|
1244 |
final Variable vo3 = smapper.pushT(vi3.getType());
|
lubomir@585
|
1245 |
final Variable vo2 = smapper.pushT(vi2.getType());
|
lubomir@585
|
1246 |
final Variable vo1 = smapper.pushT(vi1.getType());
|
lubomir@585
|
1247 |
|
jaroslav@1509
|
1248 |
emit(smapper, this, "var @1 = @2, @3 = @4, @5 = @6,",
|
lubomir@585
|
1249 |
vo1, vi1, vo2, vi2, vo3, vi3);
|
jaroslav@1509
|
1250 |
emit(smapper, this, " @1 = @2, @3 = @4;",
|
lubomir@585
|
1251 |
vo4, vo1, vo5, vo2);
|
lubomir@585
|
1252 |
} else {
|
jaroslav@1509
|
1253 |
final Variable vi4 = smapper.pop(this);
|
lubomir@585
|
1254 |
final Variable vo6 = smapper.pushT(vi2.getType());
|
lubomir@585
|
1255 |
final Variable vo5 = smapper.pushT(vi1.getType());
|
lubomir@585
|
1256 |
final Variable vo4 = smapper.pushT(vi4.getType());
|
lubomir@585
|
1257 |
final Variable vo3 = smapper.pushT(vi3.getType());
|
lubomir@585
|
1258 |
final Variable vo2 = smapper.pushT(vi2.getType());
|
lubomir@585
|
1259 |
final Variable vo1 = smapper.pushT(vi1.getType());
|
lubomir@585
|
1260 |
|
jaroslav@1509
|
1261 |
emit(smapper, this, "var @1 = @2, @3 = @4, @5 = @6, @7 = @8,",
|
lubomir@585
|
1262 |
vo1, vi1, vo2, vi2, vo3, vi3, vo4, vi4);
|
jaroslav@1509
|
1263 |
emit(smapper, this, " @1 = @2, @3 = @4;",
|
lubomir@585
|
1264 |
vo5, vo1, vo6, vo2);
|
lubomir@585
|
1265 |
}
|
lubomir@585
|
1266 |
}
|
lubomir@585
|
1267 |
break;
|
lubomir@585
|
1268 |
}
|
lubomir@585
|
1269 |
case opc_swap: {
|
lubomir@585
|
1270 |
final Variable vi1 = smapper.get(0);
|
lubomir@585
|
1271 |
final Variable vi2 = smapper.get(1);
|
lubomir@585
|
1272 |
|
lubomir@585
|
1273 |
if (vi1.getType() == vi2.getType()) {
|
lubomir@585
|
1274 |
final Variable tmp = smapper.pushT(vi1.getType());
|
lubomir@585
|
1275 |
|
jaroslav@1509
|
1276 |
emit(smapper, this, "var @1 = @2, @2 = @3, @3 = @1;",
|
lubomir@585
|
1277 |
tmp, vi1, vi2);
|
lubomir@585
|
1278 |
smapper.pop(1);
|
lubomir@585
|
1279 |
} else {
|
lubomir@585
|
1280 |
smapper.pop(2);
|
lubomir@585
|
1281 |
smapper.pushT(vi1.getType());
|
lubomir@585
|
1282 |
smapper.pushT(vi2.getType());
|
lubomir@585
|
1283 |
}
|
lubomir@585
|
1284 |
break;
|
lubomir@585
|
1285 |
}
|
jaroslav@151
|
1286 |
case opc_bipush:
|
jaroslav@1509
|
1287 |
smapper.assign(this, VarType.INTEGER,
|
jaroslav@1462
|
1288 |
"(" + Integer.toString(byteCodes[++i]) + ")");
|
jaroslav@8
|
1289 |
break;
|
jaroslav@151
|
1290 |
case opc_sipush:
|
jaroslav@1509
|
1291 |
smapper.assign(this, VarType.INTEGER,
|
jaroslav@1462
|
1292 |
"(" + Integer.toString(readShortArg(byteCodes, i)) + ")"
|
jaroslav@1462
|
1293 |
);
|
jaroslav@31
|
1294 |
i += 2;
|
jaroslav@31
|
1295 |
break;
|
jaroslav@151
|
1296 |
case opc_getfield: {
|
jaroslav@864
|
1297 |
int indx = readUShortArg(byteCodes, i);
|
jaroslav@151
|
1298 |
String[] fi = jc.getFieldInfoName(indx);
|
lubomir@307
|
1299 |
final int type = VarType.fromFieldType(fi[2].charAt(0));
|
jaroslav@1409
|
1300 |
final String mangleClass = mangleClassName(fi[0]);
|
jaroslav@592
|
1301 |
final String mangleClassAccess = accessClass(mangleClass);
|
jaroslav@1513
|
1302 |
smapper.replace(this, type, "@2.call(@1)",
|
jaroslav@1477
|
1303 |
smapper.getA(0),
|
lubomir@1085
|
1304 |
accessField(mangleClassAccess + "(false)",
|
jaroslav@1513
|
1305 |
"_" + fi[1], fi)
|
jaroslav@592
|
1306 |
);
|
jaroslav@592
|
1307 |
i += 2;
|
jaroslav@592
|
1308 |
break;
|
jaroslav@592
|
1309 |
}
|
jaroslav@592
|
1310 |
case opc_putfield: {
|
jaroslav@864
|
1311 |
int indx = readUShortArg(byteCodes, i);
|
jaroslav@592
|
1312 |
String[] fi = jc.getFieldInfoName(indx);
|
jaroslav@592
|
1313 |
final int type = VarType.fromFieldType(fi[2].charAt(0));
|
jaroslav@1409
|
1314 |
final String mangleClass = mangleClassName(fi[0]);
|
jaroslav@592
|
1315 |
final String mangleClassAccess = accessClass(mangleClass);
|
jaroslav@1513
|
1316 |
emit(smapper, this, "@3.call(@2, @1);",
|
jaroslav@592
|
1317 |
smapper.popT(type),
|
lubomir@1084
|
1318 |
smapper.popA(),
|
lubomir@1085
|
1319 |
accessField(mangleClassAccess + "(false)",
|
lubomir@1085
|
1320 |
"_" + fi[1], fi));
|
jaroslav@8
|
1321 |
i += 2;
|
jaroslav@8
|
1322 |
break;
|
jaroslav@8
|
1323 |
}
|
jaroslav@151
|
1324 |
case opc_getstatic: {
|
jaroslav@864
|
1325 |
int indx = readUShortArg(byteCodes, i);
|
jaroslav@151
|
1326 |
String[] fi = jc.getFieldInfoName(indx);
|
lubomir@307
|
1327 |
final int type = VarType.fromFieldType(fi[2].charAt(0));
|
jaroslav@1477
|
1328 |
String ac = accessClass(mangleClassName(fi[0]));
|
jaroslav@1558
|
1329 |
String af = accessField(ac + "(false)", "_" + fi[1], fi);
|
jaroslav@1558
|
1330 |
smapper.assign(this, type, af + "()");
|
jaroslav@9
|
1331 |
i += 2;
|
jaroslav@151
|
1332 |
addReference(fi[0]);
|
jaroslav@9
|
1333 |
break;
|
jaroslav@9
|
1334 |
}
|
lubomir@281
|
1335 |
case opc_putstatic: {
|
jaroslav@864
|
1336 |
int indx = readUShortArg(byteCodes, i);
|
lubomir@281
|
1337 |
String[] fi = jc.getFieldInfoName(indx);
|
lubomir@307
|
1338 |
final int type = VarType.fromFieldType(fi[2].charAt(0));
|
jaroslav@1509
|
1339 |
emit(smapper, this, "@1(false)._@2(@3);",
|
jaroslav@1409
|
1340 |
accessClass(mangleClassName(fi[0])), fi[1],
|
lubomir@317
|
1341 |
smapper.popT(type));
|
lubomir@281
|
1342 |
i += 2;
|
lubomir@281
|
1343 |
addReference(fi[0]);
|
lubomir@281
|
1344 |
break;
|
lubomir@281
|
1345 |
}
|
jaroslav@151
|
1346 |
case opc_checkcast: {
|
jaroslav@864
|
1347 |
int indx = readUShortArg(byteCodes, i);
|
jaroslav@842
|
1348 |
generateCheckcast(indx, smapper);
|
jaroslav@30
|
1349 |
i += 2;
|
jaroslav@30
|
1350 |
break;
|
jaroslav@30
|
1351 |
}
|
jaroslav@151
|
1352 |
case opc_instanceof: {
|
jaroslav@864
|
1353 |
int indx = readUShortArg(byteCodes, i);
|
jaroslav@842
|
1354 |
generateInstanceOf(indx, smapper);
|
jaroslav@17
|
1355 |
i += 2;
|
jaroslav@30
|
1356 |
break;
|
jaroslav@17
|
1357 |
}
|
jaroslav@151
|
1358 |
case opc_athrow: {
|
jaroslav@1457
|
1359 |
final CharSequence v = smapper.popA();
|
lubomir@307
|
1360 |
smapper.clear();
|
lubomir@281
|
1361 |
|
jaroslav@1509
|
1362 |
emit(smapper, this, "{ var @1 = @2; throw @2; }",
|
lubomir@307
|
1363 |
smapper.pushA(), v);
|
jaroslav@104
|
1364 |
break;
|
jaroslav@104
|
1365 |
}
|
lubomir@221
|
1366 |
|
lubomir@221
|
1367 |
case opc_monitorenter: {
|
jaroslav@1477
|
1368 |
debug("/* monitor enter */");
|
lubomir@307
|
1369 |
smapper.popA();
|
lubomir@221
|
1370 |
break;
|
lubomir@221
|
1371 |
}
|
lubomir@221
|
1372 |
|
lubomir@221
|
1373 |
case opc_monitorexit: {
|
jaroslav@1477
|
1374 |
debug("/* monitor exit */");
|
lubomir@307
|
1375 |
smapper.popA();
|
lubomir@221
|
1376 |
break;
|
lubomir@221
|
1377 |
}
|
lubomir@221
|
1378 |
|
lubomir@585
|
1379 |
case opc_wide:
|
lubomir@585
|
1380 |
wide = true;
|
lubomir@585
|
1381 |
break;
|
lubomir@585
|
1382 |
|
jaroslav@104
|
1383 |
default: {
|
lubomir@585
|
1384 |
wide = false;
|
jaroslav@1509
|
1385 |
emit(smapper, this, "throw 'unknown bytecode @1';",
|
lubomir@283
|
1386 |
Integer.toString(c));
|
jaroslav@104
|
1387 |
}
|
jaroslav@0
|
1388 |
}
|
jaroslav@399
|
1389 |
if (debug(" //")) {
|
jaroslav@842
|
1390 |
generateByteCodeComment(prev, i, byteCodes);
|
jaroslav@0
|
1391 |
}
|
jaroslav@1510
|
1392 |
if (outChanged) {
|
jaroslav@1510
|
1393 |
append("\n");
|
jaroslav@1510
|
1394 |
}
|
jaroslav@0
|
1395 |
}
|
jaroslav@398
|
1396 |
if (previousTrap != null) {
|
jaroslav@843
|
1397 |
generateCatch(previousTrap, byteCodes.length, topMostLabel);
|
jaroslav@398
|
1398 |
}
|
jaroslav@1469
|
1399 |
if (didBranches) {
|
jaroslav@1509
|
1400 |
append("\n }\n");
|
jaroslav@1469
|
1401 |
}
|
jaroslav@839
|
1402 |
while (openBraces-- > 0) {
|
jaroslav@1509
|
1403 |
append('}');
|
jaroslav@839
|
1404 |
}
|
jaroslav@1633
|
1405 |
if (obj) {
|
jaroslav@1633
|
1406 |
append("\n}});");
|
jaroslav@1633
|
1407 |
} else {
|
jaroslav@1633
|
1408 |
append("\n};");
|
jaroslav@1633
|
1409 |
}
|
jaroslav@4
|
1410 |
}
|
jaroslav@4
|
1411 |
|
jaroslav@1468
|
1412 |
private int generateIf(StackMapper mapper, byte[] byteCodes,
|
jaroslav@1468
|
1413 |
int i, final CharSequence v2, final CharSequence v1,
|
jaroslav@1468
|
1414 |
final String test, int topMostLabel
|
jaroslav@1468
|
1415 |
) throws IOException {
|
jaroslav@1509
|
1416 |
mapper.flush(this);
|
jaroslav@864
|
1417 |
int indx = i + readShortArg(byteCodes, i);
|
jaroslav@1509
|
1418 |
append("if ((").append(v1)
|
jaroslav@1477
|
1419 |
.append(") ").append(test).append(" (")
|
jaroslav@1477
|
1420 |
.append(v2).append(")) ");
|
jaroslav@1509
|
1421 |
goTo(this, i, indx, topMostLabel);
|
jaroslav@4
|
1422 |
return i + 2;
|
jaroslav@4
|
1423 |
}
|
jaroslav@839
|
1424 |
|
lubomir@697
|
1425 |
private int readInt4(byte[] byteCodes, int offset) {
|
lubomir@697
|
1426 |
final int d = byteCodes[offset + 0] << 24;
|
lubomir@697
|
1427 |
final int c = byteCodes[offset + 1] << 16;
|
lubomir@697
|
1428 |
final int b = byteCodes[offset + 2] << 8;
|
lubomir@697
|
1429 |
final int a = byteCodes[offset + 3];
|
jaroslav@115
|
1430 |
return (d & 0xff000000) | (c & 0xff0000) | (b & 0xff00) | (a & 0xff);
|
jaroslav@115
|
1431 |
}
|
jaroslav@864
|
1432 |
private static int readUByte(byte[] byteCodes, int offset) {
|
lubomir@697
|
1433 |
return byteCodes[offset] & 0xff;
|
jtulach@128
|
1434 |
}
|
lubomir@585
|
1435 |
|
jaroslav@864
|
1436 |
private static int readUShort(byte[] byteCodes, int offset) {
|
lubomir@697
|
1437 |
return ((byteCodes[offset] & 0xff) << 8)
|
lubomir@697
|
1438 |
| (byteCodes[offset + 1] & 0xff);
|
lubomir@697
|
1439 |
}
|
jaroslav@864
|
1440 |
private static int readUShortArg(byte[] byteCodes, int offsetInstruction) {
|
jaroslav@864
|
1441 |
return readUShort(byteCodes, offsetInstruction + 1);
|
jaroslav@864
|
1442 |
}
|
lubomir@697
|
1443 |
|
jaroslav@864
|
1444 |
private static int readShort(byte[] byteCodes, int offset) {
|
jaroslav@864
|
1445 |
int signed = byteCodes[offset];
|
jaroslav@864
|
1446 |
byte b0 = (byte)signed;
|
jaroslav@864
|
1447 |
return (b0 << 8) | (byteCodes[offset + 1] & 0xff);
|
jaroslav@864
|
1448 |
}
|
jaroslav@864
|
1449 |
private static int readShortArg(byte[] byteCodes, int offsetInstruction) {
|
jaroslav@864
|
1450 |
return readShort(byteCodes, offsetInstruction + 1);
|
lubomir@585
|
1451 |
}
|
lubomir@585
|
1452 |
|
lubomir@281
|
1453 |
private static void countArgs(String descriptor, char[] returnType, StringBuilder sig, StringBuilder cnt) {
|
jaroslav@4
|
1454 |
int i = 0;
|
jaroslav@4
|
1455 |
Boolean count = null;
|
jaroslav@32
|
1456 |
boolean array = false;
|
jaroslav@248
|
1457 |
sig.append("__");
|
jaroslav@10
|
1458 |
int firstPos = sig.length();
|
jaroslav@4
|
1459 |
while (i < descriptor.length()) {
|
jaroslav@4
|
1460 |
char ch = descriptor.charAt(i++);
|
jaroslav@4
|
1461 |
switch (ch) {
|
jaroslav@4
|
1462 |
case '(':
|
jaroslav@4
|
1463 |
count = true;
|
jaroslav@4
|
1464 |
continue;
|
jaroslav@4
|
1465 |
case ')':
|
jaroslav@4
|
1466 |
count = false;
|
jaroslav@4
|
1467 |
continue;
|
jaroslav@4
|
1468 |
case 'B':
|
jaroslav@4
|
1469 |
case 'C':
|
jaroslav@4
|
1470 |
case 'D':
|
jaroslav@4
|
1471 |
case 'F':
|
jaroslav@4
|
1472 |
case 'I':
|
jaroslav@4
|
1473 |
case 'J':
|
jaroslav@4
|
1474 |
case 'S':
|
jaroslav@4
|
1475 |
case 'Z':
|
jaroslav@4
|
1476 |
if (count) {
|
jaroslav@32
|
1477 |
if (array) {
|
jaroslav@248
|
1478 |
sig.append("_3");
|
jaroslav@32
|
1479 |
}
|
jaroslav@4
|
1480 |
sig.append(ch);
|
jtulach@156
|
1481 |
if (ch == 'J' || ch == 'D') {
|
jtulach@156
|
1482 |
cnt.append('1');
|
jtulach@156
|
1483 |
} else {
|
jtulach@156
|
1484 |
cnt.append('0');
|
jtulach@156
|
1485 |
}
|
jaroslav@4
|
1486 |
} else {
|
jaroslav@10
|
1487 |
sig.insert(firstPos, ch);
|
jaroslav@32
|
1488 |
if (array) {
|
lubomir@281
|
1489 |
returnType[0] = '[';
|
jaroslav@248
|
1490 |
sig.insert(firstPos, "_3");
|
lubomir@281
|
1491 |
} else {
|
lubomir@281
|
1492 |
returnType[0] = ch;
|
jaroslav@32
|
1493 |
}
|
jaroslav@4
|
1494 |
}
|
jaroslav@93
|
1495 |
array = false;
|
jaroslav@4
|
1496 |
continue;
|
jaroslav@4
|
1497 |
case 'V':
|
jaroslav@4
|
1498 |
assert !count;
|
lubomir@281
|
1499 |
returnType[0] = 'V';
|
jaroslav@10
|
1500 |
sig.insert(firstPos, 'V');
|
jaroslav@4
|
1501 |
continue;
|
jaroslav@4
|
1502 |
case 'L':
|
jaroslav@16
|
1503 |
int next = descriptor.indexOf(';', i);
|
jaroslav@248
|
1504 |
String realSig = mangleSig(descriptor, i - 1, next + 1);
|
jaroslav@4
|
1505 |
if (count) {
|
jaroslav@32
|
1506 |
if (array) {
|
jaroslav@248
|
1507 |
sig.append("_3");
|
jaroslav@32
|
1508 |
}
|
jaroslav@248
|
1509 |
sig.append(realSig);
|
jtulach@156
|
1510 |
cnt.append('0');
|
jaroslav@4
|
1511 |
} else {
|
jaroslav@248
|
1512 |
sig.insert(firstPos, realSig);
|
jaroslav@32
|
1513 |
if (array) {
|
jaroslav@248
|
1514 |
sig.insert(firstPos, "_3");
|
jaroslav@32
|
1515 |
}
|
lubomir@281
|
1516 |
returnType[0] = 'L';
|
jaroslav@4
|
1517 |
}
|
jaroslav@16
|
1518 |
i = next + 1;
|
lubomir@407
|
1519 |
array = false;
|
jaroslav@4
|
1520 |
continue;
|
jaroslav@4
|
1521 |
case '[':
|
jaroslav@248
|
1522 |
array = true;
|
jaroslav@4
|
1523 |
continue;
|
jaroslav@4
|
1524 |
default:
|
jaroslav@248
|
1525 |
throw new IllegalStateException("Invalid char: " + ch);
|
jaroslav@4
|
1526 |
}
|
jaroslav@4
|
1527 |
}
|
jaroslav@0
|
1528 |
}
|
jaroslav@248
|
1529 |
|
jaroslav@592
|
1530 |
static String mangleSig(String sig) {
|
jaroslav@592
|
1531 |
return mangleSig(sig, 0, sig.length());
|
jaroslav@592
|
1532 |
}
|
jaroslav@592
|
1533 |
|
jaroslav@1409
|
1534 |
private static String mangleMethodName(String name) {
|
jaroslav@1409
|
1535 |
StringBuilder sb = new StringBuilder(name.length() * 2);
|
jaroslav@1409
|
1536 |
int last = name.length();
|
jaroslav@1409
|
1537 |
for (int i = 0; i < last; i++) {
|
jaroslav@1409
|
1538 |
final char ch = name.charAt(i);
|
jaroslav@1409
|
1539 |
switch (ch) {
|
jaroslav@1409
|
1540 |
case '_': sb.append("_1"); break;
|
jaroslav@1409
|
1541 |
default: sb.append(ch); break;
|
jaroslav@1409
|
1542 |
}
|
jaroslav@1409
|
1543 |
}
|
jaroslav@1409
|
1544 |
return sb.toString();
|
jaroslav@1409
|
1545 |
}
|
jaroslav@248
|
1546 |
private static String mangleSig(String txt, int first, int last) {
|
jaroslav@1409
|
1547 |
StringBuilder sb = new StringBuilder((last - first) * 2);
|
jaroslav@248
|
1548 |
for (int i = first; i < last; i++) {
|
jaroslav@248
|
1549 |
final char ch = txt.charAt(i);
|
jaroslav@248
|
1550 |
switch (ch) {
|
jaroslav@248
|
1551 |
case '/': sb.append('_'); break;
|
jaroslav@248
|
1552 |
case '_': sb.append("_1"); break;
|
jaroslav@248
|
1553 |
case ';': sb.append("_2"); break;
|
jaroslav@248
|
1554 |
case '[': sb.append("_3"); break;
|
jaroslav@1547
|
1555 |
default:
|
jaroslav@1547
|
1556 |
if (Character.isJavaIdentifierPart(ch)) {
|
jaroslav@1547
|
1557 |
sb.append(ch);
|
jaroslav@1547
|
1558 |
} else {
|
jaroslav@1547
|
1559 |
sb.append("_0");
|
jaroslav@1639
|
1560 |
String hex = Integer.toHexString(ch).toLowerCase();
|
jaroslav@1547
|
1561 |
for (int m = hex.length(); m < 4; m++) {
|
jaroslav@1547
|
1562 |
sb.append("0");
|
jaroslav@1547
|
1563 |
}
|
jaroslav@1547
|
1564 |
sb.append(hex);
|
jaroslav@1547
|
1565 |
}
|
jaroslav@1547
|
1566 |
break;
|
jaroslav@248
|
1567 |
}
|
jaroslav@248
|
1568 |
}
|
jaroslav@248
|
1569 |
return sb.toString();
|
jaroslav@248
|
1570 |
}
|
jaroslav@1409
|
1571 |
|
jaroslav@1409
|
1572 |
private static String mangleClassName(String name) {
|
jaroslav@1409
|
1573 |
return mangleSig(name);
|
jaroslav@1409
|
1574 |
}
|
jaroslav@9
|
1575 |
|
jaroslav@248
|
1576 |
private static String findMethodName(MethodData m, StringBuilder cnt) {
|
jaroslav@42
|
1577 |
StringBuilder name = new StringBuilder();
|
jaroslav@10
|
1578 |
if ("<init>".equals(m.getName())) { // NOI18N
|
jaroslav@42
|
1579 |
name.append("cons"); // NOI18N
|
jaroslav@19
|
1580 |
} else if ("<clinit>".equals(m.getName())) { // NOI18N
|
jaroslav@42
|
1581 |
name.append("class"); // NOI18N
|
jaroslav@10
|
1582 |
} else {
|
jaroslav@1409
|
1583 |
name.append(mangleMethodName(m.getName()));
|
jaroslav@10
|
1584 |
}
|
jaroslav@42
|
1585 |
|
lubomir@282
|
1586 |
countArgs(m.getInternalSig(), new char[1], name, cnt);
|
jaroslav@42
|
1587 |
return name.toString();
|
jaroslav@10
|
1588 |
}
|
jaroslav@10
|
1589 |
|
lubomir@282
|
1590 |
static String findMethodName(String[] mi, StringBuilder cnt, char[] returnType) {
|
jaroslav@10
|
1591 |
StringBuilder name = new StringBuilder();
|
jaroslav@151
|
1592 |
String descr = mi[2];//mi.getDescriptor();
|
jaroslav@151
|
1593 |
String nm= mi[1];
|
jaroslav@151
|
1594 |
if ("<init>".equals(nm)) { // NOI18N
|
jaroslav@10
|
1595 |
name.append("cons"); // NOI18N
|
jaroslav@10
|
1596 |
} else {
|
jaroslav@1409
|
1597 |
name.append(mangleMethodName(nm));
|
jaroslav@10
|
1598 |
}
|
lubomir@282
|
1599 |
countArgs(descr, returnType, name, cnt);
|
jaroslav@10
|
1600 |
return name.toString();
|
jaroslav@10
|
1601 |
}
|
jaroslav@10
|
1602 |
|
lubomir@307
|
1603 |
private int invokeStaticMethod(byte[] byteCodes, int i, final StackMapper mapper, boolean isStatic)
|
jaroslav@10
|
1604 |
throws IOException {
|
jaroslav@864
|
1605 |
int methodIndex = readUShortArg(byteCodes, i);
|
jaroslav@151
|
1606 |
String[] mi = jc.getFieldInfoName(methodIndex);
|
lubomir@281
|
1607 |
char[] returnType = { 'V' };
|
jtulach@156
|
1608 |
StringBuilder cnt = new StringBuilder();
|
lubomir@281
|
1609 |
String mn = findMethodName(mi, cnt, returnType);
|
lubomir@221
|
1610 |
|
lubomir@221
|
1611 |
final int numArguments = isStatic ? cnt.length() : cnt.length() + 1;
|
jaroslav@1457
|
1612 |
final CharSequence[] vars = new CharSequence[numArguments];
|
lubomir@221
|
1613 |
|
lubomir@281
|
1614 |
for (int j = numArguments - 1; j >= 0; --j) {
|
jaroslav@1457
|
1615 |
vars[j] = mapper.popValue();
|
jaroslav@11
|
1616 |
}
|
lubomir@281
|
1617 |
|
lubomir@281
|
1618 |
if (returnType[0] != 'V') {
|
jaroslav@1595
|
1619 |
mapper.flush(this);
|
jaroslav@1509
|
1620 |
append("var ")
|
lubomir@474
|
1621 |
.append(mapper.pushT(VarType.fromFieldType(returnType[0])))
|
lubomir@281
|
1622 |
.append(" = ");
|
jaroslav@10
|
1623 |
}
|
lubomir@221
|
1624 |
|
jaroslav@151
|
1625 |
final String in = mi[0];
|
jaroslav@1515
|
1626 |
String mcn;
|
jaroslav@1515
|
1627 |
if (callbacks && in.equals("org/apidesign/html/boot/spi/Fn")) {
|
jaroslav@1515
|
1628 |
mcn = "java_lang_Class";
|
jaroslav@1515
|
1629 |
} else {
|
jaroslav@1515
|
1630 |
mcn = mangleClassName(in);
|
jaroslav@1515
|
1631 |
}
|
jaroslav@1515
|
1632 |
String object = accessClass(mcn) + "(false)";
|
jaroslav@397
|
1633 |
if (mn.startsWith("cons_")) {
|
lubomir@1094
|
1634 |
object += ".constructor";
|
jaroslav@397
|
1635 |
}
|
jaroslav@1513
|
1636 |
append(accessStaticMethod(object, mn, mi));
|
jaroslav@442
|
1637 |
if (isStatic) {
|
jaroslav@1509
|
1638 |
append('(');
|
jaroslav@442
|
1639 |
} else {
|
jaroslav@1509
|
1640 |
append(".call(");
|
jaroslav@442
|
1641 |
}
|
lubomir@221
|
1642 |
if (numArguments > 0) {
|
jaroslav@1509
|
1643 |
append(vars[0]);
|
lubomir@281
|
1644 |
for (int j = 1; j < numArguments; ++j) {
|
jaroslav@1509
|
1645 |
append(", ");
|
jaroslav@1509
|
1646 |
append(vars[j]);
|
lubomir@221
|
1647 |
}
|
jaroslav@10
|
1648 |
}
|
jaroslav@1509
|
1649 |
append(");");
|
jaroslav@10
|
1650 |
i += 2;
|
jaroslav@18
|
1651 |
addReference(in);
|
jaroslav@10
|
1652 |
return i;
|
jaroslav@10
|
1653 |
}
|
lubomir@307
|
1654 |
private int invokeVirtualMethod(byte[] byteCodes, int i, final StackMapper mapper)
|
jaroslav@12
|
1655 |
throws IOException {
|
jaroslav@864
|
1656 |
int methodIndex = readUShortArg(byteCodes, i);
|
jaroslav@151
|
1657 |
String[] mi = jc.getFieldInfoName(methodIndex);
|
lubomir@281
|
1658 |
char[] returnType = { 'V' };
|
jtulach@156
|
1659 |
StringBuilder cnt = new StringBuilder();
|
lubomir@281
|
1660 |
String mn = findMethodName(mi, cnt, returnType);
|
lubomir@221
|
1661 |
|
lubomir@281
|
1662 |
final int numArguments = cnt.length() + 1;
|
jaroslav@1458
|
1663 |
final CharSequence[] vars = new CharSequence[numArguments];
|
lubomir@221
|
1664 |
|
lubomir@281
|
1665 |
for (int j = numArguments - 1; j >= 0; --j) {
|
jaroslav@1458
|
1666 |
vars[j] = mapper.popValue();
|
jaroslav@12
|
1667 |
}
|
lubomir@221
|
1668 |
|
lubomir@281
|
1669 |
if (returnType[0] != 'V') {
|
jaroslav@1509
|
1670 |
append("var ")
|
lubomir@474
|
1671 |
.append(mapper.pushT(VarType.fromFieldType(returnType[0])))
|
lubomir@281
|
1672 |
.append(" = ");
|
jaroslav@12
|
1673 |
}
|
lubomir@281
|
1674 |
|
jaroslav@1613
|
1675 |
append(accessVirtualMethod(vars[0].toString(), mn, mi, numArguments));
|
jaroslav@442
|
1676 |
String sep = "";
|
lubomir@281
|
1677 |
for (int j = 1; j < numArguments; ++j) {
|
jaroslav@1509
|
1678 |
append(sep);
|
jaroslav@1509
|
1679 |
append(vars[j]);
|
jaroslav@442
|
1680 |
sep = ", ";
|
jaroslav@12
|
1681 |
}
|
jaroslav@1509
|
1682 |
append(");");
|
jaroslav@12
|
1683 |
i += 2;
|
jaroslav@12
|
1684 |
return i;
|
jaroslav@12
|
1685 |
}
|
lubomir@221
|
1686 |
|
jaroslav@103
|
1687 |
private void addReference(String cn) throws IOException {
|
jtulach@162
|
1688 |
if (requireReference(cn)) {
|
jaroslav@399
|
1689 |
debug(" /* needs " + cn + " */");
|
jaroslav@18
|
1690 |
}
|
jaroslav@18
|
1691 |
}
|
jaroslav@16
|
1692 |
|
jaroslav@33
|
1693 |
private void outType(String d, StringBuilder out) {
|
jaroslav@33
|
1694 |
int arr = 0;
|
jaroslav@33
|
1695 |
while (d.charAt(0) == '[') {
|
jaroslav@33
|
1696 |
out.append('A');
|
jaroslav@33
|
1697 |
d = d.substring(1);
|
jaroslav@33
|
1698 |
}
|
jaroslav@16
|
1699 |
if (d.charAt(0) == 'L') {
|
jaroslav@16
|
1700 |
assert d.charAt(d.length() - 1) == ';';
|
jaroslav@16
|
1701 |
out.append(d.replace('/', '_').substring(0, d.length() - 1));
|
jaroslav@16
|
1702 |
} else {
|
jaroslav@16
|
1703 |
out.append(d);
|
jaroslav@16
|
1704 |
}
|
jaroslav@16
|
1705 |
}
|
jaroslav@21
|
1706 |
|
jaroslav@230
|
1707 |
private String encodeConstant(int entryIndex) throws IOException {
|
jaroslav@230
|
1708 |
String[] classRef = { null };
|
jaroslav@230
|
1709 |
String s = jc.stringValue(entryIndex, classRef);
|
jaroslav@230
|
1710 |
if (classRef[0] != null) {
|
jaroslav@567
|
1711 |
if (classRef[0].startsWith("[")) {
|
jaroslav@1513
|
1712 |
s = accessClass("java_lang_Class") + "(false)['forName__Ljava_lang_Class_2Ljava_lang_String_2']('" + classRef[0] + "')";
|
jaroslav@567
|
1713 |
} else {
|
jaroslav@567
|
1714 |
addReference(classRef[0]);
|
jaroslav@1409
|
1715 |
s = accessClass(mangleClassName(s)) + "(false).constructor.$class";
|
jaroslav@567
|
1716 |
}
|
jaroslav@230
|
1717 |
}
|
jaroslav@151
|
1718 |
return s;
|
jaroslav@21
|
1719 |
}
|
jaroslav@32
|
1720 |
|
lubomir@869
|
1721 |
private String javaScriptBody(String destObject, MethodData m, boolean isStatic) throws IOException {
|
jaroslav@152
|
1722 |
byte[] arr = m.findAnnotationData(true);
|
jaroslav@152
|
1723 |
if (arr == null) {
|
jaroslav@266
|
1724 |
return null;
|
jaroslav@152
|
1725 |
}
|
jaroslav@200
|
1726 |
final String jvmType = "Lorg/apidesign/bck2brwsr/core/JavaScriptBody;";
|
jaroslav@1239
|
1727 |
final String htmlType = "Lnet/java/html/js/JavaScriptBody;";
|
jaroslav@152
|
1728 |
class P extends AnnotationParser {
|
jaroslav@237
|
1729 |
public P() {
|
jaroslav@652
|
1730 |
super(false, true);
|
jaroslav@237
|
1731 |
}
|
jaroslav@237
|
1732 |
|
jaroslav@152
|
1733 |
int cnt;
|
jaroslav@152
|
1734 |
String[] args = new String[30];
|
jaroslav@152
|
1735 |
String body;
|
jaroslav@1241
|
1736 |
boolean javacall;
|
jaroslav@1421
|
1737 |
boolean html4j;
|
jaroslav@94
|
1738 |
|
jaroslav@152
|
1739 |
@Override
|
jaroslav@236
|
1740 |
protected void visitAttr(String type, String attr, String at, String value) {
|
jaroslav@152
|
1741 |
if (type.equals(jvmType)) {
|
jaroslav@152
|
1742 |
if ("body".equals(attr)) {
|
jaroslav@152
|
1743 |
body = value;
|
jaroslav@152
|
1744 |
} else if ("args".equals(attr)) {
|
jaroslav@152
|
1745 |
args[cnt++] = value;
|
jaroslav@152
|
1746 |
} else {
|
jaroslav@152
|
1747 |
throw new IllegalArgumentException(attr);
|
jaroslav@152
|
1748 |
}
|
jaroslav@152
|
1749 |
}
|
jaroslav@1239
|
1750 |
if (type.equals(htmlType)) {
|
jaroslav@1421
|
1751 |
html4j = true;
|
jaroslav@1239
|
1752 |
if ("body".equals(attr)) {
|
jaroslav@1239
|
1753 |
body = value;
|
jaroslav@1239
|
1754 |
} else if ("args".equals(attr)) {
|
jaroslav@1239
|
1755 |
args[cnt++] = value;
|
jaroslav@1241
|
1756 |
} else if ("javacall".equals(attr)) {
|
jaroslav@1241
|
1757 |
javacall = "1".equals(value);
|
jaroslav@1635
|
1758 |
} else if ("wait4js".equals(attr)) {
|
jaroslav@1635
|
1759 |
// ignore, we always invoke synchronously
|
jaroslav@1239
|
1760 |
} else {
|
jaroslav@1239
|
1761 |
throw new IllegalArgumentException(attr);
|
jaroslav@1239
|
1762 |
}
|
jaroslav@1239
|
1763 |
}
|
jaroslav@94
|
1764 |
}
|
jaroslav@94
|
1765 |
}
|
jaroslav@152
|
1766 |
P p = new P();
|
jaroslav@152
|
1767 |
p.parse(arr, jc);
|
jaroslav@152
|
1768 |
if (p.body == null) {
|
jaroslav@266
|
1769 |
return null;
|
jaroslav@152
|
1770 |
}
|
jtulach@156
|
1771 |
StringBuilder cnt = new StringBuilder();
|
jaroslav@266
|
1772 |
final String mn = findMethodName(m, cnt);
|
jaroslav@1509
|
1773 |
append(destObject).append(".").append(mn);
|
jaroslav@1509
|
1774 |
append(" = function(");
|
jaroslav@442
|
1775 |
String space = "";
|
jaroslav@443
|
1776 |
int index = 0;
|
jaroslav@1421
|
1777 |
StringBuilder toValue = new StringBuilder();
|
jtulach@156
|
1778 |
for (int i = 0; i < cnt.length(); i++) {
|
jaroslav@1509
|
1779 |
append(space);
|
jaroslav@1509
|
1780 |
space = outputArg(this, p.args, index);
|
jaroslav@1421
|
1781 |
if (p.html4j && space.length() > 0) {
|
jaroslav@1515
|
1782 |
toValue.append("\n ").append(p.args[index]).append(" = ")
|
jaroslav@1515
|
1783 |
.append(accessClass("java_lang_Class")).append("(false).toJS(").
|
jaroslav@1421
|
1784 |
append(p.args[index]).append(");");
|
jaroslav@1421
|
1785 |
}
|
jaroslav@152
|
1786 |
index++;
|
jaroslav@152
|
1787 |
}
|
jaroslav@1509
|
1788 |
append(") {").append("\n");
|
jaroslav@1509
|
1789 |
append(toValue.toString());
|
jaroslav@1242
|
1790 |
if (p.javacall) {
|
jaroslav@1242
|
1791 |
int lastSlash = jc.getClassName().lastIndexOf('/');
|
jaroslav@1242
|
1792 |
final String pkg = jc.getClassName().substring(0, lastSlash);
|
jaroslav@1509
|
1793 |
append(mangleCallbacks(pkg, p.body));
|
jaroslav@1242
|
1794 |
requireReference(pkg + "/$JsCallbacks$");
|
jaroslav@1242
|
1795 |
} else {
|
jaroslav@1509
|
1796 |
append(p.body);
|
jaroslav@1242
|
1797 |
}
|
jaroslav@1509
|
1798 |
append("\n}\n");
|
jaroslav@266
|
1799 |
return mn;
|
jaroslav@151
|
1800 |
}
|
jaroslav@1242
|
1801 |
|
jaroslav@1242
|
1802 |
private static CharSequence mangleCallbacks(String pkgName, String body) {
|
jaroslav@1242
|
1803 |
StringBuilder sb = new StringBuilder();
|
jaroslav@1242
|
1804 |
int pos = 0;
|
jaroslav@1242
|
1805 |
for (;;) {
|
jaroslav@1242
|
1806 |
int next = body.indexOf(".@", pos);
|
jaroslav@1242
|
1807 |
if (next == -1) {
|
jaroslav@1242
|
1808 |
sb.append(body.substring(pos));
|
jaroslav@1243
|
1809 |
body = sb.toString();
|
jaroslav@1243
|
1810 |
break;
|
jaroslav@1242
|
1811 |
}
|
jaroslav@1242
|
1812 |
int ident = next;
|
jaroslav@1242
|
1813 |
while (ident > 0) {
|
jaroslav@1242
|
1814 |
if (!Character.isJavaIdentifierPart(body.charAt(--ident))) {
|
jaroslav@1242
|
1815 |
ident++;
|
jaroslav@1242
|
1816 |
break;
|
jaroslav@1242
|
1817 |
}
|
jaroslav@1242
|
1818 |
}
|
jaroslav@1242
|
1819 |
String refId = body.substring(ident, next);
|
jaroslav@1242
|
1820 |
|
jaroslav@1242
|
1821 |
sb.append(body.substring(pos, ident));
|
jaroslav@1242
|
1822 |
|
jaroslav@1242
|
1823 |
int sigBeg = body.indexOf('(', next);
|
jaroslav@1242
|
1824 |
int sigEnd = body.indexOf(')', sigBeg);
|
jaroslav@1242
|
1825 |
int colon4 = body.indexOf("::", next);
|
jaroslav@1242
|
1826 |
if (sigBeg == -1 || sigEnd == -1 || colon4 == -1) {
|
jaroslav@1242
|
1827 |
throw new IllegalStateException("Malformed body " + body);
|
jaroslav@1242
|
1828 |
}
|
jaroslav@1242
|
1829 |
String fqn = body.substring(next + 2, colon4);
|
jaroslav@1242
|
1830 |
String method = body.substring(colon4 + 2, sigBeg);
|
jaroslav@1242
|
1831 |
String params = body.substring(sigBeg, sigEnd + 1);
|
jaroslav@1242
|
1832 |
|
jaroslav@1242
|
1833 |
int paramBeg = body.indexOf('(', sigEnd + 1);
|
jaroslav@1242
|
1834 |
|
jaroslav@1242
|
1835 |
sb.append("vm.").append(pkgName.replace('/', '_')).append("_$JsCallbacks$(false)._VM().");
|
jaroslav@1409
|
1836 |
sb.append(mangleJsCallbacks(fqn, method, params, false));
|
jaroslav@1242
|
1837 |
sb.append("(").append(refId);
|
jaroslav@1242
|
1838 |
if (body.charAt(paramBeg + 1) != ')') {
|
jaroslav@1242
|
1839 |
sb.append(",");
|
jaroslav@1242
|
1840 |
}
|
jaroslav@1242
|
1841 |
pos = paramBeg + 1;
|
jaroslav@1242
|
1842 |
}
|
jaroslav@1243
|
1843 |
sb = null;
|
jaroslav@1243
|
1844 |
pos = 0;
|
jaroslav@1243
|
1845 |
for (;;) {
|
jaroslav@1243
|
1846 |
int next = body.indexOf("@", pos);
|
jaroslav@1243
|
1847 |
if (next == -1) {
|
jaroslav@1243
|
1848 |
if (sb == null) {
|
jaroslav@1243
|
1849 |
return body;
|
jaroslav@1243
|
1850 |
}
|
jaroslav@1243
|
1851 |
sb.append(body.substring(pos));
|
jaroslav@1243
|
1852 |
return sb;
|
jaroslav@1243
|
1853 |
}
|
jaroslav@1243
|
1854 |
if (sb == null) {
|
jaroslav@1243
|
1855 |
sb = new StringBuilder();
|
jaroslav@1243
|
1856 |
}
|
jaroslav@1243
|
1857 |
|
jaroslav@1243
|
1858 |
sb.append(body.substring(pos, next));
|
jaroslav@1243
|
1859 |
|
jaroslav@1243
|
1860 |
int sigBeg = body.indexOf('(', next);
|
jaroslav@1243
|
1861 |
int sigEnd = body.indexOf(')', sigBeg);
|
jaroslav@1243
|
1862 |
int colon4 = body.indexOf("::", next);
|
jaroslav@1243
|
1863 |
if (sigBeg == -1 || sigEnd == -1 || colon4 == -1) {
|
jaroslav@1243
|
1864 |
throw new IllegalStateException("Malformed body " + body);
|
jaroslav@1243
|
1865 |
}
|
jaroslav@1243
|
1866 |
String fqn = body.substring(next + 1, colon4);
|
jaroslav@1243
|
1867 |
String method = body.substring(colon4 + 2, sigBeg);
|
jaroslav@1243
|
1868 |
String params = body.substring(sigBeg, sigEnd + 1);
|
jaroslav@1243
|
1869 |
|
jaroslav@1243
|
1870 |
int paramBeg = body.indexOf('(', sigEnd + 1);
|
jaroslav@1243
|
1871 |
|
jaroslav@1243
|
1872 |
sb.append("vm.").append(pkgName.replace('/', '_')).append("_$JsCallbacks$(false)._VM().");
|
jaroslav@1409
|
1873 |
sb.append(mangleJsCallbacks(fqn, method, params, true));
|
jaroslav@1243
|
1874 |
sb.append("(");
|
jaroslav@1243
|
1875 |
pos = paramBeg + 1;
|
jaroslav@1243
|
1876 |
}
|
jaroslav@1242
|
1877 |
}
|
jaroslav@1409
|
1878 |
|
jaroslav@1409
|
1879 |
static String mangleJsCallbacks(String fqn, String method, String params, boolean isStatic) {
|
jaroslav@1242
|
1880 |
if (params.startsWith("(")) {
|
jaroslav@1242
|
1881 |
params = params.substring(1);
|
jaroslav@1242
|
1882 |
}
|
jaroslav@1242
|
1883 |
if (params.endsWith(")")) {
|
jaroslav@1242
|
1884 |
params = params.substring(0, params.length() - 1);
|
jaroslav@1242
|
1885 |
}
|
jaroslav@1243
|
1886 |
StringBuilder sb = new StringBuilder();
|
jaroslav@1409
|
1887 |
final String fqnu = fqn.replace('.', '_');
|
jaroslav@1409
|
1888 |
final String rfqn = mangleClassName(fqnu);
|
jaroslav@1409
|
1889 |
final String rm = mangleMethodName(method);
|
jaroslav@1427
|
1890 |
final String srp;
|
jaroslav@1427
|
1891 |
{
|
jaroslav@1427
|
1892 |
StringBuilder pb = new StringBuilder();
|
jaroslav@1427
|
1893 |
int len = params.length();
|
jaroslav@1427
|
1894 |
int indx = 0;
|
jaroslav@1427
|
1895 |
while (indx < len) {
|
jaroslav@1427
|
1896 |
char ch = params.charAt(indx);
|
jaroslav@1427
|
1897 |
if (ch == '[' || ch == 'L') {
|
jaroslav@1427
|
1898 |
pb.append("Ljava/lang/Object;");
|
jaroslav@1427
|
1899 |
indx = params.indexOf(';', indx) + 1;
|
jaroslav@1427
|
1900 |
} else {
|
jaroslav@1427
|
1901 |
pb.append(ch);
|
jaroslav@1427
|
1902 |
indx++;
|
jaroslav@1427
|
1903 |
}
|
jaroslav@1427
|
1904 |
}
|
jaroslav@1427
|
1905 |
srp = mangleSig(pb.toString());
|
jaroslav@1427
|
1906 |
}
|
jaroslav@1409
|
1907 |
final String rp = mangleSig(params);
|
jaroslav@1409
|
1908 |
final String mrp = mangleMethodName(rp);
|
jaroslav@1248
|
1909 |
sb.append(rfqn).append("$").append(rm).
|
jaroslav@1409
|
1910 |
append('$').append(mrp).append("__Ljava_lang_Object_2");
|
jaroslav@1243
|
1911 |
if (!isStatic) {
|
jaroslav@1409
|
1912 |
sb.append('L').append(fqnu).append("_2");
|
jaroslav@1243
|
1913 |
}
|
jaroslav@1427
|
1914 |
sb.append(srp);
|
jaroslav@1243
|
1915 |
return sb.toString();
|
jaroslav@1242
|
1916 |
}
|
jaroslav@1242
|
1917 |
|
jaroslav@151
|
1918 |
private static String className(ClassData jc) {
|
jaroslav@151
|
1919 |
//return jc.getName().getInternalName().replace('/', '_');
|
jaroslav@1409
|
1920 |
return mangleClassName(jc.getClassName());
|
jaroslav@94
|
1921 |
}
|
jaroslav@152
|
1922 |
|
jaroslav@152
|
1923 |
private static String[] findAnnotation(
|
jaroslav@152
|
1924 |
byte[] arr, ClassData cd, final String className,
|
jaroslav@152
|
1925 |
final String... attrNames
|
jaroslav@152
|
1926 |
) throws IOException {
|
jaroslav@152
|
1927 |
if (arr == null) {
|
jaroslav@152
|
1928 |
return null;
|
jaroslav@152
|
1929 |
}
|
jaroslav@152
|
1930 |
final String[] values = new String[attrNames.length];
|
jaroslav@152
|
1931 |
final boolean[] found = { false };
|
jaroslav@152
|
1932 |
final String jvmType = "L" + className.replace('.', '/') + ";";
|
jaroslav@652
|
1933 |
AnnotationParser ap = new AnnotationParser(false, true) {
|
jaroslav@152
|
1934 |
@Override
|
jaroslav@236
|
1935 |
protected void visitAttr(String type, String attr, String at, String value) {
|
jaroslav@152
|
1936 |
if (type.equals(jvmType)) {
|
jaroslav@152
|
1937 |
found[0] = true;
|
jaroslav@152
|
1938 |
for (int i = 0; i < attrNames.length; i++) {
|
jaroslav@152
|
1939 |
if (attrNames[i].equals(attr)) {
|
jaroslav@152
|
1940 |
values[i] = value;
|
jaroslav@152
|
1941 |
}
|
jaroslav@152
|
1942 |
}
|
jaroslav@152
|
1943 |
}
|
jaroslav@152
|
1944 |
}
|
jaroslav@152
|
1945 |
|
jaroslav@152
|
1946 |
};
|
jaroslav@152
|
1947 |
ap.parse(arr, cd);
|
jaroslav@152
|
1948 |
return found[0] ? values : null;
|
jaroslav@152
|
1949 |
}
|
jaroslav@173
|
1950 |
|
jaroslav@173
|
1951 |
private CharSequence initField(FieldData v) {
|
jaroslav@173
|
1952 |
final String is = v.getInternalSig();
|
jaroslav@173
|
1953 |
if (is.length() == 1) {
|
jaroslav@173
|
1954 |
switch (is.charAt(0)) {
|
jaroslav@173
|
1955 |
case 'S':
|
jaroslav@173
|
1956 |
case 'J':
|
jaroslav@173
|
1957 |
case 'B':
|
jaroslav@173
|
1958 |
case 'Z':
|
jaroslav@173
|
1959 |
case 'C':
|
jaroslav@173
|
1960 |
case 'I': return " = 0;";
|
jaroslav@173
|
1961 |
case 'F':
|
jaroslav@180
|
1962 |
case 'D': return " = 0.0;";
|
jaroslav@173
|
1963 |
default:
|
jaroslav@173
|
1964 |
throw new IllegalStateException(is);
|
jaroslav@173
|
1965 |
}
|
jaroslav@173
|
1966 |
}
|
jaroslav@173
|
1967 |
return " = null;";
|
jaroslav@173
|
1968 |
}
|
jaroslav@235
|
1969 |
|
jaroslav@1509
|
1970 |
private void generateAnno(ClassData cd, byte[] data) throws IOException {
|
jaroslav@652
|
1971 |
AnnotationParser ap = new AnnotationParser(true, false) {
|
jaroslav@652
|
1972 |
int[] cnt = new int[32];
|
jaroslav@652
|
1973 |
int depth;
|
jaroslav@235
|
1974 |
|
jaroslav@235
|
1975 |
@Override
|
jaroslav@659
|
1976 |
protected void visitAnnotationStart(String attrType, boolean top) throws IOException {
|
jaroslav@659
|
1977 |
final String slashType = attrType.substring(1, attrType.length() - 1);
|
jaroslav@659
|
1978 |
requireReference(slashType);
|
jaroslav@659
|
1979 |
|
jaroslav@652
|
1980 |
if (cnt[depth]++ > 0) {
|
jaroslav@1509
|
1981 |
append(",");
|
jaroslav@237
|
1982 |
}
|
jaroslav@659
|
1983 |
if (top) {
|
jaroslav@1509
|
1984 |
append('"').append(attrType).append("\" : ");
|
jaroslav@659
|
1985 |
}
|
jaroslav@1509
|
1986 |
append("{\n");
|
jaroslav@652
|
1987 |
cnt[++depth] = 0;
|
jaroslav@235
|
1988 |
}
|
jaroslav@235
|
1989 |
|
jaroslav@235
|
1990 |
@Override
|
jaroslav@659
|
1991 |
protected void visitAnnotationEnd(String type, boolean top) throws IOException {
|
jaroslav@1509
|
1992 |
append("\n}\n");
|
jaroslav@652
|
1993 |
depth--;
|
jaroslav@652
|
1994 |
}
|
jaroslav@652
|
1995 |
|
jaroslav@652
|
1996 |
@Override
|
jaroslav@652
|
1997 |
protected void visitValueStart(String attrName, char type) throws IOException {
|
jaroslav@652
|
1998 |
if (cnt[depth]++ > 0) {
|
jaroslav@1509
|
1999 |
append(",\n");
|
jaroslav@652
|
2000 |
}
|
jaroslav@652
|
2001 |
cnt[++depth] = 0;
|
jaroslav@652
|
2002 |
if (attrName != null) {
|
jaroslav@1564
|
2003 |
append('"').append(attrName).append("\" : ");
|
jaroslav@652
|
2004 |
}
|
jaroslav@652
|
2005 |
if (type == '[') {
|
jaroslav@1509
|
2006 |
append("[");
|
jaroslav@652
|
2007 |
}
|
jaroslav@652
|
2008 |
}
|
jaroslav@652
|
2009 |
|
jaroslav@652
|
2010 |
@Override
|
jaroslav@652
|
2011 |
protected void visitValueEnd(String attrName, char type) throws IOException {
|
jaroslav@652
|
2012 |
if (type == '[') {
|
jaroslav@1509
|
2013 |
append("]");
|
jaroslav@652
|
2014 |
}
|
jaroslav@652
|
2015 |
depth--;
|
jaroslav@235
|
2016 |
}
|
jaroslav@235
|
2017 |
|
jaroslav@235
|
2018 |
@Override
|
jaroslav@236
|
2019 |
protected void visitAttr(String type, String attr, String attrType, String value)
|
jaroslav@235
|
2020 |
throws IOException {
|
jaroslav@652
|
2021 |
if (attr == null && value == null) {
|
jaroslav@266
|
2022 |
return;
|
jaroslav@266
|
2023 |
}
|
jaroslav@1509
|
2024 |
append(value);
|
jaroslav@592
|
2025 |
}
|
jaroslav@655
|
2026 |
|
jaroslav@655
|
2027 |
@Override
|
jaroslav@655
|
2028 |
protected void visitEnumAttr(String type, String attr, String attrType, String value)
|
jaroslav@655
|
2029 |
throws IOException {
|
jaroslav@655
|
2030 |
final String slashType = attrType.substring(1, attrType.length() - 1);
|
jaroslav@655
|
2031 |
requireReference(slashType);
|
jaroslav@655
|
2032 |
|
jaroslav@1564
|
2033 |
final String cn = mangleClassName(slashType);
|
jaroslav@1564
|
2034 |
append(accessClass(cn))
|
jaroslav@1564
|
2035 |
.append("(false)['valueOf__L").
|
jaroslav@1564
|
2036 |
append(cn).
|
jaroslav@1564
|
2037 |
append("_2Ljava_lang_String_2']('").
|
jaroslav@1564
|
2038 |
append(value).
|
jaroslav@1564
|
2039 |
append("')");
|
jaroslav@235
|
2040 |
}
|
jaroslav@235
|
2041 |
};
|
jaroslav@235
|
2042 |
ap.parse(data, cd);
|
jaroslav@235
|
2043 |
}
|
jaroslav@316
|
2044 |
|
jaroslav@316
|
2045 |
private static String outputArg(Appendable out, String[] args, int indx) throws IOException {
|
jaroslav@316
|
2046 |
final String name = args[indx];
|
jaroslav@316
|
2047 |
if (name == null) {
|
jaroslav@316
|
2048 |
return "";
|
jaroslav@316
|
2049 |
}
|
jaroslav@316
|
2050 |
if (name.contains(",")) {
|
jaroslav@316
|
2051 |
throw new IOException("Wrong parameter with ',': " + name);
|
jaroslav@316
|
2052 |
}
|
jaroslav@316
|
2053 |
out.append(name);
|
jaroslav@316
|
2054 |
return ",";
|
jaroslav@316
|
2055 |
}
|
lubomir@317
|
2056 |
|
jaroslav@1466
|
2057 |
final void emitNoFlush(
|
jaroslav@1466
|
2058 |
StackMapper sm,
|
jaroslav@1466
|
2059 |
final String format, final CharSequence... params
|
jaroslav@1466
|
2060 |
) throws IOException {
|
jaroslav@1509
|
2061 |
emitImpl(this, format, params);
|
jaroslav@1466
|
2062 |
}
|
jaroslav@1509
|
2063 |
static final void emit(
|
jaroslav@1455
|
2064 |
StackMapper sm,
|
jaroslav@1455
|
2065 |
final Appendable out,
|
jaroslav@1455
|
2066 |
final String format, final CharSequence... params
|
jaroslav@1455
|
2067 |
) throws IOException {
|
jaroslav@1455
|
2068 |
sm.flush(out);
|
jaroslav@1455
|
2069 |
emitImpl(out, format, params);
|
jaroslav@1455
|
2070 |
}
|
jaroslav@1455
|
2071 |
static void emitImpl(final Appendable out,
|
lubomir@283
|
2072 |
final String format,
|
lubomir@283
|
2073 |
final CharSequence... params) throws IOException {
|
lubomir@283
|
2074 |
final int length = format.length();
|
lubomir@283
|
2075 |
|
lubomir@283
|
2076 |
int processed = 0;
|
lubomir@283
|
2077 |
int paramOffset = format.indexOf('@');
|
lubomir@283
|
2078 |
while ((paramOffset != -1) && (paramOffset < (length - 1))) {
|
lubomir@283
|
2079 |
final char paramChar = format.charAt(paramOffset + 1);
|
lubomir@283
|
2080 |
if ((paramChar >= '1') && (paramChar <= '9')) {
|
lubomir@283
|
2081 |
final int paramIndex = paramChar - '0' - 1;
|
lubomir@283
|
2082 |
|
lubomir@283
|
2083 |
out.append(format, processed, paramOffset);
|
lubomir@283
|
2084 |
out.append(params[paramIndex]);
|
lubomir@283
|
2085 |
|
lubomir@283
|
2086 |
++paramOffset;
|
lubomir@283
|
2087 |
processed = paramOffset + 1;
|
lubomir@283
|
2088 |
}
|
lubomir@283
|
2089 |
|
lubomir@283
|
2090 |
paramOffset = format.indexOf('@', paramOffset + 1);
|
lubomir@283
|
2091 |
}
|
lubomir@283
|
2092 |
|
lubomir@283
|
2093 |
out.append(format, processed, length);
|
lubomir@283
|
2094 |
}
|
jaroslav@398
|
2095 |
|
jaroslav@843
|
2096 |
private void generateCatch(TrapData[] traps, int current, int topMostLabel) throws IOException {
|
jaroslav@1509
|
2097 |
append("} catch (e) {\n");
|
jaroslav@401
|
2098 |
int finallyPC = -1;
|
jaroslav@398
|
2099 |
for (TrapData e : traps) {
|
jaroslav@398
|
2100 |
if (e == null) {
|
jaroslav@398
|
2101 |
break;
|
jaroslav@398
|
2102 |
}
|
jaroslav@398
|
2103 |
if (e.catch_cpx != 0) { //not finally
|
jaroslav@398
|
2104 |
final String classInternalName = jc.getClassName(e.catch_cpx);
|
jaroslav@398
|
2105 |
addReference(classInternalName);
|
jaroslav@1522
|
2106 |
append("e = vm.java_lang_Class(false).bck2BrwsrThrwrbl(e);");
|
jaroslav@1513
|
2107 |
append("if (e['$instOf_" + classInternalName.replace('/', '_') + "']) {");
|
jaroslav@1509
|
2108 |
append("var stA0 = e;");
|
jaroslav@1509
|
2109 |
goTo(this, current, e.handler_pc, topMostLabel);
|
jaroslav@1509
|
2110 |
append("}\n");
|
jaroslav@398
|
2111 |
} else {
|
jaroslav@401
|
2112 |
finallyPC = e.handler_pc;
|
jaroslav@398
|
2113 |
}
|
jaroslav@398
|
2114 |
}
|
jaroslav@401
|
2115 |
if (finallyPC == -1) {
|
jaroslav@1509
|
2116 |
append("throw e;");
|
jaroslav@401
|
2117 |
} else {
|
jaroslav@1509
|
2118 |
append("var stA0 = e;");
|
jaroslav@1509
|
2119 |
goTo(this, current, finallyPC, topMostLabel);
|
jaroslav@401
|
2120 |
}
|
jaroslav@1509
|
2121 |
append("\n}");
|
jaroslav@398
|
2122 |
}
|
jaroslav@839
|
2123 |
|
jaroslav@843
|
2124 |
private static void goTo(Appendable out, int current, int to, int canBack) throws IOException {
|
jaroslav@839
|
2125 |
if (to < current) {
|
jaroslav@843
|
2126 |
if (canBack < to) {
|
jaroslav@843
|
2127 |
out.append("{ gt = 0; continue X_" + to + "; }");
|
jaroslav@843
|
2128 |
} else {
|
jaroslav@843
|
2129 |
out.append("{ gt = " + to + "; continue X_0; }");
|
jaroslav@843
|
2130 |
}
|
jaroslav@839
|
2131 |
} else {
|
jaroslav@839
|
2132 |
out.append("{ gt = " + to + "; break IF; }");
|
jaroslav@839
|
2133 |
}
|
jaroslav@839
|
2134 |
}
|
jaroslav@839
|
2135 |
|
jaroslav@843
|
2136 |
private static void emitIf(
|
jaroslav@1455
|
2137 |
StackMapper sm,
|
jaroslav@1455
|
2138 |
Appendable out, String pattern,
|
jaroslav@1457
|
2139 |
CharSequence param,
|
jaroslav@843
|
2140 |
int current, int to, int canBack
|
jaroslav@843
|
2141 |
) throws IOException {
|
jaroslav@1455
|
2142 |
sm.flush(out);
|
jaroslav@1455
|
2143 |
emitImpl(out, pattern, param);
|
jaroslav@843
|
2144 |
goTo(out, current, to, canBack);
|
jaroslav@839
|
2145 |
}
|
jaroslav@842
|
2146 |
|
jaroslav@842
|
2147 |
private void generateNewArray(int atype, final StackMapper smapper) throws IOException, IllegalStateException {
|
jaroslav@842
|
2148 |
String jvmType;
|
jaroslav@842
|
2149 |
switch (atype) {
|
jaroslav@842
|
2150 |
case 4: jvmType = "[Z"; break;
|
jaroslav@842
|
2151 |
case 5: jvmType = "[C"; break;
|
jaroslav@842
|
2152 |
case 6: jvmType = "[F"; break;
|
jaroslav@842
|
2153 |
case 7: jvmType = "[D"; break;
|
jaroslav@842
|
2154 |
case 8: jvmType = "[B"; break;
|
jaroslav@842
|
2155 |
case 9: jvmType = "[S"; break;
|
jaroslav@842
|
2156 |
case 10: jvmType = "[I"; break;
|
jaroslav@842
|
2157 |
case 11: jvmType = "[J"; break;
|
jaroslav@842
|
2158 |
default: throw new IllegalStateException("Array type: " + atype);
|
jaroslav@842
|
2159 |
}
|
jaroslav@1513
|
2160 |
emit(smapper, this,
|
jaroslav@1532
|
2161 |
"var @2 = Array.prototype['newArray__Ljava_lang_Object_2ZLjava_lang_String_2Ljava_lang_Object_2I'](true, '@3', null, @1);",
|
jaroslav@842
|
2162 |
smapper.popI(), smapper.pushA(), jvmType);
|
jaroslav@842
|
2163 |
}
|
jaroslav@842
|
2164 |
|
jaroslav@842
|
2165 |
private void generateANewArray(int type, final StackMapper smapper) throws IOException {
|
jaroslav@842
|
2166 |
String typeName = jc.getClassName(type);
|
jaroslav@1532
|
2167 |
String ref = "null";
|
jaroslav@842
|
2168 |
if (typeName.startsWith("[")) {
|
jaroslav@1532
|
2169 |
typeName = "'[" + typeName + "'";
|
jaroslav@842
|
2170 |
} else {
|
jaroslav@1532
|
2171 |
ref = "vm." + mangleClassName(typeName);
|
jaroslav@1532
|
2172 |
typeName = "'[L" + typeName + ";'";
|
jaroslav@842
|
2173 |
}
|
jaroslav@1513
|
2174 |
emit(smapper, this,
|
jaroslav@1532
|
2175 |
"var @2 = Array.prototype['newArray__Ljava_lang_Object_2ZLjava_lang_String_2Ljava_lang_Object_2I'](false, @3, @4, @1);",
|
jaroslav@1532
|
2176 |
smapper.popI(), smapper.pushA(), typeName, ref);
|
jaroslav@842
|
2177 |
}
|
jaroslav@842
|
2178 |
|
jaroslav@842
|
2179 |
private int generateMultiANewArray(int type, final byte[] byteCodes, int i, final StackMapper smapper) throws IOException {
|
jaroslav@842
|
2180 |
String typeName = jc.getClassName(type);
|
jaroslav@842
|
2181 |
int dim = readUByte(byteCodes, ++i);
|
jaroslav@842
|
2182 |
StringBuilder dims = new StringBuilder();
|
jaroslav@842
|
2183 |
dims.append('[');
|
jaroslav@842
|
2184 |
for (int d = 0; d < dim; d++) {
|
jaroslav@842
|
2185 |
if (d != 0) {
|
jaroslav@842
|
2186 |
dims.insert(1, ",");
|
jaroslav@842
|
2187 |
}
|
jaroslav@842
|
2188 |
dims.insert(1, smapper.popI());
|
jaroslav@842
|
2189 |
}
|
jaroslav@842
|
2190 |
dims.append(']');
|
jaroslav@1535
|
2191 |
String fn = "null";
|
jaroslav@1535
|
2192 |
if (typeName.charAt(dim) == 'L') {
|
jaroslav@1535
|
2193 |
fn = "vm." + mangleClassName(typeName.substring(dim + 1, typeName.length() - 1));
|
jaroslav@1535
|
2194 |
}
|
jaroslav@1513
|
2195 |
emit(smapper, this,
|
jaroslav@1535
|
2196 |
"var @2 = Array.prototype['multiNewArray__Ljava_lang_Object_2Ljava_lang_String_2_3ILjava_lang_Object_2']('@3', @1, @4);",
|
jaroslav@1535
|
2197 |
dims.toString(), smapper.pushA(), typeName, fn
|
jaroslav@1535
|
2198 |
);
|
jaroslav@842
|
2199 |
return i;
|
jaroslav@842
|
2200 |
}
|
jaroslav@842
|
2201 |
|
jaroslav@843
|
2202 |
private int generateTableSwitch(int i, final byte[] byteCodes, final StackMapper smapper, int topMostLabel) throws IOException {
|
jaroslav@842
|
2203 |
int table = i / 4 * 4 + 4;
|
jaroslav@842
|
2204 |
int dflt = i + readInt4(byteCodes, table);
|
jaroslav@842
|
2205 |
table += 4;
|
jaroslav@842
|
2206 |
int low = readInt4(byteCodes, table);
|
jaroslav@842
|
2207 |
table += 4;
|
jaroslav@842
|
2208 |
int high = readInt4(byteCodes, table);
|
jaroslav@842
|
2209 |
table += 4;
|
jaroslav@1477
|
2210 |
final CharSequence swVar = smapper.popValue();
|
jaroslav@1509
|
2211 |
smapper.flush(this);
|
jaroslav@1509
|
2212 |
append("switch (").append(swVar).append(") {\n");
|
jaroslav@842
|
2213 |
while (low <= high) {
|
jaroslav@842
|
2214 |
int offset = i + readInt4(byteCodes, table);
|
jaroslav@842
|
2215 |
table += 4;
|
jaroslav@1509
|
2216 |
append(" case " + low).append(":"); goTo(this, i, offset, topMostLabel); append('\n');
|
jaroslav@842
|
2217 |
low++;
|
jaroslav@842
|
2218 |
}
|
jaroslav@1509
|
2219 |
append(" default: ");
|
jaroslav@1509
|
2220 |
goTo(this, i, dflt, topMostLabel);
|
jaroslav@1509
|
2221 |
append("\n}");
|
jaroslav@842
|
2222 |
i = table - 1;
|
jaroslav@842
|
2223 |
return i;
|
jaroslav@842
|
2224 |
}
|
jaroslav@842
|
2225 |
|
jaroslav@843
|
2226 |
private int generateLookupSwitch(int i, final byte[] byteCodes, final StackMapper smapper, int topMostLabel) throws IOException {
|
jaroslav@842
|
2227 |
int table = i / 4 * 4 + 4;
|
jaroslav@842
|
2228 |
int dflt = i + readInt4(byteCodes, table);
|
jaroslav@842
|
2229 |
table += 4;
|
jaroslav@842
|
2230 |
int n = readInt4(byteCodes, table);
|
jaroslav@842
|
2231 |
table += 4;
|
jaroslav@1477
|
2232 |
final CharSequence swVar = smapper.popValue();
|
jaroslav@1509
|
2233 |
smapper.flush(this);
|
jaroslav@1509
|
2234 |
append("switch (").append(swVar).append(") {\n");
|
jaroslav@842
|
2235 |
while (n-- > 0) {
|
jaroslav@842
|
2236 |
int cnstnt = readInt4(byteCodes, table);
|
jaroslav@842
|
2237 |
table += 4;
|
jaroslav@842
|
2238 |
int offset = i + readInt4(byteCodes, table);
|
jaroslav@842
|
2239 |
table += 4;
|
jaroslav@1509
|
2240 |
append(" case " + cnstnt).append(": "); goTo(this, i, offset, topMostLabel); append('\n');
|
jaroslav@842
|
2241 |
}
|
jaroslav@1509
|
2242 |
append(" default: ");
|
jaroslav@1509
|
2243 |
goTo(this, i, dflt, topMostLabel);
|
jaroslav@1509
|
2244 |
append("\n}");
|
jaroslav@842
|
2245 |
i = table - 1;
|
jaroslav@842
|
2246 |
return i;
|
jaroslav@842
|
2247 |
}
|
jaroslav@842
|
2248 |
|
jaroslav@842
|
2249 |
private void generateInstanceOf(int indx, final StackMapper smapper) throws IOException {
|
jaroslav@1534
|
2250 |
String type = jc.getClassName(indx);
|
jaroslav@842
|
2251 |
if (!type.startsWith("[")) {
|
jaroslav@1513
|
2252 |
emit(smapper, this,
|
jaroslav@1513
|
2253 |
"var @2 = @1 != null && @1['$instOf_@3'] ? 1 : 0;",
|
jaroslav@842
|
2254 |
smapper.popA(), smapper.pushI(),
|
jaroslav@842
|
2255 |
type.replace('/', '_'));
|
jaroslav@842
|
2256 |
} else {
|
jaroslav@1534
|
2257 |
int cnt = 0;
|
jaroslav@1534
|
2258 |
while (type.charAt(cnt) == '[') {
|
jaroslav@1534
|
2259 |
cnt++;
|
jaroslav@1534
|
2260 |
}
|
jaroslav@1534
|
2261 |
if (type.charAt(cnt) == 'L') {
|
jaroslav@1534
|
2262 |
type = "vm." + mangleClassName(type.substring(cnt + 1, type.length() - 1));
|
jaroslav@1534
|
2263 |
emit(smapper, this,
|
jaroslav@1534
|
2264 |
"var @2 = Array.prototype['isInstance__ZLjava_lang_Object_2ILjava_lang_Object_2'](@1, @4, @3);",
|
jaroslav@1534
|
2265 |
smapper.popA(), smapper.pushI(),
|
jaroslav@1534
|
2266 |
type, "" + cnt
|
jaroslav@1534
|
2267 |
);
|
jaroslav@1534
|
2268 |
} else {
|
jaroslav@1534
|
2269 |
emit(smapper, this,
|
jaroslav@1534
|
2270 |
"var @2 = Array.prototype['isInstance__ZLjava_lang_Object_2Ljava_lang_String_2'](@1, '@3');",
|
jaroslav@1534
|
2271 |
smapper.popA(), smapper.pushI(), type
|
jaroslav@1534
|
2272 |
);
|
jaroslav@1534
|
2273 |
}
|
jaroslav@842
|
2274 |
}
|
jaroslav@842
|
2275 |
}
|
jaroslav@842
|
2276 |
|
jaroslav@842
|
2277 |
private void generateCheckcast(int indx, final StackMapper smapper) throws IOException {
|
jaroslav@1534
|
2278 |
String type = jc.getClassName(indx);
|
jaroslav@842
|
2279 |
if (!type.startsWith("[")) {
|
jaroslav@1509
|
2280 |
emitNoFlush(smapper,
|
lubomir@1082
|
2281 |
"if (@1 !== null && !@1['$instOf_@2']) throw vm.java_lang_ClassCastException(true);",
|
jaroslav@1466
|
2282 |
smapper.getT(0, VarType.REFERENCE, false), type.replace('/', '_'));
|
jaroslav@842
|
2283 |
} else {
|
jaroslav@1534
|
2284 |
int cnt = 0;
|
jaroslav@1534
|
2285 |
while (type.charAt(cnt) == '[') {
|
jaroslav@1534
|
2286 |
cnt++;
|
jaroslav@1534
|
2287 |
}
|
jaroslav@1534
|
2288 |
if (type.charAt(cnt) == 'L') {
|
jaroslav@1534
|
2289 |
type = "vm." + mangleClassName(type.substring(cnt + 1, type.length() - 1));
|
jaroslav@1534
|
2290 |
emitNoFlush(smapper,
|
jaroslav@1534
|
2291 |
"if (@1 !== null && !Array.prototype['isInstance__ZLjava_lang_Object_2ILjava_lang_Object_2'](@1, @3, @2)) throw vm.java_lang_ClassCastException(true);",
|
jaroslav@1534
|
2292 |
smapper.getT(0, VarType.REFERENCE, false), type, "" + cnt
|
jaroslav@1534
|
2293 |
);
|
jaroslav@1534
|
2294 |
} else {
|
jaroslav@1534
|
2295 |
emitNoFlush(smapper,
|
jaroslav@1534
|
2296 |
"if (@1 !== null && !Array.prototype['isInstance__ZLjava_lang_Object_2Ljava_lang_String_2'](@1, '@2')) throw vm.java_lang_ClassCastException(true);",
|
jaroslav@1534
|
2297 |
smapper.getT(0, VarType.REFERENCE, false), type
|
jaroslav@1534
|
2298 |
);
|
jaroslav@1534
|
2299 |
}
|
jaroslav@842
|
2300 |
}
|
jaroslav@842
|
2301 |
}
|
jaroslav@842
|
2302 |
|
jaroslav@842
|
2303 |
private void generateByteCodeComment(int prev, int i, final byte[] byteCodes) throws IOException {
|
jaroslav@842
|
2304 |
for (int j = prev; j <= i; j++) {
|
jaroslav@1509
|
2305 |
append(" ");
|
jaroslav@842
|
2306 |
final int cc = readUByte(byteCodes, j);
|
jaroslav@1509
|
2307 |
append(Integer.toString(cc));
|
jaroslav@842
|
2308 |
}
|
jaroslav@842
|
2309 |
}
|
jaroslav@0
|
2310 |
}
|