package org.dgpf.gp.vm.instructions.arith;
import org.dgpf.gp.vm.base.IInstructionHandler;
import org.dgpf.gp.vm.base.Instruction;
import org.dgpf.gp.vm.base.VMContext;
import org.dgpf.gp.vm.instructions.base.MemInstr3Handler;
import org.dgpf.gp.vm.mutation.MutationInfo;
/**
* The instruction handler for the modulo instruction.
*
* @author Thomas Weise
*/
public final class ModuloHandler extends MemInstr3Handler
{
/**
* The serial version uid.
*/
private static final long serialVersionUID = 1;
/**
* The globally shared instance of the modulo handler.
*/
public static final IInstructionHandler INSTANCE = new ModuloHandler();
/**
* Create a new modulo handler - you cannot do this, use the shared instance.
* @see #INSTANCE
*/
private ModuloHandler()
{
super(null);
}
/**
* Create a new randomized instance of this instruction.
* @param p_context The vm context to be used.
* @param p_info The information record holding the infos on the
* instruction to be created.
* @return The new instruction instance.
*/
public final Instruction create (final VMContext p_context,
final MutationInfo p_info)
{
Addresses l_a;
l_a = new Addresses(3, p_context, p_info);
return new Modulo(l_a.m_addr[0], l_a.m_rel[0],
l_a.m_addr[1], l_a.m_rel[1],
l_a.m_addr[2], l_a.m_rel[2]);
}
/**
* Get an instruction that better represents the passed in instruction.
* @param p_i The instruction to replace.
* @return An instruction that better represents <code>p_i</code>, or
* <code>p_i</code> if it is already perfect, or <code>null</code>
* if <code>p_i</code> itself is totally useless.
*/
@Override
public Instruction get_replacement (final Instruction p_i)
{
Modulo l_s;
l_s = ((Modulo)p_i);
if((l_s.get_addr_2() == l_s.get_addr_3()) &&
(l_s.is_relative_2() == l_s.is_relative_3()))
{
return new LoadC(l_s.get_addr_1(), l_s.is_relative_1(), 0);
}
return p_i;
}
}