@Override public RewriterResult execute(K k, Optional<Integer> depth) { String ocaml = converter.execute(k, depth.orElse(-1), files.resolveTemp("run.out").getAbsolutePath()); files.saveToTemp("pgm.ml", ocaml); byte[] output = compileAndExecOcaml("pgm.ml"); return parseOcamlRewriterOutput(output); }
@Override public K match(K k, Rule rule) { String ocaml = converter.match(k, rule, files.resolveTemp("run.out").getAbsolutePath()); files.saveToTemp("match.ml", ocaml); byte[] output = compileAndExecOcaml("match.ml"); return parseOcamlSearchOutput(output); }
@Override public Tuple2<RewriterResult, K> executeAndMatch(K k, Optional<Integer> depth, Rule rule) { String ocaml = converter.executeAndMatch(k, depth.orElse(-1), rule, files.resolveTemp("run.out").getAbsolutePath(), files.resolveTemp("run.subst").getAbsolutePath()); files.saveToTemp("pgm.ml", ocaml); byte[] output = compileAndExecOcaml("pgm.ml"); byte[] subst = files.loadBytesFromTemp("run.subst"); return Tuple2.apply(parseOcamlRewriterOutput(output), parseOcamlSearchOutput(subst)); }
/** * Marshals the specified K term using the OCAML Marshal module and returns a string containing the ocaml representation of a string of the resulting bytes. * @param value * @return */ private byte[] marshalValue(K value) { files.saveToTemp("run.in", ToBinary.apply(converter.preprocess(value))); try { Process p = files.getProcessBuilder().command(files.resolveKompiled("marshalvalue").getAbsolutePath(), files.resolveKompiled("realdef.cma").getAbsolutePath()).directory(files.resolveTemp(".")).start(); int exit = p.waitFor(); if (exit != 0) { IOUtils.copy(p.getErrorStream(), System.err); throw KEMException.criticalError("Failed to precompile program variables."); } return FileUtils.readFileToByteArray(files.resolveTemp("run.out")); }catch (IOException e) { throw KEMException.criticalError("Failed to start ocamlopt: " + e.getMessage(), e); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw KEMException.criticalError("Ocaml process interrupted.", e); } } }
files.saveToTemp("interpreter.ml", ocaml); rewriter.compileOcaml("interpreter.ml"); files.resolveTemp("a.out").renameTo(files.resolveKompiled("interpreter"));
files.saveToTemp("kore_term",ToBinary.apply(converter.preprocess(unserializedVarsMap))); files.saveToTemp("marshal_term", marshalValue(serializedVars)); files.saveToTemp("plugin_path",files.resolveKompiled("realdef.cmxs").getAbsolutePath()); try { OcamlRewriter rewriter = new OcamlRewriter(files, converter, options);