def parse_model(self, \ model_files, relative_path, \ general_config, \ name=None, \ modifier=None): hts = HTS(name if name is not None else "System") invar_props = [] ltl_props = [] models = model_files.split(FILE_SP) cache_files = general_config.cache_files clean_cache = general_config.clean_cache for strfile in models: (strfile, flags) = self.get_file_flags(strfile) if len(strfile) > 1 and strfile[:2] == '~/': filepath = Path.home() / Path(strfile[2:]) else: filepath = Path(strfile) if filepath.parts[0] != "/": filepath = relative_path / filepath filetype = filepath.suffix[1:] parser = None for av_parser in ModelParsersFactory.get_parsers(): assert av_parser.name is not None if filetype in av_parser.get_extensions(): parser = av_parser if not self.parser: self.parser = av_parser if parser is not None: if not filepath.is_file(): Logger.error("File \"%s\" does not exist" % filepath) if cache_files: md5 = self.md5(filepath) cf = "-".join(["1" if general_config.abstract_clock else "0", \ "1" if general_config.add_clock else "0", \ "1" if general_config.boolean else "0"]) cachefile = "%s-%s" % (md5, cf) cachedir = filepath.parent / COSACACHEDIR if cache_files and self._is_cached(cachedir, cachefile, clean_cache): Logger.msg( "Loading from cache file \"%s\"... " % (filepath), 0) (hts_a, inv_a, ltl_a, model_info) = self._from_cache(cachedir, cachefile, general_config, flags) else: Logger.msg("Parsing file \"%s\"... " % (filepath), 0) (hts_a, inv_a, ltl_a) = parser.parse_file(filepath, general_config, flags) model_info = parser.get_model_info() if modifier is not None: modifier(hts_a) if cache_files and not clean_cache: self._to_cache(cachedir, cachefile, hts_a, inv_a, ltl_a, model_info) self.model_info.combine(model_info) hts.combine(hts_a) invar_props += inv_a ltl_props += ltl_a Logger.log("DONE", 0) continue Logger.error( "Filetype \"%s\" unsupported or parser is not available" % filetype) if Logger.level(1): print(hts.print_statistics(name, Logger.level(2))) return (hts, invar_props, ltl_props)
def parse_model(self, \ relative_path, \ model_files, \ encoder_config, \ name=None, \ modifier=None, \ cache_files=False, \ clean_cache=False): hts = HTS(name if name is not None else "System") invar_props = [] ltl_props = [] models = model_files.split(FILE_SP) for strfile in models: (strfile, flags) = self.get_file_flags(strfile) filetype = strfile.split(".")[-1] strfile = strfile.replace("~", os.path.expanduser("~")) if strfile[0] != "/": strfile = relative_path + strfile parser = None for av_parser in ModelParsersFactory.get_parsers(): assert av_parser.name is not None if filetype in av_parser.get_extensions(): parser = av_parser if not self.parser: self.parser = av_parser if parser is not None: if not os.path.isfile(strfile): Logger.error("File \"%s\" does not exist" % strfile) if cache_files: md5 = self.md5(strfile) cf = "-".join(["1" if encoder_config.abstract_clock else "0", \ "1" if encoder_config.add_clock else "0", \ "1" if encoder_config.boolean else "0"]) cachefile = "%s-%s" % (md5, cf) cachedir = "%s/%s" % ("/".join( strfile.split("/")[:-1]), COSACACHEDIR) if cache_files and self._is_cached(cachedir, cachefile, clean_cache): Logger.msg( "Loading from cache file \"%s\"... " % (strfile), 0) (hts_a, inv_a, ltl_a, model_info) = self._from_cache(cachedir, cachefile, encoder_config, flags) else: Logger.msg("Parsing file \"%s\"... " % (strfile), 0) (hts_a, inv_a, ltl_a) = parser.parse_file(strfile, encoder_config, flags) model_info = parser.get_model_info() if modifier is not None: modifier(hts_a) if cache_files and not clean_cache: self._to_cache(cachedir, cachefile, hts_a, inv_a, ltl_a, model_info) self.model_info.combine(model_info) hts.combine(hts_a) invar_props += inv_a ltl_props += ltl_a Logger.log("DONE", 0) continue Logger.error( "Filetype \"%s\" unsupported or parser is not available" % filetype) if Logger.level(1): print(hts.print_statistics(name, Logger.level(2))) return (hts, invar_props, ltl_props)
def parse_model(self, \ relative_path, \ model_files, \ abstract_clock, \ symbolic_init, \ name=None, \ deterministic=False, \ boolean=False, \ no_clock=False, \ run_passes=True): hts = HTS("System 1") invar_props = [] ltl_props = [] models = model_files.split(MODEL_SP) for strfile in models: (strfile, flags) = self.get_file_flags(strfile) filetype = strfile.split(".")[-1] strfile = strfile.replace("~", os.path.expanduser("~")) if strfile[0] != "/": strfile = relative_path + strfile parser = None if filetype in CoreIRParser.get_extensions(): parser = CoreIRParser(abstract_clock, symbolic_init, no_clock, run_passes) parser.boolean = boolean parser.deterministic = deterministic self.parser = parser if filetype in ExplicitTSParser.get_extensions(): parser = ExplicitTSParser() if not self.parser: self.parser = parser if filetype in SymbolicTSParser.get_extensions(): parser = SymbolicTSParser() if not self.parser: self.parser = parser if filetype in SymbolicSimpleTSParser.get_extensions(): parser = SymbolicSimpleTSParser() if not self.parser: self.parser = parser if filetype in BTOR2Parser.get_extensions(): parser = BTOR2Parser() if not self.parser: self.parser = parser if parser is not None: if not os.path.isfile(strfile): Logger.error("File \"%s\" does not exist" % strfile) Logger.msg("Parsing file \"%s\"... " % (strfile), 0) (hts_a, inv_a, ltl_a) = parser.parse_file(strfile, flags) hts.combine(hts_a) invar_props += inv_a ltl_props += ltl_a Logger.log("DONE", 0) continue Logger.error("Filetype \"%s\" unsupported" % filetype) if Logger.level(1): print(hts.print_statistics(name, Logger.level(2))) return (hts, invar_props, ltl_props)