30 sealed partial class ClassFile
33 internal sealed partial class Method
43 private SwitchEntry[] switch_entries;
51 internal void SetHardError(
HardError error,
int messageId)
66 internal int HandlerIndex
68 get {
return (ushort)arg2; }
71 internal int HardErrorMessageId
97 internal void SetPC(
int pc)
102 internal void SetTargetIndex(
int targetIndex)
104 this.arg1 = targetIndex;
107 internal void SetTermNop(ushort pc)
114 internal void MapSwitchTargets(
int[] pcIndexMap)
116 arg1 = pcIndexMap[arg1 + pc];
117 for (
int i = 0; i < switch_entries.Length; i++)
119 switch_entries[i].target = pcIndexMap[switch_entries[i].target + pc];
123 internal void Read(
IKVM.ByteCode.Decoding.Instruction instruction, ClassFile classFile)
125 this.pc = (ushort)instruction.Offset;
129 switch (instruction.OpCode)
131 case IKVM.ByteCode.OpCode.Nop:
133 case IKVM.ByteCode.OpCode.AconstNull:
135 case IKVM.ByteCode.OpCode.IconstM1:
137 case IKVM.ByteCode.OpCode.Iconst0:
139 case IKVM.ByteCode.OpCode.Iconst1:
141 case IKVM.ByteCode.OpCode.Iconst2:
143 case IKVM.ByteCode.OpCode.Iconst3:
145 case IKVM.ByteCode.OpCode.Iconst4:
147 case IKVM.ByteCode.OpCode.Iconst5:
149 case IKVM.ByteCode.OpCode.Lconst0:
151 case IKVM.ByteCode.OpCode.Lconst1:
153 case IKVM.ByteCode.OpCode.Fconst0:
155 case IKVM.ByteCode.OpCode.Fconst1:
157 case IKVM.ByteCode.OpCode.Fconst2:
159 case IKVM.ByteCode.OpCode.Dconst0:
161 case IKVM.ByteCode.OpCode.Dconst1:
163 case IKVM.ByteCode.OpCode.Bipush:
164 var _bipush = instruction.AsBipush();
165 arg1 = _bipush.Value;
167 case IKVM.ByteCode.OpCode.Sipush:
168 var _sipush = instruction.AsSipush();
169 arg1 = _sipush.Value;
171 case IKVM.ByteCode.OpCode.Ldc:
172 var _ldc = instruction.AsLdc();
173 arg1 = _ldc.Constant.Slot;
174 classFile.MarkLinkRequiredConstantPoolItem(arg1);
176 case IKVM.ByteCode.OpCode.LdcW:
177 var _ldcw = instruction.AsLdcW();
178 arg1 = _ldcw.Constant.Slot;
179 classFile.MarkLinkRequiredConstantPoolItem(arg1);
181 case IKVM.ByteCode.OpCode.Ldc2W:
182 var _ldc2w = instruction.AsLdc2W();
183 arg1 = _ldc2w.Constant.Slot;
184 classFile.MarkLinkRequiredConstantPoolItem(arg1);
186 case IKVM.ByteCode.OpCode.Iload:
187 var _iload = instruction.AsIload();
190 case IKVM.ByteCode.OpCode.Lload:
191 var _lload = instruction.AsLload();
194 case IKVM.ByteCode.OpCode.Fload:
195 var _fload = instruction.AsFload();
198 case IKVM.ByteCode.OpCode.Dload:
199 var _dload = instruction.AsDload();
202 case IKVM.ByteCode.OpCode.Aload:
203 var _aload = instruction.AsAload();
206 case IKVM.ByteCode.OpCode.Iload0:
208 case IKVM.ByteCode.OpCode.Iload1:
210 case IKVM.ByteCode.OpCode.Iload2:
212 case IKVM.ByteCode.OpCode.Iload3:
214 case IKVM.ByteCode.OpCode.Lload0:
216 case IKVM.ByteCode.OpCode.Lload1:
218 case IKVM.ByteCode.OpCode.Lload2:
220 case IKVM.ByteCode.OpCode.Lload3:
222 case IKVM.ByteCode.OpCode.Fload0:
224 case IKVM.ByteCode.OpCode.Fload1:
226 case IKVM.ByteCode.OpCode.Fload2:
228 case IKVM.ByteCode.OpCode.Fload3:
230 case IKVM.ByteCode.OpCode.Dload0:
232 case IKVM.ByteCode.OpCode.Dload1:
234 case IKVM.ByteCode.OpCode.Dload2:
236 case IKVM.ByteCode.OpCode.Dload3:
238 case IKVM.ByteCode.OpCode.Aload0:
240 case IKVM.ByteCode.OpCode.Aload1:
242 case IKVM.ByteCode.OpCode.Aload2:
244 case IKVM.ByteCode.OpCode.Aload3:
246 case IKVM.ByteCode.OpCode.Iaload:
248 case IKVM.ByteCode.OpCode.Laload:
250 case IKVM.ByteCode.OpCode.Faload:
252 case IKVM.ByteCode.OpCode.Daload:
254 case IKVM.ByteCode.OpCode.Aaload:
256 case IKVM.ByteCode.OpCode.Baload:
258 case IKVM.ByteCode.OpCode.Caload:
260 case IKVM.ByteCode.OpCode.Saload:
262 case IKVM.ByteCode.OpCode.Istore:
263 var _istore = instruction.AsIstore();
264 arg1 = _istore.Local;
266 case IKVM.ByteCode.OpCode.Lstore:
267 var _lstore = instruction.AsLstore();
268 arg1 = _lstore.Local;
270 case IKVM.ByteCode.OpCode.Fstore:
271 var _fstore = instruction.AsFstore();
272 arg1 = _fstore.Local;
274 case IKVM.ByteCode.OpCode.Dstore:
275 var _dstore = instruction.AsDstore();
276 arg1 = _dstore.Local;
278 case IKVM.ByteCode.OpCode.Astore:
279 var _astore = instruction.AsAstore();
280 arg1 = _astore.Local;
282 case IKVM.ByteCode.OpCode.Istore0:
284 case IKVM.ByteCode.OpCode.Istore1:
286 case IKVM.ByteCode.OpCode.Istore2:
288 case IKVM.ByteCode.OpCode.Istore3:
290 case IKVM.ByteCode.OpCode.Lstore0:
292 case IKVM.ByteCode.OpCode.Lstore1:
294 case IKVM.ByteCode.OpCode.Lstore2:
296 case IKVM.ByteCode.OpCode.Lstore3:
298 case IKVM.ByteCode.OpCode.Fstore0:
300 case IKVM.ByteCode.OpCode.Fstore1:
302 case IKVM.ByteCode.OpCode.Fstore2:
304 case IKVM.ByteCode.OpCode.Fstore3:
306 case IKVM.ByteCode.OpCode.Dstore0:
308 case IKVM.ByteCode.OpCode.Dstore1:
310 case IKVM.ByteCode.OpCode.Dstore2:
312 case IKVM.ByteCode.OpCode.Dstore3:
314 case IKVM.ByteCode.OpCode.Astore0:
316 case IKVM.ByteCode.OpCode.Astore1:
318 case IKVM.ByteCode.OpCode.Astore2:
320 case IKVM.ByteCode.OpCode.Astore3:
322 case IKVM.ByteCode.OpCode.Iastore:
324 case IKVM.ByteCode.OpCode.Lastore:
326 case IKVM.ByteCode.OpCode.Fastore:
328 case IKVM.ByteCode.OpCode.Dastore:
330 case IKVM.ByteCode.OpCode.Aastore:
332 case IKVM.ByteCode.OpCode.Bastore:
334 case IKVM.ByteCode.OpCode.Castore:
336 case IKVM.ByteCode.OpCode.Sastore:
338 case IKVM.ByteCode.OpCode.Pop:
340 case IKVM.ByteCode.OpCode.Pop2:
342 case IKVM.ByteCode.OpCode.Dup:
344 case IKVM.ByteCode.OpCode.DupX1:
346 case IKVM.ByteCode.OpCode.DupX2:
348 case IKVM.ByteCode.OpCode.Dup2:
350 case IKVM.ByteCode.OpCode.Dup2X1:
352 case IKVM.ByteCode.OpCode.Dup2X2:
354 case IKVM.ByteCode.OpCode.Swap:
356 case IKVM.ByteCode.OpCode.Iadd:
358 case IKVM.ByteCode.OpCode.Ladd:
360 case IKVM.ByteCode.OpCode.Fadd:
362 case IKVM.ByteCode.OpCode.Dadd:
364 case IKVM.ByteCode.OpCode.Isub:
366 case IKVM.ByteCode.OpCode.Lsub:
368 case IKVM.ByteCode.OpCode.Fsub:
370 case IKVM.ByteCode.OpCode.Dsub:
372 case IKVM.ByteCode.OpCode.Imul:
374 case IKVM.ByteCode.OpCode.Lmul:
376 case IKVM.ByteCode.OpCode.Fmul:
378 case IKVM.ByteCode.OpCode.Dmul:
380 case IKVM.ByteCode.OpCode.Idiv:
382 case IKVM.ByteCode.OpCode.Ldiv:
384 case IKVM.ByteCode.OpCode.Fdiv:
386 case IKVM.ByteCode.OpCode.Ddiv:
388 case IKVM.ByteCode.OpCode.Irem:
390 case IKVM.ByteCode.OpCode.Lrem:
392 case IKVM.ByteCode.OpCode.Frem:
394 case IKVM.ByteCode.OpCode.Drem:
396 case IKVM.ByteCode.OpCode.Ineg:
398 case IKVM.ByteCode.OpCode.Lneg:
400 case IKVM.ByteCode.OpCode.Fneg:
402 case IKVM.ByteCode.OpCode.Dneg:
404 case IKVM.ByteCode.OpCode.Ishl:
406 case IKVM.ByteCode.OpCode.Lshl:
408 case IKVM.ByteCode.OpCode.Ishr:
410 case IKVM.ByteCode.OpCode.Lshr:
412 case IKVM.ByteCode.OpCode.Iushr:
414 case IKVM.ByteCode.OpCode.Lushr:
416 case IKVM.ByteCode.OpCode.Iand:
418 case IKVM.ByteCode.OpCode.Land:
420 case IKVM.ByteCode.OpCode.Ior:
422 case IKVM.ByteCode.OpCode.Lor:
424 case IKVM.ByteCode.OpCode.Ixor:
426 case IKVM.ByteCode.OpCode.Lxor:
428 case IKVM.ByteCode.OpCode.Iinc:
429 var _iinc = instruction.AsIinc();
433 case IKVM.ByteCode.OpCode.I2l:
435 case IKVM.ByteCode.OpCode.I2f:
437 case IKVM.ByteCode.OpCode.I2d:
439 case IKVM.ByteCode.OpCode.L2i:
441 case IKVM.ByteCode.OpCode.L2f:
443 case IKVM.ByteCode.OpCode.L2d:
445 case IKVM.ByteCode.OpCode.F2i:
447 case IKVM.ByteCode.OpCode.F2l:
449 case IKVM.ByteCode.OpCode.F2d:
451 case IKVM.ByteCode.OpCode.D2i:
453 case IKVM.ByteCode.OpCode.D2l:
455 case IKVM.ByteCode.OpCode.D2f:
457 case IKVM.ByteCode.OpCode.I2b:
459 case IKVM.ByteCode.OpCode.I2c:
461 case IKVM.ByteCode.OpCode.I2s:
463 case IKVM.ByteCode.OpCode.Lcmp:
465 case IKVM.ByteCode.OpCode.Fcmpl:
467 case IKVM.ByteCode.OpCode.Fcmpg:
469 case IKVM.ByteCode.OpCode.Dcmpl:
471 case IKVM.ByteCode.OpCode.Dcmpg:
473 case IKVM.ByteCode.OpCode.Ifeq:
474 var _ifeq = instruction.AsIfeq();
477 case IKVM.ByteCode.OpCode.Ifne:
478 var _ifne = instruction.AsIfne();
481 case IKVM.ByteCode.OpCode.Iflt:
482 var _iflt = instruction.AsIflt();
485 case IKVM.ByteCode.OpCode.Ifge:
486 var _ifge = instruction.AsIfge();
489 case IKVM.ByteCode.OpCode.Ifgt:
490 var _ifgt = instruction.AsIfgt();
493 case IKVM.ByteCode.OpCode.Ifle:
494 var _ifle = instruction.AsIfle();
497 case IKVM.ByteCode.OpCode.IfIcmpeq:
498 var _ificmpeq = instruction.AsIfIcmpeq();
499 arg1 = _ificmpeq.Target;
501 case IKVM.ByteCode.OpCode.IfIcmpne:
502 var _ificmpne = instruction.AsIfIcmpne();
503 arg1 = _ificmpne.Target;
505 case IKVM.ByteCode.OpCode.IfIcmplt:
506 var _ificmplt = instruction.AsIfIcmplt();
507 arg1 = _ificmplt.Target;
509 case IKVM.ByteCode.OpCode.IfIcmpge:
510 var _ificmpge = instruction.AsIfIcmpge();
511 arg1 = _ificmpge.Target;
513 case IKVM.ByteCode.OpCode.IfIcmpgt:
514 var _ificmpgt = instruction.AsIfIcmpgt();
515 arg1 = _ificmpgt.Target;
517 case IKVM.ByteCode.OpCode.IfIcmple:
518 var _ificmple = instruction.AsIfIcmple();
519 arg1 = _ificmple.Target;
521 case IKVM.ByteCode.OpCode.IfAcmpeq:
522 var _ifacmpeq = instruction.AsIfAcmpeq();
523 arg1 = _ifacmpeq.Target;
525 case IKVM.ByteCode.OpCode.IfAcmpne:
526 var _ifacmpne = instruction.AsIfAcmpne();
527 arg1 = _ifacmpne.Target;
529 case IKVM.ByteCode.OpCode.Goto:
530 var _goto = instruction.AsGoto();
533 case IKVM.ByteCode.OpCode.Jsr:
534 var _jsr = instruction.AsJsr();
537 case IKVM.ByteCode.OpCode.Ret:
538 var _ret = instruction.AsRet();
541 case IKVM.ByteCode.OpCode.Ireturn:
543 case IKVM.ByteCode.OpCode.Lreturn:
545 case IKVM.ByteCode.OpCode.Freturn:
547 case IKVM.ByteCode.OpCode.Dreturn:
549 case IKVM.ByteCode.OpCode.Areturn:
551 case IKVM.ByteCode.OpCode.Return:
553 case IKVM.ByteCode.OpCode.GetStatic:
554 var _getstatic = instruction.AsGetStatic();
555 arg1 = _getstatic.Field.Slot;
556 classFile.MarkLinkRequiredConstantPoolItem(arg1);
558 case IKVM.ByteCode.OpCode.PutStatic:
559 var _putstatic = instruction.AsPutStatic();
560 arg1 = _putstatic.Field.Slot;
561 classFile.MarkLinkRequiredConstantPoolItem(arg1);
563 case IKVM.ByteCode.OpCode.GetField:
564 var _getfield = instruction.AsGetField();
565 arg1 = _getfield.Field.Slot;
566 classFile.MarkLinkRequiredConstantPoolItem(arg1);
568 case IKVM.ByteCode.OpCode.PutField:
569 var _putfield = instruction.AsPutField();
570 arg1 = _putfield.Field.Slot;
571 classFile.MarkLinkRequiredConstantPoolItem(arg1);
573 case IKVM.ByteCode.OpCode.InvokeVirtual:
574 var _invokevirtual = instruction.AsInvokeVirtual();
575 arg1 = _invokevirtual.Method.Slot;
576 classFile.MarkLinkRequiredConstantPoolItem(arg1);
578 case IKVM.ByteCode.OpCode.InvokeSpecial:
579 var _invokespecial = instruction.AsInvokeSpecial();
580 arg1 = _invokespecial.Method.Slot;
581 classFile.MarkLinkRequiredConstantPoolItem(arg1);
583 case IKVM.ByteCode.OpCode.InvokeStatic:
584 var _invokestatic = instruction.AsInvokeStatic();
585 arg1 = _invokestatic.Method.Slot;
586 classFile.MarkLinkRequiredConstantPoolItem(arg1);
588 case IKVM.ByteCode.OpCode.InvokeInterface:
589 var _invokeinterface = instruction.AsInvokeInterface();
590 if (_invokeinterface.Zero != 0)
593 arg1 = _invokeinterface.Method.Slot;
594 arg2 = _invokeinterface.Count;
595 classFile.MarkLinkRequiredConstantPoolItem(arg1);
597 case IKVM.ByteCode.OpCode.InvokeDynamic:
598 var _invokedynamic = instruction.AsInvokeDynamic();
599 if (_invokedynamic.Zero != 0)
601 if (_invokedynamic.Zero2 != 0)
604 arg1 = _invokedynamic.Method.Slot;
605 classFile.MarkLinkRequiredConstantPoolItem(arg1);
607 case IKVM.ByteCode.OpCode.New:
608 var _new = instruction.AsNew();
609 arg1 = _new.Constant.Slot;
610 classFile.MarkLinkRequiredConstantPoolItem(arg1);
612 case IKVM.ByteCode.OpCode.Newarray:
613 var _newarray = instruction.AsNewarray();
614 arg1 = _newarray.Value;
616 case IKVM.ByteCode.OpCode.Anewarray:
617 var _anewarray = instruction.AsAnewarray();
618 arg1 = _anewarray.Constant.Slot;
619 classFile.MarkLinkRequiredConstantPoolItem(arg1);
621 case IKVM.ByteCode.OpCode.Arraylength:
623 case IKVM.ByteCode.OpCode.Athrow:
625 case IKVM.ByteCode.OpCode.Checkcast:
626 var _checkcast = instruction.AsCheckcast();
627 arg1 = _checkcast.Type.Slot;
628 classFile.MarkLinkRequiredConstantPoolItem(arg1);
630 case IKVM.ByteCode.OpCode.InstanceOf:
631 var _instanceof = instruction.AsInstanceOf();
632 arg1 = _instanceof.Type.Slot;
633 classFile.MarkLinkRequiredConstantPoolItem(arg1);
635 case IKVM.ByteCode.OpCode.MonitorEnter:
637 case IKVM.ByteCode.OpCode.MonitorExit:
639 case IKVM.ByteCode.OpCode.Multianewarray:
640 var _multianewarray = instruction.AsMultianewarray();
641 arg1 = _multianewarray.Type.Slot;
642 classFile.MarkLinkRequiredConstantPoolItem(arg1);
643 arg2 = _multianewarray.Dimensions;
645 case IKVM.ByteCode.OpCode.IfNull:
646 var _ifnull = instruction.AsIfNull();
647 arg1 = _ifnull.Target;
649 case IKVM.ByteCode.OpCode.IfNonNull:
650 var _ifnonnull = instruction.AsIfNonNull();
651 arg1 = _ifnonnull.Target;
653 case IKVM.ByteCode.OpCode.GotoW:
654 var _gotow = instruction.AsGotoW();
655 arg1 = _gotow.Target;
657 case IKVM.ByteCode.OpCode.JsrW:
658 var _jsrw = instruction.AsJsrW();
661 case IKVM.ByteCode.OpCode.LookupSwitch:
662 var _lookupswitch = instruction.AsLookupSwitch();
663 if (_lookupswitch.Cases.Count < 0 || _lookupswitch.Cases.Count > 16384)
666 arg1 = _lookupswitch.DefaultTarget;
668 var _lookupswitchindex = 0;
669 var lookupswitchentries =
new SwitchEntry[_lookupswitch.Cases.Count];
670 foreach (var _case
in _lookupswitch.Cases)
672 lookupswitchentries[_lookupswitchindex].value = _case.Key;
673 lookupswitchentries[_lookupswitchindex].target = _case.Target;
674 _lookupswitchindex++;
677 switch_entries = lookupswitchentries;
679 case IKVM.ByteCode.OpCode.TableSwitch:
680 var _tableswitch = instruction.AsTableSwitch();
681 if (_tableswitch.Low > _tableswitch.High || _tableswitch.High > 16384L + _tableswitch.Low)
684 arg1 = _tableswitch.DefaultTarget;
686 var _tableswitchindex = 0;
687 var tableswitchentries =
new SwitchEntry[_tableswitch.Cases.Count];
688 foreach (var _case
in _tableswitch.Cases)
690 tableswitchentries[_tableswitchindex].value = _tableswitch.Low + _tableswitchindex;
691 tableswitchentries[_tableswitchindex].target = _case;
695 switch_entries = tableswitchentries;
701 this.normopcode = ByteCodeMetaData.GetNormalizedByteCode((ByteCode)(
int)instruction.OpCode);
702 arg1 = ByteCodeMetaData.GetArg((ByteCode)(
int)instruction.OpCode, arg1);
704 catch (ArgumentOutOfRangeException)
706 throw new ClassFormatError($
"Invalid instruction data: {instruction.OpCode}");
710 internal int PC => pc;
714 internal int Arg1 => arg1;
716 internal int TargetIndex
722 internal int Arg2 => arg2;
724 internal int NormalizedArg1 => arg1;
726 internal int DefaultTarget
732 internal int SwitchEntryCount => switch_entries.Length;
734 internal int GetSwitchValue(
int i)
736 return switch_entries[i].value;
739 internal int GetSwitchTargetIndex(
int i)
741 return switch_entries[i].target;
744 internal void SetSwitchTargets(
int[] targets)
746 var newEntries = (SwitchEntry[])switch_entries.Clone();
747 for (
int i = 0; i < newEntries.Length; i++)
748 newEntries[i].target = targets[i];
750 switch_entries = newEntries;
IKVM.Runtime.ClassFile.Method.Instruction Instruction