123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- /*
- * 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;
- import API.CodeProcessorInterface;
- import common.Code;
- import common.Instruction;
- import java.util.Iterator;
- import java.util.LinkedHashMap;
- import java.util.ListIterator;
- /**
- *
- * @author EUGENIO CARVALHO
- */
- public class MipsOtimizationProcessor implements CodeProcessorInterface {
- public MipsOtimizationProcessor() {
- }
- @Override
- public void Exec(Code c, LinkedHashMap<String, CodeProcessorInterface> cp) throws Exception {
- Instruction last = new Instruction();
- // ArrayList<Instruction> remove = new ArrayList<>();
- ListIterator<Instruction> instructions = c.Block().Instructions().listIterator();
- for (Iterator<Instruction> it = instructions; it.hasNext();) {
- Instruction current = it.next();
- switch (current.G("inst")) {
- // Realiza a copia direta quando a instrucao anterior for um load e a atual for a copia
- case "addu":
- if (current.eq("rs", "zero") && last.eq("inst", "lw")) {
- last.S("rt", current.G("rd"));
- // remove.add(current);
- it.remove();
- }
- break;
- }
- last = current;
- }
- // for (Instruction current : ) {
- //
- // switch (current.G("inst")) {
- // // Realiza a copia direta quando a instrucao anterior for um load e a atual for a copia
- // case "addu":
- // if (current.eq("rs", "zero") && last.eq("inst", "lw")) {
- // last.S("rt", current.G("rd"));
- // remove.add(current);
- // }
- // break;
- // }
- //
- // last = current;
- // }
- // for (Instruction instruction : remove) {
- // System.out.println("Remover MipsOtimizationProcessor:" + instruction);
- // instructions.remove(instruction);
- // }
- }
- }
|