summaryrefslogtreecommitdiff
path: root/tools/dfagen/dfagen/output/c
diff options
context:
space:
mode:
authorNicolas Schodet2008-03-17 22:53:01 +0100
committerNicolas Schodet2008-03-17 22:53:01 +0100
commit164ac3a34cbac441e82b256c97cb8784ea9d482c (patch)
treeb0db1276083d168b50e6aa2be9621368a36184cd /tools/dfagen/dfagen/output/c
parent388a90600023cca7d7b28702fa4cc75ed5074123 (diff)
* tools/dfagen:
- added dfagen.
Diffstat (limited to 'tools/dfagen/dfagen/output/c')
-rw-r--r--tools/dfagen/dfagen/output/c/template.c39
-rw-r--r--tools/dfagen/dfagen/output/c/template.h59
-rw-r--r--tools/dfagen/dfagen/output/c/template_cb.h12
-rw-r--r--tools/dfagen/dfagen/output/c/template_cb_decl.h6
-rw-r--r--tools/dfagen/dfagen/output/c/template_cb_impl.c9
-rw-r--r--tools/dfagen/dfagen/output/c/template_cb_skel.c9
6 files changed, 134 insertions, 0 deletions
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 <stddef.h>
+#include <assert.h>
+
+%(_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