X-Git-Url: http://svarog.pmf.uns.ac.rs/gitweb/?p=mjc2wsl.git;a=blobdiff_plain;f=src%2Fcom%2Fquemaster%2Ftransformations%2Fmjc2wsl%2Fmjc2wsl.java;h=26452e802f4b3afb5c92775d9316b322f187af5a;hp=4522d6502796e780d42eb09e6f7e1598c74c2840;hb=496e04d39934d3304e811af55b7e9911c1c46873;hpb=215cc953e6fd7896f0876c66d0de1428d8d1ba7b diff --git a/src/com/quemaster/transformations/mjc2wsl/mjc2wsl.java b/src/com/quemaster/transformations/mjc2wsl/mjc2wsl.java index 4522d65..26452e8 100644 --- a/src/com/quemaster/transformations/mjc2wsl/mjc2wsl.java +++ b/src/com/quemaster/transformations/mjc2wsl/mjc2wsl.java @@ -17,8 +17,16 @@ package com.quemaster.transformations.mjc2wsl; You should have received a copy of the GNU General Public License along with mjc2wsl. If not, see . */ -import java.io.*; -import java.util.*; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.PrintWriter; +import java.nio.file.FileSystems; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Calendar; +import java.util.Properties; import com.quemaster.transformations.TransMessages; @@ -34,7 +42,7 @@ public class mjc2wsl{ //default version name, used if the file is not found private static String versionN = "0.1.x"; - private String versionFile = "version.properties"; + private String versionFile = "/version.properties"; private TransMessages messages = new TransMessages(); @@ -44,7 +52,9 @@ public class mjc2wsl{ private boolean genPopPush=false; - private boolean genInlinePrint=false; + private boolean genInlinePrint = false; + + private boolean genLocalVars = true; /** Constant used for marking a regular comment from the original file */ public static final char C_REG = ' '; @@ -170,6 +180,9 @@ public class mjc2wsl{ ret.append("\nBEGIN"); ret.append("\nVAR <\n\t"); + if (!genLocalVars){ + ret.append("\n\ttempa := 0, tempb :=0, tempres := 0,"); + } ret.append("mjvm_locals := ARRAY(1,0),"); ret.append("\n\tmjvm_statics := ARRAY("+numWords+",0),"); ret.append("\n\tmjvm_arrays := < >,"); @@ -216,17 +229,23 @@ public class mjc2wsl{ } private String createStartVar(String... vars){ - StringBuilder ret = new StringBuilder("VAR < "); - ret.append(vars[0] + " := 0"); - for (int i=1; i : "); - - return ret.toString(); + if (genLocalVars) { + StringBuilder ret = new StringBuilder("VAR < "); + ret.append(vars[0] + " := 0"); + for (int i = 1; i < vars.length; i++) + ret.append(", " + vars[i] + " := 0"); + ret.append(" > : "); + + return ret.toString(); + } + return ""; } private String createEndVar(){ - return "ENDVAR;"; + if (genLocalVars) + return "ENDVAR;"; + else + return ""; } private String createLocal(int i) { @@ -735,12 +754,21 @@ public class mjc2wsl{ } public void printHelpDirectives(){ - System.out.println("Alternatives for code generation:"); - System.out.println(" --genPopPush generate POP/PUSH instead of TAIL/HEAD"); - System.out.println(" --genHeadTail generate TAIL/HEAD instead of POP/PUSH "); + System.out.println("Alternatives for code generation (* are the defaults):"); + System.out.print(genPopPush?'*':' '); + System.out.println(" --genPopPush generate POP/PUSH instead of TAIL/HEAD"); + System.out.print(!genPopPush?'*':' '); + System.out.println(" --genHeadTail generate TAIL/HEAD instead of POP/PUSH "); System.out.println(); - System.out.println(" --genInlinePrint generate prints directly instead of procedure calls"); - System.out.println(" --genProcedurePrint generate prints as custom procedure calls"); + System.out.print(genInlinePrint?'*':' '); + System.out.println(" --genInlinePrint generate prints directly instead of procedure calls"); + System.out.print(!genInlinePrint?'*':' '); + System.out.println(" --genProcedurePrint generate prints as custom procedure calls"); + System.out.println(); + System.out.print(genLocalVars?'*':' '); + System.out.println(" --genLocalVars generate local VAR block for temp variables"); + System.out.print(!genLocalVars?'*':' '); + System.out.println(" --genGlobalVars do NOT generate local VAR block for temp variables"); } public void printHelpHelp() { @@ -819,15 +847,24 @@ public class mjc2wsl{ genPopPush = false; } else if (args[i].compareToIgnoreCase("--genProcedurePrint") == 0) { genInlinePrint = false; + } else if (args[i].compareToIgnoreCase("--genLocalVars") == 0) { + genLocalVars = true; + } else if (args[i].compareToIgnoreCase("--genGlobalVars") == 0) { + genLocalVars = false; } i++; } if (i >= args.length) { - System.out.println("no filename supplied"); + System.err.println("no filename supplied"); System.exit(2); } - File f = new File(args[i]); + + Path p = FileSystems.getDefault().getPath(args[i]); + if (!Files.exists(p)){ + System.err.println("input file does not exist"); + System.exit(1); + } if (i + 1 < args.length) { try { @@ -846,16 +883,18 @@ public class mjc2wsl{ e.printStackTrace(); } } - if (f.exists()) { - Calendar now = Calendar.getInstance(); - convertFile(f); - long mili = Calendar.getInstance().getTimeInMillis() - - now.getTimeInMillis(); - System.out.println("conversion time:" + mili + " ms"); - messages.printMessageCounters(); - out.close(); - } else - System.out.println("file does not exist"); + Calendar now = Calendar.getInstance(); + try { + convertStream(Files.newInputStream(p)); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + long mili = Calendar.getInstance().getTimeInMillis() + - now.getTimeInMillis(); + System.out.println("conversion time:" + mili + " ms"); + messages.printMessageCounters(); + out.close(); } }