public void saveToTemp(String file, byte[] content) { save(resolveTemp(file), content); }
void createResourceObject(String name) throws IOException, InterruptedException { ProcessBuilder pb = files.getProcessBuilder().directory(files.resolveTemp(".")); pb.command("ld","-r","-b","binary","-o",name+".o",name); // writes to <name>.o. Symbols are always based on name. Process p = pb.redirectError(files.resolveTemp("ld-"+name+".err")) .redirectOutput(files.resolveTemp("ld-"+name+".out")) .start(); int exit = p.waitFor(); if (exit != 0) { System.err.println(files.loadFromTemp("ld-"+name+".err")); throw KEMException.criticalError("Failed to embed resource into object file. See output for error information."); } }
public void saveToTemp(String file, String content) { save(resolveTemp(file), content); }
public String loadFromTemp(String file) { return load(resolveTemp(file)); }
public byte[] loadBytesFromTemp(String file) { return loadBytes(resolveTemp(file)); }
@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)); }
/** Must be kept compatible with {@link .compileOcamlObject} and consistent with {@link .compileOcaml}. */ void linkOcamlObject(String compiler, String name, String target, String... objectFiles) throws IOException, InterruptedException { // now link ProcessBuilder pb = files.getProcessBuilder(); List<String> args = new ArrayList<>(Arrays.asList( compiler, name, "-o", target, "-Wl,-E")); args.addAll(Arrays.asList(objectFiles)); args.addAll(Arrays.asList("-lmpfr","-lgmp","-lffi","-lm","-ldl")); args.add("-Wl,--no-as-needed"); args.addAll(options.experimental.nativeLibraries); pb.command(args); if (options.global.verbose) { System.err.println("+ " + StringUtils.join(args, " ")); } Process p = pb.redirectError(files.resolveTemp("link.err")) .redirectOutput(files.resolveTemp("link.out")) .start(); int exit = p.waitFor(); if (exit != 0) { System.err.println(files.loadFromTemp("link.err")); throw KEMException.criticalError("Failed to link final program. See output for error information."); } }
@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); }
public void copyTempFileToKompiledDirectory(String fromPath) { copyFileToDirectory(resolveTemp(fromPath), resolveKompiled(".")); }
public void copyTempFileToDefinitionDirectory(String fromPath) { copyFileToDirectory(resolveTemp(fromPath), resolveDefinitionDirectory(".")); }
@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); }
public void copyTempFileToKompiledFile(String fromPath, String toPath) { copyFile(resolveTemp(fromPath), resolveKompiled(toPath)); }
int compileAndExecOcamlBasic(String name) { try { compileOcaml(name); return executeCommandBasic(null, files.resolveTemp("a.out").getAbsolutePath(), files.resolveKompiled("realdef.cma").getAbsolutePath(), ocamlKRunOptions.argv ); } 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); } }
k.theConfig = null; config = converter.preprocess(config); File input = files.resolveTemp("run.in"); files.resolveTemp(".").mkdirs(); try (OutputStream out = new BufferedOutputStream(new FileOutputStream(input))) { ToBinary.apply(out, config); File output = files.resolveTemp("run.out"); int exit = rewriter.execOcaml(files.resolveTemp("."), files.resolveKompiled("interpreter").getAbsolutePath(), files.resolveKompiled("realdef.cma").getAbsolutePath(),
/** * 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); } } }
List<String> args = new ArrayList<>(Arrays.asList("-g", "-o", files.resolveTemp("a.out").getAbsolutePath(), "-package", "gmp", "-package", "zarith", "-package", "uuidm", "-package", "str", "-package", "unix", "-package", "dynlink", "-linkpkg", "-safe-string")); args.addAll(0, converter.options.packages.stream().flatMap(p -> Stream.of("-package", p)).collect(Collectors.toList())); files.resolveKompiled("plugin.cmx").getAbsolutePath(), files.resolveKompiled("parser.cmx").getAbsolutePath(), files.resolveKompiled("lexer.cmx").getAbsolutePath(), files.resolveKompiled("run.cmx").getAbsolutePath(), files.resolveTemp(name).getAbsolutePath())); args.add("-inline"); args.add("20"); files.resolveKompiled("lexer.cmo").getAbsolutePath(), files.resolveKompiled("run.cmo").getAbsolutePath())); args.add(files.resolveKompiled("realdef.cmo").getAbsolutePath()); args.add(files.resolveTemp(name).getAbsolutePath()); pb = pb.command(args); System.err.println("+ " + StringUtils.join(args, " ")); Process p = pb.redirectError(files.resolveTemp("compile.err")) .redirectOutput(files.resolveTemp("compile.out")) .start(); int exit = p.waitFor();
files.saveToTemp("interpreter.ml", ocaml); rewriter.compileOcaml("interpreter.ml"); files.resolveTemp("a.out").renameTo(files.resolveKompiled("interpreter")); files.resolveKompiled("interpreter").setExecutable(true); } else {
files.resolveKompiled("execution_partial.o").getAbsolutePath(), files.resolveWorkingDirectory(outputFile).getAbsolutePath(), files.resolveTemp("kore_term.o").getAbsolutePath(), files.resolveTemp("marshal_term.o").getAbsolutePath(), files.resolveTemp("plugin_path.o").getAbsolutePath()); return null; } catch (IOException e) {