eugeniucarvalho 6 years ago
parent
commit
b0264f5709

BIN
build/classes/IntermediaryCode/BaseTacGen.class


BIN
build/classes/IntermediaryCode/CodeOtimizadorProcessor.class


BIN
build/classes/compiler/IVANNOSYS.class


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

@@ -49,7 +49,8 @@ func laplaciano() {
     for i:= 1; i < LM1; i++ {
         for j := 1; j < CM1; j++ {
 lab_1:
-            l = origin[i-1][j]
+            l = origin[i-1][j] + origin[i][j-1] + origin[i][j+1] + origin[i+1][j] - (4 * origin[i][j])
+/*
 lab_2:
             l = l + origin[i][j-1]
 lab_3:
@@ -60,6 +61,7 @@ lab_5:
             l = l - (4 * origin[i][j])
 lab_6:
 
+*/
             if l > 255 {
               l = 255
             }

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


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


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


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


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


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

@@ -4,19 +4,19 @@
 0012:	0
 0016:	0
 0020:	0
-0024:	0
-0028:	0
-0032:	0
+0024:	1
+0028:	2
+0032:	3
 0036:	0
 0040:	0
-0044:	0
-0048:	0
-0052:	0
+0044:	4
+0048:	5
+0052:	6
 0056:	0
 0060:	0
-0064:	0
-0068:	0
-0072:	0
+0064:	7
+0068:	8
+0072:	9
 0076:	0
 0080:	0
 0084:	0
@@ -29,19 +29,19 @@
 0112:	0
 0116:	0
 0120:	0
-0124:	0
-0128:	0
-0132:	0
+0124:	2
+0128:	1
+0132:	-4
 0136:	0
 0140:	0
-0144:	0
+0144:	-3
 0148:	0
-0152:	0
+0152:	-7
 0156:	0
 0160:	0
-0164:	0
-0168:	0
-0172:	0
+0164:	-16
+0168:	-11
+0172:	-22
 0176:	0
 0180:	0
 0184:	0
@@ -4088,7 +4088,7 @@
 16348:	0
 16352:	0
 16356:	0
-16360:	0
+16360:	10
 16364:	0
 16368:	0
 16372:	0

+ 124 - 187
build/classes/tools/mips/memory/mi.memory

@@ -1,190 +1,127 @@
-0666763256
+0666697728
 0001962017
-0605028352
-0605093889
-0604635137
-0302645253
-0604700675
-0302710787
-0604766213
-0369885187
-0605028362
-0134217745
-0604897282
-0370016259
-0605028372
-0134217745
-0605028382
-0604504065
-0604569603
-0285802501
-0604635138
-0604700676
-0021696547
-0071303171
-0605028362
-0134217760
-0604831746
-0604897282
-0363724803
-0605028372
-0134217760
-0605028382
-0604569601
-0371785734
-0604504065
-0604700673
-0353042435
-0605028362
-0134217772
-0604766210
-0371982339
-0605028372
-0134217772
-0605028382
-0604962818
-0036638755
-0071303171
-0605028362
-0134217778
-0605028372
-0604700674
-0036376611
-0071303172
-0604504065
-0604635137
-0352976899
-0605028362
-0134217787
-0605028372
-0604831746
-0036507683
-0071303174
-0604962817
-0605552641
-0368574467
-0605028362
-0134217796
-0605028372
-0604635138
-0036311075
-0071303178
-0604504065
-0604766209
-0285999111
-0604897282
-0036573219
-0071303172
-0604831745
-0605552641
-0364380163
-0605028362
-0134217811
-0605028372
-0604700674
-0036376611
-0071303180
-0604635137
-0604766209
-0357302281
-0604504066
-0036180003
-0071303174
-0604897281
-0605552641
-0366477315
-0605028362
-0134217826
-0605028372
-0604569602
-0036245539
-0071303172
-0604700673
-0604766209
-0292290567
-0604635138
-0036311075
-0071303174
-0604504065
-0605552641
-0353894403
-0605028362
-0134217841
-0605028372
-0604962818
-0036638755
-0071303172
-0604569601
-0604766209
-0355205129
-0604700674
-0036376611
-0071303172
-0604635137
-0605552641
-0358088707
-0605028362
-0134217856
-0605028372
-0604831746
-0036507683
-0071303180
-0604962817
-0604766209
-0367788041
-0604569602
-0036245539
-0071303172
-0604700673
-0605552641
-0360185859
-0605028362
-0134217871
-0605028372
-0604897282
-0036573219
-0071303172
+0201326597
+0201326637
+4294967295
+0666763240
+0001962017
+0605028353
+0605093892
+0605159428
+0605224960
+0134217768
+0605290496
+0134217764
+0604831744
+0309133314
+0376504323
+0605356032
+0134217755
+0604962816
+0311361538
+0378667011
+0605356032
+0134217755
+0001091617
+0638582785
+2949644288
+0001263649
+0000610432
+0019548193
+0001333281
+0019613729
+0000614528
+0059531297
+2912223232
+0647233537
+0604897285
+0042864675
+0071368680
+0645070849
+0605552645
+0041422883
+0071368674
+0666697752
+0065011720
+0666763228
+0001962017
+0605028356
+0605093892
+0605159425
+0134217851
+0605224961
+0134217848
 0604831745
-0604766209
-0363593737
-0604962818
-0036638755
-0071303174
-0604569601
-0605552641
-0355991555
-0605028362
-0134217886
-0605028372
-0604504066
-0036180003
-0071303172
-0604897281
-0604766209
-0298582023
-0604831746
-0036507683
-0071303172
-0604962817
-0605552641
-0368574467
-0605028362
-0134217901
-0605028372
-0604635138
-0036311075
-0071303178
-0604504065
-0604766209
-0285999111
-0604897282
-0036573219
-0071303174
+0038625315
+0000815232
+0026107937
+0001275937
+0026173473
+0000835712
+0060342305
+2400452608
+0001327137
+0001198113
+0000610432
+0019548193
 0604831745
-0605552641
-0364380163
-0605028362
-0134217917
-0605028372
-2949644288
-4294967295
+0040720419
+0019613729
+0000618624
+0059666465
+2379546624
+0001407009
+0017784865
+0001228833
+0001593472
+0051036193
+0644677633
+0051232801
+0001591424
+0059328545
+2369126400
+0001470497
+0026099745
+0642711553
+0001005696
+0032208929
+0001271841
+0032340001
+0001032320
+0060342305
+2400649216
+0001525793
+0017391649
+0001208353
+0000938112
+0030044193
+0001267745
+0030109729
+0000944256
+0059598881
+2377383936
+0001341473
+0604504068
+0032030744
+0000049170
+0026781731
+0604569855
+0044634147
+0406847490
+0605356287
+0001202209
+0000749696
+0024008737
+0001271841
+0023943201
+0000751744
+0059734049
+2918514788
+0645070849
+0040964131
+0071368636
+0642908161
+0038801443
+0071368631
+0666697764
+0065011720

+ 3 - 4
src/IntermediaryCode/BaseTacGen.java

@@ -114,8 +114,8 @@ public final class BaseTacGen implements TacGenInterface {
     public void Ast(AbstractSyntaxTree ast) {
         this.ast = ast;
         code = new Code("TAC", ast);
-//        code.AfterClose("clear.1", new CodeClearProcessor());
-//        code.AfterClose("oti.1", new CodeOtimizadorProcessor(enableOtimization));
+        code.AfterClose("clear.1", new CodeClearProcessor());
+        code.AfterClose("oti.1", new CodeOtimizadorProcessor(enableOtimization));
 //        code.AfterClose("oti.1", new CodeOtimizadorProcessor(false));
         compileParams = ast.BuildParams();
 
@@ -371,8 +371,7 @@ public final class BaseTacGen implements TacGenInterface {
 //            path.add(size); 
         }
 
-        System.out.println("Pathj:" + path);
-
+//        System.out.println("Pathj:" + path);
         if (path.size() % 2 == 0 && Math.abs(size - s1) == 0) {
             path.remove(path.size() - 1);
             return;

+ 13 - 5
src/IntermediaryCode/CodeOtimizadorProcessor.java

@@ -33,6 +33,7 @@ public class CodeOtimizadorProcessor implements CodeProcessing {
         }
         int index = 0;
         Block block = c.Block();
+        Instruction last = null;
         LinkedList<Instruction> instructions = block.Instructions();
         ArrayList<Instruction> remove = new ArrayList<>();
         Iterator<Instruction> interator = block.Instructions().iterator();
@@ -67,12 +68,18 @@ public class CodeOtimizadorProcessor implements CodeProcessing {
 //            System.out.println("CodeOtimizadorProcessor2:" + inst.G("type"));
             switch (inst.G("type")) {
                 case "copy":
-                    if (!inst.eq("copy", "true")) {
-                        if (ReplaceVarAndRemoveInstruction(instructions, inst, index, block)) {
-//                            System.out.println("Remove instruction:" + inst);
-                            remove.add(inst);
-                        }
+                    if (last != null && last.eq("dst", inst.G("p1"))) {
+                        last.copy("dst", inst);
+                        remove.add(inst);
                     }
+//                    if (!inst.eq("copy", "true")) {
+//                        if (!inst.isNumber("p1") && ReplaceVarAndRemoveInstruction(instructions, inst, index, block)) {
+//                            System.out.println("Remove instruction:" + inst);
+//                            remove.add(inst);
+//                        }
+//                    } else {
+//                        System.out.println("COPIA TRUE:" + inst);
+//                    }
 
                 // Se o destino da copia não for indexado então pode executar 
                 // o replace da ocorrencia e remover a instrucao de copia
@@ -89,6 +96,7 @@ public class CodeOtimizadorProcessor implements CodeProcessing {
                 //                        instructions.remove();
                 //                    }
             }
+            last = inst;
             index++;
         }
         if (!remove.isEmpty()) {

+ 1 - 1
src/compiler/IVANNOSYS.java

@@ -35,7 +35,7 @@ public class IVANNOSYS {
                 default:
                     compiler = new IvannosysCompiler(
 //                            "src\\samples\\program.go",
-                            "src\\samples\\program_if.go",
+                            "src\\samples\\program.go",
 //                            "src\\samples\\program_mult.go",
                             "UTF-8",
                             IvannosysCompiler.INPUT_FILE)

+ 3 - 1
src/samples/program.go

@@ -49,7 +49,8 @@ func laplaciano() {
     for i:= 1; i < LM1; i++ {
         for j := 1; j < CM1; j++ {
 lab_1:
-            l = origin[i-1][j]
+            l = origin[i-1][j] + origin[i][j-1] + origin[i][j+1] + origin[i+1][j] - (4 * origin[i][j])
+/*
 lab_2:
             l = l + origin[i][j-1]
 lab_3:
@@ -60,6 +61,7 @@ lab_5:
             l = l - (4 * origin[i][j])
 lab_6:
 
+*/
             if l > 255 {
               l = 255
             }

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

@@ -50,6 +50,48 @@ public class Gen extends API.Gen {
         Init();
     }
 
+    @Override
+    public IvannosysTargetArch Export() {
+        Code Target = getTarget();
+        System.out.println(Target.GData());
+        String out = "", tmp;
+        Integer index;
+        for (Map.Entry<String, Block> x : Target.stmts.entrySet()) {
+            System.out.println(x.getValue().Data());
+            index = 0;
+            for (Instruction instr : x.getValue().Instructions()) {
+//                System.out.println("Export:" + instr);
+                tmp = instr.G("inst.dec");
+                if (tmp.equals("")) {
+                    continue;
+                }
+                out = out
+                        //                        .concat(Integer.toHexString(index))
+                        //                        .concat(":")
+                        //                        .concat(String.format("%X\n", tmp.trim()) + "\n");
+                        .concat(tmp + "\n");
+                index++;
+            }
+        }
+
+//        System.out.println("Export:" + out);
+        // Grava resutlado no arquivo de memoria do simulador
+        Utils.WriteFile("\\src\\tools\\mips\\memory\\mi.memory", out);
+        try {
+            new tools.mips.MipsProcessor(new tools.mips.MipsSettings() {
+                {
+                    debugmode = false;
+                    SetInstructionMemoryFile("\\src\\tools\\mips\\memory\\mi.memory");
+                    SetDataMemoryFile("\\src\\tools\\mips\\memory\\md.memory");
+                }
+            }).Run().Persist();
+        } catch (IOException ex) {
+            Logger.getLogger(Gen.class.getName()).log(Level.SEVERE, null, ex);
+        }
+
+        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+    }
+
     public void CopyData(LinkedHashMap<String, Node> dst, LinkedHashMap<String, Node> src) throws Exception {
         Node value;
 
@@ -74,7 +116,6 @@ public class Gen extends API.Gen {
 
     public IvannosysTargetArch SetTAC(Code tac) {
         try {
-//            System.out.println(">>>>>>>>>>>>>>> Set tac");
             this.tac = tac;
             CopyData(target.GData().values(), tac.GData().values());
         } catch (Exception ex) {
@@ -86,7 +127,7 @@ public class Gen extends API.Gen {
     public void Init() {
         BeforeTranslateBlock("live.var", new OcorrenceFinderProcessor());
         BeforeTranslateBlock("register.alloc", new AllocatorMipsProcessor());
-        AfterTranslateBlock("otimization.1", new OtimizationMips());
+        AfterTranslateBlock("oti.1", new OtimizationMips());
         AfterTranslate("update.address", new UpdateAddressProcessor());
         getTarget()
                 .Template(new TemplateMips())
@@ -662,47 +703,6 @@ public class Gen extends API.Gen {
                 .S("rd", "zero"));
     }
 
-    @Override
-    public IvannosysTargetArch Export() {
-        Code Target = getTarget();
-        System.out.println(Target.GData());
-        String out = "", tmp;
-        Integer index;
-        for (Map.Entry<String, Block> x : Target.stmts.entrySet()) {
-            System.out.println(x.getValue().Data());
-            index = 0;
-            for (Instruction instr : x.getValue().Instructions()) {
-//                System.out.println("Export:" + instr);
-                tmp = instr.G("inst.dec");
-                if (tmp.equals("")) {
-                    continue;
-                }
-                out = out
-                        //                        .concat(Integer.toHexString(index))
-                        //                        .concat(":")
-                        //                        .concat(String.format("%X\n", tmp.trim()) + "\n");
-                        .concat(tmp + "\n");
-                index++;
-            }
-        }
-
-//        System.out.println("Export:" + out);
-        // Grava resutlado no arquivo de memoria do simulador
-        Utils.WriteFile("\\src\\tools\\mips\\memory\\mi.memory", out);
-        try {
-            new tools.mips.MipsProcessor(new tools.mips.MipsSettings() {
-                {
-                    SetInstructionMemoryFile("\\src\\tools\\mips\\memory\\mi.memory");
-                    SetDataMemoryFile("\\src\\tools\\mips\\memory\\md.memory");
-                }
-            }).Run().Persist();
-        } catch (IOException ex) {
-            Logger.getLogger(Gen.class.getName()).log(Level.SEVERE, null, ex);
-        }
-
-        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
-    }
-
     @Override
     public void TranslateUnary(Instruction inst) throws Exception {
         // Carrega o valor se nao esta em registrador

+ 6 - 7
src/tools/mips/MipsProcessor.java

@@ -28,8 +28,7 @@ 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 {
@@ -62,7 +61,7 @@ public class MipsProcessor {
     }
 
     protected void Log(String msg) {
-        if (debugmode) {
+        if (settings.debugmode) {
             System.out.println(msg);
         }
     }
@@ -94,7 +93,7 @@ public class MipsProcessor {
                 Log("Registradores(\n" + RBank
                         + ")\b nextPC:" + Integer.toHexString((int) PC));
 
-                if (stepByStep || breakPoint.containsKey(cAddress)) {
+                if (settings.stepByStep || breakPoint.containsKey(cAddress)) {
                     br.readLine();
                 }
                 // Decode
@@ -345,7 +344,7 @@ public class MipsProcessor {
                 }
                 break;
             case "bltz":
-                System.out.println("BLTZ:" + rs);
+//                System.out.println("BLTZ:" + rs);
                 if (RBank.R(rs) < 0) {
                     PC += imm << 2;
                     return;
@@ -370,15 +369,15 @@ 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));
-                System.out.printf("Load endereco '%d'\n", RBank.R(rs) + imm);
                 break;
 //            case "ori":
 //                break;
             case "slti":
 //            case "sltiu":
             case "sw":
-                System.out.printf("Store '%d' no endereco '%d'\n", RBank.R(rt), RBank.R(rs) + imm);
+                Log(String.format("Store '%d' no endereco '%d'\n", RBank.R(rt), RBank.R(rs) + imm));
                 MD.W(RBank.R(rs) + imm, RBank.R(rt));
                 break;
 //            case "xori":

+ 3 - 0
src/tools/mips/MipsSettings.java

@@ -13,6 +13,9 @@ import java.util.HashMap;
  */
 public class MipsSettings {
 
+    public boolean stepByStep = false;
+    public boolean debugmode = true;
+
     protected HashMap<String, String> data = new HashMap<String, String>();
 
     public MipsSettings() {

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

@@ -4,19 +4,19 @@
 0012:	0
 0016:	0
 0020:	0
-0024:	0
-0028:	0
-0032:	0
+0024:	1
+0028:	2
+0032:	3
 0036:	0
 0040:	0
-0044:	0
-0048:	0
-0052:	0
+0044:	4
+0048:	5
+0052:	6
 0056:	0
 0060:	0
-0064:	0
-0068:	0
-0072:	0
+0064:	7
+0068:	8
+0072:	9
 0076:	0
 0080:	0
 0084:	0
@@ -29,19 +29,19 @@
 0112:	0
 0116:	0
 0120:	0
-0124:	0
-0128:	0
-0132:	0
+0124:	2
+0128:	1
+0132:	-4
 0136:	0
 0140:	0
-0144:	0
+0144:	-3
 0148:	0
-0152:	0
+0152:	-7
 0156:	0
 0160:	0
-0164:	0
-0168:	0
-0172:	0
+0164:	-16
+0168:	-11
+0172:	-22
 0176:	0
 0180:	0
 0184:	0
@@ -4088,7 +4088,7 @@
 16348:	0
 16352:	0
 16356:	0
-16360:	0
+16360:	10
 16364:	0
 16368:	0
 16372:	0

+ 124 - 187
src/tools/mips/memory/mi.memory

@@ -1,190 +1,127 @@
-0666763256
+0666697728
 0001962017
-0605028352
-0605093889
-0604635137
-0302645253
-0604700675
-0302710787
-0604766213
-0369885187
-0605028362
-0134217745
-0604897282
-0370016259
-0605028372
-0134217745
-0605028382
-0604504065
-0604569603
-0285802501
-0604635138
-0604700676
-0021696547
-0071303171
-0605028362
-0134217760
-0604831746
-0604897282
-0363724803
-0605028372
-0134217760
-0605028382
-0604569601
-0371785734
-0604504065
-0604700673
-0353042435
-0605028362
-0134217772
-0604766210
-0371982339
-0605028372
-0134217772
-0605028382
-0604962818
-0036638755
-0071303171
-0605028362
-0134217778
-0605028372
-0604700674
-0036376611
-0071303172
-0604504065
-0604635137
-0352976899
-0605028362
-0134217787
-0605028372
-0604831746
-0036507683
-0071303174
-0604962817
-0605552641
-0368574467
-0605028362
-0134217796
-0605028372
-0604635138
-0036311075
-0071303178
-0604504065
-0604766209
-0285999111
-0604897282
-0036573219
-0071303172
-0604831745
-0605552641
-0364380163
-0605028362
-0134217811
-0605028372
-0604700674
-0036376611
-0071303180
-0604635137
-0604766209
-0357302281
-0604504066
-0036180003
-0071303174
-0604897281
-0605552641
-0366477315
-0605028362
-0134217826
-0605028372
-0604569602
-0036245539
-0071303172
-0604700673
-0604766209
-0292290567
-0604635138
-0036311075
-0071303174
-0604504065
-0605552641
-0353894403
-0605028362
-0134217841
-0605028372
-0604962818
-0036638755
-0071303172
-0604569601
-0604766209
-0355205129
-0604700674
-0036376611
-0071303172
-0604635137
-0605552641
-0358088707
-0605028362
-0134217856
-0605028372
-0604831746
-0036507683
-0071303180
-0604962817
-0604766209
-0367788041
-0604569602
-0036245539
-0071303172
-0604700673
-0605552641
-0360185859
-0605028362
-0134217871
-0605028372
-0604897282
-0036573219
-0071303172
+0201326597
+0201326637
+4294967295
+0666763240
+0001962017
+0605028353
+0605093892
+0605159428
+0605224960
+0134217768
+0605290496
+0134217764
+0604831744
+0309133314
+0376504323
+0605356032
+0134217755
+0604962816
+0311361538
+0378667011
+0605356032
+0134217755
+0001091617
+0638582785
+2949644288
+0001263649
+0000610432
+0019548193
+0001333281
+0019613729
+0000614528
+0059531297
+2912223232
+0647233537
+0604897285
+0042864675
+0071368680
+0645070849
+0605552645
+0041422883
+0071368674
+0666697752
+0065011720
+0666763228
+0001962017
+0605028356
+0605093892
+0605159425
+0134217851
+0605224961
+0134217848
 0604831745
-0604766209
-0363593737
-0604962818
-0036638755
-0071303174
-0604569601
-0605552641
-0355991555
-0605028362
-0134217886
-0605028372
-0604504066
-0036180003
-0071303172
-0604897281
-0604766209
-0298582023
-0604831746
-0036507683
-0071303172
-0604962817
-0605552641
-0368574467
-0605028362
-0134217901
-0605028372
-0604635138
-0036311075
-0071303178
-0604504065
-0604766209
-0285999111
-0604897282
-0036573219
-0071303174
+0038625315
+0000815232
+0026107937
+0001275937
+0026173473
+0000835712
+0060342305
+2400452608
+0001327137
+0001198113
+0000610432
+0019548193
 0604831745
-0605552641
-0364380163
-0605028362
-0134217917
-0605028372
-2949644288
-4294967295
+0040720419
+0019613729
+0000618624
+0059666465
+2379546624
+0001407009
+0017784865
+0001228833
+0001593472
+0051036193
+0644677633
+0051232801
+0001591424
+0059328545
+2369126400
+0001470497
+0026099745
+0642711553
+0001005696
+0032208929
+0001271841
+0032340001
+0001032320
+0060342305
+2400649216
+0001525793
+0017391649
+0001208353
+0000938112
+0030044193
+0001267745
+0030109729
+0000944256
+0059598881
+2377383936
+0001341473
+0604504068
+0032030744
+0000049170
+0026781731
+0604569855
+0044634147
+0406847490
+0605356287
+0001202209
+0000749696
+0024008737
+0001271841
+0023943201
+0000751744
+0059734049
+2918514788
+0645070849
+0040964131
+0071368636
+0642908161
+0038801443
+0071368631
+0666697764
+0065011720