public File resolveWorkingDirectory(String file) { return resolveWorkingDirectory(new File(file)); }
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; }
public synchronized File mainDefinitionFile(FileUtil files) { if (mainDefinitionFile == null) { if (parameters == null || parameters.size() == 0) { throw KEMException.criticalError("You have to provide exactly one main file in order to do outer parsing."); } mainDefinitionFile = files.resolveWorkingDirectory(parameters.get(0)); } return mainDefinitionFile; }
public synchronized File specFile(FileUtil files) { if (specFile == null) { if (parameters == null || parameters.size() == 0) { throw KEMException.criticalError("You have to provide exactly one main file in order to do outer parsing."); } specFile = files.resolveWorkingDirectory(parameters.get(0)); } return specFile; }
public Reader readFromWorkingDirectory(String path) { File f = resolveWorkingDirectory(path); try { return new FileReader(f); } catch (FileNotFoundException e) { throw KEMException.criticalError("Could not read from file " + f.getAbsolutePath(), e); } } }
public String loadFromWorkingDirectory(String file) { return load(resolveWorkingDirectory(file)); }
public void saveToWorkingDirectory(String file, byte[] content) { save(resolveWorkingDirectory(file), content); }
public void saveToWorkingDirectory(String file, String content) { save(resolveWorkingDirectory(file), content); }
/** * Get the source of the string to parse. This method is undefined if it is called before calling * {@link #stringToParse()}. * @return A textual description of the source of the string to parse. */ public Source source() { if (expression != null) { return Source.apply("<command line: -e>"); } else { return Source.apply(files.get().resolveWorkingDirectory(parameters.get(0)).getAbsolutePath()); } }
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])))); }
private void addOpaqueKLabels(Set<KLabel> klabels) { if (options.klabels == null) return; File definitionFile = files.resolveWorkingDirectory(options.klabels).getAbsoluteFile(); List<File> lookupDirectories = kompileOptions.outerParsing.includes.stream().map(files::resolveWorkingDirectory).collect(Collectors.toList()); lookupDirectories.add(Kompile.BUILTIN_DIRECTORY); java.util.Set<Module> mods = new ParserUtils(files::resolveWorkingDirectory, kem, globalOptions).loadModules( new HashSet<>(), "require " + StringUtil.enquoteCString(definitionFile.getPath()), Source.apply(definitionFile.getAbsolutePath()), definitionFile.getParentFile(), lookupDirectories, new HashSet<>(), false); mods.stream().forEach(m -> klabels.addAll(mutable(m.definedKLabels()))); }
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; }
file = new OutputStreamFile(f, kem); } else { RandomAccessFile f = new RandomAccessFile(fileUtil.resolveWorkingDirectory(path), mode); fileFD = f.getFD(); file = new RandomAccessFileFile(f);
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() + " \\");
@Before public void setUp() { options = new KompileOptions(); when(files.resolveWorkingDirectory(Matchers.anyString())).thenAnswer(new Answer<File>() { @Override public File answer(InvocationOnMock invocation) throws Throwable { return new File((String) invocation.getArguments()[0]); } }); }
public int run( CompiledDefinition commonDef, CompiledDefinition def1, CompiledDefinition def2, KEqOptions keqOptions, Backend backend, Function<Module, Rewriter> commonGen, Function<Module, Rewriter> gen1, Function<Module, Rewriter> gen2) { Rewriter commonRewriter = commonGen.apply(commonDef.executionModule()); Tuple2<Definition, Module> compiled1 = KProve.getProofDefinition(files.resolveWorkingDirectory(keqOptions.spec1), keqOptions.defModule1, keqOptions.specModule1, def1, backend, files, kem, sw); Rewriter rewriter1 = gen1.apply(compiled1._1().mainModule()); Module spec1 = compiled1._2(); Tuple2<Definition, Module> compiled2 = KProve.getProofDefinition(files.resolveWorkingDirectory(keqOptions.spec2), keqOptions.defModule2, keqOptions.specModule2, def2, backend, files, kem, sw); Rewriter rewriter2 = gen2.apply(compiled2._1().mainModule()); Module spec2 = compiled2._2(); boolean isEquivalent = commonRewriter.equivalence(rewriter1, rewriter2, spec1, spec2); System.out.println(isEquivalent ? "#True" : "#False"); return isEquivalent ? 0 : 1; } }
public static Tuple2<Definition, Module> getProofDefinition(File proofFile, String defModuleName, String specModuleName, CompiledDefinition compiledDefinition, Backend backend, FileUtil files, KExceptionManager kem, Stopwatch sw) { Kompile kompile = new Kompile(compiledDefinition.kompileOptions, files, kem, sw, true); if (defModuleName == null) { defModuleName = compiledDefinition.kompiledDefinition.mainModule().name(); } if (specModuleName == null) { specModuleName = FilenameUtils.getBaseName(proofFile.getName()).toUpperCase(); } java.util.Set<Module> modules = kompile.parseModules(compiledDefinition, defModuleName, files.resolveWorkingDirectory(proofFile).getAbsoluteFile()); Map<String, Module> modulesMap = new HashMap<>(); modules.forEach(m -> modulesMap.put(m.name(), m)); Module defModule = getModule(defModuleName, modulesMap, compiledDefinition.getParsedDefinition()); Module specModule = getModule(specModuleName, modulesMap, compiledDefinition.getParsedDefinition()); specModule = backend.specificationSteps(compiledDefinition.kompiledDefinition).apply(specModule); specModule = spliceModule(specModule, compiledDefinition.kompiledDefinition); Definition combinedDef = Definition.apply(defModule, compiledDefinition.getParsedDefinition().entryModules(), compiledDefinition.getParsedDefinition().att()); Definition compiled = compileDefinition(backend, combinedDef); return Tuple2.apply(compiled, specModule); }
@Test public void testReadFile() throws Exception { when(files.resolveWorkingDirectory(Matchers.anyString())).thenAnswer(new Answer<java.io.File>() { @Override public java.io.File answer(InvocationOnMock invocation) throws Throwable { return new java.io.File((String)invocation.getArguments()[0]); } }); PortableFileSystem fs = new PortableFileSystem(kem, files); long fd = fs.open(new java.io.File(getClass().getResource("/fs-test.txt").toURI()).getAbsolutePath(), "r"); File f = fs.get(fd); byte[] file = "foo\n".getBytes(Charset.forName("ASCII")); Assert.assertArrayEquals(file, f.read(4)); try { f.read(1); Assert.fail(); } catch (IOException e) { Assert.assertEquals("EOF", e.getMessage()); } }
files.resolveWorkingDirectory(outputFile).getAbsolutePath(), files.resolveTemp("kore_term.o").getAbsolutePath(), files.resolveTemp("marshal_term.o").getAbsolutePath(),