gitweb on Svarog

projekti pod git sistemom za održavanje verzija -- projects under the git version control system
transf-min updates
authorDoni Pracner <quinnuendo@gmail.com>
Mon, 10 Aug 2015 15:09:17 +0000 (17:09 +0200)
committerDoni Pracner <quinnuendo@gmail.com>
Mon, 10 Aug 2015 15:09:17 +0000 (17:09 +0200)
several updates to the transf-min script, making it work with
command line arguments and improving the output of metrics as
well as the organisation of procedures, more inline with the
newer scripts. also includes more comments and explanations.

src-wsl/transf-min.wsl

index f1046aa58f408893d250880df167a31b4231aae6..f70dc3dcbb8f943dccc7f10d4acb40a0afa6ce83 100755 (executable)
@@ -1,5 +1,6 @@
 C:"
-Copyright (C) 2012 Doni Pracner http://perun.dmi.rs/pracner
+Copyright (C) 2012,2015 Doni Pracner
+http://perun.dmi.rs/pracner
 
 This program is free software; you can redistribute it
 and/or modify it under the terms of the GNU General Public
@@ -18,38 +19,51 @@ License along with this program. If not, see
 <http://www.gnu.org/licenses/>.
 ==========================================================";
 
-C:"set the following so that Action Systems are not automaticaly treated as regular";
-Assume_A_S_Regular := 0;
-
 C:"Automatic transformation tool for simplification of WSL";
 C:"code automaticaly translated from assembly using asm2wsl.";
-C:"a simple version";
+
+C:"a very simple version, ment to be fast and relatively
+efficient. It is aimed at action-system programs and should
+remove them from the program, while doing other
+simlifications in the process.";
+
+C:"set the following so that Action Systems are not
+automaticaly treated as regular";
+C:"Not neccessary with recent versions of FermaT";
+Assume_A_S_Regular := 0;
+
+C:"Main procedure to transform the loaded program";
 MW_PROC @Process_Prog() ==
+
        @Trans(TR_Constant_Propagation, "");
+
+       C:"Try to remove the Action systems";
        FOREACH Statement DO
-               IF @ST(@I) = T_A_S THEN 
-                       C:"don't need to test for this, works for T_A_S";
-                       @Trans(TR_Simplify_Action_System, "");
+               IF @ST(@I) = T_A_S THEN
+                       IF @Trans?(TR_Simplify_Action_System) THEN
+                               @Trans(TR_Simplify_Action_System, "")
+                       FI;
                        IF @Trans?(TR_Collapse_Action_System) THEN
                                @Trans(TR_Collapse_Action_System, "");
                        FI;
                ELSIF @Trans?(TR_Remove_All_Redundant_Vars) THEN
                        @Trans(TR_Remove_All_Redundant_Vars, "");
-               ELSIF @ST(@I) = T_Skip THEN 
-                       @Delete  
+               ELSIF @ST(@I) = T_Skip THEN
+                       @Delete
                FI
        OD;
+
        C:"remove all the comments ";
        FOREACH Statement DO
-       IF @ST(@I) = T_Comment THEN 
+       IF @ST(@I) = T_Comment THEN
                        @Delete
        FI
        OD;
 
        FOREACH Statement DO
-             IF @Trans?(TR_Simplify_Item) THEN
-               @Trans(TR_Simplify_Item,"")
-             FI
+               IF @Trans?(TR_Simplify_Item) THEN
+                               @Trans(TR_Simplify_Item,"")
+               FI
        OD;
 
        C:"Convert DO loops into WHILE loops";
@@ -64,65 +78,77 @@ MW_PROC @Process_Prog() ==
        SKIP
 END;
 
