gitweb on Svarog

projekti pod git sistemom za održavanje verzija -- projects under the git version control system
ant - recording logs of testing, plus prev test
[mjc2wsl.git] / src-wsl / transf-exp.wsl
1 C:"
2 Copyright (C) 2012,2014 Doni Pracner http://perun.dmi.rs/pracner
4 This program is free software; you can redistribute it
5 and/or modify it under the terms of the GNU General Public
6 License as published by the Free Software Foundation; either
7 version 3 of the License, or (at your option) any later
8 version.
10 This program is distributed in the hope that it will be
11 useful, but WITHOUT ANY WARRANTY; without even the implied
12 warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13 PURPOSE. See the GNU General Public License for more
14 details.
16 You should have received a copy of the GNU General Public
17 License along with this program. If not, see
18 <http://www.gnu.org/licenses/>.
19 ==========================================================";
21 C:"Automatic transformation tool for simplification of WSL";
22 C:"code automaticaly translated from a low level language.";
23 C:"such as assembly or bytecode generated by our translators.";
25 C:"experimental version";
27 C:"set the following so that Action Systems are not automaticaly treated as regular";
28 Assume_A_S_Regular := 0;
30 MW_PROC @Process_Prog() ==
31 FOREACH Statement DO
32 IF @Trans?(TR_Push_Pop) THEN
33 @Trans(TR_Push_Pop, "");
34 FI
35 OD;
36 @Trans(TR_Constant_Propagation, "");
37 FOREACH Statement DO
38 IF @ST(@I) = T_A_S THEN
39 C:"don't need to test for this, works for T_A_S";
40 @Trans(TR_Simplify_Action_System, "");
41 IF @Trans?(TR_Collapse_Action_System) THEN
42 @Trans(TR_Collapse_Action_System, "");
43 FI;
44 ELSIF @Trans?(TR_Remove_All_Redundant_Vars) THEN
45 @Trans(TR_Remove_All_Redundant_Vars, "");
46 ELSIF @ST(@I) = T_Skip THEN
47 @Delete
48 FI
49 OD;
51 C:"remove all the comments ";
52 FOREACH Statement DO
53 IF @ST(@I) = T_Comment THEN
54 @Delete
55 FI
56 OD;
57 FOREACH Statement DO
58 IF @Trans?(TR_Simplify_Item) THEN
59 @Trans(TR_Simplify_Item,"")
60 FI
61 OD;
63 C:"Convert DO loops into WHILE loops";
64 FOREACH Statement DO
65 IF @Trans?(TR_Floop_To_While) THEN
66 @Trans(TR_Floop_To_While, "");
67 FI
68 OD;
69 FOREACH Statement DO
70 IF @Trans?(TR_Flag_Removal) THEN
71 @Trans(TR_Flag_Removal, "");
72 FI
73 OD;
74 C:"Go back to the start, and remove redundant";
75 @GOTO(< >);
76 @Trans(TR_Delete_All_Redundant, "");
77 SKIP
78 END;
80 MW_PROC @Prog_Stat_Comp(Pro, After VAR)==
81 VAR < ma := 0, mb :=1 > :
82 ma := @McCabe(Pro);
83 mb := @McCabe(After);
84 PRINT ("McCabe ", ma, " ", mb, " ",(mb-ma));
85 ma := @Stat_Count(Pro);
86 mb := @Stat_Count(After);
87 PRINT ("Statem ", ma, " ",mb, " ",(mb-ma));
88 ma := @CFDF_Metric(Pro);
89 mb := @CFDF_Metric(After);
90 PRINT ("CF/DF ", ma," ", mb," ", (mb-ma));
91 ma := @Total_Size(Pro);
92 mb := @Total_Size(After);
93 PRINT ("Size ", ma," ", mb, " ",(mb-ma));
94 ma := @Struct_Metric(Pro);
95 mb := @Struct_Metric(After);
96 PRINT ("Struct ", ma, " ",mb, " ",(mb-ma));
97 SKIP
98 ENDVAR
99 END;
101 MW_PROC @Get_New_Name(VAR str) ==
102 IF @Ends_With?(str, ".wsl") THEN
103 str := SUBSTR(str, 0, SLENGTH(str)-4)
104 FI;
105 str := str ++ "_t.wsl"
106 END;
108 MW_PROC @Process_File(filename) ==
109 IF @File_Exists?(filename) THEN
110 @New_Program(@Parse_File(filename, T_Statements));
111 PRINT("Processing: ", filename);
112 prog := @Program;
113 @Process_Prog();
114 @Get_New_Name(VAR filename);
115 @PP_Item(@Program, 80, filename);
116 PRINT("<Metrics>");
117 PRINT(filename);
118 @Prog_Stat_Comp(prog, @Program);
119 PRINT("</Metrics>")
120 ELSE
121 PRINT("ERROR: File ",filename," not found");
122 FI
123 END;
125 BEGIN
126 VAR< prog := < >, inifilename := "transf.ini",
127 filename:="", file := "", inifile:= "",
128 Argv := @Argv
129 >:
130 C:"First one is the script name that is being executed";
131 Argv := TAIL(Argv);
133 IF Argv = < > THEN
134 PRINT("no arguments passed; using ",inifilename);
135 IF @File_Exists?(inifilename) THEN
136 inifile := @Open_Input_File(inifilename);
137 filename := @Read_Line(inifile);
138 WHILE NOT @EOF?(filename) DO
139 PRINT("");
140 @Process_File(filename);
141 filename := @Read_Line(inifile)
142 OD;
143 @Close_Input_Port(inifile);
144 ELSE
145 PRINT("ini file (",inifilename,") not found.",
146 " it should contain a list of filenames to be converted");
147 PRINT("OR you can give command line arguments to be processed");
148 FI
149 ELSE
150 FOR arg IN Argv DO
151 @Process_File(arg);
152 OD
153 FI
154 ENDVAR
155 WHERE
157 PROC Prog_Stat(Pro VAR)==
158 PRINT ("Mc ", @McCabe(Pro));
159 PRINT ("Statements ", @Stat_Count(Pro));
160 PRINT ("Control/data Flow ", @CFDF_Metric(Pro));
161 PRINT ("Size(nodes) ", @Total_Size(Pro));
162 PRINT ("Struct ", @Struct_Metric(Pro));
163 SKIP
164 END
166 PROC Get_Before_Name(VAR str) ==
167 IF @Ends_With?(str, ".wsl") THEN
168 str := SUBSTR(str, 0, SLENGTH(str)-4)
169 FI;
170 str := str ++ "_b.wsl"
171 END
173 END
Svarog.pmf.uns.ac.rs/gitweb maintanance Doni Pracner