pangen1.h 194 KB

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