2 * Back 2 Browser Bytecode Translator
3 * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 2 of the License.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. Look for COPYING file in the top folder.
16 * If not, see http://opensource.org/licenses/GPL-2.0.
18 package org.apidesign.vm4brwsr;
20 import org.apidesign.javap.RuntimeConstants;
23 public static final int INTEGER = 0;
24 public static final int LONG = 1;
25 public static final int FLOAT = 2;
26 public static final int DOUBLE = 3;
27 public static final int REFERENCE = 4;
29 public static final int LAST = REFERENCE;
34 public static boolean isCategory2(final int varType) {
35 return (varType == LONG) || (varType == DOUBLE);
38 public static int fromStackMapType(final int smType) {
39 switch (smType & 0xff) {
40 case RuntimeConstants.ITEM_Integer:
41 return VarType.INTEGER;
42 case RuntimeConstants.ITEM_Float:
44 case RuntimeConstants.ITEM_Double:
45 return VarType.DOUBLE;
46 case RuntimeConstants.ITEM_Long:
48 case RuntimeConstants.ITEM_Null:
49 case RuntimeConstants.ITEM_InitObject:
50 case RuntimeConstants.ITEM_Object:
51 case RuntimeConstants.ITEM_NewObject:
52 return VarType.REFERENCE;
54 case RuntimeConstants.ITEM_Bogus:
55 /* unclear how to handle for now */
57 throw new IllegalStateException("Unhandled stack map type");
61 public static int fromConstantType(final byte constantTag) {
62 switch (constantTag) {
63 case RuntimeConstants.CONSTANT_INTEGER:
64 return VarType.INTEGER;
65 case RuntimeConstants.CONSTANT_FLOAT:
67 case RuntimeConstants.CONSTANT_LONG:
69 case RuntimeConstants.CONSTANT_DOUBLE:
70 return VarType.DOUBLE;
72 case RuntimeConstants.CONSTANT_CLASS:
73 case RuntimeConstants.CONSTANT_UTF8:
74 case RuntimeConstants.CONSTANT_UNICODE:
75 case RuntimeConstants.CONSTANT_STRING:
76 return VarType.REFERENCE;
78 case RuntimeConstants.CONSTANT_FIELD:
79 case RuntimeConstants.CONSTANT_METHOD:
80 case RuntimeConstants.CONSTANT_INTERFACEMETHOD:
81 case RuntimeConstants.CONSTANT_NAMEANDTYPE:
82 /* unclear how to handle for now */
84 throw new IllegalStateException("Unhandled constant tag");
88 public static int fromFieldType(final char fieldType) {
95 return VarType.INTEGER;
101 return VarType.DOUBLE;
104 return VarType.REFERENCE;
107 throw new IllegalStateException("Unhandled field type");