K transform(K term, boolean body) { AddSortInjections sorts = new AddSortInjections(module); return new RewriteAwareTransformer(body) { @Override public K apply(K k) { if (isRHS() && !isLHS()) { if (cache.containsKey(k)) { return cache.get(k); } } if (isLHS() && !isRHS()) { if (usedOnRhs.contains(k)) { return KAs(super.apply(k), cache.get(k), Att.empty().add(Sort.class, cache.get(k).att().get(Sort.class))); } } return super.apply(k); } }.apply(term); }
void gatherTerms(K term, boolean body) { AddSortInjections sorts = new AddSortInjections(module); new RewriteAwareVisitor(body, new HashSet<>()) { @Override public void apply(K k) { if (isLHS() && !isRHS() && !(k instanceof KVariable)) { cache.put(k, newDotVariable(sorts.sort(k, Sorts.K()))); } super.apply(k); } @Override public void apply(KApply k) { String hook = module.attributesFor().get(k.klabel()).getOrElse(() -> Att.empty()).getOptional("hook").orElse(""); if (hook.equals("SET.element") || hook.equals("LIST.element") || hook.equals("LIST.concat") || hook.equals("MAP.concat") || hook.equals("SET.concat")) { return; } if (hook.equals("MAP.element")) { apply(k.items().get(1)); return; } super.apply(k); } }.apply(term); }
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; }
public void convert(K k) { k = new AddSortInjections(module).addInjections(k); new VisitK() { @Override
parsed = new AddSortInjections(compiledMod).addInjections(parsed, sort); converter.convert(parsed); System.out.println(converter.toString());