MipsOtimizationProcessor.java 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 targets.mips;
  7. import API.CodeProcessorInterface;
  8. import common.Code;
  9. import common.Instruction;
  10. import java.util.Iterator;
  11. import java.util.LinkedHashMap;
  12. import java.util.ListIterator;
  13. /**
  14. *
  15. * @author EUGENIO CARVALHO
  16. */
  17. public class MipsOtimizationProcessor implements CodeProcessorInterface {
  18. public MipsOtimizationProcessor() {
  19. }
  20. @Override
  21. public void Exec(Code c, LinkedHashMap<String, CodeProcessorInterface> cp) throws Exception {
  22. Instruction last = new Instruction();
  23. // ArrayList<Instruction> remove = new ArrayList<>();
  24. ListIterator<Instruction> instructions = c.Block().Instructions().listIterator();
  25. for (Iterator<Instruction> it = instructions; it.hasNext();) {
  26. Instruction current = it.next();
  27. switch (current.G("inst")) {
  28. // Realiza a copia direta quando a instrucao anterior for um load e a atual for a copia
  29. case "addu":
  30. if (current.eq("rs", "zero") && last.eq("inst", "lw")) {
  31. last.S("rt", current.G("rd"));
  32. // remove.add(current);
  33. it.remove();
  34. }
  35. break;
  36. }
  37. last = current;
  38. }
  39. // for (Instruction current : ) {
  40. //
  41. // switch (current.G("inst")) {
  42. // // Realiza a copia direta quando a instrucao anterior for um load e a atual for a copia
  43. // case "addu":
  44. // if (current.eq("rs", "zero") && last.eq("inst", "lw")) {
  45. // last.S("rt", current.G("rd"));
  46. // remove.add(current);
  47. // }
  48. // break;
  49. // }
  50. //
  51. // last = current;
  52. // }
  53. // for (Instruction instruction : remove) {
  54. // System.out.println("Remover MipsOtimizationProcessor:" + instruction);
  55. // instructions.remove(instruction);
  56. // }
  57. }
  58. }