gitweb on Svarog

projekti pod git sistemom za održavanje verzija -- projects under the git version control system
gitignore for dist folder
[mjc2wsl.git] / src-wsl / transf-min.wsl
1 C:"
2 Copyright (C) 2012,2015 Doni Pracner
3 http://perun.dmi.rs/pracner
5 This program is free software; you can redistribute it
6 and/or modify it under the terms of the GNU General Public
7 License as published by the Free Software Foundation; either
8 version 3 of the License, or (at your option) any later
9 version.
11 This program is distributed in the hope that it will be
12 useful, but WITHOUT ANY WARRANTY; without even the implied
13 warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the GNU General Public License for more
15 details.
17 You should have received a copy of the GNU General Public
18 License along with this program. If not, see
19 <http://www.gnu.org/licenses/>.
20 ==========================================================";
22 C:"Automatic transformation tool for simplification of WSL";
23 C:"code automaticaly translated from assembly using asm2wsl.";
25 C:"a very simple version, ment to be fast and relatively
26 efficient. It is aimed at action-system programs and should
27 remove them from the program, while doing other
28 simlifications in the process.";
30 C:"set the following so that Action Systems are not
31 automaticaly treated as regular";
32 C:"Not neccessary with recent versions of FermaT";
33 Assume_A_S_Regular := 0;
35 C:"Main procedure to transform the loaded program";
36 MW_PROC @Process_Prog() ==
38 @Trans(TR_Constant_Propagation, "");
40 C:"Try to remove the Action systems";
41 FOREACH Statement DO
42 IF @ST(@I) = T_A_S THEN
43 IF @Trans?(TR_Simplify_Action_System) THEN
44 @Trans(TR_Simplify_Action_System, "")
45 FI;
46 IF @Trans?(TR_Collapse_Action_System) THEN
47 @Trans(TR_Collapse_Action_System, "");
48 FI;
49 ELSIF @Trans?(TR_Remove_All_Redundant_Vars) THEN
50 @Trans(TR_Remove_All_Redundant_Vars, "");
51 ELSIF @ST(@I) = T_Skip THEN
52 @Delete
53 FI
54 OD;
56 C:"remove all the comments ";
57 FOREACH Statement DO
58 IF @ST(@I) = T_Comment THEN
59 @Delete
60 FI
61 OD;
63 FOREACH Statement DO
64 IF @Trans?(TR_Simplify_Item) THEN
65 @Trans(TR_Simplify_Item,"")
66 FI
67 OD;
69 C:"Convert DO loops into WHILE loops";
70 FOREACH Statement DO
71 IF @Trans?(TR_Floop_To_While) THEN
72 @Trans(TR_Floop_To_While, "");
73 FI
74 OD;
75 C:"Go back to the start, and remove redundant";
76 @Goto(< >);
77 @Trans(TR_Delete_All_Redundant, "");
78 SKIP
79 END;
81 MW_PROC @Get_New_Name(VAR str) ==
82 IF @Ends_With?(str, ".wsl") THEN
83 str := SUBSTR(str, 0, SLENGTH(str)-4)
84 FI;
85 str := str ++ "_t.wsl"
86 END;
88 MW_PROC @Prog_Stat_Comp(Pro, After VAR)==
89 VAR < ma := 0, mb :=1 > :
90 ma := @McCabe(Pro);
91 mb := @McCabe(After);
92 PRINT ("McCabe ", ma, " ", mb, " ",(mb-ma));
93 ma := @Stat_Count(Pro);
94 mb := @Stat_Count(After);
95 PRINT ("Statem ", ma, " ",mb, " ",(mb-ma));
96 ma := @CFDF_Metric(Pro);
97 mb := @CFDF_Metric(After);
98 PRINT ("CF/DF ", ma," ", mb," ", (mb-ma));
99 ma := @Total_Size(Pro);
100 mb := @Total_Size(After);
101 PRINT ("Size ", ma," ", mb, " ",(mb-ma));
102 ma := @Struct_Metric(Pro);
103 mb := @Struct_Metric(After);
104 PRINT ("Struct ", ma, " ",mb, " ",(mb-ma));
105 SKIP
106 ENDVAR
107 END;
109 MW_PROC @Process_File(filename) ==
110 IF @File_Exists?(filename) THEN
111 @New_Program(@Parse_File(filename, T_Statements));
112 PRINT("Processing: ", filename);
113 prog := @Program;
114 @Process_Prog();
115 @Get_New_Name(VAR filename);
116 @PP_Item(@Program, 80, filename);
117 PRINT(filename);
118 @Prog_Stat_Comp(prog, @Program);
119 ELSE
120 PRINT("ERROR: File ",filename," not found");
121 FI
122 END;
124 VAR< prog := < >, inifilename := "transf.ini",
125 filename:="", file := "", inifile:= "",
126 Argv := @Argv
127 >:
128 C:"First one is the script name that is being executed";
129 Argv := TAIL(Argv);
131 IF Argv = < > THEN
132 PRINT("no arguments passed; using ",inifilename);
133 IF @File_Exists?(inifilename) THEN
134 inifile := @Open_Input_File(inifilename);
135 filename := @Read_Line(inifile);
136 C:"check if the loaded is an EOF";
137 WHILE NOT @EOF?(filename) DO
138 @Process_File(filename);
139 filename := @Read_Line(inifile)
140 OD;
141 @Close_Input_Port(inifile);
142 ELSE
143 PRINT("ini file (",inifilename,") not found.",
144 " it should contain a list of filenames to be converted");
145 PRINT("you can input a filename now:");
146 filename := @Read_Line(Standard_Input_Port);
147 @Process_File(filename);
148 FI
149 ELSE
150 FOR arg IN Argv DO
151 @Process_File(arg);
152 OD
153 FI
154 ENDVAR
Svarog.pmf.uns.ac.rs/gitweb maintanance Doni Pracner