Simulation.java 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 java.util.logging.Level;
  14. import java.util.logging.Logger;
  15. import targets.mips.Gen;
  16. import tools.mips.MipsSettings;
  17. /**
  18. *
  19. * @author EUGENIO CARVALHO
  20. */
  21. public class Simulation implements ExportInterface {
  22. protected MipsSettings settings;
  23. public Simulation(tools.mips.MipsSettings settings) {
  24. this.settings = settings;
  25. }
  26. @Override
  27. public void Exec(Code IR, Code Target) throws Exception {
  28. // Integer index;
  29. // System.out.println(Target.GData());
  30. String tmp, out = "";
  31. for (Map.Entry<String, Block> x : Target.stmts.entrySet()) {
  32. // System.out.println(x.getValue().Data());
  33. // index = 0;
  34. for (Instruction instr : x.getValue().Instructions()) {
  35. tmp = instr.G("inst.dec");
  36. if (tmp.equals("")) {
  37. continue;
  38. }
  39. out = out.concat(tmp + "\n");
  40. // .concat(Integer.toHexString(index))
  41. // .concat(":")
  42. // .concat(String.format("%X\n", tmp.trim()) + "\n");
  43. // index++;
  44. }
  45. }
  46. // Utils.WriteFile("\\src\\tools\\mips\\memory\\mi.memory", out);
  47. try {
  48. // Grava resutlado no arquivo de memoria do simulador
  49. Utils.WriteFile(settings.G("memory.instruction"), out);
  50. new tools.mips.MipsProcessor(settings)
  51. .Run()
  52. .Persist();
  53. } catch (Exception ex) {
  54. Logger.getLogger(Gen.class.getName()).log(Level.SEVERE, null, ex);
  55. }
  56. }
  57. }