Browse Source

basic blocks

eugeniucarvalho 5 years ago
parent
commit
a8644b4668
73 changed files with 471 additions and 437 deletions
  1. BIN
      build/classes/API/Api.class
  2. BIN
      build/classes/API/BuildParams.class
  3. BIN
      build/classes/IntermediaryCode/Allocation.class
  4. BIN
      build/classes/IntermediaryCode/CodeOtimizadorProcessor.class
  5. BIN
      build/classes/IntermediaryCode/CodeProcessing.class
  6. BIN
      build/classes/IntermediaryCode/Filtros.class
  7. BIN
      build/classes/IntermediaryCode/Interval.class
  8. BIN
      build/classes/IntermediaryCode/Ocorrence.class
  9. BIN
      build/classes/compiler/IVANNOSYS.class
  10. BIN
      build/classes/compiler/IvannosysCompiler.class
  11. BIN
      build/classes/target/mips/AllocatorMipsProcessor.class
  12. BIN
      build/classes/target/mips/CopyDeps.class
  13. BIN
      build/classes/target/mips/Gen$1.class
  14. BIN
      build/classes/target/mips/Gen$2.class
  15. BIN
      build/classes/target/mips/Gen$3.class
  16. BIN
      build/classes/target/mips/Gen$4.class
  17. BIN
      build/classes/target/mips/Gen.class
  18. BIN
      build/classes/target/mips/Mips$1.class
  19. BIN
      build/classes/target/mips/Mips$2.class
  20. BIN
      build/classes/target/mips/Mips$3.class
  21. BIN
      build/classes/target/mips/Mips$4.class
  22. BIN
      build/classes/target/mips/Mips.class
  23. BIN
      build/classes/target/mips/OtimizationMips.class
  24. BIN
      build/classes/target/mips/Registers$1.class
  25. BIN
      build/classes/target/mips/Registers$2.class
  26. BIN
      build/classes/target/mips/Registers.class
  27. BIN
      build/classes/target/mips/TListenerMips.class
  28. BIN
      build/classes/target/mips/TemplateMips.class
  29. BIN
      build/classes/target/mips/UpdateAddressProcessor$1.class
  30. BIN
      build/classes/target/mips/UpdateAddressProcessor.class
  31. BIN
      build/classes/target/mips/jun/Gen.class
  32. BIN
      build/classes/tools/mips/MipsProcessor.class
  33. BIN
      build/classes/tools/mips/RegisterBank.class
  34. 4 4
      build/classes/tools/mips/memory/md.memory
  35. 1 1
      build/classes/tools/mips/memory/mi.memory
  36. 43 2
      src/API/Api.java
  37. 10 0
      src/API/BuildParams.java
  38. 77 0
      src/API/CodeProcessor.java
  39. 3 3
      src/IntermediaryCode/CodeProcessing.java
  40. 46 0
      src/API/Target.java
  41. 8 6
      src/API/TargetGen.java
  42. 1 0
      src/IntermediaryCode/Allocation.java
  43. 0 45
      src/IntermediaryCode/Filtros.java
  44. 2 12
      src/IntermediaryCode/IRGenInterface.java
  45. 14 23
      src/IntermediaryCode/IRGenerator.java
  46. 4 3
      src/IntermediaryCode/BaseBlockProcessor.java
  47. 8 2
      src/IntermediaryCode/BlockBaseGroup.java
  48. 2 1
      src/IntermediaryCode/BlockBaseOcorrences.java
  49. 4 3
      src/IntermediaryCode/CodeOtimizadorProcessor.java
  50. 4 3
      src/IntermediaryCode/DeadInstructionsProcessor.java
  51. 1 1
      src/IntermediaryCode/Interval.java
  52. 59 0
      src/Processors/LoadStoreProcessor.java
  53. 1 1
      src/IntermediaryCode/Ocorrence.java
  54. 4 3
      src/IntermediaryCode/RemoveUnusedLabelsProcessor.java
  55. 4 3
      src/IntermediaryCode/VariablesConstantsProcessor.java
  56. 7 88
      src/common/Code.java
  57. 40 24
      src/compiler/IVANNOSYS.java
  58. 34 114
      src/compiler/IvannosysCompiler.java
  59. 26 23
      src/target/mips/AllocatorMipsProcessor.java
  60. 7 11
      src/target/mips/CopyDeps.java
  61. 20 24
      src/target/mips/Gen.java
  62. 5 5
      src/target/mips/LoadStoreProcessor.java
  63. 1 1
      src/target/mips/Mips.java
  64. 6 6
      src/target/mips/UpdateAddressProcessor.java
  65. 5 5
      src/target/mips/OTMinActivationRegister.java
  66. 4 4
      src/target/mips/OtimizationMips.java
  67. 1 1
      src/target/mips/Registers.java
  68. 1 1
      src/target/mips/TListenerMips.java
  69. 1 1
      src/target/mips/TemplateMips.java
  70. 7 7
      src/target/mips/jun/Gen.java
  71. 1 1
      src/tools/mips/MipsProcessor.java
  72. 1 1
      src/tools/mips/RegisterBank.java
  73. 4 4
      src/tools/mips/memory/md.memory

BIN
build/classes/API/Api.class


BIN
build/classes/API/BuildParams.class


BIN
build/classes/IntermediaryCode/Allocation.class


BIN
build/classes/IntermediaryCode/CodeOtimizadorProcessor.class


BIN
build/classes/IntermediaryCode/CodeProcessing.class


BIN
build/classes/IntermediaryCode/Filtros.class


BIN
build/classes/IntermediaryCode/Interval.class


BIN
build/classes/IntermediaryCode/Ocorrence.class


BIN
build/classes/compiler/IVANNOSYS.class


BIN
build/classes/compiler/IvannosysCompiler.class


BIN
build/classes/target/mips/AllocatorMipsProcessor.class


BIN
build/classes/target/mips/CopyDeps.class


BIN
build/classes/target/mips/Gen$1.class


BIN
build/classes/target/mips/Gen$2.class


BIN
build/classes/target/mips/Gen$3.class


BIN
build/classes/target/mips/Gen$4.class


BIN
build/classes/target/mips/Gen.class


BIN
build/classes/target/mips/Mips$1.class


BIN
build/classes/target/mips/Mips$2.class


BIN
build/classes/target/mips/Mips$3.class


BIN
build/classes/target/mips/Mips$4.class


BIN
build/classes/target/mips/Mips.class


BIN
build/classes/target/mips/OtimizationMips.class


BIN
build/classes/target/mips/Registers$1.class


BIN
build/classes/target/mips/Registers$2.class


BIN
build/classes/target/mips/Registers.class


BIN
build/classes/target/mips/TListenerMips.class


BIN
build/classes/target/mips/TemplateMips.class


BIN
build/classes/target/mips/UpdateAddressProcessor$1.class


BIN
build/classes/target/mips/UpdateAddressProcessor.class


BIN
build/classes/target/mips/jun/Gen.class


BIN
build/classes/tools/mips/MipsProcessor.class


BIN
build/classes/tools/mips/RegisterBank.class


+ 4 - 4
build/classes/tools/mips/memory/md.memory

@@ -4089,8 +4089,8 @@
 16352:	0
 16356:	0
 16360:	0
-16364:	-18554
-16368:	0
+16364:	0
+16368:	7
 16372:	0
-16376:	-18552
-16380:	10
+16376:	10033
+16380:	10033

+ 1 - 1
build/classes/tools/mips/memory/mi.memory

@@ -2,7 +2,7 @@
 0001962017
 0605028352
 2949644288
-0605103888
+0605103921
 2949709828
 0605159424
 2949775368

+ 43 - 2
src/API/Api.java

@@ -6,6 +6,7 @@
 package API;
 
 import IntermediaryCode.Allocation;
+import Processors.BaseBlockProcessor;
 import ast.Node;
 import compiler.IvannosysCompiler;
 import java.util.ArrayList;
