dol: initial dol commit
[jump.git] / dol / src / dol / visitor / hdsd / lib / dol.h
diff --git a/dol/src/dol/visitor/hdsd/lib/dol.h b/dol/src/dol/visitor/hdsd/lib/dol.h
new file mode 100644 (file)
index 0000000..8e99671
--- /dev/null
@@ -0,0 +1,141 @@
+#ifndef DOL_H
+#define DOL_H
+
+#include <stdarg.h>
+#include <stdio.h>
+#include <string.h>
+
+#ifdef __DOL_ETHZ_GEN__
+#include <systemc>
+using sc_core::sc_port;
+#endif
+
+/************************************************************************
+ * do not add code to this header
+ ************************************************************************/
+
+/**
+ *  Define the DOL process handler scheme.
+ *  - Local variables are defined in structure LocalState. Local
+ *    variables may vary from different processes.
+ *  - The ProcessInit function pointer points to a function which
+ *    initializes a process.
+ *  - The ProcessFire function pointer points to a function which
+ *    performs the actual computation. The communication between
+ *    processes is inside the ProcessFire function.
+ *  - The WPTR is a placeholder for callback. One can just
+ *    leave it blank.
+ */
+
+//structure for local memory of process
+typedef struct _local_states *LocalState;
+
+//additional behavioral functions could be declared here
+typedef void (*ProcessInit)(struct _process*);
+typedef int (*ProcessFire)(struct _process*);
+typedef void *WPTR;
+
+//process handler
+struct _process;
+
+typedef struct _process {
+    LocalState     local;
+    ProcessInit    init;
+    ProcessFire    fire;
+    WPTR           wptr; //placeholder for wrapper instance
+} DOLProcess;
+
+
+//macros to deal with iterated ports
+/**
+ ******************************************************
+ * The HdS code is needed to replace the current ETHZ *
+ * implementation.                                    *
+ ******************************************************
+ *
+ * Macro to create a variable to store a port name.
+ *
+ * @param name name of the variable
+ */
+#ifdef __DOL_ETHZ_GEN__
+#define CREATEPORTVAR(name) sc_port<sc_interface> *name
+#else
+#define  CREATEPORTVAR(name) // Hds Code
+#endif
+
+/**
+ * Create the port name of an iterated port based on its basename and the
+ * given indices.
+ *
+ * @param port buffer where the result is stored (created using
+ *             CREATEPORTVAR)
+ * @param base basename of the port
+ * @param number_of_indices number of dimensions of the port
+ * @param index_range_pairs index and range values for each dimension
+ */
+#define CREATEPORT(port, base, number_of_indices, index_range_pairs...) \
+  createPort(&port, base, number_of_indices, index_range_pairs)
+
+int getIndex(const char* string, char* tokens, int indexNumber);
+
+/*
+ ******************************************************
+ * The HdS code is needed to replace the current ETHZ *
+ * implementation.                                    *
+ ******************************************************
+ */
+#ifdef __DOL_ETHZ_GEN__
+template <class interface>
+sc_port<interface> *createPort(sc_port<interface> **port,
+                               void *base,
+                               int number_of_indices,
+                               int index0, int range0) {
+    *port = &((static_cast<sc_port<interface> *>(base))[index0]);
+    return &((static_cast<sc_port<interface> *>(base))[index0]);
+}
+
+template <class interface>
+sc_port<interface> *createPort(sc_port<interface> **port,
+                               void *base,
+                               int number_of_indices,
+                               int index0, int range0,
+                               int index1, int range1) {
+    *port = &((static_cast<sc_port<interface> *>(base))[
+            index0 * range1 + index1]);
+    return &((static_cast<sc_port<interface> *>(base))[
+            index0 * range1 + index1]);
+}
+
+template <class interface>
+sc_port<interface> *createPort(sc_port<interface> **port,
+                               void *base,
+                               int number_of_indices,
+                               int index0, int range0,
+                               int index1, int range1,
+                               int index2, int range2) {
+    *port = &((static_cast<sc_port<interface> *>(base))[
+            index0 * range1 * range2 + index1 * range0 + index2]);
+    return &((static_cast<sc_port<interface> *>(base))[
+            index0 * range1 * range2 + index1 * range0 + index2]);
+}
+
+template <class interface>
+sc_port<interface> *createPort(sc_port<interface> **port,
+                               void *base,
+                               int number_of_indices,
+                               int index0, int range0,
+                               int index1, int range1,
+                               int index2, int range2,
+                               int index3, int range3) {
+    *port = &((static_cast<sc_port<interface> *>(base))[
+            index0 * range1 * range2 * range3
+            + index1 * range2 * range3 + index2 * range3 + index3]);
+    return &((static_cast<sc_port<interface> *>(base))[
+            index0 * range1 * range2 * range3
+            + index1 * range2 * range3 + index2 * range3 + index3]);
+}
+#else
+#define createPort() //HdS code
+#endif
+
+#endif