From 164ac3a34cbac441e82b256c97cb8784ea9d482c Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Mon, 17 Mar 2008 22:53:01 +0100 Subject: * tools/dfagen: - added dfagen. --- tools/dfagen/dfagen/output/c/template.c | 39 ++++++++++++++++ tools/dfagen/dfagen/output/c/template.h | 59 +++++++++++++++++++++++++ tools/dfagen/dfagen/output/c/template_cb.h | 12 +++++ tools/dfagen/dfagen/output/c/template_cb_decl.h | 6 +++ tools/dfagen/dfagen/output/c/template_cb_impl.c | 9 ++++ tools/dfagen/dfagen/output/c/template_cb_skel.c | 9 ++++ 6 files changed, 134 insertions(+) create mode 100644 tools/dfagen/dfagen/output/c/template.c create mode 100644 tools/dfagen/dfagen/output/c/template.h create mode 100644 tools/dfagen/dfagen/output/c/template_cb.h create mode 100644 tools/dfagen/dfagen/output/c/template_cb_decl.h create mode 100644 tools/dfagen/dfagen/output/c/template_cb_impl.c create mode 100644 tools/dfagen/dfagen/output/c/template_cb_skel.c (limited to 'tools/dfagen/dfagen/output/c') diff --git a/tools/dfagen/dfagen/output/c/template.c b/tools/dfagen/dfagen/output/c/template.c new file mode 100644 index 00000000..a8679046 --- /dev/null +++ b/tools/dfagen/dfagen/output/c/template.c @@ -0,0 +1,39 @@ +/* + * THIS IS AN AUTOMATICALLY GENERATED FILE, DO NOT EDIT! + * + * %(name)s + * +%(*comments)s */ +#include "%(prefix)s_cb.h" +#include +#include + +%(_user.type-decl)s +/* %(name)s transition table. */ +static const %(prefix)s_transition_t +%(prefix)s_transition_table[%(PREFIX)s_STATE_NB][%(PREFIX)s_EVENT_NB] = { +%(transition_table)s}; + +/* Initialise %(name)s automaton. */ +void +%(prefix)s_init (%(user.type)s *user) +{ + user->%(user.field)s = %(PREFIX)s_STATE_%(initial)s; +} + +/* Handle events on %(name)s automaton. */ +void +%(prefix)s_handle_event (%(user.type)s *user, %(prefix)s_event_t event) +{ + assert (user); + %(prefix)s_state_t state = user->%(user.field)s; + assert (state < %(PREFIX)s_STATE_NB); + assert (event < %(PREFIX)s_EVENT_NB); + %(prefix)s_transition_t tr = %(prefix)s_transition_table[state][event]; + assert (tr); + %(prefix)s_branch_t br = tr (user); + assert (((br >> 16) & 0xff) == state); + assert (((br >> 8) & 0xff) == event); + user->%(user.field)s = br & 0xff; +} + diff --git a/tools/dfagen/dfagen/output/c/template.h b/tools/dfagen/dfagen/output/c/template.h new file mode 100644 index 00000000..2be89f31 --- /dev/null +++ b/tools/dfagen/dfagen/output/c/template.h @@ -0,0 +1,59 @@ +#ifndef %(prefix)s_h +#define %(prefix)s_h +/* + * THIS IS AN AUTOMATICALLY GENERATED FILE, DO NOT EDIT! + * + * %(name)s + * +%(*comments)s */ + +%(_user.type-forward-decl)s +/* %(name)s states. */ +enum %(prefix)s_state_t +{ +%(states)s %(PREFIX)s_STATE_NB +}; +typedef enum %(prefix)s_state_t %(prefix)s_state_t; + +/* %(name)s events. */ +enum %(prefix)s_event_t +{ +%(events)s %(PREFIX)s_EVENT_NB +}; +typedef enum %(prefix)s_event_t %(prefix)s_event_t; + +/* This macro enables checks for branches used in the wrong state/event + * combination. */ +#define _BRANCH(state, event, to) \ + ((%(PREFIX)s_STATE_ ## state) << 16 \ + | (%(PREFIX)s_EVENT_ ## event) << 8 \ + | (%(PREFIX)s_STATE_ ## to)) + +/* %(name)s branches. */ +enum %(prefix)s_branch_t +{ +%(branches)s}; +typedef enum %(prefix)s_branch_t %(prefix)s_branch_t; + +#undef _BRANCH + +/* %(name)s transition type. */ +typedef %(prefix)s_branch_t (*%(prefix)s_transition_t) (%(user.type)s *user); + +/* Initialise %(name)s automaton. */ +void +%(prefix)s_init (%(user.type)s *user); + +/* Handle events on %(name)s automaton. */ +void +%(prefix)s_handle_event (%(user.type)s *user, %(prefix)s_event_t event); + +/* Value to return to follow the only branch. */ +#define %(prefix)s_next(state, event) \ + %(PREFIX)s_BRANCH__ ## state ## __ ## event ## __ + +/* Value to return to follow a given branch. */ +#define %(prefix)s_next_branch(state, event, branch) \ + %(PREFIX)s_BRANCH__ ## state ## __ ## event ## __ ## branch + +#endif /* %(prefix)s_h */ diff --git a/tools/dfagen/dfagen/output/c/template_cb.h b/tools/dfagen/dfagen/output/c/template_cb.h new file mode 100644 index 00000000..6252b28c --- /dev/null +++ b/tools/dfagen/dfagen/output/c/template_cb.h @@ -0,0 +1,12 @@ +#ifndef %(prefix)s_cb_h +#define %(prefix)s_cb_h +/* + * THIS IS AN AUTOMATICALLY GENERATED FILE, DO NOT EDIT! + * + * %(name)s callbacks declaration. + * +%(*comments)s */ + +#include "%(prefix)s.h" + +%(cb_decl)s#endif /* %(prefix)s_cb_h */ diff --git a/tools/dfagen/dfagen/output/c/template_cb_decl.h b/tools/dfagen/dfagen/output/c/template_cb_decl.h new file mode 100644 index 00000000..a1e7c0f2 --- /dev/null +++ b/tools/dfagen/dfagen/output/c/template_cb_decl.h @@ -0,0 +1,6 @@ +/* + * %(state)s =%(event)s=> +%(*branches_to)s */ +%(prefix)s_branch_t +%(prefix)s__%(state)s__%(event)s (%(user.type)s *user); + diff --git a/tools/dfagen/dfagen/output/c/template_cb_impl.c b/tools/dfagen/dfagen/output/c/template_cb_impl.c new file mode 100644 index 00000000..ffd9720f --- /dev/null +++ b/tools/dfagen/dfagen/output/c/template_cb_impl.c @@ -0,0 +1,9 @@ +/* + * %(state)s =%(event)s=> +%(*branches_to)s */ +%(prefix)s_branch_t +%(prefix)s__%(state)s__%(event)s (%(user.type)s *user) +{ +%(returns)s +} + diff --git a/tools/dfagen/dfagen/output/c/template_cb_skel.c b/tools/dfagen/dfagen/output/c/template_cb_skel.c new file mode 100644 index 00000000..95abbd42 --- /dev/null +++ b/tools/dfagen/dfagen/output/c/template_cb_skel.c @@ -0,0 +1,9 @@ +/* + * THIS IS AN AUTOMATICALLY GENERATED FILE, DO NOT EDIT! + * + * Skeleton for %(name)s callbacks implementation. + * +%(*comments)s */ +#include "%(prefix)s_cb.h" + +%(cb_impl)s -- cgit v1.2.3