Add a mark at simulation end for vcd/lxt/lxt2 files.
[iverilog.git] / vpi / lxt_write.h
blob6a2ea50b2cb0420472346418a253b0fed9ca403f
1 /*
2 * Copyright (c) 2001-3 Tony Bybell.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 * DEALINGS IN THE SOFTWARE.
23 #ifndef DEFS_LXT_H
24 #define DEFS_LXT_H
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <string.h>
29 #include <ctype.h>
30 #include <errno.h>
31 #include <unistd.h>
32 #include <zlib.h>
33 #include <bzlib.h>
35 #if defined _MSC_VER || defined __MINGW32__
36 #define fseeko fseek
37 #define ftello ftell
38 #endif
41 typedef struct dslxt_tree_node dslxt_Tree;
42 struct dslxt_tree_node {
43 dslxt_Tree * left, * right;
44 char *item;
45 unsigned int val;
49 #define LT_HDRID (0x0138)
50 #define LT_VERSION (0x0004)
51 #define LT_TRLID (0xB4)
53 #define LT_CLKPACK (4)
54 #define LT_CLKPACK_M (2)
56 #define LT_MVL_2 (1<<0)
57 #define LT_MVL_4 (1<<1)
58 #define LT_MVL_9 (1<<2)
60 #define LT_MINDICTWIDTH (16)
62 enum lt_zmode_types { LT_ZMODE_NONE, LT_ZMODE_GZIP, LT_ZMODE_BZIP2 };
65 typedef unsigned long long lxttime_t;
66 #define ULLDescriptor(x) x##ULL
68 struct lt_timetrail
70 struct lt_timetrail *next;
71 lxttime_t timeval;
72 unsigned int position;
76 #define LT_SYMPRIME 65519
78 #define LT_SECTION_END (0)
79 #define LT_SECTION_CHG (1)
80 #define LT_SECTION_SYNC_TABLE (2)
81 #define LT_SECTION_FACNAME (3)
82 #define LT_SECTION_FACNAME_GEOMETRY (4)
83 #define LT_SECTION_TIMESCALE (5)
84 #define LT_SECTION_TIME_TABLE (6)
85 #define LT_SECTION_INITIAL_VALUE (7)
86 #define LT_SECTION_DOUBLE_TEST (8)
87 #define LT_SECTION_TIME_TABLE64 (9)
88 #define LT_SECTION_ZFACNAME_PREDEC_SIZE (10)
89 #define LT_SECTION_ZFACNAME_SIZE (11)
90 #define LT_SECTION_ZFACNAME_GEOMETRY_SIZE (12)
91 #define LT_SECTION_ZSYNC_SIZE (13)
92 #define LT_SECTION_ZTIME_TABLE_SIZE (14)
93 #define LT_SECTION_ZCHG_PREDEC_SIZE (15)
94 #define LT_SECTION_ZCHG_SIZE (16)
95 #define LT_SECTION_ZDICTIONARY (17)
96 #define LT_SECTION_ZDICTIONARY_SIZE (18)
97 #define LT_SECTION_EXCLUDE_TABLE (19)
99 struct lt_trace
101 FILE *handle;
102 gzFile zhandle;
104 dslxt_Tree *dict; /* dictionary manipulation */
105 unsigned int mindictwidth;
106 unsigned int num_dict_entries;
107 unsigned int dict_string_mem_required;
108 dslxt_Tree **sorted_dict;
110 /* assume dict8_offset == filepos zero */
111 unsigned int dict16_offset;
112 unsigned int dict24_offset;
113 unsigned int dict32_offset;
116 int (*lt_emit_u8)(struct lt_trace *lt, int value);
117 int (*lt_emit_u16)(struct lt_trace *lt, int value);
118 int (*lt_emit_u24)(struct lt_trace *lt, int value);
119 int (*lt_emit_u32)(struct lt_trace *lt, int value);
120 int (*lt_emit_u64)(struct lt_trace *lt, int valueh, int valuel);
121 int (*lt_emit_double)(struct lt_trace *lt, double value);
122 int (*lt_emit_string)(struct lt_trace *lt, char *value);
124 unsigned int position;
125 unsigned int zfacname_predec_size, zfacname_size, zfacgeometry_size, zsync_table_size, ztime_table_size, zdictionary_size;
126 unsigned int zpackcount, zchg_table_size, chg_table_size;
128 struct lt_symbol *sym[LT_SYMPRIME];
129 struct lt_symbol **sorted_facs;
130 struct lt_symbol *symchain;
131 int numfacs, numfacs_bytes;
132 int numfacbytes;
133 int longestname;
134 lxttime_t mintime, maxtime;
135 int timescale;
136 int initial_value;
138 struct lt_timetrail *timehead, *timecurr, *timebuff;
139 int timechangecount;
141 struct lt_timetrail *dumpoffhead, *dumpoffcurr;
142 int dumpoffcount;
144 unsigned int change_field_offset;
145 unsigned int facname_offset;
146 unsigned int facgeometry_offset;
147 unsigned int time_table_offset;
148 unsigned int sync_table_offset;
149 unsigned int initial_value_offset;
150 unsigned int timescale_offset;
151 unsigned int double_test_offset;
152 unsigned int dictionary_offset;
153 unsigned int exclude_offset;
155 char *compress_fac_str;
156 int compress_fac_len;
158 lxttime_t timeval; /* for clock induction, current time */
160 unsigned dumpoff_active : 1; /* when set we're not dumping */
161 unsigned double_used : 1;
162 unsigned do_strip_brackets : 1;
163 unsigned clock_compress : 1;
164 unsigned dictmode : 1; /* dictionary compression enabled */
165 unsigned zmode : 2; /* for value changes */
166 unsigned emitted : 1; /* gate off change field zmode changes when set */
170 struct lt_symbol
172 struct lt_symbol *next;
173 struct lt_symbol *symchain;
174 char *name;
175 int namlen;
177 int facnum;
178 struct lt_symbol *aliased_to;
180 unsigned int rows;
181 int msb, lsb;
182 int len;
183 int flags;
185 unsigned int last_change;
187 lxttime_t clk_delta;
188 lxttime_t clk_prevtrans;
189 int clk_numtrans;
190 int clk_prevval;
191 int clk_prevval1;
192 int clk_prevval2;
193 int clk_prevval3;
194 int clk_prevval4;
195 unsigned char clk_mask;
198 #define LT_SYM_F_BITS (0)
199 #define LT_SYM_F_INTEGER (1<<0)
200 #define LT_SYM_F_DOUBLE (1<<1)
201 #define LT_SYM_F_STRING (1<<2)
202 #define LT_SYM_F_ALIAS (1<<3)
205 struct lt_trace * lt_init(const char *name);
206 void lt_close(struct lt_trace *lt);
208 struct lt_symbol * lt_symbol_find(struct lt_trace *lt, const char *name);
209 struct lt_symbol * lt_symbol_add(struct lt_trace *lt, const char *name, unsigned int rows, int msb, int lsb, int flags);
210 struct lt_symbol * lt_symbol_alias(struct lt_trace *lt, const char *existing_name, const char *alias, int msb, int lsb);
211 void lt_symbol_bracket_stripping(struct lt_trace *lt, int doit);
213 /* lt_set_no_interlace implies bzip2 compression. if you use lt_set_chg_compress before this, */
214 /* less efficient gzip compression will be used instead so make sure lt_set_no_interlace is first */
215 /* if you are using it! */
217 void lt_set_no_interlace(struct lt_trace *lt);
219 void lt_set_chg_compress(struct lt_trace *lt);
220 void lt_set_clock_compress(struct lt_trace *lt);
221 void lt_set_dict_compress(struct lt_trace *lt, unsigned int minwidth);
222 void lt_set_initial_value(struct lt_trace *lt, char value);
223 void lt_set_timescale(struct lt_trace *lt, int timescale);
225 int lt_set_time(struct lt_trace *lt, unsigned int timeval);
226 int lt_inc_time_by_delta(struct lt_trace *lt, unsigned int timeval);
227 int lt_set_time64(struct lt_trace *lt, lxttime_t timeval);
228 int lt_inc_time_by_delta64(struct lt_trace *lt, lxttime_t timeval);
230 /* allows blackout regions in LXT files */
232 void lt_set_dumpoff(struct lt_trace *lt);
233 void lt_set_dumpon(struct lt_trace *lt);
236 * value change functions..note that if the value string len for
237 * lt_emit_value_bit_string() is shorter than the symbol length
238 * it will be left justified with the rightmost character used as
239 * a repeat value that will be propagated to pad the value string out:
241 * "10x" for 8 bits becomes "10xxxxxx"
242 * "z" for 8 bits becomes "zzzzzzzz"
244 int lt_emit_value_int(struct lt_trace *lt, struct lt_symbol *s, unsigned int row, int value);
245 int lt_emit_value_double(struct lt_trace *lt, struct lt_symbol *s, unsigned int row, double value);
246 int lt_emit_value_string(struct lt_trace *lt, struct lt_symbol *s, unsigned int row, char *value);
247 int lt_emit_value_bit_string(struct lt_trace *lt, struct lt_symbol *s, unsigned int row, char *value);
249 #endif