pangen1.h 134 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139
  1. /***** spin: pangen1.h *****/
  2. /* Copyright (c) 1989-2005 by Lucent Technologies, Bell Laboratories. */
  3. /* All Rights Reserved. This software is for educational purposes only. */
  4. /* No guarantee whatsoever is expressed or implied by the distribution of */
  5. /* this code. Permission is given to distribute this code provided that */
  6. /* this introductory message is not removed and no monies are exchanged. */
  7. /* Software written by Gerard J. Holzmann. For tool documentation see: */
  8. /* http://spinroot.com/ */
  9. /* Send all bug-reports and/or questions to: bugs@spinroot.com */
  10. static char *Code2a[] = { /* the tail of procedure run() */
  11. "#if defined(VERI) && !defined(NOREDUCE) && !defined(NP)",
  12. " if (!state_tables",
  13. "#ifdef HAS_CODE",
  14. " && !readtrail",
  15. "#endif",
  16. " )",
  17. " { printf(\"warning: for p.o. reduction to be valid \");",
  18. " printf(\"the never claim must be stutter-invariant\\n\");",
  19. " printf(\"(never claims generated from LTL \");",
  20. " printf(\"formulae are stutter-invariant)\\n\");",
  21. " }",
  22. "#endif",
  23. " UnBlock; /* disable rendez-vous */",
  24. "#ifdef BITSTATE",
  25. #ifndef POWOW
  26. " if (udmem)",
  27. " { udmem *= 1024L*1024L;",
  28. " SS = (uchar *) emalloc(udmem);",
  29. " bstore = bstore_mod;",
  30. " } else",
  31. #endif
  32. " SS = (uchar *) emalloc(1L<<(ssize-3));",
  33. "#else",
  34. " hinit();",
  35. "#endif",
  36. "#if defined(FULLSTACK) && defined(BITSTATE)",
  37. " onstack_init();",
  38. "#endif",
  39. "#if defined(CNTRSTACK) && !defined(BFS)",
  40. " LL = (uchar *) emalloc(1L<<(ssize-3));",
  41. "#endif",
  42. " stack = ( Stack *) emalloc(sizeof(Stack));",
  43. " svtack = (Svtack *) emalloc(sizeof(Svtack));",
  44. " /* a place to point for Pptr of non-running procs: */",
  45. " noptr = (uchar *) emalloc(Maxbody * sizeof(char));",
  46. "#ifdef SVDUMP",
  47. " if (vprefix > 0)",
  48. " write(svfd, (uchar *) &vprefix, sizeof(int));",
  49. "#endif",
  50. "#ifdef VERI",
  51. " Addproc(VERI); /* never - pid = 0 */",
  52. "#endif",
  53. " active_procs(); /* started after never */",
  54. "#ifdef EVENT_TRACE",
  55. " now._event = start_event;",
  56. " reached[EVENT_TRACE][start_event] = 1;",
  57. "#endif",
  58. "#ifdef HAS_CODE",
  59. " globinit();",
  60. "#endif",
  61. "#ifdef BITSTATE",
  62. "go_again:",
  63. "#endif",
  64. " do_the_search();",
  65. "#ifdef BITSTATE",
  66. " if (--Nrun > 0 && HASH_CONST[++HASH_NR])",
  67. " { printf(\"Run %%d:\\n\", HASH_NR);",
  68. " wrap_stats();",
  69. " printf(\"\\n\");",
  70. " memset(SS, 0, 1L<<(ssize-3));",
  71. "#if defined(CNTRSTACK)",
  72. " memset(LL, 0, 1L<<(ssize-3));",
  73. "#endif",
  74. "#if defined(FULLSTACK)",
  75. " memset((uchar *) S_Tab, 0, ",
  76. " maxdepth*sizeof(struct H_el *));",
  77. "#endif",
  78. " nstates=nlinks=truncs=truncs2=ngrabs = 0;",
  79. " nlost=nShadow=hcmp = 0;",
  80. " Fa=Fh=Zh=Zn = 0;",
  81. " PUT=PROBE=ZAPS=Ccheck=Cholds = 0;",
  82. " goto go_again;",
  83. " }",
  84. "#endif",
  85. "}",
  86. "#ifdef HAS_PROVIDED",
  87. "int provided(int, uchar, int, Trans *);",
  88. "#endif",
  89. #ifndef PRINTF
  90. "int",
  91. "Printf(const char *fmt, ...)",
  92. "{ /* Make sure the args to Printf",
  93. " * are always evaluated (e.g., they",
  94. " * could contain a run stmnt)",
  95. " * but do not generate the output",
  96. " * during verification runs",
  97. " * unless explicitly wanted",
  98. " * If this fails on your system",
  99. " * compile SPIN itself -DPRINTF",
  100. " * and this code is not generated",
  101. " */",
  102. "#ifdef HAS_CODE",
  103. " if (readtrail)",
  104. " { va_list args;",
  105. " va_start(args, fmt);",
  106. " vprintf(fmt, args);",
  107. " va_end(args);",
  108. " return 1;",
  109. " }",
  110. "#endif",
  111. "#ifdef PRINTF",
  112. " va_list args;",
  113. " va_start(args, fmt);",
  114. " vprintf(fmt, args);",
  115. " va_end(args);",
  116. "#endif",
  117. " return 1;",
  118. "}",
  119. #endif
  120. "extern void printm(int);",
  121. "#ifndef SC",
  122. "#define getframe(i) &trail[i];",
  123. "#else",
  124. "static long HHH, DDD, hiwater;",
  125. "static long CNT1, CNT2;",
  126. "static int stackwrite;",
  127. "static int stackread;",
  128. "static Trail frameptr;",
  129. "Trail *",
  130. "getframe(int d)",
  131. "{",
  132. " if (CNT1 == CNT2)",
  133. " return &trail[d];",
  134. "",
  135. " if (d >= (CNT1-CNT2)*DDD)",
  136. " return &trail[d - (CNT1-CNT2)*DDD];",
  137. "",
  138. " if (!stackread",
  139. " && (stackread = open(stackfile, 0)) < 0)",
  140. " { printf(\"getframe: cannot open %%s\\n\", stackfile);",
  141. " wrapup();",
  142. " }",
  143. " if (lseek(stackread, d* (off_t) sizeof(Trail), SEEK_SET) == -1",
  144. " || read(stackread, &frameptr, sizeof(Trail)) != sizeof(Trail))",
  145. " { printf(\"getframe: frame read error\\n\");",
  146. " wrapup();",
  147. " }",
  148. " return &frameptr;",
  149. "}",
  150. "#endif",
  151. "#if !defined(SAFETY) && !defined(BITSTATE)",
  152. "#if !defined(FULLSTACK) || defined(MA)",
  153. "#define depth_of(x) A_depth /* an estimate */",
  154. "#else",
  155. "int",
  156. "depth_of(struct H_el *s)",
  157. "{ Trail *t; int d;",
  158. " for (d = 0; d <= A_depth; d++)",
  159. " { t = getframe(d);",
  160. " if (s == t->ostate)",
  161. " return d;",
  162. " }",
  163. " printf(\"pan: cannot happen, depth_of\\n\");",
  164. " return depthfound;",
  165. "}",
  166. "#endif",
  167. "#endif",
  168. "void",
  169. "pan_exit(int val)",
  170. "{ if (signoff) printf(\"--end of output--\\n\");",
  171. " exit(val);",
  172. "}",
  173. "#ifdef HAS_CODE",
  174. "char *",
  175. "transmognify(char *s)",
  176. "{ char *v, *w;",
  177. " static char buf[2][2048];",
  178. " int i, toggle = 0;",
  179. " if (!s || strlen(s) > 2047) return s;",
  180. " memset(buf[0], 0, 2048);",
  181. " memset(buf[1], 0, 2048);",
  182. " strcpy(buf[toggle], s);",
  183. " while ((v = strstr(buf[toggle], \"{c_code\")))", /* assign v */
  184. " { *v = '\\0'; v++;",
  185. " strcpy(buf[1-toggle], buf[toggle]);",
  186. " for (w = v; *w != '}' && *w != '\\0'; w++) /* skip */;",
  187. " if (*w != '}') return s;",
  188. " *w = '\\0'; w++;",
  189. " for (i = 0; code_lookup[i].c; i++)",
  190. " if (strcmp(v, code_lookup[i].c) == 0",
  191. " && strlen(v) == strlen(code_lookup[i].c))",
  192. " { if (strlen(buf[1-toggle])",
  193. " + strlen(code_lookup[i].t)",
  194. " + strlen(w) > 2047)",
  195. " return s;",
  196. " strcat(buf[1-toggle], code_lookup[i].t);",
  197. " break;",
  198. " }",
  199. " strcat(buf[1-toggle], w);",
  200. " toggle = 1 - toggle;",
  201. " }",
  202. " buf[toggle][2047] = '\\0';",
  203. " return buf[toggle];",
  204. "}",
  205. "#else",
  206. "char * transmognify(char *s) { return s; }",
  207. "#endif",
  208. "#ifdef HAS_CODE",
  209. "void",
  210. "add_src_txt(int ot, int tt)",
  211. "{ Trans *t;",
  212. " char *q;",
  213. "",
  214. " for (t = trans[ot][tt]; t; t = t->nxt)",
  215. " { printf(\"\\t\\t\");",
  216. " q = transmognify(t->tp);",
  217. " for ( ; q && *q; q++)",
  218. " if (*q == '\\n')",
  219. " printf(\"\\\\n\");",
  220. " else",
  221. " putchar(*q);",
  222. " printf(\"\\n\");",
  223. " }",
  224. "}",
  225. "void",
  226. "wrap_trail(void)",
  227. "{ static int wrap_in_progress = 0;",
  228. " int i; short II;",
  229. " P0 *z;",
  230. "",
  231. " if (wrap_in_progress++) return;",
  232. "",
  233. " printf(\"spin: trail ends after %%ld steps\\n\", depth);",
  234. " if (onlyproc >= 0)",
  235. " { if (onlyproc >= now._nr_pr) pan_exit(0);",
  236. " II = onlyproc;",
  237. " z = (P0 *)pptr(II);",
  238. " printf(\"%%3ld:\tproc %%d (%%s) \",",
  239. " depth, II, procname[z->_t]);",
  240. " for (i = 0; src_all[i].src; i++)",
  241. " if (src_all[i].tp == (int) z->_t)",
  242. " { printf(\" line %%3d\",",
  243. " src_all[i].src[z->_p]);",
  244. " break;",
  245. " }",
  246. " printf(\" (state %%2d)\", z->_p);",
  247. " if (!stopstate[z->_t][z->_p])",
  248. " printf(\" (invalid end state)\");",
  249. " printf(\"\\n\");",
  250. " add_src_txt(z->_t, z->_p);",
  251. " pan_exit(0);",
  252. " }",
  253. " printf(\"#processes %%d:\\n\", now._nr_pr);",
  254. " if (depth < 0) depth = 0;",
  255. " for (II = 0; II < now._nr_pr; II++)",
  256. " { z = (P0 *)pptr(II);",
  257. " printf(\"%%3ld:\tproc %%d (%%s) \",",
  258. " depth, II, procname[z->_t]);",
  259. " for (i = 0; src_all[i].src; i++)",
  260. " if (src_all[i].tp == (int) z->_t)",
  261. " { printf(\" line %%3d\",",
  262. " src_all[i].src[z->_p]);",
  263. " break;",
  264. " }",
  265. " printf(\" (state %%2d)\", z->_p);",
  266. " if (!stopstate[z->_t][z->_p])",
  267. " printf(\" (invalid end state)\");",
  268. " printf(\"\\n\");",
  269. " add_src_txt(z->_t, z->_p);",
  270. " }",
  271. " c_globals();",
  272. " for (II = 0; II < now._nr_pr; II++)",
  273. " { z = (P0 *)pptr(II);",
  274. " c_locals(II, z->_t);",
  275. " }",
  276. "#ifdef ON_EXIT",
  277. " ON_EXIT;",
  278. "#endif",
  279. " pan_exit(0);",
  280. "}",
  281. "FILE *",
  282. "findtrail(void)",
  283. "{ FILE *fd;",
  284. " char fnm[512], *q;",
  285. " char MyFile[512];",
  286. "",
  287. " strcpy(MyFile, TrailFile);", /* avoid problem with non-writable strings */
  288. "",
  289. " if (whichtrail)",
  290. " { sprintf(fnm, \"%%s%%d.%%s\", MyFile, whichtrail, tprefix);",
  291. " fd = fopen(fnm, \"r\");",
  292. " if (fd == NULL && (q = strchr(MyFile, \'.\')))",
  293. " { *q = \'\\0\';", /* e.g., strip .pml on original file */
  294. " sprintf(fnm, \"%%s%%d.%%s\", MyFile, whichtrail, tprefix);",
  295. " *q = \'.\';",
  296. " fd = fopen(fnm, \"r\");",
  297. " if (fd == NULL)",
  298. " { printf(\"pan: cannot find %%s%%d.%%s or %%s\\n\", ",
  299. " MyFile, whichtrail, tprefix, fnm);",
  300. " pan_exit(1);",
  301. " } }",
  302. " } else",
  303. " { sprintf(fnm, \"%%s.%%s\", MyFile, tprefix);",
  304. " fd = fopen(fnm, \"r\");",
  305. " if (fd == NULL && (q = strchr(MyFile, \'.\')))",
  306. " { *q = \'\\0\';", /* e.g., strip .pml on original file */
  307. " sprintf(fnm, \"%%s.%%s\", MyFile, tprefix);",
  308. " *q = \'.\';",
  309. " fd = fopen(fnm, \"r\");",
  310. " if (fd == NULL)",
  311. " { printf(\"pan: cannot find %%s.%%s or %%s\\n\", ",
  312. " MyFile, tprefix, fnm);",
  313. " pan_exit(1);",
  314. " } } }",
  315. " if (fd == NULL)",
  316. " { printf(\"pan: cannot find trailfile %%s\\n\", fnm);",
  317. " pan_exit(1);",
  318. " }",
  319. " return fd;",
  320. "}",
  321. "",
  322. "uchar do_transit(Trans *, short);",
  323. "",
  324. "void",
  325. "getrail(void)",
  326. "{ FILE *fd;",
  327. " char *q;",
  328. " int i, t_id, lastnever=-1; short II;",
  329. " Trans *t;",
  330. " P0 *z;",
  331. "",
  332. " fd = findtrail(); /* exits if unsuccessful */",
  333. " while (fscanf(fd, \"%%ld:%%d:%%d\\n\", &depth, &i, &t_id) == 3)",
  334. " { if (depth == -1)",
  335. " printf(\"<<<<<START OF CYCLE>>>>>\\n\");",
  336. " if (depth < 0)",
  337. " continue;",
  338. " if (i > now._nr_pr)",
  339. " { printf(\"pan: Error, proc %%d invalid pid \", i);",
  340. " printf(\"transition %%d\\n\", t_id);",
  341. " break;",
  342. " }",
  343. " II = i;",
  344. "",
  345. " z = (P0 *)pptr(II);",
  346. " for (t = trans[z->_t][z->_p]; t; t = t->nxt)",
  347. " if (t->t_id == t_id)",
  348. " break;",
  349. " if (!t)",
  350. " { for (i = 0; i < NrStates[z->_t]; i++)",
  351. " { t = trans[z->_t][i];",
  352. " if (t && t->t_id == t_id)",
  353. " { printf(\" Recovered at state %%d\\n\", i);",
  354. " z->_p = i;",
  355. " goto recovered;",
  356. " } }",
  357. " printf(\"pan: Error, proc %%d type %%d state %%d: \",",
  358. " II, z->_t, z->_p);",
  359. " printf(\"transition %%d not found\\n\", t_id);",
  360. " for (t = trans[z->_t][z->_p]; t; t = t->nxt)",
  361. " printf(\" t_id %%d -- case %%d, [%%s]\\n\",",
  362. " t->t_id, t->forw, t->tp);",
  363. " break; /* pan_exit(1); */",
  364. " }",
  365. "recovered:",
  366. " q = transmognify(t->tp);",
  367. " if (gui) simvals[0] = \'\\0\';",
  368. " this = pptr(II);",
  369. " trpt->tau |= 1;", /* timeout always possible */
  370. " if (!do_transit(t, II))",
  371. " { if (onlyproc >= 0 && II != onlyproc)",
  372. " goto moveon;",
  373. " printf(\"pan: error, next transition UNEXECUTABLE on replay\\n\");",
  374. " printf(\" most likely causes: missing c_track statements\\n\");",
  375. " printf(\" or illegal side-effects in c_expr statements\\n\");",
  376. " }",
  377. " if (onlyproc >= 0 && II != onlyproc)",
  378. " goto moveon;",
  379. " if (verbose)",
  380. " { printf(\"depth: %%3ld proc: %%3d trans: %%3d (%%d procs) \",",
  381. " depth, II, t_id, now._nr_pr);",
  382. " printf(\"forw=%%3d [%%s]\\n\", t->forw, q);",
  383. "",
  384. " c_globals();",
  385. " for (i = 0; i < now._nr_pr; i++)",
  386. " { c_locals(i, ((P0 *)pptr(i))->_t);",
  387. " }",
  388. " } else",
  389. " if (strcmp(procname[z->_t], \":never:\") == 0)",
  390. " { if (lastnever != (int) z->_p)",
  391. " { for (i = 0; src_all[i].src; i++)",
  392. " if (src_all[i].tp == (int) z->_t)",
  393. " { printf(\"MSC: ~G %%d\\n\",",
  394. " src_all[i].src[z->_p]);",
  395. " break;",
  396. " }",
  397. " if (!src_all[i].src)",
  398. " printf(\"MSC: ~R %%d\\n\", z->_p);",
  399. " }",
  400. " lastnever = z->_p;",
  401. " goto sameas;",
  402. " } else",
  403. " if (strcmp(procname[z->_t], \":np_:\") != 0)",
  404. " {",
  405. "sameas: if (no_rck) goto moveon;",
  406. " if (coltrace)",
  407. " { printf(\"%%ld: \", depth);",
  408. " for (i = 0; i < II; i++)",
  409. " printf(\"\\t\\t\");",
  410. " printf(\"%%s(%%d):\", procname[z->_t], II);",
  411. " printf(\"[%%s]\\n\", q?q:\"\");",
  412. " } else if (!silent)",
  413. " { if (strlen(simvals) > 0) {",
  414. " printf(\"%%3ld: proc %%2d (%%s)\", ",
  415. " depth, II, procname[z->_t]);",
  416. " for (i = 0; src_all[i].src; i++)",
  417. " if (src_all[i].tp == (int) z->_t)",
  418. " { printf(\" line %%3d \\\"pan_in\\\" \",",
  419. " src_all[i].src[z->_p]);",
  420. " break;",
  421. " }",
  422. " printf(\"(state %%d)\t[values: %%s]\\n\", z->_p, simvals);",
  423. " }",
  424. " printf(\"%%3ld: proc %%2d (%%s)\", ",
  425. " depth, II, procname[z->_t]);",
  426. " for (i = 0; src_all[i].src; i++)",
  427. " if (src_all[i].tp == (int) z->_t)",
  428. " { printf(\" line %%3d \\\"pan_in\\\" \",",
  429. " src_all[i].src[z->_p]);",
  430. " break;",
  431. " }",
  432. " printf(\"(state %%d)\t[%%s]\\n\", z->_p, q?q:\"\");",
  433. " printf(\"\\n\");",
  434. " } }",
  435. "moveon: z->_p = t->st;",
  436. " }",
  437. " wrap_trail();",
  438. "}",
  439. "#endif",
  440. "int",
  441. "f_pid(int pt)",
  442. "{ int i;",
  443. " P0 *z;",
  444. " for (i = 0; i < now._nr_pr; i++)",
  445. " { z = (P0 *)pptr(i);",
  446. " if (z->_t == (unsigned) pt)",
  447. " return BASE+z->_pid;",
  448. " }",
  449. " return -1;",
  450. "}",
  451. "#ifdef VERI",
  452. "void check_claim(int);",
  453. "#endif",
  454. "",
  455. "#ifdef BITSTATE",
  456. #ifndef POWOW
  457. "int",
  458. "bstore_mod(char *v, int n) /* hasharray size not a power of two */",
  459. "{ unsigned long x, y;",
  460. " unsigned int i = 1;",
  461. "",
  462. " d_hash((uchar *) v, n); /* sets j3, j4, K1, K2 */",
  463. " x = K2; y = j3;",
  464. " for (;;)",
  465. " { if (!(SS[x%%udmem]&(1<<y))) break;", /* take the hit in speed */
  466. " if (i == hfns) {",
  467. "#ifdef DEBUG",
  468. " printf(\"Old bitstate\\n\");",
  469. "#endif",
  470. " return 1;",
  471. " }",
  472. " x = (x + K1 + i);", /* no mask, using mod */
  473. " y = (y + j4) & 7;",
  474. " i++;",
  475. " }",
  476. "#ifdef RANDSTOR",
  477. " if (rand()%%100 > RANDSTOR) return 0;",
  478. "#endif",
  479. " for (;;)",
  480. " { SS[x%%udmem] |= (1<<y);",
  481. " if (i == hfns) break;", /* done */
  482. " x = (x + K1 + i);", /* no mask */
  483. " y = (y + j4) & 7;",
  484. " i++;",
  485. " }",
  486. "#ifdef DEBUG",
  487. " printf(\"New bitstate\\n\");",
  488. "#endif",
  489. " if (now._a_t&1)",
  490. " { nShadow++;",
  491. " }",
  492. " return 0;",
  493. "}",
  494. #endif
  495. "int",
  496. "bstore_reg(char *v, int n) /* extended hashing, Peter Dillinger, 2004 */",
  497. "{ unsigned long x, y;",
  498. " unsigned int i = 1;",
  499. "",
  500. " d_hash((uchar *) v, n); /* sets j1-j4 */",
  501. " x = j2; y = j3;",
  502. " for (;;)",
  503. " { if (!(SS[x]&(1<<y))) break;", /* at least one bit not set */
  504. " if (i == hfns) {",
  505. "#ifdef DEBUG",
  506. " printf(\"Old bitstate\\n\");",
  507. "#endif",
  508. " return 1;",
  509. " }",
  510. " x = (x + j1 + i) & nmask;",
  511. " y = (y + j4) & 7;",
  512. " i++;",
  513. " }",
  514. "#ifdef RANDSTOR",
  515. " if (rand()%%100 > RANDSTOR) return 0;",
  516. "#endif",
  517. " for (;;)",
  518. " { SS[x] |= (1<<y);",
  519. " if (i == hfns) break;", /* done */
  520. " x = (x + j1 + i) & nmask;",
  521. " y = (y + j4) & 7;",
  522. " i++;",
  523. " }",
  524. "#ifdef DEBUG",
  525. " printf(\"New bitstate\\n\");",
  526. "#endif",
  527. " if (now._a_t&1)",
  528. " { nShadow++;",
  529. " }",
  530. " return 0;",
  531. "}",
  532. "#endif",
  533. "unsigned long TMODE = 0666; /* file permission bits for trail files */",
  534. "",
  535. "int trcnt=1;",
  536. "char snap[64], fnm[512];",
  537. "",
  538. "int",
  539. "make_trail(void)",
  540. "{ int fd;",
  541. " char *q;",
  542. " char MyFile[512];",
  543. "",
  544. " q = strrchr(TrailFile, \'/\');",
  545. " if (q == NULL) q = TrailFile; else q++;",
  546. " strcpy(MyFile, q); /* TrailFile is not a writable string */",
  547. "",
  548. " if (iterative == 0 && Nr_Trails++ > 0)",
  549. " sprintf(fnm, \"%%s%%d.%%s\",",
  550. " MyFile, Nr_Trails-1, tprefix);",
  551. " else",
  552. " sprintf(fnm, \"%%s.%%s\", MyFile, tprefix);",
  553. "",
  554. " if ((fd = creat(fnm, TMODE)) < 0)",
  555. " { if ((q = strchr(MyFile, \'.\')))",
  556. " { *q = \'\\0\';", /* strip .pml */
  557. " if (iterative == 0 && Nr_Trails-1 > 0)",
  558. " sprintf(fnm, \"%%s%%d.%%s\",",
  559. " MyFile, Nr_Trails-1, tprefix);",
  560. " else",
  561. " sprintf(fnm, \"%%s.%%s\", MyFile, tprefix);",
  562. " *q = \'.\';",
  563. " fd = creat(fnm, TMODE);",
  564. " } }",
  565. " if (fd < 0)",
  566. " { printf(\"pan: cannot create %%s\\n\", fnm);",
  567. " perror(\"cause\");",
  568. " } else",
  569. " { printf(\"pan: wrote %%s\\n\", fnm);",
  570. " }",
  571. " return fd;",
  572. "}",
  573. 0
  574. };
  575. static char *Code2b[] = { /* breadth-first search option */
  576. "#ifdef BFS",
  577. "#define Q_PROVISO",
  578. "#ifndef INLINE_REV",
  579. "#define INLINE_REV",
  580. "#endif",
  581. "",
  582. "typedef struct SV_Hold {",
  583. " State *sv;",
  584. " int sz;",
  585. " struct SV_Hold *nxt;",
  586. "} SV_Hold;",
  587. "",
  588. "typedef struct EV_Hold {",
  589. " char *sv;", /* Mask */
  590. " int sz;", /* vsize */
  591. " int nrpr;",
  592. " int nrqs;",
  593. "#if VECTORSZ>32000",
  594. " int *po;",
  595. "#else",
  596. " short *po;",
  597. "#endif",
  598. " int *qo;",
  599. " uchar *ps, *qs;",
  600. " struct EV_Hold *nxt;",
  601. "} EV_Hold;",
  602. "",
  603. "typedef struct BFS_Trail {",
  604. " Trail *frame;",
  605. " SV_Hold *onow;",
  606. " EV_Hold *omask;",
  607. "#ifdef Q_PROVISO",
  608. " struct H_el *lstate;",
  609. "#endif",
  610. " short boq;",
  611. " struct BFS_Trail *nxt;",
  612. "} BFS_Trail;",
  613. "",
  614. "BFS_Trail *bfs_trail, *bfs_bot, *bfs_free;",
  615. "",
  616. "SV_Hold *svhold, *svfree;",
  617. "",
  618. "uchar do_reverse(Trans *, short, uchar);",
  619. "void snapshot(void);",
  620. "",
  621. "SV_Hold *",
  622. "getsv(int n)",
  623. "{ SV_Hold *h = (SV_Hold *) 0, *oh;",
  624. "",
  625. " oh = (SV_Hold *) 0;",
  626. " for (h = svfree; h; oh = h, h = h->nxt)",
  627. " { if (n == h->sz)",
  628. " { if (!oh)",
  629. " svfree = h->nxt;",
  630. " else",
  631. " oh->nxt = h->nxt;",
  632. " h->nxt = (SV_Hold *) 0;",
  633. " break;",
  634. " }",
  635. " if (n < h->sz)",
  636. " { h = (SV_Hold *) 0;",
  637. " break;",
  638. " }",
  639. " /* else continue */",
  640. " }",
  641. "",
  642. " if (!h)",
  643. " { h = (SV_Hold *) emalloc(sizeof(SV_Hold));",
  644. " h->sz = n;",
  645. " h->sv = (State *) emalloc(sizeof(State) - VECTORSZ + n);",
  646. " }",
  647. " return h;",
  648. "}",
  649. "",
  650. "EV_Hold *",
  651. "getsv_mask(int n)",
  652. "{ EV_Hold *h;",
  653. " static EV_Hold *kept = (EV_Hold *) 0;",
  654. "",
  655. " for (h = kept; h; h = h->nxt)",
  656. " if (n == h->sz",
  657. " && (memcmp((char *) Mask, (char *) h->sv, n) == 0)",
  658. " && (now._nr_pr == h->nrpr)",
  659. " && (now._nr_qs == h->nrqs)",
  660. "#if VECTORSZ>32000",
  661. " && (memcmp((char *) proc_offset, (char *) h->po, now._nr_pr * sizeof(int)) == 0)",
  662. " && (memcmp((char *) q_offset, (char *) h->qo, now._nr_qs * sizeof(int)) == 0)",
  663. "#else",
  664. " && (memcmp((char *) proc_offset, (char *) h->po, now._nr_pr * sizeof(short)) == 0)",
  665. " && (memcmp((char *) q_offset, (char *) h->qo, now._nr_qs * sizeof(short)) == 0)",
  666. "#endif",
  667. " && (memcmp((char *) proc_skip, (char *) h->ps, now._nr_pr * sizeof(uchar)) == 0)",
  668. " && (memcmp((char *) q_skip, (char *) h->qs, now._nr_qs * sizeof(uchar)) == 0))",
  669. " break;",
  670. " if (!h)",
  671. " { h = (EV_Hold *) emalloc(sizeof(EV_Hold));",
  672. " h->sz = n;",
  673. " h->nrpr = now._nr_pr;",
  674. " h->nrqs = now._nr_qs;",
  675. "",
  676. " h->sv = (char *) emalloc(n * sizeof(char));",
  677. " memcpy((char *) h->sv, (char *) Mask, n);",
  678. "",
  679. " if (now._nr_pr > 0)",
  680. " { h->po = (int *) emalloc(now._nr_pr * sizeof(int));",
  681. " h->ps = (int *) emalloc(now._nr_pr * sizeof(int));",
  682. "#if VECTORSZ>32000",
  683. " memcpy((char *) h->po, (char *) proc_offset, now._nr_pr * sizeof(int));",
  684. "#else",
  685. " memcpy((char *) h->po, (char *) proc_offset, now._nr_pr * sizeof(short));",
  686. "#endif",
  687. " memcpy((char *) h->ps, (char *) proc_skip, now._nr_pr * sizeof(uchar));",
  688. " }",
  689. " if (now._nr_qs > 0)",
  690. " { h->qo = (int *) emalloc(now._nr_qs * sizeof(int));",
  691. " h->qs = (int *) emalloc(now._nr_qs * sizeof(int));",
  692. "#if VECTORSZ>32000",
  693. " memcpy((char *) h->qo, (char *) q_offset, now._nr_qs * sizeof(int));",
  694. "#else",
  695. " memcpy((char *) h->qo, (char *) q_offset, now._nr_qs * sizeof(short));",
  696. "#endif",
  697. " memcpy((char *) h->qs, (char *) q_skip, now._nr_qs * sizeof(uchar));",
  698. " }",
  699. "",
  700. " h->nxt = kept;",
  701. " kept = h;",
  702. " }",
  703. " return h;",
  704. "}",
  705. "",
  706. "void",
  707. "freesv(SV_Hold *p)",
  708. "{ SV_Hold *h, *oh;",
  709. "",
  710. " oh = (SV_Hold *) 0;",
  711. " for (h = svfree; h; oh = h, h = h->nxt)",
  712. " if (h->sz >= p->sz)",
  713. " break;",
  714. "",
  715. " if (!oh)",
  716. " { p->nxt = svfree;",
  717. " svfree = p;",
  718. " } else",
  719. " { p->nxt = h;",
  720. " oh->nxt = p;",
  721. " }",
  722. "}",
  723. "",
  724. "BFS_Trail *",
  725. "get_bfs_frame(void)",
  726. "{ BFS_Trail *t;",
  727. "",
  728. " if (bfs_free)",
  729. " { t = bfs_free;",
  730. " bfs_free = bfs_free->nxt;",
  731. " t->nxt = (BFS_Trail *) 0;",
  732. " } else",
  733. " { t = (BFS_Trail *) emalloc(sizeof(BFS_Trail));",
  734. " }",
  735. " t->frame = (Trail *) emalloc(sizeof(Trail));", /* always new */
  736. " return t;",
  737. "}",
  738. "",
  739. "void",
  740. "push_bfs(Trail *f, int d)",
  741. "{ BFS_Trail *t;",
  742. "",
  743. " t = get_bfs_frame();",
  744. " memcpy((char *)t->frame, (char *)f, sizeof(Trail));",
  745. " t->frame->o_tt = d; /* depth */",
  746. "",
  747. " t->boq = boq;",
  748. " t->onow = getsv(vsize);",
  749. " memcpy((char *)t->onow->sv, (char *)&now, vsize);",
  750. " t->omask = getsv_mask(vsize);",
  751. "#if defined(FULLSTACK) && defined(Q_PROVISO)",
  752. " t->lstate = Lstate;",
  753. "#endif",
  754. " if (!bfs_bot)",
  755. " { bfs_bot = bfs_trail = t;",
  756. " } else",
  757. " { bfs_bot->nxt = t;",
  758. " bfs_bot = t;",
  759. " }",
  760. "#ifdef CHECK",
  761. " printf(\"PUSH %%u (%%d)\\n\", t->frame, d);",
  762. "#endif",
  763. "}",
  764. "",
  765. "Trail *",
  766. "pop_bfs(void)",
  767. "{ BFS_Trail *t;",
  768. "",
  769. " if (!bfs_trail)",
  770. " return (Trail *) 0;",
  771. "",
  772. " t = bfs_trail;",
  773. " bfs_trail = t->nxt;",
  774. " if (!bfs_trail)",
  775. " bfs_bot = (BFS_Trail *) 0;",
  776. "#if defined(Q_PROVISO) && !defined(BITSTATE) && !defined(NOREDUCE)",
  777. " if (t->lstate) t->lstate->tagged = 0;",
  778. "#endif",
  779. "",
  780. " t->nxt = bfs_free;",
  781. " bfs_free = t;",
  782. "",
  783. " vsize = t->onow->sz;",
  784. " boq = t->boq;",
  785. "",
  786. " memcpy((uchar *) &now, (uchar *) t->onow->sv, vsize);",
  787. " memcpy((uchar *) Mask, (uchar *) t->omask->sv, vsize);",
  788. " if (now._nr_pr > 0)",
  789. "#if VECTORSZ>32000",
  790. " { memcpy((char *)proc_offset, (char *)t->omask->po, now._nr_pr * sizeof(int));",
  791. "#else",
  792. " { memcpy((char *)proc_offset, (char *)t->omask->po, now._nr_pr * sizeof(short));",
  793. "#endif",
  794. " memcpy((char *)proc_skip, (char *)t->omask->ps, now._nr_pr * sizeof(uchar));",
  795. " }",
  796. " if (now._nr_qs > 0)",
  797. "#if VECTORSZ>32000",
  798. " { memcpy((uchar *)q_offset, (uchar *)t->omask->qo, now._nr_qs * sizeof(int));",
  799. "#else",
  800. " { memcpy((uchar *)q_offset, (uchar *)t->omask->qo, now._nr_qs * sizeof(short));",
  801. "#endif",
  802. " memcpy((uchar *)q_skip, (uchar *)t->omask->qs, now._nr_qs * sizeof(uchar));",
  803. " }",
  804. " freesv(t->onow); /* omask not freed */",
  805. "#ifdef CHECK",
  806. " printf(\"POP %%u (%%d)\\n\", t->frame, t->frame->o_tt);",
  807. "#endif",
  808. " return t->frame;",
  809. "}",
  810. "",
  811. "void",
  812. "store_state(Trail *ntrpt, int shortcut, short oboq)",
  813. "{",
  814. "#ifdef VERI",
  815. " Trans *t2 = (Trans *) 0;",
  816. " uchar ot; int tt, E_state;",
  817. " uchar o_opm = trpt->o_pm, *othis = this;",
  818. "",
  819. " if (shortcut)",
  820. " {",
  821. "#ifdef VERBOSE",
  822. " printf(\"claim: shortcut\\n\");",
  823. "#endif",
  824. " goto store_it; /* no claim move */",
  825. " }",
  826. "",
  827. " this = (((uchar *)&now)+proc_offset[0]); /* 0 = never claim */",
  828. " trpt->o_pm = 0;", /* to interpret else in never claim */
  829. "",
  830. " tt = (int) ((P0 *)this)->_p;",
  831. " ot = (uchar) ((P0 *)this)->_t;",
  832. "",
  833. "#ifdef HAS_UNLESS",
  834. " E_state = 0;",
  835. "#endif",
  836. " for (t2 = trans[ot][tt]; t2; t2 = t2?t2->nxt:(Trans *)0)",
  837. " {",
  838. "#ifdef HAS_UNLESS",
  839. " if (E_state > 0",
  840. " && E_state != t2->e_trans)",
  841. " break;",
  842. "#endif",
  843. " if (do_transit(t2, 0))",
  844. " {",
  845. "#ifdef VERBOSE",
  846. " if (!reached[ot][t2->st])",
  847. " printf(\"depth: %%d -- claim move from %%d -> %%d\\n\",",
  848. " trpt->o_tt, ((P0 *)this)->_p, t2->st);",
  849. "#endif",
  850. "#ifdef HAS_UNLESS",
  851. " E_state = t2->e_trans;",
  852. "#endif",
  853. " if (t2->st > 0)",
  854. " { ((P0 *)this)->_p = t2->st;",
  855. " reached[ot][t2->st] = 1;",
  856. "#ifndef NOCLAIM",
  857. " check_claim(t2->st);",
  858. "#endif",
  859. " }",
  860. " if (now._nr_pr == 0) /* claim terminated */",
  861. " uerror(\"end state in claim reached\");",
  862. "",
  863. "#ifdef PEG",
  864. " peg[t2->forw]++;",
  865. "#endif",
  866. " trpt->o_pm |= 1;",
  867. " if (t2->atom&2)", /* atomic in claim */
  868. " Uerror(\"atomic in claim not supported in BFS mode\");",
  869. "store_it:",
  870. "",
  871. "#endif", /* VERI */
  872. "",
  873. "#ifdef BITSTATE",
  874. " if (!bstore((char *)&now, vsize))",
  875. "#else",
  876. "#ifdef MA",
  877. " if (!gstore((char *)&now, vsize, 0))",
  878. "#else",
  879. " if (!hstore((char *)&now, vsize))",
  880. "#endif",
  881. "#endif",
  882. " { nstates++;",
  883. "#ifndef NOREDUCE",
  884. " trpt->tau |= 64;", /* succ definitely outside stack */
  885. "#endif",
  886. "#if SYNC",
  887. " if (boq != -1)",
  888. " midrv++;",
  889. " else if (oboq != -1)",
  890. " { Trail *x;",
  891. " x = (Trail *) trpt->ostate; /* pre-rv state */",
  892. " if (x) x->o_pm |= 4; /* mark success */",
  893. " }",
  894. "#endif",
  895. " push_bfs(ntrpt, trpt->o_tt+1);",
  896. " } else",
  897. " { truncs++;",
  898. "#if !defined(NOREDUCE) && defined(FULLSTACK) && defined(Q_PROVISO)",
  899. "#if !defined(QLIST) && !defined(BITSTATE)",
  900. " if (Lstate && Lstate->tagged) trpt->tau |= 64;",
  901. "#else",
  902. " if (trpt->tau&32)",
  903. " { BFS_Trail *tprov;",
  904. " for (tprov = bfs_trail; tprov; tprov = tprov->nxt)",
  905. " if (!memcmp((uchar *)&now, (uchar *)tprov->onow->sv, vsize))",
  906. " { trpt->tau |= 64;",
  907. " break; /* state is in queue */",
  908. " } }",
  909. "#endif",
  910. "#endif",
  911. " }",
  912. "#ifdef VERI",
  913. " ((P0 *)this)->_p = tt; /* reset claim */",
  914. " if (t2)",
  915. " do_reverse(t2, 0, 0);",
  916. " else",
  917. " break;",
  918. " } }",
  919. " this = othis;",
  920. " trpt->o_pm = o_opm;",
  921. "#endif",
  922. "}",
  923. "",
  924. "Trail *ntrpt;", /* 4.2.8 */
  925. "",
  926. "void",
  927. "bfs(void)",
  928. "{ Trans *t; Trail *otrpt, *x;",
  929. " uchar _n, _m, ot, nps = 0;",
  930. " int tt, E_state;",
  931. " short II, From = (short) (now._nr_pr-1), To = BASE;",
  932. " short oboq = boq;",
  933. "",
  934. " ntrpt = (Trail *) emalloc(sizeof(Trail));",
  935. " trpt->ostate = (struct H_el *) 0;",
  936. " trpt->tau = 0;",
  937. "",
  938. " trpt->o_tt = -1;",
  939. " store_state(ntrpt, 0, oboq); /* initial state */",
  940. "",
  941. " while ((otrpt = pop_bfs())) /* also restores now */",
  942. " { memcpy((char *) trpt, (char *) otrpt, sizeof(Trail));",
  943. "#if defined(C_States) && (HAS_TRACK==1)",
  944. " c_revert((uchar *) &(now.c_state[0]));",
  945. "#endif",
  946. " if (trpt->o_pm & 4)",
  947. " {",
  948. "#ifdef VERBOSE",
  949. " printf(\"Revisit of atomic not needed (%%d)\\n\",",
  950. " trpt->o_pm);", /* at least 1 rv succeeded */
  951. "#endif",
  952. " continue;",
  953. " }",
  954. "#ifndef NOREDUCE",
  955. " nps = 0;",
  956. "#endif",
  957. " if (trpt->o_pm == 8)",
  958. " { revrv++;",
  959. " if (trpt->tau&8)",
  960. " {",
  961. "#ifdef VERBOSE",
  962. " printf(\"Break atomic (pm:%%d,tau:%%d)\\n\",",
  963. " trpt->o_pm, trpt->tau);",
  964. "#endif",
  965. " trpt->tau &= ~8;",
  966. " }",
  967. "#ifndef NOREDUCE",
  968. " else if (trpt->tau&32)", /* was a preselected move */
  969. " {",
  970. "#ifdef VERBOSE",
  971. " printf(\"Void preselection (pm:%%d,tau:%%d)\\n\",",
  972. " trpt->o_pm, trpt->tau);",
  973. "#endif",
  974. " trpt->tau &= ~32;",
  975. " nps = 1; /* no preselection in repeat */",
  976. " }",
  977. "#endif",
  978. " }",
  979. " trpt->o_pm &= ~(4|8);",
  980. " if (trpt->o_tt > mreached)",
  981. " { mreached = trpt->o_tt;",
  982. " if (mreached%%10 == 0)",
  983. " { printf(\"Depth= %%7d States= %%7g \", mreached, nstates);",
  984. " printf(\"Transitions= %%7g \", nstates+truncs);",
  985. "#ifdef MA",
  986. " printf(\"Nodes= %%7d \", nr_states);",
  987. "#endif",
  988. " printf(\"Memory= %%-6.3f\\n\", memcnt/1000000.);",
  989. " fflush(stdout);",
  990. " } }",
  991. " depth = trpt->o_tt;",
  992. " if (depth >= maxdepth)",
  993. " {",
  994. "#if SYNC",
  995. " Trail *x;",
  996. " if (boq != -1)",
  997. " { x = (Trail *) trpt->ostate;",
  998. " if (x) x->o_pm |= 4; /* not failing */",
  999. " }",
  1000. "#endif",
  1001. " truncs++;",
  1002. " if (!warned)",
  1003. " { warned = 1;",
  1004. " printf(\"error: max search depth too small\\n\");",
  1005. " }",
  1006. " if (bounded)",
  1007. " uerror(\"depth limit reached\");",
  1008. " continue;",
  1009. " }",
  1010. /* PO */
  1011. "#ifndef NOREDUCE",
  1012. " if (boq == -1 && !(trpt->tau&8) && nps == 0)",
  1013. " for (II = now._nr_pr-1; II >= BASE; II -= 1)",
  1014. " {",
  1015. "Pickup: this = pptr(II);",
  1016. " tt = (int) ((P0 *)this)->_p;",
  1017. " ot = (uchar) ((P0 *)this)->_t;",
  1018. " if (trans[ot][tt]->atom & 8)", /* safe */
  1019. " { t = trans[ot][tt];",
  1020. " if (t->qu[0] != 0)",
  1021. " { Ccheck++;",
  1022. " if (!q_cond(II, t))",
  1023. " continue;",
  1024. " Cholds++;",
  1025. " }",
  1026. " From = To = II;",
  1027. " trpt->tau |= 32; /* preselect marker */",
  1028. "#ifdef DEBUG",
  1029. " printf(\"%%3d: proc %%d PreSelected (tau=%%d)\\n\", ",
  1030. " depth, II, trpt->tau);",
  1031. "#endif",
  1032. " goto MainLoop;",
  1033. " } }",
  1034. " trpt->tau &= ~32;", /* not preselected */
  1035. "#endif",
  1036. /* PO */
  1037. "Repeat:",
  1038. " if (trpt->tau&8) /* atomic */",
  1039. " { From = To = (short ) trpt->pr;",
  1040. " nlinks++;",
  1041. " } else",
  1042. " { From = now._nr_pr-1;",
  1043. " To = BASE;",
  1044. " }",
  1045. "MainLoop:",
  1046. " _n = _m = 0;",
  1047. " for (II = From; II >= To; II -= 1)",
  1048. " {",
  1049. " this = (((uchar *)&now)+proc_offset[II]);",
  1050. " tt = (int) ((P0 *)this)->_p;",
  1051. " ot = (uchar) ((P0 *)this)->_t;",
  1052. "#if SYNC",
  1053. " /* no rendezvous with same proc */",
  1054. " if (boq != -1 && trpt->pr == II) continue;",
  1055. "#endif",
  1056. " ntrpt->pr = (uchar) II;",
  1057. " ntrpt->st = tt; ",
  1058. " trpt->o_pm &= ~1; /* no move yet */",
  1059. "#ifdef EVENT_TRACE",
  1060. " trpt->o_event = now._event;",
  1061. "#endif",
  1062. "#ifdef HAS_PROVIDED",
  1063. " if (!provided(II, ot, tt, t)) continue;",
  1064. "#endif",
  1065. "#ifdef HAS_UNLESS",
  1066. " E_state = 0;",
  1067. "#endif",
  1068. " for (t = trans[ot][tt]; t; t = t->nxt)",
  1069. " {",
  1070. "#ifdef HAS_UNLESS",
  1071. " if (E_state > 0",
  1072. " && E_state != t->e_trans)",
  1073. " break;",
  1074. "#endif",
  1075. " ntrpt->o_t = t;",
  1076. "",
  1077. " oboq = boq;",
  1078. "",
  1079. " if (!(_m = do_transit(t, II)))",
  1080. " continue;",
  1081. "",
  1082. " trpt->o_pm |= 1; /* we moved */",
  1083. " (trpt+1)->o_m = _m; /* for unsend */",
  1084. "#ifdef PEG",
  1085. " peg[t->forw]++;",
  1086. "#endif",
  1087. "#ifdef CHECK",
  1088. " printf(\"%%3d: proc %%d exec %%d, \",",
  1089. " depth, II, t->forw);",
  1090. " printf(\"%%d to %%d, %%s %%s %%s\",",
  1091. " tt, t->st, t->tp,",
  1092. " (t->atom&2)?\"atomic\":\"\",",
  1093. " (boq != -1)?\"rendez-vous\":\"\");",
  1094. "#ifdef HAS_UNLESS",
  1095. " if (t->e_trans)",
  1096. " printf(\" (escapes to state %%d)\", t->st);",
  1097. "#endif",
  1098. " printf(\" %%saccepting [tau=%%d]\\n\",",
  1099. " (trpt->o_pm&2)?\"\":\"non-\", trpt->tau);",
  1100. "#endif",
  1101. "#ifdef HAS_UNLESS",
  1102. " E_state = t->e_trans;",
  1103. "#if SYNC>0",
  1104. " if (t->e_trans > 0 && (boq != -1 /* || oboq != -1 */))",
  1105. " { fprintf(efd, \"error:\tthe use of rendezvous stmnt in the escape clause\\n\");",
  1106. " fprintf(efd, \"\tof an unless stmnt is not compatible with -DBFS\\n\");",
  1107. " pan_exit(1);",
  1108. " }",
  1109. "#endif",
  1110. "#endif",
  1111. " if (t->st > 0) ((P0 *)this)->_p = t->st;",
  1112. "",
  1113. " /* ptr to pred: */ ntrpt->ostate = (struct H_el *) otrpt;",
  1114. " ntrpt->st = tt;",
  1115. " if (boq == -1 && (t->atom&2)) /* atomic */",
  1116. " ntrpt->tau = 8; /* record for next move */",
  1117. " else",
  1118. " ntrpt->tau = 0;",
  1119. "",
  1120. " store_state(ntrpt, (boq != -1 || (t->atom&2)), oboq);",
  1121. "#ifdef EVENT_TRACE",
  1122. " now._event = trpt->o_event;",
  1123. "#endif",
  1124. "",
  1125. " /* undo move and continue */",
  1126. " trpt++; /* this is where ovals and ipt are set */",
  1127. " do_reverse(t, II, _m); /* restore now. */",
  1128. " trpt--;",
  1129. "#ifdef CHECK",
  1130. " printf(\"%%3d: proc %%d \", depth, II);",
  1131. " printf(\"reverses %%d, %%d to %%d,\",",
  1132. " t->forw, tt, t->st);",
  1133. " printf(\" %%s [abit=%%d,adepth=%%d,\",",
  1134. " t->tp, now._a_t, A_depth);",
  1135. " printf(\"tau=%%d,%%d]\\n\",",
  1136. " trpt->tau, (trpt-1)->tau);",
  1137. "#endif",
  1138. " reached[ot][t->st] = 1;",
  1139. " reached[ot][tt] = 1;",
  1140. "",
  1141. " ((P0 *)this)->_p = tt;",
  1142. " _n |= _m;",
  1143. " } }",
  1144. /* PO */
  1145. "#ifndef NOREDUCE",
  1146. " /* preselected - no succ definitely outside stack */",
  1147. " if ((trpt->tau&32) && !(trpt->tau&64))",
  1148. " { From = now._nr_pr-1; To = BASE;",
  1149. "#ifdef DEBUG",
  1150. " printf(\"%%3d: proc %%d UnSelected (_n=%%d, tau=%%d)\\n\", ",
  1151. " depth, II+1, (int) _n, trpt->tau);",
  1152. "#endif",
  1153. " _n = 0; trpt->tau &= ~32;",
  1154. " if (II >= BASE)",
  1155. " goto Pickup;",
  1156. " goto MainLoop;",
  1157. " }",
  1158. " trpt->tau &= ~(32|64);",
  1159. "#endif",
  1160. /* PO */
  1161. " if (_n != 0)",
  1162. " continue;",
  1163. "#ifdef DEBUG",
  1164. " printf(\"%%3d: no move [II=%%d, tau=%%d, boq=%%d, _nr_pr=%%d]\\n\",",
  1165. " depth, II, trpt->tau, boq, now._nr_pr);",
  1166. "#endif",
  1167. " if (boq != -1)",
  1168. " { failedrv++;",
  1169. " x = (Trail *) trpt->ostate; /* pre-rv state */",
  1170. " if (!x) continue; /* root state */",
  1171. " if ((x->tau&8) || (x->tau&32)) /* break atomic or preselect at parent */",
  1172. " { x->o_pm |= 8; /* mark failure */",
  1173. " this = (((uchar *)&now)+proc_offset[otrpt->pr]);",
  1174. "#ifdef VERBOSE",
  1175. " printf(\"\\treset state of %%d from %%d to %%d\\n\",",
  1176. " otrpt->pr, ((P0 *)this)->_p, otrpt->st);",
  1177. "#endif",
  1178. " ((P0 *)this)->_p = otrpt->st;",
  1179. " unsend(boq); /* retract rv offer */",
  1180. " boq = -1;",
  1181. " push_bfs(x, x->o_tt);",
  1182. "#ifdef VERBOSE",
  1183. " printf(\"failed rv, repush with %%d\\n\", x->o_pm);",
  1184. "#endif",
  1185. " }",
  1186. "#ifdef VERBOSE",
  1187. " else printf(\"failed rv, tau at parent: %%d\\n\", x->tau);",
  1188. "#endif",
  1189. " } else if (now._nr_pr > 0)",
  1190. " {",
  1191. " if ((trpt->tau&8)) /* atomic */",
  1192. " { trpt->tau &= ~(1|8); /* 1=timeout, 8=atomic */",
  1193. "#ifdef DEBUG",
  1194. " printf(\"%%3d: atomic step proc %%d blocks\\n\",",
  1195. " depth, II+1);",
  1196. "#endif",
  1197. " goto Repeat;",
  1198. " }",
  1199. "",
  1200. " if (!(trpt->tau&1)) /* didn't try timeout yet */",
  1201. " { trpt->tau |= 1;",
  1202. "#ifdef DEBUG",
  1203. " printf(\"%%d: timeout\\n\", depth);",
  1204. "#endif",
  1205. " goto MainLoop;",
  1206. " }",
  1207. "#ifndef VERI",
  1208. " if (!noends && !a_cycles && !endstate())",
  1209. " uerror(\"invalid end state\");",
  1210. "#endif",
  1211. " } }",
  1212. "}",
  1213. "",
  1214. "void",
  1215. "putter(Trail *trpt, int fd)",
  1216. "{ long j;",
  1217. "",
  1218. " if (!trpt) return;",
  1219. "",
  1220. " if (trpt != (Trail *) trpt->ostate)",
  1221. " putter((Trail *) trpt->ostate, fd);",
  1222. "",
  1223. " if (trpt->o_t)",
  1224. " { sprintf(snap, \"%%d:%%d:%%d\\n\",",
  1225. " trcnt++, trpt->pr, trpt->o_t->t_id);",
  1226. " j = strlen(snap);",
  1227. " if (write(fd, snap, j) != j)",
  1228. " { printf(\"pan: error writing %%s\\n\", fnm);",
  1229. " pan_exit(1);",
  1230. " } }",
  1231. "}",
  1232. "",
  1233. "void",
  1234. "nuerror(char *str)",
  1235. "{ int fd = make_trail();",
  1236. " int j;",
  1237. "",
  1238. " if (fd < 0) return;",
  1239. "#ifdef VERI",
  1240. " sprintf(snap, \"-2:%%d:-2\\n\", VERI);",
  1241. " write(fd, snap, strlen(snap));",
  1242. "#endif",
  1243. "#ifdef MERGED",
  1244. " sprintf(snap, \"-4:-4:-4\\n\");",
  1245. " write(fd, snap, strlen(snap));",
  1246. "#endif",
  1247. " trcnt = 1;",
  1248. " putter(trpt, fd);",
  1249. " if (ntrpt->o_t)", /* 4.2.8 -- Alex example, missing last transition */
  1250. " { sprintf(snap, \"%%d:%%d:%%d\\n\",",
  1251. " trcnt++, ntrpt->pr, ntrpt->o_t->t_id);",
  1252. " j = strlen(snap);",
  1253. " if (write(fd, snap, j) != j)",
  1254. " { printf(\"pan: error writing %%s\\n\", fnm);",
  1255. " pan_exit(1);",
  1256. " } }",
  1257. " close(fd);",
  1258. " if (errors >= upto && upto != 0)",
  1259. " {",
  1260. " wrapup();",
  1261. " }",
  1262. "}",
  1263. "#endif", /* BFS */
  1264. 0,
  1265. };
  1266. static char *Code2c[] = {
  1267. "void",
  1268. "do_the_search(void)",
  1269. "{ int i;",
  1270. " depth = mreached = 0;",
  1271. " trpt = &trail[0];",
  1272. "#ifdef VERI",
  1273. " trpt->tau |= 4; /* the claim moves first */",
  1274. "#endif",
  1275. " for (i = 0; i < (int) now._nr_pr; i++)",
  1276. " { P0 *ptr = (P0 *) pptr(i);",
  1277. "#ifndef NP",
  1278. " if (!(trpt->o_pm&2)",
  1279. " && accpstate[ptr->_t][ptr->_p])",
  1280. " { trpt->o_pm |= 2;",
  1281. " }",
  1282. "#else",
  1283. " if (!(trpt->o_pm&4)",
  1284. " && progstate[ptr->_t][ptr->_p])",
  1285. " { trpt->o_pm |= 4;",
  1286. " }",
  1287. "#endif",
  1288. " }",
  1289. "#ifdef EVENT_TRACE",
  1290. "#ifndef NP",
  1291. " if (accpstate[EVENT_TRACE][now._event])",
  1292. " { trpt->o_pm |= 2;",
  1293. " }",
  1294. "#else",
  1295. " if (progstate[EVENT_TRACE][now._event])",
  1296. " { trpt->o_pm |= 4;",
  1297. " }",
  1298. "#endif",
  1299. "#endif",
  1300. "#ifndef NOCOMP",
  1301. " Mask[0] = Mask[1] = 1; /* _nr_pr, _nr_qs */",
  1302. " if (!a_cycles)",
  1303. " { i = &(now._a_t) - (uchar *) &now;",
  1304. " Mask[i] = 1; /* _a_t */",
  1305. " }",
  1306. "#ifndef NOFAIR",
  1307. " if (!fairness)",
  1308. " { int j = 0;",
  1309. " i = &(now._cnt[0]) - (uchar *) &now;",
  1310. " while (j++ < NFAIR)",
  1311. " Mask[i++] = 1; /* _cnt[] */",
  1312. " }",
  1313. "#endif",
  1314. "#endif",
  1315. "#ifndef NOFAIR",
  1316. " if (fairness",
  1317. " && (a_cycles && (trpt->o_pm&2)))",
  1318. " { now._a_t = 2; /* set the A-bit */",
  1319. " now._cnt[0] = now._nr_pr + 1;", /* NEW: +1 */
  1320. "#ifdef VERBOSE",
  1321. " printf(\"%%3d: fairness Rule 1, cnt=%%d, _a_t=%%d\\n\",",
  1322. " depth, now._cnt[now._a_t&1], now._a_t);",
  1323. "#endif",
  1324. " }",
  1325. "#endif",
  1326. "#if defined(C_States) && (HAS_TRACK==1)",
  1327. " /* capture initial state of tracked C objects */",
  1328. " c_update((uchar *) &(now.c_state[0]));",
  1329. "#endif",
  1330. "#ifdef HAS_CODE",
  1331. " if (readtrail) getrail(); /* no return */",
  1332. "#endif",
  1333. "#ifdef BFS",
  1334. " bfs();",
  1335. "#else",
  1336. "#if defined(C_States) && defined(HAS_STACK) && (HAS_TRACK==1)",
  1337. " /* initial state of tracked & unmatched objects */",
  1338. " c_stack((uchar *) &(svtack->c_stack[0]));",
  1339. "#endif",
  1340. "#ifdef RANDOMIZE",
  1341. " srand(123);",
  1342. "#endif",
  1343. " new_state(); /* start 1st DFS */",
  1344. "#endif",
  1345. "}",
  1346. "#ifdef INLINE_REV",
  1347. "uchar",
  1348. "do_reverse(Trans *t, short II, uchar M)",
  1349. "{ uchar _m = M;",
  1350. " int tt = (int) ((P0 *)this)->_p;",
  1351. "#include REVERSE_MOVES",
  1352. "R999: return _m;",
  1353. "}",
  1354. "#endif",
  1355. "#ifndef INLINE",
  1356. "#ifdef EVENT_TRACE",
  1357. "static char _tp = 'n'; static int _qid = 0;",
  1358. "#endif",
  1359. "uchar",
  1360. "do_transit(Trans *t, short II)",
  1361. "{ uchar _m = 0;",
  1362. " int tt = (int) ((P0 *)this)->_p;",
  1363. "#ifdef M_LOSS",
  1364. " uchar delta_m = 0;",
  1365. "#endif",
  1366. "#ifdef EVENT_TRACE",
  1367. " short oboq = boq;",
  1368. " uchar ot = (uchar) ((P0 *)this)->_t;",
  1369. " if (ot == EVENT_TRACE) boq = -1;",
  1370. "#define continue { boq = oboq; return 0; }",
  1371. "#else",
  1372. "#define continue return 0",
  1373. "#ifdef SEPARATE",
  1374. " uchar ot = (uchar) ((P0 *)this)->_t;",
  1375. "#endif",
  1376. "#endif",
  1377. "#include FORWARD_MOVES",
  1378. "P999:",
  1379. "#ifdef EVENT_TRACE",
  1380. " if (ot == EVENT_TRACE) boq = oboq;",
  1381. "#endif",
  1382. " return _m;",
  1383. "#undef continue",
  1384. "}",
  1385. "#ifdef EVENT_TRACE",
  1386. "void",
  1387. "require(char tp, int qid)",
  1388. "{ Trans *t;",
  1389. " _tp = tp; _qid = qid;",
  1390. "",
  1391. " if (now._event != endevent)",
  1392. " for (t = trans[EVENT_TRACE][now._event]; t; t = t->nxt)",
  1393. " { if (do_transit(t, EVENT_TRACE))",
  1394. " { now._event = t->st;",
  1395. " reached[EVENT_TRACE][t->st] = 1;",
  1396. "#ifdef VERBOSE",
  1397. " printf(\" event_trace move to -> %%d\\n\", t->st);",
  1398. "#endif",
  1399. "#ifndef BFS",
  1400. "#ifndef NP",
  1401. " if (accpstate[EVENT_TRACE][now._event])",
  1402. " (trpt+1)->o_pm |= 2;",
  1403. "#else",
  1404. " if (progstate[EVENT_TRACE][now._event])",
  1405. " (trpt+1)->o_pm |= 4;",
  1406. "#endif",
  1407. "#endif",
  1408. "#ifdef NEGATED_TRACE",
  1409. " if (now._event == endevent)",
  1410. " {",
  1411. "#ifndef BFS",
  1412. " depth++; trpt++;",
  1413. "#endif",
  1414. " uerror(\"event_trace error (all events matched)\");",
  1415. "#ifndef BFS",
  1416. " trpt--; depth--;",
  1417. "#endif",
  1418. " break;",
  1419. " }",
  1420. "#endif",
  1421. " for (t = t->nxt; t; t = t->nxt)",
  1422. " { if (do_transit(t, EVENT_TRACE))",
  1423. " Uerror(\"non-determinism in event-trace\");",
  1424. " }",
  1425. " return;",
  1426. " }",
  1427. "#ifdef VERBOSE",
  1428. " else",
  1429. " printf(\" event_trace miss '%%c' -- %%d, %%d, %%d\\n\",",
  1430. " tp, qid, now._event, t->forw);",
  1431. "#endif",
  1432. " }",
  1433. "#ifdef NEGATED_TRACE",
  1434. " now._event = endevent; /* only 1st try will count -- fixed 4.2.6 */",
  1435. "#else",
  1436. "#ifndef BFS",
  1437. " depth++; trpt++;",
  1438. "#endif",
  1439. " uerror(\"event_trace error (no matching event)\");",
  1440. "#ifndef BFS",
  1441. " trpt--; depth--;",
  1442. "#endif",
  1443. "#endif",
  1444. "}",
  1445. "#endif",
  1446. "int",
  1447. "enabled(int iam, int pid)",
  1448. "{ Trans *t; uchar *othis = this;",
  1449. " int res = 0; int tt; uchar ot;",
  1450. "#ifdef VERI",
  1451. " /* if (pid > 0) */ pid++;",
  1452. "#endif",
  1453. " if (pid == iam)",
  1454. " Uerror(\"used: enabled(pid=thisproc)\");",
  1455. " if (pid < 0 || pid >= (int) now._nr_pr)",
  1456. " return 0;",
  1457. " this = pptr(pid);",
  1458. " TstOnly = 1;",
  1459. " tt = (int) ((P0 *)this)->_p;",
  1460. " ot = (uchar) ((P0 *)this)->_t;",
  1461. " for (t = trans[ot][tt]; t; t = t->nxt)",
  1462. " if (do_transit(t, (short) pid))",
  1463. " { res = 1;",
  1464. " break;",
  1465. " }",
  1466. " TstOnly = 0;",
  1467. " this = othis;",
  1468. " return res;",
  1469. "}",
  1470. "#endif",
  1471. "void",
  1472. "snapshot(void)",
  1473. "{ static long sdone = (long) 0;",
  1474. " long ndone = (unsigned long) nstates/1000000;",
  1475. " if (ndone == sdone) return;",
  1476. " sdone = ndone;",
  1477. " printf(\"Depth= %%7d States= %%7g \", mreached, nstates);",
  1478. " printf(\"Transitions= %%7g \", nstates+truncs);",
  1479. "#ifdef MA",
  1480. " printf(\"Nodes= %%7d \", nr_states);",
  1481. "#endif",
  1482. " printf(\"Memory= %%-6.3f\\n\", memcnt/1000000.);",
  1483. " fflush(stdout);",
  1484. "}",
  1485. "#ifdef SC",
  1486. "void",
  1487. "stack2disk(void)",
  1488. "{",
  1489. " if (!stackwrite",
  1490. " && (stackwrite = creat(stackfile, TMODE)) < 0)",
  1491. " Uerror(\"cannot create stackfile\");",
  1492. "",
  1493. " if (write(stackwrite, trail, DDD*sizeof(Trail))",
  1494. " != DDD*sizeof(Trail))",
  1495. " Uerror(\"stackfile write error -- disk is full?\");",
  1496. "",
  1497. " memmove(trail, &trail[DDD], (HHH-DDD+2)*sizeof(Trail));",
  1498. " memset(&trail[HHH-DDD+2], 0, (omaxdepth - HHH + DDD - 2)*sizeof(Trail));",
  1499. " CNT1++;",
  1500. "}",
  1501. "void",
  1502. "disk2stack(void)",
  1503. "{ long have;",
  1504. "",
  1505. " CNT2++;",
  1506. " memmove(&trail[DDD], trail, (HHH-DDD+2)*sizeof(Trail));",
  1507. "",
  1508. " if (!stackwrite",
  1509. " || lseek(stackwrite, -DDD* (off_t) sizeof(Trail), SEEK_CUR) == -1)",
  1510. " Uerror(\"disk2stack lseek error\");",
  1511. "",
  1512. " if (!stackread",
  1513. " && (stackread = open(stackfile, 0)) < 0)",
  1514. " Uerror(\"cannot open stackfile\");",
  1515. "",
  1516. " if (lseek(stackread, (CNT1-CNT2)*DDD* (off_t) sizeof(Trail), SEEK_SET) == -1)",
  1517. " Uerror(\"disk2stack lseek error\");",
  1518. "",
  1519. " have = read(stackread, trail, DDD*sizeof(Trail));",
  1520. " if (have != DDD*sizeof(Trail))",
  1521. " Uerror(\"stackfile read error\");",
  1522. "}",
  1523. "#endif",
  1524. "uchar *",
  1525. "Pptr(int x)", /* as a fct, to avoid a problem with the p9 compiler */
  1526. "{ if (x < 0 || x >= MAXPROC || !proc_offset[x])", /* does not exist */
  1527. " return noptr;",
  1528. " else",
  1529. " return (uchar *) pptr(x);",
  1530. "}",
  1531. "int qs_empty(void);",
  1532. "/*",
  1533. " * new_state() is the main DFS search routine in the verifier",
  1534. " * it has a lot of code ifdef-ed together to support",
  1535. " * different search modes, which makes it quite unreadable.",
  1536. " * if you are studying the code, first use the C preprocessor",
  1537. " * to generate a specific version from the pan.c source,",
  1538. " * e.g. by saying:",
  1539. " * gcc -E -DNOREDUCE -DBITSTATE pan.c > ppan.c",
  1540. " * and then study the resulting file, rather than this one",
  1541. " */",
  1542. "#if !defined(BFS) && (!defined(BITSTATE) || !defined(MA))",
  1543. "void",
  1544. "new_state(void)",
  1545. "{ Trans *t;",
  1546. " uchar _n, _m, ot;",
  1547. "#ifdef RANDOMIZE",
  1548. " short ooi, eoi;",
  1549. "#endif",
  1550. "#ifdef M_LOSS",
  1551. " uchar delta_m = 0;",
  1552. "#endif",
  1553. " short II, JJ = 0, kk;",
  1554. " int tt;",
  1555. " short From = now._nr_pr-1, To = BASE;",
  1556. "Down:",
  1557. "#ifdef CHECK",
  1558. " printf(\"%%d: Down - %%s\",",
  1559. " depth, (trpt->tau&4)?\"claim\":\"program\");",
  1560. " printf(\" %%saccepting [pids %%d-%%d]\\n\",",
  1561. " (trpt->o_pm&2)?\"\":\"non-\", From, To);",
  1562. "#endif",
  1563. "#ifdef SC",
  1564. " if (depth > hiwater)",
  1565. " { stack2disk();",
  1566. " maxdepth += DDD;",
  1567. " hiwater += DDD;",
  1568. " trpt -= DDD;",
  1569. " if(verbose)",
  1570. " printf(\"zap %%d: %%d (maxdepth now %%d)\\n\",",
  1571. " CNT1, hiwater, maxdepth);",
  1572. " }",
  1573. "#endif",
  1574. " trpt->tau &= ~(16|32|64); /* make sure these are off */",
  1575. "#if defined(FULLSTACK) && defined(MA)",
  1576. " trpt->proviso = 0;",
  1577. "#endif",
  1578. " if (depth >= maxdepth)",
  1579. " { truncs++;",
  1580. "#if SYNC",
  1581. " (trpt+1)->o_n = 1; /* not a deadlock */",
  1582. "#endif",
  1583. " if (!warned)",
  1584. " { warned = 1;",
  1585. " printf(\"error: max search depth too small\\n\");",
  1586. " }",
  1587. " if (bounded) uerror(\"depth limit reached\");",
  1588. " (trpt-1)->tau |= 16; /* worstcase guess */",
  1589. " goto Up;",
  1590. " }",
  1591. "AllOver:",
  1592. "#if defined(FULLSTACK) && !defined(MA)",
  1593. " /* if atomic or rv move, carry forward previous state */",
  1594. " trpt->ostate = (trpt-1)->ostate;", /* was: = (struct H_el *) 0;*/
  1595. "#endif",
  1596. "#ifdef VERI",
  1597. " if ((trpt->tau&4) || ((trpt-1)->tau&128))",
  1598. "#endif",
  1599. " if (boq == -1) { /* if not mid-rv */",
  1600. "#ifndef SAFETY",
  1601. " /* this check should now be redundant",
  1602. " * because the seed state also appears",
  1603. " * on the 1st dfs stack and would be",
  1604. " * matched in hstore below",
  1605. " */",
  1606. " if ((now._a_t&1) && depth > A_depth)",
  1607. " { if (!memcmp((char *)&A_Root, ",
  1608. " (char *)&now, vsize))",
  1609. " {",
  1610. " depthfound = A_depth;",
  1611. "#ifdef CHECK",
  1612. " printf(\"matches seed\\n\");",
  1613. "#endif",
  1614. "#ifdef NP",
  1615. " uerror(\"non-progress cycle\");",
  1616. "#else",
  1617. " uerror(\"acceptance cycle\");",
  1618. "#endif",
  1619. " goto Up;",
  1620. " }",
  1621. "#ifdef CHECK",
  1622. " printf(\"not seed\\n\");",
  1623. "#endif",
  1624. " }",
  1625. "#endif",
  1626. " if (!(trpt->tau&8)) /* if no atomic move */",
  1627. " {",
  1628. "#ifdef BITSTATE",
  1629. "#ifdef CNTRSTACK", /* -> bitstate, reduced, safety */
  1630. " II = bstore((char *)&now, vsize);",
  1631. " trpt->j6 = j1; trpt->j7 = j2;",
  1632. " JJ = LL[j1] && LL[j2];",
  1633. "#else",
  1634. "#ifdef FULLSTACK",
  1635. " JJ = onstack_now();", /* sets j1 */
  1636. "#else",
  1637. "#ifndef NOREDUCE",
  1638. " JJ = II; /* worstcase guess for p.o. */",
  1639. "#endif",
  1640. "#endif",
  1641. " II = bstore((char *)&now, vsize);", /* sets j1-j4 */
  1642. "#endif",
  1643. "#else",
  1644. "#ifdef MA",
  1645. " II = gstore((char *)&now, vsize, 0);",
  1646. "#ifndef FULLSTACK",
  1647. " JJ = II;",
  1648. "#else",
  1649. " JJ = (II == 2)?1:0;",
  1650. "#endif",
  1651. "#else",
  1652. " II = hstore((char *)&now, vsize);",
  1653. "#ifdef FULLSTACK",
  1654. " JJ = (II == 2)?1:0;",
  1655. "#endif",
  1656. "#endif",
  1657. "#endif",
  1658. " kk = (II == 1 || II == 2);",
  1659. /* II==0 new state */
  1660. /* II==1 old state */
  1661. /* II==2 on current dfs stack */
  1662. /* II==3 on 1st dfs stack */
  1663. "#ifndef SAFETY",
  1664. " if (!fairness && a_cycles)",
  1665. " if (II == 2 && ((trpt->o_pm&2) || ((trpt-1)->o_pm&2)))",
  1666. " { II = 3; /* Schwoon & Esparza 2005, Gastin&Moro 2004 */",
  1667. "#ifdef VERBOSE",
  1668. " printf(\"state match on dfs stack\\n\");",
  1669. "#endif",
  1670. " goto same_case;",
  1671. " }",
  1672. "#if defined(FULLSTACK) && defined(BITSTATE)",
  1673. " if (!JJ && (now._a_t&1) && depth > A_depth)",
  1674. " { int oj1 = j1;",
  1675. " uchar o_a_t = now._a_t;",
  1676. " now._a_t &= ~(1|16|32);", /* 1st stack */
  1677. " if (onstack_now())", /* changes j1 */
  1678. " { II = 3;",
  1679. "#ifdef VERBOSE",
  1680. " printf(\"state match on 1st dfs stack\\n\");",
  1681. "#endif",
  1682. " }",
  1683. " now._a_t = o_a_t;", /* restore */
  1684. " j1 = oj1;",
  1685. " }",
  1686. "#endif",
  1687. " if (II == 3 && a_cycles && (now._a_t&1))",
  1688. " {",
  1689. "#ifndef NOFAIR",
  1690. " if (fairness && now._cnt[1] > 1) /* was != 0 */",
  1691. " {",
  1692. "#ifdef VERBOSE",
  1693. " printf(\"\tfairness count non-zero\\n\");",
  1694. "#endif",
  1695. " II = 0;", /* treat as new state */
  1696. " } else",
  1697. "#endif",
  1698. " {",
  1699. "#ifndef BITSTATE",
  1700. " nShadow--;",
  1701. "#endif",
  1702. "same_case: if (Lstate) depthfound = Lstate->D;",
  1703. "#ifdef NP",
  1704. " uerror(\"non-progress cycle\");",
  1705. "#else",
  1706. " uerror(\"acceptance cycle\");",
  1707. "#endif",
  1708. " goto Up;",
  1709. " }",
  1710. " }",
  1711. "#endif",
  1712. "#ifndef NOREDUCE",
  1713. "#ifndef SAFETY",
  1714. " if ((II && JJ) || (II == 3))",
  1715. " { /* marker for liveness proviso */",
  1716. " (trpt-1)->tau |= 16;",
  1717. " truncs2++;",
  1718. " }",
  1719. "#else",
  1720. " if (!II || !JJ)",
  1721. " { /* successor outside stack */",
  1722. " (trpt-1)->tau |= 64;",
  1723. " }",
  1724. "#endif",
  1725. "#endif",
  1726. " if (II)",
  1727. " { truncs++;",
  1728. " goto Up;",
  1729. " }",
  1730. " if (!kk)",
  1731. " { nstates++;",
  1732. " if ((unsigned long) nstates%%1000000 == 0)",
  1733. " snapshot();",
  1734. "#ifdef SVDUMP",
  1735. " if (vprefix > 0)",
  1736. " if (write(svfd, (uchar *) &now, vprefix) != vprefix)",
  1737. " { fprintf(efd, \"writing %%s.svd failed\\n\", Source);",
  1738. " wrapup();",
  1739. " }",
  1740. "#endif",
  1741. "#if defined(MA) && defined(W_XPT)",
  1742. " if ((unsigned long) nstates%%W_XPT == 0)",
  1743. " { void w_xpoint(void);",
  1744. " w_xpoint();",
  1745. " }",
  1746. "#endif",
  1747. " }",
  1748. "#if defined(FULLSTACK) || defined(CNTRSTACK)",
  1749. " onstack_put();",
  1750. "#ifdef DEBUG2",
  1751. "#if defined(FULLSTACK) && !defined(MA)",
  1752. " printf(\"%%d: putting %%u (%%d)\\n\", depth,",
  1753. " trpt->ostate, ",
  1754. " (trpt->ostate)?trpt->ostate->tagged:0);",
  1755. "#else",
  1756. " printf(\"%%d: putting\\n\", depth);",
  1757. "#endif",
  1758. "#endif",
  1759. "#endif",
  1760. " } }",
  1761. " if (depth > mreached)",
  1762. " mreached = depth;",
  1763. "#ifdef VERI",
  1764. " if (trpt->tau&4)",
  1765. "#endif",
  1766. " trpt->tau &= ~(1|2); /* timeout and -request off */",
  1767. " _n = 0;",
  1768. "#if SYNC",
  1769. " (trpt+1)->o_n = 0;",
  1770. "#endif",
  1771. "#ifdef VERI",
  1772. " if (now._nr_pr == 0) /* claim terminated */",
  1773. " uerror(\"end state in claim reached\");",
  1774. " check_claim(((P0 *)pptr(0))->_p);",
  1775. "Stutter:",
  1776. " if (trpt->tau&4) /* must make a claimmove */",
  1777. " {",
  1778. "#ifndef NOFAIR",
  1779. " if ((now._a_t&2) /* A-bit set */",
  1780. " && now._cnt[now._a_t&1] == 1)",
  1781. " { now._a_t &= ~2;",
  1782. " now._cnt[now._a_t&1] = 0;",
  1783. " trpt->o_pm |= 16;",
  1784. "#ifdef DEBUG",
  1785. " printf(\"%%3d: fairness Rule 3.: _a_t = %%d\\n\",",
  1786. " depth, now._a_t);",
  1787. "#endif",
  1788. " }",
  1789. "#endif",
  1790. " II = 0; /* never */",
  1791. " goto Veri0;",
  1792. " }",
  1793. "#endif",
  1794. "#ifndef NOREDUCE",
  1795. " /* Look for a process with only safe transitions */",
  1796. " /* (special rules apply in the 2nd dfs) */",
  1797. "#ifdef SAFETY",
  1798. " if (boq == -1 && From != To)",
  1799. "#else",
  1800. "/* implied: #ifdef FULLSTACK */",
  1801. " if (boq == -1 && From != To",
  1802. " && (!(now._a_t&1)",
  1803. " || (a_cycles &&",
  1804. "#ifndef BITSTATE",
  1805. "#ifdef MA",
  1806. "#ifdef VERI",
  1807. " !((trpt-1)->proviso))",
  1808. "#else",
  1809. " !(trpt->proviso))",
  1810. "#endif",
  1811. "#else",
  1812. "#ifdef VERI",
  1813. " (trpt-1)->ostate &&",
  1814. " !(((char *)&((trpt-1)->ostate->state))[0] & 128))",
  1815. "#else",
  1816. " !(((char *)&(trpt->ostate->state))[0] & 128))",
  1817. "#endif",
  1818. "#endif",
  1819. "#else",
  1820. "#ifdef VERI",
  1821. " (trpt-1)->ostate &&",
  1822. " (trpt-1)->ostate->proviso == 0)",
  1823. "#else",
  1824. " trpt->ostate->proviso == 0)",
  1825. "#endif",
  1826. "#endif",
  1827. " ))",
  1828. "/* #endif */",
  1829. "#endif",
  1830. " for (II = From; II >= To; II -= 1)",
  1831. " {",
  1832. "Resume: /* pick up here if preselect fails */",
  1833. " this = pptr(II);",
  1834. " tt = (int) ((P0 *)this)->_p;",
  1835. " ot = (uchar) ((P0 *)this)->_t;",
  1836. " if (trans[ot][tt]->atom & 8)",
  1837. " { t = trans[ot][tt];",
  1838. " if (t->qu[0] != 0)",
  1839. " { Ccheck++;",
  1840. " if (!q_cond(II, t))",
  1841. " continue;",
  1842. " Cholds++;",
  1843. " }",
  1844. " From = To = II;",
  1845. "#ifdef NIBIS",
  1846. " t->om = 0;",
  1847. "#endif",
  1848. " trpt->tau |= 32; /* preselect marker */",
  1849. "#ifdef DEBUG",
  1850. "#ifdef NIBIS",
  1851. " printf(\"%%3d: proc %%d Pre\", depth, II);",
  1852. " printf(\"Selected (om=%%d, tau=%%d)\\n\", ",
  1853. " t->om, trpt->tau);",
  1854. "#else",
  1855. " printf(\"%%3d: proc %%d PreSelected (tau=%%d)\\n\", ",
  1856. " depth, II, trpt->tau);",
  1857. "#endif",
  1858. "#endif",
  1859. " goto Again;",
  1860. " }",
  1861. " }",
  1862. " trpt->tau &= ~32;",
  1863. "#endif",
  1864. "#if !defined(NOREDUCE) || (defined(ETIM) && !defined(VERI))",
  1865. "Again:",
  1866. "#endif",
  1867. " /* The Main Expansion Loop over Processes */",
  1868. " trpt->o_pm &= ~(8|16|32|64); /* fairness-marks */",
  1869. "#ifndef NOFAIR",
  1870. " if (fairness && boq == -1",
  1871. "#ifdef VERI",
  1872. " && (!(trpt->tau&4) && !((trpt-1)->tau&128))",
  1873. "#endif",
  1874. " && !(trpt->tau&8))",
  1875. " { /* A_bit = 1; Cnt = N in acc states with A_bit 0 */",
  1876. " if (!(now._a_t&2))", /* A-bit not set */
  1877. " {",
  1878. " if (a_cycles && (trpt->o_pm&2))",
  1879. " { /* Accepting state */",
  1880. " now._a_t |= 2;",
  1881. " now._cnt[now._a_t&1] = now._nr_pr + 1;", /* NEW +1 */
  1882. " trpt->o_pm |= 8;",
  1883. "#ifdef DEBUG",
  1884. " printf(\"%%3d: fairness Rule 1: cnt=%%d, _a_t=%%d\\n\",",
  1885. " depth, now._cnt[now._a_t&1], now._a_t);",
  1886. "#endif",
  1887. " }",
  1888. " } else", /* A-bit set */
  1889. " { /* A_bit = 0 when Cnt 0 */",
  1890. " if (now._cnt[now._a_t&1] == 1)", /* NEW: 1 iso 0 */
  1891. " { now._a_t &= ~2;", /* reset a-bit */
  1892. " now._cnt[now._a_t&1] = 0;", /* NEW: reset cnt */
  1893. " trpt->o_pm |= 16;",
  1894. "#ifdef DEBUG",
  1895. " printf(\"%%3d: fairness Rule 3: _a_t = %%d\\n\",",
  1896. " depth, now._a_t);",
  1897. "#endif",
  1898. " } } }",
  1899. "#endif",
  1900. " for (II = From; II >= To; II -= 1)",
  1901. " {",
  1902. "#if SYNC",
  1903. " /* no rendezvous with same proc */",
  1904. " if (boq != -1 && trpt->pr == II) continue;",
  1905. "#endif",
  1906. "#ifdef VERI",
  1907. "Veri0:",
  1908. "#endif",
  1909. " this = pptr(II);",
  1910. " tt = (int) ((P0 *)this)->_p;",
  1911. " ot = (uchar) ((P0 *)this)->_t;",
  1912. "#ifdef NIBIS",
  1913. " /* don't repeat a previous preselected expansion */",
  1914. " /* could hit this if reduction proviso was false */",
  1915. " t = trans[ot][tt];",
  1916. " if (!(trpt->tau&4)", /* not claim */
  1917. " && !(trpt->tau&1)", /* not timeout */
  1918. " && !(trpt->tau&32)", /* not preselected */
  1919. " && (t->atom & 8)", /* local */
  1920. " && boq == -1", /* not inside rendezvous */
  1921. " && From != To)", /* not inside atomic seq */
  1922. " { if (t->qu[0] == 0", /* unconditional */
  1923. " || q_cond(II, t))", /* true condition */
  1924. " { _m = t->om;",
  1925. " if (_m>_n||(_n>3&&_m!=0)) _n=_m;",
  1926. " continue; /* did it before */",
  1927. " } }",
  1928. "#endif",
  1929. " trpt->o_pm &= ~1; /* no move in this pid yet */",
  1930. "#ifdef EVENT_TRACE",
  1931. " (trpt+1)->o_event = now._event;",
  1932. "#endif",
  1933. " /* Fairness: Cnt++ when Cnt == II */",
  1934. "#ifndef NOFAIR",
  1935. " trpt->o_pm &= ~64; /* didn't apply rule 2 */",
  1936. " if (fairness",
  1937. " && boq == -1", /* not mid rv - except rcv - NEW 3.0.8 */
  1938. " && !(trpt->o_pm&32)", /* Rule 2 not in effect */
  1939. " && (now._a_t&2)", /* A-bit is set */
  1940. " && now._cnt[now._a_t&1] == II+2)",
  1941. " { now._cnt[now._a_t&1] -= 1;",
  1942. "#ifdef VERI",
  1943. " /* claim need not participate */",
  1944. " if (II == 1)",
  1945. " now._cnt[now._a_t&1] = 1;",
  1946. "#endif",
  1947. "#ifdef DEBUG",
  1948. " printf(\"%%3d: proc %%d fairness \", depth, II);",
  1949. " printf(\"Rule 2: --cnt to %%d (%%d)\\n\",",
  1950. " now._cnt[now._a_t&1], now._a_t);",
  1951. "#endif",
  1952. " trpt->o_pm |= (32|64);",
  1953. " }",
  1954. "#endif",
  1955. "#ifdef HAS_PROVIDED",
  1956. " if (!provided(II, ot, tt, t)) continue;",
  1957. "#endif",
  1958. " /* check all trans of proc II - escapes first */",
  1959. "#ifdef HAS_UNLESS",
  1960. " trpt->e_state = 0;",
  1961. "#endif",
  1962. " (trpt+1)->pr = (uchar) II;", /* for uerror */
  1963. " (trpt+1)->st = tt;",
  1964. "#ifdef RANDOMIZE",
  1965. " for (ooi = eoi = 0, t = trans[ot][tt]; t; t = t->nxt, ooi++)",
  1966. " if (strcmp(t->tp, \"else\") == 0)",
  1967. " eoi++;",
  1968. "",
  1969. " if (eoi)",
  1970. " { t = trans[ot][tt];",
  1971. "#ifdef VERBOSE",
  1972. " printf(\"randomizer: suppressed, saw else\\n\");",
  1973. "#endif",
  1974. " } else",
  1975. " { eoi = rand()%%ooi;",
  1976. "#ifdef VERBOSE",
  1977. " printf(\"randomizer: skip %%d in %%d\\n\", eoi, ooi);",
  1978. "#endif",
  1979. " for (t = trans[ot][tt]; t; t = t->nxt)",
  1980. " if (eoi-- <= 0) break;",
  1981. " }",
  1982. "DOMORE:",
  1983. " for ( ; t && ooi > 0; t = t->nxt, ooi--)",
  1984. "#else",
  1985. " for (t = trans[ot][tt]; t; t = t->nxt)",
  1986. "#endif",
  1987. " {",
  1988. "#ifdef HAS_UNLESS",
  1989. " /* exploring all transitions from",
  1990. " * a single escape state suffices",
  1991. " */",
  1992. " if (trpt->e_state > 0",
  1993. " && trpt->e_state != t->e_trans)",
  1994. " {",
  1995. "#ifdef DEBUG",
  1996. " printf(\"skip 2nd escape %%d (did %%d before)\\n\",",
  1997. " t->e_trans, trpt->e_state);",
  1998. "#endif",
  1999. " break;",
  2000. " }",
  2001. "#endif",
  2002. " (trpt+1)->o_t = t;", /* for uerror */
  2003. "#ifdef INLINE",
  2004. "#include FORWARD_MOVES",
  2005. "P999: /* jumps here when move succeeds */",
  2006. "#else",
  2007. " if (!(_m = do_transit(t, II))) continue;",
  2008. "#endif",
  2009. " if (boq == -1)",
  2010. "#ifdef CTL",
  2011. " /* for branching-time, can accept reduction only if */",
  2012. " /* the persistent set contains just 1 transition */",
  2013. " { if ((trpt->tau&32) && (trpt->o_pm&1))",
  2014. " trpt->tau |= 16;",
  2015. " trpt->o_pm |= 1; /* we moved */",
  2016. " }",
  2017. "#else",
  2018. " trpt->o_pm |= 1; /* we moved */",
  2019. "#endif",
  2020. "#ifdef PEG",
  2021. " peg[t->forw]++;",
  2022. "#endif",
  2023. "#if defined(VERBOSE) || defined(CHECK)",
  2024. "#if defined(SVDUMP)",
  2025. " printf(\"%%3d: proc %%d exec %%d \\n\", ",
  2026. " depth, II, t->t_id);",
  2027. "#else",
  2028. " printf(\"%%3d: proc %%d exec %%d, \", ",
  2029. " depth, II, t->forw);",
  2030. " printf(\"%%d to %%d, %%s %%s %%s\", ",
  2031. " tt, t->st, t->tp,",
  2032. " (t->atom&2)?\"atomic\":\"\",",
  2033. " (boq != -1)?\"rendez-vous\":\"\");",
  2034. "#ifdef HAS_UNLESS",
  2035. " if (t->e_trans)",
  2036. " printf(\" (escapes to state %%d)\",",
  2037. " t->st);",
  2038. "#endif",
  2039. " printf(\" %%saccepting [tau=%%d]\\n\",",
  2040. " (trpt->o_pm&2)?\"\":\"non-\", trpt->tau);",
  2041. "#endif",
  2042. "#ifdef RANDOMIZE",
  2043. " printf(\" randomizer %%d\\n\", ooi);",
  2044. "#endif",
  2045. "#endif",
  2046. "#ifdef HAS_LAST",
  2047. "#ifdef VERI",
  2048. " if (II != 0)",
  2049. "#endif",
  2050. " now._last = II - BASE;",
  2051. "#endif",
  2052. "#ifdef HAS_UNLESS",
  2053. " trpt->e_state = t->e_trans;",
  2054. "#endif",
  2055. " depth++; trpt++;",
  2056. " trpt->pr = (uchar) II;",
  2057. " trpt->st = tt;",
  2058. " trpt->o_pm &= ~(2|4);",
  2059. " if (t->st > 0)",
  2060. " { ((P0 *)this)->_p = t->st;",
  2061. "/* moved down reached[ot][t->st] = 1; */",
  2062. " }",
  2063. "#ifndef SAFETY",
  2064. " if (a_cycles)",
  2065. " {",
  2066. "#if (ACCEPT_LAB>0 && !defined(NP)) || (PROG_LAB>0 && defined(HAS_NP))",
  2067. " int ii;",
  2068. "#endif",
  2069. "#define P__Q ((P0 *)pptr(ii))",
  2070. "#if ACCEPT_LAB>0",
  2071. "#ifdef NP",
  2072. " /* state 1 of np_ claim is accepting */",
  2073. " if (((P0 *)pptr(0))->_p == 1)",
  2074. " trpt->o_pm |= 2;",
  2075. "#else",
  2076. " for (ii = 0; ii < (int) now._nr_pr; ii++)",
  2077. " { if (accpstate[P__Q->_t][P__Q->_p])",
  2078. " { trpt->o_pm |= 2;",
  2079. " break;",
  2080. " } }",
  2081. "#endif",
  2082. "#endif",
  2083. "#if defined(HAS_NP) && PROG_LAB>0",
  2084. " for (ii = 0; ii < (int) now._nr_pr; ii++)",
  2085. " { if (progstate[P__Q->_t][P__Q->_p])",
  2086. " { trpt->o_pm |= 4;",
  2087. " break;",
  2088. " } }",
  2089. "#endif",
  2090. "#undef P__Q",
  2091. " }",
  2092. "#endif",
  2093. " trpt->o_t = t; trpt->o_n = _n;",
  2094. " trpt->o_ot = ot; trpt->o_tt = tt;",
  2095. " trpt->o_To = To; trpt->o_m = _m;",
  2096. " trpt->tau = 0;",
  2097. "#ifdef RANDOMIZE",
  2098. " trpt->oo_i = ooi;",
  2099. "#endif",
  2100. " if (boq != -1 || (t->atom&2))",
  2101. " { trpt->tau |= 8;",
  2102. "#ifdef VERI",
  2103. " /* atomic sequence in claim */",
  2104. " if((trpt-1)->tau&4)",
  2105. " trpt->tau |= 4;",
  2106. " else",
  2107. " trpt->tau &= ~4;",
  2108. " } else",
  2109. " { if ((trpt-1)->tau&4)",
  2110. " trpt->tau &= ~4;",
  2111. " else",
  2112. " trpt->tau |= 4;",
  2113. " }",
  2114. " /* if claim allowed timeout, so */",
  2115. " /* does the next program-step: */",
  2116. " if (((trpt-1)->tau&1) && !(trpt->tau&4))",
  2117. " trpt->tau |= 1;",
  2118. "#else",
  2119. " } else",
  2120. " trpt->tau &= ~8;",
  2121. "#endif",
  2122. " if (boq == -1 && (t->atom&2))",
  2123. " { From = To = II; nlinks++;",
  2124. " } else",
  2125. " { From = now._nr_pr-1; To = BASE;",
  2126. " }",
  2127. " goto Down; /* pseudo-recursion */",
  2128. "Up:",
  2129. "#ifdef CHECK",
  2130. " printf(\"%%d: Up - %%s\\n\", depth,",
  2131. " (trpt->tau&4)?\"claim\":\"program\");",
  2132. "#endif",
  2133. "#ifdef MA",
  2134. " if (depth <= 0) return;",
  2135. " /* e.g., if first state is old, after a restart */",
  2136. "#endif",
  2137. "#ifdef SC",
  2138. " if (CNT1 > CNT2",
  2139. " && depth < hiwater - (HHH-DDD) + 2)",
  2140. " {",
  2141. " trpt += DDD;",
  2142. " disk2stack();",
  2143. " maxdepth -= DDD;",
  2144. " hiwater -= DDD;",
  2145. "if(verbose)",
  2146. "printf(\"unzap %%d: %%d\\n\", CNT2, hiwater);",
  2147. " }",
  2148. "#endif",
  2149. "#ifndef NOFAIR",
  2150. " if (trpt->o_pm&128) /* fairness alg */",
  2151. " { now._cnt[now._a_t&1] = trpt->bup.oval;",
  2152. " _n = 1; trpt->o_pm &= ~128;",
  2153. " depth--; trpt--;",
  2154. "#if defined(VERBOSE) || defined(CHECK)",
  2155. " printf(\"%%3d: reversed fairness default move\\n\", depth);",
  2156. "#endif",
  2157. " goto Q999;",
  2158. " }",
  2159. "#endif",
  2160. "#ifdef HAS_LAST",
  2161. "#ifdef VERI",
  2162. " { int d; Trail *trl;",
  2163. " now._last = 0;",
  2164. " for (d = 1; d < depth; d++)",
  2165. " { trl = getframe(depth-d); /* was (trpt-d) */",
  2166. " if (trl->pr != 0)",
  2167. " { now._last = trl->pr - BASE;",
  2168. " break;",
  2169. " } } }",
  2170. "#else",
  2171. " now._last = (depth<1)?0:(trpt-1)->pr;",
  2172. "#endif",
  2173. "#endif",
  2174. "#ifdef EVENT_TRACE",
  2175. " now._event = trpt->o_event;",
  2176. "#endif",
  2177. "#ifndef SAFETY",
  2178. " if ((now._a_t&1) && depth <= A_depth)",
  2179. " return; /* to checkcycles() */",
  2180. "#endif",
  2181. " t = trpt->o_t; _n = trpt->o_n;",
  2182. " ot = trpt->o_ot; II = trpt->pr;",
  2183. " tt = trpt->o_tt; this = pptr(II);",
  2184. " To = trpt->o_To; _m = trpt->o_m;",
  2185. "#ifdef RANDOMIZE",
  2186. " ooi = trpt->oo_i;",
  2187. "#endif",
  2188. "#ifdef INLINE_REV",
  2189. " _m = do_reverse(t, II, _m);",
  2190. "#else",
  2191. "#include REVERSE_MOVES",
  2192. "R999: /* jumps here when done */",
  2193. "#endif",
  2194. "#ifdef VERBOSE",
  2195. " printf(\"%%3d: proc %%d \", depth, II);",
  2196. " printf(\"reverses %%d, %%d to %%d,\",",
  2197. " t->forw, tt, t->st);",
  2198. " printf(\" %%s [abit=%%d,adepth=%%d,\", ",
  2199. " t->tp, now._a_t, A_depth);",
  2200. " printf(\"tau=%%d,%%d]\\n\", ",
  2201. " trpt->tau, (trpt-1)->tau);",
  2202. "#endif",
  2203. "#ifndef NOREDUCE",
  2204. " /* pass the proviso tags */",
  2205. " if ((trpt->tau&8) /* rv or atomic */",
  2206. " && (trpt->tau&16))",
  2207. " (trpt-1)->tau |= 16;",
  2208. "#ifdef SAFETY",
  2209. " if ((trpt->tau&8) /* rv or atomic */",
  2210. " && (trpt->tau&64))",
  2211. " (trpt-1)->tau |= 64;",
  2212. "#endif",
  2213. "#endif",
  2214. " depth--; trpt--;",
  2215. "#ifdef NIBIS",
  2216. " (trans[ot][tt])->om = _m; /* head of list */",
  2217. "#endif",
  2218. " /* i.e., not set if rv fails */",
  2219. " if (_m)",
  2220. " {",
  2221. "#if defined(VERI) && !defined(NP)",
  2222. " if (II == 0 && verbose && !reached[ot][t->st])",
  2223. " {",
  2224. " printf(\"depth %%d: Claim reached state %%d (line %%d)\\n\",",
  2225. " depth, t->st, src_claim [t->st]);",
  2226. " fflush(stdout);",
  2227. " }",
  2228. "#endif",
  2229. " reached[ot][t->st] = 1;",
  2230. " reached[ot][tt] = 1;",
  2231. " }",
  2232. "#ifdef HAS_UNLESS",
  2233. " else trpt->e_state = 0; /* undo */",
  2234. "#endif",
  2235. " if (_m>_n||(_n>3&&_m!=0)) _n=_m;",
  2236. " ((P0 *)this)->_p = tt;",
  2237. " } /* all options */",
  2238. "#ifdef RANDOMIZE",
  2239. " if (!t && ooi > 0)", /* means we skipped some initial options */
  2240. " { t = trans[ot][tt];",
  2241. "#ifdef VERBOSE",
  2242. " printf(\"randomizer: continue for %%d more\\n\", ooi);",
  2243. "#endif",
  2244. " goto DOMORE;",
  2245. " }",
  2246. "#ifdef VERBOSE",
  2247. " else",
  2248. " printf(\"randomizer: done\\n\");",
  2249. "#endif",
  2250. "#endif",
  2251. "#ifndef NOFAIR",
  2252. " /* Fairness: undo Rule 2 */",
  2253. " if ((trpt->o_pm&32)",/* rule 2 was applied */
  2254. " && (trpt->o_pm&64))",/* by this process II */
  2255. " { if (trpt->o_pm&1)",/* it didn't block */
  2256. " {",
  2257. "#ifdef VERI",
  2258. " if (now._cnt[now._a_t&1] == 1)", /* NEW: 1 iso 0 */
  2259. " now._cnt[now._a_t&1] = 2;", /* NEW: 2 iso 1*/
  2260. "#endif",
  2261. " now._cnt[now._a_t&1] += 1;",
  2262. "#ifdef VERBOSE",
  2263. " printf(\"%%3d: proc %%d fairness \", depth, II);",
  2264. " printf(\"undo Rule 2, cnt=%%d, _a_t=%%d\\n\",",
  2265. " now._cnt[now._a_t&1], now._a_t);",
  2266. "#endif",
  2267. " trpt->o_pm &= ~(32|64);",
  2268. " } else", /* process blocked */
  2269. " { if (_n > 0)", /* a prev proc didn't */
  2270. " {", /* start over */
  2271. " trpt->o_pm &= ~64;",
  2272. " II = From+1;",
  2273. " } } }",
  2274. "#endif",
  2275. "#ifdef VERI",
  2276. " if (II == 0) break; /* never claim */",
  2277. "#endif",
  2278. " } /* all processes */",
  2279. "#ifndef NOFAIR",
  2280. " /* Fairness: undo Rule 2 */",
  2281. " if (trpt->o_pm&32) /* remains if proc blocked */",
  2282. " {",
  2283. "#ifdef VERI",
  2284. " if (now._cnt[now._a_t&1] == 1)", /* NEW: 1 iso 0 */
  2285. " now._cnt[now._a_t&1] = 2;", /* NEW: 2 iso 1 */
  2286. "#endif",
  2287. " now._cnt[now._a_t&1] += 1;",
  2288. "#ifdef VERBOSE",
  2289. " printf(\"%%3d: proc -- fairness \", depth);",
  2290. " printf(\"undo Rule 2, cnt=%%d, _a_t=%%d\\n\",",
  2291. " now._cnt[now._a_t&1], now._a_t);",
  2292. "#endif",
  2293. " trpt->o_pm &= ~32;",
  2294. " }",
  2295. "#ifndef NP",
  2296. /* 12/97 non-progress cycles cannot be created
  2297. * by stuttering extension, here or elsewhere
  2298. */
  2299. " if (fairness",
  2300. " && _n == 0 /* nobody moved */",
  2301. "#ifdef VERI",
  2302. " && !(trpt->tau&4) /* in program move */",
  2303. "#endif",
  2304. " && !(trpt->tau&8) /* not an atomic one */",
  2305. "#ifdef OTIM",
  2306. " && ((trpt->tau&1) || endstate())",
  2307. "#else",
  2308. "#ifdef ETIM",
  2309. " && (trpt->tau&1) /* already tried timeout */",
  2310. "#endif",
  2311. "#endif",
  2312. "#ifndef NOREDUCE",
  2313. " /* see below */",
  2314. " && !((trpt->tau&32) && (_n == 0 || (trpt->tau&16)))",
  2315. "#endif",
  2316. " && now._cnt[now._a_t&1] > 0) /* needed more procs */",
  2317. " { depth++; trpt++;",
  2318. " trpt->o_pm |= 128 | ((trpt-1)->o_pm&(2|4));",
  2319. " trpt->bup.oval = now._cnt[now._a_t&1];",
  2320. " now._cnt[now._a_t&1] = 1;",
  2321. "#ifdef VERI",
  2322. " trpt->tau = 4;",
  2323. "#else",
  2324. " trpt->tau = 0;",
  2325. "#endif",
  2326. " From = now._nr_pr-1; To = BASE;",
  2327. "#if defined(VERBOSE) || defined(CHECK)",
  2328. " printf(\"%%3d: fairness default move \", depth);",
  2329. " printf(\"(all procs block)\\n\");",
  2330. "#endif",
  2331. " goto Down;",
  2332. " }",
  2333. "#endif",
  2334. "Q999: /* returns here with _n>0 when done */;",
  2335. " if (trpt->o_pm&8)",
  2336. " { now._a_t &= ~2;",
  2337. " now._cnt[now._a_t&1] = 0;",
  2338. " trpt->o_pm &= ~8;",
  2339. "#ifdef VERBOSE",
  2340. " printf(\"%%3d: fairness undo Rule 1, _a_t=%%d\\n\",",
  2341. " depth, now._a_t);",
  2342. "#endif",
  2343. " }",
  2344. " if (trpt->o_pm&16)",
  2345. " { now._a_t |= 2;", /* restore a-bit */
  2346. " now._cnt[now._a_t&1] = 1;", /* NEW: restore cnt */
  2347. " trpt->o_pm &= ~16;",
  2348. "#ifdef VERBOSE",
  2349. " printf(\"%%3d: fairness undo Rule 3, _a_t=%%d\\n\",",
  2350. " depth, now._a_t);",
  2351. "#endif",
  2352. " }",
  2353. "#endif",
  2354. "#ifndef NOREDUCE",
  2355. "#ifdef SAFETY",
  2356. " /* preselected move - no successors outside stack */",
  2357. " if ((trpt->tau&32) && !(trpt->tau&64))",
  2358. " { From = now._nr_pr-1; To = BASE;",
  2359. "#ifdef DEBUG",
  2360. " printf(\"%%3d: proc %%d UnSelected (_n=%%d, tau=%%d)\\n\", ",
  2361. " depth, II+1, _n, trpt->tau);",
  2362. "#endif",
  2363. " _n = 0; trpt->tau &= ~(16|32|64);",
  2364. " if (II >= BASE) /* II already decremented */",
  2365. " goto Resume;",
  2366. " else",
  2367. " goto Again;",
  2368. " }",
  2369. "#else",
  2370. " /* at least one move that was preselected at this */",
  2371. " /* level, blocked or truncated at the next level */",
  2372. "/* implied: #ifdef FULLSTACK */",
  2373. " if ((trpt->tau&32) && (_n == 0 || (trpt->tau&16)))",
  2374. " {",
  2375. "#ifdef DEBUG",
  2376. " printf(\"%%3d: proc %%d UnSelected (_n=%%d, tau=%%d)\\n\", ",
  2377. " depth, II+1, (int) _n, trpt->tau);",
  2378. "#endif",
  2379. " if (a_cycles && (trpt->tau&16))",
  2380. " { if (!(now._a_t&1))",
  2381. " {",
  2382. "#ifdef DEBUG",
  2383. " printf(\"%%3d: setting proviso bit\\n\", depth);",
  2384. "#endif",
  2385. "#ifndef BITSTATE",
  2386. "#ifdef MA",
  2387. "#ifdef VERI",
  2388. " (trpt-1)->proviso = 1;",
  2389. "#else",
  2390. " trpt->proviso = 1;",
  2391. "#endif",
  2392. "#else",
  2393. "#ifdef VERI",
  2394. " if ((trpt-1)->ostate)",
  2395. " ((char *)&((trpt-1)->ostate->state))[0] |= 128;",
  2396. "#else",
  2397. " ((char *)&(trpt->ostate->state))[0] |= 128;",
  2398. "#endif",
  2399. "#endif",
  2400. "#else",
  2401. "#ifdef VERI",
  2402. " if ((trpt-1)->ostate)",
  2403. " (trpt-1)->ostate->proviso = 1;",
  2404. "#else",
  2405. " trpt->ostate->proviso = 1;",
  2406. "#endif",
  2407. "#endif",
  2408. " From = now._nr_pr-1; To = BASE;",
  2409. " _n = 0; trpt->tau &= ~(16|32|64);",
  2410. " goto Again; /* do full search */",
  2411. " } /* else accept reduction */",
  2412. " } else",
  2413. " { From = now._nr_pr-1; To = BASE;",
  2414. " _n = 0; trpt->tau &= ~(16|32|64);",
  2415. " if (II >= BASE) /* already decremented */",
  2416. " goto Resume;",
  2417. " else",
  2418. " goto Again;",
  2419. " } }",
  2420. "/* #endif */",
  2421. "#endif",
  2422. "#endif",
  2423. " if (_n == 0 || ((trpt->tau&4) && (trpt->tau&2)))",
  2424. " {",
  2425. "#ifdef DEBUG",
  2426. " printf(\"%%3d: no move [II=%%d, tau=%%d, boq=%%d]\\n\",",
  2427. " depth, II, trpt->tau, boq);",
  2428. "#endif",
  2429. "#if SYNC",
  2430. " /* ok if a rendez-vous fails: */",
  2431. " if (boq != -1) goto Done;",
  2432. "#endif",
  2433. " /* ok if no procs or we're at maxdepth */",
  2434. " if ((now._nr_pr == 0 && (!strict || qs_empty()))",
  2435. "#ifdef OTIM",
  2436. " || endstate()",
  2437. "#endif",
  2438. " || depth >= maxdepth-1) goto Done;",
  2439. " if ((trpt->tau&8) && !(trpt->tau&4))",
  2440. " { trpt->tau &= ~(1|8);",
  2441. " /* 1=timeout, 8=atomic */",
  2442. " From = now._nr_pr-1; To = BASE;",
  2443. "#ifdef DEBUG",
  2444. " printf(\"%%3d: atomic step proc %%d \", depth, II+1);",
  2445. " printf(\"unexecutable\\n\");",
  2446. "#endif",
  2447. "#ifdef VERI",
  2448. " trpt->tau |= 4; /* switch to claim */",
  2449. "#endif",
  2450. " goto AllOver;",
  2451. " }",
  2452. "#ifdef ETIM",
  2453. " if (!(trpt->tau&1)) /* didn't try timeout yet */",
  2454. " {",
  2455. "#ifdef VERI",
  2456. " if (trpt->tau&4)",
  2457. " {",
  2458. "#ifndef NTIM",
  2459. " if (trpt->tau&2) /* requested */",
  2460. "#endif",
  2461. " { trpt->tau |= 1;",
  2462. " trpt->tau &= ~2;",
  2463. "#ifdef DEBUG",
  2464. " printf(\"%%d: timeout\\n\", depth);",
  2465. "#endif",
  2466. " goto Stutter;",
  2467. " } }",
  2468. " else",
  2469. " { /* only claim can enable timeout */",
  2470. " if ((trpt->tau&8)",
  2471. " && !((trpt-1)->tau&4))",
  2472. "/* blocks inside an atomic */ goto BreakOut;",
  2473. "#ifdef DEBUG",
  2474. " printf(\"%%d: req timeout\\n\",",
  2475. " depth);",
  2476. "#endif",
  2477. " (trpt-1)->tau |= 2; /* request */",
  2478. " goto Up;",
  2479. " }",
  2480. "#else",
  2481. "#ifdef DEBUG",
  2482. " printf(\"%%d: timeout\\n\", depth);",
  2483. "#endif",
  2484. " trpt->tau |= 1;",
  2485. " goto Again;",
  2486. "#endif",
  2487. " }",
  2488. "#endif",
  2489. /* old location of atomic block code */
  2490. "#ifdef VERI",
  2491. "BreakOut:",
  2492. "#ifndef NOSTUTTER",
  2493. " if (!(trpt->tau&4))",
  2494. " { trpt->tau |= 4; /* claim stuttering */",
  2495. " trpt->tau |= 128; /* stutter mark */",
  2496. "#ifdef DEBUG",
  2497. " printf(\"%%d: claim stutter\\n\", depth);",
  2498. "#endif",
  2499. " goto Stutter;",
  2500. " }",
  2501. "#else",
  2502. " ;",
  2503. "#endif",
  2504. "#else",
  2505. " if (!noends && !a_cycles && !endstate())",
  2506. " { depth--; trpt--; /* new 4.2.3 */",
  2507. " uerror(\"invalid end state\");",
  2508. " depth++; trpt++;",
  2509. " }",
  2510. "#ifndef NOSTUTTER",
  2511. " else if (a_cycles && (trpt->o_pm&2)) /* new 4.2.4 */",
  2512. " { depth--; trpt--;",
  2513. " uerror(\"accept stutter\");",
  2514. " depth++; trpt++;",
  2515. " }",
  2516. "#endif",
  2517. "#endif",
  2518. " }",
  2519. "Done:",
  2520. " if (!(trpt->tau&8)) /* not in atomic seqs */",
  2521. " {",
  2522. "#ifndef SAFETY",
  2523. " if (_n != 0", /* we made a move */
  2524. "#ifdef VERI",
  2525. " /* --after-- a program-step, i.e., */",
  2526. " /* after backtracking a claim-step */",
  2527. " && (trpt->tau&4)",
  2528. " /* with at least one running process */",
  2529. " /* unless in a stuttered accept state */",
  2530. " && ((now._nr_pr > 1) || (trpt->o_pm&2))",
  2531. "#endif",
  2532. " && !(now._a_t&1))", /* not in 2nd DFS */
  2533. " {",
  2534. "#ifndef NOFAIR",
  2535. " if (fairness)", /* implies a_cycles */
  2536. " {",
  2537. "#ifdef VERBOSE",
  2538. " printf(\"Consider check %%d %%d...\\n\",",
  2539. " now._a_t, now._cnt[0]);",
  2540. "#endif",
  2541. #if 0
  2542. the a-bit is set, which means that the fairness
  2543. counter is running -- it was started in an accepting state.
  2544. we check that the counter reached 1, which means that all
  2545. processes moved least once.
  2546. this means we can start the search for cycles -
  2547. to be able to return to this state, we should be able to
  2548. run down the counter to 1 again -- which implies a visit to
  2549. the accepting state -- even though the Seed state for this
  2550. search is itself not necessarily accepting
  2551. #endif
  2552. " if ((now._a_t&2) /* A-bit */",
  2553. " && (now._cnt[0] == 1))",
  2554. " checkcycles();",
  2555. " } else",
  2556. "#endif",
  2557. " if (a_cycles && (trpt->o_pm&2))",
  2558. " checkcycles();",
  2559. " }",
  2560. "#endif",
  2561. "#ifndef MA",
  2562. "#if defined(FULLSTACK) || defined(CNTRSTACK)",
  2563. "#ifdef VERI",
  2564. " if (boq == -1",
  2565. " && (((trpt->tau&4) && !(trpt->tau&128))",
  2566. " || ( (trpt-1)->tau&128)))",
  2567. "#else",
  2568. " if (boq == -1)",
  2569. "#endif",
  2570. " {",
  2571. "#ifdef DEBUG2",
  2572. "#if defined(FULLSTACK)",
  2573. " printf(\"%%d: zapping %%u (%%d)\\n\",",
  2574. " depth, trpt->ostate,",
  2575. " (trpt->ostate)?trpt->ostate->tagged:0);",
  2576. "#endif",
  2577. "#endif",
  2578. " onstack_zap();",
  2579. " }",
  2580. "#endif",
  2581. "#else",
  2582. "#ifdef VERI",
  2583. " if (boq == -1",
  2584. " && (((trpt->tau&4) && !(trpt->tau&128))",
  2585. " || ( (trpt-1)->tau&128)))",
  2586. "#else",
  2587. " if (boq == -1)",
  2588. "#endif",
  2589. " {",
  2590. "#ifdef DEBUG",
  2591. " printf(\"%%d: zapping\\n\", depth);",
  2592. "#endif",
  2593. " onstack_zap();",
  2594. "#ifndef NOREDUCE",
  2595. " if (trpt->proviso)",
  2596. " gstore((char *) &now, vsize, 1);",
  2597. "#endif",
  2598. " }",
  2599. "#endif",
  2600. " }",
  2601. " if (depth > 0) goto Up;",
  2602. "}\n",
  2603. "#else",
  2604. "void new_state(void) { /* place holder */ }",
  2605. "#endif", /* BFS */
  2606. "",
  2607. "void",
  2608. "assert(int a, char *s, int ii, int tt, Trans *t)",
  2609. "{",
  2610. " if (!a && !noasserts)",
  2611. " { char bad[1024];",
  2612. " strcpy(bad, \"assertion violated \");",
  2613. " if (strlen(s) > 1000)",
  2614. " { strncpy(&bad[19], (const char *) s, 1000);",
  2615. " bad[1019] = '\\0';",
  2616. " } else",
  2617. " strcpy(&bad[19], s);",
  2618. " uerror(bad);",
  2619. " }",
  2620. "}",
  2621. "#ifndef NOBOUNDCHECK",
  2622. "int",
  2623. "Boundcheck(int x, int y, int a1, int a2, Trans *a3)",
  2624. "{",
  2625. " assert((x >= 0 && x < y), \"- invalid array index\",",
  2626. " a1, a2, a3);",
  2627. " return x;",
  2628. "}",
  2629. "#endif",
  2630. "void",
  2631. "wrap_stats(void)",
  2632. "{",
  2633. " if (nShadow>0)",
  2634. " printf(\"%%8g states, stored (%%g visited)\\n\",",
  2635. " nstates - nShadow, nstates);",
  2636. " else",
  2637. " printf(\"%%8g states, stored\\n\", nstates);",
  2638. "#ifdef BFS",
  2639. "#if SYNC",
  2640. " printf(\" %%8g nominal states (- rv and atomic)\\n\", nstates-midrv-nlinks+revrv);",
  2641. " printf(\" %%8g rvs succeeded\\n\", midrv-failedrv);",
  2642. "#else",
  2643. " printf(\" %%8g nominal states (stored-atomic)\\n\", nstates-nlinks);",
  2644. "#endif",
  2645. "#ifdef DEBUG",
  2646. " printf(\" %%8g midrv\\n\", midrv);",
  2647. " printf(\" %%8g failedrv\\n\", failedrv);",
  2648. " printf(\" %%8g revrv\\n\", revrv);",
  2649. "#endif",
  2650. "#endif",
  2651. " printf(\"%%8g states, matched\\n\", truncs);",
  2652. "#ifdef CHECK",
  2653. " printf(\"%%8g matches within stack\\n\",truncs2);",
  2654. "#endif",
  2655. " if (nShadow>0)",
  2656. " printf(\"%%8g transitions (= visited+matched)\\n\",",
  2657. " nstates+truncs);",
  2658. " else",
  2659. " printf(\"%%8g transitions (= stored+matched)\\n\",",
  2660. " nstates+truncs);",
  2661. " printf(\"%%8g atomic steps\\n\", nlinks);",
  2662. " if (nlost) printf(\"%%g lost messages\\n\", (double) nlost);",
  2663. "",
  2664. "#ifndef BITSTATE",
  2665. " printf(\"hash conflicts: %%g (resolved)\\n\", hcmp);",
  2666. "#else",
  2667. "#ifdef CHECK",
  2668. " printf(\"%%8g states allocated for dfs stack\\n\", ngrabs);",
  2669. "#endif",
  2670. " printf(\"\\nhash factor: %%4g (best if > 100.)\\n\\n\",",
  2671. " (double)(1<<(ssize-8)) / (double) nstates * 256.0);",
  2672. " printf(\"bits set per state: %%u (-k%%u)\\n\", hfns, hfns);",
  2673. "#if 0",
  2674. #ifndef POWOW
  2675. " if (udmem)",
  2676. " printf(\"total bits available: %%8g (-M%%ld)\\n\",",
  2677. " ((double) udmem) * 8.0, udmem/(1024L*1024L));",
  2678. " else",
  2679. #endif
  2680. " printf(\"total bits available: %%8g (-w%%d)\\n\",",
  2681. " ((double) (1L << (ssize-4)) * 16.0), ssize);",
  2682. "#endif",
  2683. "#ifdef COVEST",
  2684. " /* this code requires compilation with -lm on some systems */",
  2685. " { double pow(double, double);",
  2686. " double log(double);",
  2687. " unsigned int best_k;",
  2688. " double i, n = 30000.0L;",
  2689. " double f, p, q, m, c, est = 0.0L, k = (double)hfns;",
  2690. " c = (double) nstates / n;",
  2691. " m = (double) (1<<(ssize-8)) * 256.0L / c;",
  2692. " p = 1.0L - (k / m); q = 1.0L;",
  2693. " for (i = 0.0L; i - est < n; i += 1.0L)",
  2694. " { q *= p;",
  2695. " est += pow(1.0L - q, k);",
  2696. " }",
  2697. " f = m/i;",
  2698. " est *= c;",
  2699. " i *= c;",
  2700. " /* account for loss from enhanced double hashing */",
  2701. " if (hfns > 2) est += i * pow(0.5, (double) ssize * 2.0);",
  2702. "",
  2703. " if (f < 1.134) best_k = 1;",
  2704. " else if (f < 2.348) best_k = 2;",
  2705. " else if (f < 3.644) best_k = 3;",
  2706. " else best_k = (unsigned int) (pow(3.8L,1.0L/(f+4.2L))*f*.69315L + 0.99999999L);",
  2707. "",
  2708. " if (best_k != hfns && best_k > ssize)",
  2709. " best_k = (unsigned int) 1.0 + ssize/log((double)best_k / (double)ssize + 3.0);",
  2710. "",
  2711. " if (best_k > 32)",
  2712. " best_k = 1 + (unsigned int) (32.0/log((double)best_k/35.0));",
  2713. "",
  2714. " if (est * (double) nstates < 1.0)",
  2715. " { printf(\"prob. of omissions: negligible\\n\");",
  2716. " return; /* no hints needed */",
  2717. " }",
  2718. "",
  2719. " if (best_k != hfns)",
  2720. " { printf(\"hint: repeating the search with -k%%u \", best_k);",
  2721. " printf(\"may increase accuracy\\n\");",
  2722. " } else",
  2723. " { printf(\"hint: the current setting for -k (-k%%d) \", hfns);",
  2724. " printf(\"is likely to be optimal for -w%%d\\n\", ssize);",
  2725. " }",
  2726. " if (ssize < 32)",
  2727. " { printf(\"hint: increasing -w above -w%%d \", ssize);",
  2728. " printf(\"will increase accuracy (max is -w34)\\n\");",
  2729. " printf(\"(in xspin, increase Estimated State Space Size)\\n\");",
  2730. " } }",
  2731. "#endif",
  2732. "#endif",
  2733. "}",
  2734. "void",
  2735. "wrapup(void)",
  2736. "{",
  2737. "#if defined(BITSTATE) || !defined(NOCOMP)",
  2738. " double nr1, nr2, nr3 = 0.0, nr4, nr5 = 0.0;",
  2739. "#if !defined(MA) && (defined(MEMCNT) || defined(MEMLIM))",
  2740. " int mverbose = 1;",
  2741. "#else",
  2742. " int mverbose = verbose;",
  2743. "#endif",
  2744. "#endif",
  2745. " signal(SIGINT, SIG_DFL);",
  2746. " printf(\"(%%s)\\n\", Version);",
  2747. " if (!done) printf(\"Warning: Search not completed\\n\");",
  2748. "#ifdef SC",
  2749. " (void) unlink((const char *)stackfile);",
  2750. "#endif",
  2751. "#ifdef BFS",
  2752. " printf(\" + Using Breadth-First Search\\n\");",
  2753. "#endif",
  2754. "#ifndef NOREDUCE",
  2755. " printf(\" + Partial Order Reduction\\n\");",
  2756. "#endif",
  2757. #if 0
  2758. "#ifdef Q_PROVISO",
  2759. " printf(\" + Queue Proviso\\n\");",
  2760. "#endif",
  2761. #endif
  2762. "#ifdef COLLAPSE",
  2763. " printf(\" + Compression\\n\");",
  2764. "#endif",
  2765. "#ifdef MA",
  2766. " printf(\" + Graph Encoding (-DMA=%%d)\\n\", MA);",
  2767. "#ifdef R_XPT",
  2768. " printf(\" Restarted from checkpoint %%s.xpt\\n\", Source);",
  2769. "#endif",
  2770. "#endif",
  2771. "#ifdef CHECK",
  2772. "#ifdef FULLSTACK",
  2773. " printf(\" + FullStack Matching\\n\");",
  2774. "#endif",
  2775. "#ifdef CNTRSTACK",
  2776. " printf(\" + CntrStack Matching\\n\");",
  2777. "#endif",
  2778. "#endif",
  2779. "#ifdef BITSTATE",
  2780. " printf(\"\\nBit statespace search for:\\n\");",
  2781. "#else",
  2782. "#ifdef HC",
  2783. " printf(\"\\nHash-Compact %%d search for:\\n\", HC);",
  2784. "#else",
  2785. " printf(\"\\nFull statespace search for:\\n\");",
  2786. "#endif",
  2787. "#endif",
  2788. "#ifdef EVENT_TRACE",
  2789. "#ifdef NEGATED_TRACE",
  2790. " printf(\"\tnotrace assertion \t+\\n\");",
  2791. "#else",
  2792. " printf(\"\ttrace assertion \t+\\n\");",
  2793. "#endif",
  2794. "#endif",
  2795. "#ifdef VERI",
  2796. " printf(\"\tnever claim \t+\\n\");",
  2797. " printf(\"\tassertion violations\t\");",
  2798. " if (noasserts)",
  2799. " printf(\"- (disabled by -A flag)\\n\");",
  2800. " else",
  2801. " printf(\"+ (if within scope of claim)\\n\");",
  2802. "#else",
  2803. "#ifdef NOCLAIM",
  2804. " printf(\"\tnever claim \t- (not selected)\\n\");",
  2805. "#else",
  2806. " printf(\"\tnever claim \t- (none specified)\\n\");",
  2807. "#endif",
  2808. " printf(\"\tassertion violations\t\");",
  2809. " if (noasserts)",
  2810. " printf(\"- (disabled by -A flag)\\n\");",
  2811. " else",
  2812. " printf(\"+\\n\");",
  2813. "#endif",
  2814. "#ifndef SAFETY",
  2815. "#ifdef NP",
  2816. " printf(\"\tnon-progress cycles \t\");",
  2817. "#else",
  2818. " printf(\"\tacceptance cycles \t\");",
  2819. "#endif",
  2820. " if (a_cycles)",
  2821. " printf(\"+ (fairness %%sabled)\\n\",",
  2822. " fairness?\"en\":\"dis\");",
  2823. " else printf(\"- (not selected)\\n\");",
  2824. "#else",
  2825. " printf(\"\tcycle checks \t- (disabled by -DSAFETY)\\n\");",
  2826. "#endif",
  2827. "#ifdef VERI",
  2828. " printf(\"\tinvalid end states\t- \");",
  2829. " printf(\"(disabled by \");",
  2830. " if (noends)",
  2831. " printf(\"-E flag)\\n\\n\");",
  2832. " else",
  2833. " printf(\"never claim)\\n\\n\");",
  2834. "#else",
  2835. " printf(\"\tinvalid end states\t\");",
  2836. " if (noends)",
  2837. " printf(\"- (disabled by -E flag)\\n\\n\");",
  2838. " else",
  2839. " printf(\"+\\n\\n\");",
  2840. "#endif",
  2841. " printf(\"State-vector %%d byte, depth reached %%d\", ",
  2842. " hmax, mreached);",
  2843. " printf(\", errors: %%d\\n\", errors);",
  2844. "#ifdef MA",
  2845. " if (done)",
  2846. " { extern void dfa_stats(void);",
  2847. " if (maxgs+a_cycles+2 < MA)",
  2848. " printf(\"MA stats: -DMA=%%d is sufficient\\n\",",
  2849. " maxgs+a_cycles+2);",
  2850. " dfa_stats();",
  2851. " }",
  2852. "#endif",
  2853. " wrap_stats();",
  2854. "#ifdef CHECK",
  2855. " printf(\"stackframes: %%d/%%d\\n\\n\", smax, svmax);",
  2856. " printf(\"stats: fa %%d, fh %%d, zh %%d, zn %%d - \",",
  2857. " Fa, Fh, Zh, Zn);",
  2858. " printf(\"check %%d holds %%d\\n\", Ccheck, Cholds);",
  2859. " printf(\"stack stats: puts %%d, probes %%d, zaps %%d\\n\",",
  2860. " PUT, PROBE, ZAPS);",
  2861. "#else",
  2862. " printf(\"\\n\");",
  2863. "#endif",
  2864. "",
  2865. "#if defined(BITSTATE) || !defined(NOCOMP)",
  2866. " nr1 = (nstates-nShadow)*",
  2867. " (double)(hmax+sizeof(struct H_el)-sizeof(unsigned));",
  2868. "#ifdef BFS",
  2869. " nr2 = 0.0;",
  2870. "#else",
  2871. " nr2 = (double) ((maxdepth+3)*sizeof(Trail));",
  2872. "#endif",
  2873. "#ifndef BITSTATE",
  2874. "#if !defined(MA) || defined(COLLAPSE)",
  2875. " nr3 = (double) (1L<<ssize)*sizeof(struct H_el *);",
  2876. "#endif",
  2877. "#else",
  2878. #ifndef POWOW
  2879. " if (udmem)",
  2880. " nr3 = (double) (udmem);",
  2881. " else",
  2882. #endif
  2883. " nr3 = (double) (1L<<(ssize-3));",
  2884. "#ifdef CNTRSTACK",
  2885. " nr3 += (double) (1L<<(ssize-3));",
  2886. "#endif",
  2887. "#ifdef FULLSTACK",
  2888. " nr5 = (double) (maxdepth*sizeof(struct H_el *));",
  2889. "#endif",
  2890. "#endif",
  2891. " nr4 = (double) (svmax * (sizeof(Svtack) + hmax))",
  2892. " + (double) (smax * (sizeof(Stack) + Maxbody));",
  2893. "#ifndef MA",
  2894. " if (mverbose || memcnt < nr1+nr2+nr3+nr4+nr5)",
  2895. "#endif",
  2896. " { double remainder = memcnt;",
  2897. " double tmp_nr = memcnt-nr3-nr4-(nr2-fragment)-nr5;",
  2898. " if (tmp_nr < 0.0) tmp_nr = 0.;",
  2899. " printf(\"Stats on memory usage (in Megabytes):\\n\");",
  2900. " printf(\"%%-6.3f\tequivalent memory usage for states\",",
  2901. " nr1/1000000.);",
  2902. " printf(\" (stored*(State-vector + overhead))\\n\");",
  2903. "#ifdef BITSTATE",
  2904. #ifndef POWOW
  2905. " if (udmem)",
  2906. " printf(\"%%-6.3f\tmemory used for hash array (-M%%ld)\\n\",",
  2907. " nr3/1000000., udmem/(1024L*1024L));",
  2908. " else",
  2909. #endif
  2910. " printf(\"%%-6.3f\tmemory used for hash array (-w%%d)\\n\",",
  2911. " nr3/1000000., ssize);",
  2912. " if (nr5 > 0.0)",
  2913. " printf(\"%%-6.3f\tmemory used for bit stack\\n\",",
  2914. " nr5/1000000.);",
  2915. " remainder = remainder - nr3 - nr5;",
  2916. "#else",
  2917. " printf(\"%%-6.3f\tactual memory usage for states\",",
  2918. " tmp_nr/1000000.);",
  2919. " remainder = remainder - tmp_nr;",
  2920. " printf(\" (\");",
  2921. " if (tmp_nr > 0.)",
  2922. " { if (tmp_nr > nr1) printf(\"unsuccessful \");",
  2923. " printf(\"compression: %%.2f%%%%)\\n\",",
  2924. " (100.0*tmp_nr)/nr1);",
  2925. " } else",
  2926. " printf(\"less than 1k)\\n\");",
  2927. "#ifndef MA",
  2928. " if (tmp_nr > 0.)",
  2929. " { printf(\"\tState-vector as stored = %%.0f byte\",",
  2930. " (tmp_nr)/(nstates-nShadow) -",
  2931. " (double) (sizeof(struct H_el) - sizeof(unsigned)));",
  2932. " printf(\" + %%ld byte overhead\\n\",",
  2933. " sizeof(struct H_el)-sizeof(unsigned));",
  2934. " }",
  2935. "#endif",
  2936. "#if !defined(MA) || defined(COLLAPSE)",
  2937. " printf(\"%%-6.3f\tmemory used for hash table (-w%%d)\\n\",",
  2938. " nr3/1000000., ssize);",
  2939. " remainder = remainder - nr3;",
  2940. "#endif",
  2941. "#endif",
  2942. "#ifndef BFS",
  2943. " printf(\"%%-6.3f\tmemory used for DFS stack (-m%%ld)\\n\",",
  2944. " nr2/1000000., maxdepth);",
  2945. " remainder = remainder - nr2;",
  2946. "#endif",
  2947. " if (remainder - fragment > 0.0)",
  2948. " printf(\"%%-6.3f\tother (proc and chan stacks)\\n\",",
  2949. " (remainder-fragment)/1000000.);",
  2950. " if (fragment > 0.0)",
  2951. " printf(\"%%-6.3f\tmemory lost to fragmentation\\n\",",
  2952. " fragment/1000000.);",
  2953. " printf(\"%%-6.3f\ttotal actual memory usage\\n\\n\",",
  2954. " memcnt/1000000.);",
  2955. " }",
  2956. "#ifndef MA",
  2957. " else",
  2958. "#endif",
  2959. "#endif",
  2960. "#ifndef MA",
  2961. " printf(\"%%-6.3f\tmemory usage (Mbyte)\\n\\n\",",
  2962. " memcnt/1000000.);",
  2963. "#endif",
  2964. "#ifdef COLLAPSE",
  2965. " printf(\"nr of templates: [ globals chans procs ]\\n\");",
  2966. " printf(\"collapse counts: [ \");",
  2967. " { int i; for (i = 0; i < 256+2; i++)",
  2968. " if (ncomps[i] != 0)",
  2969. " printf(\"%%d \", ncomps[i]);",
  2970. " printf(\"]\\n\");",
  2971. " }",
  2972. "#endif",
  2973. " if ((done || verbose) && !no_rck) do_reach();",
  2974. "#ifdef PEG",
  2975. " { int i;",
  2976. " printf(\"\\nPeg Counts (transitions executed):\\n\");",
  2977. " for (i = 1; i < NTRANS; i++)",
  2978. " { if (peg[i]) putpeg(i, peg[i]);",
  2979. " } }",
  2980. "#endif",
  2981. "#ifdef VAR_RANGES",
  2982. " dumpranges();",
  2983. "#endif",
  2984. "#ifdef SVDUMP",
  2985. " if (vprefix > 0) close(svfd);",
  2986. "#endif",
  2987. " pan_exit(0);",
  2988. "}\n",
  2989. "void",
  2990. "stopped(int arg)",
  2991. "{ printf(\"Interrupted\\n\");",
  2992. " wrapup();",
  2993. " pan_exit(0);",
  2994. "}",
  2995. "/*",
  2996. " * based on Bob Jenkins hash-function from 1996",
  2997. " * see: http://www.burtleburtle.net/bob/",
  2998. " */",
  2999. "",
  3000. "#if defined(HASH64) || defined(WIN64)",
  3001. /* 64-bit Jenkins hash: http://burtleburtle.net/bob/c/lookup8.c */
  3002. "#define mix(a,b,c) \\",
  3003. "{ a -= b; a -= c; a ^= (c>>43); \\",
  3004. " b -= c; b -= a; b ^= (a<<9); \\",
  3005. " c -= a; c -= b; c ^= (b>>8); \\",
  3006. " a -= b; a -= c; a ^= (c>>38); \\",
  3007. " b -= c; b -= a; b ^= (a<<23); \\",
  3008. " c -= a; c -= b; c ^= (b>>5); \\",
  3009. " a -= b; a -= c; a ^= (c>>35); \\",
  3010. " b -= c; b -= a; b ^= (a<<49); \\",
  3011. " c -= a; c -= b; c ^= (b>>11); \\",
  3012. " a -= b; a -= c; a ^= (c>>12); \\",
  3013. " b -= c; b -= a; b ^= (a<<18); \\",
  3014. " c -= a; c -= b; c ^= (b>>22); \\",
  3015. "}",
  3016. "#else",
  3017. "#define mix(a,b,c) \\",
  3018. "{ a -= b; a -= c; a ^= (c>>13); \\",
  3019. " b -= c; b -= a; b ^= (a<<8); \\",
  3020. " c -= a; c -= b; c ^= (b>>13); \\",
  3021. " a -= b; a -= c; a ^= (c>>12); \\",
  3022. " b -= c; b -= a; b ^= (a<<16); \\",
  3023. " c -= a; c -= b; c ^= (b>>5); \\",
  3024. " a -= b; a -= c; a ^= (c>>3); \\",
  3025. " b -= c; b -= a; b ^= (a<<10); \\",
  3026. " c -= a; c -= b; c ^= (b>>15); \\",
  3027. "}",
  3028. "#endif",
  3029. "void",
  3030. "d_hash(uchar *Cp, int Om) /* double bit hash - Jenkins */",
  3031. "{ unsigned long a = 0x9e3779b9, b, c = 0, len, length;",
  3032. " unsigned long *k = (unsigned long *) Cp;",
  3033. "",
  3034. " length = len = (unsigned long) ((unsigned long) Om + WS-1)/WS;",
  3035. "",
  3036. " b = HASH_CONST[HASH_NR];",
  3037. " while (len >= 3)",
  3038. " { a += k[0];",
  3039. " b += k[1];",
  3040. " c += k[2];",
  3041. " mix(a,b,c);",
  3042. " k += 3; len -= 3;",
  3043. " }",
  3044. " c += length;",
  3045. " switch (len) {",
  3046. " case 2: b += k[1];",
  3047. " case 1: a += k[0];",
  3048. " }",
  3049. " mix(a,b,c);",
  3050. " j1 = c&nmask; j3 = a&7;", /* 1st bit */
  3051. " j2 = b&nmask; j4 = (a>>3)&7;", /* 2nd bit */
  3052. " K1 = c; K2 = b;", /* no nmask */
  3053. "}",
  3054. "void",
  3055. "s_hash(uchar *cp, int om)",
  3056. "{ d_hash(cp, om); /* sets K1 and K2 */",
  3057. "#ifdef BITSTATE",
  3058. " if (S_Tab == H_tab)", /* state stack in bitstate search */
  3059. " j1 = K1 %% omaxdepth;",
  3060. " else",
  3061. "#endif", /* if (S_Tab != H_Tab) */
  3062. " if (ssize < 8*WS)",
  3063. " j1 = K1&mask;",
  3064. " else",
  3065. " j1 = K1;",
  3066. "}",
  3067. "#ifndef RANDSTOR",
  3068. "int *prerand;",
  3069. "void",
  3070. "inirand(void)",
  3071. "{ int i;",
  3072. " srand(123); /* fixed startpoint */",
  3073. " prerand = (int *) emalloc((omaxdepth+3)*sizeof(int));",
  3074. " for (i = 0; i < omaxdepth+3; i++)",
  3075. " prerand[i] = rand();",
  3076. "}",
  3077. "int",
  3078. "pan_rand(void)",
  3079. "{ if (!prerand) inirand();",
  3080. " return prerand[depth];",
  3081. "}",
  3082. "#endif",
  3083. "",
  3084. "int",
  3085. "main(int argc, char *argv[])",
  3086. "{ void to_compile(void);\n",
  3087. " efd = stderr; /* default */",
  3088. "#ifdef BITSTATE",
  3089. " bstore = bstore_reg; /* default */",
  3090. "#endif",
  3091. " while (argc > 1 && argv[1][0] == '-')",
  3092. " { switch (argv[1][1]) {",
  3093. "#ifndef SAFETY",
  3094. "#ifdef NP",
  3095. " case 'a': fprintf(efd, \"error: -a disabled\");",
  3096. " usage(efd); break;",
  3097. "#else",
  3098. " case 'a': a_cycles = 1; break;",
  3099. "#endif",
  3100. "#endif",
  3101. " case 'A': noasserts = 1; break;",
  3102. " case 'b': bounded = 1; break;",
  3103. " case 'c': upto = atoi(&argv[1][2]); break;",
  3104. " case 'd': state_tables++; break;",
  3105. " case 'e': every_error = 1; Nr_Trails = 1; break;",
  3106. " case 'E': noends = 1; break;",
  3107. "#ifdef SC",
  3108. " case 'F': if (strlen(argv[1]) > 2)",
  3109. " stackfile = &argv[1][2];",
  3110. " break;",
  3111. "#endif",
  3112. "#if !defined(SAFETY) && !defined(NOFAIR)",
  3113. " case 'f': fairness = 1; break;",
  3114. "#endif",
  3115. " case 'h': if (!argv[1][2]) usage(efd); else",
  3116. " HASH_NR = atoi(&argv[1][2])%%33; break;",
  3117. " case 'I': iterative = 2; every_error = 1; break;",
  3118. " case 'i': iterative = 1; every_error = 1; break;",
  3119. " case 'J': like_java = 1; break; /* Klaus Havelund */",
  3120. "#ifdef BITSTATE",
  3121. " case 'k': hfns = atoi(&argv[1][2]); break;",
  3122. "#endif",
  3123. "#ifndef SAFETY",
  3124. "#ifdef NP",
  3125. " case 'l': a_cycles = 1; break;",
  3126. "#else",
  3127. " case 'l': fprintf(efd, \"error: -l disabled\");",
  3128. " usage(efd); break;",
  3129. "#endif",
  3130. "#endif",
  3131. #ifndef POWOW
  3132. "#ifdef BITSTATE",
  3133. " case 'M': udmem = atoi(&argv[1][2]); break;",
  3134. " case 'G': udmem = atoi(&argv[1][2]); udmem *= 1024; break;",
  3135. "#else",
  3136. " case 'M': case 'G':",
  3137. " fprintf(stderr, \"-M and -G affect only -DBITSTATE\\n\");",
  3138. " break;",
  3139. "#endif",
  3140. #endif
  3141. " case 'm': maxdepth = atoi(&argv[1][2]); break;",
  3142. " case 'n': no_rck = 1; break;",
  3143. "#ifdef SVDUMP",
  3144. " case 'p': vprefix = atoi(&argv[1][2]); break;",
  3145. "#endif",
  3146. " case 'q': strict = 1; break;",
  3147. "#ifdef HAS_CODE",
  3148. " case 'r':",
  3149. "samething: readtrail = 1;",
  3150. " if (isdigit(argv[1][2]))",
  3151. " whichtrail = atoi(&argv[1][2]);",
  3152. " break;",
  3153. " case 'P': readtrail = 1; onlyproc = atoi(&argv[1][2]); break;",
  3154. " case 'C': coltrace = 1; goto samething;",
  3155. " case 'g': gui = 1; goto samething;",
  3156. " case 'S': silent = 1; break;",
  3157. "#endif",
  3158. " case 'R': Nrun = atoi(&argv[1][2]); break;",
  3159. "#ifdef BITSTATE",
  3160. " case 's': hfns = 1; break;",
  3161. "#endif",
  3162. " case 'T': TMODE = 0444; break;",
  3163. " case 't': if (argv[1][2]) tprefix = &argv[1][2]; break;",
  3164. " case 'V': printf(\"Generated by %%s\\n\", Version);",
  3165. " to_compile(); pan_exit(0); break;",
  3166. " case 'v': verbose = 1; break;",
  3167. " case 'w': ssize = atoi(&argv[1][2]); break;",
  3168. " case 'Y': signoff = 1; break;",
  3169. " case 'X': efd = stdout; break;",
  3170. " default : fprintf(efd, \"saw option -%%c\\n\", argv[1][1]); usage(efd); break;",
  3171. " }",
  3172. " argc--; argv++;",
  3173. " }",
  3174. " if (iterative && TMODE != 0666)",
  3175. " { TMODE = 0666;",
  3176. " fprintf(efd, \"warning: -T ignored when -i or -I is used\\n\");",
  3177. " }",
  3178. "#if defined(WIN32) || defined(WIN64)",
  3179. " if (TMODE == 0666)",
  3180. " TMODE = _S_IWRITE | _S_IREAD;",
  3181. " else",
  3182. " TMODE = _S_IREAD;",
  3183. "#endif",
  3184. "#ifdef OHASH",
  3185. " fprintf(efd, \"warning: -DOHASH no longer supported (directive ignored)\\n\");",
  3186. "#endif",
  3187. "#ifdef JHASH",
  3188. " fprintf(efd, \"warning: -DJHASH no longer supported (directive ignored)\\n\");",
  3189. "#endif",
  3190. "#ifdef HYBRID_HASH",
  3191. " fprintf(efd, \"warning: -DHYBRID_HASH no longer supported (directive ignored)\\n\");",
  3192. "#endif",
  3193. "#ifdef NOCOVEST",
  3194. " fprintf(efd, \"warning: -DNOCOVEST no longer supported (directive ignored)\\n\");",
  3195. "#endif",
  3196. "#ifdef BITSTATE",
  3197. "#ifdef BCOMP",
  3198. " fprintf(efd, \"warning: -DBCOMP no longer supported (directive ignored)\\n\");",
  3199. "#endif",
  3200. " if (hfns <= 0)",
  3201. " { hfns = 1;",
  3202. " fprintf(efd, \"warning: using -k%%d as minimal usable value\\n\", hfns);",
  3203. " }",
  3204. "#endif",
  3205. " omaxdepth = maxdepth;",
  3206. "#ifdef BITSTATE",
  3207. " if (WS == 4 && ssize > 34)", /* 32-bit word size */
  3208. " { ssize = 34;",
  3209. " fprintf(efd, \"warning: using -w%%d as max usable value\\n\", ssize);",
  3210. "/*",
  3211. " * -w35 would not work: 35-3 = 32 but 1^31 is the largest",
  3212. " * power of 2 that can be represented in an unsigned long",
  3213. " */",
  3214. " }",
  3215. "#else",
  3216. " if (WS == 4 && ssize > 27)",
  3217. " { ssize = 27;",
  3218. " fprintf(efd, \"warning: using -w%%d as max usable value\\n\", ssize);",
  3219. "/*",
  3220. " * for emalloc, the lookup table size multiplies by 4 for the pointers",
  3221. " * the largest power of 2 that can be represented in a ulong is 1^31",
  3222. " * hence the largest number of lookup table slots is 31-4 = 27",
  3223. " */",
  3224. " }",
  3225. "#endif",
  3226. "#ifdef SC",
  3227. " hiwater = HHH = maxdepth-10;",
  3228. " DDD = HHH/2;",
  3229. " if (!stackfile)",
  3230. " { stackfile = (char *) emalloc(strlen(Source)+4+1);",
  3231. " sprintf(stackfile, \"%%s._s_\", Source);",
  3232. " }",
  3233. " if (iterative)",
  3234. " { fprintf(efd, \"error: cannot use -i or -I with -DSC\\n\");",
  3235. " pan_exit(1);",
  3236. " }",
  3237. "#endif",
  3238. "#if (defined(R_XPT) || defined(W_XPT)) && !defined(MA)",
  3239. " fprintf(efd, \"error: -D?_XPT requires -DMA\\n\");",
  3240. " exit(1);",
  3241. "#endif",
  3242. " if (iterative && a_cycles)",
  3243. " fprintf(efd, \"warning: -i or -I work for safety properties only\\n\");",
  3244. "#ifdef BFS",
  3245. "#if defined(SC)",
  3246. " fprintf(efd, \"error: -DBFS not compatible with -DSC\\n\");",
  3247. " exit(1);",
  3248. "#endif",
  3249. "#if defined(HAS_LAST)",
  3250. " fprintf(efd, \"error: -DBFS not compatible with _last\\n\");",
  3251. " exit(1);",
  3252. "#endif",
  3253. "#if defined(REACH)",
  3254. " fprintf(efd, \"warning: -DREACH redundant when -DBFS is used\\n\");",
  3255. "#endif",
  3256. "#if defined(HAS_STACK)",
  3257. " fprintf(efd, \"error: cannot use UnMatched qualifier on c_track with BFS\\n\");",
  3258. " exit(1);",
  3259. "#endif",
  3260. "#endif",
  3261. "#if defined(MERGED) && defined(PEG)",
  3262. " fprintf(efd, \"error: to allow -DPEG use: spin -o3 -a %%s\\n\", Source);",
  3263. " fprintf(efd, \" to turn off transition merge optimization\\n\");",
  3264. " pan_exit(1);",
  3265. "#endif",
  3266. "#ifdef HC",
  3267. "#ifdef NOCOMP",
  3268. " fprintf(efd, \"error: cannot combine -DHC and -DNOCOMP\\n\");",
  3269. " pan_exit(1);",
  3270. "#endif",
  3271. "#ifdef BITSTATE",
  3272. " fprintf(efd, \"error: cannot combine -DHC and -DBITSTATE\\n\");",
  3273. " pan_exit(1);",
  3274. "#endif",
  3275. "#endif",
  3276. "#if defined(SAFETY) && defined(NP)",
  3277. " fprintf(efd, \"error: cannot combine -DNP and -DSAFETY\\n\");",
  3278. " pan_exit(1);",
  3279. "#endif",
  3280. "#ifdef MA",
  3281. "#ifdef BITSTATE",
  3282. " fprintf(efd, \"error: cannot combine -DMA and -DBITSTATE\\n\");",
  3283. " pan_exit(1);",
  3284. "#endif",
  3285. " if (MA <= 0)",
  3286. " { fprintf(efd, \"usage: -DMA=N with N > 0 and < VECTORSZ\\n\");",
  3287. " pan_exit(1);",
  3288. " }",
  3289. "#endif",
  3290. "#ifdef COLLAPSE",
  3291. "#if defined(BITSTATE)",
  3292. " fprintf(efd, \"error: cannot combine -DBITSTATE and -DCOLLAPSE\\n\");",
  3293. " pan_exit(1);",
  3294. "#endif",
  3295. "#if defined(NOCOMP)",
  3296. " fprintf(efd, \"error: cannot combine -DNOCOMP and -DCOLLAPSE\\n\");",
  3297. " pan_exit(1);",
  3298. "#endif",
  3299. "#endif",
  3300. " if (maxdepth <= 0 || ssize <= 1) usage(efd);",
  3301. "#if SYNC>0 && !defined(NOREDUCE)",
  3302. " if (a_cycles && fairness)",
  3303. " { fprintf(efd, \"error: p.o. reduction not compatible with \");",
  3304. " fprintf(efd, \"fairness (-f) in models\\n\");",
  3305. " fprintf(efd, \" with rendezvous operations: \");",
  3306. " fprintf(efd, \"recompile with -DNOREDUCE\\n\");",
  3307. " pan_exit(1);",
  3308. " }",
  3309. "#endif",
  3310. "#if defined(REM_VARS) && !defined(NOREDUCE)",
  3311. " { fprintf(efd, \"warning: p.o. reduction not compatible with \");",
  3312. " fprintf(efd, \"remote varrefs (use -DNOREDUCE)\\n\");",
  3313. " }",
  3314. "#endif",
  3315. "#if defined(NOCOMP) && !defined(BITSTATE)",
  3316. " if (a_cycles)",
  3317. " { fprintf(efd, \"error: -DNOCOMP voids -l and -a\\n\");",
  3318. " pan_exit(1);",
  3319. " }",
  3320. "#endif",
  3321. "#ifdef MEMLIM", /* MEMLIM setting takes precedence */
  3322. " memlim = (double) MEMLIM * (double) (1<<20); /* size in Mbyte */",
  3323. "#else",
  3324. "#ifdef MEMCNT",
  3325. "#if MEMCNT<31",
  3326. " memlim = (double) (1<<MEMCNT);",
  3327. "#else",
  3328. " memlim = (double) (1<<30);",
  3329. " memlim *= (double) (1<<(MEMCNT-30));",
  3330. "#endif",
  3331. "#endif",
  3332. "#endif",
  3333. "#ifndef BITSTATE",
  3334. " if (Nrun > 1) HASH_NR = Nrun - 1;",
  3335. "#endif",
  3336. " if (Nrun < 1 || Nrun > 32)",
  3337. " { fprintf(efd, \"error: invalid arg for -R\\n\");",
  3338. " usage(efd);",
  3339. " }",
  3340. "#ifndef SAFETY",
  3341. " if (fairness && !a_cycles)",
  3342. " { fprintf(efd, \"error: -f requires -a or -l\\n\");",
  3343. " usage(efd);",
  3344. " }",
  3345. "#if ACCEPT_LAB==0",
  3346. " if (a_cycles)",
  3347. "#ifndef VERI",
  3348. " { fprintf(efd, \"error: no accept labels defined \");",
  3349. " fprintf(efd, \"in model (for option -a)\\n\");",
  3350. " usage(efd);",
  3351. " }",
  3352. "#else",
  3353. " { fprintf(efd, \"warning: no explicit accept labels \");",
  3354. " fprintf(efd, \"defined in model (for -a)\\n\");",
  3355. " }",
  3356. "#endif",
  3357. "#endif",
  3358. "#endif",
  3359. "#if !defined(NOREDUCE)",
  3360. "#if defined(HAS_ENABLED)",
  3361. " fprintf(efd, \"error: reduced search precludes \");",
  3362. " fprintf(efd, \"use of 'enabled()'\\n\");",
  3363. " pan_exit(1);",
  3364. "#endif",
  3365. "#if defined(HAS_PCVALUE)",
  3366. " fprintf(efd, \"error: reduced search precludes \");",
  3367. " fprintf(efd, \"use of 'pcvalue()'\\n\");",
  3368. " pan_exit(1);",
  3369. "#endif",
  3370. "#if defined(HAS_BADELSE)",
  3371. " fprintf(efd, \"error: reduced search precludes \");",
  3372. " fprintf(efd, \"using 'else' combined with i/o stmnts\\n\");",
  3373. " pan_exit(1);",
  3374. "#endif",
  3375. "#if defined(HAS_LAST)",
  3376. " fprintf(efd, \"error: reduced search precludes \");",
  3377. " fprintf(efd, \"use of _last\\n\");",
  3378. " pan_exit(1);",
  3379. "#endif",
  3380. "#endif",
  3381. "#if SYNC>0 && !defined(NOREDUCE)",
  3382. "#ifdef HAS_UNLESS",
  3383. " fprintf(efd, \"warning: use of a rendezvous stmnts in the escape\\n\");",
  3384. " fprintf(efd, \"\tof an unless clause, if present, could make p.o. reduction\\n\");",
  3385. " fprintf(efd, \"\tinvalid (use -DNOREDUCE to avoid this)\\n\");",
  3386. "#ifdef BFS",
  3387. " fprintf(efd, \"\t(this type of rv is also not compatible with -DBFS)\\n\");",
  3388. "#endif",
  3389. "#endif",
  3390. "#endif",
  3391. "#if SYNC>0 && defined(BFS)",
  3392. " fprintf(efd, \"warning: use of rendezvous in BFS mode \");",
  3393. " fprintf(efd, \"does not preserve all invalid endstates\\n\");",
  3394. "#endif",
  3395. "#if !defined(REACH) && !defined(BITSTATE)",
  3396. " if (iterative != 0 && a_cycles == 0)",
  3397. " fprintf(efd, \"warning: -i and -I need -DREACH to work accurately\\n\");",
  3398. "#endif",
  3399. "#if defined(BITSTATE) && defined(REACH)",
  3400. " fprintf(efd, \"warning: -DREACH voided by -DBITSTATE\\n\");",
  3401. "#endif",
  3402. "#if defined(MA) && defined(REACH)",
  3403. " fprintf(efd, \"warning: -DREACH voided by -DMA\\n\");",
  3404. "#endif",
  3405. "#if defined(FULLSTACK) && defined(CNTRSTACK)",
  3406. " fprintf(efd, \"error: cannot combine\");",
  3407. " fprintf(efd, \" -DFULLSTACK and -DCNTRSTACK\\n\");",
  3408. " pan_exit(1);",
  3409. "#endif",
  3410. "#if defined(VERI)",
  3411. "#if ACCEPT_LAB>0",
  3412. "#ifndef BFS",
  3413. " if (!a_cycles",
  3414. "#ifdef HAS_CODE",
  3415. " && !readtrail",
  3416. "#endif",
  3417. " && !state_tables)",
  3418. " { fprintf(efd, \"warning: never claim + accept labels \");",
  3419. " fprintf(efd, \"requires -a flag to fully verify\\n\");",
  3420. " }",
  3421. "#else",
  3422. " if (",
  3423. "#ifdef HAS_CODE",
  3424. " !readtrail",
  3425. "#endif",
  3426. " && !state_tables)",
  3427. " { fprintf(efd, \"warning: verification in BFS mode \");",
  3428. " fprintf(efd, \"is restricted to safety properties\\n\");",
  3429. " }",
  3430. "#endif",
  3431. "#endif",
  3432. "#endif",
  3433. "#ifndef SAFETY",
  3434. " if (!a_cycles",
  3435. "#ifdef HAS_CODE",
  3436. " && !readtrail",
  3437. "#endif",
  3438. " && !state_tables)",
  3439. " { fprintf(efd, \"hint: this search is more efficient \");",
  3440. " fprintf(efd, \"if pan.c is compiled -DSAFETY\\n\");",
  3441. " }",
  3442. "#ifndef NOCOMP",
  3443. " if (!a_cycles)",
  3444. " S_A = 0;",
  3445. " else",
  3446. " { if (!fairness)",
  3447. " S_A = 1; /* _a_t */",
  3448. "#ifndef NOFAIR",
  3449. " else /* _a_t and _cnt[NFAIR] */",
  3450. " S_A = (&(now._cnt[0]) - (uchar *) &now) + NFAIR - 2;",
  3451. " /* -2 because first two uchars in now are masked */",
  3452. "#endif",
  3453. " }",
  3454. "#endif",
  3455. "#endif",
  3456. " signal(SIGINT, stopped);",
  3457. /******************* 4.2.5 ********************/
  3458. " if (WS == 4 && ssize >= 32)",
  3459. " { mask = 0xffffffff;",
  3460. "#ifdef BITSTATE",
  3461. " switch (ssize) {",
  3462. " case 34: nmask = (mask>>1); break;",
  3463. " case 33: nmask = (mask>>2); break;",
  3464. " default: nmask = (mask>>3); break;",
  3465. " }",
  3466. "#else",
  3467. " nmask = mask;",
  3468. "#endif",
  3469. " } else if (WS == 8)",
  3470. " { mask = ((1L<<ssize)-1); /* hash init */",
  3471. "#ifdef BITSTATE",
  3472. " nmask = mask>>3;",
  3473. "#else",
  3474. " nmask = mask;",
  3475. "#endif",
  3476. " } else if (WS != 4)",
  3477. " { fprintf(stderr, \"pan: wordsize %%ld not supported\\n\", WS);",
  3478. " exit(1);",
  3479. " } else /* WS == 4 and ssize < 32 */",
  3480. " { mask = ((1L<<ssize)-1); /* hash init */",
  3481. " nmask = (mask>>3);",
  3482. " }",
  3483. /****************** end **********************/
  3484. "#ifdef BFS",
  3485. " trail = (Trail *) emalloc(6*sizeof(Trail));",
  3486. " trail += 3;",
  3487. "#else",
  3488. " trail = (Trail *) emalloc((maxdepth+3)*sizeof(Trail));",
  3489. " trail++; /* protect trpt-1 refs at depth 0 */",
  3490. "#endif",
  3491. "#ifdef SVDUMP",
  3492. " if (vprefix > 0)",
  3493. " { char nm[64];",
  3494. " sprintf(nm, \"%%s.svd\", Source);",
  3495. " if ((svfd = creat(nm, 0666)) < 0)",
  3496. " { fprintf(efd, \"couldn't create %%s\\n\", nm);",
  3497. " vprefix = 0;",
  3498. " } }",
  3499. "#endif",
  3500. "#ifdef RANDSTOR",
  3501. " srand(123);",
  3502. "#endif",
  3503. "#if SYNC>0 && ASYNC==0",
  3504. " set_recvs();",
  3505. "#endif",
  3506. " run();",
  3507. " done = 1;",
  3508. " wrapup();",
  3509. " return 0;",
  3510. "}", /* end of main() */
  3511. "",
  3512. "void",
  3513. "usage(FILE *fd)",
  3514. "{",
  3515. " fprintf(fd, \"Valid Options are:\\n\");",
  3516. "#ifndef SAFETY",
  3517. "#ifdef NP",
  3518. " fprintf(fd, \"\t-a -> is disabled by -DNP \");",
  3519. " fprintf(fd, \"(-DNP compiles for -l only)\\n\");",
  3520. "#else",
  3521. " fprintf(fd, \"\t-a find acceptance cycles\\n\");",
  3522. "#endif",
  3523. "#else",
  3524. " fprintf(fd, \"\t-a,-l,-f -> are disabled by -DSAFETY\\n\");",
  3525. "#endif",
  3526. " fprintf(fd, \"\t-A ignore assert() violations\\n\");",
  3527. " fprintf(fd, \"\t-b consider it an error to exceed the depth-limit\\n\");",
  3528. " fprintf(fd, \"\t-cN stop at Nth error \");",
  3529. " fprintf(fd, \"(defaults to -c1)\\n\");",
  3530. " fprintf(fd, \"\t-d print state tables and stop\\n\");",
  3531. " fprintf(fd, \"\t-e create trails for all errors\\n\");",
  3532. " fprintf(fd, \"\t-E ignore invalid end states\\n\");",
  3533. "#ifdef SC",
  3534. " fprintf(fd, \"\t-Ffile use 'file' to store disk-stack\\n\");",
  3535. "#endif",
  3536. "#ifndef NOFAIR",
  3537. " fprintf(fd, \"\t-f add weak fairness (to -a or -l)\\n\");",
  3538. "#endif",
  3539. " fprintf(fd, \"\t-hN use different hash-seed N:1..32\\n\");",
  3540. " fprintf(fd, \"\t-i search for shortest path to error\\n\");",
  3541. " fprintf(fd, \"\t-I like -i, but approximate and faster\\n\");",
  3542. " fprintf(fd, \"\t-J reverse eval order of nested unlesses\\n\");",
  3543. "#ifdef BITSTATE",
  3544. " fprintf(fd, \"\t-kN set N bits per state (defaults to 3)\\n\");",
  3545. "#endif",
  3546. "#ifndef SAFETY",
  3547. "#ifdef NP",
  3548. " fprintf(fd, \"\t-l find non-progress cycles\\n\");",
  3549. "#else",
  3550. " fprintf(fd, \"\t-l find non-progress cycles -> \");",
  3551. " fprintf(fd, \"disabled, requires \");",
  3552. " fprintf(fd, \"compilation with -DNP\\n\");",
  3553. "#endif",
  3554. "#endif",
  3555. #ifndef POWOW
  3556. "#ifdef BITSTATE",
  3557. " fprintf(fd, \"\t-MN use N Megabytes for bitstate hash array\\n\");",
  3558. " fprintf(fd, \"\t-GN use N Gigabytes for bitstate hash array\\n\");",
  3559. "#endif",
  3560. #endif
  3561. " fprintf(fd, \"\t-mN max depth N steps (default=10k)\\n\");",
  3562. " fprintf(fd, \"\t-n no listing of unreached states\\n\");",
  3563. "#ifdef SVDUMP",
  3564. " fprintf(fd, \"\t-pN create svfile (save N bytes per state)\\n\");",
  3565. "#endif",
  3566. " fprintf(fd, \"\t-q require empty chans in valid end states\\n\");",
  3567. "#ifdef HAS_CODE",
  3568. " fprintf(fd, \"\t-r read and execute trail - can add -v,-n,-PN,-g,-C\\n\");",
  3569. " fprintf(fd, \"\t-rN read and execute N-th error trail\\n\");",
  3570. " fprintf(fd, \"\t-C read and execute trail - columnated output (can add -v,-n)\\n\");",
  3571. " fprintf(fd, \"\t-PN read and execute trail - restrict trail output to proc N\\n\");",
  3572. " fprintf(fd, \"\t-g read and execute trail + msc gui support\\n\");",
  3573. " fprintf(fd, \"\t-S silent replay: only user defined printfs show\\n\");",
  3574. "#endif",
  3575. "#ifdef BITSTATE",
  3576. " fprintf(fd, \"\t-RN repeat run Nx with N \");",
  3577. " fprintf(fd, \"[1..32] independent hash functions\\n\");",
  3578. " fprintf(fd, \"\t-s same as -k1 (single bit per state)\\n\");",
  3579. "#endif",
  3580. " fprintf(fd, \"\t-T create trail files in read-only mode\\n\");",
  3581. " fprintf(fd, \"\t-tsuf replace .trail with .suf on trailfiles\\n\");",
  3582. " fprintf(fd, \"\t-V print SPIN version number\\n\");",
  3583. " fprintf(fd, \"\t-v verbose -- filenames in unreached state listing\\n\");",
  3584. " fprintf(fd, \"\t-wN hashtable of 2^N entries \");",
  3585. " fprintf(fd, \"(defaults to -w%%d)\\n\", ssize);",
  3586. " exit(1);",
  3587. "}",
  3588. "",
  3589. "char *",
  3590. "Malloc(unsigned long n)",
  3591. "{ char *tmp;",
  3592. "#if defined(MEMCNT) || defined(MEMLIM)",
  3593. " if (memcnt+ (double) n > memlim) goto err;",
  3594. "#endif",
  3595. "#if 1",
  3596. " tmp = (char *) malloc(n);",
  3597. " if (!tmp)",
  3598. "#else",
  3599. /* on linux machines, a large amount of memory is set aside
  3600. * for malloc, whether it is used or not
  3601. * using sbrk would make this memory arena inaccessible
  3602. * the reason for using sbrk was originally to provide a
  3603. * small additional speedup (since this memory is never released)
  3604. */
  3605. " tmp = (char *) sbrk(n);",
  3606. " if (tmp == (char *) -1L)",
  3607. "#endif",
  3608. " {",
  3609. "#if defined(MEMCNT) || defined(MEMLIM)",
  3610. "err:",
  3611. "#endif",
  3612. " printf(\"pan: out of memory\\n\");",
  3613. "#if defined(MEMCNT) || defined(MEMLIM)",
  3614. " printf(\"\t%%g bytes used\\n\", memcnt);",
  3615. " printf(\"\t%%g bytes more needed\\n\", (double) n);",
  3616. " printf(\"\t%%g bytes limit\\n\",",
  3617. " memlim);",
  3618. "#endif",
  3619. "#ifdef COLLAPSE",
  3620. " printf(\"hint: to reduce memory, recompile with\\n\");",
  3621. "#ifndef MA",
  3622. " printf(\" -DMA=%%d # better/slower compression, or\\n\", hmax);",
  3623. "#endif",
  3624. " printf(\" -DBITSTATE # supertrace, approximation\\n\");",
  3625. "#else",
  3626. "#ifndef BITSTATE",
  3627. " printf(\"hint: to reduce memory, recompile with\\n\");",
  3628. "#ifndef HC",
  3629. " printf(\" -DCOLLAPSE # good, fast compression, or\\n\");",
  3630. "#ifndef MA",
  3631. " printf(\" -DMA=%%d # better/slower compression, or\\n\", hmax);",
  3632. "#endif",
  3633. " printf(\" -DHC # hash-compaction, approximation\\n\");",
  3634. "#endif",
  3635. " printf(\" -DBITSTATE # supertrace, approximation\\n\");",
  3636. "#endif",
  3637. "#endif",
  3638. " wrapup();",
  3639. " }",
  3640. " memcnt += (double) n;",
  3641. " return tmp;",
  3642. "}",
  3643. "",
  3644. "#define CHUNK (100*VECTORSZ)",
  3645. "",
  3646. "char *",
  3647. "emalloc(unsigned long n) /* never released or reallocated */",
  3648. "{ char *tmp;",
  3649. " if (n == 0)",
  3650. " return (char *) NULL;",
  3651. " if (n&(sizeof(void *)-1)) /* for proper alignment */",
  3652. " n += sizeof(void *)-(n&(sizeof(void *)-1));",
  3653. " if ((unsigned long) left < n)", /* was: (left < (long)n) */
  3654. " { grow = (n < CHUNK) ? CHUNK : n;",
  3655. #if 1
  3656. " have = Malloc(grow);",
  3657. #else
  3658. " /* gcc's sbrk can give non-aligned result */",
  3659. " grow += sizeof(void *); /* allow realignment */",
  3660. " have = Malloc(grow);",
  3661. " if (((unsigned) have)&(sizeof(void *)-1))",
  3662. " { have += (long) (sizeof(void *) ",
  3663. " - (((unsigned) have)&(sizeof(void *)-1)));",
  3664. " grow -= sizeof(void *);",
  3665. " }",
  3666. #endif
  3667. " fragment += (double) left;",
  3668. " left = grow;",
  3669. " }",
  3670. " tmp = have;",
  3671. " have += (long) n;",
  3672. " left -= (long) n;",
  3673. " memset(tmp, 0, n);",
  3674. " return tmp;",
  3675. "}",
  3676. "void",
  3677. "Uerror(char *str)",
  3678. "{ /* always fatal */",
  3679. " uerror(str);",
  3680. " wrapup();",
  3681. "}\n",
  3682. "#if defined(MA) && !defined(SAFETY)",
  3683. "int",
  3684. "Unwind(void)",
  3685. "{ Trans *t; uchar ot, _m; int tt; short II;",
  3686. "#ifdef VERBOSE",
  3687. " int i;",
  3688. "#endif",
  3689. " uchar oat = now._a_t;",
  3690. " now._a_t &= ~(1|16|32);",
  3691. " memcpy((char *) &comp_now, (char *) &now, vsize);",
  3692. " now._a_t = oat;",
  3693. "Up:",
  3694. "#ifdef SC",
  3695. " trpt = getframe(depth);",
  3696. "#endif",
  3697. "#ifdef VERBOSE",
  3698. " printf(\"%%d State: \", depth);",
  3699. " for (i = 0; i < vsize; i++) printf(\"%%d%%s,\",",
  3700. " ((char *)&now)[i], Mask[i]?\"*\":\"\");",
  3701. " printf(\"\\n\");",
  3702. "#endif",
  3703. "#ifndef NOFAIR",
  3704. " if (trpt->o_pm&128) /* fairness alg */",
  3705. " { now._cnt[now._a_t&1] = trpt->bup.oval;",
  3706. " depth--;",
  3707. "#ifdef SC",
  3708. " trpt = getframe(depth);",
  3709. "#else",
  3710. " trpt--;",
  3711. "#endif",
  3712. " goto Q999;",
  3713. " }",
  3714. "#endif",
  3715. "#ifdef HAS_LAST",
  3716. "#ifdef VERI",
  3717. " { int d; Trail *trl;",
  3718. " now._last = 0;",
  3719. " for (d = 1; d < depth; d++)",
  3720. " { trl = getframe(depth-d); /* was trl = (trpt-d); */",
  3721. " if (trl->pr != 0)",
  3722. " { now._last = trl->pr - BASE;",
  3723. " break;",
  3724. " } } }",
  3725. "#else",
  3726. " now._last = (depth<1)?0:(trpt-1)->pr;",
  3727. "#endif",
  3728. "#endif",
  3729. "#ifdef EVENT_TRACE",
  3730. " now._event = trpt->o_event;",
  3731. "#endif",
  3732. " if ((now._a_t&1) && depth <= A_depth)",
  3733. " { now._a_t &= ~(1|16|32);",
  3734. " if (fairness) now._a_t |= 2; /* ? */",
  3735. " A_depth = 0;",
  3736. " goto CameFromHere; /* checkcycles() */",
  3737. " }",
  3738. " t = trpt->o_t;",
  3739. " ot = trpt->o_ot; II = trpt->pr;",
  3740. " tt = trpt->o_tt; this = pptr(II);",
  3741. " _m = do_reverse(t, II, trpt->o_m);",
  3742. "#ifdef VERBOSE",
  3743. " printf(\"%%3d: proc %%d \", depth, II);",
  3744. " printf(\"reverses %%d, %%d to %%d,\",",
  3745. " t->forw, tt, t->st);",
  3746. " printf(\" %%s [abit=%%d,adepth=%%d,\", ",
  3747. " t->tp, now._a_t, A_depth);",
  3748. " printf(\"tau=%%d,%%d] <unwind>\\n\", ",
  3749. " trpt->tau, (trpt-1)->tau);",
  3750. "#endif",
  3751. " depth--;",
  3752. "#ifdef SC",
  3753. " trpt = getframe(depth);",
  3754. "#else",
  3755. " trpt--;",
  3756. "#endif",
  3757. " /* reached[ot][t->st] = 1; 3.4.13 */",
  3758. " ((P0 *)this)->_p = tt;",
  3759. "#ifndef NOFAIR",
  3760. " if ((trpt->o_pm&32))",
  3761. " {",
  3762. "#ifdef VERI",
  3763. " if (now._cnt[now._a_t&1] == 0)",
  3764. " now._cnt[now._a_t&1] = 1;",
  3765. "#endif",
  3766. " now._cnt[now._a_t&1] += 1;",
  3767. " }",
  3768. "Q999:",
  3769. " if (trpt->o_pm&8)",
  3770. " { now._a_t &= ~2;",
  3771. " now._cnt[now._a_t&1] = 0;",
  3772. " }",
  3773. " if (trpt->o_pm&16)",
  3774. " now._a_t |= 2;",
  3775. "#endif",
  3776. "CameFromHere:",
  3777. " if (memcmp((char *) &now, (char *) &comp_now, vsize) == 0)",
  3778. " return depth;",
  3779. " if (depth > 0) goto Up;",
  3780. " return 0;",
  3781. "}",
  3782. "#endif",
  3783. "static char unwinding;",
  3784. "void",
  3785. "uerror(char *str)",
  3786. "{ static char laststr[256];",
  3787. " int is_cycle;",
  3788. "",
  3789. " if (unwinding) return; /* 1.4.2 */",
  3790. " if (strncmp(str, laststr, 254))",
  3791. " printf(\"pan: %%s (at depth %%ld)\\n\", str,",
  3792. " (depthfound==-1)?depth:depthfound);",
  3793. " strncpy(laststr, str, 254);",
  3794. " errors++;",
  3795. "#ifdef HAS_CODE",
  3796. " if (readtrail) { wrap_trail(); return; }",
  3797. "#endif",
  3798. " is_cycle = (strstr(str, \" cycle\") != (char *) 0);",
  3799. " if (!is_cycle)",
  3800. " { depth++; trpt++;", /* include failed step */
  3801. " }",
  3802. " if ((every_error != 0)",
  3803. " || errors == upto)",
  3804. " {",
  3805. "#if defined(MA) && !defined(SAFETY)",
  3806. " if (is_cycle)",
  3807. " { int od = depth;",
  3808. " unwinding = 1;",
  3809. " depthfound = Unwind();",
  3810. " unwinding = 0;",
  3811. " depth = od;",
  3812. " }",
  3813. "#endif",
  3814. "#ifdef BFS",
  3815. " if (depth > 1) trpt--;",
  3816. " nuerror(str);",
  3817. " if (depth > 1) trpt++;",
  3818. "#else",
  3819. " putrail();",
  3820. "#endif",
  3821. "#if defined(MA) && !defined(SAFETY)",
  3822. " if (strstr(str, \" cycle\"))",
  3823. " { if (every_error)",
  3824. " printf(\"sorry: MA writes 1 trail max\\n\");",
  3825. " wrapup(); /* no recovery from unwind */",
  3826. " }",
  3827. "#endif",
  3828. " }",
  3829. " if (!is_cycle)",
  3830. " { depth--; trpt--; /* undo */",
  3831. " }",
  3832. "#ifndef BFS",
  3833. " if (iterative != 0 && maxdepth > 0)",
  3834. " { maxdepth = (iterative == 1)?(depth-1):(depth/2);",
  3835. " warned = 1;",
  3836. " printf(\"pan: reducing search depth to %%ld\\n\",",
  3837. " maxdepth);",
  3838. " } else",
  3839. "#endif",
  3840. " if (errors >= upto && upto != 0)",
  3841. " wrapup();",
  3842. " depthfound = -1;",
  3843. "}\n",
  3844. "int",
  3845. "xrefsrc(int lno, S_F_MAP *mp, int M, int i)",
  3846. "{ Trans *T; int j, retval=1;",
  3847. " for (T = trans[M][i]; T; T = T->nxt)",
  3848. " if (T && T->tp)",
  3849. " { if (strcmp(T->tp, \".(goto)\") == 0",
  3850. " || strncmp(T->tp, \"goto :\", 6) == 0)",
  3851. " return 1; /* not reported */",
  3852. "",
  3853. " printf(\"\\tline %%d\", lno);",
  3854. " if (verbose)",
  3855. " for (j = 0; j < sizeof(mp); j++)",
  3856. " if (i >= mp[j].from && i <= mp[j].upto)",
  3857. " { printf(\", \\\"%%s\\\"\", mp[j].fnm);",
  3858. " break;",
  3859. " }",
  3860. " printf(\", state %%d\", i);",
  3861. " if (strcmp(T->tp, \"\") != 0)",
  3862. " { char *q;",
  3863. " q = transmognify(T->tp);",
  3864. " printf(\", \\\"%%s\\\"\", q?q:\"\");",
  3865. " } else if (stopstate[M][i])",
  3866. " printf(\", -end state-\");",
  3867. " printf(\"\\n\");",
  3868. " retval = 0; /* reported */",
  3869. " }",
  3870. " return retval;",
  3871. "}\n",
  3872. "void",
  3873. "r_ck(uchar *which, int N, int M, short *src, S_F_MAP *mp)",
  3874. "{ int i, m=0;\n",
  3875. "#ifdef VERI",
  3876. " if (M == VERI && !verbose) return;",
  3877. "#endif",
  3878. " printf(\"unreached in proctype %%s\\n\", procname[M]);",
  3879. " for (i = 1; i < N; i++)",
  3880. #if 0
  3881. " if (which[i] == 0 /* && trans[M][i] */)",
  3882. #else
  3883. " if (which[i] == 0",
  3884. " && (mapstate[M][i] == 0",
  3885. " || which[mapstate[M][i]] == 0))",
  3886. #endif
  3887. " m += xrefsrc((int) src[i], mp, M, i);",
  3888. " else",
  3889. " m++;",
  3890. " printf(\"\t(%%d of %%d states)\\n\", N-1-m, N-1);",
  3891. "}\n",
  3892. "void",
  3893. "putrail(void)",
  3894. "{ int fd; long i, j;",
  3895. " Trail *trl;",
  3896. "#if defined VERI || defined(MERGED)",
  3897. " char snap[64];",
  3898. "#endif",
  3899. "",
  3900. " fd = make_trail();",
  3901. " if (fd < 0) return;",
  3902. "#ifdef VERI",
  3903. " sprintf(snap, \"-2:%%d:-2\\n\", VERI);",
  3904. " write(fd, snap, strlen(snap));",
  3905. "#endif",
  3906. "#ifdef MERGED",
  3907. " sprintf(snap, \"-4:-4:-4\\n\");",
  3908. " write(fd, snap, strlen(snap));",
  3909. "#endif",
  3910. " for (i = 1; i <= depth; i++)",
  3911. " { if (i == depthfound+1)",
  3912. " write(fd, \"-1:-1:-1\\n\", 9);",
  3913. " trl = getframe(i);",
  3914. " if (!trl->o_t) continue;",
  3915. " if (trl->o_pm&128) continue;",
  3916. " sprintf(snap, \"%%ld:%%d:%%d\\n\", ",
  3917. " i, trl->pr, trl->o_t->t_id);",
  3918. " j = strlen(snap);",
  3919. " if (write(fd, snap, j) != j)",
  3920. " { printf(\"pan: error writing trailfile\\n\");",
  3921. " close(fd);",
  3922. " wrapup();",
  3923. " }",
  3924. " }",
  3925. " close(fd);",
  3926. "}\n",
  3927. "void",
  3928. "sv_save(void) /* push state vector onto save stack */",
  3929. "{ if (!svtack->nxt)",
  3930. " { svtack->nxt = (Svtack *) emalloc(sizeof(Svtack));",
  3931. " svtack->nxt->body = emalloc(vsize*sizeof(char));",
  3932. " svtack->nxt->lst = svtack;",
  3933. " svtack->nxt->m_delta = vsize;",
  3934. " svmax++;",
  3935. " } else if (vsize > svtack->nxt->m_delta)",
  3936. " { svtack->nxt->body = emalloc(vsize*sizeof(char));",
  3937. " svtack->nxt->lst = svtack;",
  3938. " svtack->nxt->m_delta = vsize;",
  3939. " svmax++;",
  3940. " }",
  3941. " svtack = svtack->nxt;",
  3942. "#if SYNC",
  3943. " svtack->o_boq = boq;",
  3944. "#endif",
  3945. " svtack->o_delta = vsize; /* don't compress */",
  3946. " memcpy((char *)(svtack->body), (char *) &now, vsize);",
  3947. "#if defined(C_States) && defined(HAS_STACK) && (HAS_TRACK==1)",
  3948. " c_stack((uchar *) &(svtack->c_stack[0]));",
  3949. "#endif",
  3950. "#ifdef DEBUG",
  3951. " printf(\"%%d: sv_save\\n\", depth);",
  3952. "#endif",
  3953. "}\n",
  3954. "void",
  3955. "sv_restor(void) /* pop state vector from save stack */",
  3956. "{",
  3957. " memcpy((char *)&now, svtack->body, svtack->o_delta);",
  3958. "#if SYNC",
  3959. " boq = svtack->o_boq;",
  3960. "#endif",
  3961. "#if defined(C_States) && (HAS_TRACK==1)",
  3962. "#ifdef HAS_STACK",
  3963. " c_unstack((uchar *) &(svtack->c_stack[0]));",
  3964. "#endif",
  3965. " c_revert((uchar *) &(now.c_state[0]));",
  3966. "#endif",
  3967. " if (vsize != svtack->o_delta)",
  3968. " Uerror(\"sv_restor\");",
  3969. " if (!svtack->lst)",
  3970. " Uerror(\"error: v_restor\");",
  3971. " svtack = svtack->lst;",
  3972. "#ifdef DEBUG",
  3973. " printf(\" sv_restor\\n\");",
  3974. "#endif",
  3975. "}\n",
  3976. "void",
  3977. "p_restor(int h)",
  3978. "{ int i; char *z = (char *) &now;\n",
  3979. " proc_offset[h] = stack->o_offset;",
  3980. " proc_skip[h] = (uchar) stack->o_skip;",
  3981. "#ifndef XUSAFE",
  3982. " p_name[h] = stack->o_name;",
  3983. "#endif",
  3984. "#ifndef NOCOMP",
  3985. " for (i = vsize + stack->o_skip; i > vsize; i--)",
  3986. " Mask[i-1] = 1; /* align */",
  3987. "#endif",
  3988. " vsize += stack->o_skip;",
  3989. " memcpy(z+vsize, stack->body, stack->o_delta);",
  3990. " vsize += stack->o_delta;",
  3991. "#ifndef NOVSZ",
  3992. " now._vsz = vsize;",
  3993. "#endif",
  3994. "#ifndef NOCOMP",
  3995. " for (i = 1; i <= Air[((P0 *)pptr(h))->_t]; i++)",
  3996. " Mask[vsize - i] = 1; /* pad */",
  3997. " Mask[proc_offset[h]] = 1; /* _pid */",
  3998. "#endif",
  3999. " if (BASE > 0 && h > 0)",
  4000. " ((P0 *)pptr(h))->_pid = h-BASE;",
  4001. " else",
  4002. " ((P0 *)pptr(h))->_pid = h;",
  4003. " i = stack->o_delqs;",
  4004. " now._nr_pr += 1;",
  4005. " if (!stack->lst) /* debugging */",
  4006. " Uerror(\"error: p_restor\");",
  4007. " stack = stack->lst;",
  4008. " this = pptr(h);",
  4009. " while (i-- > 0)",
  4010. " q_restor();",
  4011. "}\n",
  4012. "void",
  4013. "q_restor(void)",
  4014. "{ char *z = (char *) &now;",
  4015. "#ifndef NOCOMP",
  4016. " int k, k_end;",
  4017. "#endif",
  4018. " q_offset[now._nr_qs] = stack->o_offset;",
  4019. " q_skip[now._nr_qs] = (uchar) stack->o_skip;",
  4020. "#ifndef XUSAFE",
  4021. " q_name[now._nr_qs] = stack->o_name;",
  4022. "#endif",
  4023. " vsize += stack->o_skip;",
  4024. " memcpy(z+vsize, stack->body, stack->o_delta);",
  4025. " vsize += stack->o_delta;",
  4026. "#ifndef NOVSZ",
  4027. " now._vsz = vsize;",
  4028. "#endif",
  4029. " now._nr_qs += 1;",
  4030. "#ifndef NOCOMP",
  4031. " k_end = stack->o_offset;",
  4032. " k = k_end - stack->o_skip;",
  4033. "#if SYNC",
  4034. "#ifndef BFS",
  4035. " if (q_zero(now._nr_qs)) k_end += stack->o_delta;",
  4036. "#endif",
  4037. "#endif",
  4038. " for ( ; k < k_end; k++)",
  4039. " Mask[k] = 1;",
  4040. "#endif",
  4041. " if (!stack->lst) /* debugging */",
  4042. " Uerror(\"error: q_restor\");",
  4043. " stack = stack->lst;",
  4044. "}",
  4045. "typedef struct IntChunks {",
  4046. " int *ptr;",
  4047. " struct IntChunks *nxt;",
  4048. "} IntChunks;",
  4049. "IntChunks *filled_chunks[512];",
  4050. "IntChunks *empty_chunks[512];",
  4051. "int *",
  4052. "grab_ints(int nr)",
  4053. "{ IntChunks *z;",
  4054. " if (nr >= 512) Uerror(\"cannot happen grab_int\");",
  4055. " if (filled_chunks[nr])",
  4056. " { z = filled_chunks[nr];",
  4057. " filled_chunks[nr] = filled_chunks[nr]->nxt;",
  4058. " } else ",
  4059. " { z = (IntChunks *) emalloc(sizeof(IntChunks));",
  4060. " z->ptr = (int *) emalloc(nr * sizeof(int));",
  4061. " }",
  4062. " z->nxt = empty_chunks[nr];",
  4063. " empty_chunks[nr] = z;",
  4064. " return z->ptr;",
  4065. "}",
  4066. "void",
  4067. "ungrab_ints(int *p, int nr)",
  4068. "{ IntChunks *z;",
  4069. " if (!empty_chunks[nr]) Uerror(\"cannot happen ungrab_int\");",
  4070. " z = empty_chunks[nr];",
  4071. " empty_chunks[nr] = empty_chunks[nr]->nxt;",
  4072. " z->ptr = p;",
  4073. " z->nxt = filled_chunks[nr];",
  4074. " filled_chunks[nr] = z;",
  4075. "}",
  4076. "int",
  4077. "delproc(int sav, int h)",
  4078. "{ int d, i=0;",
  4079. "#ifndef NOCOMP",
  4080. " int o_vsize = vsize;",
  4081. "#endif",
  4082. " if (h+1 != (int) now._nr_pr) return 0;\n",
  4083. " while (now._nr_qs",
  4084. " && q_offset[now._nr_qs-1] > proc_offset[h])",
  4085. " { delq(sav);",
  4086. " i++;",
  4087. " }",
  4088. " d = vsize - proc_offset[h];",
  4089. " if (sav)",
  4090. " { if (!stack->nxt)",
  4091. " { stack->nxt = (Stack *)",
  4092. " emalloc(sizeof(Stack));",
  4093. " stack->nxt->body = ",
  4094. " emalloc(Maxbody*sizeof(char));",
  4095. " stack->nxt->lst = stack;",
  4096. " smax++;",
  4097. " }",
  4098. " stack = stack->nxt;",
  4099. " stack->o_offset = proc_offset[h];",
  4100. "#if VECTORSZ>32000",
  4101. " stack->o_skip = (int) proc_skip[h];",
  4102. "#else",
  4103. " stack->o_skip = (short) proc_skip[h];",
  4104. "#endif",
  4105. "#ifndef XUSAFE",
  4106. " stack->o_name = p_name[h];",
  4107. "#endif",
  4108. " stack->o_delta = d;",
  4109. " stack->o_delqs = i;",
  4110. " memcpy(stack->body, (char *)pptr(h), d);",
  4111. " }",
  4112. " vsize = proc_offset[h];",
  4113. " now._nr_pr = now._nr_pr - 1;",
  4114. " memset((char *)pptr(h), 0, d);",
  4115. " vsize -= (int) proc_skip[h];",
  4116. "#ifndef NOVSZ",
  4117. " now._vsz = vsize;",
  4118. "#endif",
  4119. "#ifndef NOCOMP",
  4120. " for (i = vsize; i < o_vsize; i++)",
  4121. " Mask[i] = 0; /* reset */",
  4122. "#endif",
  4123. " return 1;",
  4124. "}\n",
  4125. "void",
  4126. "delq(int sav)",
  4127. "{ int h = now._nr_qs - 1;",
  4128. " int d = vsize - q_offset[now._nr_qs - 1];",
  4129. "#ifndef NOCOMP",
  4130. " int k, o_vsize = vsize;",
  4131. "#endif",
  4132. " if (sav)",
  4133. " { if (!stack->nxt)",
  4134. " { stack->nxt = (Stack *)",
  4135. " emalloc(sizeof(Stack));",
  4136. " stack->nxt->body = ",
  4137. " emalloc(Maxbody*sizeof(char));",
  4138. " stack->nxt->lst = stack;",
  4139. " smax++;",
  4140. " }",
  4141. " stack = stack->nxt;",
  4142. " stack->o_offset = q_offset[h];",
  4143. "#if VECTORSZ>32000",
  4144. " stack->o_skip = (int) q_skip[h];",
  4145. "#else",
  4146. " stack->o_skip = (short) q_skip[h];",
  4147. "#endif",
  4148. "#ifndef XUSAFE",
  4149. " stack->o_name = q_name[h];",
  4150. "#endif",
  4151. " stack->o_delta = d;",
  4152. " memcpy(stack->body, (char *)qptr(h), d);",
  4153. " }",
  4154. " vsize = q_offset[h];",
  4155. " now._nr_qs = now._nr_qs - 1;",
  4156. " memset((char *)qptr(h), 0, d);",
  4157. " vsize -= (int) q_skip[h];",
  4158. "#ifndef NOVSZ",
  4159. " now._vsz = vsize;",
  4160. "#endif",
  4161. "#ifndef NOCOMP",
  4162. " for (k = vsize; k < o_vsize; k++)",
  4163. " Mask[k] = 0; /* reset */",
  4164. "#endif",
  4165. "}\n",
  4166. "int",
  4167. "qs_empty(void)",
  4168. "{ int i;",
  4169. " for (i = 0; i < (int) now._nr_qs; i++)",
  4170. " { if (q_sz(i) > 0)",
  4171. " return 0;",
  4172. " }",
  4173. " return 1;",
  4174. "}\n",
  4175. "int",
  4176. "endstate(void)",
  4177. "{ int i; P0 *ptr;",
  4178. " for (i = BASE; i < (int) now._nr_pr; i++)",
  4179. " { ptr = (P0 *) pptr(i);",
  4180. " if (!stopstate[ptr->_t][ptr->_p])",
  4181. " return 0;",
  4182. " }",
  4183. " if (strict) return qs_empty();",
  4184. "#if defined(EVENT_TRACE) && !defined(OTIM)",
  4185. " if (!stopstate[EVENT_TRACE][now._event] && !a_cycles)",
  4186. " { printf(\"pan: event_trace not completed\\n\");",
  4187. " return 0;",
  4188. " }",
  4189. "#endif",
  4190. " return 1;",
  4191. "}\n",
  4192. "#ifndef SAFETY",
  4193. "void",
  4194. "checkcycles(void)",
  4195. "{ uchar o_a_t = now._a_t;",
  4196. "#ifndef NOFAIR",
  4197. " uchar o_cnt = now._cnt[1];",
  4198. "#endif",
  4199. "#ifdef FULLSTACK",
  4200. "#ifndef MA",
  4201. " struct H_el *sv = trpt->ostate; /* save */",
  4202. "#else",
  4203. " uchar prov = trpt->proviso; /* save */",
  4204. "#endif",
  4205. "#endif",
  4206. "#ifdef DEBUG",
  4207. " { int i; uchar *v = (uchar *) &now;",
  4208. " printf(\" set Seed state \");",
  4209. "#ifndef NOFAIR",
  4210. " if (fairness) printf(\"(cnt = %%d:%%d, nrpr=%%d) \",",
  4211. " now._cnt[0], now._cnt[1], now._nr_pr);",
  4212. "#endif",
  4213. " /* for (i = 0; i < n; i++) printf(\"%%d,\", v[i]); */",
  4214. " printf(\"\\n\");",
  4215. " }",
  4216. " printf(\"%%d: cycle check starts\\n\", depth);",
  4217. "#endif",
  4218. " now._a_t |= (1|16|32);",
  4219. " /* 1 = 2nd DFS; (16|32) to help hasher */",
  4220. "#ifndef NOFAIR",
  4221. #if 0
  4222. " if (fairness)",
  4223. " { now._a_t &= ~2; /* pre-apply Rule 3 */",
  4224. " now._cnt[1] = 0;", /* reset both a-bit and cnt=0 */
  4225. " /* avoid matching seed on claim stutter on this state */",
  4226. " }",
  4227. #else
  4228. " now._cnt[1] = now._cnt[0];",
  4229. #endif
  4230. "#endif",
  4231. " memcpy((char *)&A_Root, (char *)&now, vsize);",
  4232. " A_depth = depthfound = depth;",
  4233. " new_state(); /* start 2nd DFS */",
  4234. " now._a_t = o_a_t;",
  4235. "#ifndef NOFAIR",
  4236. " now._cnt[1] = o_cnt;",
  4237. "#endif",
  4238. " A_depth = 0; depthfound = -1;",
  4239. "#ifdef DEBUG",
  4240. " printf(\"%%d: cycle check returns\\n\", depth);",
  4241. "#endif",
  4242. "#ifdef FULLSTACK",
  4243. "#ifndef MA",
  4244. " trpt->ostate = sv; /* restore */",
  4245. "#else",
  4246. " trpt->proviso = prov;",
  4247. "#endif",
  4248. "#endif",
  4249. "}",
  4250. "#endif\n",
  4251. "#if defined(FULLSTACK) && defined(BITSTATE)",
  4252. "struct H_el *Free_list = (struct H_el *) 0;",
  4253. "void",
  4254. "onstack_init(void) /* to store stack states in a bitstate search */",
  4255. "{ S_Tab = (struct H_el **) emalloc(maxdepth*sizeof(struct H_el *));",
  4256. "}",
  4257. "struct H_el *",
  4258. "grab_state(int n)",
  4259. "{ struct H_el *v, *last = 0;",
  4260. " if (H_tab == S_Tab)",
  4261. " { for (v = Free_list; v && ((int) v->tagged >= n); v=v->nxt)",
  4262. " { if ((int) v->tagged == n)",
  4263. " { if (last)",
  4264. " last->nxt = v->nxt;",
  4265. " else",
  4266. "gotcha: Free_list = v->nxt;",
  4267. " v->tagged = 0;",
  4268. " v->nxt = 0;",
  4269. "#ifdef COLLAPSE",
  4270. " v->ln = 0;",
  4271. "#endif",
  4272. " return v;",
  4273. " }",
  4274. " Fh++; last=v;",
  4275. " }",
  4276. " /* new: second try */",
  4277. " v = Free_list;", /* try to avoid emalloc */
  4278. " if (v && ((int) v->tagged >= n))",
  4279. " goto gotcha;",
  4280. " ngrabs++;",
  4281. " }",
  4282. " return (struct H_el *)",
  4283. " emalloc(sizeof(struct H_el)+n-sizeof(unsigned));",
  4284. "}\n",
  4285. "#else",
  4286. "#define grab_state(n) (struct H_el *) \\",
  4287. " emalloc(sizeof(struct H_el)+n-sizeof(unsigned));",
  4288. "#endif",
  4289. "#ifdef COLLAPSE",
  4290. "unsigned long",
  4291. "ordinal(char *v, long n, short tp)",
  4292. "{ struct H_el *tmp, *ntmp; long m;",
  4293. " struct H_el *olst = (struct H_el *) 0;",
  4294. " s_hash((uchar *)v, n);",
  4295. " tmp = H_tab[j1];",
  4296. " if (!tmp)",
  4297. " { tmp = grab_state(n);",
  4298. " H_tab[j1] = tmp;",
  4299. " } else",
  4300. " for ( ;; olst = tmp, tmp = tmp->nxt)",
  4301. " { m = memcmp(((char *)&(tmp->state)), v, n);",
  4302. " if (n == tmp->ln)",
  4303. " {",
  4304. " if (m == 0)",
  4305. " goto done;",
  4306. " if (m < 0)",
  4307. " {",
  4308. "Insert: ntmp = grab_state(n);",
  4309. " ntmp->nxt = tmp;",
  4310. " if (!olst)",
  4311. " H_tab[j1] = ntmp;",
  4312. " else",
  4313. " olst->nxt = ntmp;",
  4314. " tmp = ntmp;",
  4315. " break;",
  4316. " } else if (!tmp->nxt)",
  4317. " {",
  4318. "Append: tmp->nxt = grab_state(n);",
  4319. " tmp = tmp->nxt;",
  4320. " break;",
  4321. " }",
  4322. " continue;",
  4323. " }",
  4324. " if (n < tmp->ln)",
  4325. " goto Insert;",
  4326. " else if (!tmp->nxt)",
  4327. " goto Append;",
  4328. " }",
  4329. " m = ++ncomps[tp];",
  4330. "#ifdef FULLSTACK",
  4331. " tmp->tagged = m;",
  4332. "#else",
  4333. " tmp->st_id = m;",
  4334. "#endif",
  4335. " memcpy(((char *)&(tmp->state)), v, n);",
  4336. " tmp->ln = n;",
  4337. "done:",
  4338. "#ifdef FULLSTACK",
  4339. " return tmp->tagged;",
  4340. "#else",
  4341. " return tmp->st_id;",
  4342. "#endif",
  4343. "}",
  4344. "",
  4345. "int",
  4346. "compress(char *vin, int nin) /* collapse compression */",
  4347. "{ char *w, *v = (char *) &comp_now;",
  4348. " int i, j;",
  4349. " unsigned long n;",
  4350. " static char *x;",
  4351. " static uchar nbytes[513]; /* 1 + 256 + 256 */",
  4352. " static unsigned short nbytelen;",
  4353. " long col_q(int, char *);",
  4354. " long col_p(int, char *);",
  4355. "#ifndef SAFETY",
  4356. " if (a_cycles)",
  4357. " *v++ = now._a_t;",
  4358. "#ifndef NOFAIR",
  4359. " if (fairness)",
  4360. " for (i = 0; i < NFAIR; i++)",
  4361. " *v++ = now._cnt[i];",
  4362. "#endif",
  4363. "#endif",
  4364. " nbytelen = 0;",
  4365. "#ifndef JOINPROCS",
  4366. " for (i = 0; i < (int) now._nr_pr; i++)",
  4367. " { n = col_p(i, (char *) 0);",
  4368. "#ifdef NOFIX",
  4369. " nbytes[nbytelen] = 0;",
  4370. "#else",
  4371. " nbytes[nbytelen] = 1;",
  4372. " *v++ = ((P0 *) pptr(i))->_t;",
  4373. "#endif",
  4374. " *v++ = n&255;",
  4375. " if (n >= (1<<8))",
  4376. " { nbytes[nbytelen]++;",
  4377. " *v++ = (n>>8)&255;",
  4378. " }",
  4379. " if (n >= (1<<16))",
  4380. " { nbytes[nbytelen]++;",
  4381. " *v++ = (n>>16)&255;",
  4382. " }",
  4383. " if (n >= (1<<24))",
  4384. " { nbytes[nbytelen]++;",
  4385. " *v++ = (n>>24)&255;",
  4386. " }",
  4387. " nbytelen++;",
  4388. " }",
  4389. "#else",
  4390. " x = scratch;",
  4391. " for (i = 0; i < (int) now._nr_pr; i++)",
  4392. " x += col_p(i, x);",
  4393. " n = ordinal(scratch, x-scratch, 2); /* procs */",
  4394. " *v++ = n&255;",
  4395. " nbytes[nbytelen] = 0;",
  4396. " if (n >= (1<<8))",
  4397. " { nbytes[nbytelen]++;",
  4398. " *v++ = (n>>8)&255;",
  4399. " }",
  4400. " if (n >= (1<<16))",
  4401. " { nbytes[nbytelen]++;",
  4402. " *v++ = (n>>16)&255;",
  4403. " }",
  4404. " if (n >= (1<<24))",
  4405. " { nbytes[nbytelen]++;",
  4406. " *v++ = (n>>24)&255;",
  4407. " }",
  4408. " nbytelen++;",
  4409. "#endif",
  4410. "#ifdef SEPQS",
  4411. " for (i = 0; i < (int) now._nr_qs; i++)",
  4412. " { n = col_q(i, (char *) 0);",
  4413. " nbytes[nbytelen] = 0;",
  4414. " *v++ = n&255;",
  4415. " if (n >= (1<<8))",
  4416. " { nbytes[nbytelen]++;",
  4417. " *v++ = (n>>8)&255;",
  4418. " }",
  4419. " if (n >= (1<<16))",
  4420. " { nbytes[nbytelen]++;",
  4421. " *v++ = (n>>16)&255;",
  4422. " }",
  4423. " if (n >= (1<<24))",
  4424. " { nbytes[nbytelen]++;",
  4425. " *v++ = (n>>24)&255;",
  4426. " }",
  4427. " nbytelen++;",
  4428. " }",
  4429. "#endif",
  4430. "#ifdef NOVSZ",
  4431. " /* 3 = _a_t, _nr_pr, _nr_qs */",
  4432. " w = (char *) &now + 3 * sizeof(uchar);",
  4433. "#ifndef NOFAIR",
  4434. " w += NFAIR;",
  4435. "#endif",
  4436. "#else",
  4437. "#if VECTORSZ<65536",
  4438. " w = (char *) &(now._vsz) + sizeof(unsigned short);",
  4439. "#else",
  4440. " w = (char *) &(now._vsz) + sizeof(unsigned long);",
  4441. "#endif",
  4442. "#endif",
  4443. " x = scratch;",
  4444. " *x++ = now._nr_pr;",
  4445. " *x++ = now._nr_qs;",
  4446. " if (now._nr_qs > 0 && qptr(0) < pptr(0))",
  4447. " n = qptr(0) - (uchar *) w;",
  4448. " else",
  4449. " n = pptr(0) - (uchar *) w;",
  4450. " j = w - (char *) &now;",
  4451. " for (i = 0; i < (int) n; i++, w++)",
  4452. " if (!Mask[j++]) *x++ = *w;",
  4453. "#ifndef SEPQS",
  4454. " for (i = 0; i < (int) now._nr_qs; i++)",
  4455. " x += col_q(i, x);",
  4456. "#endif",
  4457. " x--;",
  4458. " for (i = 0, j = 6; i < nbytelen; i++)",
  4459. " { if (j == 6)",
  4460. " { j = 0;",
  4461. " *(++x) = 0;",
  4462. " } else",
  4463. " j += 2;",
  4464. " *x |= (nbytes[i] << j);",
  4465. " }",
  4466. " x++;",
  4467. " for (j = 0; j < WS-1; j++)",
  4468. " *x++ = 0;",
  4469. " x -= j; j = 0;",
  4470. " n = ordinal(scratch, x-scratch, 0); /* globals */",
  4471. " *v++ = n&255;",
  4472. " if (n >= (1<< 8)) { *v++ = (n>> 8)&255; j++; }",
  4473. " if (n >= (1<<16)) { *v++ = (n>>16)&255; j++; }",
  4474. " if (n >= (1<<24)) { *v++ = (n>>24)&255; j++; }",
  4475. " *v++ = j; /* add last count as a byte */",
  4476. " for (i = 0; i < WS-1; i++)",
  4477. " *v++ = 0;",
  4478. " v -= i;",
  4479. "#if 0",
  4480. " printf(\"collapse %%d -> %%d\\n\",",
  4481. " vsize, v - (char *)&comp_now);",
  4482. "#endif",
  4483. " return v - (char *)&comp_now;",
  4484. "}",
  4485. "#else",
  4486. "#if !defined(NOCOMP)",
  4487. "int",
  4488. "compress(char *vin, int n) /* default compression */",
  4489. "{",
  4490. "#ifdef HC",
  4491. " int delta = 0;",
  4492. " s_hash((uchar *)vin, n); /* sets K1 and K2 */",
  4493. "#ifndef SAFETY",
  4494. " if (S_A)",
  4495. " { delta++; /* _a_t */",
  4496. "#ifndef NOFAIR",
  4497. " if (S_A > NFAIR)",
  4498. " delta += NFAIR; /* _cnt[] */",
  4499. "#endif",
  4500. " }",
  4501. "#endif",
  4502. " memcpy((char *) &comp_now + delta, (char *) &K1, WS);",
  4503. " delta += WS;",
  4504. "#if HC>0",
  4505. " memcpy((char *) &comp_now + delta, (char *) &K2, HC);",
  4506. " delta += HC;",
  4507. "#endif",
  4508. " return delta;",
  4509. "#else",
  4510. " char *vv = vin;",
  4511. " char *v = (char *) &comp_now;",
  4512. " int i;",
  4513. " for (i = 0; i < n; i++, vv++)",
  4514. " if (!Mask[i]) *v++ = *vv;",
  4515. " for (i = 0; i < WS-1; i++)",
  4516. " *v++ = 0;",
  4517. " v -= i;",
  4518. "#if 0",
  4519. " printf(\"compress %%d -> %%d\\n\",",
  4520. " n, v - (char *)&comp_now);",
  4521. "#endif",
  4522. " return v - (char *)&comp_now;",
  4523. "#endif",
  4524. "}",
  4525. "#endif",
  4526. "#endif",
  4527. "#if defined(FULLSTACK) && defined(BITSTATE)",
  4528. "#if defined(MA)",
  4529. "#if !defined(onstack_now)",
  4530. "int onstack_now(void) {}", /* to suppress compiler errors */
  4531. "#endif",
  4532. "#if !defined(onstack_put)",
  4533. "void onstack_put(void) {}", /* for this invalid combination */
  4534. "#endif",
  4535. "#if !defined(onstack_zap)",
  4536. "void onstack_zap(void) {}", /* of directives */
  4537. "#endif",
  4538. "#else",
  4539. "void",
  4540. "onstack_zap(void)",
  4541. "{ struct H_el *v, *w, *last = 0;",
  4542. " struct H_el **tmp = H_tab;",
  4543. " char *nv; int n, m;\n",
  4544. " H_tab = S_Tab;",
  4545. "#ifndef NOCOMP",
  4546. " nv = (char *) &comp_now;",
  4547. " n = compress((char *)&now, vsize);",
  4548. "#else",
  4549. "#if defined(BITSTATE) && defined(LC)",
  4550. " nv = (char *) &comp_now;",
  4551. " n = compact_stack((char *)&now, vsize);",
  4552. "#else",
  4553. " nv = (char *) &now;",
  4554. " n = vsize;",
  4555. "#endif",
  4556. "#endif",
  4557. "#if !defined(HC) && !(defined(BITSTATE) && defined(LC))",
  4558. " s_hash((uchar *)nv, n);",
  4559. "#endif",
  4560. " H_tab = tmp;",
  4561. " for (v = S_Tab[j1]; v; Zh++, last=v, v=v->nxt)",
  4562. " { m = memcmp(&(v->state), nv, n);",
  4563. " if (m == 0)",
  4564. " goto Found;",
  4565. " if (m < 0)",
  4566. " break;",
  4567. " }",
  4568. "/* NotFound: */",
  4569. " Uerror(\"stack out of wack - zap\");",
  4570. " return;",
  4571. "Found:",
  4572. " ZAPS++;",
  4573. " if (last)",
  4574. " last->nxt = v->nxt;",
  4575. " else",
  4576. " S_Tab[j1] = v->nxt;",
  4577. " v->tagged = (unsigned) n;",
  4578. "#if !defined(NOREDUCE) && !defined(SAFETY)",
  4579. " v->proviso = 0;",
  4580. "#endif",
  4581. " v->nxt = last = (struct H_el *) 0;",
  4582. " for (w = Free_list; w; Fa++, last=w, w = w->nxt)",
  4583. " { if ((int) w->tagged <= n)",
  4584. " { if (last)",
  4585. " { v->nxt = w; /* was: v->nxt = w->nxt; */",
  4586. " last->nxt = v;",
  4587. " } else",
  4588. " { v->nxt = Free_list;",
  4589. " Free_list = v;",
  4590. " }",
  4591. " return;",
  4592. " }",
  4593. " if (!w->nxt)",
  4594. " { w->nxt = v;",
  4595. " return;",
  4596. " } }",
  4597. " Free_list = v;",
  4598. "}",
  4599. "void",
  4600. "onstack_put(void)",
  4601. "{ struct H_el **tmp = H_tab;",
  4602. " H_tab = S_Tab;",
  4603. " if (hstore((char *)&now, vsize) != 0)",
  4604. "#if defined(BITSTATE) && defined(LC)",
  4605. " printf(\"pan: warning, double stack entry\\n\");",
  4606. "#else",
  4607. " Uerror(\"cannot happen - unstack_put\");",
  4608. "#endif",
  4609. " H_tab = tmp;",
  4610. " trpt->ostate = Lstate;",
  4611. " PUT++;",
  4612. "}",
  4613. "int",
  4614. "onstack_now(void)",
  4615. "{ struct H_el *tmp;",
  4616. " struct H_el **tmp2 = H_tab;",
  4617. " char *v; int n, m = 1;\n",
  4618. " H_tab = S_Tab;",
  4619. "#ifdef NOCOMP",
  4620. "#if defined(BITSTATE) && defined(LC)",
  4621. " v = (char *) &comp_now;",
  4622. " n = compact_stack((char *)&now, vsize);",
  4623. "#else",
  4624. " v = (char *) &now;",
  4625. " n = vsize;",
  4626. "#endif",
  4627. "#else",
  4628. " v = (char *) &comp_now;",
  4629. " n = compress((char *)&now, vsize);",
  4630. "#endif",
  4631. "#if !defined(HC) && !(defined(BITSTATE) && defined(LC))",
  4632. " s_hash((uchar *)v, n);",
  4633. "#endif",
  4634. " H_tab = tmp2;",
  4635. " for (tmp = S_Tab[j1]; tmp; Zn++, tmp = tmp->nxt)",
  4636. " { m = memcmp(((char *)&(tmp->state)),v,n);",
  4637. " if (m <= 0)",
  4638. " { Lstate = (struct H_el *) tmp;",
  4639. " break;",
  4640. " } }",
  4641. " PROBE++;",
  4642. " return (m == 0);",
  4643. "}",
  4644. "#endif",
  4645. "#endif",
  4646. "#ifndef BITSTATE",
  4647. "void",
  4648. "hinit(void)",
  4649. "{",
  4650. "#ifdef MA",
  4651. "#ifdef R_XPT",
  4652. " { void r_xpoint(void);",
  4653. " r_xpoint();",
  4654. " }",
  4655. "#else",
  4656. " dfa_init((unsigned short) (MA+a_cycles));",
  4657. "#endif",
  4658. "#endif",
  4659. "#if !defined(MA) || defined(COLLAPSE)",
  4660. " H_tab = (struct H_el **)",
  4661. " emalloc((1L<<ssize)*sizeof(struct H_el *));",
  4662. "#endif",
  4663. "}",
  4664. "#endif\n",
  4665. "#if !defined(BITSTATE) || defined(FULLSTACK)",
  4666. "#ifdef DEBUG",
  4667. "void",
  4668. "dumpstate(int wasnew, char *v, int n, int tag)",
  4669. "{ int i;",
  4670. "#ifndef SAFETY",
  4671. " if (S_A)",
  4672. " { printf(\"\tstate tags %%d (%%d::%%d): \",",
  4673. " V_A, wasnew, v[0]);",
  4674. "#ifdef FULLSTACK",
  4675. " printf(\" %%d \", tag);",
  4676. "#endif",
  4677. " printf(\"\\n\");",
  4678. " }",
  4679. "#endif",
  4680. "#ifdef SDUMP",
  4681. "#ifndef NOCOMP",
  4682. " printf(\"\t State: \");",
  4683. " for (i = 0; i < vsize; i++) printf(\"%%d%%s,\",",
  4684. " ((char *)&now)[i], Mask[i]?\"*\":\"\");",
  4685. "#endif",
  4686. " printf(\"\\n\tVector: \");",
  4687. " for (i = 0; i < n; i++) printf(\"%%d,\", v[i]);",
  4688. " printf(\"\\n\");",
  4689. "#endif",
  4690. "}",
  4691. "#endif",
  4692. "#ifdef MA",
  4693. "int",
  4694. "gstore(char *vin, int nin, uchar pbit)",
  4695. "{ int n, i;",
  4696. " uchar *v;",
  4697. " static uchar Info[MA+1];",
  4698. "#ifndef NOCOMP",
  4699. " n = compress(vin, nin);",
  4700. " v = (uchar *) &comp_now;",
  4701. "#else",
  4702. " n = nin;",
  4703. " v = vin;",
  4704. "#endif",
  4705. " if (n >= MA)",
  4706. " { printf(\"pan: error, MA too small, recompile pan.c\");",
  4707. " printf(\" with -DMA=N with N>%%d\\n\", n);",
  4708. " Uerror(\"aborting\");",
  4709. " }",
  4710. " if (n > (int) maxgs) maxgs = (unsigned int) n;",
  4711. " for (i = 0; i < n; i++)",
  4712. " Info[i] = v[i];",
  4713. " for ( ; i < MA-1; i++)",
  4714. " Info[i] = 0;",
  4715. " Info[MA-1] = pbit;",
  4716. " if (a_cycles) /* place _a_t at the end */",
  4717. " { Info[MA] = Info[0]; Info[0] = 0; }",
  4718. " if (!dfa_store(Info))",
  4719. " { if (pbit == 0",
  4720. " && (now._a_t&1)",
  4721. " && depth > A_depth)",
  4722. " { Info[MA] &= ~(1|16|32); /* _a_t */",
  4723. " if (dfa_member(MA))", /* was !dfa_member(MA) */
  4724. " { Info[MA-1] = 4; /* off-stack bit */",
  4725. " nShadow++;",
  4726. " if (!dfa_member(MA-1))",
  4727. " {",
  4728. "#ifdef VERBOSE",
  4729. " printf(\"intersected 1st dfs stack\\n\");",
  4730. "#endif",
  4731. " return 3;",
  4732. " } } }",
  4733. "#ifdef VERBOSE",
  4734. " printf(\"new state\\n\");",
  4735. "#endif",
  4736. " return 0; /* new state */",
  4737. " }",
  4738. "#ifdef FULLSTACK",
  4739. " if (pbit == 0)",
  4740. " { Info[MA-1] = 1; /* proviso bit */",
  4741. "#ifndef BFS",
  4742. " trpt->proviso = dfa_member(MA-1);",
  4743. "#endif",
  4744. " Info[MA-1] = 4; /* off-stack bit */",
  4745. " if (dfa_member(MA-1)) {",
  4746. "#ifdef VERBOSE",
  4747. " printf(\"old state\\n\");",
  4748. "#endif",
  4749. " return 1; /* off-stack */",
  4750. " } else {",
  4751. "#ifdef VERBOSE",
  4752. " printf(\"on-stack\\n\");",
  4753. "#endif",
  4754. " return 2; /* on-stack */",
  4755. " }",
  4756. " }",
  4757. "#endif",
  4758. "#ifdef VERBOSE",
  4759. " printf(\"old state\\n\");",
  4760. "#endif",
  4761. " return 1; /* old state */",
  4762. "}",
  4763. "#endif",
  4764. "#if defined(BITSTATE) && defined(LC)",
  4765. "int",
  4766. "compact_stack(char *vin, int n)", /* special case of HC4 */
  4767. "{ int delta = 0;",
  4768. " s_hash((uchar *)vin, n); /* sets K1 and K2 */",
  4769. "#ifndef SAFETY",
  4770. " delta++; /* room for state[0] |= 128 */",
  4771. "#endif",
  4772. " memcpy((char *) &comp_now + delta, (char *) &K1, WS);",
  4773. " delta += WS;",
  4774. " memcpy((char *) &comp_now + delta, (char *) &K2, WS);",
  4775. " delta += WS; /* use all available bits */",
  4776. " return delta;",
  4777. "}",
  4778. "#endif",
  4779. "int",
  4780. "hstore(char *vin, int nin) /* hash table storage */",
  4781. "{ struct H_el *tmp, *ntmp, *olst = (struct H_el *) 0;",
  4782. " char *v; int n, m=0;",
  4783. "#ifdef HC",
  4784. " uchar rem_a;",
  4785. "#endif",
  4786. "#ifdef NOCOMP", /* defined by BITSTATE */
  4787. "#if defined(BITSTATE) && defined(LC)",
  4788. " if (S_Tab == H_tab)",
  4789. " { v = (char *) &comp_now;",
  4790. " n = compact_stack(vin, nin);",
  4791. " } else",
  4792. " { v = vin; n = nin;",
  4793. " }",
  4794. "#else",
  4795. " v = vin; n = nin;",
  4796. "#endif",
  4797. "#else",
  4798. " v = (char *) &comp_now;",
  4799. " #ifdef HC",
  4800. " rem_a = now._a_t;", /* 4.3.0 */
  4801. " now._a_t = 0;", /* for hashing/state matching to work right */
  4802. " #endif",
  4803. " n = compress(vin, nin);", /* with HC, this calls s_hash */
  4804. " #ifdef HC",
  4805. " now._a_t = rem_a;", /* 4.3.0 */
  4806. " #endif",
  4807. "#ifndef SAFETY",
  4808. " if (S_A)",
  4809. " { v[0] = 0; /* _a_t */",
  4810. "#ifndef NOFAIR",
  4811. " if (S_A > NFAIR)",
  4812. " for (m = 0; m < NFAIR; m++)",
  4813. " v[m+1] = 0; /* _cnt[] */",
  4814. "#endif",
  4815. " m = 0;",
  4816. " }",
  4817. "#endif",
  4818. "#endif",
  4819. "#if !defined(HC) && !(defined(BITSTATE) && defined(LC))",
  4820. " s_hash((uchar *)v, n);",
  4821. "#endif",
  4822. " tmp = H_tab[j1];",
  4823. " if (!tmp)",
  4824. " { tmp = grab_state(n);",
  4825. " H_tab[j1] = tmp;",
  4826. " } else",
  4827. " { for (;; hcmp++, olst = tmp, tmp = tmp->nxt)",
  4828. " { /* skip the _a_t and the _cnt bytes */",
  4829. "#ifdef COLLAPSE",
  4830. " if (tmp->ln != 0)",
  4831. " { if (!tmp->nxt) goto Append;",
  4832. " continue;",
  4833. " }",
  4834. "#endif",
  4835. " m = memcmp(((char *)&(tmp->state)) + S_A, ",
  4836. " v + S_A, n - S_A);",
  4837. " if (m == 0) {",
  4838. "#ifdef SAFETY",
  4839. "#define wasnew 0",
  4840. "#else",
  4841. " int wasnew = 0;",
  4842. "#endif",
  4843. "#ifndef SAFETY",
  4844. "#ifndef NOCOMP",
  4845. " if (S_A)",
  4846. " { if ((((char *)&(tmp->state))[0] & V_A) != V_A)",
  4847. " { wasnew = 1; nShadow++;",
  4848. " ((char *)&(tmp->state))[0] |= V_A;",
  4849. " }",
  4850. "#ifndef NOFAIR",
  4851. " if (S_A > NFAIR)",
  4852. " { /* 0 <= now._cnt[now._a_t&1] < MAXPROC */",
  4853. " unsigned ci, bp; /* index, bit pos */",
  4854. " ci = (now._cnt[now._a_t&1] / 8);",
  4855. " bp = (now._cnt[now._a_t&1] - 8*ci);",
  4856. " if (now._a_t&1) /* use tail-bits in _cnt */",
  4857. " { ci = (NFAIR - 1) - ci;",
  4858. " bp = 7 - bp; /* bp = 0..7 */",
  4859. " }",
  4860. " ci++; /* skip over _a_t */",
  4861. " bp = 1 << bp; /* the bit mask */",
  4862. " if ((((char *)&(tmp->state))[ci] & bp)==0)",
  4863. " { if (!wasnew)",
  4864. " { wasnew = 1;",
  4865. " nShadow++;",
  4866. " }",
  4867. " ((char *)&(tmp->state))[ci] |= bp;",
  4868. " }",
  4869. " }",
  4870. " /* else: wasnew == 0, i.e., old state */",
  4871. "#endif",
  4872. " }",
  4873. "#endif",
  4874. "#endif",
  4875. "#ifdef FULLSTACK",
  4876. "#ifndef SAFETY", /* or else wasnew == 0 */
  4877. " if (wasnew)",
  4878. " { Lstate = (struct H_el *) tmp;",
  4879. " tmp->tagged |= V_A;",
  4880. " if ((now._a_t&1)",
  4881. " && (tmp->tagged&A_V)",
  4882. " && depth > A_depth)",
  4883. " {",
  4884. "intersect:",
  4885. "#ifdef CHECK",
  4886. " printf(\"1st dfs-stack intersected on state %%d+\\n\",",
  4887. " (int) tmp->st_id);",
  4888. "#endif",
  4889. " return 3;",
  4890. " }",
  4891. "#ifdef CHECK",
  4892. " printf(\"\tNew state %%d+\\n\", (int) tmp->st_id);",
  4893. "#endif",
  4894. "#ifdef DEBUG",
  4895. " dumpstate(1, (char *)&(tmp->state),n,tmp->tagged);",
  4896. "#endif",
  4897. " return 0;",
  4898. " } else",
  4899. "#endif",
  4900. " if ((S_A)?(tmp->tagged&V_A):tmp->tagged)",
  4901. " { Lstate = (struct H_el *) tmp;",
  4902. "#ifndef SAFETY",
  4903. " /* already on current dfs stack */",
  4904. " /* but may also be on 1st dfs stack */",
  4905. " if ((now._a_t&1)",
  4906. " && (tmp->tagged&A_V)",
  4907. " && depth > A_depth",
  4908. /* new (Zhang's example) */
  4909. "#ifndef NOFAIR",
  4910. " && (!fairness || now._cnt[1] <= 1)",
  4911. "#endif",
  4912. " )",
  4913. " goto intersect;",
  4914. "#endif",
  4915. "#ifdef CHECK",
  4916. " printf(\"\tStack state %%d\\n\", (int) tmp->st_id);",
  4917. "#endif",
  4918. "#ifdef DEBUG",
  4919. " dumpstate(0, (char *)&(tmp->state),n,tmp->tagged);",
  4920. "#endif",
  4921. " return 2; /* match on stack */",
  4922. " }",
  4923. "#else",
  4924. " if (wasnew)",
  4925. " {",
  4926. "#ifdef CHECK",
  4927. " printf(\"\tNew state %%d+\\n\", (int) tmp->st_id);",
  4928. "#endif",
  4929. "#ifdef DEBUG",
  4930. " dumpstate(1, (char *)&(tmp->state), n, 0);",
  4931. "#endif",
  4932. " return 0;",
  4933. " }",
  4934. "#endif",
  4935. "#ifdef CHECK",
  4936. " printf(\"\tOld state %%d\\n\", (int) tmp->st_id);",
  4937. "#endif",
  4938. "#ifdef DEBUG",
  4939. " dumpstate(0, (char *)&(tmp->state), n, 0);",
  4940. "#endif",
  4941. "#ifdef REACH",
  4942. " if (tmp->D > depth)",
  4943. " { tmp->D = depth;",
  4944. "#ifdef CHECK",
  4945. " printf(\"\t\tReVisiting (from smaller depth)\\n\");",
  4946. "#endif",
  4947. " nstates--;",
  4948. #if 0
  4949. possible variation of iterative search for shortest counter-example (pan -i
  4950. and pan -I) suggested by Pierre Moro (for safety properties):
  4951. state revisits on shorter depths do not start until after
  4952. the first counter-example is found. this assumes that the max search
  4953. depth is set large enough that a first (possibly long) counter-example
  4954. can be found
  4955. if set too short, this variant can miss the counter-example, even if
  4956. it would otherwise be shorter than the depth-limit.
  4957. (p.m. unsure if this preserves the guarantee of finding the
  4958. shortest counter-example - so not enabled yet)
  4959. " if (errors > 0 && iterative)", /* Moro */
  4960. #endif
  4961. " return 0;",
  4962. " }",
  4963. "#endif",
  4964. "#if defined(BFS) && defined(Q_PROVISO)",
  4965. " Lstate = (struct H_el *) tmp;",
  4966. "#endif",
  4967. " return 1; /* match outside stack */",
  4968. " } else if (m < 0)",
  4969. " { /* insert state before tmp */",
  4970. " ntmp = grab_state(n);",
  4971. " ntmp->nxt = tmp;",
  4972. " if (!olst)",
  4973. " H_tab[j1] = ntmp;",
  4974. " else",
  4975. " olst->nxt = ntmp;",
  4976. " tmp = ntmp;",
  4977. " break;",
  4978. " } else if (!tmp->nxt)",
  4979. " { /* append after tmp */",
  4980. "#ifdef COLLAPSE",
  4981. "Append:",
  4982. "#endif",
  4983. " tmp->nxt = grab_state(n);",
  4984. " tmp = tmp->nxt;",
  4985. " break;",
  4986. " } }",
  4987. " }",
  4988. "#ifdef CHECK",
  4989. " tmp->st_id = (unsigned) nstates;",
  4990. "#ifdef BITSTATE",
  4991. " printf(\" Push state %%d\\n\", ((int) nstates) - 1);",
  4992. "#else",
  4993. " printf(\" New state %%d\\n\", (int) nstates);",
  4994. "#endif",
  4995. "#endif",
  4996. "#if !defined(SAFETY) || defined(REACH)",
  4997. " tmp->D = depth;",
  4998. "#endif",
  4999. "#ifndef SAFETY",
  5000. "#ifndef NOCOMP",
  5001. " if (S_A)",
  5002. " { v[0] = V_A;",
  5003. "#ifndef NOFAIR",
  5004. " if (S_A > NFAIR)",
  5005. " { unsigned ci, bp; /* as above */",
  5006. " ci = (now._cnt[now._a_t&1] / 8);",
  5007. " bp = (now._cnt[now._a_t&1] - 8*ci);",
  5008. " if (now._a_t&1)",
  5009. " { ci = (NFAIR - 1) - ci;",
  5010. " bp = 7 - bp; /* bp = 0..7 */",
  5011. " }",
  5012. " v[1+ci] = 1 << bp;",
  5013. " }",
  5014. "#endif",
  5015. " }",
  5016. "#endif",
  5017. "#endif",
  5018. " memcpy(((char *)&(tmp->state)), v, n);",
  5019. "#ifdef FULLSTACK",
  5020. " tmp->tagged = (S_A)?V_A:(depth+1);",
  5021. "#ifdef DEBUG",
  5022. " dumpstate(-1, v, n, tmp->tagged);",
  5023. "#endif",
  5024. " Lstate = (struct H_el *) tmp;",
  5025. "#else",
  5026. "#ifdef DEBUG",
  5027. " dumpstate(-1, v, n, 0);",
  5028. "#endif",
  5029. "#endif",
  5030. " return 0;",
  5031. "}",
  5032. "#endif",
  5033. "#include TRANSITIONS",
  5034. "void",
  5035. "do_reach(void)",
  5036. "{",
  5037. 0,
  5038. };