TemplateFunctions.java 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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. /**
  8. *
  9. * @author EUGENIO CARVALHO
  10. */
  11. //class TemplateFunctions extends templates.TListener {
  12. //
  13. // public HashMap<String, TPLInterface> templates;
  14. //// public int AddressGap = 1;
  15. //
  16. // public TemplateFunctions(TemplateCtx ctx, TemplateCtx gctx) {
  17. // super(ctx, gctx);
  18. // }
  19. //
  20. // @Override
  21. // public void exitCall(TemplateParser.CallContext ctx) {
  22. // try {
  23. // ArrayList<String> arguments = ExecCall(ctx);
  24. //
  25. // if (Utils.Empty(this.returnCall)) {
  26. // switch (ctx.ID().getText()) {
  27. // case "OFFSET":
  28. // this.returnCall = OFFSET(arguments);
  29. // break;
  30. // case "INSTHEX":
  31. // this.returnCall = INSTHEX(arguments);
  32. // break;
  33. // case "INSTDEC":
  34. // this.returnCall = INSTDEC(arguments);
  35. // break;
  36. // case "INSTBIN":
  37. // this.returnCall = INSTBIN(arguments);
  38. // break;
  39. // case "BIN":
  40. // this.returnCall = BIN(arguments);
  41. // case "RBIN":
  42. // this.returnCall = RBIN(arguments);
  43. // break;
  44. // }
  45. // }
  46. // } catch (Exception ex) {
  47. // Logger.getLogger(TemplateFunctions.class.getName()).log(Level.SEVERE, null, ex);
  48. // }
  49. // }
  50. //
  51. //// public String OFFSET(ArrayList<String> args) {
  52. //// return args.get(0) + "(" + args.get(1) + ")";
  53. //// }
  54. //
  55. //// @Override
  56. //// protected String L(ArrayList<String> arguments) {
  57. ////
  58. //// String label = arguments.get(0).trim();
  59. ////
  60. //// if (label.equals("")) {
  61. //// return label;
  62. //// }
  63. ////
  64. //// String format = (arguments.size() > 1) ? arguments.get(1) : "dec",
  65. //// // Corresponde ao nome do label que marca o inicio do bloco
  66. //// base = gctx.G("label." + label).split("\\+")[0],
  67. //// // Corresponde ao endereco do label base (decimal)
  68. //// baseAddress = gctx.G(base),
  69. //// // Corresponde a posicao do label destino (decimal)
  70. //// laddress = gctx.G(label);
  71. ////
  72. ////// System.out.printf("TemplateListener:{%s\n %s\n %s\n %s\n}\n", base, baseAddress, label, laddress);
  73. //// int value = Integer.parseInt(laddress);
  74. //// int fromStart = value - Integer.parseInt(baseAddress);
  75. ////
  76. //// switch (ctx.Get("type")) {
  77. //// case "I": // (bne...) Salta para posicao em relacao ao pc atual
  78. ////
  79. ////// System.out.println("TemplateListenerLabel::" + base + "|" + laddress + "|" + baseAddress + "|\n" + ctx);
  80. ////// System.out.println("I Branch:{{\n" + base
  81. ////// + "\n:" + Integer.parseInt(gctx.Get(base))
  82. ////// + "\n:" + label
  83. ////// + "\n:" + value
  84. ////// + "\n:" + FormatNum(value, format)
  85. ////// + "\n}}");
  86. ////// System.out.println("Tranalate>>>>>>>>> I:[" + address + "]" + ctx);
  87. //// // address -= Integer.parseInt(ctx.Get("block.position"));
  88. //// break;
  89. //// case "J": // (j | jal) Salta para o endereco de destino
  90. ////// System.out.println(">>>>" + label + ":" + format + ":" + value + ":" + FormatNum(value, format));
  91. ////// address = valueint;
  92. //// break;
  93. //// default:
  94. //// System.out.println(String.format("Label type '%s' not defined", ctx.Get("type")));
  95. //// }
  96. ////// address = address * this.AddressGap;
  97. ////// value = value * this.AddressGap;
  98. ////// System.out.println("============LaBEL:" + label + ":" + format + ":" + value + ":" + base);
  99. ////// System.out.println("============LaBEL:" + value + ":" + address);
  100. ////
  101. //// return laddress.trim().equals("")
  102. //// ? ""
  103. //// : (FormatNum(value, format) + " <" + base + "+0x" + FormatNum(fromStart, format) + ">");
  104. //// }
  105. //
  106. // // Converte um binario para hex
  107. //// protected String INSTHEX(ArrayList<String> arguments) {
  108. //// try {
  109. //// String bin = INSTBIN(arguments);
  110. //// if (Utils.Empty(bin)) {
  111. //// return "";
  112. //// }
  113. //// String hex = PAD(Long.toString(Long.parseLong(bin, 2), 16), "0", 8);
  114. //// ctx.Set("inst.hex", hex);
  115. //// return hex;
  116. ////
  117. //// } catch (Exception e) {
  118. //// if (ctx.Get("inst").equals("bgtz")) {
  119. //// System.out.println("hex-Error:" + e.getMessage());
  120. //// e.printStackTrace();
  121. //// }
  122. //// return "error!";
  123. //// }
  124. //// }
  125. //
  126. //// 100111101111011111111111111000 == addiu sp,sp,-8
  127. //// protected String INSTDEC(ArrayList<String> arguments) {
  128. //// try {
  129. //// String bin = INSTBIN(arguments);
  130. //// if (Utils.Empty(bin)) {
  131. //// return "";
  132. //// }
  133. ////
  134. ////// System.out.println("Convertendo bin :" + arguments + ":" + bin + ":dec:" + Long.parseLong(bin, 2));
  135. //// String dec = PAD("" + Long.parseLong(bin, 2), "0", 10);
  136. //// ctx.Set("inst.dec", dec);
  137. //// return dec;
  138. ////
  139. //// } catch (Exception e) {
  140. //// if (ctx.Get("inst").equals("bgtz")) {
  141. //// System.out.println("hex-Error:" + e.getMessage());
  142. //// e.printStackTrace();
  143. //// }
  144. //// return "error!";
  145. //// }
  146. ////
  147. //// }
  148. //
  149. //// protected String INSTBIN(ArrayList<String> arguments) {
  150. //// String type = ctx.Get("type");
  151. //// if (type.equals("label")) {
  152. //// return "";
  153. //// }
  154. ////
  155. //// long shift;
  156. //// //
  157. //// switch (type) {
  158. //// case "S": // (j | jal) Salta para o endereco de destino
  159. ////// System.out.println("instbin:" + ctx);
  160. //// break;
  161. //// case "J": // (j | jal) Salta para o endereco de destino
  162. ////// System.out.println("JUMP:" + gctx.Get(ctx.Get("label")) + ":"
  163. ////// + (Long.parseLong(gctx.Get(ctx.Get("label")), 10) >> 2));
  164. ////
  165. //// shift = (Long.parseLong(gctx.G(ctx.Get("label")), 10) >> 2);
  166. //// ctx.Set("target", BIN("" + shift, 26));
  167. //// break;
  168. //// case "I": // (bne...) Salta para posicao em relacao ao pc atual + 4
  169. ////// System.out.println("BIN iiiiii" + ctx);
  170. ////// shift = (Long.parseLong(gctx.Get(ctx.Get("label")), 10) >> 2);
  171. ////// ctx.Set("target", BIN("" + shift, 26));
  172. ////
  173. ////// if (ctx.Get("offset").equals("") && !ctx.Get("label").equals("")) {
  174. //////
  175. ////// int target = Integer.parseInt(gctx.Get(ctx.Get("label")));
  176. ////// int position = Integer.parseInt(ctx.Get("global.position")) + 1;
  177. //////
  178. //////// System.out.println("INSTBIN:->" + FormatNum(target - position, "hex"));
  179. ////// ctx.Set("offset", (target - position) + "");
  180. //////
  181. ////// }
  182. ////// System.out.println("INSTBIN[" + type + ":" + bin + "]:" + ctx);
  183. //// break;
  184. //// case "R": // (bne...) Salta para posicao em relacao ao pc atual
  185. ////// System.out.println("INSTBIN[" + type + "]:" + ctx);
  186. //// break;
  187. //// default:
  188. //// }
  189. //// String bin = templates.get("bin." + type).Render(ctx);
  190. //// ctx.Set("inst.bin", bin);
  191. ////// System.out.println("bin." + type + "::" + bin);
  192. //// return bin;
  193. //// }
  194. //
  195. //
  196. //// protected String RBIN(ArrayList<String> arguments) {
  197. ////// System.out.println("RBIN(" + arguments + ")");
  198. //// String reg = arguments.get(0);
  199. //// if (reg.equals("")) {
  200. //// reg = "0";
  201. //// }
  202. //// if (!Utils.isNumber(reg)) {
  203. //// reg = Mips.Register(reg);
  204. //// }
  205. //// return Api.num2bin(reg, Integer.parseInt(arguments.get(1)));
  206. //// }
  207. //
  208. //}