Browse Source

for branch test

eugeniucarvalho 6 years ago
parent
commit
b61134bd83

BIN
build/classes/IntermediaryCode/BaseTacGen$1.class


BIN
build/classes/IntermediaryCode/BaseTacGen$2.class


BIN
build/classes/IntermediaryCode/BaseTacGen$3.class


BIN
build/classes/IntermediaryCode/BaseTacGen.class


BIN
build/classes/IntermediaryCode/DataFrame.class


+ 181 - 4
build/classes/samples/program.go

@@ -2,6 +2,170 @@
 
 package main;
 
+const (
+    LIN  = 2
+    COL  = 2
+)
+var (
+    matrizA [LIN][COL]int 
+)
+
+func main() {
+    var aux = 0
+/**
+FOR_OR_AND_AND_1:
+    for i := 0; (((i < LIN || 1 == 1) && (i < LIN && 1 == 1)) && 1 == 1 ); i++ {
+        //continue
+        aux = aux + 10
+        //break
+    }
+FOR_OR_AND_AND_OR:
+    for i := 0; (((i < LIN || 1 == 1) && (i < LIN && 1 == 1)) || 1 == 1 ); i++ {
+        //continue
+        aux = aux + 10
+        //break
+    }
+
+*/
+
+
+
+
+/**
+FOR_OR_AND_AND_1:
+    for i := 0; ((i < LIN || 1 == 1) && (i < LIN && 1 == 1)); i++ {
+        //continue
+        aux = aux + 10
+        //break
+    }
+
+FOR_AND_AND_OR_1:
+    for i := 0; ((i < LIN && 1 == 1) && (i < LIN || 1 == 1)); i++ {
+        //continue
+        aux = aux + 10
+        //break
+    }
+
+FOR_AND_OR_OR_1:
+    for i := 0; ((i < LIN && 1 == 1) || (i < LIN || 1 == 1)); i++ {
+        //continue
+        aux = aux + 10
+        //break
+    }
+
+FOR_OR_OR_AND_1:
+    for i := 0; ((i < LIN || 1 == 1) || (i < LIN && 1 == 1)); i++ {
+        //continue
+        aux = aux + 10
+        //break
+    }
+FOR_AND_OR_1:
+    for i := 0; ((i < LIN || 1 == 1) && (i < LIN || 1 == 1)); i++ {
+        //continue
+        aux = aux + 10
+        //break
+    }
+FOR_OR_AND_1:
+    for i := 0; ((i < LIN && 1 == 1) || (i < LIN && 1 == 1)); i++ {
+        //continue
+        aux = aux + 10
+        //break
+    }
+
+FOR_OR_1:
+    for i := 0; ((i < LIN || 1 == 1) || (i < LIN || 1 == 1)); i++ {
+        //continue
+        aux = aux + 10
+        //break
+    }
+
+FOR_OR_2:
+    for i := 0; i < LIN || 1 == 1; i++ {
+        //continue
+        aux = aux + 10
+        //break
+    }
+
+FOR_0:
+    for i := 0; ((i < LIN && 1 == 1) && (i < LIN && 1 == 1)); i++ {
+        //continue
+        aux = aux + 10
+        //break
+    }
+
+FOR_1:
+    for i := 0; (i < LIN && 1 == 1); i++ {
+        //continue
+        aux = aux + 10
+        //break
+    }
+
+FOR_2:
+
+    for i := 0; (i < LIN || 1 == 1); i++ {
+        //continue
+        aux = aux + 10
+        //break
+    }
+
+FOR_3:
+
+    for i := 0; (i < LIN); i++ {
+        //continue
+        aux = aux + 10
+        //break
+    }
+
+*/
+}
+
+/**
+
+package main;
+
+const (
+    LIN  = 2
+    COL  = 2
+)
+var (
+    matrizA [LIN][COL]int 
+    matrizB [LIN][COL]int
+    matrizR [LIN][COL]int
+)
+
+func preenche(){
+    var k = 1
+    for i := 0; i < LIN ; i++ {
+        for j := 0; j < COL ; j++ {
+            matrizA[i][j] = k
+            matrizB[i][j] = k
+            k++
+        }
+    }
+}
+
+func multiplica() {
+    var aux = 0
+    for i := 0; i < LIN; i++ {
+        for j := 0; j < COL; j++ {
+            for k := 0; k < LIN; k++ {
+                aux += matrizA[i][k] * matrizB[k][j]
+            }
+            matrizR[i][j] = aux
+            aux = 0
+        }
+    }
+}
+func main() {
+    preenche()
+    multiplica()
+}
+
+
+*/
+/**
+package main;
+
 const (
     LIN  = 2
     COL  = 2
@@ -15,10 +179,11 @@ type X struct {
 
 var (
     a [5][6]int
+    matrixX [3]X
 )
 
 func atualiza(x,i int) {
-    if (x != 1){
+    if (x == 1){
     //a[x][i].c = 1
 //    a[x][i] = 1
         a[x][i] = 10
@@ -26,11 +191,25 @@ func atualiza(x,i int) {
         i = 1
     }
 }
+
+func atualiza2(x *int) int {
+    *x = 10
+    return 2
+}
+
 func main() int {
     x := 1
     i := 1
+    
+    var (
+        varx X
+    )
 
-    atualiza(x,i)
+    i = atualiza2(y)
+    //atualiza(x,i)
+
+    //varx.c = 50
+    //matrixX[i].c = 50
 
 /*
 Testados
@@ -146,5 +325,3 @@ IF_ANDORAND_11:
     return x
 */
 
-
-}

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


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


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


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


File diff suppressed because it is too large
+ 0 - 1026
build/classes/tools/mips/memory/md.memory


