class InstConstraintVisitor {
/**
* Ensures the specific preconditions of the said instruction.
*/
@Override
public void visitDUP2_X2(DUP2_X2 o){
if (stack().peek(0).getSize() == 2){
if (stack().peek(1).getSize() == 2){
return; // Form 4
}
// stack top size is 2, next-to-top's size is 1
if ( stack().peek(2).getSize() != 1 ){
constraintViolated(o, "If stack top's size is 2 and stack-next-to-top's size is 1,"+
" then stack next-to-next-to-top's size must also be 1. But it is '"+stack().peek(2)+
"' of size '"+stack().peek(2).getSize()+"'.");
}
else{
return; // Form 2
}
}
else{// stack top is of size 1
if (stack().peek(1).getSize() == 1){
if ( stack().peek(2).getSize() == 2 ){
return; // Form 3
}
if ( stack().peek(3).getSize() == 1){
return; // Form 1
}
}
}
constraintViolated(o, "The operand sizes on the stack do not match any of the four forms of usage of this instruction.");
}
}