package assembler;

import java.util.HashMap;
import java.util.ArrayList;

import utilities.CacheDetailsHolder;
import gui.CacheHitWindow;
import gui.RegistersTable;
import instructions.Instruction;
import memory.Memory;

public class Program {
	Memory memory;
	int startAddress;
	int numOfInstructions;

	public Program(String code, int startAddress, int MemAccessTime,
			CacheDetailsHolder[] cacheDetails,
			HashMap<Integer, Integer> editedAddress) {
		ArrayList<CacheDetailsHolder> caches = new ArrayList<>();
		for (int i = 0; i < cacheDetails.length; i++) {
			caches.add(cacheDetails[i]);
		}
		String[] lines = code.split("\n");
		Instruction[] instructions = Assembler.assembleProgram(lines);
		memory = Memory.getInstance();
		memory.initialize(caches, MemAccessTime, instructions, startAddress,
				editedAddress);
		this.startAddress = startAddress;
		this.numOfInstructions = instructions.length;
		this.execute();
	}

	public void execute() {
		memory.setRegisterValue("PC", startAddress);
		for (int i = 0; i < numOfInstructions; i++) {
			int val = memory.getRegisterValue("PC");
			Instruction current = memory.getInstruction(val);
			memory.setRegisterValue("PC", val + 4);
			current.execute();
		}
	}

	public static void afterExec() {
		RegistersTable.updateRegisters();
		// arraylist<Pair<Integer>>
		// arraylist(i).first Hit
		// arraylist(i).second requests
		// new CacheHitWindow(arraylist);
	}
}

@@ -105,16 +105,39 @@
 Holder;%0A
+import utilities.Pair;%0A
 import g
@@ -1251,15 +1251,8 @@
 lic 
-static 
 void
@@ -1266,16 +1266,16 @@
 xec() %7B%0A
+
 %09%09Regist
@@ -1306,38 +1306,8 @@
 ();%0A
-%09%09// arraylist%3CPair%3CInteger%3E%3E%0A
 %09%09//
@@ -1366,18 +1366,118 @@
 uests%0A%09%09
-//
+ArrayList%3CPair%3CInteger, Integer%3E%3E hitRatios;%0A%09%09hitRatios = new ArrayList%3CPair%3CInteger, Integer%3E%3E();%0A%09%09
  new Cac
@@ -1488,25 +1488,25 @@
 tWindow(
-arraylist
+hitRatios
 );%0A%09%7D%0A%7D%0A

add some lines to afterExex