Simulation.java 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package Export;
  7. import API.ExportInterface;
  8. import API.Utils;
  9. import common.Block;
  10. import common.Code;
  11. import common.Instruction;
  12. import java.util.Map;
  13. import tools.mips.Memory;
  14. import tools.mips.MipsSettings;
  15. /**
  16. *
  17. * @author EUGENIO CARVALHO
  18. */
  19. public class Simulation implements ExportInterface {
  20. protected MipsSettings settings;
  21. public Simulation(tools.mips.MipsSettings settings) {
  22. this.settings = settings;
  23. }
  24. @Override
  25. public void Exec(Code IR, Code Target) throws Exception {
  26. String bin;
  27. Memory memory = new Memory(
  28. settings.Get("memory.instruction"),
  29. settings.GetInt("memory.instruction.size")
  30. );
  31. memory.SetIO(new MemoryInitializationFile());
  32. for (Map.Entry<String, Block> x : Target.stmts.entrySet()) {
  33. for (Instruction instr : x.getValue().Instructions()) {
  34. bin = instr.Get("inst.bin");
  35. if (bin.equals("")) {
  36. continue;
  37. }
  38. // Divide os bytes da instrução binaria e escreve na memoria
  39. for (String sbyte : Utils.SplitEach(bin, 8)) {
  40. memory.WB(sbyte);
  41. }
  42. }
  43. }
  44. // Grava resutlado no arquivo de memoria do simulador
  45. memory.Save();
  46. // Instancia um simulador, executa e salva a memoria
  47. new tools.mips.MipsProcessor(settings)
  48. .Run()
  49. .Persist();
  50. }
  51. }