- public static void main(String[] s) throws Exception {
- System.out.println(printLut(0x39, "se", "n", "L0"));
- }
- public static synchronized String printLut(int lut, String xn, String yn, String zn) {
- try {
- File f = File.createTempFile("mvsis", ".mvs");
- f.deleteOnExit();
-
- FileOutputStream fos = new FileOutputStream(f);
- PrintWriter pw = new PrintWriter(new OutputStreamWriter(fos));
- pw.println(".model clb");
- pw.println(".inputs "+xn+" "+yn+" "+zn);
- pw.println(".outputs O");
- pw.println(".table "+xn+" "+yn+" "+zn+/*("X_xor_Y X_xor_Z Y_xor_Z")+*/ " -> O");
- for(int i=8; i>=0; i--) {
- int x = ((i & 0x01)!=0 ? 1 : 0);
- int y = ((i & 0x02)!=0 ? 1 : 0);
- int z = ((i & 0x04)!=0 ? 1 : 0);
- pw.print(" "+x+" ");
- pw.print(" "+y+" ");
- pw.print(" "+z+" ");
- //pw.print(" "+(x ^ y)+" ");
- //pw.print(" "+(y ^ z)+" ");
- //pw.print(" "+(z ^ y)+" ");
- pw.print((lut & (1<<i))==0 ? 0 : 1);
- pw.println();
- }
- pw.println(".end");
- pw.flush();
- pw.close();
- Process p = Runtime.getRuntime().exec(new String[] { "mvsis", "-c", "simplify;print_factor", f.getAbsolutePath() });
- new Gobble("mvsis: ", p.getErrorStream()).start();
- //new Gobble("mvsis: ", p.getInputStream()).start();
- BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
- String ret = br.readLine();
- //f.delete();
- return ret.trim();
- } catch (Exception e) {
- e.printStackTrace();
- return "*mvsis_error*";
- }
- }
-
- public static class Gobble extends Thread {
- private final String header;
- private final BufferedReader br;
- public Gobble(String header, BufferedReader br) { this.br = br; this.header = header; }
- public Gobble(String header, Reader r) { this(header, new BufferedReader(r)); }
- public Gobble(String header, InputStream is) { this(header, new InputStreamReader(is)); }
- public void run() {
- try {
- for(String s = br.readLine(); s!=null; s=br.readLine())
- System.err.println(header + s);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }