Exemplo n.º 1
0
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
Exemplo n.º 2
0
def test(SM, EngineType = engine.FORWARD, PrintPRM_F = False):
    
    print SM.get_string(NormalizeF=True, OriginalStatesF=False)

    plain = core.Analyzer.from_StateMachine(SM, EngineType)

    # Print plain analyzer, note down what changed during optimization
    states_txt_db = print_analyzer(plain)

    if PrintPRM_F:
        print_this(plain)

    diff_txt_db = {}
    optimized = optimizer.do(plain)
    for state in optimized:
        optimized_txt = get_state_text(optimized, optimized.state_db[state.index])
        if states_txt_db[state.index] != optimized_txt:
            diff_txt_db[state.index] = optimized_txt

    # Print the results of optimization
    if len(diff_txt_db):
        print 
        print "--- Optimized States ---"
        print 
        for state_index, state_txt in sorted(diff_txt_db.iteritems(), key=itemgetter(0)):
            print state_txt
Exemplo n.º 3
0
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
Exemplo n.º 4
0
Arquivo: help.py Projeto: xxyzzzq/quex
def test(SM, EngineType=engine.FORWARD, PrintPRM_F=False):

    print SM.get_string(NormalizeF=True, OriginalStatesF=False)

    plain = core.Analyzer.from_StateMachine(SM, EngineType)

    # Print plain analyzer, note down what changed during optimization
    states_txt_db = print_analyzer(plain)

    if PrintPRM_F:
        print_this(plain)

    diff_txt_db = {}
    optimized = optimizer.do(plain)
    for state in optimized:
        optimized_txt = get_state_text(optimized,
                                       optimized.state_db[state.index])
        if states_txt_db[state.index] != optimized_txt:
            diff_txt_db[state.index] = optimized_txt

    # Print the results of optimization
    if len(diff_txt_db):
        print
        print "--- Optimized States ---"
        print
        for state_index, state_txt in sorted(diff_txt_db.iteritems(),
                                             key=itemgetter(0)):
            print state_txt
Exemplo n.º 5
0
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
Exemplo n.º 6
0
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