xref: /plan9-contrib/sys/src/cmd/spin/pangen2.h (revision de2caf28f9ba1a56e70be94a699435d36eb50311)
1 /***** spin: pangen2.h *****/
2 
3 /*
4  * This file is part of the public release of Spin. It is subject to the
5  * terms in the LICENSE file that is included in this source directory.
6  * Tool documentation is available at http://spinroot.com
7  */
8 
9 static const char *Pre0[] = {
10 	"#ifdef SC",
11 	"	#define _FILE_OFFSET_BITS	64",	/* allows file sizes greater than 2Gb */
12 	"#endif",
13 	"#include <stdio.h>",
14 	"#include <signal.h>",
15 	"#include <stdlib.h>",
16 	"#include <stdarg.h>",
17 	"#include <string.h>",
18 	"#include <ctype.h>",
19 	"#include <errno.h>",
20 	"#if defined(WIN32) || defined(WIN64)",
21 		"#include <time.h>",
22 	"#else",
23 		"#include <unistd.h>",
24 		"#include <sys/times.h>",
25 	"#endif",
26 	"#include <sys/types.h>",	/* defines off_t */
27 	"#include <sys/stat.h>",
28 	"#include <limits.h>",
29 	"#include <fcntl.h>",
30 
31 	"#define Offsetof(X, Y)	((ulong)(&(((X *)0)->Y)))",
32 	"#ifndef max",
33 	"#define max(a,b) (((a)<(b)) ? (b) : (a))",
34 	"#endif",
35 	"#ifndef PRINTF",
36 	"int Printf(const char *fmt, ...); /* prototype only */",
37 	"#endif",
38 	0,
39 };
40 
41 static const char *Separate[] = {
42 	"#ifdef COLLAPSE",
43 	"	#if (NCORE>1 && !defined(SEP_STATE)) || defined(BFS_PAR)",
44 	"		volatile ulong *ncomps;	/* in shared memory */",
45 	"	#else",
46 	"		ulong ncomps[256+2];",
47 	"	#endif",
48 	"#endif",
49 	"Trans ***trans;	/* 1 ptr per state per proctype */\n",
50 	"",
51 	"#if VECTORSZ>32000",
52 	"	int P_o[MAXPROC], P_o_tmp[MAXPROC+1];",
53 	"	int Q_o[MAXQ],    Q_o_tmp[MAXPROC+1];",
54 	"",
55 	"	int *proc_offset = (int *) P_o;",
56 	"	int *q_offset    = (int *) Q_o;",
57 	"#else",
58 	"	short P_o[MAXPROC], P_o_tmp[MAXPROC+1];",
59 	"	short Q_o[MAXQ],    Q_o_tmp[MAXPROC+1];",
60 	"",
61 	"	short *proc_offset = (short *) P_o;",
62 	"	short *q_offset    = (short *) Q_o;",
63 	"#endif",
64 	"uchar P_s[MAXPROC+1], P_s_tmp[MAXPROC+1];",
65 	"uchar Q_s[MAXQ+1],    Q_s_tmp[MAXQ+1];",
66 	"uchar *proc_skip = (uchar *) P_s;",
67 	"uchar *q_skip    = (uchar *) Q_s;",
68 	"",
69 	"#ifdef TRIX",
70 	"	TRIX_v6 *freebodies;",
71 	"	TRIX_v6 *processes[MAXPROC+1];",
72 	"	TRIX_v6 *channels[MAXQ+1];",
73 	"	long _p_count[MAXPROC];",
74 	"	long _c_count[MAXPROC];",
75 	"#endif\n",
76 	"ulong  vsize;	/* vector size in bytes */",
77 	"#ifdef SVDUMP",
78 	"	int vprefix=0, svfd;	/* runtime option -pN */",
79 	"#endif",
80 	"char *tprefix = \"trail\";	/* runtime option -tsuffix */",
81 	"short boq = -1;		/* blocked_on_queue status */",
82 	"int _;	/* predefined write-only variable */",
83 	"#ifdef PEG",
84 	"	long peg[NTRANS];",
85 	"#endif",
86 	0,
87 };
88 
89 static const char *Preamble[] = {
90 	"#ifdef RANDOMIZE",
91 	"	#define T_RAND  RANDOMIZE",
92 	"#endif",
93 	"#ifdef CNTRSTACK",
94 	"	#define onstack_now()	(LL[trpt->j6] && LL[trpt->j7])",
95 	"	#define onstack_put()	 LL[trpt->j6]++; LL[trpt->j7]++",
96 	"	#define onstack_zap()	 LL[trpt->j6]--; LL[trpt->j7]--",
97 	"#endif",
98 
99 	"#if !defined(SAFETY) && !defined(NOCOMP)",
100 		/*
101 		 * V_A identifies states in the current statespace
102 		 * A_V identifies states in the 'other' statespace
103 		 * S_A remembers how many leading bytes in the sv
104 		 * are used for these markers + fairness bits
105 		 */
106 	"	#define V_A	(((now._a_t&1)?2:1) << (now._a_t&2))",
107 	"	#define A_V	(((now._a_t&1)?1:2) << (now._a_t&2))",
108 	"	int	S_A = 0;",
109 	"#else",
110 	"	#define V_A	0",
111 	"	#define A_V	0",
112 	"	#define S_A	0",
113 	"#endif",
114 
115 "#ifdef MA",
116 	"#undef onstack_now",
117 	"#undef onstack_put",
118 	"#undef onstack_zap",
119 	"#define onstack_put()	;",
120 	"#define onstack_zap()	g_store((char *) &now, vsize, 4)",
121 "#else",
122 	"#if defined(FULLSTACK) && !defined(BITSTATE)",
123 	"#define onstack_put()	trpt->ostate = Lstate",
124 	"#define onstack_zap()	{ \\",
125 	"	if (trpt->ostate) \\",
126 	"		trpt->ostate->tagged = \\",
127 	"		(S_A)? (trpt->ostate->tagged&~V_A) : 0; \\",
128 	"	}",
129 	"#endif",
130 "#endif",
131 	"H_el	**H_tab, **S_Tab;",
132 	"/* #ifndef BFS_PAR */",
133 	"	H_el   *Lstate;",
134 	"/* #endif */",
135 	"Trail	*trail, *trpt;",
136 	"FILE	*efd;",
137 	"uchar	*_this;",
138 	"long	maxdepth=10000;",
139 	"long	omaxdepth=10000;",
140 	"#ifdef BCS",
141 	"	/* bitflags in trpt->bcs */",
142 	"	#define B_PHASE1	1",
143 	"	#define B_PHASE2	2",
144 	"	#define B_FORCED	4",
145 	"int	sched_max = 0;",
146 	"#endif",
147 	"",
148 	"double	quota;	/* time limit */",
149 	"#if NCORE>1",
150 	"	long	z_handoff = -1;",
151 	"#endif",
152 	"#ifdef SC",	/* stack cycling */
153 	"	char	*stackfile;",
154  	"#endif",
155 	"uchar	*SS, *LL;",
156 	"",
157 	"uchar	reversing = 0;",
158 	"uchar	HASH_NR = 0;",
159 	"",
160 	"double memcnt = (double) 0;",
161 	"double memlim = (double) (1<<30); /* 1 GB */",
162 	"#if NCORE>1",
163 	"double mem_reserved = (double) 0;",
164 	"#endif",
165 	"",
166 	"/* for emalloc: */",
167 	"static char *have;",
168 	"static long left = 0L;",
169 	"static double fragment = (double) 0;",
170 	"static ulong grow;",
171 	"",
172 #if 1
173 	"unsigned int HASH_CONST[] = {",
174 	"	/* generated by hashgen 421 -- assumes 4 bytes per int */",
175 	"	0x100d4e63,	0x0fc22f87,	0xa7155c77,	0x78f2c3b9,",
176 	"	0xde32d207,	0xc27d305b,	0x1bb3fb2b,	0x2798c7a5,",
177 	"	0x9c675ffd,	0x777d9081,	0x07aef2f1,	0xae08922f,",
178 	"	0x5bd365b7,	0xed51c47b,	0x9b5aeea1,	0xbcc9d431,",
179 	"	0x396d8fff,	0xa2fd1367,	0x08616521,	0x5e84991f,",
180 	"	0x87495bc5,	0x2930039b,	0xceb6a593,	0xfe522d63,",
181 	"	0x7ff60baf,	0xf89b1fbf,	0x74c01755,	0xe0c559bf,",
182 	"	0x3669fc47,	0x8756d3bf,	0x14f78445,	0x24c41779,",
183 	"	0x0af7b129,	0xde22368d,	0x3e1c01e3,	0xaf773e49,",
184 	"	0x5b762459,	0x86d12911,	0x0953a3af,	0xb66dc23d,",
185 	"	0x96b3bd4f,	0x19b1dd51,	0xd886fbc3,	0xa7f3a025,",
186 	"	0xccb48e63,	0x87d8f027,	0x2bea270d,	0xdb0e9379,",
187 	"	0x78c09f21,	0x0cbbfe07,	0xea4bc7c3,	0x5bfbc3c9,",
188 	"	0x3c6e53fd,	0xab320cdd,	0x31041409,	0x416e7485,",
189 	"	0xe41d75fd,	0xc3c5060f,	0x201a9dc1,	0x93dee72b,",
190 	"	0x6461305f,	0xc571dec5,	0xa1fd21c5,	0xfb421ce1,",
191 	"	0x7f024b05,	0xfa518819,	0x6c9777fb,	0x0d4d9351,",
192 	"	0x08b33861,	0xccb9d0f3,	0x34112791,	0xe962d7c9,",
193 	"	0x8d742211,	0xcd9c47a1,	0x64437b69,	0x5fe40feb,",
194 	"	0x806113cb,	0x10e1d593,	0x821851b3,	0x057a1ff3,",
195 	"	0x8ededc0b,	0x90dd5b31,	0x635ff359,	0x68dbcd35,",
196 	"	0x1050ff4f,	0xdbb07257,	0x486336db,	0x83af1e75,",
197 	"	0x432f1799,	0xc1d0e7e7,	0x21f4eb5b,	0x881ec2c1,",
198 	"	0x23f3b539,	0x6cdfb80d,	0x71d474cf,	0x97d5d4a9,",
199 	"	0xf721d2e5,	0xb5ff3711,	0x3f2e58cd,	0x4e06e3d9,",
200 	"	0x7d711739,	0x927887df,	0x7d57ad71,	0x232eb767,",
201 	"	0xe3f5cc51,	0x6576b443,	0xed17bf1f,	0x8828b637,",
202 	"	0xc940f6ab,	0xc7b830ef,	0x11ed8a13,	0xaff20949,",
203 	"	0xf28a8465,	0x0da10cf9,	0xb512497d,	0x44accae1,",
204 	"	0x95e0929f,	0xe08c8901,	0xfd22d6c9,	0xb6a5c029,",
205 	"	0xaadb428d,	0x6e8a453d,	0x3d5c0195,	0x8bf4ae39,",
206 	"	0xbf83ab19,	0x3e9dac33,	0xc4df075d,	0x39472d71,",
207 	"	0xb8647725,	0x1a6d4887,	0x78a03577,	0xafd76ef7,",
208 	"	0xc1a1d6b3,	0x1afb33c5,	0x87896299,	0x5cc992ef,",
209 	"	0x7f805d0d,	0x089a039b,	0xa353cc27,	0x57b296b3,",
210 	"	0x52badec9,	0xc916e431,	0x09171957,	0x14996d51,",
211 	"	0xe87e32c7,	0xb4fdbb5d,	0xdd216a03,	0x4ddd3fff,",
212 	"	0x767d5c57,	0x79c97509,	0xab70543b,	0xc5feca4f,",
213 	"	0x8eb37b89,	0x20a2cefd,	0xf4b00b91,	0xf166593d,",
214 	"	0x7bf50f65,	0x753e6c8b,	0xfb5b81dd,	0xf2d45ef5,",
215 	"	0x9741c04f,	0x300da48d,	0x01dc4121,	0xa112cd47,",
216 	"	0x0223b24b,	0xa89fbce7,	0x681e1f7b,	0xe7c6aedf,",
217 	"	0x1fd3d523,	0x561ba723,	0xf54042fb,	0x1a516751,",
218 	"	0xcd085bd5,	0xe74246d5,	0x8b170b5d,	0x249985e9,",
219 	"	0x5b4d9cf7,	0xe9912323,	0x5fc0f339,	0x41f8f051,",
220 	"	0x8a296fb1,	0x62909f51,	0x2c05d695,	0x095efccb,",
221 	"	0xa91574f1,	0x0f5cc6c3,	0x23a2ca2b,	0xc6053ec1,",
222 	"	0xeb19e081,	0x3d1b3997,	0xb0c5f3cd,	0xe5d85b35,",
223 	"	0x1cb1bdf1,	0x0c8f278f,	0x518249c3,	0x9f61b68d,",
224 	"	0xade0919d,	0x779e29c3,	0xdbac9485,	0x2ce149a9,",
225 	"	0x254c2409,	0x205b34fb,	0xc8ab1a89,	0x6b4a2585,",
226 	"	0x2303d94b,	0x8fa186b9,	0x49826da5,	0xd23a37ad,",
227 	"	0x680b18c9,	0xa46fbd7f,	0xe42c2cf9,	0xf7cfcb5f,",
228 	"	0xb4842b8b,	0xe483780d,	0x66cf756b,	0x3eb73781,",
229 	"	0x41ca17a5,	0x59f91b0f,	0x92fb67d9,	0x0a5c330f,",
230 	"	0x46013fdb,	0x3b0634af,	0x9024f533,	0x96a001a7,",
231 	"	0x15bcd793,	0x3a311fb1,	0x78913b8b,	0x9d4a5ddf,",
232 	"	0x33189b31,	0xa99e8283,	0xf7cb29e9,	0x12d64a27,",
233 	"	0xeda770ff,	0xa7320297,	0xbd3c14a5,	0x96d0156f,",
234 	"	0x0115db95,	0x7f79f52b,	0xa6d52521,	0xa063d4bd,",
235 	"	0x9cb5e039,	0x42cf8195,	0xcb716835,	0x1bc21273,",
236 	"	0x5a67ad27,	0x4b3b0545,	0x162cda67,	0x0489166b,",
237 	"	0x85fd06a9,	0x562b037d,	0x995bc1f3,	0xe144e78b,",
238 	"	0x1e749f69,	0xa36df057,	0xcfee1667,	0x8c4116b7,",
239 	"	0x94647fe3,	0xe6899df7,	0x6d218981,	0xf1069079,",
240 	"	0xd1851a33,	0xf424fc83,	0x24467005,	0xad8caf59,",
241 	"	0x1ae5da13,	0x497612f9,	0x10f6d1ef,	0xeaf4ff05,",
242 	"	0x405f030b,	0x693b041d,	0x2065a645,	0x9fec71b3,",
243 	"	0xc3bd1b0f,	0xf29217a3,	0x0f25e15d,	0xd48c2b97,",
244 	"	0xce8acf2d,	0x0629489b,	0x1a5b0e01,	0x32d0c059,",
245 	"	0x2d3664bf,	0xc45f3833,	0xd57f551b,	0xbdd991c5,",
246 	"	0x9f97da9f,	0xa029c2a9,	0x5dd0cbdf,	0xe237ba41,",
247 	"	0x62bb0b59,	0x93e7d037,	0x7e495619,	0x51b8282f,",
248 	"	0x853e8ef3,	0x9b8abbeb,	0x055f66f9,	0x2736f7e5,",
249 	"	0x8d7e6353,	0x143abb65,	0x4e2bb5b3,	0x872e1adf,",
250 	"	0x8fcac853,	0xb7cf6e57,	0x12177f3d,	0x1d2da641,",
251 	"	0x07856425,	0xc0ed53dd,	0x252271d9,	0x79874843,",
252 	"	0x0aa8c9b5,	0x7e804f93,	0x2d080e09,	0x3929ddfd,",
253 	"	0x36433dbd,	0xd6568c17,	0xe624e939,	0xb33189ef,",
254 	"	0x29e68bff,	0x8aae2433,	0xe6335499,	0xc5facd9d,",
255 	"	0xbd5afc65,	0x7a584fa7,	0xab191435,	0x64bbdeef,",
256 	"	0x9f5cd8e1,	0xb3a1be05,	0xbd0c1753,	0xb00e2c7f,",
257 	"	0x6a96e315,	0x96a31589,	0x660af5af,	0xc0438d43,",
258 	"	0x17637373,	0x6460e8df,	0x7d458de9,	0xd76b923f,",
259 	"	0x316f045f,	0x3ccbd035,	0x63f64d81,	0xd990d969,",
260 	"	0x7c860a93,	0x99269ff7,	0x6fbcac8f,	0xd8cc562b,",
261 	"	0x67141071,	0x09f85ea3,	0x1298f2dd,	0x41fa86e5,",
262 	"	0xce1d7cf5,	0x6b232c9d,	0x8f093d4b,	0x3203ad4b,",
263 	"	0x07d70d5f,	0x38c44c75,	0x0887c9ef,	0x1833acf5,",
264 	"	0xa3607f85,	0x7d367573,	0x0ea4ffc3,	0xad2d09c1,",
265 	"	0x7a1e664f,	0xef41dff5,	0x03563491,	0x67f30a1f,",
266 	"	0x5ce5f9ef,	0xa2487a27,	0xe5077957,	0x9beb36fd,",
267 	"	0x16e41251,	0x216799ef,	0x07181f8d,	0xc191c3cf,",
268 	"	0xba21cab5,	0x73944eb7,	0xdf9eb69d,	0x5fef6cfd,",
269 	"	0xd750a6f5,	0x04f3fa43,	0x7cb2d063,	0xd3bdb369,",
270 	"	0x35f35981,	0x9f294633,	0x5e293517,	0x70e51d05,",
271 	"	0xf8db618d,	0x66ee05db,	0x835eaa77,	0x166a02c3,",
272 	"	0xb516f283,	0x94102293,	0x1ace50a5,	0x64072651,",
273 	"	0x66df7b75,	0x02e1b261,	0x8e6a73b9,	0x19dddfe7,",
274 	"	0xd551cf39,	0x391c17cb,	0xf4304de5,	0xcd67b8d1,",
275 	"	0x25873e8d,	0x115b4c71,	0x36e062f3,	0xaec0c7c9,",
276 	"	0xd929f79d,	0x935a661b,	0xda762b47,	0x170bd76b,",
277 	"	0x1a955cb5,	0x341fb0ef,	0x7f366cef,	0xc98f60c7,",
278 	"	0xa4181af3,	0xa94a8837,	0x5fa3bc43,	0x11c638c1,",
279 	"	0x4e66fabb,	0x30ab85cf,	0x250704ef,	0x8bf3bc07,",
280 	"	0x6d2cd5ab,	0x613ef9c3,	0xb8e62149,	0x0404fd91,",
281 	"	0xa04fd9b1,	0xa5e389eb,	0x9543bd23,	0xad6ca1f9,",
282 	"	0x210c49ab,	0xf8e9532b,	0x854fba89,	0xdc7fc6bb,",
283 	"	0x48a051a7,	0x6b2f383b,	0x61a4b433,	0xd3af231b,",
284 	"	0xc5023fc7,	0xa5aa85df,	0xa0cd1157,	0x4206f64d,",
285 	"	0x3fea31c3,	0x62d510a1,	0x13988957,	0x6a11a033,",
286 	"	0x46f2a3b7,	0x2784ef85,	0x229eb9eb,	0x9c0c3053,",
287 	"	0x5b7ead39,	0x82ae9afb,	0xf99e9fb3,	0x914b6459,",
288 	"	0xaf05edd7,	0xc82710dd,	0x8fc1ea1f,	0x7e0d7a8d,",
289 	"	0x7c7592e9,	0x65321017,	0xea57553f,	0x4aeb49ff,",
290 	"	0x5239ae4d,	0x4b4b4585,	0x94091c21,	0x7eaaf4cb,",
291 	"	0x6b489d6f,	0xecb9c0c3,	0x29a7af63,	0xaf117a0d,",
292 	"	0x969ea6cd,	0x7658a34d,	0x5fc0bba9,	0x26e99b7f,",
293 	"	0x7a6f260f,	0xe37c34f1,	0x1a1569bb,	0xc3bc7371,",
294 	"	0x8567543d,	0xad0c46a9,	0xa1264fd9,	0x16f10b29,",
295 	"	0x5e00dd3b,	0xf85b6bcd,	0xa2d32d8b,	0x4a3c8d43,",
296 	"	0x6b33b959,	0x4fd1e6c9,	0x7938b8a9,	0x1ec795c7,",
297 	"	0xe2ef3409,	0x83c16b9d,	0x0d3fd9eb,	0xeb461ad7,",
298 	"	0xb09c831d,	0xaf052001,	0x7911164d,	0x1a9dc191,",
299 	"	0xb52a0815,	0x0f732157,	0xc68c4831,	0x12cf3cbb };",
300 #else
301 	"unsigned int HASH_CONST[] = {",
302 	"	/* asuming 4 bytes per int */",
303 	"	0x100d4e63,	0x0fc22f87,",
304 	"	0x3ff0c3ff,	0x38e84cd7,",
305 	"	0x02b148e9,	0x98b2e49d,",
306 	"	0xb616d379,	0xa5247fd9,",
307 	"	0xbae92a15,	0xb91c8bc5,",
308 	"	0x8e5880f3,	0xacd7c069,",
309 	"	0xb4c44bb3,	0x2ead1fb7,",
310 	"	0x8e428171,	0xdbebd459,",
311 	"	0x00400007,	0x04c11db7,",
312 	"	0x828ae611,	0x6cb25933,",
313 	"	0x86cdd651,	0x9e8f5f21,",
314 	"	0xd5f8d8e7,	0x9c4e956f,",
315 	"	0xb5cf2c71,	0x2e805a6d,",
316 	"	0x33fc3a55,	0xaf203ed1,",
317 	"	0xe31f5909,	0x5276db35,",
318 	"	0x0c565ef7,	0x273d1aa5,",
319 	"	0x8923b1dd,	0xa9acaac5,",
320 	"	0xd1f69207,	0xedfd944b,",
321 	"	0x9a68e46b,	0x5355e13f,",
322 	"	0x7eeb44f9,	0x932beea9,",
323 	"	0x330c4cd3,	0x87f34e5f,",
324 	"	0x1b5851b7,	0xb9ca6447,",
325 	"	0x58f96a8f,	0x1b3b5307,",
326 	"	0x31c387b3,	0xf35f0f35,",
327 	"	0xa0acc4df,	0xf3140303,",
328 	"	0x2446245d,	0xe4b8f4ef,",
329 	"	0x5c007383,	0x68e648af,",
330 	"	0x1814fba7,	0xcdf731b5,",
331 	"	0xd09ccb4b,	0xb92d0eff,",
332 	"	0xcc3c6b67,	0xd3af6a57,",
333 	"	0xf44fc3f5,	0x5bb67623,",
334 	"	0xaeb9c953,	0x5e0ac739,",
335 	"	0x3a7fda09,	0x5edf39eb,",
336 	"	0x661eefd9,	0x6423f0d1,",
337 	"	0x910fe413,	0x9ec92297,",
338 	"	0x4bd8159d,	0xa7b16ee1,",
339 	"	0x89d484e9,	0x7f305cb3,",
340 	"	0xc5f303e7,	0x415deeef,",
341 	"	0x09986f89,	0x7e9c4117,",
342 	"	0x0b7cbedb,	0xf9ed7561,",
343 	"	0x7a20ac99,	0xf05adef3,",
344 	"	0x5893d75b,	0x44d73327,",
345 	"	0xb583c873,	0x324d2145,",
346 	"	0x7fa3829b,	0xe4b47a23,",
347 	"	0xe256d94f,	0xb1fd8959,",
348 	"	0xe561a321,	0x1435ac09,",
349 	"	0xdd62408b,	0x02ec0bcb,",
350 	"	0x5469b785,	0x2f4f50bb,",
351 	"	0x20f19395,	0xf96ba085,",
352 	"	0x2381f937,	0x768e2a11 };",
353 #endif
354 	"",
355 	"#if NCORE>1",
356 	"extern int core_id;",
357 	"#endif",
358 	"long	mreached=0;",
359 	"ulong	errors=0;",
360 	"int	done=0, Nrun=1;",
361 	"int	c_init_done=0;",
362 	"char	*c_stack_start = (char *) 0;",
363 	"double	nstates=0, nlinks=0, truncs=0, truncs2=0;",
364 	"double	nlost=0, nShadow=0, hcmp=0, ngrabs=0;",
365 	"#ifdef BFS_PAR",
366 	"extern ulong bfs_punt;",
367 	"#endif",
368 	"#ifdef PUTPID",
369 	"char *progname;",
370 	"#endif",
371 	"#if defined(ZAPH) && defined(BITSTATE)",
372 	"double zstates = 0;",
373 	"#endif",
374 	"/* int	c_init_run; */",
375 	"#ifdef REVERSE",
376 	"	#define P_REVERSE",
377 	"#endif",
378 	"#ifdef T_REVERSE",
379 	"	int	t_reverse = 1;", /* can be modified with a parameter */
380 	"#else",
381 	"	int	t_reverse = 0;",
382 	"#endif",
383 	"#ifdef BFS",
384 	"double midrv=0, failedrv=0, revrv=0;",
385 	"#endif",
386 	"ulong	nr_states=0; /* nodes in DFA */",
387 	"long	Fa=0, Fh=0, Zh=0, Zn=0;",
388 	"long	PUT=0, PROBE=0, ZAPS=0;",
389 	"long	Ccheck=0, Cholds=0;",
390 	"int	a_cycles=0, upto=1, strict=0, verbose = 0, signoff = 0;",
391 	"#ifdef HAS_CODE",
392 	"int	gui = 0, coltrace = 0, readtrail = 0;",
393 	"int	whichtrail = 0, whichclaim = -1, onlyproc = -1, silent = 0;",
394 	"char	*claimname;",
395 	"#endif",
396 	"int	state_tables=0, fairness=0, no_rck=0, Nr_Trails=0, dodot=0;",
397 	"char	simvals[256];",
398 	"#ifndef INLINE",
399 	"int	TstOnly=0;",
400 	"#endif",
401 	"ulong mask, nmask;",
402 	"#ifdef BITSTATE",
403 	"int	ssize=27;	/* 16 Mb */",
404 	"#else",
405 	"int	ssize=24;	/* 16M slots */",
406 	"#endif",
407 	"int	hmax=0, svmax=0, smax=0;",
408 	"int	Maxbody=0, XX;",
409 	"uchar	*noptr, *noqptr;	/* used by Pptr(x) and Qptr(x) */",
410 	"#ifdef VAR_RANGES",
411 	"void logval(char *, int);",
412 	"void dumpranges(void);",
413 	"#endif",
414 
415 	"#ifdef MA",
416 	"#define INLINE_REV",
417 	"extern void dfa_init(unsigned short);",
418 	"extern int  dfa_member(ulong);",
419 	"extern int  dfa_store(uchar *);",
420 	"unsigned int	maxgs = 0;",
421 	"#endif",
422 	"",
423 	"#ifdef ALIGNED",
424 	"	State	comp_now __attribute__ ((aligned (8)));",
425 	"	/* gcc 64-bit aligned for Itanium2 systems */",
426 	"	/* MAJOR runtime penalty if not used on those systems */",
427 	"#else",
428 	"	State	comp_now;	/* compressed state vector */",
429 	"#endif",
430 	"",
431 	"#ifndef HC",
432 	"	#ifdef BFS_PAR",
433 	"		State tmp_msk;",
434 	"	#endif",
435 	"	State	comp_msk;",
436 	"	uchar	*Mask = (uchar *) &comp_msk;",
437 	"#endif",
438 	"#ifdef COLLAPSE",
439 	"	State	comp_tmp;",
440 	"	static char	*scratch = (char *) &comp_tmp;",
441 	"#endif",
442 	"",
443 	"_Stack	*stack; 	/* for queues, processes */",
444 	"Svtack	*svtack;	/* for old state vectors */",
445 	"#ifdef BITSTATE",
446 	"static unsigned int hfns = 3;	/* new default */",
447 	"#endif",
448 	"static ulong j1_spin, j2_spin; /* 5.2.1: avoid nameclash with math.h */",
449 	"static ulong j3_spin, j4_spin;",
450 	"ulong K1, K2;",
451 	"#ifdef BITSTATE",
452 	"long udmem;",
453 	"#endif",
454 	"#ifndef BFS_PAR",
455 	"static long	A_depth = 0;",
456 	"#endif",
457 	"long	depth = 0;",
458 	"long depthfound = -1;	/* loop detection */",
459 	/* depth: not static to support -S2, but possible clash with embedded code */
460 	"#if NCORE>1",
461 	"long nr_handoffs = 0;",
462 	"#endif",
463 	"uchar	warned = 0, iterative = 0, exclusive = 0, like_java = 0, every_error = 0;",
464 	"uchar	noasserts = 0, noends = 0, bounded = 0;",
465 	"uint	s_rand = 12345;	/* default seed */",
466 
467 	"#if SYNC>0 && ASYNC==0",
468 	"void set_recvs(void);",
469 	"int  no_recvs(int);",
470 	"#endif",
471 	"#if SYNC",
472 	"#define IfNotBlocked	if (boq != -1) continue;",
473 	"#define UnBlock     	boq = -1",
474 	"#else",
475 	"#define IfNotBlocked	/* cannot block */",
476 	"#define UnBlock     	/* don't bother */",
477 	"#endif\n",
478 	"#ifdef BITSTATE",
479 	"int (*b_store)(char *, int);",
480 	"int bstore_reg(char *, int);",
481 	"int bstore_mod(char *, int);",
482 	"#endif",
483 	"",
484 	"void dfs_uerror(char *);",
485 	"void dfs_Uerror(char *);",
486 	"#ifdef BFS_PAR",
487 	"void bfs_uerror(char *);",
488 	"void bfs_Uerror(char *);",
489 	"#endif",
490 	"void (*uerror)(char *);",
491 	"void (*Uerror)(char *);",
492 	"void (*hasher)(uchar *, int);",
493 	"void (*o_hash)(uchar *, int, int);",
494 	"void d_hash(uchar *, int);",
495 	"void m_hash(uchar *, int);",
496 	"void d_sfh(uchar *, int);",
497 	"void o_hash32(uchar *, int, int);",
498 	"void o_hash64(uchar *, int, int);",
499 	"",
500 	"void active_procs(void);",
501 	"void cleanup(void);",
502 	"void do_the_search(void);",
503 	"void find_shorter(int);",
504 	"void iniglobals(int);",
505 	"void stopped(int);",
506 	"void wrapup(void);",
507 	"int *grab_ints(int);",
508 	"void ungrab_ints(int *, int);",
509 	0,
510 };
511 
512 static const char *Tail[] = {
513 	"Trans *",
514 	"settr(	int t_id, int a, int b, int c, int d,",
515 	"	char *t, int g, int tpe0, int tpe1)",
516 	"{	Trans *tmp = (Trans *) emalloc(sizeof(Trans));\n",
517 	"	tmp->atom  = a&(6|32);	/* only (2|8|32) have meaning */",
518 	"	if (!g) tmp->atom |= 8;	/* no global references */",
519 	"	tmp->st    = b;",
520 	"	tmp->tpe[0] = tpe0;",
521 	"	tmp->tpe[1] = tpe1;",
522 	"	tmp->tp    = t;",
523 	"	tmp->t_id  = t_id;",
524 	"	tmp->forw  = c;",
525 	"	tmp->back  = d;",
526 	"	return tmp;",
527 	"}\n",
528 	"Trans *",
529 	"cpytr(Trans *a)",
530 	"{	Trans *tmp = (Trans *) emalloc(sizeof(Trans));\n",
531 	"	int i;",
532 	"	tmp->atom  = a->atom;",
533 	"	tmp->st    = a->st;",
534 	"#ifdef HAS_UNLESS",
535 	"	tmp->e_trans = a->e_trans;",
536 	"	for (i = 0; i < HAS_UNLESS; i++)",
537 	"		tmp->escp[i] = a->escp[i];",
538 	"#endif",
539 	"	tmp->tpe[0] = a->tpe[0];",
540 	"	tmp->tpe[1] = a->tpe[1];",
541 	"	for (i = 0; i < 6; i++)",
542 	"	{	tmp->qu[i] = a->qu[i];",
543 	"		tmp->ty[i] = a->ty[i];",
544 	"	}",
545 	"	tmp->tp    = (char *) emalloc(strlen(a->tp)+1);",
546 	"	strcpy(tmp->tp, a->tp);",
547 	"	tmp->t_id  = a->t_id;",
548 	"	tmp->forw  = a->forw;",
549 	"	tmp->back  = a->back;",
550 	"	return tmp;",
551 	"}\n",
552 	"#ifndef NOREDUCE",
553 	"int",
554 	"srinc_set(int n)",
555 	"{	if (n <= 2) return LOCAL;",
556 	"	if (n <= 2+  DELTA) return Q_FULL_F; /* 's' or nfull  */",
557 	"	if (n <= 2+2*DELTA) return Q_EMPT_F; /* 'r' or nempty */",
558 	"	if (n <= 2+3*DELTA) return Q_EMPT_T; /* empty */",
559 	"	if (n <= 2+4*DELTA) return Q_FULL_T; /* full  */",
560 	"	if (n ==   5*DELTA) return GLOBAL;",
561 	"	if (n ==   6*DELTA) return TIMEOUT_F;",
562 	"	if (n ==   7*DELTA) return ALPHA_F;",
563 	"	Uerror(\"cannot happen srinc_class\");",
564 	"	return BAD;",
565 	"}",
566 	"int",
567 	"srunc(int n, int m)",
568 	"{	switch(m) {",
569 	"	case Q_FULL_F: return n-2;",
570 	"	case Q_EMPT_F: return n-2-DELTA;",
571 	"	case Q_EMPT_T: return n-2-2*DELTA;",
572 	"	case Q_FULL_T: return n-2-3*DELTA;",
573 	"	case ALPHA_F:",
574 	"	case TIMEOUT_F: return 257; /* non-zero, and > MAXQ */",
575 	"	}",
576 	"	Uerror(\"cannot happen srunc\");",
577 	"	return 0;",
578 	"}",
579 	"#endif",
580 	"int cnt;",
581 	"#ifdef HAS_UNLESS",
582 	"int",
583 	"isthere(Trans *a, int b)", /* is b already in a's list? */
584 	"{	Trans *t;",
585 	"	for (t = a; t; t = t->nxt)",
586 	"		if (t->t_id == b)",
587 	"			return 1;",
588 	"	return 0;",
589 	"}",
590 	"#endif",
591 	"#ifndef NOREDUCE",
592 	"int",
593 	"mark_safety(Trans *t) /* for conditional safety */",
594 	"{	int g = 0, i, j, k;",
595 	"",
596 	"	if (!t) return 0;",
597 	"	if (t->qu[0])",
598 	"		return (t->qu[1])?2:1;	/* marked */",
599 	"",
600 	"	for (i = 0; i < 2; i++)",
601 	"	{	j = srinc_set(t->tpe[i]);",
602 	"		if (j >= GLOBAL && j != ALPHA_F)",
603 	"			return -1;",
604 	"		if (j != LOCAL)",
605 	"		{	k = srunc(t->tpe[i], j);",
606 	"			if (g == 0",
607 	"			||  t->qu[0] != k",
608 	"			||  t->ty[0] != j)",
609 	"			{	t->qu[g] = k;",
610 	"				t->ty[g] = j;",
611 	"				g++;",
612 	"	}	}	}",
613 	"	return g;",
614 	"}",
615 	"#endif",
616 	"void",
617 	"retrans(int n, int m, int is, short srcln[], uchar reach[], uchar lpstate[])",
618 	"	/* process n, with m states, is=initial state */",
619 	"{	Trans *T0, *T1, *T2, *T3;",
620 	"	Trans *T4, *T5; /* t_reverse or has_unless */",
621 	"	int i;",
622 	"#if defined(HAS_UNLESS) || !defined(NOREDUCE)",
623 	"	int k;",
624 	"#endif",
625 	"#ifndef NOREDUCE",
626 	"	int g, h, j, aa;",
627 	"#endif",
628 	"#ifdef HAS_UNLESS",
629 	"	int p;",
630 	"#endif",
631 	"	if (state_tables >= 4)",
632 	"	{	printf(\"STEP 1 %%s\\n\", ",
633 	"			procname[n]);",
634 	"		for (i = 1; i < m; i++)",
635 	"		for (T0 = trans[n][i]; T0; T0 = T0->nxt)",
636 	"			crack(n, i, T0, srcln);",
637 	"		return;",
638 	"	}",
639 	"	do {",
640 	"		for (i = 1, cnt = 0; i < m; i++)",
641 	"		{	T2 = trans[n][i];",
642 	"			T1 = T2?T2->nxt:(Trans *)0;",
643 	"/* prescan: */		for (T0 = T1; T0; T0 = T0->nxt)",
644 	"/* choice in choice */	{	if (T0->st && trans[n][T0->st]",
645 	"				&&  trans[n][T0->st]->nxt)",
646 	"					break;",
647 	"			}",
648 	"#if 0",
649 	"		if (T0)",
650 	"		printf(\"\\tstate %%d / %%d: choice in choice\\n\",",
651 	"		i, T0->st);",
652 	"#endif",
653 	"			if (T0)",
654 	"			for (T0 = T1; T0; T0 = T0->nxt)",
655 	"			{	T3 = trans[n][T0->st];",
656 	"				if (!T3->nxt)",
657 	"				{	T2->nxt = cpytr(T0);",
658 	"					T2 = T2->nxt;",
659 	"					imed(T2, T0->st, n, i);",
660 	"					continue;",
661 	"				}",
662 	"				do {	T3 = T3->nxt;",
663 	"					T2->nxt = cpytr(T3);",
664 	"					T2 = T2->nxt;",
665 	"					imed(T2, T0->st, n, i);",
666 	"				} while (T3->nxt);",
667 	"				cnt++;",
668 	"			}",
669 	"		}",
670 	"	} while (cnt);",
671 
672 	"	if (state_tables >= 3)",
673 	"	{	printf(\"STEP 2 %%s\\n\", ",
674 	"			procname[n]);",
675 	"		for (i = 1; i < m; i++)",
676 	"		for (T0 = trans[n][i]; T0; T0 = T0->nxt)",
677 	"			crack(n, i, T0, srcln);",
678 	"		return;",
679 	"	}",
680 	"	for (i = 1; i < m; i++)",
681 	"	{	if (trans[n][i] && trans[n][i]->nxt) /* optimize */",
682 	"		{	T1 = trans[n][i]->nxt;",
683 	"#if 0",
684 	"			printf(\"\\t\\tpull %%d (%%d) to %%d\\n\",",
685 	"			T1->st, T1->forw, i);",
686 	"#endif",		/* pull linenumber ref as well: */
687 	"			srcln[i] = srcln[T1->st];	/* Oyvind Teig, 5.2.0 */",
688 	"",
689 	"			if (!trans[n][T1->st]) continue;",
690 	"			T0 = cpytr(trans[n][T1->st]);",
691 	"			trans[n][i] = T0;",
692 	"			reach[T1->st] = 1;",
693 	"			imed(T0, T1->st, n, i);",
694 	"			for (T1 = T1->nxt; T1; T1 = T1->nxt)",
695 	"			{",
696 	"#if 0",
697 	"			printf(\"\\t\\tpull %%d (%%d) to %%d\\n\",",
698 	"				T1->st, T1->forw, i);",
699 	"#endif",
700 	"		/*		srcln[i] = srcln[T1->st];  gh: not useful */",
701 	"				if (!trans[n][T1->st]) continue;",
702 	"				T0->nxt = cpytr(trans[n][T1->st]);",
703 	"				T0 = T0->nxt;",
704 	"				reach[T1->st] = 1;",
705 	"				imed(T0, T1->st, n, i);",
706 	"	}	}	}",
707 	"	if (state_tables >= 2)",
708 	"	{	printf(\"STEP 3 %%s\\n\", ",
709 	"			procname[n]);",
710 	"		for (i = 1; i < m; i++)",
711 	"		for (T0 = trans[n][i]; T0; T0 = T0->nxt)",
712 	"			crack(n, i, T0, srcln);",
713 	"		return;",
714 	"	}",
715 	"#ifdef HAS_UNLESS",
716 	"	for (i = 1; i < m; i++)",
717 	"	{	if (!trans[n][i]) continue;",
718 	"		/* check for each state i if an",
719 	"		 * escape to some state p is defined",
720 	"		 * if so, copy and mark p's transitions",
721 	"		 * and prepend them to the transition-",
722 	"		 * list of state i",
723 	"		 */",
724 	"	 if (!like_java) /* the default */",
725 	"	 {	for (T0 = trans[n][i]; T0; T0 = T0->nxt)",
726 	"		for (k = HAS_UNLESS-1; k >= 0; k--)",
727 	"		{	if (p = T0->escp[k])",
728 	"			for (T1 = trans[n][p]; T1; T1 = T1->nxt)",
729 	"			{	if (isthere(trans[n][i], T1->t_id))",
730 	"					continue;",
731 	"				T2 = cpytr(T1);",
732 	"				T2->e_trans = p;",
733 	"				T2->nxt = trans[n][i];",
734 	"				trans[n][i] = T2;",
735 	"		}	}",
736 	"	 } else /* outermost unless checked first */",
737 	"	 {	T4 = T3 = (Trans *) 0;",
738 	"		for (T0 = trans[n][i]; T0; T0 = T0->nxt)",
739 	"		for (k = HAS_UNLESS-1; k >= 0; k--)",
740 	"		{	if (p = T0->escp[k])",
741 	"			for (T1 = trans[n][p]; T1; T1 = T1->nxt)",
742 	"			{	if (isthere(trans[n][i], T1->t_id))",
743 	"					continue;",
744 	"				T2 = cpytr(T1);",
745 	"				T2->nxt = (Trans *) 0;",
746 	"				T2->e_trans = p;",
747 	"				if (T3)	T3->nxt = T2;",
748 	"				else	T4 = T2;",
749 	"				T3 = T2;",
750 	"		}	}",
751 	"		if (T4)",
752 	"		{	T3->nxt = trans[n][i];",
753 	"			trans[n][i] = T4;",
754 	"		}",
755 	"	 }",
756 	"	}",
757 	"#endif",
758 
759 	"#ifndef NOREDUCE",
760 	"	for (i = 1; i < m; i++)",
761 	"	{	if (a_cycles)",
762 	"		{ /* moves through these states are visible */",
763 	"	#if PROG_LAB>0 && defined(HAS_NP)",
764 	"			if (progstate[n][i])",
765 	"				goto degrade;",
766 	"			for (T1 = trans[n][i]; T1; T1 = T1->nxt)",
767 	"				if (progstate[n][T1->st])",
768 	"					goto degrade;",
769 	"	#endif",
770 	"			if (accpstate[n][i] || visstate[n][i])",
771 	"				goto degrade;",
772 	"			for (T1 = trans[n][i]; T1; T1 = T1->nxt)",
773 	"				if (accpstate[n][T1->st])",
774 	"					goto degrade;",
775 	"		}",
776 	"		T1 = trans[n][i];",
777 	"		if (!T1) continue;",
778 	"		g = mark_safety(T1);	/* V3.3.1 */",
779 	"		if (g < 0) goto degrade; /* global */",
780 	"		/* check if mixing of guards preserves reduction */",
781 	"		if (T1->nxt)",
782 	"		{	k = 0;",
783 	"			for (T0 = T1; T0; T0 = T0->nxt)",
784 	"			{	if (!(T0->atom&8))",
785 	"					goto degrade;",
786 	"				for (aa = 0; aa < 2; aa++)",
787 	"				{	j = srinc_set(T0->tpe[aa]);",
788 	"					if (j >= GLOBAL && j != ALPHA_F)",
789 	"						goto degrade;",
790 	"					if (T0->tpe[aa]",
791 	"					&&  T0->tpe[aa]",
792 	"					!=  T1->tpe[0])",
793 	"						k = 1;",
794 	"			}	}",
795 	"			/* g = 0;	V3.3.1 */",
796 	"			if (k)	/* non-uniform selection */",
797 	"			for (T0 = T1; T0; T0 = T0->nxt)",
798 	"			for (aa = 0; aa < 2; aa++)",
799 	"			{	j = srinc_set(T0->tpe[aa]);",
800 	"				if (j != LOCAL)",
801 	"				{	k = srunc(T0->tpe[aa], j);",
802 	"					for (h = 0; h < 6; h++)",
803 	"						if (T1->qu[h] == k",
804 	"						&&  T1->ty[h] == j)",
805 	"							break;",
806 	"					if (h >= 6)",
807 	"					{	T1->qu[g%%6] = k;",
808 	"						T1->ty[g%%6] = j;",
809 	"						g++;",
810 	"			}	}	}",
811 	"			if (g > 6)",
812 	"			{	T1->qu[0] = 0;	/* turn it off */",
813 	"				printf(\"pan: warning, line %%d, \",",
814 	"					srcln[i]);",
815 	"			 	printf(\"too many stmnt types (%%d)\",",
816 	"					g);",
817 	"			  	printf(\" in selection\\n\");",
818 	"			  goto degrade;",
819 	"			}",
820 	"		}",
821 	"		/* mark all options global if >=1 is global */",
822 	"		for (T1 = trans[n][i]; T1; T1 = T1->nxt)",
823 	"			if (!(T1->atom&8)) break;",
824 	"		if (T1)",
825 	"degrade:	for (T1 = trans[n][i]; T1; T1 = T1->nxt)",
826 	"			T1->atom &= ~8;	/* mark as unsafe */",
827 
828 	"		/* can only mix 'r's or 's's if on same chan */",
829 	"		/* and not mixed with other local operations */",
830 	"		T1 = trans[n][i];",
831 
832 	"		if (!T1 || T1->qu[0]) continue;",
833 
834 	"		j = T1->tpe[0];",
835 	"		if (T1->nxt && T1->atom&8)",
836 	"		{ if (j == 5*DELTA)",
837 	"		  {	printf(\"warning: line %%d \", srcln[i]);",
838 	"			printf(\"mixed condition \");",
839 	"			printf(\"(defeats reduction)\\n\");",
840 	"			goto degrade;",
841 	"		  }",
842 	"		  for (T0 = T1; T0; T0 = T0->nxt)",
843 	"		  for (aa = 0; aa < 2; aa++)",
844 	"		  if  (T0->tpe[aa] && T0->tpe[aa] != j)",
845 	"		  {	printf(\"warning: line %%d \", srcln[i]);",
846 	"			printf(\"[%%d-%%d] mixed %%stion \",",
847 	"				T0->tpe[aa], j, ",
848 	"				(j==5*DELTA)?\"condi\":\"selec\");",
849 	"			printf(\"(defeats reduction)\\n\");",
850 	"			printf(\"	'%%s' <-> '%%s'\\n\",",
851 	"				T1->tp, T0->tp);",
852 	"			goto degrade;",
853 	"		} }",
854 	"	}",
855 	"#endif",
856 	"	for (i = 1; i < m; i++)",	/* R */
857 	"	{	T2 = trans[n][i];",
858 	"		if (!T2",
859 	"		||  T2->nxt",
860 	"		||  strncmp(T2->tp, \".(goto)\", 7)",
861 	"		||  !stopstate[n][i])",
862 	"			continue;",
863 	"		stopstate[n][T2->st] = 1;",
864 	"	}",
865 	"	if (state_tables && !verbose)",
866 	"	{	if (dodot)",
867 	"		{	char buf[256], *q = buf, *p = procname[n];",
868 	"			while (*p != '\\0')",
869 	"			{	if (*p != ':')",
870 	"				{	*q++ = *p;",
871 	"				}",
872 	"				p++;",
873 	"			}",
874 	"			*q = '\\0';",
875 	"			printf(\"digraph \");",
876 	"			switch (Btypes[n]) {",
877 	"			case I_PROC:  printf(\"init {\\n\"); break;",
878 	"			case N_CLAIM: printf(\"claim_%%s {\\n\", buf); break;",
879 	"			case E_TRACE: printf(\"notrace {\\n\"); break;",
880 	"			case N_TRACE: printf(\"trace {\\n\"); break;",
881 	"			default:      printf(\"p_%%s {\\n\", buf); break;",
882 	"			}",
883 	"			printf(\"size=\\\"8,10\\\";\\n\");",
884 	"			printf(\"  GT [shape=box,style=dotted,label=\\\"%%s\\\"];\\n\", buf);",
885 	"			printf(\"  GT -> S%%d;\\n\", is);",
886 	"		} else",
887 	"		{	switch (Btypes[n]) {",
888 	"			case I_PROC:  printf(\"init\\n\"); break;",
889 	"			case N_CLAIM: printf(\"claim %%s\\n\", procname[n]); break;",
890 	"			case E_TRACE: printf(\"notrace assertion\\n\"); break;",
891 	"			case N_TRACE: printf(\"trace assertion\\n\"); break;",
892 	"			default:      printf(\"proctype %%s\\n\", procname[n]); break;",
893 	"		}	}",
894 	"		for (i = 1; i < m; i++)",
895 	"		{	reach[i] = 1;",
896 	"		}",
897 	"		tagtable(n, m, is, srcln, reach);",
898 	"		if (dodot) printf(\"}\\n\");",
899 	"	} else",
900 	"	for (i = 1; i < m; i++)",
901 	"	{	int nrelse;",
902 	"		if (Btypes[n] != N_CLAIM)",
903 	"		{	for (T0 = trans[n][i]; T0; T0 = T0->nxt)",
904 	"			{	if (T0->st == i",
905 	"				&& strcmp(T0->tp, \"(1)\") == 0)",
906 	"				{	printf(\"error: proctype '%%s' \",",
907 	"						procname[n]);",
908 	"		  			printf(\"line %%d, state %%d: has un\",",
909 	"						srcln[i], i);",
910 	"					printf(\"conditional self-loop\\n\");",
911 	"					pan_exit(1);",
912 	"		}	}	}",
913 	"		nrelse = 0;",
914 	"		for (T0 = trans[n][i]; T0; T0 = T0->nxt)",
915 	"		{	if (strcmp(T0->tp, \"else\") == 0)",
916 	"				nrelse++;",
917 	"		}",
918 	"		if (nrelse > 1)",
919 	"		{	printf(\"error: proctype '%%s' state\",",
920 	"				procname[n]);",
921 	"		  	printf(\" %%d, inherits %%d\", i, nrelse);",
922 	"		  	printf(\" 'else' stmnts\\n\");",
923 	"			pan_exit(1);",
924 	"	}	}",
925 	"#if !defined(LOOPSTATE) && !defined(BFS_PAR)",
926 	"	if (state_tables)",
927 	"#endif",
928 	"	do_dfs(n, m, is, srcln, reach, lpstate);",
929 	"",
930 	"	if (!t_reverse)",
931 	"	{	return;",
932 	"	}",
933 	"	/* process n, with m states, is=initial state -- reverse list */",
934 	"	if (!state_tables && Btypes[n] != N_CLAIM)",
935 	"	{	for (i = 1; i < m; i++)", /* for each state */
936 	"		{	Trans *Tx = (Trans *) 0; /* list of escapes */",
937 	"			Trans *Ty = (Trans *) 0; /* its tail element */",
938 	"			T1 = (Trans *) 0; /* reversed list */",
939 	"			T2 = (Trans *) 0; /* its tail */",
940 	"			T3 = (Trans *) 0; /* remembers possible 'else' */",
941 	"",
942 	"			/* find unless-escapes, they should go first */",
943 	"			T4 = T5 = T0 = trans[n][i];",
944 	"	#ifdef HAS_UNLESS",
945 	"			while (T4 && T4->e_trans) /* escapes are first in orig list */",
946 	"			{	T5 = T4;	  /* remember predecessor */",
947 	"				T4 = T4->nxt;",
948 	"			}",
949 	"	#endif",
950 	"			/* T4 points to first non-escape, T5 to its parent, T0 to original list */",
951 	"			if (T4 != T0)		 /* there was at least one escape */",
952 	"			{	T3 = T5->nxt;		 /* start of non-escapes */",
953 	"				T5->nxt = (Trans *) 0;	 /* separate */",
954 	"				Tx = T0;		 /* start of the escapes */",
955 	"				Ty = T5;		 /* its tail */",
956 	"				T0 = T3;		 /* the rest, to be reversed */",
957 	"			}",
958 	"			/* T0 points to first non-escape, Tx to the list of escapes, Ty to its tail */",
959 	"",
960 	"			/* first tail-add non-escape transitions, reversed */",
961 	"			T3 = (Trans *) 0;", /* remember a possible 'else' */
962 	"			for (T5 = T0; T5; T5 = T4)",
963 	"			{	T4 = T5->nxt;",
964 	"	#ifdef HAS_UNLESS",
965 	"				if (T5->e_trans)",
966 	"				{	printf(\"error: cannot happen!\\n\");",
967 	"					continue;",
968 	"				}",
969 	"	#endif",
970 	"				if (strcmp(T5->tp, \"else\") == 0)",
971 	"				{	T3 = T5;",
972 	"					T5->nxt = (Trans *) 0;",
973 	"				} else",
974 	"				{	T5->nxt = T1;",
975 	"					if (!T1) { T2 = T5; }",
976 	"					T1 = T5;",
977 	"			}	}",
978 	"			/* T3 points to a possible else, which is removed from the list */",
979 	"			/* T1 points to the reversed list so far (without escapes) */",
980 	"			/* T2 points to the tail element -- where the else should go */",
981 	"			if (T2 && T3)",
982 	"			{	T2->nxt = T3;	/* add else */",
983 	"			} else",
984 	"			{	if (T3) /* there was an else, but there's no tail */",
985 	"				{	if (!T1)	/* and no reversed list */",
986 	"					{	T1 = T3; /* odd, but possible */",
987 	"					} else		/* even stranger */",
988 	"					{	T1->nxt = T3;",
989 	"			}	}	}",
990 	"",
991 	"			/* add in the escapes, to that they appear at the front */",
992 	"			if (Tx && Ty) { Ty->nxt = T1; T1 = Tx; }",
993 	"",
994 	"			trans[n][i] = T1;",
995 	"			/* reversed, with escapes first and else last */",
996 	"	}	}",
997 	"	if (state_tables && verbose)",
998 	"	{	printf(\"FINAL proctype %%s\\n\", ",
999 	"			procname[n]);",
1000 	"		for (i = 1; i < m; i++)",
1001 	"		for (T0 = trans[n][i]; T0; T0 = T0->nxt)",
1002 	"			crack(n, i, T0, srcln);",
1003 	"	}",
1004 	"}",
1005 	"void",
1006 	"imed(Trans *T, int v, int n, int j)	/* set intermediate state */",
1007 	"{	progstate[n][T->st] |= progstate[n][v];",
1008 	"	accpstate[n][T->st] |= accpstate[n][v];",
1009 	"	stopstate[n][T->st] |= stopstate[n][v];",
1010 	"	mapstate[n][j] = T->st;",
1011 	"}",
1012 	"void",
1013 	"tagtable(int n, int m, int is, short srcln[], uchar reach[])",
1014 	"{	Trans *z;\n",
1015 	"	if (is >= m || !trans[n][is]",
1016 	"	||  is <= 0 || reach[is] == 0)",
1017 	"		return;",
1018 	"	reach[is] = 0;",
1019 	"	if (state_tables)",
1020 	"	for (z = trans[n][is]; z; z = z->nxt)",
1021 	"	{	if (dodot)",
1022 	"			dot_crack(n, is, z);",
1023 	"		else",
1024 	"			crack(n, is, z, srcln);",
1025 	"	}",
1026 	"",
1027 	"	for (z = trans[n][is]; z; z = z->nxt)",
1028 	"	{",
1029 	"#ifdef HAS_UNLESS",
1030 	"		int i, j;",
1031 	"#endif",
1032 	"		tagtable(n, m, z->st, srcln, reach);",
1033 	"#ifdef HAS_UNLESS",
1034 	"		for (i = 0; i < HAS_UNLESS; i++)",
1035 	"		{	j = trans[n][is]->escp[i];",
1036 	"			if (!j) break;",
1037 	"			tagtable(n, m, j, srcln, reach);",
1038 	"		}",
1039 	"#endif",
1040 	"	}",
1041 	"}",
1042 	"",
1043 	"extern Trans *t_id_lkup[];",	/* needed by BFS_PAR */
1044 	"",
1045 	"void",
1046 	"dfs_table(int n, int m, int is, short srcln[], uchar reach[], uchar lpstate[])",
1047 	"{	Trans *z;\n",
1048 	"	if (is >= m || is <= 0 || !trans[n][is])",
1049 	"		return;",
1050 	"	if ((reach[is] & (4|8|16)) != 0)",
1051 	"	{	if ((reach[is] & (8|16)) == 16)	/* on stack, not yet recorded */",
1052 	"		{	lpstate[is] = 1;",
1053 	"			reach[is] |= 8; /* recorded */",
1054 	"			if (state_tables && verbose)",
1055 	"			{	printf(\"state %%d line %%d is a loopstate\\n\", is, srcln[is]);",
1056 	"		}	}",
1057 	"		return;",
1058 	"	}",
1059 	"	reach[is] |= (4|16);	/* visited | onstack */",
1060 	"	for (z = trans[n][is]; z; z = z->nxt)",
1061 	"	{	t_id_lkup[z->t_id] = z;",	/* needed by BFS_PAR */
1062 	"#ifdef HAS_UNLESS",
1063 	"		int i, j;",
1064 	"#endif",
1065 	"		dfs_table(n, m, z->st, srcln, reach, lpstate);",
1066 	"#ifdef HAS_UNLESS",
1067 	"		for (i = 0; i < HAS_UNLESS; i++)",
1068 	"		{	j = trans[n][is]->escp[i];",
1069 	"			if (!j) break;",
1070 	"			dfs_table(n, m, j, srcln, reach, lpstate);",
1071 	"		}",
1072 	"#endif",
1073 	"	}",
1074 	"	reach[is] &= ~16; /* no longer on stack */",
1075 	"}",
1076 	"void",
1077 	"do_dfs(int n, int m, int is, short srcln[], uchar reach[], uchar lpstate[])",
1078 	"{	int i;",
1079 	"	dfs_table(n, m, is, srcln, reach, lpstate);",
1080 	"	for (i = 0; i < m; i++)",
1081 	"		reach[i] &= ~(4|8|16);",
1082 	"}",
1083 	"void",
1084 	"crack(int n, int j, Trans *z, short srcln[])",
1085 	"{	int i;\n",
1086 	"	if (!z) return;",
1087 	"	printf(\"\tstate %%3d -(tr %%3d)-> state %%3d  \",",
1088 	"		j, z->forw, z->st);",
1089 	"	printf(\"[id %%3d tp %%3d\", z->t_id, z->tpe[0]);",
1090 	"	if (z->tpe[1]) printf(\",%%d\", z->tpe[1]);",
1091 	"#ifdef HAS_UNLESS",
1092 	"	if (z->e_trans)",
1093 	"		printf(\" org %%3d\", z->e_trans);",
1094 	"	else if (state_tables >= 2)",
1095 	"	for (i = 0; i < HAS_UNLESS; i++)",
1096 	"	{	if (!z->escp[i]) break;",
1097 	"		printf(\" esc %%d\", z->escp[i]);",
1098 	"	}",
1099 	"#endif",
1100 	"	printf(\"]\");",
1101 	"	printf(\" [%%s%%s%%s%%s%%s] %%s:%%d => \",",
1102 	"		z->atom&6?\"A\":z->atom&32?\"D\":\"-\",",
1103 	"		accpstate[n][j]?\"a\" :\"-\",",
1104 	"		stopstate[n][j]?\"e\" : \"-\",",
1105 	"		progstate[n][j]?\"p\" : \"-\",",
1106 	"		z->atom & 8 ?\"L\":\"G\",",
1107 	"		PanSource, srcln[j]);",
1108 	"	for (i = 0; z->tp[i]; i++)",
1109 	"		if (z->tp[i] == \'\\n\')",
1110 	"			printf(\"\\\\n\");",
1111 	"		else",
1112 	"			putchar(z->tp[i]);",
1113 	"	if (verbose && z->qu[0])",
1114 	"	{	printf(\"\\t[\");",
1115 	"		for (i = 0; i < 6; i++)",
1116 	"			if (z->qu[i])",
1117 	"				printf(\"(%%d,%%d)\",",
1118 	"				z->qu[i], z->ty[i]);",
1119 	"		printf(\"]\");",
1120 	"	}",
1121 	"	printf(\"\\n\");",
1122 	"	fflush(stdout);",
1123 	"}",
1124 	"/* spin -a m.pml; cc -o pan pan.c; ./pan -D | dot -Tps > foo.ps; ps2pdf foo.ps */",
1125 	"void",
1126 	"dot_crack(int n, int j, Trans *z)",
1127 	"{	int i;\n",
1128 	"	if (!z) return;",
1129 	"	printf(\"\tS%%d -> S%%d  [color=black\", j, z->st);",
1130 	"",
1131 	"	if (z->atom&6) printf(\",style=dashed\");",		/* A */
1132 	"	else if (z->atom&32) printf(\",style=dotted\");",	/* D */
1133 	"	else if (z->atom&8) printf(\",style=solid\");",		/* L */
1134 	"	else printf(\",style=bold\");",				/* G */
1135 		/* other styles: filled dotted */
1136 	"",
1137 	"	printf(\",label=\\\"\");",
1138 	"	for (i = 0; z->tp[i]; i++)",
1139 	"	{	if (z->tp[i] == \'\\\\\'",
1140 	"		&&  z->tp[i+1] == \'n\')",
1141 	"		{	i++; printf(\" \");",
1142 	"		} else",
1143 	"		{	putchar(z->tp[i]);",
1144 	"	}	}",
1145 	"	printf(\"\\\"];\\n\");",
1146 	"	if (accpstate[n][j]) printf(\"  S%%d [color=red,style=bold];\\n\", j);",
1147 	"	else if (progstate[n][j]) printf(\"  S%%d [color=green,style=bold];\\n\", j);",
1148 	"	if (stopstate[n][j]) printf(\"  S%%d [color=blue,style=bold,shape=box];\\n\", j);",
1149 	"}",
1150 	"",
1151 	"#ifdef VAR_RANGES",
1152 	"#define BYTESIZE	32	/* 2^8 : 2^3 = 256:8 = 32 */",
1153 	"",
1154 	"typedef struct Vr_Ptr {",
1155 	"	char	*nm;",
1156 	"	uchar	vals[BYTESIZE];",
1157 	"	struct Vr_Ptr *nxt;",
1158 	"} Vr_Ptr;",
1159 	"Vr_Ptr *ranges = (Vr_Ptr *) 0;",
1160 	"",
1161 	"void",
1162 	"logval(char *s, int v)",
1163 	"{	Vr_Ptr *tmp;",
1164 	"",
1165 	"	if (v<0 || v > 255) return;",
1166 	"	for (tmp = ranges; tmp; tmp = tmp->nxt)",
1167 	"		if (!strcmp(tmp->nm, s))",
1168 	"			goto found;",
1169 	"	tmp = (Vr_Ptr *) emalloc(sizeof(Vr_Ptr));",
1170 	"	tmp->nxt = ranges;",
1171 	"	ranges = tmp;",
1172 	"	tmp->nm = s;",
1173 	"found:",
1174 	"	tmp->vals[(v)/8] |= 1<<((v)%%8);",
1175 	"}",
1176 	"",
1177 	"void",
1178 	"dumpval(uchar X[], int range)",
1179 	"{	int w, x, i, j = -1;",
1180 	"",
1181 	"	for (w = i = 0; w < range; w++)",
1182 	"	for (x = 0; x < 8; x++, i++)",
1183 	"	{",
1184 	"from:		if ((X[w] & (1<<x)))",
1185 	"		{	printf(\"%%d\", i);",
1186 	"			j = i;",
1187 	"			goto upto;",
1188 	"	}	}",
1189 	"	return;",
1190 	"	for (w = 0; w < range; w++)",
1191 	"	for (x = 0; x < 8; x++, i++)",
1192 	"	{",
1193 	"upto:		if (!(X[w] & (1<<x)))",
1194 	"		{	if (i-1 == j)",
1195 	"				printf(\", \");",
1196 	"			else",
1197 	"				printf(\"-%%d, \", i-1);",
1198 	"			goto from;",
1199 	"	}	}",
1200 	"	if (j >= 0 && j != 255)",
1201 	"		printf(\"-255\");",
1202 	"}",
1203 	"",
1204 	"void",
1205 	"dumpranges(void)",
1206 	"{	Vr_Ptr *tmp;",
1207 	"	printf(\"\\nValues assigned within \");",
1208 	"	printf(\"interval [0..255]:\\n\");",
1209 	"	for (tmp = ranges; tmp; tmp = tmp->nxt)",
1210 	"	{	printf(\"\\t%%s\\t: \", tmp->nm);",
1211 	"		dumpval(tmp->vals, BYTESIZE);",
1212 	"		printf(\"\\n\");",
1213 	"	}",
1214 	"}",
1215 	"#endif",
1216 	0,
1217 };
1218