Browse Source

branch ||

eugeniucarvalho 6 years ago
parent
commit
e9ff2adf73
46 changed files with 10223 additions and 1159 deletions
  1. BIN
      build/classes/API/Api.class
  2. BIN
      build/classes/API/Variaveis.class
  3. BIN
      build/classes/IntermediaryCode/BaseTacGen$1.class
  4. BIN
      build/classes/IntermediaryCode/BaseTacGen$2.class
  5. BIN
      build/classes/IntermediaryCode/BaseTacGen.class
  6. BIN
      build/classes/compiler/IVANNOSYS.class
  7. BIN
      build/classes/compiler/IvannosysCompiler.class
  8. BIN
      build/classes/grammar/visitorAndWalkers/IvannosysListener.class
  9. 67 376
      build/classes/samples/program.go
  10. 440 0
      build/classes/samples/program_if.go
  11. 42 0
      build/classes/samples/program_mult.go
  12. BIN
      build/classes/target/mips/Gen$3.class
  13. BIN
      build/classes/target/mips/Gen$4.class
  14. BIN
      build/classes/target/mips/Gen.class
  15. BIN
      build/classes/target/mips/Mips$1.class
  16. BIN
      build/classes/target/mips/Mips$2.class
  17. BIN
      build/classes/target/mips/Mips$3.class
  18. BIN
      build/classes/target/mips/Mips$4.class
  19. BIN
      build/classes/target/mips/Mips.class
  20. BIN
      build/classes/target/mips/TListenerMips.class
  21. BIN
      build/classes/tools/mips/Memory.class
  22. BIN
      build/classes/tools/mips/MipsProcessor.class
  23. BIN
      build/classes/tools/mips/RegisterBank.class
  24. 4096 0
      build/classes/tools/mips/memory/md.memory
  25. 143 59
      build/classes/tools/mips/memory/mi.memory
  26. 92 31
      build/classes/tools/mips/memory/mips.code
  27. 12 8
      nbproject/private/private.xml
  28. 1 0
      src/API/Api.java
  29. 1 0
      src/API/Instruction.java
  30. 11 2
      src/API/Variaveis.java
  31. 321 152
      src/IntermediaryCode/BaseTacGen.java
  32. 3 1
      src/compiler/IVANNOSYS.java
  33. 2 2
      src/compiler/IvannosysCompiler.java
  34. 18 10
      src/grammar/visitorAndWalkers/IvannosysListener.java
  35. 67 376
      src/samples/program.go
  36. 440 0
      src/samples/program_if.go
  37. 42 0
      src/samples/program_mult.go
  38. 10 2
      src/target/mips/Gen.java
  39. 3 3
      src/target/mips/Mips.java
  40. 7 4
      src/target/mips/TListenerMips.java
  41. 13 2
      src/tools/mips/Memory.java
  42. 48 13
      src/tools/mips/MipsProcessor.java
  43. 14 3
      src/tools/mips/RegisterBank.java
  44. 4096 0
      src/tools/mips/memory/md.memory
  45. 142 84
      src/tools/mips/memory/mi.memory
  46. 92 31
      src/tools/mips/memory/mips.code

BIN
build/classes/API/Api.class


BIN
build/classes/API/Variaveis.class


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


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


BIN
build/classes/IntermediaryCode/BaseTacGen.class


BIN
build/classes/compiler/IVANNOSYS.class


BIN
build/classes/compiler/IvannosysCompiler.class


BIN
build/classes/grammar/visitorAndWalkers/IvannosysListener.class


+ 67 - 376
build/classes/samples/program.go

@@ -3,404 +3,95 @@
 package main;
 
 const (
-    LIN  = 2
-    COL  = 2
+    LIN = 5
+    COL = 5
 )
+
 var (
-    matrizA [LIN][COL]int 
+    origin [LIN][COL]int
+    result [LIN][COL]int
 )
 
-func main() {
+func preenche_matriz() {
     var (
-        aux = 0
-        i = 1
+        w = 1
+        value int
     )
-/**
-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
-    }
-
-*/
-
-//if (i < LIN || 1 == 1) && (i < LIN && 1 == 1) {
-
-IF_01:
-if (i < LIN) {
-    aux = 10
-}else {
-    aux = 20
-}
-
-IF_02:
-if (i < LIN || 1 == 1) {
-    aux = 10
-}else {
-    aux = 20
-}
-IF_03:
-if (i < LIN && 1 == 1) {
-    aux = 10
-}else {
-    aux = 20
-}
-
-IF_04:
-if ((i < LIN || 1 == 1) || (i < LIN || 1 == 1)) {
-    aux = 10
-}else {
-    aux = 20
-}
-
-IF_05:
-if ((i < LIN && 1 == 1) && (i < LIN && 1 == 1)) {
-    aux = 10
-}else {
-    aux = 20
-}
-
-IF_06:
-if ((i < LIN && 1 == 1) || (i < LIN && 1 == 1)) {
-    aux = 10
-}else {
-    aux = 20
-}
-
-IF_07:
-if ((i < LIN || 1 == 1) && (i < LIN || 1 == 1)) {
-    aux = 10
-}else {
-    aux = 20
-}
-
-IF_08:
-if ((i < LIN && 1 == 1) && (i < LIN || 1 == 1)) {
-    aux = 10
-}else {
-    aux = 20
-}
-
-IF_09:
-if ((i < LIN || 1 == 1) && (i < LIN && 1 == 1)) {
-    aux = 10
-}else {
-    aux = 20
-}
-
-IF_10:
-if ((i < LIN && 1 == 1) || (i < LIN || 1 == 1)) {
-    aux = 10
-}else {
-    aux = 20
-}
-
-IF_11:
-if ((i < LIN || 1 == 1) || (i < LIN && 1 == 1)) {
-    aux = 10
-}else {
-    aux = 20
-}
-
-
-/**
-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
-)
+    
+    LM1 := LIN - 1
+    CM1 := COL - 1
 
-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++
+    for i := 0; i < LIN; i++ {
+        for j := 0; j < COL; j++ {
+            switch {
+                case i == 0, i == LM1: // Primeira  e ultima linha
+                    value = 0
+                case j == 0, j == CM1: // Primeira e ultima coluna
+                    value = 0
+                default:               // Elementos do interior da matriz
+                    value = w
+                    w++
+            }
+            origin[i][j] = value
         }
     }
 }
 
-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]
+func laplaciano() {
+    var (
+        l int
+        //LM1,CM1 int
+        
+    )
+    LM1 := LIN - 1
+    CM1 := COL - 1
+
+    for i:= 1; i < LM1; i++ {
+        for j := 1; j < CM1; j++ {
+lab_1:
+            l = origin[i-1][j]
+lab_2:
+            l = l + origin[i][j-1]
+lab_3:
+            l = l + origin[i][j+1] 
+lab_4:
+            l = l + origin[i+1][j]
+lab_5:
+            l = l - (4 * origin[i][j])
+lab_6:
+
+            if l > 255 {
+              l = 255
             }
-            matrizR[i][j] = aux
-            aux = 0
+            result[i][j] = l
         }
     }
 }
+/*
+*/
+
 func main() {
-    preenche()
-    multiplica()
+  preenche_matriz()
+  laplaciano()
 }
 
+/**
 
 */
-/**
-package main;
+/*
 
 const (
-    LIN  = 2
-    COL  = 2
-)
-
-type X struct {
-    a int 
-    b int 
-    c int 
-}
-
-var (
-    a [5][6]int
-    matrixX [3]X
+    X = 10
+    Y = 20
 )
-
-func atualiza(x,i int) {
-    if (x == 1){
-    //a[x][i].c = 1
-//    a[x][i] = 1
-        a[x][i] = 10
-    } else {
-        i = 1
-    }
-}
-
-func atualiza2(x *int) int {
-    *x = 10
-    return 2
-}
-
-func main() int {
-    x := 1
-    i := 1
-    
+func main(){
     var (
-        varx X
+        x [Y]int
+        i = 12
     )
-
-    i = atualiza2(y)
-    //atualiza(x,i)
-
-    //varx.c = 50
-    //matrixX[i].c = 50
-
-/*
-Testados
-IF_BASIC:
-    if i < LIN  {
-        x = 10
-    }
-
-
-IF_ANDOR:
-
-    if (i < LIN && true) || 1 == 1 {
-        x = 10
-    } else {
-        x = 20
-    }
-
-*/
-/*
-IF_ORAND:
-    if (i < LIN || true) && 1 == 1 {
-        x = 10
-    } else {
-        x = 20
-    }
-
-IF_ANDOR_R:
-
-    if 1 == 1  || (i < LIN && true){
-        x = 10
-    } else {
-        x = 20
-    }
-
-IF_ORAND_R:
-    if 1 == 1 && (i < LIN || true) {
-        x = 10
-    } else {
-        x = 20
-    }
-
-IF_OROR:
-
-    if (i < LIN || true) || 1 == 1 {
-        x = 10
-    } else {
-        x = 20
-    }
-
-IF_ANDAND:
-    if (i < LIN && true) && 1 == 1 {
-        x = 10
-    } else {
-        x = 20
-    }
-
-IF_OROR_R:
-
-    if 1 == 1 || (i < LIN || true){
-        x = 10
-    } else {
-        x = 20
-    }
-
-IF_ANDAND_R:
-    if  1 == 1||(i < LIN && true) {
-        x = 10
-    } else {
-        x = 20
-    }
-
-IF_ORANDOR:
-    if (i < LIN || true) && (1 == 1 || 2==2) {
-        x = 10
-    } else {
-        x = 20
-    }
-
-
-IF_ANDORAND_0:
-    if (i < LIN || true) || (1 == 1 || 2 == 2 ) {
-        x = 10
-    } else {
-        x = 20
-    }
-
-IF_ANDORAND_1:
-    if (i < LIN && true) || (1 == 1 || 2==2) {
-        x = 10
-    } else {
-        x = 20
-    }
-
-IF_ANDORAND_2:
-    if (i < LIN || true) || (1 == 1 && 2 == 2 ) {
-        x = 10
-    } else {
-        x = 20
-    }
-
-IF_ANDORAND_10:
-    if (i < LIN && true) || 2==2 {
-        x = 10
-    } else {
-        x = 20
-    }
-IF_ANDORAND_11:
-    if 2==2 || (i < LIN && true) {
-        x = 10
-    } else {
-        x = 20
-    }
-    return x
-*/
-
+    //i++
+    //i += 10
+    //x[i + 3] = 40
+    x[X + 3] = i
+}
+*/

+ 440 - 0
build/classes/samples/program_if.go

@@ -0,0 +1,440 @@
+@target mips, mipt2
+
+package main;
+
+const (
+    LIN  = 2
+    COL  = 2
+)
+var (
+    matrizA [LIN][COL]int 
+)
+
+func main() {
+    var (
+        aux = 0
+        i = 1
+    )
+/**
+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
+    }
+
+*/
+
+
+SWITCH_1:
+
+switch aux {
+    case 1,3,5:
+        aux = 10
+    case 2:
+        aux = 20
+    default:
+        aux = 30
+}
+
+SWITCH_2:
+switch {
+    case 1 == 3, 2 < 4:
+        aux = 10
+    case 2 == 2:
+        aux = 20
+    default:
+        aux = 30
+}
+
+// if - if - else
+if i == 1 && 1 == 1 {
+   aux = 10
+
+} else if i == 2 {
+   aux = 20
+
+}else {
+   aux = 30
+}
+
+
+
+IF_01:
+if (i < LIN) {
+    aux = 10
+}else {
+    aux = 20
+}
+
+IF_02:
+if (i < LIN || 1 == 1) {
+    aux = 10
+}else {
+    aux = 20
+}
+IF_03:
+if (i < LIN && 1 == 1) {
+    aux = 10
+}else {
+    aux = 20
+}
+
+IF_04:
+if ((i < LIN || 1 == 1) || (i < LIN || 1 == 1)) {
+    aux = 10
+}else {
+    aux = 20
+}
+
+IF_05:
+if ((i < LIN && 1 == 1) && (i < LIN && 1 == 1)) {
+    aux = 10
+}else {
+    aux = 20
+}
+
+IF_06:
+if ((i < LIN && 1 == 1) || (i < LIN && 1 == 1)) {
+    aux = 10
+}else {
+    aux = 20
+}
+
+IF_07:
+if ((i < LIN || 1 == 1) && (i < LIN || 1 == 1)) {
+    aux = 10
+}else {
+    aux = 20
+}
+
+IF_08:
+if ((i < LIN && 1 == 1) && (i < LIN || 1 == 1)) {
+    aux = 10
+}else {
+    aux = 20
+}
+
+IF_09:
+if ((i < LIN || 1 == 1) && (i < LIN && 1 == 1)) {
+    aux = 10
+}else {
+    aux = 20
+}
+
+IF_10:
+if ((i < LIN && 1 == 1) || (i < LIN || 1 == 1)) {
+    aux = 10
+}else {
+    aux = 20
+}
+
+IF_11:
+if ((i < LIN || 1 == 1) || (i < LIN && 1 == 1)) {
+    aux = 10
+}else {
+    aux = 20
+}
+/** 
+*/
+
+/**
+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
+)
+
+type X struct {
+    a int 
+    b int 
+    c int 
+}
+
+var (
+    a [5][6]int
+    matrixX [3]X
+)
+
+func atualiza(x,i int) {
+    if (x == 1){
+    //a[x][i].c = 1
+//    a[x][i] = 1
+        a[x][i] = 10
+    } else {
+        i = 1
+    }
+}
+
+func atualiza2(x *int) int {
+    *x = 10
+    return 2
+}
+
+func main() int {
+    x := 1
+    i := 1
+    
+    var (
+        varx X
+    )
+
+    i = atualiza2(y)
+    //atualiza(x,i)
+
+    //varx.c = 50
+    //matrixX[i].c = 50
+
+/*
+Testados
+IF_BASIC:
+    if i < LIN  {
+        x = 10
+    }
+
+
+IF_ANDOR:
+
+    if (i < LIN && true) || 1 == 1 {
+        x = 10
+    } else {
+        x = 20
+    }
+
+*/
+/*
+IF_ORAND:
+    if (i < LIN || true) && 1 == 1 {
+        x = 10
+    } else {
+        x = 20
+    }
+
+IF_ANDOR_R:
+
+    if 1 == 1  || (i < LIN && true){
+        x = 10
+    } else {
+        x = 20
+    }
+
+IF_ORAND_R:
+    if 1 == 1 && (i < LIN || true) {
+        x = 10
+    } else {
+        x = 20
+    }
+
+IF_OROR:
+
+    if (i < LIN || true) || 1 == 1 {
+        x = 10
+    } else {
+        x = 20
+    }
+
+IF_ANDAND:
+    if (i < LIN && true) && 1 == 1 {
+        x = 10
+    } else {
+        x = 20
+    }
+
+IF_OROR_R:
+
+    if 1 == 1 || (i < LIN || true){
+        x = 10
+    } else {
+        x = 20
+    }
+
+IF_ANDAND_R:
+    if  1 == 1||(i < LIN && true) {
+        x = 10
+    } else {
+        x = 20
+    }
+
+IF_ORANDOR:
+    if (i < LIN || true) && (1 == 1 || 2==2) {
+        x = 10
+    } else {
+        x = 20
+    }
+
+
+IF_ANDORAND_0:
+    if (i < LIN || true) || (1 == 1 || 2 == 2 ) {
+        x = 10
+    } else {
+        x = 20
+    }
+
+IF_ANDORAND_1:
+    if (i < LIN && true) || (1 == 1 || 2==2) {
+        x = 10
+    } else {
+        x = 20
+    }
+
+IF_ANDORAND_2:
+    if (i < LIN || true) || (1 == 1 && 2 == 2 ) {
+        x = 10
+    } else {
+        x = 20
+    }
+
+IF_ANDORAND_10:
+    if (i < LIN && true) || 2==2 {
+        x = 10
+    } else {
+        x = 20
+    }
+IF_ANDORAND_11:
+    if 2==2 || (i < LIN && true) {
+        x = 10
+    } else {
+        x = 20
+    }
+    return x
+*/
+

+ 42 - 0
build/classes/samples/program_mult.go

@@ -0,0 +1,42 @@
+@target mips, mipt2
+
+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 = aux + (matrizA[i][k] * matrizB[k][j])
+            }
+            matrizR[i][j] = aux
+            aux = 0
+        }
+    }
+}
+
+func main() {
+    preenche()
+    multiplica()
+}

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/TListenerMips.class


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


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


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


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


