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 StateLog(JavaExecutionOptions javaExecutionOptions, FileUtil files) { this.inited = false; this.loggingOn = javaExecutionOptions.stateLog; this.loggingPath = javaExecutionOptions.stateLogPath == null ? files.resolveKompiled("stateLog") : new File(javaExecutionOptions.stateLogPath); if (javaExecutionOptions.stateLogId != null) this.sessionId = javaExecutionOptions.stateLogId; this.blobsDir = new File(loggingPath, "blobs/"); this.blobsDir.mkdirs(); this.logEvents = javaExecutionOptions.stateLogEvents; }
public File resolveWorkingDirectory(String file) { return resolveWorkingDirectory(new File(file)); }
public void saveToWorkingDirectory(String file, byte[] content) { save(resolveWorkingDirectory(file), content); }
public String loadFromWorkingDirectory(String file) { return load(resolveWorkingDirectory(file)); }
public void saveToTemp(String file, String content) { save(resolveTemp(file), content); }
def.initialize(compiledDefinition); String ocaml = def.constants(); files.saveToKompiled("constants.ml", ocaml); ocaml = def.definition(); files.saveToKompiled("realdef.ml", ocaml); new BinaryLoader(kem).saveOrDie(files.resolveKompiled("ocaml_converter.bin"), def); try { FileUtils.copyFile(files.resolveKBase("include/ocaml/prelude.ml"), files.resolveKompiled("prelude.ml")); FileUtils.copyFile(files.resolveKBase("include/ocaml/lexer.mll"), files.resolveKompiled("lexer.mll")); FileUtils.copyFile(files.resolveKBase("include/ocaml/parser.mly"), files.resolveKompiled("parser.mly")); FileUtils.copyFile(files.resolveKBase("include/ocaml/run.ml"), files.resolveKompiled("run.ml")); FileUtils.copyFile(files.resolveKBase("include/ocaml/marshalvalue.ml"), files.resolveKompiled("marshalvalue.ml")); FileUtils.copyFile(files.resolveKBase("include/ocaml/plugin.ml"), files.resolveKompiled("plugin.ml")); FileUtils.copyFile(files.resolveKBase("include/ocaml/load_terms.c"), files.resolveKompiled("load_terms.c")); FileUtils.copyFile(files.resolveKBase("include/ocaml/fake_load_terms.c"), files.resolveKompiled("fake_load_terms.c")); String execution_pmg_ocaml = def.ocamlCompile(compiledDefinition.topCellInitializer, compiledDefinition.exitCodePattern, options.dumpExitCode); files.saveToKompiled("execution_pgm.ml", execution_pmg_ocaml); ProcessBuilder pb = files.getProcessBuilder(); int exit = pb.command("ocamllex", "lexer.mll").directory(files.resolveKompiled(".")).inheritIO().start().waitFor(); if (exit != 0) { throw KEMException.criticalError("ocamllex returned nonzero exit code: " + exit + "\nExamine output to see errors."); exit = pb.command("ocamlyacc", "parser.mly").directory(files.resolveKompiled(".")).inheritIO().start().waitFor(); if (exit != 0) { throw KEMException.criticalError("ocamlyacc returned nonzero exit code: " + exit + "\nExamine output to see errors."); .directory(files.resolveKompiled(".")) .inheritIO()
/** * 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); } } }
ProcessBuilder pb = files.getProcessBuilder(); 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())); args.add(1, "ocamlopt"); if (!converter.options.noLinkPrelude) { args.add(files.resolveKompiled("constants.cmx").getAbsolutePath()); args.add(files.resolveKompiled("prelude.cmx").getAbsolutePath()); args.addAll(Arrays.asList("-I", files.resolveKompiled(".").getAbsolutePath(), 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"); args.add(1, "ocamlc"); if (!converter.options.noLinkPrelude) { args.add(files.resolveKompiled("constants.cmo").getAbsolutePath()); args.add(files.resolveKompiled("prelude.cmo").getAbsolutePath()); args.addAll(Arrays.asList("-I", files.resolveKompiled(".").getAbsolutePath(), files.resolveKompiled("plugin.cmo").getAbsolutePath(), files.resolveKompiled("parser.cmo").getAbsolutePath(), 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);
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); 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) {
public void copyTempFileToKompiledDirectory(String fromPath) { copyFileToDirectory(resolveTemp(fromPath), resolveKompiled(".")); }
public void copyTempFileToKompiledFile(String fromPath, String toPath) { copyFile(resolveTemp(fromPath), resolveKompiled(toPath)); }
private RuleGrammarGenerator makeRuleGrammarGenerator() { String definitionText; FileUtil files = FileUtil.testFileUtil(); ParserUtils parser = new ParserUtils(files::resolveWorkingDirectory, new KExceptionManager(new GlobalOptions())); File definitionFile = new File(Kompile.BUILTIN_DIRECTORY.toString() + "/kast.k"); definitionText = files.loadFromWorkingDirectory(definitionFile.getPath()); Definition baseK = parser.loadDefinition("K", "K", definitionText, definitionFile, definitionFile.getParentFile(), Lists.newArrayList(Kompile.BUILTIN_DIRECTORY), false, false); return new RuleGrammarGenerator(baseK); }
modules.addAll(parser.slurp(FileUtil.load(options.mainDefinitionFile(files)), source, currentDirectory, requiredFiles));; Set<File> allFiles = modules.stream().map(m -> new File(m.getSource().source())).collect(Collectors.toSet()); System.out.println(files.resolveWorkingDirectory(".").toURI().relativize(files.resolveKompiled("timestamp").toURI()).getPath() + " : \\"); for (File file : allFiles) { System.out.println(" " + file.getAbsolutePath() + " \\");
public Kompile(KompileOptions kompileOptions, FileUtil files, KExceptionManager kem, Stopwatch sw, boolean cacheParses) { this.kompileOptions = kompileOptions; this.files = files; this.kem = kem; this.errors = new HashSet<>(); this.parser = new ParserUtils(files::resolveWorkingDirectory, kem, kem.options); List<File> lookupDirectories = kompileOptions.outerParsing.includes.stream().map(files::resolveWorkingDirectory).collect(Collectors.toList()); // these directories should be relative to the current working directory if we refer to them later after the WD has changed. kompileOptions.outerParsing.includes = lookupDirectories.stream().map(File::getAbsolutePath).collect(Collectors.toList()); File cacheFile = kompileOptions.experimental.cacheFile != null ? files.resolveWorkingDirectory(kompileOptions.experimental.cacheFile) : files.resolveKompiled("cache.bin"); this.definitionParsing = new DefinitionParsing( lookupDirectories, kompileOptions.strict(), kem, parser, cacheParses, cacheFile, !kompileOptions.outerParsing.noPrelude, kompileOptions.isKore()); this.sw = sw; }
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); } }
public static String getOcamlFind(FileUtil files) { String ocamlfind = "ocamlfind"; String env = files.getEnv().get("K_OCAML_HOME"); if (env != null) { ocamlfind = new File(files.resolveWorkingDirectory(env), "ocamlfind").getAbsolutePath(); } return ocamlfind; }
@Provides ProcessBuilder pb(@WorkingDir File workingDir, @Environment Map<String, String> env) { return new FileUtil(null, null, workingDir, null, null, env).getProcessBuilder(); }
public static void nailMain(NGContext context) throws IOException { FileUtil files = new FileUtil(null,null,new File(context.getWorkingDirectory()),null,null,null); File f = files.resolveWorkingDirectory(context.getArgs()[0]); FileChannel channel = FileChannel.open(f.toPath()); ByteBuffer buf = channel.map(FileChannel.MapMode.READ_ONLY, 0, channel.size()); K result = BinaryParser.parse(buf); ToKast.apply(result, new PrintStream(new FileOutputStream(files.resolveWorkingDirectory(context.getArgs()[1])))); }
public void saveToKompiled(String file, String content) { save(resolveKompiled(file), content); }