Browse Source

fix stack reference

eugeniucarvalho 5 years ago
parent
commit
6a5988e044

BIN
build/classes/IntermediaryCode/BaseTacGen.class


BIN
build/classes/IntermediaryCode/DataFrame.class


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


+ 3 - 1
build/classes/samples/program_mult_manycore.go

@@ -54,12 +54,13 @@ var (
     matrizA [LIN][COL]int
     matrizB [LIN][COL]int
     matrizR [LIN][COL]int
+    variavel1, variavel2 int = 10, 14
+    variavel3 int = 15
 )
 
 func multiplica(initial int) {
     aux   := 0
     limit := initial + NUM_LINHAS_MULT
-
     for i := initial; i < limit; i++ {
         for j := 0; j < COL; j++ {
             for k := 0; k < LIN; k++ {
@@ -69,6 +70,7 @@ func multiplica(initial int) {
             aux = 0
         }
     }
+    variavel1 = 16
 
     x()
 }

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


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


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


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


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


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


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


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


+ 800 - 0
build/classes/tools/mips/memory/md2.memory

@@ -0,0 +1,800 @@
+0:1
+4:2
+8:3
+12:4
+16:5
+20:6
+24:7
+28:8
+32:9
+36:10
+40:11
+44:12
+48:13
+52:14
+56:15
+60:16
+64:17
+68:18
+72:19
+76:20
+80:21
+84:22
+88:23
+92:24
+96:25
+100:26
+104:27
+108:28
+112:29
+116:30
+120:31
+124:32
+128:33
+132:34
+136:35
+140:36
+144:37
+148:38
+152:39
+156:40
+160:41
+164:42
+168:43
+172:44
+176:45
+180:46
+184:47
+188:48
+192:49
+196:50
+200:51
+204:52
+208:53
+212:54
+216:55
+220:56
+224:57
+228:58
+232:59
+236:60
+240:61
+244:62
+248:63
+252:64
+256:65
+260:66
+264:67
+268:68
+272:69
+276:70
+280:71
+284:72
+288:73
+292:74
+296:75
+300:76
+304:77
+308:78
+312:79
+316:80
+320:81
+324:82
+328:83
+332:84
+336:85
+340:86
+344:87
+348:88
+352:89
+356:90
+360:91
+364:92
+368:93
+372:94
+376:95
+380:96
+384:97
+388:98
+392:99
+396:100
+400:101
+404:102
+408:103
+412:104
+416:105
+420:106
+424:107
+428:108
+432:109
+436:110
+440:111
+444:112
+448:113
+452:114
+456:115
+460:116
+464:117
+468:118
+472:119
+476:120
+480:121
+484:122
+488:123
+492:124
+496:125
+500:126
+504:127
+508:128
+512:129
+516:130
+520:131
+524:132
+528:133
+532:134
+536:135
+540:136
+544:137
+548:138
+552:139
+556:140
+560:141
+564:142
+568:143
+572:144
+576:145
+580:146
+584:147
+588:148
+592:149
+596:150
+600:151
+604:152
+608:153
+612:154
+616:155
+620:156
+624:157
+628:158
+632:159
+636:160
+640:161
+644:162
+648:163
+652:164
+656:165
+660:166
+664:167
+668:168
+672:169
+676:170
+680:171
+684:172
+688:173
+692:174
+696:175
+700:176
+704:177
+708:178
+712:179
+716:180
+720:181
+724:182
+728:183
+732:184
+736:185
+740:186
+744:187
+748:188
+752:189
+756:190
+760:191
+764:192
+768:193
+772:194
+776:195
+780:196
+784:197
+788:198
+792:199
+796:200
+800:201
+804:202
+808:203
+812:204
+816:205
+820:206
+824:207
+828:208
+832:209
+836:210
+840:211
+844:212
+848:213
+852:214
+856:215
+860:216
+864:217
+868:218
+872:219
+876:220
+880:221
+884:222
+888:223
+892:224
+896:225
+900:226
+904:227
+908:228
+912:229
+916:230
+920:231
+924:232
+928:233
+932:234
+936:235
+940:236
+944:237
+948:238
+952:239
+956:240
+960:241
+964:242
+968:243
+972:244
+976:245
+980:246
+984:247
+988:248
+992:249
+996:250
+1000:251
+1004:252
+1008:253
+1012:254
+1016:255
+1020:256
+1024:257
+1028:258
+1032:259
+1036:260
+1040:261
+1044:262
+1048:263
+1052:264
+1056:265
+1060:266
+1064:267
+1068:268
+1072:269
+1076:270
+1080:271
+1084:272
+1088:273
+1092:274
+1096:275
+1100:276
+1104:277
+1108:278
+1112:279
+1116:280
+1120:281
+1124:282
+1128:283
+1132:284
+1136:285
+1140:286
+1144:287
+1148:288
+1152:289
+1156:290
+1160:291
+1164:292
+1168:293
+1172:294
+1176:295
+1180:296
+1184:297
+1188:298
+1192:299
+1196:300
+1200:301
+1204:302
+1208:303
+1212:304
+1216:305
+1220:306
+1224:307
+1228:308
+1232:309
+1236:310
+1240:311
+1244:312
+1248:313
+1252:314
+1256:315
+1260:316
+1264:317
+1268:318
+1272:319
+1276:320
+1280:321
+1284:322
+1288:323
+1292:324
+1296:325
+1300:326
+1304:327
+1308:328
+1312:329
+1316:330
+1320:331
+1324:332
+1328:333
+1332:334
+1336:335
+1340:336
+1344:337
+1348:338
+1352:339
+1356:340
+1360:341
+1364:342
+1368:343
+1372:344
+1376:345
+1380:346
+1384:347
+1388:348
+1392:349
+1396:350
+1400:351
+1404:352
+1408:353
+1412:354
+1416:355
+1420:356
+1424:357
+1428:358
+1432:359
+1436:360
+1440:361
+1444:362
+1448:363
+1452:364
+1456:365
+1460:366
+1464:367
+1468:368
+1472:369
+1476:370
+1480:371
+1484:372
+1488:373
+1492:374
+1496:375
+1500:376
+1504:377
+1508:378
+1512:379
+1516:380
+1520:381
+1524:382
+1528:383
+1532:384
+1536:385
+1540:386
+1544:387
+1548:388
+1552:389
+1556:390
+1560:391
+1564:392
+1568:393
+1572:394
+1576:395
+1580:396
+1584:397
+1588:398
+1592:399
+1596:400
+1600:1
+1604:2
+1608:3
+1612:4
+1616:5
+1620:6
+1624:7
+1628:8
+1632:9
+1636:10
+1640:11
+1644:12
+1648:13
+1652:14
+1656:15
+1660:16
+1664:17
+1668:18
+1672:19
+1676:20
+1680:21
+1684:22
+1688:23
+1692:24
+1696:25
+1700:26
+1704:27
+1708:28
+1712:29
+1716:30
+1720:31
+1724:32
+1728:33
+1732:34
+1736:35
+1740:36
+1744:37
+1748:38
+1752:39
+1756:40
+1760:41
+1764:42
+1768:43
+1772:44
+1776:45
+1780:46
+1784:47
+1788:48
+1792:49
+1796:50
+1800:51
+1804:52
+1808:53
+1812:54
+1816:55
+1820:56
+1824:57
+1828:58
+1832:59
+1836:60
+1840:61
+1844:62
+1848:63
+1852:64
+1856:65
+1860:66
+1864:67
+1868:68
+1872:69
+1876:70
+1880:71
+1884:72
+1888:73
+1892:74
+1896:75
+1900:76
+1904:77
+1908:78
+1912:79
+1916:80
+1920:81
+1924:82
+1928:83
+1932:84
+1936:85
+1940:86
+1944:87
+1948:88
+1952:89
+1956:90
+1960:91
+1964:92
+1968:93
+1972:94
+1976:95
+1980:96
+1984:97
+1988:98
+1992:99
+1996:100
+2000:101
+2004:102
+2008:103
+2012:104
+2016:105
+2020:106
+2024:107
+2028:108
+2032:109
+2036:110
+2040:111
+2044:112
+2048:113
+2052:114
+2056:115
+2060:116
+2064:117
+2068:118
+2072:119
+2076:120
+2080:121
+2084:122
+2088:123
+2092:124
+2096:125
+2100:126
+2104:127
+2108:128
+2112:129
+2116:130
+2120:131
+2124:132
+2128:133
+2132:134
+2136:135
+2140:136
+2144:137
+2148:138
+2152:139
+2156:140
+2160:141
+2164:142
+2168:143
+2172:144
+2176:145
+2180:146
+2184:147
+2188:148
+2192:149
+2196:150
+2200:151
+2204:152
+2208:153
+2212:154
+2216:155
+2220:156
+2224:157
+2228:158
+2232:159
+2236:160
+2240:161
+2244:162
+2248:163
+2252:164
+2256:165
+2260:166
+2264:167
+2268:168
+2272:169
+2276:170
+2280:171
+2284:172
+2288:173
+2292:174
+2296:175
+2300:176
+2304:177
+2308:178
+2312:179
+2316:180
+2320:181
+2324:182
+2328:183
+2332:184
+2336:185
+2340:186
+2344:187
+2348:188
+2352:189
+2356:190
+2360:191
+2364:192
+2368:193
+2372:194
+2376:195
+2380:196
+2384:197
+2388:198
+2392:199
+2396:200
+2400:201
+2404:202
+2408:203
+2412:204
+2416:205
+2420:206
+2424:207
+2428:208
+2432:209
+2436:210
+2440:211
+2444:212
+2448:213
+2452:214
+2456:215
+2460:216
+2464:217
+2468:218
+2472:219
+2476:220
+2480:221
+2484:222
+2488:223
+2492:224
+2496:225
+2500:226
+2504:227
+2508:228
+2512:229
+2516:230
+2520:231
+2524:232
+2528:233
+2532:234
+2536:235
+2540:236
+2544:237
+2548:238
+2552:239
+2556:240
+2560:241
+2564:242
+2568:243
+2572:244
+2576:245
+2580:246
+2584:247
+2588:248
+2592:249
+2596:250
+2600:251
+2604:252
+2608:253
+2612:254
+2616:255
+2620:256
+2624:257
+2628:258
+2632:259
+2636:260
+2640:261
+2644:262
+2648:263
+2652:264
+2656:265
+2660:266
+2664:267
+2668:268
+2672:269
+2676:270
+2680:271
+2684:272
+2688:273
+2692:274
+2696:275
+2700:276
+2704:277
+2708:278
+2712:279
+2716:280
+2720:281
+2724:282
+2728:283
+2732:284
+2736:285
+2740:286
+2744:287
+2748:288
+2752:289
+2756:290
+2760:291
+2764:292
+2768:293
+2772:294
+2776:295
+2780:296
+2784:297
+2788:298
+2792:299
+2796:300
+2800:301
+2804:302
+2808:303
+2812:304
+2816:305
+2820:306
+2824:307
+2828:308
+2832:309
+2836:310
+2840:311
+2844:312
+2848:313
+2852:314
+2856:315
+2860:316
+2864:317
+2868:318
+2872:319
+2876:320
+2880:321
+2884:322
+2888:323
+2892:324
+2896:325
+2900:326
+2904:327
+2908:328
+2912:329
+2916:330
+2920:331
+2924:332
+2928:333
+2932:334
+2936:335
+2940:336
+2944:337
+2948:338
+2952:339
+2956:340
+2960:341
+2964:342
+2968:343
+2972:344
+2976:345
+2980:346
+2984:347
+2988:348
+2992:349
+2996:350
+3000:351
+3004:352
+3008:353
+3012:354
+3016:355
+3020:356
+3024:357
+3028:358
+3032:359
+3036:360
+3040:361
+3044:362
+3048:363
+3052:364
+3056:365
+3060:366
+3064:367
+3068:368
+3072:369
+3076:370
+3080:371
+3084:372
+3088:373
+3092:374
+3096:375
+3100:376
+3104:377
+3108:378
+3112:379
+3116:380
+3120:381
+3124:382
+3128:383
+3132:384
+3136:385
+3140:386
+3144:387
+3148:388
+3152:389
+3156:390
+3160:391
+3164:392
+3168:393
+3172:394
+3176:395
+3180:396
+3184:397
+3188:398
+3192:399
+3196:400

+ 74 - 0
build/classes/tools/mips/memory/mi2.memory

@@ -0,0 +1,74 @@
+0604241920
+0666763232
+2948464664
+2948530204
+0001962017
+2948857856
+2412773376
+0605093888
+0638713861
+0001087521
+0134217786
+0605290496
+0134217782
+0605356032
+0134217767
+0001269793
+0000811136
+0000813184
+0026042401
+0001404961
+0026107937
+0000817280
+0059734049
+2381709312
+0001490977
+0001392673
+0000540800
+0000542848
+0017383457
+0001331233
+0017448993
+0000546944
+0059463713
+2373387840
+0001533985
+0051212312
+0000028690
+0036603937
+0649396225
+0604962836
+0045027363
+0071368677
+0001263649
+0000608384
+0000610432
+0019548193
+0001327137
+0019417121
+0000612480
+0059463713
+2909867136
+0605093888
+2949709828
+0647233537
+0604897300
+0042864675
+0071368660
+0645070849
+0041029667
+0071368655
+0605421584
+2945848000
+0201326660
+2948726816
+2411593752
+2411659292
+0666697760
+4294967295
+0666763260
+0001962017
+0605028353
+0001052705
+0666697732
+0065011720

+ 8 - 6
nbproject/private/private.xml

@@ -10,18 +10,18 @@
             </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>91</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>91</line>
+                <line>32</line>
                 <key/>
             </bookmark>
         </file>
@@ -30,7 +30,9 @@
         <group>
             <file>file:/C:/Users/EUGENIO%20CARVALHO/Desktop/projects/Ivannosys/src/target/mips/jun/Gen.java</file>
             <file>file:/C:/Users/EUGENIO%20CARVALHO/Desktop/projects/Ivannosys/src/grammar/IvannosysGrammar.g4</file>
+            <file>file:/C:/Users/EUGENIO%20CARVALHO/Desktop/projects/Ivannosys/src/API/BuildParams.java</file>
             <file>file:/C:/Users/EUGENIO%20CARVALHO/Desktop/projects/Ivannosys/src/samples/program_mult_manycore.go</file>
+            <file>file:/C:/Users/EUGENIO%20CARVALHO/Desktop/projects/Ivannosys/src/API/Utils.java</file>
             <file>file:/C:/Users/EUGENIO%20CARVALHO/Desktop/projects/Ivannosys/src/grammar/visitorAndWalkers/IvannosysListener.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/compiler/IvannosysCompiler.java</file>

+ 16 - 14
src/IntermediaryCode/BaseTacGen.java

@@ -2019,7 +2019,7 @@ public final class BaseTacGen implements TacGenInterface {
      */
     protected void genPopParams(Node func) throws Exception {
         int reg = 0;
-        String destino, atribuido;
+        String destino, atribuido, id;
         /**
          * Se for method declara e atribui o endereco a variavel
          */
@@ -2029,7 +2029,8 @@ public final class BaseTacGen implements TacGenInterface {
 //            destino = clearPointer(atribuido, gerarVariavel(receive.childrens().G(0)));
             destino = gerarVariavel(receive.childrens().get(0));
             // copy_pointer?
-            Copy(Api.clearID(destino), __popParam().G("_return"), false);
+//            Copy(Api.clearID(destino), __popParam().G("_return"), false);
+            __popParam(Api.clearID(destino));
         }
 
         for (Node argument : func.find("arguments").childrens()) {
@@ -2043,13 +2044,15 @@ public final class BaseTacGen implements TacGenInterface {
                 //                System.out.println("PopArg:" + arg);
                 //                destino = clearPointer(atribuido, gerarVariavel(arg));
                 // copy_pointer?
-                Copy(Api.clearID(gerarVariavel(arg)), __popParam().G("_return"), false);
+//                id = Api.clearID(gerarVariavel(arg));
+//                Copy(id, __popParam(id).G("_return"), false);
+                __popParam(Api.clearID(gerarVariavel(arg)));
             }
         }
     }
 
-    protected Instruction __popParam() throws Exception {
-        String varname = gerarVariavel("T");
+    protected Instruction __popParam(String varname) throws Exception {
+//        String varname = gerarVariavel("T");
         Instruction r = new Instruction()
                 .S("type", "pop_param")
                 .S("format", "pop_param")
@@ -2214,7 +2217,8 @@ public final class BaseTacGen implements TacGenInterface {
             varGenMap.put(varname, alias);
 //            vn = var.G("scope");
 
-            int size = Tipos.Size(var.G("type")), b = 1;
+            int size = Tipos.Size(var.G("type")), elementCount = 1;
+            var.set("size", size);
 
 //            System.out.println("gerarVariavelSetVAR:" + var);
             // Se for um array considera os filhos como index
@@ -2226,22 +2230,20 @@ public final class BaseTacGen implements TacGenInterface {
 //                            + "\n" + node
 //                            + "\nVARIABLE:\n" + var
 //                    );
-                    b *= (node.eq("constant", "true")
-                            ? node.getInt("valueConstant")
+                    elementCount *= (node.eq("constant", "true")
+                            ? node.getInt("default.value")
                             : node.getInt("value"));
                 }
             }
-            size *= b;
-
-            var.set("size", size);
+//            size *= elementCount;
 
-//            System.out.println("gerarVariave[" + prefix + "|" + id + "]:" + 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);
+                (prefix.equals("G") ? code.GData() : code.Block().Data())
+                        .Add(alias, var, elementCount);
             } else {
 //                System.out.println("var:" + var);
-                alias = var.G("valueConstant");
+                alias = var.G("default.value");
             }
         }
         return alias;

+ 31 - 5
src/IntermediaryCode/DataFrame.java

@@ -49,24 +49,43 @@ public class DataFrame {
         initialized = init;
     }
 
-    public DataFrame Add(String alias, Node var) throws Exception {
-//        System.out.println("Add data to frame:" + var);
-        int size = var.getInt("size"), vSize = 1;
+    public DataFrame Add(String alias, Node var, int elements) {
+        //        System.out.println("Add data to frame:" + var);
+//        int vSize = 1;
+//        int size = var.getInt("size"), vSize = 1;
 //        boolean isArray = var.eq("array", "true");
 
 //        if (isArray) {
 //            vSize = Tipos.Size(var.G("type"));
 //        }
-        for (int i = 0; i < size; i++) {
+        for (int i = 0; i < elements; i++) {
             values.put(
                     alias + "." + i,
-                    var.copy().S("size", vSize)
+                    var.copy()
             );
+            //                    var.copy().S("size", vSize)
         }
 
         return this;
     }
 
+//    public DataFrame Add(String alias, Node var) throws Exception {
+////        System.out.println("Add data to frame:" + var);
+//        int size = var.getInt("size"), vSize = 1;
+////        boolean isArray = var.eq("array", "true");
+//
+////        if (isArray) {
+////            vSize = Tipos.Size(var.G("type"));
+////        }
+//        for (int i = 0; i < size; i++) {
+//            values.put(
+//                    alias + "." + i,
+//                    var.copy().S("size", vSize)
+//            );
+//        }
+//
+//        return this;
+//    }
     public LinkedHashMap<String, Node> values() {
         return values;
     }
@@ -102,12 +121,18 @@ public class DataFrame {
         Node value;
         for (Map.Entry<String, Node> x : values.entrySet()) {
             value = x.getValue();
+
+//            System.out.println("Value:" + value);
+ 
             s.append(x.getKey())
                     .append(": ")
                     .append(value.G("name"))
                     .append("\tsize:")
                     .append(value.G("size"))
+                    .append("\tvalue:")
+                    .append(value.G("var.value"))
                     .append("\n");
+//            break;
         }
 
         return s.toString();
@@ -200,4 +225,5 @@ public class DataFrame {
 
 //        System.out.println("Replace << " + this.values);
     }
+
 }

+ 8 - 3
src/grammar/visitorAndWalkers/IvannosysListener.java

@@ -303,6 +303,8 @@ public class IvannosysListener extends IvannosysGrammarBaseListener {
                     .S("subclass", "operand");
 
             variable.copy("type,value,pointer,array,array_size", var);
+            
+            variable.S("var.value", varname);
 
             astBaseSet(ctx, variable);
 
@@ -378,7 +380,7 @@ public class IvannosysListener extends IvannosysGrammarBaseListener {
 
         String varID = scopeStack.peek() + "." + id;
         Node var = new Node(varID).S("name", id)
-                .S("valueConstant", value.getText())
+                .S("default.value", value.getText())
                 .S("constant", "true")
                 .S("pointer", "false")
                 .S("array", "false")
@@ -557,7 +559,7 @@ public class IvannosysListener extends IvannosysGrammarBaseListener {
                 Node ref = Variaveis.Get(scopeStack.peek() + "." + val);
                 if (ref != null && ref.eq("constant", "true")) {
 //                    System.out.println("INDEXEDTYPE" + constante);
-                    val = ref.G("valueConstant");
+                    val = ref.G("default.value");
                 }
             }
 
@@ -872,7 +874,10 @@ public class IvannosysListener extends IvannosysGrammarBaseListener {
         astReturnLevel();
         super.exitDef_function(ctx); //To change body of generated methods, choose Tools | Templates.
     }
-
+    /**
+     * Não possui valor padrão. corresponde a variavel da qual é chamado um metodo
+     * @param ctx 
+     */
     @Override
     public void enterReceive_type(IvannosysGrammarParser.Receive_typeContext ctx) {
         astSetCurrentNode("receive.type", ctx);

+ 3 - 1
src/samples/program_mult_manycore.go

@@ -54,12 +54,13 @@ var (
     matrizA [LIN][COL]int
     matrizB [LIN][COL]int
     matrizR [LIN][COL]int
+    variavel1, variavel2 int = 10, 14
+    variavel3 int = 15
 )
 
 func multiplica(initial int) {
     aux   := 0
     limit := initial + NUM_LINHAS_MULT
-
     for i := initial; i < limit; i++ {
         for j := 0; j < COL; j++ {
             for k := 0; k < LIN; k++ {
@@ -69,6 +70,7 @@ func multiplica(initial int) {
             aux = 0
         }
     }
+    variavel1 = 16
 
     x()
 }

+ 17 - 8
src/target/mips/Gen.java

@@ -13,7 +13,6 @@ import IntermediaryCode.DataFrame;
 import IntermediaryCode.OcorrenceFinderProcessor;
 import ast.Node;
 import compiler.IvannosysTargetArch;
-import java.io.IOException;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.LinkedHashMap;
@@ -112,7 +111,7 @@ public class Gen extends API.Gen {
                     SetDataMemoryFile("\\src\\tools\\mips\\memory\\md.memory");
                 }
             }).Run().Persist();
-        } catch (IOException ex) {
+        } catch (Exception ex) {
             Logger.getLogger(Gen.class.getName()).log(Level.SEVERE, null, ex);
         }
 
@@ -382,6 +381,7 @@ public class Gen extends API.Gen {
 //        System.out.println("PopParam:" + inst);
         String p1 = inst.G("p1");
         // O indice é 2 por conta dos dois primeiros registradores {v0, v1}
+//        System.out.println("PopParams:" + inst);
         int offset = getTarget().Block().Data().Offset(p1);
         StoreWord(returnRegisters.remove(2),
                 GlobalOrFrameRegister(p1),
@@ -461,19 +461,28 @@ public class Gen extends API.Gen {
         if (!getTarget().Block().getName().equals("main")) {
             // Restaura o fp
             // Restaura o ra
-            boolean call = getTac().Block().HasCall();
-            int newvars = 0;
-            for (String reg : new String[]{Registers.R_FP, Registers.R_RA}) {
-                if (call) {
-                    data.Add(reg, new Node().S("type", "int").set("size", 1 * WORD_INC));
+//            boolean call = getTac().Block().HasCall();
+
+            if (getTac().Block().HasCall()) {
+                int newvars = 0;
+
+                for (String reg : new String[]{Registers.R_FP, Registers.R_RA}) {
+
+                    data.Add(reg, new Node()
+                            .S("type", "int")
+                            .S("size", 1 * WORD_INC),
+                            1);
                     newvars -= WORD_INC;
+
                     StoreWord(reg, Registers.R_SP, data.Offset(reg))
                             .S("comment", "p| backup " + reg);
                 }
+
+                alloc.somar("offset", newvars);
             }
-            alloc.somar("offset", newvars);
 //            System.out.println("PROLOG:(" + newvars + ")" + alloc);
         }
+//        System.out.println("Activation Registry:()\n" + data);
 
         // Copia o sp para o fp
         CopyReg(Registers.R_SP, Registers.R_FP).Prepend("comment", "p|");

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

@@ -42,6 +42,7 @@ public class Gen extends target.mips.Gen {
         try {
             Code Target = getTarget(), newCode;
             System.out.println("Export do juninho");
+//            System.out.println("Data:" + Target.GData());
 
             Long stackBaseAddress = 0L,
                     updateBaseAddress = 0L,
@@ -96,6 +97,7 @@ public class Gen extends target.mips.Gen {
                             true);
                     // Atualiza os enderecos de salto do codigo
                     uap.Exec(newCode, null);
+
                     format = (String) profile.get("filename");
 
                     if (format == null) {
@@ -106,7 +108,10 @@ public class Gen extends target.mips.Gen {
                     SaveMips(newCode, base + "\\" + String.format(format, "mips"));
                     SaveDec(newCode, base + "\\" + String.format(format, "dec"));
                     stackBaseAddress = updateBaseAddress;
-//                    System.out.println("value::" + code);
+
+//                    ExecuteCode(newCode);
+//                    break;
+//                  System.out.println("value::" + code);
                 }
                 //  System.out.println("params:" + getTac().ast.getCompileParams().GetLists());
                 //  System.out.println("params:" + p);
@@ -121,6 +126,48 @@ public class Gen extends target.mips.Gen {
 //        return super.Export(); //To change body of generated methods, choose Tools | Templates.
     }
 
+//    protected void ExecuteCode(Code c) {
+//        try {
+//            String out = "", tmp;
+//            for (Map.Entry<String, Block> x : c.stmts.entrySet()) {
+////                System.out.println(x.getValue().Data());
+//                for (Instruction instr : x.getValue().Instructions()) {
+//                    tmp = instr.G("inst.dec");
+//                    if (tmp.equals("")) {
+//                        continue;
+//                    }
+//                    out = out.concat(tmp + "\n");
+//                }
+//            }
+//
+//            Utils.WriteFile("\\src\\tools\\mips\\memory\\mi2.memory", out);
+//
+//            out = "";
+//            for (int i = 0, y = 0; i < 2; i++) {
+//                for (int j = 1; j <= 400; j++, y += 4) {
+//                    out = out.concat(y + ":" + j + "\n");
+//                }
+//            }
+//
+//            Utils.WriteFile("\\src\\tools\\mips\\memory\\md2.memory", out);
+//
+//            MipsProcessor sim = new tools.mips.MipsProcessor(new tools.mips.MipsSettings() {
+//                {
+//                    debugmode = true;
+////                    stepByStep = true;
+//                    SetInstructionMemoryFile("\\src\\tools\\mips\\memory\\mi2.memory");
+//                    SetDataMemoryFile("\\src\\tools\\mips\\memory\\md2.memory");
+//                }
+//            });
+//
+//            sim.SetBreak("5c,84,c8")
+//                    .Run()
+//                    .Persist();
+//
+//        } catch (Exception ex) {
+//            Logger.getLogger(target.mips.Gen.class.getName()).log(Level.SEVERE, null, ex);
+//        }
+//    }
     protected Long fixCacheBlockSize(Long size, Long sizeOfBlock) {
         Long t = sizeOfBlock;
         while (true) {

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

@@ -92,7 +92,9 @@ public class Memory {
             }
 
 //            System.out.println("Read:" + (long) addr + ":" + Long.parseLong(value, 10));
+
             data.put((long) addr, Long.parseLong(value, 10));
+//            System.out.println("ReadFile:" + data.get(0));
         }
 //        System.out.println("ReadFiel:" + content);
     }

+ 5 - 4
src/tools/mips/MipsProcessor.java

@@ -8,7 +8,6 @@ package tools.mips;
 import API.Instruction;
 import API.Utils;
 import java.io.BufferedReader;
-import java.io.IOException;
 import java.io.InputStreamReader;
 import java.util.HashMap;
 import java.util.Map;
@@ -31,13 +30,15 @@ public class MipsProcessor {
 
     public HashMap<String, Boolean> breakPoint = new HashMap<>();
 
-    public MipsProcessor(MipsSettings settings) throws IOException {
+    public MipsProcessor(MipsSettings settings) throws Exception {
         this.settings = settings;
         int size = (16 * 1024); //16KB
         MI = new Memory(settings.Get("mi"), size, false);
         MD = new Memory(settings.Get("md"), size, true);
+//        System.out.println("MD:" + MD);
         // Limpa todos os dados armazenados 
-        MD.Reset();
+//        MD.Reset();
+//        System.out.println("Init Md:" + MD.R(0L));
         RBank = new RegisterBank(32);
 
         InitInstructions();
@@ -369,8 +370,8 @@ public class MipsProcessor {
                 RBank.W(rt, imm);
                 break;
             case "lw":
-                Log(String.format("Load endereco '%d'\n", RBank.R(rs) + imm));
                 RBank.W(rt, MD.R(RBank.R(rs) + imm));
+                Log(String.format("Load endereco '%d' <- '%d'\n", RBank.R(rs) + imm, MD.R(RBank.R(rs) + imm)));
                 break;
 //            case "ori":
 //                break;

+ 800 - 0
src/tools/mips/memory/md2.memory

@@ -0,0 +1,800 @@
+0:1
+4:2
+8:3
+12:4
+16:5
+20:6
+24:7
+28:8
+32:9
+36:10
+40:11
+44:12
+48:13
+52:14
+56:15
+60:16
+64:17
+68:18
+72:19
+76:20
+80:21
+84:22
+88:23
+92:24
+96:25
+100:26
+104:27
+108:28
+112:29
+116:30
+120:31
+124:32
+128:33
+132:34
+136:35
+140:36
+144:37
+148:38
+152:39
+156:40
+160:41
+164:42
+168:43
+172:44
+176:45
+180:46
+184:47
+188:48
+192:49
+196:50
+200:51
+204:52
+208:53
+212:54
+216:55
+220:56
+224:57
+228:58
+232:59
+236:60
+240:61
+244:62
+248:63
+252:64
+256:65
+260:66
+264:67
+268:68
+272:69
+276:70
+280:71
+284:72
+288:73
+292:74
+296:75
+300:76
+304:77
+308:78
+312:79
+316:80
+320:81
+324:82
+328:83
+332:84
+336:85
+340:86
+344:87
+348:88
+352:89
+356:90
+360:91
+364:92
+368:93
+372:94
+376:95
+380:96
+384:97
+388:98
+392:99
+396:100
+400:101
+404:102
+408:103
+412:104
+416:105
+420:106
+424:107
+428:108
+432:109
+436:110
+440:111
+444:112
+448:113
+452:114
+456:115
+460:116
+464:117
+468:118
+472:119
+476:120
+480:121
+484:122
+488:123
+492:124
+496:125
+500:126
+504:127
+508:128
+512:129
+516:130
+520:131
+524:132
+528:133
+532:134
+536:135
+540:136
+544:137
+548:138
+552:139
+556:140
+560:141
+564:142
+568:143
+572:144
+576:145
+580:146
+584:147
+588:148
+592:149
+596:150
+600:151
+604:152
+608:153
+612:154
+616:155
+620:156
+624:157
+628:158
+632:159
+636:160
+640:161
+644:162
+648:163
+652:164
+656:165
+660:166
+664:167
+668:168
+672:169
+676:170
+680:171
+684:172
+688:173
+692:174
+696:175
+700:176
+704:177
+708:178
+712:179
+716:180
+720:181
+724:182
+728:183
+732:184
+736:185
+740:186
+744:187
+748:188
+752:189
+756:190
+760:191
+764:192
+768:193
+772:194
+776:195
+780:196
+784:197
+788:198
+792:199
+796:200
+800:201
+804:202
+808:203
+812:204
+816:205
+820:206
+824:207
+828:208
+832:209
+836:210
+840:211
+844:212
+848:213
+852:214
+856:215
+860:216
+864:217
+868:218
+872:219
+876:220
+880:221
+884:222
+888:223
+892:224
+896:225
+900:226
+904:227
+908:228
+912:229
+916:230
+920:231
+924:232
+928:233
+932:234
+936:235
+940:236
+944:237
+948:238
+952:239
+956:240
+960:241
+964:242
+968:243
+972:244
+976:245
+980:246
+984:247
+988:248
+992:249
+996:250
+1000:251
+1004:252
+1008:253
+1012:254
+1016:255
+1020:256
+1024:257
+1028:258
+1032:259
+1036:260
+1040:261
+1044:262
+1048:263
+1052:264
+1056:265
+1060:266
+1064:267
+1068:268
+1072:269
+1076:270
+1080:271
+1084:272
+1088:273
+1092:274
+1096:275
+1100:276
+1104:277
+1108:278
+1112:279
+1116:280
+1120:281
+1124:282
+1128:283
+1132:284
+1136:285
+1140:286
+1144:287
+1148:288
+1152:289
+1156:290
+1160:291
+1164:292
+1168:293
+1172:294
+1176:295
+1180:296
+1184:297
+1188:298
+1192:299
+1196:300
+1200:301
+1204:302
+1208:303
+1212:304
+1216:305
+1220:306
+1224:307
+1228:308
+1232:309
+1236:310
+1240:311
+1244:312
+1248:313
+1252:314
+1256:315
+1260:316
+1264:317
+1268:318
+1272:319
+1276:320
+1280:321
+1284:322
+1288:323
+1292:324
+1296:325
+1300:326
+1304:327
+1308:328
+1312:329
+1316:330
+1320:331
+1324:332
+1328:333
+1332:334
+1336:335
+1340:336
+1344:337
+1348:338
+1352:339
+1356:340
+1360:341
+1364:342
+1368:343
+1372:344
+1376:345
+1380:346
+1384:347
+1388:348
+1392:349
+1396:350
+1400:351
+1404:352
+1408:353
+1412:354
+1416:355
+1420:356
+1424:357
+1428:358
+1432:359
+1436:360
+1440:361
+1444:362
+1448:363
+1452:364
+1456:365
+1460:366
+1464:367
+1468:368
+1472:369
+1476:370
+1480:371
+1484:372
+1488:373
+1492:374
+1496:375
+1500:376
+1504:377
+1508:378
+1512:379
+1516:380
+1520:381
+1524:382
+1528:383
+1532:384
+1536:385
+1540:386
+1544:387
+1548:388
+1552:389
+1556:390
+1560:391
+1564:392
+1568:393
+1572:394
+1576:395
+1580:396
+1584:397
+1588:398
+1592:399
+1596:400
+1600:1
+1604:2
+1608:3
+1612:4
+1616:5
+1620:6
+1624:7
+1628:8
+1632:9
+1636:10
+1640:11
+1644:12
+1648:13
+1652:14
+1656:15
+1660:16
+1664:17
+1668:18
+1672:19
+1676:20
+1680:21
+1684:22
+1688:23
+1692:24
+1696:25
+1700:26
+1704:27
+1708:28
+1712:29
+1716:30
+1720:31
+1724:32
+1728:33
+1732:34
+1736:35
+1740:36
+1744:37
+1748:38
+1752:39
+1756:40
+1760:41
+1764:42
+1768:43
+1772:44
+1776:45
+1780:46
+1784:47
+1788:48
+1792:49
+1796:50
+1800:51
+1804:52
+1808:53
+1812:54
+1816:55
+1820:56
+1824:57
+1828:58
+1832:59
+1836:60
+1840:61
+1844:62
+1848:63
+1852:64
+1856:65
+1860:66
+1864:67
+1868:68
+1872:69
+1876:70
+1880:71
+1884:72
+1888:73
+1892:74
+1896:75
+1900:76
+1904:77
+1908:78
+1912:79
+1916:80
+1920:81
+1924:82
+1928:83
+1932:84
+1936:85
+1940:86
+1944:87
+1948:88
+1952:89
+1956:90
+1960:91
+1964:92
+1968:93
+1972:94
+1976:95
+1980:96
+1984:97
+1988:98
+1992:99
+1996:100
+2000:101
+2004:102
+2008:103
+2012:104
+2016:105
+2020:106
+2024:107
+2028:108
+2032:109
+2036:110
+2040:111
+2044:112
+2048:113
+2052:114
+2056:115
+2060:116
+2064:117
+2068:118
+2072:119
+2076:120
+2080:121
+2084:122
+2088:123
+2092:124
+2096:125
+2100:126
+2104:127
+2108:128
+2112:129
+2116:130
+2120:131
+2124:132
+2128:133
+2132:134
+2136:135
+2140:136
+2144:137
+2148:138
+2152:139
+2156:140
+2160:141
+2164:142
+2168:143
+2172:144
+2176:145
+2180:146
+2184:147
+2188:148
+2192:149
+2196:150
+2200:151
+2204:152
+2208:153
+2212:154
+2216:155
+2220:156
+2224:157
+2228:158
+2232:159
+2236:160
+2240:161
+2244:162
+2248:163
+2252:164
+2256:165
+2260:166
+2264:167
+2268:168
+2272:169
+2276:170
+2280:171
+2284:172
+2288:173
+2292:174
+2296:175
+2300:176
+2304:177
+2308:178
+2312:179
+2316:180
+2320:181
+2324:182
+2328:183
+2332:184
+2336:185
+2340:186
+2344:187
+2348:188
+2352:189
+2356:190
+2360:191
+2364:192
+2368:193
+2372:194
+2376:195
+2380:196
+2384:197
+2388:198
+2392:199
+2396:200
+2400:201
+2404:202
+2408:203
+2412:204
+2416:205
+2420:206
+2424:207
+2428:208
+2432:209
+2436:210
+2440:211
+2444:212
+2448:213
+2452:214
+2456:215
+2460:216
+2464:217
+2468:218
+2472:219
+2476:220
+2480:221
+2484:222
+2488:223
+2492:224
+2496:225
+2500:226
+2504:227
+2508:228
+2512:229
+2516:230
+2520:231
+2524:232
+2528:233
+2532:234
+2536:235
+2540:236
+2544:237
+2548:238
+2552:239
+2556:240
+2560:241
+2564:242
+2568:243
+2572:244
+2576:245
+2580:246
+2584:247
+2588:248
+2592:249
+2596:250
+2600:251
+2604:252
+2608:253
+2612:254
+2616:255
+2620:256
+2624:257
+2628:258
+2632:259
+2636:260
+2640:261
+2644:262
+2648:263
+2652:264
+2656:265
+2660:266
+2664:267
+2668:268
+2672:269
+2676:270
+2680:271
+2684:272
+2688:273
+2692:274
+2696:275
+2700:276
+2704:277
+2708:278
+2712:279
+2716:280
+2720:281
+2724:282
+2728:283
+2732:284
+2736:285
+2740:286
+2744:287
+2748:288
+2752:289
+2756:290
+2760:291
+2764:292
+2768:293
+2772:294
+2776:295
+2780:296
+2784:297
+2788:298
+2792:299
+2796:300
+2800:301
+2804:302
+2808:303
+2812:304
+2816:305
+2820:306
+2824:307
+2828:308
+2832:309
+2836:310
+2840:311
+2844:312
+2848:313
+2852:314
+2856:315
+2860:316
+2864:317
+2868:318
+2872:319
+2876:320
+2880:321
+2884:322
+2888:323
+2892:324
+2896:325
+2900:326
+2904:327
+2908:328
+2912:329
+2916:330
+2920:331
+2924:332
+2928:333
+2932:334
+2936:335
+2940:336
+2944:337
+2948:338
+2952:339
+2956:340
+2960:341
+2964:342
+2968:343
+2972:344
+2976:345
+2980:346
+2984:347
+2988:348
+2992:349
+2996:350
+3000:351
+3004:352
+3008:353
+3012:354
+3016:355
+3020:356
+3024:357
+3028:358
+3032:359
+3036:360
+3040:361
+3044:362
+3048:363
+3052:364
+3056:365
+3060:366
+3064:367
+3068:368
+3072:369
+3076:370
+3080:371
+3084:372
+3088:373
+3092:374
+3096:375
+3100:376
+3104:377
+3108:378
+3112:379
+3116:380
+3120:381
+3124:382
+3128:383
+3132:384
+3136:385
+3140:386
+3144:387
+3148:388
+3152:389
+3156:390
+3160:391
+3164:392
+3168:393
+3172:394
+3176:395
+3180:396
+3184:397
+3188:398
+3192:399
+3196:400

+ 74 - 0
src/tools/mips/memory/mi2.memory

@@ -0,0 +1,74 @@
+0604241920
+0666763232
+2948464664
+2948530204
+0001962017
+2948857856
+2412773376
+0605093888
+0638713861
+0001087521
+0134217786
+0605290496
+0134217782
+0605356032
+0134217767
+0001269793
+0000811136
+0000813184
+0026042401
+0001404961
+0026107937
+0000817280
+0059734049
+2381709312
+0001490977
+0001392673
+0000540800
+0000542848
+0017383457
+0001331233
+0017448993
+0000546944
+0059463713
+2373387840
+0001533985
+0051212312
+0000028690
+0036603937
+0649396225
+0604962836
+0045027363
+0071368677
+0001263649
+0000608384
+0000610432
+0019548193
+0001327137
+0019417121
+0000612480
+0059463713
+2909867136
+0605093888
+2949709828
+0647233537
+0604897300
+0042864675
+0071368660
+0645070849
+0041029667
+0071368655
+0605421584
+2945848000
+0201326660
+2948726816
+2411593752
+2411659292
+0666697760
+4294967295
+0666763260
+0001962017
+0605028353
+0001052705
+0666697732
+0065011720