def do(SM, EngineType=engine.FORWARD, ReloadStateExtern=None, OnBeforeReload=None, OnAfterReload=None): # Generate Analyzer from StateMachine analyzer = Analyzer.from_StateMachine(SM, EngineType, ReloadStateExtern) # Optimize the Analyzer analyzer = optimizer.do(analyzer) # DoorID-s required by '.prepare_for_reload()' analyzer.prepare_DoorIDs() # Prepare the reload BEFORE mega state compression! # (Null-operation, in case no reload required.) # TransitionMap: On BufferLimitCode --> ReloadState # ReloadState.door of state: OnBeforeReload # prepare goto on reload success and reload fail # State.door of ReloadState: OnAfterReload (when reload was a success). for state in analyzer.state_db.itervalues(): # Null-operation, in case no reload required. state.prepare_for_reload(analyzer, OnBeforeReload, OnAfterReload) # [Optional] Combination of states into MegaState-s. if len(Setup.compression_type_list) != 0: mega_state_analyzer.do(analyzer) # Prepare Reload: # (Null-operation, in case no reload required.) # TransitionMap: On BufferLimitCode --> ReloadState # ReloadState.door of mega state: Router to doors of implemented states. for state in analyzer.mega_state_list: state.prepare_again_for_reload(analyzer) # AnalyzerState.transition_map: Interval --> DoorID # MegaState.transition_map: Interval --> TargetByStateKey # or Interval --> DoorID return analyzer
def do(SM, EngineType=E_EngineTypes.FORWARD): # Generate Analyzer from StateMachine analyzer = Analyzer(SM, EngineType) # Optimize the Analyzer analyzer = optimizer.do(analyzer) # The language database requires the analyzer for labels etc. if Setup.language_db is not None: Setup.language_db.register_analyzer(analyzer) # If required by the user: Combine some states into mega states. mega_state_analyzer.do(analyzer) return analyzer
def do(SmOrSmList, EngineType=engine.FORWARD, ReloadStateExtern=None, OnBeforeReload=None, OnAfterReload=None, OnBeforeEntry=None, dial_db=None, OnReloadFailureDoorId=None, CutF=True, ReverseF=False): assert dial_db is not None def treat(sm, ReverseF): backup_id = sm.get_id() ok_f, sm = Setup.buffer_encoding.do_state_machine(sm) if not ok_f: error.warning("Pattern contains elements not found in engine codec '%s'.\n" % Setup.buffer_encoding.name \ + "(Buffer element size is %s [byte])" % Setup.lexatom.size_in_byte, sm.sr) if ReverseF: sm = reverse.do(sm, EnsureDFA_f=True) sm.set_id(backup_id) return sm if type(SmOrSmList) != list: SM = treat(SmOrSmList, ReverseF) else: assert SmOrSmList sm_list = [treat(sm, ReverseF) for sm in SmOrSmList] SM = combination.do(sm_list, FilterDominatedOriginsF=False) SM.sr = sm_list[0].sr if CutF: error_name = SM.delete_named_number_list(signal_lexatoms(Setup)) if error_name: error.log( "Pattern is empty after deletion of signal lexatom '%s'" % error_name, SM.sr) # Generate FSM from DFA analyzer = FSM.from_DFA(SM, EngineType, ReloadStateExtern, OnBeforeEntry, dial_db=dial_db) # Optimize the FSM analyzer = optimizer.do(analyzer) # DoorID-s required by '.prepare_for_reload()' analyzer.prepare_DoorIDs() # Prepare the reload BEFORE mega state compression! # (Null-operation, in case no reload required.) # TransitionMap: On BufferLimitCode --> ReloadState # ReloadState.door of state: OnBeforeReload # prepare goto on reload success and reload fail # State.door of ReloadState: OnAfterReload (when reload was a success). for si, state in sorted(analyzer.state_db.iteritems(), key=itemgetter(0)): # Null-operation, in case no reload required. state.prepare_for_reload(analyzer, OnBeforeReload, OnAfterReload, OnFailureDoorId=OnReloadFailureDoorId) # [Optional] Combination of states into MegaState-s. if len(Setup.compression_type_list) != 0: mega_state_analyzer.do(analyzer) # Prepare Reload: # (Null-operation, in case no reload required.) # TransitionMap: On BufferLimitCode --> ReloadState # ReloadState.door of mega state: Router to doors of implemented states. for state in analyzer.mega_state_list: state.prepare_again_for_reload(analyzer) # FSM_State.transition_map: Interval --> DoorID # MegaState.transition_map: Interval --> TargetByStateKey # or Interval --> DoorID return analyzer