package ch.ntb.inf.deep.ssa.instruction;

import ch.ntb.inf.deep.ssa.SSAValue;

public class PhiFunction extends SSAInstruction {
	private int nofOperands;
	

	public PhiFunction(int opCode, int nofOperands) {
		this.ssaOpcode = opCode;
		this.nofOperands = nofOperands;
		operands = new SSAValue[nofOperands];
	}

	@Override
	public SSAValue[] getOperands() {	
		return operands;
	}

	@Override
	public void setOperands(SSAValue[] operands) {
		this.operands = operands;
		nofOperands = operands.length;

	}
	public void addOperand(SSAValue operand, int pos) {
		int len = operands.length;
		if (len == nofOperands) {
			SSAValue[] newArray = new SSAValue[2 * len];
			for (int i = 0; i < len; i++) {
				newArray[i] = operands[i];
			}
			operands = newArray;
		}
		if(operands.length >= pos){
			throw new ArrayIndexOutOfBoundsException();
		}
		operands[pos] = operand;
		nofOperands++;
	}
	@Override
	public void print(int level) {
		for (int i = 0; i < level*3; i++)System.out.print(" ");
		System.out.print("PhiFunction["+ scMnemonics[ssaOpcode]+"] (");
		for (int i=0;i<operands.length-1;i++){
			System.out.print(operands[i].typeName()+", ");
		}
		System.out.println(operands[operands.length-1].typeName()+")");		
	}
}

@@ -194,30 +194,13 @@
 Code
-, int nofOperands
 ) %7B%0D%0A
+
 %09%09th
@@ -227,43 +227,8 @@
 e;%0D%0A
-%09%09this.nofOperands = nofOperands;%0D%0A
 %09%09op
@@ -249,16 +249,23 @@
 SAValue%5B
+2%5D;%0D%0A%09%09
 nofOpera
@@ -267,17 +267,20 @@
 Operands
-%5D
+ = 0
 ;%0D%0A%09%7D%0D%0A%0D
@@ -529,17 +529,8 @@
 rand
-, int pos
 ) %7B%0D
@@ -748,19 +748,16 @@
 %0D%0A%09%09
-if(
 operands
 .len
@@ -756,93 +756,22 @@
 ands
-.length %3E= pos)%7B%0D%0A%09%09%09throw new ArrayIndexOutOfBoundsException();%0D%0A%09%09%7D%0D%0A%09%09o
+%5BnofO
 perands
-%5Bpos
+++
 %5D = 
@@ -786,22 +786,8 @@
 %0D%0A%09%09
-nofOperands++;
 %0D%0A%09%7D
@@ -976,31 +976,27 @@
 t i=0;i%3C
-o
+nofO
 perands
-.length
 -1;i++)%7B
@@ -1083,31 +1083,27 @@
 perands%5B
-o
+nofO
 perands
-.length
 -1%5D.type

correct addOperand