OcorrenceFinderProcessor.java 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. package IntermediaryCode;
  2. /*
  3. * To change this license header, choose License Headers in Project Properties.
  4. * To change this template file, choose Tools | Templates
  5. * and open the template in the editor.
  6. */
  7. import API.Instruction;
  8. import API.Utils;
  9. import java.util.HashMap;
  10. import java.util.LinkedHashMap;
  11. import java.util.regex.Pattern;
  12. /**
  13. *
  14. * @author EUGENIO CARVALHO
  15. */
  16. public class OcorrenceFinderProcessor implements CodeProcessing {
  17. protected HashMap<String, BlockOcorrences> blocks = new HashMap<>();
  18. protected BlockOcorrences block;
  19. public static Pattern addresspattern = Pattern.compile("\\_[VTGC].*", Pattern.CASE_INSENSITIVE);
  20. public HashMap<String, BlockOcorrences> getBlocks() {
  21. return blocks;
  22. }
  23. public void setBlocks(HashMap<String, BlockOcorrences> blocks) {
  24. this.blocks = blocks;
  25. }
  26. public BlockOcorrences getBlock() {
  27. return block;
  28. }
  29. public void setBlock(BlockOcorrences block) {
  30. this.block = block;
  31. }
  32. public static Pattern getAddresspattern() {
  33. return addresspattern;
  34. }
  35. public static void setAddresspattern(Pattern addresspattern) {
  36. OcorrenceFinderProcessor.addresspattern = addresspattern;
  37. }
  38. public OcorrenceFinderProcessor() {
  39. }
  40. @Override
  41. public void Exec(Code c, LinkedHashMap<String, CodeProcessing> cp) throws Exception {
  42. String name = c.Block().getName();
  43. block = new BlockOcorrences(name);
  44. blocks.put(name, block);
  45. block.LastPosition = c.Block().CurrentAddress - 1;
  46. for (Instruction x : c.Block().Instructions()) {
  47. switch (x.G("type")) {
  48. case "label":
  49. break;
  50. case "call":
  51. block.CloseAllIntervals();
  52. default:
  53. block.Register(x, "dst");
  54. block.Register(x, "p1");
  55. block.Register(x, "p2");
  56. block.Position++;
  57. }
  58. }
  59. // Retorna para o ultimo endereco;
  60. block.Position--;
  61. // Atualiza todos os encerramentos de intervalo para a ultima ocorrencia da variavel;
  62. block.CloseAllIntervals();
  63. }
  64. public static boolean IsAddress(String alias) {
  65. // System.out.println("Is Address:" + alias + "::" + addresspattern.matcher(alias).matches());
  66. return !Utils.Empty(alias) && addresspattern.matcher(alias).matches();
  67. }
  68. }