X-Git-Url: http://git.megacz.com/?p=nestedvm.git;a=blobdiff_plain;f=src%2Forg%2Fibex%2Fnestedvm%2FCompiler.java;h=c16a18f27b9da7e612a955f2bb4c4361d7a6d547;hp=7a1eb4387f31f296acbe6c84e7ff47f38aa35b0f;hb=b7956688249a89b71e4873cdff862631e4b3704a;hpb=6ca8e846620f8c46811c8417b6f9b7f05d79a706 diff --git a/src/org/ibex/nestedvm/Compiler.java b/src/org/ibex/nestedvm/Compiler.java index 7a1eb43..c16a18f 100644 --- a/src/org/ibex/nestedvm/Compiler.java +++ b/src/org/ibex/nestedvm/Compiler.java @@ -7,8 +7,6 @@ import java.io.*; import org.ibex.nestedvm.util.*; -// FEATURE: -d option for classfilecompiler (just like javac's -d) - public abstract class Compiler implements Registers { /** The ELF binary being read */ ELF elf; @@ -101,6 +99,7 @@ public abstract class Compiler implements Registers { public static void main(String[] args) throws IOException { String outfile = null; + String outdir = null; String o = null; String className = null; String mipsBinaryFileName = null; @@ -112,6 +111,10 @@ public abstract class Compiler implements Registers { arg++; if(arg==args.length) usage(); outfile = args[arg]; + } else if(args[arg].equals("-d")) { + arg++; + if(arg==args.length) usage(); + outdir = args[arg]; } else if(args[arg].equals("-outformat")) { arg++; if(arg==args.length) usage(); @@ -142,12 +145,20 @@ public abstract class Compiler implements Registers { OutputStream os = null; Compiler comp = null; if(outformat == null || outformat.equals("class")) { - if(outfile == null) { + if(outfile != null) { + os = new FileOutputStream(outfile); + comp = new ClassFileCompiler(mipsBinary,className,os); + } else if(outdir != null) { + File f = new File(outdir); + if(!f.isDirectory()) { + System.err.println(outdir + " doesn't exist or is not a directory"); + System.exit(1); + } + comp = new ClassFileCompiler(mipsBinary,className,f); + } else { System.err.println("Refusing to write a classfile to stdout - use -outfile foo.class"); System.exit(1); } - os = new FileOutputStream(outfile); - comp = new ClassFileCompiler(mipsBinary,className,os); } else if(outformat.equals("javasource") || outformat .equals("java")) { w = outfile == null ? new OutputStreamWriter(System.out): new FileWriter(outfile); comp = new JavaSourceCompiler(mipsBinary,className,w);