package org.dgpf.gp.vm.instructions.base;
import org.dgpf.gp.vm.base.Instruction;
import org.sfc.utils.Typesafe;
/**
* This static helper class provides you with information on if one
* instruction has an side effect on another one.
*
* @author Thomas Weise
*/
public final class SideEffect
{
/**
* Determines if one instruction has a (memory related) side effect on
* another one.
* @param p_i1 The instruction that will be called first.
* @param p_i2 The instruction that will be called last.
* @return <code>true</code> if and only if the first instruction
* (<code>p_i1</code>) modifies the behavior of the second one
* (<code>p_i2</code>).
*
*/
public static final boolean has_side_effect (final Instruction p_i1,
final Instruction p_i2)
{
int l_a11, l_a12, l_a13, l_a21, l_a22, l_a23;
boolean l_r11, l_r12, l_r13, l_r21, l_r22, l_r23;
MemInstr1 l_m11, l_m12;
MemInstr2 l_m2;
MemInstr3 l_m3;
if(p_i1 instanceof MemInstr1)
{
l_m11 = ((MemInstr1)p_i1);
l_r11 = l_m11.m_relative_1;
l_a11 = l_m11.m_addr_1;
l_a13 = (Integer.MAX_VALUE-1);
l_r13 = false;
l_a12 = Integer.MAX_VALUE;
l_r12 = false;
if(p_i1 instanceof MemInstr2)
{
l_m2 = ((MemInstr2)p_i1);
l_a12 = l_m2.m_addr_2;
l_r12 = l_m2.m_relative_2;
if(p_i1 instanceof MemInstr3)
{
l_m3 = ((MemInstr3)p_i1);
l_a13 = l_m3.m_addr_3;
l_r13 = l_m3.m_relative_3;
}
}
}
else return false;
if(p_i2 instanceof MemInstr2)
{
l_a23 = (Integer.MAX_VALUE-3);
l_r23 = false;
l_a22 = (Integer.MAX_VALUE-2);
l_r22 = false;
l_m12 = ((MemInstr2)p_i2);
l_r21 = l_m12.m_relative_1;
l_a21 = l_m12.m_addr_1;
if(p_i2 instanceof MemInstr2)
{
l_m2 = ((MemInstr2)p_i2);
l_a22 = l_m2.m_addr_2;
l_r22 = l_m2.m_relative_2;
if(p_i2 instanceof MemInstr3)
{
l_m3 = ((MemInstr3)p_i2);
l_a23 = l_m3.m_addr_3;
l_r23 = l_m3.m_relative_3;
}
}
}
else return false;
if( (l_m12.get_access(1) & 1) != 0 )
{
if( ((l_m11.get_access(1) & 2) != 0) &&
(l_r11 || l_r21 || (l_a11 == l_a21) ) ) return true;
if( ((l_m11.get_access(2) & 2) != 0) &&
(l_r12 || l_r21 || (l_a12 == l_a21) ) ) return true;
if( ((l_m11.get_access(3) & 2) != 0) &&
(l_r13 || l_r21 || (l_a13 == l_a21) ) ) return true;
}
if( (l_m12.get_access(2) & 1) != 0 )
{
if( ((l_m11.get_access(1) & 2) != 0) &&
(l_r11 || l_r22 || (l_a11 == l_a22) ) ) return true;
if( ((l_m11.get_access(2) & 2) != 0) &&
(l_r12 || l_r22 || (l_a12 == l_a22) ) ) return true;
if( ((l_m11.get_access(3) & 2) != 0) &&
(l_r13 || l_r22 || (l_a13 == l_a22) ) ) return true;
}
if( (l_m12.get_access(3) & 1) != 0 )
{
if( ((l_m11.get_access(1) & 2) != 0) &&
(l_r11 || l_r23 || (l_a11 == l_a23) ) ) return true;
if( ((l_m11.get_access(2) & 2) != 0) &&
(l_r12 || l_r23 || (l_a12 == l_a23) ) ) return true;
if( ((l_m11.get_access(3) & 2) != 0) &&
(l_r13 || l_r23 || (l_a13 == l_a23) ) ) return true;
}
return false;
}
/**
* Never call this, kid.
*/
private SideEffect()
{
Typesafe.do_not_call();
}
}