1 //
2 //  Copyright (C) 2011-2018  Nick Gasson
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 3 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
15 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 //
17 
18 #ifndef _RT_H
19 #define _RT_H
20 
21 #include "ident.h"
22 #include "prim.h"
23 
24 #include <stdint.h>
25 
26 typedef struct watch watch_t;
27 
28 typedef void (*sig_event_fn_t)(uint64_t now, tree_t, watch_t *, void *user);
29 typedef void (*timeout_fn_t)(uint64_t now, void *user);
30 typedef void (*rt_event_fn_t)(void *user);
31 
32 typedef enum {
33    BOUNDS_ARRAY_TO,
34    BOUNDS_ARRAY_DOWNTO,
35    BOUNDS_ENUM,
36    BOUNDS_TYPE_TO,
37    BOUNDS_TYPE_DOWNTO,
38    BOUNDS_ARRAY_SIZE,
39    BOUNDS_INDEX_TO,
40    BOUNDS_INDEX_DOWNTO,
41 } bounds_kind_t;
42 
43 typedef enum {
44    BIT_SHIFT_SLL,
45    BIT_SHIFT_SRL,
46    BIT_SHIFT_SLA,
47    BIT_SHIFT_SRA,
48    BIT_SHIFT_ROL,
49    BIT_SHIFT_ROR,
50 } bit_shift_kind_t;
51 
52 typedef enum {
53    BIT_VEC_NOT,
54    BIT_VEC_AND,
55    BIT_VEC_OR,
56    BIT_VEC_XOR,
57    BIT_VEC_XNOR,
58    BIT_VEC_NAND,
59    BIT_VEC_NOR
60 } bit_vec_op_kind_t;
61 
62 typedef enum {
63    IMAGE_INTEGER,
64    IMAGE_REAL,
65    IMAGE_ENUM,
66    IMAGE_PHYSICAL,
67 } image_kind_t;
68 
69 typedef enum {
70    R_MEMO     = (1 << 0),
71    R_IDENT    = (1 << 1),
72    R_RECORD   = (1 << 2),
73    R_BOUNDARY = (1 << 3),
74 } res_flags_t;
75 
76 typedef enum {
77    NET_F_ACTIVE     = (1 << 0),
78    NET_F_EVENT      = (1 << 1),
79    NET_F_FORCED     = (1 << 2),
80    NET_F_OWNS_MEM   = (1 << 3),
81    NET_F_GLOBAL     = (1 << 4),
82    NET_F_LAST_VALUE = (1 << 5),
83    NET_F_BOUNDARY   = (1 << 6),
84 } net_flags_t;
85 
86 typedef enum {
87    SCHED_SEQUENTIAL = (1 << 0),
88    SCHED_STATIC     = (1 << 1)
89 } sched_flags_t;
90 
91 typedef enum {
92    RT_START_OF_SIMULATION,
93    RT_END_OF_SIMULATION,
94    RT_END_OF_PROCESSES,
95    RT_LAST_KNOWN_DELTA_CYCLE,
96    RT_NEXT_TIME_STEP,
97 
98    RT_LAST_EVENT
99 } rt_event_t;
100 
101 typedef enum {
102    SEVERITY_NOTE,
103    SEVERITY_WARNING,
104    SEVERITY_ERROR,
105    SEVERITY_FAILURE
106 } rt_severity_t;
107 
108 typedef struct {
109    loc_t  loc;
110    tree_t tree;
111 } jit_trace_t;
112 
113 void rt_start_of_tool(tree_t top);
114 void rt_end_of_tool(tree_t top);
115 void rt_run_sim(uint64_t stop_time);
116 void rt_run_interactive(uint64_t stop_time);
117 void rt_restart(tree_t top);
118 void rt_set_timeout_cb(uint64_t when, timeout_fn_t fn, void *user);
119 watch_t *rt_set_event_cb(tree_t s, sig_event_fn_t fn, void *user,
120                          bool postponed);
121 void rt_set_global_cb(rt_event_t event, rt_event_fn_t fn, void *user);
122 size_t rt_watch_value(watch_t *w, uint64_t *buf, size_t max, bool last);
123 size_t rt_watch_string(watch_t *w, const char *map, char *buf, size_t max);
124 size_t rt_signal_value(tree_t s, uint64_t *buf, size_t max);
125 size_t rt_signal_string(tree_t s, const char *map, char *buf, size_t max);
126 bool rt_force_signal(tree_t s, const uint64_t *buf, size_t count,
127                      bool propagate);
128 bool rt_can_create_delta(void);
129 uint64_t rt_now(unsigned *deltas);
130 void rt_stop(void);
131 void rt_set_exit_severity(rt_severity_t severity);
132 
133 void jit_init(tree_t top);
134 void jit_shutdown(void);
135 void *jit_find_symbol(const char *name, bool required);
136 void jit_trace(jit_trace_t **trace, size_t *count);
137 
138 text_buf_t *pprint(struct tree *t, const uint64_t *values, size_t len);
139 
140 void vcd_init(const char *file, struct tree *top);
141 void vcd_restart(void);
142 
143 void lxt_init(const char *file, struct tree *top);
144 void lxt_restart(void);
145 
146 void fst_init(const char *file, tree_t top);
147 void fst_restart(void);
148 
149 void wave_include_glob(const char *glob);
150 void wave_exclude_glob(const char *glob);
151 void wave_include_file(const char *base);
152 bool wave_should_dump(tree_t decl);
153 
154 #ifdef ENABLE_VHPI
155 void vhpi_load_plugins(tree_t top, const char *plugins);
156 #else
157 #define vhpi_load_plugins(top, plugins)
158 #endif
159 
160 #endif  // _RT_H
161