+ 143 - 59
build/classes/tools/mips/memory/mi.memory

@@ -1,106 +1,190 @@
-0666763252
+0666763256
 0001962017
 0605028352
 0605093889
-2412380168
-0036311075
-0071303171
+0604635137
+0302645253
+0604700675
+0302710787
+0604766213
+0369885187
 0605028362
-0134217768
+0134217745
+0604897282
+0370016259
 0605028372
-0036311075
-0071303172
-0604831745
-0604897281
-0363724803
+0134217745
+0605028382
+0604504065
+0604569603
+0285802501
+0604635138
+0604700676
+0021696547
+0071303171
 0605028362
-0134217800
+0134217760
+0604831746
+0604897282
+0363724803
 0605028372
-0036311075
-0071303174
-0604504065
+0134217760
+0605028382
 0604569601
-0352911363
+0371785734
+0604504065
+0604700673
+0353042435
 0605028362
-0134217832
+0134217772
+0604766210
+0371982339
 0605028372
-0036311075
-0071303177
-0604897281
-0604831745
-0298647558
-0036311075
+0134217772
+0605028382
+0604962818
+0036638755
+0071303171
+0605028362
+0134217778
+0605028372
+0604700674
+0036376611
 0071303172
+0604504065
+0604635137
+0352976899
+0605028362
+0134217787
+0605028372
+0604831746
+0036507683
+0071303174
 0604962817
 0605552641
 0368574467
 0605028362
-0134217884
+0134217796
 0605028372
+0604635138
 0036311075
-0071303179
-0604700673
+0071303178
+0604504065
 0604766209
-0359399432
-0036311075
-0071303174
+0285999111
+0604897282
+0036573219
+0071303172
 0604831745
+0605552641
+0364380163
+0605028362
+0134217811
+0605028372
+0604700674
+0036376611
+0071303180
+0604635137
+0604766209
+0357302281
+0604504066
+0036180003
+0071303174
 0604897281
-0363724803
+0605552641
+0366477315
 0605028362
-0134217936
+0134217826
 0605028372
-0036311075
+0604569602
+0036245539
 0071303172
-0604569601
-0604504065
-0287834118
+0604700673
+0604766209
+0292290567
+0604635138
 0036311075
 0071303174
-0604766209
-0604700673
-0361431043
+0604504065
+0605552641
+0353894403
 0605028362
-0134217988
+0134217841
 0605028372
-0036311075
+0604962818
+0036638755
+0071303172
+0604569601
+0604766209
+0355205129
+0604700674
+0036376611
 0071303172
+0604635137
 0605552641
+0358088707
+0605028362
+0134217856
+0605028372
+0604831746
+0036507683
+0071303180
 0604962817
-0386859016
-0036311075
+0604766209
+0367788041
+0604569602
+0036245539
 0071303172
-0604504065
+0604700673
+0605552641
+0360185859
+0605028362
+0134217871
+0605028372
+0604897282
+0036573219
+0071303172
+0604831745
+0604766209
+0363593737
+0604962818
+0036638755
+0071303174
 0604569601
-0352911363
+0605552641
+0355991555
 0605028362
-0134218040
+0134217886
 0605028372
-0036311075
-0071303179
+0604504066
+0036180003
+0071303172
 0604897281
-0604831745
-0365756424
-0036311075
+0604766209
+0298582023
+0604831746
+0036507683
 0071303172
 0604962817
 0605552641
 0368574467
 0605028362
-0134218092
+0134217901
 0605028372
+0604635138
 0036311075
-0071303172
-0604700673
+0071303178
+0604504065
 0604766209
-0359399432
-0036311075
+0285999111
+0604897282
+0036573219
 0071303174
 0604831745
-0604897281
-0363724803
+0605552641
+0364380163
 0605028362
-0134218148
-0604962836
-2949578752
+0134217917
+0605028372
+2949644288
 4294967295

+ 92 - 31
build/classes/tools/mips/memory/mips.code

@@ -1,32 +1,93 @@
-  00000000 <main>:
- 0:  0666763256	addiu sp,sp,-8	--p| push stack frame
+ 00000000 <main>:
+ 0:  0666697728	addiu sp,sp,-0	--p| push stack frame
  4:  0001962017	addu fp,zero,sp	--p|copy fp ← sp
- 8:  0605028353	addiu s0,zero,1	.0.--copy _V1 ← 1
- c:  0605093889	addiu s1,zero,1	.1.--copy _V2 ← 1
-10:  0001056801	addu a0,zero,s0	.2.--push param
-14:  0001124385	addu a1,zero,s1	.3.--push param
-18:  0201326624	jal 20 <main.atualiza+0x0>	.4.--jump to <main.atualiza>
-1c:  4294967295	stop 	--end of programa
-  00000020 <main.atualiza>:
-20:  0666763256	addiu sp,sp,-8	--p| push stack frame
-24:  0001962017	addu fp,zero,sp	--p|copy fp ← sp
-28:  2948857856	sw a0,fp,0	.0.--pop param
-2c:  2412249088	lw t0,fp,0	
-30:  2948923396	sw a1,fp,4	.1.--pop param
-34:  2412314628	lw t1,fp,4	
-38:  0604635137	addiu t2,zero,1	.2.
-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:  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
+ 8:  0201326597	jal 14 <main.preenche+0x0>	.0.--jump to <main.preenche>
+ c:  0201326630	jal 98 <main.multiplica+0x0>	.1.--jump to <main.multiplica>
+10:  4294967295	stop 	--end of programa
+  00000014 <main.preenche>:
+14:  0666763252	addiu sp,sp,-12	--p| push stack frame
+18:  0001962017	addu fp,zero,sp	--p|copy fp ← sp
+1c:  0605028353	addiu s0,zero,1	.0.--copy _V1 ← 1
+20:  0605093888	addiu s1,zero,0	.1.--copy _V2 ← 0
+24:  0134217761	j 84 <main.preenche+0x70>	.2.
+28:  0605159424	addiu s2,zero,0	.3.--copy _V3 ← 0
+2c:  0134217757	j 74 <main.preenche+0x60>	.4.
+30:  0001136673	addu t3,zero,s1	.5.--copy _T4 ← _V2
+34:  0000745536	sll t4,t3,1	.6.
+38:  0001206305	addu t5,zero,s2	.7.--copy _T7 ← _V3
+3c:  0026042401	addu t4,t4,t5	.8.
+40:  0000815232	sll t6,t4,2	.9.
+44:  0059666465	addu t6,gp,t6	.10.
+48:  2916089856	sw s0,t6,0	.10.--store in loaded address
+4c:  0001144865	addu t7,zero,s1	.11.--copy _T14 ← _V2
+50:  0001032256	sll t8,t7,1	.12.
+54:  0001196065	addu t0,zero,s2	.13.--copy _T17 ← _V3
+58:  0050905121	addu t8,t8,t0	.14.
+5c:  0001591424	sll t1,t8,2	.15.
+60:  0059328545	addu t1,gp,t1	.16.
+64:  2905604112	sw s0,t1,16	.16.--store in loaded address
+68:  0638582785	addiu s0,s0,1	.17.
+6c:  2949644288	sw s0,fp,0	.17.
+70:  0642908161	addiu s2,s2,1	.18.
+74:  0604831746	addiu t5,zero,2	.19.
+78:  0038604835	subu v0,s2,t5	.19.
+7c:  0071368685	bltz v0,30 <main.preenche+0x1c>	.19.--branch if register < 0
+80:  0640745473	addiu s1,s1,1	.20.
+84:  0604897282	addiu t6,zero,2	.21.
+88:  0036573219	subu v0,s1,t6	.21.
+8c:  0071368679	bltz v0,28 <main.preenche+0x14>	.21.--branch if register < 0
+90:  0666697740	addiu sp,sp,12	--e|pop stack frame
+94:  0065011720	jr ra	--e|return
+  00000098 <main.multiplica>:
+98:  0666763248	addiu sp,sp,-16	--p| push stack frame
+9c:  0001962017	addu fp,zero,sp	--p|copy fp ← sp
+a0:  0605028352	addiu s0,zero,0	.0.--copy _V26 ← 0
+a4:  0605093888	addiu s1,zero,0	.1.--copy _V27 ← 0
+a8:  0134217813	j 154 <main.multiplica+0xbc>	.2.
+ac:  0605159424	addiu s2,zero,0	.3.--copy _V28 ← 0
+b0:  0134217809	j 144 <main.multiplica+0xac>	.4.
+b4:  0605224960	addiu s3,zero,0	.5.--copy _V29 ← 0
+b8:  0134217796	j 110 <main.multiplica+0x78>	.6.
+bc:  0001138721	addu t4,zero,s1	.7.--copy _T30 ← _V27
+c0:  0000813120	sll t5,t4,1	.8.
+c4:  0001273889	addu t6,zero,s3	.9.--copy _T33 ← _V29
+c8:  0028207137	addu t5,t5,t6	.10.
+cc:  0000882816	sll t7,t5,2	.11.
+d0:  0059734049	addu t7,gp,t7	.12.
+d4:  2381578240	lw s4,t7,0	.12.
+d8:  0001359905	addu t8,zero,s4	.12.--copy t8 ← s4
+dc:  0001261601	addu t0,zero,s3	.13.--copy _T40 ← _V29
+e0:  0000542784	sll t1,t0,1	.14.
+e4:  0001200161	addu t2,zero,s2	.15.--copy _T43 ← _V28
+e8:  0019548193	addu t1,t1,t2	.16.
+ec:  0000612480	sll t3,t1,2	.17.
+f0:  0059463713	addu t3,gp,t3	.18.
+f4:  2373255184	lw s5,t3,16	.18.
+f8:  0001400865	addu t4,zero,s5	.18.--copy t4 ← s5
+fc:  0051146776	mult t8,t4	.19.
+100:  0000028690	mflo t6	.19.
+104:  0034498593	addu t5,s0,t6	.20.
+108:  0000884769	addu s0,zero,t5	.21.--copy _V26 ← _T51
+10c:  0645070849	addiu s3,s3,1	.22.
+110:  0604504066	addiu t0,zero,2	.23.
+114:  0040374307	subu v0,s3,t0	.23.
+118:  0071368681	bltz v0,bc <main.multiplica+0x24>	.23.--branch if register < 0
+11c:  0001134625	addu t2,zero,s1	.24.--copy _T53 ← _V27
+120:  0000673856	sll t1,t2,1	.25.
+124:  0001202209	addu t3,zero,s2	.26.--copy _T56 ← _V28
+128:  0019613729	addu t1,t1,t3	.27.
+12c:  0000639104	sll t8,t1,2	.28.
+130:  0060342305	addu t8,gp,t8	.29.
+134:  2937061408	sw s0,t8,32	.29.--store in loaded address
+138:  0605028352	addiu s0,zero,0	.30.
+13c:  2949644288	sw s0,fp,0	.30.--store content of s0 in _V26
+140:  0642908161	addiu s2,s2,1	.31.
+144:  0604831746	addiu t5,zero,2	.32.
+148:  0038604835	subu v0,s2,t5	.32.
+14c:  0071368666	bltz v0,b4 <main.multiplica+0x1c>	.32.--branch if register < 0
+150:  0640745473	addiu s1,s1,1	.33.
+154:  0604504066	addiu t0,zero,2	.34.
+158:  0036180003	subu v0,s1,t0	.34.
+15c:  0071368660	bltz v0,ac <main.multiplica+0x14>	.34.--branch if register < 0
+160:  0666697744	addiu sp,sp,16	--e|pop stack frame
+164:  0065011720	jr ra	--e|return

+ 12 - 8
nbproject/private/private.xml

@@ -5,23 +5,23 @@
             <url>src/API/Api.java</url>
             <bookmark id="2">
                 <name/>
-                <line>169</line>
+                <line>170</line>
                 <key/>
             </bookmark>
         </file>
         <file>
-            <url>src/samples/program.ivan</url>
-            <bookmark id="1">
+            <url>src/samples/program.go</url>
+            <bookmark id="3">
                 <name/>
-                <line>32</line>
+                <line>81</line>
                 <key/>
             </bookmark>
         </file>
         <file>
-            <url>src/samples/program.go</url>
-            <bookmark id="3">
+            <url>src/samples/program.ivan</url>
+            <bookmark id="1">
                 <name/>
-                <line>4</line>
+                <line>32</line>
                 <key/>
             </bookmark>
         </file>
@@ -29,8 +29,12 @@
     <open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
         <group>
             <file>file:/C:/Users/EUGENIO%20CARVALHO/Desktop/projects/Ivannosys/src/IntermediaryCode/BaseTacGen.java</file>
-            <file>file:/C:/Users/EUGENIO%20CARVALHO/Desktop/projects/Ivannosys/src/API/Api.java</file>
+            <file>file:/C:/Users/EUGENIO%20CARVALHO/Desktop/projects/Ivannosys/src/tools/mips/memory/mips.code</file>
+            <file>file:/C:/Users/EUGENIO%20CARVALHO/Desktop/projects/Ivannosys/src/IntermediaryCode/Code.java</file>
+            <file>file:/C:/Users/EUGENIO%20CARVALHO/Desktop/projects/Ivannosys/src/target/mips/UpdateAddressProcessor.java</file>
+            <file>file:/C:/Users/EUGENIO%20CARVALHO/Desktop/projects/Ivannosys/src/target/mips/Gen.java</file>
             <file>file:/C:/Users/EUGENIO%20CARVALHO/Desktop/projects/Ivannosys/src/samples/program.go</file>
+            <file>file:/C:/Users/EUGENIO%20CARVALHO/Desktop/projects/Ivannosys/src/API/Instruction.java</file>
         </group>
     </open-files>
 </project-private>

+ 1 - 0
src/API/Api.java

@@ -24,6 +24,7 @@ public class Api {
         if (inicializada) {
             return;
         }
+        
         /*Inicializando importes*/
         /*Inicializando constantes*/
 

+ 1 - 0
src/API/Instruction.java

@@ -129,4 +129,5 @@ public class Instruction extends RegistroBase {
         }
         return rb;
     }
+
 }

+ 11 - 2
src/API/Variaveis.java