-BEGIN
-VAR< prog := < >, inifilename := "transf.ini", 
-       filename:="", file := "", inifile:= ""
->:
-IF @File_Exists?(inifilename) THEN
-       inifile := @Open_Input_File(inifilename);
-       filename := @Read_Line(inifile);
-       WHILE NOT @EOF?(filename) DO
+MW_PROC @Get_New_Name(VAR str) ==
+       IF @Ends_With?(str, ".wsl") THEN
+               str := SUBSTR(str, 0, SLENGTH(str)-4)
+       FI;
+       str := str ++ "_t.wsl"
+END;
+
+MW_PROC @Prog_Stat_Comp(Pro, After VAR)==
+  VAR < ma := 0, mb :=1 > :
+  ma := @McCabe(Pro);
+  mb := @McCabe(After);
+  PRINT ("McCabe ", ma, "  ", mb, "  ",(mb-ma));
+  ma := @Stat_Count(Pro);
+  mb := @Stat_Count(After);
+  PRINT ("Statem ", ma, "  ",mb, "  ",(mb-ma));
+  ma := @CFDF_Metric(Pro);
+  mb := @CFDF_Metric(After);
+  PRINT ("CF/DF  ", ma,"  ", mb,"  ", (mb-ma));
+  ma := @Total_Size(Pro);
+  mb := @Total_Size(After);
+  PRINT ("Size   ", ma,"  ", mb, "  ",(mb-ma));
+  ma := @Struct_Metric(Pro);
+  mb := @Struct_Metric(After);
+  PRINT ("Struct ", ma, "  ",mb, "  ",(mb-ma));
+  SKIP
+  ENDVAR
+END;
+
+MW_PROC @Process_File(filename) ==
                IF @File_Exists?(filename) THEN
                        @New_Program(@Parse_File(filename, T_Statements));
                        PRINT("Processing: ", filename);
                        prog := @Program;
                        @Process_Prog();
-                       Get_New_Name(VAR filename);
+                       @Get_New_Name(VAR filename);
                        @PP_Item(@Program, 80, filename);
-                       Prog_Stat(prog);
-                       PRINT("");
-                       PRINT("After Conversion");
-                       Prog_Stat(@Program)
-               FI;
-               filename := @Read_Line(inifile)
-       OD;
-       @Close_Input_Port(inifile);
+                       PRINT(filename);
+                       @Prog_Stat_Comp(prog, @Program);
+               ELSE
+                       PRINT("ERROR: File ",filename," not found");
+               FI
+END;
+
+VAR< prog := < >, inifilename := "transf.ini",
+       filename:="", file := "", inifile:= "",
+       Argv := @Argv
+>:
+C:"First one is the script name that is being executed";
+Argv := TAIL(Argv);
+
+IF Argv = < > THEN
+       PRINT("no arguments passed; using ",inifilename);
+       IF @File_Exists?(inifilename) THEN
+               inifile := @Open_Input_File(inifilename);
+               filename := @Read_Line(inifile);
+               C:"check if the loaded is an EOF";
+               WHILE NOT @EOF?(filename) DO
+                       @Process_File(filename);
+                       filename := @Read_Line(inifile)
+               OD;
+               @Close_Input_Port(inifile);
+       ELSE
+               PRINT("ini file (",inifilename,") not found.",
+               " it should contain a list of filenames to be converted");
+               PRINT("you can input a filename now:");
+               filename := @Read_Line(Standard_Input_Port);
+               @Process_File(filename);
+       FI
 ELSE
-    PRINT("ini file (",inifilename,") not found.",
-    " it should contain a list of filenames to be converted");
-    PRINT("you can input a filename now:");
-    filename := @Read_Line(Standard_Input_Port);
-    IF @File_Exists?(filename) THEN
-       @New_Program(@Parse_File(filename, T_Statements));
-       @Process_Prog();
-       Get_New_Name(VAR filename);
-       @PP_Item(@Program, 80, filename)
-    FI;
+       FOR arg IN Argv DO
+               @Process_File(arg);
+       OD
 FI
 ENDVAR
-WHERE
-
-PROC Prog_Stat(Pro VAR)==
-  PRINT ("Mc ", @McCabe(Pro));
-  PRINT ("Statements ", @Stat_Count(Pro));
-  PRINT ("Control/data Flow ", @CFDF_Metric(Pro));
-  PRINT ("Size(nodes) ", @Total_Size(Pro));
-  PRINT ("Struct ", @Struct_Metric(Pro));
-  SKIP
-END
-
-PROC Get_New_Name(VAR str) == 
-       IF @Ends_With?(str, ".wsl") THEN
-               str := SUBSTR(str, 0, SLENGTH(str)-4)
-       FI;
-       str := str ++ "_t.wsl"
-END
-
-PROC Get_Before_Name(VAR str) == 
-       IF @Ends_With?(str, ".wsl") THEN
-               str := SUBSTR(str, 0, SLENGTH(str)-4)
-       FI;
-       str := str ++ "_b.wsl"
-END
-
-END
Svarog.pmf.uns.ac.rs/gitweb maintanance Doni Pracner