object FixOperand(IList <Instruction> instrs, Instruction instr, IVmOperand vmOperand) { if (vmOperand is TargetDisplOperand) { return(GetInstruction(instr, ((TargetDisplOperand)vmOperand).Displacement)); } if (vmOperand is SwitchTargetDisplOperand) { var targetDispls = ((SwitchTargetDisplOperand)vmOperand).TargetDisplacements; var targets = new Instruction[targetDispls.Length]; for (int i = 0; i < targets.Length; i++) { targets[i] = GetInstruction(instr, targetDispls[i]); } return(targets); } if (vmOperand is ArgOperand || vmOperand is LocalOperand) { return(vmOperand); } if (vmOperand is FieldInstructionOperand fieldInfo) { return(FixLoadStoreFieldInstruction(instr, fieldInfo.Field, fieldInfo.StaticOpCode, fieldInfo.InstanceOpCode)); } throw new ApplicationException($"Unknown operand type: {vmOperand.GetType()}"); }
object FixOperand(IList<Instruction> instrs, Instruction instr, IVmOperand vmOperand) { if (vmOperand is TargetDisplOperand) return GetInstruction(instr, ((TargetDisplOperand)vmOperand).Displacement); if (vmOperand is SwitchTargetDisplOperand) { var targetDispls = ((SwitchTargetDisplOperand)vmOperand).TargetDisplacements; Instruction[] targets = new Instruction[targetDispls.Length]; for (int i = 0; i < targets.Length; i++) targets[i] = GetInstruction(instr, targetDispls[i]); return targets; } if (vmOperand is ArgOperand || vmOperand is LocalOperand) return vmOperand; if (vmOperand is FieldInstructionOperand) { var fieldInfo = (FieldInstructionOperand)vmOperand; return FixLoadStoreFieldInstruction(instr, fieldInfo.Field, fieldInfo.StaticOpCode, fieldInfo.InstanceOpCode); } throw new ApplicationException(string.Format("Unknown operand type: {0}", vmOperand.GetType())); }
object fixOperand(IList <Instruction> instrs, Instruction instr, IVmOperand vmOperand) { if (vmOperand is TokenOperand) { return(getMemberRef(((TokenOperand)vmOperand).token)); } if (vmOperand is TargetDisplOperand) { return(getInstruction(instrs, instr, ((TargetDisplOperand)vmOperand).displacement)); } if (vmOperand is SwitchTargetDisplOperand) { var targetDispls = ((SwitchTargetDisplOperand)vmOperand).targetDisplacements; Instruction[] targets = new Instruction[targetDispls.Length]; for (int i = 0; i < targets.Length; i++) { targets[i] = getInstruction(instrs, instr, targetDispls[i]); } return(targets); } if (vmOperand is ArgOperand || vmOperand is LocalOperand) { return(vmOperand); } if (vmOperand is LoadFieldOperand) { return(fixLoadStoreFieldInstruction(instr, ((LoadFieldOperand)vmOperand).token, OpCodes.Ldsfld, OpCodes.Ldfld)); } if (vmOperand is LoadFieldAddressOperand) { return(fixLoadStoreFieldInstruction(instr, ((LoadFieldAddressOperand)vmOperand).token, OpCodes.Ldsflda, OpCodes.Ldflda)); } if (vmOperand is StoreFieldOperand) { return(fixLoadStoreFieldInstruction(instr, ((StoreFieldOperand)vmOperand).token, OpCodes.Stsfld, OpCodes.Stfld)); } throw new ApplicationException(string.Format("Unknown operand type: {0}", vmOperand.GetType())); }
object fixOperand(IList<Instruction> instrs, Instruction instr, IVmOperand vmOperand) { if (vmOperand is TokenOperand) return getMemberRef(((TokenOperand)vmOperand).token); if (vmOperand is TargetDisplOperand) return getInstruction(instrs, instr, ((TargetDisplOperand)vmOperand).displacement); if (vmOperand is SwitchTargetDisplOperand) { var targetDispls = ((SwitchTargetDisplOperand)vmOperand).targetDisplacements; Instruction[] targets = new Instruction[targetDispls.Length]; for (int i = 0; i < targets.Length; i++) targets[i] = getInstruction(instrs, instr, targetDispls[i]); return targets; } if (vmOperand is ArgOperand || vmOperand is LocalOperand) return vmOperand; if (vmOperand is LoadFieldOperand) return fixLoadStoreFieldInstruction(instr, ((LoadFieldOperand)vmOperand).token, OpCodes.Ldsfld, OpCodes.Ldfld); if (vmOperand is LoadFieldAddressOperand) return fixLoadStoreFieldInstruction(instr, ((LoadFieldAddressOperand)vmOperand).token, OpCodes.Ldsflda, OpCodes.Ldflda); if (vmOperand is StoreFieldOperand) return fixLoadStoreFieldInstruction(instr, ((StoreFieldOperand)vmOperand).token, OpCodes.Stsfld, OpCodes.Stfld); throw new ApplicationException(string.Format("Unknown operand type: {0}", vmOperand.GetType())); }