gitweb on Svarog

projekti pod git sistemom za održavanje verzija -- projects under the git version control system
simplified ascii codes to chars in printing based on a new FermaT feature
[mjc2wsl.git] / src-wsl / transf-exp.wsl
1 C:"
2 Copyright (C) 2012 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 assembly using asm2wsl.";
23 C:"experimental version";
25 C:"set the following so that Action Systems are not automaticaly treated as regular";
26 Assume_A_S_Regular := 0;
28 MW_PROC @Process_Prog() ==
29 FOREACH Statement DO
30 IF @Trans?(TR_Push_Pop) THEN
31 @Trans(TR_Push_Pop, "");
32 FI
33 OD;
34 @Trans(TR_Constant_Propagation, "");
35 FOREACH Statement DO
36 IF @ST(@I) = T_A_S THEN
37 C:"don't need to test for this, works for T_A_S";
38 @Trans(TR_Simplify_Action_System, "");
39 IF @Trans?(TR_Collapse_Action_System) THEN
40 @Trans(TR_Collapse_Action_System, "");
41 FI;
42 ELSIF @Trans?(TR_Remove_All_Redundant_Vars) THEN
43 @Trans(TR_Remove_All_Redundant_Vars, "");
44 ELSIF @ST(@I) = T_Skip THEN
45 @Delete
46 FI
47 OD;
48 FOREACH Statement DO
49 IF @Trans?(TR_Flag_Removal) THEN
50 @Trans(TR_Flag_Removal, "");
51 FI
52 OD;
53 C:"remove all the comments ";
54 FOREACH Statement DO
55 IF @ST(@I) = T_Comment THEN
56 @Delete
57 FI
58 OD;
59 FOREACH Statement DO
60 IF @Trans?(TR_Simplify_Item) THEN
61 @Trans(TR_Simplify_Item,"")
62 FI
63 OD;
65 C:"Convert DO loops into WHILE loops";
66 FOREACH Statement DO
67 IF @Trans?(TR_Floop_To_While) THEN
68 @Trans(TR_Floop_To_While, "");
69 FI
70 OD;
71 C:"Go back to the start, and remove redundant";
72 @GOTO(< >);
73 @Trans(TR_Delete_All_Redundant, "");
74 SKIP
75 END;
77 BEGIN
78 VAR< prog := < >, inifilename := "transf.ini",
79 filename:="", file := "", inifile:= ""
80 >:
81 IF @File_Exists?(inifilename) THEN
82 inifile := @Open_Input_File(inifilename);
83 filename := @Read_Line(inifile);
84 WHILE NOT @EOF?(filename) DO
85 IF @File_Exists?(filename) THEN
86 PRINT("");
87 @New_Program(@Parse_File(filename, T_Statements));
88 PRINT("Processing: ", filename);
89 prog := @Program;
90 @Process_Prog();
91 Get_New_Name(VAR filename);
92 @PP_Item(@Program, 80, filename);
93 PRINT("<Metrics>");
94 PRINT(filename);
95 Prog_Stat_Comp(prog, @Program);
96 PRINT("</Metrics>")
97 FI;
98 filename := @Read_Line(inifile)
99 OD;
100 @Close_Input_Port(inifile);
101 ELSE
102 PRINT("ini file (",inifilename,") not found.",
103 " it should contain a list of filenames to be converted");
104 PRINT("you can input a filename now:");
105 filename := @Read_Line(Standard_Input_Port);
106 IF @File_Exists?(filename) THEN
107 @New_Program(@Parse_File(filename, T_Statements));
108 @Process_Prog();
109 Get_New_Name(VAR filename);
110 @PP_Item(@Program, 80, filename)
111 FI;
112 FI
113 ENDVAR
114 WHERE
116 PROC Prog_Stat(Pro VAR)==
117 PRINT ("Mc ", @McCabe(Pro));
118 PRINT ("Statements ", @Stat_Count(Pro));
119 PRINT ("Control/data Flow ", @CFDF_Metric(Pro));
120 PRINT ("Size(nodes) ", @Total_Size(Pro));
121 PRINT ("Struct ", @Struct_Metric(Pro));
122 SKIP
123 END
125 PROC Prog_Stat_Comp(Pro, After VAR)==
126 VAR < ma := 0, mb :=1 > :
127 ma := @McCabe(Pro);
128 mb := @McCabe(After);
129 PRINT ("McCabe ", ma, " ", mb, " ",(mb-ma));
130 ma := @Stat_Count(Pro);
131 mb := @Stat_Count(After);
132 PRINT ("Statem ", ma, " ",mb, " ",(mb-ma));
133 ma := @CFDF_Metric(Pro);
134 mb := @CFDF_Metric(After);
135 PRINT ("CF/DF ", ma," ", mb," ", (mb-ma));
136 ma := @Total_Size(Pro);
137 mb := @Total_Size(After);
138 PRINT ("Size ", ma," ", mb, " ",(mb-ma));
139 ma := @Struct_Metric(Pro);
140 mb := @Struct_Metric(After);
141 PRINT ("Struct ", ma, " ",mb, " ",(mb-ma));
142 SKIP
143 ENDVAR
144 END
146 PROC Get_New_Name(VAR str) ==
147 IF @Ends_With?(str, ".wsl") THEN
148 str := SUBSTR(str, 0, SLENGTH(str)-4)
149 FI;
150 str := str ++ "_t.wsl"
151 END
153 PROC Get_Before_Name(VAR str) ==
154 IF @Ends_With?(str, ".wsl") THEN
155 str := SUBSTR(str, 0, SLENGTH(str)-4)
156 FI;
157 str := str ++ "_b.wsl"
158 END
160 END
Svarog.pmf.uns.ac.rs/gitweb maintanance Doni Pracner