gitweb on Svarog

projekti pod git sistemom za održavanje verzija -- projects under the git version control system
substr should not be called with a negative length - so we prevent this with a MIN...
[mjc2wsl.git] / src / mjc2wsl.java
1 /*
2 Copyright (C) 2014 Doni Pracner
4 This file is part of mjc2wsl.
6 mjc2wsl is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 mjc2wsl is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with mjc2wsl. If not, see <http://www.gnu.org/licenses/>.
18 */
19 import java.io.*;
20 import java.util.*;
22 /**
23 * This program converts file from compiled MicroJava bytecode to WSL language
24 * which is a part of the FermaT Transformation system. MicroJava is a subset
25 * used in Compiler Construction courses by Hanspeter Moessenboeck, not
26 * "Java ME".
27 *
28 * @author Doni Pracner, http://perun.dmi.rs/pracner http://quemaster.com
29 */
30 public class mjc2wsl{
31 public static String versionN = "0.1.7";
33 private TransMessages messages = new TransMessages();
35 private boolean genPauseAfterEachAddress=false,
36 genPrintForEachAddress = false,
37 genPrintEStackOnChange = false;
39 private boolean genPopPush=false;
41 private boolean genInlinePrint=false;
43 /** Constant used for marking a regular comment from the original file */
44 public static final char C_REG = ' ';
45 /**
46 * Constant used for marking when original code is inserted in the file,
47 * next to the translations
48 */
49 public static final char C_OC = '#';
50 /** Constant used for marking special messages from the translator */
51 public static final char C_SPEC = '&';
52 /** Constant used for marking error messages from the translator */
53 public static final char C_ERR = '!';
55 /** instruction code in MicroJava bytecode. */
56 public static final int
57 load = 1,
58 load_0 = 2,
59 load_1 = 3,
60 load_2 = 4,
61 load_3 = 5,
62 store = 6,
63 store_0 = 7,
64 store_1 = 8,
65 store_2 = 9,
66 store_3 = 10,
67 getstatic = 11,
68 putstatic = 12,
69 getfield = 13,
70 putfield = 14,
71 const_0 = 15,
72 const_1 = 16,
73 const_2 = 17,
74 const_3 = 18,
75 const_4 = 19,
76 const_5 = 20,
77 const_m1 = 21,
78 const_ = 22,
79 add = 23,
80 sub = 24,
81 mul = 25,
82 div = 26,
83 rem = 27,
84 neg = 28,
85 shl = 29,
86 shr = 30,
87 inc = 31,
88 new_ = 32,
89 newarray = 33,
90 aload = 34,
91 astore = 35,
92 baload = 36,
93 bastore = 37,
94 arraylength = 38,
95 pop = 39,
96 dup = 40,
97 dup2 = 41,
98 jmp = 42,
99 jeq = 43,
100 jne = 44,
101 jlt = 45,
102 jle = 46,
103 jgt = 47,
104 jge = 48,
105 call = 49,
106 return_ = 50,
107 enter = 51,
108 exit = 52,
109 read = 53,
110 print = 54,
111 bread = 55,
112 bprint = 56,
113 trap = 57;
115 private boolean originalInComments = false;
117 private HashMap<Integer,String> opMap = null;
119 private String opCodeFile = "mj-bytecodes.properties";
121 private HashMap<Integer, String> getOpMap() {
122 if (opMap == null) {
123 opMap = new HashMap<Integer, String>(60, 0.98f);
124 try {
125 BufferedReader in = new BufferedReader(new InputStreamReader(
126 getClass().getResourceAsStream(opCodeFile)));
127 String str = in.readLine();
128 while (str != null) {
129 String[] ss = str.split("=");
130 opMap.put(Integer.parseInt(ss[0]), ss[1]);
131 str = in.readLine();
133 in.close();
134 } catch (Exception ex) {
135 ex.printStackTrace();
138 return opMap;
141 public String getOpString(int op) {
142 return getOpMap().get(op);
145 public String describeOpCode(int op) {
146 return op + " (" + getOpString(op) + ")";
149 private InputStream mainIn;
150 private PrintWriter out = null;
151 private int counter = -1;
153 private void pr(int i){
154 out.print(i);
157 private void pr(char i){
158 out.print(i);
161 private void pr(String i){
162 out.print(i);
165 private void prl(String i){
166 out.println(i);
169 private int get() {
170 int res = -1;
171 try {
172 res = mainIn.read();
173 if (res >= 0)
174 res = res << 24 >>> 24;
175 } catch (IOException ex) {
176 ex.printStackTrace();
178 counter++;
179 return res;
182 private int get2() {
183 return (get() * 256 + get()) << 16 >> 16;
186 private int get4() {
187 return (get2() << 16) + (get2() << 16 >>> 16);
190 public String createStandardStart(){
191 return createStandardStart(10);
194 public String createStandardStart(int numWords){
195 StringBuilder ret = new StringBuilder(
196 "C:\" This file automatically converted from microjava bytecode\";\n"
197 +"C:\" with mjc2wsl v "+versionN+"\";\n");
199 ret.append("\nBEGIN");
200 ret.append("\nVAR <\n\t");
201 ret.append("mjvm_locals := ARRAY(1,0),");
202 ret.append("\n\tmjvm_statics := ARRAY("+numWords+",0),");
203 ret.append("\n\tmjvm_arrays := < >,");
204 ret.append("\n\tmjvm_flag_jump := 0,");
205 ret.append("\n\tmjvm_objects := < >,");
206 ret.append("\n\tmjvm_estack := < >, mjvm_mstack := < > > :");
208 return ret.toString();
211 public String createAsciiString(){
212 StringBuilder ret = new StringBuilder("C:\"char array for ascii code conversions\";");
213 ret.append("\nascii := \"????????????????????????????????\"++\n");
214 ret.append("\" !\"++Quote++\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\";\n");
216 return ret.toString();
219 public String createStandardEnd(){
220 StringBuilder ret = new StringBuilder("SKIP\nENDVAR\n");
221 ret.append("\nWHERE\n");
223 ret.append("\nFUNCT CHR(num) ==:\n");
224 ret.append("\t@List_To_String(< num >)\n");
225 ret.append("END\n");
227 if (!genInlinePrint) {
228 ret.append("\nPROC Print_MJ(val, format VAR)==\n");
229 ret.append(createComment("print spacing", C_SPEC));
230 ret.append("\n\tIF format>1 THEN\n\t\tFOR i:=2 TO ");
231 ret.append("format STEP 1 DO PRINFLUSH(\" \") OD\n");
232 ret.append("\tFI;\n\tPRINFLUSH(val)\nEND\n");
234 ret.append("\nPROC Print_MJ_CHAR(val, format VAR)==\n");
235 ret.append(createComment("print spacing", C_SPEC));
236 ret.append("\n\tIF format>1 THEN\n\t\tFOR i:=2 TO ");
237 ret.append("format STEP 1 DO PRINFLUSH(\" \") OD\n");
238 ret.append("\tFI;\n\tPRINFLUSH(CHR(val))\n");
239 ret.append("END\n");
242 ret.append("\nEND");
243 return ret.toString();
246 private String createStartVar(String... vars){
247 StringBuilder ret = new StringBuilder("VAR < ");
248 ret.append(vars[0] + " := 0");
249 for (int i=1; i<vars.length; i++)
250 ret.append(", "+ vars[i] +" := 0");
251 ret.append(" > : ");
253 return ret.toString();
256 private String createEndVar(){
257 return "ENDVAR;";
260 private String createLocal(int i) {
261 // arrays start at 1 in WSL, so we need an offset
262 return "mjvm_locals[" + (i + 1) + "]";
265 private String createStatic(int i) {
266 return "mjvm_statics[" + (i + 1) + "]";
269 private String createArray(int i) {
270 return "mjvm_arrays[" + i + "]";
273 private String createArray(String i) {
274 return "mjvm_arrays[" + i + "]";
277 private String createObject(String i) {
278 return "mjvm_objects[" + i + "]";
281 /**
282 * Creates a WSL comment with care to quote chars.
283 */
284 public static String createComment(String str){
285 return createComment(str, C_REG);
288 /**
289 * Creates a WSL comment with care to quote chars, of the
290 * given type. Types are given as char constants. They can be
291 * default comments, comments that contain the original code
292 * in them, or additional comments regarding the translation
293 * process.
294 */
295 public static String createComment(String str, char type) {
296 return "C:\"" + type + str.replace("\"", "''") + "\";";
299 // generalised stack operations
301 private String createToStack(String stack, String var){
302 if (genPopPush)
303 return "PUSH("+stack+"," + var + ");";
304 else
305 return stack + " := <" + var + " > ++ " + stack +";";
308 private String createFromStack(String stack, String var){
309 if (genPopPush)
310 return "POP("+ var + ", "+stack+");";
311 else
312 return var + ":= HEAD("+stack+"); "+stack+" := TAIL("+stack+");";
314 //Expression stack
316 private String createToEStack(int i) {
317 return createToEStack(i+"");
320 private String createToEStack(String i) {
321 String res = createToStack("mjvm_estack", i);
322 if (genPrintEStackOnChange)
323 res += "PRINT(\"eStack\",mjvm_estack);";
324 return res;
327 private String createFromEStack(String st) {
328 String res = createFromStack("mjvm_estack",st);
329 if (genPrintEStackOnChange)
330 res += "PRINT(\"eStack\",mjvm_estack);";
331 return res;
334 private String createPopEStack() {
335 String res = "mjvm_estack := TAIL(mjvm_estack);";
336 if (genPrintEStackOnChange)
337 res += "PRINT(\"eStack\",mjvm_estack);";
338 return res;
341 private String createTopTwoEStack() {
342 return createFromEStack("tempa") + "\n" + createFromEStack("tempb");
345 private String createTopEStack() {
346 return createFromEStack("tempa");
349 //Method stack
351 private String createToMStack(int i) {
352 return createToMStack(i+"");
355 private String createToMStack(String i) {
356 return createToStack("mjvm_mstack", i);
359 private String createFromMStack(String st) {
360 return createFromStack("mjvm_mstack", st);
363 private String getRelationFor(int opcode) throws Exception {
364 switch (opcode) {
365 case jeq: return "=";
366 case jne: return "<>";
367 case jlt: return "<";
368 case jle: return "<=";
369 case jgt: return ">";
370 case jge: return ">=";
372 throw new Exception("Wrong opcode for a relation");
375 private boolean isJumpCode(int opcode) {
376 return (opcode >= jmp) && (opcode <= jge);
379 public void convertStream(InputStream ins) throws Exception{
380 mainIn = ins;
381 //process start
382 byte m = (byte) get();
383 byte j = (byte) get();
384 if (m!='M' || j !='J')
385 throw new Exception("Wrong start of bytecode file");
386 int codesize = get4();
387 int numberOfWords = get4();
388 int mainAdr = get4();
390 prl(createStandardStart(numberOfWords));
391 prl("SKIP;\n ACTIONS a" + (14 + mainAdr) + " :");
392 int op = get();
393 while (op >= 0) {
394 prl(" a" + counter + " ==");
395 if (originalInComments)
396 prl(createComment(describeOpCode(op), C_OC));
397 if (genPrintForEachAddress) {
398 prl("PRINT(\"a" + counter + "\");");
399 if (genPauseAfterEachAddress)
400 prl("debug_disposable_string := @Read_Line(Standard_Input_Port);");
402 switch (op) {
403 case load: {
404 prl(createToEStack(createLocal(get())));
405 break;
407 case load_0:
408 case load_1:
409 case load_2:
410 case load_3: {
411 prl(createStartVar("tempa"));
412 prl("tempa :="+createLocal(op - load_0)+";");
413 prl(createToEStack("tempa"));
414 prl(createEndVar());
415 break;
417 case store: {
418 prl(createFromEStack(createLocal(get())));
419 break;
421 case store_0:
422 case store_1:
423 case store_2:
424 case store_3: {
425 prl(createStartVar("tempa"));
426 prl(createFromEStack("tempa"));
427 prl(createLocal(op - store_0)+" := tempa;");
428 prl(createEndVar());
429 break;
432 case getstatic: {
433 prl(createToEStack(createStatic(get2())));
434 break;
436 case putstatic: {
437 prl(createFromEStack(createStatic(get2())));
438 break;
441 case getfield: {
442 int f = get2();
443 prl(createStartVar("tempa"));
444 prl(createTopEStack());
445 prl(createToEStack(createObject("tempa") + "[" + (f + 1) + "]"));
446 prl(createEndVar());
447 break;
449 case putfield: {
450 int f = get2();
451 prl(createStartVar("tempa", "tempb"));
452 prl(createTopTwoEStack());
453 prl(createObject("tempb") + "[" + (f + 1) + "]:=tempa;");
454 prl(createEndVar());
455 break;
458 case const_: {
459 prl(createToEStack(get4()));
460 break;
463 case const_m1: {
464 prl(createToEStack(-1));
465 break;
468 case const_0:
469 case const_1:
470 case const_2:
471 case const_3:
472 case const_4:
473 case const_5: {
474 prl(createToEStack(op - const_0));
475 break;
478 case add: {
479 prl(createStartVar("tempa", "tempb", "tempres"));
480 prl(createTopTwoEStack());
481 prl("tempres := tempb + tempa;");
482 prl(createToEStack("tempres"));
483 prl(createEndVar());
484 break;
486 case sub: {
487 prl(createStartVar("tempa", "tempb", "tempres"));
488 prl(createTopTwoEStack());
489 prl("tempres := tempb - tempa;");
490 prl(createToEStack("tempres"));
491 prl(createEndVar());
492 break;
494 case mul: {
495 prl(createStartVar("tempa", "tempb", "tempres"));
496 prl(createTopTwoEStack());
497 prl("tempres := tempb * tempa;");
498 prl(createToEStack("tempres"));
499 prl(createEndVar());
500 break;
502 case div: {
503 prl(createStartVar("tempa", "tempb", "tempres"));
504 prl(createTopTwoEStack());
505 prl("IF tempa = 0 THEN ERROR(\"division by zero\") FI;");
506 prl("tempres := tempb DIV tempa;");
507 prl(createToEStack("tempres"));
508 prl(createEndVar());
509 break;
511 case rem: {
512 prl(createStartVar("tempa", "tempb", "tempres"));
513 prl(createTopTwoEStack());
514 prl("IF tempa = 0 THEN ERROR(\"division by zero\") FI;");
515 prl("tempres := tempb MOD tempa;");
516 prl(createToEStack("tempres"));
517 prl(createEndVar());
518 break;
521 case neg: {
522 prl(createStartVar("tempa"));
523 prl(createTopEStack());
524 prl(createToEStack("-tempa"));
525 prl(createEndVar());
526 break;
529 case shl: {
530 prl(createStartVar("tempa", "tempb"));
531 prl(createTopTwoEStack());
532 prl("VAR <tempres :=tempb, i:=1 >:");
533 prl("\tFOR i:=1 TO tempa STEP 1 DO tempres := tempres * 2 OD;");
534 prl(createToEStack("tempres"));
535 prl("ENDVAR;");
536 prl(createEndVar());
537 break;
539 case shr: {
540 prl(createStartVar("tempa", "tempb"));
541 prl(createTopTwoEStack());
542 prl("VAR <tempres :=tempb, i:=1 >:");
543 prl("\tFOR i:=1 TO tempa STEP 1 DO tempres := tempres DIV 2 OD;");
544 prl(createToEStack("tempres"));
545 prl("ENDVAR;");
546 prl(createEndVar());
547 break;
550 case inc: {
551 int b1 = get(), b2 = get();
552 prl(createLocal(b1) + " := " + createLocal(b1) + " + " + b2 + ";");
553 break;
556 case new_: {
557 int size = get2();
558 // TODO maybe objects and arrays should be in the same list?
559 prl("mjvm_objects := mjvm_objects ++ < ARRAY(" + size
560 + ",0) >;");
561 prl(createToEStack("LENGTH(mjvm_objects)"));
562 break;
564 case newarray: {
565 get();// 0 - bytes, 1 - words; ignore for now
566 // TODO take into consideration 0/1
567 prl(createStartVar("tempa"));
568 prl(createTopEStack());
569 prl("mjvm_arrays := mjvm_arrays ++ < ARRAY(tempa,0) >;");
570 prl(createToEStack("LENGTH(mjvm_arrays)"));
571 prl(createEndVar());
572 break;
575 case aload:
576 case baload: {
577 prl(createStartVar("tempa", "tempb"));
578 prl(createTopTwoEStack());
579 prl(createToEStack(createArray("tempb") + "[tempa+1]"));
580 prl(createEndVar());
581 break;
583 case astore:
584 case bastore: {
585 prl(createStartVar("tempa", "tempb", "tempres"));
586 prl(createFromEStack("tempres"));
587 prl(createTopTwoEStack());
588 prl("mjvm_arrays[tempb][tempa+1]:=tempres;");
589 prl(createEndVar());
590 break;
592 case arraylength: {
593 prl(createStartVar("tempa", "tempb"));
594 prl(createTopEStack());
595 prl("tempb := LENGTH("+ createArray("tempa") + ");");
596 prl(createToEStack("tempb"));
597 prl(createEndVar());
598 break;
601 case dup: {
602 prl(createStartVar("tempa", "tempb"));
603 prl(createTopEStack());
604 prl(createToEStack("tempa"));
605 prl(createToEStack("tempa"));
606 prl(createEndVar());
607 break;
609 case dup2: {
610 prl(createStartVar("tempa", "tempb"));
611 prl(createTopTwoEStack());
612 prl(createToEStack("tempb"));
613 prl(createToEStack("tempa"));
614 prl(createToEStack("tempb"));
615 prl(createToEStack("tempa"));
616 prl(createEndVar());
617 break;
620 case pop: {
621 prl(createPopEStack());
622 break;
625 case jmp: {
626 prl("CALL a" + (counter + get2()) + ";");
627 break;
630 case jeq:
631 case jne:
632 case jlt:
633 case jle:
634 case jgt:
635 case jge: {
636 prl(createStartVar("tempa", "tempb"));
637 prl(createTopTwoEStack());
638 prl("IF tempb " + getRelationFor(op)
639 + " tempa THEN mjvm_flag_jump := 1"
640 + " ELSE mjvm_flag_jump := 0"
641 + " FI;");
642 prl(createEndVar());
643 prl("IF mjvm_flag_jump = 1 THEN CALL a"
644 + (counter + get2())
645 + " ELSE CALL a" + (counter + 1)
646 + " FI;");
648 break;
651 case call: {
652 prl("CALL a" + (counter + get2()) + ";");
653 break;
656 case return_: {
657 // we let the actions return
658 // there is nothing to clean up
659 prl("SKIP\n END\n b" + counter + " ==");
660 break;
662 case enter: {
663 int parameters = get();
665 int locals = get();
666 prl(createToMStack("mjvm_locals"));
667 prl("mjvm_locals := ARRAY(" + locals + ",0);");
668 for (int i = parameters - 1; i >= 0; i--)
669 prl(createFromEStack(createLocal(i)));
670 break;
672 case exit: {
673 prl(createFromMStack("mjvm_locals"));
674 break;
677 // read, print
678 case bread: {
679 // TODO make it a char for read
680 messages.message("char is read like a number", TransMessages.M_WAR);
681 prl(createComment("char is read like a number", C_SPEC));
683 case read: {
684 prl(createStartVar("tempa"));
685 prl("tempa := @String_To_Num(@Read_Line(Standard_Input_Port));");
686 prl(createToEStack("tempa"));
687 prl(createEndVar());
688 break;
691 // the prints
692 case bprint: {
693 prl(createStartVar("tempa", "tempb"));
694 prl(createTopTwoEStack());
695 if (genInlinePrint){
696 prl(createComment("print spacing and transformation",C_SPEC));
697 prl("PRINFLUSH(SUBSTR(\" \", 0, MIN(10, MAX(0,tempa-1))), @List_To_String(< tempb >));");
698 } else
699 prl("Print_MJ_CHAR(tempb,tempa);");
700 prl(createEndVar());
701 break;
703 case print: {
704 // TODO printing numbers needs different lengths of spacing
705 prl(createStartVar("tempa", "tempb"));
707 prl(createTopTwoEStack());
708 if (genInlinePrint){
709 prl(createComment("print spacing",C_SPEC));
710 prl("PRINFLUSH(SUBSTR(\" \", 0, MIN(10, MAX(0, tempa-1))), tempb);");
712 else
713 prl("Print_MJ(tempb,tempa);");
714 prl(createEndVar());
715 break;
718 case trap: {
719 prl("ERROR(\"Runtime error: trap(" + get() + ")\");");
720 break;
723 default:
724 prl(createComment("unknown op error: " + op, C_ERR));
725 messages.message("unknown op error: " + op, TransMessages.M_ERR);
726 break;
729 boolean wasJump = isJumpCode(op);
730 op = get();
731 if (op >= 0)
732 if (wasJump)
733 prl("SKIP\n END");
734 else
735 prl("CALL a" + counter + "\n END");
737 prl("SKIP\n END\nENDACTIONS;\n");
738 pr(createStandardEnd());
741 public void convertFile(File f) {
742 try {
743 convertStream(new FileInputStream(f));
744 } catch (Exception ex) {
745 ex.printStackTrace();
749 public void printHelp() {
750 printVersion();
751 printUsage();
752 printHelpOutput();
753 printHelpHelp();
756 public void printLongHelp() {
757 printVersion();
758 printUsage();
759 System.out.println();
760 printHelpOutput();
761 System.out.println();
762 printHelpDirectives();
763 System.out.println();
764 printHelpGenerating();
765 System.out.println();
766 printHelpHelp();
769 public void printHelpOutput() {
770 System.out.println("Output options:");
771 System.out.println(" --screen print output to screen");
772 System.out.println(" -o --oc[+-] include original code in comments");
773 System.out.println(" -v verbose, print warning messages");
774 System.out.println(" -q quiet; don't print even the error messages");
775 System.out.println(" -d print detailed debug messages");
778 public void printHelpGenerating() {
779 System.out.println("Options for generating extra code for tracking code execution");
780 System.out.println(" --genEStackPrint generate print for all EStack changes");
781 System.out.println(" --genAddrPrint generate prints after every address of the original code ");
782 System.out.println(" --genAddrPause generate a pause after every address of the original code ");
783 System.out.println(" --genAddr short for --genAddrPrint and --genAddrPause");
784 System.out.println(" --genAll short for applying all code generation");
787 public void printHelpDirectives(){
788 System.out.println("Alternatives for code generation:");
789 System.out.println(" --genPopPush generate POP/PUSH instead of TAIL/HEAD");
792 public void printHelpHelp() {
793 System.out.println("Help and info options");
794 System.out.println(" -h basic help");
795 System.out.println(" --help print more detailed help");
796 System.out.println(" --version or -version print version and exit");
799 public void printUsage(){
800 System.out.println("usage:\n\t mjc2wsl {options} filename [outfile]");
803 public void printVersion() {
804 System.out.println("MicroJava bytecode to WSL converter. v " + versionN
805 + ", by Doni Pracner");
808 public String makeDefaultOutName(String inname){
809 String rez = inname;
810 if (inname.endsWith(".obj"))
811 rez = rez.substring(0, rez.length() - 4);
812 return rez + ".wsl";
815 public void run(String[] args) {
816 if (args.length == 0) {
817 printHelp();
818 } else {
819 int i = 0;
820 while (i < args.length && args[i].charAt(0) == '-') {
821 if (args[i].compareTo("-h") == 0) {
822 printHelp();
823 return;
824 } else if (args[i].compareTo("--help") == 0) {
825 printLongHelp();
826 return;
827 } else if (args[i].compareTo("--version") == 0
828 || args[i].compareTo("-version") == 0) {
829 printVersion();
830 return;
831 } else if (args[i].compareTo("-o") == 0
832 || args[i].startsWith("--oc")) {
833 if (args[i].length() == 2)
834 originalInComments = true;
835 else if (args[i].length() == 5)
836 originalInComments = args[i].charAt(4) == '+';
837 else
838 originalInComments = true;
839 } else if (args[i].compareTo("--screen") == 0) {
840 out = new PrintWriter(System.out);
841 } else if (args[i].compareTo("-d") == 0) {
842 messages.setPrintLevel(TransMessages.M_DEB);// print debug info
843 } else if (args[i].compareTo("-v") == 0) {
844 messages.setPrintLevel(TransMessages.M_WAR);// print warnings
845 } else if (args[i].compareTo("-q") == 0) {
846 messages.setPrintLevel(TransMessages.M_QUIET);// no printing
847 } else if (args[i].compareToIgnoreCase("--genEStackPrint") == 0) {
848 genPrintEStackOnChange = true;
849 } else if (args[i].compareToIgnoreCase("--genAddrPause") == 0) {
850 genPauseAfterEachAddress = true;
851 } else if (args[i].compareToIgnoreCase("--genAddrPrint") == 0) {
852 genPrintForEachAddress = true;
853 } else if (args[i].compareToIgnoreCase("--genAddr") == 0) {
854 genPrintForEachAddress = true;
855 genPauseAfterEachAddress = true;
856 } else if (args[i].compareToIgnoreCase("--genAll") == 0) {
857 genPrintEStackOnChange = true;
858 genPrintForEachAddress = true;
859 genPauseAfterEachAddress = true;
860 } else if (args[i].compareToIgnoreCase("--genPopPush") == 0) {
861 genPopPush = true;
862 } else if (args[i].compareToIgnoreCase("--genInlinePrint") == 0) {
863 genInlinePrint = true;
865 i++;
868 if (i >= args.length) {
869 System.out.println("no filename supplied");
870 System.exit(2);
872 File f = new File(args[i]);
874 if (i + 1 < args.length) {
875 try {
876 out = new PrintWriter(args[i + 1]);
877 } catch (Exception e) {
878 System.err.println("error in opening out file:");
879 e.printStackTrace();
882 if (out == null) {
883 // if not set to screen, or a file, make a default filename
884 try {
885 out = new PrintWriter(makeDefaultOutName(args[i]));
886 } catch (Exception e) {
887 System.err.println("error in opening out file:");
888 e.printStackTrace();
891 if (f.exists()) {
892 Calendar now = Calendar.getInstance();
893 convertFile(f);
894 long mili = Calendar.getInstance().getTimeInMillis()
895 - now.getTimeInMillis();
896 System.out.println("conversion time:" + mili + " ms");
897 messages.printMessageCounters();
898 out.close();
899 } else
900 System.out.println("file does not exist");
904 public static void main(String[] args) {
905 new mjc2wsl().run(args);
Svarog.pmf.uns.ac.rs/gitweb maintanance Doni Pracner