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) {
		this.ssaOpcode = opCode;
		operands = new SSAValue[2];
		nofOperands = 0;
	}

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

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

	}
	public void addOperand(SSAValue operand) {
		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;
		}
		operands[nofOperands++] = operand;
		
	}
	@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<nofOperands-1;i++){
			System.out.print(operands[i].typeName()+", ");
		}
		System.out.println(operands[nofOperands-1].typeName()+")");		
	}
}

@@ -134,14 +134,13 @@
 %0D%0A%09p
-rivate
+ublic
  int
@@ -329,28 +329,142 @@
 () %7B
-%09%0D%0A%09%09return operands
+%0D%0A%09%09SSAValue%5B%5D opnd = new SSAValue%5BnofOperands%5D;%0D%0A%09%09for(int i = 0; i %3C nofOperands; i++)%7B%0D%0A%09%09%09opnd%5Bi%5D=operands%5Bi%5D;%0D%0A%09%09%7D%0D%0A%09%09return opnd
 ;%0D%0A%09
@@ -901,16 +901,211 @@
 %09%09%0D%0A%09%7D%0D%0A
+%09%0D%0A%09public void insertOperand(SSAValue operand, int pos)%7B%0D%0A%09%09if(pos %3E= nofOperands %7C%7C pos %3C 0)%7B%0D%0A%09%09%09throw new IndexOutOfBoundsException(%22invalid Position%22);%0D%0A%09%09%7D%0D%0A%09%09operands%5Bpos%5D = operand;%0D%0A%09%7D%0D%0A
 %09@Overri
@@ -1305,16 +1305,46 @@
 ;i++)%7B%0D%0A
+%09%09%09if(operands%5Bi%5D != null)%7B%0D%0A%09
 %09%09%09Syste
@@ -1388,19 +1388,110 @@
  %22);%0D%0A%09%09
-%7D%0D%0A
+%09%7Delse%7B%0D%0A%09%09%09%09System.out.print(%22null, %22);%0D%0A%09%09%09%7D%0D%0A%09%09%7D%0D%0A%09%09if(operands%5BnofOperands-1%5D != null)%7B%0D%0A%09
 %09%09System
@@ -1543,17 +1543,64 @@
 ()+%22)%22);
-%09
+%0D%0A%09%09%7Delse%7B%0D%0A%09%09%09System.out.println(%22null)%22);%0D%0A%09%09%7D
 %09%0D%0A%09%7D%0D%0A%7D

change visibility of nofOperands, change methods print and getOperands, create new method insertOperand