/*
* Copyright (c) 2006 Thomas Weise
*
* E-Mail : tweise@gmx.de
* Creation Date : 2006-07-03 04:10:21
* Original Filename: org.dgpf.gp.vm.instructions.base.NoMemInstrHandler.java
* Version : 1.0.0
* Last modification: 2006-07-03
* by: Thomas Weise
*
* License : GNU LESSER GENERAL PUBLIC LICENSE
* Version 2.1, February 1999
* You should have received a copy of this license along
* with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307, USA or download the license under
* http://www.gnu.org/copyleft/lesser.html.
*
* Warranty : This software is provided "as is" without any
* warranty; without even the implied warranty of
* merchantability or fitness for a particular purpose.
* See the Gnu Lesser General Public License for more
* details.
*/
package org.dgpf.gp.vm.instructions.base;
import org.dgpf.gp.vm.base.IInstructionHandler;
import org.dgpf.gp.vm.base.Instruction;
/**
* A simple instruction handler prototype for instructions not accessing
* memory cells.
*
* @author Thomas Weise
*/
public abstract class NoMemInstrHandler
implements IInstructionHandler
{
/**
* Create a new non memory accessing instruction handler. Such handlers
* use internal mutator lists.
*/
protected NoMemInstrHandler()
{
super();
}
/**
* Replace a memory access address by another one.
* @param p_instruction The instruction to replace the address.
* @param p_old The old address.
* @param p_new The new address.
* @return The new instruction where the address relacement has been
* performed, or the old one if no replacement was needed.
*/
public final Instruction swap_address(final Instruction p_instruction,
final int p_old,
final int p_new)
{
return p_instruction;
}
/**
* This method tells if this instruction can be useful at the end of a
* procedure. A comparison, for example, will never be useful, since
* its result will always get lost.
* @return true
if and only if an instruction is useful at the
* end of a procedure.
*/
public boolean is_useful_at_end()
{
return true;
}
/**
* This method tells if this instruction can be useful at the beginning of
* a procedure. A pop, for example, will never be useful, since the stack
* of a procedure is initially empty.
* @return true
if and only if an instruction is useful at the
* beginning of a procedure.
*/
public boolean is_useful_at_begin()
{
return true;
}
/**
* Get an instruction that better represents the passed in instruction.
* @param p_i The instruction to replace.
* @return An instruction that better represents p_i
, or
* p_i
if it is already perfect, or null
* if p_i
itself is totally useless.
*/
public Instruction get_replacement (final Instruction p_i)
{
return p_i;
}
/**
* Try to melt two instructions together. The second instruction is of
* the type this instruction handler handles.
* @param p_first The first instruction.
* @param p_second The second instruction.
* @return An instruction able to replace the sequence of these both
* instructions, or null
if no valid replacement
* coult be found.
*/
public Instruction try_melt (final Instruction p_first,
final Instruction p_second)
{
return null;
}
}