1 /****************************************************************************
2     Copyright (C) 1987-2015 by Jeffery P. Hansen
3 
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8 
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13 
14     You should have received a copy of the GNU General Public License along
15     with this program; if not, write to the Free Software Foundation, Inc.,
16     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 ****************************************************************************/
18 #ifndef __systask_h
19 #define __systask_h
20 
21 /*
22  * Indicate there is no limit to the number of arguments
23  */
24 #define NOLIM		0x7ffffff
25 
26 /*
27  * Maximum number of files open through Verilog $fopen()
28  */
29 #define STT_MAXFILES	31
30 
31 /*****************************************************************************
32  *
33  * Task argument type code
34  *
35  *****************************************************************************/
36 typedef enum {
37   TAT_VALUE=0,
38   TAT_NET=1,
39   TAT_TRIGGER=2,
40   TAT_TRIGGERPAIR=3,
41   TAT_EXPR=4
42 } stargtype_t;
43 
44 /*****************************************************************************
45  *
46  * Task action code
47  *
48  *****************************************************************************/
49 typedef enum {
50   TA_SETUP,					/* This is the setup call of the task */
51   TA_STROBE,					/* This is a strobed call of the task */
52   TA_REMOVE,					/* This is a remove call of the task */
53 } taskact_t;
54 
55 
56 /*****************************************************************************
57  *
58  * System task flags
59  *
60  *****************************************************************************/
61 typedef enum {
62   STF_NONE = 0,
63   STF_NEEDCTX = 0x1,
64   STF_NEEDNETS = 0x2,
65   STF_SPECIFY = 0x4,
66 } taskflag_t;
67 
68 /*****************************************************************************
69  *
70  * Context for persistent or late executing tasks.
71  *
72  *****************************************************************************/
73 typedef struct {
74   taskact_t	tc_action;			/* Type of action we are doing */
75 
76   VGThread	*tc_thread;			/* Thread to use in block */
77   CodeBlock	*tc_codeBlock;			/* Copy of bytecode to execute systask */
78   int		tc_numNets;			/* Number of dependent nets */
79   Net		**tc_nets;			/* Array of dependent nets */
80   Value		**tc_lastValues;		/* Array of last values for nets */
81   void		*tc_data;			/* Task specific data */
82 } TaskContext;
83 
84 /*****************************************************************************
85  *
86  * Function pointer class for function implementing Verilog system tasks such
87  * as $display, $monitor, $strobe, $stop, etc.
88  *
89  *****************************************************************************/
90 typedef void systask_f(VGThread *t,		/* Thread system task is executing in */
91 		       Value *r,		/* Return value if used in expression */
92 		       int numArgs,		/* Number of arguments */
93 		       void **args,		/* Argument values */
94 		       TaskContext *tc);	/* Optional task context (used by persistent tasks) */
95 
96 /*****************************************************************************
97  *
98  * Description of system tasks
99  *
100  *****************************************************************************/
101 typedef struct {
102   const char	*st_name;		/* Name of task */
103   systask_f	*st_func;		/* Function implementing task */
104   int		st_minArgs;		/* Minimum number of arguments */
105   int		st_maxArgs;		/* Maximum number of arguments */
106 #if 0
107   int		st_needContext;		/* Non-zero if we need to pass context */
108   int		st_needNets;		/* Do we need net dependency info? */
109 #endif
110   taskflag_t	st_flags;		/* Task flags */
111   stargtype_t	st_argTypes[STASK_MAXSPECARGS];	/* Argument types */
112 } SysTaskDescript;
113 
114 
115 systask_f *SysTask_find(const char*);		/* Find named system task */
116 SysTaskDescript *SysTask_findEnt(const char*);	/* Find named system task */
117 const char *SysTask_findName(systask_f *);	/* Find task name from task function */
118 
119 /*****************************************************************************
120  * TaskContext member functions
121  *****************************************************************************/
122 TaskContext *new_TaskContext(int nargs,Expr **args,ModuleInst *modCtx);
123 void delete_TaskContext(TaskContext *);
124 void TaskContext_setBlock(TaskContext *tc,CodeBlock *cb,ModuleInst *modCtx,unsigned start,unsigned stop);
125 
126 #endif
127 
128