gitweb on Svarog

projekti pod git sistemom za održavanje verzija -- projects under the git version control system
f754e4ef1d6c3cf719ca58c08bdb80fa06466ccf
[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 /** Constant used for marking a regular comment from the original file */
42 public static final char C_REG = ' ';
43 /**
44 * Constant used for marking when original code is inserted in the file,
45 * next to the translations
46 */
47 public static final char C_OC = '#';
48 /** Constant used for marking special messages from the translator */
49 public static final char C_SPEC = '&';
50 /** Constant used for marking error messages from the translator */
51 public static final char C_ERR = '!';
53 /** instruction code in MicroJava bytecode. */
54 public static final int
55 load = 1,
56 load_0 = 2,
57 load_1 = 3,
58 load_2 = 4,
59 load_3 = 5,
60 store = 6,
61 store_0 = 7,
62 store_1 = 8,
63 store_2 = 9,
64 store_3 = 10,
65 getstatic = 11,
66 putstatic = 12,
67 getfield = 13,
68 putfield = 14,
69 const_0 = 15,
70 const_1 = 16,
71 const_2 = 17,
72 const_3 = 18,
73 const_4 = 19,
74 const_5 = 20,
75 const_m1 = 21,
76 const_ = 22,
77 add = 23,
78 sub = 24,
79 mul = 25,
80 div = 26,
81 rem = 27,
82 neg = 28,
83 shl = 29,
84 shr = 30,
85 inc = 31,
86 new_ = 32,
87 newarray = 33,
88 aload = 34,
89 astore = 35,
90 baload = 36,
91 bastore = 37,
92 arraylength = 38,
93 pop = 39,
94 dup = 40,
95 dup2 = 41,
96 jmp = 42,
97 jeq = 43,
98 jne = 44,
99 jlt = 45,
100 jle = 46,
101 jgt = 47,
102 jge = 48,
103 call = 49,
104 return_ = 50,
105 enter = 51,
106 exit = 52,
107 read = 53,
108 print = 54,
109 bread = 55,
110 bprint = 56,
111 trap = 57;
113 private boolean originalInComments = false;
115 private HashMap<Integer,String> opMap = null;
117 private String opCodeFile = "mj-bytecodes.properties";
119 private HashMap<Integer, String> getOpMap() {
120 if (opMap == null) {
121 opMap = new HashMap<Integer, String>(60, 0.98f);
122 try {
123 BufferedReader in = new BufferedReader(new InputStreamReader(
124 getClass().getResourceAsStream(opCodeFile)));
125 String str = in.readLine();
126 while (str != null) {
127 String[] ss = str.split("=");
128 opMap.put(Integer.parseInt(ss[0]), ss[1]);
129 str = in.readLine();
131 in.close();
132 } catch (Exception ex) {
133 ex.printStackTrace();
136 return opMap;
139 public String getOpString(int op) {
140 return getOpMap().get(op);
143 public String describeOpCode(int op) {
144 return op + " (" + getOpString(op) + ")";
147 private InputStream mainIn;
148 private PrintWriter out = null;
149 private int counter = -1;
151 private void pr(int i){
152 out.print(i);
155 private void pr(char i){
156 out.print(i);
159 private void pr(String i){
160 out.print(i);
163 private void prl(String i){
164 out.println(i);
167 private int get() {
168 int res = -1;
169 try {
170 res = mainIn.read();
171 if (res >= 0)
172 res = res << 24 >>> 24;
173 } catch (IOException ex) {
174 ex.printStackTrace();
176 counter++;
177 return res;
180 private int get2() {
181 return (get() * 256 + get()) << 16 >> 16;
184 private int get4() {
185 return (get2() << 16) + (get2() << 16 >>> 16);
188 public String createStandardStart(){
189 return createStandardStart(10);
192 public String createStandardStart(int numWords){
193 StringBuilder ret = new StringBuilder(
194 "C:\" This file automatically converted from microjava bytecode\";\n"
195 +"C:\" with mjc2wsl v "+versionN+"\";\n");
197 ret.append("\nBEGIN");
198 ret.append("\nVAR <\n\t");
199 ret.append("mjvm_locals := ARRAY(1,0),");
200 ret.append("\n\tmjvm_statics := ARRAY("+numWords+",0),");
201 ret.append("\n\tmjvm_arrays := < >,");
202 ret.append("\n\tmjvm_flag_jump := 0,");
203 ret.append("\n\tmjvm_objects := < >,");
204 ret.append("\n\tmjvm_estack := < >, mjvm_mstack := < > > :");
206 return ret.toString();
209 public String createAsciiString(){
210 StringBuilder ret = new StringBuilder("C:\"char array for ascii code conversions\";");
211 ret.append("\nascii := \"????????????????????????????????\"++\n");
212 ret.append("\" !\"++Quote++\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\";\n");
214 return ret.toString();
217 public String createStandardEnd(){
218 StringBuilder ret = new StringBuilder("SKIP\nENDVAR\n");
219 ret.append("\nWHERE\n");
221 ret.append("\nFUNCT CHR(num) ==:\n");
222 ret.append("\t@List_To_String(< num >)\n");
223 ret.append("END\n");
225 ret.append("\nPROC Print_MJ(val, format VAR)==\n");
226 ret.append(createComment("print spacing", C_SPEC));
227 ret.append("\n\tIF format>1 THEN\n\t\tFOR i:=2 TO ");
228 ret.append("format STEP 1 DO PRINFLUSH(\" \") OD\n");
229 ret.append("\tFI;\n\tPRINFLUSH(val)\nEND\n");
231 ret.append("\nPROC Print_MJ_CHAR(val, format VAR)==\n");
232 ret.append(createComment("print spacing", C_SPEC));
233 ret.append("\n\tIF format>1 THEN\n\t\tFOR i:=2 TO ");
234 ret.append("format STEP 1 DO PRINFLUSH(\" \") OD\n");
235 ret.append("\tFI;\n\tPRINFLUSH(CHR(val))\n");
236 ret.append("END\n");
238 ret.append("\nEND");
239 return ret.toString();
242 private String createStartVar(String... vars){
243 StringBuilder ret = new StringBuilder("VAR < ");
244 ret.append(vars[0] + " := 0");
245 for (int i=1; i<vars.length; i++)
246 ret.append(", "+ vars[i] +" := 0");
247 ret.append(" > : ");
249 return ret.toString();
252 private String createEndVar(){
253 return "ENDVAR;";
256 private String createLocal(int i) {
257 // arrays start at 1 in WSL, so we need an offset
258 return "mjvm_locals[" + (i + 1) + "]";
261 private String createStatic(int i) {
262 return "mjvm_statics[" + (i + 1) + "]";
265 private String createArray(int i) {
266 return "mjvm_arrays[" + i + "]";
269 private String createArray(String i) {
270 return "mjvm_arrays[" + i + "]";
273 private String createObject(String i) {
274 return "mjvm_objects[" + i + "]";
277 /**
278 * Creates a WSL comment with care to quote chars.
279 */
280 public static String createComment(String str){
281 return createComment(str, C_REG);
284 /**
285 * Creates a WSL comment with care to quote chars, of the
286 * given type. Types are given as char constants. They can be
287 * default comments, comments that contain the original code
288 * in them, or additional comments regarding the translation
289 * process.
290 */
291 public static String createComment(String str, char type) {
292 return "C:\"" + type + str.replace("\"", "''") + "\";";
295 // generalised stack operations
297 private String createToStack(String stack, String var){
298 if (genPopPush)
299 return "PUSH("+stack+"," + var + ");";
300 else
301 return stack + " := <" + var + " > ++ " + stack +";";
304 private String createFromStack(String stack, String var){
305 if (genPopPush)
306 return "POP("+ var + ", "+stack+");";
307 else
308 return var + ":= HEAD("+stack+"); "+stack+" := TAIL("+stack+");";
310 //Expression stack
312 private String createToEStack(int i) {
313 return createToEStack(i+"");
316 private String createToEStack(String i) {
317 String res = createToStack("mjvm_estack", i);
318 if (genPrintEStackOnChange)
319 res += "PRINT(\"eStack\",mjvm_estack);";
320 return res;
323 private String createFromEStack(String st) {
324 String res = createFromStack("mjvm_estack",st);
325 if (genPrintEStackOnChange)
326 res += "PRINT(\"eStack\",mjvm_estack);";
327 return res;
330 private String createPopEStack() {
331 String res = "mjvm_estack := TAIL(mjvm_estack);";
332 if (genPrintEStackOnChange)
333 res += "PRINT(\"eStack\",mjvm_estack);";
334 return res;
337 private String createTopTwoEStack() {
338 return createFromEStack("tempa") + "\n" + createFromEStack("tempb");
341 private String createTopEStack() {
342 return createFromEStack("tempa");
345 //Method stack
347 private String createToMStack(int i) {
348 return createToMStack(i+"");
351 private String createToMStack(String i) {
352 return createToStack("mjvm_mstack", i);
355 private String createFromMStack(String st) {
356 return createFromStack("mjvm_mstack", st);
359 private String getRelationFor(int opcode) throws Exception {
360 switch (opcode) {
361 case jeq: return "=";
362 case jne: return "<>";
363 case jlt: return "<";
364 case jle: return "<=";
365 case jgt: return ">";
366 case jge: return ">=";
368 throw new Exception("Wrong opcode for a relation");
371 private boolean isJumpCode(int opcode) {
372 return (opcode >= jmp) && (opcode <= jge);
375 public void convertStream(InputStream ins) throws Exception{
376 mainIn = ins;
377 //process start
378 byte m = (byte) get();
379 byte j = (byte) get();
380 if (m!='M' || j !='J')
381 throw new Exception("Wrong start of bytecode file");
382 int codesize = get4();
383 int numberOfWords = get4();
384 int mainAdr = get4();
386 prl(createStandardStart(numberOfWords));
387 prl("SKIP;\n ACTIONS a" + (14 + mainAdr) + " :");
388 int op = get();
389 while (op >= 0) {
390 prl(" a" + counter + " ==");
391 if (originalInComments)
392 prl(createComment(describeOpCode(op), C_OC));
393 if (genPrintForEachAddress) {
394 prl("PRINT(\"a" + counter + "\");");
395 if (genPauseAfterEachAddress)
396 prl("debug_disposable_string := @Read_Line(Standard_Input_Port);");
398 switch (op) {
399 case load: {
400 prl(createToEStack(createLocal(get())));
401 break;
403 case load_0:
404 case load_1:
405 case load_2:
406 case load_3: {
407 prl(createStartVar("tempa"));
408 prl("tempa :="+createLocal(op - load_0)+";");
409 prl(createToEStack("tempa"));
410 prl(createEndVar());
411 break;
413 case store: {
414 prl(createFromEStack(createLocal(get())));
415 break;
417 case store_0:
418 case store_1:
419 case store_2:
420 case store_3: {
421 prl(createStartVar("tempa"));
422 prl(createFromEStack("tempa"));
423 prl(createLocal(op - store_0)+" := tempa;");
424 prl(createEndVar());
425 break;
428 case getstatic: {
429 prl(createToEStack(createStatic(get2())));
430 break;
432 case putstatic: {
433 prl(createFromEStack(createStatic(get2())));
434 break;
437 case getfield: {
438 int f = get2();
439 prl(createStartVar("tempa"));
440 prl(createTopEStack());
441 prl(createToEStack(createObject("tempa") + "[" + (f + 1) + "]"));
442 prl(createEndVar());
443 break;
445 case putfield: {
446 int f = get2();
447 prl(createStartVar("tempa", "tempb"));
448 prl(createTopTwoEStack());
449 prl(createObject("tempb") + "[" + (f + 1) + "]:=tempa;");
450 prl(createEndVar());
451 break;
454 case const_: {
455 prl(createToEStack(get4()));
456 break;
459 case const_m1: {
460 prl(createToEStack(-1));
461 break;
464 case const_0:
465 case const_1:
466 case const_2:
467 case const_3:
468 case const_4:
469 case const_5: {
470 prl(createToEStack(op - const_0));
471 break;
474 case add: {
475 prl(createStartVar("tempa", "tempb", "tempres"));
476 prl(createTopTwoEStack());
477 prl("tempres := tempb + tempa;");
478 prl(createToEStack("tempres"));
479 prl(createEndVar());
480 break;
482 case sub: {
483 prl(createStartVar("tempa", "tempb", "tempres"));
484 prl(createTopTwoEStack());
485 prl("tempres := tempb - tempa;");
486 prl(createToEStack("tempres"));
487 prl(createEndVar());
488 break;
490 case mul: {
491 prl(createStartVar("tempa", "tempb", "tempres"));
492 prl(createTopTwoEStack());
493 prl("tempres := tempb * tempa;");
494 prl(createToEStack("tempres"));
495 prl(createEndVar());
496 break;
498 case div: {
499 prl(createStartVar("tempa", "tempb", "tempres"));
500 prl(createTopTwoEStack());
501 prl("IF tempa = 0 THEN ERROR(\"division by zero\") FI;");
502 prl("tempres := tempb DIV tempa;");
503 prl(createToEStack("tempres"));
504 prl(createEndVar());
505 break;
507 case rem: {
508 prl(createStartVar("tempa", "tempb", "tempres"));
509 prl(createTopTwoEStack());
510 prl("IF tempa = 0 THEN ERROR(\"division by zero\") FI;");
511 prl("tempres := tempb MOD tempa;");
512 prl(createToEStack("tempres"));
513 prl(createEndVar());
514 break;
517 case neg: {
518 prl(createStartVar("tempa"));
519 prl(createTopEStack());
520 prl(createToEStack("-tempa"));
521 prl(createEndVar());
522 break;
525 case shl: {
526 prl(createStartVar("tempa", "tempb"));
527 prl(createTopTwoEStack());
528 prl("VAR <tempres :=tempb, i:=1 >:");
529 prl("\tFOR i:=1 TO tempa STEP 1 DO tempres := tempres * 2 OD;");
530 prl(createToEStack("tempres"));
531 prl("ENDVAR;");
532 prl(createEndVar());
533 break;
535 case shr: {
536 prl(createStartVar("tempa", "tempb"));
537 prl(createTopTwoEStack());
538 prl("VAR <tempres :=tempb, i:=1 >:");
539 prl("\tFOR i:=1 TO tempa STEP 1 DO tempres := tempres DIV 2 OD;");
540 prl(createToEStack("tempres"));
541 prl("ENDVAR;");
542 prl(createEndVar());
543 break;
546 case inc: {
547 int b1 = get(), b2 = get();
548 prl(createLocal(b1) + " := " + createLocal(b1) + " + " + b2 + ";");
549 break;
552 case new_: {
553 int size = get2();
554 // TODO maybe objects and arrays should be in the same list?
555 prl("mjvm_objects := mjvm_objects ++ < ARRAY(" + size
556 + ",0) >;");
557 prl(createToEStack("LENGTH(mjvm_objects)"));
558 break;
560 case newarray: {
561 get();// 0 - bytes, 1 - words; ignore for now
562 // TODO take into consideration 0/1
563 prl(createStartVar("tempa"));
564 prl(createTopEStack());
565 prl("mjvm_arrays := mjvm_arrays ++ < ARRAY(tempa,0) >;");
566 prl(createToEStack("LENGTH(mjvm_arrays)"));
567 prl(createEndVar());
568 break;
571 case aload:
572 case baload: {
573 prl(createStartVar("tempa", "tempb"));
574 prl(createTopTwoEStack());
575 prl(createToEStack(createArray("tempb") + "[tempa+1]"));
576 prl(createEndVar());
577 break;
579 case astore:
580 case bastore: {
581 prl(createStartVar("tempa", "tempb", "tempres"));
582 prl(createFromEStack("tempres"));
583 prl(createTopTwoEStack());
584 prl("mjvm_arrays[tempb][tempa+1]:=tempres;");
585 prl(createEndVar());
586 break;
588 case arraylength: {
589 prl(createStartVar("tempa", "tempb"));
590 prl(createTopEStack());
591 prl("tempb := LENGTH("+ createArray("tempa") + ");");
592 prl(createToEStack("tempb"));
593 prl(createEndVar());
594 break;
597 case dup: {
598 prl(createStartVar("tempa", "tempb"));
599 prl(createTopEStack());
600 prl(createToEStack("tempa"));
601 prl(createToEStack("tempa"));
602 prl(createEndVar());
603 break;
605 case dup2: {
606 prl(createStartVar("tempa", "tempb"));
607 prl(createTopTwoEStack());
608 prl(createToEStack("tempb"));
609 prl(createToEStack("tempa"));
610 prl(createToEStack("tempb"));
611 prl(createToEStack("tempa"));
612 prl(createEndVar());
613 break;
616 case pop: {
617 prl(createPopEStack());
618 break;
621 case jmp: {
622 prl("CALL a" + (counter + get2()) + ";");
623 break;
626 case jeq:
627 case jne:
628 case jlt:
629 case jle:
630 case jgt:
631 case jge: {
632 prl(createStartVar("tempa", "tempb"));
633 prl(createTopTwoEStack());
634 prl("IF tempb " + getRelationFor(op)
635 + " tempa THEN mjvm_flag_jump := 1"
636 + " ELSE mjvm_flag_jump := 0"
637 + " FI;");
638 prl(createEndVar());
639 prl("IF mjvm_flag_jump = 1 THEN CALL a"
640 + (counter + get2())
641 + " ELSE CALL a" + (counter + 1)
642 + " FI;");
644 break;
647 case call: {
648 prl("CALL a" + (counter + get2()) + ";");
649 break;
652 case return_: {
653 // we let the actions return
654 // there is nothing to clean up
655 prl("SKIP\n END\n b" + counter + " ==");
656 break;
658 case enter: {
659 int parameters = get();
661 int locals = get();
662 prl(createToMStack("mjvm_locals"));
663 prl("mjvm_locals := ARRAY(" + locals + ",0);");
664 for (int i = parameters - 1; i >= 0; i--)
665 prl(createFromEStack(createLocal(i)));
666 break;
668 case exit: {
669 prl(createFromMStack("mjvm_locals"));
670 break;
673 // read, print
674 case bread: {
675 // TODO make it a char for read
676 messages.message("char is read like a number", TransMessages.M_WAR);
677 prl(createComment("char is read like a number", C_SPEC));
679 case read: {
680 prl(createStartVar("tempa"));
681 prl("tempa := @String_To_Num(@Read_Line(Standard_Input_Port));");
682 prl(createToEStack("tempa"));
683 prl(createEndVar());
684 break;
687 // the prints
688 case bprint: {
689 prl(createStartVar("tempa", "tempb"));
690 prl(createTopTwoEStack());
691 prl("Print_MJ_CHAR(tempb,tempa);");
692 prl(createEndVar());
693 break;
695 case print: {
696 // TODO printing numbers needs different lengths of spacing
697 prl(createStartVar("tempa", "tempb"));
699 prl(createTopTwoEStack());
700 prl("Print_MJ(tempb,tempa);");
701 prl(createEndVar());
702 break;
705 case trap: {
706 prl("ERROR(\"Runtime error: trap(" + get() + ")\");");
707 break;
710 default:
711 prl(createComment("unknown op error: " + op, C_ERR));
712 messages.message("unknown op error: " + op, TransMessages.M_ERR);
713 break;
716 boolean wasJump = isJumpCode(op);
717 op = get();
718 if (op >= 0)
719 if (wasJump)
720 prl("SKIP\n END");
721 else
722 prl("CALL a" + counter + "\n END");
724 prl("SKIP\n END\nENDACTIONS;\n");
725 pr(createStandardEnd());
728 public void convertFile(File f) {
729 try {
730 convertStream(new FileInputStream(f));
731 } catch (Exception ex) {
732 ex.printStackTrace();
736 public void printHelp() {
737 printVersion();
738 printUsage();
739 printHelpOutput();
740 printHelpHelp();
743 public void printLongHelp() {
744 printVersion();
745 printUsage();
746 System.out.println();
747 printHelpOutput();
748 System.out.println();
749 printHelpDirectives();
750 System.out.println();
751 printHelpGenerating();
752 System.out.println();
753 printHelpHelp();
756 public void printHelpOutput() {
757 System.out.println("Output options:");
758 System.out.println(" --screen print output to screen");
759 System.out.println(" -o --oc[+-] include original code in comments");
760 System.out.println(" -v verbose, print warning messages");
761 System.out.println(" -q quiet; don't print even the error messages");
762 System.out.println(" -d print detailed debug messages");
765 public void printHelpGenerating() {
766 System.out.println("Options for generating extra code for tracking code execution");
767 System.out.println(" --genEStackPrint generate print for all EStack changes");
768 System.out.println(" --genAddrPrint generate prints after every address of the original code ");
769 System.out.println(" --genAddrPause generate a pause after every address of the original code ");
770 System.out.println(" --genAddr short for --genAddrPrint and --genAddrPause");
771 System.out.println(" --genAll short for applying all code generation");
774 public void printHelpDirectives(){
775 System.out.println("Alternatives for code generation:");
776 System.out.println(" --genPopPush generate POP/PUSH instead of TAIL/HEAD");
779 public void printHelpHelp() {
780 System.out.println("Help and info options");
781 System.out.println(" -h basic help");
782 System.out.println(" --help print more detailed help");
783 System.out.println(" --version or -version print version and exit");
786 public void printUsage(){
787 System.out.println("usage:\n\t mjc2wsl {options} filename [outfile]");
790 public void printVersion() {
791 System.out.println("MicroJava bytecode to WSL converter. v " + versionN
792 + ", by Doni Pracner");
795 public String makeDefaultOutName(String inname){
796 String rez = inname;
797 if (inname.endsWith(".obj"))
798 rez = rez.substring(0, rez.length() - 4);
799 return rez + ".wsl";
802 public void run(String[] args) {
803 if (args.length == 0) {
804 printHelp();
805 } else {
806 int i = 0;
807 while (i < args.length && args[i].charAt(0) == '-') {
808 if (args[i].compareTo("-h") == 0) {
809 printHelp();
810 return;
811 } else if (args[i].compareTo("--help") == 0) {
812 printLongHelp();
813 return;
814 } else if (args[i].compareTo("--version") == 0
815 || args[i].compareTo("-version") == 0) {
816 printVersion();
817 return;
818 } else if (args[i].compareTo("-o") == 0
819 || args[i].startsWith("--oc")) {
820 if (args[i].length() == 2)
821 originalInComments = true;
822 else if (args[i].length() == 5)
823 originalInComments = args[i].charAt(4) == '+';
824 else
825 originalInComments = true;
826 } else if (args[i].compareTo("--screen") == 0) {
827 out = new PrintWriter(System.out);
828 } else if (args[i].compareTo("-d") == 0) {
829 messages.setPrintLevel(TransMessages.M_DEB);// print debug info
830 } else if (args[i].compareTo("-v") == 0) {
831 messages.setPrintLevel(TransMessages.M_WAR);// print warnings
832 } else if (args[i].compareTo("-q") == 0) {
833 messages.setPrintLevel(TransMessages.M_QUIET);// no printing
834 } else if (args[i].compareToIgnoreCase("--genEStackPrint") == 0) {
835 genPrintEStackOnChange = true;
836 } else if (args[i].compareToIgnoreCase("--genAddrPause") == 0) {
837 genPauseAfterEachAddress = true;
838 } else if (args[i].compareToIgnoreCase("--genAddrPrint") == 0) {
839 genPrintForEachAddress = true;
840 } else if (args[i].compareToIgnoreCase("--genAddr") == 0) {
841 genPrintForEachAddress = true;
842 genPauseAfterEachAddress = true;
843 } else if (args[i].compareToIgnoreCase("--genAll") == 0) {
844 genPrintEStackOnChange = true;
845 genPrintForEachAddress = true;
846 genPauseAfterEachAddress = true;
847 } else if (args[i].compareToIgnoreCase("--genPopPush") == 0) {
848 genPopPush = true;
850 i++;
853 if (i >= args.length) {
854 System.out.println("no filename supplied");
855 System.exit(2);
857 File f = new File(args[i]);
859 if (i + 1 < args.length) {
860 try {
861 out = new PrintWriter(args[i + 1]);
862 } catch (Exception e) {
863 System.err.println("error in opening out file:");
864 e.printStackTrace();
867 if (out == null) {
868 // if not set to screen, or a file, make a default filename
869 try {
870 out = new PrintWriter(makeDefaultOutName(args[i]));
871 } catch (Exception e) {
872 System.err.println("error in opening out file:");
873 e.printStackTrace();
876 if (f.exists()) {
877 Calendar now = Calendar.getInstance();
878 convertFile(f);
879 long mili = Calendar.getInstance().getTimeInMillis()
880 - now.getTimeInMillis();
881 System.out.println("conversion time:" + mili + " ms");
882 messages.printMessageCounters();
883 out.close();
884 } else
885 System.out.println("file does not exist");
889 public static void main(String[] args) {
890 new mjc2wsl().run(args);
Svarog.pmf.uns.ac.rs/gitweb maintanance Doni Pracner