Browse Source

fix default value

eugeniucarvalho 5 years ago
parent
commit
22f36623f9

+ 2 - 0
.gitignore

@@ -0,0 +1,2 @@
+build
+src/tools/mips/memory

BIN
build/classes/IntermediaryCode/DataFrame.class


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


+ 0 - 10
build/classes/samples/program_mult_manycore.go

@@ -54,8 +54,6 @@ 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) {
@@ -70,12 +68,4 @@ func multiplica(initial int) {
             aux = 0
         }
     }
-    variavel1 = 16
-
-    x()
-}
-
-func x() int {
-    a := 1
-    return a
 }

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


+ 1 - 1
src/IntermediaryCode/BaseTacGen.java

@@ -2238,7 +2238,7 @@ public final class BaseTacGen implements TacGenInterface {
 //            size *= elementCount;
 
             if (!var.eq("constant", "true") || !var.in("type", new String[]{"int", "char", "bool"})) {
-
+                // Adiciona variaveis no frame global ou da funcao
                 (prefix.equals("G") ? code.GData() : code.Block().Data())
                         .Add(alias, var, elementCount);
             } else {

+ 7 - 5
src/IntermediaryCode/DataFrame.java

@@ -8,6 +8,7 @@ package IntermediaryCode;
 import API.Utils;
 import ast.AbstractSyntaxTree;
 import ast.Node;
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.LinkedHashMap;
 import java.util.Map;
@@ -54,16 +55,18 @@ public class DataFrame {
 //        int vSize = 1;
 //        int size = var.getInt("size"), vSize = 1;
 //        boolean isArray = var.eq("array", "true");
-
 //        if (isArray) {
 //            vSize = Tipos.Size(var.G("type"));
 //        }
+        ArrayList<String> defaults = var.getList("default.values");
+        Integer size = defaults.size();
+
         for (int i = 0; i < elements; i++) {
+
             values.put(
                     alias + "." + i,
-                    var.copy()
+                    var.copy().S("default.value", (i < size ? defaults.get(i) : "0"))
             );
-            //                    var.copy().S("size", vSize)
         }
 
         return this;
@@ -123,14 +126,13 @@ public class DataFrame {
             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(value.G("default.value"))
                     .append("\n");
 //            break;
         }

+ 34 - 7
src/grammar/visitorAndWalkers/IvannosysListener.java

@@ -226,12 +226,12 @@ public class IvannosysListener extends IvannosysGrammarBaseListener {
 
     protected void DeclVar(ParserRuleContext ctx, Node node) throws Exception {
         int i = 0;
-        String varname, t;
+        String varname, t, value;
         Node variable,
                 exprs = node.find("exprs"),
                 type = node.find("type");
-
-        ArrayList<String> types = new ArrayList<>();
+        ArrayList<ArrayList<String>> valuesGroup = new ArrayList<>();
+        ArrayList<String> types = new ArrayList<>(), values;
         ArrayList<Node> ids = node.find("ids").childrens();
         ArrayList<ArrayList<Node>> indexes = new ArrayList<>();
 
@@ -241,11 +241,31 @@ public class IvannosysListener extends IvannosysGrammarBaseListener {
             for (int k = 0; k < ids.size(); k++) {
                 types.add(t);
                 indexes.add(type.childrens());
+                values = new ArrayList<>();
+                if (exprs != null) {
+                    Node e = exprs.childrens().get(k);
+//                    for (Node e : exprs.childrens()) {
+                    switch (e.Class()) {
+//                        case "selector":
+//                            break;
+                        default:
+                            value = e.G("value");
+                            switch (t) {
+                                case "bool":
+                                    value = value.equals("true") ? "1" : "0";
+                            }
+                            values.add(value);
+//                            System.out.println("Ey:" + e);
+                    }
+//                    }
+                }
+                valuesGroup.add(values);
             }
         } else {
             // Quando declarado encurtado
             //Todo fazer os tipos inferidos;
             for (Node e : exprs.childrens()) {
+                values = new ArrayList<>();
                 switch (e.Class()) {
                     case "call":
 //                        System.out.println("Call:" + e.getText());
@@ -265,6 +285,8 @@ public class IvannosysListener extends IvannosysGrammarBaseListener {
                         }
                         break;
                     case "literal":
+//                        System.out.println("Lit:" + e);
+
                         if (e.eq("subclass", "array")) {
                             ArrayList<Node> indc = new ArrayList<>();
                             indexes.add(indc);
@@ -274,6 +296,8 @@ public class IvannosysListener extends IvannosysGrammarBaseListener {
                         }
                         break;
                     case "expr":
+//                        System.out.println("Exp:" + e);
+
                         types.add(e.G("type"));
                         indexes.add(new ArrayList<Node>());
                         break;
@@ -283,6 +307,7 @@ public class IvannosysListener extends IvannosysGrammarBaseListener {
                         indexes.add(e.childrens());
                         break;
                 }
+                valuesGroup.add(values);
             }
         }
 
@@ -303,8 +328,7 @@ public class IvannosysListener extends IvannosysGrammarBaseListener {
                     .S("subclass", "operand");
 
             variable.copy("type,value,pointer,array,array_size", var);
-            
-            variable.S("var.value", varname);
+            variable.addList("default.values", valuesGroup.get(i));
 
             astBaseSet(ctx, variable);
 
@@ -874,9 +898,12 @@ 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 
+     * 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) {

+ 0 - 10
src/samples/program_mult_manycore.go

@@ -54,8 +54,6 @@ 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) {
@@ -70,12 +68,4 @@ func multiplica(initial int) {
             aux = 0
         }
     }
-    variavel1 = 16
-
-    x()
-}
-
-func x() int {
-    a := 1
-    return a
 }

+ 2 - 3
src/target/mips/jun/Gen.java

@@ -41,7 +41,7 @@ public class Gen extends target.mips.Gen {
     public IvannosysTargetArch Export() {
         try {
             Code Target = getTarget(), newCode;
-            System.out.println("Export do juninho");
+            System.out.println("Export MIPSJUN");
 //            System.out.println("Data:" + Target.GData());
 
             Long stackBaseAddress = 0L,
@@ -53,7 +53,6 @@ public class Gen extends target.mips.Gen {
                     blockName,
                     format,
                     cacheBlockSize = BuildParams.Get("cacheBlockSize").get(0),
-                    //                    base = "\\src\\results\\mipsjun\\";
                     base = BuildParams.Get("outputDirectory").get(0);
             String[] parts;
 
@@ -104,9 +103,9 @@ public class Gen extends target.mips.Gen {
                         throw new Exception("Arquivo de saida para o core `" + id + "` não definido!");
                     }
 
-//                    Utils.WriteFile("\\src\\results\\mipsjun\\" + id + "\\main.dec.txt", code);
                     SaveMips(newCode, base + "\\" + String.format(format, "mips"));
                     SaveDec(newCode, base + "\\" + String.format(format, "dec"));
+                    
                     stackBaseAddress = updateBaseAddress;
 
 //                    ExecuteCode(newCode);