@@ -20,11 +21,18 @@ public class Api {
 
     protected static boolean inicializada = false;
 
-    public static void inicializar(IvannosysCompiler compiler) throws Exception {
+    public static void Init(IvannosysCompiler compiler) throws Exception {
         if (inicializada) {
             return;
         }
 
+        BuildParams.Set("display.PARSETREE", "false");
+        BuildParams.Set("display.ERRORS", "false");
+        BuildParams.Set("display.AST", "true");
+
+        BuildParams.Set("mode", "developement");
+
+
         /*Inicializando importes*/
         /*Inicializando constantes*/
 //        Constantes.add("FALSE", "bool", "0", "global");
@@ -67,6 +75,39 @@ public class Api {
                 .S("public", "true")
         );
 
+        // Registra os processadores de codigo padrão
+        BaseBlockProcessor bb = new Processors.BaseBlockProcessor();
+        CodeProcessor.Add("ir.clear.labels", new Processors.RemoveUnusedLabelsProcessor());
+        CodeProcessor.Add("ir.basic.blocks", bb);
+        CodeProcessor.Add("ir.o.load_store", new Processors.LoadStoreProcessor(bb));
+        //                     CodeProcessor.Add("ir.o.VariablesConstants", new Processors.VariablesConstantsProcessor());
+        //                     CodeProcessor.Add("ir.o.DeadInstructions", new Processors.DeadInstructionsProcessor());
+        CodeProcessor.Add("ir.o.copies", new Processors.CodeOtimizadorProcessor(true));
+
+        // Processadores do alvo mips
+        CodeProcessor.Add("mips.copy.dep", new targets.mips.CopyDepsProcessor());
+        CodeProcessor.Add("mips.register.alloc", new targets.mips.AllocatorMipsProcessor());
+        CodeProcessor.Add("mips.o.L1", new targets.mips.OtimizationMips());
+        CodeProcessor.Add("mips.update.address", new targets.mips.MipsUpdateAddressProcessor());
+
+        // Define os processadores padrão da IR
+        CodeProcessor.On(
+                "IR",
+                "CloseBlock",
+                // Remove labels não referenciadas
+                "ir.clear.labels,"
+                // Remove copias
+                + "ir.o.copies,"
+                // Extrai os blocos basicos de uma subrotina
+                + "ir.basic.blocks,"
+                // Remove loads e stores desnecessarios
+                + "ir.o.load_store"
+                // Remove variaveis que são escrias apenas uma vez. Transformando em constantes
+        // + "ir.o.VariablesConstants,"
+        //                // Remove instrucoes mortas
+        // + "ir.ot.DeadInstructions,"
+        );
+
         Imports._init(compiler);
 //        Constantes._init();
 
@@ -76,7 +117,7 @@ public class Api {
 //        Types.add("thread", 1);
 //        Types.add("reference", 1);
         Interfaces._init();
-        
+
         /*Inicializando funcoes*/
         Functions._init();
 

+ 10 - 0
src/API/BuildParams.java

@@ -24,6 +24,10 @@ public class BuildParams {
         params.put(tag, values);
     }
 
+    public static String GetFirst(String tag) throws Exception {
+        return Get(tag).get(0);
+    }
+
     public static ArrayList<String> Get(String tag) throws Exception {
         if (!params.containsKey(tag)) {
             throw new Exception(String.format("Build param `%s` não definido!", tag));
@@ -43,6 +47,12 @@ public class BuildParams {
         container.add(value);
     }
 
+    public static void Set(String tag, String value) {
+        ArrayList<String> a = new ArrayList<>();
+        a.add(value);
+        params.put(tag, a);
+    }
+
     public static void List() {
         System.out.println("BuildParams:\n");
         for (Map.Entry<String, ArrayList<String>> entry : params.entrySet()) {

+ 77 - 0
src/API/CodeProcessor.java

@@ -0,0 +1,77 @@
+/*
+ * 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 API;
+
+import common.Instruction;
+import common.Log;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+
+/**
+ *
+ * @author Eugenio
+ */
+public class CodeProcessor {
+
+    // Todos os processors serão armazenados aqui, e cada evendo possui uma lista de processors separada por virgula
+    protected static LinkedHashMap<String, API.CodeProcessorInterface> processors = new LinkedHashMap<>();
+    protected static HashMap<String, HashMap<String, String>> events = new HashMap<>();
+
+    public static void _init() {
+
+    }
+
+    public static void On(String selectors, String event, String processors) {
+        for (String selector : selectors.split(",")) {
+            if (!events.containsKey(selector)) {
+                events.put(selector, new HashMap<String, String>());
+            }
+            events.get(selector).put(event, processors);
+        }
+    }
+
+    public static void Trigger(common.Code c, String selector, String event) throws Exception {
+//        System.out.println("Try trigger:" + selector);
+        if (events.containsKey(selector)) {
+            HashMap<String, String> t = events.get(selector);
+            if (t.containsKey(event)) {
+                ProcessorExecute(c, t.get(event));
+            }
+        }
+
+    }
+
+    public static void Add(String id, API.CodeProcessorInterface p) throws Exception {
+        if (processors.containsKey(id)) {
+            Log.PrintWarning(
+                    "Code Processor",
+                    new Instruction().S("msg", String.format("Tentativa de sobrescrita do processor %s.", id))
+            );
+        }
+        processors.put(id, p);
+    }
+
+    protected static String[] ProcToList(String events) {
+//        System.out.println("events:" + events);
+        return events.replaceAll("\\s+", "").split(",");
+    }
+
+    public static void ProcessorExecute(common.Code c, String eventList) throws Exception {
+        for (String x : ProcToList(eventList)) {
+
+            if (x.equals("")) {
+                continue;
+            }
+
+            if (!processors.containsKey(x)) {
+                throw new Exception(String.format("Processador de código '%s' não definido!", x));
+            }
+
+            processors.get(x.trim()).Exec(c, processors);
+        }
+    }
+
+}

+ 3 - 3
src/IntermediaryCode/CodeProcessing.java

@@ -3,7 +3,7 @@
  * To change this template file, choose Tools | Templates
  * and open the template in the editor.
  */
-package IntermediaryCode;
+package API;
 
 import common.Code;
 import java.util.LinkedHashMap;
@@ -12,7 +12,7 @@ import java.util.LinkedHashMap;
  *
  * @author EUGENIO CARVALHO
  */
-public interface CodeProcessing {
+public interface CodeProcessorInterface {
 
-    public void Exec(Code c, LinkedHashMap<String, CodeProcessing> cp) throws Exception;
+    public void Exec(Code c, LinkedHashMap<String, CodeProcessorInterface> cp) throws Exception;
 }

+ 46 - 0
src/API/Target.java

@@ -0,0 +1,46 @@
+/*
+ * 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 API;
+
+import common.Instruction;
+import common.IvannosysTargetArch;
+import common.Log;
+import java.util.HashMap;
+
+/**
+ *
+ * @author Eugenio
+ */
+public class Target {
+
+    // Todos os processors serão armazenados aqui, e cada evendo possui uma lista de processors separada por virgula
+    protected static HashMap<String, IvannosysTargetArch> targets = new HashMap<>();
+
+    public static void _init() {
+
+    }
+
+    public static void Add(String id, IvannosysTargetArch target) throws Exception {
+        if (targets.containsKey(id)) {
+            Log.PrintWarning(
+                    "Target API",
+                    new Instruction().S("msg", String.format("Tentativa de sobrescrita do gerador alvo %s.", id))
+            );
+        }
+        targets.put(id, target);
+    }
+
+    public static IvannosysTargetArch Get(String id) throws Exception {
+        if (!targets.containsKey(id)) {
+            throw new Exception(String.format("Gerador alvo '%s' não definido.", id));
+        }
+        return targets.get(id);
+    }
+
+    public static boolean Has(String id) {
+        return targets.containsKey(id);
+    }
+}

+ 8 - 6
src/API/TargetGen.java

@@ -48,6 +48,7 @@ public abstract class TargetGen implements IvannosysTargetArch {
     public IvannosysTargetArch SetTAC(Code tac) {
         IR = tac;
         target.GData().copy(tac.GData());
+        target.Parent = IR;
         return this;
     }
 
@@ -81,19 +82,20 @@ public abstract class TargetGen implements IvannosysTargetArch {
     }
 
     protected void Translate() throws Exception {
-        String id;
+        String targetID = target.Name(), id;
+        target.Parent = IR;
 
-        IR.BeforeTranslate();
+        CodeProcessor.Trigger(target, targetID, "BeforeTranslate");
 
         for (Map.Entry<String, Block> b : IR.getBlocks().entrySet()) {
             id = b.getKey();
 
             IR.Use(id);
 
-            IR.BeforeTranslateBlock();
-
             target.OpenBlock(id);
 
+            CodeProcessor.Trigger(target, targetID, "BeforeTranslateBlock");
+
             Prolog(id);
 
             TranslateBlock(b.getValue());
@@ -104,10 +106,10 @@ public abstract class TargetGen implements IvannosysTargetArch {
 
             target.UpdatePositions();
 
-            target.AfterTranslateBlock();
+            CodeProcessor.Trigger(target, targetID, "AfterTranslateBlock");
         }
 
-        target.AfterTranslate();
+        CodeProcessor.Trigger(target, targetID, "AfterTranslate");
     }
 
     protected void TranslateBlock(Block b) throws Exception {

+ 1 - 0
src/IntermediaryCode/Allocation.java

@@ -5,6 +5,7 @@
  */
 package IntermediaryCode;
 
+import Processors.Ocorrence;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Map;

+ 0 - 45
src/IntermediaryCode/Filtros.java

@@ -1,45 +0,0 @@
-/*
- * 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 IntermediaryCode;
-
-import common.Code;
-import common.Instruction;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- *
- * @author Eugenio
- */
-class Filtros {
-
-    protected Code code;
-
-    void filtrar(Code code) throws Exception {
-        this.code = code;
-        exec();
-    }
-
-    protected void exec() throws Exception {
-//        HashMap<String, ArrayList<Registro>> blocos = code.getBlock();
-//        try {
-//            for (Map.Entry<String, ArrayList<Registro>> entry : blocos.entrySet()) {
-//                ArrayList<Registro> bloco = entry.getValue();
-//                tratarBloco(bloco);
-//            }
-//        } catch (Exception e) {
-//            System.out.println("[ErrorFiltro]" + e.getMessage());
-//            e.printStackTrace();
-//            throw e;
-//        }
-    }
-
-    protected void tratarBloco(ArrayList<Instruction> bloco) {
-
-    }
-
-}

+ 2 - 12
src/IntermediaryCode/IRGenInterface.java

@@ -7,9 +7,8 @@ package IntermediaryCode;
 //    sync    recebe  mandando
 //    exec    recebe  mandando
 
-import common.Code;
 import ast.AbstractSyntaxTree;
-import java.util.HashMap;
+import common.Code;
 
 //    synexec recebe  mandando
 /**
@@ -18,15 +17,6 @@ import java.util.HashMap;
  */
 public interface IRGenInterface {
 
-    /**
-     *
-     * @param ast
-     * @param settings
-     * @return
-     * @throws java.lang.Exception
-     */
-    public Code Create(AbstractSyntaxTree ast, HashMap<String, String> settings) throws Exception;
-
-//    public IRGenInterface AfterCreate(CodeProcessing p);
+    public Code Create(AbstractSyntaxTree ast) throws Exception;
 
 }

+ 14 - 23
src/IntermediaryCode/IRGenerator.java

@@ -24,9 +24,11 @@ import java.util.regex.Pattern;
  */
 public final class IRGenerator implements IRGenInterface {
 
-    protected boolean inicializado = false;
+    protected int jb = 0;
     protected int incLabel = 0;
     protected int tmpVarCount = 1;
+    protected boolean inicializado = false;
+    protected boolean enableOtimization = true;
     protected AbstractSyntaxTree ast;
     protected Code code;
     protected Node calEndAtt;
@@ -44,6 +46,12 @@ public final class IRGenerator implements IRGenInterface {
     protected ArrayList<String> currentMatrixvalues = new ArrayList<>();
     protected HashMap<String, ArrayList<String>> matrixValues = new HashMap<>();
 
+    protected HashMap<String, String> ArrayShiftMap = new HashMap<>();
+    protected Stack<Boolean> loopScope = new Stack<Boolean>() {
+        {
+            push(false);
+        }
+    };
     protected LinkedHashMap<String, Long> power2 = new LinkedHashMap<String, Long>() {
         {
             for (long i = 0; i < 31; i++) {
@@ -51,23 +59,13 @@ public final class IRGenerator implements IRGenInterface {
             }
         }
     };
-
     public static Pattern AddressOperator = Pattern.compile("(\\&|\\*)");
-    protected boolean enableOtimization = true;
-    protected HashMap<String, String> ArrayShiftMap = new HashMap<>();
-    protected int jb = 0;
-
-    protected Stack<Boolean> loopScope = new Stack<Boolean>() {
-        {
-            push(false);
-        }
-    };
 
     public IRGenerator() throws Exception {
 
     }
 
-    public IRGenerator(AbstractSyntaxTree ast) {
+    public IRGenerator(AbstractSyntaxTree ast) throws Exception {
         Ast(ast);
     }
 
@@ -99,18 +97,12 @@ public final class IRGenerator implements IRGenInterface {
         }
     }
 
-    public void Ast(AbstractSyntaxTree ast) {
+    public void Ast(AbstractSyntaxTree ast) throws Exception {
+
         this.ast = ast;
         code = new Code("IR", ast);
+
         code
-                // Remove labels não referenciadas
-                .AfterClose("ot.UnusedLabels", new RemoveUnusedLabelsProcessor())
-                // Remove instrucoes mortas
-                // Remove variaveis que são escrias apenas uma vez. Transformando em constantes
-                //                .AfterClose("ot.VariablesConstants", new VariablesConstantsProcessor())
-                //                .AfterClose("ot.DeadInstructions", new DeadInstructionsProcessor())
-                //                // Remove copias
-                .AfterClose("oti.1", new CodeOtimizadorProcessor(enableOtimization))
                 // Especifica o template engine
                 .Template(new template.Template())
                 // Especifica os templates das instruções
@@ -146,14 +138,13 @@ public final class IRGenerator implements IRGenInterface {
 //        }
 //    }
     @Override
-    public Code Create(AbstractSyntaxTree ast, HashMap<String, String> settings) throws Exception {
+    public Code Create(AbstractSyntaxTree ast) throws Exception {
         Ast(ast);
 
 //        DeclareConstants(ast.getRoot());
 //        setOtimizacao(settings.G("clearCode").equals("true"));
         Code code = run();
         // Executa todos os tratametos definidos apos geracao do codigo
-
         printVarMap();
 
         code.Print();

+ 4 - 3
src/IntermediaryCode/BaseBlockProcessor.java

@@ -1,4 +1,4 @@
-package IntermediaryCode;
+package Processors;
 
 /*
  * To change this license header, choose License Headers in Project Properties.
@@ -6,6 +6,7 @@ package IntermediaryCode;
  * and open the template in the editor.
  */
 import API.Utils;
+import API.CodeProcessorInterface;
 import common.Code;
 import common.Instruction;
 import java.util.ArrayList;
@@ -19,7 +20,7 @@ import java.util.regex.Pattern;
  *
  * @author EUGENIO CARVALHO
  */
-public class BaseBlockProcessor implements CodeProcessing {
+public class BaseBlockProcessor implements CodeProcessorInterface {
 
 //    protected LinkedHashMap<String, ArrayList<ArrayList<Integer>>> basicBlocks = new LinkedHashMap<>();
 //    protected String basicBlockName;
@@ -73,7 +74,7 @@ public class BaseBlockProcessor implements CodeProcessing {
 //        basicBlockCount++;
 //    }
     @Override
-    public void Exec(Code c, LinkedHashMap<String, CodeProcessing> cp) throws Exception {
+    public void Exec(Code c, LinkedHashMap<String, CodeProcessorInterface> cp) throws Exception {
         String name = c.Block().getName();
         BlockBaseGroup g = new BlockBaseGroup(name);
         group = g;

+ 8 - 2
src/IntermediaryCode/BlockBaseGroup.java

@@ -3,7 +3,7 @@
  * To change this template file, choose Tools | Templates
  * and open the template in the editor.
  */
-package IntermediaryCode;
+package Processors;
 
 import common.Instruction;
 import java.util.LinkedList;
@@ -27,9 +27,15 @@ public class BlockBaseGroup {
         current = bbs.get(0);
     }
 
-    public void NextBlock() {
+    public boolean NextBlock() {
         currentIndex++;
+
+        if (currentIndex > (bbs.size() - 1)) {
+            return false;
+        }
+
         current = bbs.get(currentIndex);
+        return true;
     }
 
     public void RegisterBlock(Integer leader, Integer size) {

+ 2 - 1
src/IntermediaryCode/BlockBaseOcorrences.java

@@ -3,8 +3,9 @@
  * To change this template file, choose Tools | Templates
  * and open the template in the editor.
  */
-package IntermediaryCode;
+package Processors;
 
+import Processors.BaseBlockProcessor;
 import API.Utils;
 import common.Instruction;
 import java.util.ArrayList;

+ 4 - 3
src/IntermediaryCode/CodeOtimizadorProcessor.java

@@ -1,5 +1,6 @@
-package IntermediaryCode;
+package Processors;
 
+import API.CodeProcessorInterface;
 import common.Block;
 import common.Code;
 import common.Instruction;
@@ -12,7 +13,7 @@ import java.util.LinkedList;
  *
  * @author Eugenio
  */
-public class CodeOtimizadorProcessor implements CodeProcessing {
+public class CodeOtimizadorProcessor implements CodeProcessorInterface {
 
     protected Code code;
 //    protected ArrayList<Filtros> filtros = new ArrayList<Filtros>();
@@ -29,7 +30,7 @@ public class CodeOtimizadorProcessor implements CodeProcessing {
 //    }
 
     @Override
-    public void Exec(Code c, LinkedHashMap<String, CodeProcessing> cp) throws Exception {
+    public void Exec(Code c, LinkedHashMap<String, CodeProcessorInterface> cp) throws Exception {
         if (!enable) {
             return;
         }

+ 4 - 3
src/IntermediaryCode/DeadInstructionsProcessor.java

@@ -3,8 +3,9 @@
  * To change this template file, choose Tools | Templates
  * and open the template in the editor.
  */
-package IntermediaryCode;
+package Processors;
 
+import API.CodeProcessorInterface;
 import common.Block;
 import common.Code;
 import common.Instruction;
@@ -18,7 +19,7 @@ import java.util.regex.Pattern;
  *
  * @author EUGENIO CARVALHO
  */
-class DeadInstructionsProcessor implements CodeProcessing {
+public class DeadInstructionsProcessor implements CodeProcessorInterface {
 
     public static Pattern varPattern = Pattern.compile("\\_[VT].*", Pattern.CASE_INSENSITIVE);
 
@@ -26,7 +27,7 @@ class DeadInstructionsProcessor implements CodeProcessing {
     }
 
     @Override
-    public void Exec(Code c, LinkedHashMap<String, CodeProcessing> cp) throws Exception {
+    public void Exec(Code c, LinkedHashMap<String, CodeProcessorInterface> cp) throws Exception {
         String dst;
         Instruction instruction;
         Block block = c.Block();

+ 1 - 1
src/IntermediaryCode/Interval.java

@@ -3,7 +3,7 @@
  * To change this template file, choose Tools | Templates
  * and open the template in the editor.
  */
-package IntermediaryCode;
+package Processors;
 
 /**
  *

+ 59 - 0
src/Processors/LoadStoreProcessor.java

@@ -0,0 +1,59 @@
+/*
+ * 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 Processors;
+
+import API.CodeProcessorInterface;
+import common.Code;
+import java.util.LinkedHashMap;
+
+/**
+ *
+ * @author EUGENIO CARVALHO
+ */
+public class LoadStoreProcessor implements CodeProcessorInterface {
+
+    protected BaseBlockProcessor basicBlocks;
+    private BlockBaseGroup group;
+
+    public LoadStoreProcessor() {
+    }
+
+    public LoadStoreProcessor(BaseBlockProcessor bb) {
+        this.basicBlocks = bb;
+    }
+
+    @Override
+    public void Exec(Code c, LinkedHashMap<String, CodeProcessorInterface> cp) throws Exception {
+//        BlockBaseOcorrences g;
+//        Integer leader, limit, lposition;
+//        group = basicBlocks.getGroups().get(c.Block().getName());
+//        group.Init();
+//
+//        while (true) {
+//            g = group.getCurrent();
+//            if (g == null) {
+//                break;
+//            }
+//            leader = g.getLeader();
+//            limit = leader + g.Position;
+//
+//            System.out.println("LoadStoreProcessor:[" + leader + "][" + limit + "]");
+//
+//            for (int i = leader; i < limit; i++) {
+//
+//            }
+//
+//            if (group.getBasicBlocks(1) == null) {
+//                break;
+//            }
+//            group.NextBlock();
+//        }
+//
+//        System.out.println("groupgroupgroupgroupgroup:" + group);
+
+    }
+
+}

+ 1 - 1
src/IntermediaryCode/Ocorrence.java

@@ -3,7 +3,7 @@
  * To change this template file, choose Tools | Templates
  * and open the template in the editor.
  */
-package IntermediaryCode;
+package Processors;
 
 import java.util.HashMap;
 import java.util.LinkedHashMap;

+ 4 - 3
src/IntermediaryCode/RemoveUnusedLabelsProcessor.java

@@ -3,9 +3,10 @@
  * To change this template file, choose Tools | Templates
  * and open the template in the editor.
  */
-package IntermediaryCode;
+package Processors;
 
 import API.Utils;
+import API.CodeProcessorInterface;
 import common.Block;
 import common.Code;
 import common.Instruction;
@@ -19,7 +20,7 @@ import java.util.LinkedList;
  *
  * @author EUGENIO CARVALHO
  */
-class RemoveUnusedLabelsProcessor implements CodeProcessing {
+public class RemoveUnusedLabelsProcessor implements CodeProcessorInterface {
 
     protected HashMap<String, HashMap<String, ArrayList<Instruction>>> labelMap = new HashMap<>();
     protected String currentBlock;
@@ -30,7 +31,7 @@ class RemoveUnusedLabelsProcessor implements CodeProcessing {
     }
 
     @Override
-    public void Exec(Code c, LinkedHashMap<String, CodeProcessing> cp) throws Exception {
+    public void Exec(Code c, LinkedHashMap<String, CodeProcessorInterface> cp) throws Exception {
         String label;
         Instruction instruction = null;
         block = c.Block();

+ 4 - 3
src/IntermediaryCode/VariablesConstantsProcessor.java

@@ -3,9 +3,10 @@
  * To change this template file, choose Tools | Templates
  * and open the template in the editor.
  */
-package IntermediaryCode;
+package Processors;
 
 import API.Utils;
+import API.CodeProcessorInterface;
 import common.Block;
 import common.Code;
 import common.Instruction;
@@ -18,7 +19,7 @@ import java.util.LinkedList;
  *
  * @author EUGENIO CARVALHO
  */
-class VariablesConstantsProcessor implements CodeProcessing {
+public class VariablesConstantsProcessor implements CodeProcessorInterface {
 
     private Block block;
     private Iterator<Instruction> interator;
@@ -28,7 +29,7 @@ class VariablesConstantsProcessor implements CodeProcessing {
     }
 
     @Override
-    public void Exec(Code c, LinkedHashMap<String, CodeProcessing> cp) throws Exception {
+    public void Exec(Code c, LinkedHashMap<String, CodeProcessorInterface> cp) throws Exception {
 //        String label, dst;
         String dst;
 

+ 7 - 88
src/common/Code.java

@@ -5,8 +5,8 @@
  */
 package common;
 
-import IntermediaryCode.CodeProcessing;
-import IntermediaryCode.Ocorrence;
+import API.CodeProcessor;
+import Processors.Ocorrence;
 import ast.AbstractSyntaxTree;
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -49,19 +49,11 @@ public class Code {
     protected TPLInterface TPLManager;
     protected int PositionIncrement = 1;
 //    private ArrayList<CodeProcessing> processing = new ArrayList<>();
-    protected LinkedHashMap<String, CodeProcessing> afterClose = new LinkedHashMap<>();
-    protected LinkedHashMap<String, CodeProcessing> afterOpen = new LinkedHashMap<>();
-//    protected DataFrame gdata;
-    protected LinkedHashMap<String, CodeProcessing> beforeTranslate = new LinkedHashMap<>();
-    protected LinkedHashMap<String, CodeProcessing> beforeTranslateBlock = new LinkedHashMap<>();
-    protected LinkedHashMap<String, CodeProcessing> afterTranslate = new LinkedHashMap<>();
-    protected LinkedHashMap<String, CodeProcessing> afterTranslateBlock = new LinkedHashMap<>();
+    public Code Parent;
 
     public Code(String id, AbstractSyntaxTree arvore) {
         name = id;
         ast = arvore;
-//        currentBlock = new LinkedList<>();
-//        stmts = new HashMap<>();
         Data = new DataFrame(id, null);
     }
 
@@ -100,6 +92,7 @@ public class Code {
         currentBlock.push(id);
         current = new Block(id, this);
         stmts.put(id, current);
+        CodeProcessor.Trigger(this, this.Name(), "OpenBlock");
 
 //        incEndereco = 0;
 //        ocorrences = new LinkedHashMap<>();
@@ -115,12 +108,13 @@ public class Code {
 //        registerVar("sp", 1, dataFrame.TYPE_STACK);
 //        storeReturnAddress = false;
 //        registerVar("ra", 1, dataFrame.TYPE_STACK);
-        AfterOpen();
+//        AfterOpen();
         return true;
     }
 
     public void CloseBlock() throws Exception {
-        AfterClose();
+//        AfterClose();
+        CodeProcessor.Trigger(this, this.Name(), "CloseBlock");
         Block().Close();
         currentBlock.pop();
         Use(currentBlock.peek());
@@ -136,28 +130,6 @@ public class Code {
 //        
     }
 
-    protected void AfterOpen() throws Exception {
-        for (Map.Entry<String, CodeProcessing> x : afterOpen.entrySet()) {
-            x.getValue().Exec(this, afterOpen);
-        }
-    }
-
-    protected void AfterClose() throws Exception {
-        for (Map.Entry<String, CodeProcessing> x : afterClose.entrySet()) {
-            x.getValue().Exec(this, afterClose);
-        }
-    }
-
-    public Code OnOpenBlock(String id, CodeProcessing c) {
-        afterOpen.put(id, c);
-        return this;
-    }
-
-    public Code AfterClose(String id, CodeProcessing c) {
-        afterClose.put(id, c);
-        return this;
-    }
-
     public void Use(String id) {
 //        System.out.println("Use '" + id + "'");
         if (id == null || id.equals("")) {
@@ -456,58 +428,5 @@ public class Code {
         PosicaoLabel += PositionIncrement;
         return cur;
     }
-//
-//    public DataFrame GData() {
-//        return gdata;
-//    }
-
-    public Code BeforeTranslate(String id, CodeProcessing processor) {
-        beforeTranslate.put(id, processor);
-        return this;
-    }
-
-    public Code BeforeTranslateBlock(String id, CodeProcessing processor) {
-        beforeTranslateBlock.put(id, processor);
-        return this;
-    }
-
-    public Code AfterTranslate(String id, CodeProcessing processor) {
-        afterTranslate.put(id, processor);
-        return this;
-    }
-
-    public Code AfterTranslateBlock(String id, CodeProcessing processor) {
-        afterTranslateBlock.put(id, processor);
-        return this;
-    }
-
-    public Code BeforeTranslate() throws Exception {
-        for (Map.Entry<String, CodeProcessing> codeProcessing : beforeTranslate.entrySet()) {
-            codeProcessing.getValue().Exec(this, beforeTranslate);
-        }
-        return this;
-    }
-
-    public Code BeforeTranslateBlock() throws Exception {
-        for (Map.Entry<String, CodeProcessing> codeProcessing : beforeTranslateBlock.entrySet()) {
-            codeProcessing.getValue().Exec(this, beforeTranslateBlock);
-        }
-        return this;
-    }
-
-    public Code AfterTranslate() throws Exception {
-//        System.out.println("AfterTranslate:" + afterTranslate.entrySet().size());
-        for (Map.Entry<String, CodeProcessing> codeProcessing : afterTranslate.entrySet()) {
-            codeProcessing.getValue().Exec(this, afterTranslate);
-        }
-        return this;
-    }
-
-    public Code AfterTranslateBlock() throws Exception {
-        for (Map.Entry<String, CodeProcessing> codeProcessing : afterTranslateBlock.entrySet()) {
-            codeProcessing.getValue().Exec(this, afterTranslateBlock);
-        }
-        return this;
-    }
 
 }

+ 40 - 24
src/compiler/IVANNOSYS.java

@@ -6,6 +6,10 @@ package compiler;
  * To change this template file, choose Tools | Templates
  * and open the template in the editor.
  */
+import API.Api;
+import API.BuildParams;
+import API.CodeProcessor;
+import API.Target;
 import IntermediaryCode.IRGenerator;
 import java.util.logging.Level;
 import java.util.logging.Logger;
@@ -16,7 +20,7 @@ import java.util.logging.Logger;
  */
 public class IVANNOSYS {
 
-    protected static IvannosysCompiler compiler;
+    protected static IvannosysCompiler COM;
 
     /**
      * @param args the command line arguments
@@ -24,7 +28,8 @@ public class IVANNOSYS {
     public static void main(String[] args) throws Exception {
 
         try {
-            String cmd = "";
+            String cmd = "", file = "";
+
             if (args.length
                     > 0) {
                 cmd = args[0];
@@ -33,32 +38,43 @@ public class IVANNOSYS {
                 case "create":
                     break;
                 default:
-                    compiler = new IvannosysCompiler(
-                            //                            "src\\samples\\program.go",
-                            //                            "src\\samples\\program.go",
-                            //                            "src\\samples\\program_mult_manycore.go",
-                            //                            "src\\samples\\program_mult_jon.go",
-                            //                            "src\\samples\\program_mult.go",
-                            "src\\samples\\program_jun_bit_count.go",
+
+                    COM = new IvannosysCompiler(
                             "UTF-8",
                             IvannosysCompiler.INPUT_FILE)
-                            // Especifica a classe de geração de codigo de tres enderecos
-                            .TacGen(new IRGenerator())
-                            // Especifica a classe de geração de codigo alvo mips
-                            .RegisterTarget("mips", new target.mips.Gen())
-                            .RegisterTarget("mipsjun", new target.mips.jun.Gen())
                             .include(".\\src\\samples")
-                            // Variavel de ambiente que indica o caminho do repositorio de includes
-                            .EnvPathVar("IVANPATH")
+                            // Especifica a classe de geração de codigo de tres enderecos
+                            .IRGenerator(new IRGenerator())
                             // Extensao dos arquivos 
-                            .setExtensionLibrary(".go")
-                            .SetOption("developement", "true")
-                            .SetOption("displayAst", "true")
-                            .SetOption("displayTac", "true")
-                            .SetOption("clearCode", "false")
-                            .setDisplayParserTree(false)
-                            .setDisplayErros(true)
-                            .Compile();
+                            .setExtensionLibrary(".go");
+
+                    // Inicializa a api do compilador
+                    Api.Init(COM);
+
+                    // Parametros de compilação
+                    BuildParams.Add("display.ERROS", "true");
+                    BuildParams.Add("display.IR", "true");
+                    BuildParams.Add("display.AST", "true");
+                    BuildParams.Add("mode", "developement");
+
+                    // Especifica a classe de geração de codigo alvo mips
+                    Target.Add("mips", new targets.mips.Gen());
+                    Target.Add("mipsjun", new targets.mips.jun.Gen());
+
+                    // Registra os processadores para o alvo mips
+                    // Executa alocacao de registradores antes de traduzir cada bloco
+                    CodeProcessor.On("mips,mipsjun", "BeforeTranslateBlock", "mips.register.alloc");
+                    CodeProcessor.On("mips,mipsjun", "AfterTranslateBlock", "mips.o.L1,mips.copy.dep");
+                    // Atualiza os enderecos
+                    CodeProcessor.On("mips,mipsjun", "AfterTranslate", "mips.update.address");
+
+                    // String file = "src\\samples\\program.go",
+                    // String file = "src\\samples\\program.go",
+                    // String file = "src\\samples\\program_mult_manycore.go",
+                    // String file = "src\\samples\\program_mult_jon.go",
+                    // String file = "src\\samples\\program_mult.go",
+                    file = "src\\samples\\program_jun_bit_count.go";
+                    COM.Compile(file);
             }
 
         } catch (Exception ex) {

+ 34 - 114
src/compiler/IvannosysCompiler.java

@@ -5,21 +5,21 @@
  */
 package compiler;
 
-import common.SyntaxError;
-import common.IvannosysTargetArch;
-import API.Api;
 import API.BuildParams;
-import common.Instruction;
-import common.Code;
+import API.Target;
 import IntermediaryCode.IRGenInterface;
 import ast.AbstractSyntaxTree;
 import ast.Semantic;
+import common.Code;
 import common.ErrorReport;
+import common.Instruction;
+import common.IvannosysTargetArch;
 import common.Log;
-import grammar.IvannosysGrammarLexer;
-import grammar.IvannosysGrammarParser;
+import common.SyntaxError;
 import frontend.Ivannosys.IvannosysListener;
 import frontend.Ivannosys.IvannosysVisitor;
+import grammar.IvannosysGrammarLexer;
+import grammar.IvannosysGrammarParser;
 import java.io.File;
 import java.io.IOException;
 import java.util.ArrayList;
@@ -42,91 +42,31 @@ public final class IvannosysCompiler {
 
     public static final int INPUT_FILE = 0;
     public static final int INPUT_STREAM = 1;
-    protected String inputFile = "";
-    protected String inputStream = "";
+    protected String userInput = "";
     protected String encType = "UTF-8";
     protected int inputType = 0;
     public ArrayList<String> path;
     public ArrayList<String> pathLibs;
     protected ParseTreeWalker walker;
     protected IvannosysListener listener;
-    protected IvannosysGrammarParser.InitContext tree;
-//    protected IvannosysVisitor iVisitor;
-    protected HashMap<String, IvannosysTargetArch> targets = new HashMap<>();
-//    protected HashMap<String, IvannosysVisitor> visitors;
-    protected HashMap<String, AbstractSyntaxTree> asts;
+    protected IRGenInterface IR;
     protected AbstractSyntaxTree ast;
-    protected HashMap<String, String> settings;
     protected String ExtensionLibrary = ".go";
+    protected HashMap<String, AbstractSyntaxTree> asts;
+    protected IvannosysGrammarParser.InitContext tree;
+    protected HashMap<String, IvannosysTargetArch> targets = new HashMap<>();
 
-    protected String EnvPathVarName = "IVANPATH";
-    protected String EnvBinVarName = "IVANBIN";
-    protected String EnvRootVarName = "IVANROOT";
-    protected IRGenInterface IR;
-
-    IvannosysCompiler(String srcinputprogram, String enc, int inputType) throws Exception {
-        settings = new HashMap<>();
-        path = new ArrayList<>();
-        pathLibs = new ArrayList<>();
-//        visitors = new HashMap<>();
-        asts = new HashMap<>();
+    IvannosysCompiler(String enc, int inputType) throws Exception {
         ast = AbstractSyntaxTree.getAbstractSyntaxTree();
-        if (inputType == INPUT_STREAM) {
-            inputStream = srcinputprogram;
-        } else {
-            inputFile = srcinputprogram;
-        }
+        asts = new HashMap<>();
+        path = new ArrayList<>();
         encType = enc;
+        pathLibs = new ArrayList<>();
 
-        initSrcPath();
-        initOptions();
-    }
-
-    protected IvannosysCompiler RegisterTarget(String id, IvannosysTargetArch target) {
-        targets.put(id, target);
-        return this;
-    }
-
-    protected boolean HasTarget(String id) {
-        return targets.containsKey(id);
-    }
-
-    protected void initSrcPath() throws Exception {
-        String[] variavies = new String[]{this.EnvPathVarName, this.EnvRootVarName};
-        for (String variavel : variavies) {
-            variavel = System.getenv(variavel);
-            if (variavel == null) {
-                throw new Exception(String.format("Não encontrou a variável de ambeinte %s.", variavel));
-            }
-            include(variavel);
-        }
-    }
-
-    /**
-     * StingS.put("clearCode", true);<br>
-     * StingS.put("developement",falSe);<br>
-     * StingS.put("diSplayASt", falSe);<br>
-     * StingS.put("diSplayErroS", falSe);<br>
-     * StingS.put("diSplaParSerTree", falSe);
-     *
-     * @return
-     */
-    public IvannosysCompiler initOptions() {
-        settings.put("clearCode", "true");
-        settings.put("developement", "false");
-        settings.put("displayAst", "false");
-        settings.put("displayErros", "false");
-        settings.put("displaParserTree", "false");
-        return this;
-    }
-
-    public IvannosysCompiler SetOption(String prop, String valor) {
-        settings.put(prop, valor);
-        return this;
     }
 
-    public IvannosysCompiler SetClearCode(String lc) {
-        settings.put("clearCode", lc);
+    public IvannosysCompiler IRGenerator(IRGenInterface ir) {
+        this.IR = ir;
         return this;
     }
 
@@ -137,14 +77,20 @@ public final class IvannosysCompiler {
         return listener;
     }
 
-    public IvannosysCompiler Compile() throws IOException, Exception {
+    public void Compile(String input) throws Exception {
+        this.userInput = input;
+        Compile();
+    }
+
+    protected IvannosysCompiler Compile() throws IOException, Exception {
         try {
             // create a CharStream that reads from standard input
             ANTLRInputStream input;
+
             if (inputType == INPUT_STREAM) {
-                input = new ANTLRInputStream(inputStream);
+                input = new ANTLRInputStream(userInput);
             } else {
-                input = new ANTLRFileStream(inputFile, encType);
+                input = new ANTLRFileStream(userInput, encType);
             }
 
             SyntaxError se = new SyntaxError();
@@ -166,8 +112,6 @@ public final class IvannosysCompiler {
                 return this;
             }
 
-            Api.inicializar(this);
-
             listener = getListener();
             walker = new ParseTreeWalker();
 
@@ -202,7 +146,7 @@ public final class IvannosysCompiler {
 
             Log.PrintInfo("TAC", new Instruction().S("msg", "Gerando código de três endereços"));
 
-            Code code = IR.Create(ast, settings);
+            Code code = IR.Create(ast);
 
             for (String arch : BuildParams.Get("target")) {
                 Log.PrintInfo("TAC → TARGET", new Instruction().S("msg", "Gerando código " + arch));
@@ -211,7 +155,7 @@ public final class IvannosysCompiler {
 
         } catch (Exception e) {
             System.out.println(e.getMessage());
-            if (settings.get("developement").equals("true")) {
+            if (BuildParams.GetFirst("mode").equals("developement")) {
                 e.printStackTrace();
             }
         }
@@ -219,25 +163,22 @@ public final class IvannosysCompiler {
     }
 
     public void Generate(String arch, Code code) throws Exception {
-        if (!HasTarget(arch)) {
-            throw new Exception(String.format("Arch '%s' não definida.", arch));
-        }
 
-        this.targets.get(arch)
+        Target.Get(arch)
                 .SetTAC(code)
                 .Compile()
                 .Format()
                 .Export();
     }
 
-    protected void DisplayAST(IvannosysGrammarParser parser) {
-        if (settings.get("displaParserTree").equals("true")) {
+    protected void DisplayAST(IvannosysGrammarParser parser) throws Exception {
+        if (BuildParams.GetFirst("display.PARSETREE").equals("true")) {
 //            ((ParserRuleContext) tree).inspect(parser); 
             displayTree(parser);//mostra a arvore grafica
             System.out.println(tree.toStringTree(parser)); // print LISP-style tree
         }
 
-        if (settings.get("displayAst").equals("true")) {
+        if (BuildParams.GetFirst("display.AST").equals("true")) {
             System.out.println("...................................Abstract Syntax Tree");
             System.out.println(ast.stringfy());
         }
@@ -286,7 +227,7 @@ public final class IvannosysCompiler {
             IvannosysGrammarParser parser = new IvannosysGrammarParser((TokenStream) tokens);
             IvannosysGrammarParser.InitContext ltree = parser.init(); // begin parsing at init rule
 
-            if (settings.get("displaParserTree").equals("true")) {
+            if (BuildParams.GetFirst("displaParserTree").equals("true")) {
 //            ((ParserRuleContext) ltree).inspect(parser); //mostra a arvore grafica
                 System.out.println(ltree.toStringTree(parser)); // print LISP-style tree
                 displayTree(parser);//mostra a arvore grafica
@@ -300,16 +241,6 @@ public final class IvannosysCompiler {
         return this;
     }
 
-    public IvannosysCompiler setDisplayParserTree(boolean b) {
-        settings.put("displaParserTree", b ? "true" : "false");
-        return this;
-    }
-
-    public IvannosysCompiler setDisplayErros(boolean b) {
-        settings.put("displayErros", b ? "true" : "false");
-        return this;
-    }
-
     public IvannosysCompiler include(String srcinput) {
         if (!path.contains(srcinput)) {
             path.add(srcinput);
@@ -343,15 +274,4 @@ public final class IvannosysCompiler {
         this.ExtensionLibrary = ExtensionLibrary;
         return this;
     }
-
-    public IvannosysCompiler EnvPathVar(String ivanpath) {
-        this.EnvPathVarName = ivanpath;
-        return this;
-    }
-
-    public IvannosysCompiler TacGen(IRGenInterface tac) {
-        this.IR = tac;
-        return this;
-    }
-
 }

+ 26 - 23
src/target/mips/AllocatorMipsProcessor.java

@@ -3,14 +3,14 @@
  * To change this template file, choose Tools | Templates
  * and open the template in the editor.
  */
-package target.mips;
+package targets.mips;
 
 import API.Api;
-import IntermediaryCode.BaseBlockProcessor;
-import IntermediaryCode.BlockBaseGroup;
-import IntermediaryCode.BlockBaseOcorrences;
-import IntermediaryCode.CodeProcessing;
-import IntermediaryCode.Interval;
+import API.CodeProcessorInterface;
+import Processors.BaseBlockProcessor;
+import Processors.BlockBaseGroup;
+import Processors.BlockBaseOcorrences;
+import Processors.Interval;
 import common.AllocatorInterface;
 import common.Code;
 import common.Instruction;
@@ -21,33 +21,37 @@ import java.util.LinkedList;
  *
  * @author EUGENIO CARVALHO
  */
-public class AllocatorMipsProcessor implements AllocatorInterface, CodeProcessing {
+public class AllocatorMipsProcessor implements AllocatorInterface, CodeProcessorInterface {
 
+    protected int instructionPosition;
     protected Code tac;
     protected Registers registers;
+    protected BlockBaseGroup group;
     protected LinkedList<String> free = new LinkedList<>();
     protected BaseBlockProcessor blockProcessor;
-    protected BlockBaseGroup group;
-    protected int instructionPosition;
 
-    public AllocatorMipsProcessor(BaseBlockProcessor blockProcessor) {
-        this.blockProcessor = blockProcessor;
+    public AllocatorMipsProcessor() {
+
     }
 
     @Override
-    public void Exec(Code c, LinkedHashMap<String, CodeProcessing> cp) throws Exception {
+    public void Exec(Code c, LinkedHashMap<String, CodeProcessorInterface> cp) throws Exception {
+
+        System.out.println("AllocatorMipsProcessor:");
+        String blockname = c.Block().getName();
+        Code IR = c.Parent;
+        IR.Use(blockname);
+
         BlockBaseOcorrences bb;
         registers = new Registers();
-//        System.out.println("Exec Allocation:" + c.getCurrentBlockName());
-//        BlockBaseOcorrences group = ((BaseBlockProcessor) cp.get("live.var"))
-
-        group = blockProcessor.getBasicBlockGroup(c.Block().getName());
-        // 
-        group.Init();
+        blockProcessor = (BaseBlockProcessor) cp.get("ir.basic.blocks");
 
         instructionPosition = 0;
+        group = blockProcessor.getBasicBlockGroup(IR.Block().getName());
+        group.Init();
 
-        for (Instruction inst : c.Block().Instructions()) {
+        for (Instruction inst : IR.Block().Instructions()) {
+//            System.out.println("Alloc:(" + IR.Block().getName() + ")" + inst);
             // tipos onde não se usa registrador
             switch (inst.G("type")) {
                 case "jump":
@@ -59,12 +63,11 @@ public class AllocatorMipsProcessor implements AllocatorInterface, CodeProcessin
                 default:
                     // Se a instruncao pertence ao proximo bloco basico atualiza o grupo
                     bb = group.getBasicBlocks(1);
-                    
-//                    System.out.println("###ASSIGN:(" + instructionPosition + ")(" + group.getBasicBlocks(1).getLeader() + ")");
 
+//                    System.out.println("###ASSIGN:(" + instructionPosition + ")(" + group.getBasicBlocks(1).getLeader() + ")");
                     if (bb != null && instructionPosition >= bb.getLeader()) {
                         group.NextBlock();
-                        System.out.println(">>>>> Mudei para bloco basico:" + group.Current().getName());
+//                        System.out.println(">>>>> Mudei para bloco basico:" + group.Current().getName());
                     }
 
                     // Libera registradores alocados temporariamente
@@ -145,11 +148,11 @@ public class AllocatorMipsProcessor implements AllocatorInterface, CodeProcessin
 //                + " : "
 //                + leader + "] {");
 //        System.out.println(x);
-
         Interval interval = bb.Get(addr, position);
 
 //        System.out.println(bb);
 //        System.out.println(interval);
+//        System.out.println("}");
         // Define um registrador se não possuir um definido no intervalo
         if (!interval.RegisterDefined()) {
 //            System.out.println("Não tinha definido: Carregar da memoria(" + (!dst) + ")");

+ 7 - 11
src/target/mips/CopyDeps.java

@@ -3,32 +3,28 @@
  * To change this template file, choose Tools | Templates
  * and open the template in the editor.
  */
-package target.mips;
+package targets.mips;
 
+import API.CodeProcessorInterface;
 import common.Block;
 import common.Code;
-import IntermediaryCode.CodeProcessing;
 import java.util.LinkedHashMap;
 
 /**
  *
  * @author EUGENIO CARVALHO
  */
-class CopyDeps implements CodeProcessing {
+public class CopyDepsProcessor implements CodeProcessorInterface {
 
-    private Code tac;
+    protected Code tac;
 
-    public CopyDeps() {
-    }
-
-    CopyDeps(Code tac) {
-        this.tac = tac;
+    public CopyDepsProcessor() {
     }
 
     @Override
-    public void Exec(Code c, LinkedHashMap<String, CodeProcessing> cp) throws Exception {
+    public void Exec(Code c, LinkedHashMap<String, CodeProcessorInterface> cp) throws Exception {
         Block currentBlock = c.Block(),
-                tacBlock = tac.getBlocks().get(currentBlock.getName());
+                tacBlock = c.Parent.getBlocks().get(currentBlock.getName());
 //        System.out.println("EXEC COPY DEPS:" + currentBlock.getName() + "\n" + tacBlock.GetDependences());
         for (String dep : tacBlock.GetDependences()) {
             currentBlock.AddDependence(dep);

+ 20 - 24
src/target/mips/Gen.java

@@ -3,10 +3,9 @@
  * To change this template file, choose Tools | Templates
  * and open the template in the editor.
  */
-package target.mips;
+package targets.mips;
 
 import API.Utils;
-import IntermediaryCode.BaseBlockProcessor;
 import ast.Node;
 import common.Block;
 import common.Code;
@@ -28,6 +27,8 @@ import java.util.logging.Logger;
  */
 public class Gen extends API.TargetGen {
 
+    protected ArrayList<String> returnRegisters;
+
     protected HashMap<String, String> AddressCalculated = new HashMap<>();
 //    protected AllocatorMipsProcessor allocation = new AllocatorMipsProcessor();
     protected HashMap<String, String> formatMips = new HashMap<String, String>() {
@@ -70,33 +71,30 @@ public class Gen extends API.TargetGen {
             put("bgtz", "branch if register > 0");
         }
     };
-    protected ArrayList<String> returnRegisters;
     protected HashMap<String, Boolean> ctrlDataUpdate = new HashMap<>();
     protected Integer WORD_INC = 4;
 
     public Gen() {
-        super("MIPS");
+        super("mips");
+
     }
 
     public void Init() {
-        BaseBlockProcessor ocorrences = new BaseBlockProcessor();
-        // Rotinas executadas no codigo intermediario de um bloco antes de ser traduzido.
-        getIR()
-                .BeforeTranslateBlock("basic.blocks", ocorrences)
-                .BeforeTranslateBlock("remove.load.store", new LoadStoreProcessor(ocorrences))
-                .BeforeTranslateBlock("register.alloc", new AllocatorMipsProcessor(ocorrences));
-
+//        // Rotinas executadas no codigo intermediario de um bloco antes de ser traduzido.
+//        getIR()
+//                .BeforeTranslateBlock("register.alloc", new AllocatorMipsProcessor());
+//
         getTarget()
-                // Rotina a ser executada em um bloco do codigo alvo depois de ser traduzido.
-                .AfterTranslateBlock("oti.1", new OtimizationMips())
-                // Otimizacao - Reducao do registro de ativacao de uma chamada
-                //                .AfterTranslateBlock("oti.1", new OTMinActivationRegister(ocorrences))
-                // Rotina a ser executada em todo o codigo alvo apos ser traduzido.
-                .AfterTranslate("update.address", new UpdateAddressProcessor())
-                // Tefinicao da classe de renderizacao de templates
+                //                // Rotina a ser executada em um bloco do codigo alvo depois de ser traduzido.
+                //                .AfterTranslateBlock("oti.1", new OtimizationMips())
+                //                // Otimizacao - Reducao do registro de ativacao de uma chamada
+                //                //                .AfterTranslateBlock("oti.1", new OTMinActivationRegister(ocorrences))
+                //                // Rotina a ser executada em todo o codigo alvo apos ser traduzido.
+                //                .AfterTranslate("update.address", new UpdateAddressProcessor())
+                // Definicao da classe de renderizacao de templates
                 .Template(new TemplateMips())
-                // Templa das instrucoes mips
                 .Formats(formatMips);
+
     }
 
     @Override
@@ -114,8 +112,7 @@ public class Gen extends API.TargetGen {
 
         //Se o valor deve ser armazenado em memoria
 //        String regDst = inst.G("reg.dst");
-        System.out.println("COPY:::::::::::" + inst);
-
+//        System.out.println("COPY:::::::::::" + inst);
 //        if (inst.eq("reg.dst.store", "true")) {
 //
 ////            System.out.println("::" + inst);
@@ -294,7 +291,7 @@ public class Gen extends API.TargetGen {
                         getTarget().Block().Data().Offset(p1));
             }
 
-            System.out.println("Translate pop return" + inst);
+//            System.out.println("Translate pop return" + inst);
         } catch (Exception ex) {
             Logger.getLogger(Gen.class.getName()).log(Level.SEVERE, null, ex);
         }
@@ -672,8 +669,7 @@ public class Gen extends API.TargetGen {
 
             Init();
 
-            getTarget().AfterTranslateBlock("copy.dep", new CopyDeps(tac));
-
+//            getTarget().AfterTranslateBlock("copy.dep", new CopyDeps(tac));
 //            CopyData(target.GData().values(), IR.GData().values());
             CopyData(
                     target.GData(),

+ 5 - 5
src/target/mips/LoadStoreProcessor.java

@@ -3,10 +3,10 @@
  * To change this template file, choose Tools | Templates
  * and open the template in the editor.
  */
-package target.mips;
+package targets.mips;
 
-import IntermediaryCode.BaseBlockProcessor;
-import IntermediaryCode.CodeProcessing;
+import Processors.BaseBlockProcessor;
+import API.CodeProcessorInterface;
 import common.Code;
 import java.util.LinkedHashMap;
 
@@ -14,13 +14,13 @@ import java.util.LinkedHashMap;
  *
  * @author EUGENIO CARVALHO
  */
-class LoadStoreProcessor implements CodeProcessing {
+class LoadStoreProcessor implements CodeProcessorInterface {
 
     public LoadStoreProcessor(BaseBlockProcessor ocorrences) {
     }
 
     @Override
-    public void Exec(Code c, LinkedHashMap<String, CodeProcessing> cp) throws Exception {
+    public void Exec(Code c, LinkedHashMap<String, CodeProcessorInterface> cp) throws Exception {
 //        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
     }
 

+ 1 - 1
src/target/mips/Mips.java

@@ -3,7 +3,7 @@
  * To change this template file, choose Tools | Templates
  * and open the template in the editor.
  */
-package target.mips;
+package targets.mips;
 
 import common.Instruction;
 import java.util.HashMap;

+ 6 - 6
src/target/mips/UpdateAddressProcessor.java

@@ -3,12 +3,12 @@
  * To change this template file, choose Tools | Templates
  * and open the template in the editor.
  */
-package target.mips;
+package targets.mips;
 
 import common.Instruction;
 import common.Block;
 import common.Code;
-import IntermediaryCode.CodeProcessing;
+import API.CodeProcessorInterface;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.LinkedHashMap;
@@ -18,18 +18,18 @@ import java.util.Map;
  *
  * @author EUGENIO CARVALHO
  */
-public class UpdateAddressProcessor implements CodeProcessing {
+public class MipsUpdateAddressProcessor implements CodeProcessorInterface {
 
     protected HashMap<String, Boolean> updateOffsetShift;/*
             
-     public UpdateAddressProcessor() {
+     public MipsUpdateAddressProcessor() {
      }
 
      (parseInt("2c",10) * 4).toString(16)
      */
 
 
-    public UpdateAddressProcessor() {
+    public MipsUpdateAddressProcessor() {
         this.updateOffsetShift = new HashMap<String, Boolean>() {
             {
                 put("beq", true);
@@ -44,7 +44,7 @@ public class UpdateAddressProcessor implements CodeProcessing {
 
     @Override
 
-    public void Exec(Code c, LinkedHashMap<String, CodeProcessing> cp) throws Exception {
+    public void Exec(Code c, LinkedHashMap<String, CodeProcessorInterface> cp) throws Exception {
         Integer offset;
         for (Map.Entry<String, Block> x : c.getBlocks().entrySet()) {
             for (Instruction y : x.getValue().Instructions()) {

+ 5 - 5
src/target/mips/OTMinActivationRegister.java

@@ -3,20 +3,20 @@
  * To change this template file, choose Tools | Templates
  * and open the template in the editor.
  */
-package target.mips;
+package targets.mips;
 
 import common.Block;
 import common.Code;
-import IntermediaryCode.CodeProcessing;
+import API.CodeProcessorInterface;
 import common.DataFrame;
-import IntermediaryCode.BaseBlockProcessor;
+import Processors.BaseBlockProcessor;
 import java.util.LinkedHashMap;
 
 /**
  *
  * @author EUGENIO CARVALHO
  */
-public class OTMinActivationRegister implements CodeProcessing {
+public class OTMinActivationRegister implements CodeProcessorInterface {
 
     protected BaseBlockProcessor ocorrences;
 
@@ -25,7 +25,7 @@ public class OTMinActivationRegister implements CodeProcessing {
     }
 
     @Override
-    public void Exec(Code c, LinkedHashMap<String, CodeProcessing> cp) throws Exception {
+    public void Exec(Code c, LinkedHashMap<String, CodeProcessorInterface> cp) throws Exception {
         Block B = c.Block();
         DataFrame D = B.Data();
 //        BlockBaseOcorrences o = ocorrences.getBlocks().get(B.getName());

+ 4 - 4
src/target/mips/OtimizationMips.java

@@ -3,23 +3,23 @@
  * To change this template file, choose Tools | Templates
  * and open the template in the editor.
  */
-package target.mips;
+package targets.mips;
 
+import API.CodeProcessorInterface;
 import common.Code;
-import IntermediaryCode.CodeProcessing;
 import java.util.LinkedHashMap;
 
 /**
  *
  * @author EUGENIO CARVALHO
  */
-class OtimizationMips implements CodeProcessing {
+public class OtimizationMips implements CodeProcessorInterface {
 
     public OtimizationMips() {
     }
 
     @Override
-    public void Exec(Code c, LinkedHashMap<String, CodeProcessing> cp) throws Exception {
+    public void Exec(Code c, LinkedHashMap<String, CodeProcessorInterface> cp) throws Exception {
     }
 
 }

+ 1 - 1
src/target/mips/Registers.java

@@ -4,7 +4,7 @@
  * and open the template 
  varsin the editor.
  */
-package target.mips;
+package targets.mips;
 
 import java.util.LinkedList;
 

+ 1 - 1
src/target/mips/TListenerMips.java

@@ -3,7 +3,7 @@
  * To change this template file, choose Tools | Templates
  * and open the template in the editor.
  */
-package target.mips;
+package targets.mips;
 
 import API.Api;
 import API.Utils;

+ 1 - 1
src/target/mips/TemplateMips.java

@@ -3,7 +3,7 @@
  * To change this template file, choose Tools | Templates
  * and open the template in the editor.
  */
-package target.mips;
+package targets.mips;
 
 import java.util.HashMap;
 import template.TPLInterface;

+ 7 - 7
src/target/mips/jun/Gen.java

@@ -3,7 +3,7 @@
  * To change this template file, choose Tools | Templates
  * and open the template in the editor.
  */
-package target.mips.jun;
+package targets.mips.jun;
 
 import API.BuildParams;
 import API.Utils;
@@ -20,17 +20,17 @@ import java.util.logging.Logger;
 import org.json.simple.JSONArray;
 import org.json.simple.JSONObject;
 import org.json.simple.parser.JSONParser;
-import target.mips.Mips;
-import target.mips.Registers;
-import target.mips.TemplateMips;
-import target.mips.UpdateAddressProcessor;
+import targets.mips.Mips;
+import targets.mips.Registers;
+import targets.mips.TemplateMips;
+import targets.mips.MipsUpdateAddressProcessor;
 
 /**
  * MipS tranSlation
  *
  * @author EUGENIO CARVALHO
  */
-public class Gen extends target.mips.Gen {
+public class Gen extends targets.mips.Gen {
 
     public Gen() {
         super();
@@ -58,7 +58,7 @@ public class Gen extends target.mips.Gen {
             Block func;
             JSONObject profile;
 
-            UpdateAddressProcessor uap = new UpdateAddressProcessor();
+            MipsUpdateAddressProcessor uap = new MipsUpdateAddressProcessor();
 
             ArrayList<String> p = BuildParams.Get("profile");
 

+ 1 - 1
src/tools/mips/MipsProcessor.java

@@ -13,7 +13,7 @@ import java.util.HashMap;
 import java.util.Map;
 import java.util.logging.Level;
 import java.util.logging.Logger;
-import target.mips.Mips;
+import targets.mips.Mips;
 
 /**
  *

+ 1 - 1
src/tools/mips/RegisterBank.java

@@ -27,7 +27,7 @@ class RegisterBank {
         REG_HI = i;
         REG_LO = i + 1;
 
-        for (Map.Entry<String, String> en : target.mips.Mips.registers.entrySet()) {
+        for (Map.Entry<String, String> en : targets.mips.Mips.registers.entrySet()) {
             names.add(en.getKey());
         }
         names.add("hi");

+ 4 - 4
src/tools/mips/memory/md.memory

@@ -4089,8 +4089,8 @@
 16352:	0
 16356:	0
 16360:	0
-16364:	-18554
-16368:	0
+16364:	0
+16368:	7
 16372:	0
-16376:	-18552
-16380:	10
+16376:	10033
+16380:	10033