dol: initial dol commit
[jump.git] / dol / src / dol / visitor / hdsd / lib / dol.h
1 #ifndef DOL_H
2 #define DOL_H
3
4 #include <stdarg.h>
5 #include <stdio.h>
6 #include <string.h>
7
8 #ifdef __DOL_ETHZ_GEN__
9 #include <systemc>
10 using sc_core::sc_port;
11 #endif
12
13 /************************************************************************
14  * do not add code to this header
15  ************************************************************************/
16
17 /**
18  *  Define the DOL process handler scheme.
19  *  - Local variables are defined in structure LocalState. Local
20  *    variables may vary from different processes.
21  *  - The ProcessInit function pointer points to a function which
22  *    initializes a process.
23  *  - The ProcessFire function pointer points to a function which
24  *    performs the actual computation. The communication between
25  *    processes is inside the ProcessFire function.
26  *  - The WPTR is a placeholder for callback. One can just
27  *    leave it blank.
28  */
29
30 //structure for local memory of process
31 typedef struct _local_states *LocalState;
32
33 //additional behavioral functions could be declared here
34 typedef void (*ProcessInit)(struct _process*);
35 typedef int (*ProcessFire)(struct _process*);
36 typedef void *WPTR;
37
38 //process handler
39 struct _process;
40
41 typedef struct _process {
42     LocalState     local;
43     ProcessInit    init;
44     ProcessFire    fire;
45     WPTR           wptr; //placeholder for wrapper instance
46 } DOLProcess;
47
48
49 //macros to deal with iterated ports
50 /**
51  ******************************************************
52  * The HdS code is needed to replace the current ETHZ *
53  * implementation.                                    *
54  ******************************************************
55  *
56  * Macro to create a variable to store a port name.
57  *
58  * @param name name of the variable
59  */
60 #ifdef __DOL_ETHZ_GEN__
61 #define CREATEPORTVAR(name) sc_port<sc_interface> *name
62 #else
63 #define  CREATEPORTVAR(name) // Hds Code
64 #endif
65
66 /**
67  * Create the port name of an iterated port based on its basename and the
68  * given indices.
69  *
70  * @param port buffer where the result is stored (created using
71  *             CREATEPORTVAR)
72  * @param base basename of the port
73  * @param number_of_indices number of dimensions of the port
74  * @param index_range_pairs index and range values for each dimension
75  */
76 #define CREATEPORT(port, base, number_of_indices, index_range_pairs...) \
77   createPort(&port, base, number_of_indices, index_range_pairs)
78
79 int getIndex(const char* string, char* tokens, int indexNumber);
80
81 /*
82  ******************************************************
83  * The HdS code is needed to replace the current ETHZ *
84  * implementation.                                    *
85  ******************************************************
86  */
87 #ifdef __DOL_ETHZ_GEN__
88 template <class interface>
89 sc_port<interface> *createPort(sc_port<interface> **port,
90                                void *base,
91                                int number_of_indices,
92                                int index0, int range0) {
93     *port = &((static_cast<sc_port<interface> *>(base))[index0]);
94     return &((static_cast<sc_port<interface> *>(base))[index0]);
95 }
96
97 template <class interface>
98 sc_port<interface> *createPort(sc_port<interface> **port,
99                                void *base,
100                                int number_of_indices,
101                                int index0, int range0,
102                                int index1, int range1) {
103     *port = &((static_cast<sc_port<interface> *>(base))[
104             index0 * range1 + index1]);
105     return &((static_cast<sc_port<interface> *>(base))[
106             index0 * range1 + index1]);
107 }
108
109 template <class interface>
110 sc_port<interface> *createPort(sc_port<interface> **port,
111                                void *base,
112                                int number_of_indices,
113                                int index0, int range0,
114                                int index1, int range1,
115                                int index2, int range2) {
116     *port = &((static_cast<sc_port<interface> *>(base))[
117             index0 * range1 * range2 + index1 * range0 + index2]);
118     return &((static_cast<sc_port<interface> *>(base))[
119             index0 * range1 * range2 + index1 * range0 + index2]);
120 }
121
122 template <class interface>
123 sc_port<interface> *createPort(sc_port<interface> **port,
124                                void *base,
125                                int number_of_indices,
126                                int index0, int range0,
127                                int index1, int range1,
128                                int index2, int range2,
129                                int index3, int range3) {
130     *port = &((static_cast<sc_port<interface> *>(base))[
131             index0 * range1 * range2 * range3
132             + index1 * range2 * range3 + index2 * range3 + index3]);
133     return &((static_cast<sc_port<interface> *>(base))[
134             index0 * range1 * range2 * range3
135             + index1 * range2 * range3 + index2 * range3 + index3]);
136 }
137 #else
138 #define createPort() //HdS code
139 #endif
140
141 #endif