gitweb on Svarog

projekti pod git sistemom za održavanje verzija -- projects under the git version control system
new InOut samples, one for a char, other for branching
[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;
49 C:"remove all the comments ";
50 FOREACH Statement DO
51 IF @ST(@I) = T_Comment THEN
52 @Delete
53 FI
54 OD;
55 FOREACH Statement DO
56 IF @Trans?(TR_Simplify_Item) THEN
57 @Trans(TR_Simplify_Item,"")
58 FI
59 OD;
61 C:"Convert DO loops into WHILE loops";
62 FOREACH Statement DO
63 IF @Trans?(TR_Floop_To_While) THEN
64 @Trans(TR_Floop_To_While, "");
65 FI
66 OD;
67 FOREACH Statement DO
68 IF @Trans?(TR_Flag_Removal) THEN
69 @Trans(TR_Flag_Removal, "");
70 FI
71 OD;
72 C:"Go back to the start, and remove redundant";
73 @GOTO(< >);
74 @Trans(TR_Delete_All_Redundant, "");
75 SKIP
76 END;
78 BEGIN
79 VAR< prog := < >, inifilename := "transf.ini",
80 filename:="", file := "", inifile:= ""
81 >:
82 IF @File_Exists?(inifilename) THEN
83 inifile := @Open_Input_File(inifilename);
84 filename := @Read_Line(inifile);
85 WHILE NOT @EOF?(filename) DO
86 IF @File_Exists?(filename) THEN
87 PRINT("");
88 @New_Program(@Parse_File(filename, T_Statements));
89 PRINT("Processing: ", filename);
90 prog := @Program;
91 @Process_Prog();
92 Get_New_Name(VAR filename);
93 @PP_Item(@Program, 80, filename);
94 PRINT("<Metrics>");
95 PRINT(filename);
96 Prog_Stat_Comp(prog, @Program);
97 PRINT("</Metrics>")
98 FI;
99 filename := @Read_Line(inifile)
100 OD;
101 @Close_Input_Port(inifile);
102 ELSE
103 PRINT("ini file (",inifilename,") not found.",
104 " it should contain a list of filenames to be converted");
105 PRINT("you can input a filename now:");
106 filename := @Read_Line(Standard_Input_Port);
107 IF @File_Exists?(filename) THEN
108 @New_Program(@Parse_File(filename, T_Statements));
109 @Process_Prog();
110 Get_New_Name(VAR filename);
111 @PP_Item(@Program, 80, filename)
112 FI;
113 FI
114 ENDVAR
115 WHERE
117 PROC Prog_Stat(Pro VAR)==
118 PRINT ("Mc ", @McCabe(Pro));
119 PRINT ("Statements ", @Stat_Count(Pro));
120 PRINT ("Control/data Flow ", @CFDF_Metric(Pro));
121 PRINT ("Size(nodes) ", @Total_Size(Pro));
122 PRINT ("Struct ", @Struct_Metric(Pro));
123 SKIP
124 END
126 PROC Prog_Stat_Comp(Pro, After VAR)==
127 VAR < ma := 0, mb :=1 > :
128 ma := @McCabe(Pro);
129 mb := @McCabe(After);
130 PRINT ("McCabe ", ma, " ", mb, " ",(mb-ma));
131 ma := @Stat_Count(Pro);
132 mb := @Stat_Count(After);
133 PRINT ("Statem ", ma, " ",mb, " ",(mb-ma));
134 ma := @CFDF_Metric(Pro);
135 mb := @CFDF_Metric(After);
136 PRINT ("CF/DF ", ma," ", mb," ", (mb-ma));
137 ma := @Total_Size(Pro);
138 mb := @Total_Size(After);
139 PRINT ("Size ", ma," ", mb, " ",(mb-ma));
140 ma := @Struct_Metric(Pro);
141 mb := @Struct_Metric(After);
142 PRINT ("Struct ", ma, " ",mb, " ",(mb-ma));
143 SKIP
144 ENDVAR
145 END
147 PROC Get_New_Name(VAR str) ==
148 IF @Ends_With?(str, ".wsl") THEN
149 str := SUBSTR(str, 0, SLENGTH(str)-4)
150 FI;
151 str := str ++ "_t.wsl"
152 END
154 PROC Get_Before_Name(VAR str) ==
155 IF @Ends_With?(str, ".wsl") THEN
156 str := SUBSTR(str, 0, SLENGTH(str)-4)
157 FI;
158 str := str ++ "_b.wsl"
159 END
161 END
Svarog.pmf.uns.ac.rs/gitweb maintanance Doni Pracner