|
1 | 1 | /* |
2 | 2 | * Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved. |
| 3 | + * Copyright (c) 2024, Alibaba Group Holding Limited. All Rights Reserved. |
3 | 4 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 | 5 | * |
5 | 6 | * This code is free software; you can redistribute it and/or modify it |
@@ -56,83 +57,125 @@ public static IllegalArgumentException cannotConvertException(TypeKind from, Typ |
56 | 57 |
|
57 | 58 | public static Opcode loadOpcode(TypeKind tk, int slot) { |
58 | 59 | return switch (tk) { |
59 | | - case INT, SHORT, BYTE, CHAR, BOOLEAN -> switch (slot) { |
60 | | - case 0 -> Opcode.ILOAD_0; |
61 | | - case 1 -> Opcode.ILOAD_1; |
62 | | - case 2 -> Opcode.ILOAD_2; |
63 | | - case 3 -> Opcode.ILOAD_3; |
64 | | - default -> (slot < 256) ? Opcode.ILOAD : Opcode.ILOAD_W; |
65 | | - }; |
66 | | - case LONG -> switch (slot) { |
67 | | - case 0 -> Opcode.LLOAD_0; |
68 | | - case 1 -> Opcode.LLOAD_1; |
69 | | - case 2 -> Opcode.LLOAD_2; |
70 | | - case 3 -> Opcode.LLOAD_3; |
71 | | - default -> (slot < 256) ? Opcode.LLOAD : Opcode.LLOAD_W; |
72 | | - }; |
73 | | - case DOUBLE -> switch (slot) { |
74 | | - case 0 -> Opcode.DLOAD_0; |
75 | | - case 1 -> Opcode.DLOAD_1; |
76 | | - case 2 -> Opcode.DLOAD_2; |
77 | | - case 3 -> Opcode.DLOAD_3; |
78 | | - default -> (slot < 256) ? Opcode.DLOAD : Opcode.DLOAD_W; |
79 | | - }; |
80 | | - case FLOAT -> switch (slot) { |
81 | | - case 0 -> Opcode.FLOAD_0; |
82 | | - case 1 -> Opcode.FLOAD_1; |
83 | | - case 2 -> Opcode.FLOAD_2; |
84 | | - case 3 -> Opcode.FLOAD_3; |
85 | | - default -> (slot < 256) ? Opcode.FLOAD : Opcode.FLOAD_W; |
86 | | - }; |
87 | | - case REFERENCE -> switch (slot) { |
88 | | - case 0 -> Opcode.ALOAD_0; |
89 | | - case 1 -> Opcode.ALOAD_1; |
90 | | - case 2 -> Opcode.ALOAD_2; |
91 | | - case 3 -> Opcode.ALOAD_3; |
92 | | - default -> (slot < 256) ? Opcode.ALOAD : Opcode.ALOAD_W; |
93 | | - }; |
94 | | - case VOID -> throw new IllegalArgumentException("void"); |
| 60 | + case INT, SHORT, BYTE, CHAR, BOOLEAN |
| 61 | + -> iload(slot); |
| 62 | + case LONG -> lload(slot); |
| 63 | + case DOUBLE -> dload(slot); |
| 64 | + case FLOAT -> fload(slot); |
| 65 | + case REFERENCE -> aload(slot); |
| 66 | + case VOID -> throw new IllegalArgumentException("void"); |
| 67 | + }; |
| 68 | + } |
| 69 | + |
| 70 | + public static Opcode aload(int slot) { |
| 71 | + return switch (slot) { |
| 72 | + case 0 -> Opcode.ALOAD_0; |
| 73 | + case 1 -> Opcode.ALOAD_1; |
| 74 | + case 2 -> Opcode.ALOAD_2; |
| 75 | + case 3 -> Opcode.ALOAD_3; |
| 76 | + default -> (slot < 256) ? Opcode.ALOAD : Opcode.ALOAD_W; |
| 77 | + }; |
| 78 | + } |
| 79 | + |
| 80 | + public static Opcode fload(int slot) { |
| 81 | + return switch (slot) { |
| 82 | + case 0 -> Opcode.FLOAD_0; |
| 83 | + case 1 -> Opcode.FLOAD_1; |
| 84 | + case 2 -> Opcode.FLOAD_2; |
| 85 | + case 3 -> Opcode.FLOAD_3; |
| 86 | + default -> (slot < 256) ? Opcode.FLOAD : Opcode.FLOAD_W; |
| 87 | + }; |
| 88 | + } |
| 89 | + |
| 90 | + public static Opcode dload(int slot) { |
| 91 | + return switch (slot) { |
| 92 | + case 0 -> Opcode.DLOAD_0; |
| 93 | + case 1 -> Opcode.DLOAD_1; |
| 94 | + case 2 -> Opcode.DLOAD_2; |
| 95 | + case 3 -> Opcode.DLOAD_3; |
| 96 | + default -> (slot < 256) ? Opcode.DLOAD : Opcode.DLOAD_W; |
| 97 | + }; |
| 98 | + } |
| 99 | + |
| 100 | + public static Opcode lload(int slot) { |
| 101 | + return switch (slot) { |
| 102 | + case 0 -> Opcode.LLOAD_0; |
| 103 | + case 1 -> Opcode.LLOAD_1; |
| 104 | + case 2 -> Opcode.LLOAD_2; |
| 105 | + case 3 -> Opcode.LLOAD_3; |
| 106 | + default -> (slot < 256) ? Opcode.LLOAD : Opcode.LLOAD_W; |
| 107 | + }; |
| 108 | + } |
| 109 | + |
| 110 | + public static Opcode iload(int slot) { |
| 111 | + return switch (slot) { |
| 112 | + case 0 -> Opcode.ILOAD_0; |
| 113 | + case 1 -> Opcode.ILOAD_1; |
| 114 | + case 2 -> Opcode.ILOAD_2; |
| 115 | + case 3 -> Opcode.ILOAD_3; |
| 116 | + default -> (slot < 256) ? Opcode.ILOAD : Opcode.ILOAD_W; |
95 | 117 | }; |
96 | 118 | } |
97 | 119 |
|
98 | 120 | public static Opcode storeOpcode(TypeKind tk, int slot) { |
99 | 121 | return switch (tk) { |
100 | | - case INT, SHORT, BYTE, CHAR, BOOLEAN -> switch (slot) { |
101 | | - case 0 -> Opcode.ISTORE_0; |
102 | | - case 1 -> Opcode.ISTORE_1; |
103 | | - case 2 -> Opcode.ISTORE_2; |
104 | | - case 3 -> Opcode.ISTORE_3; |
105 | | - default -> (slot < 256) ? Opcode.ISTORE : Opcode.ISTORE_W; |
106 | | - }; |
107 | | - case LONG -> switch (slot) { |
108 | | - case 0 -> Opcode.LSTORE_0; |
109 | | - case 1 -> Opcode.LSTORE_1; |
110 | | - case 2 -> Opcode.LSTORE_2; |
111 | | - case 3 -> Opcode.LSTORE_3; |
112 | | - default -> (slot < 256) ? Opcode.LSTORE : Opcode.LSTORE_W; |
113 | | - }; |
114 | | - case DOUBLE -> switch (slot) { |
115 | | - case 0 -> Opcode.DSTORE_0; |
116 | | - case 1 -> Opcode.DSTORE_1; |
117 | | - case 2 -> Opcode.DSTORE_2; |
118 | | - case 3 -> Opcode.DSTORE_3; |
119 | | - default -> (slot < 256) ? Opcode.DSTORE : Opcode.DSTORE_W; |
120 | | - }; |
121 | | - case FLOAT -> switch (slot) { |
122 | | - case 0 -> Opcode.FSTORE_0; |
123 | | - case 1 -> Opcode.FSTORE_1; |
124 | | - case 2 -> Opcode.FSTORE_2; |
125 | | - case 3 -> Opcode.FSTORE_3; |
126 | | - default -> (slot < 256) ? Opcode.FSTORE : Opcode.FSTORE_W; |
127 | | - }; |
128 | | - case REFERENCE -> switch (slot) { |
129 | | - case 0 -> Opcode.ASTORE_0; |
130 | | - case 1 -> Opcode.ASTORE_1; |
131 | | - case 2 -> Opcode.ASTORE_2; |
132 | | - case 3 -> Opcode.ASTORE_3; |
133 | | - default -> (slot < 256) ? Opcode.ASTORE : Opcode.ASTORE_W; |
134 | | - }; |
135 | | - case VOID -> throw new IllegalArgumentException("void"); |
| 122 | + case INT, SHORT, BYTE, CHAR, BOOLEAN |
| 123 | + -> istore(slot); |
| 124 | + case LONG -> lstore(slot); |
| 125 | + case DOUBLE -> dstore(slot); |
| 126 | + case FLOAT -> fstore(slot); |
| 127 | + case REFERENCE -> astore(slot); |
| 128 | + case VOID -> throw new IllegalArgumentException("void"); |
| 129 | + }; |
| 130 | + } |
| 131 | + |
| 132 | + public static Opcode astore(int slot) { |
| 133 | + return switch (slot) { |
| 134 | + case 0 -> Opcode.ASTORE_0; |
| 135 | + case 1 -> Opcode.ASTORE_1; |
| 136 | + case 2 -> Opcode.ASTORE_2; |
| 137 | + case 3 -> Opcode.ASTORE_3; |
| 138 | + default -> (slot < 256) ? Opcode.ASTORE : Opcode.ASTORE_W; |
| 139 | + }; |
| 140 | + } |
| 141 | + |
| 142 | + public static Opcode fstore(int slot) { |
| 143 | + return switch (slot) { |
| 144 | + case 0 -> Opcode.FSTORE_0; |
| 145 | + case 1 -> Opcode.FSTORE_1; |
| 146 | + case 2 -> Opcode.FSTORE_2; |
| 147 | + case 3 -> Opcode.FSTORE_3; |
| 148 | + default -> (slot < 256) ? Opcode.FSTORE : Opcode.FSTORE_W; |
| 149 | + }; |
| 150 | + } |
| 151 | + |
| 152 | + public static Opcode dstore(int slot) { |
| 153 | + return switch (slot) { |
| 154 | + case 0 -> Opcode.DSTORE_0; |
| 155 | + case 1 -> Opcode.DSTORE_1; |
| 156 | + case 2 -> Opcode.DSTORE_2; |
| 157 | + case 3 -> Opcode.DSTORE_3; |
| 158 | + default -> (slot < 256) ? Opcode.DSTORE : Opcode.DSTORE_W; |
| 159 | + }; |
| 160 | + } |
| 161 | + |
| 162 | + public static Opcode lstore(int slot) { |
| 163 | + return switch (slot) { |
| 164 | + case 0 -> Opcode.LSTORE_0; |
| 165 | + case 1 -> Opcode.LSTORE_1; |
| 166 | + case 2 -> Opcode.LSTORE_2; |
| 167 | + case 3 -> Opcode.LSTORE_3; |
| 168 | + default -> (slot < 256) ? Opcode.LSTORE : Opcode.LSTORE_W; |
| 169 | + }; |
| 170 | + } |
| 171 | + |
| 172 | + public static Opcode istore(int slot) { |
| 173 | + return switch (slot) { |
| 174 | + case 0 -> Opcode.ISTORE_0; |
| 175 | + case 1 -> Opcode.ISTORE_1; |
| 176 | + case 2 -> Opcode.ISTORE_2; |
| 177 | + case 3 -> Opcode.ISTORE_3; |
| 178 | + default -> (slot < 256) ? Opcode.ISTORE : Opcode.ISTORE_W; |
136 | 179 | }; |
137 | 180 | } |
138 | 181 |
|
|
0 commit comments