BlockBaseGroup.java 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 IntermediaryCode;
  7. import common.Instruction;
  8. import java.util.LinkedList;
  9. /**
  10. *
  11. * @author EUGENIO CARVALHO
  12. */
  13. public class BlockBaseGroup {
  14. protected LinkedList<BlockBaseOcorrences> bbs = new LinkedList<>();
  15. protected BlockBaseOcorrences current = null;
  16. public Integer currentIndex = 0;
  17. protected String name;
  18. BlockBaseGroup(String name) {
  19. this.name = name;
  20. }
  21. public void Init() {
  22. current = bbs.get(0);
  23. }
  24. public void NextBlock() {
  25. currentIndex++;
  26. current = bbs.get(currentIndex);
  27. }
  28. public void RegisterBlock(Integer leader, Integer size) {
  29. if (current != null) {
  30. current.CloseAllIntervals();
  31. }
  32. // System.out.println("Register block:" + name + "." + bbs.size() + "/" + (size - 1));
  33. BlockBaseOcorrences c = new BlockBaseOcorrences(name + "." + bbs.size(), leader);
  34. c.LastPosition = (size - 1);
  35. current = c;
  36. bbs.add(c);
  37. }
  38. public LinkedList<BlockBaseOcorrences> getBasicBlocks() {
  39. return bbs;
  40. }
  41. public BlockBaseOcorrences getCurrent() {
  42. return current;
  43. }
  44. public void ParseInstruction(Instruction inst, String attrs) {
  45. for (String attr : attrs.split(",")) {
  46. RegisterInstruction(inst, attr);
  47. }
  48. current.Position++;
  49. }
  50. public BlockBaseGroup RegisterInstruction(Instruction inst, String attr) {
  51. // System.out.println("RegisterInstruction:" + attr);
  52. current.Register(inst, attr);
  53. return this;
  54. }
  55. @Override
  56. public String toString() {
  57. StringBuilder sb = new StringBuilder();
  58. for (BlockBaseOcorrences blockBaseOcorrences : bbs) {
  59. sb.append(blockBaseOcorrences);
  60. }
  61. return sb.toString();
  62. }
  63. public void Close() {
  64. current.CloseAllIntervals();
  65. }
  66. public BlockBaseOcorrences Current() {
  67. return current;
  68. }
  69. public LinkedList<BlockBaseOcorrences> getBbs() {
  70. return bbs;
  71. }
  72. public void setBbs(LinkedList<BlockBaseOcorrences> bbs) {
  73. this.bbs = bbs;
  74. }
  75. public Integer getCurrentIndex() {
  76. return currentIndex;
  77. }
  78. public void setCurrentIndex(Integer currentIndex) {
  79. this.currentIndex = currentIndex;
  80. }
  81. public String getName() {
  82. return name;
  83. }
  84. public void setName(String name) {
  85. this.name = name;
  86. }
  87. public BlockBaseOcorrences getBasicBlocks(Integer i) {
  88. int index = currentIndex + i;
  89. if (index > bbs.size() - 1) {
  90. return null;
  91. }
  92. return bbs.get(index);
  93. }
  94. }