pangen1.h 92 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607
  1. /***** spin: pangen1.h *****/
  2. /* Copyright (c) 1991-2000 by Lucent Technologies - Bell Laboratories */
  3. /* All Rights Reserved. This software is for educational purposes only. */
  4. /* Permission is given to distribute this code provided that this intro- */
  5. /* ductory message is not removed and no monies are exchanged. */
  6. /* No guarantee is expressed or implied by the distribution of this code. */
  7. /* Software written by Gerard J. Holzmann as part of the book: */
  8. /* `Design and Validation of Computer Protocols,' ISBN 0-13-539925-4, */
  9. /* Prentice Hall, Englewood Cliffs, NJ, 07632. */
  10. /* Send bug-reports and/or questions to: gerard@research.bell-labs.com */
  11. static char *Code2[] = { /* the tail of procedure run() */
  12. "#if defined(VERI) && !defined(NOREDUCE) && !defined(NP)",
  13. " if (!state_tables)",
  14. " { printf(\"warning: for p.o. reduction to be valid \");",
  15. " printf(\"the never claim must be stutter-closed\\n\");",
  16. " printf(\"(never claims generated from LTL \");",
  17. " printf(\"formulae are stutter-closed)\\n\");",
  18. " }",
  19. "#endif",
  20. " UnBlock; /* disable rendez-vous */",
  21. "#ifdef MEMCNT",
  22. " overhead = memcnt;",
  23. "#endif",
  24. "#ifdef BITSTATE",
  25. " SS = (uchar *) emalloc(1<<(ssize-3));",
  26. "#else",
  27. " hinit();",
  28. "#endif",
  29. "#if defined(FULLSTACK) && defined(BITSTATE)",
  30. " onstack_init();",
  31. "#endif",
  32. "#ifdef CNTRSTACK",
  33. " LL = (uchar *) emalloc(1<<(ssize-3));",
  34. "#endif",
  35. " stack = ( Stack *) emalloc(sizeof(Stack));",
  36. " svtack = (Svtack *) emalloc(sizeof(Svtack));",
  37. " /* a place to point for Pptr of non-running procs: */",
  38. " noptr = (uchar *) emalloc(Maxbody * sizeof(char));",
  39. "#ifdef SVDUMP",
  40. " if (vprefix > 0)",
  41. " write(svfd, (uchar *) &vprefix, sizeof(int));",
  42. "#endif",
  43. "#ifdef VERI",
  44. " Addproc(VERI); /* never - pid = 0 */",
  45. "#endif",
  46. " active_procs(); /* started after never */",
  47. "#ifdef EVENT_TRACE",
  48. " now._event = start_event;",
  49. " reached[EVENT_TRACE][start_event] = 1;",
  50. "#endif",
  51. "go_again:",
  52. " do_the_search();",
  53. "#if defined(BITSTATE)",
  54. " if (--Nrun > 0 && HASH_CONST[++HASH_NR])",
  55. " { printf(\"Run %%d:\\n\", HASH_NR);",
  56. " wrap_stats();",
  57. " printf(\"\\n\");",
  58. " memset(SS, 0, 1<<(ssize-3));",
  59. "#if defined(CNTRSTACK)",
  60. " memset(LL, 0, 1<<(ssize-3));",
  61. "#endif",
  62. "#if defined(FULLSTACK)",
  63. " memset((uchar *) S_Tab, 0, ",
  64. " (1<<(ssize-3))*sizeof(struct H_el *));",
  65. "#endif",
  66. " nstates=nlinks=truncs=truncs2=ngrabs = 0;",
  67. " nlost=nShadow=hcmp = 0;",
  68. " Fa=Fh=Zh=Zn = 0;",
  69. " PUT=PROBE=ZAPS=Ccheck=Cholds = 0;",
  70. " goto go_again;",
  71. " }",
  72. "#endif",
  73. "}",
  74. #ifndef PRINTF
  75. "#include <stdarg.h>",
  76. "void",
  77. "Printf(const char *fmt, ...)",
  78. "{ /* Make sure the args to Printf",
  79. " * are always evaluated (e.g., they",
  80. " * could contain a run stmnt)",
  81. " * but don't generate the output",
  82. " * during verification runs",
  83. " * unless explicitly wanted",
  84. " * If this fails on your system",
  85. " * compile SPIN itself -DPRINTF",
  86. " * and this code is not generated",
  87. " */",
  88. "#ifdef PRINTF",
  89. " va_list args;",
  90. " va_start(args, fmt);",
  91. " vprintf(fmt, args);",
  92. " va_end(args);",
  93. "#endif",
  94. "}",
  95. #endif
  96. "#ifndef SC",
  97. "#define getframe(i) &trail[i];",
  98. "#else",
  99. "static long HHH, DDD, hiwater;",
  100. "static long CNT1, CNT2;",
  101. "static int stackwrite;",
  102. "static int stackread;",
  103. "static Trail frameptr;",
  104. "Trail *"
  105. "getframe(int d)",
  106. "{",
  107. " if (CNT1 == CNT2)",
  108. " return &trail[d];",
  109. "",
  110. " if (d >= (CNT1-CNT2)*DDD)",
  111. " return &trail[d - (CNT1-CNT2)*DDD];",
  112. "",
  113. " if (!stackread",
  114. " && (stackread = open(stackfile, 0)) < 0)",
  115. " { printf(\"getframe: cannot open %%s\\n\", stackfile);",
  116. " wrapup();",
  117. " }",
  118. " if (lseek(stackread, d*sizeof(Trail), SEEK_SET) == -1",
  119. " || read(stackread, &frameptr, sizeof(Trail)) != sizeof(Trail))",
  120. " { printf(\"getframe: frame read error\\n\");",
  121. " wrapup();",
  122. " }",
  123. " return &frameptr;",
  124. "}",
  125. "#endif",
  126. "#if !defined(SAFETY) && !defined(BITSTATE)",
  127. "#if !defined(FULLSTACK) || defined(MA)",
  128. "#define depth_of(x) A_depth /* an estimate */",
  129. "#else",
  130. "int",
  131. "depth_of(struct H_el *s)",
  132. "{ Trail *t; int d;",
  133. " for (d = 0; d <= A_depth; d++)",
  134. " { t = getframe(d);",
  135. " if (s == t->ostate)",
  136. " return d;",
  137. " }",
  138. " printf(\"pan: cannot happen, depth_of\\n\");",
  139. " return depthfound;",
  140. "}",
  141. "#endif",
  142. "#endif",
  143. "void",
  144. "do_the_search(void)",
  145. "{ int i;",
  146. " depth=mreached=0;",
  147. " trpt = &trail[depth];",
  148. "#ifdef VERI",
  149. " trpt->tau |= 4; /* the claim moves first */",
  150. "#endif",
  151. " for (i = 0; i < (int) now._nr_pr; i++)",
  152. " { P0 *ptr = (P0 *) pptr(i);",
  153. "#ifndef NP",
  154. " if (!(trpt->o_pm&2)",
  155. " && accpstate[ptr->_t][ptr->_p])",
  156. " { trpt->o_pm |= 2;",
  157. " }",
  158. "#else",
  159. " if (!(trpt->o_pm&4)",
  160. " && progstate[ptr->_t][ptr->_p])",
  161. " { trpt->o_pm |= 4;",
  162. " }",
  163. "#endif",
  164. " }",
  165. "#ifdef EVENT_TRACE",
  166. "#ifndef NP",
  167. " if (accpstate[EVENT_TRACE][now._event])",
  168. " { trpt->o_pm |= 2;",
  169. " }",
  170. "#else",
  171. " if (progstate[EVENT_TRACE][now._event])",
  172. " { trpt->o_pm |= 4;",
  173. " }",
  174. "#endif",
  175. "#endif",
  176. "#ifndef NOCOMP",
  177. " Mask[0] = Mask[1] = 1; /* _nr_pr, _nr_qs */",
  178. " if (!a_cycles)",
  179. " { i = &(now._a_t) - (uchar *) &now;",
  180. " Mask[i] = 1; /* _a_t */",
  181. " }",
  182. "#ifndef NOFAIR",
  183. " if (!fairness)",
  184. " { int j = 0;",
  185. " i = &(now._cnt[0]) - (uchar *) &now;",
  186. " while (j++ < NFAIR)",
  187. " Mask[i++] = 1; /* _cnt[] */",
  188. " }",
  189. "#endif",
  190. "#endif",
  191. "#ifndef NOFAIR",
  192. " if (fairness",
  193. " && (a_cycles && (trpt->o_pm&2)))",
  194. " { now._a_t = 2; /* set the A-bit */",
  195. " now._cnt[0] = now._nr_pr + 1;", /* NEW: +1 */
  196. "#ifdef VERBOSE",
  197. " printf(\"%%3d: fairness Rule 1, cnt=%%d, _a_t=%%d\\n\",",
  198. " depth, now._cnt[now._a_t&1], now._a_t);",
  199. "#endif",
  200. " }",
  201. "#endif",
  202. " new_state(); /* start 1st DFS */",
  203. "}",
  204. "#ifdef INLINE_REV",
  205. "char",
  206. "do_reverse(Trans *t, short II, char M)",
  207. "{ char m = M;",
  208. " short tt = (short) ((P0 *)this)->_p;",
  209. "#include REVERSE_MOVES",
  210. "R999: return m;",
  211. "}",
  212. "#endif",
  213. "#ifndef INLINE",
  214. "#ifdef EVENT_TRACE",
  215. "static char _tp = 'n'; static int _qid = 0;",
  216. "#endif",
  217. "char",
  218. "do_transit(Trans *t, short II, int n)",
  219. "{ char m;",
  220. " short tt = (short) ((P0 *)this)->_p;",
  221. " char ot = (char) ((P0 *)this)->_t;",
  222. "#ifdef EVENT_TRACE",
  223. " short oboq = boq;",
  224. " if (II == EVENT_TRACE) boq = -1;",
  225. "#define continue { boq = oboq; return 0; }",
  226. "#else",
  227. "#define continue return 0",
  228. "#endif",
  229. "#include FORWARD_MOVES",
  230. "P999:",
  231. "#ifdef EVENT_TRACE",
  232. " boq = oboq;",
  233. "#endif",
  234. " return m;",
  235. "#undef continue",
  236. "}",
  237. "#ifdef EVENT_TRACE",
  238. "void",
  239. "require(char tp, int qid)",
  240. "{ Trans *t;",
  241. " _tp = tp; _qid = qid;",
  242. "#ifdef NEGATED_TRACE",
  243. " if (now._event == endevent)",
  244. " { depth++; trpt++;",
  245. " uerror(\"event_trace error (all events matched)\");",
  246. "#ifndef NP",
  247. " if (accpstate[EVENT_TRACE][now._event])",
  248. " trpt->o_pm |= 2;",
  249. "#else",
  250. " if (progstate[EVENT_TRACE][now._event])",
  251. " trpt->o_pm |= 4;",
  252. "#endif",
  253. " trpt--; depth--;",
  254. " now._event = start_event;",
  255. " return;",
  256. " } else",
  257. "#else",
  258. " if (now._event != endevent)",
  259. "#endif",
  260. " for (t = trans[EVENT_TRACE][now._event]; t; t = t->nxt)",
  261. " { if (do_transit(t, EVENT_TRACE, 0))",
  262. " { now._event = t->st;",
  263. " reached[EVENT_TRACE][t->st] = 1;",
  264. "#ifdef VERBOSE",
  265. " printf(\" event_trace move to -> %%d\\n\", t->st);",
  266. "#endif",
  267. "#ifndef NP",
  268. " if (accpstate[EVENT_TRACE][now._event])",
  269. " (trpt+1)->o_pm |= 2;",
  270. "#else",
  271. " if (progstate[EVENT_TRACE][now._event])",
  272. " (trpt+1)->o_pm |= 4;",
  273. "#endif",
  274. " for (t = t->nxt; t; t = t->nxt)",
  275. " { if (do_transit(t, EVENT_TRACE, 0))",
  276. " uerror(\"non-determinism in event-trace\");",
  277. " }",
  278. " return;",
  279. " }",
  280. "#ifdef VERBOSE",
  281. " else",
  282. " printf(\" event_trace miss '%%c' -- %%d, %%d, %%d\\n\",",
  283. " tp, qid, now._event, t->forw);",
  284. "#endif",
  285. " }",
  286. "#ifdef NEGATED_TRACE",
  287. " now._event = start_event; /* only 1st try will count */",
  288. "#else",
  289. " depth++; trpt++;",
  290. " uerror(\"event_trace error (no matching event)\");",
  291. " trpt--; depth--;",
  292. "#endif",
  293. "}",
  294. "#endif",
  295. "int",
  296. "enabled(int iam, int pid)",
  297. "{ Trans *t; uchar *othis = this;",
  298. " int res = 0; short tt; char ot;",
  299. "#ifdef VERI",
  300. " /* if (pid > 0) */ pid++;",
  301. "#endif",
  302. " if (pid == iam)",
  303. " Uerror(\"used: enabled(pid=thisproc)\");",
  304. " if (pid < 0 || pid >= (int) now._nr_pr)",
  305. " return 0;",
  306. " this = pptr(pid);",
  307. " TstOnly = 1;",
  308. " tt = (short) ((P0 *)this)->_p;",
  309. " ot = (uchar) ((P0 *)this)->_t;",
  310. " for (t = trans[ot][tt]; t; t = t->nxt)",
  311. " if (do_transit(t, pid, 0))",
  312. " { res = 1;",
  313. " break;",
  314. " }",
  315. " TstOnly = 0;",
  316. " this = othis;",
  317. " return res;",
  318. "}",
  319. "#endif",
  320. "void",
  321. "snapshot(void)",
  322. "{ static long sdone = (long) 0;",
  323. " long ndone = (unsigned long) nstates/1000000;",
  324. " if (ndone == sdone) return;",
  325. " sdone = ndone;",
  326. " printf(\"Depth= %%7d States= %%7g \", mreached, nstates);",
  327. " printf(\"Transitions= %%7g \", nstates+truncs);",
  328. "#ifdef MA",
  329. " printf(\"Nodes= %%7d \", nr_states);",
  330. "#endif",
  331. " printf(\"Memory= %%-6.3f\\n\", memcnt/1000000.);",
  332. " fflush(stdout);",
  333. "}",
  334. "#ifdef SC",
  335. "void",
  336. "stack2disk(void)",
  337. "{",
  338. " if (!stackwrite",
  339. " && (stackwrite = creat(stackfile, 0666)) <= 0)",
  340. " Uerror(\"cannot create stackfile\");",
  341. "",
  342. " if (write(stackwrite, trail, DDD*sizeof(Trail))",
  343. " != DDD*sizeof(Trail))",
  344. " Uerror(\"stackfile write error -- disk is full?\");",
  345. "",
  346. " memmove(trail, &trail[DDD], (HHH-DDD+2)*sizeof(Trail));",
  347. " memset(&trail[HHH-DDD+2], 0, (omaxdepth - HHH + DDD - 2)*sizeof(Trail));",
  348. " CNT1++;",
  349. "}",
  350. "void",
  351. "disk2stack(void)",
  352. "{ long have;",
  353. "",
  354. " CNT2++;",
  355. " memmove(&trail[DDD], trail, (HHH-DDD+2)*sizeof(Trail));",
  356. "",
  357. " if (!stackwrite",
  358. " || lseek(stackwrite, -DDD*sizeof(Trail), SEEK_CUR) == -1)",
  359. " Uerror(\"disk2stack lseek error\");",
  360. "",
  361. " if (!stackread",
  362. " && (stackread = open(stackfile, 0)) < 0)",
  363. " Uerror(\"cannot open stackfile\");",
  364. "",
  365. " if (lseek(stackread, (CNT1-CNT2)*DDD*sizeof(Trail), SEEK_SET) == -1)",
  366. " Uerror(\"disk2stack lseek error2\");",
  367. "",
  368. " have = read(stackread, trail, DDD*sizeof(Trail));",
  369. " if (have != DDD*sizeof(Trail))",
  370. " Uerror(\"stackfile read error\");",
  371. "}",
  372. "#endif",
  373. "uchar *",
  374. "Pptr(int x)", /* as a fct, to avoid a problem with the p9 compiler */
  375. "{ if (proc_offset[x])",
  376. " return (uchar *) pptr(x);",
  377. " else",
  378. " return noptr;",
  379. "}",
  380. "extern void check_claim(int);",
  381. "/* new_state() is the main search routine in the verifier",
  382. " * it has a lot of code ifdef-ed together to support",
  383. " * different search modes -- this makes it quite unreadable",
  384. " * of course. if you are studying the code, first",
  385. " * let the C preprocessor generate a specific version",
  386. " * from the pan.c source, e.g. by saying:",
  387. " * /lib/cpp -DNOREDUCE -DBITSTATE pan.c > Pan.c",
  388. " * and study the resulting file, rather than this one",
  389. " */",
  390. "void",
  391. "new_state(void)",
  392. "{ Trans *t;",
  393. " char n, m, ot;",
  394. " short II, JJ=0, tt, kk;\n",
  395. " short From = now._nr_pr-1, To = BASE;",
  396. "Down:",
  397. "#ifdef CHECK",
  398. " printf(\"%%d: Down - %%s\",",
  399. " depth, (trpt->tau&4)?\"claim\":\"program\");",
  400. " printf(\" %%saccepting [pids %%d-%%d]\\n\",",
  401. " (trpt->o_pm&2)?\"\":\"non-\", From, To);",
  402. "#endif",
  403. "#ifdef SC",
  404. " if (depth > hiwater)",
  405. " { stack2disk();",
  406. " maxdepth += DDD;",
  407. " hiwater += DDD;",
  408. " trpt -= DDD;",
  409. "if(verbose)",
  410. "printf(\"zap %%d: %%d (maxdepth now %%d)\\n\", CNT1, hiwater, maxdepth);",
  411. " }",
  412. "#endif",
  413. " trpt->tau &= ~(16|32|64); /* make sure these are off */",
  414. "#if defined(FULLSTACK) && defined(MA)",
  415. " trpt->proviso = 0;",
  416. "#endif",
  417. " if (depth >= maxdepth)",
  418. " { truncs++;",
  419. "#if SYNC",
  420. " (trpt+1)->o_n = 1; /* not a deadlock */",
  421. "#endif",
  422. " if (!warned)",
  423. " { warned = 1;",
  424. " printf(\"error: max search depth too small\\n\");",
  425. " }",
  426. " (trpt-1)->tau |= 16; /* worstcase guess */",
  427. " goto Up;",
  428. " }",
  429. "AllOver:",
  430. "#if defined(FULLSTACK) && !defined(MA)",
  431. " trpt->ostate = (struct H_el *) 0;",
  432. "#endif",
  433. "#ifdef VERI",
  434. " if ((trpt->tau&4) || ((trpt-1)->tau&128))",
  435. "#endif",
  436. " if (boq == -1) { /* if not mid-rv */",
  437. "#ifndef SAFETY",
  438. " /* this check should now be redundant",
  439. " * because the seed state also appears",
  440. " * on the 1st dfs stack and would be",
  441. " * matched in hstore below",
  442. " */",
  443. " if ((now._a_t&1) && depth > A_depth)",
  444. " { if (!memcmp((char *)&A_Root, ",
  445. " (char *)&now, vsize))",
  446. " {",
  447. " depthfound = A_depth;",
  448. "#ifdef CHECK",
  449. " printf(\"matches seed\\n\");",
  450. "#endif",
  451. "#ifdef NP",
  452. " uerror(\"non-progress cycle\");",
  453. "#else",
  454. " uerror(\"acceptance cycle\");",
  455. "#endif",
  456. " goto Up;",
  457. " }",
  458. "#ifdef CHECK",
  459. " printf(\"not seed\\n\");",
  460. "#endif",
  461. " }",
  462. "#endif",
  463. " if (!(trpt->tau&8)) /* if no atomic move */",
  464. " {",
  465. "#ifdef CNTRSTACK", /* -> bitstate, reduced, safety */
  466. " d_hash((uchar *)&now, vsize);",
  467. " trpt->j6 = j1; trpt->j7 = j2;",
  468. " JJ = LL[j1] && LL[j2];",
  469. "#endif",
  470. "#ifdef FULLSTACK",
  471. "#ifdef BITSTATE",
  472. " JJ = onstack_now();",
  473. "#else",
  474. "#ifdef MA",
  475. " II = gstore((char *)&now, vsize, 0);",
  476. "#else",
  477. " II = hstore((char *)&now, vsize, 1);",
  478. "#endif",
  479. " JJ = (II == 2)?1:0;",
  480. "#endif",
  481. "#endif",
  482. "#ifdef BITSTATE",
  483. "#ifndef CNTRSTACK", /* !reduced */
  484. " d_hash((uchar *) &now, vsize);",
  485. "#endif",
  486. " kk = II = ((SS[j2]&j3) && (SS[j1]&j4));",
  487. "#ifdef DEBUG",
  488. " if (II) printf(\"Old bitstate\\n\");",
  489. " else printf(\"New bitstate\\n\");",
  490. "#endif",
  491. "#else",
  492. "#ifndef FULLSTACK",
  493. "#ifdef MA",
  494. " JJ = II = gstore((char *) &now, vsize, 0);",
  495. "#else",
  496. " II = hstore((char *)&now, vsize, 2);",
  497. "#endif",
  498. "#endif",
  499. " kk = (II == 1 || II == 2);",
  500. "#endif",
  501. "#ifndef SAFETY",
  502. "#if defined(FULLSTACK) && defined(BITSTATE)",
  503. " if (!JJ && (now._a_t&1) && depth > A_depth)",
  504. " { int oj1 = j1;",
  505. " uchar o_a_t = now._a_t;",
  506. " now._a_t &= ~(1|16|32);",
  507. " if (onstack_now())",
  508. " { II = 3;",
  509. "#ifdef VERBOSE",
  510. " printf(\"state match on 1st dfs stack\\n\");",
  511. "#endif",
  512. " }",
  513. " now._a_t = o_a_t;",
  514. " j1 = oj1;",
  515. " }",
  516. "#endif",
  517. " if (II == 3 && a_cycles && (now._a_t&1))",
  518. " {",
  519. "#ifndef NOFAIR",
  520. " if (fairness && now._cnt[1] > 1) /* was != 0 */",
  521. " {",
  522. "#ifdef VERBOSE",
  523. " printf(\" fairness count non-zero\\n\");",
  524. "#endif",
  525. " II = 0;",
  526. " } else",
  527. "#endif",
  528. " {",
  529. "#ifdef BITSTATE",
  530. " depthfound = Lstate->tagged - 1;",
  531. "#ifdef NP",
  532. " uerror(\"non-progress cycle\");",
  533. "#else",
  534. " uerror(\"acceptance cycle\");",
  535. "#endif",
  536. "#else",
  537. " depthfound = depth_of(Lstate);",
  538. "#ifdef NP",
  539. " uerror(\"non-progress cycle\");",
  540. "#else",
  541. " uerror(\"acceptance cycle\");",
  542. "#endif",
  543. " nShadow--;",
  544. "#endif",
  545. " goto Up;",
  546. " }",
  547. " }",
  548. "#endif",
  549. "#if !defined(FULLSTACK) && !defined(CNTRSTACK) && defined(BITSTATE)",
  550. "#ifndef NOREDUCE",
  551. " JJ = II; /* worstcase guess for p.o. */",
  552. "#endif",
  553. "#endif",
  554. "#ifndef NOREDUCE",
  555. "#ifndef SAFETY",
  556. " if ((II && JJ) || (II == 3))",
  557. " { /* marker for liveness proviso */",
  558. " truncs2++;",
  559. " (trpt-1)->tau |= 16;",
  560. " }",
  561. "#else",
  562. " if (!II || !JJ)",
  563. " { /* has successor outside stack */",
  564. " (trpt-1)->tau |= 64;",
  565. " }",
  566. "#endif",
  567. "#endif",
  568. " if (II)",
  569. " { truncs++;",
  570. " goto Up;",
  571. " }",
  572. " if (!kk)",
  573. " { nstates++;",
  574. "#ifdef SVDUMP",
  575. " if (vprefix > 0)",
  576. " if (write(svfd, (uchar *) &now, vprefix) != vprefix)",
  577. " { fprintf(efd, \"writing %%s.svd failed\\n\", Source);",
  578. " wrapup();",
  579. " }",
  580. "#endif",
  581. " if ((unsigned long) nstates%%1000000 == 0)",
  582. " snapshot();",
  583. "#ifdef MA",
  584. "#ifdef W_XPT",
  585. " if ((unsigned long) nstates%%W_XPT == 0)",
  586. " { void w_xpoint(void);",
  587. " w_xpoint();",
  588. " }",
  589. "#endif",
  590. "#endif",
  591. " }",
  592. "#ifdef BITSTATE",
  593. "#ifdef RANDSTOR",
  594. " if (rand()%%100 <= RANDSTOR)",
  595. "#endif",
  596. " { SS[j2] |= j3; SS[j1] |= j4; }",
  597. "#endif",
  598. "#if defined(FULLSTACK) || defined(CNTRSTACK)",
  599. " onstack_put();",
  600. "#ifdef DEBUG2",
  601. "#if defined(FULLSTACK) && !defined(MA)",
  602. " printf(\"%%d: putting %%u (%%d)\\n\", depth,",
  603. " trpt->ostate, ",
  604. " (trpt->ostate)?trpt->ostate->tagged:0);",
  605. "#else",
  606. " printf(\"%%d: putting\\n\", depth);",
  607. "#endif",
  608. "#endif",
  609. "#endif",
  610. " } }",
  611. " if (depth > mreached)",
  612. " mreached = depth;",
  613. "#ifdef VERI",
  614. " if (trpt->tau&4)",
  615. "#endif",
  616. " trpt->tau &= ~(1|2); /* timeout and -request off */",
  617. " n = 0;",
  618. "#if SYNC",
  619. " (trpt+1)->o_n = 0;",
  620. "#endif",
  621. "#ifdef VERI",
  622. " if (now._nr_pr == 0) /* claim terminated */",
  623. " uerror(\"endstate in claim reached\");",
  624. " check_claim(((P0 *)pptr(0))->_p);",
  625. "Stutter:",
  626. " if (trpt->tau&4) /* must make a claimmove */",
  627. " { II = 0; /* never */",
  628. " goto Veri0;",
  629. " }",
  630. "#endif",
  631. "#ifndef NOREDUCE",
  632. " /* Look for a process with only safe transitions */",
  633. " /* (special rules apply in the 2nd dfs) */",
  634. "#ifdef SAFETY",
  635. " if (boq == -1 && From != To)",
  636. "#else",
  637. "/* implied: #ifdef FULLSTACK */",
  638. " if (boq == -1 && From != To",
  639. " && (!(now._a_t&1)",
  640. " || (a_cycles &&",
  641. "#ifndef BITSTATE",
  642. "#ifdef MA",
  643. "#ifdef VERI",
  644. " !((trpt-1)->proviso))",
  645. "#else",
  646. " !(trpt->proviso))",
  647. "#endif",
  648. "#else",
  649. "#ifdef VERI",
  650. " (trpt-1)->ostate &&",
  651. " !(((char *)&((trpt-1)->ostate->state))[0] & 128))",
  652. "#else",
  653. " !(((char *)&(trpt->ostate->state))[0] & 128))",
  654. "#endif",
  655. "#endif",
  656. "#else",
  657. "#ifdef VERI",
  658. " (trpt-1)->ostate &&",
  659. " (trpt-1)->ostate->proviso == 0)",
  660. "#else",
  661. " trpt->ostate->proviso == 0)",
  662. "#endif",
  663. "#endif",
  664. " ))",
  665. "/* #endif */",
  666. "#endif",
  667. " for (II = From; II >= To; II -= 1)",
  668. " {",
  669. "Resume: /* pick up here if preselect fails */",
  670. " this = pptr(II);",
  671. " tt = (short) ((P0 *)this)->_p;",
  672. " ot = (uchar) ((P0 *)this)->_t;",
  673. " if (trans[ot][tt]->atom & 8)",
  674. " { t = trans[ot][tt];",
  675. " if (t->qu[0] != 0)",
  676. " { Ccheck++;",
  677. " if (!q_cond(II, t))",
  678. " continue;",
  679. " Cholds++;",
  680. " }",
  681. " From = To = II;",
  682. "#ifdef NIBIS",
  683. " t->om = 0;",
  684. "#endif",
  685. " trpt->tau |= 32; /* preselect marker */",
  686. "#ifdef DEBUG",
  687. "#ifdef NIBIS",
  688. " printf(\"%%3d: proc %%d Pre\", depth, II);",
  689. " printf(\"Selected (om=%%d, tau=%%d)\\n\", ",
  690. " t->om, trpt->tau);",
  691. "#else",
  692. " printf(\"%%3d: proc %%d PreSelected (tau=%%d)\\n\", ",
  693. " depth, II, trpt->tau);",
  694. "#endif",
  695. "#endif",
  696. " goto Again;",
  697. " }",
  698. " }",
  699. " trpt->tau &= ~32;",
  700. "#endif",
  701. "Again:",
  702. " /* The Main Expansion Loop over Processes */",
  703. " trpt->o_pm &= ~(8|16|32|64); /* fairness-marks */",
  704. "#ifndef NOFAIR",
  705. " if (fairness && boq == -1",
  706. "#ifdef VERI",
  707. " && (!(trpt->tau&4) && !((trpt-1)->tau&128))",
  708. "#endif",
  709. " && !(trpt->tau&8))",
  710. " { /* A_bit = 1; Cnt = N in acc states with A_bit 0 */",
  711. " if (!(now._a_t&2))", /* A-bit not set */
  712. " {",
  713. " if (a_cycles && (trpt->o_pm&2))",
  714. " { /* Accepting state */",
  715. " now._a_t |= 2;",
  716. " now._cnt[now._a_t&1] = now._nr_pr + 1;", /* NEW +1 */
  717. " trpt->o_pm |= 8;",
  718. "#ifdef DEBUG",
  719. " printf(\"%%3d: fairness Rule 1: cnt=%%d, _a_t=%%d\\n\",",
  720. " depth, now._cnt[now._a_t&1], now._a_t);",
  721. "#endif",
  722. " }",
  723. " } else", /* A-bit set */
  724. " { /* A_bit = 0 when Cnt 0 */",
  725. " if (now._cnt[now._a_t&1] == 1)", /* NEW: 1 iso 0 */
  726. " { now._a_t &= ~2;", /* reset a-bit */
  727. " now._cnt[now._a_t&1] = 0;", /* NEW: reset cnt */
  728. " trpt->o_pm |= 16;",
  729. "#ifdef DEBUG",
  730. " printf(\"%%3d: fairness Rule 3: _a_t = %%d\\n\",",
  731. " depth, now._a_t);",
  732. "#endif",
  733. " } } }",
  734. "#endif",
  735. " for (II = From; II >= To; II -= 1)",
  736. " {",
  737. "#if SYNC",
  738. " /* no rendezvous with same proc */",
  739. " if (boq != -1 && trpt->pr == II) continue;",
  740. "#endif",
  741. "Veri0: this = pptr(II);",
  742. " tt = (short) ((P0 *)this)->_p;",
  743. " ot = (uchar) ((P0 *)this)->_t;",
  744. "#ifdef NIBIS",
  745. " /* don't repeat a previous preselected expansion */",
  746. " /* could hit this if reduction proviso was false */",
  747. " t = trans[ot][tt];",
  748. " if (!(trpt->tau&4)", /* not claim */
  749. " && !(trpt->tau&1)", /* not timeout */
  750. " && !(trpt->tau&32)", /* not preselected */
  751. " && (t->atom & 8)", /* local */
  752. " && boq == -1", /* not inside rendezvous */
  753. " && From != To)", /* not inside atomic seq */
  754. " { if (t->qu[0] == 0", /* unconditional */
  755. " || q_cond(II, t))", /* true condition */
  756. " { m = t->om;",
  757. " if (m>n||(n>3&&m!=0)) n=m;",
  758. " continue; /* did it before */",
  759. " } }",
  760. "#endif",
  761. " trpt->o_pm &= ~1; /* no move in this pid yet */",
  762. "#ifdef EVENT_TRACE",
  763. " (trpt+1)->o_event = now._event;",
  764. "#endif",
  765. " /* Fairness: Cnt++ when Cnt == II */",
  766. "#ifndef NOFAIR",
  767. " trpt->o_pm &= ~64; /* didn't apply rule 2 */",
  768. " if (fairness",
  769. " && boq == -1", /* not mid rv - except rcv - NEW 3.0.8 */
  770. " && !(trpt->o_pm&32)", /* Rule 2 not in effect */
  771. " && (now._a_t&2)", /* A-bit is set */
  772. " && now._cnt[now._a_t&1] == II+2)",
  773. " { now._cnt[now._a_t&1] -= 1;",
  774. "#ifdef VERI",
  775. " /* claim need not participate */",
  776. " if (II == 1)",
  777. " now._cnt[now._a_t&1] = 1;",
  778. "#endif",
  779. "#ifdef DEBUG",
  780. " printf(\"%%3d: proc %%d fairness \", depth, II);",
  781. " printf(\"Rule 2: --cnt to %%d (%%d)\\n\",",
  782. " now._cnt[now._a_t&1], now._a_t);",
  783. "#endif",
  784. " trpt->o_pm |= (32|64);",
  785. " }",
  786. "#endif",
  787. "#ifdef HAS_PROVIDED",
  788. " if (!provided(II, ot, tt, t)) continue;",
  789. "#endif",
  790. " /* check all trans of proc II - escapes first */",
  791. "#ifdef HAS_UNLESS",
  792. " trpt->e_state = 0;",
  793. "#endif",
  794. "#ifdef EVENT_TRACE",
  795. " (trpt+1)->pr = II;",
  796. "#endif",
  797. " for (t = trans[ot][tt]; t; t = t->nxt)",
  798. " {",
  799. "#ifdef HAS_UNLESS",
  800. " /* exploring all transitions from",
  801. " * a single escape state suffices",
  802. " */",
  803. " if (trpt->e_state > 0",
  804. " && trpt->e_state != t->e_trans)",
  805. " {",
  806. "#ifdef DEBUG",
  807. " printf(\"skip 2nd escape %%d (did %%d before)\\n\",",
  808. " t->e_trans, trpt->e_state);",
  809. "#endif",
  810. " break;",
  811. " }",
  812. "#endif",
  813. "#ifdef EVENT_TRACE",
  814. " (trpt+1)->o_t = t;",
  815. "#endif",
  816. "#ifdef INLINE",
  817. "#include FORWARD_MOVES",
  818. "#else",
  819. " if (!(m = do_transit(t, II, n))) continue;",
  820. "#endif",
  821. "P999: /* jumps here when move succeeds */",
  822. " if (boq == -1)",
  823. "#ifdef CTL",
  824. " /* for branching-time, can accept reduction only if */",
  825. " /* the persistent set contains just 1 transition */",
  826. " { if ((trpt->tau&32) && (trpt->o_pm&1))",
  827. " trpt->tau |= 16;",
  828. " trpt->o_pm |= 1; /* we moved */",
  829. " }",
  830. "#else",
  831. " trpt->o_pm |= 1; /* we moved */",
  832. "#endif",
  833. "#ifdef PEG",
  834. " peg[t->forw]++;",
  835. "#endif",
  836. "#if defined(VERBOSE) || defined(CHECK)",
  837. "#if defined(SVDUMP)",
  838. " printf(\"%%3d: proc %%d exec %%d \\n\", ",
  839. " depth, II, t->t_id);",
  840. "#else",
  841. " printf(\"%%3d: proc %%d exec %%d, \", ",
  842. " depth, II, t->forw);",
  843. " printf(\"%%d to %%d, %%s %%s %%s\", ",
  844. " tt, t->st, t->tp,",
  845. " (t->atom&2)?\"atomic\":\"\",",
  846. " (boq != -1)?\"rendez-vous\":\"\");",
  847. "#ifdef HAS_UNLESS",
  848. " if (t->e_trans)",
  849. " printf(\" (escapes to state %%d)\", t->st);",
  850. "#endif",
  851. " printf(\" %%saccepting [tau=%%d]\\n\",",
  852. " (trpt->o_pm&2)?\"\":\"non-\", trpt->tau);",
  853. "#endif",
  854. "#endif",
  855. "#ifdef HAS_LAST",
  856. "#ifdef VERI",
  857. " if (II != 0)",
  858. "#endif",
  859. " now._last = II - BASE;",
  860. "#endif",
  861. "#ifdef HAS_UNLESS",
  862. " trpt->e_state = t->e_trans;",
  863. "#endif",
  864. " depth++; trpt++;",
  865. " trpt->pr = II;",
  866. " trpt->st = tt;",
  867. " trpt->o_pm &= ~(2|4);",
  868. " if (t->st > 0)",
  869. " { ((P0 *)this)->_p = t->st;",
  870. "/* moved down reached[ot][t->st] = 1; */",
  871. " }",
  872. "#ifndef SAFETY",
  873. " if (a_cycles)",
  874. " { int ii;",
  875. "#define PQ ((P0 *)pptr(ii))",
  876. "#if ACCEPT_LAB>0",
  877. "#ifdef NP",
  878. " /* state 1 of np_ claim is accepting */",
  879. " if (((P0 *)pptr(0))->_p == 1)",
  880. " trpt->o_pm |= 2;",
  881. "#else",
  882. " for (ii = 0; ii < (int) now._nr_pr; ii++)",
  883. " { if (accpstate[PQ->_t][PQ->_p])",
  884. " { trpt->o_pm |= 2;",
  885. " break;",
  886. " } }",
  887. "#endif",
  888. "#endif",
  889. "#if defined(HAS_NP) && PROG_LAB>0",
  890. " for (ii = 0; ii < (int) now._nr_pr; ii++)",
  891. " { if (progstate[PQ->_t][PQ->_p])",
  892. " { trpt->o_pm |= 4;",
  893. " break;",
  894. " } }",
  895. "#endif",
  896. "#undef PQ",
  897. " }",
  898. "#endif",
  899. " trpt->o_t = t; trpt->o_n = n;",
  900. " trpt->o_ot = ot; trpt->o_tt = tt;",
  901. " trpt->o_To = To; trpt->o_m = m;",
  902. " trpt->tau = 0;",
  903. " if (boq != -1 || (t->atom&2))",
  904. " { trpt->tau |= 8;",
  905. "#ifdef VERI",
  906. " /* atomic sequence in claim */",
  907. " if((trpt-1)->tau&4)",
  908. " trpt->tau |= 4;",
  909. " else",
  910. " trpt->tau &= ~4;",
  911. " } else",
  912. " { if ((trpt-1)->tau&4)",
  913. " trpt->tau &= ~4;",
  914. " else",
  915. " trpt->tau |= 4;",
  916. " }",
  917. " /* if claim allowed timeout, so */",
  918. " /* does the next program-step: */",
  919. " if (((trpt-1)->tau&1) && !(trpt->tau&4))",
  920. " trpt->tau |= 1;",
  921. "#else",
  922. " } else",
  923. " trpt->tau &= ~8;",
  924. "#endif",
  925. " if (boq == -1 && (t->atom&2))",
  926. " { From = To = II; nlinks++;",
  927. " } else",
  928. " { From = now._nr_pr-1; To = BASE;",
  929. " }",
  930. " goto Down; /* pseudo-recursion */",
  931. "Up:",
  932. "#ifdef CHECK",
  933. " printf(\"%%d: Up - %%s\\n\", depth,",
  934. " (trpt->tau&4)?\"claim\":\"program\");",
  935. "#endif",
  936. "#ifdef MA",
  937. " if (depth <= 0) return;",
  938. " /* e.g., if first state is old, after a restart */",
  939. "#endif",
  940. "#ifdef SC",
  941. " if (CNT1 > CNT2",
  942. " && depth < hiwater - (HHH-DDD) + 2)",
  943. " {",
  944. " trpt += DDD;",
  945. " disk2stack();",
  946. " maxdepth -= DDD;",
  947. " hiwater -= DDD;",
  948. "if(verbose)",
  949. "printf(\"unzap %%d: %%d\\n\", CNT2, hiwater);",
  950. " }",
  951. "#endif",
  952. "#ifndef NOFAIR",
  953. " if (trpt->o_pm&128) /* fairness alg */",
  954. " { now._cnt[now._a_t&1] = trpt->bup.oval;",
  955. " n = 1; trpt->o_pm &= ~128;",
  956. " depth--; trpt--;",
  957. "#if defined(VERBOSE) || defined(CHECK)",
  958. " printf(\"%%3d: reversed fairness default move\\n\", depth);",
  959. "#endif",
  960. " goto Q999;",
  961. " }",
  962. "#endif",
  963. "#ifdef HAS_LAST",
  964. "#ifdef VERI",
  965. " { int d; Trail *trl;",
  966. " now._last = 0;",
  967. " for (d = 1; d < depth; d++)",
  968. " { trl = getframe(depth-d); /* was (trpt-d) */",
  969. " if (trl->pr != 0)",
  970. " { now._last = trl->pr - BASE;",
  971. " break;",
  972. " } } }",
  973. "#else",
  974. " now._last = (depth<1)?0:(trpt-1)->pr;",
  975. "#endif",
  976. "#endif",
  977. "#ifdef EVENT_TRACE",
  978. " now._event = trpt->o_event;",
  979. "#endif",
  980. "#ifndef SAFETY",
  981. " if ((now._a_t&1) && depth <= A_depth)",
  982. " return; /* to checkcycles() */",
  983. "#endif",
  984. " t = trpt->o_t; n = trpt->o_n;",
  985. " ot = trpt->o_ot; II = trpt->pr;",
  986. " tt = trpt->o_tt; this = pptr(II);",
  987. " To = trpt->o_To; m = trpt->o_m;",
  988. "#ifdef INLINE_REV",
  989. " m = do_reverse(t, II, m);",
  990. "#else",
  991. "#include REVERSE_MOVES",
  992. "R999: /* jumps here when done */",
  993. "#endif",
  994. "#ifdef VERBOSE",
  995. " printf(\"%%3d: proc %%d \", depth, II);",
  996. " printf(\"reverses %%d, %%d to %%d,\",",
  997. " t->forw, tt, t->st);",
  998. " printf(\" %%s [abit=%%d,adepth=%%d,\", ",
  999. " t->tp, now._a_t, A_depth);",
  1000. " printf(\"tau=%%d,%%d]\\n\", ",
  1001. " trpt->tau, (trpt-1)->tau);",
  1002. "#endif",
  1003. "#ifndef NOREDUCE",
  1004. " /* pass the proviso tags */",
  1005. " if ((trpt->tau&8) /* rv or atomic */",
  1006. " && (trpt->tau&16))",
  1007. " (trpt-1)->tau |= 16;",
  1008. "#ifdef SAFETY",
  1009. " if ((trpt->tau&8) /* rv or atomic */",
  1010. " && (trpt->tau&64))",
  1011. " (trpt-1)->tau |= 64;",
  1012. "#endif",
  1013. "#endif",
  1014. " depth--; trpt--;",
  1015. "#ifdef NIBIS",
  1016. " (trans[ot][tt])->om = m; /* head of list */",
  1017. "#endif",
  1018. " /* i.e., not set if rv fails */",
  1019. " if (m)",
  1020. " {",
  1021. "#if defined(VERI) && !defined(NP)",
  1022. " if (II == 0 && verbose && !reached[ot][t->st])",
  1023. " {",
  1024. " printf(\"depth %%d: Claim reached state %%d (line %%d)\\n\",",
  1025. " depth, t->st, src_claim [t->st]);",
  1026. " fflush(stdout);",
  1027. " }",
  1028. "#endif",
  1029. " reached[ot][t->st] = 1;",
  1030. " }",
  1031. "#ifdef HAS_UNLESS",
  1032. " else trpt->e_state = 0; /* undo */",
  1033. "#endif",
  1034. " if (m>n||(n>3&&m!=0)) n=m;",
  1035. " ((P0 *)this)->_p = tt;",
  1036. " } /* all options */",
  1037. "#ifndef NOFAIR",
  1038. " /* Fairness: undo Rule 2 */",
  1039. " if ((trpt->o_pm&32)",/* rule 2 was applied */
  1040. " && (trpt->o_pm&64))",/* by this process II */
  1041. " { if (trpt->o_pm&1)",/* it didn't block */
  1042. " {",
  1043. "#ifdef VERI",
  1044. " if (now._cnt[now._a_t&1] == 1)", /* NEW: 1 iso 0 */
  1045. " now._cnt[now._a_t&1] = 2;", /* NEW: 2 iso 1*/
  1046. "#endif",
  1047. " now._cnt[now._a_t&1] += 1;",
  1048. "#ifdef VERBOSE",
  1049. " printf(\"%%3d: proc %%d fairness \", depth, II);",
  1050. " printf(\"undo Rule 2, cnt=%%d, _a_t=%%d\\n\",",
  1051. " now._cnt[now._a_t&1], now._a_t);",
  1052. "#endif",
  1053. " trpt->o_pm &= ~(32|64);",
  1054. " } else", /* process blocked */
  1055. " { if (n > 0)", /* a prev proc didn't */
  1056. " {", /* start over */
  1057. " trpt->o_pm &= ~64;",
  1058. " II = From+1;",
  1059. " } } }",
  1060. "#endif",
  1061. "#ifdef VERI",
  1062. " if (II == 0) break; /* never claim */",
  1063. "#endif",
  1064. " } /* all processes */",
  1065. "#ifndef NOFAIR",
  1066. " /* Fairness: undo Rule 2 */",
  1067. " if (trpt->o_pm&32) /* remains if proc blocked */",
  1068. " {",
  1069. "#ifdef VERI",
  1070. " if (now._cnt[now._a_t&1] == 1)", /* NEW: 1 iso 0 */
  1071. " now._cnt[now._a_t&1] = 2;", /* NEW: 2 iso 1 */
  1072. "#endif",
  1073. " now._cnt[now._a_t&1] += 1;",
  1074. "#ifdef VERBOSE",
  1075. " printf(\"%%3d: proc -- fairness \", depth);",
  1076. " printf(\"undo Rule 2, cnt=%%d, _a_t=%%d\\n\",",
  1077. " now._cnt[now._a_t&1], now._a_t);",
  1078. "#endif",
  1079. " trpt->o_pm &= ~32;",
  1080. " }",
  1081. "#ifndef NP",
  1082. /* 12/97 non-progress cycles cannot be created
  1083. * by stuttering extension, here or elsewhere
  1084. */
  1085. " if (fairness",
  1086. " && n == 0 /* nobody moved */",
  1087. "#ifdef VERI",
  1088. " && !(trpt->tau&4) /* in program move */",
  1089. "#endif",
  1090. " && !(trpt->tau&8) /* not an atomic one */",
  1091. "#ifdef OTIM",
  1092. " && ((trpt->tau&1) || endstate())",
  1093. "#else",
  1094. "#ifdef ETIM",
  1095. " && (trpt->tau&1) /* already tried timeout */",
  1096. "#endif",
  1097. "#endif",
  1098. "#ifndef NOREDUCE",
  1099. " /* see below */",
  1100. " && !((trpt->tau&32) && (n == 0 || (trpt->tau&16)))",
  1101. "#endif",
  1102. " && now._cnt[now._a_t&1] > 0) /* needed more procs */",
  1103. " { depth++; trpt++;",
  1104. " trpt->o_pm |= 128 | ((trpt-1)->o_pm&(2|4));",
  1105. " trpt->bup.oval = now._cnt[now._a_t&1];",
  1106. " now._cnt[now._a_t&1] = 1; /* gh,1/99 was 0 */",
  1107. "#ifdef VERI",
  1108. " trpt->tau = 4;",
  1109. "#else",
  1110. " trpt->tau = 0;",
  1111. "#endif",
  1112. " From = now._nr_pr-1; To = BASE;",
  1113. "#if defined(VERBOSE) || defined(CHECK)",
  1114. " printf(\"%%3d: fairness default move \", depth);",
  1115. " printf(\"(all procs block)\\n\");",
  1116. "#endif",
  1117. " goto Down;",
  1118. " }",
  1119. "#endif",
  1120. "Q999: /* returns here with n>0 when done */;",
  1121. " if (trpt->o_pm&8)",
  1122. " { now._a_t &= ~2;",
  1123. " now._cnt[now._a_t&1] = 0;",
  1124. " trpt->o_pm &= ~8;",
  1125. "#ifdef VERBOSE",
  1126. " printf(\"%%3d: fairness undo Rule 1, _a_t=%%d\\n\",",
  1127. " depth, now._a_t);",
  1128. "#endif",
  1129. " }",
  1130. " if (trpt->o_pm&16)",
  1131. " { now._a_t |= 2;", /* restore a-bit */
  1132. " now._cnt[now._a_t&1] = 1;", /* NEW: restore cnt */
  1133. " trpt->o_pm &= ~16;",
  1134. "#ifdef VERBOSE",
  1135. " printf(\"%%3d: fairness undo Rule 3, _a_t=%%d\\n\",",
  1136. " depth, now._a_t);",
  1137. "#endif",
  1138. " }",
  1139. "#endif",
  1140. "#ifndef NOREDUCE",
  1141. "#ifdef SAFETY",
  1142. " /* preselected move - no successors outside stack */",
  1143. " if ((trpt->tau&32) && !(trpt->tau&64))",
  1144. " { From = now._nr_pr-1; To = BASE;",
  1145. "#ifdef DEBUG",
  1146. " printf(\"%%3d: proc %%d UnSelected (n=%%d, tau=%%d)\\n\", ",
  1147. " depth, II+1, n, trpt->tau);",
  1148. "#endif",
  1149. " n = 0; trpt->tau &= ~(16|32|64);",
  1150. " if (II >= BASE) /* II already decremented */",
  1151. " goto Resume;",
  1152. " else",
  1153. " goto Again;",
  1154. " }",
  1155. "#else",
  1156. " /* at least one move that was preselected at this */",
  1157. " /* level, blocked or truncated at the next level */",
  1158. "/* implied: #ifdef FULLSTACK */",
  1159. " if ((trpt->tau&32) && (n == 0 || (trpt->tau&16)))",
  1160. " {",
  1161. "#ifdef DEBUG",
  1162. " printf(\"%%3d: proc %%d UnSelected (n=%%d, tau=%%d)\\n\", ",
  1163. " depth, II+1, n, trpt->tau);",
  1164. "#endif",
  1165. " if (a_cycles && (trpt->tau&16))",
  1166. " { if (!(now._a_t&1))",
  1167. " {",
  1168. "#ifdef DEBUG",
  1169. " printf(\"%%3d: setting proviso bit\\n\", depth);",
  1170. "#endif",
  1171. "#ifndef BITSTATE",
  1172. "#ifdef MA",
  1173. "#ifdef VERI",
  1174. " (trpt-1)->proviso = 1;",
  1175. "#else",
  1176. " trpt->proviso = 1;",
  1177. "#endif",
  1178. "#else",
  1179. "#ifdef VERI",
  1180. " if ((trpt-1)->ostate)",
  1181. " ((char *)&((trpt-1)->ostate->state))[0] |= 128;",
  1182. "#else",
  1183. " ((char *)&(trpt->ostate->state))[0] |= 128;",
  1184. "#endif",
  1185. "#endif",
  1186. "#else",
  1187. "#ifdef VERI",
  1188. " if ((trpt-1)->ostate)",
  1189. " (trpt-1)->ostate->proviso = 1;",
  1190. "#else",
  1191. " trpt->ostate->proviso = 1;",
  1192. "#endif",
  1193. "#endif",
  1194. " From = now._nr_pr-1; To = BASE;",
  1195. " n = 0; trpt->tau &= ~(16|32|64);",
  1196. " goto Again; /* do full search */",
  1197. " } /* else accept reduction */",
  1198. " } else",
  1199. " { From = now._nr_pr-1; To = BASE;",
  1200. " n = 0; trpt->tau &= ~(16|32|64);",
  1201. " if (II >= BASE) /* already decremented */",
  1202. " goto Resume;",
  1203. " else",
  1204. " goto Again;",
  1205. " } }",
  1206. "/* #endif */",
  1207. "#endif",
  1208. "#endif",
  1209. " if (n == 0 || ((trpt->tau&4) && (trpt->tau&2)))",
  1210. " {",
  1211. "#ifdef DEBUG",
  1212. " printf(\"%%3d: no move [II=%%d, tau=%%d, boq=%%d]\\n\",",
  1213. " depth, II, trpt->tau, boq);",
  1214. "#endif",
  1215. "#if SYNC",
  1216. " /* ok if a rendez-vous fails: */",
  1217. " if (boq != -1) goto Done;",
  1218. "#endif",
  1219. " /* ok if no procs or we're at maxdepth */",
  1220. " if (now._nr_pr == 0",
  1221. "#ifdef OTIM",
  1222. " || endstate()",
  1223. "#endif",
  1224. " || depth >= maxdepth-1) goto Done;",
  1225. /* new location of atomic block code -- BEFORE timeout */
  1226. " if ((trpt->tau&8) && !(trpt->tau&4))",
  1227. " { trpt->tau &= ~(1|8);",
  1228. " /* 1=timeout, 8=atomic */",
  1229. " From = now._nr_pr-1; To = BASE;",
  1230. "#ifdef DEBUG",
  1231. " printf(\"%%3d: atomic step proc %%d \", depth, II);",
  1232. " printf(\"unexecutable\\n\");",
  1233. "#endif",
  1234. "#ifdef VERI",
  1235. " trpt->tau |= 4; /* switch to claim */",
  1236. "#endif",
  1237. " goto AllOver;",
  1238. " }",
  1239. "#ifdef ETIM",
  1240. " if (!(trpt->tau&1)) /* didn't try timeout yet */",
  1241. " {",
  1242. "#ifdef VERI",
  1243. " if (trpt->tau&4)",
  1244. " {",
  1245. "#ifndef NTIM",
  1246. " if (trpt->tau&2) /* requested */",
  1247. "#endif",
  1248. " { trpt->tau |= 1;",
  1249. " trpt->tau &= ~2;",
  1250. "#ifdef DEBUG",
  1251. " printf(\"%%d: timeout\\n\", depth);",
  1252. "#endif",
  1253. " goto Stutter;",
  1254. " } }",
  1255. " else",
  1256. " { /* only claim can enable timeout */",
  1257. " if ((trpt->tau&8)",
  1258. " && !((trpt-1)->tau&4))",
  1259. "/* blocks inside an atomic */ goto BreakOut;",
  1260. "#ifdef DEBUG",
  1261. " printf(\"%%d: req timeout\\n\",",
  1262. " depth);",
  1263. "#endif",
  1264. " (trpt-1)->tau |= 2; /* request */",
  1265. " goto Up;",
  1266. " }",
  1267. "#else",
  1268. "#ifdef DEBUG",
  1269. " printf(\"%%d: timeout\\n\", depth);",
  1270. "#endif",
  1271. " trpt->tau |= 1;",
  1272. " goto Again;",
  1273. "#endif",
  1274. " }",
  1275. "#endif",
  1276. /* old location of atomic block code */
  1277. "BreakOut:",
  1278. "#ifdef VERI",
  1279. "#ifndef NOSTUTTER",
  1280. #if 1
  1281. " if (!(trpt->tau&4))",
  1282. #else
  1283. /* visser's example shows this is insufficient: */
  1284. " if ((now._a_t&1) && !(trpt->tau&4))",
  1285. #endif
  1286. " { trpt->tau |= 4; /* claim stuttering */",
  1287. " trpt->tau |= 128; /* stutter mark */",
  1288. "#ifdef DEBUG",
  1289. " printf(\"%%d: claim stutter\\n\", depth);",
  1290. "#endif",
  1291. " goto Stutter;",
  1292. " }",
  1293. "#endif",
  1294. "#else",
  1295. " if (!noends && !a_cycles && !endstate())",
  1296. " uerror(\"invalid endstate\");",
  1297. "#endif",
  1298. " }",
  1299. "Done:",
  1300. " if (!(trpt->tau&8)) /* not in atomic seqs */",
  1301. " {",
  1302. "#ifndef SAFETY",
  1303. " if (n != 0", /* we made a move */
  1304. "#ifdef VERI",
  1305. " /* --after-- a program-step, i.e., */",
  1306. " /* after backtracking a claim-step */",
  1307. " && (trpt->tau&4)",
  1308. " /* with at least one running process */",
  1309. " /* unless in a stuttered accept state */",
  1310. " && ((now._nr_pr > 1) || (trpt->o_pm&2))",
  1311. "#endif",
  1312. " && !(now._a_t&1))", /* not in 2nd DFS */
  1313. " {",
  1314. "#ifndef NOFAIR",
  1315. " if (fairness)",
  1316. " {",
  1317. "#ifdef VERBOSE",
  1318. " printf(\"Consider check %%d %%d...\\n\",",
  1319. " now._a_t, now._cnt[0]);",
  1320. "#endif",
  1321. " if ((now._a_t&2) /* A-bit */",
  1322. " && (now._cnt[0] == 1))",
  1323. " checkcycles();",
  1324. " } else",
  1325. "#endif",
  1326. " if (a_cycles && (trpt->o_pm&2))",
  1327. " checkcycles();",
  1328. " }",
  1329. "#endif",
  1330. "#ifndef MA",
  1331. "#if defined(FULLSTACK) || defined(CNTRSTACK)",
  1332. "#ifdef VERI",
  1333. " if (boq == -1",
  1334. " && (((trpt->tau&4) && !(trpt->tau&128))",
  1335. " || ( (trpt-1)->tau&128)))",
  1336. "#else",
  1337. " if (boq == -1)",
  1338. "#endif",
  1339. " {",
  1340. "#ifdef DEBUG2",
  1341. "#if defined(FULLSTACK)",
  1342. " printf(\"%%d: zapping %%u (%%d)\\n\",",
  1343. " depth, trpt->ostate,",
  1344. " (trpt->ostate)?trpt->ostate->tagged:0);",
  1345. "#endif",
  1346. "#endif",
  1347. " onstack_zap();",
  1348. " }",
  1349. "#endif",
  1350. "#else",
  1351. "#ifdef VERI",
  1352. " if (boq == -1",
  1353. " && (((trpt->tau&4) && !(trpt->tau&128))",
  1354. " || ( (trpt-1)->tau&128)))",
  1355. "#else",
  1356. " if (boq == -1)",
  1357. "#endif",
  1358. " {",
  1359. "#ifdef DEBUG",
  1360. " printf(\"%%d: zapping\\n\", depth);",
  1361. "#endif",
  1362. " onstack_zap();",
  1363. "#ifndef NOREDUCE",
  1364. " if (trpt->proviso)",
  1365. " gstore((char *) &now, vsize, 1);",
  1366. "#endif",
  1367. " }",
  1368. "#endif",
  1369. " }",
  1370. " if (depth > 0) goto Up;",
  1371. "}\n",
  1372. "void",
  1373. "assert(int a, char *s, int ii, int tt, Trans *t)",
  1374. "{",
  1375. " if (!a && !noasserts)",
  1376. " { char bad[1024];",
  1377. " if (strlen(s) > 999) s[999] = '\\0';",
  1378. " sprintf(bad, \"assertion violated %%s\", s);",
  1379. " depth++; trpt++;",
  1380. " if (t) {",
  1381. " trpt->pr = ii;",
  1382. " trpt->st = tt;",
  1383. " trpt->o_t = t;",
  1384. " } else {",
  1385. " trpt->pr = (trpt-1)->pr;",
  1386. " trpt->st = (trpt-1)->st;",
  1387. " trpt->o_t = (trpt-1)->o_t;",
  1388. " }",
  1389. " uerror(bad);",
  1390. " depth--; trpt--;",
  1391. " }",
  1392. "}",
  1393. "#ifndef NOBOUNDCHECK",
  1394. "int",
  1395. "Boundcheck(int x, int y, int a1, int a2, Trans *a3)",
  1396. "{",
  1397. " assert((x >= 0 && x < y), \"- invalid array index\",",
  1398. " a1, a2, a3);",
  1399. " return x;",
  1400. "}",
  1401. "#endif",
  1402. "void",
  1403. "wrap_stats(void)",
  1404. "{ double a, b;",
  1405. "#ifdef COVEST",
  1406. " extern double log(double);\n",
  1407. "#endif",
  1408. " if (nShadow>0)",
  1409. " printf(\"%%8g states, stored (%%g visited)\\n\",",
  1410. " nstates - nShadow, nstates);",
  1411. " else",
  1412. " printf(\"%%8g states, stored\\n\", nstates);",
  1413. " printf(\"%%8g states, matched\\n\", truncs);",
  1414. "#ifdef CHECK",
  1415. " printf(\"%%8g matches within stack\\n\",truncs2);",
  1416. "#endif",
  1417. " if (nShadow>0)",
  1418. " printf(\"%%8g transitions (= visited+matched)\\n\",",
  1419. " nstates+truncs);",
  1420. " else",
  1421. " printf(\"%%8g transitions (= stored+matched)\\n\",",
  1422. " nstates+truncs);",
  1423. " printf(\"%%8g atomic steps\\n\", nlinks);",
  1424. " if (nlost) printf(\"%%g lost messages\\n\", (double)nlost);",
  1425. "#ifdef BITSTATE",
  1426. "#ifdef CHECK",
  1427. " printf(\"%%8g states allocated for dfs stack\\n\", ngrabs);",
  1428. "#endif",
  1429. " a = (double) (1<<(ssize-3)); a = 8.*a; /* avoid overflow on << */",
  1430. " b = nstates+1.;",
  1431. "#ifdef COVEST",
  1432. " printf(\"coverage estimate: %%0.1f%%%%\\n\",",
  1433. " (100.*b)/(log(1. - b / a)/log(1. - 1. / a)));",
  1434. "#endif",
  1435. " printf(\"hash factor: %%g \", a/b);",
  1436. " if (!single)",
  1437. " { if (a/b > 100.)",
  1438. "#ifdef COVEST",
  1439. " printf(\"(good confidence estimate)\\n\");",
  1440. " else if (a/b > 10.)",
  1441. " printf(\"(medium confidence estimate)\\n\");",
  1442. " else",
  1443. " printf(\"(low confidence estimate, best if >100)\\n\");",
  1444. " } else",
  1445. " { if (a/b > 1000.)",
  1446. " printf(\"(good confidence estimate)\\n\");",
  1447. " else if (a/b > 100.)",
  1448. " printf(\"(medium confidence estimate)\\n\");",
  1449. " else",
  1450. " printf(\"(low confidence estimate (1-bit hash), best if >1000)\\n\");",
  1451. "#else",
  1452. " printf(\"(expected coverage: >= 99.9%%%% on avg.)\\n\");",
  1453. " else if (a/b > 10.)",
  1454. " printf(\"(expected coverage: >= 98%%%% on avg.)\\n\");",
  1455. " else",
  1456. " printf(\"(best coverage if >100)\\n\");",
  1457. " } else",
  1458. " { if (a/b > 1000.)",
  1459. " printf(\"(expected coverage: >= 99.9%%%% on avg.)\\n\");",
  1460. " else if (a/b > 100.)",
  1461. " printf(\"(expected coverage: >= 98%%%% on avg.)\\n\");",
  1462. " else",
  1463. " printf(\"(best coverage (1-bit hash) if >1000)\\n\");",
  1464. "#endif",
  1465. " }",
  1466. "#else",
  1467. " printf(\"hash conflicts: %%g (resolved)\\n\", hcmp);",
  1468. "#endif",
  1469. "}",
  1470. "void",
  1471. "wrapup(void)",
  1472. "{ double nr1, nr2, nr3 = 0.0, nr4;",
  1473. "#ifndef BITSTATE",
  1474. " double tmp_nr;",
  1475. "#endif",
  1476. " signal(SIGINT, SIG_DFL);",
  1477. " printf(\"(%%s)\\n\", Version);",
  1478. " if (!done) printf(\"Warning: Search not completed\\n\");",
  1479. "#ifdef SC",
  1480. " (void) unlink((const char *)stackfile);",
  1481. "#endif",
  1482. "#ifndef NOREDUCE",
  1483. " printf(\" + Partial Order Reduction\\n\");",
  1484. "#endif",
  1485. "#ifdef COLLAPSE",
  1486. " printf(\" + Compression\\n\");",
  1487. "#endif",
  1488. "#ifdef MA",
  1489. " printf(\" + Graph Encoding (-DMA=%%d)\\n\", MA);",
  1490. "#ifdef R_XPT",
  1491. " printf(\" Restarted from checkpoint %%s.xpt\\n\", Source);",
  1492. "#endif",
  1493. "#endif",
  1494. "#ifdef CHECK",
  1495. "#ifdef FULLSTACK",
  1496. " printf(\" + FullStack Matching\\n\");",
  1497. "#endif",
  1498. "#ifdef CNTRSTACK",
  1499. " printf(\" + CntrStack Matching\\n\");",
  1500. "#endif",
  1501. "#endif",
  1502. "#ifdef BITSTATE",
  1503. " printf(\"\\nBit statespace search for:\\n\");",
  1504. "#else",
  1505. "#ifdef HC",
  1506. " printf(\"\\nHash-Compact %%d search for:\\n\", HC);",
  1507. "#else",
  1508. " printf(\"\\nFull statespace search for:\\n\");",
  1509. "#endif",
  1510. "#endif",
  1511. "#ifdef EVENT_TRACE",
  1512. "#ifdef NEGATED_TRACE",
  1513. " printf(\"\tnotrace assertion \t+\\n\");",
  1514. "#else",
  1515. " printf(\"\ttrace assertion \t+\\n\");",
  1516. "#endif",
  1517. "#endif",
  1518. "#ifdef VERI",
  1519. " printf(\"\tnever-claim \t+\\n\");",
  1520. " printf(\"\tassertion violations\t\");",
  1521. " if (noasserts)",
  1522. " printf(\"- (disabled by -A flag)\\n\");",
  1523. " else",
  1524. " printf(\"+ (if within scope of claim)\\n\");",
  1525. "#else",
  1526. "#ifdef NOCLAIM",
  1527. " printf(\"\tnever-claim \t- (not selected)\\n\");",
  1528. "#else",
  1529. " printf(\"\tnever-claim \t- (none specified)\\n\");",
  1530. "#endif",
  1531. " printf(\"\tassertion violations\t\");",
  1532. " if (noasserts)",
  1533. " printf(\"- (disabled by -A flag)\\n\");",
  1534. " else",
  1535. " printf(\"+\\n\");",
  1536. "#endif",
  1537. "#ifndef SAFETY",
  1538. "#ifdef NP",
  1539. " printf(\"\tnon-progress cycles \t\");",
  1540. "#else",
  1541. " printf(\"\tacceptance cycles \t\");",
  1542. "#endif",
  1543. " if (a_cycles)",
  1544. " printf(\"+ (fairness %%sabled)\\n\",",
  1545. " fairness?\"en\":\"dis\");",
  1546. " else printf(\"- (not selected)\\n\");",
  1547. "#else",
  1548. " printf(\"\tcycle checks \t- (disabled by -DSAFETY)\\n\");",
  1549. "#endif",
  1550. "#ifdef VERI",
  1551. " printf(\"\tinvalid endstates\t- \");",
  1552. " printf(\"(disabled by \");",
  1553. " if (noends)",
  1554. " printf(\"-E flag)\\n\\n\");",
  1555. " else",
  1556. " printf(\"never-claim)\\n\\n\");",
  1557. "#else",
  1558. " printf(\"\tinvalid endstates\t\");",
  1559. " if (noends)",
  1560. " printf(\"- (disabled by -E flag)\\n\\n\");",
  1561. " else",
  1562. " printf(\"+\\n\\n\");",
  1563. "#endif",
  1564. " printf(\"State-vector %%d byte, depth reached %%d\", ",
  1565. " hmax, mreached);",
  1566. " printf(\", errors: %%d\\n\", errors);",
  1567. "#ifdef MA",
  1568. " if (done)",
  1569. " { extern void dfa_stats(void);",
  1570. " if (maxgs+a_cycles+2 < MA)",
  1571. " printf(\"MA stats: -DMA=%%d is sufficient\\n\",",
  1572. " maxgs+a_cycles+2);",
  1573. " dfa_stats();",
  1574. " }",
  1575. "#endif",
  1576. " wrap_stats();",
  1577. " printf(\"(max size 2^%%d states\", ssize);",
  1578. "#ifdef CHECK",
  1579. " printf(\", stackframes: %%d/%%d)\\n\\n\", smax, svmax);",
  1580. " printf(\"stats: fa %%d, fh %%d, zh %%d, zn %%d - \",",
  1581. " Fa, Fh, Zh, Zn);",
  1582. " printf(\"check %%d holds %%d\\n\", Ccheck, Cholds);",
  1583. " printf(\"stack stats: puts %%d, probes %%d, zaps %%d\\n\",",
  1584. " PUT, PROBE, ZAPS);",
  1585. "#else",
  1586. " printf(\")\\n\\n\");",
  1587. "#endif",
  1588. "#ifdef MEMCNT",
  1589. "#if defined(BITSTATE) || !defined(NOCOMP)",
  1590. " nr1 = (nstates-nShadow)*",
  1591. " (double)(hmax+sizeof(struct H_el)-sizeof(unsigned));",
  1592. " nr2 = (double) ((maxdepth+3)*sizeof(Trail));",
  1593. "#ifndef BITSTATE",
  1594. "#if !defined(MA) || defined(COLLAPSE)",
  1595. " nr3 = (double) (1<<ssize)*sizeof(struct H_el *);",
  1596. "#endif",
  1597. "#else",
  1598. " nr3 = (double) (1<<(ssize-3));",
  1599. "#ifdef CNTRSTACK",
  1600. " nr3 += (double) (1<<(ssize-3));",
  1601. "#endif",
  1602. "#ifdef FULLSTACK",
  1603. " overhead += (double) (1<<(ssize-3))*sizeof(struct H_el *);",
  1604. "#endif",
  1605. "#endif",
  1606. " nr4 = (double) (svmax * (sizeof(Svtack) + hmax))",
  1607. " + (double) (smax * (sizeof(Stack) + Maxbody));",
  1608. " overhead = overhead - nr2 + fragment;",
  1609. "#ifndef MA",
  1610. " if (memcnt < nr1+nr2+nr3+nr4)",
  1611. "#else",
  1612. " if (1)",
  1613. "#endif",
  1614. " { printf(\"Stats on memory usage (in Megabytes):\\n\");",
  1615. " printf(\"%%-6.3f\tequivalent memory usage for states\",",
  1616. " nr1/1000000.);",
  1617. " printf(\" (stored*(State-vector + overhead))\\n\");",
  1618. "#ifdef BITSTATE",
  1619. " printf(\"%%-6.3f\tmemory used for hash-array (-w%%d)\\n\",",
  1620. " nr3/1000000., ssize);",
  1621. "#else",
  1622. " tmp_nr = memcnt-nr3-nr4-(overhead+nr2-fragment);",
  1623. " if (tmp_nr < 0.0) tmp_nr = 0.;",
  1624. " printf(\"%%-6.3f\tactual memory usage for states\",",
  1625. " tmp_nr/1000000.);",
  1626. " printf(\" (\");",
  1627. " if (tmp_nr > 0.)",
  1628. " { if (tmp_nr > nr1)",
  1629. " printf(\"unsuccessful \");",
  1630. " printf(\"compression: %%.2f%%%%)\\n\",",
  1631. " (100.0*tmp_nr)/nr1);",
  1632. " } else",
  1633. " printf(\"less than 1k)\\n\");",
  1634. "#ifndef MA",
  1635. " if (tmp_nr > 0.)",
  1636. " { printf(\"\tState-vector as stored = %%.0f byte\",",
  1637. " (tmp_nr)/(nstates-nShadow) -",
  1638. " (double) (sizeof(struct H_el) - sizeof(unsigned)));",
  1639. " printf(\" + %%d byte overhead\\n\",",
  1640. " sizeof(struct H_el)-sizeof(unsigned));",
  1641. " }",
  1642. "#endif",
  1643. "#if !defined(MA) || defined(COLLAPSE)",
  1644. " printf(\"%%-6.3f\tmemory used for hash-table (-w%%d)\\n\",",
  1645. " nr3/1000000., ssize);",
  1646. "#endif",
  1647. "#endif",
  1648. " printf(\"%%-6.3f\tmemory used for DFS stack (-m%%d)\\n\",",
  1649. " nr2/1000000., maxdepth);",
  1650. " /* remainder is mem used for proc and chan stacks */",
  1651. " /* and memory lost in allocator (=fragment) */",
  1652. " printf(\"%%-6.3f\ttotal actual memory usage\\n\\n\",",
  1653. " memcnt/1000000.);",
  1654. " } else",
  1655. "#endif",
  1656. " printf(\"%%-6.3f\tmemory usage (Mbyte)\\n\\n\",",
  1657. " memcnt/1000000.);",
  1658. "#endif",
  1659. "#ifdef COLLAPSE",
  1660. " printf(\"nr of templates: [ globals procs chans ]\\n\");",
  1661. " printf(\"collapse counts: [ \");",
  1662. " { int i; for (i = 0; i < 256+2; i++)",
  1663. " if (ncomps[i] != 0)",
  1664. " printf(\"%%d \", ncomps[i]);",
  1665. " printf(\"]\\n\");",
  1666. " }",
  1667. "#endif",
  1668. " if ((done || verbose) && !no_rck) do_reach();",
  1669. "#ifdef PEG",
  1670. " { int i;",
  1671. " printf(\"\\nPeg Counts (transitions executed):\\n\");",
  1672. " for (i = 1; i < NTRANS; i++)",
  1673. " { if (peg[i]) putpeg(i, peg[i]);",
  1674. " } }",
  1675. "#endif",
  1676. "#ifdef VAR_RANGES",
  1677. " dumpranges();",
  1678. "#endif",
  1679. "#ifdef SVDUMP",
  1680. " if (vprefix > 0) close(svfd);",
  1681. "#endif",
  1682. " exit(0);",
  1683. "}\n",
  1684. "void",
  1685. "stopped(int arg)",
  1686. "{ printf(\"Interrupted\\n\");",
  1687. " wrapup();",
  1688. "}",
  1689. "void",
  1690. "d_hash(uchar *Cp, int Om)",
  1691. "{ long z = (long) HASH_CONST[HASH_NR];",
  1692. " long *q, *r, h;",
  1693. " long m, n;",
  1694. "#ifndef BCOMP",
  1695. " uchar *cp = Cp;",
  1696. " long om = (long) Om;",
  1697. "#else",
  1698. " uchar *cp = (uchar *) &comp_now;",
  1699. " char *vv = (char *) Cp;",
  1700. " char *v = (char *) &comp_now;",
  1701. " long i, om;",
  1702. " for (i = 0; i < Om; i++, vv++)",
  1703. " if (!Mask[i]) *v++ = *vv;",
  1704. " for (i = 0; i < WS-1; i++)",
  1705. " *v++ = 0;",
  1706. " v -= i;",
  1707. " om = v - (char *)&comp_now;",
  1708. "#endif",
  1709. " h = (om+sizeof(long)-1)/sizeof(long);",
  1710. " m = n = -1;",
  1711. " q = r = (long *) cp;",
  1712. " r += (long) h;",
  1713. " do {",
  1714. " if (m < 0)",
  1715. " { m += m;",
  1716. " m ^= z;",
  1717. " } else",
  1718. " m += m;",
  1719. " m ^= *q++;",
  1720. " if (n < 0)",
  1721. " { n += n;",
  1722. " n ^= z;",
  1723. " } else",
  1724. " n += n;",
  1725. " n ^= *--r;",
  1726. " } while (--h > 0);",
  1727. " J1 = (m ^ (m>>(8*sizeof(long)-ssize)))&mask;",
  1728. " J2 = (n ^ (n>>(8*sizeof(long)-ssize)))&mask;",
  1729. "#if 0",
  1730. " j3 = (1<<(J1&7)); j1 = J1>>3;",
  1731. " j4 = (1<<(J2&7)); j2 = J2>>3;",
  1732. "#endif",
  1733. " if (!single)",
  1734. " { j3 = (1<<(J1&7)); j2 = J2>>3;",
  1735. " j4 = (1<<(J2&7)); j1 = J1>>3;",
  1736. " } else /* single-bit address */",
  1737. " { J1 = J1^J2; /* use all bits */",
  1738. " j3 = (1<<(J1&7)); j2 = J1>>3;",
  1739. " j1 = 0; j4 = 1;",
  1740. " }",
  1741. "}\n",
  1742. "#ifdef HYBRID_HASH",
  1743. "long",
  1744. "#else",
  1745. "void",
  1746. "#endif",
  1747. "s_hash(uchar *cp, int om) /* single forward hash */",
  1748. "{ long z = (long) HASH_CONST[HASH_NR];",
  1749. " long *q;",
  1750. " long h;",
  1751. " long m = -1;",
  1752. " h = (om+sizeof(long)-1)/sizeof(long);",
  1753. " q = (long *) cp;",
  1754. " do {",
  1755. " if (m < 0)",
  1756. " { m += m;",
  1757. " m ^= z;",
  1758. " } else",
  1759. " m += m;",
  1760. " m ^= *q++;",
  1761. " } while (--h > 0);",
  1762. "#ifdef BITSTATE",
  1763. " if (S_Tab == H_tab)",
  1764. " j1 = (m^(m>>(8*sizeof(long)-(ssize-3))))&((1<<(ssize-3))-1);",
  1765. " else",
  1766. "#endif",
  1767. " j1 = (m^(m>>(8*sizeof(long)-ssize)))&mask;",
  1768. "#ifdef HYBRID_HASH",
  1769. "#ifndef BITSTATE",
  1770. " if ((om&(sizeof(void *)-1)) == 1) /* very badly aligned */",
  1771. " { /* use last data byte as first byte of hash */",
  1772. " j1 = (j1 & (~255)) | cp[om-1];",
  1773. " return om-1; /* perfect alignment */",
  1774. " }",
  1775. "#endif",
  1776. " return om;",
  1777. "#endif",
  1778. "}",
  1779. "#if defined(HC) || (defined(BITSTATE) && defined(LC))",
  1780. "void",
  1781. "r_hash(uchar *cp, int om) /* reverse direction from s_hash */",
  1782. "{ long z = (long) HASH_CONST[HASH_NR];",
  1783. " long *r, h, n = -1;",
  1784. " h = (om+sizeof(long)-1)/sizeof(long);",
  1785. " r = (long *) cp + h;",
  1786. " do {",
  1787. " if (n < 0)",
  1788. " { n += n;",
  1789. " n ^= z;",
  1790. " } else",
  1791. " n += n;",
  1792. " n ^= *--r;",
  1793. " } while (--h > 0);",
  1794. " J3 = n; /* the compressed state vector */",
  1795. " n = -1; /* forward hash for hash_table index */",
  1796. " h = (om+sizeof(long)-1)/sizeof(long);",
  1797. " r = (long *) cp;",
  1798. " do {",
  1799. " if (n < 0)",
  1800. " { n += n;",
  1801. " n ^= z;",
  1802. " } else",
  1803. " n += n;",
  1804. " n ^= *r++;",
  1805. " } while (--h > 0);",
  1806. " J4 = n; /* more bits, when needed */",
  1807. " j1 = (n^(n>>(8*sizeof(long)-ssize)))&((1<<(ssize-3))-1);",
  1808. "}",
  1809. "#endif",
  1810. "unsigned long TMODE = 0666; /* default permission bits for trail files */",
  1811. "int",
  1812. "main(int argc, char *argv[])",
  1813. "{ void to_compile(void);\n",
  1814. " efd = stderr; /* default */",
  1815. " while (argc > 1 && argv[1][0] == '-')",
  1816. " { switch (argv[1][1]) {",
  1817. "#ifndef SAFETY",
  1818. "#ifdef NP",
  1819. " case 'a': fprintf(efd, \"error: -a disabled\");",
  1820. " usage(efd); break;",
  1821. "#else",
  1822. " case 'a': a_cycles = 1; break;",
  1823. "#endif",
  1824. "#endif",
  1825. " case 'A': noasserts = 1; break;",
  1826. " case 'c': upto = atoi(&argv[1][2]); break;",
  1827. " case 'd': state_tables++; break;",
  1828. " case 'e': every_error = 1; break;",
  1829. " case 'E': noends = 1; break;",
  1830. "#ifdef SC",
  1831. " case 'F': if (strlen(argv[1]) > 2)",
  1832. " stackfile = &argv[1][2];",
  1833. " break;",
  1834. "#endif",
  1835. "#if !defined(SAFETY) && !defined(NOFAIR)",
  1836. " case 'f': fairness = 1; break;",
  1837. "#endif",
  1838. " case 'h': if (!argv[1][2]) usage(efd); else",
  1839. " HASH_NR = atoi(&argv[1][2])%%33; break;",
  1840. " case 'I': iterative = 2; every_error = 1; break;",
  1841. " case 'i': iterative = 1; every_error = 1; break;",
  1842. " case 'J': like_java = 1; break; /* Klaus Havelund */",
  1843. "#ifndef SAFETY",
  1844. "#ifdef NP",
  1845. " case 'l': a_cycles = 1; break;",
  1846. "#else",
  1847. " case 'l': fprintf(efd, \"error: -l disabled\");",
  1848. " usage(efd); break;",
  1849. "#endif",
  1850. "#endif",
  1851. " case 'm': maxdepth = atoi(&argv[1][2]); break;",
  1852. " case 'n': no_rck = 1; break;",
  1853. "#ifdef SVDUMP",
  1854. " case 'p': vprefix = atoi(&argv[1][2]); break;",
  1855. "#endif",
  1856. " case 'q': strict = 1; break;",
  1857. " case 'R': Nrun = atoi(&argv[1][2]); break;",
  1858. " case 's': single = 1; break;",
  1859. " case 'T': TMODE = 0444; break;",
  1860. " case 't': if (argv[1][2]) tprefix = &argv[1][2]; break;",
  1861. " case 'V': printf(\"Generated by %%s\\n\", Version);",
  1862. " to_compile(); exit(0); break;",
  1863. " case 'v': verbose = 1; break;",
  1864. " case 'w': ssize = atoi(&argv[1][2]); break;",
  1865. " case 'X': efd = stdout; break;",
  1866. " default : usage(efd); break;",
  1867. " }",
  1868. " argc--; argv++;",
  1869. " }",
  1870. " if (iterative && TMODE != 0666)",
  1871. " { TMODE = 0666;",
  1872. " fprintf(efd, \"warning: -T ignored when -i or -I is used\\n\");",
  1873. " }",
  1874. "#ifdef SC",
  1875. " omaxdepth = maxdepth;",
  1876. " hiwater = HHH = maxdepth-10;",
  1877. " DDD = HHH/2;",
  1878. " if (!stackfile)",
  1879. " { stackfile = (char *) emalloc(strlen(Source)+4+1);",
  1880. " sprintf(stackfile, \"%%s._s_\", Source);",
  1881. " }",
  1882. " if (iterative)",
  1883. " { fprintf(efd, \"error: cannot use -i or -I with -DSC\\n\");",
  1884. " exit(1);",
  1885. " }",
  1886. "#endif",
  1887. "#if defined(MERGED) && defined(PEG)",
  1888. " fprintf(efd, \"error: to allow -DPEG use: spin -o3 -a %%s\\n\", Source);",
  1889. " fprintf(efd, \" to turn off transition merge optimization\\n\");",
  1890. " exit(1);",
  1891. "#endif",
  1892. "#ifdef HC",
  1893. "#ifdef NOCOMP",
  1894. " fprintf(efd, \"error: cannot combine -DHC and -DNOCOMP\\n\");",
  1895. " exit(1);",
  1896. "#endif",
  1897. "#ifdef BITSTATE",
  1898. " fprintf(efd, \"error: cannot combine -DHC and -DBITSTATE\\n\");",
  1899. " exit(1);",
  1900. "#endif",
  1901. "#endif",
  1902. "#if defined(SAFETY) && defined(NP)",
  1903. " fprintf(efd, \"error: cannot combine -DNP and -DSAFETY\\n\");",
  1904. " exit(1);",
  1905. "#endif",
  1906. "#ifdef MA",
  1907. "#ifdef BITSTATE",
  1908. " fprintf(efd, \"error: cannot combine -DMA and -DBITSTATE\\n\");",
  1909. " exit(1);",
  1910. "#endif",
  1911. " if (MA <= 0)",
  1912. " { fprintf(efd, \"usage: -DMA=N with N > 0 and < VECTORSZ\\n\");",
  1913. " exit(1);",
  1914. " }",
  1915. "#endif",
  1916. "#ifdef COLLAPSE",
  1917. "#if defined(BITSTATE)",
  1918. " fprintf(efd, \"error: cannot combine -DBITSTATE and -DCOLLAPSE\\n\");",
  1919. " exit(1);",
  1920. "#endif",
  1921. "#if defined(NOCOMP)",
  1922. " fprintf(efd, \"error: cannot combine -DNOCOMP and -DCOLLAPSE\\n\");",
  1923. " exit(1);",
  1924. "#endif",
  1925. "#endif",
  1926. " if (maxdepth <= 0 || ssize <= 0) usage(efd);",
  1927. "#if SYNC>0 && !defined(NOREDUCE)",
  1928. " if (a_cycles && fairness)",
  1929. " { fprintf(efd, \"error: p.o. reduction not compatible with \");",
  1930. " fprintf(efd, \"fairness (-f) in models\\n\");",
  1931. " fprintf(efd, \" with rendezvous operations: \");",
  1932. " fprintf(efd, \"recompile with -DNOREDUCE\\n\");",
  1933. " exit(1);",
  1934. " }",
  1935. "#endif",
  1936. "#if defined(NOCOMP) && !defined(BITSTATE)",
  1937. " if (a_cycles)",
  1938. " { fprintf(efd, \"error: -DNOCOMP voids -l and -a\\n\");",
  1939. " exit(1);",
  1940. " }",
  1941. "#endif",
  1942. "#ifdef MEMLIM", /* MEMLIM setting takes precedence */
  1943. " memlim = (double) MEMLIM * (double) (1<<20); /* size in Mbyte */",
  1944. "#else",
  1945. "#ifdef MEMCNT",
  1946. "#if MEMCNT<31",
  1947. " memlim = (double) (1<<MEMCNT);",
  1948. "#else",
  1949. " memlim = (double) (1<<30);",
  1950. " memlim *= (double) (1<<(MEMCNT-30));",
  1951. "#endif",
  1952. "#endif",
  1953. "#endif",
  1954. "#ifndef BITSTATE",
  1955. " if (Nrun > 1) HASH_NR = Nrun - 1;",
  1956. "#endif",
  1957. " if (Nrun < 1 || Nrun > 32)",
  1958. " { fprintf(efd, \"error: invalid arg for -R\\n\");",
  1959. " usage(efd);",
  1960. " }",
  1961. "#ifndef SAFETY",
  1962. " if (fairness && !a_cycles)",
  1963. " { fprintf(efd, \"error: -f requires -a or -l\\n\");",
  1964. " usage(efd);",
  1965. " }",
  1966. "#if ACCEPT_LAB==0",
  1967. " if (a_cycles)",
  1968. "#ifndef VERI",
  1969. " { fprintf(efd, \"error: no accept labels defined \");",
  1970. " fprintf(efd, \"in model (for option -a)\\n\");",
  1971. " usage(efd);",
  1972. " }",
  1973. "#else",
  1974. " { fprintf(efd, \"warning: no explicit accept labels \");",
  1975. " fprintf(efd, \"defined in model (for -a)\\n\");",
  1976. " }",
  1977. "#endif",
  1978. "#endif",
  1979. "#endif",
  1980. "#if !defined(NOREDUCE)",
  1981. "#if defined(HAS_ENABLED)",
  1982. " fprintf(efd, \"error: reduced search precludes \");",
  1983. " fprintf(efd, \"use of 'enabled()'\\n\");",
  1984. " exit(1);",
  1985. "#endif",
  1986. "#if defined(HAS_PCVALUE)",
  1987. " fprintf(efd, \"error: reduced search precludes \");",
  1988. " fprintf(efd, \"use of 'pcvalue()'\\n\");",
  1989. " exit(1);",
  1990. "#endif",
  1991. "#if defined(HAS_BADELSE)",
  1992. " fprintf(efd, \"error: reduced search precludes \");",
  1993. " fprintf(efd, \"using 'else' combined with i/o stmnts\\n\");",
  1994. " exit(1);",
  1995. "#endif",
  1996. "#if defined(HAS_LAST)",
  1997. " fprintf(efd, \"error: reduced search precludes \");",
  1998. " fprintf(efd, \"use of _last\\n\");",
  1999. " exit(1);",
  2000. "#endif",
  2001. "#endif",
  2002. "#if SYNC>0 && !defined(NOREDUCE)",
  2003. "#ifdef HAS_UNLESS",
  2004. " fprintf(efd, \"warning: use of a rendezvous stmnts in the escape\\n\");",
  2005. " fprintf(efd, \"\tof an unless clause, could make p.o. reduction\\n\");",
  2006. " fprintf(efd, \"\tinvalid (use -DNOREDUCE to avoid this)\\n\");",
  2007. "#endif",
  2008. "#endif",
  2009. "#if !defined(REACH) && !defined(BITSTATE)",
  2010. " if (iterative != 0)",
  2011. " fprintf(efd, \"warning: -i and -I need -DREACH to work accurately\\n\");",
  2012. "#endif",
  2013. "#if defined(BITSTATE) && defined(REACH)",
  2014. " fprintf(efd, \"warning: -DREACH voided by -DBITSTATE\\n\");",
  2015. "#endif",
  2016. "#if defined(FULLSTACK) && defined(CNTRSTACK)",
  2017. " fprintf(efd, \"error: cannot combine\");",
  2018. " fprintf(efd, \" -DFULLSTACK and -DCNTRSTACK\\n\");",
  2019. " exit(1);",
  2020. "#endif",
  2021. "#ifdef VERI",
  2022. "#if ACCEPT_LAB>0",
  2023. " if (!a_cycles && !state_tables)",
  2024. " { fprintf(efd, \"warning: never-claim + accept-labels \");",
  2025. " fprintf(efd, \"requires -a flag to fully verify\\n\");",
  2026. " }",
  2027. "#endif",
  2028. "#endif",
  2029. "#ifndef SAFETY",
  2030. " if (!a_cycles && !state_tables)",
  2031. " { fprintf(efd, \"hint: this search is more efficient \");",
  2032. " fprintf(efd, \"if pan.c is compiled -DSAFETY\\n\");",
  2033. " }",
  2034. "#ifndef NOCOMP",
  2035. " if (!a_cycles)",
  2036. " S_A = 0;",
  2037. " else",
  2038. " { if (!fairness)",
  2039. " S_A = 1; /* _a_t */",
  2040. "#ifndef NOFAIR",
  2041. " else /* _a_t and _cnt[NFAIR] */",
  2042. " S_A = (&(now._cnt[0]) - (uchar *) &now) + NFAIR - 2;",
  2043. " /* -2 because first two uchars in now are masked */",
  2044. "#endif",
  2045. " }",
  2046. "#endif",
  2047. "#endif",
  2048. " signal(SIGINT, stopped);",
  2049. " mask = ((1<<ssize)-1); /* hash init */",
  2050. " trail = (Trail *) emalloc((maxdepth+3)*sizeof(Trail));",
  2051. " trail++; /* protect trpt-1 refs at depth 0 */",
  2052. "#ifdef SVDUMP",
  2053. " if (vprefix > 0)",
  2054. " { char nm[64];",
  2055. " sprintf(nm, \"%%s.svd\", Source);",
  2056. " if ((svfd = creat(nm, 0666)) <= 0)",
  2057. " { fprintf(efd, \"couldn't create %%s\\n\", nm);",
  2058. " vprefix = 0;",
  2059. " } }",
  2060. "#endif",
  2061. "#ifdef RANDSTOR",
  2062. " srand(123);",
  2063. "#endif",
  2064. "#if SYNC>0 && ASYNC==0",
  2065. " set_recvs();",
  2066. "#endif",
  2067. " run();",
  2068. " done = 1;",
  2069. " wrapup();",
  2070. " return 0;",
  2071. "}\n",
  2072. "void",
  2073. "usage(FILE *fd)",
  2074. "{",
  2075. " fprintf(fd, \"Valid Options are:\\n\");",
  2076. "#ifndef SAFETY",
  2077. "#ifdef NP",
  2078. " fprintf(fd, \"\t-a -> is disabled by -DNP \");",
  2079. " fprintf(fd, \"(-DNP compiles for -l only)\\n\");",
  2080. "#else",
  2081. " fprintf(fd, \"\t-a find acceptance cycles\\n\");",
  2082. "#endif",
  2083. "#else",
  2084. " fprintf(fd, \"\t-a,-l,-f -> are disabled by -DSAFETY\\n\");",
  2085. "#endif",
  2086. " fprintf(fd, \"\t-A ignore assert() violations\\n\");",
  2087. " fprintf(fd, \"\t-cN stop at Nth error \");",
  2088. " fprintf(fd, \"(defaults to -c1)\\n\");",
  2089. " fprintf(fd, \"\t-d print state tables and stop\\n\");",
  2090. " fprintf(fd, \"\t-e create trails for all errors\\n\");",
  2091. " fprintf(fd, \"\t-E ignore invalid endstates\\n\");",
  2092. "#ifdef SC",
  2093. " fprintf(fd, \"\t-Ffile use 'file' to store disk-stack\\n\");",
  2094. "#endif",
  2095. "#ifndef NOFAIR",
  2096. " fprintf(fd, \"\t-f add weak fairness (to -a or -l)\\n\");",
  2097. "#endif",
  2098. " fprintf(fd, \"\t-hN choose other hash-function 1..32\\n\");",
  2099. " fprintf(fd, \"\t-i search for shortest path to error\\n\");",
  2100. " fprintf(fd, \"\t-I like -i, but approximate and faster\\n\");",
  2101. " fprintf(fd, \"\t-J reverse eval order of nested unlesses\\n\");",
  2102. "#ifndef SAFETY",
  2103. "#ifdef NP",
  2104. " fprintf(fd, \"\t-l find non-progress cycles\\n\");",
  2105. "#else",
  2106. " fprintf(fd, \"\t-l find non-progress cycles -> \");",
  2107. " fprintf(fd, \"disabled, requires \");",
  2108. " fprintf(fd, \"compilation with -DNP\\n\");",
  2109. "#endif",
  2110. "#endif",
  2111. " fprintf(fd, \"\t-mN max depth N steps (default=10k)\\n\");",
  2112. " fprintf(fd, \"\t-n no listing of unreached states\\n\");",
  2113. "#ifdef SVDUMP",
  2114. " fprintf(fd, \"\t-pN create svfile (save N bytes per state)\\n\");",
  2115. "#endif",
  2116. " fprintf(fd, \"\t-q require empty chans in valid endstates\\n\");",
  2117. "#ifdef BITSTATE",
  2118. " fprintf(fd, \"\t-RN repeat run Nx with N \");",
  2119. " fprintf(fd, \"[1..32] independent hash functions\\n\");",
  2120. "#endif",
  2121. " fprintf(fd, \"\t-s 1-bit hashing (default is 2-bit)\\n\");",
  2122. " fprintf(fd, \"\t-T create trail files in read-only mode\\n\");",
  2123. " fprintf(fd, \"\t-tsuf replace .trail with .suf on trailfiles\\n\");",
  2124. " fprintf(fd, \"\t-V print SPIN version number\\n\");",
  2125. " fprintf(fd, \"\t-v verbose -- filenames in unreached state listing\\n\");",
  2126. " fprintf(fd, \"\t-wN hashtable of 2^N entries\");",
  2127. " fprintf(fd, \"(defaults to -w%%d)\\n\", ssize);",
  2128. " exit(1);",
  2129. "}",
  2130. "",
  2131. "char *",
  2132. "Malloc(unsigned long n)",
  2133. "{ char *tmp;",
  2134. "#ifdef MEMCNT",
  2135. " if (memcnt+ (double) n > memlim) goto err;",
  2136. "#endif",
  2137. "#ifdef PC",
  2138. " tmp = (char *) malloc(n);",
  2139. "#else",
  2140. " tmp = (char *) sbrk(n);",
  2141. "#endif",
  2142. " if (tmp == (char *) -1L)", /* was: if ((int)tmp == -1) */
  2143. " {",
  2144. "err:",
  2145. " printf(\"pan: out of memory\\n\");",
  2146. "#ifdef MEMCNT",
  2147. " printf(\"\t%%g bytes used\\n\", memcnt);",
  2148. " printf(\"\t%%g bytes more needed\\n\", (double) n);",
  2149. " printf(\"\t%%g bytes limit (2^MEMCNT)\\n\",",
  2150. " memlim);",
  2151. "#endif",
  2152. "#ifdef COLLAPSE",
  2153. " printf(\"hint: to reduce memory, recompile with\\n\");",
  2154. "#ifndef MA",
  2155. " printf(\" -DMA=%%d # better/slower compression, or\\n\", hmax);",
  2156. "#endif",
  2157. " printf(\" -DBITSTATE # supertrace, approximation\\n\");",
  2158. "#else",
  2159. "#ifndef BITSTATE",
  2160. " printf(\"hint: to reduce memory, recompile with\\n\");",
  2161. "#ifndef HC",
  2162. " printf(\" -DCOLLAPSE # good, fast compression, or\\n\");",
  2163. "#ifndef MA",
  2164. " printf(\" -DMA=%%d # better/slower compression, or\\n\", hmax);",
  2165. "#endif",
  2166. " printf(\" -DHC # hash-compaction, approximation\\n\");",
  2167. "#endif",
  2168. " printf(\" -DBITSTATE # supertrace, approximation\\n\");",
  2169. "#endif",
  2170. "#endif",
  2171. " wrapup();",
  2172. " }",
  2173. "#ifdef MEMCNT",
  2174. " memcnt += n;",
  2175. "#endif",
  2176. " return tmp;",
  2177. "}",
  2178. "",
  2179. "#define CHUNK (100*VECTORSZ)",
  2180. "",
  2181. "char *",
  2182. "emalloc(unsigned long n) /* never released or reallocated */",
  2183. "{ char *tmp;",
  2184. " if (n == 0)",
  2185. " return (char *) NULL;",
  2186. " if (n&(sizeof(void *)-1)) /* for proper alignment */",
  2187. " n += sizeof(void *)-(n&(sizeof(void *)-1));",
  2188. " if (left < (long) n)",
  2189. " { grow = (n < CHUNK) ? CHUNK : n;",
  2190. "#ifdef PC",
  2191. " have = Malloc(grow);",
  2192. "#else",
  2193. " /* gcc's sbrk can give non-aligned result */",
  2194. " grow += sizeof(void *); /* allow realignment */",
  2195. " have = Malloc(grow);",
  2196. " if (((unsigned) have)&(sizeof(void *)-1))",
  2197. " { have += (long) (sizeof(void *) ",
  2198. " - (((unsigned) have)&(sizeof(void *)-1)));",
  2199. " grow -= sizeof(void *);",
  2200. " }",
  2201. "#endif",
  2202. " fragment += (double) left;",
  2203. " left = grow;",
  2204. " }",
  2205. " tmp = have;",
  2206. " have += (long) n;",
  2207. " left -= (long) n;",
  2208. " memset(tmp, 0, n);",
  2209. " return tmp;",
  2210. "}",
  2211. "void",
  2212. "Uerror(char *str)",
  2213. "{ /* always fatal */",
  2214. " uerror(str);",
  2215. " wrapup();",
  2216. "}\n",
  2217. "#if defined(MA) && !defined(SAFETY)",
  2218. "int",
  2219. "Unwind(void)",
  2220. "{ Trans *t; char ot, m; short tt; short II, i;\n",
  2221. " uchar oat = now._a_t;",
  2222. " now._a_t &= ~(1|16|32);",
  2223. " memcpy((char *) &comp_now, (char *) &now, vsize);",
  2224. " now._a_t = oat;",
  2225. "Up:",
  2226. "#ifdef SC",
  2227. " trpt = getframe(depth);",
  2228. "#endif",
  2229. "#ifdef VERBOSE",
  2230. " printf(\"%%d State: \", depth);",
  2231. " for (i = 0; i < vsize; i++) printf(\"%%d%%s,\",",
  2232. " ((char *)&now)[i], Mask[i]?\"*\":\"\");",
  2233. " printf(\"\\n\");",
  2234. "#endif",
  2235. "#ifndef NOFAIR",
  2236. " if (trpt->o_pm&128) /* fairness alg */",
  2237. " { now._cnt[now._a_t&1] = trpt->bup.oval;",
  2238. " depth--;",
  2239. "#ifdef SC",
  2240. " trpt = getframe(depth);",
  2241. "#else",
  2242. " trpt--;",
  2243. "#endif",
  2244. " goto Q999;",
  2245. " }",
  2246. "#endif",
  2247. "#ifdef HAS_LAST",
  2248. "#ifdef VERI",
  2249. " { int d; Trail *trl;",
  2250. " now._last = 0;",
  2251. " for (d = 1; d < depth; d++)",
  2252. " { trl = getframe(depth-d); /* was trl = (trpt-d); */",
  2253. " if (trl->pr != 0)",
  2254. " { now._last = trl->pr - BASE;",
  2255. " break;",
  2256. " } } }",
  2257. "#else",
  2258. " now._last = (depth<1)?0:(trpt-1)->pr;",
  2259. "#endif",
  2260. "#endif",
  2261. "#ifdef EVENT_TRACE",
  2262. " now._event = trpt->o_event;",
  2263. "#endif",
  2264. " if ((now._a_t&1) && depth <= A_depth)",
  2265. " { now._a_t &= ~(1|16|32);",
  2266. " if (fairness) now._a_t |= 2; /* ? */",
  2267. " A_depth = 0;",
  2268. " goto CameFromHere; /* checkcycles() */",
  2269. " }",
  2270. " t = trpt->o_t;",
  2271. " ot = trpt->o_ot; II = trpt->pr;",
  2272. " tt = trpt->o_tt; this = pptr(II);",
  2273. " m = do_reverse(t, II, trpt->o_m);",
  2274. "#ifdef VERBOSE",
  2275. " printf(\"%%3d: proc %%d \", depth, II);",
  2276. " printf(\"reverses %%d, %%d to %%d,\",",
  2277. " t->forw, tt, t->st);",
  2278. " printf(\" %%s [abit=%%d,adepth=%%d,\", ",
  2279. " t->tp, now._a_t, A_depth);",
  2280. " printf(\"tau=%%d,%%d] <unwind>\\n\", ",
  2281. " trpt->tau, (trpt-1)->tau);",
  2282. "#endif",
  2283. " depth--;",
  2284. "#ifdef SC",
  2285. " trpt = getframe(depth);",
  2286. "#else",
  2287. " trpt--;",
  2288. "#endif",
  2289. " reached[ot][t->st] = 1;",
  2290. " ((P0 *)this)->_p = tt;",
  2291. "#ifndef NOFAIR",
  2292. " if ((trpt->o_pm&32))",
  2293. " {",
  2294. "#ifdef VERI",
  2295. " if (now._cnt[now._a_t&1] == 0)",
  2296. " now._cnt[now._a_t&1] = 1;",
  2297. "#endif",
  2298. " now._cnt[now._a_t&1] += 1;",
  2299. " }",
  2300. "Q999:",
  2301. " if (trpt->o_pm&8)",
  2302. " { now._a_t &= ~2;",
  2303. " now._cnt[now._a_t&1] = 0;",
  2304. " }",
  2305. " if (trpt->o_pm&16)",
  2306. " now._a_t |= 2;",
  2307. "#endif",
  2308. "CameFromHere:",
  2309. " if (memcmp((char *) &now, (char *) &comp_now, vsize) == 0)",
  2310. " return depth;",
  2311. " if (depth > 0) goto Up;",
  2312. " return 0;",
  2313. "}",
  2314. "#endif",
  2315. "void",
  2316. "uerror(char *str)",
  2317. "{ static char laststr[256];\n",
  2318. " if (strcmp(str, laststr))",
  2319. " printf(\"pan: %%s (at depth %%d)\\n\", str,",
  2320. " (depthfound==-1)?depth:depthfound);",
  2321. " strcpy(laststr, str);",
  2322. " errors++;",
  2323. " if (every_error != 0",
  2324. " || errors == upto)",
  2325. " {",
  2326. "#if defined(MA) && !defined(SAFETY)",
  2327. " if (strstr(str, \" cycle\"))",
  2328. " { int od = depth;",
  2329. " depthfound = Unwind();",
  2330. " depth = od;",
  2331. " }",
  2332. "#endif",
  2333. " putrail();",
  2334. "#if defined(MA) && !defined(SAFETY)",
  2335. " if (strstr(str, \" cycle\"))",
  2336. " { if (every_error)",
  2337. " printf(\"sorry: MA writes 1 trail max\\n\");",
  2338. " wrapup(); /* no recovery from unwind */",
  2339. " }",
  2340. "#endif",
  2341. " }",
  2342. " if (iterative != 0 && maxdepth > 0)",
  2343. " { maxdepth = (iterative == 1)?(depth-1):(depth/2);",
  2344. " warned = 1;",
  2345. " printf(\"pan: reducing search depth to %%d\\n\",",
  2346. " maxdepth);",
  2347. " } else if (errors >= upto && upto != 0)",
  2348. " wrapup();",
  2349. " depthfound = -1; /* tripakis */",
  2350. "}\n",
  2351. "void",
  2352. "r_ck(uchar *which, int N, int M, short *src, S_F_MAP *mp)",
  2353. "{ int i, m=0;\n",
  2354. "#ifdef VERI",
  2355. " if (M == VERI && !verbose) return;",
  2356. "#endif",
  2357. " printf(\"unreached in proctype %%s\\n\", procname[M]);",
  2358. " for (i = 1; i < N; i++)",
  2359. " if (which[i] == 0 && trans[M][i])",
  2360. " xrefsrc((int) src[i], mp, M, i);",
  2361. " else",
  2362. " m++;",
  2363. " printf(\"\t(%%d of %%d states)\\n\", N-1-m, N-1);",
  2364. "}\n",
  2365. "void",
  2366. "xrefsrc(int lno, S_F_MAP *mp, int M, int i)",
  2367. "{ Trans *T; int j;",
  2368. " for (T = trans[M][i]; T; T = T->nxt)",
  2369. " if (T && T->tp)",
  2370. " { printf(\"\\tline %%d\", lno);",
  2371. " if (verbose)",
  2372. " for (j = 0; j < sizeof(mp); j++)",
  2373. " if (i >= mp[j].from && i <= mp[j].upto)",
  2374. " { printf(\", \\\"%%s\\\"\", mp[j].fnm);",
  2375. " break;",
  2376. " }",
  2377. " printf(\", state %%d\", i);",
  2378. " if (strcmp(T->tp, \"\") != 0)",
  2379. " printf(\", \\\"%%s\\\"\", T->tp);",
  2380. " else if (stopstate[M][i])",
  2381. " printf(\", -endstate-\");",
  2382. " printf(\"\\n\");",
  2383. " }",
  2384. "}\n",
  2385. "void",
  2386. "putrail(void)",
  2387. "{ int fd; long i, j;",
  2388. " Trail *trl;",
  2389. " char snap[64], fnm[256];",
  2390. " if (iterative == 0 && Nr_Trails++ > 0)",
  2391. " sprintf(fnm, \"%%s%%d.%%s\",",
  2392. " TrailFile, Nr_Trails, tprefix);",
  2393. " else",
  2394. " sprintf(fnm, \"%%s.%%s\",",
  2395. " TrailFile, tprefix);",
  2396. " if ((fd = creat(fnm, TMODE)) <= 0)",
  2397. " { printf(\"cannot create %%s\\n\", fnm);",
  2398. " perror(\"cause\");",
  2399. " return;",
  2400. " }",
  2401. "#ifdef VERI",
  2402. " sprintf(snap, \"-2:%%d:-2\\n\", VERI);",
  2403. " write(fd, snap, strlen(snap));",
  2404. "#endif",
  2405. "#ifdef MERGED",
  2406. " sprintf(snap, \"-4:-4:-4\\n\");",
  2407. " write(fd, snap, strlen(snap));",
  2408. "#endif",
  2409. " for (i = 1; i <= depth; i++)",
  2410. " { if (i == depthfound+1)",
  2411. " write(fd, \"-1:-1:-1\\n\", 9);",
  2412. " trl = getframe(i);",
  2413. " if (trl->o_pm&128) continue;",
  2414. " sprintf(snap, \"%%d:%%d:%%d\\n\", ",
  2415. " i, trl->pr, trl->o_t->t_id);",
  2416. " j = strlen(snap);",
  2417. " if (write(fd, snap, j) != j)",
  2418. " { printf(\"pan: error writing %%s\\n\", fnm);",
  2419. " close(fd);",
  2420. " wrapup();",
  2421. " }",
  2422. " }",
  2423. " printf(\"pan: wrote %%s\\n\", fnm);",
  2424. " close(fd);",
  2425. "}\n",
  2426. "void",
  2427. "sv_save(char *won) /* push state vector onto save stack */",
  2428. "{",
  2429. " if (!svtack->nxt)",
  2430. " { svtack->nxt = (Svtack *) emalloc(sizeof(Svtack));",
  2431. " svtack->nxt->body = emalloc(vsize*sizeof(char));",
  2432. " svtack->nxt->lst = svtack;",
  2433. " svtack->nxt->m_delta = vsize;",
  2434. " svmax++;",
  2435. " } else if (vsize > svtack->nxt->m_delta)",
  2436. " { svtack->nxt->body = emalloc(vsize*sizeof(char));",
  2437. " svtack->nxt->lst = svtack;",
  2438. " svtack->nxt->m_delta = vsize;",
  2439. " svmax++;",
  2440. " }",
  2441. " svtack = svtack->nxt;",
  2442. "#if SYNC",
  2443. " svtack->o_boq = boq;",
  2444. "#endif",
  2445. " svtack->o_delta = vsize; /* don't compress */",
  2446. " memcpy((char *)(svtack->body), won, vsize);",
  2447. "#ifdef DEBUG",
  2448. " printf(\"%%d: sv_save\\n\", depth);",
  2449. "#endif",
  2450. "}\n",
  2451. "void",
  2452. "sv_restor(void) /* pop state vector from save stack */",
  2453. "{",
  2454. " memcpy((char *)&now, svtack->body, svtack->o_delta);",
  2455. "#if SYNC",
  2456. " boq = svtack->o_boq;",
  2457. "#endif",
  2458. " if (vsize != svtack->o_delta)",
  2459. " Uerror(\"sv_restor\");",
  2460. " if (!svtack->lst)",
  2461. " Uerror(\"error: v_restor\");",
  2462. " svtack = svtack->lst;",
  2463. "#ifdef DEBUG",
  2464. " printf(\" sv_restor\\n\");",
  2465. "#endif",
  2466. "}\n",
  2467. "void",
  2468. "p_restor(int h)",
  2469. "{ int i; char *z = (char *) &now;\n",
  2470. " proc_offset[h] = stack->o_offset;",
  2471. " proc_skip[h] = stack->o_skip;",
  2472. "#ifndef XUSAFE",
  2473. " p_name[h] = stack->o_name;",
  2474. "#endif",
  2475. "#ifndef NOCOMP",
  2476. " for (i = vsize + stack->o_skip; i > vsize; i--)",
  2477. " Mask[i-1] = 1; /* align */",
  2478. "#endif",
  2479. " vsize += stack->o_skip;",
  2480. " memcpy(z+vsize, stack->body, stack->o_delta);",
  2481. " vsize += stack->o_delta;",
  2482. "#ifndef NOVSZ",
  2483. " now._vsz = vsize;",
  2484. "#endif",
  2485. "#ifndef NOCOMP",
  2486. " for (i = 1; i <= Air[((P0 *)pptr(h))->_t]; i++)",
  2487. " Mask[vsize - i] = 1; /* pad */",
  2488. " Mask[proc_offset[h]] = 1; /* _pid */",
  2489. "#endif",
  2490. " if (BASE > 0 && h > 0)",
  2491. " ((P0 *)pptr(h))->_pid = h-BASE;",
  2492. " else",
  2493. " ((P0 *)pptr(h))->_pid = h;",
  2494. " i = stack->o_delqs;",
  2495. " now._nr_pr += 1;",
  2496. " if (!stack->lst) /* debugging */",
  2497. " Uerror(\"error: p_restor\");",
  2498. " stack = stack->lst;",
  2499. " this = pptr(h);",
  2500. " while (i-- > 0)",
  2501. " q_restor();",
  2502. "}\n",
  2503. "void",
  2504. "q_restor(void)",
  2505. "{ int k; char *z = (char *) &now;\n",
  2506. " q_offset[now._nr_qs] = stack->o_offset;",
  2507. " q_skip[now._nr_qs] = stack->o_skip;",
  2508. "#ifndef XUSAFE",
  2509. " q_name[now._nr_qs] = stack->o_name;",
  2510. "#endif",
  2511. " vsize += stack->o_skip;",
  2512. " memcpy(z+vsize, stack->body, stack->o_delta);",
  2513. " vsize += stack->o_delta;",
  2514. "#ifndef NOVSZ",
  2515. " now._vsz = vsize;",
  2516. "#endif",
  2517. " now._nr_qs += 1;",
  2518. "#ifndef NOCOMP",
  2519. " k = stack->o_offset - stack->o_skip;",
  2520. "#if SYNC",
  2521. " if (q_zero(now._nr_qs)) k += stack->o_delta;",
  2522. "#endif",
  2523. " for ( ; k < stack->o_offset; k++)",
  2524. " Mask[k] = 1; /* align */",
  2525. "#endif",
  2526. " if (!stack->lst) /* debugging */",
  2527. " Uerror(\"error: q_restor\");",
  2528. " stack = stack->lst;",
  2529. "}",
  2530. "typedef struct IntChunks {",
  2531. " int *ptr;",
  2532. " struct IntChunks *nxt;",
  2533. "} IntChunks;",
  2534. "IntChunks *filled_chunks[128];",
  2535. "IntChunks *empty_chunks[128];",
  2536. "int *",
  2537. "grab_ints(int nr)",
  2538. "{ IntChunks *z;",
  2539. " if (nr >= 128) Uerror(\"cannot happen grab_int\");",
  2540. " if (filled_chunks[nr])",
  2541. " { z = filled_chunks[nr];",
  2542. " filled_chunks[nr] = filled_chunks[nr]->nxt;",
  2543. " } else ",
  2544. " { z = (IntChunks *) emalloc(sizeof(IntChunks));",
  2545. " z->ptr = (int *) emalloc(nr * sizeof(int));",
  2546. " }",
  2547. " z->nxt = empty_chunks[nr];",
  2548. " empty_chunks[nr] = z;",
  2549. " return z->ptr;",
  2550. "}",
  2551. "void",
  2552. "ungrab_ints(int *p, int nr)",
  2553. "{ IntChunks *z;",
  2554. " if (!empty_chunks[nr]) Uerror(\"cannot happen ungrab_int\");",
  2555. " z = empty_chunks[nr];",
  2556. " empty_chunks[nr] = empty_chunks[nr]->nxt;",
  2557. " z->ptr = p;",
  2558. " z->nxt = filled_chunks[nr];",
  2559. " filled_chunks[nr] = z;",
  2560. "}",
  2561. #if 0
  2562. "void",
  2563. "p_q_restor(int h, int K)",
  2564. "{ int k = K-1;",
  2565. " if (!stack || !stack->lst || !stack->lst->lst)",
  2566. " Uerror(\"error: p_q_restor\");",
  2567. " /* restore globals */",
  2568. " memcpy((char *)&now, stack->body, sizeof(State)-VECTORSZ);",
  2569. " stack = stack->lst;",
  2570. " memcpy((char *) qptr(k), stack->body, Maxbody);",
  2571. " stack = stack->lst;",
  2572. "#if SYNC",
  2573. " boq = stack->o_boq;",
  2574. "#endif",
  2575. " memcpy((char *) pptr(h), stack->body, Maxbody);",
  2576. " stack = stack->lst;",
  2577. "}",
  2578. "Stack *",
  2579. "p_q_frame(void)",
  2580. "{ if (!stack->nxt)",
  2581. " { stack->nxt = (Stack *)",
  2582. " emalloc(sizeof(Stack));",
  2583. " stack->nxt->body = ",
  2584. " emalloc(Maxbody*sizeof(char));",
  2585. " stack->nxt->lst = stack;",
  2586. " smax++;",
  2587. " }",
  2588. " return stack->nxt;",
  2589. "}",
  2590. "void",
  2591. "p_q_save(int h, int K)",
  2592. "{ int k = K-1;",
  2593. " stack = p_q_frame();",
  2594. " memcpy(stack->body, (char *)pptr(h), Maxbody);",
  2595. "#if SYNC",
  2596. " stack->o_boq = boq;",
  2597. "#endif",
  2598. " stack = p_q_frame();",
  2599. " memcpy(stack->body, (char *)qptr(k), Maxbody);",
  2600. " /* save globals */",
  2601. " stack = p_q_frame();",
  2602. " memcpy(stack->body, (char *)&now, sizeof(State)-VECTORSZ);",
  2603. "}",
  2604. "void",
  2605. "bup_q(int h, int K)",
  2606. "{",
  2607. "#if VECTORSZ<=1024",
  2608. " sv_save((char *)&now);",
  2609. "#else",
  2610. " p_q_save(h, K);",
  2611. "#endif",
  2612. "}",
  2613. "void",
  2614. "unbup_q(int h, int K)",
  2615. "{",
  2616. "#if VECTORSZ<=1024",
  2617. " sv_restor();",
  2618. "#else",
  2619. " p_q_restor(h, K);",
  2620. "#endif",
  2621. "}",
  2622. #endif
  2623. "int",
  2624. "delproc(int sav, int h)",
  2625. "{ int d, i=0, o_vsize = vsize;\n",
  2626. " if (h+1 != (int) now._nr_pr) return 0;\n",
  2627. " while (now._nr_qs",
  2628. " && q_offset[now._nr_qs-1] > proc_offset[h])",
  2629. " { delq(sav);",
  2630. " i++;",
  2631. " }",
  2632. " d = vsize - proc_offset[h];",
  2633. " if (sav)",
  2634. " { if (!stack->nxt)",
  2635. " { stack->nxt = (Stack *)",
  2636. " emalloc(sizeof(Stack));",
  2637. " stack->nxt->body = ",
  2638. " emalloc(Maxbody*sizeof(char));",
  2639. " stack->nxt->lst = stack;",
  2640. " smax++;",
  2641. " }",
  2642. " stack = stack->nxt;",
  2643. " stack->o_offset = proc_offset[h];",
  2644. " stack->o_skip = proc_skip[h];",
  2645. "#ifndef XUSAFE",
  2646. " stack->o_name = p_name[h];",
  2647. "#endif",
  2648. " stack->o_delta = d;",
  2649. " stack->o_delqs = i;",
  2650. " memcpy(stack->body, (char *)pptr(h), d);",
  2651. " }",
  2652. " vsize = proc_offset[h];",
  2653. " now._nr_pr = now._nr_pr - 1;",
  2654. " memset((char *)pptr(h), 0, d);",
  2655. " vsize -= proc_skip[h];",
  2656. "#ifndef NOVSZ",
  2657. " now._vsz = vsize;",
  2658. "#endif",
  2659. "#ifndef NOCOMP",
  2660. " for (i = vsize; i < o_vsize; i++)",
  2661. " Mask[i] = 0; /* reset */",
  2662. "#endif",
  2663. " return 1;",
  2664. "}\n",
  2665. "void",
  2666. "delq(int sav)",
  2667. "{ int h = now._nr_qs - 1;",
  2668. " int d = vsize - q_offset[now._nr_qs - 1];",
  2669. "#ifndef NOCOMP",
  2670. " int k, o_vsize = vsize;",
  2671. "#endif",
  2672. " if (sav)",
  2673. " { if (!stack->nxt)",
  2674. " { stack->nxt = (Stack *)",
  2675. " emalloc(sizeof(Stack));",
  2676. " stack->nxt->body = ",
  2677. " emalloc(Maxbody*sizeof(char));",
  2678. " stack->nxt->lst = stack;",
  2679. " smax++;",
  2680. " }",
  2681. " stack = stack->nxt;",
  2682. " stack->o_offset = q_offset[h];",
  2683. " stack->o_skip = q_skip[h];",
  2684. "#ifndef XUSAFE",
  2685. " stack->o_name = q_name[h];",
  2686. "#endif",
  2687. " stack->o_delta = d;",
  2688. " memcpy(stack->body, (char *)qptr(h), d);",
  2689. " }",
  2690. " vsize = q_offset[h];",
  2691. " now._nr_qs = now._nr_qs - 1;",
  2692. " memset((char *)qptr(h), 0, d);",
  2693. " vsize -= q_skip[h];",
  2694. "#ifndef NOVSZ",
  2695. " now._vsz = vsize;",
  2696. "#endif",
  2697. "#ifndef NOCOMP",
  2698. " for (k = vsize; k < o_vsize; k++)",
  2699. " Mask[k] = 0; /* reset */",
  2700. "#endif",
  2701. "}\n",
  2702. "int",
  2703. "qs_empty(void)",
  2704. "{ int i;",
  2705. " for (i = 0; i < (int) now._nr_qs; i++)",
  2706. " { if (q_sz(i) > 0)",
  2707. " return 0;",
  2708. " }",
  2709. " return 1;",
  2710. "}\n",
  2711. "int",
  2712. "endstate(void)",
  2713. "{ int i; P0 *ptr;",
  2714. " for (i = BASE; i < (int) now._nr_pr; i++)",
  2715. " { ptr = (P0 *) pptr(i);",
  2716. " if (!stopstate[ptr->_t][ptr->_p])",
  2717. " return 0;",
  2718. " }",
  2719. " if (strict) return qs_empty();",
  2720. "#if defined(EVENT_TRACE) && !defined(OTIM)",
  2721. " if (!stopstate[EVENT_TRACE][now._event] && !a_cycles)",
  2722. " { printf(\"pan: event_trace not completed\\n\");",
  2723. " return 0;",
  2724. " }",
  2725. "#endif",
  2726. " return 1;",
  2727. "}\n",
  2728. "#ifndef SAFETY",
  2729. "void",
  2730. "checkcycles(void)",
  2731. "{ uchar o_a_t = now._a_t;",
  2732. "#ifndef NOFAIR",
  2733. " uchar o_cnt = now._cnt[1];",
  2734. "#endif",
  2735. "#ifdef FULLSTACK",
  2736. "#ifndef MA",
  2737. " struct H_el *sv = trpt->ostate; /* save */",
  2738. "#else",
  2739. " uchar prov = trpt->proviso; /* save */",
  2740. "#endif",
  2741. "#endif",
  2742. "#ifdef DEBUG",
  2743. " { int i; uchar *v = (uchar *) &now;",
  2744. " printf(\" set Seed state \");",
  2745. "#ifndef NOFAIR",
  2746. " if (fairness) printf(\"(cnt = %%d:%%d, nrpr=%%d) \",",
  2747. " now._cnt[0], now._cnt[1], now._nr_pr);",
  2748. "#endif",
  2749. " /* for (i = 0; i < n; i++) printf(\"%%d,\", v[i]); */",
  2750. " printf(\"\\n\");",
  2751. " }",
  2752. " printf(\"%%d: cycle check starts\\n\", depth);",
  2753. "#endif",
  2754. " now._a_t |= (1|16|32);",
  2755. " /* 1 = 2nd DFS; (16|32) to help hasher */",
  2756. "#ifndef NOFAIR",
  2757. #if 0
  2758. " if (fairness)",
  2759. " { now._a_t &= ~2; /* pre-apply Rule 3 */",
  2760. " now._cnt[1] = 0;", /* reset both a-bit and cnt=0 */
  2761. " /* avoid matching seed on claim stutter on this state */",
  2762. " }",
  2763. #else
  2764. " now._cnt[1] = now._cnt[0];",
  2765. #endif
  2766. "#endif",
  2767. " memcpy((char *)&A_Root, (char *)&now, vsize);",
  2768. " A_depth = depthfound = depth;",
  2769. " new_state(); /* start 2nd DFS */",
  2770. " now._a_t = o_a_t;",
  2771. "#ifndef NOFAIR",
  2772. " now._cnt[1] = o_cnt;",
  2773. "#endif",
  2774. " A_depth = 0; depthfound = -1;",
  2775. "#ifdef DEBUG",
  2776. " printf(\"%%d: cycle check returns\\n\", depth);",
  2777. "#endif",
  2778. "#ifdef FULLSTACK",
  2779. "#ifndef MA",
  2780. " trpt->ostate = sv; /* restore */",
  2781. "#else",
  2782. " trpt->proviso = prov;",
  2783. "#endif",
  2784. "#endif",
  2785. "}",
  2786. "#endif\n",
  2787. "#if defined(FULLSTACK) && defined(BITSTATE)",
  2788. "struct H_el *Free_list = (struct H_el *) 0;",
  2789. "void",
  2790. "onstack_init(void)",
  2791. "{ S_Tab = (struct H_el **)",
  2792. " emalloc((1<<(ssize-3))*sizeof(struct H_el *));",
  2793. "}",
  2794. "struct H_el *",
  2795. "grab_state(int n)",
  2796. "{ struct H_el *v, *last = 0;",
  2797. " if (H_tab == S_Tab)",
  2798. " { for (v = Free_list; v && v->tagged >= n; v=v->nxt)",
  2799. " { if (v->tagged == n)",
  2800. " { if (last)",
  2801. " last->nxt = v->nxt;",
  2802. " else",
  2803. "gotcha: Free_list = v->nxt;",
  2804. " v->tagged = 0;",
  2805. " v->nxt = 0;",
  2806. "#ifdef COLLAPSE",
  2807. " v->ln = 0;",
  2808. "#endif",
  2809. " return v;",
  2810. " }",
  2811. " Fh++; last=v;",
  2812. " }",
  2813. " /* new: second try */",
  2814. " v = Free_list;", /* try to avoid emalloc */
  2815. " if (v && v->tagged >= n)",
  2816. " goto gotcha;",
  2817. " ngrabs++;",
  2818. " }",
  2819. " return (struct H_el *)",
  2820. " emalloc(sizeof(struct H_el)+n-sizeof(unsigned));",
  2821. "}\n",
  2822. "#else",
  2823. "#define grab_state(n) (struct H_el *) \\",
  2824. " emalloc(sizeof(struct H_el)+n-sizeof(unsigned));",
  2825. "#endif",
  2826. "#ifdef COLLAPSE",
  2827. "unsigned long",
  2828. "#ifdef HYBRID_HASH",
  2829. "ordinal(char *v, long N, short tp) /* store components */",
  2830. "{ struct H_el *tmp, *ntmp; long n, m;",
  2831. " struct H_el *olst = (struct H_el *) 0;",
  2832. " n = s_hash((uchar *)v, N);",
  2833. "#else",
  2834. "ordinal(char *v, long n, short tp)",
  2835. "{ struct H_el *tmp, *ntmp; long m;",
  2836. " struct H_el *olst = (struct H_el *) 0;",
  2837. " s_hash((uchar *)v, n);",
  2838. "#endif",
  2839. " tmp = H_tab[j1];",
  2840. " if (!tmp)",
  2841. " { tmp = grab_state(n);",
  2842. " H_tab[j1] = tmp;",
  2843. " } else",
  2844. " for ( ;; olst = tmp, tmp = tmp->nxt)",
  2845. " { m = memcmp(((char *)&(tmp->state)), v, n);",
  2846. " if (n == tmp->ln)",
  2847. " {",
  2848. " if (m == 0)",
  2849. " goto done;",
  2850. " if (m < 0)",
  2851. " {",
  2852. "Insert: ntmp = grab_state(n);",
  2853. " ntmp->nxt = tmp;",
  2854. " if (!olst)",
  2855. " H_tab[j1] = ntmp;",
  2856. " else",
  2857. " olst->nxt = ntmp;",
  2858. " tmp = ntmp;",
  2859. " break;",
  2860. " } else if (!tmp->nxt)",
  2861. " {",
  2862. "Append: tmp->nxt = grab_state(n);",
  2863. " tmp = tmp->nxt;",
  2864. " break;",
  2865. " }",
  2866. " continue;",
  2867. " }",
  2868. " if (n < tmp->ln)",
  2869. " goto Insert;",
  2870. " else if (!tmp->nxt)",
  2871. " goto Append;",
  2872. " }",
  2873. " m = ++ncomps[tp];",
  2874. "#ifdef FULLSTACK",
  2875. " tmp->tagged = m;",
  2876. "#else",
  2877. " tmp->st_id = m;",
  2878. "#endif",
  2879. " memcpy(((char *)&(tmp->state)), v, n);",
  2880. " tmp->ln = n;",
  2881. "done:",
  2882. "#ifdef FULLSTACK",
  2883. " return tmp->tagged;",
  2884. "#else",
  2885. " return tmp->st_id;",
  2886. "#endif",
  2887. "}",
  2888. "",
  2889. "int",
  2890. "compress(char *vin, int nin) /* collapse compression */",
  2891. "{ char *w, *v = (char *) &comp_now;",
  2892. " int i, j;",
  2893. " unsigned long n;",
  2894. " static char *x;",
  2895. " static uchar nbytes[513]; /* 1 + 256 + 256 */",
  2896. " static unsigned short nbytelen;",
  2897. " long col_q(int, char *);",
  2898. " long col_p(int, char *);",
  2899. "#ifndef SAFETY",
  2900. " if (a_cycles)",
  2901. " *v++ = now._a_t;",
  2902. "#ifndef NOFAIR",
  2903. " if (fairness)",
  2904. " for (i = 0; i < NFAIR; i++)",
  2905. " *v++ = now._cnt[i];",
  2906. "#endif",
  2907. "#endif",
  2908. " nbytelen = 0;",
  2909. "#ifndef JOINPROCS",
  2910. " for (i = 0; i < (int) now._nr_pr; i++)",
  2911. " { n = col_p(i, (char *) 0);",
  2912. " nbytes[nbytelen] = 0;",
  2913. " *v++ = n&255;",
  2914. " if (n >= (1<<8))",
  2915. " { nbytes[nbytelen]++;",
  2916. " *v++ = (n>>8)&255;",
  2917. " }",
  2918. " if (n >= (1<<16))",
  2919. " { nbytes[nbytelen]++;",
  2920. " *v++ = (n>>16)&255;",
  2921. " }",
  2922. " if (n >= (1<<24))",
  2923. " { nbytes[nbytelen]++;",
  2924. " *v++ = (n>>24)&255;",
  2925. " }",
  2926. " nbytelen++;",
  2927. " }",
  2928. "#else",
  2929. " x = scratch;",
  2930. " for (i = 0; i < (int) now._nr_pr; i++)",
  2931. " x += col_p(i, x);",
  2932. " n = ordinal(scratch, x-scratch, 2); /* procs */",
  2933. " *v++ = n&255;",
  2934. " nbytes[nbytelen] = 0;",
  2935. " if (n >= (1<<8))",
  2936. " { nbytes[nbytelen]++;",
  2937. " *v++ = (n>>8)&255;",
  2938. " }",
  2939. " if (n >= (1<<16))",
  2940. " { nbytes[nbytelen]++;",
  2941. " *v++ = (n>>16)&255;",
  2942. " }",
  2943. " if (n >= (1<<24))",
  2944. " { nbytes[nbytelen]++;",
  2945. " *v++ = (n>>24)&255;",
  2946. " }",
  2947. " nbytelen++;",
  2948. "#endif",
  2949. "#ifdef SEPQS",
  2950. " for (i = 0; i < (int) now._nr_qs; i++)",
  2951. " { n = col_q(i, (char *) 0);",
  2952. " nbytes[nbytelen] = 0;",
  2953. " *v++ = n&255;",
  2954. " if (n >= (1<<8))",
  2955. " { nbytes[nbytelen]++;",
  2956. " *v++ = (n>>8)&255;",
  2957. " }",
  2958. " if (n >= (1<<16))",
  2959. " { nbytes[nbytelen]++;",
  2960. " *v++ = (n>>16)&255;",
  2961. " }",
  2962. " if (n >= (1<<24))",
  2963. " { nbytes[nbytelen]++;",
  2964. " *v++ = (n>>24)&255;",
  2965. " }",
  2966. " nbytelen++;",
  2967. " }",
  2968. "#endif",
  2969. "#ifdef NOVSZ",
  2970. " /* 3 = _a_t, _nr_pr, _nr_qs */",
  2971. " w = (char *) &now + 3 * sizeof(uchar);",
  2972. "#ifndef NOFAIR",
  2973. " w += NFAIR;",
  2974. "#endif",
  2975. "#else",
  2976. "#if VECTORSZ<65536",
  2977. " w = (char *) &(now._vsz) + sizeof(unsigned short);",
  2978. "#else",
  2979. " w = (char *) &(now._vsz) + sizeof(unsigned long);",
  2980. "#endif",
  2981. "#endif",
  2982. " x = scratch;",
  2983. " *x++ = now._nr_pr;",
  2984. " *x++ = now._nr_qs;",
  2985. " if (now._nr_qs > 0 && qptr(0) < pptr(0))",
  2986. " n = qptr(0) - (uchar *) w;",
  2987. " else",
  2988. " n = pptr(0) - (uchar *) w;",
  2989. " j = w - (char *) &now;",
  2990. " for (i = 0; i < n; i++, w++)",
  2991. " if (!Mask[j++]) *x++ = *w;",
  2992. "#ifndef SEPQS",
  2993. " for (i = 0; i < (int) now._nr_qs; i++)",
  2994. " x += col_q(i, x);",
  2995. "#endif",
  2996. " x--;",
  2997. " for (i = 0, j = 6; i < nbytelen; i++)",
  2998. " { if (j == 6)",
  2999. " { j = 0;",
  3000. " *(++x) = 0;",
  3001. " } else",
  3002. " j += 2;",
  3003. " *x |= (nbytes[i] << j);",
  3004. " }",
  3005. " x++;",
  3006. " for (j = 0; j < WS-1; j++)",
  3007. " *x++ = 0;",
  3008. " x -= j; j = 0;",
  3009. " n = ordinal(scratch, x-scratch, 0); /* globals */",
  3010. " *v++ = n&255;",
  3011. " if (n >= (1<< 8)) { *v++ = (n>> 8)&255; j++; }",
  3012. " if (n >= (1<<16)) { *v++ = (n>>16)&255; j++; }",
  3013. " if (n >= (1<<24)) { *v++ = (n>>24)&255; j++; }",
  3014. " *v++ = j; /* add last count as a byte */",
  3015. " for (i = 0; i < WS-1; i++)",
  3016. " *v++ = 0;",
  3017. " v -= i;",
  3018. "#if 0",
  3019. " printf(\"collapse %%d -> %%d\\n\",",
  3020. " vsize, v - (char *)&comp_now);",
  3021. "#endif",
  3022. " return v - (char *)&comp_now;",
  3023. "}",
  3024. "#else",
  3025. "#if !defined(NOCOMP)",
  3026. "int",
  3027. "compress(char *vin, int n) /* default compression */",
  3028. "{",
  3029. "#ifdef HC",
  3030. " int delta = 0;",
  3031. " r_hash((uchar *)vin, n); /* sets J3 and J4 */",
  3032. "#ifndef SAFETY",
  3033. " if (S_A)",
  3034. " { delta++; /* _a_t */",
  3035. "#ifndef NOFAIR",
  3036. " if (S_A > NFAIR)",
  3037. " delta += NFAIR; /* _cnt[] */",
  3038. "#endif",
  3039. " }",
  3040. "#endif",
  3041. " memcpy((char *) &comp_now + delta, (char *) &J3, sizeof(long));",
  3042. " delta += sizeof(long);",
  3043. "#if HC>0",
  3044. " memcpy((char *) &comp_now + delta, (char *) &J4, HC);",
  3045. " delta += HC;",
  3046. "#endif",
  3047. " return delta;",
  3048. "#else",
  3049. " char *vv = vin;",
  3050. " char *v = (char *) &comp_now;",
  3051. " int i;",
  3052. " for (i = 0; i < n; i++, vv++)",
  3053. " if (!Mask[i]) *v++ = *vv;",
  3054. " for (i = 0; i < WS-1; i++)",
  3055. " *v++ = 0;",
  3056. " v -= i;",
  3057. "#if 0",
  3058. " printf(\"compress %%d -> %%d\\n\",",
  3059. " n, v - (char *)&comp_now);",
  3060. "#endif",
  3061. " return v - (char *)&comp_now;",
  3062. "#endif",
  3063. "}",
  3064. "#endif",
  3065. "#endif",
  3066. "#if defined(FULLSTACK) && defined(BITSTATE)",
  3067. "void",
  3068. "onstack_zap(void)",
  3069. "{ struct H_el *v, *w, *last = 0;",
  3070. " struct H_el **tmp = H_tab;",
  3071. " char *nv; int n, m;\n",
  3072. " H_tab = S_Tab;",
  3073. "#ifndef NOCOMP",
  3074. " nv = (char *) &comp_now;",
  3075. " n = compress((char *)&now, vsize);",
  3076. "#else",
  3077. "#if defined(BITSTATE) && defined(LC)",
  3078. " nv = (char *) &comp_now;",
  3079. " n = compact_stack((char *)&now, vsize);",
  3080. "#else",
  3081. " nv = (char *) &now;",
  3082. " n = vsize;",
  3083. "#endif",
  3084. "#endif",
  3085. "#if !defined(HC) && !(defined(BITSTATE) && defined(LC))",
  3086. "#ifdef HYBRID_HASH",
  3087. " n = ",
  3088. "#endif",
  3089. " s_hash((uchar *)nv, n);",
  3090. "#endif",
  3091. " H_tab = tmp;",
  3092. " for (v = S_Tab[j1]; v; Zh++, last=v, v=v->nxt)",
  3093. " { m = memcmp(&(v->state), nv, n);",
  3094. " if (m == 0)",
  3095. " goto Found;",
  3096. " if (m < 0)",
  3097. " break;",
  3098. " }",
  3099. "NotFound:",
  3100. " Uerror(\"stack out of wack - zap\");",
  3101. " return;",
  3102. "Found:",
  3103. " ZAPS++;",
  3104. " if (last)",
  3105. " last->nxt = v->nxt;",
  3106. " else",
  3107. " S_Tab[j1] = v->nxt;",
  3108. " v->tagged = n;",
  3109. "#if !defined(NOREDUCE) && !defined(SAFETY)",
  3110. " v->proviso = 0;",
  3111. "#endif",
  3112. " v->nxt = last = (struct H_el *) 0;",
  3113. " for (w = Free_list; w; Fa++, last=w, w = w->nxt)",
  3114. " { if (w->tagged <= n)",
  3115. " { if (last)",
  3116. " { v->nxt = w->nxt;",
  3117. " last->nxt = v;",
  3118. " } else",
  3119. " { v->nxt = Free_list;",
  3120. " Free_list = v;",
  3121. " }",
  3122. " return;",
  3123. " }",
  3124. " if (!w->nxt)",
  3125. " { w->nxt = v;",
  3126. " return;",
  3127. " } }",
  3128. " Free_list = v;",
  3129. "}",
  3130. "void",
  3131. "onstack_put(void)",
  3132. "{ struct H_el **tmp = H_tab;",
  3133. " H_tab = S_Tab;",
  3134. " if (hstore((char *)&now, vsize, 3) != 0)",
  3135. "#if defined(BITSTATE) && defined(LC)",
  3136. " printf(\"pan: warning, double stack entry\\n\");",
  3137. "#else",
  3138. " Uerror(\"cannot happen - unstack_put\");",
  3139. "#endif",
  3140. " H_tab = tmp;",
  3141. " trpt->ostate = Lstate;",
  3142. " PUT++;",
  3143. "}",
  3144. "int",
  3145. "onstack_now(void)",
  3146. "{ struct H_el *tmp;",
  3147. " struct H_el **tmp2 = H_tab;",
  3148. " char *v; int n, m = 1;\n",
  3149. " H_tab = S_Tab;",
  3150. "#ifdef NOCOMP",
  3151. "#if defined(BITSTATE) && defined(LC)",
  3152. " v = (char *) &comp_now;",
  3153. " n = compact_stack((char *)&now, vsize);",
  3154. "#else",
  3155. " v = (char *) &now;",
  3156. " n = vsize;",
  3157. "#endif",
  3158. "#else",
  3159. " v = (char *) &comp_now;",
  3160. " n = compress((char *)&now, vsize);",
  3161. "#endif",
  3162. "#if !defined(HC) && !(defined(BITSTATE) && defined(LC))",
  3163. "#ifdef HYBRID_HASH",
  3164. " n = ",
  3165. "#endif",
  3166. " s_hash((uchar *)v, n);",
  3167. "#endif",
  3168. " H_tab = tmp2;",
  3169. " for (tmp = S_Tab[j1]; tmp; Zn++, tmp = tmp->nxt)",
  3170. " { m = memcmp(((char *)&(tmp->state)),v,n);",
  3171. " if (m <= 0)",
  3172. " { Lstate = tmp;",
  3173. " break;",
  3174. " } }",
  3175. " PROBE++;",
  3176. " return (m == 0);",
  3177. "}",
  3178. "#endif",
  3179. "#ifndef BITSTATE",
  3180. "void",
  3181. "hinit(void)",
  3182. "{",
  3183. "#ifdef MA",
  3184. "#ifdef R_XPT",
  3185. " { void r_xpoint(void);",
  3186. " r_xpoint();",
  3187. " }",
  3188. "#else",
  3189. " dfa_init(MA+a_cycles);",
  3190. "#endif",
  3191. "#endif",
  3192. "#if !defined(MA) || defined(COLLAPSE)",
  3193. " H_tab = (struct H_el **)",
  3194. " emalloc((1<<ssize)*sizeof(struct H_el *));",
  3195. "#endif",
  3196. "}",
  3197. "#endif\n",
  3198. "#if !defined(BITSTATE) || defined(FULLSTACK)",
  3199. "#ifdef DEBUG",
  3200. "void",
  3201. "dumpstate(int wasnew, char *v, int n, int tag)",
  3202. "{ int i;",
  3203. "#ifndef SAFETY",
  3204. " if (S_A)",
  3205. " { printf(\"\tstate tags %%d (%%d::%%d): \",",
  3206. " V_A, wasnew, v[0]);",
  3207. "#ifdef FULLSTACK",
  3208. " printf(\" %%d \", tag);",
  3209. "#endif",
  3210. " printf(\"\\n\");",
  3211. " }",
  3212. "#endif",
  3213. "#ifdef SDUMP",
  3214. "#ifndef NOCOMP",
  3215. " printf(\"\t State: \");",
  3216. " for (i = 0; i < vsize; i++) printf(\"%%d%%s,\",",
  3217. " ((char *)&now)[i], Mask[i]?\"*\":\"\");",
  3218. "#endif",
  3219. " printf(\"\\n\tVector: \");",
  3220. " for (i = 0; i < n; i++) printf(\"%%d,\", v[i]);",
  3221. " printf(\"\\n\");",
  3222. "#endif",
  3223. "}",
  3224. "#endif",
  3225. "#ifdef MA",
  3226. "int",
  3227. "gstore(char *vin, int nin, uchar pbit)",
  3228. "{ int n = compress(vin, nin);",
  3229. " int i, j=0;",
  3230. " static uchar Info[MA+1];",
  3231. " if (n >= MA)",
  3232. " { printf(\"pan: error, MA too small, recompile pan.c\");",
  3233. " printf(\" with -DMA=N with N>%%d\\n\", n);",
  3234. " Uerror(\"aborting\");",
  3235. " }",
  3236. " if (n > maxgs) maxgs = n;",
  3237. " for (i = 0; i < n; i++)",
  3238. " Info[i] = ((uchar *)&comp_now)[i];",
  3239. " for ( ; i < MA-1; i++)",
  3240. " Info[i] = 0;",
  3241. " Info[MA-1] = pbit;",
  3242. " if (a_cycles) /* place _a_t at the end */",
  3243. " { Info[MA] = Info[0]; Info[0] = 0; }",
  3244. " if (!dfa_store(Info))",
  3245. " { if (pbit == 0",
  3246. " && (now._a_t&1)",
  3247. " && depth > A_depth)",
  3248. " { Info[MA] &= ~(1|16|32); /* _a_t */",
  3249. " if (dfa_member(MA))", /* was !dfa_member(MA) */
  3250. " { Info[MA-1] = 4; /* off-stack bit */",
  3251. " nShadow++;",
  3252. " if (!dfa_member(MA-1))",
  3253. " {",
  3254. "#ifdef VERBOSE",
  3255. " printf(\"intersected 1st dfs stack\\n\");",
  3256. "#endif",
  3257. " return 3;",
  3258. " } } }",
  3259. "#ifdef VERBOSE",
  3260. " printf(\"new state\\n\");",
  3261. "#endif",
  3262. " return 0; /* new state */",
  3263. " }",
  3264. "#ifdef FULLSTACK",
  3265. " if (pbit == 0)",
  3266. " { Info[MA-1] = 1; /* proviso bit */",
  3267. " trpt->proviso = dfa_member(MA-1);",
  3268. " Info[MA-1] = 4; /* off-stack bit */",
  3269. " if (dfa_member(MA-1)) {",
  3270. "#ifdef VERBOSE",
  3271. " printf(\"old state\\n\");",
  3272. "#endif",
  3273. " return 1; /* off-stack */",
  3274. " } else {",
  3275. "#ifdef VERBOSE",
  3276. " printf(\"on-stack\\n\");",
  3277. "#endif",
  3278. " return 2; /* on-stack */",
  3279. " }",
  3280. " }",
  3281. "#endif",
  3282. "#ifdef VERBOSE",
  3283. " printf(\"old state\\n\");",
  3284. "#endif",
  3285. " return 1; /* old state */",
  3286. "}",
  3287. "#endif",
  3288. "#if defined(BITSTATE) && defined(LC)",
  3289. "int",
  3290. "compact_stack(char *vin, int n)", /* special case of HC4 */
  3291. "{ int delta = 0;",
  3292. " r_hash((uchar *)vin, n); /* sets J3 and J4 */",
  3293. "#ifndef SAFETY",
  3294. " delta++; /* room for state[0] |= 128 */",
  3295. "#endif",
  3296. " memcpy((char *) &comp_now + delta, (char *) &J3, sizeof(long));",
  3297. " delta += sizeof(long);",
  3298. " memcpy((char *) &comp_now + delta, (char *) &J4, sizeof(long));",
  3299. " delta += sizeof(long); /* use all available bits */",
  3300. " return delta;",
  3301. "}",
  3302. "#endif",
  3303. "int",
  3304. "hstore(char *vin, int nin, short xx)",
  3305. "{ struct H_el *tmp, *ntmp, *olst = (struct H_el *) 0;",
  3306. " char *v; int n, m=0;",
  3307. "#ifdef NOCOMP",
  3308. "#if defined(BITSTATE) && defined(LC)",
  3309. " if (S_Tab == H_tab)",
  3310. " { v = (char *) &comp_now;",
  3311. " n = compact_stack(vin, nin);",
  3312. " } else",
  3313. " { v = vin; n = nin;",
  3314. " }",
  3315. "#else",
  3316. " v = vin; n = nin;",
  3317. "#endif",
  3318. "#else",
  3319. " v = (char *) &comp_now;",
  3320. " n = compress(vin, nin);",
  3321. "#ifndef SAFETY",
  3322. " if (S_A)",
  3323. " { v[0] = 0; /* _a_t */",
  3324. "#ifndef NOFAIR",
  3325. " if (S_A > NFAIR)",
  3326. " for (m = 0; m < NFAIR; m++)",
  3327. " v[m+1] = 0; /* _cnt[] */",
  3328. "#endif",
  3329. " m = 0;",
  3330. " }",
  3331. "#endif",
  3332. "#endif",
  3333. "#if !defined(HC) && !(defined(BITSTATE) && defined(LC))",
  3334. "#ifdef HYBRID_HASH",
  3335. " n = ",
  3336. "#endif",
  3337. " s_hash((uchar *)v, n);",
  3338. "#endif",
  3339. " tmp = H_tab[j1];",
  3340. " if (!tmp)",
  3341. " { tmp = grab_state(n);",
  3342. " H_tab[j1] = tmp;",
  3343. " } else",
  3344. " { for (;; hcmp++, olst = tmp, tmp = tmp->nxt)",
  3345. " { /* skip the _a_t and the _cnt bytes */",
  3346. "#ifdef COLLAPSE",
  3347. " if (tmp->ln != 0)",
  3348. " { if (!tmp->nxt) goto Append;",
  3349. " continue;",
  3350. " }",
  3351. "#endif",
  3352. " m = memcmp(((char *)&(tmp->state)) + S_A, ",
  3353. " v + S_A, n - S_A);",
  3354. " if (m == 0) {",
  3355. "#ifdef SAFETY",
  3356. "#define wasnew 0",
  3357. "#else",
  3358. " int wasnew = 0;",
  3359. "#endif",
  3360. "#ifndef SAFETY",
  3361. "#ifndef NOCOMP",
  3362. " if (S_A)",
  3363. " { if ((((char *)&(tmp->state))[0] & V_A) != V_A)",
  3364. " { wasnew = 1; nShadow++;",
  3365. " ((char *)&(tmp->state))[0] |= V_A;",
  3366. " }",
  3367. "#ifndef NOFAIR",
  3368. " if (S_A > NFAIR)",
  3369. " { /* 0 <= now._cnt[now._a_t&1] < MAXPROC */",
  3370. " unsigned ci, bp; /* index, bit pos */",
  3371. " ci = (now._cnt[now._a_t&1] / 8);",
  3372. " bp = (now._cnt[now._a_t&1] - 8*ci);",
  3373. " if (now._a_t&1) /* use tail-bits in _cnt */",
  3374. " { ci = (NFAIR - 1) - ci;",
  3375. " bp = 7 - bp; /* bp = 0..7 */",
  3376. " }",
  3377. " ci++; /* skip over _a_t */",
  3378. " bp = 1 << bp; /* the bit mask */",
  3379. " if ((((char *)&(tmp->state))[ci] & bp)==0)",
  3380. " { if (!wasnew)",
  3381. " { wasnew = 1;",
  3382. " nShadow++;",
  3383. " }",
  3384. " ((char *)&(tmp->state))[ci] |= bp;",
  3385. " }",
  3386. " }",
  3387. " /* else: wasnew == 0, i.e., old state */",
  3388. "#endif",
  3389. " }",
  3390. "#endif",
  3391. "#endif",
  3392. "#ifdef FULLSTACK",
  3393. "#ifndef SAFETY", /* or else wasnew == 0 */
  3394. " if (wasnew)",
  3395. " { Lstate = tmp;",
  3396. " tmp->tagged |= V_A;",
  3397. " if ((now._a_t&1)",
  3398. " && (tmp->tagged&A_V)",
  3399. " && depth > A_depth)",
  3400. " {",
  3401. "intersect:",
  3402. "#ifdef CHECK",
  3403. " printf(\"1st dfs-stack intersected on state %%d+\\n\",",
  3404. " (int) tmp->st_id);",
  3405. "#endif",
  3406. " return 3;",
  3407. " }",
  3408. "#ifdef CHECK",
  3409. " printf(\"\tNew state %%d+\\n\", (int) tmp->st_id);",
  3410. "#endif",
  3411. "#ifdef DEBUG",
  3412. " dumpstate(1, (char *)&(tmp->state),n,tmp->tagged);",
  3413. "#endif",
  3414. " return 0;",
  3415. " } else",
  3416. "#endif",
  3417. " if ((S_A)?(tmp->tagged&V_A):tmp->tagged)",
  3418. " { Lstate = tmp;",
  3419. "#ifndef SAFETY",
  3420. " /* already on current dfs stack */",
  3421. " /* but may also be on 1st dfs stack */",
  3422. " if ((now._a_t&1)",
  3423. " && (tmp->tagged&A_V)",
  3424. " && depth > A_depth",
  3425. /* new (Zhang's example) */
  3426. "#ifndef NOFAIR",
  3427. " && (!fairness || now._cnt[1] <= 1)",
  3428. "#endif",
  3429. " )",
  3430. " goto intersect;",
  3431. "#endif",
  3432. "#ifdef CHECK",
  3433. " printf(\"\tStack state %%d\\n\", (int) tmp->st_id);",
  3434. "#endif",
  3435. "#ifdef DEBUG",
  3436. " dumpstate(0, (char *)&(tmp->state),n,tmp->tagged);",
  3437. "#endif",
  3438. " return 2; /* match on stack */",
  3439. " }",
  3440. "#else",
  3441. " if (wasnew)",
  3442. " {",
  3443. "#ifdef CHECK",
  3444. " printf(\"\tNew state %%d+\\n\", (int) tmp->st_id);",
  3445. "#endif",
  3446. "#ifdef DEBUG",
  3447. " dumpstate(1, (char *)&(tmp->state), n, 0);",
  3448. "#endif",
  3449. " return 0;",
  3450. " }",
  3451. "#endif",
  3452. "#ifdef CHECK",
  3453. " printf(\"\tOld state %%d\\n\", (int) tmp->st_id);",
  3454. "#endif",
  3455. "#ifdef DEBUG",
  3456. " dumpstate(0, (char *)&(tmp->state), n, 0);",
  3457. "#endif",
  3458. "#ifdef REACH",
  3459. " if (tmp->D > depth)",
  3460. " { tmp->D = depth;",
  3461. "#ifdef CHECK",
  3462. " printf(\"\t\tReVisiting (from smaller depth)\\n\");",
  3463. "#endif",
  3464. " nstates--;",
  3465. " return 0;",
  3466. " }",
  3467. "#endif",
  3468. " return 1; /* match outside stack */",
  3469. " } else if (m < 0)",
  3470. " { /* insert state before tmp */",
  3471. " ntmp = grab_state(n);",
  3472. " ntmp->nxt = tmp;",
  3473. " if (!olst)",
  3474. " H_tab[j1] = ntmp;",
  3475. " else",
  3476. " olst->nxt = ntmp;",
  3477. " tmp = ntmp;",
  3478. " break;",
  3479. " } else if (!tmp->nxt)",
  3480. " { /* append after tmp */",
  3481. "Append: tmp->nxt = grab_state(n);",
  3482. " tmp = tmp->nxt;",
  3483. " break;",
  3484. " } }",
  3485. " }",
  3486. "#ifdef CHECK",
  3487. " tmp->st_id = (unsigned) nstates;",
  3488. "#ifdef BITSTATE",
  3489. " printf(\" Push state %%d\\n\", ((int) nstates) - 1);",
  3490. "#else",
  3491. " printf(\" New state %%d\\n\", (int) nstates);",
  3492. "#endif",
  3493. "#endif",
  3494. "#ifdef REACH",
  3495. " tmp->D = depth;",
  3496. "#endif",
  3497. "#ifndef SAFETY",
  3498. "#ifndef NOCOMP",
  3499. " if (S_A)",
  3500. " { v[0] = V_A;",
  3501. "#ifndef NOFAIR",
  3502. " if (S_A > NFAIR)",
  3503. " { unsigned ci, bp; /* as above */",
  3504. " ci = (now._cnt[now._a_t&1] / 8);",
  3505. " bp = (now._cnt[now._a_t&1] - 8*ci);",
  3506. " if (now._a_t&1)",
  3507. " { ci = (NFAIR - 1) - ci;",
  3508. " bp = 7 - bp; /* bp = 0..7 */",
  3509. " }",
  3510. " v[1+ci] = 1 << bp;",
  3511. " }",
  3512. "#endif",
  3513. " }",
  3514. "#endif",
  3515. "#endif",
  3516. " memcpy(((char *)&(tmp->state)), v, n);",
  3517. "#ifdef FULLSTACK",
  3518. " tmp->tagged = (S_A)?V_A:(depth+1);",
  3519. "#ifdef DEBUG",
  3520. " dumpstate(-1, v, n, tmp->tagged);",
  3521. "#endif",
  3522. " Lstate = tmp;",
  3523. "#else",
  3524. "#ifdef DEBUG",
  3525. " dumpstate(-1, v, n, 0);",
  3526. "#endif",
  3527. "#endif",
  3528. " return 0;",
  3529. "}",
  3530. "#endif",
  3531. "#include TRANSITIONS",
  3532. "void",
  3533. "do_reach(void)",
  3534. "{",
  3535. 0,
  3536. };