Subversion Repositories planix.SVN

Rev

Rev 2 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 - 1
/***** spin: pangen1.h *****/
2
 
3
/* Copyright (c) 1989-2003 by Lucent Technologies, Bell Laboratories.     */
4
/* All Rights Reserved.  This software is for educational purposes only.  */
5
/* No guarantee whatsoever is expressed or implied by the distribution of */
6
/* this code.  Permission is given to distribute this code provided that  */
7
/* this introductory message is not removed and no monies are exchanged.  */
8
/* Software written by Gerard J. Holzmann.  For tool documentation see:   */
9
/*             http://spinroot.com/                                       */
10
/* Send all bug-reports and/or questions to: bugs@spinroot.com            */
11
/* (c) 2007-2011: additions, enhancements, and bugfixes GJH               */
12
 
13
static char *Code2a[] = { /* the tail of procedure run() */
14
	"	if (state_tables)",
15
	"	{ if (dodot) exit(0);",
16
	"	  printf(\"\\nTransition Type: \");",
17
	"	  printf(\"A=atomic; D=d_step; L=local; G=global\\n\");",
18
	"	  printf(\"Source-State Labels: \");",
19
	"	  printf(\"p=progress; e=end; a=accept;\\n\");",
20
	"#ifdef MERGED",
21
	"	  printf(\"Note: statement merging was used. Only the first\\n\");",
22
	"	  printf(\"      stmnt executed in each merge sequence is shown\\n\");",
23
	"	  printf(\"      (use spin -a -o3 to disable statement merging)\\n\");",
24
	"#endif",
25
	"	  pan_exit(0);",
26
	"	}",
27
	"#if defined(BFS) && defined(TRIX)", /* before iniglobals */
28
	"	{ int i;",
29
	"	  for (i = 0; i < MAXPROC+1; i++)",
30
	"	  {	processes[i] = (TRIX_v6 *) emalloc(sizeof(TRIX_v6));",
31
	"		processes[i]->body = (uchar *) emalloc(Maxbody * sizeof(char));",
32
	"	  }",
33
	"	  for (i = 0; i < MAXQ+1; i++)",
34
	"	  {	channels[i] = (TRIX_v6 *) emalloc(sizeof(TRIX_v6));",
35
	"		channels[i]->body = (uchar *) emalloc(Maxbody * sizeof(char));",
36
	"	} }",
37
	"#endif",
38
	"	iniglobals(258); /* arg outside range of pids */",
39
	"#if defined(VERI) && !defined(NOREDUCE) && !defined(NP)",
40
	"	if (!state_tables",
41
	"#ifdef HAS_CODE",
42
	"	&& !readtrail",
43
	"#endif",
44
	"#if NCORE>1",
45
	"	&& core_id == 0",
46
	"#endif",
47
	"	)",
48
	"	{ printf(\"warning: for p.o. reduction to be valid \");",
49
	"	  printf(\"the never claim must be stutter-invariant\\n\");",
50
	"	  printf(\"(never claims generated from LTL \");",
51
	"	  printf(\"formulae are stutter-invariant)\\n\");",
52
	"	}",
53
	"#endif",
54
	"	UnBlock;	/* disable rendez-vous */",
55
	"#ifdef BITSTATE",
56
	"	if (udmem)",
57
	"	{	udmem *= 1024L*1024L;",
58
	"	#if NCORE>1",
59
	"		if (!readtrail)",
60
	"		{	void init_SS(unsigned long);",
61
	"			init_SS((unsigned long) udmem);",
62
	"		} else",
63
	"	#endif",
64
	"		SS = (uchar *) emalloc(udmem);",
65
	"		bstore = bstore_mod;",
66
	"	} else",
67
	"	#if NCORE>1",
68
	"		{ void init_SS(unsigned long);",
69
	"		  init_SS(ONE_L<<(ssize-3));",
70
	"		}",
71
	"	#else",
72
	"		SS = (uchar *) emalloc(ONE_L<<(ssize-3));",
73
	"	#endif",
74
	"#else",	/* if not BITSTATE */
75
	"	hinit();",
76
	"#endif",
77
	"#if defined(FULLSTACK) && defined(BITSTATE)",
78
	"	onstack_init();",
79
	"#endif",
80
	"#if defined(CNTRSTACK) && !defined(BFS)",
81
	"	LL = (uchar *) emalloc(ONE_L<<(ssize-3));",
82
	"#endif",
83
	"	stack	= (_Stack *) emalloc(sizeof(_Stack));",
84
	"	svtack	= (Svtack *) emalloc(sizeof(Svtack));",
85
	"	/* a place to point for Pptr of non-running procs: */",
86
	"	noqptr = noptr	= (uchar *) emalloc(Maxbody * sizeof(char));",
87
	"#if defined(SVDUMP) && defined(VERBOSE)",
88
	"	if (vprefix > 0)",
89
	"		(void) write(svfd, (uchar *) &vprefix, sizeof(int));",
90
	"#endif",
91
	"#ifdef VERI",
92
	"	Addproc(VERI);	/* pid = 0 */",
93
	"	#if NCLAIMS>1",
94
	"	if (claimname != NULL)",
95
	"	{	whichclaim = find_claim(claimname);",
96
	"		select_claim(whichclaim);",
97
	"	}",
98
	"	#endif",
99
	"#endif",
100
	"	active_procs();	/* started after never */",
101
	"#ifdef EVENT_TRACE",
102
	"	now._event = start_event;",
103
	"	reached[EVENT_TRACE][start_event] = 1;",
104
	"#endif",
105
 
106
	"#ifdef HAS_CODE",
107
	"	globinit();",
108
	"#endif",
109
	"#ifdef BITSTATE",
110
	"go_again:",
111
	"#endif",
112
	"	do_the_search();",
113
	"#ifdef BITSTATE",
114
	"	if (--Nrun > 0 && HASH_CONST[++HASH_NR])",
115
	"	{	printf(\"Run %%d:\\n\", HASH_NR);",
116
	"		wrap_stats();",
117
	"		printf(\"\\n\");",
118
 
119
	"		if (udmem)	/* Dillinger 3/2/09 */",
120
	"		{	memset(SS, 0, udmem);",
121
	"		} else",
122
	"		{	memset(SS, 0, ONE_L<<(ssize-3));",
123
	"		}",
124
 
125
		"#ifdef CNTRSTACK",
126
	"		memset(LL, 0, ONE_L<<(ssize-3));",
127
		"#endif",
128
		"#ifdef FULLSTACK",
129
	"		memset((uchar *) S_Tab, 0, ",
130
	"		maxdepth*sizeof(struct H_el *));",
131
		"#endif",
132
	"		nstates=nlinks=truncs=truncs2=ngrabs = 0;",
133
	"		nlost=nShadow=hcmp = 0;",
134
	"		Fa=Fh=Zh=Zn = 0;",
135
	"		PUT=PROBE=ZAPS=Ccheck=Cholds = 0;",
136
	"		goto go_again;",
137
	"	}",
138
	"#endif",
139
	"}",
140
	"#ifdef HAS_PROVIDED",
141
	"int provided(int, uchar, int, Trans *);",
142
	"#endif",
143
 
144
	"#if NCORE>1",
145
	"#define GLOBAL_LOCK	(0)",
146
	"#ifndef CS_N",
147
	"#define CS_N		(256*NCORE)", /* must be a power of 2 */
148
	"#endif",
149
 
150
	"#ifdef NGQ",	/* no global queue */
151
	"#define NR_QS		(NCORE)",
152
	"#define CS_NR		(CS_N+1)	/* 2^N + 1, nr critical sections */",
153
	"#define GQ_RD		GLOBAL_LOCK",	/* not really used in this mode */
154
	"#define GQ_WR		GLOBAL_LOCK",	/* but just in case... */
155
	"#define CS_ID		(1 + (int) (j1_spin & (CS_N-1))) /* mask: 2^N - 1, zero reserved */",
156
	"#define QLOCK(n)	(1+n)", /* overlaps first n zones of hashtable */
157
	"#else",
158
	"#define NR_QS		(NCORE+1)",	/* add a global queue */
159
	"#define CS_NR		(CS_N+3)",	/* 2 extra locks for global q */
160
	"#define GQ_RD		(1)",		/* read access to global q */
161
	"#define GQ_WR		(2)",		/* write access to global q */
162
	"#define CS_ID		(3 + (int) (j1_spin & (CS_N-1)))",
163
	"#define QLOCK(n)	(3+n)",/* overlaps first n zones of hashtable */
164
	"#endif",
165
	"",
166
	"void e_critical(int);",
167
	"void x_critical(int);",
168
	"",
169
	"#ifndef SEP_STATE",
170
	"	#define enter_critical(w)	e_critical(w)",
171
	"	#define leave_critical(w)	x_critical(w)",
172
	"#else",
173
	"	#ifdef NGQ",
174
	"	#define enter_critical(w)	{ if (w < 1+NCORE) e_critical(w); }",
175
	"	#define leave_critical(w)	{ if (w < 1+NCORE) x_critical(w); }",
176
	"	#else",
177
	"	#define enter_critical(w)	{ if (w < 3+NCORE) e_critical(w); }",
178
	"	#define leave_critical(w)	{ if (w < 3+NCORE) x_critical(w); }",
179
	"	#endif",
180
	"#endif",
181
	"",
182
	"int",
183
	"cpu_printf(const char *fmt, ...)", /* only used with VERBOSE/CHECK/DEBUG */
184
	"{	va_list args;",
185
	"	enter_critical(GLOBAL_LOCK);	/* printing */",
186
	"	printf(\"cpu%%d: \", core_id);",
187
	"	fflush(stdout);",
188
	"	va_start(args, fmt);",
189
	"	vprintf(fmt, args);",
190
	"	va_end(args);",
191
	"	fflush(stdout);",
192
	"	leave_critical(GLOBAL_LOCK);",
193
	"	return 1;",
194
	"}",
195
	"#else",
196
	"int",
197
	"cpu_printf(const char *fmt, ...)",
198
	"{	va_list args;",
199
	"	va_start(args, fmt);",
200
	"	vprintf(fmt, args);",
201
	"	va_end(args);",
202
	"	return 1;",
203
	"}",
204
	"#endif",
205
 
206
#ifndef PRINTF
207
	"int",
208
	"Printf(const char *fmt, ...)",
209
	"{	/* Make sure the args to Printf",
210
	"	 * are always evaluated (e.g., they",
211
	"	 * could contain a run stmnt)",
212
	"	 * but do not generate the output",
213
	"	 * during verification runs",
214
	"	 * unless explicitly wanted",
215
	"	 * If this fails on your system",
216
	"	 * compile SPIN itself -DPRINTF",
217
	"	 * and this code is not generated",
218
	"	 */",
219
	"#ifdef HAS_CODE",
220
	"	if (readtrail)",
221
	"	{	va_list args;",
222
	"		va_start(args, fmt);",
223
	"		vprintf(fmt, args);",
224
	"		va_end(args);",
225
	"		return 1;",
226
	"	}",
227
	"#endif",
228
	"#ifdef PRINTF",
229
	"	va_list args;",
230
	"	va_start(args, fmt);",
231
	"	vprintf(fmt, args);",
232
	"	va_end(args);",
233
	"#endif",
234
	"	return 1;",
235
	"}",
236
#endif
237
	"extern void printm(int);",
238
 
239
	"#ifndef SC",
240
	"#define getframe(i)	&trail[i];",
241
	"#else",
242
	"static long HHH, DDD, hiwater;",
243
	"static long CNT1, CNT2;",
244
	"static int stackwrite;",
245
	"static int stackread;",
246
	"static Trail frameptr;",
247
	"Trail *",
248
	"getframe(int d)",
249
	"{",
250
	"	if (CNT1 == CNT2)",
251
	"		return &trail[d];",
252
	"",
253
	"	if (d >= (CNT1-CNT2)*DDD)",
254
	"		return &trail[d - (CNT1-CNT2)*DDD];",
255
	"",
256
	"	if (!stackread",
257
	"	&&  (stackread = open(stackfile, 0)) < 0)",
258
	"	{	printf(\"getframe: cannot open %%s\\n\", stackfile);",
259
	"		wrapup();",
260
	"	}",
261
	"	if (lseek(stackread, d* (off_t) sizeof(Trail), SEEK_SET) == -1",
262
	"	|| read(stackread, &frameptr, sizeof(Trail)) != sizeof(Trail))",
263
	"	{	printf(\"getframe: frame read error\\n\");",
264
	"		wrapup();",
265
	"	}",
266
	"	return &frameptr;",
267
	"}",
268
	"#endif",
269
 
270
	"#if !defined(SAFETY) && !defined(BITSTATE)",
271
	"#if !defined(FULLSTACK) || defined(MA)",
272
	"#define depth_of(x)	A_depth /* an estimate */",
273
	"#else",
274
	"int",
275
	"depth_of(struct H_el *s)",
276
	"{	Trail *t; int d;",
277
	"	for (d = 0; d <= A_depth; d++)",
278
	"	{	t = getframe(d);",
279
	"		if (s == t->ostate)",
280
	"			return d;",
281
	"	}",
282
	"	printf(\"pan: cannot happen, depth_of\\n\");",
283
	"	return depthfound;",
284
	"}",
285
	"#endif",
286
	"#endif",
287
 
288
	"#if NCORE>1",
289
	"extern void cleanup_shm(int);",
290
	"volatile unsigned int	*search_terminated; /* to signal early termination */",
291
	/*
292
	 *	Meaning of bitflags in search_terminated:
293
	 *	  1	set by pan_exit
294
	 *	  2	set by wrapup
295
	 *	  4	set by uerror
296
	 *	  8	set by sudden_stop -- called after someone_crashed and [Uu]error
297
	 *	 16	set by cleanup_shm
298
	 *	 32	set by give_up	-- called on signal
299
	 *	 64	set by proxy_exit
300
	 *	128	set by proxy on write port failure
301
	 *	256	set by proxy on someone_crashed
302
	 *
303
	 *	Flags 8|32|128|256 indicate abnormal termination
304
	 *
305
	 *	The flags are checked in 4 functions in the code:
306
	 *		sudden_stop()
307
	 *		someone_crashed() (proxy and pan version)
308
	 *		mem_hand_off()
309
	 */
310
	"#endif",
311
	"void",
312
	"pan_exit(int val)",
313
	"{	void stop_timer(void);",
314
	"	if (signoff)",
315
	"	{	printf(\"--end of output--\\n\");",
316
	"	}",
317
	"#if NCORE>1",
318
	"	if (search_terminated != NULL)",
319
	"	{	*search_terminated |= 1;	/* pan_exit */",
320
	"	}",
321
		"#ifdef USE_DISK",
322
	"	{ void	dsk_stats(void);",
323
	"		dsk_stats();",
324
	"	}",
325
		"#endif",
326
	"	if (!state_tables && !readtrail)",
327
	"	{	cleanup_shm(1);",
328
	"	}",
329
	"#endif",
330
	"	if (val == 2)",
331
	"	{	val = 0;",
332
	"	} else",
333
	"	{	stop_timer();",
334
	"	}",
335
	"",
336
	"#ifdef C_EXIT",
337
	"	C_EXIT; /* trust that it defines a fct */",
338
	"#endif",
339
	"	exit(val);",
340
	"}",
341
 
342
	"#ifdef HAS_CODE",
343
	"static char tbuf[2][2048];",
344
	"",
345
	"char *",
346
	"transmognify(char *s)",
347
	"{	char *v, *w;",
348
	"	int i, toggle = 0;",
349
	"	if (!s || strlen(s) > 2047) return s;",
350
	"	memset(tbuf[0], 0, 2048);",
351
	"	memset(tbuf[1], 0, 2048);",
352
	"	strcpy(tbuf[toggle], s);",
353
	"	while ((v = strstr(tbuf[toggle], \"{c_code\")))",	/* assign v */
354
	"	{	*v = '\\0'; v++;",
355
	"		strcpy(tbuf[1-toggle], tbuf[toggle]);",
356
	"		for (w = v; *w != '}' && *w != '\\0'; w++) /* skip */;",
357
	"		if (*w != '}') return s;",
358
	"		*w = '\\0'; w++;",
359
	"		for (i = 0; code_lookup[i].c; i++)",
360
	"			if (strcmp(v, code_lookup[i].c) == 0",
361
	"			&&  strlen(v) == strlen(code_lookup[i].c))",
362
	"			{	if (strlen(tbuf[1-toggle])",
363
	"				 +  strlen(code_lookup[i].t)",
364
	"				 +  strlen(w) > 2047)",
365
	"					return s;",
366
	"				strcat(tbuf[1-toggle], code_lookup[i].t);",
367
	"				break;",
368
	"			}",
369
	"		strcat(tbuf[1-toggle], w);",
370
	"		toggle = 1 - toggle;",
371
	"	}",
372
	"	tbuf[toggle][2047] = '\\0';",
373
	"	return tbuf[toggle];",
374
	"}",
375
	"#else",
376
	"char * transmognify(char *s) { return s; }",
377
	"#endif",
378
 
379
	"#ifdef HAS_CODE",
380
	"void",
381
	"add_src_txt(int ot, int tt)",
382
	"{	Trans *t;",
383
	"	char *q;",
384
	"",
385
	"	for (t = trans[ot][tt]; t; t = t->nxt)",
386
	"	{	printf(\"\\t\\t\");",
387
	"		q = transmognify(t->tp);",
388
	"		for ( ; q && *q; q++)",
389
	"			if (*q == '\\n')",
390
	"				printf(\"\\\\n\");",
391
	"			else",
392
	"				putchar(*q);",
393
	"		printf(\"\\n\");",
394
	"	}",
395
	"}",
396
	"",
397
	"char *",
398
	"find_source(int tp, int s)",
399
	"{",
400
	"	if (s >= flref[tp]->from",
401
	"	&&  s <= flref[tp]->upto)",
402
	"	{	return flref[tp]->fnm;",
403
	"	}",
404
	"	return PanSource; /* i.e., don't know */",
405
	"}",
406
	"",
407
	"void",
408
	"wrap_trail(void)",
409
	"{	static int wrap_in_progress = 0;",
410
	"	int i; short II;",
411
	"	P0 *z;",
412
	"",
413
	"	if (wrap_in_progress++) return;",
414
	"",
415
	"	printf(\"spin: trail ends after %%ld steps\\n\", depth);",
416
	"	if (onlyproc >= 0)",
417
	"	{	if (onlyproc >= now._nr_pr) { pan_exit(0); }",
418
	"		II = onlyproc;",
419
	"		z = (P0 *)pptr(II);",
420
	"		printf(\"%%3ld:\tproc %%d (%%s) \",",
421
	"			depth, II, procname[z->_t]);",
422
	"		for (i = 0; src_all[i].src; i++)",
423
	"			if (src_all[i].tp == (int) z->_t)",
424
	"			{	printf(\" %%s:%%d\",",
425
	"					find_source((int) z->_t, (int) z->_p),",
426
	"					src_all[i].src[z->_p]);",
427
	"				break;",
428
	"			}",
429
	"		printf(\" (state %%2d)\", z->_p);",
430
	"		if (!stopstate[z->_t][z->_p])",
431
	"			printf(\" (invalid end state)\");",
432
	"		printf(\"\\n\");",
433
	"		add_src_txt(z->_t, z->_p);",
434
	"		pan_exit(0);",
435
	"	}",
436
	"	printf(\"#processes %%d:\\n\", now._nr_pr);",
437
	"	if (depth < 0) depth = 0;",
438
	"	for (II = 0; II < now._nr_pr; II++)",
439
	"	{	z = (P0 *)pptr(II);",
440
	"		printf(\"%%3ld:\tproc %%d (%%s) \",",
441
	"			depth, II, procname[z->_t]);",
442
	"		for (i = 0; src_all[i].src; i++)",
443
	"			if (src_all[i].tp == (int) z->_t)",
444
	"			{	printf(\" %%s:%%d\",",
445
	"					find_source((int) z->_t, (int) z->_p),",
446
	"					src_all[i].src[z->_p]);",
447
	"				break;",
448
	"			}",
449
	"		printf(\" (state %%2d)\", z->_p);",
450
	"		if (!stopstate[z->_t][z->_p])",
451
	"			printf(\" (invalid end state)\");",
452
	"		printf(\"\\n\");",
453
	"		add_src_txt(z->_t, z->_p);",
454
	"	}",
455
	"	c_globals();",
456
	"	for (II = 0; II < now._nr_pr; II++)",
457
	"	{	z = (P0 *)pptr(II);",
458
	"		c_locals(II, z->_t);",
459
	"	}",
460
	"#ifdef ON_EXIT",
461
	"	ON_EXIT;",
462
	"#endif",
463
	"	pan_exit(0);",
464
	"}",
465
	"FILE *",
466
	"findtrail(void)",
467
	"{	FILE *fd;",
468
	"	char fnm[512], *q;",
469
	"	char MyFile[512];",	/* avoid using a non-writable string */
470
	"	char MySuffix[16];",
471
	"	int  try_core;",
472
	"	int  candidate_files;",
473
	"",
474
	"	if (trailfilename != NULL)",
475
	"	{	fd = fopen(trailfilename, \"r\");",
476
	"		if (fd == NULL)",
477
	"		{	printf(\"pan: cannot find %%s\\n\", trailfilename);",
478
	"			pan_exit(1);",
479
	"		} /* else */",
480
	"		goto success;",
481
	"	}",
482
	"talk:",
483
	"	try_core = 1;",
484
	"	candidate_files = 0;",
485
	"	tprefix = \"trail\";",
486
	"	strcpy(MyFile, TrailFile);",
487
	"	do { /* see if there's more than one possible trailfile */",
488
	"		if (whichtrail)",
489
	"		{	sprintf(fnm, \"%%s%%d.%%s\",",
490
	"				MyFile, whichtrail, tprefix);",
491
	"			fd = fopen(fnm, \"r\");",
492
	"			if (fd != NULL)",
493
	"			{	candidate_files++;",
494
	"				if (verbose==100)",
495
	"					printf(\"trail%%d: %%s\\n\",",
496
	"						candidate_files, fnm);",
497
	"				fclose(fd);",
498
	"			}",
499
	"			if ((q = strchr(MyFile, \'.\')) != NULL)",
500
	"			{	*q = \'\\0\';",	/* e.g., strip .pml */
501
	"				sprintf(fnm, \"%%s%%d.%%s\",",
502
	"					MyFile, whichtrail, tprefix);",
503
	"				*q = \'.\';",
504
	"				fd = fopen(fnm, \"r\");",
505
	"				if (fd != NULL)",
506
	"				{	candidate_files++;",
507
	"					if (verbose==100)",
508
	"						printf(\"trail%%d: %%s\\n\",",
509
	"							candidate_files, fnm);",
510
	"					fclose(fd);",
511
	"			}	}",
512
	"		} else",
513
	"		{	sprintf(fnm, \"%%s.%%s\", MyFile, tprefix);",
514
	"			fd = fopen(fnm, \"r\");",
515
	"			if (fd != NULL)",
516
	"			{	candidate_files++;",
517
	"				if (verbose==100)",
518
	"					printf(\"trail%%d: %%s\\n\",",
519
	"						candidate_files, fnm);",
520
	"				fclose(fd);",
521
	"			}",
522
	"			if ((q = strchr(MyFile, \'.\')) != NULL)",
523
	"			{	*q = \'\\0\';",	/* e.g., strip .pml */
524
	"				sprintf(fnm, \"%%s.%%s\", MyFile, tprefix);",
525
	"				*q = \'.\';",
526
	"				fd = fopen(fnm, \"r\");",
527
	"				if (fd != NULL)",
528
	"				{	candidate_files++;",
529
	"					if (verbose==100)",
530
	"						printf(\"trail%%d: %%s\\n\",",
531
	"							candidate_files, fnm);",
532
	"					fclose(fd);",
533
	"		}	}	}",
534
	"		tprefix = MySuffix;",
535
	"		sprintf(tprefix, \"cpu%%d_trail\", try_core++);",
536
	"	} while (try_core <= NCORE);",
537
	"",
538
	"	if (candidate_files != 1)",
539
	"	{	if (verbose != 100)",
540
	"		{	printf(\"error: there are %%d trail files:\\n\",",
541
	"				candidate_files);",
542
	"			verbose = 100;",
543
	"			goto talk;",
544
	"		} else",
545
	"		{	printf(\"pan: rm or mv all except one\\n\");",
546
	"			exit(1);",
547
	"	}	}",
548
 
549
	"	try_core = 1;",
550
	"	strcpy(MyFile, TrailFile); /* restore */",
551
	"	tprefix = \"trail\";",
552
	"try_again:",
553
	"	if (whichtrail)",
554
	"	{	sprintf(fnm, \"%%s%%d.%%s\", MyFile, whichtrail, tprefix);",
555
	"		fd = fopen(fnm, \"r\");",
556
	"		if (fd == NULL && (q = strchr(MyFile, \'.\')))",
557
	"		{	*q = \'\\0\';",	/* e.g., strip .pml on original file */
558
	"			sprintf(fnm, \"%%s%%d.%%s\",",
559
	"				MyFile, whichtrail, tprefix);",
560
	"			*q = \'.\';",
561
	"			fd = fopen(fnm, \"r\");",
562
	"		}",
563
	"	} else",
564
	"	{	sprintf(fnm, \"%%s.%%s\", MyFile, tprefix);",
565
	"		fd = fopen(fnm, \"r\");",
566
	"		if (fd == NULL && (q = strchr(MyFile, \'.\')))",
567
	"		{	*q = \'\\0\';",	/* e.g., strip .pml on original file */
568
	"			sprintf(fnm, \"%%s.%%s\", MyFile, tprefix);",
569
	"			*q = \'.\';",
570
	"			fd = fopen(fnm, \"r\");",
571
	"	}	}",
572
	"	if (fd == NULL)",
573
	"	{	if (try_core < NCORE)",
574
	"		{	tprefix = MySuffix;",
575
	"			sprintf(tprefix, \"cpu%%d_trail\", try_core++);",
576
	"			goto try_again;",
577
	"		}",
578
	"		printf(\"pan: cannot find trailfile %%s\\n\", fnm);",
579
	"		pan_exit(1);",
580
	"	}",
581
	"success:",
582
	"#if NCORE>1 && defined(SEP_STATE)",
583
	"	{	void set_root(void); /* for partial traces from local root */",
584
	"		set_root();",
585
	"	}",
586
	"#endif",
587
	"	return fd;",
588
	"}",
589
	"",
590
	"uchar do_transit(Trans *, short);",
591
	"",
592
	"void",
593
	"getrail(void)",
594
	"{	FILE *fd;",
595
	"	char *q;",
596
	"	int i, t_id, lastnever=-1; short II;",
597
	"	Trans *t;",
598
	"	P0 *z;",
599
	"",
600
	"	fd = findtrail();	/* exits if unsuccessful */",
601
	"	while (fscanf(fd, \"%%ld:%%d:%%d\\n\", &depth, &i, &t_id) == 3)",
602
	"	{	if (depth == -1)",
603
	"			printf(\"<<<<<START OF CYCLE>>>>>\\n\");",
604
	"		if (depth < 0)",
605
	"			continue;",
606
	"		if (i > now._nr_pr)",
607
	"		{	printf(\"pan: Error, proc %%d invalid pid \", i);",
608
	"			printf(\"transition %%d\\n\", t_id);",
609
	"			break;",
610
	"		}",
611
	"		II = i;",
612
	"		z = (P0 *)pptr(II);",
613
	"		for (t = trans[z->_t][z->_p]; t; t = t->nxt)",
614
	"			if (t->t_id == (T_ID) t_id)",
615
	"				break;",
616
	"		if (!t)",
617
	"		{	for (i = 0; i < NrStates[z->_t]; i++)",
618
	"			{	t = trans[z->_t][i];",
619
	"				if (t && t->t_id == (T_ID) t_id)",
620
	"				{	printf(\"\\tRecovered at state %%d\\n\", i);",
621
	"					z->_p = i;",
622
	"					goto recovered;",
623
	"			}	}",
624
	"			printf(\"pan: Error, proc %%d type %%d state %%d: \",",
625
	"				II, z->_t, z->_p);",
626
	"			printf(\"transition %%d not found\\n\", t_id);",
627
	"			printf(\"pan: list of possible transitions in this process:\\n\");",
628
	"			if (z->_t >= 0 && z->_t <= _NP_)",
629
	"			for (t = trans[z->_t][z->_p]; t; t = t->nxt)",
630
	"				printf(\"	t_id %%d -- case %%d, [%%s]\\n\",",
631
	"					t->t_id, t->forw, t->tp);",
632
	"			break; /* pan_exit(1); */",
633
	"		}",
634
	"recovered:",
635
	"		q = transmognify(t->tp);",
636
	"		if (gui) simvals[0] = \'\\0\';",
637
 
638
	"		this = pptr(II);",
639
	"		trpt->tau |= 1;",	/* timeout always possible */
640
	"		if (!do_transit(t, II))",
641
	"		{	if (onlyproc >= 0 && II != onlyproc)",
642
	"				goto moveon;",
643
	"			printf(\"pan: error, next transition UNEXECUTABLE on replay\\n\");",
644
	"			printf(\"     most likely causes: missing c_track statements\\n\");",
645
	"			printf(\"       or illegal side-effects in c_expr statements\\n\");",
646
	"		}",
647
 
648
	"		if (onlyproc >= 0 && II != onlyproc)",
649
	"			goto moveon;",
650
 
651
	"		if (verbose)",
652
	"		{	printf(\"%%3ld: proc %%2d (%%s) \", depth, II, procname[z->_t]);",
653
 
654
	"			for (i = 0; src_all[i].src; i++)",
655
	"				if (src_all[i].tp == (int) z->_t)",
656
	"				{	printf(\" %%s:%%d \",",
657
	"						find_source((int) z->_t, (int) z->_p),",
658
	"						src_all[i].src[z->_p]);",
659
	"					break;",
660
	"				}",
661
 
662
	"			printf(\"(state %%d) trans {%%d,%%d} [%%s]\\n\",",
663
	"				z->_p, t_id, t->forw, q?q:\"\");",
664
 
665
	"			c_globals();",
666
	"			for (i = 0; i < now._nr_pr; i++)",
667
	"			{	c_locals(i, ((P0 *)pptr(i))->_t);",
668
	"			}",
669
	"		} else if (Btypes[z->_t] == N_CLAIM)",
670
	"		{	if (lastnever != (int) z->_p)",
671
	"			{	for (i = 0; src_all[i].src; i++)",
672
	"					if (src_all[i].tp == (int) z->_t)",
673
	"					{	printf(\"MSC: ~G %%d\\n\",",
674
	"							src_all[i].src[z->_p]);",
675
	"						break;",
676
	"					}",
677
	"				if (!src_all[i].src)",
678
	"					printf(\"MSC: ~R %%d\\n\", z->_p);",
679
	"			}",
680
	"			lastnever = z->_p;",
681
	"			goto sameas;",
682
	"		} else if (Btypes[z->_t] != 0) /* not :np_: */",
683
	"		{",
684
	"sameas:		if (no_rck) goto moveon;",
685
	"			if (coltrace)",
686
	"			{	printf(\"%%ld: \", depth);",
687
	"				for (i = 0; i < II; i++)",
688
	"					printf(\"\\t\\t\");",
689
	"				printf(\"%%s(%%d):\", procname[z->_t], II);",
690
	"				printf(\"[%%s]\\n\", q?q:\"\");",
691
	"			} else if (!silent)",
692
	"			{	if (strlen(simvals) > 0) {",
693
	"				printf(\"%%3ld:	proc %%2d (%%s)\", ",
694
	"					depth, II, procname[z->_t]);",
695
	"				for (i = 0; src_all[i].src; i++)",
696
	"					if (src_all[i].tp == (int) z->_t)",
697
	"					{	printf(\" %%s:%%d \",",
698
	"							find_source((int) z->_t, (int) z->_p),",
699
	"							src_all[i].src[z->_p]);",
700
	"						break;",
701
	"					}",
702
	"				printf(\"(state %%d)\t[values: %%s]\\n\", z->_p, simvals);",
703
	"				}",
704
	"				printf(\"%%3ld:	proc %%2d (%%s)\", ",
705
	"					depth, II, procname[z->_t]);",
706
	"				for (i = 0; src_all[i].src; i++)",
707
	"					if (src_all[i].tp == (int) z->_t)",
708
	"					{	printf(\" %%s:%%d \",",
709
	"							find_source((int) z->_t, (int) z->_p),",
710
	"							src_all[i].src[z->_p]);",
711
	"						break;",
712
	"					}",
713
	"				printf(\"(state %%d)\t[%%s]\\n\", z->_p, q?q:\"\");",
714
	"			/*	printf(\"\\n\");	*/",
715
	"		}	}",
716
	"moveon:	z->_p = t->st;",
717
	"	}",
718
	"	wrap_trail();",
719
	"}",
720
	"#endif",
721
	"int",
722
	"f_pid(int pt)",
723
	"{	int i;",
724
	"	P0 *z;",
725
	"	for (i = 0; i < now._nr_pr; i++)",
726
	"	{	z = (P0 *)pptr(i);",
727
	"		if (z->_t == (unsigned) pt)",
728
	"			return BASE+z->_pid;",
729
	"	}",
730
	"	return -1;",
731
	"}",
732
	"",
733
	"#if !defined(HASH64) && !defined(HASH32)",
734
	"	#if WS>4",
735
	"		#define HASH64",
736
	"	#else",
737
	"		#define HASH32",
738
	"	#endif",
739
	"#endif",
740
	"#if defined(HASH32) && defined(SAFETY) && !defined(SFH) && !defined(SPACE)",
741
	"	#define SFH",
742
	"#endif",
743
	"#if defined(SFH) && (defined(BITSTATE) || defined(COLLAPSE) || defined(HC) || defined(HASH64) || defined(MA))",
744
	"	#undef SFH",	/* need 2 hash fcts, for which Jenkins is best */
745
	"#endif",		/* or a 64 bit hash, which we dont have for SFH */
746
	/* for MA, it would slow down the search to use a larger sv then possible */
747
	"#if defined(SFH) && !defined(NOCOMP)",
748
	"	#define NOCOMP	/* go for speed */",
749
	"#endif",
750
	"#if NCORE>1 && !defined(GLOB_HEAP)",
751
	"	#define SEP_HEAP /* version 5.1.2 */",
752
	"#endif",
753
	"",
754
	"#ifdef BITSTATE",
755
	"int",
756
	"bstore_mod(char *v, int n)	/* hasharray size not a power of two */",
757
	"{	unsigned long x, y;",
758
	"	unsigned int i = 1;",
759
	"",
760
	"	d_hash((uchar *) v, n); /* sets j3, j4, K1, K2 */",
761
	"	x = K1; y = j3;",	/* was K2 before 5.1.1 */
762
	"	for (;;)",
763
	"	{	if (!(SS[x%%udmem]&(1<<y))) break;",	/* take the hit in speed */
764
	"		if (i == hfns) {",
765
				"#ifdef DEBUG",
766
	"			printf(\"Old bitstate\\n\");",
767
				"#endif",
768
	"			return 1;",
769
	"		}",
770
	"		x = (x + K2 + i);",	/* no mask, using mod - was K1 before 5.1.1 */
771
	"		y = (y + j4) & 7;",
772
	"		i++;",
773
	"	}",
774
		"#ifdef RANDSTOR",
775
	"	if (rand()%%100 > RANDSTOR) return 0;",
776
		"#endif",
777
	"	for (;;)",
778
	"	{	SS[x%%udmem] |= (1<<y);",
779
	"		if (i == hfns) break;",	/* done */
780
	"		x = (x + K2 + i);",	/* no mask - was K1 before 5.1.1 */
781
	"		y = (y + j4) & 7;",
782
	"		i++;",
783
	"	}",
784
		"#ifdef DEBUG",
785
	"	printf(\"New bitstate\\n\");",
786
		"#endif",
787
	"	if (now._a_t&1)",
788
	"	{	nShadow++;",
789
	"	}",
790
	"	return 0;",
791
	"}",
792
	"int",
793
	"bstore_reg(char *v, int n)	/* extended hashing, Peter Dillinger, 2004 */",
794
	"{	unsigned long x, y;",
795
	"	unsigned int i = 1;",
796
	"",
797
	"	d_hash((uchar *) v, n); /* sets j1-j4 */",
798
	"	x = j2; y = j3;",
799
	"	for (;;)",
800
	"	{	if (!(SS[x]&(1<<y))) break;",	/* at least one bit not set */
801
	"		if (i == hfns) {",
802
				"#ifdef DEBUG",
803
	"			printf(\"Old bitstate\\n\");",
804
				"#endif",
805
	"			return 1;",
806
	"		}",
807
	"		x = (x + j1_spin + i) & nmask;",
808
	"		y = (y + j4) & 7;",
809
	"		i++;",
810
	"	}",
811
		"#ifdef RANDSTOR",
812
	"	if (rand()%%100 > RANDSTOR) return 0;",
813
		"#endif",
814
	"	for (;;)",
815
	"	{	SS[x] |= (1<<y);",
816
	"		if (i == hfns) break;",		/* done */
817
	"		x = (x + j1_spin + i) & nmask;",
818
	"		y = (y + j4) & 7;",
819
	"		i++;",
820
	"	}",
821
		"#ifdef DEBUG",
822
	"	printf(\"New bitstate\\n\");",
823
		"#endif",
824
	"	if (now._a_t&1)",
825
	"	{	nShadow++;",
826
	"	}",
827
	"	return 0;",
828
	"}",
829
	"#endif", /* BITSTATE */
830
	"unsigned long TMODE = 0666; /* file permission bits for trail files */",
831
	"",
832
	"int trcnt=1;",
833
	"char snap[64], fnm[512];",
834
	"",
835
	"int",
836
	"make_trail(void)",
837
	"{	int fd;",
838
	"	char *q;",
839
	"	char MyFile[512];",
840
	"	int w_flags = O_CREAT|O_WRONLY|O_TRUNC;",
841
	"",
842
	"	if (exclusive == 1 && iterative == 0)",
843
	"	{	w_flags |= O_EXCL;",
844
	"	}",
845
	"",
846
	"	q = strrchr(TrailFile, \'/\');",
847
	"	if (q == NULL) q = TrailFile; else q++;",
848
	"	strcpy(MyFile, q); /* TrailFile is not a writable string */",
849
	"",
850
	"	if (iterative == 0 && Nr_Trails++ > 0)",
851
	"	{	sprintf(fnm, \"%%s%%d.%%s\",",
852
	"			MyFile, Nr_Trails-1, tprefix);",
853
	"	} else",
854
	"	{",
855
	"#ifdef PUTPID",
856
	"		sprintf(fnm, \"%%s_%%s_%%d.%%s\", MyFile, progname, getpid(), tprefix);",
857
	"#else",
858
	"		sprintf(fnm, \"%%s.%%s\", MyFile, tprefix);",
859
	"#endif",
860
	"	}",
861
	"	if ((fd = open(fnm, w_flags, TMODE)) < 0)",
862
	"	{	if ((q = strchr(MyFile, \'.\')))",
863
	"		{	*q = \'\\0\';",		/* strip .pml */
864
	"			if (iterative == 0 && Nr_Trails-1 > 0)",
865
	"				sprintf(fnm, \"%%s%%d.%%s\",",
866
	"					MyFile, Nr_Trails-1, tprefix);",
867
	"			else",
868
	"				sprintf(fnm, \"%%s.%%s\", MyFile, tprefix);",
869
	"			*q = \'.\';",
870
	"			fd = open(fnm, w_flags, TMODE);",
871
	"	}	}",
872
	"	if (fd < 0)",
873
	"	{	printf(\"pan: cannot create %%s\\n\", fnm);",
874
	"		perror(\"cause\");",
875
	"	} else",
876
	"	{",
877
	"#if NCORE>1 && (defined(SEP_STATE) || !defined(FULL_TRAIL))",
878
	"	void write_root(void); ",
879
	"	write_root();",
880
	"#else",
881
	"		printf(\"pan: wrote %%s\\n\", fnm);",
882
	"#endif",
883
	"	}",
884
	"	return fd;",
885
	"}",
886
	"",
887
	"#ifndef FREQ",
888
	"#define FREQ	(1000000)",
889
	"#endif",
890
	"double freq = (double) FREQ;\n",
891
 
892
	"#ifdef TRIX",
893
	"void sv_populate(void);",
894
	"",
895
	"void",
896
	"re_populate(void) /* restore procs and chans from now._ids_ */",
897
	"{	int i, cnt = 0;",
898
	"	char *b;",
899
	"#ifdef V_TRIX",
900
	"	printf(\"%%4d: re_populate\\n\", depth);",
901
	"#endif",
902
	"	for (i = 0; i < now._nr_pr; i++, cnt++)",
903
	"	{	b = now._ids_[cnt];",
904
	"		processes[i]->psize = what_p_size( ((P0 *)b)->_t );",
905
	"		memcpy(processes[i]->body, b, processes[i]->psize);",
906
	"#ifdef TRIX_RIX",
907
	"		((P0 *)pptr(i))->_pid = i;",
908
	"#endif",
909
	"#ifndef BFS",
910
	"		processes[i]->modified = 1; /* re-populate */",
911
	"#endif",
912
	"	}",
913
	"	for (i = 0; i < now._nr_qs; i++, cnt++)",
914
	"	{	b = now._ids_[cnt];",
915
	"		channels[i]->psize = what_q_size( ((Q0 *)b)->_t );",
916
	"		memcpy(channels[i]->body, b, channels[i]->psize);",
917
	"#ifndef BFS",
918
	"		channels[i]->modified = 1; /* re-populate */",
919
	"#endif",
920
	"	}",
921
	"}",
922
	"#endif\n",
923
 
924
	"#ifdef BFS",	/* breadth-first search */
925
	"#define Q_PROVISO",
926
	"	#ifndef INLINE_REV",
927
	"		#define INLINE_REV",
928
	"	#endif",
929
	"",
930
	"typedef struct SV_Hold {",
931
	"	State *sv;",
932
	"	int  sz;",
933
	"	struct SV_Hold *nxt;",
934
	"} SV_Hold;",
935
	"",
936
	"typedef struct EV_Hold {",
937
	"	char *sv;",	/* Mask */
938
	"	int  sz;",	/* vsize */
939
	"	int nrpr;",
940
	"	int nrqs;",
941
	"#ifndef TRIX",
942
	"	char *po, *qo;",
943
	"	char *ps, *qs;",
944
	"#endif",
945
	"	struct EV_Hold *nxt;",
946
	"} EV_Hold;",
947
	"",
948
	"typedef struct BFS_Trail {",
949
	"	Trail	*frame;",
950
	"	SV_Hold *onow;",
951
	"	EV_Hold *omask;",
952
	"#ifdef Q_PROVISO",
953
	"	struct H_el *lstate;",
954
	"#endif",
955
	"	short boq;",
956
	"#ifdef VERBOSE",
957
	"	unsigned long nr;",
958
	"#endif",
959
	"	struct BFS_Trail *nxt;",
960
	"} BFS_Trail;",
961
	"",
962
	"BFS_Trail *bfs_trail, *bfs_bot, *bfs_free;",
963
	"",
964
	"SV_Hold *svhold, *svfree;",
965
	"",
966
	"#ifdef BFS_DISK",
967
	"	#ifndef BFS_LIMIT",
968
	"	#define BFS_LIMIT	100000",
969
	"	#endif",
970
	"	#ifndef BFS_DSK_LIMIT",
971
	"	#define BFS_DSK_LIMIT	1000000",
972
	"	#endif",
973
	"	#if defined(WIN32) || defined(WIN64)",
974
	"	#define RFLAGS	(O_RDONLY|O_BINARY)",
975
	"	#define WFLAGS	(O_CREAT|O_WRONLY|O_TRUNC|O_BINARY)",
976
	"	#else",
977
	"	#define RFLAGS	(O_RDONLY)",
978
	"	#define WFLAGS	(O_CREAT|O_WRONLY|O_TRUNC)",
979
	"	#endif",
980
 
981
	"long bfs_size_limit;",
982
	"int bfs_dsk_write = -1;",
983
	"int bfs_dsk_read = -1;",
984
	"long bfs_dsk_writes, bfs_dsk_reads;",
985
	"int bfs_dsk_seqno_w, bfs_dsk_seqno_r;",
986
	"#endif",
987
	"",
988
	"uchar do_reverse(Trans *, short, uchar);",
989
	"void snapshot(void);",
990
	"",
991
	"void",
992
	"select_claim(int x)	/* ignored in BFS mode */",
993
	"{	if (verbose)",
994
	"	{	printf(\"select %%d (ignored)\\n\", x);",
995
	"	}",
996
	"}",
997
	"",
998
	"SV_Hold *",
999
	"getsv(int n)",
1000
	"{	SV_Hold *h = (SV_Hold *) 0, *oh;",
1001
	"",
1002
	"	oh = (SV_Hold *) 0;",
1003
	"	for (h = svfree; h; oh = h, h = h->nxt)",
1004
	"	{	if (n == h->sz)",
1005
	"		{	if (!oh)",
1006
	"				svfree = h->nxt;",
1007
	"			else",
1008
	"				oh->nxt = h->nxt;",
1009
	"			h->nxt = (SV_Hold *) 0;",
1010
	"			break;",
1011
	"		}",
1012
	"		if (n < h->sz)",
1013
	"		{	h = (SV_Hold *) 0;",
1014
	"			break;",
1015
	"		}",
1016
	"		/* else continue */",
1017
	"	}",
1018
	"",
1019
	"	if (!h)",
1020
	"	{	h = (SV_Hold *) emalloc(sizeof(SV_Hold));",
1021
	"		h->sz = n;",
1022
	"#ifdef BFS_DISK",
1023
	"		if (bfs_size_limit >= BFS_LIMIT)",
1024
	"		{	h->sv = (State *) 0;	/* means: read disk */",
1025
	"			bfs_dsk_writes++;	/* count */",
1026
	"			if (bfs_dsk_write < 0	/* file descriptor */",
1027
	"			||  bfs_dsk_writes%%BFS_DSK_LIMIT == 0)",
1028
	"			{	char dsk_nm[32];",
1029
	"				if (bfs_dsk_write >= 0)",
1030
	"				{	(void) close(bfs_dsk_write);",
1031
	"				}",
1032
	"				sprintf(dsk_nm, \"pan_bfs_%%d.tmp\", bfs_dsk_seqno_w++);",
1033
	"				bfs_dsk_write = open(dsk_nm, WFLAGS, 0644);",
1034
	"				if (bfs_dsk_write < 0)",
1035
	"				{	Uerror(\"could not create tmp disk file\");",
1036
	"				}",
1037
	"				printf(\"pan: created disk file %%s\\n\", dsk_nm);",
1038
	"			}",
1039
	"			if (write(bfs_dsk_write, (char *) &now, n) != n)",
1040
	"			{	Uerror(\"aborting -- disk write failed (disk full?)\");",
1041
	"			}",
1042
	"			return h; /* no memcpy */",
1043
	"		}", /* else */
1044
	"		bfs_size_limit++;",
1045
	"#endif",
1046
	"		h->sv = (State *) emalloc(sizeof(State) - VECTORSZ + n);",
1047
	"	}",
1048
	"",
1049
	"	memcpy((char *)h->sv, (char *)&now, n);",
1050
	"	return h;",
1051
	"}",
1052
	"",
1053
	"EV_Hold *",
1054
	"getsv_mask(int n)",
1055
	"{	EV_Hold *h;",
1056
	"	static EV_Hold *kept = (EV_Hold *) 0;",
1057
	"",
1058
	"	for (h = kept; h; h = h->nxt)",
1059
	"		if (n == h->sz",
1060
	"		&&  (memcmp((char *) Mask, (char *) h->sv, n) == 0)",
1061
	"		&&  (now._nr_pr == h->nrpr)",
1062
	"		&&  (now._nr_qs == h->nrqs)",
1063
	"#ifdef TRIX",
1064
	"		)",
1065
	"#else",
1066
	"	#if VECTORSZ>32000",
1067
	"		&&  (memcmp((char *) proc_offset, (char *) h->po, now._nr_pr * sizeof(int)) == 0)",
1068
	"		&&  (memcmp((char *) q_offset, (char *) h->qo, now._nr_qs * sizeof(int)) == 0)",
1069
	"	#else",
1070
	"		&&  (memcmp((char *) proc_offset, (char *) h->po, now._nr_pr * sizeof(short)) == 0)",
1071
	"		&&  (memcmp((char *) q_offset, (char *) h->qo, now._nr_qs * sizeof(short)) == 0)",
1072
	"	#endif",
1073
	"		&&  (memcmp((char *) proc_skip, (char *) h->ps, now._nr_pr * sizeof(uchar)) == 0)",
1074
	"		&&  (memcmp((char *) q_skip,    (char *) h->qs, now._nr_qs * sizeof(uchar)) == 0))",
1075
	"#endif",
1076
	"			break;",
1077
	"	if (!h)",
1078
	"	{	h = (EV_Hold *) emalloc(sizeof(EV_Hold));",
1079
	"		h->sz = n;",
1080
	"		h->nrpr = now._nr_pr;",
1081
	"		h->nrqs = now._nr_qs;",
1082
	"",
1083
	"		h->sv = (char *) emalloc(n * sizeof(char));",
1084
	"		memcpy((char *) h->sv, (char *) Mask, n);",
1085
	"#ifndef TRIX",
1086
	"		if (now._nr_pr > 0)",
1087
	"		{	h->ps = (char *) emalloc(now._nr_pr * sizeof(int));",
1088
	"			memcpy((char *) h->ps, (char *) proc_skip,   now._nr_pr * sizeof(uchar));",
1089
	"	#if VECTORSZ>32000",
1090
	"			h->po = (char *) emalloc(now._nr_pr * sizeof(int));",
1091
	"			memcpy((char *) h->po, (char *) proc_offset, now._nr_pr * sizeof(int));",
1092
	"	#else",
1093
	"			h->po = (char *) emalloc(now._nr_pr * sizeof(short));",
1094
	"			memcpy((char *) h->po, (char *) proc_offset, now._nr_pr * sizeof(short));",
1095
	"	#endif",
1096
	"		}",
1097
	"		if (now._nr_qs > 0)",
1098
	"		{	h->qs = (char *) emalloc(now._nr_qs * sizeof(int));",
1099
	"			memcpy((char *) h->qs, (char *) q_skip,   now._nr_qs * sizeof(uchar));",
1100
	"	#if VECTORSZ>32000",
1101
	"			h->qo = (char *) emalloc(now._nr_qs * sizeof(int));",
1102
	"			memcpy((char *) h->qo, (char *) q_offset, now._nr_qs * sizeof(int));",
1103
	"	#else",
1104
	"			h->qo = (char *) emalloc(now._nr_qs * sizeof(short));",
1105
	"			memcpy((char *) h->qo, (char *) q_offset, now._nr_qs * sizeof(short));",
1106
	"	#endif",
1107
	"		}",
1108
	"#endif",
1109
	"		h->nxt = kept;",
1110
	"		kept = h;",
1111
	"	}",
1112
	"	return h;",
1113
	"}",
1114
	"",
1115
	"void",
1116
	"freesv(SV_Hold *p)",
1117
	"{	SV_Hold *h, *oh;",
1118
	"",
1119
	"	oh = (SV_Hold *) 0;",
1120
	"	for (h = svfree; h; oh = h, h = h->nxt)",
1121
	"	{	if (h->sz >= p->sz)",
1122
	"			break;",
1123
	"	}",
1124
	"	if (!oh)",
1125
	"	{	p->nxt = svfree;",
1126
	"		svfree = p;",
1127
	"	} else",
1128
	"	{	p->nxt = h;",
1129
	"		oh->nxt = p;",
1130
	"	}",
1131
	"}",
1132
	"",
1133
	"BFS_Trail *",
1134
	"get_bfs_frame(void)",
1135
	"{	BFS_Trail *t;",
1136
	"",
1137
	"	if (bfs_free)",
1138
	"	{	t = bfs_free;",
1139
	"		bfs_free = bfs_free->nxt;",
1140
	"		t->nxt = (BFS_Trail *) 0;",
1141
	"	} else",
1142
	"	{	t = (BFS_Trail *) emalloc(sizeof(BFS_Trail));",
1143
	"	}",
1144
	"	t->frame = (Trail *) emalloc(sizeof(Trail));", /* always new */
1145
	"	/* new because we keep a ptr to the frame of parent states */",
1146
	"	/* used for reconstructing path and recovering failed rvs etc */",
1147
	"	return t;",
1148
	"}",
1149
	"",
1150
	"void",
1151
	"push_bfs(Trail *f, int d)",
1152
	"{	BFS_Trail *t;",
1153
	"",
1154
	"	t = get_bfs_frame();",
1155
	"	memcpy((char *)t->frame, (char *)f, sizeof(Trail));",
1156
	"	t->frame->o_tt = d;	/* depth */",
1157
	"",
1158
	"	t->boq = boq;",
1159
	"#ifdef TRIX",
1160
	"	sv_populate();",
1161
	"#endif",
1162
	"	t->onow = getsv(vsize);",
1163
	"	t->omask = getsv_mask(vsize);",
1164
	"#if defined(FULLSTACK) && defined(Q_PROVISO)",
1165
	"	t->lstate = Lstate;",
1166
	"#endif",
1167
	"	if (!bfs_bot)",
1168
	"	{	bfs_bot = bfs_trail = t;",
1169
	"	} else",
1170
	"	{	bfs_bot->nxt = t;",
1171
	"		bfs_bot = t;",
1172
	"	}",
1173
	"#ifdef VERBOSE",
1174
	"	t->nr = nstates;",
1175
	"#endif",
1176
	"#ifdef CHECK",
1177
	"	printf(\"PUSH %%u (depth %%d, nr %%d)\\n\", t->frame, d, t->nr);",
1178
	"#endif",
1179
	"}",
1180
	"",
1181
	"Trail *",
1182
	"pop_bfs(void)",
1183
	"{	BFS_Trail *t;",
1184
	"",
1185
	"	if (!bfs_trail)",
1186
	"	{	return (Trail *) 0;",
1187
	"	}",
1188
	"	t = bfs_trail;",
1189
	"	bfs_trail = t->nxt;",
1190
	"	if (!bfs_trail)",
1191
	"	{	bfs_bot = (BFS_Trail *) 0;",
1192
	"	}",
1193
	"#if defined(Q_PROVISO) && !defined(BITSTATE) && !defined(NOREDUCE)",
1194
	"	if (t->lstate)",
1195
	"	{	t->lstate->tagged = 0;",
1196
	"	}",
1197
	"#endif",
1198
	"	t->nxt = bfs_free;",
1199
	"	bfs_free = t;",
1200
	"",
1201
	"	vsize = t->onow->sz;",
1202
	"	boq = t->boq;",
1203
	"#ifdef BFS_DISK",
1204
	"	if (t->onow->sv == (State *) 0)",
1205
	"	{	char dsk_nm[32];",
1206
	"		bfs_dsk_reads++;	/* count */",
1207
	"		if (bfs_dsk_read >= 0	/* file descriptor */",
1208
	"		&&  bfs_dsk_reads%%BFS_DSK_LIMIT == 0)",
1209
	"		{	(void) close(bfs_dsk_read);",
1210
	"			sprintf(dsk_nm, \"pan_bfs_%%d.tmp\", bfs_dsk_seqno_r-1);",
1211
	"			(void) unlink(dsk_nm);",
1212
	"			bfs_dsk_read = -1;",
1213
	"		}",
1214
	"		if (bfs_dsk_read < 0)",
1215
	"		{	sprintf(dsk_nm, \"pan_bfs_%%d.tmp\", bfs_dsk_seqno_r++);",
1216
	"			bfs_dsk_read = open(dsk_nm, RFLAGS);",
1217
	"			if (bfs_dsk_read < 0)",
1218
	"			{	Uerror(\"could not open temp disk file\");",
1219
	"		}	}",
1220
	"		if (read(bfs_dsk_read, (char *) &now, vsize) != vsize)",
1221
	"		{	Uerror(\"bad bfs disk file read\");",
1222
	"		}",
1223
	"	#ifndef NOVSZ",
1224
	"		if (now._vsz != vsize)",
1225
	"		{	Uerror(\"disk read vsz mismatch\");",
1226
	"		}",
1227
	"	#endif",
1228
	"	} else",
1229
	"#endif",
1230
	"	{	memcpy((uchar *) &now, (uchar *) t->onow->sv, vsize);",
1231
	"	}",
1232
	"	memcpy((uchar *) Mask, (uchar *) t->omask->sv, vsize);",
1233
	"#ifdef TRIX",
1234
	"	re_populate();",
1235
	"#else",
1236
	"	if (now._nr_pr > 0)",
1237
	"	#if VECTORSZ>32000",
1238
	"	{	memcpy((char *)proc_offset, (char *)t->omask->po, now._nr_pr * sizeof(int));",
1239
	"	#else",
1240
	"	{	memcpy((char *)proc_offset, (char *)t->omask->po, now._nr_pr * sizeof(short));",
1241
	"	#endif",
1242
	"		memcpy((char *)proc_skip,   (char *)t->omask->ps, now._nr_pr * sizeof(uchar));",
1243
	"	}",
1244
	"	if (now._nr_qs > 0)",
1245
	"	#if VECTORSZ>32000",
1246
	"	{	memcpy((uchar *)q_offset, (uchar *)t->omask->qo, now._nr_qs * sizeof(int));",
1247
	"	#else",
1248
	"	{	memcpy((uchar *)q_offset, (uchar *)t->omask->qo, now._nr_qs * sizeof(short));",
1249
	"	#endif",
1250
	"		memcpy((uchar *)q_skip,   (uchar *)t->omask->qs, now._nr_qs * sizeof(uchar));",
1251
	"	}",
1252
	"#endif",
1253
	"#ifdef BFS_DISK",
1254
	"	if (t->onow->sv != (State *) 0)",
1255
	"#endif",
1256
	"	{	freesv(t->onow);	/* omask not freed */",
1257
	"	}",
1258
	"#ifdef CHECK",
1259
	"	printf(\"POP %%u (depth %%d, nr %%d)\\n\", t->frame, t->frame->o_tt, t->nr);",
1260
	"#endif",
1261
	"	return t->frame;",
1262
	"}",
1263
	"",
1264
	"void",
1265
	"store_state(Trail *ntrpt, int shortcut, short oboq)",
1266
	"{",
1267
	"#ifdef VERI",
1268
	"	Trans *t2 = (Trans *) 0;",
1269
	"	uchar ot; int tt, E_state;",
1270
	"	uchar o_opm = trpt->o_pm, *othis = this;",
1271
	"",
1272
	"	if (shortcut)",
1273
	"	{",
1274
	"	#ifdef VERBOSE",
1275
	"		printf(\"claim: shortcut\\n\");",
1276
	"	#endif",
1277
	"		goto store_it;	/* no claim move */",
1278
	"	}",
1279
	"",
1280
	"	this  = pptr(0);	/* 0 = never claim */",
1281
	"	trpt->o_pm = 0;",	/* to interpret else in never claim */
1282
	"",
1283
	"	tt    = (int)   ((P0 *)this)->_p;",
1284
	"	ot    = (uchar) ((P0 *)this)->_t;",
1285
	"",
1286
	"	#ifdef HAS_UNLESS",
1287
	"	E_state = 0;",
1288
	"	#endif",
1289
	"	for (t2 = trans[ot][tt]; t2; t2 = t2?t2->nxt:(Trans *)0)",
1290
	"	{",
1291
	"	#ifdef HAS_UNLESS",
1292
	"		if (E_state > 0 && E_state != t2->e_trans)",
1293
	"		{	break;",
1294
	"		}",
1295
	"	#endif",
1296
	"		if (do_transit(t2, 0))",
1297
	"		{",
1298
	"	#ifdef VERBOSE",
1299
	"			if (!reached[ot][t2->st])",
1300
	"			printf(\"depth: %%d -- claim move from %%d -> %%d\\n\",",
1301
	"				trpt->o_tt, ((P0 *)this)->_p, t2->st);",
1302
	"	#endif",
1303
	"	#ifdef HAS_UNLESS",
1304
	"			E_state = t2->e_trans;",
1305
	"	#endif",
1306
	"			if (t2->st > 0)",
1307
	"			{	((P0 *)this)->_p = t2->st;",
1308
	"				reached[ot][t2->st] = 1;",
1309
	"	#ifndef NOCLAIM",
1310
	"				if (stopstate[ot][t2->st])",
1311
	"				{	uerror(\"end state in claim reached\");",
1312
	"				}",
1313
	"	#endif",
1314
	"			}",
1315
	"			if (now._nr_pr == 0)	/* claim terminated */",
1316
	"				uerror(\"end state in claim reached\");",
1317
	"",
1318
	"	#ifdef PEG",
1319
	"			peg[t2->forw]++;",
1320
	"	#endif",
1321
	"			trpt->o_pm |= 1;",
1322
	"			if (t2->atom&2)",
1323
	"			{ Uerror(\"atomic in claim not supported in BFS\");",
1324
	"			}",
1325
	"store_it:",
1326
	"",
1327
	"#endif",	/* VERI */
1328
	"",
1329
	"#if defined(BITSTATE)",
1330
	"			if (!bstore((char *)&now, vsize))",
1331
	"#elif defined(MA)",
1332
	"			if (!gstore((char *)&now, vsize, 0))",
1333
	"#else",
1334
	"			if (!hstore((char *)&now, vsize))",
1335
	"#endif",
1336
	"			{	static long sdone = (long) 0; long ndone;",
1337
	"				nstates++;",
1338
	"#ifndef NOREDUCE",
1339
	"				trpt->tau |= 64;", /* bfs: succ definitely outside stack */
1340
	"#endif",
1341
	"				ndone = (unsigned long) (nstates/(freq));",
1342
	"				if (ndone != sdone && mreached%%10 != 0)",
1343
	"				{	snapshot();",
1344
	"					sdone = ndone;",
1345
	"#if defined(AUTO_RESIZE) && !defined(BITSTATE) && !defined(MA)",
1346
	"					if (nstates > ((double)(1<<(ssize+1))))",
1347
	"					{	void resize_hashtable(void);",
1348
	"						resize_hashtable();",
1349
	"					}",
1350
	"#endif",
1351
	"				}",
1352
	"#if SYNC",
1353
	"				if (boq != -1)",
1354
	"					midrv++;",
1355
	"				else if (oboq != -1)",
1356
	"				{	Trail *x;",
1357
	"					x = (Trail *) trpt->ostate; /* pre-rv state */",
1358
	"					if (x) x->o_pm |= 4; /* mark success */",
1359
	"				}",
1360
	"#endif",
1361
	"				push_bfs(ntrpt, trpt->o_tt+1);",
1362
	"			} else",
1363
	"			{	truncs++;",
1364
 
1365
	"#if !defined(NOREDUCE) && defined(FULLSTACK) && defined(Q_PROVISO)",
1366
	"	#if !defined(BITSTATE)",
1367
	"				if (Lstate && Lstate->tagged)",
1368
	"				{  trpt->tau |= 64;",
1369
	"				}",
1370
	"	#else",
1371
	"				if (trpt->tau&32)",
1372
	"				{  BFS_Trail *tprov;",
1373
	"				   for (tprov = bfs_trail; tprov; tprov = tprov->nxt)",
1374
	"					if (tprov->onow->sv != (State *) 0",
1375
	"					&&  memcmp((uchar *)&now, (uchar *)tprov->onow->sv, vsize) == 0)",
1376
	"					{	trpt->tau |= 64;",
1377
	"						break;	/* state is in queue */",
1378
	"				}	}",
1379
	"	#endif",
1380
	"#endif",
1381
	"			}",
1382
	"#ifdef VERI",
1383
	"			((P0 *)this)->_p = tt;	/* reset claim */",
1384
	"			if (t2)",
1385
	"				do_reverse(t2, 0, 0);",
1386
	"			else",
1387
	"				break;",
1388
	"	}	}",
1389
	"	this = othis;",
1390
	"	trpt->o_pm = o_opm;",
1391
	"#endif",
1392
	"}",
1393
	"",
1394
	"Trail *ntrpt;",	/* 4.2.8 */
1395
	"",
1396
	"void",
1397
	"bfs(void)",
1398
	"{	Trans *t; Trail *otrpt, *x;",
1399
	"	uchar _n, _m, ot, nps = 0;",
1400
	"	int tt, E_state;",
1401
	"	short II, From = (short) (now._nr_pr-1), To = BASE;",
1402
	"	short oboq = boq;",
1403
	"",
1404
	"	ntrpt = (Trail *) emalloc(sizeof(Trail));",
1405
	"	trpt->ostate = (struct H_el *) 0;",
1406
	"	trpt->tau = 0;",
1407
	"",
1408
	"	trpt->o_tt = -1;",
1409
	"	store_state(ntrpt, 0, oboq);	/* initial state */",
1410
	"",
1411
	"	while ((otrpt = pop_bfs()))	/* also restores now */",
1412
	"	{	memcpy((char *) trpt, (char *) otrpt, sizeof(Trail));",
1413
	"#if defined(C_States) && (HAS_TRACK==1)",
1414
	"		c_revert((uchar *) &(now.c_state[0]));",
1415
	"#endif",
1416
	"		if (trpt->o_pm & 4)",
1417
	"		{",
1418
	"#ifdef VERBOSE",
1419
	"			printf(\"Revisit of atomic not needed (%%d)\\n\",",
1420
	"				trpt->o_pm);",	/* at least 1 rv succeeded */
1421
	"#endif",
1422
	"			continue;",
1423
	"		}",
1424
	"#ifndef NOREDUCE",
1425
	"		nps = 0;",
1426
	"#endif",
1427
	"		if (trpt->o_pm == 8)",
1428
	"		{	revrv++;",
1429
	"			if (trpt->tau&8)",
1430
	"			{",
1431
	"#ifdef VERBOSE",
1432
	"				printf(\"Break atomic (pm:%%d,tau:%%d)\\n\",",
1433
	"					trpt->o_pm, trpt->tau);",
1434
	"#endif",
1435
	"				trpt->tau &= ~8;",
1436
	"			}",
1437
	"#ifndef NOREDUCE",
1438
	"			else if (trpt->tau&32)",	/* was a preselected move */
1439
	"			{",
1440
	"	#ifdef VERBOSE",
1441
	"				printf(\"Void preselection (pm:%%d,tau:%%d)\\n\",",
1442
	"					trpt->o_pm, trpt->tau);",
1443
	"	#endif",
1444
	"				trpt->tau &= ~32;",
1445
	"				nps = 1; /* no preselection in repeat */",
1446
	"			}",
1447
	"#endif",
1448
	"		}",
1449
	"		trpt->o_pm &= ~(4|8);",
1450
	"		if (trpt->o_tt > mreached)",
1451
	"		{	mreached = trpt->o_tt;",
1452
	"			if (mreached%%10 == 0)",
1453
	"			{	snapshot();",
1454
	"		}	}",
1455
	"		depth = trpt->o_tt;",
1456
 
1457
	"		if (depth >= maxdepth)",
1458
	"		{",
1459
	"#if SYNC",
1460
	"			Trail *x;",
1461
	"			if (boq != -1)",
1462
	"			{	x = (Trail *) trpt->ostate;",
1463
	"				if (x) x->o_pm |= 4; /* not failing */",
1464
	"			}",
1465
	"#endif",
1466
	"			truncs++;",
1467
	"			if (!warned)",
1468
	"			{	warned = 1;",
1469
	"		  		printf(\"error: max search depth too small\\n\");",
1470
	"			}",
1471
	"			if (bounded)",
1472
	"			{	uerror(\"depth limit reached\");",
1473
	"			}",
1474
	"			continue;",
1475
	"		}",
1476
	"#ifndef NOREDUCE",
1477
	"		if (boq == -1 && !(trpt->tau&8) && nps == 0)",
1478
	"		for (II = now._nr_pr-1; II >= BASE; II -= 1)",
1479
	"		{",
1480
	"Pickup:		this = pptr(II);",
1481
	"			tt = (int) ((P0 *)this)->_p;",
1482
	"			ot = (uchar) ((P0 *)this)->_t;",
1483
	"			if (trans[ot][tt]->atom & 8)",	/* safe */
1484
	"			{	t = trans[ot][tt];",
1485
	"				if (t->qu[0] != 0)",
1486
	"				{	Ccheck++;",
1487
	"					if (!q_cond(II, t))",
1488
	"						continue;",
1489
	"					Cholds++;",
1490
	"				}",
1491
	"				From = To = II;",
1492
	"				trpt->tau |= 32; /* preselect marker */",
1493
	"	#ifdef DEBUG",
1494
	"				printf(\"%%3ld: proc %%d PreSelected (tau=%%d)\\n\", ",
1495
	"					depth, II, trpt->tau);",
1496
	"	#endif",
1497
	"				goto MainLoop;",
1498
	"		}	}",
1499
	"		trpt->tau &= ~32;",	/* not preselected */
1500
	"#endif",	/* if !NOREDUCE */
1501
	"Repeat:",
1502
	"		if (trpt->tau&8)		/* atomic */",
1503
	"		{	From = To = (short ) trpt->pr;",
1504
	"			nlinks++;",
1505
	"		} else",
1506
	"		{	From = now._nr_pr-1;",
1507
	"			To = BASE;",
1508
	"		}",
1509
	"MainLoop:",
1510
	"		_n = _m = 0;",
1511
	"		for (II = From; II >= To; II -= 1)",
1512
	"		{",
1513
	"			this = pptr(II);",
1514
	"			tt = (int) ((P0 *)this)->_p;",
1515
	"			ot = (uchar) ((P0 *)this)->_t;",
1516
	"#if SYNC",
1517
	"			/* no rendezvous with same proc */",
1518
	"			if (boq != -1 && trpt->pr == II)",
1519
	"			{	continue;",
1520
	"			}",
1521
	"#endif",
1522
	"			ntrpt->pr = (uchar) II;",
1523
	"			ntrpt->st = tt;	",
1524
	"			trpt->o_pm &= ~1; /* no move yet */",
1525
	"#ifdef EVENT_TRACE",
1526
	"			trpt->o_event = now._event;",
1527
	"#endif",
1528
	"#ifdef HAS_PROVIDED",
1529
	"			if (!provided(II, ot, tt, t))",
1530
	"			{	continue;",
1531
	"			}",
1532
	"#endif",
1533
	"#ifdef HAS_UNLESS",
1534
	"			E_state = 0;",
1535
	"#endif",
1536
	"			for (t = trans[ot][tt]; t; t = t->nxt)",
1537
	"			{",
1538
	"#ifdef HAS_UNLESS",
1539
	"				if (E_state > 0",
1540
	"				&&  E_state != t->e_trans)",
1541
	"					break;",
1542
	"#endif",
1543
	"				ntrpt->o_t = t;",
1544
	"",
1545
	"				oboq = boq;",
1546
	"",
1547
	"				if (!(_m = do_transit(t, II)))",
1548
	"					continue;",
1549
	"",
1550
	"				trpt->o_pm |= 1;	/* we moved */",
1551
	"				(trpt+1)->o_m = _m;	/* for unsend */",
1552
	"#ifdef PEG",
1553
	"				peg[t->forw]++;",
1554
	"#endif",
1555
	"#ifdef CHECK",
1556
	"				printf(\"%%3ld: proc %%d exec %%d, \",",
1557
	"					depth, II, t->forw);",
1558
	"				printf(\"%%d to %%d, %%s %%s %%s\",",
1559
	"					tt, t->st, t->tp,",
1560
	"					(t->atom&2)?\"atomic\":\"\",",
1561
	"					(boq != -1)?\"rendez-vous\":\"\");",
1562
	"	#ifdef HAS_UNLESS",
1563
	"				if (t->e_trans)",
1564
	"					printf(\" (escapes to state %%d)\", t->st);",
1565
	"	#endif",
1566
	"				printf(\" %%saccepting [tau=%%d]\\n\",",
1567
	"					(trpt->o_pm&2)?\"\":\"non-\", trpt->tau);",
1568
	"#endif",
1569
	"#ifdef HAS_UNLESS",
1570
	"				E_state = t->e_trans;",
1571
	"	#if SYNC>0",
1572
	"				if (t->e_trans > 0 && (boq != -1 /* || oboq != -1 */))",
1573
	"				{ fprintf(efd, \"error:\ta rendezvous stmnt in the escape clause\\n\");",
1574
	"				  fprintf(efd, \"\tof an unless stmnt is not compatible with -DBFS\\n\");",
1575
	"				  pan_exit(1);",
1576
	"				}",
1577
	"	#endif",
1578
	"#endif",
1579
	"				if (t->st > 0)",
1580
	"				{	((P0 *)this)->_p = t->st;",
1581
	"				}",
1582
	"",
1583
	"	/* ptr to pred: */	ntrpt->ostate = (struct H_el *) otrpt;",
1584
	"				ntrpt->st = tt;",
1585
	"				if (boq == -1 && (t->atom&2))	/* atomic */",
1586
	"					ntrpt->tau = 8;	/* record for next move */",
1587
	"				else",
1588
	"					ntrpt->tau = 0;",
1589
	"				store_state(ntrpt, (boq != -1 || (t->atom&2)), oboq);",
1590
	"#ifdef EVENT_TRACE",
1591
	"				now._event = trpt->o_event;",
1592
	"#endif",
1593
	"				/* undo move and continue */",
1594
	"				trpt++;	/* this is where ovals and ipt are set */",
1595
	"				do_reverse(t, II, _m);	/* restore now. */",
1596
	"				trpt--;",
1597
	"#ifdef CHECK",
1598
	"	#if NCORE>1",
1599
	"				enter_critical(GLOBAL_LOCK);	/* verbose mode */",
1600
	"				printf(\"cpu%%d: \", core_id);",
1601
	"	#endif",
1602
	"				printf(\"%%3d: proc %%d \", depth, II);",
1603
	"				printf(\"reverses %%d, %%d to %%d,\",",
1604
	"					t->forw, tt, t->st);",
1605
	"				printf(\" %%s [abit=%%d,adepth=%%d,\",",
1606
	"					t->tp, now._a_t, A_depth);",
1607
	"				printf(\"tau=%%d,%%d]\\n\",",
1608
	"					trpt->tau, (trpt-1)->tau);",
1609
	"	#if NCORE>1",
1610
	"				leave_critical(GLOBAL_LOCK);",
1611
	"	#endif",
1612
	"#endif",
1613
	"				reached[ot][t->st] = 1;",
1614
	"				reached[ot][tt]    = 1;",
1615
	"",
1616
	"				((P0 *)this)->_p = tt;",
1617
	"				_n |= _m;",
1618
	"		}	}",
1619
	"#ifndef NOREDUCE",	/* with PO */
1620
	"		/* preselected - no succ definitely outside stack */",
1621
	"		if ((trpt->tau&32) && !(trpt->tau&64))",
1622
	"		{	From = now._nr_pr-1; To = BASE;",
1623
	"	#ifdef DEBUG",
1624
	"			cpu_printf(\"%%3ld: proc %%d UnSelected (_n=%%d, tau=%%d)\\n\", ",
1625
	"				depth, II+1, (int) _n, trpt->tau);",
1626
	"	#endif",
1627
	"			_n = 0; trpt->tau &= ~32;",
1628
	"			if (II >= BASE)",
1629
	"			{	goto Pickup;",
1630
	"			}",
1631
	"			goto MainLoop;",
1632
	"		}",
1633
	"		trpt->tau &= ~(32|64);",
1634
	"#endif",	/* PO */
1635
	"		if (_n != 0)",
1636
	"		{	continue;",
1637
	"		}",
1638
	"#ifdef DEBUG",
1639
	"		printf(\"%%3ld: no move [II=%%d, tau=%%d, boq=%%d, _nr_pr=%%d]\\n\",",
1640
	"			depth, II, trpt->tau, boq, now._nr_pr);",
1641
	"#endif",
1642
	"		if (boq != -1)",
1643
	"		{	failedrv++;",
1644
	"			x = (Trail *) trpt->ostate;	/* pre-rv state */",
1645
	"			if (!x)",
1646
	"			{	continue;		/* root state */",
1647
	"			}",
1648
	"			if ((x->tau&8) || (x->tau&32)) /* break atomic or preselect at parent */",
1649
	"			{	x->o_pm |= 8; /* mark failure */",
1650
	"				this = pptr(otrpt->pr);",
1651
	"#ifdef VERBOSE",
1652
	"				printf(\"\\treset state of %%d from %%d to %%d\\n\",",
1653
	"					otrpt->pr, ((P0 *)this)->_p, otrpt->st);",
1654
	"#endif",
1655
	"				((P0 *)this)->_p = otrpt->st;",
1656
	"				unsend(boq);	/* retract rv offer */",
1657
	"				boq = -1;",
1658
 
1659
	"				push_bfs(x, x->o_tt);",
1660
	"#ifdef VERBOSE",
1661
	"				printf(\"failed rv, repush with %%d\\n\", x->o_pm);",
1662
	"#endif",
1663
	"			}",
1664
	"#ifdef VERBOSE",
1665
	"			else",
1666
	"			{	printf(\"failed rv, tau at parent: %%d\\n\", x->tau);",
1667
	"			}",
1668
	"#endif",
1669
	"		} else if (now._nr_pr > 0)",
1670
	"		{",
1671
	"			if ((trpt->tau&8))		/* atomic */",
1672
	"			{	trpt->tau &= ~(1|8);	/* 1=timeout, 8=atomic */",
1673
	"#ifdef DEBUG",
1674
	"				printf(\"%%3ld: atomic step proc %%d blocks\\n\",",
1675
	"					depth, II+1);",
1676
	"#endif",
1677
	"				goto Repeat;",
1678
	"			}",
1679
	"",
1680
	"			if (!(trpt->tau&1)) /* didn't try timeout yet */",
1681
	"			{	trpt->tau |=  1;",
1682
	"#ifdef DEBUG",
1683
	"				printf(\"%%d: timeout\\n\", depth);",
1684
	"#endif",
1685
	"				goto MainLoop;",
1686
	"			}",
1687
	"#ifndef VERI",
1688
	"			if (!noends && !a_cycles && !endstate())",
1689
	"			{	uerror(\"invalid end state\");",
1690
	"			}",
1691
	"#endif",
1692
	"	}	}",
1693
	"}",
1694
	"",
1695
	"void",
1696
	"putter(Trail *trpt, int fd)",
1697
	"{	long j;",
1698
	"",
1699
	"	if (!trpt) return;",
1700
	"",
1701
	"	if (trpt != (Trail *) trpt->ostate)",
1702
	"		putter((Trail *) trpt->ostate, fd);",
1703
	"",
1704
	"	if (trpt->o_t)",
1705
	"	{	sprintf(snap, \"%%d:%%d:%%d\\n\",",
1706
	"			trcnt++, trpt->pr, trpt->o_t->t_id);",
1707
	"		j = strlen(snap);",
1708
	"		if (write(fd, snap, j) != j)",
1709
	"		{       printf(\"pan: error writing %%s\\n\", fnm);",
1710
	"			pan_exit(1);",
1711
	"	}	}",
1712
	"}",
1713
	"",
1714
	"void",
1715
	"nuerror(char *str)",
1716
	"{	int fd = make_trail();",
1717
	"	int j;",
1718
	"",
1719
	"	if (fd < 0) return;",
1720
	"#ifdef VERI",
1721
	"	sprintf(snap, \"-2:%%d:-2\\n\", (uchar) ((P0 *)pptr(0))->_t);",
1722
	"	(void) write(fd, snap, strlen(snap));",
1723
	"#endif",
1724
	"#ifdef MERGED",
1725
	"	sprintf(snap, \"-4:-4:-4\\n\");",
1726
	"	(void) write(fd, snap, strlen(snap));",
1727
	"#endif",
1728
	"	trcnt = 1;",
1729
	"	putter(trpt, fd);",
1730
	"	if (ntrpt->o_t)",	/* 4.2.8 -- Alex example, missing last transition */
1731
	"	{	sprintf(snap, \"%%d:%%d:%%d\\n\",",
1732
	"			trcnt++, ntrpt->pr, ntrpt->o_t->t_id);",
1733
	"		j = strlen(snap);",
1734
	"		if (write(fd, snap, j) != j)",
1735
	"		{       printf(\"pan: error writing %%s\\n\", fnm);",
1736
	"			pan_exit(1);",
1737
	"	}	}",
1738
	"	close(fd);",
1739
	"	if (errors >= upto && upto != 0)",
1740
	"	{	wrapup();",
1741
	"	}",
1742
	"}",
1743
	"#endif",	/* BFS */
1744
	0,
1745
};
1746
 
1747
static char *Code2d[] = {
1748
	"clock_t start_time;",
1749
	"#if NCORE>1",
1750
	"clock_t crash_stamp;",
1751
	"#endif",
1752
	"#if !defined(WIN32) && !defined(WIN64)",
1753
	"struct tms start_tm;",
1754
	"#endif",
1755
	"",
1756
	"void",
1757
	"start_timer(void)",
1758
	"{",
1759
	"#if defined(WIN32) || defined(WIN64)",
1760
	"	start_time = clock();",
1761
	"#else",
1762
	"	start_time = times(&start_tm);",
1763
	"#endif",
1764
	"}",
1765
	"",
1766
	"void",
1767
	"stop_timer(void)",
1768
	"{	clock_t stop_time;",
1769
	"	double delta_time;",
1770
	"#if !defined(WIN32) && !defined(WIN64)",
1771
	"	struct tms stop_tm;",
1772
	"	stop_time = times(&stop_tm);",
1773
	"	delta_time = ((double) (stop_time - start_time)) / ((double) sysconf(_SC_CLK_TCK));",
1774
	"#else",
1775
	"	stop_time = clock();",
1776
	"	delta_time = ((double) (stop_time - start_time)) / ((double) CLOCKS_PER_SEC);",
1777
	"#endif",
1778
	"	if (readtrail || delta_time < 0.00) return;",
1779
	"#if NCORE>1",
1780
	"	if (core_id == 0 && nstates > (double) 0)",
1781
	"	{	printf(\"\\ncpu%%d: elapsed time %%.3g seconds (%%g states visited)\\n\",",
1782
	"			core_id, delta_time, nstates);",
1783
	"		if (delta_time > 0.01)",
1784
	"		{	printf(\"cpu%%d: rate %%g states/second\\n\", core_id, nstates/delta_time);",
1785
	"		}",
1786
	"		{ void check_overkill(void);",
1787
	"	 	  check_overkill();",
1788
	"	}	}",
1789
	"#else",
1790
	"	printf(\"\\npan: elapsed time %%.3g seconds\\n\", delta_time);",
1791
	"	if (delta_time > 0.01)",
1792
	"	{	printf(\"pan: rate %%9.8g states/second\\n\", nstates/delta_time);",
1793
	"		if (verbose)",
1794
	"		{	printf(\"pan: avg transition delay %%.5g usec\\n\",",
1795
	"				delta_time/(nstates+truncs));",
1796
	"	}	}",
1797
	"#endif",
1798
	"}",
1799
	"",
1800
	"#if NCORE>1",
1801
	"#ifdef T_ALERT",
1802
	"double t_alerts[17];",
1803
	"",
1804
	"void",
1805
	"crash_report(void)",
1806
	"{	int i;",
1807
	"	printf(\"crash alert intervals:\\n\");",
1808
	"	for (i = 0; i < 17; i++)",
1809
	"	{	printf(\"%%d\\t%%g\\n\", i, t_alerts[i]);",
1810
	"}	}",
1811
	"#endif",
1812
	"",
1813
	"void",
1814
	"crash_reset(void)",
1815
	"{	/* false alarm */",
1816
	"	if (crash_stamp != (clock_t) 0)",
1817
	"	{",
1818
	"#ifdef T_ALERT",
1819
	"		double delta_time;",
1820
	"		int i;",
1821
		"#if defined(WIN32) || defined(WIN64)",
1822
	"		delta_time = ((double) (clock() - crash_stamp)) / ((double) CLOCKS_PER_SEC);",
1823
		"#else",
1824
	"		delta_time = ((double) (times(&start_tm) - crash_stamp)) / ((double) sysconf(_SC_CLK_TCK));",
1825
		"#endif",
1826
	"		for (i = 0; i < 16; i++)",
1827
	"		{	if (delta_time <= (i*30))",
1828
	"			{	t_alerts[i] = delta_time;",
1829
	"				break;",
1830
	"		}	}",
1831
	"		if (i == 16) t_alerts[i] = delta_time;",
1832
	"#endif",
1833
	"		if (verbose)",
1834
	"		printf(\"cpu%%d: crash alert off\\n\", core_id);",
1835
	"	}",
1836
	"	crash_stamp = (clock_t) 0;",
1837
	"}",
1838
	"",
1839
	"int",
1840
	"crash_test(double maxtime)",
1841
	"{	double delta_time;",
1842
	"	if (crash_stamp == (clock_t) 0)",
1843
	"	{	/* start timing */",
1844
	"#if defined(WIN32) || defined(WIN64)",
1845
	"		crash_stamp = clock();",
1846
	"#else",
1847
	"		crash_stamp = times(&start_tm);",
1848
	"#endif",
1849
	"		if (verbose)",
1850
	"		{	printf(\"cpu%%d: crash detection\\n\", core_id);",
1851
	"		}",
1852
	"		return 0;",
1853
	"	}",
1854
	"#if defined(WIN32) || defined(WIN64)",
1855
	"	delta_time = ((double) (clock() - crash_stamp)) / ((double) CLOCKS_PER_SEC);",
1856
	"#else",
1857
	"	delta_time = ((double) (times(&start_tm) - crash_stamp)) / ((double) sysconf(_SC_CLK_TCK));",
1858
	"#endif",
1859
	"	return (delta_time >= maxtime);",
1860
	"}",
1861
	"#endif",
1862
	"",
1863
	"void",
1864
	"do_the_search(void)",
1865
	"{	int i;",
1866
	"	depth = mreached = 0;",
1867
	"	trpt = &trail[0];",
1868
	"#ifdef VERI",
1869
	"	trpt->tau |= 4;	/* the claim moves first */",
1870
	"#endif",
1871
	"	for (i = 0; i < (int) now._nr_pr; i++)",
1872
	"	{	P0 *ptr = (P0 *) pptr(i);",
1873
	"#ifndef NP",
1874
	"		if (!(trpt->o_pm&2)",
1875
	"		&&  accpstate[ptr->_t][ptr->_p])",
1876
	"		{	trpt->o_pm |= 2;",
1877
	"		}",
1878
	"#else",
1879
	"		if (!(trpt->o_pm&4)",
1880
	"		&&  progstate[ptr->_t][ptr->_p])",
1881
	"		{	trpt->o_pm |= 4;",
1882
	"		}",
1883
	"#endif",
1884
	"	}",
1885
	"#ifdef EVENT_TRACE",
1886
	"#ifndef NP",
1887
	"	if (accpstate[EVENT_TRACE][now._event])",
1888
	"	{	trpt->o_pm |= 2;",
1889
	"	}",
1890
	"#else",
1891
	"	if (progstate[EVENT_TRACE][now._event])",
1892
	"	{	trpt->o_pm |= 4;",
1893
	"	}",
1894
	"#endif",
1895
	"#endif",
1896
	"#ifndef NOCOMP",
1897
	"	Mask[0] = Mask[1] = 1;	/* _nr_pr, _nr_qs */",
1898
	"	if (!a_cycles)",
1899
	"	{	i = &(now._a_t) - (uchar *) &now;",
1900
	"		Mask[i] = 1; /* _a_t */",
1901
	"	}",
1902
	"#ifndef NOFAIR",
1903
	"	if (!fairness)",
1904
	"	{	int j = 0;",
1905
	"		i = &(now._cnt[0]) - (uchar *) &now;",
1906
	"		while (j++ < NFAIR)",
1907
	"			Mask[i++] = 1; /* _cnt[] */",
1908
	"	}",
1909
	"#endif",
1910
	"#endif",
1911
	"#ifndef NOFAIR",
1912
	"	if (fairness",
1913
	"	&&  (a_cycles && (trpt->o_pm&2)))",
1914
	"	{	now._a_t = 2;	/* set the A-bit */",
1915
	"		now._cnt[0] = now._nr_pr + 1;",	/* NEW: +1 */
1916
		"#ifdef VERBOSE",
1917
	"	printf(\"%%3ld: fairness Rule 1, cnt=%%d, _a_t=%%d\\n\",",
1918
	"		depth, now._cnt[now._a_t&1], now._a_t);",
1919
		"#endif",
1920
	"	}",
1921
	"#endif",
1922
 
1923
	"	c_stack_start = (char *) &i; /* meant to be read-only */",
1924
 
1925
	"#if defined(HAS_CODE) && defined (C_INIT)",
1926
	"	C_INIT; /* initialization of data that must precede fork() */",
1927
	"	c_init_done++;",
1928
	"#endif",
1929
 
1930
	"#if defined(C_States) && (HAS_TRACK==1)",
1931
	"	/* capture initial state of tracked C objects */",
1932
	"	c_update((uchar *) &(now.c_state[0]));",
1933
	"#endif",
1934
 
1935
	"#ifdef HAS_CODE",
1936
	"	if (readtrail) getrail(); /* no return */",
1937
	"#endif",
1938
	"	start_timer();",
1939
	"#ifdef BFS",
1940
	"	bfs();",
1941
	"#else",
1942
		"#if defined(C_States) && defined(HAS_STACK) && (HAS_TRACK==1)",
1943
		"	/* initial state of tracked & unmatched objects */",
1944
		"	c_stack((uchar *) &(svtack->c_stack[0]));",
1945
		"#endif",
1946
 
1947
	"#if defined(P_RAND) || defined(T_RAND)",
1948
	"	srand(s_rand);",
1949
	"#endif",
1950
 
1951
	"#if NCORE>1",
1952
	"	mem_get();",
1953
	"#else",
1954
	"	new_state();	/* start 1st DFS */",
1955
	"#endif",
1956
	"#endif",
1957
	"}",
1958
 
1959
	"#ifdef INLINE_REV",
1960
	"uchar",
1961
	"do_reverse(Trans *t, short II, uchar M)",
1962
	"{	uchar _m = M;",
1963
	"	int  tt = (int) ((P0 *)this)->_p;",
1964
	"#include REVERSE_MOVES",
1965
	"R999:	return _m;",
1966
	"}",
1967
	"#endif",
1968
 
1969
	"#ifndef INLINE",
1970
	"#ifdef EVENT_TRACE",
1971
	"static char _tp = 'n'; static int _qid = 0;",
1972
	"#endif",
1973
	"uchar",
1974
	"do_transit(Trans *t, short II)",
1975
	"{	uchar _m = 0;",
1976
	"	int  tt = (int) ((P0 *)this)->_p;",
1977
	"#ifdef M_LOSS",
1978
	"	uchar delta_m = 0;",
1979
	"#endif",
1980
	"#ifdef EVENT_TRACE",
1981
	"	short oboq = boq;",
1982
	"	uchar ot = (uchar)  ((P0 *)this)->_t;",
1983
	"	if (II == -EVENT_TRACE) boq = -1;",
1984
		"#define continue	{ boq = oboq; return 0; }",
1985
	"#else",
1986
		"#define continue	return 0",
1987
		"#ifdef SEPARATE",
1988
	"	uchar ot = (uchar)  ((P0 *)this)->_t;",
1989
		"#endif",
1990
	"#endif",
1991
	"#include FORWARD_MOVES",
1992
	"P999:",
1993
	"#ifdef EVENT_TRACE",
1994
	"	if (II == -EVENT_TRACE) boq = oboq;",
1995
	"#endif",
1996
	"	return _m;",
1997
	"#undef continue",
1998
	"}",
1999
	"#ifdef EVENT_TRACE",
2000
	"void",
2001
	"require(char tp, int qid)",
2002
	"{	Trans *t;",
2003
	"	_tp = tp; _qid = qid;",
2004
	"",
2005
	"	if (now._event != endevent)",
2006
	"	for (t = trans[EVENT_TRACE][now._event]; t; t = t->nxt)",
2007
	"	{	if (do_transit(t, -EVENT_TRACE))",
2008
	"		{	now._event = t->st;",
2009
	"			reached[EVENT_TRACE][t->st] = 1;",
2010
	"#ifdef VERBOSE",
2011
	"	printf(\"	event_trace move to -> %%d\\n\", t->st);",
2012
	"#endif",
2013
	"#ifndef BFS",
2014
		"#ifndef NP",
2015
	"			if (accpstate[EVENT_TRACE][now._event])",
2016
	"				(trpt+1)->o_pm |= 2;",
2017
		"#else",
2018
	"			if (progstate[EVENT_TRACE][now._event])",
2019
	"				(trpt+1)->o_pm |= 4;",
2020
		"#endif",
2021
	"#endif",
2022
	"#ifdef NEGATED_TRACE",
2023
	"			if (now._event == endevent)",
2024
	"			{",
2025
		"#ifndef BFS",
2026
	"				depth++; trpt++;",
2027
		"#endif",
2028
	"				uerror(\"event_trace error (all events matched)\");",
2029
		"#ifndef BFS",
2030
	"				trpt--; depth--;",
2031
		"#endif",
2032
	"				break;",
2033
	"			}",
2034
	"#endif",
2035
	"			for (t = t->nxt; t; t = t->nxt)",
2036
	"			{	if (do_transit(t, -EVENT_TRACE))",
2037
	"				 Uerror(\"non-determinism in event-trace\");",
2038
	"			}",
2039
	"			return;",
2040
	"		}",
2041
	"#ifdef VERBOSE",
2042
	"		 else",
2043
	"	printf(\"	event_trace miss '%%c' -- %%d, %%d, %%d\\n\",",
2044
	"			tp, qid, now._event, t->forw);",
2045
	"#endif",
2046
	"	}",
2047
	"#ifdef NEGATED_TRACE",
2048
	"	now._event = endevent; /* only 1st try will count -- fixed 4.2.6 */",
2049
	"#else",	
2050
		"#ifndef BFS",
2051
	"	depth++; trpt++;",
2052
		"#endif",
2053
	"	uerror(\"event_trace error (no matching event)\");",
2054
		"#ifndef BFS",
2055
	"	trpt--; depth--;",
2056
		"#endif",
2057
	"#endif",
2058
	"}",
2059
	"#endif",
2060
	"int",
2061
	"enabled(int iam, int pid)",
2062
	"{	Trans *t; uchar *othis = this;",
2063
	"	int res = 0; int tt; uchar ot;",
2064
	"#ifdef VERI",
2065
	"	/* if (pid > 0) */ pid++;",
2066
	"#endif",
2067
	"	if (pid == iam)",
2068
	"		Uerror(\"used: enabled(pid=thisproc)\");",
2069
	"	if (pid < 0 || pid >= (int) now._nr_pr)",
2070
	"		return 0;",
2071
	"	this = pptr(pid);",
2072
	"	TstOnly = 1;",
2073
	"	tt = (int) ((P0 *)this)->_p;",
2074
	"	ot = (uchar) ((P0 *)this)->_t;",
2075
	"	for (t = trans[ot][tt]; t; t = t->nxt)",
2076
	"		if (do_transit(t, (short) pid))",
2077
	"		{	res = 1;",
2078
	"			break;",
2079
	"		}",
2080
	"	TstOnly = 0;",
2081
	"	this = othis;",
2082
	"	return res;",
2083
	"}",
2084
	"#endif",
2085
	"void",
2086
	"snap_time(void)",
2087
	"{	clock_t stop_time;",
2088
	"	double delta_time;",
2089
	"#if !defined(WIN32) && !defined(WIN64)",
2090
	"	struct tms stop_tm;",
2091
	"	stop_time  = times(&stop_tm);",
2092
	"	delta_time = ((double) (stop_time - start_time)) / ((double) sysconf(_SC_CLK_TCK));",
2093
	"#else",
2094
	"	stop_time  = clock();",
2095
	"	delta_time = ((double) (stop_time - start_time)) / ((double) CLOCKS_PER_SEC);",
2096
	"#endif",
2097
	"	if (delta_time > 0.01)",
2098
	"	{	printf(\"t= %%8.3g \", delta_time);",
2099
	"		printf(\"R= %%7.0g\", nstates/delta_time);",
2100
	"	}",
2101
	"	printf(\"\\n\");",
2102
	"	if (quota > 0.1 && delta_time > quota)",
2103
	"	{	printf(\"Time limit of %%6.3g minutes exceeded\\n\", quota/60.0);",
2104
	"#if NCORE>1",
2105
	"		fflush(stdout);",
2106
	"		leave_critical(GLOBAL_LOCK);",
2107
	"		sudden_stop(\"time-limit\");",
2108
	"		exit(1);",
2109
	"#endif",
2110
	"		wrapup();",
2111
	"	}",
2112
	"}",
2113
	"void",
2114
	"snapshot(void)",
2115
	"{",
2116
	"#if NCORE>1",
2117
	"	enter_critical(GLOBAL_LOCK);	/* snapshot */",
2118
	"	printf(\"cpu%%d: \", core_id);",
2119
	"#endif",
2120
	"	printf(\"Depth= %%7ld States= %%8.3g \",",
2121
	"#if NCORE>1",
2122
	"		(long) (nr_handoffs * z_handoff) +",
2123
	"#endif",
2124
	"		mreached, nstates);",
2125
	"	printf(\"Transitions= %%8.3g \", nstates+truncs);",
2126
	"#ifdef MA",
2127
	"	printf(\"Nodes= %%7d \", nr_states);",
2128
	"#endif",
2129
	"	printf(\"Memory= %%9.3f\\t\", memcnt/1048576.);",
2130
	"	snap_time();",
2131
	"	fflush(stdout);",
2132
	"#if NCORE>1",
2133
	"	leave_critical(GLOBAL_LOCK);",
2134
	"#endif",
2135
	"}",
2136
	"#ifdef SC",
2137
	"void",
2138
	"stack2disk(void)",
2139
	"{",
2140
	"	if (!stackwrite",
2141
	"	&&  (stackwrite = creat(stackfile, TMODE)) < 0)",
2142
	"		Uerror(\"cannot create stackfile\");",
2143
	"",
2144
	"	if (write(stackwrite, trail, DDD*sizeof(Trail))",
2145
	"	!=  DDD*sizeof(Trail))",
2146
	"		Uerror(\"stackfile write error -- disk is full?\");",
2147
	"",
2148
	"	memmove(trail, &trail[DDD], (HHH-DDD+2)*sizeof(Trail));",
2149
	"	memset(&trail[HHH-DDD+2], 0, (omaxdepth - HHH + DDD - 2)*sizeof(Trail));",
2150
	"	CNT1++;",
2151
	"}",
2152
	"void",
2153
	"disk2stack(void)",
2154
	"{	long have;",
2155
	"",
2156
	"	CNT2++;",
2157
	"	memmove(&trail[DDD], trail, (HHH-DDD+2)*sizeof(Trail));",
2158
	"",
2159
	"	if (!stackwrite",
2160
	"	||  lseek(stackwrite, -DDD* (off_t) sizeof(Trail), SEEK_CUR) == -1)",
2161
	"		Uerror(\"disk2stack lseek error\");",
2162
	"",
2163
	"	if (!stackread",
2164
	"	&&  (stackread = open(stackfile, 0)) < 0)",
2165
	"		Uerror(\"cannot open stackfile\");",
2166
	"",
2167
	"	if (lseek(stackread, (CNT1-CNT2)*DDD* (off_t) sizeof(Trail), SEEK_SET) == -1)",
2168
	"		Uerror(\"disk2stack lseek error\");",
2169
	"",
2170
	"	have = read(stackread, trail, DDD*sizeof(Trail));",
2171
	"	if (have !=  DDD*sizeof(Trail))",
2172
	"		Uerror(\"stackfile read error\");",
2173
	"}",
2174
	"#endif",
2175
 
2176
	"uchar *",
2177
	"Pptr(int x)",
2178
	"{	if (x < 0 || x >= MAXPROC",	/* does not exist */
2179
	"#ifdef TRIX",
2180
	"	|| !processes[x])",
2181
	"#else",
2182
	"	|| !proc_offset[x])",
2183
	"#endif",
2184
	"		return noptr;",
2185
	"	else",
2186
	"		return (uchar *) pptr(x);",
2187
	"}\n",
2188
	"uchar *",
2189
	"Qptr(int x)",
2190
	"{	if (x < 0 || x >= MAXQ",
2191
	"#ifdef TRIX",
2192
	"	|| !channels[x])",
2193
	"#else",
2194
	"	|| !q_offset[x])",
2195
	"#endif",
2196
	"		return noqptr;",
2197
	"	else",
2198
	"		return (uchar *) qptr(x);",
2199
	"}\n",
2200
 
2201
	"int qs_empty(void);",
2202
	"#if !defined(BFS) && (!defined(BITSTATE) || !defined(MA))",
2203
	"#ifdef NSUCC",
2204
	"int N_succ[512];",
2205
	"void",
2206
	"tally_succ(int cnt)",
2207
	"{	if (cnt < 512) N_succ[cnt]++;",
2208
	"	else printf(\"tally_succ: cnt %%d exceeds range\\n\", cnt);",
2209
	"}",
2210
	"",
2211
	"void",
2212
	"dump_succ(void)",
2213
	"{	int i; double sum = 0.0;",
2214
	"	double w_avg = 0.0;",
2215
	"	printf(\"Successor counts:\\n\");",
2216
	"	for (i = 0; i < 512; i++)",
2217
	"	{	sum += (double) N_succ[i];",
2218
	"	}",
2219
	"	for (i = 0; i < 512; i++)",
2220
	"	{	if (N_succ[i] > 0)",
2221
	"		{	printf(\"%%3d\t%%10d\t(%%.4g %%%% of total)\\n\",",
2222
	"				i, N_succ[i], (100.0 * (double) N_succ[i])/sum);",
2223
	"			w_avg += (double) i * (double) N_succ[i];",
2224
	"	}	}",
2225
	"	if (sum > N_succ[0])",
2226
	"	printf(\"mean %%.4g (without 0: %%.4g)\\n\", w_avg / sum, w_avg / (sum - (double) N_succ[0]));",
2227
	"}",
2228
	"#endif",
2229
	"",
2230
	"#if NCLAIMS>1",
2231
	"void",
2232
	"select_claim(int n)",
2233
	"{	int m, i;",
2234
	"	if (n < 0 || n >= NCLAIMS)",
2235
	"	{	uerror(\"non-existing claim\");",
2236
	"	} else",
2237
	"	{	m = ((Pclaim *)pptr(0))->_n;",
2238
	"		if (verbose)",
2239
	"		{	printf(\"%%d: Claim %%s (%%d), from state %%d\\n\",",
2240
	"				(int) depth, procname[spin_c_typ[n]],",
2241
	"				n, ((Pclaim *)pptr(0))->c_cur[n]);",
2242
	"		}",
2243
	"		((Pclaim *)pptr(0))->c_cur[m] = ((Pclaim *)pptr(0))->_p;",
2244
	"		((Pclaim *)pptr(0))->_t = spin_c_typ[n];",
2245
	"		((Pclaim *)pptr(0))->_p = ((Pclaim *)pptr(0))->c_cur[n];",
2246
	"		((Pclaim *)pptr(0))->_n = n;",
2247
	"		for (i = 0; src_all[i].src != (short *) 0; i++)",
2248
	"		{	if (src_all[i].tp == spin_c_typ[n])",
2249
	"			{	src_claim = src_all[i].src;",
2250
	"				break;",
2251
	"		}	}", 
2252
	"		if (src_all[i].src == (short *) 0)",
2253
	"		{	uerror(\"cannot happen: src_ln ref\");",
2254
	"	}	}",
2255
	"}",
2256
	"#else",
2257
	"void",
2258
	"select_claim(int n)",
2259
	"{	if (n != 0) uerror(\"non-existing claim\");",
2260
	"}",
2261
	"#endif",
2262
	"",
2263
	"#ifdef REVERSE",
2264
	"	#define FROM_P	(BASE)",
2265
	"	#define UPTO_P	(now._nr_pr-1)",
2266
	"	#define MORE_P	(II <= To)",	/* p.o. only */
2267
	"	#define INI_P	(From-1)",	/* fairness only */
2268
	"	#define ALL_P	(II = From; II <= To; II++)",
2269
	"#else",
2270
	"	#define FROM_P	(now._nr_pr-1)",
2271
	"	#define UPTO_P	(BASE)",
2272
	"	#define MORE_P	(II >= BASE)",
2273
	"	#define INI_P	(From+1)",
2274
	"	#define ALL_P	(II = From; II >= To; II--)",
2275
	"#endif",
2276
	"/*",
2277
	" * new_state() is the main DFS search routine in the verifier",
2278
	" * it has a lot of code ifdef-ed together to support",
2279
	" * different search modes, which makes it quite unreadable.",
2280
	" * if you are studying the code, use the C preprocessor",
2281
	" * to generate a specific version from the pan.c source,",
2282
	" * e.g. by saying:",
2283
	" *	gcc -E -DNOREDUCE -DBITSTATE pan.c > ppan.c",
2284
	" * and then study the resulting file, instead of this version",
2285
	" */",
2286
	"",
2287
	"void",
2288
	"new_state(void)",
2289
	"{	Trans *t;",
2290
	"	uchar _n, _m, ot;",
2291
	"#ifdef T_RAND",
2292
	"	short ooi, eoi;",
2293
	"#endif",
2294
 
2295
	"#ifdef M_LOSS",
2296
	"	uchar delta_m = 0;",
2297
	"#endif",
2298
	"	short II, JJ = 0, kk;",
2299
	"	int tt;",
2300
	"	short From = FROM_P, To = UPTO_P;",
2301
	"#ifdef BCS",
2302
	"	trpt->sched_limit = 0; /* at depth=0 only */",
2303
	"#endif",
2304
	"Down:",
2305
	"#ifdef CHECK",
2306
	"	cpu_printf(\"%%d: Down - %%s %%saccepting [pids %%d-%%d]\\n\",",
2307
	"		depth, (trpt->tau&4)?\"claim\":\"program\",",
2308
	"		(trpt->o_pm&2)?\"\":\"non-\", From, To);",
2309
	"#endif",
2310
 
2311
	"#ifdef P_RAND",
2312
	"	trpt->p_skip = -1;",
2313
	"#endif",
2314
 
2315
	"#ifdef SC",
2316
	"	if (depth > hiwater)",
2317
	"	{	stack2disk();",
2318
	"		maxdepth += DDD;",
2319
	"		hiwater += DDD;",
2320
	"		trpt -= DDD;",
2321
	"		if(verbose)",
2322
	"		printf(\"zap %%d: %%d (maxdepth now %%d)\\n\",",
2323
	"			CNT1, hiwater, maxdepth);",
2324
	"	}",
2325
	"#endif",
2326
 
2327
	"	trpt->tau &= ~(16|32|64); /* make sure these are off */",
2328
	"#if defined(FULLSTACK) && defined(MA)",
2329
	"	trpt->proviso = 0;",
2330
	"#endif",
2331
	"#ifdef NSUCC",
2332
	"	trpt->n_succ = 0;",
2333
	"#endif",
2334
	"#if NCORE>1",
2335
	"	if (mem_hand_off())",
2336
	"	{",
2337
	"#if SYNC",
2338
	"		(trpt+1)->o_n = 1;	/* not a deadlock: as below  */",
2339
	"#endif",
2340
	"#ifndef LOOPSTATE",
2341
	"		(trpt-1)->tau |= 16;	/* worstcase guess: as below */",
2342
	"#endif",
2343
	"#if NCORE>1 && defined(FULL_TRAIL)",
2344
	"		if (upto > 0)",
2345
	"		{	Pop_Stack_Tree();",
2346
	"		}",
2347
	"#endif",
2348
	"		goto Up;",
2349
	"	}",
2350
	"#endif",
2351
 
2352
	"	if (depth >= maxdepth)",
2353
	"	{	if (!warned)",
2354
	"		{ warned = 1;",
2355
	"		  printf(\"error: max search depth too small\\n\");",
2356
	"		}",
2357
	"		if (bounded)",
2358
	"		{	uerror(\"depth limit reached\");",
2359
	"		}",
2360
	"		truncs++;",
2361
	"#if SYNC",
2362
	"		(trpt+1)->o_n = 1; /* not a deadlock */",
2363
	"#endif",
2364
	"#ifndef LOOPSTATE",
2365
	"		(trpt-1)->tau |= 16;	/* worstcase guess */",
2366
	"#endif",
2367
 
2368
	"#if NCORE>1 && defined(FULL_TRAIL)",
2369
	"		if (upto > 0)",
2370
	"		{	Pop_Stack_Tree();",
2371
	"		}",
2372
	"#endif",
2373
	"		goto Up;",
2374
	"	}",
2375
	"AllOver:",
2376
	"#if (defined(FULLSTACK) && !defined(MA)) || NCORE>1",
2377
	"	/* if atomic or rv move, carry forward previous state */",
2378
	"	trpt->ostate = (trpt-1)->ostate;",
2379
	"#endif",
2380
	"#ifdef VERI",
2381
	"	if ((trpt->tau&4) || ((trpt-1)->tau&128))",
2382
	"#endif",
2383
	"	if (boq == -1) {	/* if not mid-rv */",
2384
	"#ifndef SAFETY",
2385
	"		/* this check should now be redundant",
2386
	"		 * because the seed state also appears",
2387
	"		 * on the 1st dfs stack and would be",
2388
	"		 * matched in hstore below",
2389
	"		 */",
2390
	"		if ((now._a_t&1) && depth > A_depth)",
2391
	"		{	if (!memcmp((char *)&A_Root, ",
2392
	"				(char *)&now, vsize))",
2393
	"			{",
2394
	"				depthfound = A_depth;",
2395
		"#ifdef CHECK",
2396
	"			  printf(\"matches seed\\n\");",
2397
		"#endif",
2398
		"#ifdef NP",
2399
	"			  uerror(\"non-progress cycle\");",
2400
		"#else",
2401
	"			  uerror(\"acceptance cycle\");",
2402
		"#endif",
2403
	"#if NCORE>1 && defined(FULL_TRAIL)",
2404
	"			if (upto > 0)",
2405
	"			{	Pop_Stack_Tree();",
2406
	"			}",
2407
	"#endif",
2408
	"			  goto Up;",
2409
	"			}",
2410
		"#ifdef CHECK",
2411
	"			printf(\"not seed\\n\");",
2412
		"#endif",
2413
	"		}",
2414
	"#endif",
2415
	"		if (!(trpt->tau&8)) /* if no atomic move */",
2416
	"		{",
2417
	"#if defined(BCS) && defined(NO_LAST) && defined(HAS_LAST)",
2418
	"			uchar was_last = now._last;",
2419
	"			now._last = 0;	/* value not stored */",
2420
	"#endif",
2421
	"#ifdef BITSTATE",
2422
		"#ifdef CNTRSTACK",	/* -> bitstate, reduced, safety */
2423
	"		#if defined(BCS) && defined(STORE_CTX)",
2424
	"		{ int xj;",
2425
	"			for (xj = trpt->sched_limit; xj <= sched_max; xj++)",
2426
	"			{	now._ctx = xj;",
2427
	"				II = bstore((char *)&now, vsize);",
2428
	"				trpt->j6 = j1_spin; trpt->j7 = j2;",
2429
	"				JJ = LL[j1_spin] && LL[j2];",
2430
	"				if (II != 0) { break; }",
2431
	"			}",
2432
	"			now._ctx = 0; /* just in case */",
2433
	"		}",
2434
	"		#else",
2435
	"			II = bstore((char *)&now, vsize);",
2436
	"			trpt->j6 = j1_spin; trpt->j7 = j2;",
2437
	"			JJ = LL[j1_spin] && LL[j2];",
2438
	"		#endif",
2439
		"#else",
2440
	"		#ifdef FULLSTACK", /* bstore after onstack_now, to preserve j1-j4 */
2441
	"		   #if defined(BCS) && defined(STORE_CTX)",
2442
	"		   { int xj;",
2443
	"			now._ctx = 0;",
2444
	"			JJ = onstack_now();",		    /* mangles j1 */
2445
	"			for (xj = trpt->sched_limit; xj <= sched_max; xj++)",
2446
	"			{	now._ctx = xj;",
2447
	"				II = bstore((char *)&now, vsize);", /* sets j1-j4 */
2448
	"				if (II != 0) { break; }",
2449
	"			}",
2450
	"			now._ctx = 0;",
2451
	"		   }",
2452
	"		   #else",
2453
	"			JJ = onstack_now();",		    /* mangles j1 */
2454
	"			II = bstore((char *)&now, vsize);", /* sets j1-j4 */
2455
	"		   #endif",
2456
	"		#else",
2457
	"		   #if defined(BCS) && defined(STORE_CTX)",
2458
	"		   { int xj;",
2459
	"			for (xj = trpt->sched_limit; xj <= sched_max; xj++)",
2460
	"			{	now._ctx = xj;",
2461
	"				II = bstore((char *)&now, vsize);", /* sets j1-j4 */
2462
	"				JJ = II; /* worstcase guess for p.o. - order corrected in 5.2.1 */",
2463
	"				if (II != 0) { break; }",
2464
	"			}",
2465
	"			now._ctx = 0;",
2466
	"		   }",
2467
	"		   #else",
2468
	"			II = bstore((char *)&now, vsize);", /* sets j1-j4 */
2469
	"			JJ = II; /* worstcase guess for p.o. - order corrected in 5.2.1 */",
2470
	"		   #endif",
2471
	"		#endif",
2472
		"#endif",
2473
	"#else",
2474
		"#ifdef MA",
2475
	"			II = gstore((char *)&now, vsize, 0);",
2476
			"#ifndef FULLSTACK",
2477
	"			JJ = II;",
2478
			"#else",
2479
	"			JJ = (II == 2)?1:0;",
2480
			"#endif",
2481
		"#else",
2482
	"			II = hstore((char *)&now, vsize);",
2483
	"			/* @hash j1_spin II */",
2484
			"#ifdef FULLSTACK",
2485
	"			JJ = (II == 2)?1:0;",
2486
			"#endif",
2487
		"#endif",
2488
	"#endif",
2489
	"			kk = (II == 1 || II == 2);",
2490
	/* actually, BCS implies HAS_LAST */
2491
	"#if defined(BCS) && defined(NO_LAST) && defined(HAS_LAST)",
2492
	"			now._last = was_last;	/* restore value */",
2493
	"#endif",
2494
 
2495
				/* II==0 new state */
2496
				/* II==1 old state */
2497
				/* II==2 on current dfs stack */
2498
				/* II==3 on 1st dfs stack */
2499
	"#ifndef SAFETY",
2500
 
2501
		"#if NCORE==1 || defined (SEP_STATE)",	/* or else we don't know which stack its on */
2502
	"			if (II == 2 && ((trpt->o_pm&2) || ((trpt-1)->o_pm&2)))",
2503
	"		#ifndef NOFAIR",
2504
	"#if 0",
2505
	"			if (!fairness || ((now._a_t&1) && now._cnt[1] == 1)) /* 5.1.4 */",
2506
	"#else",
2507
	"			if (a_cycles && !fairness) /* 5.1.6 -- example by Hirofumi Watanabe */",
2508
	"#endif",
2509
	"		#endif",
2510
	"			{",
2511
	"				II = 3; /* Schwoon & Esparza 2005, Gastin&Moro 2004 */",
2512
			"#ifdef VERBOSE",
2513
	"				printf(\"state match on dfs stack\\n\");",
2514
			"#endif",
2515
	"				goto same_case;",
2516
	"			}",
2517
		"#endif",
2518
 
2519
		"#if defined(FULLSTACK) && defined(BITSTATE)",
2520
	"			if (!JJ && (now._a_t&1) && depth > A_depth)",
2521
	"			{	int oj1 = j1_spin;",
2522
	"				uchar o_a_t = now._a_t;",
2523
	"				now._a_t &= ~(1|16|32);", /* 1st stack  */
2524
	"				if (onstack_now())",	  /* changes j1_spin */
2525
	"				{	II = 3;",
2526
		"#ifdef VERBOSE",
2527
	"					printf(\"state match on 1st dfs stack\\n\");",
2528
		"#endif",
2529
	"				}",
2530
	"				now._a_t = o_a_t;",	/* restore */
2531
	"				j1_spin = oj1;",
2532
	"			}",
2533
		"#endif",
2534
	"			if (II == 3 && a_cycles && (now._a_t&1))",
2535
	"			{",
2536
		"#ifndef NOFAIR",
2537
	"			   if (fairness && now._cnt[1] > 1)	/* was != 0 */",
2538
	"			   {",
2539
		"#ifdef VERBOSE",
2540
	"				printf(\"\tfairness count non-zero\\n\");",
2541
		"#endif",
2542
	"				II = 0;", /* treat as new state */
2543
	"			   } else",
2544
		"#endif",
2545
	"			   {",
2546
		"#ifndef BITSTATE",
2547
	"				nShadow--;",
2548
		"#endif",
2549
	"same_case:			if (Lstate) depthfound = Lstate->D;",
2550
		"#ifdef NP",
2551
	"				uerror(\"non-progress cycle\");",
2552
		"#else",
2553
	"				uerror(\"acceptance cycle\");",
2554
		"#endif",
2555
	"#if NCORE>1 && defined(FULL_TRAIL)",
2556
	"				if (upto > 0)",
2557
	"				{	Pop_Stack_Tree();",
2558
	"				}",
2559
	"#endif",
2560
	"				goto Up;",
2561
	"			   }",
2562
	"			}",
2563
	"#endif",
2564
 
2565
	"#ifndef NOREDUCE",
2566
	"	#ifndef SAFETY",
2567
	"		#if NCORE>1 && !defined(SEP_STATE) && defined(V_PROVISO)",
2568
	"			if (II != 0 && (!Lstate || Lstate->cpu_id < core_id))",
2569
	"			{	(trpt-1)->tau |= 16;",	/* treat as a stack state */
2570
	"			}",
2571
	"		#endif",
2572
	"			if ((II && JJ) || (II == 3))",
2573
	"			{	/* marker for liveness proviso */",
2574
	"		#ifndef LOOPSTATE",
2575
	"				(trpt-1)->tau |= 16;",	/* truncated on stack */
2576
	"		#endif",
2577
	"				truncs2++;",
2578
	"			}",
2579
		"#else",
2580
	"		#if NCORE>1 && !defined(SEP_STATE) && defined(V_PROVISO)",
2581
	"			if (!(II != 0 && (!Lstate || Lstate->cpu_id < core_id)))",
2582
	"			{	/* treat as stack state */",
2583
	"				(trpt-1)->tau |= 16;",
2584
	"			} else",
2585
	"			{	/* treat as non-stack state */",
2586
	"				(trpt-1)->tau |= 64;",
2587
	"			}",
2588
	"		#endif",
2589
	"			if (!II || !JJ)",
2590
	"			{	/* successor outside stack */",
2591
	"				(trpt-1)->tau |= 64;",
2592
	"			}",
2593
	"	#endif",
2594
	"#endif",
2595
	"#if defined(BCS) && (defined(NOREDUCE) || !defined(SAFETY))",
2596
	/* needed for BCS - cover cases where it would not otherwise be set */
2597
	"			if (!II || !JJ)",
2598
	"			{	(trpt-1)->tau |= 64;",
2599
	"			}",
2600
	"#endif",
2601
	"			if (II)",
2602
	"			{	truncs++;",
2603
	"#if NCORE>1 && defined(FULL_TRAIL)",
2604
	"				if (upto > 0)",
2605
	"				{	Pop_Stack_Tree();",
2606
	"					if (depth == 0)",
2607
	"					{	return;",
2608
	"				}	}",
2609
	"#endif",
2610
	"				goto Up;",
2611
	"			}",
2612
	"			if (!kk)",
2613
	"			{	static long sdone = (long) 0; long ndone;",
2614
	"				nstates++;",
2615
	"#if defined(ZAPH) && defined(BITSTATE)",
2616
	"				zstates += (double) hfns;",
2617
	"#endif",
2618
	"				ndone = (unsigned long) (nstates/(freq));",
2619
	"				if (ndone != sdone)",
2620
	"				{	snapshot();",
2621
	"					sdone = ndone;",
2622
	"#if defined(AUTO_RESIZE) && !defined(BITSTATE) && !defined(MA)",
2623
	"					if (nstates > ((double)(ONE_L<<(ssize+1))))",
2624
	"					{	void resize_hashtable(void);",
2625
	"						resize_hashtable();",
2626
	"					}",
2627
	"#endif",
2628
	"#if defined(ZAPH) && defined(BITSTATE)",
2629
	"					if (zstates > ((double)(ONE_L<<(ssize-2))))",
2630
	"					{	/* more than half the bits set */",
2631
	"						void zap_hashtable(void);",
2632
	"						zap_hashtable();",
2633
	"						zstates = 0;",
2634
	"					}",
2635
	"#endif",
2636
	"				}",
2637
	"#ifdef SVDUMP",
2638
	"				if (vprefix > 0)",
2639
	"	#ifdef SHO",	/* Store Hash Only */
2640
	"			/* always use the same hashfunction, for consistency across runs */",
2641
	"				if (HASH_NR != 0)",
2642
	"				{	int oh = HASH_NR;",
2643
	"					HASH_NR = 0;",
2644
	"					d_hash((char *) &now, vsize); /* set K1 */",
2645
	"					HASH_NR = oh;",
2646
	"				}",
2647
	"				if (write(svfd, (uchar *) &K1, sizeof(unsigned long)) != sizeof(unsigned long))",
2648
	"	#else",
2649
	"				if (write(svfd, (uchar *) &now, vprefix) != vprefix)",
2650
	"	#endif",
2651
	"				{	fprintf(efd, \"writing %%s.svd failed\\n\", PanSource);",
2652
	"					wrapup();",
2653
	"				}",
2654
	"#endif",
2655
	"#if defined(MA) && defined(W_XPT)",
2656
	"				if ((unsigned long) nstates%%W_XPT == 0)",
2657
	"				{	void w_xpoint(void);",
2658
	"					w_xpoint();",
2659
	"				}",
2660
	"#endif",
2661
	"			}",
2662
 
2663
	"#if defined(FULLSTACK) || defined(CNTRSTACK)",
2664
	"			onstack_put();",
2665
		"#ifdef DEBUG2",
2666
		"#if defined(FULLSTACK) && !defined(MA)",
2667
	"			printf(\"%%d: putting %%u (%%d)\\n\", depth,",
2668
	"				trpt->ostate, ",
2669
	"				(trpt->ostate)?trpt->ostate->tagged:0);",
2670
		"#else",
2671
	"			printf(\"%%d: putting\\n\", depth);",
2672
		"#endif",
2673
		"#endif",
2674
	"#else",
2675
	"	#if NCORE>1",
2676
	"			trpt->ostate = Lstate;",
2677
	"	#endif",
2678
	"#endif",
2679
	"	}	}",
2680
 
2681
	"	if (depth > mreached)",
2682
	"		mreached = depth;",
2683
	"#ifdef VERI",
2684
	"	if (trpt->tau&4)",
2685
	"#endif",
2686
	"	trpt->tau &= ~(1|2);	/* timeout and -request off */",
2687
	"	_n = 0;",
2688
	"#if SYNC",
2689
	"	(trpt+1)->o_n = 0;",
2690
	"#endif",
2691
	"#ifdef VERI",
2692
	"	if (now._nr_pr == 0)	/* claim terminated */",
2693
	"		uerror(\"end state in claim reached\");",
2694
	"",
2695
	"	if (stopstate[((Pclaim *)pptr(0))->_t][((Pclaim *)pptr(0))->_p])",
2696
	"	{	uerror(\"end state in claim reached\");",
2697
	"	}",
2698
	"Stutter:",
2699
	"	if (trpt->tau&4)	/* must make a claimmove */",
2700
	"	{",
2701
	"#ifndef NOFAIR",
2702
	"		if ((now._a_t&2)	/* A-bit set */",
2703
	"		&&   now._cnt[now._a_t&1] == 1)",
2704
	"		{	now._a_t &= ~2;",
2705
	"			now._cnt[now._a_t&1] = 0;",
2706
	"			trpt->o_pm |= 16;",
2707
		"#ifdef DEBUG",
2708
	"	printf(\"%%3d: fairness Rule 3.: _a_t = %%d\\n\",",
2709
	"		depth, now._a_t);",
2710
		"#endif",
2711
	"		}",
2712
	"#endif",
2713
	"		II = 0;		/* never */",
2714
	"		goto Veri0;",
2715
	"	}",
2716
	"#endif",
2717
	"#ifndef NOREDUCE",
2718
	"	/* Look for a process with only safe transitions */",
2719
	"	/* (special rules apply in the 2nd dfs) */",
2720
	"	if (boq == -1 && From != To",
2721
	"",
2722
	"#ifdef SAFETY",
2723
	" #if NCORE>1",
2724
	"	&& (depth < z_handoff)", /* not for border states */
2725
	" #endif",
2726
	"	)",
2727
	"#else",
2728
	" #if NCORE>1",
2729
	"	&& ((a_cycles) || (!a_cycles && depth < z_handoff))",
2730
	" #endif",
2731
	" #ifdef BCS",
2732
	"	&& (sched_max > 0 || depth > BASE)", /* no po in initial state if -L0 */
2733
	" #endif",
2734
	"	&&  (!(now._a_t&1)",
2735
	"	    ||	(a_cycles &&",
2736
	" #ifndef BITSTATE",
2737
		"#ifdef MA",
2738
			"#ifdef VERI",
2739
	"		 !((trpt-1)->proviso))",
2740
			"#else",
2741
	"		!(trpt->proviso))",
2742
			"#endif",
2743
		"#else",
2744
			"#ifdef VERI",
2745
	"		 (trpt-1)->ostate &&",
2746
	"		!(((char *)&((trpt-1)->ostate->state))[0] & 128))", /* proviso bit in _a_t */
2747
			"#else",
2748
	"		!(((char *)&(trpt->ostate->state))[0] & 128))",
2749
			"#endif",
2750
		"#endif",
2751
	" #else",
2752
		"#ifdef VERI",
2753
	"		(trpt-1)->ostate &&",
2754
	"		(trpt-1)->ostate->proviso == 0)",
2755
		"#else",
2756
	"		trpt->ostate->proviso == 0)",
2757
		"#endif",
2758
	" #endif",
2759
	"	   ))",
2760
	"#endif", /* SAFETY */
2761
	"	/* attempt Partial Order Reduction as preselect moves */",
2762
	"#ifdef BCS",
2763
	"	if (trpt->sched_limit < sched_max)",	/* po only if we can switch */
2764
	"#endif",
2765
	"	{	for ALL_P",
2766
	"		{",
2767
	"Resume:		/* pick up here if preselect fails */",
2768
	"			this = pptr(II);",
2769
	"			tt = (int) ((P0 *)this)->_p;",
2770
	"			ot = (uchar) ((P0 *)this)->_t;",
2771
	"			if (trans[ot][tt]->atom & 8)",
2772
	"			{	t = trans[ot][tt];",
2773
	"				if (t->qu[0] != 0)",
2774
	"				{	Ccheck++;",
2775
	"					if (!q_cond(II, t))",
2776
	"						continue;",
2777
	"					Cholds++;",
2778
	"				}",
2779
	"SelectIt:			From = To = II; /* preselect process */",
2780
	"#ifdef NIBIS",
2781
	"				t->om = 0;",
2782
	"#endif",
2783
	"				trpt->tau |= 32; /* preselect marker */",
2784
	"#ifdef DEBUG",
2785
	"				printf(\"%%3ld: proc %%d PreSelected (tau=%%d)\\n\", ",
2786
	"					depth, II, trpt->tau);",
2787
	"#endif",
2788
	"				goto Again;",
2789
	"	}	}	}",
2790
	"	trpt->tau &= ~32;",
2791
	"#endif",
2792
	"#if !defined(NOREDUCE) || (defined(ETIM) && !defined(VERI))",
2793
	"Again:",
2794
	"#endif",
2795
	"	trpt->o_pm &= ~(8|16|32|64); /* clear fairness-marks */",
2796
	"#ifndef NOFAIR",
2797
	"	if (fairness && boq == -1",
2798
		"#ifdef VERI",
2799
	"	&& (!(trpt->tau&4) && !((trpt-1)->tau&128))",
2800
		"#endif",
2801
	"	&& !(trpt->tau&8))",
2802
	"	{	/* A_bit = 1; Cnt = N in acc states with A_bit 0 */",
2803
	"		if (!(now._a_t&2))",	/* A-bit not set */
2804
	"		{	if (a_cycles && (trpt->o_pm&2))",
2805
	"			{	/* Accepting state */",
2806
	"				now._a_t |= 2;",
2807
	"				now._cnt[now._a_t&1] = now._nr_pr + 1;",
2808
	"				trpt->o_pm |= 8;",
2809
		"#ifdef DEBUG",
2810
	"	printf(\"%%3ld: fairness Rule 1: cnt=%%d, _a_t=%%d\\n\",",
2811
	"			depth, now._cnt[now._a_t&1], now._a_t);",
2812
		"#endif",
2813
	"			}",
2814
	"		} else",		/* A-bit set */
2815
	"		{	/* A_bit = 0 when Cnt 0 */",
2816
	"			if (now._cnt[now._a_t&1] == 1)",
2817
	"			{	now._a_t &= ~2;",	/* reset a-bit */
2818
	"				now._cnt[now._a_t&1] = 0;",
2819
	"				trpt->o_pm |= 16;",
2820
		"#ifdef DEBUG",
2821
	"	printf(\"%%3ld: fairness Rule 3: _a_t = %%d\\n\",",
2822
	"		depth, now._a_t);",
2823
		"#endif",
2824
	"	}	}	}",
2825
	"#endif",
2826
 
2827
	"#ifdef BCS",	/* bounded context switching */
2828
	"	trpt->bcs = trpt->b_pno = 0;	/* initial */",
2829
	"	if (From != To		/* not a PO or atomic move */",
2830
	"	&&  depth > BASE)	/* there is a prior move */",
2831
	"	{	trpt->b_pno = now._last + BASE;",
2832
	"		trpt->bcs = B_PHASE1;",
2833
	"	#ifdef VERBOSE",
2834
	"		printf(\"%%3ld: BCS phase 1 proc %%d limit %%d\\n\",",
2835
	"			depth, trpt->b_pno, trpt->sched_limit);",
2836
	"	#endif",
2837
	"		/* allow only process b_pno to move in this phase */",
2838
	"	}",
2839
	"c_switch:	/* jumps here with bcs == B_PHASE2 with or wo B_FORCED added */",
2840
	"	#ifdef VERBOSE",
2841
	"		printf(\"%%3ld: BCS c_switch phase=%%d pno=%%d [forced %%d]\\n\",",
2842
	"			depth, trpt->bcs, trpt->b_pno, (trpt->bcs&B_FORCED)?1:0);",
2843
	"	#endif",
2844
	"#endif",
2845
 
2846
	"#ifdef P_RAND",
2847
	"	#ifdef REVERSE",
2848
	"	trpt->p_left = 1 + (To - From);",
2849
	"	#else",
2850
	"	trpt->p_left = 1 + (From - To);",
2851
	"	#endif",
2852
	"	if (trpt->p_left > 1)",
2853
	"	{	trpt->p_skip = rand() %% (trpt->p_left);",
2854
	"	} else",
2855
	"	{	trpt->p_skip = -1;",
2856
	"	}",
2857
	"r_switch:",
2858
	"	#ifdef VERBOSE",
2859
	"		printf(\"%%3ld: P_RAND r_switch p_skip=%%d p_left=%%d\\n\",",
2860
	"			depth, trpt->p_skip, trpt->p_left);",
2861
	"	#endif",
2862
	"#endif",
2863
 
2864
	"	/* Main Expansion Loop over Processes */",
2865
	"	for ALL_P",
2866
	"	{",
2867
	"#ifdef P_RAND",
2868
	"		if (trpt->p_skip >= 0)",
2869
	"		{	trpt->p_skip--; /* skip random nr of procs */",
2870
	"	#ifdef VERBOSE",
2871
	"		printf(\"%%3ld: P_RAND skipping %%d [new p_skip=%%d p_left=%%d]\\n\",",
2872
	"			depth, II, trpt->p_skip, trpt->p_left);",
2873
	"	#endif",
2874
	"			continue;",
2875
	"		}",
2876
	"		if (trpt->p_left == 0)",
2877
	"		{",
2878
	"	#ifdef VERBOSE",
2879
	"		printf(\"%%3ld: P_RAND done at %%d\\n\", depth, II);",
2880
	"	#endif",
2881
	"			break;	/* done */",
2882
	"		}",
2883
	"	#ifdef VERBOSE",
2884
	"		printf(\"%%3ld: P_RAND explore %%d [p_left=%%d]\\n\",",
2885
	"			depth, II, trpt->p_left);",
2886
	"	#endif",
2887
	"		trpt->p_left--;",
2888
	"#endif",
2889
 
2890
	"#if SYNC",
2891
	"		/* no rendezvous with same proc */",
2892
	"		if (boq != -1 && trpt->pr == II) continue;",
2893
	"#endif",
2894
 
2895
	"#ifdef BCS",	/* never claim with II==0 cannot get here */
2896
	"		if ((trpt->bcs & B_PHASE1)",
2897
	"		&&  trpt->b_pno != II)",
2898
	"		{",
2899
	"	#ifdef VERBOSE",
2900
	"		printf(\"%%3ld: BCS NotPre II=%%d bcs=%%d pno=%%d [forced %%d]\\n\",",
2901
	"			depth, II, trpt->bcs, trpt->b_pno, (trpt->bcs&B_FORCED)?1:0);",
2902
	"	#endif",
2903
	"			continue;",	/* avoid context switch */
2904
	"		}",
2905
	"	#ifdef VERBOSE",
2906
	"		else if ((trpt->bcs & B_PHASE1) && trpt->b_pno == II)",
2907
	"		printf(\"%%3ld: BCS IsPre II=%%d bcs=%%d pno=%%d [forced %%d]\\n\",",
2908
	"			depth, II, trpt->bcs, trpt->b_pno, (trpt->bcs&B_FORCED)?1:0);",
2909
	"	#endif",
2910
 
2911
	"		if (trpt->bcs & B_PHASE2)	/* 2nd phase */",
2912
	"		{	if (trpt->b_pno == II)	/* was already done in phase 1 */",
2913
	"			{",
2914
	"	#ifdef VERBOSE",
2915
	"		printf(\"%%3ld: BCS NoRepeat II=%%d bcs=%%d pno=%%d [forced %%d]\\n\",",
2916
	"			depth, II, trpt->bcs, trpt->b_pno, (trpt->bcs&B_FORCED)?1:0);",
2917
	"	#endif",
2918
	"				continue;",
2919
	"			}",
2920
	"			if (!(trpt->bcs & B_FORCED)	/* unless forced */",
2921
	"			&&  trpt->sched_limit >= sched_max)",
2922
	"			{",
2923
	"	#ifdef VERBOSE",
2924
	"		printf(\"%%3ld: BCS Bound II=%%d bcs=%%d pno=%%d [forced %%d]\\n\",",
2925
	"			depth, II, trpt->bcs, trpt->b_pno, (trpt->bcs&B_FORCED)?1:0);",
2926
	"	#endif",
2927
	"				continue;	/* enforce bound */",
2928
	"		}	}",
2929
	"#endif",
2930
 
2931
	"#ifdef VERI",
2932
	"Veri0:",
2933
	"#endif",
2934
	"		this = pptr(II);",
2935
	"		tt = (int) ((P0 *)this)->_p;",
2936
	"		ot = (uchar) ((P0 *)this)->_t;",
2937
 
2938
	"#ifdef NIBIS",
2939
	"		/* don't repeat a previous preselected expansion */",
2940
	"		/* could hit this if reduction proviso was false */",
2941
	"		t = trans[ot][tt];",
2942
	"		if (!(trpt->tau&4)",	/* not claim */
2943
	"		&& !(trpt->tau&1)",	/* not timeout */
2944
	"		&& !(trpt->tau&32)",	/* not preselected */
2945
	"		&& (t->atom & 8)",	/* local */
2946
	"		&& boq == -1",		/* not inside rendezvous */
2947
	"		&& From != To)",	/* not inside atomic seq */
2948
	"		{	if (t->qu[0] == 0",	/* unconditional */
2949
	"			||  q_cond(II, t))",	/* true condition */
2950
	"			{	_m = t->om;",
2951
	"				if (_m>_n||(_n>3&&_m!=0)) _n=_m;",
2952
	"				continue; /* did it before */",
2953
	"		}	}",
2954
	"#endif",
2955
	"		trpt->o_pm &=  ~1; /* no move in this pid yet */",
2956
	"#ifdef EVENT_TRACE",
2957
	"		(trpt+1)->o_event = now._event;",
2958
	"#endif",
2959
	"		/* Fairness: Cnt++ when Cnt == II */",
2960
	"#ifndef NOFAIR",
2961
	"		trpt->o_pm &= ~64; /* didn't apply rule 2 */",
2962
	"		if (fairness",
2963
	"		&& boq == -1",	/* not mid rv - except rcv - NEW 3.0.8 */
2964
	"		&& !(trpt->o_pm&32)",	/* Rule 2 not in effect */
2965
	"		&& (now._a_t&2)",	/* A-bit is set */
2966
	"		&&  now._cnt[now._a_t&1] == II+2)",
2967
	"		{	now._cnt[now._a_t&1] -= 1;",
2968
		"#ifdef VERI",
2969
	"			/* claim need not participate */",
2970
	"			if (II == 1)",
2971
	"				now._cnt[now._a_t&1] = 1;",
2972
		"#endif",
2973
		"#ifdef DEBUG",
2974
	"		printf(\"%%3ld: proc %%d fairness \", depth, II);",
2975
	"		printf(\"Rule 2: --cnt to %%d (%%d)\\n\",",
2976
	"			now._cnt[now._a_t&1], now._a_t);",
2977
		"#endif",
2978
	"			trpt->o_pm |= (32|64);",
2979
	"		}",
2980
	"#endif",
2981
	"#ifdef HAS_PROVIDED",
2982
	"		if (!provided(II, ot, tt, t)) continue;",
2983
	"#endif",
2984
	"		/* check all trans of proc II - escapes first */",
2985
	"#ifdef HAS_UNLESS",
2986
	"		trpt->e_state = 0;",
2987
	"#endif",
2988
	"		(trpt+1)->pr = (uchar) II;",	/* for uerror */
2989
	"		(trpt+1)->st = tt;",
2990
 
2991
	"#ifdef T_RAND",
2992
	"		for (ooi = eoi = 0, t = trans[ot][tt]; t; t = t->nxt, ooi++)",
2993
	"		{	if (strcmp(t->tp, \"else\") == 0",
2994
	"#ifdef HAS_UNLESS",
2995
	"			||  t->e_trans != 0",
2996
	"#endif",
2997
	"			)",
2998
	"			{	eoi++;", /* no break, must count ooi */
2999
	"		}	}",
3000
	"		if (eoi > 0)",
3001
	"		{	t = trans[ot][tt];",
3002
	"	#ifdef VERBOSE",
3003
	"			printf(\"randomizer: suppressed, saw else or escape\\n\");",
3004
	"	#endif",
3005
	"		} else",
3006
	"		{	eoi = rand()%%ooi;",
3007
	"	#ifdef VERBOSE",
3008
	"			printf(\"randomizer: skip %%d in %%d\\n\", eoi, ooi);",
3009
	"	#endif",
3010
	"			for (t = trans[ot][tt]; t; t = t->nxt)",
3011
	"				if (eoi-- <= 0) break;",
3012
	"		}",
3013
	"domore:",
3014
	"		for ( ; t && ooi > 0; t = t->nxt, ooi--)",
3015
	"#else", /* ie dont randomize */
3016
	"		for (t = trans[ot][tt]; t; t = t->nxt)",
3017
	"#endif",
3018
	"		{",
3019
	"#ifdef HAS_UNLESS",
3020
	"			/* exploring all transitions from",
3021
	"			 * a single escape state suffices",
3022
	"			 */",
3023
	"			if (trpt->e_state > 0",
3024
	"			&&  trpt->e_state != t->e_trans)",
3025
	"			{",
3026
		"#ifdef DEBUG",
3027
	"		printf(\"skip 2nd escape %%d (did %%d before)\\n\",",
3028
	"			t->e_trans, trpt->e_state);",
3029
		"#endif",
3030
	"				break;",
3031
	"			}",
3032
	"#endif",
3033
	"	#if defined(TRIX) && !defined(TRIX_ORIG) && !defined(BFS)",
3034
	"			(trpt+1)->p_bup = now._ids_[II];",
3035
	"	#endif",
3036
	"			(trpt+1)->o_t = t;",	/* for uerror */
3037
	"#ifdef INLINE",
3038
	"#include FORWARD_MOVES",
3039
	"P999:			/* jumps here when move succeeds */",
3040
	"#else",
3041
	"			if (!(_m = do_transit(t, II))) continue;",
3042
	"#endif",
3043
	"#ifdef BCS",
3044
	"			if (depth > BASE",	/* has prior move */
3045
	"			&& II >= BASE",		/* not claim */
3046
	"			&& From != To",		/* not atomic or po */
3047
	"	#ifndef BCS_NOFIX",
3048
	"			/* added 5.2.5: prior move was not po */",
3049
	"			&& !((trpt-(BASE+1))->tau & 32)",
3050
	"	#endif",
3051
	"			&& boq == -1",		/* not rv */
3052
	"			&& (trpt->bcs & B_PHASE2)",
3053
	"			&&  trpt->b_pno != II	/* context switch */", /* redundant */
3054
	"			&& !(trpt->bcs & B_FORCED))	/* unless forced */",
3055
	"			{	(trpt+1)->sched_limit = 1 + trpt->sched_limit;",
3056
	"	#ifdef VERBOSE",
3057
	"		printf(\"%%3ld: up sched count to %%d\\n\", depth, (trpt+1)->sched_limit);",
3058
	"	#endif",
3059
	"			} else",
3060
	"			{	(trpt+1)->sched_limit = trpt->sched_limit;",
3061
	"	#ifdef VERBOSE",
3062
	"		printf(\"%%3ld: keep sched count at %%d\\n\", depth, (trpt+1)->sched_limit);",
3063
	"	#endif",
3064
	"			}",
3065
	"#endif",
3066
	"			if (boq == -1)",
3067
		"#ifdef CTL",
3068
	"	/* for branching-time, can accept reduction only if */",
3069
	"	/* the persistent set contains just 1 transition */",
3070
	"			{	if ((trpt->tau&32) && (trpt->o_pm&1))",
3071
	"					trpt->tau |= 16;",	/* CTL */
3072
	"				trpt->o_pm |= 1; /* we moved */",
3073
	"			}",
3074
		"#else",
3075
	"				trpt->o_pm |= 1; /* we moved */",
3076
		"#endif",
3077
 
3078
	"#ifdef LOOPSTATE",
3079
	"			if (loopstate[ot][tt])",
3080
	"			{",
3081
		"#ifdef VERBOSE",
3082
	"				printf(\"exiting from loopstate:\\n\");",
3083
		"#endif",
3084
	"				trpt->tau |= 16;",	/* exiting loopstate */
3085
	"				cnt_loops++;",
3086
	"			}",
3087
	"#endif",
3088
 
3089
	"#ifdef PEG",
3090
	"			peg[t->forw]++;",
3091
	"#endif",
3092
	"#if defined(VERBOSE) || defined(CHECK)",
3093
		"#if defined(SVDUMP)",
3094
	"	cpu_printf(\"%%3ld: proc %%d exec %%d \\n\", depth, II, t->t_id);",
3095
		"#else",
3096
	"	cpu_printf(\"%%3ld: proc %%d exec %%d, %%d to %%d, %%s %%s %%s %%saccepting [tau=%%d]\\n\", ",
3097
	"				depth, II, t->forw, tt, t->st, t->tp,",
3098
	"				(t->atom&2)?\"atomic\":\"\",",
3099
	"				(boq != -1)?\"rendez-vous\":\"\",",
3100
	"				(trpt->o_pm&2)?\"\":\"non-\", trpt->tau);",
3101
		"#ifdef HAS_UNLESS",
3102
	"			if (t->e_trans)",
3103
	"			cpu_printf(\"\\t(escape to state %%d)\\n\", t->st);",
3104
		"#endif",
3105
		"#endif",
3106
		"#ifdef T_RAND",
3107
	"			cpu_printf(\"\\t(randomizer %%d)\\n\", ooi);",
3108
		"#endif",
3109
	"#endif",
3110
 
3111
	"#ifdef HAS_LAST",
3112
	"#ifdef VERI",
3113
	"			if (II != 0)",
3114
	"#endif",
3115
	"				now._last = II - BASE;",
3116
	"#endif",
3117
	"#ifdef HAS_UNLESS",
3118
	"			trpt->e_state = t->e_trans;",
3119
	"#endif",
3120
 
3121
	"			depth++; trpt++;",
3122
	"			trpt->pr = (uchar) II;",
3123
	"			trpt->st = tt;",
3124
	"			trpt->o_pm &= ~(2|4);",
3125
	"			if (t->st > 0)",
3126
	"			{	((P0 *)this)->_p = t->st;",
3127
	"/*	moved down		reached[ot][t->st] = 1; */",
3128
	"			}",
3129
	"#ifndef SAFETY",
3130
	"			if (a_cycles)",
3131
	"			{",
3132
		"#if (ACCEPT_LAB>0 && !defined(NP)) || (PROG_LAB>0 && defined(HAS_NP))",
3133
	"				int ii;",
3134
		"#endif",
3135
		"#define P__Q	((P0 *)pptr(ii))",
3136
		"#if ACCEPT_LAB>0",
3137
			"#ifdef NP",
3138
	"				/* state 1 of np_ claim is accepting */",
3139
	"				if (((P0 *)pptr(0))->_p == 1)",
3140
	"					trpt->o_pm |= 2;",
3141
			"#else",
3142
	"				for (ii = 0; ii < (int) now._nr_pr; ii++)",
3143
	"				{ if (accpstate[P__Q->_t][P__Q->_p])",
3144
	"				  {	trpt->o_pm |= 2;",
3145
	"					break;",
3146
	"			   	} }",
3147
			"#endif",
3148
		"#endif",
3149
		"#if defined(HAS_NP) && PROG_LAB>0",
3150
	"				for (ii = 0; ii < (int) now._nr_pr; ii++)",
3151
	"				{ if (progstate[P__Q->_t][P__Q->_p])",
3152
	"				  {	trpt->o_pm |= 4;",
3153
	"					break;",
3154
	"			   	} }",
3155
		"#endif",
3156
		"#undef P__Q",
3157
	"			}",
3158
	"#endif",
3159
	"			trpt->o_t  =  t; trpt->o_n  = _n;",
3160
	"			trpt->o_ot = ot; trpt->o_tt = tt;",
3161
	"			trpt->o_To = To; trpt->o_m  = _m;",
3162
	"			trpt->tau = 0;",
3163
 
3164
	"#ifdef T_RAND",
3165
	"			trpt->oo_i = ooi;",
3166
	"#endif",
3167
	"			if (boq != -1 || (t->atom&2))",
3168
	"			{	trpt->tau |= 8;",
3169
	"#ifdef VERI",
3170
	"				/* atomic sequence in claim */",
3171
	"				if((trpt-1)->tau&4)",
3172
	"					trpt->tau |= 4;",
3173
	"				else",
3174
	"					trpt->tau &= ~4;",
3175
	"			} else",
3176
	"			{	if ((trpt-1)->tau&4)",
3177
	"					trpt->tau &= ~4;",
3178
	"				else",
3179
	"					trpt->tau |= 4;",
3180
	"			}",
3181
	"			/* if claim allowed timeout, so */",
3182
	"			/* does the next program-step: */",
3183
	"			if (((trpt-1)->tau&1) && !(trpt->tau&4))",
3184
	"				trpt->tau |= 1;",
3185
	"#else",
3186
	"			} else",
3187
	"				trpt->tau &= ~8;",
3188
	"#endif",
3189
	"			if (boq == -1 && (t->atom&2))",
3190
	"			{	From = To = II; nlinks++;",
3191
	"			} else",
3192
	"			{	From = FROM_P; To = UPTO_P;",
3193
	"			}",
3194
	"#if NCORE>1 && defined(FULL_TRAIL)",
3195
	"			if (upto > 0)",
3196
	"			{	Push_Stack_Tree(II, t->t_id);",
3197
	"			}",
3198
	"#endif",
3199
	"#ifdef TRIX",
3200
	"			if (processes[II])", /* last move could have been a delproc */
3201
	"			{	processes[II]->modified = 1; /* transition in II */",
3202
	"	#ifdef V_TRIX",
3203
	"				printf(\"%%4d: process %%d modified\\n\", depth, II);",
3204
	"			} else",
3205
	"			{	printf(\"%%4d: process %%d modified but gone (%%p)\\n\",",
3206
	"					depth, II, trpt);",
3207
	"	#endif",
3208
	"			}",
3209
	"#endif",
3210
	"			goto Down;	/* pseudo-recursion */",
3211
	"Up:",
3212
	"#ifdef TRIX",
3213
	"	#ifndef TRIX_ORIG",
3214
	"		#ifndef BFS",
3215
	"			now._ids_[trpt->pr] = trpt->p_bup;",
3216
	"		#endif",
3217
	"	#else",
3218
	"			if (processes[trpt->pr])",
3219
	"			{",
3220
	"				processes[trpt->pr]->modified = 1; /* reverse move */",
3221
	"		#ifdef V_TRIX",
3222
	"				printf(\"%%4d: unmodify pr %%d (%%p)\\n\",",
3223
	"					depth, trpt->pr, trpt);",
3224
	"			} else",
3225
	"			{	printf(\"%%4d: unmodify pr %%d (gone) (%%p)\\n\",",
3226
	"					depth, trpt->pr, trpt);",
3227
	"		#endif",
3228
	"			}",
3229
	"	#endif",
3230
	"#endif",
3231
	"#ifdef CHECK",
3232
	"			cpu_printf(\"%%d: Up - %%s\\n\", depth,",
3233
	"				(trpt->tau&4)?\"claim\":\"program\");",
3234
	"#endif",
3235
	"#if NCORE>1",
3236
	"			iam_alive();",
3237
	"	#ifdef USE_DISK",
3238
	"			mem_drain();",
3239
	"	#endif",
3240
	"#endif",
3241
	"#if defined(MA) || NCORE>1",
3242
	"			if (depth <= 0) return;",
3243
	"			/* e.g., if first state is old, after a restart */",
3244
	"#endif",
3245
 
3246
	"#ifdef SC",
3247
	"			if (CNT1 > CNT2",
3248
	"			&& depth < hiwater - (HHH-DDD) - 2)",	/* 5.1.6: was + 2 */
3249
	"			{",
3250
	" 				trpt += DDD;",
3251
	"				disk2stack();",
3252
	"				maxdepth -= DDD;",
3253
	"				hiwater -= DDD;",
3254
	"				if(verbose)",
3255
	"				printf(\"unzap %%d: %%d\\n\", CNT2, hiwater);",
3256
	"			}",
3257
	"#endif",
3258
 
3259
	"#ifndef SAFETY",	/* moved earlier in version 5.2.5 */
3260
	"			if ((now._a_t&1) && depth <= A_depth)",
3261
	"				return;	/* to checkcycles() */",
3262
	"#endif",
3263
 
3264
	"#ifndef NOFAIR",
3265
	"			if (trpt->o_pm&128)	/* fairness alg */",
3266
	"			{	now._cnt[now._a_t&1] = trpt->bup.oval;",
3267
	"				_n = 1; trpt->o_pm &= ~128;",
3268
	"				depth--; trpt--;",
3269
		"#if defined(VERBOSE) || defined(CHECK)",
3270
	"	printf(\"%%3ld: reversed fairness default move\\n\", depth);",
3271
		"#endif",
3272
	"				goto Q999;",
3273
	"			}",
3274
	"#endif",
3275
 
3276
	"#ifdef HAS_LAST",
3277
	"#ifdef VERI",
3278
	"			{ int d; Trail *trl;",
3279
	"			  now._last = 0;",
3280
	"			  for (d = 1; d < depth; d++)",
3281
	"			  {	trl = getframe(depth-d); /* was (trpt-d) */",
3282
	"				if (trl->pr != 0)",
3283
	"				{ now._last = trl->pr - BASE;",
3284
	"				  break;",
3285
	"			} }	}",
3286
	"#else",
3287
	"			now._last = (depth<1)?0:(trpt-1)->pr;",
3288
	"#endif",
3289
	"#endif",
3290
	"#ifdef EVENT_TRACE",
3291
	"			now._event = trpt->o_event;",
3292
	"#endif",
3293
	"			t  = trpt->o_t;  _n = trpt->o_n;",
3294
	"			ot = trpt->o_ot; II = trpt->pr;",
3295
	"			tt = trpt->o_tt; this = Pptr(II);",
3296
	"			To = trpt->o_To; _m  = trpt->o_m;",
3297
	"#ifdef T_RAND",
3298
	"			ooi = trpt->oo_i;",
3299
	"#endif",
3300
	"#ifdef INLINE_REV",
3301
	"			_m = do_reverse(t, II, _m);",
3302
	"#else",
3303
	"#include REVERSE_MOVES",
3304
	"R999:			/* jumps here when done */",
3305
	"#endif",
3306
 
3307
	"#ifdef VERBOSE",
3308
	"			cpu_printf(\"%%3ld: proc %%d reverses %%d, %%d to %%d\\n\",",
3309
	"				depth, II, t->forw, tt, t->st);",
3310
	"			cpu_printf(\"\\t%%s [abit=%%d,adepth=%%d,tau=%%d,%%d]\\n\", ",
3311
	"				t->tp, now._a_t, A_depth, trpt->tau, (trpt-1)->tau);",
3312
	"#endif",
3313
	"#ifndef NOREDUCE",
3314
	"			/* pass the proviso tags */",
3315
	"			if ((trpt->tau&8)	/* rv or atomic */",
3316
	"			&&  (trpt->tau&16))",
3317
	"				(trpt-1)->tau |= 16;",	/* pass upward */
3318
	"	#ifdef SAFETY",
3319
	"			if ((trpt->tau&8)	/* rv or atomic */",
3320
	"			&&  (trpt->tau&64))",
3321
	"				(trpt-1)->tau |= 64;",
3322
	"	#endif",
3323
	"#endif",
3324
 
3325
	"#if defined(BCS) && (defined(NOREDUCE) || !defined(SAFETY))",
3326
	/* for BCS, cover cases where 64 is otherwise not handled */
3327
	"			if ((trpt->tau&8)",
3328
	"			&&  (trpt->tau&64))",
3329
	"				(trpt-1)->tau |= 64;",
3330
	"#endif",
3331
 
3332
	"			depth--; trpt--;",
3333
	"",
3334
	"#ifdef NSUCC",
3335
	"			trpt->n_succ++;",
3336
	"#endif",
3337
	"#ifdef NIBIS",
3338
	"			(trans[ot][tt])->om = _m; /* head of list */",
3339
	"#endif",
3340
 
3341
	"			/* i.e., not set if rv fails */",
3342
	"			if (_m)",
3343
	"			{	reached[ot][t->st] = 1;",
3344
	"				reached[ot][tt] = 1;",
3345
	"			}",
3346
	"#ifdef HAS_UNLESS",
3347
	"			else trpt->e_state = 0; /* undo */",
3348
	"#endif",
3349
 
3350
	"			if (_m>_n||(_n>3&&_m!=0)) _n=_m;",
3351
	"			((P0 *)this)->_p = tt;",
3352
	"		} /* all options */",
3353
 
3354
	"#ifdef T_RAND",
3355
	"		if (!t && ooi > 0)",	/* means we skipped some initial options */
3356
	"		{	t = trans[ot][tt];",
3357
	"	#ifdef VERBOSE",
3358
	"			printf(\"randomizer: continue for %%d more\\n\", ooi);",
3359
	"	#endif",
3360
	"			goto domore;",
3361
	"		}",
3362
	"	#ifdef VERBOSE",
3363
	"		  else",
3364
	"			printf(\"randomizer: done\\n\");",
3365
	"	#endif",
3366
	"#endif",
3367
 
3368
	"#ifndef NOFAIR",
3369
	"		/* Fairness: undo Rule 2 */",
3370
	"		if ((trpt->o_pm&32)",/* rule 2 was applied */
3371
	"		&&  (trpt->o_pm&64))",/* by this process II */
3372
	"		{	if (trpt->o_pm&1)",/* it didn't block */
3373
	"			{",
3374
		"#ifdef VERI",
3375
	"				if (now._cnt[now._a_t&1] == 1)",
3376
	"					now._cnt[now._a_t&1] = 2;",
3377
		"#endif",
3378
	"				now._cnt[now._a_t&1] += 1;",
3379
		"#ifdef VERBOSE",
3380
	"		printf(\"%%3ld: proc %%d fairness \", depth, II);",
3381
	"		printf(\"undo Rule 2, cnt=%%d, _a_t=%%d\\n\",",
3382
	"			now._cnt[now._a_t&1], now._a_t);",
3383
		"#endif",
3384
	"				trpt->o_pm &= ~(32|64);",
3385
	"			} else",	/* process blocked  */
3386
	"			{	if (_n > 0)", /* a prev proc didn't */
3387
	"				{",	/* start over */
3388
	"					trpt->o_pm &= ~64;",
3389
	"					II = INI_P;", /* after loop incr II == From */
3390
	"		}	}	}",
3391
	"#endif",
3392
 
3393
	"#ifdef VERI",
3394
	"		if (II == 0) break;	/* never claim */",
3395
	"#endif",
3396
	"	} /* all processes */",
3397
 
3398
	"#ifdef NSUCC",
3399
	"	tally_succ(trpt->n_succ);",
3400
	"#endif",
3401
 
3402
	"#ifdef P_RAND",
3403
	"	if (trpt->p_left > 0)",
3404
	"	{	trpt->p_skip = -1; /* probably rendundant */",
3405
	"	#ifdef VERBOSE",
3406
	"		printf(\"%%3ld: P_RAND -- explore remainder\\n\", depth);",
3407
	"	#endif",
3408
	"		goto r_switch; /* explore the remaining procs */",
3409
	"	} else",
3410
	"	{",
3411
	"	#ifdef VERBOSE",
3412
	"		printf(\"%%3ld: P_RAND -- none left\\n\", depth);",
3413
	"	#endif",
3414
	"	}",
3415
	"#endif",
3416
 
3417
	"#ifdef BCS",
3418
	"	if (trpt->bcs & B_PHASE1)",
3419
	"	{	trpt->bcs = B_PHASE2;	/* start 2nd phase */",
3420
	"		if (_n == 0 || !(trpt->tau&64))	/* pre-move unexecutable or led to stackstate */",
3421
	"		{	trpt->bcs |= B_FORCED; /* forced switch */",
3422
	"		}",
3423
	"	#ifdef VERBOSE",
3424
	"		printf(\"%%3ld: BCS move to phase 2, _n=%%d %%s\\n\", depth, _n,",
3425
	"			(trpt->bcs & B_FORCED)?\"forced\":\"free\");",
3426
	"	#endif",
3427
	"		From = FROM_P; To = UPTO_P;",
3428
	"		goto c_switch;",
3429
	"	}",
3430
	"",
3431
	"	if (_n == 0	/* no process could move */",
3432
	"	&&  II >= BASE	/* not the never claim */",
3433
	"	&&  trpt->sched_limit >= sched_max)",
3434
	"	{	_n = 1;",
3435
	"	#ifdef VERBOSE",
3436
	"		printf(\"%%3ld: BCS not a deadlock\\n\", depth);",
3437
	"	#endif",
3438
	"	}",
3439
	"#endif",
3440
 
3441
	"#ifndef NOFAIR",
3442
	"	/* Fairness: undo Rule 2 */",
3443
	"	if (trpt->o_pm&32)	/* remains if proc blocked */",
3444
	"	{",
3445
		"#ifdef VERI",
3446
	"		if (now._cnt[now._a_t&1] == 1)",
3447
	"			now._cnt[now._a_t&1] = 2;",
3448
		"#endif",
3449
	"		now._cnt[now._a_t&1] += 1;",
3450
		"#ifdef VERBOSE",
3451
	"		printf(\"%%3ld: proc -- fairness \", depth);",
3452
	"		printf(\"undo Rule 2, cnt=%%d, _a_t=%%d\\n\",",
3453
	"			now._cnt[now._a_t&1], now._a_t);",
3454
		"#endif",
3455
	"		trpt->o_pm &= ~32;",
3456
	"	}",
3457
	"#ifndef NP",
3458
	/* 12/97 non-progress cycles cannot be created
3459
	 * by stuttering extension, here or elsewhere
3460
	 */
3461
	"	if (fairness",
3462
	"	&&  _n == 0		/* nobody moved */",
3463
		"#ifdef VERI",
3464
		"	&& !(trpt->tau&4)	/* in program move */",
3465
		"#endif",
3466
	"	&& !(trpt->tau&8)	/* not an atomic one */",
3467
		"#ifdef OTIM",
3468
		"	&& ((trpt->tau&1) || endstate())",
3469
		"#else",
3470
			"#ifdef ETIM",
3471
			"	&&  (trpt->tau&1)	/* already tried timeout */",
3472
			"#endif",
3473
		"#endif",
3474
		"#ifndef NOREDUCE",
3475
		"	/* see below  */",
3476
		"	&& !((trpt->tau&32) && (_n == 0 || (trpt->tau&16)))",
3477
		"#endif",
3478
	"	&& now._cnt[now._a_t&1] > 0)	/* needed more procs */",
3479
	"	{	depth++; trpt++;",
3480
	"		trpt->o_pm |= 128 | ((trpt-1)->o_pm&(2|4));",
3481
	"		trpt->bup.oval = now._cnt[now._a_t&1];",
3482
	"		now._cnt[now._a_t&1] = 1;",
3483
		"#ifdef VERI",
3484
	"		trpt->tau = 4;",
3485
		"#else",
3486
	"		trpt->tau = 0;",
3487
		"#endif",
3488
	"		From = FROM_P; To = UPTO_P;",
3489
		"#if defined(VERBOSE) || defined(CHECK)",
3490
	"		printf(\"%%3ld: fairness default move \", depth);",
3491
	"		printf(\"(all procs block)\\n\");",
3492
		"#endif",
3493
	"		goto Down;",
3494
	"	}",
3495
	"#endif",
3496
	"Q999:	/* returns here with _n>0 when done */;",
3497
 
3498
	"	if (trpt->o_pm&8)",
3499
	"	{	now._a_t &= ~2;",
3500
	"		now._cnt[now._a_t&1] = 0;",
3501
	"		trpt->o_pm &= ~8;",
3502
		"#ifdef VERBOSE",
3503
	"		printf(\"%%3ld: fairness undo Rule 1, _a_t=%%d\\n\",",
3504
	"			depth, now._a_t);",
3505
		"#endif",
3506
	"	}",
3507
	"	if (trpt->o_pm&16)",
3508
	"	{	now._a_t |= 2;",		/* restore a-bit */
3509
	"		now._cnt[now._a_t&1] = 1;",	/* NEW: restore cnt */
3510
	"		trpt->o_pm &= ~16;",
3511
		"#ifdef VERBOSE",
3512
	"		printf(\"%%3ld: fairness undo Rule 3, _a_t=%%d\\n\",",
3513
	"			depth, now._a_t);",
3514
		"#endif",
3515
	"	}",
3516
	"#endif",
3517
 
3518
	"#ifndef NOREDUCE",
3519
"#ifdef SAFETY",
3520
	"	#ifdef LOOPSTATE",
3521
	"	/* at least one move that was preselected at this */",
3522
	"	/* level, blocked or was a loop control flow point */",
3523
	"	if ((trpt->tau&32) && (_n == 0 || (trpt->tau&16)))",
3524
	"	#else",
3525
	"	/* preselected move - no successors outside stack */",
3526
	"	if ((trpt->tau&32) && !(trpt->tau&64))",
3527
	"	#endif",
3528
	"	{	From = FROM_P; To = UPTO_P;",
3529
	"	#ifdef DEBUG",
3530
	"		printf(\"%%3ld: proc %%d UnSelected (_n=%%d, tau=%%d)\\n\", ",
3531
	"			depth, II+1, _n, trpt->tau);",
3532
	"	#endif",
3533
	"		_n = 0; trpt->tau &= ~(16|32|64);",
3534
 
3535
	"		if (MORE_P)	/* II already decremented */",
3536
	"			goto Resume;",
3537
	"		else",
3538
	"			goto Again;",
3539
	"	}",
3540
"#else",
3541
	"	/* at least one move that was preselected at this */",
3542
	"	/* level, blocked or truncated at the next level  */",
3543
	"	if ((trpt->tau&32) && (_n == 0 || (trpt->tau&16)))",
3544
	"	{",
3545
	"	#ifdef DEBUG",
3546
	"		printf(\"%%3ld: proc %%d UnSelected (_n=%%d, tau=%%d)\\n\", ",
3547
	"		depth, II+1, (int) _n, trpt->tau);",
3548
	"	#endif",
3549
	"		if (a_cycles && (trpt->tau&16))",
3550
	"		{	if (!(now._a_t&1))",
3551
	"			{",
3552
	"	#ifdef DEBUG",
3553
	"			printf(\"%%3ld: setting proviso bit\\n\", depth);",
3554
	"	#endif",
3555
	"#ifndef BITSTATE",
3556
		"#ifdef MA",
3557
			"#ifdef VERI",
3558
	"			(trpt-1)->proviso = 1;",
3559
			"#else",
3560
	"			trpt->proviso = 1;",
3561
			"#endif",
3562
		"#else",
3563
			"#ifdef VERI",
3564
	"			if ((trpt-1)->ostate)",
3565
	"			((char *)&((trpt-1)->ostate->state))[0] |= 128;",
3566
			"#else",
3567
	"			((char *)&(trpt->ostate->state))[0] |= 128;",
3568
			"#endif",
3569
		"#endif",
3570
	"#else",
3571
		"#ifdef VERI",
3572
	"			if ((trpt-1)->ostate)",
3573
	"			(trpt-1)->ostate->proviso = 1;",
3574
		"#else",
3575
	"			trpt->ostate->proviso = 1;",
3576
		"#endif",
3577
	"#endif",
3578
	"				From = FROM_P; To = UPTO_P;",
3579
	"				_n = 0; trpt->tau &= ~(16|32|64);",
3580
	"				goto Again; /* do full search */",
3581
	"			} /* else accept reduction */",
3582
	"		} else",
3583
	"		{	From = FROM_P; To = UPTO_P;",
3584
	"			_n = 0; trpt->tau &= ~(16|32|64);",
3585
	"			if (MORE_P)	/* II already decremented */",
3586
	"				goto Resume;",
3587
	"			else",
3588
	"				goto Again;",
3589
	"	}	}",
3590
"#endif",
3591
	"#endif",
3592
 
3593
	"	if (_n == 0 || ((trpt->tau&4) && (trpt->tau&2)))",
3594
	"	{",
3595
		"#ifdef DEBUG",
3596
	"		cpu_printf(\"%%3ld: no move [II=%%d, tau=%%d, boq=%%d]\\n\",",
3597
	"			depth, II, trpt->tau, boq);",
3598
		"#endif",
3599
	"#if SYNC",
3600
	"		/* ok if a rendez-vous fails: */",
3601
	"		if (boq != -1) goto Done;",
3602
	"#endif",
3603
	"		/* ok if no procs or we're at maxdepth */",
3604
	"		if ((now._nr_pr == 0 && (!strict || qs_empty()))",
3605
	"#ifdef OTIM",
3606
	"		||  endstate()",
3607
	"#endif",
3608
	"		||  depth >= maxdepth-1) goto Done;	/* undo change from 5.2.3 */",
3609
 
3610
	"		if ((trpt->tau&8) && !(trpt->tau&4))",
3611
	"		{	trpt->tau &= ~(1|8);",
3612
	"			/* 1=timeout, 8=atomic */",
3613
	"			From = FROM_P; To = UPTO_P;",
3614
		"#ifdef DEBUG",
3615
	"		cpu_printf(\"%%3ld: atomic step proc %%d unexecutable\\n\", depth, II+1);",
3616
		"#endif",
3617
	"#ifdef VERI",
3618
	"			trpt->tau |= 4;	/* switch to claim */",
3619
	"#endif",
3620
	"			goto AllOver;",
3621
	"		}",
3622
 
3623
	"#ifdef ETIM",
3624
	"		if (!(trpt->tau&1)) /* didn't try timeout yet */",
3625
	"		{",
3626
	"#ifdef VERI",
3627
	"			if (trpt->tau&4)",
3628
	"			{",
3629
		"#ifndef NTIM",
3630
	"				if (trpt->tau&2) /* requested */",
3631
		"#endif",
3632
	"				{	trpt->tau |=  1;",
3633
	"					trpt->tau &= ~2;",
3634
				"#ifdef DEBUG",
3635
	"				cpu_printf(\"%%d: timeout\\n\", depth);",
3636
				"#endif",
3637
	"					goto Stutter;",
3638
	"			}	}",
3639
	"			else",
3640
	"			{	/* only claim can enable timeout */",
3641
	"				if ((trpt->tau&8)",
3642
	"				&&  !((trpt-1)->tau&4))",
3643
	"/* blocks inside an atomic */		goto BreakOut;",
3644
				"#ifdef DEBUG",
3645
	"				cpu_printf(\"%%d: req timeout\\n\",",
3646
	"					depth);",
3647
				"#endif",
3648
	"				(trpt-1)->tau |= 2; /* request */",
3649
	"#if NCORE>1 && defined(FULL_TRAIL)",
3650
	"				if (upto > 0)",
3651
	"				{	Pop_Stack_Tree();",
3652
	"				}",
3653
	"#endif",
3654
	"				goto Up;",
3655
	"			}",
3656
	"#else",
3657
 
3658
				"#ifdef DEBUG",
3659
	"			cpu_printf(\"%%d: timeout\\n\", depth);",
3660
				"#endif",
3661
	"			trpt->tau |=  1;",
3662
	"			goto Again;",
3663
	"#endif",
3664
	"		}",
3665
	"#endif",
3666
 
3667
	/* old location of atomic block code */
3668
	"#ifdef VERI",
3669
	"BreakOut:",
3670
		"#ifndef NOSTUTTER",
3671
	"		if (!(trpt->tau&4))",
3672
	"		{	trpt->tau |= 4;   /* claim stuttering */",
3673
	"			trpt->tau |= 128; /* stutter mark */",
3674
				"#ifdef DEBUG",
3675
	"			cpu_printf(\"%%d: claim stutter\\n\", depth);",
3676
				"#endif",
3677
	"			goto Stutter;",
3678
	"		}",
3679
		"#else",
3680
	"		;",
3681
		"#endif",
3682
	"#else",
3683
	"		if (!noends && !a_cycles && !endstate())",
3684
	"		{	depth--; trpt--;	/* new 4.2.3 */",
3685
	"			uerror(\"invalid end state\");",
3686
	"			depth++; trpt++;",
3687
	"		}",
3688
		"#ifndef NOSTUTTER",
3689
	"		else if (a_cycles && (trpt->o_pm&2)) /* new 4.2.4 */",
3690
	"		{	depth--; trpt--;",
3691
	"			uerror(\"accept stutter\");",
3692
	"			depth++; trpt++;",
3693
	"		}",
3694
		"#endif",
3695
	"#endif",
3696
	"	}",
3697
	"Done:",
3698
	"	if (!(trpt->tau&8))	/* not in atomic seqs */",
3699
	"	{",
3700
 
3701
"#ifndef MA",
3702
	"#if defined(FULLSTACK) || defined(CNTRSTACK)",
3703
	"#ifdef VERI",
3704
	"		if (boq == -1",
3705
	"		&&  (((trpt->tau&4) && !(trpt->tau&128))",
3706
	"		||  ( (trpt-1)->tau&128)))",
3707
	"#else",
3708
	"		if (boq == -1)",
3709
	"#endif",
3710
	"		{",
3711
		"#ifdef DEBUG2",
3712
		"#if defined(FULLSTACK)",
3713
	"			printf(\"%%d: zapping %%u (%%d)\\n\",",
3714
	"				depth, trpt->ostate,",
3715
	"			(trpt->ostate)?trpt->ostate->tagged:0);",
3716
		"#endif",
3717
		"#endif",
3718
	"			onstack_zap();",
3719
	"		}",
3720
	"#endif",
3721
"#else",
3722
	"#ifdef VERI",
3723
	"		if (boq == -1",
3724
	"		&&  (((trpt->tau&4) && !(trpt->tau&128))",
3725
	"		||  ( (trpt-1)->tau&128)))",
3726
	"#else",
3727
	"		if (boq == -1)",
3728
	"#endif",
3729
	"		{",
3730
		"#ifdef DEBUG",
3731
	"			printf(\"%%d: zapping\\n\", depth);",
3732
		"#endif",
3733
	"			onstack_zap();",
3734
		"#ifndef NOREDUCE",
3735
	"			if (trpt->proviso)",
3736
	"			gstore((char *) &now, vsize, 1);",
3737
		"#endif",
3738
	"		}",
3739
"#endif",
3740
 
3741
	"#ifndef SAFETY",
3742
	"		if (_n != 0",		/* we made a move */
3743
		"#ifdef VERI",
3744
	"		/* --after-- a program-step, i.e., */",
3745
	"		/* after backtracking a claim-step */",
3746
	"		&& (trpt->tau&4)",
3747
	"		/* with at least one running process */",
3748
	"		/* unless in a stuttered accept state */",
3749
	"		&& ((now._nr_pr > 1) || (trpt->o_pm&2))",
3750
		"#endif",
3751
	"		&& !(now._a_t&1))",	/* not in 2nd DFS */
3752
	"		{",
3753
		"#ifndef NOFAIR",
3754
	"			if (fairness)",	/* implies a_cycles */
3755
	"			{",
3756
			"#ifdef VERBOSE",
3757
	"			cpu_printf(\"Consider check %%d %%d...\\n\",",
3758
	"				now._a_t, now._cnt[0]);",
3759
			"#endif",
3760
#if 0
3761
		the a-bit is set, which means that the fairness
3762
		counter is running -- it was started in an accepting state.
3763
		we check that the counter reached 1, which means that all
3764
		processes moved least once.
3765
		this means we can start the search for cycles -
3766
		to be able to return to this state, we should be able to
3767
		run down the counter to 1 again -- which implies a visit to
3768
		the accepting state -- even though the Seed state for this
3769
		search is itself not necessarily accepting
3770
#endif
3771
	"				if ((now._a_t&2) /* A-bit */",
3772
	"				&&  (now._cnt[0] == 1))",
3773
	"					checkcycles();",
3774
	"			} else",
3775
		"#endif",
3776
	"			if (a_cycles && (trpt->o_pm&2))",
3777
	"				checkcycles();",
3778
	"		}",
3779
	"#endif",
3780
	"	}",
3781
	"	if (depth > 0)",
3782
	"	{",
3783
	"#if NCORE>1 && defined(FULL_TRAIL)",
3784
	"		if (upto > 0)",
3785
	"		{	Pop_Stack_Tree();",
3786
	"		}",
3787
	"#endif",
3788
	"		goto Up;",
3789
	"	}",
3790
	"}\n",
3791
	"#else",
3792
	"void new_state(void) { /* place holder */ }",
3793
	"#endif",	/* BFS */
3794
	"",
3795
	"void",
3796
	"spin_assert(int a, char *s, int ii, int tt, Trans *t)",
3797
	"{",
3798
	"	if (!a && !noasserts)",
3799
	"	{	char bad[1024];",
3800
	"		strcpy(bad, \"assertion violated \");",
3801
	"		if (strlen(s) > 1000)",
3802
	"		{	strncpy(&bad[19], (const char *) s, 1000);",
3803
	"			bad[1019] = '\\0';",
3804
	"		} else",
3805
	"			strcpy(&bad[19], s);",
3806
	"		uerror(bad);",
3807
	"	}",
3808
	"}",
3809
	"#ifndef NOBOUNDCHECK",
3810
	"int",
3811
	"Boundcheck(int x, int y, int a1, int a2, Trans *a3)",
3812
	"{",
3813
	"	spin_assert((x >= 0 && x < y), \"- invalid array index\",",
3814
	"		a1, a2, a3);",
3815
	"	return x;",
3816
	"}",
3817
	"#endif",
3818
	"void",
3819
	"wrap_stats(void)",
3820
	"{",
3821
	"	if (nShadow>0)",
3822
	"	  printf(\"%%9.8g states, stored (%%g visited)\\n\",",
3823
	"			nstates - nShadow, nstates);",
3824
	"	else",
3825
	"	  printf(\"%%9.8g states, stored\\n\", nstates);",
3826
	"#ifdef BFS",
3827
	"#if SYNC",
3828
	"	printf(\"	%%8g nominal states (- rv and atomic)\\n\", nstates-midrv-nlinks+revrv);",
3829
	"	printf(\"	%%8g rvs succeeded\\n\", midrv-failedrv);",
3830
	"#else",
3831
	"	printf(\"	%%8g nominal states (stored-atomic)\\n\", nstates-nlinks);",
3832
	"#endif",
3833
	"#ifdef DEBUG",
3834
	"	printf(\"	%%8g midrv\\n\", midrv);",
3835
	"	printf(\"	%%8g failedrv\\n\", failedrv);",
3836
	"	printf(\"	%%8g revrv\\n\", revrv);",
3837
	"#endif",
3838
	"#endif",
3839
	"	printf(\"%%9.8g states, matched\\n\", truncs);",
3840
	"#ifdef CHECK",
3841
	"	printf(\"%%9.8g matches within stack\\n\",truncs2);",
3842
	"#endif",
3843
	"	if (nShadow>0)",
3844
	"	printf(\"%%9.8g transitions (= visited+matched)\\n\",",
3845
	"		nstates+truncs);",
3846
	"	else",
3847
	"	printf(\"%%9.8g transitions (= stored+matched)\\n\",",
3848
	"		nstates+truncs);",
3849
	"	printf(\"%%9.8g atomic steps\\n\", nlinks);",
3850
	"	if (nlost) printf(\"%%g lost messages\\n\", (double) nlost);",
3851
	"",
3852
	"#ifndef BITSTATE",
3853
	"	#ifndef MA",
3854
	"	printf(\"hash conflicts: %%9.8g (resolved)\\n\", hcmp);",
3855
	"	#ifndef AUTO_RESIZE",
3856
	"	if (hcmp > (double) (1<<ssize))",
3857
	"	{	printf(\"hint: increase hashtable-size (-w) to reduce runtime\\n\");",
3858
	"	}	/* in multi-core: also reduces lock delays on access to hashtable */",
3859
	"	#endif",
3860
	"	#endif",
3861
	"#else",
3862
		"#ifdef CHECK",
3863
		"	printf(\"%%8g states allocated for dfs stack\\n\", ngrabs);",
3864
		"#endif",
3865
	"	if (udmem)",
3866
	"	printf(\"\\nhash factor: %%4g (best if > 100.)\\n\\n\",",
3867
	"		(double)(((double) udmem) * 8.0) / (double) nstates);",
3868
	"	else",
3869
	"	printf(\"\\nhash factor: %%4g (best if > 100.)\\n\\n\",",
3870
	"		(double)(1<<(ssize-8)) / (double) nstates * 256.0);",
3871
	"       printf(\"bits set per state: %%u (-k%%u)\\n\", hfns, hfns);",
3872
	"  #if 0",
3873
	"	if (udmem)",
3874
	"	{	printf(\"total bits available: %%8g (-M%%ld)\\n\",",
3875
	"		((double) udmem) * 8.0, udmem/(1024L*1024L));",
3876
	"	} else",
3877
	"	{	printf(\"total bits available: %%8g (-w%%d)\\n\",",
3878
	"			((double) (ONE_L << (ssize-4)) * 16.0), ssize);",
3879
	"	}",
3880
	"  #endif",
3881
	"#endif",
3882
	"#ifdef BFS_DISK",
3883
	"	printf(\"bfs disk reads: %%ld writes %%ld -- diff %%ld\\n\",",
3884
	"		bfs_dsk_reads, bfs_dsk_writes, bfs_dsk_writes-bfs_dsk_reads);",
3885
	"	if (bfs_dsk_read  >= 0) (void) close(bfs_dsk_read);",
3886
	"	if (bfs_dsk_write >= 0) (void) close(bfs_dsk_write);",
3887
	"	(void) unlink(\"pan_bfs_dsk.tmp\");",
3888
	"#endif",
3889
	"}",
3890
	"",
3891
	"void",
3892
	"wrapup(void)",
3893
	"{	double nr1, nr2, nr3 = 0.0, nr4, nr5 = 0.0;",
3894
	"#if !defined(MA) && (defined(MEMCNT) || defined(MEMLIM))",
3895
	"	int mverbose = 1;",
3896
	"#else",
3897
	"	int mverbose = verbose;",
3898
	"#endif",
3899
	"#if NCORE>1",
3900
	"	if (verbose) cpu_printf(\"wrapup -- %%d error(s)\\n\", errors);",
3901
	"	if (core_id != 0)",
3902
	"	{",
3903
	"#ifdef USE_DISK",
3904
	"		void	dsk_stats(void);",
3905
	"		dsk_stats();",
3906
	"#endif",
3907
	"		if (search_terminated != NULL)",
3908
	"		{	*search_terminated |= 2;	/* wrapup */",
3909
	"		}",
3910
	"		exit(0); /* normal termination, not an error */",
3911
	"	}",
3912
	"#endif",
3913
	"#if !defined(WIN32) && !defined(WIN64)",
3914
	"	signal(SIGINT, SIG_DFL);",
3915
	"#endif",
3916
	"	printf(\"\\n(%%s)\\n\", SpinVersion);",
3917
	"	if (!done) printf(\"Warning: Search not completed\\n\");",
3918
	"#ifdef SC",
3919
	"	(void) unlink((const char *)stackfile);",
3920
	"#endif",
3921
	"#if NCORE>1",
3922
	"	if (a_cycles)",
3923
	"	{	printf(\"	+ Multi-Core (NCORE=%%d)\\n\", NCORE);",
3924
	"	} else",
3925
	"	{	printf(\"	+ Multi-Core (NCORE=%%d -z%%ld)\\n\", NCORE, z_handoff);",
3926
	"	}",
3927
	"#endif",
3928
	"#ifdef BFS",
3929
	"	printf(\"	+ Using Breadth-First Search\\n\");",
3930
	"#endif",
3931
	"#ifndef NOREDUCE",
3932
	"	printf(\"	+ Partial Order Reduction\\n\");",
3933
	"#endif",
3934
	"#ifdef REVERSE",
3935
	"	printf(\"	+ Reverse Depth-First Search Order\\n\");",
3936
	"#endif",
3937
	"#ifdef T_REVERSE",
3938
	"	printf(\"	+ Reverse Transition Ordering\\n\");",
3939
	"#endif",
3940
	"#ifdef T_RAND",
3941
	"	printf(\"	+ Randomized Transition Ordering\\n\");",
3942
	"#endif",
3943
	"#ifdef P_RAND",
3944
	"	printf(\"	+ Randomized Process Ordering\\n\");",
3945
	"#endif",
3946
	"#ifdef BCS",
3947
	"	printf(\"	+ Scheduling Restriction (-L%%d)\\n\", sched_max);",
3948
	"#endif",
3949
	"#ifdef TRIX",
3950
	"	printf(\"	+ Tree Index Compression\\n\");",
3951
	"#endif",
3952
	"#ifdef COLLAPSE",
3953
	"	printf(\"	+ Compression\\n\");",
3954
	"#endif",
3955
	"#ifdef MA",
3956
	"	printf(\"	+ Graph Encoding (-DMA=%%d)\\n\", MA);",
3957
	"  #ifdef R_XPT",
3958
	"	printf(\"	  Restarted from checkpoint %%s.xpt\\n\", PanSource);",
3959
	"  #endif",
3960
	"#endif",
3961
	"#ifdef CHECK",
3962
	"  #ifdef FULLSTACK",
3963
	"	printf(\"	+ FullStack Matching\\n\");",
3964
	"  #endif",
3965
	"  #ifdef CNTRSTACK",
3966
	"	printf(\"	+ CntrStack Matching\\n\");",
3967
	"  #endif",
3968
	"#endif",
3969
	"#ifdef BITSTATE",
3970
	"	printf(\"\\nBit statespace search for:\\n\");",
3971
	"#else",
3972
	"  #ifdef HC",
3973
	"	printf(\"\\nHash-Compact %%d search for:\\n\", HC);",
3974
	"  #else",
3975
	"	printf(\"\\nFull statespace search for:\\n\");",
3976
	"  #endif",
3977
	"#endif",
3978
	"#ifdef EVENT_TRACE",
3979
	"#ifdef NEGATED_TRACE",
3980
	"	printf(\"\tnotrace assertion  \t+\\n\");",
3981
	"#else",
3982
	"	printf(\"\ttrace assertion    \t+\\n\");",
3983
	"#endif",
3984
	"#endif",
3985
	"#ifdef VERI",
3986
	"	printf(\"\tnever claim         \t+\");",
3987
	"	printf(\" (%%s)\\n\", procname[((Pclaim *)pptr(0))->_t]);",
3988
	"	printf(\"\tassertion violations\t\");",
3989
	"	if (noasserts)",
3990
	"		printf(\"- (disabled by -A flag)\\n\");",
3991
	"	else",
3992
	"		printf(\"+ (if within scope of claim)\\n\");",
3993
	"#else",
3994
		"#ifdef NOCLAIM",
3995
	"	printf(\"\tnever claim         \t- (not selected)\\n\");",
3996
		"#else",
3997
	"	printf(\"\tnever claim         \t- (none specified)\\n\");",
3998
		"#endif",
3999
	"	printf(\"\tassertion violations\t\");",
4000
	"	if (noasserts)",
4001
	"		printf(\"- (disabled by -A flag)\\n\");",
4002
	"	else",
4003
	"		printf(\"+\\n\");",
4004
	"#endif",
4005
	"#ifndef SAFETY",
4006
		"#ifdef NP",
4007
	"	printf(\"\tnon-progress cycles \t\");",
4008
		"#else",
4009
	"	printf(\"\tacceptance   cycles \t\");",
4010
		"#endif",
4011
	"	if (a_cycles)",
4012
	"		printf(\"+ (fairness %%sabled)\\n\",",
4013
	"			fairness?\"en\":\"dis\");",
4014
	"	else printf(\"- (not selected)\\n\");",
4015
	"#else",
4016
	"	printf(\"\tcycle checks       \t- (disabled by -DSAFETY)\\n\");",
4017
	"#endif",
4018
	"#ifdef VERI",
4019
	"	printf(\"\tinvalid end states\t- \");",
4020
	"	printf(\"(disabled by \");",
4021
	"	if (noends)",
4022
	"		printf(\"-E flag)\\n\\n\");",
4023
	"	else",
4024
	"		printf(\"never claim)\\n\\n\");",
4025
	"#else",
4026
	"	printf(\"\tinvalid end states\t\");",
4027
	"	if (noends)",
4028
	"		printf(\"- (disabled by -E flag)\\n\\n\");",
4029
	"	else",
4030
	"		printf(\"+\\n\\n\");",
4031
	"#endif",
4032
	"	printf(\"State-vector %%d byte, depth reached %%ld\", hmax,",
4033
	"#if NCORE>1",
4034
	"					(nr_handoffs * z_handoff) +",
4035
	"#endif",
4036
	"					mreached);",
4037
	"	printf(\", errors: %%d\\n\", errors);",
4038
	"	fflush(stdout);",
4039
	"#ifdef MA",
4040
	"	if (done)",
4041
	"	{	extern void dfa_stats(void);",
4042
	"		if (maxgs+a_cycles+2 < MA)",
4043
	"		printf(\"MA stats: -DMA=%%d is sufficient\\n\",",
4044
	"			maxgs+a_cycles+2);",
4045
	"		dfa_stats();",
4046
	"	}",
4047
	"#endif",
4048
	"	wrap_stats();",
4049
	"#ifdef CHECK",
4050
	"	printf(\"stackframes: %%d/%%d\\n\\n\", smax, svmax);",
4051
	"	printf(\"stats: fa %%ld, fh %%ld, zh %%ld, zn %%ld - \",",
4052
	"		Fa, Fh, Zh, Zn);",
4053
	"	printf(\"check %%ld holds %%ld\\n\", Ccheck, Cholds);",
4054
	"	printf(\"stack stats: puts %%ld, probes %%ld, zaps %%ld\\n\",",
4055
	"		PUT, PROBE, ZAPS);",
4056
	"#else",
4057
	"	printf(\"\\n\");",
4058
	"#endif",
4059
	"",
4060
	"#if !defined(BITSTATE) && defined(NOCOMP)",
4061
	"	if (!verbose) { goto jump_here; }",	/* added 5.2.0 */
4062
	"#endif",
4063
	"",
4064
	"#if 1",	/* omitted 5.2.0:  defined(BITSTATE) || !defined(NOCOMP) */
4065
	"	nr1 = (nstates-nShadow)*",
4066
	"	      (double)(hmax+sizeof(struct H_el)-sizeof(unsigned));",
4067
	"	#ifdef BFS",
4068
	"	nr2 = 0.0;",
4069
	"	#else",
4070
	"	nr2 = (double) ((maxdepth+3)*sizeof(Trail));",
4071
	"	#endif",
4072
 
4073
	"	#ifndef BITSTATE",
4074
			"#if !defined(MA) || defined(COLLAPSE)",
4075
	"	nr3 = (double) (ONE_L<<ssize)*sizeof(struct H_el *);",
4076
			"#endif",
4077
	"	#else",
4078
	"	if (udmem)",
4079
	"		nr3 = (double) (udmem);",
4080
	"	else",
4081
	"		nr3 = (double) (ONE_L<<(ssize-3));",
4082
			"#ifdef CNTRSTACK",
4083
	"	nr5 = (double) (ONE_L<<(ssize-3));",
4084
			"#endif",
4085
			"#ifdef FULLSTACK",
4086
	"	nr5 = (double) (maxdepth*sizeof(struct H_el *));",
4087
			"#endif",
4088
	"	#endif",
4089
 
4090
	"	nr4 = (double) (svmax * (sizeof(Svtack) + hmax))",
4091
	"	    + (double) (smax  * (sizeof(_Stack) + Maxbody * sizeof(char)));",
4092
		"#ifndef MA",
4093
	"	if (1 /* mverbose || memcnt < nr1+nr2+nr3+nr4+nr5 */)",
4094
		"#endif",
4095
	"	{ double remainder = memcnt;",
4096
	"	  double tmp_nr = memcnt-nr3-nr4-(nr2-fragment)-nr5;",
4097
	"",
4098
	"	#if NCORE>1 && !defined(SEP_STATE)",
4099
	"		tmp_nr -= ((double) NCORE * LWQ_SIZE) + GWQ_SIZE;",
4100
	"	#endif",
4101
	"		if (tmp_nr < 0.0) tmp_nr = 0.;",
4102
	"		printf(\"Stats on memory usage (in Megabytes):\\n\");",
4103
	"		printf(\"%%9.3f\tequivalent memory usage for states\",",
4104
	"			nr1/1048576.); /* 1024*1024=1048576 */",
4105
	"		printf(\" (stored*(State-vector + overhead))\\n\");",
4106
	"	#if NCORE>1 && !defined(WIN32) && !defined(WIN64)",
4107
	"		printf(\"%%9.3f\tshared memory reserved for state storage\\n\",",
4108
	"			mem_reserved/1048576.);",
4109
	"		#ifdef SEP_HEAP",
4110
	"		printf(\"\t\tin %%d local heaps of %%7.3f MB each\\n\",",
4111
	"			NCORE, mem_reserved/(NCORE*1048576.));",
4112
	"		#endif",
4113
	"		printf(\"\\n\");",
4114
	"	#endif",
4115
		"#ifdef BITSTATE",
4116
	"		if (udmem)",
4117
	"			printf(\"%%9.3f\tmemory used for hash array (-M%%ld)\\n\",",
4118
	"			nr3/1048576., udmem/(1024L*1024L));",
4119
	"		else",
4120
	"			printf(\"%%9.3f\tmemory used for hash array (-w%%d)\\n\",",
4121
	"			nr3/1048576., ssize);",
4122
	"		if (nr5 > 0.0)",
4123
	"		printf(\"%%9.3f\tmemory used for bit stack\\n\",",
4124
	"			nr5/1048576.);",
4125
	"		remainder = remainder - nr3 - nr5;",
4126
		"#else",
4127
	"		printf(\"%%9.3f\tactual memory usage for states\",",
4128
	"			tmp_nr/1048576.);",
4129
	"		remainder -= tmp_nr;",
4130
	"		printf(\" (\");",
4131
	"		if (tmp_nr > 0.)",
4132
	"		{	if (tmp_nr > nr1) printf(\"unsuccessful \");",
4133
	"			printf(\"compression: %%.2f%%%%)\\n\",",
4134
	"				(100.0*tmp_nr)/nr1);",
4135
	"		} else",
4136
	"			printf(\"less than 1k)\\n\");",
4137
			"#ifndef MA",
4138
	"		if (tmp_nr > 0.)",
4139
	"		{	printf(\"         \tstate-vector as stored = %%.0f byte\",",
4140
	"			(tmp_nr)/(nstates-nShadow) -",
4141
	"			(double) (sizeof(struct H_el) - sizeof(unsigned)));",
4142
	"			printf(\" + %%ld byte overhead\\n\",",
4143
	"			(long int) sizeof(struct H_el)-sizeof(unsigned));",
4144
	"		}",
4145
			"#endif",
4146
			"#if !defined(MA) || defined(COLLAPSE)",
4147
	"		printf(\"%%9.3f\tmemory used for hash table (-w%%d)\\n\",",
4148
	"			nr3/1048576., ssize);",
4149
	"		remainder -= nr3;",
4150
			"#endif",
4151
		"#endif",
4152
	"	#ifndef BFS",
4153
	"		printf(\"%%9.3f\tmemory used for DFS stack (-m%%ld)\\n\",",
4154
	"			nr2/1048576., maxdepth);",
4155
	"		remainder -= nr2;",
4156
	"	#endif",
4157
		"#if NCORE>1",
4158
	"		remainder -= ((double) NCORE * LWQ_SIZE) + GWQ_SIZE;",
4159
	"		printf(\"%%9.3f\tshared memory used for work-queues\\n\",",
4160
	"			(GWQ_SIZE + (double) NCORE * LWQ_SIZE) /1048576.);",
4161
	"		printf(\"\t\tin %%d queues of %%7.3f MB each\",",
4162
	"			NCORE, (double) LWQ_SIZE /1048576.);",
4163
	"		#ifndef NGQ",
4164
	"		printf(\" + a global q of %%7.3f MB\\n\",",
4165
	"			(double) GWQ_SIZE / 1048576.);",
4166
	"		#else",
4167
	"		printf(\"\\n\");",
4168
	"		#endif",
4169
	"	#endif",
4170
	"		if (remainder - fragment > 1048576.)",
4171
	"		printf(\"%%9.3f\tother (proc and chan stacks)\\n\",",
4172
	"			(remainder-fragment)/1048576.);",
4173
	"		if (fragment > 1048576.)",
4174
	"		printf(\"%%9.3f\tmemory lost to fragmentation\\n\",",
4175
	"			fragment/1048576.);",
4176
	"		printf(\"%%9.3f\ttotal actual memory usage\\n\\n\",",
4177
	"			memcnt/1048576.);",
4178
	"	}",
4179
	"	#ifndef MA",
4180
	"	else",
4181
	"	#endif",
4182
	"#endif",
4183
 
4184
	"#if !defined(BITSTATE) && defined(NOCOMP)",
4185
	"jump_here:",
4186
	"#endif",
4187
 
4188
		"#ifndef MA",
4189
	"		printf(\"%%9.3f\tmemory usage (Mbyte)\\n\\n\",",
4190
	"			memcnt/1048576.);",
4191
		"#endif",
4192
	"#ifdef COLLAPSE",
4193
	"	printf(\"nr of templates: [ globals chans procs ]\\n\");",
4194
	"	printf(\"collapse counts: [ \");",
4195
	"	{ int i; for (i = 0; i < 256+2; i++)",
4196
	"		if (ncomps[i] != 0)",
4197
	"			printf(\"%%d \", (int) ncomps[i]);",
4198
	"		printf(\"]\\n\");",
4199
	"	}",
4200
	"#endif",
4201
	"	#ifdef TRIX",
4202
	"	if (mverbose)",
4203
	"	{	int i;",
4204
	"		printf(\"TRIX counts:\\n\");",
4205
	"		printf(\"  processes: \");",
4206
	"		for (i = 0; i < MAXPROC; i++)",
4207
	"			if (_p_count[i] != 0)",
4208
	"			{	printf(\"%%3d:%%ld \",",
4209
	"					i, _p_count[i]);",
4210
	"			}",
4211
	"		printf(\"\\n  channels : \");",
4212
	"		for (i = 0; i < MAXQ; i++)",
4213
	"			if (_c_count[i] != 0)",
4214
	"			{	printf(\"%%3d:%%ld \",",
4215
	"					i, _c_count[i]);",
4216
	"			}",
4217
	"		printf(\"\\n\\n\");",
4218
	"	}",
4219
	"	#endif",
4220
 
4221
	"	if ((done || verbose) && !no_rck) do_reach();",
4222
	"#ifdef PEG",
4223
	"	{ int i;",
4224
	"	  printf(\"\\nPeg Counts (transitions executed):\\n\");",
4225
	"	  for (i = 1; i < NTRANS; i++)",
4226
	"	  {	if (peg[i]) putpeg(i, peg[i]);",
4227
	"	} }",
4228
	"#endif",
4229
	"#ifdef VAR_RANGES",
4230
	"	dumpranges();",
4231
	"#endif",
4232
	"#ifdef SVDUMP",
4233
	"	if (vprefix > 0) close(svfd);",
4234
	"#endif",
4235
	"#ifdef LOOPSTATE",
4236
	"	printf(\"%%g loopstates hit\\n\", cnt_loops);",
4237
	"#endif",
4238
	"#ifdef NSUCC",
4239
	"	dump_succ();",
4240
	"#endif",
4241
	"#if NCORE>1 && defined(T_ALERT)",
4242
	"	crash_report();",
4243
	"#endif",
4244
	"	pan_exit(0);",
4245
	"}\n",
4246
	"void",
4247
	"stopped(int arg)",
4248
	"{	printf(\"Interrupted\\n\");",
4249
	"#if NCORE>1",
4250
	"	was_interrupted = 1;",
4251
	"#endif",
4252
	"	wrapup();",
4253
	"	pan_exit(0);",
4254
	"}",
4255
	"",
4256
	"#ifdef SFH",
4257
	"/*",
4258
	" * super fast hash, based on Paul Hsieh's function",
4259
	" * http://www.azillionmonkeys.com/qed/hash.html",
4260
	" */",
4261
	"#include <stdint.h>",	/* for uint32_t etc */
4262
	"	#undef get16bits",
4263
	"	#if (defined(__GNUC__) && defined(__i386__)) || defined(__WATCOMC__) \\",
4264
	"	|| defined(_MSC_VER) || defined (__BORLANDC__) || defined (__TURBOC__)",
4265
	"		#define get16bits(d) (*((const uint16_t *) (d)))",
4266
	"	#endif",
4267
	"",
4268
	"	#ifndef get16bits",
4269
	"		#define get16bits(d) ((((uint32_t)(((const uint8_t *)(d))[1])) << 8)\\",
4270
	"                       +(uint32_t)(((const uint8_t *)(d))[0]) )",
4271
	"	#endif",
4272
	"",
4273
	"void",
4274
	"d_sfh(const char *s, int len)",
4275
	"{	uint32_t h = len, tmp;",
4276
	"	int rem;",
4277
	"",
4278
	"	rem = len & 3;",
4279
	"	len >>= 2;",
4280
	"",
4281
	"	for ( ; len > 0; len--)",
4282
	"	{	h  += get16bits(s);",
4283
	"        	tmp = (get16bits(s+2) << 11) ^ h;",
4284
	"        	h   = (h << 16) ^ tmp;",
4285
	"        	s  += 2*sizeof(uint16_t);",
4286
	"		h  += h >> 11;",
4287
	"	}",
4288
	"	switch (rem) {",
4289
	"	case 3: h += get16bits(s);",
4290
	"		h ^= h << 16;",
4291
	"		h ^= s[sizeof(uint16_t)] << 18;",
4292
	"		h += h >> 11;",
4293
	"		break;",
4294
	"	case 2: h += get16bits(s);",
4295
	"		h ^= h << 11;",
4296
	"		h += h >> 17;",
4297
	"		break;",
4298
	"	case 1: h += *s;",
4299
	"		h ^= h << 10;",
4300
	"		h += h >> 1;",
4301
	"		break;",
4302
	"	}",
4303
	"	h ^= h << 3;",
4304
	"	h += h >> 5;",
4305
	"	h ^= h << 4;",
4306
	"	h += h >> 17;",
4307
	"	h ^= h << 25;",
4308
	"	h += h >> 6;",
4309
	"",
4310
	"	K1 = h;",
4311
	"}",
4312
	"#endif", /* SFH */
4313
	"",
4314
	"#include <stdint.h>", /* uint32_t etc. */
4315
	"#if defined(HASH64) || defined(WIN64)",
4316
	"/* 64-bit Jenkins hash, 1997",
4317
	" * http://burtleburtle.net/bob/c/lookup8.c",
4318
	" */",
4319
	"#define mix(a,b,c) \\",
4320
	"{ a -= b; a -= c; a ^= (c>>43); \\",
4321
	"  b -= c; b -= a; b ^= (a<<9);  \\",
4322
	"  c -= a; c -= b; c ^= (b>>8);  \\",
4323
	"  a -= b; a -= c; a ^= (c>>38); \\",
4324
	"  b -= c; b -= a; b ^= (a<<23); \\",
4325
	"  c -= a; c -= b; c ^= (b>>5);  \\",
4326
	"  a -= b; a -= c; a ^= (c>>35); \\",
4327
	"  b -= c; b -= a; b ^= (a<<49); \\",
4328
	"  c -= a; c -= b; c ^= (b>>11); \\",
4329
	"  a -= b; a -= c; a ^= (c>>12); \\",
4330
	"  b -= c; b -= a; b ^= (a<<18); \\",
4331
	"  c -= a; c -= b; c ^= (b>>22); \\",
4332
	"}",
4333
	"#else",
4334
	"/* 32-bit Jenkins hash, 2006",
4335
	" * http://burtleburtle.net/bob/c/lookup3.c",
4336
	" */",
4337
	"#define rot(x,k)	(((x)<<(k))|((x)>>(32-(k))))",
4338
	"",
4339
	"#define mix(a,b,c) \\",
4340
	"{ a -= c;  a ^= rot(c, 4);  c += b; \\",
4341
	"  b -= a;  b ^= rot(a, 6);  a += c; \\",
4342
	"  c -= b;  c ^= rot(b, 8);  b += a; \\",
4343
	"  a -= c;  a ^= rot(c,16);  c += b; \\",
4344
	"  b -= a;  b ^= rot(a,19);  a += c; \\",
4345
	"  c -= b;  c ^= rot(b, 4);  b += a; \\",
4346
	"}",
4347
	"",
4348
	"#define final(a,b,c) \\",
4349
	"{ c ^= b; c -= rot(b,14); \\",
4350
	"  a ^= c; a -= rot(c,11); \\",
4351
	"  b ^= a; b -= rot(a,25); \\",
4352
	"  c ^= b; c -= rot(b,16); \\",
4353
	"  a ^= c; a -= rot(c,4);  \\",
4354
	"  b ^= a; b -= rot(a,14); \\",
4355
	"  c ^= b; c -= rot(b,24); \\",
4356
	"}",
4357
	"#endif",
4358
	"",
4359
	"void",
4360
	"d_hash(uchar *kb, int nbytes)",
4361
	"{	uint8_t  *bp;",
4362
	"#if defined(HASH64) || defined(WIN64)",
4363
	"	uint64_t a = 0, b, c, n;",
4364
	"	uint64_t *k = (uint64_t *) kb;",
4365
	"#else",
4366
	"	uint32_t a = 0, b, c, n;",
4367
	"	uint32_t *k = (uint32_t *) kb;",
4368
	"#endif",
4369
	"	n = nbytes/WS;	/* nr of words */",
4370
	"	/* extend to multiple of words, if needed */",
4371
	"	a = WS - (nbytes %% WS);",
4372
	"	if (a > 0 && a < WS)",
4373
	"	{	n++;",
4374
	"		bp = kb + nbytes;",
4375
	"		switch (a) {",
4376
	"#if defined(HASH64) || defined(WIN64)",
4377
	"		case 7: *bp++ = 0; /* fall thru */",
4378
	"		case 6: *bp++ = 0; /* fall thru */",
4379
	"		case 5: *bp++ = 0; /* fall thru */",
4380
	"		case 4: *bp++ = 0; /* fall thru */",
4381
	"#endif",
4382
	"		case 3: *bp++ = 0; /* fall thru */",
4383
	"		case 2: *bp++ = 0; /* fall thru */",
4384
	"		case 1: *bp   = 0;",
4385
	"		case 0: break;",
4386
	"	}	}",
4387
	"#if defined(HASH64) || defined(WIN64)",
4388
	"	b = HASH_CONST[HASH_NR];",
4389
	"	c = 0x9e3779b97f4a7c13LL; /* arbitrary value */",
4390
	"	while (n >= 3)",
4391
	"	{	a += k[0];",
4392
	"		b += k[1];",
4393
	"		c += k[2];",
4394
	"		mix(a,b,c);",
4395
	"		n -= 3;",
4396
	"		k += 3;",
4397
	"	}",
4398
	"	c += (((uint64_t) nbytes)<<3);",
4399
	"	switch (n) {",
4400
	"	case 2: b += k[1];",
4401
	"	case 1: a += k[0];",
4402
	"	case 0: break;",
4403
	"	}",
4404
	"	mix(a,b,c);",
4405
	"#else", /* 32 bit version: */
4406
	"	a = c = 0xdeadbeef + (n<<2);",
4407
	"	b = HASH_CONST[HASH_NR];",
4408
	"	while (n > 3)",
4409
	"	{	a += k[0];",
4410
	"		b += k[1];",
4411
	"		c += k[2];",
4412
	"		mix(a,b,c);",
4413
	"		n -= 3;",
4414
	"		k += 3;",
4415
	"	}",
4416
	"	switch (n) { ",
4417
	"	case 3: c += k[2];",
4418
	"	case 2: b += k[1];",
4419
	"	case 1: a += k[0];",
4420
	"		final(a,b,c);",
4421
	"	case 0: break;",
4422
	"	}",
4423
	"#endif",
4424
	"	j1_spin = c&nmask; j3 = a&7; /* 1st bit */",
4425
	"	j2 = b&nmask; j4 = (a>>3)&7; /* 2nd bit */",
4426
	"	K1 = c; K2 = b;",
4427
	"}",
4428
	"",
4429
	"void",
4430
	"s_hash(uchar *cp, int om)",
4431
	"{",
4432
	"#if defined(SFH)",
4433
	"	d_sfh((const char *) cp, om); /* sets K1 */",
4434
	"#else",
4435
	"	d_hash(cp, om);	/* sets K1 etc */",
4436
	"#endif",
4437
	"#ifdef BITSTATE",
4438
	"	if (S_Tab == H_tab)",	/* state stack in bitstate search */
4439
	"		j1_spin = K1 %% omaxdepth;",
4440
	"	else",
4441
	"#endif", /* if (S_Tab != H_Tab) */
4442
	"		if (ssize < 8*WS)",
4443
	"			j1_spin = K1&mask;",
4444
	"		else",
4445
	"			j1_spin = K1;",
4446
	"}",
4447
	"#ifndef RANDSTOR",
4448
	"int *prerand;",
4449
	"void",
4450
	"inirand(void)",
4451
	"{	int i;",
4452
	"	srand(123);	/* fixed startpoint */",
4453
	"	prerand = (int *) emalloc((omaxdepth+3)*sizeof(int));",
4454
	"	for (i = 0; i < omaxdepth+3; i++)",
4455
	"		prerand[i] = rand();",
4456
	"}",
4457
	"int",
4458
	"pan_rand(void)",
4459
	"{	if (!prerand) inirand();",
4460
	"	return prerand[depth];",
4461
	"}",
4462
	"#endif",
4463
	"",
4464
	"void",
4465
	"set_masks(void)	/* 4.2.5 */",
4466
	"{",
4467
	"	if (WS == 4 && ssize >= 32)",
4468
	"	{	mask = 0xffffffff;",
4469
	"#ifdef BITSTATE",
4470
	"		switch (ssize) {",
4471
	"		case 34: nmask = (mask>>1); break;",
4472
	"		case 33: nmask = (mask>>2); break;",
4473
	"		default: nmask = (mask>>3); break;",
4474
	"		}",
4475
	"#else",
4476
	"		nmask = mask;",
4477
	"#endif",
4478
	"	} else if (WS == 8)",
4479
	"	{	mask = ((ONE_L<<ssize)-1);	/* hash init */",
4480
	"#ifdef BITSTATE",
4481
	"		nmask = mask>>3;",
4482
	"#else",
4483
	"		nmask = mask;",
4484
	"#endif",
4485
	"	} else if (WS != 4)",
4486
	"	{	fprintf(stderr, \"pan: wordsize %%ld not supported\\n\", (long int) WS);",
4487
	"		exit(1);",
4488
	"	} else	/* WS == 4 and ssize < 32 */",
4489
	"	{	mask = ((ONE_L<<ssize)-1);	/* hash init */",
4490
	"		nmask = (mask>>3);",
4491
	"	}",
4492
	"}",
4493
	"",
4494
	"static long reclaim_size;",
4495
	"static char *reclaim_mem;",
4496
	"#if defined(AUTO_RESIZE) && !defined(BITSTATE) && !defined(MA)",
4497
	"#if NCORE>1",
4498
	"	#error cannot combine AUTO_RESIZE with NCORE>1 yet",
4499
	"#endif",
4500
	"static struct H_el **N_tab;",
4501
	"void",
4502
	"reverse_capture(struct H_el *p)",
4503
	"{	if (!p) return;",
4504
	"	reverse_capture(p->nxt);",
4505
	"	/* last element of list moves first */",
4506
	"	/* to preserve list-order */",
4507
	"	j2 = p->m_K1;",
4508
	"	if (ssize < 8*WS) /* probably always true */",
4509
	"	{	j2 &= mask;",
4510
	"	}",
4511
	"	p->nxt = N_tab[j2];",
4512
	"	N_tab[j2] = p;",
4513
	"}",
4514
	"void",
4515
	"resize_hashtable(void)",
4516
	"{",
4517
	"	if (WS == 4 && ssize >= 27 - 1)",
4518
	"	{	return;	/* cannot increase further */",
4519
	"	}",
4520
	"",
4521
	"	ssize += 2; /* 4x size @htable ssize */",
4522
	"",
4523
	"	printf(\"pan: resizing hashtable to -w%%d.. \", ssize);",
4524
	"",
4525
	"	N_tab = (struct H_el **)",
4526
	"		emalloc((ONE_L<<ssize)*sizeof(struct H_el *));",
4527
	"",
4528
	"	set_masks();	/* they changed */",
4529
	"",
4530
	"	for (j1_spin = 0; j1_spin < (ONE_L << (ssize - 2)); j1_spin++)",
4531
	"	{	reverse_capture(H_tab[j1_spin]);",
4532
	"	}",
4533
	"	reclaim_mem = (char *) H_tab;",
4534
	"	reclaim_size = (ONE_L << (ssize - 2));",
4535
	"	H_tab = N_tab;",
4536
	"",
4537
	"	printf(\" done\\n\");",
4538
	"}",
4539
	"#endif",
4540
	"#if defined(ZAPH) && defined(BITSTATE)",
4541
	"void",
4542
	"zap_hashtable(void)",
4543
	"{	cpu_printf(\"pan: resetting hashtable\\n\");",
4544
	"	if (udmem)",
4545
	"	{	memset(SS, 0, udmem);",
4546
	"	} else",
4547
	"	{	memset(SS, 0, ONE_L<<(ssize-3));",
4548
	"	}",
4549
	"}",
4550
	"#endif",
4551
	"",
4552
	"#if NCLAIMS>1",
4553
	"int",
4554
	"find_claim(char *s)",
4555
	"{	int i, j;",
4556
	"	for (i = 0; procname[i] != \":np_:\"; i++)",
4557
	"	{	if (strcmp(s, procname[i]) == 0)",
4558
	"		{	for (j = 0; j < NCLAIMS; j++)",
4559
	"			{	if (spin_c_typ[j] == i)",
4560
	"				{	return j;",
4561
	"			}	}",
4562
	"			break;",
4563
	"	}	}",
4564
	"	printf(\"pan: error: cannot find claim '%%s'\\n\", s);",
4565
	"	exit(1);",
4566
	"	return -1; /* unreachable */",
4567
	"}",
4568
	"#endif",
4569
	"",
4570
	"int",
4571
	"main(int argc, char *argv[])",
4572
	"{	void to_compile(void);\n",
4573
	"	efd = stderr;	/* default */",
4574
	"",
4575
	"	if (G_long != sizeof(long)",
4576
	"	||  G_int  != sizeof(int))",
4577
	"	{	printf(\"spin: error, the version of spin \");",
4578
	"		printf(\"that generated this pan.c assumed a different \");",
4579
	"		printf(\"wordsize (%%d iso %%d)\\n\", G_long, (int) sizeof(long));",
4580
	"		exit(1);",
4581
	"	}",
4582
	"",
4583
	"#if defined(T_RAND) && (T_RAND>0)",
4584
	"	s_rand = T_RAND;", /* so that -RS can override */
4585
	"#elif defined(P_RAND) && (P_RAND>0)",
4586
	"	s_rand = P_RAND;",
4587
	"#endif", /* else, could use time as seed... */
4588
	"",
4589
	"#ifdef PUTPID",
4590
	"	{	char *ptr = strrchr(argv[0], '/');",
4591
	"		if (ptr == NULL)",
4592
	"		{	ptr = argv[0];",
4593
	"		} else",
4594
	"		{	ptr++;",
4595
	"		}",
4596
	"		progname = emalloc(strlen(ptr));",
4597
	"		strcpy(progname, ptr);",
4598
	"		/* printf(\"progname: %%s\\n\", progname); */",
4599
	"	}",
4600
	"#endif",
4601
	"",
4602
	"#ifdef BITSTATE",
4603
	"	bstore = bstore_reg; /* default */",
4604
	"#endif",
4605
	"#if NCORE>1",
4606
	"	{	int i, j;",
4607
	"		strcpy(o_cmdline, \"\");",
4608
	"		for (j = 1; j < argc; j++)",
4609
	"		{	strcat(o_cmdline, argv[j]);",
4610
	"			strcat(o_cmdline, \" \");",
4611
	"		}",
4612
	"		/* printf(\"Command Line: %%s\\n\", o_cmdline); */",
4613
	"		if (strlen(o_cmdline) >= sizeof(o_cmdline))",
4614
	"		{	Uerror(\"option list too long\");",
4615
	"	}	}",
4616
	"#endif",
4617
	"	while (argc > 1 && argv[1][0] == '-')",
4618
	"	{	switch (argv[1][1]) {",
4619
	"#ifndef SAFETY",
4620
		"#ifdef NP",
4621
	"		case 'a': fprintf(efd, \"error: -a disabled\");",
4622
	"			  usage(efd); break;",
4623
		"#else",
4624
	"		case 'a': a_cycles = 1; break;",
4625
		"#endif",
4626
	"#endif",
4627
	"		case 'A': noasserts = 1; break;",
4628
	"		case 'b': bounded = 1; break;",
4629
	"#ifdef HAS_CODE",
4630
	"		case 'C': coltrace = 1; goto samething;",
4631
	"#endif",
4632
	"		case 'c': upto  = atoi(&argv[1][2]); break;",
4633
	"		case 'D': dodot++; state_tables++; break;",
4634
	"		case 'd': state_tables++; break;",
4635
	"		case 'e': every_error = 1; upto = 0; Nr_Trails = 1; break;",
4636
	"		case 'E': noends = 1; break;",
4637
	"#ifdef SC",
4638
	"		case 'F': if (strlen(argv[1]) > 2)",
4639
	"				stackfile = &argv[1][2];",
4640
	"			  break;",
4641
	"#endif",
4642
	"#if !defined(SAFETY) && !defined(NOFAIR)",
4643
	"		case 'f': fairness = 1; break;",
4644
	"#endif",
4645
	"#ifdef HAS_CODE",
4646
	"		case 'g': gui = 1; goto samething;",
4647
	"#endif",
4648
	"		case 'h': if (!argv[1][2]) usage(efd); else",
4649
	"			  HASH_NR = atoi(&argv[1][2])%%100; break;",
4650
	"		case 'I': iterative = 2; every_error = 1; break;",
4651
	"		case 'i': iterative = 1; every_error = 1; break;",
4652
	"		case 'J': like_java = 1; break; /* Klaus Havelund */",
4653
	"#ifdef BITSTATE",
4654
	"		case 'k': hfns = atoi(&argv[1][2]); break;",
4655
	"#endif",
4656
	"#ifdef BCS",
4657
	"		case 'L':",
4658
	"			sched_max = atoi(&argv[1][2]);",
4659
	"			if (sched_max > 255)	/* stored as one byte */",
4660
	"			{	fprintf(efd, \"warning: using max bound (255)\\n\");",
4661
	"				sched_max = 255;",
4662
	"			}",
4663
	"	#ifndef NOREDUCE",
4664
	"			if (sched_max == 0)",
4665
	"			{	fprintf(efd, \"warning: with (default) bound -L0, \");",
4666
	"				fprintf(efd, \"using -DNOREDUCE performs better\\n\");",
4667
	"			}",
4668
	"	#endif",
4669
	"			break;",
4670
	"#endif",
4671
	"#ifndef SAFETY",
4672
		"#ifdef NP",
4673
	"		case 'l': a_cycles = 1; break;",
4674
		"#else",
4675
	"		case 'l': fprintf(efd, \"error: -l disabled\");",
4676
	"			  usage(efd); break;",
4677
		"#endif",
4678
	"#endif",
4679
	"#ifdef BITSTATE",
4680
	"		case 'M': udmem = atoi(&argv[1][2]); break;",
4681
	"		case 'G': udmem = atoi(&argv[1][2]); udmem *= 1024; break;",
4682
	"#else",
4683
	"		case 'M': case 'G':",
4684
	"			  fprintf(stderr, \"-M and -G affect only -DBITSTATE\\n\");",
4685
	"			  break;",
4686
	"#endif",
4687
	"		case 'm': maxdepth = atoi(&argv[1][2]); break;",
4688
"#ifndef NOCLAIM",
4689
	"		case 'N':",
4690
	"#if NCLAIMS>1",
4691
	"			  if (isdigit(argv[1][2]))",
4692
	"				whichclaim = atoi(&argv[1][2]);",
4693
	"			  else if (isalpha(argv[1][2]))",
4694
	"			  {     claimname = &argv[1][2];",
4695
	"			  } else if (argc > 2 && argv[2][0] != '-') /* check next arg */",
4696
	"			  {	claimname = argv[2];",
4697
	"				argc--; argv++; /* skip next arg */",
4698
	"			  }",
4699
	"#else",
4700
	"	#if NCLAIMS==1",
4701
	"			  fprintf(stderr, \"warning: only one claim defined, -N ignored\\n\");",
4702
	"	#else",
4703
	"			  fprintf(stderr, \"warning: no claims defined, -N ignored\\n\");",
4704
	"	#endif",
4705
	"			  if (!isdigit(argv[1][2]) && argc > 2 && argv[2][0] != '-')",
4706
	"			  {	argc--; argv++;",
4707
	"			  }",
4708
	"#endif",
4709
"#endif",
4710
	"			  break;\n",
4711
	"		case 'n': no_rck = 1; break;",
4712
	"		case 'P': readtrail = 1; onlyproc = atoi(&argv[1][2]);",
4713
	"			  if (argv[2][0] != '-') /* check next arg */",
4714
	"			  {	trailfilename = argv[2];",
4715
	"				argc--; argv++; /* skip next arg */",
4716
	"			  }",
4717
	"			  break;",
4718
	"#ifdef SVDUMP",
4719
	"		case 'p': vprefix = atoi(&argv[1][2]); break;",
4720
	"#endif",
4721
	"#if NCORE==1",
4722
	"		case 'Q': quota = (double) 60.0 * (double) atoi(&argv[1][2]);",
4723
	"	#ifndef FREQ",
4724
	"			  freq /= 10.; /* for better resolution */",
4725
	"	#endif",
4726
	"			  break;",
4727
	"#endif",
4728
	"		case 'q': strict = 1; break;",
4729
	"		case 'R':",
4730
	"#if defined(T_RAND) || defined(P_RAND) || defined(RANDSTOR)",
4731
	"			if (argv[1][2] == 'S') /* e.g., -RS76842 */",
4732
	"			{	s_rand = atoi(&argv[1][3]);",
4733
	"			} else",
4734
	"#endif",
4735
	"			{	Nrun = atoi(&argv[1][2]);",
4736
	"			}",
4737
	"			break;",
4738
	"#ifdef HAS_CODE",
4739
	"		case 'r':",
4740
	"samething:		  readtrail = 1;",
4741
	"			  if (isdigit(argv[1][2]))",
4742
	"				whichtrail = atoi(&argv[1][2]);",
4743
	"			  else if (argc > 2 && argv[2][0] != '-') /* check next arg */",
4744
	"			  {	trailfilename = argv[2];",
4745
	"				argc--; argv++; /* skip next arg */",
4746
	"			  }",
4747
	"			  break;",
4748
	"		case 'S': silent = 1; goto samething;",
4749
	"#endif",
4750
	"#ifdef BITSTATE",
4751
	"		case 's': hfns = 1; break;",
4752
	"#endif",
4753
	"		case 'T': TMODE = 0444; break;",
4754
	"		case 't': if (argv[1][2]) tprefix = &argv[1][2]; break;",
4755
	"		case 'V': start_timer(); printf(\"Generated by %%s\\n\", SpinVersion);",
4756
	"			  to_compile(); pan_exit(2); break;",
4757
	"		case 'v': verbose++; break;",
4758
	"		case 'w': ssize = atoi(&argv[1][2]); break;",
4759
	"		case 'Y': signoff = 1; break;",
4760
	"		case 'X': efd = stdout; break;",
4761
	"		case 'x': exclusive = 1; break;",
4762
	"#if NCORE>1",
4763
	"		/* -B ip is passthru to proxy of remote ip address: */",
4764
	"		case 'B': argc--; argv++; break;",
4765
	"		case 'Q': worker_pids[0] = atoi(&argv[1][2]); break;",
4766
	"			/* -Un means that the nth worker should be instantiated as a proxy */",
4767
	"		case 'U': proxy_pid = atoi(&argv[1][2]); break;",
4768
	"			/* -W means that this copy is started by a cluster-server as a remote */",
4769
	"			/* this flag is passed to ./pan_proxy, which interprets it */",
4770
	"		case 'W': remote_party++; break;",
4771
	"		case 'Z': core_id = atoi(&argv[1][2]);",
4772
	"			  if (verbose)",
4773
	"			  { printf(\"cpu%%d: pid %%d parent %%d\\n\",",
4774
	"				core_id, getpid(), worker_pids[0]);",
4775
	"			  }",
4776
	"			  break;",
4777
	"		case 'z': z_handoff = atoi(&argv[1][2]); break;",
4778
	"#else",
4779
	"		case 'z': break; /* ignored for single-core */",
4780
	"#endif",
4781
	"		default : fprintf(efd, \"saw option -%%c\\n\", argv[1][1]); usage(efd); break;",
4782
	"		}",
4783
	"		argc--; argv++;",
4784
	"	}",
4785
	"	if (iterative && TMODE != 0666)",
4786
	"	{	TMODE = 0666;",
4787
	"		fprintf(efd, \"warning: -T ignored when -i or -I is used\\n\");",
4788
	"	}",
4789
	"#if defined(HASH32) && !defined(SFH)",
4790
	"	if (WS > 4)",
4791
	"	{	fprintf(efd, \"strong warning: compiling -DHASH32 on a 64-bit machine\\n\");",
4792
	"		fprintf(efd, \" without -DSFH can slow down performance a lot\\n\");",
4793
	"	}",
4794
	"#endif",
4795
	"#if defined(WIN32) || defined(WIN64)",
4796
	"	if (TMODE == 0666)",
4797
	"		TMODE = _S_IWRITE | _S_IREAD;",
4798
	"	else",
4799
	"		TMODE = _S_IREAD;",
4800
	"#endif",
4801
	"#if NCORE>1",
4802
	"	store_proxy_pid = proxy_pid; /* for checks in mem_file() and someone_crashed() */",
4803
	"	if (core_id != 0) { proxy_pid = 0; }",
4804
	"	#ifndef SEP_STATE",
4805
	"	if (core_id == 0 && a_cycles)",
4806
	"	{	fprintf(efd, \"hint: this search may be more efficient \");",
4807
	"		fprintf(efd, \"if pan.c is compiled -DSEP_STATE\\n\");",
4808
	"	}",
4809
	"	#endif",
4810
	"	if (z_handoff < 0)",
4811
	"	{	z_handoff =  20; /* conservative default - for non-liveness checks */",
4812
	"	}",
4813
	"#if defined(NGQ) || defined(LWQ_FIXED)",
4814
	"	LWQ_SIZE = (double) (128.*1048576.);",
4815
	"#else",
4816
	"	LWQ_SIZE = (double) ( z_handoff + 2.) * (double) sizeof(SM_frame);",
4817
		/* the added margin of +2 is not really necessary */
4818
	"#endif",
4819
	"	#if NCORE>2",
4820
	"	if (a_cycles)",
4821
	"	{	fprintf(efd, \"warning: the intended nr of cores to be used in liveness mode is 2\\n\");",
4822
	"		#ifndef SEP_STATE",
4823
	"		fprintf(efd, \"warning: without -DSEP_STATE there is no guarantee that all liveness violations are found\\n\");",
4824
	"		#endif",
4825
	"	}",	/* it still works though, the later cores get states from the global q */
4826
	"	#endif",
4827
	"	#ifdef HAS_HIDDEN",
4828
	"	#error cannot use hidden variables when compiling multi-core",
4829
	"	#endif",
4830
	"#endif",
4831
	"#ifdef BITSTATE",
4832
	"	if (hfns <= 0)",
4833
	"	{	hfns = 1;",
4834
	"		fprintf(efd, \"warning: using -k%%d as minimal usable value\\n\", hfns);",
4835
	"	}",
4836
	"#endif",
4837
	"	omaxdepth = maxdepth;",
4838
	"#ifdef BITSTATE",
4839
	"	if (WS == 4 && ssize > 34)",	/* 32-bit word size */
4840
	"	{	ssize = 34;",
4841
	"		fprintf(efd, \"warning: using -w%%d as max usable value\\n\", ssize);",
4842
	"/*",
4843
	" *	-w35 would not work: 35-3 = 32 but 1^31 is the largest",
4844
	" *	power of 2 that can be represented in an unsigned long",
4845
	" */",
4846
	"	}",
4847
	"#else",
4848
	"	if (WS == 4 && ssize > 27)",
4849
	"	{	ssize = 27;",
4850
	"		fprintf(efd, \"warning: using -w%%d as max usable value\\n\", ssize);",
4851
	"/*",
4852
	" *	for emalloc, the lookup table size multiplies by 4 for the pointers",
4853
	" *	the largest power of 2 that can be represented in a ulong is 1^31",
4854
	" *	hence the largest number of lookup table slots is 31-4 = 27",
4855
	" */",
4856
	"	}",
4857
 
4858
	"#endif",
4859
	"#ifdef SC",
4860
	"	hiwater = HHH = maxdepth-10;",
4861
	"	DDD = HHH/2;",
4862
	"	if (!stackfile)",
4863
	"	{	stackfile = (char *) emalloc(strlen(PanSource)+4+1);",
4864
	"		sprintf(stackfile, \"%%s._s_\", PanSource);",
4865
	"	}",
4866
	"	if (iterative)",
4867
	"	{	fprintf(efd, \"error: cannot use -i or -I with -DSC\\n\");",
4868
	"		pan_exit(1);",
4869
	"	}",
4870
	"#endif",
4871
 
4872
	"#if (defined(R_XPT) || defined(W_XPT)) && !defined(MA)",
4873
	"	#warning -DR_XPT and -DW_XPT assume -DMA (ignored)",
4874
	"#endif",
4875
 
4876
	"	if (iterative && a_cycles)",
4877
	"	fprintf(efd, \"warning: -i or -I work for safety properties only\\n\");",
4878
 
4879
	"#ifdef BFS",
4880
	"	#ifdef SC",
4881
	"		#error -DBFS not compatible with -DSC",
4882
	"	#endif",
4883
	"	#ifdef HAS_LAST",
4884
	"		#error -DBFS not compatible with _last",
4885
	"	#endif",
4886
	"	#ifdef HAS_STACK",
4887
	"		#error cannot use c_track UnMatched with BFS",
4888
	"	#endif",
4889
	"	#ifdef BCS",
4890
	"		#error -DBFS not compatible with -DBCS",
4891
	"	#endif",
4892
	"	#ifdef REACH",
4893
	"		#warning -DREACH is redundant when -DBFS is used",
4894
	"	#endif",
4895
	"#endif",
4896
 
4897
	"#ifdef TRIX",
4898
	"	#ifdef BITSTATE",
4899
	"		#error cannot combine -DTRIX and -DBITSTATE",
4900
	"	#endif",
4901
	"	#ifdef COLLAPSE",
4902
	"		#error cannot combine -DTRIX and -DCOLLAPSE",
4903
	"	#endif",
4904
	"	#ifdef MA",
4905
	"		#error cannot combine -DTRIX and -DMA",
4906
	"	#endif",
4907
	"#endif",
4908
 
4909
	"#ifdef BCS",
4910
	"	#ifdef P_RAND",
4911
	"		#error cannot combine -DBCS and -DP_RAND",
4912
	"	#endif",
4913
	"	#ifdef BFS",
4914
	"		#error cannot combine -DBCS and -DBFS",
4915
	"	#endif",
4916
	"#endif",
4917
 
4918
	"#if defined(MERGED) && defined(PEG)",
4919
	"	#error to use -DPEG use: spin -o3 -a",
4920
	"#endif",
4921
	"#ifdef HC",
4922
	"	#ifdef SFH", /* cannot happen -- undef-ed in this case */
4923
	"		#error cannot combine -DHC and -DSFH",
4924
	"		/* use of NOCOMP is the real reason */",
4925
	"	#else",
4926
	"		#ifdef NOCOMP",
4927
	"		#error cannot combine -DHC and -DNOCOMP",
4928
	"		#endif",
4929
	"	#endif",
4930
	"	#ifdef BITSTATE",
4931
	"		#error cannot combine -DHC and -DBITSTATE",
4932
	"	#endif",
4933
	"#endif",
4934
	"#if defined(SAFETY) && defined(NP)",
4935
	"	#error cannot combine -DNP and -DBFS or -DSAFETY",
4936
	"#endif",
4937
	"#ifdef MA",
4938
	"	#ifdef BITSTATE",
4939
	"		#error cannot combine -DMA and -DBITSTATE",
4940
	"	#endif",
4941
	"	#if MA <= 0",
4942
	"		#error usage: -DMA=N with N > 0 and N < VECTORSZ",
4943
	"	#endif",
4944
	"#endif",
4945
	"#ifdef COLLAPSE",
4946
	"	#ifdef BITSTATE",
4947
	"		#error cannot combine -DBITSTATE and -DCOLLAPSE",
4948
	"	#endif",
4949
	"	#ifdef SFH",
4950
	"		#error cannot combine -DCOLLAPSE and -DSFH",
4951
	"		/* use of NOCOMP is the real reason */",
4952
	"	#else",
4953
	"		#ifdef NOCOMP",
4954
	"		#error cannot combine -DCOLLAPSE and -DNOCOMP",
4955
	"		#endif",
4956
	"	#endif",
4957
	"#endif",
4958
	"	if (maxdepth <= 0 || ssize <= 1) usage(efd);",
4959
	"#if SYNC>0 && !defined(NOREDUCE)",
4960
	"	if (a_cycles && fairness)",
4961
	"	{ fprintf(efd, \"error: p.o. reduction not compatible with \");",
4962
	"	  fprintf(efd, \"fairness (-f) in models\\n\");",
4963
	"	  fprintf(efd, \"       with rendezvous operations: \");",
4964
	"	  fprintf(efd, \"recompile with -DNOREDUCE\\n\");",
4965
	"	  pan_exit(1);",
4966
	"	}",
4967
	"#endif",
4968
	"#if defined(REM_VARS) && !defined(NOREDUCE)",
4969
	"	#warning p.o. reduction not compatible with remote varrefs (use -DNOREDUCE)",
4970
	"#endif",
4971
	"#if defined(NOCOMP) && !defined(BITSTATE)",
4972
	"	if (a_cycles)",
4973
	"	{ fprintf(efd, \"error: use of -DNOCOMP voids -l and -a\\n\");",
4974
	"	  pan_exit(1);",
4975
	"	}",
4976
	"#endif",
4977
 
4978
	"#ifdef MEMLIM",
4979
	"	memlim = ((double) MEMLIM) * (double) (1<<20);	/* size in Mbyte */",
4980
	"#endif",
4981
 
4982
	"#ifndef BITSTATE",
4983
	"	if (Nrun > 1) HASH_NR = Nrun - 1;",
4984
	"#endif",
4985
	"	if (Nrun < 1 || Nrun > 32)",
4986
	"	{	fprintf(efd, \"error: invalid arg for -R\\n\");",
4987
	"		usage(efd);",
4988
	"	}",
4989
	"#ifndef SAFETY",
4990
	"	if (fairness && !a_cycles)",
4991
	"	{	fprintf(efd, \"error: -f requires -a or -l\\n\");", 
4992
	"		usage(efd);",
4993
	"	}",
4994
	"	#if ACCEPT_LAB==0",
4995
	"	if (a_cycles)",
4996
	"	{	fprintf(efd, \"error: no accept labels defined \");",
4997
	"		fprintf(efd, \"in model (for option -a)\\n\");",
4998
	"		usage(efd);",
4999
	"	}",
5000
	"	#endif",
5001
	"#endif",
5002
	"#ifndef NOREDUCE",
5003
	"	#ifdef HAS_ENABLED",
5004
	"		#error use of enabled() requires -DNOREDUCE",
5005
	"	#endif",
5006
	"	#ifdef HAS_PCVALUE",
5007
	"		#error use of pcvalue() requires -DNOREDUCE",
5008
	"	#endif",
5009
	"	#ifdef HAS_BADELSE",
5010
	"		#error use of 'else' combined with i/o stmnts requires -DNOREDUCE",
5011
	"	#endif",
5012
	"	#if defined(HAS_LAST) && !defined(BCS)",
5013
	"		#error use of _last requires -DNOREDUCE",
5014
	"	#endif",
5015
	"#endif",
5016
 
5017
	"#if SYNC>0 && !defined(NOREDUCE)",
5018
	"	#ifdef HAS_UNLESS",
5019
	"	fprintf(efd, \"warning: use of a rendezvous stmnts in the escape\\n\");",
5020
	"	fprintf(efd, \"\tof an unless clause, if present, could make p.o. reduction\\n\");",
5021
	"	fprintf(efd, \"\tinvalid (use -DNOREDUCE to avoid this)\\n\");",
5022
	"		#ifdef BFS",
5023
	"		fprintf(efd, \"\t(this type of rv is also not compatible with -DBFS)\\n\");",
5024
	"		#endif",
5025
	"	#endif",
5026
	"#endif",
5027
	"#if SYNC>0 && defined(BFS)",
5028
	"	#warning use of rendezvous with BFS does not preserve all invalid endstates",
5029
	"#endif",
5030
	"#if !defined(REACH) && !defined(BITSTATE)",
5031
	"	if (iterative != 0 && a_cycles == 0)",
5032
	"	{	fprintf(efd, \"warning: -i and -I need -DREACH to work accurately\\n\");",
5033
	"	}",
5034
	"#endif",
5035
	"#if defined(BITSTATE) && defined(REACH)",
5036
	"	#warning -DREACH is voided by -DBITSTATE",
5037
	"#endif",
5038
	"#if defined(MA) && defined(REACH)",
5039
	"	#warning -DREACH is voided by -DMA",
5040
	"#endif",
5041
	"#if defined(FULLSTACK) && defined(CNTRSTACK)",
5042
	"	#error cannot combine -DFULLSTACK and -DCNTRSTACK",
5043
	"#endif",
5044
	"#if defined(VERI)",
5045
	"	#if ACCEPT_LAB>0",
5046
	"		#ifndef BFS",
5047
	"			if (!a_cycles",
5048
	"			#ifdef HAS_CODE",
5049
	"			&& !readtrail",
5050
	"			#endif",
5051
	"			#if NCORE>1",
5052
	"			&& core_id == 0",
5053
	"			#endif",
5054
	"			&& !state_tables)",
5055
	"			{ fprintf(efd, \"warning: never claim + accept labels \");",
5056
	"			  fprintf(efd, \"requires -a flag to fully verify\\n\");",
5057
	"			}",
5058
	"		#else",
5059
	"			if (!state_tables",
5060
	"			#ifdef HAS_CODE",
5061
	"			&& !readtrail",
5062
	"			#endif",
5063
	"			)",
5064
	"			{ fprintf(efd, \"warning: verification in BFS mode \");",
5065
	"			  fprintf(efd, \"is restricted to safety properties\\n\");",
5066
	"			}",
5067
	"		#endif",
5068
	"	#endif",
5069
	"#endif",
5070
	"#ifndef SAFETY",
5071
	"	if (!a_cycles",
5072
	"	#ifdef HAS_CODE",
5073
	"	&& !readtrail",
5074
	"	#endif",
5075
	"	#if NCORE>1",
5076
	"	&& core_id == 0",
5077
	"	#endif",
5078
	"	&& !state_tables)",
5079
	"	{ fprintf(efd, \"hint: this search is more efficient \");",
5080
	"	  fprintf(efd, \"if pan.c is compiled -DSAFETY\\n\");",
5081
	"	}",
5082
	"	#ifndef NOCOMP",
5083
	"	if (!a_cycles)",
5084
	"	{	S_A = 0;",
5085
	"	} else",
5086
	"	{	if (!fairness)",
5087
	"		{	S_A = 1; /* _a_t */",
5088
	"		#ifndef NOFAIR",
5089
	"		} else /* _a_t and _cnt[NFAIR] */",
5090
	"		{  S_A = (&(now._cnt[0]) - (uchar *) &now) + NFAIR - 2;",
5091
	"		/* -2 because first two uchars in now are masked */",
5092
	"		#endif",
5093
	"	}	}",
5094
	"	#endif",
5095
	"#endif",
5096
	"	signal(SIGINT, stopped);",
5097
	"	set_masks();",
5098
	"#ifdef BFS",
5099
	"	trail = (Trail *) emalloc(6*sizeof(Trail));",
5100
	"	trail += 3;",
5101
	"#else",
5102
	"	trail = (Trail *) emalloc((maxdepth+3)*sizeof(Trail));",
5103
	"	trail++;	/* protect trpt-1 refs at depth 0 */",
5104
	"#endif",
5105
	"#ifdef SVDUMP",
5106
	"	if (vprefix > 0)",
5107
	"	{	char nm[64];",
5108
	"		sprintf(nm, \"%%s.svd\", PanSource);",
5109
	"		if ((svfd = creat(nm, TMODE)) < 0)",
5110
	"		{	fprintf(efd, \"couldn't create %%s\\n\", nm);",
5111
	"			vprefix = 0;",
5112
	"	}	}",
5113
	"#endif",
5114
	"#ifdef RANDSTOR",
5115
	"	srand(s_rand);",
5116
	"#endif",
5117
	"#if SYNC>0 && ASYNC==0",
5118
	"	set_recvs();",
5119
	"#endif",
5120
	"	run();",
5121
	"	done = 1;",
5122
	"	wrapup();",
5123
	"	return 0;",
5124
	"}",	/* end of main() */
5125
	"",
5126
	"void",
5127
	"usage(FILE *fd)",
5128
	"{",
5129
	"	fprintf(fd, \"%%s\\n\", SpinVersion);",
5130
	"	fprintf(fd, \"Valid Options are:\\n\");",
5131
	"#ifndef SAFETY",
5132
		"#ifdef NP",
5133
	"	fprintf(fd, \"\t-a  -> is disabled by -DNP \");",
5134
	"	fprintf(fd, \"(-DNP compiles for -l only)\\n\");",
5135
		"#else",
5136
	"	fprintf(fd, \"\t-a  find acceptance cycles\\n\");",
5137
		"#endif",
5138
	"#else",
5139
	"	fprintf(fd, \"\t-a,-l,-f  -> are disabled by -DSAFETY\\n\");",
5140
	"#endif",
5141
	"	fprintf(fd, \"\t-A  ignore assert() violations\\n\");",
5142
	"	fprintf(fd, \"\t-b  consider it an error to exceed the depth-limit\\n\");",
5143
	"	fprintf(fd, \"\t-cN stop at Nth error \");",
5144
	"	fprintf(fd, \"(defaults to -c1)\\n\");",
5145
	"	fprintf(fd, \"\t-D  print state tables in dot-format and stop\\n\");",
5146
	"	fprintf(fd, \"\t-d  print state tables and stop\\n\");",
5147
	"	fprintf(fd, \"\t-e  create trails for all errors\\n\");",
5148
	"	fprintf(fd, \"\t-E  ignore invalid end states\\n\");",
5149
	"#ifdef SC",
5150
	"	fprintf(fd, \"\t-Ffile  use 'file' to store disk-stack\\n\");",
5151
	"#endif",
5152
	"#ifndef NOFAIR",
5153
	"	fprintf(fd, \"\t-f  add weak fairness (to -a or -l)\\n\");",
5154
	"#endif",
5155
	"	fprintf(fd, \"\t-hN use different hash-seed N:1..32\\n\");",
5156
	"	fprintf(fd, \"\t-i  search for shortest path to error\\n\");",
5157
	"	fprintf(fd, \"\t-I  like -i, but approximate and faster\\n\");",
5158
	"	fprintf(fd, \"\t-J  reverse eval order of nested unlesses\\n\");",
5159
	"#ifdef BITSTATE",
5160
	"	fprintf(fd, \"\t-kN set N bits per state (defaults to 3)\\n\");",
5161
	"#endif",
5162
	"#ifdef BCS",
5163
	"	fprintf(fd, \"\t-LN set scheduling restriction to N (default 0)\\n\");",
5164
	"#endif",
5165
	"#ifndef SAFETY",
5166
		"#ifdef NP",
5167
	"	fprintf(fd, \"\t-l  find non-progress cycles\\n\");",
5168
		"#else",
5169
	"	fprintf(fd, \"\t-l  find non-progress cycles -> \");",
5170
	"	fprintf(fd, \"disabled, requires \");",
5171
	"	fprintf(fd, \"compilation with -DNP\\n\");",
5172
		"#endif",
5173
	"#endif",
5174
	"#ifdef BITSTATE",
5175
	"	fprintf(fd, \"\t-MN use N Megabytes for bitstate hash array\\n\");",
5176
	"	fprintf(fd, \"\t-GN use N Gigabytes for bitstate hash array\\n\");",
5177
	"#endif",
5178
	"	fprintf(fd, \"\t-mN max depth N steps (default=10k)\\n\");",
5179
	"#if NCLAIMS>1",
5180
	"	fprintf(fd, \"\t-N cn -- use the claim named cn\\n\");",
5181
	"	fprintf(fd, \"\t-Nn   -- use claim number n\\n\");",
5182
	"#endif",
5183
	"	fprintf(fd, \"\t-n  no listing of unreached states\\n\");",
5184
	"#ifdef SVDUMP",
5185
	"	fprintf(fd, \"\t-pN create svfile (save N bytes per state)\\n\");",
5186
	"#endif",
5187
	"	fprintf(fd, \"\t-QN set time-limit on execution of N minutes\\n\");",
5188
	"	fprintf(fd, \"\t-q  require empty chans in valid end states\\n\");",
5189
	"#ifdef HAS_CODE",
5190
	"	fprintf(fd, \"\t-r  read and execute trail - can add -v,-n,-PN,-g,-C\\n\");",
5191
	"	fprintf(fd, \"\t-rN read and execute N-th error trail\\n\");",
5192
	"	fprintf(fd, \"\t-C  read and execute trail - columnated output (can add -v,-n)\\n\");",
5193
	"	fprintf(fd, \"\t-PN read and execute trail - restrict trail output to proc N\\n\");",
5194
	"	fprintf(fd, \"\t-g  read and execute trail + msc gui support\\n\");",
5195
	"	fprintf(fd, \"\t-S  silent replay: only user defined printfs show\\n\");",
5196
	"#endif",
5197
	"#if defined(T_RAND) || defined(P_RAND) || defined(RANDSTOR)",
5198
	"	fprintf(fd, \"\t-RSN use randomization seed N\\n\");",
5199
	"#endif",
5200
	"#ifdef BITSTATE",
5201
	"	fprintf(fd, \"\t-RN repeat run Nx with N \");",
5202
	"	fprintf(fd, \"[1..32] independent hash functions\\n\");",
5203
	"	fprintf(fd, \"\t-s  same as -k1 (single bit per state)\\n\");",
5204
	"#endif",
5205
	"	fprintf(fd, \"\t-T  create trail files in read-only mode\\n\");",
5206
	"	fprintf(fd, \"\t-tsuf replace .trail with .suf on trailfiles\\n\");",
5207
	"	fprintf(fd, \"\t-V  print SPIN version number\\n\");",
5208
	"	fprintf(fd, \"\t-v  verbose -- filenames in unreached state listing\\n\");",
5209
	"	fprintf(fd, \"\t-wN hashtable of 2^N entries \");",
5210
	"	fprintf(fd, \"(defaults to -w%%d)\\n\", ssize);",
5211
	"	fprintf(fd, \"\t-x  do not overwrite an existing trail file\\n\");",
5212
	"#if NCORE>1",
5213
	"	fprintf(fd, \"\t-zN handoff states below depth N to 2nd cpu (multi_core)\\n\");",
5214
	"#endif",
5215
	"#ifdef HAS_CODE",
5216
	"	fprintf(fd, \"\\n\toptions -r, -C, -PN, -g, and -S can optionally be followed by\\n\");",
5217
	"	fprintf(fd, \"\ta filename argument, as in \'-r filename\', naming the trailfile\\n\");",
5218
	"#endif",
5219
	"#if NCORE>1",
5220
	"	multi_usage(fd);",
5221
	"#endif",
5222
	"	exit(1);",
5223
	"}",
5224
	"",
5225
	"char *",
5226
	"Malloc(unsigned long n)",
5227
	"{	char *tmp;",
5228
	"#ifdef MEMLIM",
5229
	"	if (memcnt + (double) n > memlim)",
5230
	"	{	printf(\"pan: reached -DMEMLIM bound\\n\");",
5231
	"		goto err;",
5232
	"	}",
5233
	"#endif",
5234
	"	tmp = (char *) malloc(n);",
5235
	"	if (!tmp)",
5236
	"	{	printf(\"pan: out of memory\\n\");",
5237
	"#ifdef MEMLIM",
5238
	"err:",
5239
	"		printf(\"\t%%g bytes used\\n\", memcnt);",
5240
	"		printf(\"\t%%g bytes more needed\\n\", (double) n);",
5241
	"		printf(\"\t%%g bytes limit\\n\", memlim);",
5242
	"#endif",
5243
	"#ifdef COLLAPSE",
5244
	"		printf(\"hint: to reduce memory, recompile with\\n\");",
5245
		"#ifndef MA",
5246
	"		printf(\"  -DMA=%%d   # better/slower compression, or\\n\", hmax);",
5247
		"#endif",
5248
	"		printf(\"  -DBITSTATE # supertrace, approximation\\n\");",
5249
	"#else",
5250
	"#ifndef BITSTATE",
5251
	"		printf(\"hint: to reduce memory, recompile with\\n\");",
5252
		"#ifndef HC",
5253
	"		printf(\"  -DCOLLAPSE # good, fast compression, or\\n\");",
5254
			"#ifndef MA",
5255
	"		printf(\"  -DMA=%%d   # better/slower compression, or\\n\", hmax);",
5256
			"#endif",
5257
	"		printf(\"  -DHC # hash-compaction, approximation\\n\");",
5258
		"#endif",
5259
	"		printf(\"  -DBITSTATE # supertrace, approximation\\n\");",
5260
	"#endif",
5261
	"#endif",
5262
	"#if NCORE>1",
5263
	"	#ifdef FULL_TRAIL",
5264
	"		printf(\"  omit -DFULL_TRAIL or use pan -c0 to reduce memory\\n\");",
5265
	"	#endif",
5266
	"	#ifdef SEP_STATE",
5267
	"		printf(\"hint: to reduce memory, recompile without\\n\");",
5268
	"		printf(\"  -DSEP_STATE # may be faster, but uses more memory\\n\");",
5269
	"	#endif",
5270
	"#endif",
5271
	"		wrapup();",
5272
	"	}",
5273
	"	memcnt += (double) n;",
5274
	"	return tmp;",
5275
	"}",
5276
	"",
5277
	"#define CHUNK	(100*VECTORSZ)",
5278
	"",
5279
	"char *",
5280
	"emalloc(unsigned long n) /* never released or reallocated */",
5281
	"{	char *tmp;",
5282
	"	if (n == 0)",
5283
	"	        return (char *) NULL;",
5284
	"	if (n&(sizeof(void *)-1)) /* for proper alignment */",
5285
	"	        n += sizeof(void *)-(n&(sizeof(void *)-1));",
5286
	"	if ((unsigned long) left < n)",	/* was: (left < (long)n) */
5287
	"	{       grow = (n < CHUNK) ? CHUNK : n;",
5288
#if 1
5289
	"	        have = Malloc(grow);",
5290
#else
5291
	"		/* gcc's sbrk can give non-aligned result */",
5292
	"		grow += sizeof(void *);	/* allow realignment */",
5293
	"	        have = Malloc(grow);",
5294
	"		if (((unsigned) have)&(sizeof(void *)-1))",
5295
	"		{	have += (long) (sizeof(void *) ",
5296
	"				- (((unsigned) have)&(sizeof(void *)-1)));",
5297
	"			grow -= sizeof(void *);",
5298
	"		}",
5299
#endif
5300
	"	        fragment += (double) left;",
5301
	"	        left = grow;",
5302
	"	}",
5303
	"	tmp = have;",
5304
	"	have += (long) n;",
5305
	"	left -= (long) n;",
5306
	"	memset(tmp, 0, n);",
5307
	"	return tmp;",
5308
	"}",
5309
 
5310
	"void",
5311
	"Uerror(char *str)",
5312
	"{	/* always fatal */",
5313
	"	uerror(str);",
5314
	"#if NCORE>1",
5315
	"	sudden_stop(\"Uerror\");",
5316
	"#endif",
5317
	"	wrapup();",
5318
	"}\n",
5319
	"#if defined(MA) && !defined(SAFETY)",
5320
	"int",
5321
	"Unwind(void)",
5322
	"{	Trans *t; uchar ot, _m; int tt; short II;",
5323
	"#ifdef VERBOSE",
5324
	"	int i;",
5325
	"#endif",
5326
	"	uchar oat = now._a_t;",
5327
	"	now._a_t &= ~(1|16|32);",
5328
	"	memcpy((char *) &comp_now, (char *) &now, vsize);",
5329
	"	now._a_t = oat;",
5330
	"Up:",
5331
	"#ifdef SC",
5332
	"	trpt = getframe(depth);",
5333
	"#endif",
5334
	"#ifdef VERBOSE",
5335
	"	printf(\"%%d	 State: \", depth);",
5336
	"	for (i = 0; i < vsize; i++) printf(\"%%d%%s,\",",
5337
	"		((char *)&now)[i], Mask[i]?\"*\":\"\");",
5338
	"	printf(\"\\n\");",
5339
	"#endif",
5340
	"#ifndef NOFAIR",
5341
	"	if (trpt->o_pm&128)	/* fairness alg */",
5342
	"	{	now._cnt[now._a_t&1] = trpt->bup.oval;",
5343
	"		depth--;",
5344
	"#ifdef SC",
5345
	"		trpt = getframe(depth);",
5346
	"#else",
5347
	"		trpt--;",
5348
	"#endif",
5349
	"		goto Q999;",
5350
	"	}",
5351
	"#endif",
5352
	"#ifdef HAS_LAST",
5353
	"#ifdef VERI",
5354
	"	{ int d; Trail *trl;",
5355
	"	  now._last = 0;",
5356
	"	  for (d = 1; d < depth; d++)",
5357
	"	  {	trl = getframe(depth-d); /* was trl = (trpt-d); */",
5358
	"		if (trl->pr != 0)",
5359
	"		{ now._last = trl->pr - BASE;",
5360
	"		  break;",
5361
	"	} }	}",
5362
	"#else",
5363
	"	now._last = (depth<1)?0:(trpt-1)->pr;",
5364
	"#endif",
5365
	"#endif",
5366
	"#ifdef EVENT_TRACE",
5367
	"	now._event = trpt->o_event;",
5368
	"#endif",
5369
	"	if ((now._a_t&1) && depth <= A_depth)",
5370
	"	{	now._a_t &= ~(1|16|32);",
5371
	"		if (fairness) now._a_t |= 2;	/* ? */",
5372
	"		A_depth = 0;",
5373
	"		goto CameFromHere;	/* checkcycles() */",
5374
	"	}",
5375
	"	t  = trpt->o_t;",
5376
	"	ot = trpt->o_ot; II = trpt->pr;",
5377
	"	tt = trpt->o_tt; this = pptr(II);",
5378
	"	_m = do_reverse(t, II, trpt->o_m);",
5379
	"#ifdef VERBOSE",
5380
	"	printf(\"%%3ld: proc %%d \", depth, II);",
5381
	"	printf(\"reverses %%d, %%d to %%d,\",",
5382
	"		t->forw, tt, t->st);",
5383
	"	printf(\" %%s [abit=%%d,adepth=%%d,\", ",
5384
	"		t->tp, now._a_t, A_depth);",
5385
	"	printf(\"tau=%%d,%%d] <unwind>\\n\", ",
5386
	"		trpt->tau, (trpt-1)->tau);",
5387
	"#endif",
5388
	"	depth--;",
5389
	"#ifdef SC",
5390
	"	trpt = getframe(depth);",
5391
	"#else",
5392
	"	trpt--;",
5393
	"#endif",
5394
	"	/* reached[ot][t->st] = 1;	3.4.13 */",
5395
	"	((P0 *)this)->_p = tt;",
5396
	"#ifndef NOFAIR",
5397
	"	if ((trpt->o_pm&32))",
5398
	"	{",
5399
		"#ifdef VERI",
5400
	"		if (now._cnt[now._a_t&1] == 0)",
5401
	"			now._cnt[now._a_t&1] = 1;",
5402
		"#endif",
5403
	"		now._cnt[now._a_t&1] += 1;",
5404
	"	}",
5405
	"Q999:",
5406
	"	if (trpt->o_pm&8)",
5407
	"	{	now._a_t &= ~2;",
5408
	"		now._cnt[now._a_t&1] = 0;",
5409
	"	}",
5410
	"	if (trpt->o_pm&16)",
5411
	"		now._a_t |= 2;",
5412
	"#endif",
5413
	"CameFromHere:",
5414
	"	if (memcmp((char *) &now, (char *) &comp_now, vsize) == 0)",
5415
	"		return depth;",
5416
	"	if (depth > 0) goto Up;",
5417
	"	return 0;",
5418
	"}",
5419
	"#endif",
5420
	"static char unwinding;",
5421
	"void",
5422
	"uerror(char *str)",
5423
	"{	static char laststr[256];",
5424
	"	int is_cycle;",
5425
	"",
5426
	"	if (unwinding) return; /* 1.4.2 */",
5427
	"	if (strncmp(str, laststr, 254))",
5428
	"#if NCORE>1",
5429
	"	cpu_printf(\"pan:%%d: %%s (at depth %%ld)\\n\", errors+1, str,",
5430
	"#else",
5431
	"	printf(\"pan:%%d: %%s (at depth %%ld)\\n\", errors+1, str,",
5432
	"#endif",
5433
	"#if NCORE>1",
5434
	"		(nr_handoffs * z_handoff) + ",
5435
	"#endif",
5436
	"		((depthfound==-1)?depth:depthfound));",
5437
	"	strncpy(laststr, str, 254);",
5438
	"	errors++;",
5439
	"#ifdef HAS_CODE",
5440
	"	if (readtrail) { wrap_trail(); return; }",
5441
	"#endif",
5442
	"	is_cycle = (strstr(str, \" cycle\") != (char *) 0);",
5443
	"	if (!is_cycle)",
5444
	"	{	depth++; trpt++;",	/* include failed step */
5445
	"	}",
5446
	"	if ((every_error != 0)",
5447
	"	||  errors == upto)",
5448
	"	{",
5449
	"#if defined(MA) && !defined(SAFETY)",
5450
	"		if (is_cycle)",
5451
	"		{	int od = depth;",
5452
	"			unwinding = 1;",
5453
	"			depthfound = Unwind();",
5454
	"			unwinding = 0;",
5455
	"			depth = od;",
5456
	"		}",
5457
	"#endif",
5458
	"#if NCORE>1",
5459
	"		writing_trail = 1;",
5460
	"#endif",
5461
	"#ifdef BFS",
5462
	"		if (depth > 1) trpt--;",
5463
	"		nuerror(str);",
5464
	"		if (depth > 1) trpt++;",
5465
	"#else",
5466
	"		putrail();",
5467
	"#endif",
5468
	"#if defined(MA) && !defined(SAFETY)",
5469
	"		if (strstr(str, \" cycle\"))",
5470
	"		{	if (every_error)",
5471
	"			printf(\"sorry: MA writes 1 trail max\\n\");",
5472
	"			wrapup(); /* no recovery from unwind */",
5473
	"		}",
5474
	"#endif",
5475
	"#if NCORE>1",
5476
	"		if (search_terminated != NULL)",
5477
	"		{	*search_terminated |= 4; /* uerror */",
5478
	"		}",
5479
	"		writing_trail = 0;",
5480
	"#endif",
5481
	"	}",
5482
	"	if (!is_cycle)",
5483
	"	{	depth--; trpt--;	/* undo */",
5484
	"	}",
5485
	"#ifndef BFS",
5486
	"	if (iterative != 0 && maxdepth > 0)",
5487
	"	{	if (maxdepth > depth)",
5488
	"		{	maxdepth = (iterative == 1)?(depth+1):(depth/2);",
5489
	"		}",
5490
	"		warned = 1;",
5491
	"		printf(\"pan: reducing search depth to %%ld\\n\",",
5492
	"			maxdepth);",
5493
	"	} else",
5494
	"#endif",
5495
	"	if (errors >= upto && upto != 0)",
5496
	"	{",
5497
	"#if NCORE>1",
5498
	"		sudden_stop(\"uerror\");",
5499
	"#endif",
5500
	"		wrapup();",
5501
	"	}",
5502
	"	depthfound = -1;",
5503
	"}\n",
5504
	"int",
5505
	"xrefsrc(int lno, S_F_MAP *mp, int M, int i)",
5506
	"{	Trans *T; int j, retval=1;",
5507
	"	for (T = trans[M][i]; T; T = T->nxt)",
5508
	"	if (T && T->tp)",
5509
	"	{	if (strcmp(T->tp, \".(goto)\") == 0",
5510
	"		||  strncmp(T->tp, \"goto :\", 6) == 0)",
5511
	"			return 1; /* not reported */",
5512
	"",
5513
	"		for (j = 0; j < sizeof(mp); j++)",
5514
	"			if (i >= mp[j].from && i <= mp[j].upto)",
5515
	"			{	printf(\"\\t%%s:%%d\", mp[j].fnm, lno);",
5516
	"				break;",
5517
	"			}",
5518
	"		if (j >= sizeof(mp))	/* fnm not found in list */",
5519
	"		{	printf(\"\\t%%s:%%d\", PanSource, lno); /* use default */",
5520
	"		}",
5521
	"		printf(\", state %%d\", i);",
5522
	"		if (strcmp(T->tp, \"\") != 0)",
5523
	"		{	char *q;",
5524
	"			q = transmognify(T->tp);",
5525
	"			printf(\", \\\"%%s\\\"\", q?q:\"\");",
5526
	"		} else if (stopstate[M][i])",
5527
	"			printf(\", -end state-\");",
5528
	"		printf(\"\\n\");",
5529
	"		retval = 0; /* reported */",
5530
	"	}",
5531
	"	return retval;",
5532
	"}\n",
5533
	"void",
5534
	"r_ck(uchar *which, int N, int M, short *src, S_F_MAP *mp)",
5535
	"{	int i, m=0;",
5536
	"",
5537
	"	if ((enum btypes) Btypes[M] == N_CLAIM",
5538
	"	&& claimname != NULL && strcmp(claimname, procname[M]) != 0)",
5539
	"	{	return;",
5540
	"	}",
5541
	"",
5542
	"	switch ((enum btypes) Btypes[M]) {",
5543
	"	case P_PROC:",
5544
	"	case A_PROC:",
5545
	"		printf(\"unreached in proctype %%s\\n\", procname[M]);",
5546
	"		break;",
5547
	"	case I_PROC:",
5548
	"		printf(\"unreached in init\\n\");",
5549
	"		break;",
5550
	"	case E_TRACE:",
5551
	"	case N_TRACE:",
5552
	"	case N_CLAIM:",
5553
	"	default:",
5554
	"		printf(\"unreached in claim %%s\\n\", procname[M]);",
5555
	"		break;",
5556
	"	}",
5557
	"	for (i = 1; i < N; i++)",
5558
	"	{	if (which[i] == 0",
5559
	"		&&  (mapstate[M][i] == 0",
5560
	"		||   which[mapstate[M][i]] == 0))",
5561
	"		{	m += xrefsrc((int) src[i], mp, M, i);",
5562
	"		} else",
5563
	"		{	m++;",
5564
	"	}	}",
5565
	"	printf(\"\t(%%d of %%d states)\\n\", N-1-m, N-1);",
5566
	"}",
5567
	"#if NCORE>1 && !defined(SEP_STATE)",
5568
	"static long rev_trail_cnt;",
5569
	"",
5570
	"#ifdef FULL_TRAIL",
5571
	"void",
5572
	"rev_trail(int fd, volatile Stack_Tree *st_tr)",
5573
	"{	long j; char snap[64];",
5574
	"",
5575
	"	if (!st_tr)",
5576
	"	{	return;",
5577
	"	}",
5578
	"	rev_trail(fd, st_tr->prv);",
5579
	"#ifdef VERBOSE",
5580
	"	printf(\"%%d (%%d) LRT [%%d,%%d] -- %%9u (root %%9u)\\n\",",
5581
	"		depth, rev_trail_cnt, st_tr->pr, st_tr->t_id, st_tr, stack_last[core_id]);",
5582
	"#endif",
5583
	"	if (st_tr->pr != 255)", /* still needed? */
5584
	"	{	sprintf(snap, \"%%ld:%%d:%%d\\n\", ",
5585
	"			rev_trail_cnt++, st_tr->pr, st_tr->t_id);",
5586
	"		j = strlen(snap);",
5587
	"		if (write(fd, snap, j) != j)",
5588
	"		{	printf(\"pan: error writing trailfile\\n\");",
5589
	"			close(fd);",
5590
	"			wrapup();",
5591
	"			return;",
5592
	"		}",
5593
	"	} else  /* handoff point */",
5594
	"	{	if (a_cycles)",
5595
	"		{	(void) write(fd, \"-1:-1:-1\\n\", 9);",
5596
	"	}	}",
5597
	"}",
5598
	"#endif", /* FULL_TRAIL */
5599
	"#endif", /* NCORE>1 */
5600
	"",
5601
	"void",
5602
	"putrail(void)",
5603
	"{	int fd;",
5604
	"#if defined VERI || defined(MERGED)",
5605
	"	char snap[64];",
5606
	"#endif",
5607
	"#if NCORE==1 || defined(SEP_STATE) || !defined(FULL_TRAIL)",
5608
	"	long i, j;",
5609
	"	Trail *trl;",
5610
	"#endif",
5611
	"	fd = make_trail();",
5612
	"	if (fd < 0) return;",
5613
	"#ifdef VERI",
5614
	"	sprintf(snap, \"-2:%%d:-2\\n\", (uchar) ((P0 *)pptr(0))->_t);",
5615
	"	if (write(fd, snap, strlen(snap)) < 0) return;",
5616
	"#endif",
5617
	"#ifdef MERGED",
5618
	"	sprintf(snap, \"-4:-4:-4\\n\");",
5619
	"	if (write(fd, snap, strlen(snap)) < 0) return;",
5620
	"#endif",
5621
	"#if NCORE>1 && !defined(SEP_STATE) && defined(FULL_TRAIL)",
5622
	"	rev_trail_cnt = 1;",
5623
	"	enter_critical(GLOBAL_LOCK);",
5624
	"	 rev_trail(fd, stack_last[core_id]);",
5625
	"	leave_critical(GLOBAL_LOCK);",
5626
	"#else",
5627
	"	i = 1; /* trail starts at position 1 */",
5628
	"	#if NCORE>1 && defined(SEP_STATE)",
5629
	"	if (cur_Root.m_vsize > 0) { i++; depth++; }",
5630
	"	#endif",
5631
	"	for ( ; i <= depth; i++)",
5632
	"	{	if (i == depthfound+1)",
5633
	"		{	if (write(fd, \"-1:-1:-1\\n\", 9) != 9)",
5634
	"			{	goto notgood;",
5635
	"		}	}",
5636
	"		trl = getframe(i);",
5637
	"		if (!trl->o_t) continue;",
5638
	"		if (trl->o_pm&128) continue;",
5639
	"		sprintf(snap, \"%%ld:%%d:%%d\\n\", ",
5640
	"			i, trl->pr, trl->o_t->t_id);",
5641
	"		j = strlen(snap);",
5642
	"		if (write(fd, snap, j) != j)",
5643
	"		{",
5644
	"notgood:		printf(\"pan: error writing trailfile\\n\");",
5645
	"			close(fd);",
5646
	"			wrapup();",
5647
	"	}	}",
5648
	"#endif",
5649
	"	close(fd);",
5650
	"#if NCORE>1",
5651
	"	cpu_printf(\"pan: wrote trailfile\\n\");",
5652
	"#endif",
5653
	"}\n",
5654
	"void",
5655
	"sv_save(void)	/* push state vector onto save stack */",
5656
	"{	if (!svtack->nxt)",
5657
	"	{  svtack->nxt = (Svtack *) emalloc(sizeof(Svtack));",
5658
	"	   svtack->nxt->body = emalloc(vsize*sizeof(char));",
5659
	"	   svtack->nxt->lst = svtack;",
5660
	"	   svtack->nxt->m_delta = vsize;",
5661
	"	   svmax++;",
5662
	"	} else if (vsize > svtack->nxt->m_delta)",
5663
	"	{  svtack->nxt->body = emalloc(vsize*sizeof(char));",
5664
	"	   svtack->nxt->lst = svtack;",
5665
	"	   svtack->nxt->m_delta = vsize;",
5666
	"	   svmax++;",
5667
	"	}",
5668
	"	svtack = svtack->nxt;",
5669
	"#if SYNC",
5670
	"	svtack->o_boq = boq;",
5671
	"#endif",
5672
	"#ifdef TRIX",
5673
	"	sv_populate();",
5674
	"#endif",
5675
	"	svtack->o_delta = vsize; /* don't compress */",
5676
	"	memcpy((char *)(svtack->body), (char *) &now, vsize);",
5677
	"#if defined(C_States) && defined(HAS_STACK) && (HAS_TRACK==1)",
5678
	"	c_stack((uchar *) &(svtack->c_stack[0]));",
5679
	"#endif",
5680
	"#ifdef DEBUG",
5681
	"	cpu_printf(\"%%d:	sv_save\\n\", depth);",
5682
	"#endif",
5683
	"}\n",
5684
	"void",
5685
	"sv_restor(void)	/* pop state vector from save stack */",
5686
	"{",
5687
	"	memcpy((char *)&now, svtack->body, svtack->o_delta);",
5688
	"#if SYNC",
5689
	"	boq = svtack->o_boq;",
5690
	"#endif",
5691
	"#ifdef TRIX",
5692
	"	re_populate();",
5693
	"#endif",
5694
	"#if defined(C_States) && (HAS_TRACK==1)",
5695
	"#ifdef HAS_STACK",
5696
	"	c_unstack((uchar *) &(svtack->c_stack[0]));",
5697
	"#endif",
5698
	"	c_revert((uchar *) &(now.c_state[0]));",
5699
	"#endif",
5700
 
5701
	"	if (vsize != svtack->o_delta)",
5702
	"		Uerror(\"sv_restor\");",
5703
	"	if (!svtack->lst)",
5704
	"		Uerror(\"error: sv_restor\");",
5705
	"	svtack  = svtack->lst;",
5706
	"#ifdef DEBUG",
5707
	"	cpu_printf(\"	sv_restor\\n\");",
5708
	"#endif",
5709
	"}\n",
5710
	"void",
5711
	"p_restor(int h)",
5712
	"{	int i;",
5713
	"	char *z = (char *) &now;\n",
5714
	"#ifndef TRIX",
5715
	"	proc_offset[h] = stack->o_offset;",
5716
	"	proc_skip[h]   = (uchar) stack->o_skip;",
5717
	"#else",
5718
	"	char *oi;",
5719
	"	#ifdef V_TRIX",
5720
	"		printf(\"%%4d: p_restor %%d\\n\", depth, h);",
5721
	"	#endif",
5722
	"#endif",
5723
	"#ifndef XUSAFE",
5724
	"	p_name[h] = stack->o_name;",
5725
	"#endif",
5726
	"#ifdef TRIX",
5727
	"	vsize += sizeof(char *);",
5728
	"	#ifndef BFS",
5729
	"		if (processes[h] != NULL || freebodies == NULL)",
5730
	"		{	Uerror(\"processes error\");",
5731
	"		}",
5732
	"		processes[h] = freebodies;",
5733
	"		freebodies = freebodies->nxt;",
5734
	"		processes[h]->nxt = (TRIX_v6 *) 0;",
5735
	"		processes[h]->modified = 1;	/* p_restor */",
5736
	"	#endif",
5737
	"	processes[h]->parent_pid = stack->parent;",
5738
	"	processes[h]->psize = stack->o_delta;",
5739
	"	memcpy((char *)pptr(h), stack->b_ptr, stack->o_delta);",
5740
	"	oi = stack->b_ptr;",
5741
	"#else",
5742
	"	#ifndef NOCOMP",
5743
	"	for (i = vsize + stack->o_skip; i > vsize; i--)",
5744
	"		Mask[i-1] = 1; /* align */",
5745
	"	#endif",
5746
	"	vsize += stack->o_skip;",
5747
	"	memcpy(z+vsize, stack->body, stack->o_delta);",
5748
	"	vsize += stack->o_delta;",
5749
	"	#ifndef NOCOMP",
5750
	"		for (i = 1; i <= Air[((P0 *)pptr(h))->_t]; i++)",
5751
	"			Mask[vsize - i] = 1;	/* pad */",
5752
	"		Mask[proc_offset[h]] = 1;	/* _pid */",
5753
	"	#endif",
5754
	"	if (BASE > 0 && h > 0)",
5755
	"		((P0 *)pptr(h))->_pid = h-BASE;",
5756
	"	else",
5757
	"		((P0 *)pptr(h))->_pid = h;",
5758
	"#endif",
5759
	"	now._nr_pr += 1;",
5760
	"#ifndef NOVSZ",
5761
	"	now._vsz = vsize;",
5762
	"#endif",
5763
	"	i = stack->o_delqs;",
5764
	"	if (!stack->lst)",
5765
	"		Uerror(\"error: p_restor\");",
5766
	"	stack = stack->lst;",
5767
	"	this = pptr(h);",
5768
	"	while (i-- > 0)",
5769
	"		q_restor();",
5770
	"#ifdef TRIX",
5771
	"	re_mark_all(1);	/* p_restor - all chans move up in _ids_ */",
5772
	"	now._ids_[h] = oi; /* restor the original contents */",
5773
	"#endif",
5774
	"}\n",
5775
	"void",
5776
	"q_restor(void)",
5777
	"{	int h = now._nr_qs;",
5778
	"#ifdef TRIX",
5779
	"	#ifdef V_TRIX",
5780
	"		printf(\"%%4d: q_restor %%d\\n\", depth, h);",
5781
	"	#endif",
5782
	"	vsize += sizeof(char *);",
5783
	"	#ifndef BFS",
5784
	"		if (channels[h] != NULL || freebodies == NULL)",
5785
	"		{	Uerror(\"channels error\");",
5786
	"		}",
5787
	"		channels[h] = freebodies;",
5788
	"		freebodies = freebodies->nxt;",
5789
	"		channels[h]->nxt = (TRIX_v6 *) 0;",
5790
	"		channels[h]->modified = 1;	/* q_restor */",
5791
	"	#endif",
5792
	"	channels[h]->parent_pid = stack->parent;",
5793
	"	channels[h]->psize = stack->o_delta;",
5794
	"	memcpy((char *)qptr(h), stack->b_ptr, stack->o_delta);",
5795
	"	now._ids_[now._nr_pr + h] = stack->b_ptr;",
5796
	"#else",
5797
	"	char *z = (char *) &now;",
5798
	"	#ifndef NOCOMP",
5799
	"		int k, k_end;",
5800
	"	#endif",
5801
	"	q_offset[h] = stack->o_offset;",
5802
	"	q_skip[h]   = (uchar) stack->o_skip;",
5803
	"	vsize += stack->o_skip;",
5804
	"	memcpy(z+vsize, stack->body, stack->o_delta);",
5805
	"	vsize += stack->o_delta;",
5806
	"#endif",
5807
	"#ifndef XUSAFE",
5808
	"	q_name[h] = stack->o_name;",
5809
	"#endif",
5810
	"#ifndef NOVSZ",
5811
	"	now._vsz = vsize;",
5812
	"#endif",
5813
	"	now._nr_qs += 1;",
5814
	"#ifndef NOCOMP",
5815
	"#ifndef TRIX",
5816
	"	k_end = stack->o_offset;",
5817
	"	k = k_end - stack->o_skip;",
5818
	"	#if SYNC",
5819
	"	#ifndef BFS",
5820
	"		if (q_zero(now._nr_qs)) k_end += stack->o_delta;",
5821
	"	#endif",
5822
	"	#endif",
5823
	"	for ( ; k < k_end; k++)",
5824
	"		Mask[k] = 1;",
5825
	"#endif",
5826
	"#endif",
5827
	"	if (!stack->lst)",
5828
	"		Uerror(\"error: q_restor\");",
5829
	"	stack = stack->lst;",
5830
	"}",
5831
 
5832
	"typedef struct IntChunks {",
5833
	"	int	*ptr;",
5834
	"	struct	IntChunks *nxt;",
5835
	"} IntChunks;",
5836
	"IntChunks *filled_chunks[512];",
5837
	"IntChunks *empty_chunks[512];",
5838
 
5839
	"int *",
5840
	"grab_ints(int nr)",
5841
	"{	IntChunks *z;",
5842
	"	if (nr >= 512) Uerror(\"cannot happen grab_int\");",
5843
	"	if (filled_chunks[nr])",
5844
	"	{	z = filled_chunks[nr];",
5845
	"		filled_chunks[nr] = filled_chunks[nr]->nxt;",
5846
	"	} else ",
5847
	"	{	z = (IntChunks *) emalloc(sizeof(IntChunks));",
5848
	"		z->ptr = (int *) emalloc(nr * sizeof(int));",
5849
	"	}",
5850
	"	z->nxt = empty_chunks[nr];",
5851
	"	empty_chunks[nr] = z;",
5852
	"	return z->ptr;",
5853
	"}",
5854
	"void",
5855
	"ungrab_ints(int *p, int nr)",
5856
	"{	IntChunks *z;",
5857
	"	if (!empty_chunks[nr]) Uerror(\"cannot happen ungrab_int\");",
5858
	"	z = empty_chunks[nr];",
5859
	"	empty_chunks[nr] = empty_chunks[nr]->nxt;",
5860
	"	z->ptr = p;",
5861
	"	z->nxt = filled_chunks[nr];",
5862
	"	filled_chunks[nr] = z;",
5863
	"}",
5864
	"int",
5865
	"delproc(int sav, int h)",
5866
	"{	int d, i=0;",
5867
	"#ifndef NOCOMP",
5868
	"	int o_vsize = vsize;",
5869
	"#endif",
5870
	"	if (h+1 != (int) now._nr_pr)",
5871
	"	{	return 0;",
5872
	"	}",
5873
	"#ifdef TRIX",
5874
	"	#ifdef V_TRIX",
5875
	"		printf(\"%%4d: delproc %%d -- parent %%d\\n\", depth, h, processes[h]->parent_pid);",
5876
	"		if (now._nr_qs > 0)",
5877
	"		printf(\"	top channel: %%d -- parent %%d\\n\", now._nr_qs-1, channels[now._nr_qs-1]->parent_pid);",
5878
	"	#endif",
5879
	"	while (now._nr_qs > 0",
5880
	"	&&     channels[now._nr_qs-1]->parent_pid == processes[h]->parent_pid)",
5881
	"	{	delq(sav);",
5882
	"		i++;",
5883
	"	}",
5884
	"	d = processes[h]->psize;",
5885
	"	if (sav)",
5886
	"	{	if (!stack->nxt)",
5887
	"		{	stack->nxt = (_Stack *) emalloc(sizeof(_Stack));",
5888
	"			stack->nxt->lst = stack;",
5889
	"			smax++;",
5890
	"		}",
5891
	"		stack = stack->nxt;",
5892
	"	#ifndef XUSAFE",
5893
	"		stack->o_name   = p_name[h];",
5894
	"	#endif",
5895
	"		stack->parent   = processes[h]->parent_pid;",
5896
	"		stack->o_delta  = d;",
5897
	"		stack->o_delqs  = i;",
5898
	"		stack->b_ptr = now._ids_[h];", /* new 6.1 */
5899
	"	}",
5900
	"	memset((char *)pptr(h), 0, d);",
5901
	"	#ifndef BFS",
5902
	"		processes[h]->nxt = freebodies;",
5903
	"		freebodies = processes[h];",
5904
	"		processes[h] = (TRIX_v6 *) 0;",
5905
	"	#endif",
5906
	"	vsize -= sizeof(char *);",
5907
	"	now._nr_pr -= 1;",
5908
	"	re_mark_all(-1); /* delproc - all chans move down in _ids_ */",
5909
	"#else",
5910
	"	while (now._nr_qs",
5911
	"	&&     q_offset[now._nr_qs-1] > proc_offset[h])",
5912
	"	{	delq(sav);",
5913
	"		i++;",
5914
	"	}",
5915
	"	d = vsize - proc_offset[h];",
5916
	"	if (sav)",
5917
	"	{	if (!stack->nxt)",
5918
	"		{	stack->nxt = (_Stack *) emalloc(sizeof(_Stack));",
5919
	"			stack->nxt->body = emalloc(Maxbody * sizeof(char));",
5920
	"			stack->nxt->lst = stack;",
5921
	"			smax++;",
5922
	"		}",
5923
	"		stack = stack->nxt;",
5924
	"		stack->o_offset = proc_offset[h];",
5925
	"	#if VECTORSZ>32000",
5926
	"		stack->o_skip   = (int) proc_skip[h];",
5927
	"	#else",
5928
	"		stack->o_skip   = (short) proc_skip[h];",
5929
	"	#endif",
5930
	"	#ifndef XUSAFE",
5931
	"		stack->o_name   = p_name[h];",
5932
	"	#endif",
5933
	"		stack->o_delta  = d;",
5934
	"		stack->o_delqs  = i;",
5935
	"		memcpy(stack->body, (char *)pptr(h), d);",
5936
	"	}",
5937
	"	vsize = proc_offset[h];",
5938
	"	now._nr_pr -= 1;",
5939
	"	memset((char *)pptr(h), 0, d);",
5940
	"	vsize -= (int) proc_skip[h];",
5941
	"	#ifndef NOCOMP",
5942
	"	for (i = vsize; i < o_vsize; i++)",
5943
	"		Mask[i] = 0; /* reset */",
5944
	"	#endif",
5945
	"#endif",
5946
	"#ifndef NOVSZ",
5947
	"	now._vsz = vsize;",
5948
	"#endif",
5949
	"	return 1;",
5950
	"}\n",
5951
	"void",
5952
	"delq(int sav)",
5953
	"{	int h = now._nr_qs - 1;",
5954
	"#ifdef TRIX",
5955
	"	int d = channels[now._nr_qs - 1]->psize;",
5956
	"#else",
5957
	"	int d = vsize - q_offset[now._nr_qs - 1];",
5958
	"#endif",
5959
	"#ifndef NOCOMP",
5960
	"	int k, o_vsize = vsize;",
5961
	"#endif",
5962
	"	if (sav)",
5963
	"	{	if (!stack->nxt)",
5964
	"		{	stack->nxt = (_Stack *) emalloc(sizeof(_Stack));",
5965
	"#ifndef TRIX",
5966
	"			stack->nxt->body = emalloc(Maxbody * sizeof(char));",
5967
	"#endif",
5968
	"			stack->nxt->lst = stack;",
5969
	"			smax++;",
5970
	"		}",
5971
	"		stack = stack->nxt;",
5972
	"#ifdef TRIX",
5973
	"		stack->parent = channels[h]->parent_pid;",
5974
	"		stack->b_ptr = now._ids_[h];", /* new 6.1 */
5975
	"#else",
5976
	"		stack->o_offset = q_offset[h];",
5977
	"	#if VECTORSZ>32000",
5978
	"		stack->o_skip   = (int) q_skip[h];",
5979
	"	#else",
5980
	"		stack->o_skip   = (short) q_skip[h];",
5981
	"	#endif",
5982
	"#endif",
5983
	"	#ifndef XUSAFE",
5984
	"		stack->o_name   = q_name[h];",
5985
	"	#endif",
5986
	"		stack->o_delta  = d;",
5987
	"#ifndef TRIX",
5988
	"		memcpy(stack->body, (char *)qptr(h), d);",
5989
	"#endif",
5990
	"	}",
5991
	"#ifdef TRIX",
5992
	"	vsize -= sizeof(char *);",
5993
	"	#ifdef V_TRIX",
5994
	"		printf(\"%%4d: delq %%d parent %%d\\n\", depth, h, channels[h]->parent_pid);",
5995
	"	#endif",
5996
	"#else",
5997
	"	vsize = q_offset[h];",
5998
	"	vsize -= (int) q_skip[h];",
5999
	"	#ifndef NOCOMP",
6000
	"		for (k = vsize; k < o_vsize; k++)",
6001
	"			Mask[k] = 0; /* reset */",
6002
	"	#endif",
6003
	"#endif",
6004
	"	now._nr_qs -= 1;",
6005
	"	memset((char *)qptr(h), 0, d);",
6006
	"#ifdef TRIX",
6007
	"	#ifndef BFS",
6008
	"		channels[h]->nxt = freebodies;",
6009
	"		freebodies = channels[h];",
6010
	"		channels[h] = (TRIX_v6 *) 0;",
6011
	"	#endif",
6012
	"#endif",
6013
	"#ifndef NOVSZ",
6014
	"	now._vsz = vsize;",
6015
	"#endif",
6016
	"}\n",
6017
	"int",
6018
	"qs_empty(void)",
6019
	"{	int i;",
6020
	"	for (i = 0; i < (int) now._nr_qs; i++)",
6021
	"	{	if (q_sz(i) > 0)",
6022
	"			return 0;",
6023
	"	}",
6024
	"	return 1;",
6025
	"}\n",
6026
	"int",
6027
	"endstate(void)",
6028
	"{	int i; P0 *ptr;",
6029
	"	for (i = BASE; i < (int) now._nr_pr; i++)",
6030
	"	{	ptr = (P0 *) pptr(i);",
6031
	"		if (!stopstate[ptr->_t][ptr->_p])",
6032
	"			return 0;",
6033
	"	}",
6034
	"	if (strict) return qs_empty();",
6035
	"#if defined(EVENT_TRACE) && !defined(OTIM)",
6036
	"	if (!stopstate[EVENT_TRACE][now._event] && !a_cycles)",
6037
	"	{	printf(\"pan: event_trace not completed\\n\");",
6038
	"		return 0;",
6039
	"	}",
6040
	"#endif",
6041
	"	return 1;",
6042
	"}\n",
6043
	"#ifndef SAFETY",
6044
	"void",
6045
	"checkcycles(void)",
6046
	"{	uchar o_a_t = now._a_t;",
6047
	"#ifndef NOFAIR",
6048
	"	uchar o_cnt = now._cnt[1];",
6049
	"#endif",
6050
		"#ifdef FULLSTACK",
6051
		"#ifndef MA",
6052
	"	struct H_el *sv = trpt->ostate; /* save */",
6053
		"#else",
6054
	"	uchar prov = trpt->proviso; /* save */",
6055
		"#endif",
6056
		"#endif",
6057
		"#ifdef DEBUG",
6058
	"	{ int i; uchar *v = (uchar *) &now;",
6059
	"	  printf(\"	set Seed state \");",
6060
	"#ifndef NOFAIR",
6061
	"	  if (fairness) printf(\"(cnt = %%d:%%d, nrpr=%%d) \",",
6062
	"		now._cnt[0], now._cnt[1], now._nr_pr);",
6063
	"#endif",
6064
	"	/* for (i = 0; i < n; i++) printf(\"%%d,\", v[i]);	*/",
6065
	"	  printf(\"\\n\");",
6066
	"	}",
6067
	"	printf(\"%%ld: cycle check starts\\n\", depth);",
6068
		"#endif",
6069
	"	now._a_t |= (1|16|32);",
6070
	"	/* 1 = 2nd DFS; (16|32) to help hasher */",
6071
	"#ifndef NOFAIR",
6072
	"	now._cnt[1] = now._cnt[0];",
6073
	"#endif",
6074
	"	memcpy((char *)&A_Root, (char *)&now, vsize);",
6075
	"	A_depth = depthfound = depth;",
6076
 
6077
	"#if NCORE>1",
6078
	"	mem_put_acc();", /* handoff accept states */
6079
	"#else",
6080
	"	new_state();	/* start 2nd DFS */",
6081
	"#endif",
6082
 
6083
	"	now._a_t = o_a_t;",
6084
	"#ifndef NOFAIR",
6085
	"	now._cnt[1] = o_cnt;",
6086
	"#endif",
6087
	"	A_depth = 0; depthfound = -1;",
6088
		"#ifdef DEBUG",
6089
	"	printf(\"%%ld: cycle check returns\\n\", depth);",
6090
		"#endif",
6091
		"#ifdef FULLSTACK",
6092
		"#ifndef MA",
6093
	"	trpt->ostate = sv;	/* restore */",
6094
		"#else",
6095
	"	trpt->proviso = prov;",
6096
		"#endif",
6097
		"#endif",
6098
	"}",
6099
	"#endif\n",
6100
	"#if defined(FULLSTACK) && defined(BITSTATE)",
6101
	"struct H_el *Free_list = (struct H_el *) 0;",
6102
	"void",
6103
	"onstack_init(void)	/* to store stack states in a bitstate search */",
6104
	"{	S_Tab = (struct H_el **) emalloc(maxdepth*sizeof(struct H_el *));",
6105
	"}",
6106
	"struct H_el *",
6107
	"grab_state(int n)",
6108
	"{	struct H_el *v, *last = 0;",
6109
	"	if (H_tab == S_Tab)",
6110
	"	{	for (v = Free_list; v && ((int) v->tagged >= n); v=v->nxt)",
6111
	"		{	if ((int) v->tagged == n)",
6112
	"			{	if (last)",
6113
	"					last->nxt = v->nxt;",
6114
	"				else",
6115
	"gotcha:				Free_list = v->nxt;",
6116
	"				v->tagged = 0;",
6117
	"				v->nxt = 0;",
6118
		"#ifdef COLLAPSE",
6119
	"				v->ln = 0;",
6120
		"#endif",
6121
	"				return v;",
6122
	"			}",
6123
	"			Fh++; last=v;",
6124
	"		}",
6125
	"		/* new: second try */",
6126
	"		v = Free_list;", /* try to avoid emalloc */
6127
	"		if (v && ((int) v->tagged >= n))",
6128
	"			goto gotcha;",
6129
	"		ngrabs++;",
6130
	"	}",
6131
	"	return (struct H_el *)",
6132
	"	      emalloc(sizeof(struct H_el)+n-sizeof(unsigned));",
6133
	"}\n",
6134
	"#else",
6135
 
6136
	"#if NCORE>1",
6137
	"struct H_el *",
6138
	"grab_state(int n)",
6139
	"{	struct H_el *grab_shared(int);",
6140
	"	return grab_shared(sizeof(struct H_el)+n-sizeof(unsigned));",
6141
	"}",
6142
	"#else",
6143
	" #ifndef AUTO_RESIZE",
6144
	"  #define grab_state(n) (struct H_el *) \\",
6145
	"		emalloc(sizeof(struct H_el)+n-sizeof(unsigned long));",
6146
	" #else",
6147
	"  struct H_el *",
6148
	"  grab_state(int n)",
6149
	"  {	struct H_el *p;",
6150
	"	int cnt = sizeof(struct H_el)+n-sizeof(unsigned long);",
6151
	"",
6152
	"	if (reclaim_size >= cnt+WS)",
6153
	"	{	if ((cnt & (WS-1)) != 0) /* alignment */",
6154
	"		{	cnt += WS - (cnt & (WS-1));",
6155
	"		}",
6156
	"		p = (struct H_el *) reclaim_mem;",
6157
	"		reclaim_mem  += cnt;",
6158
	"		reclaim_size -= cnt;",
6159
	"		memset(p, 0, cnt);",
6160
	"	} else",
6161
	"	{	p = (struct H_el *) emalloc(cnt);",
6162
	"	}",
6163
	"	return p;",
6164
	"  }",
6165
	" #endif",
6166
	"#endif",
6167
 
6168
	"#endif",
6169
"#ifdef COLLAPSE",
6170
	"unsigned long",
6171
	"ordinal(char *v, long n, short tp)",
6172
	"{	struct H_el *tmp, *ntmp; long m;",
6173
	"	struct H_el *olst = (struct H_el *) 0;",
6174
	"	s_hash((uchar *)v, n);",
6175
 
6176
	"#if NCORE>1 && !defined(SEP_STATE)",
6177
	"	enter_critical(CS_ID);	/* uses spinlock - 1..128 */",
6178
	"#endif",
6179
	"	tmp = H_tab[j1_spin];",
6180
	"	if (!tmp)",
6181
	"	{	tmp = grab_state(n);",
6182
	"		H_tab[j1_spin] = tmp;",
6183
	"	} else",
6184
	"	for ( ;; olst = tmp, tmp = tmp->nxt)",
6185
	"	{	if (n == tmp->ln)",
6186
	"		{	m = memcmp(((char *)&(tmp->state)), v, n);",
6187
	"			if (m == 0)",
6188
	"				goto done;",
6189
	"			if (m < 0)",
6190
	"			{",
6191
	"Insert:			ntmp = grab_state(n);",
6192
	"				ntmp->nxt = tmp;",
6193
	"				if (!olst)",
6194
	"					H_tab[j1_spin] = ntmp;",
6195
	"				else",
6196
	"					olst->nxt = ntmp;",
6197
	"				tmp = ntmp;",
6198
	"				break;",
6199
	"			} else if (!tmp->nxt)",
6200
	"			{",
6201
	"Append:			tmp->nxt = grab_state(n);",
6202
	"				tmp = tmp->nxt;",
6203
	"				break;",
6204
	"			}",
6205
	"			continue;",
6206
	"		}",
6207
	"		if (n < tmp->ln)",
6208
	"			goto Insert;",
6209
	"		else if (!tmp->nxt)",
6210
	"			goto Append;",
6211
	"	}",
6212
	"#if NCORE>1 && !defined(SEP_STATE)",
6213
	"	enter_critical(GLOBAL_LOCK);",
6214
	"#endif",
6215
	"	m = ++ncomps[tp];",
6216
	"#if NCORE>1 && !defined(SEP_STATE)",
6217
	"	leave_critical(GLOBAL_LOCK);",
6218
	"#endif",
6219
	"#ifdef FULLSTACK",
6220
	"	tmp->tagged = m;",
6221
	"#else",
6222
	"	tmp->st_id  = m;",
6223
	"#endif",
6224
	"#if defined(AUTO_RESIZE) && !defined(BITSTATE)",
6225
	"	tmp->m_K1 = K1;",
6226
	"#endif",
6227
	"	memcpy(((char *)&(tmp->state)), v, n);",
6228
	"	tmp->ln = n;",
6229
	"done:",
6230
 
6231
	"#if NCORE>1 && !defined(SEP_STATE)",
6232
	"	leave_critical(CS_ID);	/* uses spinlock */",
6233
	"#endif",
6234
 
6235
	"#ifdef FULLSTACK",
6236
	"	return tmp->tagged;",
6237
	"#else",
6238
	"	return tmp->st_id;",
6239
	"#endif",
6240
	"}",
6241
	"",
6242
	"int",
6243
	"compress(char *vin, int nin)	/* collapse compression */",
6244
	"{	char	*w, *v = (char *) &comp_now;",
6245
	"	int	i, j;",
6246
	"	unsigned long	n;",
6247
	"	static char	*x;",
6248
	"	static uchar	nbytes[513]; /* 1 + 256 + 256 */",
6249
	"	static unsigned	short nbytelen;",
6250
	"	long col_q(int, char *);",
6251
	"	long col_p(int, char *);",
6252
	"#ifndef SAFETY",
6253
	"	if (a_cycles)",
6254
	"		*v++ = now._a_t;",
6255
		"#ifndef NOFAIR",
6256
	"	if (fairness)",
6257
	"	for (i = 0; i < NFAIR; i++)",
6258
	"		*v++ = now._cnt[i];",
6259
		"#endif",
6260
	"#endif",
6261
	"	nbytelen = 0;",
6262
 
6263
	"#ifndef JOINPROCS",
6264
	"	for (i = 0; i < (int) now._nr_pr; i++)",
6265
	"	{	n = col_p(i, (char *) 0);",
6266
	"#ifdef NOFIX",
6267
	"		nbytes[nbytelen] = 0;",
6268
	"#else",
6269
	"		nbytes[nbytelen] = 1;",
6270
	"		*v++ = ((P0 *) pptr(i))->_t;",
6271
	"#endif",
6272
	"		*v++ = n&255;",
6273
	"		if (n >= (1<<8))",
6274
	"		{	nbytes[nbytelen]++;",
6275
	"			*v++ = (n>>8)&255;",
6276
	"		}",
6277
	"		if (n >= (1<<16))",
6278
	"		{	nbytes[nbytelen]++;",
6279
	"			*v++ = (n>>16)&255;",
6280
	"		}",
6281
	"		if (n >= (1<<24))",
6282
	"		{	nbytes[nbytelen]++;",
6283
	"			*v++ = (n>>24)&255;",
6284
	"		}",
6285
	"		nbytelen++;",
6286
	"	}",
6287
	"#else",
6288
	"	x = scratch;",
6289
	"	for (i = 0; i < (int) now._nr_pr; i++)",
6290
	"		x += col_p(i, x);",
6291
	"	n = ordinal(scratch, x-scratch, 2); /* procs */",
6292
	"	*v++ = n&255;",
6293
	"	nbytes[nbytelen] = 0;",
6294
	"	if (n >= (1<<8))",
6295
	"	{	nbytes[nbytelen]++;",
6296
	"		*v++ = (n>>8)&255;",
6297
	"	}",
6298
	"	if (n >= (1<<16))",
6299
	"	{	nbytes[nbytelen]++;",
6300
	"		*v++ = (n>>16)&255;",
6301
	"	}",
6302
	"	if (n >= (1<<24))",
6303
	"	{	nbytes[nbytelen]++;",
6304
	"		*v++ = (n>>24)&255;",
6305
	"	}",
6306
	"	nbytelen++;",
6307
	"#endif",
6308
	"#ifdef SEPQS",
6309
	"	for (i = 0; i < (int) now._nr_qs; i++)",
6310
	"	{	n = col_q(i, (char *) 0);",
6311
	"		nbytes[nbytelen] = 0;",
6312
	"		*v++ = n&255;",
6313
	"		if (n >= (1<<8))",
6314
	"		{	nbytes[nbytelen]++;",
6315
	"			*v++ = (n>>8)&255;",
6316
	"		}",
6317
	"		if (n >= (1<<16))",
6318
	"		{	nbytes[nbytelen]++;",
6319
	"			*v++ = (n>>16)&255;",
6320
	"		}",
6321
	"		if (n >= (1<<24))",
6322
	"		{	nbytes[nbytelen]++;",
6323
	"			*v++ = (n>>24)&255;",
6324
	"		}",
6325
	"		nbytelen++;",
6326
	"	}",
6327
	"#endif",
6328
 
6329
	"#ifdef NOVSZ",
6330
	"	/* 3 = _a_t, _nr_pr, _nr_qs */",
6331
	"	w = (char *) &now + 3 * sizeof(uchar);",
6332
		"#ifndef NOFAIR",
6333
		"	w += NFAIR;",
6334
		"#endif",
6335
	"#else",
6336
		"#if VECTORSZ<65536",
6337
		"	w = (char *) &(now._vsz) + sizeof(unsigned short);",
6338
		"#else",
6339
		"	w = (char *) &(now._vsz) + sizeof(unsigned long);",
6340
		"#endif",
6341
	"#endif",
6342
	"	x = scratch;",
6343
	"	*x++ = now._nr_pr;",
6344
	"	*x++ = now._nr_qs;",
6345
 
6346
	"	if (now._nr_qs > 0 && qptr(0) < pptr(0))",
6347
	"		n = qptr(0) - (uchar *) w;",
6348
	"	else",
6349
	"		n = pptr(0) - (uchar *) w;",
6350
	"	j = w - (char *) &now;",
6351
	"	for (i = 0; i < (int) n; i++, w++)",
6352
	"		if (!Mask[j++]) *x++ = *w;",
6353
	"#ifndef SEPQS",
6354
	"	for (i = 0; i < (int) now._nr_qs; i++)",
6355
	"		x += col_q(i, x);",
6356
	"#endif",
6357
 
6358
	"	x--;",
6359
	"	for (i = 0, j = 6; i < nbytelen; i++)",
6360
	"	{	if (j == 6)",
6361
	"		{	j = 0;",
6362
	"			*(++x) = 0;",
6363
	"		} else",
6364
	"			j += 2;",
6365
	"		*x |= (nbytes[i] << j);",
6366
	"	}",
6367
	"	x++;",
6368
	"	for (j = 0; j < WS-1; j++)",
6369
	"		*x++ = 0;",
6370
	"	x -= j; j = 0;",
6371
	"	n = ordinal(scratch, x-scratch, 0); /* globals */",
6372
	"	*v++ = n&255;",
6373
	"	if (n >= (1<< 8)) { *v++ = (n>> 8)&255; j++; }",
6374
	"	if (n >= (1<<16)) { *v++ = (n>>16)&255; j++; }",
6375
	"	if (n >= (1<<24)) { *v++ = (n>>24)&255; j++; }",
6376
	"	*v++ = j;	/* add last count as a byte */",
6377
 
6378
	"	for (i = 0; i < WS-1; i++)",
6379
	"		*v++ = 0;",
6380
	"	v -= i;",
6381
	"#if 0",
6382
	"	printf(\"collapse %%d -> %%d\\n\",",
6383
	"		vsize, v - (char *)&comp_now);",
6384
	"#endif",
6385
	"	return v - (char *)&comp_now;",
6386
	"}",
6387
 
6388
"#else",
6389
"#if !defined(NOCOMP)",
6390
	"int",
6391
	"compress(char *vin, int n)	/* default compression */",
6392
	"{",
6393
	"#ifdef HC",
6394
	"	int delta = 0;",
6395
	"	s_hash((uchar *)vin, n); /* sets K1 and K2 */",
6396
		"#ifndef SAFETY",
6397
	"	if (S_A)",
6398
	"	{	delta++;	/* _a_t  */",
6399
			"#ifndef NOFAIR",
6400
	"		if (S_A > NFAIR)",
6401
	"			delta += NFAIR;	/* _cnt[] */",
6402
			"#endif",
6403
	"	}",
6404
		"#endif",
6405
	"	memcpy((char *) &comp_now + delta, (char *) &K1, WS);",
6406
	"	delta += WS;",
6407
		"#if HC>0",
6408
	"	memcpy((char *) &comp_now + delta, (char *) &K2, HC);",
6409
	"	delta += HC;",
6410
		"#endif",
6411
	"	return delta;",
6412
	"#else",
6413
	"	char *vv = vin;",
6414
	"	char *v = (char *) &comp_now;",
6415
	"	int i;",
6416
	"  #ifndef NO_FAST_C", /* disable faster compress */
6417
	"	int r = 0, unroll = n/8;", /* most sv are much longer */
6418
	"	if (unroll > 0)",
6419
	"	{	i = 0;",
6420
	"		while (r++ < unroll)",
6421
	"		{	/* unroll 8 times, avoid ifs */",
6422
	"	/* 1 */		*v = *vv++; v += 1 - Mask[i++];",
6423
	"	/* 2 */		*v = *vv++; v += 1 - Mask[i++];",
6424
	"	/* 3 */		*v = *vv++; v += 1 - Mask[i++];",
6425
	"	/* 4 */		*v = *vv++; v += 1 - Mask[i++];",
6426
	"	/* 5 */		*v = *vv++; v += 1 - Mask[i++];",
6427
	"	/* 6 */		*v = *vv++; v += 1 - Mask[i++];",
6428
	"	/* 7 */		*v = *vv++; v += 1 - Mask[i++];",
6429
	"	/* 8 */		*v = *vv++; v += 1 - Mask[i++];",
6430
	"		}",
6431
	"		r = n - i; /* the rest, at most 7 */",
6432
	"		switch (r) {",
6433
	"		case 7: *v = *vv++; v += 1 - Mask[i++];",
6434
	"		case 6: *v = *vv++; v += 1 - Mask[i++];",
6435
	"		case 5: *v = *vv++; v += 1 - Mask[i++];",
6436
	"		case 4: *v = *vv++; v += 1 - Mask[i++];",
6437
	"		case 3: *v = *vv++; v += 1 - Mask[i++];",
6438
	"		case 2: *v = *vv++; v += 1 - Mask[i++];",
6439
	"		case 1: *v = *vv++; v += 1 - Mask[i++];",
6440
	"		case 0: break;",
6441
	"		}",
6442
	"#if 1",
6443
	"		n = i = v - (char *)&comp_now; /* bytes written so far */",
6444
	"#endif",
6445
	"		r = (n+WS-1)/WS; /* in words, rounded up */",
6446
	"		r *= WS;	 /* total bytes to fill  */",
6447
	"		i = r - i;	 /* remaining bytes      */",
6448
	"		switch (i) {",   /* fill word */
6449
	"		case 7: *v++ = 0;    /* fall thru */",
6450
	"		case 6: *v++ = 0;",
6451
	"		case 5: *v++ = 0;",
6452
	"		case 4: *v++ = 0;",
6453
	"		case 3: *v++ = 0;",
6454
	"		case 2: *v++ = 0;",
6455
	"		case 1: *v++ = 0;",
6456
	"		case 0: break;",
6457
	"		default: Uerror(\"unexpected wordsize\");",
6458
	"		}",
6459
	"		v -= i;",
6460
	"	} else",
6461
	"  #endif",
6462
	"	{	for (i = 0; i < n; i++, vv++)",
6463
	"			if (!Mask[i]) *v++ = *vv;",
6464
	"		for (i = 0; i < WS-1; i++)",
6465
	"			*v++ = 0;",
6466
	"		v -= i;",
6467
	"	}",
6468
		"#if 0",
6469
	"	printf(\"compress %%d -> %%d\\n\",",
6470
	"		n, v - (char *)&comp_now);",
6471
		"#endif",
6472
	"	return v - (char *)&comp_now;",
6473
	"#endif",
6474
	"}",
6475
"#endif",
6476
"#endif",
6477
	"#if defined(FULLSTACK) && defined(BITSTATE)",
6478
"#if defined(MA)",
6479
	"#if !defined(onstack_now)",
6480
	"int  onstack_now(void) {}", /* to suppress compiler errors */
6481
	"#endif",
6482
	"#if !defined(onstack_put)",
6483
	"void onstack_put(void) {}", /* for this invalid combination */
6484
	"#endif",
6485
	"#if !defined(onstack_zap)",
6486
	"void onstack_zap(void) {}", /* of directives */
6487
	"#endif",
6488
"#else",
6489
	"void",
6490
	"onstack_zap(void)",
6491
	"{	struct H_el *v, *w, *last = 0;",
6492
	"	struct H_el **tmp = H_tab;",
6493
	"	char *nv; int n, m;",
6494
	"	static char warned = 0;",
6495
	"#if defined(BCS) && defined(NO_LAST) && defined(HAS_LAST)",
6496
	"	uchar was_last = now._last;",
6497
	"	now._last = 0;",
6498
	"#endif",
6499
	"",
6500
	"	H_tab = S_Tab;",
6501
	"#ifndef NOCOMP",
6502
	"	nv = (char *) &comp_now;",
6503
	"	n = compress((char *)&now, vsize);",
6504
	"#else",
6505
		"#if defined(BITSTATE) && defined(LC)",
6506
	"	nv = (char *) &comp_now;",
6507
	"	n = compact_stack((char *)&now, vsize);",
6508
		"#else",
6509
	"	nv = (char *) &now;",
6510
	"	n = vsize;",
6511
		"#endif",
6512
	"#endif",
6513
	"#if !defined(HC) && !(defined(BITSTATE) && defined(LC))",
6514
	"	s_hash((uchar *)nv, n);",
6515
	"#endif",
6516
	"	H_tab = tmp;",
6517
	"	for (v = S_Tab[j1_spin]; v; Zh++, last=v, v=v->nxt)",
6518
	"	{	m = memcmp(&(v->state), nv, n);",
6519
	"		if (m == 0)",
6520
	"			goto Found;",
6521
	"		if (m < 0)",
6522
	"			break;",
6523
	"	}",
6524
	"/* NotFound: */",
6525
	"#ifndef ZAPH",
6526
	"	/* seen this happen, likely harmless in multicore */",
6527
	"	if (warned == 0)",
6528
	"	{	/* Uerror(\"stack out of wack - zap\"); */",
6529
	"		cpu_printf(\"pan: warning, stack incomplete\\n\");",
6530
	"		warned = 1;",
6531
	"	}",
6532
	"#endif",
6533
	"	goto done;",
6534
	"Found:",
6535
	"	ZAPS++;",
6536
	"	if (last)",
6537
	"		last->nxt = v->nxt;",
6538
	"	else",
6539
	"		S_Tab[j1_spin] = v->nxt;",
6540
	"	v->tagged = (unsigned) n;",
6541
	"#if !defined(NOREDUCE) && !defined(SAFETY)",
6542
	"	v->proviso = 0;",
6543
	"#endif",
6544
	"	v->nxt = last = (struct H_el *) 0;",
6545
	"	for (w = Free_list; w; Fa++, last=w, w = w->nxt)",
6546
	"	{	if ((int) w->tagged <= n)",
6547
	"		{	if (last)",
6548
	"			{	v->nxt = w;",
6549
	"				last->nxt = v;",
6550
	"			} else",
6551
	"			{	v->nxt = Free_list;",
6552
	"				Free_list = v;",
6553
	"			}",
6554
	"			goto done;",
6555
	"		}",
6556
	"		if (!w->nxt)",
6557
	"		{	w->nxt = v;",
6558
	"			goto done;",
6559
	"	}	}",
6560
	"	Free_list = v;",
6561
	"done:",
6562
	"#if defined(BCS) && defined(NO_LAST) && defined(HAS_LAST)",
6563
	"	now._last = was_last;",
6564
	"#endif",
6565
	"	return;",
6566
	"}",
6567
	"void",
6568
	"onstack_put(void)",
6569
	"{	struct H_el **tmp = H_tab;",
6570
	"#if defined(BCS) && defined(NO_LAST) && defined(HAS_LAST)",
6571
	"	uchar was_last = now._last;",
6572
	"	now._last = 0;",
6573
	"#endif",
6574
	"	H_tab = S_Tab;",
6575
	"	if (hstore((char *)&now, vsize) != 0)",
6576
	"#if defined(BITSTATE) && defined(LC)",
6577
	"		printf(\"pan: warning, double stack entry\\n\");",
6578
	"#else",
6579
	"	#ifndef ZAPH",
6580
	"		Uerror(\"cannot happen - unstack_put\");",
6581
	"	#endif",
6582
	"#endif",
6583
	"	H_tab = tmp;",
6584
	"	trpt->ostate = Lstate;",
6585
	"	PUT++;",
6586
	"#if defined(BCS) && defined(NO_LAST) && defined(HAS_LAST)",
6587
	"	now._last = was_last;",
6588
	"#endif",
6589
	"}",
6590
	"int",
6591
	"onstack_now(void)",
6592
	"{	struct H_el *tmp;",
6593
	"	struct H_el **tmp2 = H_tab;",
6594
	"	char *v; int n, m = 1;\n",
6595
	"#if defined(BCS) && defined(NO_LAST) && defined(HAS_LAST)",
6596
	"	uchar was_last = now._last;",
6597
	"	now._last = 0;",
6598
	"#endif",
6599
	"	H_tab = S_Tab;",
6600
	"#ifdef NOCOMP",
6601
		"#if defined(BITSTATE) && defined(LC)",
6602
	"	v = (char *) &comp_now;",
6603
	"	n = compact_stack((char *)&now, vsize);",
6604
		"#else",
6605
	"	v = (char *) &now;",
6606
	"	n = vsize;",
6607
		"#endif",
6608
	"#else",
6609
	"	v = (char *) &comp_now;",
6610
	"	n = compress((char *)&now, vsize);",
6611
	"#endif",
6612
	"#if !defined(HC) && !(defined(BITSTATE) && defined(LC))",
6613
	"	s_hash((uchar *)v, n);",
6614
	"#endif",
6615
	"	H_tab = tmp2;",
6616
	"	for (tmp = S_Tab[j1_spin]; tmp; Zn++, tmp = tmp->nxt)",
6617
	"	{	m = memcmp(((char *)&(tmp->state)),v,n);",
6618
	"		if (m <= 0)",
6619
	"		{	Lstate = (struct H_el *) tmp;",
6620
	"			break;",
6621
	"	}	}",
6622
	"	PROBE++;",
6623
	"#if defined(BCS) && defined(NO_LAST) && defined(HAS_LAST)",
6624
	"	now._last = was_last;",
6625
	"#endif",
6626
	"	return (m == 0);",
6627
	"}",
6628
	"#endif",
6629
"#endif",
6630
 
6631
	"#ifndef BITSTATE",
6632
	"void",
6633
	"hinit(void)",
6634
	"{",
6635
	"  #ifdef MA",
6636
		"#ifdef R_XPT",
6637
		"	{	void r_xpoint(void);",
6638
		"		r_xpoint();",
6639
		"	}",
6640
		"#else",
6641
		"	dfa_init((unsigned short) (MA+a_cycles));",
6642
			"#if NCORE>1 && !defined(COLLAPSE)",
6643
			"	if (!readtrail)",
6644
			"	{	void init_HT(unsigned long);",
6645
			"		init_HT(0L);",
6646
			"	}",
6647
			"#endif",
6648
		"#endif",
6649
	"  #endif",
6650
	"  #if !defined(MA) || defined(COLLAPSE)",
6651
		"#if NCORE>1",
6652
			"	if (!readtrail)",
6653
			"	{	void init_HT(unsigned long);",
6654
			"		init_HT((unsigned long) (ONE_L<<ssize)*sizeof(struct H_el *));",
6655
			"	} else",
6656
		"#endif",
6657
			"	H_tab = (struct H_el **)",
6658
			"		emalloc((ONE_L<<ssize)*sizeof(struct H_el *));",
6659
			"	/* @htable ssize */",
6660
	"  #endif",
6661
	"}",
6662
	"#endif\n",
6663
 
6664
	"#if !defined(BITSTATE) || defined(FULLSTACK)",
6665
 
6666
	"#ifdef DEBUG",
6667
	"void",
6668
	"dumpstate(int wasnew, char *v, int n, int tag)",
6669
	"{	int i;",
6670
	"#ifndef SAFETY",
6671
	"	if (S_A)",
6672
	"	{	printf(\"\tstate tags %%d (%%d::%%d): \",",
6673
	"			V_A, wasnew, v[0]);",
6674
		"#ifdef FULLSTACK",
6675
	"		printf(\" %%d \", tag);",
6676
		"#endif",
6677
	"		printf(\"\\n\");",
6678
	"	}",
6679
	"#endif",
6680
	"#ifdef SDUMP",
6681
	"#ifndef NOCOMP",
6682
	"	printf(\"\t State: \");",
6683
	"	for (i = 0; i < vsize; i++) printf(\"%%d%%s,\",",
6684
	"		((char *)&now)[i], Mask[i]?\"*\":\"\");",
6685
	"#endif",
6686
	"	printf(\"\\n\tVector: \");",
6687
	"	for (i = 0; i < n; i++) printf(\"%%d,\", v[i]);",
6688
	"	printf(\"\\n\");",
6689
	"#endif",
6690
	"}",
6691
	"#endif",
6692
 
6693
"#ifdef MA",
6694
	"int",
6695
	"gstore(char *vin, int nin, uchar pbit)",
6696
	"{	int n, i;",
6697
	"	int ret_val = 1;",
6698
	"	uchar *v;",
6699
	"	static uchar Info[MA+1];",
6700
	"#ifndef NOCOMP",
6701
	"	n = compress(vin, nin);",
6702
	"	v = (uchar *) &comp_now;",
6703
	"#else",
6704
	"	n = nin;",
6705
	"	v = (uchar *) vin;",
6706
	"#endif",
6707
	"	if (n >= MA)",
6708
	"	{	printf(\"pan: error, MA too small, recompile pan.c\");",
6709
	"		printf(\" with -DMA=N with N>%%d\\n\", n);",
6710
	"		Uerror(\"aborting\");",
6711
	"	}",
6712
	"	if (n > (int) maxgs)",
6713
	"	{	maxgs = (unsigned int) n;",
6714
	"	}",
6715
	"	for (i = 0; i < n; i++)",
6716
	"	{	Info[i] = v[i];",
6717
	"	}",
6718
	"	for ( ; i < MA-1; i++)",
6719
	"	{	Info[i] = 0;",
6720
	"	}",
6721
	"	Info[MA-1] = pbit;",
6722
	"	if (a_cycles)	/* place _a_t at the end */",
6723
	"	{	Info[MA] = Info[0];",
6724
	"		Info[0]  = 0;",
6725
	"	}",
6726
	"",
6727
	"#if NCORE>1 && !defined(SEP_STATE)",
6728
	"	enter_critical(GLOBAL_LOCK); /* crude, but necessary */",
6729
	"	/* to make this mode work, also replace emalloc with grab_shared inside store MA routines */",
6730
	"#endif",
6731
	"",
6732
	"	if (!dfa_store(Info))",
6733
	"	{	if (pbit == 0",
6734
	"		&& (now._a_t&1)",
6735
	"		&&  depth > A_depth)",
6736
	"		{	Info[MA] &= ~(1|16|32);	/* _a_t */",
6737
	"			if (dfa_member(MA))",	/* was !dfa_member(MA) */
6738
	"			{	Info[MA-1] = 4; /* off-stack bit */",
6739
	"				nShadow++;",
6740
	"				if (!dfa_member(MA-1))",
6741
	"				{	ret_val = 3;",
6742
	"			#ifdef VERBOSE",
6743
	"					printf(\"intersected 1st dfs stack\\n\");",
6744
	"			#endif",
6745
	"					goto done;",
6746
	"		}	}	}",
6747
	"		ret_val = 0;",
6748
	"	#ifdef VERBOSE",
6749
	"		printf(\"new state\\n\");",
6750
	"	#endif",
6751
	"		goto done;",
6752
	"	}",
6753
	"#ifdef FULLSTACK",
6754
	"	if (pbit == 0)",
6755
	"	{	Info[MA-1] = 1;	/* proviso bit */",
6756
	"#ifndef BFS",
6757
	"		trpt->proviso = dfa_member(MA-1);",
6758
	"#endif",
6759
	"		Info[MA-1] = 4;	/* off-stack bit */",
6760
	"		if (dfa_member(MA-1))",
6761
	"		{	ret_val = 1; /* off-stack */",
6762
	"	#ifdef VERBOSE",
6763
	"			printf(\"old state\\n\");",
6764
	"	#endif",
6765
	"		} else",
6766
	"		{	ret_val = 2; /* on-stack */",
6767
	"	#ifdef VERBOSE",
6768
	"			printf(\"on-stack\\n\");",
6769
	"	#endif",
6770
	"		}",
6771
	"		goto done;",
6772
	"	}",
6773
	"#endif",
6774
	"	ret_val = 1;",
6775
	"#ifdef VERBOSE",
6776
	"	printf(\"old state\\n\");",
6777
	"#endif",
6778
	"done:",
6779
	"#if NCORE>1 && !defined(SEP_STATE)",
6780
	"	leave_critical(GLOBAL_LOCK);",
6781
	"#endif",
6782
	"	return ret_val;	/* old state */",
6783
	"}",
6784
"#endif",
6785
 
6786
	"#if defined(BITSTATE) && defined(LC)",
6787
	"int",
6788
	"compact_stack(char *vin, int n)",	/* special case of HC4 */
6789
	"{	int delta = 0;",
6790
	"	s_hash((uchar *)vin, n); /* sets K1 and K2 */",
6791
		"#ifndef SAFETY",
6792
	"	delta++;	/* room for state[0] |= 128 */",
6793
		"#endif",
6794
	"	memcpy((char *) &comp_now + delta, (char *) &K1, WS);",
6795
	"	delta += WS;",
6796
	"	memcpy((char *) &comp_now + delta, (char *) &K2, WS);",
6797
	"	delta += WS; /* use all available bits */",
6798
	"	return delta;",
6799
	"}",
6800
	"#endif",
6801
 
6802
	"#ifdef TRIX",
6803
	"void",
6804
	"sv_populate(void)",
6805
	"{	int i, cnt = 0;",
6806
	"	TRIX_v6 **base = processes;",
6807
	"	int bound = now._nr_pr; /* MAXPROC+1; */",
6808
	"#ifdef V_TRIX",
6809
	"	printf(\"%%4d: sv_populate\\n\", depth);",
6810
	"#endif",
6811
	"again:",
6812
	"	for (i = 0; i < bound; i++)",
6813
	"	{	if (base[i] != NULL)",
6814
	"		{	struct H_el *tmp;",
6815
	"			int m, n; uchar *v;",
6816
	"#ifndef BFS",
6817
	"			if (base[i]->modified == 0)",
6818
	"			{	cnt++;",
6819
	"	#ifdef V_TRIX",
6820
	"				printf(\"%%4d: %%s %%d not modified\\n\",",
6821
	"				depth, (base == processes)?\"proc\":\"chan\", i);",
6822
	"	#endif",
6823
	"				continue;",
6824
	"			}",
6825
	"	#ifndef V_MOD",
6826
	"			base[i]->modified = 0;",
6827
	"	#endif",
6828
	"#endif",
6829
	"#ifdef TRIX_RIX",
6830
	"			if (base == processes)",
6831
	"			{	((P0 *)pptr(i))->_pid = 0;",
6832
	"			}",
6833
	"#endif",
6834
	"			n = base[i]->psize;",
6835
	"			v = base[i]->body;",
6836
	"			s_hash(v, n); /* sets j1_spin */",
6837
	"			tmp = H_tab[j1_spin];",
6838
	"			if (!tmp)	/* new */",
6839
	"			{	tmp = grab_state(n);",
6840
	"				H_tab[j1_spin] = tmp;",
6841
	"				m = 1; /* non-zero */",
6842
	"			} else",
6843
	"			{  struct H_el *ntmp, *olst = (struct H_el *) 0;",
6844
	"			   for (;; hcmp++, olst = tmp, tmp = tmp->nxt)",
6845
	"			   { 	m = memcmp(((char *)&(tmp->state)), v, n);",
6846
	"				if (m == 0)	/* match */",
6847
	"				{	break;",
6848
	"				} else if (m < 0) /* insert */",
6849
	"				{	ntmp = grab_state(n);",
6850
	"					ntmp->nxt = tmp;",
6851
	"					if (!olst)",
6852
	"						H_tab[j1_spin] = ntmp;",
6853
	"					else",
6854
	"						olst->nxt = ntmp;",
6855
	"					tmp = ntmp;",
6856
	"					break;",
6857
	"				} else if (!tmp->nxt)	/* append */",
6858
	"				{	tmp->nxt = grab_state(n);",
6859
	"					tmp = tmp->nxt;",
6860
	"					break;",
6861
	"			}  }	}",
6862
	"			if (m != 0)",
6863
	"			{	memcpy((char *)&(tmp->state), v, n);",
6864
	"#if defined(AUTO_RESIZE) && !defined(BITSTATE)",
6865
	"				tmp->m_K1 = K1; /* set via s_hash */",
6866
	"#endif",
6867
	"				if (base == processes)",
6868
	"				{	_p_count[i]++;",
6869
	"				} else",
6870
	"				{	_c_count[i]++;",
6871
	"			}	}",
6872
	"			now._ids_[cnt++] = (char *)&(tmp->state);",
6873
	"#ifdef TRIX_RIX",
6874
	"			if (base == processes)",
6875
	"			{	((P0 *)pptr(i))->_pid = i;",
6876
	"			}",
6877
	"#endif",
6878
	"	}	}",
6879
#if 0
6880
	if a process appears or disappears: always secure a full sv_populate
6881
	(channels come and go only with a process)
6882
 
6883
	only one process can disappear per step
6884
	but any nr of channels can be removed at the same time
6885
		if a process disappears, all subsequent entries
6886
		are then in the wrong place in the _ids_ list
6887
		and need to be recomputed
6888
	but we do not need to fill out with zeros
6889
		because vsize prevents them being used
6890
#endif
6891
	"	/* do the same for all channels */",
6892
	"	if (base == processes)",
6893
	"	{	base = channels;",
6894
	"		bound = now._nr_qs; /* MAXQ+1; */",
6895
	"		goto again;",
6896
	"	}",
6897
	"}",
6898
	"#endif\n",
6899
	"int",
6900
	"hstore(char *vin, int nin)	/* hash table storage */",
6901
	"{	struct H_el *ntmp;",
6902
	"	struct H_el *tmp, *olst = (struct H_el *) 0;",
6903
	"	char *v; int n, m=0;",
6904
	"#ifdef HC",
6905
	"	uchar rem_a;",
6906
	"#endif",
6907
 
6908
	"#ifdef TRIX",
6909
	"	sv_populate();	/* update proc and chan ids */",
6910
	"#endif",
6911
 
6912
	"#ifdef NOCOMP",	/* defined by BITSTATE */
6913
	"	#if defined(BITSTATE) && defined(LC)",
6914
	"	if (S_Tab == H_tab)",
6915
	"	{	v = (char *) &comp_now;",
6916
	"		n = compact_stack(vin, nin);",
6917
	"	} else",
6918
	"	{	v = vin; n = nin;",
6919
	"	}",
6920
	"	#else",
6921
	"	v = vin; n = nin;",
6922
	"	#endif",
6923
	"#else",
6924
	"	v = (char *) &comp_now;",
6925
	"	#ifdef HC",
6926
	"	rem_a = now._a_t;",	/* new 5.0 */
6927
	"	now._a_t = 0;",	/* for hashing/state matching to work right */
6928
	"	#endif",
6929
	"	n = compress(vin, nin);", /* with HC, this calls s_hash -- but on vin, not on v... */
6930
	"	#ifdef HC",
6931
	"	now._a_t = rem_a;",	/* new 5.0 */
6932
	"	#endif",
6933
		/* with HC4 -a, compress copies K1 and K2 into v[], leaving v[0] free for the a-bit */
6934
		"#ifndef SAFETY",
6935
	"	if (S_A)",
6936
	"	{	v[0] = 0;	/* _a_t  */",
6937
			"#ifndef NOFAIR",
6938
	"		if (S_A > NFAIR)",
6939
	"		for (m = 0; m < NFAIR; m++)",
6940
	"			v[m+1] = 0;	/* _cnt[] */",
6941
			"#endif",
6942
	"		m = 0;",
6943
	"	}",
6944
	"	#endif",
6945
	"#endif",
6946
	"#if !defined(HC) && !(defined(BITSTATE) && defined(LC))",
6947
	"	s_hash((uchar *)v, n);",
6948
	"#endif",
6949
	"#if NCORE>1 && !defined(SEP_STATE) && !defined(BITSTATE)",
6950
	"	enter_critical(CS_ID);	/* uses spinlock */",
6951
	"#endif",
6952
 
6953
	"	tmp = H_tab[j1_spin];",
6954
	"	if (!tmp)",
6955
	"	{  tmp = grab_state(n);",
6956
	"#if NCORE>1",
6957
	"	   if (!tmp)",
6958
	"	   {	/* if we get here -- we've already issued a warning */",
6959
	"		/* but we want to allow the normal distributed termination */",
6960
	"		/* to collect the stats on all cpus in the wrapup */",
6961
	"	#if !defined(SEP_STATE) && !defined(BITSTATE)",
6962
	"		leave_critical(CS_ID);",
6963
	"	#endif",
6964
	"		return 1; /* allow normal termination */",
6965
	"	   }",
6966
	"#endif",
6967
	"	   H_tab[j1_spin] = tmp;",
6968
	"	} else",
6969
	"	{  for (;; hcmp++, olst = tmp, tmp = tmp->nxt)",
6970
	"	   {   /* skip the _a_t and the _cnt bytes */",
6971
	"#ifdef COLLAPSE",
6972
	"		if (tmp->ln != 0)",
6973
	"		{	if (!tmp->nxt) goto Append;",
6974
	"			continue;",
6975
	"		}",
6976
	"#endif",
6977
	"		m = memcmp(((char *)&(tmp->state)) + S_A, ",
6978
	"			v + S_A, n - S_A);",
6979
	"		if (m == 0) {",
6980
	"#ifdef SAFETY",
6981
			"#define wasnew	0",
6982
	"#else",
6983
	"		int wasnew = 0;",
6984
	"#endif",
6985
 
6986
	"#ifndef SAFETY",
6987
	"#ifndef NOCOMP",
6988
	"		if (S_A)",
6989
	"		{ if ((((char *)&(tmp->state))[0] & V_A) != V_A)",
6990
	"		  {	wasnew = 1; nShadow++;",
6991
	"			((char *)&(tmp->state))[0] |= V_A;",
6992
	"		  }",
6993
		"#ifndef NOFAIR",
6994
	"		  if (S_A > NFAIR)",
6995
	"		  {	/* 0 <= now._cnt[now._a_t&1] < MAXPROC */",
6996
	"			unsigned ci, bp; /* index, bit pos */",
6997
	"			ci = (now._cnt[now._a_t&1] / 8);",
6998
	"			bp = (now._cnt[now._a_t&1] - 8*ci);",
6999
	"			if (now._a_t&1)	/* use tail-bits in _cnt */",
7000
	"			{	ci = (NFAIR - 1) - ci;",
7001
	"				bp = 7 - bp; /* bp = 0..7 */",
7002
	"			}",
7003
	"			ci++;	/* skip over _a_t */",
7004
	"			bp = 1 << bp;	/* the bit mask */",
7005
	"			if ((((char *)&(tmp->state))[ci] & bp)==0)",
7006
	"			{	if (!wasnew)",
7007
	"				{	wasnew = 1;",
7008
	"					nShadow++;",
7009
	"				}",
7010
	"				((char *)&(tmp->state))[ci] |= bp;",
7011
	"			}",
7012
	"		   }",
7013
	"		   /* else: wasnew == 0, i.e., old state */",
7014
		"#endif",
7015
	"		}",
7016
	"#endif",
7017
	"#endif",
7018
 
7019
	"#if NCORE>1",
7020
	"		Lstate = (struct H_el *) tmp;",
7021
	"#endif",
7022
 
7023
	"#ifdef FULLSTACK",
7024
		"#ifndef SAFETY",	/* or else wasnew == 0 */
7025
	"		if (wasnew)",
7026
	"		{	Lstate = (struct H_el *) tmp;",
7027
	"			tmp->tagged |= V_A;",
7028
	"			if ((now._a_t&1)",
7029
	"			&& (tmp->tagged&A_V)",
7030
	"			&& depth > A_depth)",
7031
	"			{",
7032
	"intersect:",
7033
		"#ifdef CHECK",
7034
	"#if NCORE>1",
7035
	"	printf(\"cpu%%d: \", core_id);",
7036
	"#endif",
7037
	"	printf(\"1st dfs-stack intersected on state %%d+\\n\",",
7038
	"		(int) tmp->st_id);",
7039
		"#endif",
7040
 
7041
	"#if NCORE>1 && !defined(SEP_STATE) && !defined(BITSTATE)",
7042
	"				leave_critical(CS_ID);",
7043
	"#endif",
7044
 
7045
	"				return 3;",
7046
	"			}",
7047
		"#ifdef CHECK",
7048
	"#if NCORE>1",
7049
	"	printf(\"cpu%%d: \", core_id);",
7050
	"#endif",
7051
	"	printf(\"\tNew state %%d+\\n\", (int) tmp->st_id);",
7052
		"#endif",
7053
		"#ifdef DEBUG",
7054
	"	dumpstate(1, (char *)&(tmp->state),n,tmp->tagged);",
7055
		"#endif",
7056
	"#if NCORE>1 && !defined(SEP_STATE) && !defined(BITSTATE)",
7057
	"			leave_critical(CS_ID);",
7058
	"#endif",
7059
	"			return 0;",
7060
	"		} else",
7061
		"#endif",
7062
	"		if ((S_A)?(tmp->tagged&V_A):tmp->tagged)",
7063
	"		{	Lstate = (struct H_el *) tmp;",
7064
		"#ifndef SAFETY",
7065
	"			/* already on current dfs stack */",
7066
	"			/* but may also be on 1st dfs stack */",
7067
	"			if ((now._a_t&1)",
7068
	"			&& (tmp->tagged&A_V)",
7069
 
7070
	"			&& depth > A_depth",
7071
		/* new (Zhang's example) */
7072
		"#ifndef NOFAIR",
7073
	"			&& (!fairness || now._cnt[1] <= 1)",
7074
		"#endif",
7075
	"			)",
7076
 
7077
	"				goto intersect;",
7078
		"#endif",
7079
		"#ifdef CHECK",
7080
	"#if NCORE>1",
7081
	"	printf(\"cpu%%d: \", core_id);",
7082
	"#endif",
7083
	"	printf(\"\tStack state %%d\\n\", (int) tmp->st_id);",
7084
		"#endif",
7085
		"#ifdef DEBUG",
7086
	"	dumpstate(0, (char *)&(tmp->state),n,tmp->tagged);",
7087
		"#endif",
7088
	"#if NCORE>1 && !defined(SEP_STATE) && !defined(BITSTATE)",
7089
	"			leave_critical(CS_ID);",
7090
	"#endif",
7091
	"			return 2; /* match on stack */",
7092
	"		}",
7093
	"#else",
7094
	"		if (wasnew)",
7095
	"		{",
7096
		"#ifdef CHECK",
7097
	"#if NCORE>1",
7098
	"	printf(\"cpu%%d: \", core_id);",
7099
	"#endif",
7100
	"	printf(\"\tNew state %%d+\\n\", (int) tmp->st_id);",
7101
		"#endif",
7102
		"#ifdef DEBUG",
7103
	"	dumpstate(1, (char *)&(tmp->state), n, 0);",
7104
		"#endif",
7105
	"#if NCORE>1 && !defined(SEP_STATE) && !defined(BITSTATE)",
7106
	"			leave_critical(CS_ID);",
7107
	"#endif",
7108
	"			return 0;",
7109
	"		}",
7110
	"#endif",
7111
		"#ifdef CHECK",
7112
	"#if NCORE>1",
7113
	"	printf(\"cpu%%d: \", core_id);",
7114
	"#endif",
7115
	"	printf(\"\tOld state %%d\\n\", (int) tmp->st_id);",
7116
		"#endif",
7117
		"#ifdef DEBUG",
7118
	"	dumpstate(0, (char *)&(tmp->state), n, 0);",
7119
		"#endif",
7120
	"#if defined(BCS)",
7121
	"  #ifdef CONSERVATIVE",
7122
	"	if (tmp->ctx_low > trpt->sched_limit)",
7123
	"	{	tmp->ctx_low = trpt->sched_limit;",
7124
	"		tmp->ctx_pid[(now._last)/8] = 1 << ((now._last)%8); /* new */",
7125
	"	#ifdef CHECK",
7126
	"		#if NCORE>1",
7127
	"		printf(\"cpu%%d: \", core_id);",
7128
	"		#endif",
7129
	"		printf(\"\t\tRevisit with fewer context switches\\n\");",
7130
	"	#endif",
7131
	"		nstates--;",
7132
	"		#if NCORE>1 && !defined(SEP_STATE) && !defined(BITSTATE)",
7133
	"		leave_critical(CS_ID);",
7134
	"		#endif",
7135
	"		return 0;",
7136
	"	} else if ((tmp->ctx_low == trpt->sched_limit",
7137
	"	&&   (tmp->ctx_pid[(now._last)/8] & ( 1 << ((now._last)%8) )) == 0 ))",
7138
	"	{	tmp->ctx_pid[(now._last)/8] |= 1 << ((now._last)%8); /* add */",
7139
	"	#ifdef CHECK",
7140
	"		#if NCORE>1",
7141
	"		printf(\"cpu%%d: \", core_id);",
7142
	"		#endif",
7143
	"		printf(\"\t\tRevisit with same nr of context switches\\n\");",
7144
	"	#endif",
7145
	"		nstates--;",
7146
	"		#if NCORE>1 && !defined(SEP_STATE) && !defined(BITSTATE)",
7147
	"		leave_critical(CS_ID);",
7148
	"		#endif",
7149
	"		return 0;",
7150
	"	}",
7151
	"  #endif",
7152
	"#endif",
7153
	"#ifdef REACH",
7154
	"	if (tmp->D > depth)",
7155
	"	{	tmp->D = depth;",
7156
	"	#ifdef CHECK",
7157
	"		#if NCORE>1",
7158
	"		printf(\"cpu%%d: \", core_id);",
7159
	"		#endif",
7160
	"		printf(\"\t\tReVisiting (from smaller depth)\\n\");",
7161
	"	#endif",
7162
	"		nstates--;",
7163
	"	#if NCORE>1 && !defined(SEP_STATE) && !defined(BITSTATE)",
7164
	"		leave_critical(CS_ID);",
7165
	"	#endif",
7166
#if 0
7167
  a possible variation of iterative search for shortest counter-example
7168
  (pan -i and pan -I) suggested by Pierre Moro (for safety properties):
7169
  state revisits on shorter depths do not start until after
7170
  the first counter-example is found.  this assumes that the max search
7171
  depth is set large enough that a first (possibly long) counter-example
7172
  can be found
7173
  if set too short, this variant can miss the counter-example, even if
7174
  it would otherwise be shorter than the depth-limit.
7175
  (p.m. unsure if this preserves the guarantee of finding the
7176
   shortest counter-example - so not enabled by default)
7177
	"		if (errors > 0 && iterative)", /* Moro */
7178
#endif
7179
	"		return 0;",
7180
	"	}",
7181
	"#endif",
7182
	"#if (defined(BFS) && defined(Q_PROVISO)) || NCORE>1",
7183
	"		Lstate = (struct H_el *) tmp;",
7184
	"#endif",
7185
	"#if NCORE>1 && !defined(SEP_STATE) && !defined(BITSTATE)",
7186
	"		leave_critical(CS_ID);",
7187
	"#endif",
7188
	"		return 1; /* match outside stack */",
7189
	"	       } else if (m < 0)",
7190
	"	       {	/* insert state before tmp */",
7191
	"			ntmp = grab_state(n);",
7192
	"#if NCORE>1",
7193
	"			if (!ntmp)",
7194
	"			{",
7195
	"	#if !defined(SEP_STATE) && !defined(BITSTATE)",
7196
	"				leave_critical(CS_ID);",
7197
	"	#endif",
7198
	"				return 1;  /* allow normal termination */",
7199
	"			}",
7200
	"#endif",
7201
	"			ntmp->nxt = tmp;",
7202
	"			if (!olst)",
7203
	"				H_tab[j1_spin] = ntmp;",
7204
	"			else",
7205
	"				olst->nxt = ntmp;",
7206
	"			tmp = ntmp;",
7207
	"			break;",
7208
	"	       } else if (!tmp->nxt)",
7209
	"	       {	/* append after tmp */",
7210
	"#ifdef COLLAPSE",
7211
	"Append:",
7212
	"#endif",
7213
	"			tmp->nxt = grab_state(n);",
7214
	"#if NCORE>1",
7215
	"			if (!tmp->nxt)",
7216
	"			{",
7217
	"	#if !defined(SEP_STATE) && !defined(BITSTATE)",
7218
	"				leave_critical(CS_ID);",
7219
	"	#endif",
7220
	"				return 1;  /* allow normal termination */",
7221
	"			}",
7222
	"#endif",
7223
	"			tmp = tmp->nxt;",
7224
	"			break;",
7225
	"	   }   }",
7226
	"	}",
7227
	"#ifdef CHECK",
7228
	"	tmp->st_id = (unsigned) nstates;",
7229
	"#if NCORE>1",
7230
	"	printf(\"cpu%%d: \", core_id);",
7231
	"#endif",
7232
		"#ifdef BITSTATE",
7233
	"	printf(\"	Push state %%d\\n\", ((int) nstates) - 1);",
7234
		"#else",
7235
	"	printf(\"	New state %%d\\n\", (int) nstates);",
7236
		"#endif",
7237
	"#endif",
7238
	"#if defined(BCS)",
7239
	"	tmp->ctx_low = trpt->sched_limit;",
7240
	"	#ifdef CONSERVATIVE",
7241
	"	tmp->ctx_pid[(now._last)/8] = 1 << ((now._last)%8); /* new limit */",
7242
	"	#endif",
7243
	"#endif",
7244
	"#if !defined(SAFETY) || defined(REACH)",
7245
	"	tmp->D = depth;",
7246
	"#endif",
7247
	"#ifndef SAFETY",
7248
	"#ifndef NOCOMP",
7249
	"	if (S_A)",
7250
	"	{	v[0] = V_A;",
7251
		"#ifndef NOFAIR",
7252
	"		if (S_A > NFAIR)",
7253
	"		{	unsigned ci, bp; /* as above */",
7254
	"			ci = (now._cnt[now._a_t&1] / 8);",
7255
	"			bp = (now._cnt[now._a_t&1] - 8*ci);",
7256
	"			if (now._a_t&1)",
7257
	"			{	ci = (NFAIR - 1) - ci;",
7258
	"				bp = 7 - bp; /* bp = 0..7 */",
7259
	"			}",
7260
	"			v[1+ci] = 1 << bp;",
7261
	"		}",
7262
		"#endif",
7263
	"	}",
7264
	"#endif",
7265
	"#endif",
7266
	"#if defined(AUTO_RESIZE) && !defined(BITSTATE)",
7267
	"	tmp->m_K1 = K1;",
7268
	"#endif",
7269
	"	memcpy(((char *)&(tmp->state)), v, n);",
7270
	"#ifdef FULLSTACK",
7271
	"	tmp->tagged = (S_A)?V_A:(depth+1);",
7272
		"#ifdef DEBUG",
7273
	"		dumpstate(-1, v, n, tmp->tagged);",
7274
		"#endif",
7275
	"	Lstate = (struct H_el *) tmp;",
7276
	"#else",
7277
	"	#ifdef DEBUG",
7278
	"		dumpstate(-1, v, n, 0);",
7279
	"	#endif",
7280
	"	#if NCORE>1",
7281
	"		Lstate = (struct H_el *) tmp;",
7282
	"	#endif",
7283
	"#endif",
7284
 
7285
	"/* #if NCORE>1 && !defined(SEP_STATE) */",
7286
	"#if NCORE>1",
7287
	"	#ifdef V_PROVISO",
7288
	"		tmp->cpu_id = core_id;",
7289
	"	#endif",
7290
	"	#if !defined(SEP_STATE) && !defined(BITSTATE)",
7291
	"		leave_critical(CS_ID);",
7292
	"	#endif",
7293
	"#endif",
7294
 
7295
	"	return 0;",
7296
	"}",
7297
	"#endif",
7298
	"#include TRANSITIONS",
7299
	0,
7300
};