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 GenerateCoverage(boolean cover, FileUtil files) { this.cover = cover; this.files = files; files.resolveKompiled(".").mkdirs(); try { allRulesFile = new PrintWriter(new BufferedWriter(new FileWriter(files.resolveKompiled("allRules.txt").getAbsolutePath()))); } catch (IOException e) { throw KEMException.internalError("Could not write list of rules to coverage document.", e); } }
@Inject public InitializeDefinition(BinaryLoader loader, FileUtil files) { serialized = loader.loadOrDie(DefinitionToOcaml.class, files.resolveKompiled("ocaml_converter.bin")); } }
public String loadFromKompiled(String file) { return load(resolveKompiled(file)); }
public void saveToKompiled(String file, String content) { save(resolveKompiled(file), content); }
@Provides @DefinitionScoped CompiledDefinition koreDefinition(BinaryLoader loader, FileUtil files) { return loader.loadOrDie(CompiledDefinition.class, files.resolveKompiled("compiled.bin")); }
public void copyTempFileToKompiledDirectory(String fromPath) { copyFileToDirectory(resolveTemp(fromPath), resolveKompiled(".")); }
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; }
public void copyTempFileToKompiledFile(String fromPath, String toPath) { copyFile(resolveTemp(fromPath), resolveKompiled(toPath)); }
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(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);
public ExpandMacros(Module mod, FileUtil files, KompileOptions kompileOptions, boolean reverse) { this.mod = mod; this.reverse = reverse; this.cover = kompileOptions.coverage; files.resolveKompiled(".").mkdirs(); macros = stream(mod.rules()).filter(r -> isMacro(r.att(), reverse)).sorted(Comparator.comparing(r -> r.att().contains("owise"))).collect(Collectors.groupingBy(r -> ((KApply)getLeft(r, reverse)).klabel())); if (cover) { try { FileOutputStream os = new FileOutputStream(files.resolveKompiled("coverage.txt"), true); channel = os.getChannel(); coverage = new PrintWriter(new BufferedWriter(new OutputStreamWriter(os))); } catch (IOException e) { throw KEMException.internalError("Could not write list of rules to coverage document.", e); } } else { channel = null; coverage = null; } }
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); } }
/** * 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); } } }
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() + " \\");
files.resolveKompiled("interpreter").getAbsolutePath(), files.resolveKompiled("realdef.cma").getAbsolutePath(), "-t", input.getAbsolutePath(), "binaryfile", "--output-file", output.getAbsolutePath(),
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); 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() .start(); files.saveToTemp("interpreter.ml", ocaml); rewriter.compileOcaml("interpreter.ml");
public static String getKompiledString(Module mainModule, KLabel topCellInitializer, FileUtil files, boolean heatCoolEquations) { mainModule = new GenerateSortPredicateRules(true).gen(mainModule); mainModule = ModuleTransformer.fromKTransformer(new AddSortInjections(mainModule)::addInjections, "Add sort injections").apply(mainModule); mainModule = ModuleTransformer.fromSentenceTransformer(new MinimizeTermConstruction(mainModule)::resolve, "Minimize term construction").apply(mainModule); ModuleToKORE moduleToKORE = new ModuleToKORE(mainModule, files, topCellInitializer); String kompiledString = moduleToKORE.convert(heatCoolEquations); Properties koreToKLabels = new Properties(); koreToKLabels.putAll(moduleToKORE.getKToKoreLabelMap().inverse()); try { FileOutputStream output = new FileOutputStream(files.resolveKompiled("kore_to_k_labels.properties")); koreToKLabels.store(output, "Properties file containing the mapping from kore to k labels"); } catch (IOException e) { throw KEMException.criticalError("Error while saving kore to K labels map", e); } return kompiledString; }
@Override public int run() { if (!options.outerParsing.mainDefinitionFile(files).exists()) { throw KEMException.criticalError("Definition file doesn't exist: " + options.outerParsing.mainDefinitionFile(files).getAbsolutePath()); } Kompile kompile = new Kompile(options, files, kem, sw); Backend backend = koreBackend.get(); CompiledDefinition def = kompile.run(options.outerParsing.mainDefinitionFile(files), options.mainModule(files), options.syntaxModule(files), backend.steps(), backend.excludedModuleTags()); sw.printIntermediate("Kompile to kore"); loader.saveOrDie(files.resolveKompiled("compiled.bin"), def); sw.printIntermediate("Save to disk"); backend.accept(def); sw.printIntermediate("Backend"); loader.saveOrDie(files.resolveKompiled("timestamp"), ""); sw.printTotal("Total"); return 0; } }
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(),
public K gen(Rule r, K body) { if (!cover || !r.att().getOptional(Source.class).isPresent()) { return body; } K left = RewriteToTop.toLeft(body); K right = RewriteToTop.toRight(body); String file = r.att().get(Source.class).source(); if (file.startsWith(JarInfo.getKBase())) { return body; } int line = r.att().get(Location.class).startLine(); int col = r.att().get(Location.class).startColumn(); String loc = file + ":" + line + ":" + col; String id = r.att().get("UNIQUE_ID"); allRulesFile.print(id); allRulesFile.print(" "); allRulesFile.println(loc); if (r.att().contains("macro") || r.att().contains("alias")) { //handled by macro expander return body; } return KRewrite(left, KSequence(KApply(KLabel("#logToFile"), KToken(StringUtil.enquoteKString(files.resolveKompiled("coverage.txt").getAbsolutePath()), Sorts.String()), KToken(StringUtil.enquoteKString(id + '\n'), Sorts.String())), right)); }