gitweb on Svarog

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