jvm_assembler/program/instructions.rs
1/// JVM instruction enumeration
2#[derive(Debug, Clone, PartialEq, Eq, Hash)]
3pub enum JvmInstruction {
4 /// No operation
5 Nop,
6 /// Push null onto the stack
7 AconstNull,
8 /// Push int constant -1 onto the stack
9 IconstM1,
10 /// Push int constant 0 onto the stack
11 Iconst0,
12 /// Push int constant 1 onto the stack
13 Iconst1,
14 /// Push int constant 2 onto the stack
15 Iconst2,
16 /// Push int constant 3 onto the stack
17 Iconst3,
18 /// Push int constant 4 onto the stack
19 Iconst4,
20 /// Push int constant 5 onto the stack
21 Iconst5,
22 /// Push long constant 0 onto the stack
23 Lconst0,
24 /// Push long constant 1 onto the stack
25 Lconst1,
26 /// Push float constant 0 onto the stack
27 Fconst0,
28 /// Push float constant 1 onto the stack
29 Fconst1,
30 /// Push float constant 2 onto the stack
31 Fconst2,
32 /// Push double constant 0 onto the stack
33 Dconst0,
34 /// Push double constant 1 onto the stack
35 Dconst1,
36
37 /// Push byte constant onto the stack
38 Bipush {
39 /// The value
40 value: i8,
41 },
42 /// Push short constant onto the stack
43 Sipush {
44 /// The value
45 value: i16,
46 },
47
48 /// Push item from constant pool (int, float, or String)
49 Ldc {
50 /// The symbol name in the pool
51 symbol: String,
52 },
53 /// Push item from constant pool (wide index)
54 LdcW {
55 /// The symbol name in the pool
56 symbol: String,
57 },
58 /// Push long or double from constant pool (wide index)
59 Ldc2W {
60 /// The symbol name in the pool
61 symbol: String,
62 },
63
64 /// Load int from local variable
65 Iload {
66 /// Variable index
67 index: u16,
68 },
69 /// Load int from local variable 0
70 Iload0,
71 /// Load int from local variable 1
72 Iload1,
73 /// Load int from local variable 2
74 Iload2,
75 /// Load int from local variable 3
76 Iload3,
77
78 /// Load long from local variable
79 Lload {
80 /// Variable index
81 index: u16,
82 },
83 /// Load long from local variable 0
84 Lload0,
85 /// Load long from local variable 1
86 Lload1,
87 /// Load long from local variable 2
88 Lload2,
89 /// Load long from local variable 3
90 Lload3,
91
92 /// Load float from local variable
93 Fload {
94 /// Variable index
95 index: u16,
96 },
97 /// Load float from local variable 0
98 Fload0,
99 /// Load float from local variable 1
100 Fload1,
101 /// Load float from local variable 2
102 Fload2,
103 /// Load float from local variable 3
104 Fload3,
105
106 /// Load double from local variable
107 Dload {
108 /// Variable index
109 index: u16,
110 },
111 /// Load double from local variable 0
112 Dload0,
113 /// Load double from local variable 1
114 Dload1,
115 /// Load double from local variable 2
116 Dload2,
117 /// Load double from local variable 3
118 Dload3,
119
120 /// Load reference from local variable
121 Aload {
122 /// Variable index
123 index: u16,
124 },
125 /// Load reference from local variable 0
126 Aload0,
127 /// Load reference from local variable 1
128 Aload1,
129 /// Load reference from local variable 2
130 Aload2,
131 /// Load reference from local variable 3
132 Aload3,
133
134 /// Load int from array
135 Iaload,
136 /// Load long from array
137 Laload,
138 /// Load float from array
139 Faload,
140 /// Load double from array
141 Daload,
142 /// Load reference from array
143 Aaload,
144 /// Load byte or boolean from array
145 Baload,
146 /// Load char from array
147 Caload,
148 /// Load short from array
149 Saload,
150
151 /// Store int into local variable
152 Istore {
153 /// Variable index
154 index: u16,
155 },
156 /// Store int into local variable 0
157 Istore0,
158 /// Store int into local variable 1
159 Istore1,
160 /// Store int into local variable 2
161 Istore2,
162 /// Store int into local variable 3
163 Istore3,
164
165 /// Store long into local variable
166 Lstore {
167 /// Variable index
168 index: u16,
169 },
170 /// Store long into local variable 0
171 Lstore0,
172 /// Store long into local variable 1
173 Lstore1,
174 /// Store long into local variable 2
175 Lstore2,
176 /// Store long into local variable 3
177 Lstore3,
178
179 /// Store float into local variable
180 Fstore {
181 /// Variable index
182 index: u16,
183 },
184 /// Store float into local variable 0
185 Fstore0,
186 /// Store float into local variable 1
187 Fstore1,
188 /// Store float into local variable 2
189 Fstore2,
190 /// Store float into local variable 3
191 Fstore3,
192
193 /// Store double into local variable
194 Dstore {
195 /// Variable index
196 index: u16,
197 },
198 /// Store double into local variable 0
199 Dstore0,
200 /// Store double into local variable 1
201 Dstore1,
202 /// Store double into local variable 2
203 Dstore2,
204 /// Store double into local variable 3
205 Dstore3,
206
207 /// Store reference into local variable
208 Astore {
209 /// Variable index
210 index: u16,
211 },
212 /// Store reference into local variable 0
213 Astore0,
214 /// Store reference into local variable 1
215 Astore1,
216 /// Store reference into local variable 2
217 Astore2,
218 /// Store reference into local variable 3
219 Astore3,
220
221 /// Store int into array
222 Iastore,
223 /// Store long into array
224 Lastore,
225 /// Store float into array
226 Fastore,
227 /// Store double into array
228 Dastore,
229 /// Store reference into array
230 Aastore,
231 /// Store byte or boolean into array
232 Bastore,
233 /// Store char into array
234 Castore,
235 /// Store short into array
236 Sastore,
237
238 /// Pop top operand stack value
239 Pop,
240 /// Pop top two operand stack values
241 Pop2,
242 /// Duplicate top operand stack value
243 Dup,
244 /// Duplicate top operand stack value and insert two values down
245 DupX1,
246 /// Duplicate top operand stack value and insert three values down
247 DupX2,
248 /// Duplicate top two operand stack values
249 Dup2,
250 /// Duplicate top two operand stack values and insert three values down
251 Dup2X1,
252 /// Duplicate top two operand stack values and insert four values down
253 Dup2X2,
254 /// Swap top two operand stack values
255 Swap,
256
257 /// Add int
258 Iadd,
259 /// Add long
260 Ladd,
261 /// Add float
262 Fadd,
263 /// Add double
264 Dadd,
265 /// Subtract int
266 Isub,
267 /// Subtract long
268 Lsub,
269 /// Subtract float
270 Fsub,
271 /// Subtract double
272 Dsub,
273 /// Multiply int
274 Imul,
275 /// Multiply long
276 Lmul,
277 /// Multiply float
278 Fmul,
279 /// Multiply double
280 Dmul,
281 /// Divide int
282 Idiv,
283 /// Divide long
284 Ldiv,
285 /// Divide float
286 Fdiv,
287 /// Divide double
288 Ddiv,
289 /// Remainder int
290 Irem,
291 /// Remainder long
292 Lrem,
293 /// Remainder float
294 Frem,
295 /// Remainder double
296 Drem,
297 /// Negate int
298 Ineg,
299 /// Negate long
300 Lneg,
301 /// Negate float
302 Fneg,
303 /// Negate double
304 Dneg,
305
306 /// Shift left int
307 Ishl,
308 /// Shift left long
309 Lshl,
310 /// Arithmetic shift right int
311 Ishr,
312 /// Arithmetic shift right long
313 Lshr,
314 /// Logical shift right int
315 Iushr,
316 /// Logical shift right long
317 Lushr,
318 /// Bitwise AND int
319 Iand,
320 /// Bitwise AND long
321 Land,
322 /// Bitwise OR int
323 Ior,
324 /// Bitwise OR long
325 Lor,
326 /// Bitwise XOR int
327 Ixor,
328 /// Bitwise XOR long
329 Lxor,
330
331 /// Increment local variable by constant
332 Iinc {
333 /// Variable index
334 index: u16,
335 /// Increment value
336 value: i16,
337 },
338
339 /// Convert int to long
340 I2l,
341 /// Convert int to float
342 I2f,
343 /// Convert int to double
344 I2d,
345 /// Convert long to int
346 L2i,
347 /// Convert long to float
348 L2f,
349 /// Convert long to double
350 L2d,
351 /// Convert float to int
352 F2i,
353 /// Convert float to long
354 F2l,
355 /// Convert float to double
356 F2d,
357 /// Convert double to int
358 D2i,
359 /// Convert double to long
360 D2l,
361 /// Convert double to float
362 D2f,
363 /// Convert int to byte
364 I2b,
365 /// Convert int to char
366 I2c,
367 /// Convert int to short
368 I2s,
369
370 /// Compare long
371 Lcmp,
372 /// Compare float (less than returns -1)
373 Fcmpl,
374 /// Compare float (greater than returns 1)
375 Fcmpg,
376 /// Compare double (less than returns -1)
377 Dcmpl,
378 /// Compare double (greater than returns 1)
379 Dcmpg,
380
381 /// Jump if zero
382 Ifeq {
383 /// Target label
384 target: String,
385 },
386 /// Jump if not zero
387 Ifne {
388 /// Target label
389 target: String,
390 },
391 /// Jump if less than zero
392 Iflt {
393 /// Target label
394 target: String,
395 },
396 /// Jump if greater than or equal to zero
397 Ifge {
398 /// Target label
399 target: String,
400 },
401 /// Jump if greater than zero
402 Ifgt {
403 /// Target label
404 target: String,
405 },
406 /// Jump if less than or equal to zero
407 Ifle {
408 /// Target label
409 target: String,
410 },
411 /// Jump if int comparison succeeds (equal)
412 IfIcmpeq {
413 /// Target label
414 target: String,
415 },
416 /// Jump if int comparison succeeds (not equal)
417 IfIcmpne {
418 /// Target label
419 target: String,
420 },
421 /// Jump if int comparison succeeds (less than)
422 IfIcmplt {
423 /// Target label
424 target: String,
425 },
426 /// Jump if int comparison succeeds (greater than or equal)
427 IfIcmpge {
428 /// Target label
429 target: String,
430 },
431 /// Jump if int comparison succeeds (greater than)
432 IfIcmpgt {
433 /// Target label
434 target: String,
435 },
436 /// Jump if int comparison succeeds (less than or equal)
437 IfIcmple {
438 /// Target label
439 target: String,
440 },
441 /// Jump if reference comparison succeeds (equal)
442 IfAcmpeq {
443 /// Target label
444 target: String,
445 },
446 /// Jump if reference comparison succeeds (not equal)
447 IfAcmpne {
448 /// Target label
449 target: String,
450 },
451
452 /// Unconditional jump
453 Goto {
454 /// Target label
455 target: String,
456 },
457 /// Jump to subroutine (deprecated)
458 Jsr {
459 /// Target label
460 target: String,
461 },
462 /// Return from subroutine (deprecated)
463 Ret {
464 /// Variable index
465 index: u16,
466 },
467
468 /// Jump index into table and jump
469 Tableswitch {
470 /// Default target label
471 default: String,
472 /// Low key value
473 low: i32,
474 /// High key value
475 high: i32,
476 /// Jump offsets labels
477 offsets: Vec<String>,
478 },
479 /// Match key in table and jump
480 Lookupswitch {
481 /// Default target label
482 default: String,
483 /// Number of pairs
484 npairs: i32,
485 /// Match value and target label pairs
486 match_offsets: Vec<(i32, String)>,
487 },
488
489 /// Return int from method
490 Ireturn,
491 /// Return long from method
492 Lreturn,
493 /// Return float from method
494 Freturn,
495 /// Return double from method
496 Dreturn,
497 /// Return reference from method
498 Areturn,
499 /// Return void from method
500 Return,
501
502 /// Get static field from class
503 Getstatic {
504 /// Class name
505 class_name: String,
506 /// Field name
507 field_name: String,
508 /// Field descriptor
509 descriptor: String,
510 },
511 /// Set static field in class
512 Putstatic {
513 /// Class name
514 class_name: String,
515 /// Field name
516 field_name: String,
517 /// Field descriptor
518 descriptor: String,
519 },
520 /// Get field from object
521 Getfield {
522 /// Class name
523 class_name: String,
524 /// Field name
525 field_name: String,
526 /// Field descriptor
527 descriptor: String,
528 },
529 /// Set field in object
530 Putfield {
531 /// Class name
532 class_name: String,
533 /// Field name
534 field_name: String,
535 /// Field descriptor
536 descriptor: String,
537 },
538
539 /// Invoke instance method; dispatch based on class
540 Invokevirtual {
541 /// Class name
542 class_name: String,
543 /// Method name
544 method_name: String,
545 /// Method descriptor
546 descriptor: String,
547 },
548 /// Invoke instance method; special handling for superclass, private, and instance initialization method invocations
549 Invokespecial {
550 /// Class name
551 class_name: String,
552 /// Method name
553 method_name: String,
554 /// Method descriptor
555 descriptor: String,
556 },
557 /// Invoke a class (static) method
558 Invokestatic {
559 /// Class name
560 class_name: String,
561 /// Method name
562 method_name: String,
563 /// Method descriptor
564 descriptor: String,
565 },
566 /// Invoke interface method
567 Invokeinterface {
568 /// Class name
569 class_name: String,
570 /// Method name
571 method_name: String,
572 /// Method descriptor
573 descriptor: String,
574 },
575 /// Invoke dynamic method
576 Invokedynamic {
577 /// Class name
578 class_name: String,
579 /// Method name
580 method_name: String,
581 /// Method descriptor
582 descriptor: String,
583 },
584
585 /// Create new object
586 New {
587 /// Class name
588 class_name: String,
589 },
590 /// Create new array of primitive type
591 Newarray {
592 /// Type code
593 type_code: u8,
594 },
595 /// Create new array of reference type
596 Anewarray {
597 /// Class name
598 class_name: String,
599 },
600 /// Get length of array
601 Arraylength,
602 /// Throw exception or error
603 Athrow,
604 /// Check whether object is of given type
605 Checkcast {
606 /// Class name
607 class_name: String,
608 },
609 /// Determine if object is of given type
610 Instanceof {
611 /// Class name
612 class_name: String,
613 },
614 /// Enter monitor for object
615 Monitorenter,
616 /// Exit monitor for object
617 Monitorexit,
618
619 /// Extend local variable index by additional bytes
620 Wide,
621 /// Create new multidimensional array
622 Multianewarray {
623 /// Class name
624 class_name: String,
625 /// Number of dimensions
626 dimensions: u8,
627 },
628 /// Jump if reference is null
629 Ifnull {
630 /// Target label
631 target: String,
632 },
633 /// Jump if reference is not null
634 Ifnonnull {
635 /// Target label
636 target: String,
637 },
638 /// Unconditional jump (wide index)
639 GotoW {
640 /// Target label
641 target: String,
642 },
643 /// Jump to subroutine (wide index)
644 JsrW {
645 /// Target label
646 target: String,
647 },
648
649 /// Label (pseudo-instruction, does not generate bytecode)
650 Label {
651 /// Label name
652 name: String,
653 },
654}