+ 9 - 29
build/classes/tools/mips/memory/mi.memory

@@ -1,30 +1,10 @@
-0666763256
+0666763164
 0001962017
-0605028353
-0605093889
-0001056801
-0001124385
-0201326624
-4294967295
-0666763256
-0001962017
-2948857856
-2412249088
-2948923396
-2412314628
-0604635137
-0285868044
-0000546849
-0000743488
-0000745536
-0023877665
-0000616481
-0023943201
-0000749568
-0604962826
-0059666465
-2916024320
-0134217840
-0604569601
-0666697736
-0065011720
+0605028352
+0605093888
+0134217736
+0638189578
+0000688161
+0640745473
+2412576776
+0036507683

+ 3 - 3
build/classes/tools/mips/memory/mips.code

@@ -15,18 +15,18 @@
 30:  2948923396	sw a1,fp,4	.1.--pop param
 34:  2412314628	lw t1,fp,4	
 38:  0604635137	addiu t2,zero,1	.2.
-3c:  0285868044	beq t2,t0,6c <main.atualiza+0x4c>	.2.--branch if equals
+3c:  0352976908	bne t2,t0,6c <main.atualiza+0x4c>	.2.--branch if not equals
 40:  0000546849	addu t3,zero,t0	.3.--copy _T7 ← _T4
 44:  0000743488	sll t3,t3,1	.4.
 48:  0000745536	sll t4,t3,1	.5.
 4c:  0023877665	addu t3,t3,t4	.6.
 50:  0000616481	addu t5,zero,t1	.7.--copy _T10 ← _T6
 54:  0023943201	addu t3,t3,t5	.8.
-58:  0000749568	sll t6,t3,0	.9.
+58:  0000749696	sll t6,t3,2	.9.
 5c:  0604962826	addiu t7,zero,10	.10.
 60:  0059666465	addu t6,gp,t6	.10.
 64:  2916024320	sw t7,t6,0	.10.--store in loaded address
 68:  0134217840	j 70 <main.atualiza+0x50>	.11.
 6c:  0604569601	addiu t1,zero,1	.12.--copy _T6 ← 1
 70:  0666697736	addiu sp,sp,8	--e|pop stack frame
-74:  0065011720	jr ra	--e|return
+74:  0065011720	jr ra	--e|return

+ 1 - 1
src/API/Tipos.java

@@ -111,7 +111,7 @@ public class Tipos {
     }
 
     public static int Size(String type) {
-//        System.out.println("Size of " + type + ">" + _sizes.G(type));
+//        System.out.println("Size of " + type + ">" + _sizes);
         return _sizes.get(type);
     }
 

+ 242 - 274
src/IntermediaryCode/BaseTacGen.java

@@ -15,6 +15,7 @@ import ast.AbstractSyntaxTree;
 import ast.Node;
 import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.LinkedHashMap;
 import java.util.LinkedList;
 import java.util.Map;
 import java.util.Stack;
