/**
 * 
 */
package dspl.backend.test;

import dspl.SymbolTable;
import dspl.frontend.SymbolicException;
import dspl.intermediate.Comparison;
import dspl.intermediate.instructions.ArithmaticInstruction;
import dspl.intermediate.instructions.BranchInstruction;
import dspl.intermediate.instructions.Instruction;
import dspl.intermediate.variable.Variable;

/**
 * HelloWorldv1 manually generates the intermediate representation 
 * for milestone "HelloWorldv1". 
 * 
 * HelloWorldv1:<BR>
 * L1 : int_array iA[5];<BR>
 * L2 : int_array iB[5];<BR>
 * L3 : int x;<BR>
 * L4 : x = 5;<BR>
 * L5 :<BR>
 * L6 : if (x==6) { <BR>
 * L7 :    iA += 7;<BR>
 * L8 : }<BR>
 * L9 : else { <BR>
 * L10:    iA = iA + iB;<BR>
 * L11: }<BR>
 * 
 * @author David
 *
 */
public class HelloWorldv1 extends IntermediateTestCase {
	
	public HelloWorldv1() throws SymbolicException { 
		//setup the symbol table by adding iA, iB, and x
		st = new SymbolTable(); 
		st.addVariable(Variable.getNewArray(Variable.LITERAL_int_array, "iA", 5, 1));
		st.addVariable(Variable.getNewArray(Variable.LITERAL_int_array, "iB", 5, 2));
		st.addVariable(Variable.getNewAtomic(Variable.LITERAL_int, "x", 3, false));
		
		//x = 5
		Variable const5 = Variable.getNewAtomic(Variable.LITERAL_int, "5", 4, true); 
		Instruction l4inst = new ArithmaticInstruction(ArithmaticInstruction.OPERATION_ASSIGNMENT, const5, null, st.getVariable("x")); 
		
		//if l6inst (if) is true instruction, "iA = iA + 7"
		Variable const7 = Variable.getNewAtomic(Variable.LITERAL_int, "7", 7, true); 
		Instruction l7inst = new ArithmaticInstruction(ArithmaticInstruction.OPERATION_ADDITION, st.getVariable("iA"), const7, st.getVariable("iA"));
		
		//if l6inst (if) is false instruction (the else instruction), "iA = iA + iB"
		Instruction l10inst = new ArithmaticInstruction(ArithmaticInstruction.OPERATION_MULTIPLICATION, st.getVariable("iA"), st.getVariable("iB"), st.getVariable("iA"));
	
		//if (x==6)
		Variable const6 = Variable.getNewAtomic(Variable.LITERAL_int, "6", 6, true); 
		Instruction l6inst = new BranchInstruction(new Comparison(st.getVariable("x"), const6, Comparison.CONDITION_EQUAL), l7inst, l10inst);
		l4inst.setNextInstruction(l6inst); 
		
		this.firstInst = l4inst; 
	}

	public String getTestCaseName() {
		return "HelloWorldv1"; 
	}
}
