gitweb on Svarog

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