123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210 |
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package targets.mips;
- /**
- *
- * @author EUGENIO CARVALHO
- */
- //class TemplateFunctions extends templates.TListener {
- //
- // public HashMap<String, TPLInterface> templates;
- //// public int AddressGap = 1;
- //
- // public TemplateFunctions(TemplateCtx ctx, TemplateCtx gctx) {
- // super(ctx, gctx);
- // }
- //
- // @Override
- // public void exitCall(TemplateParser.CallContext ctx) {
- // try {
- // ArrayList<String> arguments = ExecCall(ctx);
- //
- // if (Utils.Empty(this.returnCall)) {
- // switch (ctx.ID().getText()) {
- // case "OFFSET":
- // this.returnCall = OFFSET(arguments);
- // break;
- // case "INSTHEX":
- // this.returnCall = INSTHEX(arguments);
- // break;
- // case "INSTDEC":
- // this.returnCall = INSTDEC(arguments);
- // break;
- // case "INSTBIN":
- // this.returnCall = INSTBIN(arguments);
- // break;
- // case "BIN":
- // this.returnCall = BIN(arguments);
- // case "RBIN":
- // this.returnCall = RBIN(arguments);
- // break;
- // }
- // }
- // } catch (Exception ex) {
- // Logger.getLogger(TemplateFunctions.class.getName()).log(Level.SEVERE, null, ex);
- // }
- // }
- //
- //// public String OFFSET(ArrayList<String> args) {
- //// return args.get(0) + "(" + args.get(1) + ")";
- //// }
- //
- //// @Override
- //// protected String L(ArrayList<String> arguments) {
- ////
- //// String label = arguments.get(0).trim();
- ////
- //// if (label.equals("")) {
- //// return label;
- //// }
- ////
- //// String format = (arguments.size() > 1) ? arguments.get(1) : "dec",
- //// // Corresponde ao nome do label que marca o inicio do bloco
- //// base = gctx.G("label." + label).split("\\+")[0],
- //// // Corresponde ao endereco do label base (decimal)
- //// baseAddress = gctx.G(base),
- //// // Corresponde a posicao do label destino (decimal)
- //// laddress = gctx.G(label);
- ////
- ////// System.out.printf("TemplateListener:{%s\n %s\n %s\n %s\n}\n", base, baseAddress, label, laddress);
- //// int value = Integer.parseInt(laddress);
- //// int fromStart = value - Integer.parseInt(baseAddress);
- ////
- //// switch (ctx.Get("type")) {
- //// case "I": // (bne...) Salta para posicao em relacao ao pc atual
- ////
- ////// System.out.println("TemplateListenerLabel::" + base + "|" + laddress + "|" + baseAddress + "|\n" + ctx);
- ////// System.out.println("I Branch:{{\n" + base
- ////// + "\n:" + Integer.parseInt(gctx.Get(base))
- ////// + "\n:" + label
- ////// + "\n:" + value
- ////// + "\n:" + FormatNum(value, format)
- ////// + "\n}}");
- ////// System.out.println("Tranalate>>>>>>>>> I:[" + address + "]" + ctx);
- //// // address -= Integer.parseInt(ctx.Get("block.position"));
- //// break;
- //// case "J": // (j | jal) Salta para o endereco de destino
- ////// System.out.println(">>>>" + label + ":" + format + ":" + value + ":" + FormatNum(value, format));
- ////// address = valueint;
- //// break;
- //// default:
- //// System.out.println(String.format("Label type '%s' not defined", ctx.Get("type")));
- //// }
- ////// address = address * this.AddressGap;
- ////// value = value * this.AddressGap;
- ////// System.out.println("============LaBEL:" + label + ":" + format + ":" + value + ":" + base);
- ////// System.out.println("============LaBEL:" + value + ":" + address);
- ////
- //// return laddress.trim().equals("")
- //// ? ""
- //// : (FormatNum(value, format) + " <" + base + "+0x" + FormatNum(fromStart, format) + ">");
- //// }
- //
- // // Converte um binario para hex
- //// protected String INSTHEX(ArrayList<String> arguments) {
- //// try {
- //// String bin = INSTBIN(arguments);
- //// if (Utils.Empty(bin)) {
- //// return "";
- //// }
- //// String hex = PAD(Long.toString(Long.parseLong(bin, 2), 16), "0", 8);
- //// ctx.Set("inst.hex", hex);
- //// return hex;
- ////
- //// } catch (Exception e) {
- //// if (ctx.Get("inst").equals("bgtz")) {
- //// System.out.println("hex-Error:" + e.getMessage());
- //// e.printStackTrace();
- //// }
- //// return "error!";
- //// }
- //// }
- //
- //// 100111101111011111111111111000 == addiu sp,sp,-8
- //// protected String INSTDEC(ArrayList<String> arguments) {
- //// try {
- //// String bin = INSTBIN(arguments);
- //// if (Utils.Empty(bin)) {
- //// return "";
- //// }
- ////
- ////// System.out.println("Convertendo bin :" + arguments + ":" + bin + ":dec:" + Long.parseLong(bin, 2));
- //// String dec = PAD("" + Long.parseLong(bin, 2), "0", 10);
- //// ctx.Set("inst.dec", dec);
- //// return dec;
- ////
- //// } catch (Exception e) {
- //// if (ctx.Get("inst").equals("bgtz")) {
- //// System.out.println("hex-Error:" + e.getMessage());
- //// e.printStackTrace();
- //// }
- //// return "error!";
- //// }
- ////
- //// }
- //
- //// protected String INSTBIN(ArrayList<String> arguments) {
- //// String type = ctx.Get("type");
- //// if (type.equals("label")) {
- //// return "";
- //// }
- ////
- //// long shift;
- //// //
- //// switch (type) {
- //// case "S": // (j | jal) Salta para o endereco de destino
- ////// System.out.println("instbin:" + ctx);
- //// break;
- //// case "J": // (j | jal) Salta para o endereco de destino
- ////// System.out.println("JUMP:" + gctx.Get(ctx.Get("label")) + ":"
- ////// + (Long.parseLong(gctx.Get(ctx.Get("label")), 10) >> 2));
- ////
- //// shift = (Long.parseLong(gctx.G(ctx.Get("label")), 10) >> 2);
- //// ctx.Set("target", BIN("" + shift, 26));
- //// break;
- //// case "I": // (bne...) Salta para posicao em relacao ao pc atual + 4
- ////// System.out.println("BIN iiiiii" + ctx);
- ////// shift = (Long.parseLong(gctx.Get(ctx.Get("label")), 10) >> 2);
- ////// ctx.Set("target", BIN("" + shift, 26));
- ////
- ////// if (ctx.Get("offset").equals("") && !ctx.Get("label").equals("")) {
- //////
- ////// int target = Integer.parseInt(gctx.Get(ctx.Get("label")));
- ////// int position = Integer.parseInt(ctx.Get("global.position")) + 1;
- //////
- //////// System.out.println("INSTBIN:->" + FormatNum(target - position, "hex"));
- ////// ctx.Set("offset", (target - position) + "");
- //////
- ////// }
- ////// System.out.println("INSTBIN[" + type + ":" + bin + "]:" + ctx);
- //// break;
- //// case "R": // (bne...) Salta para posicao em relacao ao pc atual
- ////// System.out.println("INSTBIN[" + type + "]:" + ctx);
- //// break;
- //// default:
- //// }
- //// String bin = templates.get("bin." + type).Render(ctx);
- //// ctx.Set("inst.bin", bin);
- ////// System.out.println("bin." + type + "::" + bin);
- //// return bin;
- //// }
- //
- //
- //// protected String RBIN(ArrayList<String> arguments) {
- ////// System.out.println("RBIN(" + arguments + ")");
- //// String reg = arguments.get(0);
- //// if (reg.equals("")) {
- //// reg = "0";
- //// }
- //// if (!Utils.isNumber(reg)) {
- //// reg = Mips.Register(reg);
- //// }
- //// return Api.num2bin(reg, Integer.parseInt(arguments.get(1)));
- //// }
- //
- //}
|