gitweb on Svarog

projekti pod git sistemom za održavanje verzija -- projects under the git version control system
44e7ccacd67c7e0ccaadb9f7f4ad79b89eb5086f
[mjc2wsl.git] / src-wsl / transf-min.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:"a simple version";
24 MW_PROC @Process_Prog() ==
25 @Trans(TR_Constant_Propagation, "");
26 FOREACH Statement DO
27 IF @ST(@I) = T_A_S THEN
28 C:"don't need to test for this, works for T_A_S";
29 IF @Trans?(TR_Collapse_Action_System) THEN
30 @Trans(TR_Collapse_Action_System, "");
31 FI;
32 ELSIF @Trans?(TR_Remove_All_Redundant_Vars) THEN
33 @Trans(TR_Remove_All_Redundant_Vars, "");
34 ELSIF @ST(@I) = T_Skip THEN
35 @Delete
36 FI
37 OD;
38 C:"remove all the comments ";
39 FOREACH Statement DO
40 IF @ST(@I) = T_Comment THEN
41 @Delete
42 FI
43 OD;
44 C:"Convert DO loops into WHILE loops";
45 FOREACH Statement DO
46 IF @Trans?(TR_Floop_To_While) THEN
47 @Trans(TR_Floop_To_While, "");
48 FI
49 OD;
50 C:"Go back to the start, and remove redundant";
51 @GOTO(< >);
52 @Trans(TR_Delete_All_Redundant, "");
53 SKIP
54 END;
56 BEGIN
57 VAR< prog := < >, inifilename := "transf.ini",
58 filename:="", file := "", inifile:= ""
59 >:
60 IF @File_Exists?(inifilename) THEN
61 inifile := @Open_Input_File(inifilename);
62 filename := @Read_Line(inifile);
63 WHILE NOT @EOF?(filename) DO
64 IF @File_Exists?(filename) THEN
65 @New_Program(@Parse_File(filename, T_Statements));
66 PRINT("Processing: ", filename);
67 prog := @Program;
68 @Process_Prog();
69 Get_New_Name(VAR filename);
70 @PP_Item(@Program, 80, filename);
71 Prog_Stat(prog);
72 PRINT("");
73 PRINT("After Conversion");
74 Prog_Stat(@Program)
75 FI;
76 filename := @Read_Line(inifile)
77 OD;
78 @Close_Input_Port(inifile);
79 ELSE
80 PRINT("ini file (",inifilename,") not found.",
81 " it should contain a list of filenames to be converted");
82 PRINT("you can input a filename now:");
83 filename := @Read_Line(Standard_Input_Port);
84 IF @File_Exists?(filename) THEN
85 @New_Program(@Parse_File(filename, T_Statements));
86 @Process_Prog();
87 Get_New_Name(VAR filename);
88 @PP_Item(@Program, 80, filename)
89 FI;
90 FI
91 ENDVAR
92 WHERE
94 PROC Prog_Stat(Pro VAR)==
95 PRINT ("Mc ", @McCabe(Pro));
96 PRINT ("Statements ", @Stat_Count(Pro));
97 PRINT ("Control/data Flow ", @CFDF_Metric(Pro));
98 PRINT ("Size(nodes) ", @Total_Size(Pro));
99 PRINT ("Struct ", @Struct_Metric(Pro));
100 SKIP
101 END
103 PROC Get_New_Name(VAR str) ==
104 IF @Ends_With?(str, ".wsl") THEN
105 str := SUBSTR(str, 0, SLENGTH(str)-4)
106 FI;
107 str := str ++ "_t.wsl"
108 END
110 PROC Get_Before_Name(VAR str) ==
111 IF @Ends_With?(str, ".wsl") THEN
112 str := SUBSTR(str, 0, SLENGTH(str)-4)
113 FI;
114 str := str ++ "_b.wsl"
115 END
117 END
Svarog.pmf.uns.ac.rs/gitweb maintanance Doni Pracner