gitweb on Svarog
projekti pod git sistemom za održavanje verzija -- projects under the git version control system 2 /*
3 Copyright 2012,2018 Doni Pracner
5 This program is free software: you can redistribute it
6 and/or modify it under the terms of the GNU General Public
7 License as published by the Free Software Foundation, either
8 version 3 of the License, or (at your option) any later
9 version.
11 This program is distributed in the hope that it will be
12 useful, but WITHOUT ANY WARRANTY; without even the implied
13 warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the GNU General Public License for more
15 details.
17 You should have received a copy of the GNU General Public
18 License along with this program. If not, see
19 <http://www.gnu.org/licenses/>.
21 */
25 /**
26 * This program converts files from assembly x86 to WSL language which is a part
27 * of the FermaT Transformation system.<br />
28 * Currently it works only on a very limited subset of x86, and has a number of
29 * predefined macro names it uses for translation. It works with 16 bit
30 * registers (ax,bx, etc) and presumes that the rest of the variables are 8bit
31 * if not applied to a 16bit reg. Check the documentation for more details.
32 *
33 * @author Doni Pracner, http://perun.dmi.rs/pracner http://quemaster.com
34 */
39 /** translation processing switch */
49 // regular comments from the original file
50 // OC when original code is inserted in the file, next to the translations
51 // SPEC special messages from the translator
52 // ERR error messages from the translator
76 }
88 }
91 }
93 /**
94 * When the param works with array addressing, this should reformat it so
95 * that it works as intended. An important thing to remember is that there
96 * is a[0] element in WSL, all arrays start with a[1].
97 */
101 }
103 /**
104 * Transforms an asembler source parameter as need so that it can be used in
105 * WSL. Among other things it converts Hex numbers to decimal, fixes array
106 * access indexes and the high/low parts of registers.
107 */
119 }
136 else
137 // for undefined variables
140 else
143 }
145 /**
146 * Transforms an asembler destination parameter as need so that it can be
147 * used in WSL. Among other things it fixes array access indexes and the
148 * high/low parts of registers.
149 */
157 else
159 }
161 /**
162 * Used for fixing low/high register access. The given param should be the
163 * dst operand of an assembler command.
164 */
173 }
175 }
177 /**
178 * Creates a WSL comment with care to quote chars.
179 */
182 }
184 /**
185 * Creates a WSL comment with care to quote chars, of the given type. Types
186 * are given as char constants. They can be default comments, comments that
187 * contain the original code in them, or additional comments regarding the
188 * translation process.
189 */
192 }
194 /**
195 * Creates a wsl statement that modifies the overflow limit based on the
196 * input string that should be the parameter of a command.
197 */
206 }
208 }
215 }
216 }
220 // internal state, if a procedure body is being translated currently
223 // the name of the procedure currently translated, if there is one
226 /**
227 * Takes a single assembler line and returns the translated WSL line(s). It
228 * also changes the translator modes (data, code etc).
229 */
231 /* Most of the logic is here, some parts could be split off */
237 // removes the comments
241 // if there is a non-comment part
243 // separators are whitespace: tab, space and comma
250 // special case, we are processing lines in a macro definition
257 }
258 // by this time, all the real words should be in the com array
261 // debugPrint(com);
268 // labelfound = true;
270 // ------------------------------------------------------------
271 // procedures, calls and similar activities
273 // if (labelfound)
290 // check for recursive calls, don't do outside of current
291 // action system
296 // segments and other special assembler directives
310 "other models than small not supported :: "
312 C_SPEC);
313 nUnknownD++;
315 }
319 C_SPEC);
320 nUnknownD++;
322 }
327 C_SPEC);
328 nUnknownD++;
350 C_SPEC);
351 nUnknownD++;
353 }
368 C_SPEC);
373 C_SPEC);
374 nUnknownD++;
375 }
379 }
382 // macro ideas ----
386 C_ERR);
387 nUnknownC++;
393 C_ERR);
394 nUnknownC++;
398 /*
399 * ------------------------------
400 *
401 * special macro names translated directly
402 */
436 // ---------------------------------------
437 // operators and similar commands
444 C_SPEC);
450 }
468 // rez += getOverflow(a);
491 // rez += getOverflow(a);
514 // logical exp
516 // rez += com.get(i+1)+" := "+com.get(i+1)+" AND
517 // "+formatParam(com.get(i+2))+";";
520 nUnknownC++;
530 // a+" := ("+a+" AND NOT "+b+") OR (NOT "+a+" AND "+b+"
531 // );");
532 nUnknownC++;
533 }
536 // rez += com.get(i+1)+" := NOT "+com.get(i+1)+";";
539 nUnknownC++;
542 // jumps
576 // end and other
578 // TODO parse the optional entry label that comes with end
586 // stack
593 }
603 }
606 // var definitions
618 }
621 }
622 }
623 i++;
624 }
627 nUnknownC++;
630 }
633 }
635 /**
636 * Converts an asm file to a wsl file. It also prints out the number of
637 * unsupported commands.
638 */
660 }
665 // remove comments from dataseg
686 }
687 }
706 }
712 else
717 else
723 }
724 i++;
725 }
730 }
740 }
741 }
745 }
746 }