gitweb on Svarog

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