public static Module transformModule(Module mod) { ConfigurationInfoFromModule configInfo = new ConfigurationInfoFromModule(mod); LabelInfo labelInfo = new LabelInfoFromModule(mod); return ModuleTransformer.fromSentenceTransformer( new AddImplicitComputationCell(configInfo, labelInfo), "concretizing configuration").apply(mod); }
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 Function<Module, Module> specificationSteps(Definition def) { Module mod = def.mainModule(); ConfigurationInfoFromModule configInfo = new ConfigurationInfoFromModule(mod); LabelInfo labelInfo = new LabelInfoFromModule(mod); SortInfo sortInfo = SortInfo.fromModule(mod); ModuleTransformer resolveAnonVars = ModuleTransformer.fromSentenceTransformer( new ResolveAnonVar()::resolve, "resolving \"_\" vars"); ModuleTransformer resolveSemanticCasts = ModuleTransformer.fromSentenceTransformer( new ResolveSemanticCasts(true)::resolve, "resolving semantic casts"); ModuleTransformer subsortKItem = ModuleTransformer.from(Kompile::subsortKItem, "subsort all sorts to KItem"); ModuleTransformer addImplicitComputationCell = ModuleTransformer.fromSentenceTransformer( new AddImplicitComputationCell(configInfo, labelInfo), "concretizing configuration"); Function1<Module, Module> resolveFreshConstants = d -> ModuleTransformer.from(new ResolveFreshConstants(def, true)::resolve, "resolving !Var variables").apply(d); ModuleTransformer concretizeCells = ModuleTransformer.fromSentenceTransformer( new ConcretizeCells(configInfo, labelInfo, sortInfo, mod)::concretize, "concretizing configuration"); return m -> resolveAnonVars .andThen(resolveSemanticCasts) .andThen(addImplicitComputationCell) .andThen(resolveFreshConstants) .andThen(concretizeCells) .andThen(subsortKItem) .apply(m); }
@Override public Function<Module, Module> specificationSteps(Definition def) { BiFunction<Module, K, K> convertCellCollections = (Module m, K k) -> new ConvertDataStructureToLookup(m, false).convert(k); return m -> ModuleTransformer.fromSentenceTransformer(new ResolveAnonVar()::resolve, "resolve anonymous varaibles") .andThen(ModuleTransformer.fromSentenceTransformer(s -> new ResolveSemanticCasts(kompileOptions.backend.equals(Backends.JAVA)).resolve(s), "resolve semantic casts")) .andThen(AddImplicitComputationCell::transformModule) .andThen(ConcretizeCells::transformModule) .andThen(ModuleTransformer.fromRuleBodyTransformer(RewriteToTop::bubbleRewriteToTopInsideCells, "bubble out rewrites below cells")) .andThen(AddBottomSortForListsWithIdenticalLabels.singleton()) .andThen(ModuleTransformer.fromSentenceTransformer((mod, s) -> new ExpandMacros(mod, files, kompileOptions, false).expand(s), "expand macros")) .andThen(ModuleTransformer.fromKTransformerWithModuleInfo(convertCellCollections::apply, "convert cell to the underlying collections")) .andThen(ModuleTransformer.fromRuleBodyTransformer(JavaBackend::ADTKVariableToSortedVariable, "ADT.KVariable to SortedVariable")) .andThen(ModuleTransformer.fromRuleBodyTransformer(JavaBackend::convertKSeqToKApply, "kseq to kapply")) .andThen(ModuleTransformer.fromRuleBodyTransformer(NormalizeKSeq.self(), "normalize kseq")) .andThen(mod -> JavaBackend.markRegularRules(def, mod)) .andThen(ModuleTransformer.fromSentenceTransformer(new AddConfigurationRecoveryFlags()::apply, "add refers_THIS_CONFIGURATION_marker")) .apply(m); }
public void initialize(CompiledDefinition def) { Function1<Module, Module> generatePredicates = new GenerateSortPredicateRules(false)::gen; this.convertDataStructure = new ConvertDataStructureToLookup(def.executionModule(), true); ModuleTransformer convertLookups = ModuleTransformer.fromSentenceTransformer(convertDataStructure::convert, "convert data structures to lookups"); ModuleTransformer liftToKSequence = ModuleTransformer.fromSentenceTransformer(new LiftToKSequence()::lift, "lift K into KSequence"); this.expandMacros = new ExpandMacros(def.executionModule(), files, kompileOptions, false); ModuleTransformer expandMacros = ModuleTransformer.fromSentenceTransformer(this.expandMacros::expand, "expand macro rules"); ModuleTransformer deconstructInts = ModuleTransformer.fromSentenceTransformer(new DeconstructIntegerAndFloatLiterals()::convert, "remove matches on integer literals in left hand side"); this.threadCellExists = containsThreadCell(def); this.exitCodePattern = def.exitCodePattern; ModuleTransformer splitThreadCell = this.threadCellExists ? ModuleTransformer.fromSentenceTransformer(new SplitThreadsCell(def.executionModule())::convert, "split threads cell into thread local and global") : ModuleTransformer.fromSentenceTransformer(s -> s, "identity function -- no transformation"); ModuleTransformer preprocessKLabelPredicates = ModuleTransformer.fromSentenceTransformer(new PreprocessKLabelPredicates(def.executionModule())::convert, "preprocess klabel predicates"); Sentence thread = Production(KLabel("#Thread"), Sorts.KItem(), Seq( Terminal("#Thread"), Terminal("("), Sentence threadLocal = Production(KLabel("#ThreadLocal"), Sorts.KItem(), Seq(Terminal("#ThreadLocal"))); Function1<Module, Module> pipeline = preprocessKLabelPredicates .andThen(splitThreadCell) .andThen(mod -> Module(mod.name(), mod.imports(), Stream.concat(stream(mod.localSentences()),
private static Module markRegularRules(Definition d, Module mod) { ConfigurationInfoFromModule configInfo = new ConfigurationInfoFromModule(d.mainModule()); return ModuleTransformer.fromSentenceTransformer(s -> markRegularRules(d, configInfo, s, "specification"), "mark regular rules").apply(mod); }
public static Module transformModule(Module mod) { ConfigurationInfoFromModule configInfo = new ConfigurationInfoFromModule(mod); LabelInfo labelInfo = new LabelInfoFromModule(mod); SortInfo sortInfo = SortInfo.fromModule(mod); return ModuleTransformer.fromSentenceTransformer( new ConcretizeCells(configInfo, labelInfo, sortInfo, mod)::concretize, "concretizing configuration").apply(mod); }