@@ -68,19 +69,9 @@ public final class BaseTacGen implements TacGenInterface {
     protected HashMap<String, String> ArrayShiftMap = new HashMap<>();
 
     public BaseTacGen() throws Exception {
-
-//        for (int i = 44; i > 0; i--) {
-//
-//            System.out.println("----- " + i);
-//
-//            ShiftPath(i);
-//
-//        }
-//        ShiftPath(48);
-//        ShiftPath(52);
-//        ShiftPath(56);
-//        ShiftPath(108);
-//        throw new Exception("SHIFT");
+        for (long i = 0; i < 31; i++) {
+            power2.put(Long.valueOf(1 << i), Long.valueOf(i));
+        }
     }
 
     protected int calc(ArrayList<Integer> data) {
@@ -112,27 +103,14 @@ public final class BaseTacGen implements TacGenInterface {
     }
 
     public BaseTacGen(AbstractSyntaxTree ast) {
-
         Ast(ast);
     }
 
-//    @Override
-//    public TacGenInterface AfterCreate(CodeProcessing p) {
-//        this.afterCreate.add(p);
-//        return this;
-//    }
-//
-//    public TacGenInterface AfterCreate() throws Exception {
-//        for (CodeProcessing x : afterCreate) {
-//            x.Exec(code);
-//        }
-//        return this;
-//    }
     public void Ast(AbstractSyntaxTree ast) {
         this.ast = ast;
         code = new Code("TAC", ast);
         code.AfterClose("clear.1", new CodeClearProcessor());
-        code.AfterClose("oti.1", new CodeOtimizadorProcessor(enableOtimization));
+//        code.AfterClose("oti.1", new CodeOtimizadorProcessor(enableOtimization));
 //        code.AfterClose("oti.1", new CodeOtimizadorProcessor(false));
         compileParams = ast.BuildParams();
 
@@ -323,26 +301,8 @@ public final class BaseTacGen implements TacGenInterface {
     }
 
     protected ArrayList<Integer> ShiftPath(int size) {
-
-//        ArrayList<Integer> ret1 = new ArrayList<>(), ret2 = new ArrayList<>();
-//        ArrayList<Integer> ret = new ArrayList<>();
-//        ArrayList<Integer> shift = ShiftInterval(size);
-//        Integer op = shift.get(2);
-//
-//        int s1 = shift.get(op);
-//
-//        ret.add(s1);
-//        ret.add(op);
-//
-//        FindShiftPath(size - s1, ret);
-//
-//        System.out.println("Find SHIFT path:{" + size + "}" + ret);
-//        return ret;
         ArrayList<Integer> ret = new ArrayList<>();
-
         FindShiftPath(size, ret);
-
-//        System.out.println("Find SHIFT path:{" + size + "}" + ret + "[" + (calc(ret) == size) + "]");
         return ret;
     }
 
@@ -376,42 +336,7 @@ public final class BaseTacGen implements TacGenInterface {
         return ret;
     }
 
-    protected HashMap<Integer, Integer> power2 = new HashMap<Integer, Integer>() {
-        {
-            put(1, 0);
-            put(2, 1);
-            put(4, 2);
-            put(8, 3);
-            put(16, 4);
-            put(32, 5);
-            put(64, 6);
-            put(128, 7);
-            put(256, 8);
-            put(512, 9);
-            put(1024, 10);
-            put(2048, 11);
-            put(4096, 12);
-            put(8192, 13);
-            put(16384, 14);
-            put(32768, 15);
-            put(65536, 16);
-            put(131072, 17);
-            put(262144, 18);
-            put(524288, 19);
-            put(1048576, 20);
-            put(2097152, 21);
-            put(4194304, 22);
-            put(8388608, 23);
-            put(16777216, 24);
-            put(33554432, 25);
-            put(67108864, 26);
-            put(134217728, 27);
-            put(268435456, 28);
-            put(536870912, 29);
-            put(1073741824, 30);
-//            put(2147483648, true);
-        }
-    };
+    protected LinkedHashMap<Long, Long> power2 = new LinkedHashMap<Long, Long>();
 
     protected void FindShiftPath(int size, ArrayList<Integer> path) {
         size = Math.abs(size);
@@ -458,6 +383,10 @@ public final class BaseTacGen implements TacGenInterface {
 //        FindShiftPath(size, m4, op, path);
     }
 
+    protected int Size(String type) {
+        return Tipos.Size(type) * 4;
+    }
+
     protected String ArrayShift(Node n) throws Exception {
         // Cria a chave para a ocorrencia de um acesso ao array, evitando recalcular o endereco
         String key = n.getText();
@@ -475,7 +404,7 @@ public final class BaseTacGen implements TacGenInterface {
                 n.childrens().get(i++).S("collNumber", var.childrens().get(j).getText());
             }
 
-            String ret = CalcArrayAddress(n.childrens(), Tipos.Size(var.G("type")));
+            String ret = CalcArrayAddress(n.childrens(), Size(var.G("type")));
             // Se o offset for calculado em um inteiro atribui o mesmo como shift
 //            if (Utils.isNumber(ret)) {
 //                shift = ret;
@@ -497,7 +426,7 @@ public final class BaseTacGen implements TacGenInterface {
         for (int i = path.size() - 1; i >= 0; i--) {
             reverse.add(path.remove(i));
         }
-        System.out.println(">>>>>(" + var + ", " + size + ")" + reverse);
+        System.out.println(">>>>>(var:" + var + ", size:" + size + ") arithpath:" + reverse);
 
         var = GSLL(var, reverse, mps, size);
 
@@ -513,7 +442,9 @@ public final class BaseTacGen implements TacGenInterface {
         switch (path.size()) {
             case 1:
                 if (!mps) {
-                    Copy(T1, var, false).S("comment", "Copy value of index").S("copy", "true");
+                    Copy(T1, var, false)
+                            .S("comment", "Copy value of index")
+                            .S("copy", "true");
                 } else {
                     T1 = var;
                 }
@@ -529,7 +460,9 @@ public final class BaseTacGen implements TacGenInterface {
 
 //                String T4 = gerarVariavel("T");
                 if (!mps) {
-                    Copy(T1, var, false).S("comment", "Copy value of index").S("copy", "true");
+                    Copy(T1, var, false)
+                            .S("comment", "Copy value of index")
+                            .S("copy", "true");
                 }
 
                 if (op1 != 1) {
@@ -563,7 +496,7 @@ public final class BaseTacGen implements TacGenInterface {
     }
 
     protected String CalcArrayAddress(ArrayList<Node> childrens, int Size) throws Exception {
-
+        System.out.println("CalcArrayAddressINIT:" + Size);
         boolean onlyNumber = true;
 
         for (Node node : childrens) {
@@ -580,8 +513,10 @@ public final class BaseTacGen implements TacGenInterface {
 //            System.out.println("CAA:" + childrens);
 
             String current = CalcArrayAddressAux(childrens, Size);
+
             System.out.println("Size {" + current + "}:----------->" + Size);
-            // multiplica pelo tamanho
+
+// multiplica pelo tamanho
             return GenShiftLeftLogical(current, Size, true);
         }
     }
@@ -900,138 +835,140 @@ public final class BaseTacGen implements TacGenInterface {
     protected void BranchAnd(Node n, int index) throws Exception {
 //        int pos = 0;
         OrTestAndOccurrence++;
+        Instruction instruction = null;
         ArrayList<Node> x = n.childrens();
         Node op1 = x.get(0), op2 = x.get(1);
+        String type = n.G("test.type"),
+                step = gerarLabel(),
+                attrs = "next,start,end,inc,test.type,skip.test";
 
-        String step = gerarLabel(), attrs = "next,start,end,skip.test,invert.test";
         n.S("skip.test", step);
 
         op1.copy(attrs, n);
         op2.copy(attrs, n);
 
-        switch (n.parent.G("value")) {
-            case "||":
-                if (index == 1) {
-                    // Se for o no atual for o operando 1 do pai
-                    op1.S("next", n.parent.G("skip.test")).S("invert.test", "true");
-                    op2.S("next", n.G("start")).S("invert.test", "false");
-
-                } else if (index == 2) {
-                    op1.S("invert.test", "true");
-                    op2.S("invert.test", "true");
-
-                    System.out.println("BA:" + n + "\b" + op1);
-                    // Se for o no atual for o operando 1 do pai
-//                    op1.S("next", n.G("next"));
-//                    op2.S("next", n.G("next"));
-                }
-//                pos = 2;
-                break;
-            case "&&":
-                if (index == 1) {
-                    // Se for o no atual for o operando 1 do pai
-                    op1.S("invert.test", "true");
-                    op2.S("invert.test", "true");
-                } else if (index == 2) {
-                    op2.S("invert.test", "true");
-                    op2.S("invert.test", "true");
-                }
-//                pos = 1;
-            default:
+        instruction = Branch(op1, 1);
 
-        }
+        if (instruction != null) {
+            switch (type) {
+                case "jtb":
+                    instruction.S("op", Complement(instruction.G("op")));
 
-        Branch(op1, 1);
+                    if (n.parent.eq("value", "||")) {
+                        if (index == 1) {
+                            instruction.S("label", n.parent.G("skip.test"));
+                        } else if (index == 2) {
+                            instruction.S("label", n.parent.G("end"));
+                        }
+//                    } else if (n.parent.eq("value", "&&")) {
 
-        if (index == 0 || (op1.in("value", new String[]{"||", "&&"}) && !n.eq("value", op1.G("value")))) {
-            // Registra o label para o saldo dos testes do primeiro parametro
-            PushLabel(step, "branch");
+                    } else {
+                        instruction.S("label", n.G("end"));
+                    }
+            }
         }
+//        System.out.println("instruction Branch 1:" + instruction + "\n" + op1);
 
-        Branch(op2, 2);
-
+//        if (index == 0 || (op1.in("value", new String[]{"||", "&&"}) && !n.eq("value", op1.G("value")))) {
+        // Registra o label para o saldo dos testes do primeiro parametro
+        PushLabel(step, "branch");
+//        }
+        instruction = Branch(op2, 2);
+        if (instruction != null) {
+            switch (type) {
+                case "jtb":
+                    if (n.parent.eq("value", "||")) {
+                        if (index == 1) { // teste 1 do parametro 2 com pai ||
+                            instruction.S("op", Complement(instruction.G("op")));
+                            instruction.S("label", n.G("end"));
+                        } else if (index == 2) {  // teste 2 do parametro 2
+                            instruction.S("label", n.G("start"));
+                        }
+//                    } else if (n.parent.eq("value", "&&")) {
+//                        if (index == 1) { // teste 1 do parametro 2 com pai && 
+////                            throw new Exception("// teste 1 do parametro 2 com pai &&");
+//
+//                        } else if (index == 2) {  // teste 2 do parametro 2 com pai && 
+//                            instruction.S("op", Complement(instruction.G("op")));
+//                            instruction.S("label", n.G("end"));
+//                        }
+                    } else {
+                        if (index == 1) {  // teste 1 do parametro 2 geral
+                            instruction.S("op", Complement(instruction.G("op")));
+                            instruction.S("label", n.G("end"));
+                        } else if (index == 2) {
+//                            throw new Exception("teste 2 do parametro 2 geral");
+                        }
+                    }
+            }
+        }
     }
 
     protected void BranchOr(Node n, int index) throws Exception {
-        boolean root = index == 0;
-        String step = gerarLabel(), attrs = "next,start,end,skip.test,invert.test";
+        //        int pos = 0;
+        OrTestAndOccurrence++;
+        Instruction instruction = null;
         ArrayList<Node> x = n.childrens();
         Node op1 = x.get(0), op2 = x.get(1);
+        String type = n.G("test.type"),
+                step = gerarLabel(),
+                attrs = "next,start,end,inc,test.type,skip.test";
 
-        if (root) {
-            OrTestAndOccurrence = 0;
-        }
         n.S("skip.test", step);
 
         op1.copy(attrs, n);
         op2.copy(attrs, n);
 
-        switch (n.parent.G("value")) {
-            case "||":
-                if (index == 1) {
-                    // Se for o no atual for o operando 1 do pai
-//                    op1.S("true", n.G("skip.test"));
-                } else if (index == 2) {
-                    // Se for o no atual for o operando 2 do pai
-//                    op2.S("true", n.G("start"));
-                } else {
-//                
-                }
-
-            case "&&":
-                if (index == 1) {
-                    // Se for o no atual for o operando 1 do pai
-                    op1.S("next", n.parent.G("skip.test"));
-                    op1.S("invert.test", "true");
-
-                } else if (index == 2) {
-//                    op1.S("op", Complement(op1.G("op")));
-                    // Se for o no atual for o operando 2 do pai
-                    op2.S("next", n.G("start"));
-//                    op2.S("invert.test2", "true");
-                } else {
-
-                }
-                break;
-        }
-
-        Branch(op1, 1);
+        System.out.println("BranchOr:" + n.parent);
+        // Executa o lado esquerdo do ||
+        instruction = Branch(op1, 1);
 
-        if (index == 0 || (op1.in("value", new String[]{"||", "&&"}) && !n.eq("value", op1.G("value")))) {
-            // Registra o label para o saldo dos testes do primeiro parametro
-            PushLabel(step, "branch");
+        if (instruction != null) {
+            switch (type) {
+                case "jtb":
+                    if (n.parent.eq("value", "&&")) {
+                        if (index == 1) {
+                            instruction.S("label", n.parent.G("skip.test"));
+                        }
+                    }
+            }
         }
-
-        Branch(op2, 2);
-//        if (pos == 2) {
-//            // Registra o label para o saldo dos testes do primeiro parametro
-//            PushLabel(step, "branch");
-//        }
-        // Se o n for a raiz do test e não ocorre uma combinação and inverte o ultimo 
-        // test para saltar o bloco
-        if (root && OrTestAndOccurrence == 0) {
-            Instruction inst = code.Last();
-            code.RemoveLabelReference(inst.G("label"));
-            String next = n.G("next");
-            inst.S("op", Complement(inst.G("op"))).S("label", next);
-
-            code.AddLabelReference(next);
-
+//        System.out.println("instruction Branch 1:" + instruction + "\n" + op1);
+        // Registra o label para o saldo dos testes do primeiro parametro
+        PushLabel(step, "branch");
+
+        // Executa o lado direito do ||
+        instruction = Branch(op2, 2);
+        if (instruction != null) {
+            switch (type) {
+                case "jtb":
+                    if (n.parent.eq("value", "&&")) {
+                        if (index == 1) {
+                            instruction.S("op", Complement(instruction.G("op")));
+                            instruction.S("label", n.parent.G("end"));
+                        }
+                    }
+            }
         }
-
-//        branckInvert.pop();
     }
 
-    protected void BranchTest(Node n, int index) throws Exception {
-//                boolean empty = branckInvert.isEmpty();
-//
-//                if (empty) {
-//                    branckInvert.push(true);
-//                }
-
-        String op = n.getText(), p0, p1, label = n.G("next");
+    protected Instruction BranchTest(Node n, int index) throws Exception {
         ArrayList<Node> x = n.childrens();
-        boolean invert = true;
+        String type = n.G("test.type");
+        boolean invert = false;
+        String op, p0, p1, next = "";
+
+        switch (type) {
+            case "jb":
+                invert = true;
+                next = n.G("end");
+                break;
+            case "jtb":
+                next = n.G("start");
+                break;
+            default:
+                throw new Exception("test.type '".concat(type).concat("' not suported. Values {jtb,jb}"));
+        }
 
         visit(n);
 
@@ -1041,34 +978,33 @@ public final class BaseTacGen implements TacGenInterface {
             p0 = n.G("_return");
             p1 = "1";
         } else { //(<, <=, >, >=, ==, !=)
+            op = n.getText();
             p0 = visit(x.get(0)).G("_return");
             p1 = visit(x.get(1)).G("_return");
         }
 
-        switch (n.parent.G("value")) {
-            case "||":
-                if (index == 1) {
-                    invert = false;
-                    label = n.G("start");
-                }
-                break;
-            case "&&":
-                break;
-            default:
-            // Sem combinação ( || / && )
-        }
-        if (n.eq("invert.test", "false")) {
-            invert = false;
-        }
-
+        // Inverte o teste e salta o bloco
         if (invert) {
-            // Inverte o teste e salta o bloco
             op = Complement(op);
         }
+
+        return Branch(op, p0, p1, next);
+
+//        switch (n.parent.G("value")) {
+//            case "||":
+//                if (index == 1) {
+//                    invert = false;
+//                    next = n.G("start");
+//                }
+//                break;
+//            case "&&":
+//                break;
+//            default:
+//            // Sem combinação ( || / && )
+//        }
 //        System.out.println("BranchTest:[" + index + ":" + op + ":" + invert
 //                + ":" + n.eq("invert.test", "false") + "]" + n);
-
-        Instruction instruction = Branch(op, p0, p1, label);
+//        Instruction instruction = Branch(op, p0, p1, label);
 //                instruction. ;
 //                if (n.Has("false")) {
         //                    _goto(n.G("false"));
@@ -1083,7 +1019,6 @@ public final class BaseTacGen implements TacGenInterface {
         Instruction r1 = new Instruction();
         r1.S("format", "branch")
                 .S("type", "branch")
-                //                .S("op", (!branckInvert.isEmpty() && branckInvert.peek()) ? Complement(op) : op)
                 .S("op", op)
                 .S("p1", p1)
                 .S("p2", p2)
@@ -1096,11 +1031,11 @@ public final class BaseTacGen implements TacGenInterface {
         return r1;
     }
 
-    protected void Branch(Node n, int index) throws Exception {
-        ArrayList<Node> x = n.childrens();
+    protected Instruction Branch(Node n, int index) throws Exception {
+//        ArrayList<Node> x = n.childrens();
+        Instruction instruction = null;
 
         switch (n.getText()) {
-
             case "&&":
                 BranchAnd(n, index);
                 break;
@@ -1108,58 +1043,14 @@ public final class BaseTacGen implements TacGenInterface {
                 BranchOr(n, index);
                 break;
             default:
-                BranchTest(n, index);
-//            case "||":
-//                and = false;
-//                // Não deve inverter operacao no caso de ||
-//                branckInvert.push(and);
-//
-//                _or(n);
-//
-//                Branch(x.get(0));
-//                Branch(x.get(1));
-//
-//                // Inverte a ultima operacao
-//                if (n.parent.eq("value", "||")) {
-//                }
-//
-////                if (!loop && branckInvert.size() == 1) {
-////                    Instruction last = code.Last();
-////                    last.S("op", Complement(last.G("op"))).S("label", n.G("next"));
-////                }
-//                if (!x.get(0).Has("and")) {
-//                    n.remove("and");
-//                }
-//                branckInvert.pop();
-//
-//                break;
-//            default:
-////                boolean empty = branckInvert.isEmpty();
-////
-////                if (empty) {
-////                    branckInvert.push(true);
-////                }
-//
-//                visit(n);
-//                // Resultado do test class ou acesso a um id ou bool
-//                if (!n.eq("class", "expr")) {
-//                    op = "==";
-//                    p0 = n.G("_return");
-//                    p1 = "1";
-//                } else { //(<, <=, >, >=, ==, !=)
-//                    p0 = visit(x.get(0)).G("_return");
-//                    p1 = visit(x.get(1)).G("_return");
-//                }
-//
-//                Instruction instruction = Branch(op, p0, p1, n.G("next"));
-////                instruction. ;
-////                if (n.Has("false")) {
-//            //                    _goto(n.G("false"));
-//            //                }
-//            //                if (empty) {
-//            //                    branckInvert.pop();
-//            //                }
+                instruction = BranchTest(n, index);
         }
+
+        if (index == 0 && instruction != null) {
+
+        }
+
+        return instruction;
 //        if (and) {
 //            n.remove("or");
 //        }
@@ -1272,22 +1163,26 @@ public final class BaseTacGen implements TacGenInterface {
      * @throws Exception
      */
     protected void genFor(Node n) throws Exception {
+        String attrs = "next,start,end,inc,test";
         Node test = n.find("test").first();
 
         setMaster(n);
 
         String start = gerarLabel(),
-                next = gerarLabel(),
+                //                next = gerarLabel(),
                 end = gerarLabel(),
+                inc = gerarLabel(),
                 testLabel = gerarLabel();
 
-        n.S("next", next)
-                .S("start", start)
+        n.S("start", start)
                 .S("end", end)
+                .S("inc", inc)
                 .S("test", testLabel);
 
         Node stmt = n.find("stmts");
-        stmt.copy("next,start,end,test", n);
+
+        stmt.copy(attrs, n);
+        test.copy(attrs, n).S("test.type", "jtb");
 
         /*Inicializacoes e atribuicoes*/
         visit(n.find("initialization"));
@@ -1301,21 +1196,25 @@ public final class BaseTacGen implements TacGenInterface {
         /*Executa o bloco do for*/
         visit(stmt);
 
+        /*Label que marca os incrementos dos laco*/
+        PushLabel(inc, "branch");
+
         /*Executa os incrementos*/
         visit(n.find("increment"));
 
         /*Label que marca o teste do laco*/
         PushLabel(testLabel, "branch");
 
-        test.copy("next,start,end,test", n).S("test.type", "for");
-
+        // test.type = ((JumpToBlock in LOOP) | (JumpBlock in IF || SWITCH))
+        // test.type = JumpToBlock 
 //        test.S("test.type", "for").S("next", next).S("end", end).S("or", next);
 //        System.out.println("Teste:" + test);
         Branch(test, 0);
 
-        if (n.Has("set.end_label")) {
-            PushLabel(n.G("end"), "branch");
-        }
+//        if (n.Has("set.end_label")) {
+//        PushLabel(n.G("end"), "branch");
+        PushLabel(end, "branch");
+//        }
 
         setNullMaster();
     }
@@ -1909,10 +1808,16 @@ public final class BaseTacGen implements TacGenInterface {
 
         switch (n.getText()) {
             case "continue":
-                _goto(container.G("start"));
+                String go;
+                if (container.eq("class", "for.stmt")) {
+                    go = container.G("inc");
+                } else {
+                    go = container.G("end");
+                }
+                _goto(go);
                 break;
             case "break":
-                _goto(container.G("next"));
+                _goto(container.G("end"));
                 break;
             case "goto":
                 _goto(n.G("label"));
@@ -2253,3 +2158,66 @@ public final class BaseTacGen implements TacGenInterface {
     }
 
 }
+//            case "||":
+//                and = false;
+//                // Não deve inverter operacao no caso de ||
+//                branckInvert.push(and);
+//
+//                _or(n);
+//
+//                Branch(x.get(0));
+//                Branch(x.get(1));
+//
+//                // Inverte a ultima operacao
+//                if (n.parent.eq("value", "||")) {
+//                }
+//
+////                if (!loop && branckInvert.size() == 1) {
+////                    Instruction last = code.Last();
+////                    last.S("op", Complement(last.G("op"))).S("label", n.G("next"));
+////                }
+//                if (!x.get(0).Has("and")) {
+//                    n.remove("and");
+//                }
+//                branckInvert.pop();
+//
+//                break;
+//            default:
+////                boolean empty = branckInvert.isEmpty();
+////
+////                if (empty) {
+////                    branckInvert.push(true);
+////                }
+//
+//                visit(n);
+//                // Resultado do test class ou acesso a um id ou bool
+//                if (!n.eq("class", "expr")) {
+//                    op = "==";
+//                    p0 = n.G("_return");
+//                    p1 = "1";
+//                } else { //(<, <=, >, >=, ==, !=)
+//                    p0 = visit(x.get(0)).G("_return");
+//                    p1 = visit(x.get(1)).G("_return");
+//                }
+//
+//                Instruction instruction = Branch(op, p0, p1, n.G("next"));
+////                instruction. ;
+////                if (n.Has("false")) {
+//            //                    _goto(n.G("false"));
+//            //                }
+//            //                if (empty) {
+//            //                    branckInvert.pop();
+//            //                }
+
+//    @Override
+//    public TacGenInterface AfterCreate(CodeProcessing p) {
+//        this.afterCreate.add(p);
+//        return this;
+//    }
+//
+//    public TacGenInterface AfterCreate() throws Exception {
+//        for (CodeProcessing x : afterCreate) {
+//            x.Exec(code);
+//        }
+//        return this;
+//    }

+ 20 - 7
src/IntermediaryCode/DataFrame.java

@@ -5,7 +5,6 @@
  */
 package IntermediaryCode;
 
-import API.Tipos;
 import API.Utils;
 import ast.AbstractSyntaxTree;
 import ast.Node;
@@ -50,13 +49,21 @@ public class DataFrame {
         initialized = init;
     }
 
-    public DataFrame Add(String alias, Node var) {
-
-        int size = Integer.parseInt(var.G("size"));
+    public DataFrame Add(String alias, Node var) throws Exception {
+//        System.out.println("Add data to frame:" + var);
+        int size = var.getInt("size"), vSize = 1;
+//        boolean isArray = var.eq("array", "true");
 
+//        if (isArray) {
+//            vSize = Tipos.Size(var.G("type"));
+//        }
         for (int i = 0; i < size; i++) {
-            values.put(alias + "." + i, var.copy().S("size", Tipos.Size(var.G("type"))));
+            values.put(
+                    alias + "." + i,
+                    var.copy().S("size", vSize)
+            );
         }
+
         return this;
     }
 
@@ -92,9 +99,15 @@ public class DataFrame {
     @Override
     public String toString() {
         StringBuilder s = new StringBuilder("Data Frame <" + name + ">:" + Size() + "\n");
-
+        Node value;
         for (Map.Entry<String, Node> x : values.entrySet()) {
-            s.append(x.getKey()).append(": ").append(x.getValue().G("name")).append("\n");
+            value = x.getValue();
+            s.append(x.getKey())
+                    .append(": ")
+                    .append(value.G("name"))
+                    .append("\tsize:")
+                    .append(value.G("size"))
+                    .append("\n");
         }
 
         return s.toString();

+ 181 - 4
src/samples/program.go

@@ -2,6 +2,170 @@
 
 package main;
 
+const (
+    LIN  = 2
+    COL  = 2
+)
+var (
+    matrizA [LIN][COL]int 
+)
+
+func main() {
+    var aux = 0
+/**
+FOR_OR_AND_AND_1:
+    for i := 0; (((i < LIN || 1 == 1) && (i < LIN && 1 == 1)) && 1 == 1 ); i++ {
+        //continue
+        aux = aux + 10
+        //break
+    }
+FOR_OR_AND_AND_OR:
+    for i := 0; (((i < LIN || 1 == 1) && (i < LIN && 1 == 1)) || 1 == 1 ); i++ {
+        //continue
+        aux = aux + 10
+        //break
+    }
+
+*/
+
+
+
+
+/**
+FOR_OR_AND_AND_1:
+    for i := 0; ((i < LIN || 1 == 1) && (i < LIN && 1 == 1)); i++ {
+        //continue
+        aux = aux + 10
+        //break
+    }
+
+FOR_AND_AND_OR_1:
+    for i := 0; ((i < LIN && 1 == 1) && (i < LIN || 1 == 1)); i++ {
+        //continue
+        aux = aux + 10
+        //break
+    }
+
+FOR_AND_OR_OR_1:
+    for i := 0; ((i < LIN && 1 == 1) || (i < LIN || 1 == 1)); i++ {
+        //continue
+        aux = aux + 10
+        //break
+    }
+
+FOR_OR_OR_AND_1:
+    for i := 0; ((i < LIN || 1 == 1) || (i < LIN && 1 == 1)); i++ {
+        //continue
+        aux = aux + 10
+        //break
+    }
+FOR_AND_OR_1:
+    for i := 0; ((i < LIN || 1 == 1) && (i < LIN || 1 == 1)); i++ {
+        //continue
+        aux = aux + 10
+        //break
+    }
+FOR_OR_AND_1:
+    for i := 0; ((i < LIN && 1 == 1) || (i < LIN && 1 == 1)); i++ {
+        //continue
+        aux = aux + 10
+        //break
+    }
+
+FOR_OR_1:
+    for i := 0; ((i < LIN || 1 == 1) || (i < LIN || 1 == 1)); i++ {
+        //continue
+        aux = aux + 10
+        //break
+    }
+
+FOR_OR_2:
+    for i := 0; i < LIN || 1 == 1; i++ {
+        //continue
+        aux = aux + 10
+        //break
+    }
+
+FOR_0:
+    for i := 0; ((i < LIN && 1 == 1) && (i < LIN && 1 == 1)); i++ {
+        //continue
+        aux = aux + 10
+        //break
+    }
+
+FOR_1:
+    for i := 0; (i < LIN && 1 == 1); i++ {
+        //continue
+        aux = aux + 10
+        //break
+    }
+
+FOR_2:
+
+    for i := 0; (i < LIN || 1 == 1); i++ {
+        //continue
+        aux = aux + 10
+        //break
+    }
+
+FOR_3:
+
+    for i := 0; (i < LIN); i++ {
+        //continue
+        aux = aux + 10
+        //break
+    }
+
+*/
+}
+
+/**
+
+package main;
+
+const (
+    LIN  = 2
+    COL  = 2
+)
+var (
+    matrizA [LIN][COL]int 
+    matrizB [LIN][COL]int
+    matrizR [LIN][COL]int
+)
+
+func preenche(){
+    var k = 1
+    for i := 0; i < LIN ; i++ {
+        for j := 0; j < COL ; j++ {
+            matrizA[i][j] = k
+            matrizB[i][j] = k
+            k++
+        }
+    }
+}
+
+func multiplica() {
+    var aux = 0
+    for i := 0; i < LIN; i++ {
+        for j := 0; j < COL; j++ {
+            for k := 0; k < LIN; k++ {
+                aux += matrizA[i][k] * matrizB[k][j]
+            }
+            matrizR[i][j] = aux
+            aux = 0
+        }
+    }
+}
+func main() {
+    preenche()
+    multiplica()
+}
+
+
+*/
+/**
+package main;
+
 const (
     LIN  = 2
     COL  = 2
@@ -15,10 +179,11 @@ type X struct {
 
 var (
     a [5][6]int
+    matrixX [3]X
 )
 
 func atualiza(x,i int) {
-    if (x != 1){
+    if (x == 1){
     //a[x][i].c = 1
 //    a[x][i] = 1
         a[x][i] = 10
@@ -26,11 +191,25 @@ func atualiza(x,i int) {
         i = 1
     }
 }
+
+func atualiza2(x *int) int {
+    *x = 10
+    return 2
+}
+
 func main() int {
     x := 1
     i := 1
+    
+    var (
+        varx X
+    )
 
-    atualiza(x,i)
+    i = atualiza2(y)
+    //atualiza(x,i)
+
+    //varx.c = 50
+    //matrixX[i].c = 50
 
 /*
 Testados
@@ -146,5 +325,3 @@ IF_ANDORAND_11:
     return x
 */
 
-
-}

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

@@ -336,7 +336,7 @@ public class Gen extends API.Gen {
                 .S("tac.position", inst.G("block.position"))
                 .S("comment", "pop param");
 
-        System.out.println("POPpARAM:" + inst);
+//        System.out.println("POPpARAM:" + inst);
         LoadWord(inst.G("reg.p1"), Registers.R_FP, offset);
     }
 

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

@@ -59,7 +59,7 @@ class UpdateAddressProcessor implements CodeProcessing {
                 }
                 // Atualziza o offset das instruições de branch
                 if (updateOffsetShift.containsKey(y.G("inst"))) {
-//                    System.out.println("UPDATE ADDRESS:" + y);
+                    System.out.println("UPDATE ADDRESS:" + y + c.labels);
                     offset = Integer.parseInt(c.labels.get(y.G("label")).get(0)) * 4;
                     offset = (offset - y.getInt("global.position")) / 4;
 //                    System.out.println("Offset:" + offset);

+ 3 - 3
src/tools/mips/Memory.java

@@ -88,18 +88,18 @@ public class Memory {
 
     public long R(long address) throws Exception {
         valid(address);
-        return data.get(address);
+        return data.get((address + size) % size);
     }
 
     public void W(long address, long value) throws Exception {
         valid(address);
-        data.put(address, value);
+        data.put((address + size) % size, value);
     }
 
     protected void valid(long address) throws Exception {
 
 //        System.out.println("VALID:" + address + ":" + size);
-        if (address > size) {
+        if (Math.abs(address) > size) {
             throw new Exception("Address '" + address + "' out of range limit " + size + "!");
         }
     }

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

@@ -72,7 +72,7 @@ public class MipsProcessor {
                 System.out.println("Registradores(\n" + RBank
                         + ")\b nextPC:" + Integer.toHexString((int) PC));
 
-//                br.readLine();
+                br.readLine();
                 // Decode
                 // Exec
                 // Persist
@@ -336,12 +336,14 @@ public class MipsProcessor {
                 break;
             case "lw":
                 RBank.W(rt, MD.R(RBank.R(rs) + imm));
+                System.out.printf("Load endereco '%d'\n", RBank.R(rs) + imm);
                 break;
 //            case "ori":
 //                break;
             case "slti":
 //            case "sltiu":
             case "sw":
+                System.out.printf("Store '%d' no endereco '%d'\n", RBank.R(rt), RBank.R(rs) + imm);
                 MD.W(RBank.R(rs) + imm, RBank.R(rt));
                 break;
 //            case "xori":

File diff suppressed because it is too large
+ 0 - 1026
src/tools/mips/memory/md.memory


+ 9 - 29
src/tools/mips/memory/mi.memory

@@ -1,30 +1,10 @@
-0666763256
+0666763164
 0001962017
-0605028353
-0605093889
-0001056801
-0001124385
-0201326624
-4294967295
-0666763256
-0001962017
-2948857856
-2412249088
-2948923396
-2412314628
-0604635137
-0285868044
-0000546849
-0000743488
-0000745536
-0023877665
-0000616481
-0023943201
-0000749568
-0604962826
-0059666465
-2916024320
-0134217840
-0604569601
-0666697736
-0065011720
+0605028352
+0605093888
+0134217736
+0638189578
+0000688161
+0640745473
+2412576776
+0036507683

+ 3 - 3
src/tools/mips/memory/mips.code

@@ -15,18 +15,18 @@
 30:  2948923396	sw a1,fp,4	.1.--pop param
 34:  2412314628	lw t1,fp,4	
 38:  0604635137	addiu t2,zero,1	.2.
-3c:  0285868044	beq t2,t0,6c <main.atualiza+0x4c>	.2.--branch if equals
+3c:  0352976908	bne t2,t0,6c <main.atualiza+0x4c>	.2.--branch if not equals
 40:  0000546849	addu t3,zero,t0	.3.--copy _T7 ← _T4
 44:  0000743488	sll t3,t3,1	.4.
 48:  0000745536	sll t4,t3,1	.5.
 4c:  0023877665	addu t3,t3,t4	.6.
 50:  0000616481	addu t5,zero,t1	.7.--copy _T10 ← _T6
 54:  0023943201	addu t3,t3,t5	.8.
-58:  0000749568	sll t6,t3,0	.9.
+58:  0000749696	sll t6,t3,2	.9.
 5c:  0604962826	addiu t7,zero,10	.10.
 60:  0059666465	addu t6,gp,t6	.10.
 64:  2916024320	sw t7,t6,0	.10.--store in loaded address
 68:  0134217840	j 70 <main.atualiza+0x50>	.11.
 6c:  0604569601	addiu t1,zero,1	.12.--copy _T6 ← 1
 70:  0666697736	addiu sp,sp,8	--e|pop stack frame
-74:  0065011720	jr ra	--e|return
+74:  0065011720	jr ra	--e|return