Menu

#100 Conditional compilation for state machine elements

QM
closed
None
1
2014-10-20
2014-10-09
No

This feature request is filed on behalf of a commercial QP licensee. Here is the original feature request:

Would it be possible to add following feature to QM?

C-preprocessor flagging for code. The QM would emit C-preprocessor directives to code to optimize away parts of the code in specific configurations.

Example:

FEA_BUTTON_TIMEOUT is defined to BUTTON_LP_TIMEOUT_SIG processing in the QM UI.

#if defined(FEA_BUTTON_LP_TIMEOUT_SIG)  <-- generated by QM
    case BUTTON_LP_TIMEOUT_SIG: {
        static QMTranActTable const tatbl_ = { /* transition-action table */
            &Button_long_s,
            {
                Q_ACTION_CAST(0) /* zero terminator */
            }
        };
        maVERIFY(Q_EVT_CAST(ButtonTimeoutEvt)->id < BF_BUTTONS, Q_HANDLED());

        QF_PUBLISH(&buttons_long_start_to_signals[Q_EVT_CAST(ButtonTimeoutEvt)->id], me);
        status_ = QM_TRAN(&tatbl_);
        break;
    }
#endif <-- generated by QM

Use case:

Currently we are sharing many active objects between multiple projects. As we are compiling the active objects into libraries (.a) and then linking into the product project, the IAR compiler or IAR linker does not know that specific code is unused in the project and thus leaves the dead code to the resulting binary. I think the dead code elimination works in IAR based on symbols, such as functions or global variables / constants. The IAR does not know that the BUTTON_LP_TIMEOUT_SIG signal is never sent in specific project so the code remains.

If we could add this flagging to the model, we could make product specific configurations of the libraries and thus reduce the size of the code drastically.

Implementation in QM

The UI of the QM could have a one property field called "pre-processor filter" for each internal or external transition, entry and exit handler and perhaps even for state. If this property field would contain any text, the QM would generate #if <pre-processor-filter> .... #endif pair to the correct code components.

Alternative options:

We have researched alternative options to reduce the code size.

1) One way is to use special config_xxx() function in the each of the signal handlers and implement the actual code in the project specific files, but this defeats the whole purpose of the modeler.
2) We could make product specific versions of the model files, but the number of combinations would grow too large really fast

Discussion

  • Quantum Leaps

    Quantum Leaps - 2014-10-20
    • status: open --> closed
     
  • Quantum Leaps

    Quantum Leaps - 2014-10-20

    Implemented in QM 3.2.2. The feature is described in the QM Help at:

    http://www.state-machine.com/qm/help/ce_cond.html

    --MMS

     

Anonymous
Anonymous

Add attachments
Cancel