@@ -34,6 +34,7 @@ public class Variaveis {
     }
 
     public static void Add(String id, Node var) throws Exception {
+//        System.out.println("AddVar:" + id + "\n" + var);
         if (vars.containsKey(id)) {
             String[] parts = id.split("\\.");
             throw new Exception("'" + parts[parts.length - 1] + "' previamente declarado em na linha " + vars.get(id).get("line", ""));
@@ -571,14 +572,22 @@ public class Variaveis {
     public static void List() {
         StringBuilder s = new StringBuilder();
         Node v;
-        String index;
+        String index, constant, Public;
         for (String var : vars.keySet()) {
             index = "";
+            constant = "";
             v = vars.get(var);
+
+            if (v.eq("constant", "true")) {
+                constant = "constant";
+            }
+
+            Public = v.eq("public", "true") ? "public" : "private";
+
             for (Node i : v.childrens()) {
                 index += "[" + i.getText() + "]";
             }
-            s.append(var + ": " + index + v.G("type") + "\n");
+            s.append(var + ": " + index + v.G("type") + " [" + Public + " " + constant + "]\n");
         }
         System.out.println("Vars:\n" + s.toString());
     }

+ 321 - 152
src/IntermediaryCode/BaseTacGen.java

@@ -25,6 +25,7 @@ import java.util.regex.Pattern;
 //    exec    recebe  mandando 
 //    synexec recebe  mandando
 
+// Atualizei as labels mas não atualizei as referencias por isso esta sendo removida quando faz a limpeza
 /**
  *
  * @author Eugenio
@@ -34,7 +35,7 @@ public final class BaseTacGen implements TacGenInterface {
     protected boolean inicializado = false;
     protected int incLabel = 0;
     protected int tmpVarCount = 1;
-    protected int OrTestAndOccurrence = 0;
+//    protected int OrTestAndOccurrence = 0;
 
     protected AbstractSyntaxTree ast;
     protected Code code;
@@ -67,10 +68,11 @@ public final class BaseTacGen implements TacGenInterface {
     public static Pattern AddressOperator = Pattern.compile("(\\&|\\*)");
     protected boolean enableOtimization = true;
     protected HashMap<String, String> ArrayShiftMap = new HashMap<>();
+    private int jb = 0;
 
     public BaseTacGen() throws Exception {
         for (long i = 0; i < 31; i++) {
-            power2.put(Long.valueOf(1 << i), Long.valueOf(i));
+            power2.put(Long.toString(Long.valueOf(1 << i)), Long.valueOf(i));
         }
     }
 
@@ -103,6 +105,9 @@ public final class BaseTacGen implements TacGenInterface {
     }
 
     public BaseTacGen(AbstractSyntaxTree ast) {
+        for (long i = 0; i < 31; i++) {
+            power2.put(Long.toString(Long.valueOf(1 << i)), Long.valueOf(i));
+        }
         Ast(ast);
     }
 
@@ -136,11 +141,21 @@ public final class BaseTacGen implements TacGenInterface {
                         put("pop_return", base + " 'pop_return '{[p1]} {' --'[comment]}" + end);
                     }
                 });
+
     }
 
+//    public void DeclareConstants(Node root) throws Exception {
+////        System.out.println("DeclareConstants() ...");
+//        for (Node constants : root.findAll("dec.const", "class", 0)) {
+////            System.out.println("Declare constant ..." + constants);
+//            visit(constants);
+//        }
+//    }
     @Override
     public Code Create(AbstractSyntaxTree ast, HashMap<String, String> settings) 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
@@ -263,6 +278,7 @@ public final class BaseTacGen implements TacGenInterface {
                 } else {
 
                     String v = gerarVariavel(n);
+
                     if (n.eq("pointer", "*") && n.eq("access", "read")) {
                         String t = gerarVariavel("T");
                         Copy(t, v, false);
@@ -336,7 +352,7 @@ public final class BaseTacGen implements TacGenInterface {
         return ret;
     }
 
-    protected LinkedHashMap<Long, Long> power2 = new LinkedHashMap<Long, Long>();
+    protected LinkedHashMap<String, Long> power2 = new LinkedHashMap<String, Long>();
 
     protected void FindShiftPath(int size, ArrayList<Integer> path) {
         size = Math.abs(size);
@@ -344,14 +360,19 @@ public final class BaseTacGen implements TacGenInterface {
 
         int op = shift.get(2), s1 = shift.get(op);
 
-//        System.out.println("FindShiftPath:(" + size + "|" + s1 + ")\t\t" + shift);
-        if (power2.containsKey(s1)) {
+//        System.out.println("FindShiftPath:(" + power2.containsKey("" + s1) + "|" + size + "|" + s1 + ")\t\t" + shift);
+//        System.out.println(power2);
+        if (power2.containsKey("" + s1)) {
             path.add(s1);
             path.add(op);
         }
+
         if (size == 1) {
-//            path.add(size);
+//            path.add(size); 
         }
+
+        System.out.println("Pathj:" + path);
+
         if (path.size() % 2 == 0 && Math.abs(size - s1) == 0) {
             path.remove(path.size() - 1);
             return;
@@ -398,7 +419,7 @@ public final class BaseTacGen implements TacGenInterface {
 
 //            String shift;
             Node var = Variaveis.Get(n.getText());
-//            System.out.println("INDEX shift:" + n.childrens());
+//            System.out.println("INDEX shift:" + n + var);
 
             for (int i = 0, j = 1; j < var.childrens().size(); j++) {
                 n.childrens().get(i++).S("collNumber", var.childrens().get(j).getText());
@@ -419,21 +440,29 @@ public final class BaseTacGen implements TacGenInterface {
         return ArrayShiftMap.get(key);
     }
 
-    protected String GenShiftLeftLogical(String var, int size, boolean mps) throws Exception {
+    protected String GenShiftLeftLogical(String var, int size, boolean mps, boolean last) throws Exception {
         ArrayList<Integer> path = ShiftPath(size);
 
         ArrayList<Integer> reverse = new ArrayList<>();
         for (int i = path.size() - 1; i >= 0; i--) {
             reverse.add(path.remove(i));
         }
-        System.out.println(">>>>>(var:" + var + ", size:" + size + ") arithpath:" + reverse);
+//        System.out.println(">>>>>(var:" + var + ", size:" + size + ") arithpath:" + reverse);
 
-        var = GSLL(var, reverse, mps, size);
+        var = GSLL(var, reverse, mps, size, last);
 
         return var;
     }
 
-    protected String GSLL(String var, ArrayList<Integer> path, boolean mps, int size) throws Exception {
+    protected long pow2(long p) {
+        return pow2("" + p);
+    }
+
+    protected long pow2(String p) {
+        return power2.get(p);
+    }
+
+    protected String GSLL(String var, ArrayList<Integer> path, boolean mps, int size, boolean last) throws Exception {
         int op1, operacao, op2;
         String T1 = gerarVariavel("T"),
                 T2 = gerarVariavel("T"),
@@ -448,8 +477,8 @@ public final class BaseTacGen implements TacGenInterface {
                 } else {
                     T1 = var;
                 }
-                if (mps) {
-                    __exp("<<", T1, "" + power2.get(size), T2).S("comment", "");
+                if (!last) {
+                    __exp("<<", T1, "" + pow2(size), T2).S("comment", "");
                     return T2;
                 }
                 return T1;
@@ -466,13 +495,17 @@ public final class BaseTacGen implements TacGenInterface {
                 }
 
                 if (op1 != 1) {
-                    __exp("<<", T1, "" + power2.get(op1), T1).S("comment", "");
+                    __exp("<<", T1, "" + pow2(op1), T1).S("comment", "");
                 }
 //                if (op2 == 1) {
 //                } else {
 //                    Copy(T3, var, false).S("comment", "Copy value of index");
                 if (op2 != 1) {
-                    __exp("<<", T1, "" + (power2.get(op2) - power2.get(op1)), T2).S("comment", "");
+//                    System.out.println("GSLL:" + op2 + ":" + op1);
+//                    System.out.println("GSLL:op2" + pow2(op2));
+//                    System.out.println("GSLL:op1" + pow2(op1));
+
+                    __exp("<<", T1, "" + (pow2(op2) - pow2(op1)), T2).S("comment", "");
                     // deve realizar um novo deslocamento
                 } else {
                     T2 = T1;
@@ -489,14 +522,14 @@ public final class BaseTacGen implements TacGenInterface {
 //
 //                Copy(T1, var, false).S("comment", "Copy value of index");
 //
-//                __exp("<<", T1, "" + power2.get(op1), T1).S("comment", "");
+//                __exp("<<", T1, "" + pow2(op1), T1).S("comment", "");
 //                __exp("+", T1, T2, T1).S("comment", "");
         }
         return var;
     }
 
     protected String CalcArrayAddress(ArrayList<Node> childrens, int Size) throws Exception {
-        System.out.println("CalcArrayAddressINIT:" + Size);
+//        System.out.println("CalcArrayAddressINIT(" + Size + "):");
         boolean onlyNumber = true;
 
         for (Node node : childrens) {
@@ -514,10 +547,9 @@ public final class BaseTacGen implements TacGenInterface {
 
             String current = CalcArrayAddressAux(childrens, Size);
 
-            System.out.println("Size {" + current + "}:----------->" + Size);
-
+//            System.out.println("Size {" + current + "}:----------->" + Size);
 // multiplica pelo tamanho
-            return GenShiftLeftLogical(current, Size, true);
+            return GenShiftLeftLogical(current, Size, true, false);
         }
     }
 
@@ -538,19 +570,34 @@ public final class BaseTacGen implements TacGenInterface {
     }
 
     protected String CalcArrayAddressAux(ArrayList<Node> childrens, int Size) throws Exception {
-        String current;
 //        boolean multPerSize = true;
         Node ind, nextIndex;
         ind = childrens.remove(0);
-        System.out.println("CalcArrayAddressAux:" + childrens.size() + ":" + Size);
-
+//        System.out.println("CalcArrayAddressAux:" + childrens.size() + ":" + Size + "\n" + ind);
+        String current, varname;
+
+        if (ind.eq("class", "expr")) {
+            varname = gerarVariavel(
+                    new Node(gerarVariavel("TMP"))
+                    .S("array", "false")
+                    .S("type", "int")
+                    .S("var.tmp", "true")
+            );
+
+            Node p1 = visit(ind.childrens().get(0)),
+                    p2 = visit(ind.childrens().get(1));
+            __exp(ind.getText(), p1.G("_return"), p2.G("_return"), varname);
+        } else {
+            varname = gerarVariavel(ind);
+        }
+//        if (ind)
         // ultimo elemento da idexacao
         if (childrens.size() == 0) {
 
             if (Utils.isNumber(ind.getText())) {
                 return "" + ind.getInt("value");
             } else {
-                return GenShiftLeftLogical(gerarVariavel(ind), Size, false);
+                return GenShiftLeftLogical(varname, Size, false, true);
             }
         }
 
@@ -565,7 +612,8 @@ public final class BaseTacGen implements TacGenInterface {
         } else {
 //                System.out.println("collNumber:" + collNumber);
 
-            current = GenShiftLeftLogical(gerarVariavel(ind), collNumber, false);
+//            current = GenShiftLeftLogical(gerarVariavel(ind), collNumber, false, false);
+            current = GenShiftLeftLogical(varname, collNumber, false, false);
 //            System.out.println("Gerando index calc:" + retl);
 //            current = GenShiftLeftLogical(retl, Size);
 //            current = retl;
@@ -693,7 +741,9 @@ public final class BaseTacGen implements TacGenInterface {
      * @throws Exception
      */
     protected void gerarConstante(Node n) throws Exception {
-        gerarVariavel(n);
+
+//        System.out.println("Gerando constant:" + n.childrens().get(0) + n.childrens().get(1));
+//        gerarVariavel(n.get(label, label));
 //        getLabel("C", n);
 //        if (n.closest("block", "class") != null) {
 //            code.registerVar(n.G("_return"), 1, DataFrame.TYPE_VAR);
@@ -832,7 +882,10 @@ public final class BaseTacGen implements TacGenInterface {
 
     protected void BranchAnd(Node n, int index) throws Exception {
 //        int pos = 0;
-        OrTestAndOccurrence++;
+//         if (n.parent == null) {
+//            System.out.println("BranchAnd:" + n);
+//        }
+//        OrTestAndOccurrence++;
         Instruction instruction = null;
         ArrayList<Node> x = n.childrens();
         Node op1 = x.get(0), op2 = x.get(1);
@@ -852,29 +905,32 @@ public final class BaseTacGen implements TacGenInterface {
                 case "jtb":
                     instruction.S("op", Complement(instruction.G("op")));
 
-                    if (n.parent.eq("value", "||")) {
+                    if (n.parent != null && n.parent.eq("value", "||")) {
                         if (index == 1) {
-                            instruction.S("label", n.parent.G("skip.test"));
+                            UpdateLabel(instruction, n.parent.G("skip.test"));
                         } else if (index == 2) {
-                            instruction.S("label", n.parent.G("end"));
+                            UpdateLabel(instruction, n.parent.G("end"));
                         }
 //                    } else if (n.parent.eq("value", "&&")) {
 
                     } else {
-                        instruction.S("label", n.G("end"));
+                        UpdateLabel(instruction, n.G("end"));
                     }
                     break;
                 case "jb":
-                    if (n.parent.eq("value", "||")) {
+//                    if (n.parent != null) {
+                    if (n.parent != null && n.parent.eq("value", "||")) {
                         if (index <= 1) {
-                            instruction.S("label", n.parent.G("skip.test"));
+                            UpdateLabel(instruction, n.parent.G("skip.test"));
+
                         } else if (index == 2) {
 //                            instruction.S("op", Complement(instruction.G("op")));
-                            instruction.S("label", n.G("next"));
+                            UpdateLabel(instruction, n.G("next"));
                         }
-                    } else {
-
                     }
+//                    } else {
+
+//                    }
             }
         }
 //        System.out.println("instruction Branch 1:" + instruction + "\n" + op1);
@@ -887,12 +943,12 @@ public final class BaseTacGen implements TacGenInterface {
         if (instruction != null) {
             switch (type) {
                 case "jtb":
-                    if (n.parent.eq("value", "||")) {
+                    if (n.parent != null && 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"));
+                            UpdateLabel(instruction, n.G("end"));
                         } else if (index == 2) {  // teste 2 do parametro 2
-                            instruction.S("label", n.G("next"));
+                            UpdateLabel(instruction, n.G("next"));
                         }
 //                    } else if (n.parent.eq("value", "&&")) {
 //                        if (index == 1) { // teste 1 do parametro 2 com pai && 
@@ -900,12 +956,12 @@ public final class BaseTacGen implements TacGenInterface {
 //
 //                        } else if (index == 2) {  // teste 2 do parametro 2 com pai && 
 //                            instruction.S("op", Complement(instruction.G("op")));
-//                            instruction.S("label", n.G("end"));
+//                            UpdateLabel(instruction, 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"));
+                            UpdateLabel(instruction, n.G("end"));
                         } else if (index == 2) {
 //                            throw new Exception("teste 2 do parametro 2 geral");
                         }
@@ -913,28 +969,42 @@ public final class BaseTacGen implements TacGenInterface {
                     break;
                 case "jb":
 
-                    System.out.println("I(jb:and:2)[" + index + "]\n" + instruction + "\n" + n);
-
-                    if (n.parent.eq("value", "||")) {
+//                    System.out.println("I(jb:and:2)[" + index + "]\n" + instruction + "\n" + n);
+//                    if (n.parent != null) {
+                    if (n.parent != null && n.parent.eq("value", "||")) {
                         if (index <= 1) {
-//                            instruction.S("label", n.parent.G("skip.test"));
+//                            UpdateLabel(instruction, n.parent.G("skip.test"));
                             instruction.S("op", Complement(instruction.G("op")));
-                            instruction.S("label", n.G("start"));
+                            UpdateLabel(instruction, n.G("start"));
 
                         } else if (index == 2) {
 //                            instruction.S("op", Complement(instruction.G("op")));
-                            instruction.S("label", n.G("next"));
-                        }
-                    } else {
+                            UpdateLabel(instruction, n.G("next"));
 
+                        }
                     }
+//                    } else {
+
+//                    }
             }
         }
     }
 
+    public void UpdateLabel(Instruction I, String label) {
+        String copy = I.G("label");
+        if (!copy.equals("")) {
+            code.RemoveLabelReference(copy);
+        }
+        I.S("label", label);
+        code.AddLabelReference(label);
+    }
+
     protected void BranchOr(Node n, int index) throws Exception {
+//        if (n.parent == null) {
+//            System.out.println("BranchOr:" + n);
+//        }
         //        int pos = 0;
-        OrTestAndOccurrence++;
+//        OrTestAndOccurrence++;
         Instruction instruction = null;
         ArrayList<Node> x = n.childrens();
         Node op1 = x.get(0), op2 = x.get(1);
@@ -954,32 +1024,35 @@ public final class BaseTacGen implements TacGenInterface {
         if (instruction != null) {
             switch (type) {
                 case "jtb":
-                    if (n.parent.eq("value", "&&")) {
+                    if (n.parent != null && n.parent.eq("value", "&&")) {
                         if (index == 1) {
-                            instruction.S("label", n.parent.G("skip.test"));
+                            UpdateLabel(instruction, n.parent.G("skip.test"));
                         }
                     }
                     break;
                 case "jb":
 //                    System.out.println("I(jb:1)[" + index + "]\n" + instruction + "\n" + n);
 
-                    if (n.parent.eq("value", "||")) {
+//                    System.out.println("Entrei no jb ||" + (jb++) + instruction + n.parent);
+//                    if (n.parent != null) {
+                    if (n.parent != null && n.parent.eq("value", "||")) {
 //                        if (index == 2) {
                         instruction.S("op", Complement(instruction.G("op")));
-                        instruction.S("label", n.G("start"));
+                        UpdateLabel(instruction, n.G("start"));
 //                        }
-                    } else if (n.parent.eq("value", "&&")) {
+                    } else if (n.parent != null && n.parent.eq("value", "&&")) {
                         if (index <= 1) {
                             instruction.S("op", Complement(instruction.G("op")));
-                            instruction.S("label", n.parent.G("skip.test"));
+                            UpdateLabel(instruction, n.parent.G("skip.test"));
                         } else if (index == 2) {
                             instruction.S("op", Complement(instruction.G("op")));
-                            instruction.S("label", n.parent.G("start"));
+                            UpdateLabel(instruction, n.parent.G("start"));
                         }
+//                        }
                     } else {
                         instruction.S("op", Complement(instruction.G("op")));
                         if (index <= 1) {
-                            instruction.S("label", n.G("start"));
+                            UpdateLabel(instruction, n.G("start"));
                         } else if (index == 2) {
 
                         }
@@ -995,36 +1068,38 @@ public final class BaseTacGen implements TacGenInterface {
         if (instruction != null) {
             switch (type) {
                 case "jtb":
-                    if (n.parent.eq("value", "&&")) {
+                    if (n.parent != null && n.parent.eq("value", "&&")) {
                         if (index == 1) {
                             instruction.S("op", Complement(instruction.G("op")));
-                            instruction.S("label", n.parent.G("end"));
+                            UpdateLabel(instruction, n.parent.G("end"));
                         }
                     }
                     break;
                 case "jb":
-                    if (n.parent.eq("value", "||")) {
+//                    if (n.parent != null) {
+                    if (n.parent != null && n.parent.eq("value", "||")) {
                         if (index <= 1) {
 
                             instruction.S("op", Complement(instruction.G("op")));
-                            instruction.S("label", n.G("start"));
+                            UpdateLabel(instruction, n.G("start"));
 
                         } else if (index == 2) {
 //
 //                            instruction.S("op", Complement(instruction.G("op")));
-                            instruction.S("label", n.G("next"));
+                            UpdateLabel(instruction, n.G("next"));
                         }
-                    } else if (n.parent.eq("value", "&&")) {
+                    } else if (n.parent != null && n.parent.eq("value", "&&")) {
                         if (index == 1) {
 //                            instruction.S("op", Complement(instruction.G("op")));
-//                            instruction.S("label", n.parent.G("start"));
+//                            UpdateLabel(instruction, n.parent.G("start"));
                         } else if (index == 2) {
 //                            instruction.S("op", Complement(instruction.G("op")));
-//                            instruction.S("label", n.parent.G("start"));
+//                            UpdateLabel(instruction, n.parent.G("start"));
                         }
+//                        }
                     } else {
 //                        instruction.S("op", Complement(instruction.G("op")));
-//                        instruction.S("label", n.G("next"));
+//                        UpdateLabel(instruction, n.G("next"));
                     }
             }
         }
@@ -1354,12 +1429,16 @@ public final class BaseTacGen implements TacGenInterface {
      */
     protected void switchStmt(Node n) throws Exception {
         /*Label que sera consultado pelo break para sair do case*/
-        String end = gerarLabel();
-        String dst = null, next = null;
-        Node test = n.find("test");
+
+        String start,
+                next,
+                end = gerarLabel(),
+                dst = null;
 
         n.S("next", end);
 
+        Node test = n.find("test");
+
         // Verifica se existe entrada para selecao
         if (test.childrens().size() > 0) {
             test = test.first();
@@ -1367,46 +1446,26 @@ public final class BaseTacGen implements TacGenInterface {
             dst = test.G("_return");
         }
 
+//        test;
         ArrayList<Node> cases = n.findAll("def.case", "class", 1);
-        int id = 0, count = cases.size() - 1;
 
         for (Node _case : cases) {
-            if (next != null) {
-                _case.S("start", next);
-            }
-            _case.S("_input", dst);
-            _case.S("end", end);
 
-            genCase(_case, id == count);
-            next = _case.G("next");
-            id++;
-        }
+            start = gerarLabel();
+            next = gerarLabel();
 
-        /*Marca o endereço final para sair do switch*/
-        PushLabel(end, "branch");
-    }
+            _case.S("start", start)
+                    .S("_input", dst)
+                    .S("next", next)
+                    .S("end", end)
+                    .S("test.type", "jb");
 
-    protected Node NodeBoolExpr(String op, Node e1, Node e2) {
-        return new Node(op)
-                .S("type", "bool")
-                .S("class", "expr")
-                .S("subclass", "bool")
-                .addFilho(e1)
-                .addFilho(e2);
-    }
+            genCase(_case);
 
-    protected ArrayList<Node> ExprsEq(Node n, Node input) throws Exception {
-        ArrayList<Node> list = new ArrayList<>();
-        switch (n.Class()) {
-            case "exprs":
-                for (Node e : n.childrens()) {
-                    list.add(NodeBoolExpr("==", input, e));
-                }
-                break;
-            default:
-                list.add(NodeBoolExpr("==", input, n));
         }
-        return list;
+
+        /*Marca o endereço final para sair do switch*/
+        PushLabel(end, "branch");
     }
 
     /**
@@ -1414,60 +1473,138 @@ public final class BaseTacGen implements TacGenInterface {
      *
      * @param n
      */
-    protected void genCase(Node n, boolean last) throws Exception {
+    protected void genCase(Node n) throws Exception {
+        ArrayList<Node> exprs;
+        Node test;
+//        System.out.println("GEN_CASE:" + n);
 
-        String start = n.Has("start") ? n.G("start") : gerarLabel();
-        String next = gerarLabel(), end;
-
-//        System.out.println("GenCase:" + start + ":" + next);
+//        String start = n.Has("start") ? n.G("start") : gerarLabel();
+//        String next = gerarLabel(), end;
+//
+////        System.out.println("GenCase:" + start + ":" + next);
         ArrayList<Node> itens = n.childrens();
         Node stmts = n.find("stmts");
-        Node or;
-
+//        Node or;
+//  
         if (itens.size() >= 2) { // Tem teste
-            String input = n.G("_input");
-            Node test = n.first();
-            ArrayList<Node> exprs;
+            test = n.first();
+            String input = n.G("_input"),
+                    start = n.G("start"),
+                    end = n.G("end"),
+                    next = n.G("next");
 
+//
             if (input != null) {
                 exprs = ExprsEq(test, new Node(input).S("_return", input));
             } else {
                 exprs = test.childrens();
             }
 
-            /*Seleciona o endereco de saida se é no proximo case ou no fim do switch*/
-            if (stmts.last().eq("value", "fallthrough")) {
-                end = gerarLabel();
-                n.S("next", end);
-            } else {
-                end = n.G("end");
-            }
-
-            // Atualiza o PushLabel de sucesso das exprs
+//            /*Seleciona o endereco de saida se é no proximo case ou no fim do switch*/
+//            if (stmts.last().eq("value", "fallthrough")) {
+//                end = gerarLabel();
+//                n.S("next", end);
+//            } else {
+//                end = n.G("end");
+//            }
+//
+//            // Atualiza o PushLabel de sucesso das exprs
             for (Node expr : exprs) {
-                expr.S("true", !last ? next : end);
-//                expr.S("false", next);
-//                expr.S("false", start);
+                expr.copy("start,next,end,test.type", n);
             }
-
+//
             Branch(OR(exprs).S("next", next), 0);
 
             /*Se nenhum dos casos for compativel salta para o proximo*/
-//            _goto(!last ? next : end);
+
             /*Marca o PushLabel inicial do caso*/
             PushLabel(start, "branch");
             /*Visita o bloco do case*/
             visit(stmts);
+            /*Salta para o proximo case ou para o fim do switchcase*/
+            _goto(end);
+            /*Label do inicio do proximo case*/
+            PushLabel(next, "branch");
 
-            if (!last) {
-                /*Salta para o proximo case ou para o fim do switchcase*/
-                _goto(end);
-                /*Label do inicio do proximo case*/
-                PushLabel(next, "branch");
-            }
         } else {  // Default statiment
             visit(stmts);
         }
+
+//        String start = n.Has("start") ? n.G("start") : gerarLabel();
+//        String next = gerarLabel(), end;
+//
+////        System.out.println("GenCase:" + start + ":" + next);
+//        ArrayList<Node> itens = n.childrens();
+//        Node stmts = n.find("stmts");
+//        Node or;
+//
+//        if (itens.size() >= 2) { // Tem teste
+//            String input = n.G("_input");
+//            Node test = n.first();
+//            ArrayList<Node> exprs;
+//
+//            if (input != null) {
+//                exprs = ExprsEq(test, new Node(input).S("_return", input));
+//            } else {
+//                exprs = test.childrens();
+//            }
+//
+//            /*Seleciona o endereco de saida se é no proximo case ou no fim do switch*/
+//            if (stmts.last().eq("value", "fallthrough")) {
+//                end = gerarLabel();
+//                n.S("next", end);
+//            } else {
+//                end = n.G("end");
+//            }
+//
+//            // Atualiza o PushLabel de sucesso das exprs
+//            for (Node expr : exprs) {
+//                expr.S("true", !last ? next : end);
+////                expr.S("false", next);
+////                expr.S("false", start);
+//            }
+//
+//            Branch(OR(exprs).S("next", next), 0);
+//
+//            /*Se nenhum dos casos for compativel salta para o proximo*/
+////            _goto(!last ? next : end);
+//            /*Marca o PushLabel inicial do caso*/
+//            PushLabel(start, "branch");
+//            /*Visita o bloco do case*/
+//            visit(stmts);
+//
+//            if (!last) {
+//                /*Salta para o proximo case ou para o fim do switchcase*/
+//                _goto(end);
+//                /*Label do inicio do proximo case*/
+//                PushLabel(next, "branch");
+//            }
+//        } else {  // Default statiment
+//            visit(stmts);
+//        }
+    }
+
+    protected Node NodeBoolExpr(String op, Node e1, Node e2) {
+        return new Node(op)
+                .S("type", "bool")
+                .S("class", "expr")
+                .S("subclass", "bool")
+                .addFilho(e1)
+                .addFilho(e2);
+    }
+
+    protected ArrayList<Node> ExprsEq(Node n, Node input) throws Exception {
+        ArrayList<Node> list = new ArrayList<>();
+        switch (n.Class()) {
+            case "exprs":
+                for (Node e : n.childrens()) {
+                    list.add(NodeBoolExpr("==", input, e));
+                }
+                break;
+            default:
+                list.add(NodeBoolExpr("==", input, n));
+        }
+        return list;
     }
 
     protected Node OR(ArrayList<Node> n) throws Exception {
@@ -1479,7 +1616,7 @@ public final class BaseTacGen implements TacGenInterface {
             default:
                 Node x = n.get(0);
                 n.remove(x);
-                return NodeBoolExpr("||", x, OR(n)).copy("true,false", x);
+                return NodeBoolExpr("||", x, OR(n)).copy("start,next,end,test.type", x);
         }
     }
 
@@ -1509,8 +1646,11 @@ public final class BaseTacGen implements TacGenInterface {
                 //                operators = new ArrayList<>(),
                 returns;
         ArrayList<Boolean> copyaddress = new ArrayList<>();
-        String p1, declare = "" + n.getText().equals("dec.var.short");
+        String p1,
+                modify = n.G("modify"),
+                declare = "" + n.getText().equals("dec.var.short");
 
+//        System.out.println("genAssign:" + n.childrens().get(0).childrens().get(0));
         Node dsts = n.childrens().get(0);
 
         if (n.in("value", new String[]{"dec.var.short", "def.assign"})) {
@@ -1586,7 +1726,12 @@ public final class BaseTacGen implements TacGenInterface {
             } else {
                 // Copia valor para endereco
 //                System.out.println("Attrib:" + d.G("_return") + "<" + localAttribs.get(i));
-                Copy(d.G("_return"), localAttribs.get(i), copyaddress.get(i));
+                if (!modify.equals("")) {
+
+                    __exp(modify, d.G("_return"), localAttribs.get(i), d.G("_return")).S("comment", "");
+                } else {
+                    Copy(d.G("_return"), localAttribs.get(i), copyaddress.get(i));
+                }
                 i++;
             }
         }
@@ -1795,26 +1940,23 @@ public final class BaseTacGen implements TacGenInterface {
      * @throws Exception
      */
     protected void ctrlStmt(Node n) throws Exception {
-        Node container = n.closest("for.stmt,switch.stmt", "class");
+        String go;
+        Node ctn = n.closest("for.stmt,switch.stmt", "class");
 
         switch (n.getText()) {
             case "continue":
-                String go;
-                if (container.eq("class", "for.stmt")) {
-                    go = container.G("inc");
-                } else {
-                    go = container.G("end");
-                }
-                _goto(go);
+                go = ctn.G(ctn.eq("class", "for.stmt") ? "inc" : "end");
                 break;
             case "break":
-                _goto(container.G("end"));
+                go = ctn.G("end");
                 break;
             case "goto":
-                _goto(n.G("label"));
+                go = n.G("label");
                 break;
+            default:
+                throw new Exception("Undefined ctrl stmt '" + n.getText() + "'.");
         }
-
+        _goto(go);
     }
 
     /**
@@ -2015,11 +2157,20 @@ public final class BaseTacGen implements TacGenInterface {
         Node var = Variaveis.Get(id);
         String varname, alias, vn;
 
-        if (var.eq("constant", "true")) {
-            varname = id;
+        if (var != null) {
+            if (var.eq("constant", "true")) {
+                varname = id;
+            } else {
+                varname = var.getText();
+            }
+//            System.out.println("Variavel definida:" + varname);
         } else {
-            varname = var.getText();
+            varname = n.getText();
+            var = n;
+//            System.out.println("Variavel do no consultado:" + varname);
+//            Variaveis.Add(id, n);
         }
+
 //        System.out.printf("GerarVariavelSet{%s\n,%s\n,%s\n}\n", id, varname, var);
 //        if (var.eq("constant", "true")) {
 //            System.out.printf("GerarVariavelSet{%s\n,%s\n,%s\n}\n", id, varname, var);
@@ -2034,10 +2185,13 @@ public final class BaseTacGen implements TacGenInterface {
                 prefix = "C";
             } else if (var.eq("global", "true")) {
                 prefix = "G";
+            } else if (var.eq("var.tmp", "true")) {
+                prefix = "T";
             } else {
                 prefix = "V";
             }
 
+//            System.out.println("gerarVariavelSet:" + id + var);
 //            System.out.println("DecVar:" + var);
 //            alias = var.G("pointer") + gerarVariavel(prefix);
             alias = gerarVariavel(prefix);
@@ -2049,10 +2203,19 @@ public final class BaseTacGen implements TacGenInterface {
 
             int size = Tipos.Size(var.G("type")), b = 1;
 
+//            System.out.println("gerarVariavelSetVAR:" + var);
             // Se for um array considera os filhos como index
-            if (!var.eq("constant", "true") && var.childrens().size() > 0) {
+            if (var.eq("array", "true") && var.childrens().size() > 0) {
                 for (Node node : var.childrens()) {
-                    b *= node.getInt("value");
+
+//                    System.out.println("gerarVariavelSetArray:"
+//                            + node.eq("constant", "true")
+//                            + "\n" + node
+//                            + "\nVARIABLE:\n" + var
+//                    );
+                    b *= (node.eq("constant", "true")
+                            ? node.getInt("valueConstant")
+                            : node.getInt("value"));
                 }
             }
             size *= b;
@@ -2060,7 +2223,13 @@ public final class BaseTacGen implements TacGenInterface {
             var.set("size", size);
 
 //            System.out.println("gerarVariave[" + prefix + "|" + id + "]:" + var);
-            (prefix.equals("G") ? code.GData() : code.Block().Data()).Add(alias, var);
+            if (!var.eq("constant", "true") || !var.in("type", new String[]{"int", "char", "bool"})) {
+
+                (prefix.equals("G") ? code.GData() : code.Block().Data()).Add(alias, var);
+            } else {
+//                System.out.println("var:" + var);
+                alias = var.G("valueConstant");
+            }
         }
         return alias;
     }

+ 3 - 1
src/compiler/IVANNOSYS.java

@@ -34,7 +34,9 @@ public class IVANNOSYS {
                     break;
                 default:
                     compiler = new IvannosysCompiler(
-                            "src\\samples\\program.go",
+//                            "src\\samples\\program.go",
+                            "src\\samples\\program_if.go",
+//                            "src\\samples\\program_mult.go",
                             "UTF-8",
                             IvannosysCompiler.INPUT_FILE)
                             // Especifica a classe de geração de codigo de tres enderecos

+ 2 - 2
src/compiler/IvannosysCompiler.java

@@ -7,7 +7,6 @@ package compiler;
 
 import API.Api;
 import API.Instruction;
-import API.Variaveis;
 import IntermediaryCode.Code;
 import IntermediaryCode.TacGenInterface;
 import ast.AbstractSyntaxTree;
@@ -188,7 +187,7 @@ public class IvannosysCompiler {
 
             DisplayAST(parser);
 
-            Variaveis.List();
+//            Variaveis.List();
             Semantic semantic = new Semantic(ast);
             if (semantic.Execute().HasError()) {
                 abortarPorErro(semantic, "semantic");
@@ -198,6 +197,7 @@ public class IvannosysCompiler {
              * Etapa de geração de codigo de 3 enderecos
              */
             Log.PrintInfo("TAC", new Instruction().S("msg", "Gerando código de três endereços"));
+            
             Code code = tac.Create(ast, settings);
 //            return this;
             for (String arch : code.ast.getCompileParams().getList("target")) {

+ 18 - 10
src/grammar/visitorAndWalkers/IvannosysListener.java

@@ -56,7 +56,7 @@ public class IvannosysListener extends IvannosysGrammarBaseListener {
 
     public IvannosysListener(IvannosysCompiler comp) throws Exception {
         ast = AbstractSyntaxTree.getAbstractSyntaxTree();
-        compiler = comp; 
+        compiler = comp;
         errors = new Log();
         this.ReadId.push(true);
     }
@@ -264,6 +264,10 @@ public class IvannosysListener extends IvannosysGrammarBaseListener {
                             types.add(e.find("exprs").childrens().get(0).G("type"));
                         }
                         break;
+                    case "expr":
+                        types.add(e.G("type"));
+                        indexes.add(new ArrayList<Node>());
+                        break;
                     default:
 //                        System.out.println("E:" + e);
                         types.add(e.G("type"));
@@ -361,15 +365,18 @@ public class IvannosysListener extends IvannosysGrammarBaseListener {
         ArrayList<Node> childrens = node.childrens();
 
         String id = childrens.get(0).getText();
-
         Node value = childrens.get(1);
 
-        node.S("name", id)
-                .S("type", value.G("type"))
-                .S("value", value.getText());
+        String varID = scopeStack.peek() + "." + id;
+        Node var = new Node(varID).S("name", id)
+                .S("valueConstant", value.getText())
+                .S("constant", "true")
+                .S("pointer", "false")
+                .S("array", "false")
+                .copy("file,scope,line,col,type", value);
         try {
 
-            Variaveis.Add(scopeStack.peek() + "." + id, node);
+            Variaveis.Add(varID, var);
 
         } catch (Exception e) {
             errors.AddError(
@@ -538,9 +545,10 @@ public class IvannosysListener extends IvannosysGrammarBaseListener {
         if (ctx.index() != null) {
             String val = ctx.index().expression().getText();
             if (!Utils.isNumber(val)) {
-                Node constante = Variaveis.Get(scopeStack.peek() + "." + val);
-                if (constante != null) {
-                    val = constante.G("value");
+                Node ref = Variaveis.Get(scopeStack.peek() + "." + val);
+                if (ref != null && ref.eq("constant", "true")) {
+//                    System.out.println("INDEXEDTYPE" + constante);
+                    val = ref.G("valueConstant");
                 }
             }
 
@@ -658,7 +666,7 @@ public class IvannosysListener extends IvannosysGrammarBaseListener {
         Node decl = astCurrent(), type;
         ArrayList<Node> attribs = new ArrayList<>();
         ArrayList<Node> decls = decl.childrens();
-        System.out.println("StructType:" + decl);
+//        System.out.println("StructType:" + decl);
         for (Node ids : decl.findAll("ids", "value")) {
             type = decls.get(decls.indexOf(ids) + 1);
             for (Node id : ids.childrens()) {

+ 67 - 376
src/samples/program.go

@@ -3,404 +3,95 @@
 package main;
 
 const (
-    LIN  = 2
-    COL  = 2
+    LIN = 5
+    COL = 5
 )
+
 var (
-    matrizA [LIN][COL]int 
+    origin [LIN][COL]int
+    result [LIN][COL]int
 )
 
-func main() {
+func preenche_matriz() {
     var (
-        aux = 0
-        i = 1
+        w = 1
+        value int
     )
-/**
-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
-    }
-
-*/
-
-//if (i < LIN || 1 == 1) && (i < LIN && 1 == 1) {
-
-IF_01:
-if (i < LIN) {
-    aux = 10
-}else {
-    aux = 20
-}
-
-IF_02:
-if (i < LIN || 1 == 1) {
-    aux = 10
-}else {
-    aux = 20
-}
-IF_03:
-if (i < LIN && 1 == 1) {
-    aux = 10
-}else {
-    aux = 20
-}
-
-IF_04:
-if ((i < LIN || 1 == 1) || (i < LIN || 1 == 1)) {
-    aux = 10
-}else {
-    aux = 20
-}
-
-IF_05:
-if ((i < LIN && 1 == 1) && (i < LIN && 1 == 1)) {
-    aux = 10
-}else {
-    aux = 20
-}
-
-IF_06:
-if ((i < LIN && 1 == 1) || (i < LIN && 1 == 1)) {
-    aux = 10
-}else {
-    aux = 20
-}
-
-IF_07:
-if ((i < LIN || 1 == 1) && (i < LIN || 1 == 1)) {
-    aux = 10
-}else {
-    aux = 20
-}
-
-IF_08:
-if ((i < LIN && 1 == 1) && (i < LIN || 1 == 1)) {
-    aux = 10
-}else {
-    aux = 20
-}
-
-IF_09:
-if ((i < LIN || 1 == 1) && (i < LIN && 1 == 1)) {
-    aux = 10
-}else {
-    aux = 20
-}
-
-IF_10:
-if ((i < LIN && 1 == 1) || (i < LIN || 1 == 1)) {
-    aux = 10
-}else {
-    aux = 20
-}
-
-IF_11:
-if ((i < LIN || 1 == 1) || (i < LIN && 1 == 1)) {
-    aux = 10
-}else {
-    aux = 20
-}
-
-
-/**
-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
-)
+    
+    LM1 := LIN - 1
+    CM1 := COL - 1
 
-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++
+    for i := 0; i < LIN; i++ {
+        for j := 0; j < COL; j++ {
+            switch {
+                case i == 0, i == LM1: // Primeira  e ultima linha
+                    value = 0
+                case j == 0, j == CM1: // Primeira e ultima coluna
+                    value = 0
+                default:               // Elementos do interior da matriz
+                    value = w
+                    w++
+            }
+            origin[i][j] = value
         }
     }
 }
 
-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]
+func laplaciano() {
+    var (
+        l int
+        //LM1,CM1 int
+        
+    )
+    LM1 := LIN - 1
+    CM1 := COL - 1
+
+    for i:= 1; i < LM1; i++ {
+        for j := 1; j < CM1; j++ {
+lab_1:
+            l = origin[i-1][j]
+lab_2:
+            l = l + origin[i][j-1]
+lab_3:
+            l = l + origin[i][j+1] 
+lab_4:
+            l = l + origin[i+1][j]
+lab_5:
+            l = l - (4 * origin[i][j])
+lab_6:
+
+            if l > 255 {
+              l = 255
             }
-            matrizR[i][j] = aux
-            aux = 0
+            result[i][j] = l
         }
     }
 }
+/*
+*/
+
 func main() {
-    preenche()
-    multiplica()
+  preenche_matriz()
+  laplaciano()
 }
 
+/**
 
 */
-/**
-package main;
+/*
 
 const (
-    LIN  = 2
-    COL  = 2
-)
-
-type X struct {
-    a int 
-    b int 
-    c int 
-}
-
-var (
-    a [5][6]int
-    matrixX [3]X
+    X = 10
+    Y = 20
 )
-
-func atualiza(x,i int) {
-    if (x == 1){
-    //a[x][i].c = 1
-//    a[x][i] = 1
-        a[x][i] = 10
-    } else {
-        i = 1
-    }
-}
-
-func atualiza2(x *int) int {
-    *x = 10
-    return 2
-}
-
-func main() int {
-    x := 1
-    i := 1
-    
+func main(){
     var (
-        varx X
+        x [Y]int
+        i = 12
     )
-
-    i = atualiza2(y)
-    //atualiza(x,i)
-
-    //varx.c = 50
-    //matrixX[i].c = 50
-
-/*
-Testados
-IF_BASIC:
-    if i < LIN  {
-        x = 10
-    }
-
-
-IF_ANDOR:
-
-    if (i < LIN && true) || 1 == 1 {
-        x = 10
-    } else {
-        x = 20
-    }
-
-*/
-/*
-IF_ORAND:
-    if (i < LIN || true) && 1 == 1 {
-        x = 10
-    } else {
-        x = 20
-    }
-
-IF_ANDOR_R:
-
-    if 1 == 1  || (i < LIN && true){
-        x = 10
-    } else {
-        x = 20
-    }
-
-IF_ORAND_R:
-    if 1 == 1 && (i < LIN || true) {
-        x = 10
-    } else {
-        x = 20
-    }
-
-IF_OROR:
-
-    if (i < LIN || true) || 1 == 1 {
-        x = 10
-    } else {
-        x = 20
-    }
-
-IF_ANDAND:
-    if (i < LIN && true) && 1 == 1 {
-        x = 10
-    } else {
-        x = 20
-    }
-
-IF_OROR_R:
-
-    if 1 == 1 || (i < LIN || true){
-        x = 10
-    } else {
-        x = 20
-    }
-
-IF_ANDAND_R:
-    if  1 == 1||(i < LIN && true) {
-        x = 10
-    } else {
-        x = 20
-    }
-
-IF_ORANDOR:
-    if (i < LIN || true) && (1 == 1 || 2==2) {
-        x = 10
-    } else {
-        x = 20
-    }
-
-
-IF_ANDORAND_0:
-    if (i < LIN || true) || (1 == 1 || 2 == 2 ) {
-        x = 10
-    } else {
-        x = 20
-    }
-
-IF_ANDORAND_1:
-    if (i < LIN && true) || (1 == 1 || 2==2) {
-        x = 10
-    } else {
-        x = 20
-    }
-
-IF_ANDORAND_2:
-    if (i < LIN || true) || (1 == 1 && 2 == 2 ) {
-        x = 10
-    } else {
-        x = 20
-    }
-
-IF_ANDORAND_10:
-    if (i < LIN && true) || 2==2 {
-        x = 10
-    } else {
-        x = 20
-    }
-IF_ANDORAND_11:
-    if 2==2 || (i < LIN && true) {
-        x = 10
-    } else {
-        x = 20
-    }
-    return x
-*/
-
+    //i++
+    //i += 10
+    //x[i + 3] = 40
+    x[X + 3] = i
+}
+*/

+ 440 - 0
src/samples/program_if.go

@@ -0,0 +1,440 @@
+@target mips, mipt2
+
+package main;
+
+const (
+    LIN  = 2
+    COL  = 2
+)
+var (
+    matrizA [LIN][COL]int 
+)
+
+func main() {
+    var (
+        aux = 0
+        i = 1
+    )
+/**
+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
+    }
+
+*/
+
+
+SWITCH_1:
+
+switch aux {
+    case 1,3,5:
+        aux = 10
+    case 2:
+        aux = 20
+    default:
+        aux = 30
+}
+
+SWITCH_2:
+switch {
+    case 1 == 3, 2 < 4:
+        aux = 10
+    case 2 == 2:
+        aux = 20
+    default:
+        aux = 30
+}
+
+// if - if - else
+if i == 1 && 1 == 1 {
+   aux = 10
+
+} else if i == 2 {
+   aux = 20
+
+}else {
+   aux = 30
+}
+
+
+
+IF_01:
+if (i < LIN) {
+    aux = 10
+}else {
+    aux = 20
+}
+
+IF_02:
+if (i < LIN || 1 == 1) {
+    aux = 10
+}else {
+    aux = 20
+}
+IF_03:
+if (i < LIN && 1 == 1) {
+    aux = 10
+}else {
+    aux = 20
+}
+
+IF_04:
+if ((i < LIN || 1 == 1) || (i < LIN || 1 == 1)) {
+    aux = 10
+}else {
+    aux = 20
+}
+
+IF_05:
+if ((i < LIN && 1 == 1) && (i < LIN && 1 == 1)) {
+    aux = 10
+}else {
+    aux = 20
+}
+
+IF_06:
+if ((i < LIN && 1 == 1) || (i < LIN && 1 == 1)) {
+    aux = 10
+}else {
+    aux = 20
+}
+
+IF_07:
+if ((i < LIN || 1 == 1) && (i < LIN || 1 == 1)) {
+    aux = 10
+}else {
+    aux = 20
+}
+
+IF_08:
+if ((i < LIN && 1 == 1) && (i < LIN || 1 == 1)) {
+    aux = 10
+}else {
+    aux = 20
+}
+
+IF_09:
+if ((i < LIN || 1 == 1) && (i < LIN && 1 == 1)) {
+    aux = 10
+}else {
+    aux = 20
+}
+
+IF_10:
+if ((i < LIN && 1 == 1) || (i < LIN || 1 == 1)) {
+    aux = 10
+}else {
+    aux = 20
+}
+
+IF_11:
+if ((i < LIN || 1 == 1) || (i < LIN && 1 == 1)) {
+    aux = 10
+}else {
+    aux = 20
+}
+/** 
+*/
+
+/**
+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
+)
+
+type X struct {
+    a int 
+    b int 
+    c int 
+}
+
+var (
+    a [5][6]int
+    matrixX [3]X
+)
+
+func atualiza(x,i int) {
+    if (x == 1){
+    //a[x][i].c = 1
+//    a[x][i] = 1
+        a[x][i] = 10
+    } else {
+        i = 1
+    }
+}
+
+func atualiza2(x *int) int {
+    *x = 10
+    return 2
+}
+
+func main() int {
+    x := 1
+    i := 1
+    
+    var (
+        varx X
+    )
+
+    i = atualiza2(y)
+    //atualiza(x,i)
+
+    //varx.c = 50
+    //matrixX[i].c = 50
+
+/*
+Testados
+IF_BASIC:
+    if i < LIN  {
+        x = 10
+    }
+
+
+IF_ANDOR:
+
+    if (i < LIN && true) || 1 == 1 {
+        x = 10
+    } else {
+        x = 20
+    }
+
+*/
+/*
+IF_ORAND:
+    if (i < LIN || true) && 1 == 1 {
+        x = 10
+    } else {
+        x = 20
+    }
+
+IF_ANDOR_R:
+
+    if 1 == 1  || (i < LIN && true){
+        x = 10
+    } else {
+        x = 20
+    }
+
+IF_ORAND_R:
+    if 1 == 1 && (i < LIN || true) {
+        x = 10
+    } else {
+        x = 20
+    }
+
+IF_OROR:
+
+    if (i < LIN || true) || 1 == 1 {
+        x = 10
+    } else {
+        x = 20
+    }
+
+IF_ANDAND:
+    if (i < LIN && true) && 1 == 1 {
+        x = 10
+    } else {
+        x = 20
+    }
+
+IF_OROR_R:
+
+    if 1 == 1 || (i < LIN || true){
+        x = 10
+    } else {
+        x = 20
+    }
+
+IF_ANDAND_R:
+    if  1 == 1||(i < LIN && true) {
+        x = 10
+    } else {
+        x = 20
+    }
+
+IF_ORANDOR:
+    if (i < LIN || true) && (1 == 1 || 2==2) {
+        x = 10
+    } else {
+        x = 20
+    }
+
+
+IF_ANDORAND_0:
+    if (i < LIN || true) || (1 == 1 || 2 == 2 ) {
+        x = 10
+    } else {
+        x = 20
+    }
+
+IF_ANDORAND_1:
+    if (i < LIN && true) || (1 == 1 || 2==2) {
+        x = 10
+    } else {
+        x = 20
+    }
+
+IF_ANDORAND_2:
+    if (i < LIN || true) || (1 == 1 && 2 == 2 ) {
+        x = 10
+    } else {
+        x = 20
+    }
+
+IF_ANDORAND_10:
+    if (i < LIN && true) || 2==2 {
+        x = 10
+    } else {
+        x = 20
+    }
+IF_ANDORAND_11:
+    if 2==2 || (i < LIN && true) {
+        x = 10
+    } else {
+        x = 20
+    }
+    return x
+*/
+

+ 42 - 0
src/samples/program_mult.go

@@ -0,0 +1,42 @@
+@target mips, mipt2
+
+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 = aux + (matrizA[i][k] * matrizB[k][j])
+            }
+            matrizR[i][j] = aux
+            aux = 0
+        }
+    }
+}
+
+func main() {
+    preenche()
+    multiplica()
+}

+ 10 - 2
src/target/mips/Gen.java

@@ -134,16 +134,22 @@ public class Gen extends API.Gen {
     public void TranslateCopy(Instruction inst) throws Exception {
 
         //Se o valor deve ser armazenado em memoria
+        String regDst = inst.G("reg.dst");
+
         if (inst.eq("reg.dst.store", "true")) {
+
+//            System.out.println("::" + inst);
+            inst.S("reg.p1", regDst);
             String dst = inst.G("dst");
             LoadParam(inst, "p1");
-            StoreWord(inst.G("reg.p1"),
+//            StoreWord(inst.G("reg.p1"),
+            StoreWord(regDst,
                     GlobalOrFrameRegister(dst),
                     getTarget().Block().Data().Offset(dst))
                     .S("tac.position", inst.G("block.position"))
                     .S("comment", "store content of " + inst.G("reg.p1") + " in " + dst);
         } else {
-            Copy(inst, inst.G("reg.dst"))
+            Copy(inst, regDst)
                     .S("tac.position", inst.G("block.position"))
                     .S("comment", "copy " + inst.G("dst") + " ← " + inst.G("p1"));
         }
@@ -209,6 +215,7 @@ public class Gen extends API.Gen {
         }
 
         // Gravar na memoria?
+//        System.out.println("ASSIGN:" + inst);
         StoreResult(inst, rd, dst);
     }
 
@@ -307,6 +314,7 @@ public class Gen extends API.Gen {
             LoadParam(inst, "p1");
             c = CopyReg(inst.G("reg.p1"), rt);
         }
+//        System.out.println("COPY::" + c);
         return c.S("tac.position", inst.G("block.position"));
     }
 

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

@@ -8,7 +8,6 @@ package target.mips;
 import API.Instruction;
 import java.util.HashMap;
 import java.util.LinkedHashMap;
-import java.util.Map;
 
 /**
  *
@@ -21,7 +20,7 @@ public class Mips {
 
         }
     };
-    public static Map<String, Instruction> instOperators = new HashMap<String, Instruction>() {
+    public static LinkedHashMap<String, Instruction> instOperators = new LinkedHashMap<String, Instruction>() {
         {
             put("+", new Instruction()
                     //        .S("std", "add");
@@ -124,7 +123,7 @@ public class Mips {
             );
         }
     };
-    public static HashMap<String, String> registers = new HashMap<String, String>() {
+    public static LinkedHashMap<String, String> registers = new LinkedHashMap<String, String>() {
         {
             put("zero", "0");
             put("at", "1");
@@ -536,4 +535,5 @@ public class Mips {
     public static String Register(String reg) {
         return registers.get(reg);
     }
+
 }

+ 7 - 4
src/target/mips/TListenerMips.java

@@ -127,9 +127,8 @@ class TListenerMips extends template.TListener {
             return "error!";
         }
     }
-    
-//    100111101111011111111111111000 == addiu sp,sp,-8
 
+//    100111101111011111111111111000 == addiu sp,sp,-8
     protected String INSTDEC(ArrayList<String> arguments) {
         try {
             String bin = INSTBIN(arguments);
@@ -149,7 +148,7 @@ class TListenerMips extends template.TListener {
             }
             return "error!";
         }
-        
+
     }
 
     protected String INSTBIN(ArrayList<String> arguments) {
@@ -164,7 +163,11 @@ class TListenerMips extends template.TListener {
 //                System.out.println("instbin:" + ctx);
                 break;
             case "J": // (j | jal) Salta para o endereco de destino
-                ctx.Set("target", BIN(gctx.G(ctx.G("label")), 26));
+//                System.out.println("JUMP:" + gctx.G(ctx.G("label")) + ":"
+//                        + (Long.parseLong(gctx.G(ctx.G("label")), 10) >> 2));
+
+                long shift = (Long.parseLong(gctx.G(ctx.G("label")), 10) >> 2);
+                ctx.Set("target", BIN("" + shift, 26));
                 break;
             case "I": // (bne...) Salta para posicao em relacao ao pc atual
 

+ 13 - 2
src/tools/mips/Memory.java

@@ -51,6 +51,12 @@ public class Memory {
         }
     }
 
+    public void Reset() {
+        for (long i = 0; i < size; i += 4) {
+            data.put(i, (long) 0);
+        }
+    }
+
     @Override
     public String toString() {
         String out = "";
@@ -72,15 +78,20 @@ public class Memory {
         while (sc.hasNextLine()) {
 //            content += sc.nextLine() + "\n";
             value = sc.nextLine();
-            parts = value.replaceAll("\\s+", "").split(":");
+            if (value.equals("")) {
+                continue;
+            }
 
+            parts = value.replaceAll("\\s+", "").split(":");
+//            System.out.println("parts:" + new ArrayList<String>(Arrays.asList(parts)));
             if (parts.length == 1) {
                 addr += 4;
             } else {
-                addr = Long.parseLong(parts[0], 16);
+                addr = Long.parseLong(parts[0], 10);
                 value = parts[1];
             }
 
+//            System.out.println("Read:" + (long) addr + ":" + Long.parseLong(value, 10));
             data.put((long) addr, Long.parseLong(value, 10));
         }
 //        System.out.println("ReadFiel:" + content);

+ 48 - 13
src/tools/mips/MipsProcessor.java

@@ -28,25 +28,45 @@ public class MipsProcessor {
     public long PC = 0;
     public RegisterBank RBank;
     public HashMap<String, Instruction> instructions;
+    public boolean stepByStep = false;
+    public boolean debugmode = true;
+    public HashMap<String, Boolean> breakPoint = new HashMap<>();
 
     public MipsProcessor(MipsSettings settings) throws IOException {
         this.settings = settings;
-
-        MI = new Memory(settings.Get("mi"), 4096, false);
-        MD = new Memory(settings.Get("md"), 4096, true);
-        MD.AllAddress = true;
-
+        int size = (16 * 1024); //16KB
+        MI = new Memory(settings.Get("mi"), size, false);
+        MD = new Memory(settings.Get("md"), size, true);
+        // Limpa todos os dados armazenados 
+        MD.Reset();
         RBank = new RegisterBank(32);
 
         InitInstructions();
+
+//        SetBreak("44,48,58,5c");
 //        InitInstructions2();
     }
 
+    public MipsProcessor SetBreak(String address) {
+        for (String addr : address.split(",")) {
+            if (!addr.equals("")) {
+                breakPoint.put(addr, true);
+            }
+        }
+        return this;
+    }
+
     public MipsProcessor Persist() {
         MD.Save();
         return this;
     }
 
+    protected void Log(String msg) {
+        if (debugmode) {
+            System.out.println(msg);
+        }
+    }
+
     public MipsProcessor Run() {
         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
         // Fetch
@@ -55,6 +75,7 @@ public class MipsProcessor {
         try {
             Instruction instruction;
             int i = 0;
+            String cAddress;
             while (true) {
                 long inst = MI.R(PC);
                 instruction = Decode(inst);
@@ -62,17 +83,20 @@ public class MipsProcessor {
                 if (instruction.eq("inst", "stop")) {
                     break;
                 }
+                cAddress = Integer.toHexString((int) PC);
 
-                System.out.println("Interation(" + (i++) + ")["
-                        + Integer.toHexString((int) PC) + "]"
+                Log("Interation(" + (i++) + ")["
+                        + cAddress + "]"
                         + instruction.G("inst"));
 
                 Execute(instruction);
 
-                System.out.println("Registradores(\n" + RBank
+                Log("Registradores(\n" + RBank
                         + ")\b nextPC:" + Integer.toHexString((int) PC));
 
-                br.readLine();
+                if (stepByStep || breakPoint.containsKey(cAddress)) {
+                    br.readLine();
+                }
                 // Decode
                 // Exec
                 // Persist
@@ -216,7 +240,13 @@ public class MipsProcessor {
                 }
         }
 
-        System.out.println(inst.G("inst") + " [rd:" + rd + "] [rs:" + rs + "] [rt:" + rt + "] [shamt:" + shamt + "] [imm:" + imm + "]");
+        Log(inst.G("inst")
+                + " [rd:" + RBank.names.get((int) rd)
+                + "] [rs:" + RBank.names.get((int) rs)
+                + "] [rt:" + RBank.names.get((int) rt)
+                + "] [shamt:" + shamt
+                + "] [imm:" + imm + "]");
+
         switch (inst.G("inst")) {
             // R
             case "add":
@@ -257,7 +287,11 @@ public class MipsProcessor {
             case "mult":
             case "multu":
                 // verificar a questao do hi e lo
-                RBank.W(RBank.R(RBank.REG_LO), RBank.R(rs) * RBank.R(rt));
+
+//                System.out.println("Mult:"
+//                        + rs + "(" + RBank.names.get((int) rs) + "):"
+//                        + rt + "(" + RBank.names.get((int) rt) + ")");
+                RBank.W(RBank.REG_LO, RBank.R(rs) * RBank.R(rt));
                 break;
 //            case "nor":
 //                RBank.W(rd, rs * rt);
@@ -292,7 +326,7 @@ public class MipsProcessor {
                 }
                 break;
             case "bgez":
-                if (RBank.R(rs) >= RBank.R(rt)) {
+                if (RBank.R(rs) >= 0) {
                     PC += imm << 2;
                     return;
                 }
@@ -311,6 +345,7 @@ public class MipsProcessor {
                 }
                 break;
             case "bltz":
+                System.out.println("BLTZ:" + rs);
                 if (RBank.R(rs) < 0) {
                     PC += imm << 2;
                     return;
@@ -351,7 +386,7 @@ public class MipsProcessor {
             case "jal":
                 RBank.W(31, PC);
             case "j":
-                PC = imm;
+                PC = imm << 2;
                 return;
             default:
                 throw new Exception("Instrução " + inst.G("inst") + " não definida!");

+ 14 - 3
src/tools/mips/RegisterBank.java

@@ -5,6 +5,9 @@
  */
 package tools.mips;
 
+import java.util.ArrayList;
+import java.util.Map;
+
 /**
  *
  * @author EUGENIO CARVALHO
@@ -16,11 +19,19 @@ class RegisterBank {
     public final long REG_HI;
     public final long REG_LO;
     public long last;
+    public ArrayList<String> names = new ArrayList<String>();
 
     public RegisterBank(long i) {
+
         registers = new long[(int) i + 2];
-        REG_HI = i + 1;
-        REG_LO = i + 2;
+        REG_HI = i;
+        REG_LO = i + 1;
+
+        for (Map.Entry<String, String> en : target.mips.Mips.registers.entrySet()) {
+            names.add(en.getKey());
+        }
+        names.add("hi");
+        names.add("lo");
     }
 
     public long R(Integer i) {
@@ -49,7 +60,7 @@ class RegisterBank {
                 t = "   ";
             }
             out = out.concat(t)
-                    .concat(i + ":" + registers[i])
+                    .concat(names.get(i) + "\t:" + registers[i])
                     .concat(",\n");
         }
 

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


+ 142 - 84
src/tools/mips/memory/mi.memory

@@ -1,132 +1,190 @@
-0666763252
+0666763256
 0001962017
 0605028352
 0605093889
-2412380168
-0036311075
-0071303171
+0604635137
+0302645253
+0604700675
+0302710787
+0604766213
+0369885187
 0605028362
-0134217768
+0134217745
+0604897282
+0370016259
 0605028372
-0036311075
-0071303172
-0604831745
-0604897281
-0363724803
+0134217745
+0605028382
+0604504065
+0604569603
+0285802501
+0604635138
+0604700676
+0021696547
+0071303171
 0605028362
-0134217800
+0134217760
+0604831746
+0604897282
+0363724803
 0605028372
-0036311075
-0071303174
-0604504065
+0134217760
+0605028382
 0604569601
-0352911363
+0371785734
+0604504065
+0604700673
+0353042435
 0605028362
-0134217832
+0134217772
+0604766210
+0371982339
 0605028372
-0036311075
-0071303177
-0604897281
-0604831745
-0298647558
-0036311075
+0134217772
+0605028382
+0604962818
+0036638755
+0071303171
+0605028362
+0134217778
+0605028372
+0604700674
+0036376611
 0071303172
+0604504065
+0604635137
+0352976899
+0605028362
+0134217787
+0605028372
+0604831746
+0036507683
+0071303174
 0604962817
 0605552641
 0368574467
 0605028362
-0134217884
+0134217796
 0605028372
+0604635138
 0036311075
-0071303179
-0604700673
+0071303178
+0604504065
 0604766209
-0359399432
-0036311075
-0071303174
+0285999111
+0604897282
+0036573219
+0071303172
 0604831745
+0605552641
+0364380163
+0605028362
+0134217811
+0605028372
+0604700674
+0036376611
+0071303180
+0604635137
+0604766209
+0357302281
+0604504066
+0036180003
+0071303174
 0604897281
-0363724803
+0605552641
+0366477315
 0605028362
-0134217936
+0134217826
 0605028372
-0036311075
+0604569602
+0036245539
 0071303172
-0604569601
-0604504065
-0287834118
+0604700673
+0604766209
+0292290567
+0604635138
 0036311075
 0071303174
-0604766209
-0604700673
-0361431043
+0604504065
+0605552641
+0353894403
 0605028362
-0134217988
+0134217841
 0605028372
-0036311075
+0604962818
+0036638755
 0071303172
-0605552641
-0604962817
-0386859016
-0036311075
-0071303172
-0604504065
 0604569601
-0352911363
+0604766209
+0355205129
+0604700674
+0036376611
+0071303172
+0604635137
+0605552641
+0358088707
 0605028362
-0134218040
+0134217856
 0605028372
-0036311075
-0071303179
-0604897281
-0604831745
-0365756424
-0036311075
-0071303172
+0604831746
+0036507683
+0071303180
 0604962817
+0604766209
+0367788041
+0604569602
+0036245539
+0071303172
+0604700673
 0605552641
-0368574467
+0360185859
 0605028362
-0134218092
+0134217871
 0605028372
-0036311075
+0604897282
+0036573219
 0071303172
-0604700673
+0604831745
 0604766209
-0359399432
-0036311075
+0363593737
+0604962818
+0036638755
 0071303174
-0604831745
-0604897281
-0363724803
+0604569601
+0605552641
+0355991555
 0605028362
-0134218144
+0134217886
 0605028372
-0036311075
-0071303172
-0604569601
-0604504065
-0287834118
-0036311075
+0604504066
+0036180003
 0071303172
+0604897281
 0604766209
-0604700673
-0361431043
+0298582023
+0604831746
+0036507683
+0071303172
+0604962817
+0605552641
+0368574467
 0605028362
-0134218196
+0134217901
 0605028372
+0604635138
 0036311075
-0071303177
-0605552641
-0604962817
-0319750150
-0036311075
-0071303174
+0071303178
 0604504065
-0604569601
-0352911363
+0604766209
+0285999111
+0604897282
+0036573219
+0071303174
+0604831745
+0605552641
+0364380163
 0605028362
-0134218252
-0604766228
-2949382144
+0134217917
+0605028372
+2949644288
 4294967295

+ 92 - 31
src/tools/mips/memory/mips.code

@@ -1,32 +1,93 @@
-  00000000 <main>:
- 0:  0666763256	addiu sp,sp,-8	--p| push stack frame
+ 00000000 <main>:
+ 0:  0666697728	addiu sp,sp,-0	--p| push stack frame
  4:  0001962017	addu fp,zero,sp	--p|copy fp ← sp
- 8:  0605028353	addiu s0,zero,1	.0.--copy _V1 ← 1
- c:  0605093889	addiu s1,zero,1	.1.--copy _V2 ← 1
-10:  0001056801	addu a0,zero,s0	.2.--push param
-14:  0001124385	addu a1,zero,s1	.3.--push param
-18:  0201326624	jal 20 <main.atualiza+0x0>	.4.--jump to <main.atualiza>
-1c:  4294967295	stop 	--end of programa
-  00000020 <main.atualiza>:
-20:  0666763256	addiu sp,sp,-8	--p| push stack frame
-24:  0001962017	addu fp,zero,sp	--p|copy fp ← sp
-28:  2948857856	sw a0,fp,0	.0.--pop param
-2c:  2412249088	lw t0,fp,0	
-30:  2948923396	sw a1,fp,4	.1.--pop param
-34:  2412314628	lw t1,fp,4	
-38:  0604635137	addiu t2,zero,1	.2.
-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:  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
+ 8:  0201326597	jal 14 <main.preenche+0x0>	.0.--jump to <main.preenche>
+ c:  0201326630	jal 98 <main.multiplica+0x0>	.1.--jump to <main.multiplica>
+10:  4294967295	stop 	--end of programa
+  00000014 <main.preenche>:
+14:  0666763252	addiu sp,sp,-12	--p| push stack frame
+18:  0001962017	addu fp,zero,sp	--p|copy fp ← sp
+1c:  0605028353	addiu s0,zero,1	.0.--copy _V1 ← 1
+20:  0605093888	addiu s1,zero,0	.1.--copy _V2 ← 0
+24:  0134217761	j 84 <main.preenche+0x70>	.2.
+28:  0605159424	addiu s2,zero,0	.3.--copy _V3 ← 0
+2c:  0134217757	j 74 <main.preenche+0x60>	.4.
+30:  0001136673	addu t3,zero,s1	.5.--copy _T4 ← _V2
+34:  0000745536	sll t4,t3,1	.6.
+38:  0001206305	addu t5,zero,s2	.7.--copy _T7 ← _V3
+3c:  0026042401	addu t4,t4,t5	.8.
+40:  0000815232	sll t6,t4,2	.9.
+44:  0059666465	addu t6,gp,t6	.10.
+48:  2916089856	sw s0,t6,0	.10.--store in loaded address
+4c:  0001144865	addu t7,zero,s1	.11.--copy _T14 ← _V2
+50:  0001032256	sll t8,t7,1	.12.
+54:  0001196065	addu t0,zero,s2	.13.--copy _T17 ← _V3
+58:  0050905121	addu t8,t8,t0	.14.
+5c:  0001591424	sll t1,t8,2	.15.
+60:  0059328545	addu t1,gp,t1	.16.
+64:  2905604112	sw s0,t1,16	.16.--store in loaded address
+68:  0638582785	addiu s0,s0,1	.17.
+6c:  2949644288	sw s0,fp,0	.17.
+70:  0642908161	addiu s2,s2,1	.18.
+74:  0604831746	addiu t5,zero,2	.19.
+78:  0038604835	subu v0,s2,t5	.19.
+7c:  0071368685	bltz v0,30 <main.preenche+0x1c>	.19.--branch if register < 0
+80:  0640745473	addiu s1,s1,1	.20.
+84:  0604897282	addiu t6,zero,2	.21.
+88:  0036573219	subu v0,s1,t6	.21.
+8c:  0071368679	bltz v0,28 <main.preenche+0x14>	.21.--branch if register < 0
+90:  0666697740	addiu sp,sp,12	--e|pop stack frame
+94:  0065011720	jr ra	--e|return
+  00000098 <main.multiplica>:
+98:  0666763248	addiu sp,sp,-16	--p| push stack frame
+9c:  0001962017	addu fp,zero,sp	--p|copy fp ← sp
+a0:  0605028352	addiu s0,zero,0	.0.--copy _V26 ← 0
+a4:  0605093888	addiu s1,zero,0	.1.--copy _V27 ← 0
+a8:  0134217813	j 154 <main.multiplica+0xbc>	.2.
+ac:  0605159424	addiu s2,zero,0	.3.--copy _V28 ← 0
+b0:  0134217809	j 144 <main.multiplica+0xac>	.4.
+b4:  0605224960	addiu s3,zero,0	.5.--copy _V29 ← 0
+b8:  0134217796	j 110 <main.multiplica+0x78>	.6.
+bc:  0001138721	addu t4,zero,s1	.7.--copy _T30 ← _V27
+c0:  0000813120	sll t5,t4,1	.8.
+c4:  0001273889	addu t6,zero,s3	.9.--copy _T33 ← _V29
+c8:  0028207137	addu t5,t5,t6	.10.
+cc:  0000882816	sll t7,t5,2	.11.
+d0:  0059734049	addu t7,gp,t7	.12.
+d4:  2381578240	lw s4,t7,0	.12.
+d8:  0001359905	addu t8,zero,s4	.12.--copy t8 ← s4
+dc:  0001261601	addu t0,zero,s3	.13.--copy _T40 ← _V29
+e0:  0000542784	sll t1,t0,1	.14.
+e4:  0001200161	addu t2,zero,s2	.15.--copy _T43 ← _V28
+e8:  0019548193	addu t1,t1,t2	.16.
+ec:  0000612480	sll t3,t1,2	.17.
+f0:  0059463713	addu t3,gp,t3	.18.
+f4:  2373255184	lw s5,t3,16	.18.
+f8:  0001400865	addu t4,zero,s5	.18.--copy t4 ← s5
+fc:  0051146776	mult t8,t4	.19.
+100:  0000028690	mflo t6	.19.
+104:  0034498593	addu t5,s0,t6	.20.
+108:  0000884769	addu s0,zero,t5	.21.--copy _V26 ← _T51
+10c:  0645070849	addiu s3,s3,1	.22.
+110:  0604504066	addiu t0,zero,2	.23.
+114:  0040374307	subu v0,s3,t0	.23.
+118:  0071368681	bltz v0,bc <main.multiplica+0x24>	.23.--branch if register < 0
+11c:  0001134625	addu t2,zero,s1	.24.--copy _T53 ← _V27
+120:  0000673856	sll t1,t2,1	.25.
+124:  0001202209	addu t3,zero,s2	.26.--copy _T56 ← _V28
+128:  0019613729	addu t1,t1,t3	.27.
+12c:  0000639104	sll t8,t1,2	.28.
+130:  0060342305	addu t8,gp,t8	.29.
+134:  2937061408	sw s0,t8,32	.29.--store in loaded address
+138:  0605028352	addiu s0,zero,0	.30.
+13c:  2949644288	sw s0,fp,0	.30.--store content of s0 in _V26
+140:  0642908161	addiu s2,s2,1	.31.
+144:  0604831746	addiu t5,zero,2	.32.
+148:  0038604835	subu v0,s2,t5	.32.
+14c:  0071368666	bltz v0,b4 <main.multiplica+0x1c>	.32.--branch if register < 0
+150:  0640745473	addiu s1,s1,1	.33.
+154:  0604504066	addiu t0,zero,2	.34.
+158:  0036180003	subu v0,s1,t0	.34.
+15c:  0071368660	bltz v0,ac <main.multiplica+0x14>	.34.--branch if register < 0
+160:  0666697744	addiu sp,sp,16	--e|pop stack frame
+164:  0065011720	jr ra	--e|return