1 30 import java.io.FileOutputStream ; 31 import java.io.FileReader ; 32 import java.io.IOException ; 33 import java.io.PrintWriter ; 34 35 import org.objectweb.asm.ClassWriter; 36 import org.objectweb.asm.jbfc.BFCompiler; 37 import org.objectweb.asm.util.TraceClassVisitor; 38 39 45 public class jbfc { 46 47 public static void main(String [] args) throws IOException { 48 if (args.length < 2) { 49 System.out.println("Usage: jbfc [-v] <bf program file> <java class name>"); 50 return; 51 } 52 53 boolean verbose = false; 54 String fileName = null; 55 String className = null; 56 for (int i = 0; i < args.length; i++) { 57 if ("-v".equals(args[i])) { 58 verbose = true; 59 } else { 60 fileName = args[i]; 61 className = args[i + 1]; 62 break; 63 } 64 } 65 66 FileReader r = new FileReader (fileName); 67 68 ClassWriter cw = new ClassWriter(true); 69 BFCompiler c = new BFCompiler(); 70 if (verbose) { 71 c.compile(r, className, fileName, new TraceClassVisitor(cw, 72 new PrintWriter (System.out))); 73 } else { 74 c.compile(r, className, fileName, cw); 75 } 76 77 r.close(); 78 79 FileOutputStream os = new FileOutputStream (className + ".class"); 80 os.write(cw.toByteArray()); 81 os.flush(); 82 os.close(); 83 } 84 85 } 86 | Popular Tags |