/* SPDX-License-Identifier: GPL-2.0 */1/*2* Copyright (C) 2019-2022 Red Hat, Inc. Daniel Bristot de Oliveira <[email protected]>3*4* Deterministic automata helper functions, to be used with the automata5* models in C generated by the dot2k tool.6*/78/*9* DECLARE_AUTOMATA_HELPERS - define a set of helper functions for automata10*11* Define a set of helper functions for automata. The 'name' argument is used12* as suffix for the functions and data. These functions will handle automaton13* with data type 'type'.14*/15#define DECLARE_AUTOMATA_HELPERS(name, type) \16\17/* \18* model_get_state_name_##name - return the (string) name of the given state \19*/ \20static char *model_get_state_name_##name(enum states_##name state) \21{ \22if ((state < 0) || (state >= state_max_##name)) \23return "INVALID"; \24\25return automaton_##name.state_names[state]; \26} \27\28/* \29* model_get_event_name_##name - return the (string) name of the given event \30*/ \31static char *model_get_event_name_##name(enum events_##name event) \32{ \33if ((event < 0) || (event >= event_max_##name)) \34return "INVALID"; \35\36return automaton_##name.event_names[event]; \37} \38\39/* \40* model_get_initial_state_##name - return the automaton's initial state \41*/ \42static inline type model_get_initial_state_##name(void) \43{ \44return automaton_##name.initial_state; \45} \46\47/* \48* model_get_next_state_##name - process an automaton event occurrence \49* \50* Given the current state (curr_state) and the event (event), returns \51* the next state, or INVALID_STATE in case of error. \52*/ \53static inline type model_get_next_state_##name(enum states_##name curr_state, \54enum events_##name event) \55{ \56if ((curr_state < 0) || (curr_state >= state_max_##name)) \57return INVALID_STATE; \58\59if ((event < 0) || (event >= event_max_##name)) \60return INVALID_STATE; \61\62return automaton_##name.function[curr_state][event]; \63} \64\65/* \66* model_is_final_state_##name - check if the given state is a final state \67*/ \68static inline bool model_is_final_state_##name(enum states_##name state) \69{ \70if ((state < 0) || (state >= state_max_##name)) \71return 0; \72\73return automaton_##name.final_states[state]; \74}757677