verilog-mode.el 539 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328
  1. ;;; verilog-mode.el --- major mode for editing verilog source in Emacs
  2. ;; Copyright (C) 1996-2015 Free Software Foundation, Inc.
  3. ;; Author: Michael McNamara <mac@verilog.com>
  4. ;; Wilson Snyder <wsnyder@wsnyder.org>
  5. ;; http://www.verilog.com
  6. ;; http://www.veripool.org
  7. ;; Created: 3 Jan 1996
  8. ;; Keywords: languages
  9. ;; Yoni Rabkin <yoni@rabkins.net> contacted the maintainer of this
  10. ;; file on 19/3/2008, and the maintainer agreed that when a bug is
  11. ;; filed in the Emacs bug reporting system against this file, a copy
  12. ;; of the bug report be sent to the maintainer's email address.
  13. ;; This code supports Emacs 21.1 and later
  14. ;; And XEmacs 21.1 and later
  15. ;; Please do not make changes that break Emacs 21. Thanks!
  16. ;;
  17. ;;
  18. ;; This file is part of GNU Emacs.
  19. ;; GNU Emacs is free software: you can redistribute it and/or modify
  20. ;; it under the terms of the GNU General Public License as published by
  21. ;; the Free Software Foundation, either version 3 of the License, or
  22. ;; (at your option) any later version.
  23. ;; GNU Emacs is distributed in the hope that it will be useful,
  24. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  26. ;; GNU General Public License for more details.
  27. ;; You should have received a copy of the GNU General Public License
  28. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  29. ;;; Commentary:
  30. ;; USAGE
  31. ;; =====
  32. ;; A major mode for editing Verilog and SystemVerilog HDL source code (IEEE
  33. ;; 1364-2005 and IEEE 1800-2012 standards). When you have entered Verilog
  34. ;; mode, you may get more info by pressing C-h m. You may also get online
  35. ;; help describing various functions by: C-h f <Name of function you want
  36. ;; described>
  37. ;; KNOWN BUGS / BUG REPORTS
  38. ;; =======================
  39. ;; SystemVerilog is a rapidly evolving language, and hence this mode is
  40. ;; under continuous development. Please report any issues to the issue
  41. ;; tracker at
  42. ;;
  43. ;; http://www.veripool.org/verilog-mode
  44. ;;
  45. ;; Please use verilog-submit-bug-report to submit a report; type C-c
  46. ;; C-b to invoke this and as a result we will have a much easier time
  47. ;; of reproducing the bug you find, and hence fixing it.
  48. ;; INSTALLING THE MODE
  49. ;; ===================
  50. ;; An older version of this mode may be already installed as a part of
  51. ;; your environment, and one method of updating would be to update
  52. ;; your Emacs environment. Sometimes this is difficult for local
  53. ;; political/control reasons, and hence you can always install a
  54. ;; private copy (or even a shared copy) which overrides the system
  55. ;; default.
  56. ;; You can get step by step help in installing this file by going to
  57. ;; <http://www.verilog.com/emacs_install.html>
  58. ;; The short list of installation instructions are: To set up
  59. ;; automatic Verilog mode, put this file in your load path, and put
  60. ;; the following in code (please un comment it first!) in your
  61. ;; .emacs, or in your site's site-load.el
  62. ;; (autoload 'verilog-mode "verilog-mode" "Verilog mode" t )
  63. ;; (add-to-list 'auto-mode-alist '("\\.[ds]?vh?\\'" . verilog-mode))
  64. ;; Be sure to examine at the help for verilog-auto, and the other
  65. ;; verilog-auto-* functions for some major coding time savers.
  66. ;;
  67. ;; If you want to customize Verilog mode to fit your needs better,
  68. ;; you may add the below lines (the values of the variables presented
  69. ;; here are the defaults). Note also that if you use an Emacs that
  70. ;; supports custom, it's probably better to use the custom menu to
  71. ;; edit these. If working as a member of a large team these settings
  72. ;; should be common across all users (in a site-start file), or set
  73. ;; in Local Variables in every file. Otherwise, different people's
  74. ;; AUTO expansion may result different whitespace changes.
  75. ;;
  76. ;; ;; Enable syntax highlighting of **all** languages
  77. ;; (global-font-lock-mode t)
  78. ;;
  79. ;; ;; User customization for Verilog mode
  80. ;; (setq verilog-indent-level 3
  81. ;; verilog-indent-level-module 3
  82. ;; verilog-indent-level-declaration 3
  83. ;; verilog-indent-level-behavioral 3
  84. ;; verilog-indent-level-directive 1
  85. ;; verilog-case-indent 2
  86. ;; verilog-auto-newline t
  87. ;; verilog-auto-indent-on-newline t
  88. ;; verilog-tab-always-indent t
  89. ;; verilog-auto-endcomments t
  90. ;; verilog-minimum-comment-distance 40
  91. ;; verilog-indent-begin-after-if t
  92. ;; verilog-auto-lineup 'declarations
  93. ;; verilog-highlight-p1800-keywords nil
  94. ;; verilog-linter "my_lint_shell_command"
  95. ;; )
  96. ;;; History:
  97. ;;
  98. ;; See commit history at http://www.veripool.org/verilog-mode.html
  99. ;; (This section is required to appease checkdoc.)
  100. ;;; Code:
  101. ;;
  102. ;; This variable will always hold the version number of the mode
  103. (defconst verilog-mode-version "2015-09-18-314cf1d-vpo-GNU"
  104. "Version of this Verilog mode.")
  105. (defconst verilog-mode-release-emacs t
  106. "If non-nil, this version of Verilog mode was released with Emacs itself.")
  107. (defun verilog-version ()
  108. "Inform caller of the version of this file."
  109. (interactive)
  110. (message "Using verilog-mode version %s" verilog-mode-version))
  111. ;; Insure we have certain packages, and deal with it if we don't
  112. ;; Be sure to note which Emacs flavor and version added each feature.
  113. (eval-when-compile
  114. ;; Provide stuff if we are XEmacs
  115. (when (featurep 'xemacs)
  116. (condition-case nil
  117. (require 'easymenu)
  118. (error nil))
  119. (condition-case nil
  120. (require 'regexp-opt)
  121. (error nil))
  122. ;; Bug in 19.28 through 19.30 skeleton.el, not provided.
  123. (condition-case nil
  124. (load "skeleton")
  125. (error nil))
  126. (condition-case nil
  127. (if (fboundp 'when)
  128. nil ; fab
  129. (defmacro when (cond &rest body)
  130. (list 'if cond (cons 'progn body))))
  131. (error nil))
  132. (condition-case nil
  133. (if (fboundp 'unless)
  134. nil ; fab
  135. (defmacro unless (cond &rest body)
  136. (cons 'if (cons cond (cons nil body)))))
  137. (error nil))
  138. (condition-case nil
  139. (if (fboundp 'store-match-data)
  140. nil ; fab
  141. (defmacro store-match-data (&rest _args) nil))
  142. (error nil))
  143. (condition-case nil
  144. (if (fboundp 'char-before)
  145. nil ; great
  146. (defmacro char-before (&rest _body)
  147. (char-after (1- (point)))))
  148. (error nil))
  149. (condition-case nil
  150. (if (fboundp 'when)
  151. nil ; fab
  152. (defsubst point-at-bol (&optional N)
  153. (save-excursion (beginning-of-line N) (point))))
  154. (error nil))
  155. (condition-case nil
  156. (if (fboundp 'when)
  157. nil ; fab
  158. (defsubst point-at-eol (&optional N)
  159. (save-excursion (end-of-line N) (point))))
  160. (error nil))
  161. (condition-case nil
  162. (require 'custom)
  163. (error nil))
  164. (condition-case nil
  165. (if (fboundp 'match-string-no-properties)
  166. nil ; great
  167. (defsubst match-string-no-properties (num &optional string)
  168. "Return string of text matched by last search, without text properties.
  169. NUM specifies which parenthesized expression in the last regexp.
  170. Value is nil if NUMth pair didn't match, or there were less than NUM pairs.
  171. Zero means the entire text matched by the whole regexp or whole string.
  172. STRING should be given if the last search was by `string-match' on STRING."
  173. (if (match-beginning num)
  174. (if string
  175. (let ((result
  176. (substring string
  177. (match-beginning num) (match-end num))))
  178. (set-text-properties 0 (length result) nil result)
  179. result)
  180. (buffer-substring-no-properties (match-beginning num)
  181. (match-end num)
  182. (current-buffer)))))
  183. )
  184. (error nil))
  185. (if (and (featurep 'custom) (fboundp 'custom-declare-variable))
  186. nil ; We've got what we needed
  187. ;; We have the old custom-library, hack around it!
  188. (defmacro defgroup (&rest _args) nil)
  189. (defmacro customize (&rest _args)
  190. (message
  191. "Sorry, Customize is not available with this version of Emacs"))
  192. (defmacro defcustom (var value doc &rest _args)
  193. `(defvar ,var ,value ,doc))
  194. )
  195. (if (fboundp 'defface)
  196. nil ; great!
  197. (defmacro defface (var values doc &rest _args)
  198. `(make-face ,var))
  199. )
  200. (if (and (featurep 'custom) (fboundp 'customize-group))
  201. nil ; We've got what we needed
  202. ;; We have an intermediate custom-library, hack around it!
  203. (defmacro customize-group (var &rest _args)
  204. `(customize ,var))
  205. )
  206. (unless (boundp 'inhibit-point-motion-hooks)
  207. (defvar inhibit-point-motion-hooks nil))
  208. (unless (boundp 'deactivate-mark)
  209. (defvar deactivate-mark nil))
  210. )
  211. ;;
  212. ;; OK, do this stuff if we are NOT XEmacs:
  213. (unless (featurep 'xemacs)
  214. (unless (fboundp 'region-active-p)
  215. (defmacro region-active-p ()
  216. `(and transient-mark-mode mark-active))))
  217. )
  218. ;; Provide a regular expression optimization routine, using regexp-opt
  219. ;; if provided by the user's elisp libraries
  220. (eval-and-compile
  221. ;; The below were disabled when GNU Emacs 22 was released;
  222. ;; perhaps some still need to be there to support Emacs 21.
  223. (if (featurep 'xemacs)
  224. (if (fboundp 'regexp-opt)
  225. ;; regexp-opt is defined, does it take 3 or 2 arguments?
  226. (if (fboundp 'function-max-args)
  227. (let ((args (function-max-args `regexp-opt)))
  228. (cond
  229. ((eq args 3) ; It takes 3
  230. (condition-case nil ; Hide this defun from emacses
  231. ; with just a two input regexp
  232. (defun verilog-regexp-opt (a b)
  233. "Deal with differing number of required arguments for `regexp-opt'.
  234. Call `regexp-opt' on A and B."
  235. (regexp-opt a b t))
  236. (error nil))
  237. )
  238. ((eq args 2) ; It takes 2
  239. (defun verilog-regexp-opt (a b)
  240. "Call `regexp-opt' on A and B."
  241. (regexp-opt a b))
  242. )
  243. (t nil)))
  244. ;; We can't tell; assume it takes 2
  245. (defun verilog-regexp-opt (a b)
  246. "Call `regexp-opt' on A and B."
  247. (regexp-opt a b))
  248. )
  249. ;; There is no regexp-opt, provide our own
  250. (defun verilog-regexp-opt (strings &optional paren _shy)
  251. (let ((open (if paren "\\(" "")) (close (if paren "\\)" "")))
  252. (concat open (mapconcat 'regexp-quote strings "\\|") close)))
  253. )
  254. ;; Emacs.
  255. (defalias 'verilog-regexp-opt 'regexp-opt)))
  256. ;; emacs >=22 has looking-back, but older emacs and xemacs don't.
  257. ;; This function is lifted directly from emacs's subr.el
  258. ;; so that it can be used by xemacs.
  259. ;; The idea for this was borrowed from org-mode via this link:
  260. ;; https://lists.gnu.org/archive/html/emacs-orgmode/2009-12/msg00032.html
  261. (eval-and-compile
  262. (cond
  263. ((fboundp 'looking-back)
  264. (defalias 'verilog-looking-back 'looking-back))
  265. (t
  266. (defun verilog-looking-back (regexp limit &optional greedy)
  267. "Return non-nil if text before point matches regular expression REGEXP.
  268. Like `looking-at' except matches before point, and is slower.
  269. LIMIT if non-nil speeds up the search by specifying a minimum
  270. starting position, to avoid checking matches that would start
  271. before LIMIT.
  272. If GREEDY is non-nil, extend the match backwards as far as
  273. possible, stopping when a single additional previous character
  274. cannot be part of a match for REGEXP. When the match is
  275. extended, its starting position is allowed to occur before
  276. LIMIT.
  277. As a general recommendation, try to avoid using `looking-back'
  278. wherever possible, since it is slow."
  279. (let ((start (point))
  280. (pos
  281. (save-excursion
  282. (and (re-search-backward (concat "\\(?:" regexp "\\)\\=") limit t)
  283. (point)))))
  284. (if (and greedy pos)
  285. (save-restriction
  286. (narrow-to-region (point-min) start)
  287. (while (and (> pos (point-min))
  288. (save-excursion
  289. (goto-char pos)
  290. (backward-char 1)
  291. (looking-at (concat "\\(?:" regexp "\\)\\'"))))
  292. (setq pos (1- pos)))
  293. (save-excursion
  294. (goto-char pos)
  295. (looking-at (concat "\\(?:" regexp "\\)\\'")))))
  296. (not (null pos)))))))
  297. (eval-and-compile
  298. ;; Both xemacs and emacs
  299. (condition-case nil
  300. (require 'diff) ; diff-command and diff-switches
  301. (error nil))
  302. (condition-case nil
  303. (require 'compile) ; compilation-error-regexp-alist-alist
  304. (error nil))
  305. (condition-case nil
  306. (unless (fboundp 'buffer-chars-modified-tick) ; Emacs 22 added
  307. (defmacro buffer-chars-modified-tick () (buffer-modified-tick)))
  308. (error nil))
  309. ;; Added in Emacs 24.1
  310. (condition-case nil
  311. (unless (fboundp 'prog-mode)
  312. (define-derived-mode prog-mode fundamental-mode "Prog"))
  313. (error nil)))
  314. (eval-when-compile
  315. (defun verilog-regexp-words (a)
  316. "Call `regexp-opt' with word delimiters for the words A."
  317. (concat "\\<" (verilog-regexp-opt a t) "\\>")))
  318. (defun verilog-regexp-words (a)
  319. "Call `regexp-opt' with word delimiters for the words A."
  320. ;; The FAQ references this function, so user LISP sometimes calls it
  321. (concat "\\<" (verilog-regexp-opt a t) "\\>"))
  322. (defun verilog-easy-menu-filter (menu)
  323. "Filter `easy-menu-define' MENU to support new features."
  324. (cond ((not (featurep 'xemacs))
  325. menu) ; GNU Emacs - passthru
  326. ;; XEmacs doesn't support :help. Strip it.
  327. ;; Recursively filter the a submenu
  328. ((listp menu)
  329. (mapcar 'verilog-easy-menu-filter menu))
  330. ;; Look for [:help "blah"] and remove
  331. ((vectorp menu)
  332. (let ((i 0) (out []))
  333. (while (< i (length menu))
  334. (if (equal `:help (aref menu i))
  335. (setq i (+ 2 i))
  336. (setq out (vconcat out (vector (aref menu i)))
  337. i (1+ i))))
  338. out))
  339. (t menu))) ; Default - ok
  340. ;;(verilog-easy-menu-filter
  341. ;; `("Verilog" ("MA" ["SAA" nil :help "Help SAA"] ["SAB" nil :help "Help SAA"])
  342. ;; "----" ["MB" nil :help "Help MB"]))
  343. (defun verilog-define-abbrev (table name expansion &optional hook)
  344. "Filter `define-abbrev' TABLE NAME EXPANSION and call HOOK.
  345. Provides SYSTEM-FLAG in newer Emacs."
  346. (condition-case nil
  347. (define-abbrev table name expansion hook 0 t)
  348. (error
  349. (define-abbrev table name expansion hook))))
  350. (defun verilog-customize ()
  351. "Customize variables and other settings used by Verilog-Mode."
  352. (interactive)
  353. (customize-group 'verilog-mode))
  354. (defun verilog-font-customize ()
  355. "Customize fonts used by Verilog-Mode."
  356. (interactive)
  357. (if (fboundp 'customize-apropos)
  358. (customize-apropos "font-lock-*" 'faces)))
  359. (defun verilog-booleanp (value)
  360. "Return t if VALUE is boolean.
  361. This implements GNU Emacs 22.1's `booleanp' function in earlier Emacs.
  362. This function may be removed when Emacs 21 is no longer supported."
  363. (or (equal value t) (equal value nil)))
  364. (defun verilog-insert-last-command-event ()
  365. "Insert the `last-command-event'."
  366. (insert (if (featurep 'xemacs)
  367. ;; XEmacs 21.5 doesn't like last-command-event
  368. last-command-char
  369. ;; And GNU Emacs 22 has obsoleted last-command-char
  370. last-command-event)))
  371. (defvar verilog-no-change-functions nil
  372. "True if `after-change-functions' is disabled.
  373. Use of `syntax-ppss' may break, as ppss's cache may get corrupted.")
  374. (defvar verilog-in-hooks nil
  375. "True when within a `verilog-run-hooks' block.")
  376. (defmacro verilog-run-hooks (&rest hooks)
  377. "Run each hook in HOOKS using `run-hooks'.
  378. Set `verilog-in-hooks' during this time, to assist AUTO caches."
  379. `(let ((verilog-in-hooks t))
  380. (run-hooks ,@hooks)))
  381. (defun verilog-syntax-ppss (&optional pos)
  382. (when verilog-no-change-functions
  383. (if verilog-in-hooks
  384. (verilog-scan-cache-flush)
  385. ;; else don't let the AUTO code itself get away with flushing the cache,
  386. ;; as that'll make things very slow
  387. (backtrace)
  388. (error "%s: Internal problem; use of syntax-ppss when cache may be corrupt"
  389. (verilog-point-text))))
  390. (if (fboundp 'syntax-ppss)
  391. (syntax-ppss pos)
  392. (parse-partial-sexp (point-min) (or pos (point)))))
  393. (defgroup verilog-mode nil
  394. "Major mode for Verilog source code."
  395. :version "22.2"
  396. :group 'languages)
  397. ;; (defgroup verilog-mode-fonts nil
  398. ;; "Facilitates easy customization fonts used in Verilog source text"
  399. ;; :link '(customize-apropos "font-lock-*" 'faces)
  400. ;; :group 'verilog-mode)
  401. (defgroup verilog-mode-indent nil
  402. "Customize indentation and highlighting of Verilog source text."
  403. :group 'verilog-mode)
  404. (defgroup verilog-mode-actions nil
  405. "Customize actions on Verilog source text."
  406. :group 'verilog-mode)
  407. (defgroup verilog-mode-auto nil
  408. "Customize AUTO actions when expanding Verilog source text."
  409. :group 'verilog-mode)
  410. (defvar verilog-debug nil
  411. "Non-nil means enable debug messages for `verilog-mode' internals.")
  412. (defvar verilog-warn-fatal nil
  413. "Non-nil means `verilog-warn-error' warnings are fatal `error's.")
  414. (defcustom verilog-linter
  415. "echo 'No verilog-linter set, see \"M-x describe-variable verilog-linter\"'"
  416. "Unix program and arguments to call to run a lint checker on Verilog source.
  417. Depending on the `verilog-set-compile-command', this may be invoked when
  418. you type \\[compile]. When the compile completes, \\[next-error] will take
  419. you to the next lint error."
  420. :type 'string
  421. :group 'verilog-mode-actions)
  422. ;; We don't mark it safe, as it's used as a shell command
  423. (defcustom verilog-coverage
  424. "echo 'No verilog-coverage set, see \"M-x describe-variable verilog-coverage\"'"
  425. "Program and arguments to use to annotate for coverage Verilog source.
  426. Depending on the `verilog-set-compile-command', this may be invoked when
  427. you type \\[compile]. When the compile completes, \\[next-error] will take
  428. you to the next lint error."
  429. :type 'string
  430. :group 'verilog-mode-actions)
  431. ;; We don't mark it safe, as it's used as a shell command
  432. (defcustom verilog-simulator
  433. "echo 'No verilog-simulator set, see \"M-x describe-variable verilog-simulator\"'"
  434. "Program and arguments to use to interpret Verilog source.
  435. Depending on the `verilog-set-compile-command', this may be invoked when
  436. you type \\[compile]. When the compile completes, \\[next-error] will take
  437. you to the next lint error."
  438. :type 'string
  439. :group 'verilog-mode-actions)
  440. ;; We don't mark it safe, as it's used as a shell command
  441. (defcustom verilog-compiler
  442. "echo 'No verilog-compiler set, see \"M-x describe-variable verilog-compiler\"'"
  443. "Program and arguments to use to compile Verilog source.
  444. Depending on the `verilog-set-compile-command', this may be invoked when
  445. you type \\[compile]. When the compile completes, \\[next-error] will take
  446. you to the next lint error."
  447. :type 'string
  448. :group 'verilog-mode-actions)
  449. ;; We don't mark it safe, as it's used as a shell command
  450. (defcustom verilog-preprocessor
  451. ;; Very few tools give preprocessed output, so we'll default to Verilog-Perl
  452. "vppreproc __FLAGS__ __FILE__"
  453. "Program and arguments to use to preprocess Verilog source.
  454. This is invoked with `verilog-preprocess', and depending on the
  455. `verilog-set-compile-command', may also be invoked when you type
  456. \\[compile]. When the compile completes, \\[next-error] will
  457. take you to the next lint error."
  458. :type 'string
  459. :group 'verilog-mode-actions)
  460. ;; We don't mark it safe, as it's used as a shell command
  461. (defvar verilog-preprocess-history nil
  462. "History for `verilog-preprocess'.")
  463. (defvar verilog-tool 'verilog-linter
  464. "Which tool to use for building compiler-command.
  465. Either nil, `verilog-linter', `verilog-compiler',
  466. `verilog-coverage', `verilog-preprocessor', or `verilog-simulator'.
  467. Alternatively use the \"Choose Compilation Action\" menu. See
  468. `verilog-set-compile-command' for more information.")
  469. (defcustom verilog-highlight-translate-off nil
  470. "Non-nil means background-highlight code excluded from translation.
  471. That is, all code between \"// synopsys translate_off\" and
  472. \"// synopsys translate_on\" is highlighted using a different background color
  473. \(face `verilog-font-lock-translate-off-face').
  474. Note: This will slow down on-the-fly fontification (and thus editing).
  475. Note: Activate the new setting in a Verilog buffer by re-fontifying it (menu
  476. entry \"Fontify Buffer\"). XEmacs: turn off and on font locking."
  477. :type 'boolean
  478. :group 'verilog-mode-indent)
  479. ;; Note we don't use :safe, as that would break on Emacsen before 22.0.
  480. (put 'verilog-highlight-translate-off 'safe-local-variable 'verilog-booleanp)
  481. (defcustom verilog-auto-lineup 'declarations
  482. "Type of statements to lineup across multiple lines.
  483. If `all' is selected, then all line ups described below are done.
  484. If `declarations', then just declarations are lined up with any
  485. preceding declarations, taking into account widths and the like,
  486. so or example the code:
  487. reg [31:0] a;
  488. reg b;
  489. would become
  490. reg [31:0] a;
  491. reg b;
  492. If `assignment', then assignments are lined up with any preceding
  493. assignments, so for example the code
  494. a_long_variable <= b + c;
  495. d = e + f;
  496. would become
  497. a_long_variable <= b + c;
  498. d = e + f;
  499. In order to speed up editing, large blocks of statements are lined up
  500. only when a \\[verilog-pretty-expr] is typed; and large blocks of declarations
  501. are lineup only when \\[verilog-pretty-declarations] is typed."
  502. :type '(radio (const :tag "Line up Assignments and Declarations" all)
  503. (const :tag "Line up Assignment statements" assignments )
  504. (const :tag "Line up Declarations" declarations)
  505. (function :tag "Other"))
  506. :group 'verilog-mode-indent )
  507. (put 'verilog-auto-lineup 'safe-local-variable
  508. '(lambda (x) (memq x '(nil all assignments declarations))))
  509. (defcustom verilog-indent-level 3
  510. "Indentation of Verilog statements with respect to containing block."
  511. :group 'verilog-mode-indent
  512. :type 'integer)
  513. (put 'verilog-indent-level 'safe-local-variable 'integerp)
  514. (defcustom verilog-indent-level-module 3
  515. "Indentation of Module level Verilog statements (eg always, initial).
  516. Set to 0 to get initial and always statements lined up on the left side of
  517. your screen."
  518. :group 'verilog-mode-indent
  519. :type 'integer)
  520. (put 'verilog-indent-level-module 'safe-local-variable 'integerp)
  521. (defcustom verilog-indent-level-declaration 3
  522. "Indentation of declarations with respect to containing block.
  523. Set to 0 to get them list right under containing block."
  524. :group 'verilog-mode-indent
  525. :type 'integer)
  526. (put 'verilog-indent-level-declaration 'safe-local-variable 'integerp)
  527. (defcustom verilog-indent-declaration-macros nil
  528. "How to treat macro expansions in a declaration.
  529. If nil, indent as:
  530. input [31:0] a;
  531. input \\=`CP;
  532. output c;
  533. If non nil, treat as:
  534. input [31:0] a;
  535. input \\=`CP ;
  536. output c;"
  537. :group 'verilog-mode-indent
  538. :type 'boolean)
  539. (put 'verilog-indent-declaration-macros 'safe-local-variable 'verilog-booleanp)
  540. (defcustom verilog-indent-lists t
  541. "How to treat indenting items in a list.
  542. If t (the default), indent as:
  543. always @( posedge a or
  544. reset ) begin
  545. If nil, treat as:
  546. always @( posedge a or
  547. reset ) begin"
  548. :group 'verilog-mode-indent
  549. :type 'boolean)
  550. (put 'verilog-indent-lists 'safe-local-variable 'verilog-booleanp)
  551. (defcustom verilog-indent-level-behavioral 3
  552. "Absolute indentation of first begin in a task or function block.
  553. Set to 0 to get such code to start at the left side of the screen."
  554. :group 'verilog-mode-indent
  555. :type 'integer)
  556. (put 'verilog-indent-level-behavioral 'safe-local-variable 'integerp)
  557. (defcustom verilog-indent-level-directive 1
  558. "Indentation to add to each level of \\=`ifdef declarations.
  559. Set to 0 to have all directives start at the left side of the screen."
  560. :group 'verilog-mode-indent
  561. :type 'integer)
  562. (put 'verilog-indent-level-directive 'safe-local-variable 'integerp)
  563. (defcustom verilog-cexp-indent 2
  564. "Indentation of Verilog statements split across lines."
  565. :group 'verilog-mode-indent
  566. :type 'integer)
  567. (put 'verilog-cexp-indent 'safe-local-variable 'integerp)
  568. (defcustom verilog-case-indent 2
  569. "Indentation for case statements."
  570. :group 'verilog-mode-indent
  571. :type 'integer)
  572. (put 'verilog-case-indent 'safe-local-variable 'integerp)
  573. (defcustom verilog-auto-newline t
  574. "Non-nil means automatically newline after semicolons."
  575. :group 'verilog-mode-indent
  576. :type 'boolean)
  577. (put 'verilog-auto-newline 'safe-local-variable 'verilog-booleanp)
  578. (defcustom verilog-auto-indent-on-newline t
  579. "Non-nil means automatically indent line after newline."
  580. :group 'verilog-mode-indent
  581. :type 'boolean)
  582. (put 'verilog-auto-indent-on-newline 'safe-local-variable 'verilog-booleanp)
  583. (defcustom verilog-tab-always-indent t
  584. "Non-nil means TAB should always re-indent the current line.
  585. A nil value means TAB will only reindent when at the beginning of the line."
  586. :group 'verilog-mode-indent
  587. :type 'boolean)
  588. (put 'verilog-tab-always-indent 'safe-local-variable 'verilog-booleanp)
  589. (defcustom verilog-tab-to-comment nil
  590. "Non-nil means TAB moves to the right hand column in preparation for a comment."
  591. :group 'verilog-mode-actions
  592. :type 'boolean)
  593. (put 'verilog-tab-to-comment 'safe-local-variable 'verilog-booleanp)
  594. (defcustom verilog-indent-begin-after-if t
  595. "Non-nil means indent begin statements following if, else, while, etc.
  596. Otherwise, line them up."
  597. :group 'verilog-mode-indent
  598. :type 'boolean)
  599. (put 'verilog-indent-begin-after-if 'safe-local-variable 'verilog-booleanp)
  600. (defcustom verilog-align-ifelse nil
  601. "Non-nil means align `else' under matching `if'.
  602. Otherwise else is lined up with first character on line holding matching if."
  603. :group 'verilog-mode-indent
  604. :type 'boolean)
  605. (put 'verilog-align-ifelse 'safe-local-variable 'verilog-booleanp)
  606. (defcustom verilog-minimum-comment-distance 10
  607. "Minimum distance (in lines) between begin and end required before a comment.
  608. Setting this variable to zero results in every end acquiring a comment; the
  609. default avoids too many redundant comments in tight quarters."
  610. :group 'verilog-mode-indent
  611. :type 'integer)
  612. (put 'verilog-minimum-comment-distance 'safe-local-variable 'integerp)
  613. (defcustom verilog-highlight-p1800-keywords nil
  614. "Non-nil means highlight words newly reserved by IEEE-1800.
  615. These will appear in `verilog-font-lock-p1800-face' in order to gently
  616. suggest changing where these words are used as variables to something else.
  617. A nil value means highlight these words as appropriate for the SystemVerilog
  618. IEEE-1800 standard. Note that changing this will require restarting Emacs
  619. to see the effect as font color choices are cached by Emacs."
  620. :group 'verilog-mode-indent
  621. :type 'boolean)
  622. (put 'verilog-highlight-p1800-keywords 'safe-local-variable 'verilog-booleanp)
  623. (defcustom verilog-highlight-grouping-keywords nil
  624. "Non-nil means highlight grouping keywords more dramatically.
  625. If false, these words are in the `font-lock-type-face'; if True
  626. then they are in `verilog-font-lock-grouping-keywords-face'.
  627. Some find that special highlighting on these grouping constructs
  628. allow the structure of the code to be understood at a glance."
  629. :group 'verilog-mode-indent
  630. :type 'boolean)
  631. (put 'verilog-highlight-grouping-keywords 'safe-local-variable 'verilog-booleanp)
  632. (defcustom verilog-highlight-modules nil
  633. "Non-nil means highlight module statements for `verilog-load-file-at-point'.
  634. When true, mousing over module names will allow jumping to the
  635. module definition. If false, this is not supported. Setting
  636. this is experimental, and may lead to bad performance."
  637. :group 'verilog-mode-indent
  638. :type 'boolean)
  639. (put 'verilog-highlight-modules 'safe-local-variable 'verilog-booleanp)
  640. (defcustom verilog-highlight-includes t
  641. "Non-nil means highlight module statements for `verilog-load-file-at-point'.
  642. When true, mousing over include file names will allow jumping to the
  643. file referenced. If false, this is not supported."
  644. :group 'verilog-mode-indent
  645. :type 'boolean)
  646. (put 'verilog-highlight-includes 'safe-local-variable 'verilog-booleanp)
  647. (defcustom verilog-auto-declare-nettype nil
  648. "Non-nil specifies the data type to use with `verilog-auto-input' etc.
  649. Set this to \"wire\" if the Verilog code uses \"\\=`default_nettype
  650. none\". Note using \\=`default_nettype none isn't recommended practice; this
  651. mode is experimental."
  652. :version "24.1" ; rev670
  653. :group 'verilog-mode-actions
  654. :type 'boolean)
  655. (put 'verilog-auto-declare-nettype 'safe-local-variable `stringp)
  656. (defcustom verilog-auto-wire-type nil
  657. "Non-nil specifies the data type to use with `verilog-auto-wire' etc.
  658. Set this to \"logic\" for SystemVerilog code, or use `verilog-auto-logic'."
  659. :version "24.1" ; rev673
  660. :group 'verilog-mode-actions
  661. :type 'boolean)
  662. (put 'verilog-auto-wire-type 'safe-local-variable `stringp)
  663. (defcustom verilog-auto-endcomments t
  664. "Non-nil means insert a comment /* ... */ after 'end's.
  665. The name of the function or case will be set between the braces."
  666. :group 'verilog-mode-actions
  667. :type 'boolean)
  668. (put 'verilog-auto-endcomments 'safe-local-variable 'verilog-booleanp)
  669. (defcustom verilog-auto-delete-trailing-whitespace nil
  670. "Non-nil means to `delete-trailing-whitespace' in `verilog-auto'."
  671. :version "24.1" ; rev703
  672. :group 'verilog-mode-actions
  673. :type 'boolean)
  674. (put 'verilog-auto-delete-trailing-whitespace 'safe-local-variable 'verilog-booleanp)
  675. (defcustom verilog-auto-ignore-concat nil
  676. "Non-nil means ignore signals in {...} concatenations for AUTOWIRE etc.
  677. This will exclude signals referenced as pin connections in {...}
  678. from AUTOWIRE, AUTOOUTPUT and friends. This flag should be set
  679. for backward compatibility only and not set in new designs; it
  680. may be removed in future versions."
  681. :group 'verilog-mode-actions
  682. :type 'boolean)
  683. (put 'verilog-auto-ignore-concat 'safe-local-variable 'verilog-booleanp)
  684. (defcustom verilog-auto-read-includes nil
  685. "Non-nil means to automatically read includes before AUTOs.
  686. This will do a `verilog-read-defines' and `verilog-read-includes' before
  687. each AUTO expansion. This makes it easier to embed defines and includes,
  688. but can result in very slow reading times if there are many or large
  689. include files."
  690. :group 'verilog-mode-actions
  691. :type 'boolean)
  692. (put 'verilog-auto-read-includes 'safe-local-variable 'verilog-booleanp)
  693. (defcustom verilog-auto-save-policy nil
  694. "Non-nil indicates action to take when saving a Verilog buffer with AUTOs.
  695. A value of `force' will always do a \\[verilog-auto] automatically if
  696. needed on every save. A value of `detect' will do \\[verilog-auto]
  697. automatically when it thinks necessary. A value of `ask' will query the
  698. user when it thinks updating is needed.
  699. You should not rely on the 'ask or 'detect policies, they are safeguards
  700. only. They do not detect when AUTOINSTs need to be updated because a
  701. sub-module's port list has changed."
  702. :group 'verilog-mode-actions
  703. :type '(choice (const nil) (const ask) (const detect) (const force)))
  704. (defcustom verilog-auto-star-expand t
  705. "Non-nil means to expand SystemVerilog .* instance ports.
  706. They will be expanded in the same way as if there was an AUTOINST in the
  707. instantiation. See also `verilog-auto-star' and `verilog-auto-star-save'."
  708. :group 'verilog-mode-actions
  709. :type 'boolean)
  710. (put 'verilog-auto-star-expand 'safe-local-variable 'verilog-booleanp)
  711. (defcustom verilog-auto-star-save nil
  712. "Non-nil means save to disk SystemVerilog .* instance expansions.
  713. A nil value indicates direct connections will be removed before saving.
  714. Only meaningful to those created due to `verilog-auto-star-expand' being set.
  715. Instead of setting this, you may want to use /*AUTOINST*/, which will
  716. always be saved."
  717. :group 'verilog-mode-actions
  718. :type 'boolean)
  719. (put 'verilog-auto-star-save 'safe-local-variable 'verilog-booleanp)
  720. (defvar verilog-auto-update-tick nil
  721. "Modification tick at which autos were last performed.")
  722. (defvar verilog-auto-last-file-locals nil
  723. "Text from file-local-variables during last evaluation.")
  724. (defvar verilog-diff-function 'verilog-diff-report
  725. "Function to run when `verilog-diff-auto' detects differences.
  726. Function takes three arguments, the original buffer, the
  727. difference buffer, and the point in original buffer with the
  728. first difference.")
  729. ;;; Compile support:
  730. ;;
  731. (require 'compile)
  732. (defvar verilog-error-regexp-added nil)
  733. (defvar verilog-error-regexp-emacs-alist
  734. '(
  735. (verilog-xl-1
  736. "\\(Error\\|Warning\\)!.*\n?.*\"\\([^\"]+\\)\", \\([0-9]+\\)" 2 3)
  737. (verilog-xl-2
  738. "([WE][0-9A-Z]+)[ \t]+\\([^ \t\n,]+\\)[, \t]+\\(line[ \t]+\\)?\\([0-9]+\\):.*$" 1 3)
  739. (verilog-IES
  740. ".*\\*[WE],[0-9A-Z]+\\(\\[[0-9A-Z_,]+\\]\\)? (\\([^ \t,]+\\),\\([0-9]+\\)" 2 3)
  741. (verilog-surefire-1
  742. "[^\n]*\\[\\([^:]+\\):\\([0-9]+\\)\\]" 1 2)
  743. (verilog-surefire-2
  744. "\\(WARNING\\|ERROR\\|INFO\\)[^:]*: \\([^,]+\\),\\s-+\\(line \\)?\\([0-9]+\\):" 2 4 )
  745. (verilog-verbose
  746. "\
  747. \\([a-zA-Z]?:?[^:( \t\n]+\\)[:(][ \t]*\\([0-9]+\\)\\([) \t]\\|\
  748. :\\([^0-9\n]\\|\\([0-9]+:\\)\\)\\)" 1 2 5)
  749. (verilog-xsim
  750. "\\(Error\\|Warning\\).*in file (\\([^ \t]+\\) at line *\\([0-9]+\\))" 2 3)
  751. (verilog-vcs-1
  752. "\\(Error\\|Warning\\):[^(]*(\\([^ \t]+\\) line *\\([0-9]+\\))" 2 3)
  753. (verilog-vcs-2
  754. "Warning:.*(port.*(\\([^ \t]+\\) line \\([0-9]+\\))" 1 2)
  755. (verilog-vcs-3
  756. "\\(Error\\|Warning\\):[\n.]*\\([^ \t]+\\) *\\([0-9]+\\):" 2 3)
  757. (verilog-vcs-4
  758. "syntax error:.*\n\\([^ \t]+\\) *\\([0-9]+\\):" 1 2)
  759. (verilog-verilator
  760. "%?\\(Error\\|Warning\\)\\(-[^:]+\\|\\):[\n ]*\\([^ \t:]+\\):\\([0-9]+\\):" 3 4)
  761. (verilog-leda
  762. "^In file \\([^ \t]+\\)[ \t]+line[ \t]+\\([0-9]+\\):\n[^\n]*\n[^\n]*\n\\(Warning\\|Error\\|Failure\\)[^\n]*" 1 2)
  763. )
  764. "List of regexps for Verilog compilers.
  765. See `compilation-error-regexp-alist' for the formatting. For Emacs 22+.")
  766. (defvar verilog-error-regexp-xemacs-alist
  767. ;; Emacs form is '((v-tool "re" 1 2) ...)
  768. ;; XEmacs form is '(verilog ("re" 1 2) ...)
  769. ;; So we can just map from Emacs to XEmacs
  770. (cons 'verilog (mapcar 'cdr verilog-error-regexp-emacs-alist))
  771. "List of regexps for Verilog compilers.
  772. See `compilation-error-regexp-alist-alist' for the formatting. For XEmacs.")
  773. (defvar verilog-error-font-lock-keywords
  774. '(
  775. ;; verilog-xl-1
  776. ("\\(Error\\|Warning\\)!.*\n?.*\"\\([^\"]+\\)\", \\([0-9]+\\)" 2 bold t)
  777. ("\\(Error\\|Warning\\)!.*\n?.*\"\\([^\"]+\\)\", \\([0-9]+\\)" 2 bold t)
  778. ;; verilog-xl-2
  779. ("([WE][0-9A-Z]+)[ \t]+\\([^ \t\n,]+\\)[, \t]+\\(line[ \t]+\\)?\\([0-9]+\\):.*$" 1 bold t)
  780. ("([WE][0-9A-Z]+)[ \t]+\\([^ \t\n,]+\\)[, \t]+\\(line[ \t]+\\)?\\([0-9]+\\):.*$" 3 bold t)
  781. ;; verilog-IES (nc-verilog)
  782. (".*\\*[WE],[0-9A-Z]+\\(\\[[0-9A-Z_,]+\\]\\)? (\\([^ \t,]+\\),\\([0-9]+\\)|" 2 bold t)
  783. (".*\\*[WE],[0-9A-Z]+\\(\\[[0-9A-Z_,]+\\]\\)? (\\([^ \t,]+\\),\\([0-9]+\\)|" 3 bold t)
  784. ;; verilog-surefire-1
  785. ("[^\n]*\\[\\([^:]+\\):\\([0-9]+\\)\\]" 1 bold t)
  786. ("[^\n]*\\[\\([^:]+\\):\\([0-9]+\\)\\]" 2 bold t)
  787. ;; verilog-surefire-2
  788. ("\\(WARNING\\|ERROR\\|INFO\\): \\([^,]+\\), line \\([0-9]+\\):" 2 bold t)
  789. ("\\(WARNING\\|ERROR\\|INFO\\): \\([^,]+\\), line \\([0-9]+\\):" 3 bold t)
  790. ;; verilog-verbose
  791. ("\
  792. \\([a-zA-Z]?:?[^:( \t\n]+\\)[:(][ \t]*\\([0-9]+\\)\\([) \t]\\|\
  793. :\\([^0-9\n]\\|\\([0-9]+:\\)\\)\\)" 1 bold t)
  794. ("\
  795. \\([a-zA-Z]?:?[^:( \t\n]+\\)[:(][ \t]*\\([0-9]+\\)\\([) \t]\\|\
  796. :\\([^0-9\n]\\|\\([0-9]+:\\)\\)\\)" 1 bold t)
  797. ;; verilog-vcs-1
  798. ("\\(Error\\|Warning\\):[^(]*(\\([^ \t]+\\) line *\\([0-9]+\\))" 2 bold t)
  799. ("\\(Error\\|Warning\\):[^(]*(\\([^ \t]+\\) line *\\([0-9]+\\))" 3 bold t)
  800. ;; verilog-vcs-2
  801. ("Warning:.*(port.*(\\([^ \t]+\\) line \\([0-9]+\\))" 1 bold t)
  802. ("Warning:.*(port.*(\\([^ \t]+\\) line \\([0-9]+\\))" 1 bold t)
  803. ;; verilog-vcs-3
  804. ("\\(Error\\|Warning\\):[\n.]*\\([^ \t]+\\) *\\([0-9]+\\):" 2 bold t)
  805. ("\\(Error\\|Warning\\):[\n.]*\\([^ \t]+\\) *\\([0-9]+\\):" 3 bold t)
  806. ;; verilog-vcs-4
  807. ("syntax error:.*\n\\([^ \t]+\\) *\\([0-9]+\\):" 1 bold t)
  808. ("syntax error:.*\n\\([^ \t]+\\) *\\([0-9]+\\):" 2 bold t)
  809. ;; verilog-verilator
  810. (".*%?\\(Error\\|Warning\\)\\(-[^:]+\\|\\):[\n ]*\\([^ \t:]+\\):\\([0-9]+\\):" 3 bold t)
  811. (".*%?\\(Error\\|Warning\\)\\(-[^:]+\\|\\):[\n ]*\\([^ \t:]+\\):\\([0-9]+\\):" 4 bold t)
  812. ;; verilog-leda
  813. ("^In file \\([^ \t]+\\)[ \t]+line[ \t]+\\([0-9]+\\):\n[^\n]*\n[^\n]*\n\\(Warning\\|Error\\|Failure\\)[^\n]*" 1 bold t)
  814. ("^In file \\([^ \t]+\\)[ \t]+line[ \t]+\\([0-9]+\\):\n[^\n]*\n[^\n]*\n\\(Warning\\|Error\\|Failure\\)[^\n]*" 2 bold t)
  815. )
  816. "Keywords to also highlight in Verilog *compilation* buffers.
  817. Only used in XEmacs; GNU Emacs uses `verilog-error-regexp-emacs-alist'.")
  818. (defcustom verilog-library-flags '("")
  819. "List of standard Verilog arguments to use for /*AUTOINST*/.
  820. These arguments are used to find files for `verilog-auto', and match
  821. the flags accepted by a standard Verilog-XL simulator.
  822. -f filename Reads more `verilog-library-flags' from the filename.
  823. +incdir+dir Adds the directory to `verilog-library-directories'.
  824. -Idir Adds the directory to `verilog-library-directories'.
  825. -y dir Adds the directory to `verilog-library-directories'.
  826. +libext+.v Adds the extensions to `verilog-library-extensions'.
  827. -v filename Adds the filename to `verilog-library-files'.
  828. filename Adds the filename to `verilog-library-files'.
  829. This is not recommended, -v is a better choice.
  830. You might want these defined in each file; put at the *END* of your file
  831. something like:
  832. // Local Variables:
  833. // verilog-library-flags:(\"-y dir -y otherdir\")
  834. // End:
  835. Verilog-mode attempts to detect changes to this local variable, but they
  836. are only insured to be correct when the file is first visited. Thus if you
  837. have problems, use \\[find-alternate-file] RET to have these take effect.
  838. See also the variables mentioned above."
  839. :group 'verilog-mode-auto
  840. :type '(repeat string))
  841. (put 'verilog-library-flags 'safe-local-variable 'listp)
  842. (defcustom verilog-library-directories '(".")
  843. "List of directories when looking for files for /*AUTOINST*/.
  844. The directory may be relative to the current file, or absolute.
  845. Environment variables are also expanded in the directory names.
  846. Having at least the current directory is a good idea.
  847. You might want these defined in each file; put at the *END* of your file
  848. something like:
  849. // Local Variables:
  850. // verilog-library-directories:(\".\" \"subdir\" \"subdir2\")
  851. // End:
  852. Verilog-mode attempts to detect changes to this local variable, but they
  853. are only insured to be correct when the file is first visited. Thus if you
  854. have problems, use \\[find-alternate-file] RET to have these take effect.
  855. See also `verilog-library-flags', `verilog-library-files'
  856. and `verilog-library-extensions'."
  857. :group 'verilog-mode-auto
  858. :type '(repeat file))
  859. (put 'verilog-library-directories 'safe-local-variable 'listp)
  860. (defcustom verilog-library-files '()
  861. "List of files to search for modules.
  862. AUTOINST will use this when it needs to resolve a module name.
  863. This is a complete path, usually to a technology file with many standard
  864. cells defined in it.
  865. You might want these defined in each file; put at the *END* of your file
  866. something like:
  867. // Local Variables:
  868. // verilog-library-files:(\"/some/path/technology.v\" \"/some/path/tech2.v\")
  869. // End:
  870. Verilog-mode attempts to detect changes to this local variable, but they
  871. are only insured to be correct when the file is first visited. Thus if you
  872. have problems, use \\[find-alternate-file] RET to have these take effect.
  873. See also `verilog-library-flags', `verilog-library-directories'."
  874. :group 'verilog-mode-auto
  875. :type '(repeat directory))
  876. (put 'verilog-library-files 'safe-local-variable 'listp)
  877. (defcustom verilog-library-extensions '(".v" ".sv")
  878. "List of extensions to use when looking for files for /*AUTOINST*/.
  879. See also `verilog-library-flags', `verilog-library-directories'."
  880. :type '(repeat string)
  881. :group 'verilog-mode-auto)
  882. (put 'verilog-library-extensions 'safe-local-variable 'listp)
  883. (defcustom verilog-active-low-regexp nil
  884. "If true, treat signals matching this regexp as active low.
  885. This is used for AUTORESET and AUTOTIEOFF. For proper behavior,
  886. you will probably also need `verilog-auto-reset-widths' set."
  887. :group 'verilog-mode-auto
  888. :type '(choice (const nil) regexp))
  889. (put 'verilog-active-low-regexp 'safe-local-variable 'stringp)
  890. (defcustom verilog-auto-sense-include-inputs nil
  891. "Non-nil means AUTOSENSE should include all inputs.
  892. If nil, only inputs that are NOT output signals in the same block are
  893. included."
  894. :group 'verilog-mode-auto
  895. :type 'boolean)
  896. (put 'verilog-auto-sense-include-inputs 'safe-local-variable 'verilog-booleanp)
  897. (defcustom verilog-auto-sense-defines-constant nil
  898. "Non-nil means AUTOSENSE should assume all defines represent constants.
  899. When true, the defines will not be included in sensitivity lists. To
  900. maintain compatibility with other sites, this should be set at the bottom
  901. of each Verilog file that requires it, rather than being set globally."
  902. :group 'verilog-mode-auto
  903. :type 'boolean)
  904. (put 'verilog-auto-sense-defines-constant 'safe-local-variable 'verilog-booleanp)
  905. (defcustom verilog-auto-reset-blocking-in-non t
  906. "Non-nil means AUTORESET will reset blocking statements.
  907. When true, AUTORESET will reset in blocking statements those
  908. signals which were assigned with blocking assignments (=) even in
  909. a block with non-blocking assignments (<=).
  910. If nil, all blocking assigned signals are ignored when any
  911. non-blocking assignment is in the AUTORESET block. This allows
  912. blocking assignments to be used for temporary values and not have
  913. those temporaries reset. See example in `verilog-auto-reset'."
  914. :version "24.1" ; rev718
  915. :type 'boolean
  916. :group 'verilog-mode-auto)
  917. (put 'verilog-auto-reset-blocking-in-non 'safe-local-variable 'verilog-booleanp)
  918. (defcustom verilog-auto-reset-widths t
  919. "True means AUTORESET should determine the width of signals.
  920. This is then used to set the width of the zero (32'h0 for example). This
  921. is required by some lint tools that aren't smart enough to ignore widths of
  922. the constant zero. This may result in ugly code when parameters determine
  923. the MSB or LSB of a signal inside an AUTORESET.
  924. If nil, AUTORESET uses \"0\" as the constant.
  925. If `unbased', AUTORESET used the unbased unsized literal \"\\='0\"
  926. as the constant. This setting is strongly recommended for
  927. SystemVerilog designs."
  928. :type 'boolean
  929. :group 'verilog-mode-auto)
  930. (put 'verilog-auto-reset-widths 'safe-local-variable
  931. '(lambda (x) (memq x '(nil t unbased))))
  932. (defcustom verilog-assignment-delay ""
  933. "Text used for delays in delayed assignments. Add a trailing space if set."
  934. :group 'verilog-mode-auto
  935. :type 'string)
  936. (put 'verilog-assignment-delay 'safe-local-variable 'stringp)
  937. (defcustom verilog-auto-arg-format 'packed
  938. "Formatting to use for AUTOARG signal names.
  939. If `packed', then as many inputs and outputs that fit within
  940. `fill-column' will be put onto one line.
  941. If `single', then a single input or output will be put onto each
  942. line."
  943. :version "25.1"
  944. :type '(radio (const :tag "Line up Assignments and Declarations" packed)
  945. (const :tag "Line up Assignment statements" single))
  946. :group 'verilog-mode-auto)
  947. (put 'verilog-auto-arg-format 'safe-local-variable
  948. '(lambda (x) (memq x '(packed single))))
  949. (defcustom verilog-auto-arg-sort nil
  950. "Non-nil means AUTOARG signal names will be sorted, not in declaration order.
  951. Declaration order is advantageous with order based instantiations
  952. and is the default for backward compatibility. Sorted order
  953. reduces changes when declarations are moved around in a file, and
  954. it's bad practice to rely on order based instantiations anyhow.
  955. See also `verilog-auto-inst-sort'."
  956. :group 'verilog-mode-auto
  957. :type 'boolean)
  958. (put 'verilog-auto-arg-sort 'safe-local-variable 'verilog-booleanp)
  959. (defcustom verilog-auto-inst-dot-name nil
  960. "Non-nil means when creating ports with AUTOINST, use .name syntax.
  961. This will use \".port\" instead of \".port(port)\" when possible.
  962. This is only legal in SystemVerilog files, and will confuse older
  963. simulators. Setting `verilog-auto-inst-vector' to nil may also
  964. be desirable to increase how often .name will be used."
  965. :group 'verilog-mode-auto
  966. :type 'boolean)
  967. (put 'verilog-auto-inst-dot-name 'safe-local-variable 'verilog-booleanp)
  968. (defcustom verilog-auto-inst-param-value nil
  969. "Non-nil means AUTOINST will replace parameters with the parameter value.
  970. If nil, leave parameters as symbolic names.
  971. Parameters must be in Verilog 2001 format #(...), and if a parameter is not
  972. listed as such there (as when the default value is acceptable), it will not
  973. be replaced, and will remain symbolic.
  974. For example, imagine a submodule uses parameters to declare the size of its
  975. inputs. This is then used by an upper module:
  976. module InstModule (o,i);
  977. parameter WIDTH;
  978. input [WIDTH-1:0] i;
  979. endmodule
  980. module ExampInst;
  981. InstModule
  982. #(.PARAM(10))
  983. instName
  984. (/*AUTOINST*/
  985. .i (i[PARAM-1:0]));
  986. Note even though PARAM=10, the AUTOINST has left the parameter as a
  987. symbolic name. If `verilog-auto-inst-param-value' is set, this will
  988. instead expand to:
  989. module ExampInst;
  990. InstModule
  991. #(.PARAM(10))
  992. instName
  993. (/*AUTOINST*/
  994. .i (i[9:0]));"
  995. :group 'verilog-mode-auto
  996. :type 'boolean)
  997. (put 'verilog-auto-inst-param-value 'safe-local-variable 'verilog-booleanp)
  998. (defcustom verilog-auto-inst-sort nil
  999. "Non-nil means AUTOINST signals will be sorted, not in declaration order.
  1000. Also affects AUTOINSTPARAM. Declaration order is the default for
  1001. backward compatibility, and as some teams prefer signals that are
  1002. declared together to remain together. Sorted order reduces
  1003. changes when declarations are moved around in a file.
  1004. See also `verilog-auto-arg-sort'."
  1005. :version "24.1" ; rev688
  1006. :group 'verilog-mode-auto
  1007. :type 'boolean)
  1008. (put 'verilog-auto-inst-sort 'safe-local-variable 'verilog-booleanp)
  1009. (defcustom verilog-auto-inst-vector t
  1010. "Non-nil means when creating default ports with AUTOINST, use bus subscripts.
  1011. If nil, skip the subscript when it matches the entire bus as declared in
  1012. the module (AUTOWIRE signals always are subscripted, you must manually
  1013. declare the wire to have the subscripts removed.) Setting this to nil may
  1014. speed up some simulators, but is less general and harder to read, so avoid."
  1015. :group 'verilog-mode-auto
  1016. :type 'boolean)
  1017. (put 'verilog-auto-inst-vector 'safe-local-variable 'verilog-booleanp)
  1018. (defcustom verilog-auto-inst-template-numbers nil
  1019. "If true, when creating templated ports with AUTOINST, add a comment.
  1020. If t, the comment will add the line number of the template that
  1021. was used for that port declaration. This setting is suggested
  1022. only for debugging use, as regular use may cause a large numbers
  1023. of merge conflicts.
  1024. If `lhs', the comment will show the left hand side of the
  1025. AUTO_TEMPLATE rule that is matched. This is less precise than
  1026. numbering (t) when multiple rules have the same pin name, but
  1027. won't merge conflict."
  1028. :group 'verilog-mode-auto
  1029. :type '(choice (const nil) (const t) (const lhs)))
  1030. (put 'verilog-auto-inst-template-numbers 'safe-local-variable
  1031. '(lambda (x) (memq x '(nil t lhs))))
  1032. (defcustom verilog-auto-inst-column 40
  1033. "Indent-to column number for net name part of AUTOINST created pin."
  1034. :group 'verilog-mode-indent
  1035. :type 'integer)
  1036. (put 'verilog-auto-inst-column 'safe-local-variable 'integerp)
  1037. (defcustom verilog-auto-inst-interfaced-ports nil
  1038. "Non-nil means include interfaced ports in AUTOINST expansions."
  1039. :version "24.3" ; rev773, default change rev815
  1040. :group 'verilog-mode-auto
  1041. :type 'boolean)
  1042. (put 'verilog-auto-inst-interfaced-ports 'safe-local-variable 'verilog-booleanp)
  1043. (defcustom verilog-auto-input-ignore-regexp nil
  1044. "If non-nil, when creating AUTOINPUT, ignore signals matching this regexp.
  1045. See the \\[verilog-faq] for examples on using this."
  1046. :group 'verilog-mode-auto
  1047. :type '(choice (const nil) regexp))
  1048. (put 'verilog-auto-input-ignore-regexp 'safe-local-variable 'stringp)
  1049. (defcustom verilog-auto-inout-ignore-regexp nil
  1050. "If non-nil, when creating AUTOINOUT, ignore signals matching this regexp.
  1051. See the \\[verilog-faq] for examples on using this."
  1052. :group 'verilog-mode-auto
  1053. :type '(choice (const nil) regexp))
  1054. (put 'verilog-auto-inout-ignore-regexp 'safe-local-variable 'stringp)
  1055. (defcustom verilog-auto-output-ignore-regexp nil
  1056. "If non-nil, when creating AUTOOUTPUT, ignore signals matching this regexp.
  1057. See the \\[verilog-faq] for examples on using this."
  1058. :group 'verilog-mode-auto
  1059. :type '(choice (const nil) regexp))
  1060. (put 'verilog-auto-output-ignore-regexp 'safe-local-variable 'stringp)
  1061. (defcustom verilog-auto-template-warn-unused nil
  1062. "Non-nil means report warning if an AUTO_TEMPLATE line is not used.
  1063. This feature is not supported before Emacs 21.1 or XEmacs 21.4."
  1064. :version "24.3" ; rev787
  1065. :group 'verilog-mode-auto
  1066. :type 'boolean)
  1067. (put 'verilog-auto-template-warn-unused 'safe-local-variable 'verilog-booleanp)
  1068. (defcustom verilog-auto-tieoff-declaration "wire"
  1069. "Data type used for the declaration for AUTOTIEOFF.
  1070. If \"wire\" then create a wire, if \"assign\" create an
  1071. assignment, else the data type for variable creation."
  1072. :version "24.1" ; rev713
  1073. :group 'verilog-mode-auto
  1074. :type 'string)
  1075. (put 'verilog-auto-tieoff-declaration 'safe-local-variable 'stringp)
  1076. (defcustom verilog-auto-tieoff-ignore-regexp nil
  1077. "If non-nil, when creating AUTOTIEOFF, ignore signals matching this regexp.
  1078. See the \\[verilog-faq] for examples on using this."
  1079. :group 'verilog-mode-auto
  1080. :type '(choice (const nil) regexp))
  1081. (put 'verilog-auto-tieoff-ignore-regexp 'safe-local-variable 'stringp)
  1082. (defcustom verilog-auto-unused-ignore-regexp nil
  1083. "If non-nil, when creating AUTOUNUSED, ignore signals matching this regexp.
  1084. See the \\[verilog-faq] for examples on using this."
  1085. :group 'verilog-mode-auto
  1086. :type '(choice (const nil) regexp))
  1087. (put 'verilog-auto-unused-ignore-regexp 'safe-local-variable 'stringp)
  1088. (defcustom verilog-case-fold t
  1089. "Non-nil means `verilog-mode' regexps should ignore case.
  1090. This variable is t for backward compatibility; nil is suggested."
  1091. :version "24.4"
  1092. :group 'verilog-mode
  1093. :type 'boolean)
  1094. (put 'verilog-case-fold 'safe-local-variable 'verilog-booleanp)
  1095. (defcustom verilog-typedef-regexp nil
  1096. "If non-nil, regular expression that matches Verilog-2001 typedef names.
  1097. For example, \"_t$\" matches typedefs named with _t, as in the C language.
  1098. See also `verilog-case-fold'."
  1099. :group 'verilog-mode-auto
  1100. :type '(choice (const nil) regexp))
  1101. (put 'verilog-typedef-regexp 'safe-local-variable 'stringp)
  1102. (defcustom verilog-mode-hook 'verilog-set-compile-command
  1103. "Hook run after Verilog mode is loaded."
  1104. :type 'hook
  1105. :group 'verilog-mode)
  1106. (defcustom verilog-auto-hook nil
  1107. "Hook run after `verilog-mode' updates AUTOs."
  1108. :group 'verilog-mode-auto
  1109. :type 'hook)
  1110. (defcustom verilog-before-auto-hook nil
  1111. "Hook run before `verilog-mode' updates AUTOs."
  1112. :group 'verilog-mode-auto
  1113. :type 'hook)
  1114. (defcustom verilog-delete-auto-hook nil
  1115. "Hook run after `verilog-mode' deletes AUTOs."
  1116. :group 'verilog-mode-auto
  1117. :type 'hook)
  1118. (defcustom verilog-before-delete-auto-hook nil
  1119. "Hook run before `verilog-mode' deletes AUTOs."
  1120. :group 'verilog-mode-auto
  1121. :type 'hook)
  1122. (defcustom verilog-getopt-flags-hook nil
  1123. "Hook run after `verilog-getopt-flags' determines the Verilog option lists."
  1124. :group 'verilog-mode-auto
  1125. :type 'hook)
  1126. (defcustom verilog-before-getopt-flags-hook nil
  1127. "Hook run before `verilog-getopt-flags' determines the Verilog option lists."
  1128. :group 'verilog-mode-auto
  1129. :type 'hook)
  1130. (defcustom verilog-before-save-font-hook nil
  1131. "Hook run before `verilog-save-font-mods' removes highlighting."
  1132. :version "24.3" ; rev735
  1133. :group 'verilog-mode-auto
  1134. :type 'hook)
  1135. (defcustom verilog-after-save-font-hook nil
  1136. "Hook run after `verilog-save-font-mods' restores highlighting."
  1137. :version "24.3" ; rev735
  1138. :group 'verilog-mode-auto
  1139. :type 'hook)
  1140. (defvar verilog-imenu-generic-expression
  1141. '((nil "^\\s-*\\(\\(m\\(odule\\|acromodule\\)\\)\\|primitive\\)\\s-+\\([a-zA-Z0-9_.:]+\\)" 4)
  1142. ("*Vars*" "^\\s-*\\(reg\\|wire\\)\\s-+\\(\\|\\[[^]]+\\]\\s-+\\)\\([A-Za-z0-9_]+\\)" 3))
  1143. "Imenu expression for Verilog mode. See `imenu-generic-expression'.")
  1144. ;;
  1145. ;; provide a verilog-header function.
  1146. ;; Customization variables:
  1147. ;;
  1148. (defvar verilog-date-scientific-format nil
  1149. "If non-nil, dates are written in scientific format (e.g. 1997/09/17).
  1150. If nil, in European format (e.g. 17.09.1997). The brain-dead American
  1151. format (e.g. 09/17/1997) is not supported.")
  1152. (defvar verilog-company nil
  1153. "Default name of Company for Verilog header.
  1154. If set will become buffer local.")
  1155. (make-variable-buffer-local 'verilog-company)
  1156. (defvar verilog-project nil
  1157. "Default name of Project for Verilog header.
  1158. If set will become buffer local.")
  1159. (make-variable-buffer-local 'verilog-project)
  1160. ;;; Keymap and Menu:
  1161. ;;
  1162. (defvar verilog-mode-map
  1163. (let ((map (make-sparse-keymap)))
  1164. (define-key map ";" 'electric-verilog-semi)
  1165. (define-key map [(control 59)] 'electric-verilog-semi-with-comment)
  1166. (define-key map ":" 'electric-verilog-colon)
  1167. ;;(define-key map "=" 'electric-verilog-equal)
  1168. (define-key map "`" 'electric-verilog-tick)
  1169. (define-key map "\t" 'electric-verilog-tab)
  1170. (define-key map "\r" 'electric-verilog-terminate-line)
  1171. ;; backspace/delete key bindings
  1172. (define-key map [backspace] 'backward-delete-char-untabify)
  1173. (unless (boundp 'delete-key-deletes-forward) ; XEmacs variable
  1174. (define-key map [delete] 'delete-char)
  1175. (define-key map [(meta delete)] 'kill-word))
  1176. (define-key map "\M-\C-b" 'electric-verilog-backward-sexp)
  1177. (define-key map "\M-\C-f" 'electric-verilog-forward-sexp)
  1178. (define-key map "\M-\r" `electric-verilog-terminate-and-indent)
  1179. (define-key map "\M-\t" 'verilog-complete-word)
  1180. (define-key map "\M-?" 'verilog-show-completions)
  1181. ;; Note \C-c and letter are reserved for users
  1182. (define-key map "\C-c`" 'verilog-lint-off)
  1183. (define-key map "\C-c*" 'verilog-delete-auto-star-implicit)
  1184. (define-key map "\C-c?" 'verilog-diff-auto)
  1185. (define-key map "\C-c\C-r" 'verilog-label-be)
  1186. (define-key map "\C-c\C-i" 'verilog-pretty-declarations)
  1187. (define-key map "\C-c=" 'verilog-pretty-expr)
  1188. (define-key map "\C-c\C-b" 'verilog-submit-bug-report)
  1189. (define-key map "\M-*" 'verilog-star-comment)
  1190. (define-key map "\C-c\C-c" 'verilog-comment-region)
  1191. (define-key map "\C-c\C-u" 'verilog-uncomment-region)
  1192. (when (featurep 'xemacs)
  1193. (define-key map [(meta control h)] 'verilog-mark-defun)
  1194. (define-key map "\M-\C-a" 'verilog-beg-of-defun)
  1195. (define-key map "\M-\C-e" 'verilog-end-of-defun))
  1196. (define-key map "\C-c\C-d" 'verilog-goto-defun)
  1197. (define-key map "\C-c\C-k" 'verilog-delete-auto)
  1198. (define-key map "\C-c\C-a" 'verilog-auto)
  1199. (define-key map "\C-c\C-s" 'verilog-auto-save-compile)
  1200. (define-key map "\C-c\C-p" 'verilog-preprocess)
  1201. (define-key map "\C-c\C-z" 'verilog-inject-auto)
  1202. (define-key map "\C-c\C-e" 'verilog-expand-vector)
  1203. (define-key map "\C-c\C-h" 'verilog-header)
  1204. map)
  1205. "Keymap used in Verilog mode.")
  1206. ;; menus
  1207. (easy-menu-define
  1208. verilog-menu verilog-mode-map "Menu for Verilog mode"
  1209. (verilog-easy-menu-filter
  1210. '("Verilog"
  1211. ("Choose Compilation Action"
  1212. ["None"
  1213. (progn
  1214. (setq verilog-tool nil)
  1215. (verilog-set-compile-command))
  1216. :style radio
  1217. :selected (equal verilog-tool nil)
  1218. :help "When invoking compilation, use compile-command"]
  1219. ["Lint"
  1220. (progn
  1221. (setq verilog-tool 'verilog-linter)
  1222. (verilog-set-compile-command))
  1223. :style radio
  1224. :selected (equal verilog-tool `verilog-linter)
  1225. :help "When invoking compilation, use lint checker"]
  1226. ["Coverage"
  1227. (progn
  1228. (setq verilog-tool 'verilog-coverage)
  1229. (verilog-set-compile-command))
  1230. :style radio
  1231. :selected (equal verilog-tool `verilog-coverage)
  1232. :help "When invoking compilation, annotate for coverage"]
  1233. ["Simulator"
  1234. (progn
  1235. (setq verilog-tool 'verilog-simulator)
  1236. (verilog-set-compile-command))
  1237. :style radio
  1238. :selected (equal verilog-tool `verilog-simulator)
  1239. :help "When invoking compilation, interpret Verilog source"]
  1240. ["Compiler"
  1241. (progn
  1242. (setq verilog-tool 'verilog-compiler)
  1243. (verilog-set-compile-command))
  1244. :style radio
  1245. :selected (equal verilog-tool `verilog-compiler)
  1246. :help "When invoking compilation, compile Verilog source"]
  1247. ["Preprocessor"
  1248. (progn
  1249. (setq verilog-tool 'verilog-preprocessor)
  1250. (verilog-set-compile-command))
  1251. :style radio
  1252. :selected (equal verilog-tool `verilog-preprocessor)
  1253. :help "When invoking compilation, preprocess Verilog source, see also `verilog-preprocess'"]
  1254. )
  1255. ("Move"
  1256. ["Beginning of function" verilog-beg-of-defun
  1257. :keys "C-M-a"
  1258. :help "Move backward to the beginning of the current function or procedure"]
  1259. ["End of function" verilog-end-of-defun
  1260. :keys "C-M-e"
  1261. :help "Move forward to the end of the current function or procedure"]
  1262. ["Mark function" verilog-mark-defun
  1263. :keys "C-M-h"
  1264. :help "Mark the current Verilog function or procedure"]
  1265. ["Goto function/module" verilog-goto-defun
  1266. :help "Move to specified Verilog module/task/function"]
  1267. ["Move to beginning of block" electric-verilog-backward-sexp
  1268. :help "Move backward over one balanced expression"]
  1269. ["Move to end of block" electric-verilog-forward-sexp
  1270. :help "Move forward over one balanced expression"]
  1271. )
  1272. ("Comments"
  1273. ["Comment Region" verilog-comment-region
  1274. :help "Put marked area into a comment"]
  1275. ["UnComment Region" verilog-uncomment-region
  1276. :help "Uncomment an area commented with Comment Region"]
  1277. ["Multi-line comment insert" verilog-star-comment
  1278. :help "Insert Verilog /* */ comment at point"]
  1279. ["Lint error to comment" verilog-lint-off
  1280. :help "Convert a Verilog linter warning line into a disable statement"]
  1281. )
  1282. "----"
  1283. ["Compile" compile
  1284. :help "Perform compilation-action (above) on the current buffer"]
  1285. ["AUTO, Save, Compile" verilog-auto-save-compile
  1286. :help "Recompute AUTOs, save buffer, and compile"]
  1287. ["Next Compile Error" next-error
  1288. :help "Visit next compilation error message and corresponding source code"]
  1289. ["Ignore Lint Warning at point" verilog-lint-off
  1290. :help "Convert a Verilog linter warning line into a disable statement"]
  1291. "----"
  1292. ["Line up declarations around point" verilog-pretty-declarations
  1293. :help "Line up declarations around point"]
  1294. ["Line up equations around point" verilog-pretty-expr
  1295. :help "Line up expressions around point"]
  1296. ["Redo/insert comments on every end" verilog-label-be
  1297. :help "Label matching begin ... end statements"]
  1298. ["Expand [x:y] vector line" verilog-expand-vector
  1299. :help "Take a signal vector on the current line and expand it to multiple lines"]
  1300. ["Insert begin-end block" verilog-insert-block
  1301. :help "Insert begin ... end"]
  1302. ["Complete word" verilog-complete-word
  1303. :help "Complete word at point"]
  1304. "----"
  1305. ["Recompute AUTOs" verilog-auto
  1306. :help "Expand AUTO meta-comment statements"]
  1307. ["Kill AUTOs" verilog-delete-auto
  1308. :help "Remove AUTO expansions"]
  1309. ["Diff AUTOs" verilog-diff-auto
  1310. :help "Show differences in AUTO expansions"]
  1311. ["Inject AUTOs" verilog-inject-auto
  1312. :help "Inject AUTOs into legacy non-AUTO buffer"]
  1313. ("AUTO Help..."
  1314. ["AUTO General" (describe-function 'verilog-auto)
  1315. :help "Help introduction on AUTOs"]
  1316. ["AUTO Library Flags" (describe-variable 'verilog-library-flags)
  1317. :help "Help on verilog-library-flags"]
  1318. ["AUTO Library Path" (describe-variable 'verilog-library-directories)
  1319. :help "Help on verilog-library-directories"]
  1320. ["AUTO Library Files" (describe-variable 'verilog-library-files)
  1321. :help "Help on verilog-library-files"]
  1322. ["AUTO Library Extensions" (describe-variable 'verilog-library-extensions)
  1323. :help "Help on verilog-library-extensions"]
  1324. ["AUTO `define Reading" (describe-function 'verilog-read-defines)
  1325. :help "Help on reading `defines"]
  1326. ["AUTO `include Reading" (describe-function 'verilog-read-includes)
  1327. :help "Help on parsing `includes"]
  1328. ["AUTOARG" (describe-function 'verilog-auto-arg)
  1329. :help "Help on AUTOARG - declaring module port list"]
  1330. ["AUTOASCIIENUM" (describe-function 'verilog-auto-ascii-enum)
  1331. :help "Help on AUTOASCIIENUM - creating ASCII for enumerations"]
  1332. ["AUTOASSIGNMODPORT" (describe-function 'verilog-auto-assign-modport)
  1333. :help "Help on AUTOASSIGNMODPORT - creating assignments to/from modports"]
  1334. ["AUTOINOUT" (describe-function 'verilog-auto-inout)
  1335. :help "Help on AUTOINOUT - adding inouts from cells"]
  1336. ["AUTOINOUTCOMP" (describe-function 'verilog-auto-inout-comp)
  1337. :help "Help on AUTOINOUTCOMP - copying complemented i/o from another file"]
  1338. ["AUTOINOUTIN" (describe-function 'verilog-auto-inout-in)
  1339. :help "Help on AUTOINOUTIN - copying i/o from another file as all inputs"]
  1340. ["AUTOINOUTMODPORT" (describe-function 'verilog-auto-inout-modport)
  1341. :help "Help on AUTOINOUTMODPORT - copying i/o from an interface modport"]
  1342. ["AUTOINOUTMODULE" (describe-function 'verilog-auto-inout-module)
  1343. :help "Help on AUTOINOUTMODULE - copying i/o from another file"]
  1344. ["AUTOINOUTPARAM" (describe-function 'verilog-auto-inout-param)
  1345. :help "Help on AUTOINOUTPARAM - copying parameters from another file"]
  1346. ["AUTOINPUT" (describe-function 'verilog-auto-input)
  1347. :help "Help on AUTOINPUT - adding inputs from cells"]
  1348. ["AUTOINSERTLISP" (describe-function 'verilog-auto-insert-lisp)
  1349. :help "Help on AUTOINSERTLISP - insert text from a lisp function"]
  1350. ["AUTOINSERTLAST" (describe-function 'verilog-auto-insert-last)
  1351. :help "Help on AUTOINSERTLISPLAST - insert text from a lisp function"]
  1352. ["AUTOINST" (describe-function 'verilog-auto-inst)
  1353. :help "Help on AUTOINST - adding pins for cells"]
  1354. ["AUTOINST (.*)" (describe-function 'verilog-auto-star)
  1355. :help "Help on expanding Verilog-2001 .* pins"]
  1356. ["AUTOINSTPARAM" (describe-function 'verilog-auto-inst-param)
  1357. :help "Help on AUTOINSTPARAM - adding parameter pins to cells"]
  1358. ["AUTOLOGIC" (describe-function 'verilog-auto-logic)
  1359. :help "Help on AUTOLOGIC - declaring logic signals"]
  1360. ["AUTOOUTPUT" (describe-function 'verilog-auto-output)
  1361. :help "Help on AUTOOUTPUT - adding outputs from cells"]
  1362. ["AUTOOUTPUTEVERY" (describe-function 'verilog-auto-output-every)
  1363. :help "Help on AUTOOUTPUTEVERY - adding outputs of all signals"]
  1364. ["AUTOREG" (describe-function 'verilog-auto-reg)
  1365. :help "Help on AUTOREG - declaring registers for non-wires"]
  1366. ["AUTOREGINPUT" (describe-function 'verilog-auto-reg-input)
  1367. :help "Help on AUTOREGINPUT - declaring inputs for non-wires"]
  1368. ["AUTORESET" (describe-function 'verilog-auto-reset)
  1369. :help "Help on AUTORESET - resetting always blocks"]
  1370. ["AUTOSENSE or AS" (describe-function 'verilog-auto-sense)
  1371. :help "Help on AUTOSENSE - sensitivity lists for always blocks"]
  1372. ["AUTOTIEOFF" (describe-function 'verilog-auto-tieoff)
  1373. :help "Help on AUTOTIEOFF - tying off unused outputs"]
  1374. ["AUTOUNDEF" (describe-function 'verilog-auto-undef)
  1375. :help "Help on AUTOUNDEF - undefine all local defines"]
  1376. ["AUTOUNUSED" (describe-function 'verilog-auto-unused)
  1377. :help "Help on AUTOUNUSED - terminating unused inputs"]
  1378. ["AUTOWIRE" (describe-function 'verilog-auto-wire)
  1379. :help "Help on AUTOWIRE - declaring wires for cells"]
  1380. )
  1381. "----"
  1382. ["Submit bug report" verilog-submit-bug-report
  1383. :help "Submit via mail a bug report on verilog-mode.el"]
  1384. ["Version and FAQ" verilog-faq
  1385. :help "Show the current version, and where to get the FAQ etc"]
  1386. ["Customize Verilog Mode..." verilog-customize
  1387. :help "Customize variables and other settings used by Verilog-Mode"]
  1388. ["Customize Verilog Fonts & Colors" verilog-font-customize
  1389. :help "Customize fonts used by Verilog-Mode."])))
  1390. (easy-menu-define
  1391. verilog-stmt-menu verilog-mode-map "Menu for statement templates in Verilog."
  1392. (verilog-easy-menu-filter
  1393. '("Statements"
  1394. ["Header" verilog-sk-header
  1395. :help "Insert a header block at the top of file"]
  1396. ["Comment" verilog-sk-comment
  1397. :help "Insert a comment block"]
  1398. "----"
  1399. ["Module" verilog-sk-module
  1400. :help "Insert a module .. (/*AUTOARG*/);.. endmodule block"]
  1401. ["OVM Class" verilog-sk-ovm-class
  1402. :help "Insert an OVM class block"]
  1403. ["UVM Object" verilog-sk-uvm-object
  1404. :help "Insert an UVM object block"]
  1405. ["UVM Component" verilog-sk-uvm-component
  1406. :help "Insert an UVM component block"]
  1407. ["Primitive" verilog-sk-primitive
  1408. :help "Insert a primitive .. (.. );.. endprimitive block"]
  1409. "----"
  1410. ["Input" verilog-sk-input
  1411. :help "Insert an input declaration"]
  1412. ["Output" verilog-sk-output
  1413. :help "Insert an output declaration"]
  1414. ["Inout" verilog-sk-inout
  1415. :help "Insert an inout declaration"]
  1416. ["Wire" verilog-sk-wire
  1417. :help "Insert a wire declaration"]
  1418. ["Reg" verilog-sk-reg
  1419. :help "Insert a register declaration"]
  1420. ["Define thing under point as a register" verilog-sk-define-signal
  1421. :help "Define signal under point as a register at the top of the module"]
  1422. "----"
  1423. ["Initial" verilog-sk-initial
  1424. :help "Insert an initial begin .. end block"]
  1425. ["Always" verilog-sk-always
  1426. :help "Insert an always @(AS) begin .. end block"]
  1427. ["Function" verilog-sk-function
  1428. :help "Insert a function .. begin .. end endfunction block"]
  1429. ["Task" verilog-sk-task
  1430. :help "Insert a task .. begin .. end endtask block"]
  1431. ["Specify" verilog-sk-specify
  1432. :help "Insert a specify .. endspecify block"]
  1433. ["Generate" verilog-sk-generate
  1434. :help "Insert a generate .. endgenerate block"]
  1435. "----"
  1436. ["Begin" verilog-sk-begin
  1437. :help "Insert a begin .. end block"]
  1438. ["If" verilog-sk-if
  1439. :help "Insert an if (..) begin .. end block"]
  1440. ["(if) else" verilog-sk-else-if
  1441. :help "Insert an else if (..) begin .. end block"]
  1442. ["For" verilog-sk-for
  1443. :help "Insert a for (...) begin .. end block"]
  1444. ["While" verilog-sk-while
  1445. :help "Insert a while (...) begin .. end block"]
  1446. ["Fork" verilog-sk-fork
  1447. :help "Insert a fork begin .. end .. join block"]
  1448. ["Repeat" verilog-sk-repeat
  1449. :help "Insert a repeat (..) begin .. end block"]
  1450. ["Case" verilog-sk-case
  1451. :help "Insert a case block, prompting for details"]
  1452. ["Casex" verilog-sk-casex
  1453. :help "Insert a casex (...) item: begin.. end endcase block"]
  1454. ["Casez" verilog-sk-casez
  1455. :help "Insert a casez (...) item: begin.. end endcase block"])))
  1456. (defvar verilog-mode-abbrev-table nil
  1457. "Abbrev table in use in Verilog-mode buffers.")
  1458. (define-abbrev-table 'verilog-mode-abbrev-table ())
  1459. (verilog-define-abbrev verilog-mode-abbrev-table "class" "" 'verilog-sk-ovm-class)
  1460. (verilog-define-abbrev verilog-mode-abbrev-table "always" "" 'verilog-sk-always)
  1461. (verilog-define-abbrev verilog-mode-abbrev-table "begin" nil `verilog-sk-begin)
  1462. (verilog-define-abbrev verilog-mode-abbrev-table "case" "" `verilog-sk-case)
  1463. (verilog-define-abbrev verilog-mode-abbrev-table "for" "" `verilog-sk-for)
  1464. (verilog-define-abbrev verilog-mode-abbrev-table "generate" "" `verilog-sk-generate)
  1465. (verilog-define-abbrev verilog-mode-abbrev-table "initial" "" `verilog-sk-initial)
  1466. (verilog-define-abbrev verilog-mode-abbrev-table "fork" "" `verilog-sk-fork)
  1467. (verilog-define-abbrev verilog-mode-abbrev-table "module" "" `verilog-sk-module)
  1468. (verilog-define-abbrev verilog-mode-abbrev-table "primitive" "" `verilog-sk-primitive)
  1469. (verilog-define-abbrev verilog-mode-abbrev-table "repeat" "" `verilog-sk-repeat)
  1470. (verilog-define-abbrev verilog-mode-abbrev-table "specify" "" `verilog-sk-specify)
  1471. (verilog-define-abbrev verilog-mode-abbrev-table "task" "" `verilog-sk-task)
  1472. (verilog-define-abbrev verilog-mode-abbrev-table "while" "" `verilog-sk-while)
  1473. (verilog-define-abbrev verilog-mode-abbrev-table "casex" "" `verilog-sk-casex)
  1474. (verilog-define-abbrev verilog-mode-abbrev-table "casez" "" `verilog-sk-casez)
  1475. (verilog-define-abbrev verilog-mode-abbrev-table "if" "" `verilog-sk-if)
  1476. (verilog-define-abbrev verilog-mode-abbrev-table "else if" "" `verilog-sk-else-if)
  1477. (verilog-define-abbrev verilog-mode-abbrev-table "assign" "" `verilog-sk-assign)
  1478. (verilog-define-abbrev verilog-mode-abbrev-table "function" "" `verilog-sk-function)
  1479. (verilog-define-abbrev verilog-mode-abbrev-table "input" "" `verilog-sk-input)
  1480. (verilog-define-abbrev verilog-mode-abbrev-table "output" "" `verilog-sk-output)
  1481. (verilog-define-abbrev verilog-mode-abbrev-table "inout" "" `verilog-sk-inout)
  1482. (verilog-define-abbrev verilog-mode-abbrev-table "wire" "" `verilog-sk-wire)
  1483. (verilog-define-abbrev verilog-mode-abbrev-table "reg" "" `verilog-sk-reg)
  1484. ;;
  1485. ;; Macros
  1486. ;;
  1487. (defsubst verilog-within-string ()
  1488. (nth 3 (parse-partial-sexp (point-at-bol) (point))))
  1489. (defsubst verilog-string-match-fold (regexp string &optional start)
  1490. "Like `string-match', but use `verilog-case-fold'.
  1491. Return index of start of first match for REGEXP in STRING, or nil.
  1492. Matching ignores case if `verilog-case-fold' is non-nil.
  1493. If third arg START is non-nil, start search at that index in STRING."
  1494. (let ((case-fold-search verilog-case-fold))
  1495. (string-match regexp string start)))
  1496. (defsubst verilog-string-replace-matches (from-string to-string fixedcase literal string)
  1497. "Replace occurrences of FROM-STRING with TO-STRING.
  1498. FIXEDCASE and LITERAL as in `replace-match'. STRING is what to replace.
  1499. The case (verilog-string-replace-matches \"o\" \"oo\" nil nil \"foobar\")
  1500. will break, as the o's continuously replace. xa -> x works ok though."
  1501. ;; Hopefully soon to an Emacs built-in
  1502. ;; Also note \ in the replacement prevent multiple replacements; IE
  1503. ;; (verilog-string-replace-matches "@" "\\\\([0-9]+\\\\)" nil nil "wire@_@")
  1504. ;; Gives "wire\([0-9]+\)_@" not "wire\([0-9]+\)_\([0-9]+\)"
  1505. (let ((start 0))
  1506. (while (string-match from-string string start)
  1507. (setq string (replace-match to-string fixedcase literal string)
  1508. start (min (length string) (+ (match-beginning 0) (length to-string)))))
  1509. string))
  1510. (defsubst verilog-string-remove-spaces (string)
  1511. "Remove spaces surrounding STRING."
  1512. (save-match-data
  1513. (setq string (verilog-string-replace-matches "^\\s-+" "" nil nil string))
  1514. (setq string (verilog-string-replace-matches "\\s-+$" "" nil nil string))
  1515. string))
  1516. (defsubst verilog-re-search-forward (REGEXP BOUND NOERROR)
  1517. ;; checkdoc-params: (REGEXP BOUND NOERROR)
  1518. "Like `re-search-forward', but skips over match in comments or strings."
  1519. (let ((mdata '(nil nil))) ; So match-end will return nil if no matches found
  1520. (while (and
  1521. (re-search-forward REGEXP BOUND NOERROR)
  1522. (setq mdata (match-data))
  1523. (and (verilog-skip-forward-comment-or-string)
  1524. (progn
  1525. (setq mdata '(nil nil))
  1526. (if BOUND
  1527. (< (point) BOUND)
  1528. t)))))
  1529. (store-match-data mdata)
  1530. (match-end 0)))
  1531. (defsubst verilog-re-search-backward (REGEXP BOUND NOERROR)
  1532. ;; checkdoc-params: (REGEXP BOUND NOERROR)
  1533. "Like `re-search-backward', but skips over match in comments or strings."
  1534. (let ((mdata '(nil nil))) ; So match-end will return nil if no matches found
  1535. (while (and
  1536. (re-search-backward REGEXP BOUND NOERROR)
  1537. (setq mdata (match-data))
  1538. (and (verilog-skip-backward-comment-or-string)
  1539. (progn
  1540. (setq mdata '(nil nil))
  1541. (if BOUND
  1542. (> (point) BOUND)
  1543. t)))))
  1544. (store-match-data mdata)
  1545. (match-end 0)))
  1546. (defsubst verilog-re-search-forward-quick (regexp bound noerror)
  1547. "Like `verilog-re-search-forward', including use of REGEXP BOUND and NOERROR,
  1548. but trashes match data and is faster for REGEXP that doesn't match often.
  1549. This uses `verilog-scan' and text properties to ignore comments,
  1550. so there may be a large up front penalty for the first search."
  1551. (let (pt)
  1552. (while (and (not pt)
  1553. (re-search-forward regexp bound noerror))
  1554. (if (verilog-inside-comment-or-string-p)
  1555. (re-search-forward "[/\"\n]" nil t) ; Only way a comment or quote can end
  1556. (setq pt (match-end 0))))
  1557. pt))
  1558. (defsubst verilog-re-search-backward-quick (regexp bound noerror)
  1559. ;; checkdoc-params: (REGEXP BOUND NOERROR)
  1560. "Like `verilog-re-search-backward', including use of REGEXP BOUND and NOERROR,
  1561. but trashes match data and is faster for REGEXP that doesn't match often.
  1562. This uses `verilog-scan' and text properties to ignore comments,
  1563. so there may be a large up front penalty for the first search."
  1564. (let (pt)
  1565. (while (and (not pt)
  1566. (re-search-backward regexp bound noerror))
  1567. (if (verilog-inside-comment-or-string-p)
  1568. (re-search-backward "[/\"]" nil t) ; Only way a comment or quote can begin
  1569. (setq pt (match-beginning 0))))
  1570. pt))
  1571. (defsubst verilog-re-search-forward-substr (substr regexp bound noerror)
  1572. "Like `re-search-forward', but first search for SUBSTR constant.
  1573. Then searched for the normal REGEXP (which contains SUBSTR), with given
  1574. BOUND and NOERROR. The REGEXP must fit within a single line.
  1575. This speeds up complicated regexp matches."
  1576. ;; Problem with overlap: search-forward BAR then FOOBARBAZ won't match.
  1577. ;; thus require matches to be on one line, and use beginning-of-line.
  1578. (let (done)
  1579. (while (and (not done)
  1580. (search-forward substr bound noerror))
  1581. (save-excursion
  1582. (beginning-of-line)
  1583. (setq done (re-search-forward regexp (point-at-eol) noerror)))
  1584. (unless (and (<= (match-beginning 0) (point))
  1585. (>= (match-end 0) (point)))
  1586. (setq done nil)))
  1587. (when done (goto-char done))
  1588. done))
  1589. ;;(verilog-re-search-forward-substr "-end" "get-end-of" nil t) ; -end (test bait)
  1590. (defsubst verilog-re-search-backward-substr (substr regexp bound noerror)
  1591. "Like `re-search-backward', but first search for SUBSTR constant.
  1592. Then searched for the normal REGEXP (which contains SUBSTR), with given
  1593. BOUND and NOERROR. The REGEXP must fit within a single line.
  1594. This speeds up complicated regexp matches."
  1595. ;; Problem with overlap: search-backward BAR then FOOBARBAZ won't match.
  1596. ;; thus require matches to be on one line, and use beginning-of-line.
  1597. (let (done)
  1598. (while (and (not done)
  1599. (search-backward substr bound noerror))
  1600. (save-excursion
  1601. (end-of-line)
  1602. (setq done (re-search-backward regexp (point-at-bol) noerror)))
  1603. (unless (and (<= (match-beginning 0) (point))
  1604. (>= (match-end 0) (point)))
  1605. (setq done nil)))
  1606. (when done (goto-char done))
  1607. done))
  1608. ;;(verilog-re-search-backward-substr "-end" "get-end-of" nil t) ; -end (test bait)
  1609. (defun verilog-delete-trailing-whitespace ()
  1610. "Delete trailing spaces or tabs, but not newlines nor linefeeds.
  1611. Also add missing final newline.
  1612. To call this from the command line, see \\[verilog-batch-diff-auto].
  1613. To call on \\[verilog-auto], set `verilog-auto-delete-trailing-whitespace'."
  1614. ;; Similar to `delete-trailing-whitespace' but that's not present in XEmacs
  1615. (save-excursion
  1616. (goto-char (point-min))
  1617. (while (re-search-forward "[ \t]+$" nil t) ; Not syntactic WS as no formfeed
  1618. (replace-match "" nil nil))
  1619. (goto-char (point-max))
  1620. (unless (bolp) (insert "\n"))))
  1621. (defvar compile-command)
  1622. (defvar create-lockfiles) ; Emacs 24
  1623. ;; compilation program
  1624. (defun verilog-set-compile-command ()
  1625. "Function to compute shell command to compile Verilog.
  1626. This reads `verilog-tool' and sets `compile-command'. This specifies the
  1627. program that executes when you type \\[compile] or
  1628. \\[verilog-auto-save-compile].
  1629. By default `verilog-tool' uses a Makefile if one exists in the
  1630. current directory. If not, it is set to the `verilog-linter',
  1631. `verilog-compiler', `verilog-coverage', `verilog-preprocessor',
  1632. or `verilog-simulator' variables, as selected with the Verilog ->
  1633. \"Choose Compilation Action\" menu.
  1634. You should set `verilog-tool' or the other variables to the path and
  1635. arguments for your Verilog simulator. For example:
  1636. \"vcs -p123 -O\"
  1637. or a string like:
  1638. \"(cd /tmp; surecov %s)\".
  1639. In the former case, the path to the current buffer is concat'ed to the
  1640. value of `verilog-tool'; in the later, the path to the current buffer is
  1641. substituted for the %s.
  1642. Where __FLAGS__ appears in the string `verilog-current-flags'
  1643. will be substituted.
  1644. Where __FILE__ appears in the string, the variable
  1645. `buffer-file-name' of the current buffer, without the directory
  1646. portion, will be substituted."
  1647. (interactive)
  1648. (cond
  1649. ((or (file-exists-p "makefile") ;If there is a makefile, use it
  1650. (file-exists-p "Makefile"))
  1651. (set (make-local-variable 'compile-command) "make "))
  1652. (t
  1653. (set (make-local-variable 'compile-command)
  1654. (if verilog-tool
  1655. (if (string-match "%s" (eval verilog-tool))
  1656. (format (eval verilog-tool) (or buffer-file-name ""))
  1657. (concat (eval verilog-tool) " " (or buffer-file-name "")))
  1658. ""))))
  1659. (verilog-modify-compile-command))
  1660. (defun verilog-expand-command (command)
  1661. "Replace meta-information in COMMAND and return it.
  1662. Where __FLAGS__ appears in the string `verilog-current-flags'
  1663. will be substituted. Where __FILE__ appears in the string, the
  1664. current buffer's file-name, without the directory portion, will
  1665. be substituted."
  1666. (setq command (verilog-string-replace-matches
  1667. ;; Note \\b only works if under verilog syntax table
  1668. "\\b__FLAGS__\\b" (verilog-current-flags)
  1669. t t command))
  1670. (setq command (verilog-string-replace-matches
  1671. "\\b__FILE__\\b" (file-name-nondirectory
  1672. (or (buffer-file-name) ""))
  1673. t t command))
  1674. command)
  1675. (defun verilog-modify-compile-command ()
  1676. "Update `compile-command' using `verilog-expand-command'."
  1677. (when (and
  1678. (stringp compile-command)
  1679. (string-match "\\b\\(__FLAGS__\\|__FILE__\\)\\b" compile-command))
  1680. (set (make-local-variable 'compile-command)
  1681. (verilog-expand-command compile-command))))
  1682. (if (featurep 'xemacs)
  1683. ;; Following code only gets called from compilation-mode-hook on XEmacs to add error handling.
  1684. (defun verilog-error-regexp-add-xemacs ()
  1685. "Teach XEmacs about verilog errors.
  1686. Called by `compilation-mode-hook'. This allows \\[next-error] to
  1687. find the errors."
  1688. (interactive)
  1689. (if (boundp 'compilation-error-regexp-systems-alist)
  1690. (if (and
  1691. (not (equal compilation-error-regexp-systems-list 'all))
  1692. (not (member compilation-error-regexp-systems-list 'verilog)))
  1693. (push 'verilog compilation-error-regexp-systems-list)))
  1694. (if (boundp 'compilation-error-regexp-alist-alist)
  1695. (if (not (assoc 'verilog compilation-error-regexp-alist-alist))
  1696. (setcdr compilation-error-regexp-alist-alist
  1697. (cons verilog-error-regexp-xemacs-alist
  1698. (cdr compilation-error-regexp-alist-alist)))))
  1699. (if (boundp 'compilation-font-lock-keywords)
  1700. (progn
  1701. (set (make-local-variable 'compilation-font-lock-keywords)
  1702. verilog-error-font-lock-keywords)
  1703. (font-lock-set-defaults)))
  1704. ;; Need to re-run compilation-error-regexp builder
  1705. (if (fboundp 'compilation-build-compilation-error-regexp-alist)
  1706. (compilation-build-compilation-error-regexp-alist))
  1707. ))
  1708. ;; Following code only gets called from compilation-mode-hook on Emacs to add error handling.
  1709. (defun verilog-error-regexp-add-emacs ()
  1710. "Tell Emacs compile that we are Verilog.
  1711. Called by `compilation-mode-hook'. This allows \\[next-error] to
  1712. find the errors."
  1713. (interactive)
  1714. (when (boundp 'compilation-error-regexp-alist-alist)
  1715. (when (not (assoc 'verilog-xl-1 compilation-error-regexp-alist-alist))
  1716. (mapcar
  1717. (lambda (item)
  1718. (push (car item) compilation-error-regexp-alist)
  1719. (push item compilation-error-regexp-alist-alist))
  1720. verilog-error-regexp-emacs-alist))))
  1721. (if (featurep 'xemacs) (add-hook 'compilation-mode-hook 'verilog-error-regexp-add-xemacs))
  1722. (if (featurep 'emacs) (add-hook 'compilation-mode-hook 'verilog-error-regexp-add-emacs))
  1723. (defconst verilog-compiler-directives
  1724. (eval-when-compile
  1725. '(
  1726. ;; compiler directives, from IEEE 1800-2012 section 22.1
  1727. "`__FILE__" "`__LINE" "`begin_keywords" "`celldefine" "`default_nettype"
  1728. "`define" "`else" "`elsif" "`end_keywords" "`endcelldefine" "`endif"
  1729. "`ifdef" "`ifndef" "`include" "`line" "`nounconnected_drive" "`pragma"
  1730. "`resetall" "`timescale" "`unconnected_drive" "`undef" "`undefineall"
  1731. ;; compiler directives not covered by IEEE 1800
  1732. "`case" "`default" "`endfor" "`endprotect" "`endswitch" "`endwhile" "`for"
  1733. "`format" "`if" "`let" "`protect" "`switch" "`timescale" "`time_scale"
  1734. "`while"
  1735. ))
  1736. "List of Verilog compiler directives.")
  1737. (defconst verilog-directive-re
  1738. (verilog-regexp-words verilog-compiler-directives))
  1739. (defconst verilog-directive-re-1
  1740. (concat "[ \t]*" verilog-directive-re))
  1741. (defconst verilog-directive-begin
  1742. "\\<`\\(for\\|i\\(f\\|fdef\\|fndef\\)\\|switch\\|while\\)\\>")
  1743. (defconst verilog-directive-middle
  1744. "\\<`\\(else\\|elsif\\|default\\|case\\)\\>")
  1745. (defconst verilog-directive-end
  1746. "`\\(endfor\\|endif\\|endswitch\\|endwhile\\)\\>")
  1747. (defconst verilog-ovm-begin-re
  1748. (eval-when-compile
  1749. (verilog-regexp-opt
  1750. '(
  1751. "`ovm_component_utils_begin"
  1752. "`ovm_component_param_utils_begin"
  1753. "`ovm_field_utils_begin"
  1754. "`ovm_object_utils_begin"
  1755. "`ovm_object_param_utils_begin"
  1756. "`ovm_sequence_utils_begin"
  1757. "`ovm_sequencer_utils_begin"
  1758. ) nil )))
  1759. (defconst verilog-ovm-end-re
  1760. (eval-when-compile
  1761. (verilog-regexp-opt
  1762. '(
  1763. "`ovm_component_utils_end"
  1764. "`ovm_field_utils_end"
  1765. "`ovm_object_utils_end"
  1766. "`ovm_sequence_utils_end"
  1767. "`ovm_sequencer_utils_end"
  1768. ) nil )))
  1769. (defconst verilog-uvm-begin-re
  1770. (eval-when-compile
  1771. (verilog-regexp-opt
  1772. '(
  1773. "`uvm_component_utils_begin"
  1774. "`uvm_component_param_utils_begin"
  1775. "`uvm_field_utils_begin"
  1776. "`uvm_object_utils_begin"
  1777. "`uvm_object_param_utils_begin"
  1778. "`uvm_sequence_utils_begin"
  1779. "`uvm_sequencer_utils_begin"
  1780. ) nil )))
  1781. (defconst verilog-uvm-end-re
  1782. (eval-when-compile
  1783. (verilog-regexp-opt
  1784. '(
  1785. "`uvm_component_utils_end"
  1786. "`uvm_field_utils_end"
  1787. "`uvm_object_utils_end"
  1788. "`uvm_sequence_utils_end"
  1789. "`uvm_sequencer_utils_end"
  1790. ) nil )))
  1791. (defconst verilog-vmm-begin-re
  1792. (eval-when-compile
  1793. (verilog-regexp-opt
  1794. '(
  1795. "`vmm_data_member_begin"
  1796. "`vmm_env_member_begin"
  1797. "`vmm_scenario_member_begin"
  1798. "`vmm_subenv_member_begin"
  1799. "`vmm_xactor_member_begin"
  1800. ) nil ) ) )
  1801. (defconst verilog-vmm-end-re
  1802. (eval-when-compile
  1803. (verilog-regexp-opt
  1804. '(
  1805. "`vmm_data_member_end"
  1806. "`vmm_env_member_end"
  1807. "`vmm_scenario_member_end"
  1808. "`vmm_subenv_member_end"
  1809. "`vmm_xactor_member_end"
  1810. ) nil ) ) )
  1811. (defconst verilog-vmm-statement-re
  1812. (eval-when-compile
  1813. (verilog-regexp-opt
  1814. '(
  1815. "`vmm_\\(data\\|env\\|scenario\\|subenv\\|xactor\\)_member_\\(scalar\\|string\\|enum\\|vmm_data\\|channel\\|xactor\\|subenv\\|user_defined\\)\\(_array\\)?"
  1816. ;; "`vmm_xactor_member_enum_array"
  1817. ;; "`vmm_xactor_member_scalar_array"
  1818. ;; "`vmm_xactor_member_scalar"
  1819. ) nil )))
  1820. (defconst verilog-ovm-statement-re
  1821. (eval-when-compile
  1822. (verilog-regexp-opt
  1823. '(
  1824. ;; Statements
  1825. "`DUT_ERROR"
  1826. "`MESSAGE"
  1827. "`dut_error"
  1828. "`message"
  1829. "`ovm_analysis_imp_decl"
  1830. "`ovm_blocking_get_imp_decl"
  1831. "`ovm_blocking_get_peek_imp_decl"
  1832. "`ovm_blocking_master_imp_decl"
  1833. "`ovm_blocking_peek_imp_decl"
  1834. "`ovm_blocking_put_imp_decl"
  1835. "`ovm_blocking_slave_imp_decl"
  1836. "`ovm_blocking_transport_imp_decl"
  1837. "`ovm_component_registry"
  1838. "`ovm_component_registry_param"
  1839. "`ovm_component_utils"
  1840. "`ovm_create"
  1841. "`ovm_create_seq"
  1842. "`ovm_declare_sequence_lib"
  1843. "`ovm_do"
  1844. "`ovm_do_seq"
  1845. "`ovm_do_seq_with"
  1846. "`ovm_do_with"
  1847. "`ovm_error"
  1848. "`ovm_fatal"
  1849. "`ovm_field_aa_int_byte"
  1850. "`ovm_field_aa_int_byte_unsigned"
  1851. "`ovm_field_aa_int_int"
  1852. "`ovm_field_aa_int_int_unsigned"
  1853. "`ovm_field_aa_int_integer"
  1854. "`ovm_field_aa_int_integer_unsigned"
  1855. "`ovm_field_aa_int_key"
  1856. "`ovm_field_aa_int_longint"
  1857. "`ovm_field_aa_int_longint_unsigned"
  1858. "`ovm_field_aa_int_shortint"
  1859. "`ovm_field_aa_int_shortint_unsigned"
  1860. "`ovm_field_aa_int_string"
  1861. "`ovm_field_aa_object_int"
  1862. "`ovm_field_aa_object_string"
  1863. "`ovm_field_aa_string_int"
  1864. "`ovm_field_aa_string_string"
  1865. "`ovm_field_array_int"
  1866. "`ovm_field_array_object"
  1867. "`ovm_field_array_string"
  1868. "`ovm_field_enum"
  1869. "`ovm_field_event"
  1870. "`ovm_field_int"
  1871. "`ovm_field_object"
  1872. "`ovm_field_queue_int"
  1873. "`ovm_field_queue_object"
  1874. "`ovm_field_queue_string"
  1875. "`ovm_field_sarray_int"
  1876. "`ovm_field_string"
  1877. "`ovm_field_utils"
  1878. "`ovm_file"
  1879. "`ovm_get_imp_decl"
  1880. "`ovm_get_peek_imp_decl"
  1881. "`ovm_info"
  1882. "`ovm_info1"
  1883. "`ovm_info2"
  1884. "`ovm_info3"
  1885. "`ovm_info4"
  1886. "`ovm_line"
  1887. "`ovm_master_imp_decl"
  1888. "`ovm_msg_detail"
  1889. "`ovm_non_blocking_transport_imp_decl"
  1890. "`ovm_nonblocking_get_imp_decl"
  1891. "`ovm_nonblocking_get_peek_imp_decl"
  1892. "`ovm_nonblocking_master_imp_decl"
  1893. "`ovm_nonblocking_peek_imp_decl"
  1894. "`ovm_nonblocking_put_imp_decl"
  1895. "`ovm_nonblocking_slave_imp_decl"
  1896. "`ovm_object_registry"
  1897. "`ovm_object_registry_param"
  1898. "`ovm_object_utils"
  1899. "`ovm_peek_imp_decl"
  1900. "`ovm_phase_func_decl"
  1901. "`ovm_phase_task_decl"
  1902. "`ovm_print_aa_int_object"
  1903. "`ovm_print_aa_string_int"
  1904. "`ovm_print_aa_string_object"
  1905. "`ovm_print_aa_string_string"
  1906. "`ovm_print_array_int"
  1907. "`ovm_print_array_object"
  1908. "`ovm_print_array_string"
  1909. "`ovm_print_object_queue"
  1910. "`ovm_print_queue_int"
  1911. "`ovm_print_string_queue"
  1912. "`ovm_put_imp_decl"
  1913. "`ovm_rand_send"
  1914. "`ovm_rand_send_with"
  1915. "`ovm_send"
  1916. "`ovm_sequence_utils"
  1917. "`ovm_slave_imp_decl"
  1918. "`ovm_transport_imp_decl"
  1919. "`ovm_update_sequence_lib"
  1920. "`ovm_update_sequence_lib_and_item"
  1921. "`ovm_warning"
  1922. "`static_dut_error"
  1923. "`static_message") nil )))
  1924. (defconst verilog-uvm-statement-re
  1925. (eval-when-compile
  1926. (verilog-regexp-opt
  1927. '(
  1928. ;; Statements
  1929. "`uvm_analysis_imp_decl"
  1930. "`uvm_blocking_get_imp_decl"
  1931. "`uvm_blocking_get_peek_imp_decl"
  1932. "`uvm_blocking_master_imp_decl"
  1933. "`uvm_blocking_peek_imp_decl"
  1934. "`uvm_blocking_put_imp_decl"
  1935. "`uvm_blocking_slave_imp_decl"
  1936. "`uvm_blocking_transport_imp_decl"
  1937. "`uvm_component_param_utils"
  1938. "`uvm_component_registry"
  1939. "`uvm_component_registry_param"
  1940. "`uvm_component_utils"
  1941. "`uvm_create"
  1942. "`uvm_create_on"
  1943. "`uvm_create_seq" ; Undocumented in 1.1
  1944. "`uvm_declare_p_sequencer"
  1945. "`uvm_declare_sequence_lib" ; Deprecated in 1.1
  1946. "`uvm_do"
  1947. "`uvm_do_callbacks"
  1948. "`uvm_do_callbacks_exit_on"
  1949. "`uvm_do_obj_callbacks"
  1950. "`uvm_do_obj_callbacks_exit_on"
  1951. "`uvm_do_on"
  1952. "`uvm_do_on_pri"
  1953. "`uvm_do_on_pri_with"
  1954. "`uvm_do_on_with"
  1955. "`uvm_do_pri"
  1956. "`uvm_do_pri_with"
  1957. "`uvm_do_seq" ; Undocumented in 1.1
  1958. "`uvm_do_seq_with" ; Undocumented in 1.1
  1959. "`uvm_do_with"
  1960. "`uvm_error"
  1961. "`uvm_error_context"
  1962. "`uvm_fatal"
  1963. "`uvm_fatal_context"
  1964. "`uvm_field_aa_int_byte"
  1965. "`uvm_field_aa_int_byte_unsigned"
  1966. "`uvm_field_aa_int_enum"
  1967. "`uvm_field_aa_int_int"
  1968. "`uvm_field_aa_int_int_unsigned"
  1969. "`uvm_field_aa_int_integer"
  1970. "`uvm_field_aa_int_integer_unsigned"
  1971. "`uvm_field_aa_int_key"
  1972. "`uvm_field_aa_int_longint"
  1973. "`uvm_field_aa_int_longint_unsigned"
  1974. "`uvm_field_aa_int_shortint"
  1975. "`uvm_field_aa_int_shortint_unsigned"
  1976. "`uvm_field_aa_int_string"
  1977. "`uvm_field_aa_object_int"
  1978. "`uvm_field_aa_object_string"
  1979. "`uvm_field_aa_string_int"
  1980. "`uvm_field_aa_string_string"
  1981. "`uvm_field_array_enum"
  1982. "`uvm_field_array_int"
  1983. "`uvm_field_array_object"
  1984. "`uvm_field_array_string"
  1985. "`uvm_field_enum"
  1986. "`uvm_field_event"
  1987. "`uvm_field_int"
  1988. "`uvm_field_object"
  1989. "`uvm_field_queue_enum"
  1990. "`uvm_field_queue_int"
  1991. "`uvm_field_queue_object"
  1992. "`uvm_field_queue_string"
  1993. "`uvm_field_real"
  1994. "`uvm_field_sarray_enum"
  1995. "`uvm_field_sarray_int"
  1996. "`uvm_field_sarray_object"
  1997. "`uvm_field_sarray_string"
  1998. "`uvm_field_string"
  1999. "`uvm_field_utils"
  2000. "`uvm_file" ; Undocumented in 1.1, use `__FILE__
  2001. "`uvm_get_imp_decl"
  2002. "`uvm_get_peek_imp_decl"
  2003. "`uvm_info"
  2004. "`uvm_info_context"
  2005. "`uvm_line" ; Undocumented in 1.1, use `__LINE__
  2006. "`uvm_master_imp_decl"
  2007. "`uvm_non_blocking_transport_imp_decl" ; Deprecated in 1.1
  2008. "`uvm_nonblocking_get_imp_decl"
  2009. "`uvm_nonblocking_get_peek_imp_decl"
  2010. "`uvm_nonblocking_master_imp_decl"
  2011. "`uvm_nonblocking_peek_imp_decl"
  2012. "`uvm_nonblocking_put_imp_decl"
  2013. "`uvm_nonblocking_slave_imp_decl"
  2014. "`uvm_nonblocking_transport_imp_decl"
  2015. "`uvm_object_param_utils"
  2016. "`uvm_object_registry"
  2017. "`uvm_object_registry_param" ; Undocumented in 1.1
  2018. "`uvm_object_utils"
  2019. "`uvm_pack_array"
  2020. "`uvm_pack_arrayN"
  2021. "`uvm_pack_enum"
  2022. "`uvm_pack_enumN"
  2023. "`uvm_pack_int"
  2024. "`uvm_pack_intN"
  2025. "`uvm_pack_queue"
  2026. "`uvm_pack_queueN"
  2027. "`uvm_pack_real"
  2028. "`uvm_pack_sarray"
  2029. "`uvm_pack_sarrayN"
  2030. "`uvm_pack_string"
  2031. "`uvm_peek_imp_decl"
  2032. "`uvm_put_imp_decl"
  2033. "`uvm_rand_send"
  2034. "`uvm_rand_send_pri"
  2035. "`uvm_rand_send_pri_with"
  2036. "`uvm_rand_send_with"
  2037. "`uvm_record_attribute"
  2038. "`uvm_record_field"
  2039. "`uvm_register_cb"
  2040. "`uvm_send"
  2041. "`uvm_send_pri"
  2042. "`uvm_sequence_utils" ; Deprecated in 1.1
  2043. "`uvm_set_super_type"
  2044. "`uvm_slave_imp_decl"
  2045. "`uvm_transport_imp_decl"
  2046. "`uvm_unpack_array"
  2047. "`uvm_unpack_arrayN"
  2048. "`uvm_unpack_enum"
  2049. "`uvm_unpack_enumN"
  2050. "`uvm_unpack_int"
  2051. "`uvm_unpack_intN"
  2052. "`uvm_unpack_queue"
  2053. "`uvm_unpack_queueN"
  2054. "`uvm_unpack_real"
  2055. "`uvm_unpack_sarray"
  2056. "`uvm_unpack_sarrayN"
  2057. "`uvm_unpack_string"
  2058. "`uvm_update_sequence_lib" ; Deprecated in 1.1
  2059. "`uvm_update_sequence_lib_and_item" ; Deprecated in 1.1
  2060. "`uvm_warning"
  2061. "`uvm_warning_context") nil )))
  2062. ;;
  2063. ;; Regular expressions used to calculate indent, etc.
  2064. ;;
  2065. (defconst verilog-symbol-re "\\<[a-zA-Z_][a-zA-Z_0-9.]*\\>")
  2066. ;; Want to match
  2067. ;; aa :
  2068. ;; aa,bb :
  2069. ;; a[34:32] :
  2070. ;; a,
  2071. ;; b :
  2072. (defconst verilog-assignment-operator-re
  2073. (eval-when-compile
  2074. (verilog-regexp-opt
  2075. `(
  2076. ;; blocking assignment_operator
  2077. "=" "+=" "-=" "*=" "/=" "%=" "&=" "|=" "^=" "<<=" ">>=" "<<<=" ">>>="
  2078. ;; non blocking assignment operator
  2079. "<="
  2080. ;; comparison
  2081. "==" "!=" "===" "!==" "<=" ">=" "==?" "!=?" "<->"
  2082. ;; event_trigger
  2083. "->" "->>"
  2084. ;; property_expr
  2085. "|->" "|=>" "#-#" "#=#"
  2086. ;; distribution weighting
  2087. ":=" ":/"
  2088. ) 't
  2089. )))
  2090. (defconst verilog-assignment-operation-re
  2091. (concat
  2092. ;; "\\(^\\s-*[A-Za-z0-9_]+\\(\\[\\([A-Za-z0-9_]+\\)\\]\\)*\\s-*\\)"
  2093. ;; "\\(^\\s-*[^=<>+-*/%&|^:\\s-]+[^=<>+-*/%&|^\n]*?\\)"
  2094. "\\(^.*?\\)" "\\B" verilog-assignment-operator-re "\\B" ))
  2095. (defconst verilog-label-re (concat verilog-symbol-re "\\s-*:\\s-*"))
  2096. (defconst verilog-property-re
  2097. (concat "\\(" verilog-label-re "\\)?"
  2098. ;; "\\(assert\\|assume\\|cover\\)\\s-+property\\>"
  2099. "\\(\\(assert\\|assume\\|cover\\)\\>\\s-+\\<property\\>\\)\\|\\(assert\\)"))
  2100. (defconst verilog-no-indent-begin-re
  2101. (eval-when-compile
  2102. (verilog-regexp-words
  2103. '("always" "always_comb" "always_ff" "always_latch" "initial" "final" ; procedural blocks
  2104. "if" "else" ; conditional statements
  2105. "while" "for" "foreach" "repeat" "do" "forever" )))) ; loop statements
  2106. (defconst verilog-ends-re
  2107. ;; Parenthesis indicate type of keyword found
  2108. (concat
  2109. "\\(\\<else\\>\\)\\|" ; 1
  2110. "\\(\\<if\\>\\)\\|" ; 2
  2111. "\\(\\<assert\\>\\)\\|" ; 3
  2112. "\\(\\<end\\>\\)\\|" ; 3.1
  2113. "\\(\\<endcase\\>\\)\\|" ; 4
  2114. "\\(\\<endfunction\\>\\)\\|" ; 5
  2115. "\\(\\<endtask\\>\\)\\|" ; 6
  2116. "\\(\\<endspecify\\>\\)\\|" ; 7
  2117. "\\(\\<endtable\\>\\)\\|" ; 8
  2118. "\\(\\<endgenerate\\>\\)\\|" ; 9
  2119. "\\(\\<join\\(_any\\|_none\\)?\\>\\)\\|" ; 10
  2120. "\\(\\<endclass\\>\\)\\|" ; 11
  2121. "\\(\\<endgroup\\>\\)\\|" ; 12
  2122. ;; VMM
  2123. "\\(\\<`vmm_data_member_end\\>\\)\\|"
  2124. "\\(\\<`vmm_env_member_end\\>\\)\\|"
  2125. "\\(\\<`vmm_scenario_member_end\\>\\)\\|"
  2126. "\\(\\<`vmm_subenv_member_end\\>\\)\\|"
  2127. "\\(\\<`vmm_xactor_member_end\\>\\)\\|"
  2128. ;; OVM
  2129. "\\(\\<`ovm_component_utils_end\\>\\)\\|"
  2130. "\\(\\<`ovm_field_utils_end\\>\\)\\|"
  2131. "\\(\\<`ovm_object_utils_end\\>\\)\\|"
  2132. "\\(\\<`ovm_sequence_utils_end\\>\\)\\|"
  2133. "\\(\\<`ovm_sequencer_utils_end\\>\\)"
  2134. ;; UVM
  2135. "\\(\\<`uvm_component_utils_end\\>\\)\\|"
  2136. "\\(\\<`uvm_field_utils_end\\>\\)\\|"
  2137. "\\(\\<`uvm_object_utils_end\\>\\)\\|"
  2138. "\\(\\<`uvm_sequence_utils_end\\>\\)\\|"
  2139. "\\(\\<`uvm_sequencer_utils_end\\>\\)"
  2140. ))
  2141. (defconst verilog-auto-end-comment-lines-re
  2142. ;; Matches to names in this list cause auto-end-commenting
  2143. (concat "\\("
  2144. verilog-directive-re "\\)\\|\\("
  2145. (eval-when-compile
  2146. (verilog-regexp-words
  2147. `( "begin"
  2148. "else"
  2149. "end"
  2150. "endcase"
  2151. "endclass"
  2152. "endclocking"
  2153. "endgroup"
  2154. "endfunction"
  2155. "endmodule"
  2156. "endprogram"
  2157. "endprimitive"
  2158. "endinterface"
  2159. "endpackage"
  2160. "endsequence"
  2161. "endproperty"
  2162. "endspecify"
  2163. "endtable"
  2164. "endtask"
  2165. "join"
  2166. "join_any"
  2167. "join_none"
  2168. "module"
  2169. "macromodule"
  2170. "primitive"
  2171. "interface"
  2172. "package")))
  2173. "\\)"))
  2174. ;; NOTE: verilog-leap-to-head expects that verilog-end-block-re and
  2175. ;; verilog-end-block-ordered-re matches exactly the same strings.
  2176. (defconst verilog-end-block-ordered-re
  2177. ;; Parenthesis indicate type of keyword found
  2178. (concat "\\(\\<endcase\\>\\)\\|" ; 1
  2179. "\\(\\<end\\>\\)\\|" ; 2
  2180. "\\(\\<end" ; 3, but not used
  2181. "\\(" ; 4, but not used
  2182. "\\(function\\)\\|" ; 5
  2183. "\\(task\\)\\|" ; 6
  2184. "\\(module\\)\\|" ; 7
  2185. "\\(primitive\\)\\|" ; 8
  2186. "\\(interface\\)\\|" ; 9
  2187. "\\(package\\)\\|" ; 10
  2188. "\\(class\\)\\|" ; 11
  2189. "\\(group\\)\\|" ; 12
  2190. "\\(program\\)\\|" ; 13
  2191. "\\(sequence\\)\\|" ; 14
  2192. "\\(clocking\\)\\|" ; 15
  2193. "\\(property\\)\\|" ; 16
  2194. "\\)\\>\\)"))
  2195. (defconst verilog-end-block-re
  2196. (eval-when-compile
  2197. (verilog-regexp-words
  2198. `("end" ; closes begin
  2199. "endcase" ; closes any of case, casex casez or randcase
  2200. "join" "join_any" "join_none" ; closes fork
  2201. "endclass"
  2202. "endtable"
  2203. "endspecify"
  2204. "endfunction"
  2205. "endgenerate"
  2206. "endtask"
  2207. "endgroup"
  2208. "endproperty"
  2209. "endinterface"
  2210. "endpackage"
  2211. "endprogram"
  2212. "endsequence"
  2213. "endclocking"
  2214. ;; OVM
  2215. "`ovm_component_utils_end"
  2216. "`ovm_field_utils_end"
  2217. "`ovm_object_utils_end"
  2218. "`ovm_sequence_utils_end"
  2219. "`ovm_sequencer_utils_end"
  2220. ;; UVM
  2221. "`uvm_component_utils_end"
  2222. "`uvm_field_utils_end"
  2223. "`uvm_object_utils_end"
  2224. "`uvm_sequence_utils_end"
  2225. "`uvm_sequencer_utils_end"
  2226. ;; VMM
  2227. "`vmm_data_member_end"
  2228. "`vmm_env_member_end"
  2229. "`vmm_scenario_member_end"
  2230. "`vmm_subenv_member_end"
  2231. "`vmm_xactor_member_end"
  2232. ))))
  2233. (defconst verilog-endcomment-reason-re
  2234. ;; Parenthesis indicate type of keyword found
  2235. (concat
  2236. "\\(\\<begin\\>\\)\\|" ; 1
  2237. "\\(\\<else\\>\\)\\|" ; 2
  2238. "\\(\\<end\\>\\s-+\\<else\\>\\)\\|" ; 3
  2239. "\\(\\<always\\(?:_ff\\)?\\>\\(?:[ \t]*@\\)\\)\\|" ; 4 (matches always or always_ff w/ @...)
  2240. "\\(\\<always\\(?:_comb\\|_latch\\)?\\>\\)\\|" ; 5 (matches always, always_comb, always_latch w/o @...)
  2241. "\\(\\<fork\\>\\)\\|" ; 7
  2242. "\\(\\<if\\>\\)\\|"
  2243. verilog-property-re "\\|"
  2244. "\\(\\(" verilog-label-re "\\)?\\<assert\\>\\)\\|"
  2245. "\\(\\<clocking\\>\\)\\|"
  2246. "\\(\\<task\\>\\)\\|"
  2247. "\\(\\<function\\>\\)\\|"
  2248. "\\(\\<initial\\>\\)\\|"
  2249. "\\(\\<interface\\>\\)\\|"
  2250. "\\(\\<package\\>\\)\\|"
  2251. "\\(\\<final\\>\\)\\|"
  2252. "\\(@\\)\\|"
  2253. "\\(\\<while\\>\\)\\|\\(\\<do\\>\\)\\|"
  2254. "\\(\\<for\\(ever\\|each\\)?\\>\\)\\|"
  2255. "\\(\\<repeat\\>\\)\\|\\(\\<wait\\>\\)\\|"
  2256. "#"))
  2257. (defconst verilog-named-block-re "begin[ \t]*:")
  2258. ;; These words begin a block which can occur inside a module which should be indented,
  2259. ;; and closed with the respective word from the end-block list
  2260. (defconst verilog-beg-block-re
  2261. (eval-when-compile
  2262. (verilog-regexp-words
  2263. `("begin"
  2264. "case" "casex" "casez" "randcase"
  2265. "clocking"
  2266. "generate"
  2267. "fork"
  2268. "function"
  2269. "property"
  2270. "specify"
  2271. "table"
  2272. "task"
  2273. ;; OVM
  2274. "`ovm_component_utils_begin"
  2275. "`ovm_component_param_utils_begin"
  2276. "`ovm_field_utils_begin"
  2277. "`ovm_object_utils_begin"
  2278. "`ovm_object_param_utils_begin"
  2279. "`ovm_sequence_utils_begin"
  2280. "`ovm_sequencer_utils_begin"
  2281. ;; UVM
  2282. "`uvm_component_utils_begin"
  2283. "`uvm_component_param_utils_begin"
  2284. "`uvm_field_utils_begin"
  2285. "`uvm_object_utils_begin"
  2286. "`uvm_object_param_utils_begin"
  2287. "`uvm_sequence_utils_begin"
  2288. "`uvm_sequencer_utils_begin"
  2289. ;; VMM
  2290. "`vmm_data_member_begin"
  2291. "`vmm_env_member_begin"
  2292. "`vmm_scenario_member_begin"
  2293. "`vmm_subenv_member_begin"
  2294. "`vmm_xactor_member_begin"
  2295. ))))
  2296. ;; These are the same words, in a specific order in the regular
  2297. ;; expression so that matching will work nicely for
  2298. ;; verilog-forward-sexp and verilog-calc-indent
  2299. (defconst verilog-beg-block-re-ordered
  2300. ( concat "\\(\\<begin\\>\\)" ;1
  2301. "\\|\\(\\<randcase\\>\\|\\(\\<unique0?\\s-+\\|priority\\s-+\\)?case[xz]?\\>\\)" ; 2,3
  2302. "\\|\\(\\(\\<disable\\>\\s-+\\|\\<wait\\>\\s-+\\)?fork\\>\\)" ;4,5
  2303. "\\|\\(\\<class\\>\\)" ;6
  2304. "\\|\\(\\<table\\>\\)" ;7
  2305. "\\|\\(\\<specify\\>\\)" ;8
  2306. "\\|\\(\\<function\\>\\)" ;9
  2307. "\\|\\(\\(\\(\\<virtual\\>\\s-+\\)\\|\\(\\<protected\\>\\s-+\\)\\)*\\<function\\>\\)" ;10
  2308. "\\|\\(\\<task\\>\\)" ;14
  2309. "\\|\\(\\(\\(\\<virtual\\>\\s-+\\)\\|\\(\\<protected\\>\\s-+\\)\\)*\\<task\\>\\)" ;15
  2310. "\\|\\(\\<generate\\>\\)" ;18
  2311. "\\|\\(\\<covergroup\\>\\)" ;16 20
  2312. "\\|\\(\\(\\(\\<cover\\>\\s-+\\)\\|\\(\\<assert\\>\\s-+\\)\\)*\\<property\\>\\)" ;17 21
  2313. "\\|\\(\\<\\(rand\\)?sequence\\>\\)" ;21 25
  2314. "\\|\\(\\<clocking\\>\\)" ;22 27
  2315. "\\|\\(\\<`[ou]vm_[a-z_]+_begin\\>\\)" ;28
  2316. "\\|\\(\\<`vmm_[a-z_]+_member_begin\\>\\)"
  2317. ;;
  2318. ))
  2319. (defconst verilog-end-block-ordered-rry
  2320. [ "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)\\|\\(\\<endcase\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)"
  2321. "\\(\\<randcase\\>\\|\\<case[xz]?\\>\\)\\|\\(\\<endcase\\>\\)"
  2322. "\\(\\<fork\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)"
  2323. "\\(\\<class\\>\\)\\|\\(\\<endclass\\>\\)"
  2324. "\\(\\<table\\>\\)\\|\\(\\<endtable\\>\\)"
  2325. "\\(\\<specify\\>\\)\\|\\(\\<endspecify\\>\\)"
  2326. "\\(\\<function\\>\\)\\|\\(\\<endfunction\\>\\)"
  2327. "\\(\\<generate\\>\\)\\|\\(\\<endgenerate\\>\\)"
  2328. "\\(\\<task\\>\\)\\|\\(\\<endtask\\>\\)"
  2329. "\\(\\<covergroup\\>\\)\\|\\(\\<endgroup\\>\\)"
  2330. "\\(\\<property\\>\\)\\|\\(\\<endproperty\\>\\)"
  2331. "\\(\\<\\(rand\\)?sequence\\>\\)\\|\\(\\<endsequence\\>\\)"
  2332. "\\(\\<clocking\\>\\)\\|\\(\\<endclocking\\>\\)"
  2333. ] )
  2334. (defconst verilog-nameable-item-re
  2335. (eval-when-compile
  2336. (verilog-regexp-words
  2337. `("begin"
  2338. "fork"
  2339. "join" "join_any" "join_none"
  2340. "end"
  2341. "endcase"
  2342. "endchecker"
  2343. "endclass"
  2344. "endclocking"
  2345. "endconfig"
  2346. "endfunction"
  2347. "endgenerate"
  2348. "endgroup"
  2349. "endmodule"
  2350. "endprimitive"
  2351. "endinterface"
  2352. "endpackage"
  2353. "endprogram"
  2354. "endproperty"
  2355. "endsequence"
  2356. "endspecify"
  2357. "endtable"
  2358. "endtask" )
  2359. )))
  2360. (defconst verilog-declaration-opener
  2361. (eval-when-compile
  2362. (verilog-regexp-words
  2363. `("module" "begin" "task" "function"))))
  2364. (defconst verilog-declaration-prefix-re
  2365. (eval-when-compile
  2366. (verilog-regexp-words
  2367. `(
  2368. ;; port direction
  2369. "inout" "input" "output" "ref"
  2370. ;; changeableness
  2371. "const" "static" "protected" "local"
  2372. ;; parameters
  2373. "localparam" "parameter" "var"
  2374. ;; type creation
  2375. "typedef"
  2376. ))))
  2377. (defconst verilog-declaration-core-re
  2378. (eval-when-compile
  2379. (verilog-regexp-words
  2380. `(
  2381. ;; port direction (by themselves)
  2382. "inout" "input" "output"
  2383. ;; integer_atom_type
  2384. "byte" "shortint" "int" "longint" "integer" "time"
  2385. ;; integer_vector_type
  2386. "bit" "logic" "reg"
  2387. ;; non_integer_type
  2388. "shortreal" "real" "realtime"
  2389. ;; net_type
  2390. "supply0" "supply1" "tri" "triand" "trior" "trireg" "tri0" "tri1" "uwire" "wire" "wand" "wor"
  2391. ;; misc
  2392. "string" "event" "chandle" "virtual" "enum" "genvar"
  2393. "struct" "union"
  2394. ;; builtin classes
  2395. "mailbox" "semaphore"
  2396. ))))
  2397. (defconst verilog-declaration-re
  2398. (concat "\\(" verilog-declaration-prefix-re "\\s-*\\)?" verilog-declaration-core-re))
  2399. (defconst verilog-range-re "\\(\\[[^]]*\\]\\s-*\\)+")
  2400. (defconst verilog-optional-signed-re "\\s-*\\(\\(un\\)?signed\\)?")
  2401. (defconst verilog-optional-signed-range-re
  2402. (concat
  2403. "\\s-*\\(\\<\\(reg\\|wire\\)\\>\\s-*\\)?\\(\\<\\(un\\)?signed\\>\\s-*\\)?\\(" verilog-range-re "\\)?"))
  2404. (defconst verilog-macroexp-re "`\\sw+")
  2405. (defconst verilog-delay-re "#\\s-*\\(\\([0-9_]+\\('s?[hdxbo][0-9a-fA-F_xz]+\\)?\\)\\|\\(([^()]*)\\)\\|\\(\\sw+\\)\\)")
  2406. (defconst verilog-declaration-re-2-no-macro
  2407. (concat "\\s-*" verilog-declaration-re
  2408. "\\s-*\\(\\(" verilog-optional-signed-range-re "\\)\\|\\(" verilog-delay-re "\\)"
  2409. "\\)?"))
  2410. (defconst verilog-declaration-re-2-macro
  2411. (concat "\\s-*" verilog-declaration-re
  2412. "\\s-*\\(\\(" verilog-optional-signed-range-re "\\)\\|\\(" verilog-delay-re "\\)"
  2413. "\\|\\(" verilog-macroexp-re "\\)"
  2414. "\\)?"))
  2415. (defconst verilog-declaration-re-1-macro
  2416. (concat "^" verilog-declaration-re-2-macro))
  2417. (defconst verilog-declaration-re-1-no-macro (concat "^" verilog-declaration-re-2-no-macro))
  2418. (defconst verilog-defun-re
  2419. (eval-when-compile (verilog-regexp-words `("macromodule" "module" "class" "program" "interface" "package" "primitive" "config"))))
  2420. (defconst verilog-end-defun-re
  2421. (eval-when-compile (verilog-regexp-words `("endmodule" "endclass" "endprogram" "endinterface" "endpackage" "endprimitive" "endconfig"))))
  2422. (defconst verilog-zero-indent-re
  2423. (concat verilog-defun-re "\\|" verilog-end-defun-re))
  2424. (defconst verilog-inst-comment-re
  2425. (eval-when-compile (verilog-regexp-words `("Outputs" "Inouts" "Inputs" "Interfaces" "Interfaced"))))
  2426. (defconst verilog-behavioral-block-beg-re
  2427. (eval-when-compile (verilog-regexp-words `("initial" "final" "always" "always_comb" "always_latch" "always_ff"
  2428. "function" "task"))))
  2429. (defconst verilog-coverpoint-re "\\w+\\s*:\\s*\\(coverpoint\\|cross\\constraint\\)" )
  2430. (defconst verilog-in-constraint-re ; keywords legal in constraint blocks starting a statement/block
  2431. (eval-when-compile (verilog-regexp-words `("if" "else" "solve" "foreach"))))
  2432. (defconst verilog-indent-re
  2433. (eval-when-compile
  2434. (verilog-regexp-words
  2435. `(
  2436. "{"
  2437. "always" "always_latch" "always_ff" "always_comb"
  2438. "begin" "end"
  2439. ;; "unique" "priority"
  2440. "case" "casex" "casez" "randcase" "endcase"
  2441. "class" "endclass"
  2442. "clocking" "endclocking"
  2443. "config" "endconfig"
  2444. "covergroup" "endgroup"
  2445. "fork" "join" "join_any" "join_none"
  2446. "function" "endfunction"
  2447. "final"
  2448. "generate" "endgenerate"
  2449. "initial"
  2450. "interface" "endinterface"
  2451. "module" "macromodule" "endmodule"
  2452. "package" "endpackage"
  2453. "primitive" "endprimitive"
  2454. "program" "endprogram"
  2455. "property" "endproperty"
  2456. "sequence" "randsequence" "endsequence"
  2457. "specify" "endspecify"
  2458. "table" "endtable"
  2459. "task" "endtask"
  2460. "virtual"
  2461. "`case"
  2462. "`default"
  2463. "`define" "`undef"
  2464. "`if" "`ifdef" "`ifndef" "`else" "`elsif" "`endif"
  2465. "`while" "`endwhile"
  2466. "`for" "`endfor"
  2467. "`format"
  2468. "`include"
  2469. "`let"
  2470. "`protect" "`endprotect"
  2471. "`switch" "`endswitch"
  2472. "`timescale"
  2473. "`time_scale"
  2474. ;; OVM Begin tokens
  2475. "`ovm_component_utils_begin"
  2476. "`ovm_component_param_utils_begin"
  2477. "`ovm_field_utils_begin"
  2478. "`ovm_object_utils_begin"
  2479. "`ovm_object_param_utils_begin"
  2480. "`ovm_sequence_utils_begin"
  2481. "`ovm_sequencer_utils_begin"
  2482. ;; OVM End tokens
  2483. "`ovm_component_utils_end"
  2484. "`ovm_field_utils_end"
  2485. "`ovm_object_utils_end"
  2486. "`ovm_sequence_utils_end"
  2487. "`ovm_sequencer_utils_end"
  2488. ;; UVM Begin tokens
  2489. "`uvm_component_utils_begin"
  2490. "`uvm_component_param_utils_begin"
  2491. "`uvm_field_utils_begin"
  2492. "`uvm_object_utils_begin"
  2493. "`uvm_object_param_utils_begin"
  2494. "`uvm_sequence_utils_begin"
  2495. "`uvm_sequencer_utils_begin"
  2496. ;; UVM End tokens
  2497. "`uvm_component_utils_end" ; Typo in spec, it's not uvm_component_end
  2498. "`uvm_field_utils_end"
  2499. "`uvm_object_utils_end"
  2500. "`uvm_sequence_utils_end"
  2501. "`uvm_sequencer_utils_end"
  2502. ;; VMM Begin tokens
  2503. "`vmm_data_member_begin"
  2504. "`vmm_env_member_begin"
  2505. "`vmm_scenario_member_begin"
  2506. "`vmm_subenv_member_begin"
  2507. "`vmm_xactor_member_begin"
  2508. ;; VMM End tokens
  2509. "`vmm_data_member_end"
  2510. "`vmm_env_member_end"
  2511. "`vmm_scenario_member_end"
  2512. "`vmm_subenv_member_end"
  2513. "`vmm_xactor_member_end"
  2514. ))))
  2515. (defconst verilog-defun-level-not-generate-re
  2516. (eval-when-compile
  2517. (verilog-regexp-words
  2518. `( "module" "macromodule" "primitive" "class" "program"
  2519. "interface" "package" "config"))))
  2520. (defconst verilog-defun-level-re
  2521. (eval-when-compile
  2522. (verilog-regexp-words
  2523. (append
  2524. `( "module" "macromodule" "primitive" "class" "program"
  2525. "interface" "package" "config")
  2526. `( "initial" "final" "always" "always_comb" "always_ff"
  2527. "always_latch" "endtask" "endfunction" )))))
  2528. (defconst verilog-defun-level-generate-only-re
  2529. (eval-when-compile
  2530. (verilog-regexp-words
  2531. `( "initial" "final" "always" "always_comb" "always_ff"
  2532. "always_latch" "endtask" "endfunction" ))))
  2533. (defconst verilog-cpp-level-re
  2534. (eval-when-compile
  2535. (verilog-regexp-words
  2536. `(
  2537. "endmodule" "endprimitive" "endinterface" "endpackage" "endprogram" "endclass"
  2538. ))))
  2539. (defconst verilog-dpi-import-export-re
  2540. (eval-when-compile
  2541. "\\(\\<\\(import\\|export\\)\\>\\s-+\"DPI\\(-C\\)?\"\\s-+\\(\\<\\(context\\|pure\\)\\>\\s-+\\)?\\([A-Za-z_][A-Za-z0-9_]*\\s-*=\\s-*\\)?\\<\\(function\\|task\\)\\>\\)"
  2542. ))
  2543. (defconst verilog-disable-fork-re "\\(disable\\|wait\\)\\s-+fork\\>")
  2544. (defconst verilog-extended-case-re "\\(\\(unique0?\\s-+\\|priority\\s-+\\)?case[xz]?\\)")
  2545. (defconst verilog-extended-complete-re
  2546. (concat "\\(\\(\\<extern\\s-+\\|\\<\\(\\<\\(pure\\|context\\)\\>\\s-+\\)?virtual\\s-+\\|\\<protected\\s-+\\)*\\(\\<function\\>\\|\\<task\\>\\)\\)"
  2547. "\\|\\(\\(\\<typedef\\>\\s-+\\)*\\(\\<struct\\>\\|\\<union\\>\\|\\<class\\>\\)\\)"
  2548. "\\|\\(\\(\\<\\(import\\|export\\)\\>\\s-+\\)?\\(\"DPI\\(-C\\)?\"\\s-+\\)?\\(\\<\\(pure\\|context\\)\\>\\s-+\\)?\\([A-Za-z_][A-Za-z0-9_]*\\s-*=\\s-*\\)?\\(function\\>\\|task\\>\\)\\)"
  2549. "\\|" verilog-extended-case-re ))
  2550. (defconst verilog-basic-complete-re
  2551. (eval-when-compile
  2552. (verilog-regexp-words
  2553. `(
  2554. "always" "assign" "always_latch" "always_ff" "always_comb" "constraint"
  2555. "import" "initial" "final" "module" "macromodule" "repeat" "randcase" "while"
  2556. "if" "for" "forever" "foreach" "else" "parameter" "do" "localparam" "assert"
  2557. ))))
  2558. (defconst verilog-complete-reg
  2559. (concat
  2560. verilog-extended-complete-re "\\|\\(" verilog-basic-complete-re "\\)"))
  2561. (defconst verilog-end-statement-re
  2562. (concat "\\(" verilog-beg-block-re "\\)\\|\\("
  2563. verilog-end-block-re "\\)"))
  2564. (defconst verilog-endcase-re
  2565. (concat verilog-extended-case-re "\\|"
  2566. "\\(endcase\\)\\|"
  2567. verilog-defun-re
  2568. ))
  2569. (defconst verilog-exclude-str-start "/* -----\\/----- EXCLUDED -----\\/-----"
  2570. "String used to mark beginning of excluded text.")
  2571. (defconst verilog-exclude-str-end " -----/\\----- EXCLUDED -----/\\----- */"
  2572. "String used to mark end of excluded text.")
  2573. (defconst verilog-preprocessor-re
  2574. (eval-when-compile
  2575. (concat
  2576. ;; single words
  2577. "\\(?:"
  2578. (verilog-regexp-words
  2579. `("`__FILE__"
  2580. "`__LINE__"
  2581. "`celldefine"
  2582. "`else"
  2583. "`end_keywords"
  2584. "`endcelldefine"
  2585. "`endif"
  2586. "`nounconnected_drive"
  2587. "`resetall"
  2588. "`unconnected_drive"
  2589. "`undefineall"))
  2590. "\\)\\|\\(?:"
  2591. ;; two words: i.e. `ifdef DEFINE
  2592. "\\<\\(`elsif\\|`ifn?def\\|`undef\\|`default_nettype\\|`begin_keywords\\)\\>\\s-"
  2593. "\\)\\|\\(?:"
  2594. ;; `line number "filename" level
  2595. "\\<\\(`line\\)\\>\\s-+[0-9]+\\s-+\"[^\"]+\"\\s-+[012]"
  2596. "\\)\\|\\(?:"
  2597. ;;`include "file" or `include <file>
  2598. "\\<\\(`include\\)\\>\\s-+\\(?:\"[^\"]+\"\\|<[^>]+>\\)"
  2599. "\\)\\|\\(?:"
  2600. ;; `pragma <stuff> (no mention in IEEE 1800-2012 that pragma can span multiple lines
  2601. "\\<\\(`pragma\\)\\>\\s-+.+$"
  2602. "\\)\\|\\(?:"
  2603. ;; `timescale time_unit / time_precision
  2604. "\\<\\(`timescale\\)\\>\\s-+10\\{0,2\\}\\s-*[munpf]?s\\s-*\\/\\s-*10\\{0,2\\}\\s-*[munpf]?s"
  2605. "\\)\\|\\(?:"
  2606. ;; `define and `if can span multiple lines if line ends in '\'. NOTE: `if is not IEEE 1800-2012
  2607. ;; from http://www.emacswiki.org/emacs/MultilineRegexp
  2608. (concat "\\<\\(`define\\|`if\\)\\>" ; directive
  2609. "\\s-+" ; separator
  2610. "\\(?:.*?\\(?:\n.*\\)*?\\)" ; definition: to end of line, then maybe more lines (excludes any trailing \n)
  2611. "\\(?:\n\\s-*\n\\|\\'\\)") ; blank line or EOF
  2612. "\\)\\|\\(?:"
  2613. ;; `<macro>() : i.e. `uvm_info(a,b,c) or any other pre-defined macro
  2614. ;; Since parameters inside the macro can have parentheses, and
  2615. ;; the macro can span multiple lines, just look for the opening
  2616. ;; parentheses and then continue to the end of the first
  2617. ;; non-escaped EOL
  2618. (concat "\\<`\\w+\\>\\s-*("
  2619. "\\(?:.*?\\(?:\n.*\\)*?\\)" ; definition: to end of line, then maybe more lines (excludes any trailing \n)
  2620. "\\(?:\n\\s-*\n\\|\\'\\)") ; blank line or EOF
  2621. "\\)"
  2622. )))
  2623. (defconst verilog-keywords
  2624. (append verilog-compiler-directives
  2625. '(
  2626. "after" "alias" "always" "always_comb" "always_ff" "always_latch" "and"
  2627. "assert" "assign" "assume" "automatic" "before" "begin" "bind"
  2628. "bins" "binsof" "bit" "break" "buf" "bufif0" "bufif1" "byte"
  2629. "case" "casex" "casez" "cell" "chandle" "class" "clocking" "cmos"
  2630. "config" "const" "constraint" "context" "continue" "cover"
  2631. "covergroup" "coverpoint" "cross" "deassign" "default" "defparam"
  2632. "design" "disable" "dist" "do" "edge" "else" "end" "endcase"
  2633. "endclass" "endclocking" "endconfig" "endfunction" "endgenerate"
  2634. "endgroup" "endinterface" "endmodule" "endpackage" "endprimitive"
  2635. "endprogram" "endproperty" "endspecify" "endsequence" "endtable"
  2636. "endtask" "enum" "event" "expect" "export" "extends" "extern"
  2637. "final" "first_match" "for" "force" "foreach" "forever" "fork"
  2638. "forkjoin" "function" "generate" "genvar" "highz0" "highz1" "if"
  2639. "iff" "ifnone" "ignore_bins" "illegal_bins" "import" "incdir"
  2640. "include" "initial" "inout" "input" "inside" "instance" "int"
  2641. "integer" "interface" "intersect" "join" "join_any" "join_none"
  2642. "large" "liblist" "library" "local" "localparam" "logic"
  2643. "longint" "macromodule" "mailbox" "matches" "medium" "modport" "module"
  2644. "nand" "negedge" "new" "nmos" "nor" "noshowcancelled" "not"
  2645. "notif0" "notif1" "null" "or" "output" "package" "packed"
  2646. "parameter" "pmos" "posedge" "primitive" "priority" "program"
  2647. "property" "protected" "pull0" "pull1" "pulldown" "pullup"
  2648. "pulsestyle_onevent" "pulsestyle_ondetect" "pure" "rand" "randc"
  2649. "randcase" "randsequence" "rcmos" "real" "realtime" "ref" "reg"
  2650. "release" "repeat" "return" "rnmos" "rpmos" "rtran" "rtranif0"
  2651. "rtranif1" "scalared" "semaphore" "sequence" "shortint" "shortreal"
  2652. "showcancelled" "signed" "small" "solve" "specify" "specparam"
  2653. "static" "string" "strong0" "strong1" "struct" "super" "supply0"
  2654. "supply1" "table" "tagged" "task" "this" "throughout" "time"
  2655. "timeprecision" "timeunit" "tran" "tranif0" "tranif1" "tri"
  2656. "tri0" "tri1" "triand" "trior" "trireg" "type" "typedef" "union"
  2657. "unique" "unsigned" "use" "uwire" "var" "vectored" "virtual" "void"
  2658. "wait" "wait_order" "wand" "weak0" "weak1" "while" "wildcard"
  2659. "wire" "with" "within" "wor" "xnor" "xor"
  2660. ;; 1800-2009
  2661. "accept_on" "checker" "endchecker" "eventually" "global" "implies"
  2662. "let" "nexttime" "reject_on" "restrict" "s_always" "s_eventually"
  2663. "s_nexttime" "s_until" "s_until_with" "strong" "sync_accept_on"
  2664. "sync_reject_on" "unique0" "until" "until_with" "untyped" "weak"
  2665. ;; 1800-2012
  2666. "implements" "interconnect" "nettype" "soft"
  2667. ))
  2668. "List of Verilog keywords.")
  2669. (defconst verilog-comment-start-regexp "//\\|/\\*"
  2670. "Dual comment value for `comment-start-regexp'.")
  2671. (defvar verilog-mode-syntax-table
  2672. (let ((table (make-syntax-table)))
  2673. ;; Populate the syntax TABLE.
  2674. (modify-syntax-entry ?\\ "\\" table)
  2675. (modify-syntax-entry ?+ "." table)
  2676. (modify-syntax-entry ?- "." table)
  2677. (modify-syntax-entry ?= "." table)
  2678. (modify-syntax-entry ?% "." table)
  2679. (modify-syntax-entry ?< "." table)
  2680. (modify-syntax-entry ?> "." table)
  2681. (modify-syntax-entry ?& "." table)
  2682. (modify-syntax-entry ?| "." table)
  2683. ;; FIXME: This goes against Emacs conventions. Use "_" syntax instead and
  2684. ;; then use regexps with things like "\\_<...\\_>".
  2685. (modify-syntax-entry ?` "w" table) ; ` is part of definition symbols in Verilog
  2686. (modify-syntax-entry ?_ "w" table)
  2687. (modify-syntax-entry ?\' "." table)
  2688. ;; Set up TABLE to handle block and line style comments.
  2689. (if (featurep 'xemacs)
  2690. (progn
  2691. ;; XEmacs (formerly Lucid) has the best implementation
  2692. (modify-syntax-entry ?/ ". 1456" table)
  2693. (modify-syntax-entry ?* ". 23" table)
  2694. (modify-syntax-entry ?\n "> b" table))
  2695. ;; Emacs does things differently, but we can work with it
  2696. (modify-syntax-entry ?/ ". 124b" table)
  2697. (modify-syntax-entry ?* ". 23" table)
  2698. (modify-syntax-entry ?\n "> b" table))
  2699. table)
  2700. "Syntax table used in Verilog mode buffers.")
  2701. (defvar verilog-font-lock-keywords nil
  2702. "Default highlighting for Verilog mode.")
  2703. (defvar verilog-font-lock-keywords-1 nil
  2704. "Subdued level highlighting for Verilog mode.")
  2705. (defvar verilog-font-lock-keywords-2 nil
  2706. "Medium level highlighting for Verilog mode.
  2707. See also `verilog-font-lock-extra-types'.")
  2708. (defvar verilog-font-lock-keywords-3 nil
  2709. "Gaudy level highlighting for Verilog mode.
  2710. See also `verilog-font-lock-extra-types'.")
  2711. (defvar verilog-font-lock-translate-off-face
  2712. 'verilog-font-lock-translate-off-face
  2713. "Font to use for translated off regions.")
  2714. (defface verilog-font-lock-translate-off-face
  2715. '((((class color)
  2716. (background light))
  2717. (:background "gray90" :italic t ))
  2718. (((class color)
  2719. (background dark))
  2720. (:background "gray10" :italic t ))
  2721. (((class grayscale) (background light))
  2722. (:foreground "DimGray" :italic t))
  2723. (((class grayscale) (background dark))
  2724. (:foreground "LightGray" :italic t))
  2725. (t (:italis t)))
  2726. "Font lock mode face used to background highlight translate-off regions."
  2727. :group 'font-lock-highlighting-faces)
  2728. (defvar verilog-font-lock-p1800-face
  2729. 'verilog-font-lock-p1800-face
  2730. "Font to use for p1800 keywords.")
  2731. (defface verilog-font-lock-p1800-face
  2732. '((((class color)
  2733. (background light))
  2734. (:foreground "DarkOrange3" :bold t ))
  2735. (((class color)
  2736. (background dark))
  2737. (:foreground "orange1" :bold t ))
  2738. (t (:italic t)))
  2739. "Font lock mode face used to highlight P1800 keywords."
  2740. :group 'font-lock-highlighting-faces)
  2741. (defvar verilog-font-lock-ams-face
  2742. 'verilog-font-lock-ams-face
  2743. "Font to use for Analog/Mixed Signal keywords.")
  2744. (defface verilog-font-lock-ams-face
  2745. '((((class color)
  2746. (background light))
  2747. (:foreground "Purple" :bold t ))
  2748. (((class color)
  2749. (background dark))
  2750. (:foreground "orange1" :bold t ))
  2751. (t (:italic t)))
  2752. "Font lock mode face used to highlight AMS keywords."
  2753. :group 'font-lock-highlighting-faces)
  2754. (defvar verilog-font-grouping-keywords-face
  2755. 'verilog-font-lock-grouping-keywords-face
  2756. "Font to use for Verilog Grouping Keywords (such as begin..end).")
  2757. (defface verilog-font-lock-grouping-keywords-face
  2758. '((((class color)
  2759. (background light))
  2760. (:foreground "Purple" :bold t ))
  2761. (((class color)
  2762. (background dark))
  2763. (:foreground "orange1" :bold t ))
  2764. (t (:italic t)))
  2765. "Font lock mode face used to highlight verilog grouping keywords."
  2766. :group 'font-lock-highlighting-faces)
  2767. (let* ((verilog-type-font-keywords
  2768. (eval-when-compile
  2769. (verilog-regexp-opt
  2770. '(
  2771. "and" "bit" "buf" "bufif0" "bufif1" "cmos" "defparam"
  2772. "event" "genvar" "inout" "input" "integer" "localparam"
  2773. "logic" "mailbox" "nand" "nmos" "nor" "not" "notif0" "notif1" "or"
  2774. "output" "parameter" "pmos" "pull0" "pull1" "pulldown" "pullup"
  2775. "rcmos" "real" "realtime" "reg" "rnmos" "rpmos" "rtran"
  2776. "rtranif0" "rtranif1" "semaphore" "signed" "struct" "supply"
  2777. "supply0" "supply1" "time" "tran" "tranif0" "tranif1"
  2778. "tri" "tri0" "tri1" "triand" "trior" "trireg" "typedef"
  2779. "uwire" "vectored" "wand" "wire" "wor" "xnor" "xor"
  2780. ) nil )))
  2781. (verilog-pragma-keywords
  2782. (eval-when-compile
  2783. (verilog-regexp-opt
  2784. '("surefire" "auto" "synopsys" "rtl_synthesis" "verilint" "leda" "0in"
  2785. ) nil )))
  2786. (verilog-1800-2005-keywords
  2787. (eval-when-compile
  2788. (verilog-regexp-opt
  2789. '("alias" "assert" "assume" "automatic" "before" "bind"
  2790. "bins" "binsof" "break" "byte" "cell" "chandle" "class"
  2791. "clocking" "config" "const" "constraint" "context" "continue"
  2792. "cover" "covergroup" "coverpoint" "cross" "deassign" "design"
  2793. "dist" "do" "edge" "endclass" "endclocking" "endconfig"
  2794. "endgroup" "endprogram" "endproperty" "endsequence" "enum"
  2795. "expect" "export" "extends" "extern" "first_match" "foreach"
  2796. "forkjoin" "genvar" "highz0" "highz1" "ifnone" "ignore_bins"
  2797. "illegal_bins" "import" "incdir" "include" "inside" "instance"
  2798. "int" "intersect" "large" "liblist" "library" "local" "longint"
  2799. "matches" "medium" "modport" "new" "noshowcancelled" "null"
  2800. "packed" "program" "property" "protected" "pull0" "pull1"
  2801. "pulsestyle_onevent" "pulsestyle_ondetect" "pure" "rand" "randc"
  2802. "randcase" "randsequence" "ref" "release" "return" "scalared"
  2803. "sequence" "shortint" "shortreal" "showcancelled" "small" "solve"
  2804. "specparam" "static" "string" "strong0" "strong1" "struct"
  2805. "super" "tagged" "this" "throughout" "timeprecision" "timeunit"
  2806. "type" "union" "unsigned" "use" "var" "virtual" "void"
  2807. "wait_order" "weak0" "weak1" "wildcard" "with" "within"
  2808. ) nil )))
  2809. (verilog-1800-2009-keywords
  2810. (eval-when-compile
  2811. (verilog-regexp-opt
  2812. '("accept_on" "checker" "endchecker" "eventually" "global"
  2813. "implies" "let" "nexttime" "reject_on" "restrict" "s_always"
  2814. "s_eventually" "s_nexttime" "s_until" "s_until_with" "strong"
  2815. "sync_accept_on" "sync_reject_on" "unique0" "until"
  2816. "until_with" "untyped" "weak" ) nil )))
  2817. (verilog-1800-2012-keywords
  2818. (eval-when-compile
  2819. (verilog-regexp-opt
  2820. '("implements" "interconnect" "nettype" "soft" ) nil )))
  2821. (verilog-ams-keywords
  2822. (eval-when-compile
  2823. (verilog-regexp-opt
  2824. '("above" "abs" "absdelay" "acos" "acosh" "ac_stim"
  2825. "aliasparam" "analog" "analysis" "asin" "asinh" "atan" "atan2" "atanh"
  2826. "branch" "ceil" "connectmodule" "connectrules" "cos" "cosh" "ddt"
  2827. "ddx" "discipline" "driver_update" "enddiscipline" "endconnectrules"
  2828. "endnature" "endparamset" "exclude" "exp" "final_step" "flicker_noise"
  2829. "floor" "flow" "from" "ground" "hypot" "idt" "idtmod" "inf"
  2830. "initial_step" "laplace_nd" "laplace_np" "laplace_zd" "laplace_zp"
  2831. "last_crossing" "limexp" "ln" "log" "max" "min" "nature"
  2832. "net_resolution" "noise_table" "paramset" "potential" "pow" "sin"
  2833. "sinh" "slew" "sqrt" "tan" "tanh" "timer" "transition" "white_noise"
  2834. "wreal" "zi_nd" "zi_np" "zi_zd" ) nil )))
  2835. (verilog-font-keywords
  2836. (eval-when-compile
  2837. (verilog-regexp-opt
  2838. '(
  2839. "assign" "case" "casex" "casez" "randcase" "deassign"
  2840. "default" "disable" "else" "endcase" "endfunction"
  2841. "endgenerate" "endinterface" "endmodule" "endprimitive"
  2842. "endspecify" "endtable" "endtask" "final" "for" "force" "return" "break"
  2843. "continue" "forever" "fork" "function" "generate" "if" "iff" "initial"
  2844. "interface" "join" "join_any" "join_none" "macromodule" "module" "negedge"
  2845. "package" "endpackage" "always" "always_comb" "always_ff"
  2846. "always_latch" "posedge" "primitive" "priority" "release"
  2847. "repeat" "specify" "table" "task" "unique" "wait" "while"
  2848. "class" "program" "endclass" "endprogram"
  2849. ) nil )))
  2850. (verilog-font-grouping-keywords
  2851. (eval-when-compile
  2852. (verilog-regexp-opt
  2853. '( "begin" "end" ) nil ))))
  2854. (setq verilog-font-lock-keywords
  2855. (list
  2856. ;; Fontify all builtin keywords
  2857. (concat "\\<\\(" verilog-font-keywords "\\|"
  2858. ;; And user/system tasks and functions
  2859. "\\$[a-zA-Z][a-zA-Z0-9_\\$]*"
  2860. "\\)\\>")
  2861. ;; Fontify all types
  2862. (if verilog-highlight-grouping-keywords
  2863. (cons (concat "\\<\\(" verilog-font-grouping-keywords "\\)\\>")
  2864. 'verilog-font-lock-grouping-keywords-face)
  2865. (cons (concat "\\<\\(" verilog-font-grouping-keywords "\\)\\>")
  2866. 'font-lock-type-face))
  2867. (cons (concat "\\<\\(" verilog-type-font-keywords "\\)\\>")
  2868. 'font-lock-type-face)
  2869. ;; Fontify IEEE-1800-2005 keywords appropriately
  2870. (if verilog-highlight-p1800-keywords
  2871. (cons (concat "\\<\\(" verilog-1800-2005-keywords "\\)\\>")
  2872. 'verilog-font-lock-p1800-face)
  2873. (cons (concat "\\<\\(" verilog-1800-2005-keywords "\\)\\>")
  2874. 'font-lock-type-face))
  2875. ;; Fontify IEEE-1800-2009 keywords appropriately
  2876. (if verilog-highlight-p1800-keywords
  2877. (cons (concat "\\<\\(" verilog-1800-2009-keywords "\\)\\>")
  2878. 'verilog-font-lock-p1800-face)
  2879. (cons (concat "\\<\\(" verilog-1800-2009-keywords "\\)\\>")
  2880. 'font-lock-type-face))
  2881. ;; Fontify IEEE-1800-2012 keywords appropriately
  2882. (if verilog-highlight-p1800-keywords
  2883. (cons (concat "\\<\\(" verilog-1800-2012-keywords "\\)\\>")
  2884. 'verilog-font-lock-p1800-face)
  2885. (cons (concat "\\<\\(" verilog-1800-2012-keywords "\\)\\>")
  2886. 'font-lock-type-face))
  2887. ;; Fontify Verilog-AMS keywords
  2888. (cons (concat "\\<\\(" verilog-ams-keywords "\\)\\>")
  2889. 'verilog-font-lock-ams-face)))
  2890. (setq verilog-font-lock-keywords-1
  2891. (append verilog-font-lock-keywords
  2892. (list
  2893. ;; Fontify module definitions
  2894. (list
  2895. "\\<\\(\\(macro\\)?module\\|primitive\\|class\\|program\\|interface\\|package\\|task\\)\\>\\s-*\\(\\sw+\\)"
  2896. '(1 font-lock-keyword-face)
  2897. '(3 font-lock-function-name-face 'prepend))
  2898. ;; Fontify function definitions
  2899. (list
  2900. (concat "\\<function\\>\\s-+\\(integer\\|real\\(time\\)?\\|time\\)\\s-+\\(\\sw+\\)" )
  2901. '(1 font-lock-keyword-face)
  2902. '(3 font-lock-constant-face prepend))
  2903. '("\\<function\\>\\s-+\\(\\[[^]]+\\]\\)\\s-+\\(\\sw+\\)"
  2904. (1 font-lock-keyword-face)
  2905. (2 font-lock-constant-face append))
  2906. '("\\<function\\>\\s-+\\(\\sw+\\)"
  2907. 1 'font-lock-constant-face append))))
  2908. (setq verilog-font-lock-keywords-2
  2909. (append verilog-font-lock-keywords-1
  2910. (list
  2911. ;; Fontify pragmas
  2912. (concat "\\(//\\s-*\\(" verilog-pragma-keywords "\\)\\s-.*\\)")
  2913. ;; Fontify escaped names
  2914. '("\\(\\\\\\S-*\\s-\\)" 0 font-lock-function-name-face)
  2915. ;; Fontify macro definitions/ uses
  2916. '("`\\s-*[A-Za-z][A-Za-z0-9_]*" 0 (if (boundp 'font-lock-preprocessor-face)
  2917. 'font-lock-preprocessor-face
  2918. 'font-lock-type-face))
  2919. ;; Fontify delays/numbers
  2920. '("\\(@\\)\\|\\([ \t\n\f\r]#\\s-*\\(\\([0-9_.]+\\('s?[hdxbo][0-9a-fA-F_xz]*\\)?\\)\\|\\(([^()]+)\\|\\sw+\\)\\)\\)"
  2921. 0 font-lock-type-face append)
  2922. ;; Fontify property/sequence cycle delays - these start with '##'
  2923. '("\\(##\\(\\sw+\\|\\[[^]]+\\]\\)\\)"
  2924. 0 font-lock-type-face append)
  2925. ;; Fontify instantiation names
  2926. '("\\([A-Za-z][A-Za-z0-9_]*\\)\\s-*(" 1 font-lock-function-name-face)
  2927. )))
  2928. (setq verilog-font-lock-keywords-3
  2929. (append verilog-font-lock-keywords-2
  2930. (when verilog-highlight-translate-off
  2931. (list
  2932. ;; Fontify things in translate off regions
  2933. '(verilog-match-translate-off
  2934. (0 'verilog-font-lock-translate-off-face prepend))
  2935. )))))
  2936. ;;
  2937. ;; Buffer state preservation
  2938. (defmacro verilog-save-buffer-state (&rest body)
  2939. "Execute BODY forms, saving state around insignificant change.
  2940. Changes in text properties like `face' or `syntax-table' are
  2941. considered insignificant. This macro allows text properties to
  2942. be changed, even in a read-only buffer.
  2943. A change is considered significant if it affects the buffer text
  2944. in any way that isn't completely restored again. Any
  2945. user-visible changes to the buffer must not be within a
  2946. `verilog-save-buffer-state'."
  2947. ;; From c-save-buffer-state
  2948. `(let* ((modified (buffer-modified-p))
  2949. (buffer-undo-list t)
  2950. (inhibit-read-only t)
  2951. (inhibit-point-motion-hooks t)
  2952. (verilog-no-change-functions t)
  2953. before-change-functions
  2954. after-change-functions
  2955. deactivate-mark
  2956. buffer-file-name ; Prevent primitives checking
  2957. buffer-file-truename) ; for file modification
  2958. (unwind-protect
  2959. (progn ,@body)
  2960. (and (not modified)
  2961. (buffer-modified-p)
  2962. (set-buffer-modified-p nil)))))
  2963. (defmacro verilog-save-no-change-functions (&rest body)
  2964. "Execute BODY forms, disabling all change hooks in BODY.
  2965. For insignificant changes, see instead `verilog-save-buffer-state'."
  2966. `(let* ((inhibit-point-motion-hooks t)
  2967. (verilog-no-change-functions t)
  2968. before-change-functions
  2969. after-change-functions)
  2970. (progn ,@body)))
  2971. (defvar verilog-save-font-mod-hooked nil
  2972. "Local variable when inside a `verilog-save-font-mods' block.")
  2973. (make-variable-buffer-local 'verilog-save-font-mod-hooked)
  2974. (defmacro verilog-save-font-mods (&rest body)
  2975. "Execute BODY forms, disabling text modifications to allow performing BODY.
  2976. Includes temporary disabling of `font-lock' to restore the buffer
  2977. to full text form for parsing. Additional actions may be specified with
  2978. `verilog-before-save-font-hook' and `verilog-after-save-font-hook'."
  2979. ;; Before version 20, match-string with font-lock returns a
  2980. ;; vector that is not equal to the string. IE if on "input"
  2981. ;; nil==(equal "input" (progn (looking-at "input") (match-string 0)))
  2982. `(let* ((hooked (unless verilog-save-font-mod-hooked
  2983. (verilog-run-hooks 'verilog-before-save-font-hook)
  2984. t))
  2985. (verilog-save-font-mod-hooked t)
  2986. (fontlocked (when (and (boundp 'font-lock-mode) font-lock-mode)
  2987. (font-lock-mode 0)
  2988. t)))
  2989. (unwind-protect
  2990. (progn ,@body)
  2991. ;; Unwind forms
  2992. (when fontlocked (font-lock-mode t))
  2993. (when hooked (verilog-run-hooks 'verilog-after-save-font-hook)))))
  2994. ;;
  2995. ;; Comment detection and caching
  2996. (defvar verilog-scan-cache-preserving nil
  2997. "If true, the specified buffer's comment properties are static.
  2998. Buffer changes will be ignored. See `verilog-inside-comment-or-string-p'
  2999. and `verilog-scan'.")
  3000. (defvar verilog-scan-cache-tick nil
  3001. "Modification tick at which `verilog-scan' was last completed.")
  3002. (make-variable-buffer-local 'verilog-scan-cache-tick)
  3003. (defun verilog-scan-cache-flush ()
  3004. "Flush the `verilog-scan' cache."
  3005. (setq verilog-scan-cache-tick nil))
  3006. (defun verilog-scan-cache-ok-p ()
  3007. "Return t if the scan cache is up to date."
  3008. (or (and verilog-scan-cache-preserving
  3009. (eq verilog-scan-cache-preserving (current-buffer))
  3010. verilog-scan-cache-tick)
  3011. (equal verilog-scan-cache-tick (buffer-chars-modified-tick))))
  3012. (defmacro verilog-save-scan-cache (&rest body)
  3013. "Execute the BODY forms, allowing scan cache preservation within BODY.
  3014. This requires that insertions must use `verilog-insert'."
  3015. ;; If the buffer is out of date, trash it, as we'll not check later the tick
  3016. ;; Note this must work properly if there's multiple layers of calls
  3017. ;; to verilog-save-scan-cache even with differing ticks.
  3018. `(progn
  3019. (unless (verilog-scan-cache-ok-p) ; Must be before let
  3020. (setq verilog-scan-cache-tick nil))
  3021. (let* ((verilog-scan-cache-preserving (current-buffer)))
  3022. (progn ,@body))))
  3023. (defun verilog-scan-region (beg end)
  3024. "Parse between BEG and END for `verilog-inside-comment-or-string-p'.
  3025. This creates v-cmts properties where comments are in force."
  3026. ;; Why properties and not overlays? Overlays have much slower non O(1)
  3027. ;; lookup times.
  3028. ;; This function is warm - called on every verilog-insert
  3029. (save-excursion
  3030. (save-match-data
  3031. (verilog-save-buffer-state
  3032. (let (pt)
  3033. (goto-char beg)
  3034. (while (< (point) end)
  3035. (cond ((looking-at "//")
  3036. (setq pt (point))
  3037. (or (search-forward "\n" end t)
  3038. (goto-char end))
  3039. ;; "1+": The leading // or /* itself isn't considered as
  3040. ;; being "inside" the comment, so that a (search-backward)
  3041. ;; that lands at the start of the // won't mis-indicate
  3042. ;; it's inside a comment. Also otherwise it would be
  3043. ;; hard to find a commented out /*AS*/ vs one that isn't
  3044. (put-text-property (1+ pt) (point) 'v-cmts t))
  3045. ((looking-at "/\\*")
  3046. (setq pt (point))
  3047. (or (search-forward "*/" end t)
  3048. ;; No error - let later code indicate it so we can
  3049. ;; use inside functions on-the-fly
  3050. ;;(error "%s: Unmatched /* */, at char %d"
  3051. ;; (verilog-point-text) (point))
  3052. (goto-char end))
  3053. (put-text-property (1+ pt) (point) 'v-cmts t))
  3054. ((looking-at "\"")
  3055. (setq pt (point))
  3056. (or (re-search-forward "[^\\]\"" end t) ; don't forward-char first, since we look for a non backslash first
  3057. ;; No error - let later code indicate it so we can
  3058. (goto-char end))
  3059. (put-text-property (1+ pt) (point) 'v-cmts t))
  3060. (t
  3061. (forward-char 1)
  3062. (if (re-search-forward "[/\"]" end t)
  3063. (backward-char 1)
  3064. (goto-char end))))))))))
  3065. (defun verilog-scan ()
  3066. "Parse the buffer, marking all comments with properties.
  3067. Also assumes any text inserted since `verilog-scan-cache-tick'
  3068. either is ok to parse as a non-comment, or `verilog-insert' was used."
  3069. ;; See also `verilog-scan-debug' and `verilog-scan-and-debug'
  3070. (unless (verilog-scan-cache-ok-p)
  3071. (save-excursion
  3072. (verilog-save-buffer-state
  3073. (when verilog-debug
  3074. (message "Scanning %s cache=%s cachetick=%S tick=%S" (current-buffer)
  3075. verilog-scan-cache-preserving verilog-scan-cache-tick
  3076. (buffer-chars-modified-tick)))
  3077. (remove-text-properties (point-min) (point-max) '(v-cmts nil))
  3078. (verilog-scan-region (point-min) (point-max))
  3079. (setq verilog-scan-cache-tick (buffer-chars-modified-tick))
  3080. (when verilog-debug (message "Scanning... done"))))))
  3081. (defun verilog-scan-debug ()
  3082. "For debugging, show with display face results of `verilog-scan'."
  3083. (font-lock-mode 0)
  3084. ;;(if dbg (setq dbg (concat dbg (format "verilog-scan-debug\n"))))
  3085. (save-excursion
  3086. (goto-char (point-min))
  3087. (remove-text-properties (point-min) (point-max) '(face nil))
  3088. (while (not (eobp))
  3089. (cond ((get-text-property (point) 'v-cmts)
  3090. (put-text-property (point) (1+ (point)) `face 'underline)
  3091. ;;(if dbg (setq dbg (concat dbg (format " v-cmts at %S\n" (point)))))
  3092. (forward-char 1))
  3093. (t
  3094. (goto-char (or (next-property-change (point)) (point-max))))))))
  3095. (defun verilog-scan-and-debug ()
  3096. "For debugging, run `verilog-scan' and `verilog-scan-debug'."
  3097. (let (verilog-scan-cache-preserving
  3098. verilog-scan-cache-tick)
  3099. (goto-char (point-min))
  3100. (verilog-scan)
  3101. (verilog-scan-debug)))
  3102. (defun verilog-inside-comment-or-string-p (&optional pos)
  3103. "Check if optional point POS is inside a comment.
  3104. This may require a slow pre-parse of the buffer with `verilog-scan'
  3105. to establish comment properties on all text."
  3106. ;; This function is very hot
  3107. (verilog-scan)
  3108. (if pos
  3109. (and (>= pos (point-min))
  3110. (get-text-property pos 'v-cmts))
  3111. (get-text-property (point) 'v-cmts)))
  3112. (defun verilog-insert (&rest stuff)
  3113. "Insert STUFF arguments, tracking for `verilog-inside-comment-or-string-p'.
  3114. Any insert that includes a comment must have the entire comment
  3115. inserted using a single call to `verilog-insert'."
  3116. (let ((pt (point)))
  3117. (while stuff
  3118. (insert (car stuff))
  3119. (setq stuff (cdr stuff)))
  3120. (verilog-scan-region pt (point))))
  3121. ;; More searching
  3122. (defun verilog-declaration-end ()
  3123. (search-forward ";"))
  3124. (defun verilog-point-text (&optional pointnum)
  3125. "Return text describing where POINTNUM or current point is (for errors).
  3126. Use filename, if current buffer being edited shorten to just buffer name."
  3127. (concat (or (and (equal (window-buffer) (current-buffer))
  3128. (buffer-name))
  3129. buffer-file-name
  3130. (buffer-name))
  3131. ":" (int-to-string (1+ (count-lines (point-min) (or pointnum (point)))))))
  3132. (defun electric-verilog-backward-sexp ()
  3133. "Move backward over one balanced expression."
  3134. (interactive)
  3135. ;; before that see if we are in a comment
  3136. (verilog-backward-sexp))
  3137. (defun electric-verilog-forward-sexp ()
  3138. "Move forward over one balanced expression."
  3139. (interactive)
  3140. ;; before that see if we are in a comment
  3141. (verilog-forward-sexp))
  3142. (defun verilog-forward-sexp-function (arg)
  3143. "Move forward ARG sexps."
  3144. ;; Used by hs-minor-mode
  3145. (if (< arg 0)
  3146. (verilog-backward-sexp)
  3147. (verilog-forward-sexp)))
  3148. (defun verilog-backward-sexp ()
  3149. (let ((reg)
  3150. (elsec 1)
  3151. (found nil)
  3152. (st (point)))
  3153. (if (not (looking-at "\\<"))
  3154. (forward-word -1))
  3155. (cond
  3156. ((verilog-skip-backward-comment-or-string))
  3157. ((looking-at "\\<else\\>")
  3158. (setq reg (concat
  3159. verilog-end-block-re
  3160. "\\|\\(\\<else\\>\\)"
  3161. "\\|\\(\\<if\\>\\)"))
  3162. (while (and (not found)
  3163. (verilog-re-search-backward reg nil 'move))
  3164. (cond
  3165. ((match-end 1) ; matched verilog-end-block-re
  3166. ;; try to leap back to matching outward block by striding across
  3167. ;; indent level changing tokens then immediately
  3168. ;; previous line governs indentation.
  3169. (verilog-leap-to-head))
  3170. ((match-end 2) ; else, we're in deep
  3171. (setq elsec (1+ elsec)))
  3172. ((match-end 3) ; found it
  3173. (setq elsec (1- elsec))
  3174. (if (= 0 elsec)
  3175. ;; Now previous line describes syntax
  3176. (setq found 't))))))
  3177. ((looking-at verilog-end-block-re)
  3178. (verilog-leap-to-head))
  3179. ((looking-at "\\(endmodule\\>\\)\\|\\(\\<endprimitive\\>\\)\\|\\(\\<endclass\\>\\)\\|\\(\\<endprogram\\>\\)\\|\\(\\<endinterface\\>\\)\\|\\(\\<endpackage\\>\\)")
  3180. (cond
  3181. ((match-end 1)
  3182. (verilog-re-search-backward "\\<\\(macro\\)?module\\>" nil 'move))
  3183. ((match-end 2)
  3184. (verilog-re-search-backward "\\<primitive\\>" nil 'move))
  3185. ((match-end 3)
  3186. (verilog-re-search-backward "\\<class\\>" nil 'move))
  3187. ((match-end 4)
  3188. (verilog-re-search-backward "\\<program\\>" nil 'move))
  3189. ((match-end 5)
  3190. (verilog-re-search-backward "\\<interface\\>" nil 'move))
  3191. ((match-end 6)
  3192. (verilog-re-search-backward "\\<package\\>" nil 'move))
  3193. (t
  3194. (goto-char st)
  3195. (backward-sexp 1))))
  3196. (t
  3197. (goto-char st)
  3198. (backward-sexp)))))
  3199. (defun verilog-forward-sexp ()
  3200. (let ((reg)
  3201. (md 2)
  3202. (st (point))
  3203. (nest 'yes))
  3204. (if (not (looking-at "\\<"))
  3205. (forward-word -1))
  3206. (cond
  3207. ((verilog-skip-forward-comment-or-string)
  3208. (verilog-forward-syntactic-ws))
  3209. ((looking-at verilog-beg-block-re-ordered)
  3210. (cond
  3211. ((match-end 1);
  3212. ;; Search forward for matching end
  3213. (setq reg "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)" ))
  3214. ((match-end 2)
  3215. ;; Search forward for matching endcase
  3216. (setq reg "\\(\\<randcase\\>\\|\\(\\<unique0?\\>\\s-+\\|\\<priority\\>\\s-+\\)?\\<case[xz]?\\>[^:]\\)\\|\\(\\<endcase\\>\\)" )
  3217. (setq md 3) ; ender is third item in regexp
  3218. )
  3219. ((match-end 4)
  3220. ;; might be "disable fork" or "wait fork"
  3221. (let
  3222. (here)
  3223. (if (or
  3224. (looking-at verilog-disable-fork-re)
  3225. (and (looking-at "fork")
  3226. (progn
  3227. (setq here (point)) ; sometimes a fork is just a fork
  3228. (forward-word -1)
  3229. (looking-at verilog-disable-fork-re))))
  3230. (progn ; it is a disable fork; ignore it
  3231. (goto-char (match-end 0))
  3232. (forward-word 1)
  3233. (setq reg nil))
  3234. (progn ; it is a nice simple fork
  3235. (goto-char here) ; return from looking for "disable fork"
  3236. ;; Search forward for matching join
  3237. (setq reg "\\(\\<fork\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)" )))))
  3238. ((match-end 6)
  3239. ;; Search forward for matching endclass
  3240. (setq reg "\\(\\<class\\>\\)\\|\\(\\<endclass\\>\\)" ))
  3241. ((match-end 7)
  3242. ;; Search forward for matching endtable
  3243. (setq reg "\\<endtable\\>" )
  3244. (setq nest 'no))
  3245. ((match-end 8)
  3246. ;; Search forward for matching endspecify
  3247. (setq reg "\\(\\<specify\\>\\)\\|\\(\\<endspecify\\>\\)" ))
  3248. ((match-end 9)
  3249. ;; Search forward for matching endfunction
  3250. (setq reg "\\<endfunction\\>" )
  3251. (setq nest 'no))
  3252. ((match-end 10)
  3253. ;; Search forward for matching endfunction
  3254. (setq reg "\\<endfunction\\>" )
  3255. (setq nest 'no))
  3256. ((match-end 14)
  3257. ;; Search forward for matching endtask
  3258. (setq reg "\\<endtask\\>" )
  3259. (setq nest 'no))
  3260. ((match-end 15)
  3261. ;; Search forward for matching endtask
  3262. (setq reg "\\<endtask\\>" )
  3263. (setq nest 'no))
  3264. ((match-end 19)
  3265. ;; Search forward for matching endgenerate
  3266. (setq reg "\\(\\<generate\\>\\)\\|\\(\\<endgenerate\\>\\)" ))
  3267. ((match-end 20)
  3268. ;; Search forward for matching endgroup
  3269. (setq reg "\\(\\<covergroup\\>\\)\\|\\(\\<endgroup\\>\\)" ))
  3270. ((match-end 21)
  3271. ;; Search forward for matching endproperty
  3272. (setq reg "\\(\\<property\\>\\)\\|\\(\\<endproperty\\>\\)" ))
  3273. ((match-end 25)
  3274. ;; Search forward for matching endsequence
  3275. (setq reg "\\(\\<\\(rand\\)?sequence\\>\\)\\|\\(\\<endsequence\\>\\)" )
  3276. (setq md 3)) ; 3 to get to endsequence in the reg above
  3277. ((match-end 27)
  3278. ;; Search forward for matching endclocking
  3279. (setq reg "\\(\\<clocking\\>\\)\\|\\(\\<endclocking\\>\\)" )))
  3280. (if (and reg
  3281. (forward-word 1))
  3282. (catch 'skip
  3283. (if (eq nest 'yes)
  3284. (let ((depth 1)
  3285. here)
  3286. (while (verilog-re-search-forward reg nil 'move)
  3287. (cond
  3288. ((match-end md) ; a closer in regular expression, so we are climbing out
  3289. (setq depth (1- depth))
  3290. (if (= 0 depth) ; we are out!
  3291. (throw 'skip 1)))
  3292. ((match-end 1) ; an opener in the r-e, so we are in deeper now
  3293. (setq here (point)) ; remember where we started
  3294. (goto-char (match-beginning 1))
  3295. (cond
  3296. ((if (or
  3297. (looking-at verilog-disable-fork-re)
  3298. (and (looking-at "fork")
  3299. (progn
  3300. (forward-word -1)
  3301. (looking-at verilog-disable-fork-re))))
  3302. (progn ; it is a disable fork; another false alarm
  3303. (goto-char (match-end 0)))
  3304. (progn ; it is a simple fork (or has nothing to do with fork)
  3305. (goto-char here)
  3306. (setq depth (1+ depth))))))))))
  3307. (if (verilog-re-search-forward reg nil 'move)
  3308. (throw 'skip 1))))))
  3309. ((looking-at (concat
  3310. "\\(\\<\\(macro\\)?module\\>\\)\\|"
  3311. "\\(\\<primitive\\>\\)\\|"
  3312. "\\(\\<class\\>\\)\\|"
  3313. "\\(\\<program\\>\\)\\|"
  3314. "\\(\\<interface\\>\\)\\|"
  3315. "\\(\\<package\\>\\)"))
  3316. (cond
  3317. ((match-end 1)
  3318. (verilog-re-search-forward "\\<endmodule\\>" nil 'move))
  3319. ((match-end 2)
  3320. (verilog-re-search-forward "\\<endprimitive\\>" nil 'move))
  3321. ((match-end 3)
  3322. (verilog-re-search-forward "\\<endclass\\>" nil 'move))
  3323. ((match-end 4)
  3324. (verilog-re-search-forward "\\<endprogram\\>" nil 'move))
  3325. ((match-end 5)
  3326. (verilog-re-search-forward "\\<endinterface\\>" nil 'move))
  3327. ((match-end 6)
  3328. (verilog-re-search-forward "\\<endpackage\\>" nil 'move))
  3329. (t
  3330. (goto-char st)
  3331. (if (= (following-char) ?\) )
  3332. (forward-char 1)
  3333. (forward-sexp 1)))))
  3334. (t
  3335. (goto-char st)
  3336. (if (= (following-char) ?\) )
  3337. (forward-char 1)
  3338. (forward-sexp 1))))))
  3339. (defun verilog-declaration-beg ()
  3340. (verilog-re-search-backward verilog-declaration-re (bobp) t))
  3341. ;;
  3342. ;;
  3343. ;; Mode
  3344. ;;
  3345. (defvar verilog-which-tool 1)
  3346. ;;;###autoload
  3347. (define-derived-mode verilog-mode prog-mode "Verilog"
  3348. "Major mode for editing Verilog code.
  3349. \\<verilog-mode-map>
  3350. See \\[describe-function] verilog-auto (\\[verilog-auto]) for details on how
  3351. AUTOs can improve coding efficiency.
  3352. Use \\[verilog-faq] for a pointer to frequently asked questions.
  3353. NEWLINE, TAB indents for Verilog code.
  3354. Delete converts tabs to spaces as it moves back.
  3355. Supports highlighting.
  3356. Turning on Verilog mode calls the value of the variable `verilog-mode-hook'
  3357. with no args, if that value is non-nil.
  3358. Variables controlling indentation/edit style:
  3359. variable `verilog-indent-level' (default 3)
  3360. Indentation of Verilog statements with respect to containing block.
  3361. `verilog-indent-level-module' (default 3)
  3362. Absolute indentation of Module level Verilog statements.
  3363. Set to 0 to get initial and always statements lined up
  3364. on the left side of your screen.
  3365. `verilog-indent-level-declaration' (default 3)
  3366. Indentation of declarations with respect to containing block.
  3367. Set to 0 to get them list right under containing block.
  3368. `verilog-indent-level-behavioral' (default 3)
  3369. Indentation of first begin in a task or function block
  3370. Set to 0 to get such code to lined up underneath the task or
  3371. function keyword.
  3372. `verilog-indent-level-directive' (default 1)
  3373. Indentation of \\=`ifdef/\\=`endif blocks.
  3374. `verilog-cexp-indent' (default 1)
  3375. Indentation of Verilog statements broken across lines i.e.:
  3376. if (a)
  3377. begin
  3378. `verilog-case-indent' (default 2)
  3379. Indentation for case statements.
  3380. `verilog-auto-newline' (default nil)
  3381. Non-nil means automatically newline after semicolons and the punctuation
  3382. mark after an end.
  3383. `verilog-auto-indent-on-newline' (default t)
  3384. Non-nil means automatically indent line after newline.
  3385. `verilog-tab-always-indent' (default t)
  3386. Non-nil means TAB in Verilog mode should always reindent the current line,
  3387. regardless of where in the line point is when the TAB command is used.
  3388. `verilog-indent-begin-after-if' (default t)
  3389. Non-nil means to indent begin statements following a preceding
  3390. if, else, while, for and repeat statements, if any. Otherwise,
  3391. the begin is lined up with the preceding token. If t, you get:
  3392. if (a)
  3393. begin // amount of indent based on `verilog-cexp-indent'
  3394. otherwise you get:
  3395. if (a)
  3396. begin
  3397. `verilog-auto-endcomments' (default t)
  3398. Non-nil means a comment /* ... */ is set after the ends which ends
  3399. cases, tasks, functions and modules.
  3400. The type and name of the object will be set between the braces.
  3401. `verilog-minimum-comment-distance' (default 10)
  3402. Minimum distance (in lines) between begin and end required before a comment
  3403. will be inserted. Setting this variable to zero results in every
  3404. end acquiring a comment; the default avoids too many redundant
  3405. comments in tight quarters.
  3406. `verilog-auto-lineup' (default 'declarations)
  3407. List of contexts where auto lineup of code should be done.
  3408. Variables controlling other actions:
  3409. `verilog-linter' (default surelint)
  3410. Unix program to call to run the lint checker. This is the default
  3411. command for \\[compile-command] and \\[verilog-auto-save-compile].
  3412. See \\[customize] for the complete list of variables.
  3413. AUTO expansion functions are, in part:
  3414. \\[verilog-auto] Expand AUTO statements.
  3415. \\[verilog-delete-auto] Remove the AUTOs.
  3416. \\[verilog-inject-auto] Insert AUTOs for the first time.
  3417. Some other functions are:
  3418. \\[verilog-complete-word] Complete word with appropriate possibilities.
  3419. \\[verilog-mark-defun] Mark function.
  3420. \\[verilog-beg-of-defun] Move to beginning of current function.
  3421. \\[verilog-end-of-defun] Move to end of current function.
  3422. \\[verilog-label-be] Label matching begin ... end, fork ... join, etc statements.
  3423. \\[verilog-comment-region] Put marked area in a comment.
  3424. \\[verilog-uncomment-region] Uncomment an area commented with \\[verilog-comment-region].
  3425. \\[verilog-insert-block] Insert begin ... end.
  3426. \\[verilog-star-comment] Insert /* ... */.
  3427. \\[verilog-sk-always] Insert an always @(AS) begin .. end block.
  3428. \\[verilog-sk-begin] Insert a begin .. end block.
  3429. \\[verilog-sk-case] Insert a case block, prompting for details.
  3430. \\[verilog-sk-for] Insert a for (...) begin .. end block, prompting for details.
  3431. \\[verilog-sk-generate] Insert a generate .. endgenerate block.
  3432. \\[verilog-sk-header] Insert a header block at the top of file.
  3433. \\[verilog-sk-initial] Insert an initial begin .. end block.
  3434. \\[verilog-sk-fork] Insert a fork begin .. end .. join block.
  3435. \\[verilog-sk-module] Insert a module .. (/*AUTOARG*/);.. endmodule block.
  3436. \\[verilog-sk-ovm-class] Insert an OVM Class block.
  3437. \\[verilog-sk-uvm-object] Insert an UVM Object block.
  3438. \\[verilog-sk-uvm-component] Insert an UVM Component block.
  3439. \\[verilog-sk-primitive] Insert a primitive .. (.. );.. endprimitive block.
  3440. \\[verilog-sk-repeat] Insert a repeat (..) begin .. end block.
  3441. \\[verilog-sk-specify] Insert a specify .. endspecify block.
  3442. \\[verilog-sk-task] Insert a task .. begin .. end endtask block.
  3443. \\[verilog-sk-while] Insert a while (...) begin .. end block, prompting for details.
  3444. \\[verilog-sk-casex] Insert a casex (...) item: begin.. end endcase block, prompting for details.
  3445. \\[verilog-sk-casez] Insert a casez (...) item: begin.. end endcase block, prompting for details.
  3446. \\[verilog-sk-if] Insert an if (..) begin .. end block.
  3447. \\[verilog-sk-else-if] Insert an else if (..) begin .. end block.
  3448. \\[verilog-sk-comment] Insert a comment block.
  3449. \\[verilog-sk-assign] Insert an assign .. = ..; statement.
  3450. \\[verilog-sk-function] Insert a function .. begin .. end endfunction block.
  3451. \\[verilog-sk-input] Insert an input declaration, prompting for details.
  3452. \\[verilog-sk-output] Insert an output declaration, prompting for details.
  3453. \\[verilog-sk-state-machine] Insert a state machine definition, prompting for details.
  3454. \\[verilog-sk-inout] Insert an inout declaration, prompting for details.
  3455. \\[verilog-sk-wire] Insert a wire declaration, prompting for details.
  3456. \\[verilog-sk-reg] Insert a register declaration, prompting for details.
  3457. \\[verilog-sk-define-signal] Define signal under point as a register at the top of the module.
  3458. All key bindings can be seen in a Verilog-buffer with \\[describe-bindings].
  3459. Key bindings specific to `verilog-mode-map' are:
  3460. \\{verilog-mode-map}"
  3461. :abbrev-table verilog-mode-abbrev-table
  3462. (set (make-local-variable 'beginning-of-defun-function)
  3463. 'verilog-beg-of-defun)
  3464. (set (make-local-variable 'end-of-defun-function)
  3465. 'verilog-end-of-defun)
  3466. (set-syntax-table verilog-mode-syntax-table)
  3467. (set (make-local-variable 'indent-line-function)
  3468. #'verilog-indent-line-relative)
  3469. (set (make-local-variable 'comment-indent-function) 'verilog-comment-indent)
  3470. (set (make-local-variable 'parse-sexp-ignore-comments) nil)
  3471. (set (make-local-variable 'comment-start) "// ")
  3472. (set (make-local-variable 'comment-end) "")
  3473. (set (make-local-variable 'comment-start-skip) "/\\*+ *\\|// *")
  3474. (set (make-local-variable 'comment-multi-line) nil)
  3475. ;; Set up for compilation
  3476. (setq verilog-which-tool 1)
  3477. (setq verilog-tool 'verilog-linter)
  3478. (verilog-set-compile-command)
  3479. (when (boundp 'hack-local-variables-hook) ; Also modify any file-local-variables
  3480. (add-hook 'hack-local-variables-hook 'verilog-modify-compile-command t))
  3481. ;; Setting up menus
  3482. (when (featurep 'xemacs)
  3483. (easy-menu-add verilog-stmt-menu)
  3484. (easy-menu-add verilog-menu)
  3485. (setq mode-popup-menu (cons "Verilog Mode" verilog-stmt-menu)))
  3486. ;; Stuff for GNU Emacs
  3487. (set (make-local-variable 'font-lock-defaults)
  3488. `((verilog-font-lock-keywords
  3489. verilog-font-lock-keywords-1
  3490. verilog-font-lock-keywords-2
  3491. verilog-font-lock-keywords-3)
  3492. nil nil nil
  3493. ,(if (functionp 'syntax-ppss)
  3494. ;; verilog-beg-of-defun uses syntax-ppss, and syntax-ppss uses
  3495. ;; font-lock-beginning-of-syntax-function, so
  3496. ;; font-lock-beginning-of-syntax-function, can't use
  3497. ;; verilog-beg-of-defun.
  3498. nil
  3499. 'verilog-beg-of-defun)))
  3500. ;;------------------------------------------------------------
  3501. ;; now hook in 'verilog-highlight-include-files (eldo-mode.el&spice-mode.el)
  3502. ;; all buffer local:
  3503. (unless noninteractive ; Else can't see the result, and change hooks are slow
  3504. (when (featurep 'xemacs)
  3505. (make-local-hook 'font-lock-mode-hook)
  3506. (make-local-hook 'font-lock-after-fontify-buffer-hook); doesn't exist in Emacs
  3507. (make-local-hook 'after-change-functions))
  3508. (add-hook 'font-lock-mode-hook 'verilog-highlight-buffer t t)
  3509. (add-hook 'font-lock-after-fontify-buffer-hook 'verilog-highlight-buffer t t) ; not in Emacs
  3510. (add-hook 'after-change-functions 'verilog-highlight-region t t))
  3511. ;; Tell imenu how to handle Verilog.
  3512. (set (make-local-variable 'imenu-generic-expression)
  3513. verilog-imenu-generic-expression)
  3514. ;; Tell which-func-modes that imenu knows about verilog
  3515. (when (and (boundp 'which-func-modes) (listp which-func-modes))
  3516. (add-to-list 'which-func-modes 'verilog-mode))
  3517. ;; hideshow support
  3518. (when (boundp 'hs-special-modes-alist)
  3519. (unless (assq 'verilog-mode hs-special-modes-alist)
  3520. (setq hs-special-modes-alist
  3521. (cons '(verilog-mode-mode "\\<begin\\>" "\\<end\\>" nil
  3522. verilog-forward-sexp-function)
  3523. hs-special-modes-alist))))
  3524. ;; Stuff for autos
  3525. (add-hook 'write-contents-hooks 'verilog-auto-save-check nil 'local)
  3526. ;; verilog-mode-hook call added by define-derived-mode
  3527. )
  3528. ;;; Electric functions:
  3529. ;;
  3530. (defun electric-verilog-terminate-line (&optional arg)
  3531. "Terminate line and indent next line.
  3532. With optional ARG, remove existing end of line comments."
  3533. (interactive)
  3534. ;; before that see if we are in a comment
  3535. (let ((state (save-excursion (verilog-syntax-ppss))))
  3536. (cond
  3537. ((nth 7 state) ; Inside // comment
  3538. (if (eolp)
  3539. (progn
  3540. (delete-horizontal-space)
  3541. (newline))
  3542. (progn
  3543. (newline)
  3544. (insert "// ")
  3545. (beginning-of-line)))
  3546. (verilog-indent-line))
  3547. ((nth 4 state) ; Inside any comment (hence /**/)
  3548. (newline)
  3549. (verilog-more-comment))
  3550. ((eolp)
  3551. ;; First, check if current line should be indented
  3552. (if (save-excursion
  3553. (delete-horizontal-space)
  3554. (beginning-of-line)
  3555. (skip-chars-forward " \t")
  3556. (if (looking-at verilog-auto-end-comment-lines-re)
  3557. (let ((indent-str (verilog-indent-line)))
  3558. ;; Maybe we should set some endcomments
  3559. (if verilog-auto-endcomments
  3560. (verilog-set-auto-endcomments indent-str arg))
  3561. (end-of-line)
  3562. (delete-horizontal-space)
  3563. (if arg
  3564. ()
  3565. (newline))
  3566. nil)
  3567. (progn
  3568. (end-of-line)
  3569. (delete-horizontal-space)
  3570. 't)))
  3571. ;; see if we should line up assignments
  3572. (progn
  3573. (if (or (eq 'all verilog-auto-lineup)
  3574. (eq 'assignments verilog-auto-lineup))
  3575. (verilog-pretty-expr t "\\(<\\|:\\)?=" ))
  3576. (newline))
  3577. (forward-line 1))
  3578. ;; Indent next line
  3579. (if verilog-auto-indent-on-newline
  3580. (verilog-indent-line)))
  3581. (t
  3582. (newline)))))
  3583. (defun electric-verilog-terminate-and-indent ()
  3584. "Insert a newline and indent for the next statement."
  3585. (interactive)
  3586. (electric-verilog-terminate-line 1))
  3587. (defun electric-verilog-semi ()
  3588. "Insert `;' character and reindent the line."
  3589. (interactive)
  3590. (verilog-insert-last-command-event)
  3591. (if (or (verilog-in-comment-or-string-p)
  3592. (verilog-in-escaped-name-p))
  3593. ()
  3594. (save-excursion
  3595. (beginning-of-line)
  3596. (verilog-forward-ws&directives)
  3597. (verilog-indent-line))
  3598. (if (and verilog-auto-newline
  3599. (not (verilog-parenthesis-depth)))
  3600. (electric-verilog-terminate-line))))
  3601. (defun electric-verilog-semi-with-comment ()
  3602. "Insert `;' character, reindent the line and indent for comment."
  3603. (interactive)
  3604. (insert ";")
  3605. (save-excursion
  3606. (beginning-of-line)
  3607. (verilog-indent-line))
  3608. (indent-for-comment))
  3609. (defun electric-verilog-colon ()
  3610. "Insert `:' and do all indentations except line indent on this line."
  3611. (interactive)
  3612. (verilog-insert-last-command-event)
  3613. ;; Do nothing if within string.
  3614. (if (or
  3615. (verilog-within-string)
  3616. (not (verilog-in-case-region-p)))
  3617. ()
  3618. (save-excursion
  3619. (let ((p (point))
  3620. (lim (progn (verilog-beg-of-statement) (point))))
  3621. (goto-char p)
  3622. (verilog-backward-case-item lim)
  3623. (verilog-indent-line)))
  3624. ;; (let ((verilog-tab-always-indent nil))
  3625. ;; (verilog-indent-line))
  3626. ))
  3627. ;;(defun electric-verilog-equal ()
  3628. ;; "Insert `=', and do indentation if within block."
  3629. ;; (interactive)
  3630. ;; (verilog-insert-last-command-event)
  3631. ;; Could auto line up expressions, but not yet
  3632. ;; (if (eq (car (verilog-calculate-indent)) 'block)
  3633. ;; (let ((verilog-tab-always-indent nil))
  3634. ;; (verilog-indent-command)))
  3635. ;; )
  3636. (defun electric-verilog-tick ()
  3637. "Insert back-tick, and indent to column 0 if this is a CPP directive."
  3638. (interactive)
  3639. (verilog-insert-last-command-event)
  3640. (save-excursion
  3641. (if (verilog-in-directive-p)
  3642. (verilog-indent-line))))
  3643. (defun electric-verilog-tab ()
  3644. "Function called when TAB is pressed in Verilog mode."
  3645. (interactive)
  3646. ;; If verilog-tab-always-indent, indent the beginning of the line.
  3647. (cond
  3648. ;; The region is active, indent it.
  3649. ((and (region-active-p)
  3650. (not (eq (region-beginning) (region-end))))
  3651. (indent-region (region-beginning) (region-end) nil))
  3652. ((or verilog-tab-always-indent
  3653. (save-excursion
  3654. (skip-chars-backward " \t")
  3655. (bolp)))
  3656. (let* ((oldpnt (point))
  3657. (boi-point
  3658. (save-excursion
  3659. (beginning-of-line)
  3660. (skip-chars-forward " \t")
  3661. (verilog-indent-line)
  3662. (back-to-indentation)
  3663. (point))))
  3664. (if (< (point) boi-point)
  3665. (back-to-indentation)
  3666. (cond ((not verilog-tab-to-comment))
  3667. ((not (eolp))
  3668. (end-of-line))
  3669. (t
  3670. (indent-for-comment)
  3671. (when (and (eolp) (= oldpnt (point)))
  3672. ;; kill existing comment
  3673. (beginning-of-line)
  3674. (re-search-forward comment-start-skip oldpnt 'move)
  3675. (goto-char (match-beginning 0))
  3676. (skip-chars-backward " \t")
  3677. (kill-region (point) oldpnt)))))))
  3678. (t (progn (insert "\t")))))
  3679. ;;; Interactive functions:
  3680. ;;
  3681. (defun verilog-indent-buffer ()
  3682. "Indent-region the entire buffer as Verilog code.
  3683. To call this from the command line, see \\[verilog-batch-indent]."
  3684. (interactive)
  3685. (verilog-mode)
  3686. (indent-region (point-min) (point-max) nil))
  3687. (defun verilog-insert-block ()
  3688. "Insert Verilog begin ... end; block in the code with right indentation."
  3689. (interactive)
  3690. (verilog-indent-line)
  3691. (insert "begin")
  3692. (electric-verilog-terminate-line)
  3693. (save-excursion
  3694. (electric-verilog-terminate-line)
  3695. (insert "end")
  3696. (beginning-of-line)
  3697. (verilog-indent-line)))
  3698. (defun verilog-star-comment ()
  3699. "Insert Verilog star comment at point."
  3700. (interactive)
  3701. (verilog-indent-line)
  3702. (insert "/*")
  3703. (save-excursion
  3704. (newline)
  3705. (insert " */"))
  3706. (newline)
  3707. (insert " * "))
  3708. (defun verilog-insert-1 (fmt max)
  3709. "Use format string FMT to insert integers 0 to MAX - 1.
  3710. Inserts one integer per line, at the current column. Stops early
  3711. if it reaches the end of the buffer."
  3712. (let ((col (current-column))
  3713. (n 0))
  3714. (save-excursion
  3715. (while (< n max)
  3716. (insert (format fmt n))
  3717. (forward-line 1)
  3718. ;; Note that this function does not bother to check for lines
  3719. ;; shorter than col.
  3720. (if (eobp)
  3721. (setq n max)
  3722. (setq n (1+ n))
  3723. (move-to-column col))))))
  3724. (defun verilog-insert-indices (max)
  3725. "Insert a set of indices into a rectangle.
  3726. The upper left corner is defined by point. Indices begin with 0
  3727. and extend to the MAX - 1. If no prefix arg is given, the user
  3728. is prompted for a value. The indices are surrounded by square
  3729. brackets []. For example, the following code with the point
  3730. located after the first 'a' gives:
  3731. a = b a[ 0] = b
  3732. a = b a[ 1] = b
  3733. a = b a[ 2] = b
  3734. a = b a[ 3] = b
  3735. a = b ==> insert-indices ==> a[ 4] = b
  3736. a = b a[ 5] = b
  3737. a = b a[ 6] = b
  3738. a = b a[ 7] = b
  3739. a = b a[ 8] = b"
  3740. (interactive "NMAX: ")
  3741. (verilog-insert-1 "[%3d]" max))
  3742. (defun verilog-generate-numbers (max)
  3743. "Insert a set of generated numbers into a rectangle.
  3744. The upper left corner is defined by point. The numbers are padded to three
  3745. digits, starting with 000 and extending to (MAX - 1). If no prefix argument
  3746. is supplied, then the user is prompted for the MAX number. Consider the
  3747. following code fragment:
  3748. buf buf buf buf000
  3749. buf buf buf buf001
  3750. buf buf buf buf002
  3751. buf buf buf buf003
  3752. buf buf ==> generate-numbers ==> buf buf004
  3753. buf buf buf buf005
  3754. buf buf buf buf006
  3755. buf buf buf buf007
  3756. buf buf buf buf008"
  3757. (interactive "NMAX: ")
  3758. (verilog-insert-1 "%3.3d" max))
  3759. (defun verilog-mark-defun ()
  3760. "Mark the current Verilog function (or procedure).
  3761. This puts the mark at the end, and point at the beginning."
  3762. (interactive)
  3763. (if (featurep 'xemacs)
  3764. (progn
  3765. (push-mark (point))
  3766. (verilog-end-of-defun)
  3767. (push-mark (point))
  3768. (verilog-beg-of-defun)
  3769. (if (fboundp 'zmacs-activate-region)
  3770. (zmacs-activate-region)))
  3771. (mark-defun)))
  3772. (defun verilog-comment-region (start end)
  3773. ;; checkdoc-params: (start end)
  3774. "Put the region into a Verilog comment.
  3775. The comments that are in this area are \"deformed\":
  3776. `*)' becomes `!(*' and `}' becomes `!{'.
  3777. These deformed comments are returned to normal if you use
  3778. \\[verilog-uncomment-region] to undo the commenting.
  3779. The commented area starts with `verilog-exclude-str-start', and ends with
  3780. `verilog-exclude-str-end'. But if you change these variables,
  3781. \\[verilog-uncomment-region] won't recognize the comments."
  3782. (interactive "r")
  3783. (save-excursion
  3784. ;; Insert start and endcomments
  3785. (goto-char end)
  3786. (if (and (save-excursion (skip-chars-forward " \t") (eolp))
  3787. (not (save-excursion (skip-chars-backward " \t") (bolp))))
  3788. (forward-line 1)
  3789. (beginning-of-line))
  3790. (insert verilog-exclude-str-end)
  3791. (setq end (point))
  3792. (newline)
  3793. (goto-char start)
  3794. (beginning-of-line)
  3795. (insert verilog-exclude-str-start)
  3796. (newline)
  3797. ;; Replace end-comments within commented area
  3798. (goto-char end)
  3799. (save-excursion
  3800. (while (re-search-backward "\\*/" start t)
  3801. (replace-match "*-/" t t)))
  3802. (save-excursion
  3803. (let ((s+1 (1+ start)))
  3804. (while (re-search-backward "/\\*" s+1 t)
  3805. (replace-match "/-*" t t))))))
  3806. (defun verilog-uncomment-region ()
  3807. "Uncomment a commented area; change deformed comments back to normal.
  3808. This command does nothing if the pointer is not in a commented
  3809. area. See also `verilog-comment-region'."
  3810. (interactive)
  3811. (save-excursion
  3812. (let ((start (point))
  3813. (end (point)))
  3814. ;; Find the boundaries of the comment
  3815. (save-excursion
  3816. (setq start (progn (search-backward verilog-exclude-str-start nil t)
  3817. (point)))
  3818. (setq end (progn (search-forward verilog-exclude-str-end nil t)
  3819. (point))))
  3820. ;; Check if we're really inside a comment
  3821. (if (or (equal start (point)) (<= end (point)))
  3822. (message "Not standing within commented area.")
  3823. (progn
  3824. ;; Remove endcomment
  3825. (goto-char end)
  3826. (beginning-of-line)
  3827. (let ((pos (point)))
  3828. (end-of-line)
  3829. (delete-region pos (1+ (point))))
  3830. ;; Change comments back to normal
  3831. (save-excursion
  3832. (while (re-search-backward "\\*-/" start t)
  3833. (replace-match "*/" t t)))
  3834. (save-excursion
  3835. (while (re-search-backward "/-\\*" start t)
  3836. (replace-match "/*" t t)))
  3837. ;; Remove start comment
  3838. (goto-char start)
  3839. (beginning-of-line)
  3840. (let ((pos (point)))
  3841. (end-of-line)
  3842. (delete-region pos (1+ (point)))))))))
  3843. (defun verilog-beg-of-defun ()
  3844. "Move backward to the beginning of the current function or procedure."
  3845. (interactive)
  3846. (verilog-re-search-backward verilog-defun-re nil 'move))
  3847. (defun verilog-beg-of-defun-quick ()
  3848. "Move backward to the beginning of the current function or procedure.
  3849. Uses `verilog-scan' cache."
  3850. (interactive)
  3851. (verilog-re-search-backward-quick verilog-defun-re nil 'move))
  3852. (defun verilog-end-of-defun ()
  3853. "Move forward to the end of the current function or procedure."
  3854. (interactive)
  3855. (verilog-re-search-forward verilog-end-defun-re nil 'move))
  3856. (defun verilog-get-end-of-defun ()
  3857. (save-excursion
  3858. (cond ((verilog-re-search-forward-quick verilog-end-defun-re nil t)
  3859. (point))
  3860. (t
  3861. (error "%s: Can't find endmodule" (verilog-point-text))
  3862. (point-max)))))
  3863. (defun verilog-label-be ()
  3864. "Label matching begin ... end, fork ... join and case ... endcase statements."
  3865. (interactive)
  3866. (let ((cnt 0)
  3867. (case-fold-search nil)
  3868. (oldpos (point))
  3869. (b (progn
  3870. (verilog-beg-of-defun)
  3871. (point-marker)))
  3872. (e (progn
  3873. (verilog-end-of-defun)
  3874. (point-marker))))
  3875. (goto-char (marker-position b))
  3876. (if (> (- e b) 200)
  3877. (message "Relabeling module..."))
  3878. (while (and
  3879. (> (marker-position e) (point))
  3880. (verilog-re-search-forward
  3881. verilog-auto-end-comment-lines-re
  3882. nil 'move))
  3883. (goto-char (match-beginning 0))
  3884. (let ((indent-str (verilog-indent-line)))
  3885. (verilog-set-auto-endcomments indent-str 't)
  3886. (end-of-line)
  3887. (delete-horizontal-space))
  3888. (setq cnt (1+ cnt))
  3889. (if (= 9 (% cnt 10))
  3890. (message "%d..." cnt)))
  3891. (goto-char oldpos)
  3892. (if (or
  3893. (> (- e b) 200)
  3894. (> cnt 20))
  3895. (message "%d lines auto commented" cnt))))
  3896. (defun verilog-beg-of-statement ()
  3897. "Move backward to beginning of statement."
  3898. (interactive)
  3899. ;; Move back token by token until we see the end
  3900. ;; of some earlier line.
  3901. (let (h)
  3902. (while
  3903. ;; If the current point does not begin a new
  3904. ;; statement, as in the character ahead of us is a ';', or SOF
  3905. ;; or the string after us unambiguously starts a statement,
  3906. ;; or the token before us unambiguously ends a statement,
  3907. ;; then move back a token and test again.
  3908. (not (or
  3909. ;; stop if beginning of buffer
  3910. (bobp)
  3911. ;; stop if looking at a pre-processor directive
  3912. (looking-at "`\\w+")
  3913. ;; stop if we find a ;
  3914. (= (preceding-char) ?\;)
  3915. ;; stop if we see a named coverpoint
  3916. (looking-at "\\w+\\W*:\\W*\\(coverpoint\\|cross\\|constraint\\)")
  3917. ;; keep going if we are in the middle of a word
  3918. (not (or (looking-at "\\<") (forward-word -1)))
  3919. ;; stop if we see an assertion (perhaps labeled)
  3920. (and
  3921. (looking-at "\\(\\w+\\W*:\\W*\\)?\\(\\<\\(assert\\|assume\\|cover\\)\\>\\s-+\\<property\\>\\)\\|\\(\\<assert\\>\\)")
  3922. (progn
  3923. (setq h (point))
  3924. (save-excursion
  3925. (verilog-backward-token)
  3926. (if (and (looking-at verilog-label-re)
  3927. (not (looking-at verilog-end-block-re)))
  3928. (setq h (point))))
  3929. (goto-char h)))
  3930. ;; stop if we see an extended complete reg, perhaps a complete one
  3931. (and
  3932. (looking-at verilog-complete-reg)
  3933. (let* ((p (point)))
  3934. (while (and (looking-at verilog-extended-complete-re)
  3935. (progn (setq p (point))
  3936. (verilog-backward-token)
  3937. (/= p (point)))))
  3938. (goto-char p)))
  3939. ;; stop if we see a complete reg (previous found extended ones)
  3940. (looking-at verilog-basic-complete-re)
  3941. ;; stop if previous token is an ender
  3942. (save-excursion
  3943. (verilog-backward-token)
  3944. (looking-at verilog-end-block-re))))
  3945. (verilog-backward-syntactic-ws)
  3946. (verilog-backward-token))
  3947. ;; Now point is where the previous line ended.
  3948. (verilog-forward-syntactic-ws)
  3949. ;; Skip forward over any preprocessor directives, as they have wacky indentation
  3950. (if (looking-at verilog-preprocessor-re)
  3951. (progn (goto-char (match-end 0))
  3952. (verilog-forward-syntactic-ws)))))
  3953. (defun verilog-beg-of-statement-1 ()
  3954. "Move backward to beginning of statement."
  3955. (interactive)
  3956. (if (verilog-in-comment-p)
  3957. (verilog-backward-syntactic-ws))
  3958. (let ((pt (point)))
  3959. (catch 'done
  3960. (while (not (looking-at verilog-complete-reg))
  3961. (setq pt (point))
  3962. (verilog-backward-syntactic-ws)
  3963. (if (or (bolp)
  3964. (= (preceding-char) ?\;)
  3965. (progn
  3966. (verilog-backward-token)
  3967. (looking-at verilog-ends-re)))
  3968. (progn
  3969. (goto-char pt)
  3970. (throw 'done t)))))
  3971. (verilog-forward-syntactic-ws)))
  3972. ;;
  3973. ;; (while (and
  3974. ;; (not (looking-at verilog-complete-reg))
  3975. ;; (not (bolp))
  3976. ;; (not (= (preceding-char) ?\;)))
  3977. ;; (verilog-backward-token)
  3978. ;; (verilog-backward-syntactic-ws)
  3979. ;; (setq pt (point)))
  3980. ;; (goto-char pt)
  3981. ;; ;(verilog-forward-syntactic-ws)
  3982. (defun verilog-end-of-statement ()
  3983. "Move forward to end of current statement."
  3984. (interactive)
  3985. (let ((nest 0) pos)
  3986. (cond
  3987. ((verilog-in-directive-p)
  3988. (forward-line 1)
  3989. (backward-char 1))
  3990. ((looking-at verilog-beg-block-re)
  3991. (verilog-forward-sexp))
  3992. ((equal (char-after) ?\})
  3993. (forward-char))
  3994. ;; Skip to end of statement
  3995. ((condition-case nil
  3996. (setq pos
  3997. (catch 'found
  3998. (while t
  3999. (forward-sexp 1)
  4000. (verilog-skip-forward-comment-or-string)
  4001. (if (eolp)
  4002. (forward-line 1))
  4003. (cond ((looking-at "[ \t]*;")
  4004. (skip-chars-forward "^;")
  4005. (forward-char 1)
  4006. (throw 'found (point)))
  4007. ((save-excursion
  4008. (forward-sexp -1)
  4009. (looking-at verilog-beg-block-re))
  4010. (goto-char (match-beginning 0))
  4011. (throw 'found nil))
  4012. ((looking-at "[ \t]*)")
  4013. (throw 'found (point)))
  4014. ((eobp)
  4015. (throw 'found (point)))
  4016. )))
  4017. )
  4018. (error nil))
  4019. (if (not pos)
  4020. ;; Skip a whole block
  4021. (catch 'found
  4022. (while t
  4023. (verilog-re-search-forward verilog-end-statement-re nil 'move)
  4024. (setq nest (if (match-end 1)
  4025. (1+ nest)
  4026. (1- nest)))
  4027. (cond ((eobp)
  4028. (throw 'found (point)))
  4029. ((= 0 nest)
  4030. (throw 'found (verilog-end-of-statement))))))
  4031. pos)))))
  4032. (defun verilog-in-case-region-p ()
  4033. "Return true if in a case region.
  4034. More specifically, point @ in the line foo : @ begin"
  4035. (interactive)
  4036. (save-excursion
  4037. (if (and
  4038. (progn (verilog-forward-syntactic-ws)
  4039. (looking-at "\\<begin\\>"))
  4040. (progn (verilog-backward-syntactic-ws)
  4041. (= (preceding-char) ?\:)))
  4042. (catch 'found
  4043. (let ((nest 1))
  4044. (while t
  4045. (verilog-re-search-backward
  4046. (concat "\\(\\<module\\>\\)\\|\\(\\<randcase\\>\\|\\<case[xz]?\\>[^:]\\)\\|"
  4047. "\\(\\<endcase\\>\\)\\>")
  4048. nil 'move)
  4049. (cond
  4050. ((match-end 3)
  4051. (setq nest (1+ nest)))
  4052. ((match-end 2)
  4053. (if (= nest 1)
  4054. (throw 'found 1))
  4055. (setq nest (1- nest)))
  4056. (t
  4057. (throw 'found (= nest 0)))))))
  4058. nil)))
  4059. (defun verilog-backward-up-list (arg)
  4060. "Call `backward-up-list' ARG, ignoring comments."
  4061. (let ((parse-sexp-ignore-comments t))
  4062. (backward-up-list arg)))
  4063. (defun verilog-forward-sexp-cmt (arg)
  4064. "Call `forward-sexp' ARG, inside comments."
  4065. (let ((parse-sexp-ignore-comments nil))
  4066. (forward-sexp arg)))
  4067. (defun verilog-forward-sexp-ign-cmt (arg)
  4068. "Call `forward-sexp' ARG, ignoring comments."
  4069. (let ((parse-sexp-ignore-comments t))
  4070. (forward-sexp arg)))
  4071. (defun verilog-in-generate-region-p ()
  4072. "Return true if in a generate region.
  4073. More specifically, after a generate and before an endgenerate."
  4074. (interactive)
  4075. (let ((nest 1))
  4076. (save-excursion
  4077. (catch 'done
  4078. (while (and
  4079. (/= nest 0)
  4080. (verilog-re-search-backward
  4081. "\\<\\(module\\)\\|\\(generate\\)\\|\\(endgenerate\\)\\>" nil 'move)
  4082. (cond
  4083. ((match-end 1) ; module - we have crawled out
  4084. (throw 'done 1))
  4085. ((match-end 2) ; generate
  4086. (setq nest (1- nest)))
  4087. ((match-end 3) ; endgenerate
  4088. (setq nest (1+ nest))))))))
  4089. (= nest 0) )) ; return nest
  4090. (defun verilog-in-fork-region-p ()
  4091. "Return true if between a fork and join."
  4092. (interactive)
  4093. (let ((lim (save-excursion (verilog-beg-of-defun) (point)))
  4094. (nest 1))
  4095. (save-excursion
  4096. (while (and
  4097. (/= nest 0)
  4098. (verilog-re-search-backward "\\<\\(fork\\)\\|\\(join\\(_any\\|_none\\)?\\)\\>" lim 'move)
  4099. (cond
  4100. ((match-end 1) ; fork
  4101. (setq nest (1- nest)))
  4102. ((match-end 2) ; join
  4103. (setq nest (1+ nest)))))))
  4104. (= nest 0) )) ; return nest
  4105. (defun verilog-in-deferred-immediate-final-p ()
  4106. "Return true if inside an `assert/assume/cover final' statement."
  4107. (interactive)
  4108. (and (looking-at "final")
  4109. (verilog-looking-back "\\<\\(?:assert\\|assume\\|cover\\)\\>\\s-+" nil))
  4110. )
  4111. (defun verilog-backward-case-item (lim)
  4112. "Skip backward to nearest enclosing case item.
  4113. Limit search to point LIM."
  4114. (interactive)
  4115. (let ((str 'nil)
  4116. (lim1
  4117. (progn
  4118. (save-excursion
  4119. (verilog-re-search-backward verilog-endcomment-reason-re
  4120. lim 'move)
  4121. (point)))))
  4122. ;; Try to find the real :
  4123. (if (save-excursion (search-backward ":" lim1 t))
  4124. (let ((colon 0)
  4125. b e )
  4126. (while
  4127. (and
  4128. (< colon 1)
  4129. (verilog-re-search-backward "\\(\\[\\)\\|\\(\\]\\)\\|\\(:\\)"
  4130. lim1 'move))
  4131. (cond
  4132. ((match-end 1) ; [
  4133. (setq colon (1+ colon))
  4134. (if (>= colon 0)
  4135. (error "%s: unbalanced [" (verilog-point-text))))
  4136. ((match-end 2) ; ]
  4137. (setq colon (1- colon)))
  4138. ((match-end 3) ; :
  4139. (setq colon (1+ colon)))))
  4140. ;; Skip back to beginning of case item
  4141. (skip-chars-backward "\t ")
  4142. (verilog-skip-backward-comment-or-string)
  4143. (setq e (point))
  4144. (setq b
  4145. (progn
  4146. (if
  4147. (verilog-re-search-backward
  4148. "\\<\\(case[zx]?\\)\\>\\|;\\|\\<end\\>" nil 'move)
  4149. (progn
  4150. (cond
  4151. ((match-end 1)
  4152. (goto-char (match-end 1))
  4153. (verilog-forward-ws&directives)
  4154. (if (looking-at "(")
  4155. (progn
  4156. (forward-sexp)
  4157. (verilog-forward-ws&directives)))
  4158. (point))
  4159. (t
  4160. (goto-char (match-end 0))
  4161. (verilog-forward-ws&directives)
  4162. (point))))
  4163. (error "Malformed case item"))))
  4164. (setq str (buffer-substring b e))
  4165. (if
  4166. (setq e
  4167. (string-match
  4168. "[ \t]*\\(\\(\n\\)\\|\\(//\\)\\|\\(/\\*\\)\\)" str))
  4169. (setq str (concat (substring str 0 e) "...")))
  4170. str)
  4171. 'nil)))
  4172. ;;; Other functions:
  4173. ;;
  4174. (defun verilog-kill-existing-comment ()
  4175. "Kill auto comment on this line."
  4176. (save-excursion
  4177. (let* (
  4178. (e (progn
  4179. (end-of-line)
  4180. (point)))
  4181. (b (progn
  4182. (beginning-of-line)
  4183. (search-forward "//" e t))))
  4184. (if b
  4185. (delete-region (- b 2) e)))))
  4186. (defconst verilog-directive-nest-re
  4187. (concat "\\(`else\\>\\)\\|"
  4188. "\\(`endif\\>\\)\\|"
  4189. "\\(`if\\>\\)\\|"
  4190. "\\(`ifdef\\>\\)\\|"
  4191. "\\(`ifndef\\>\\)\\|"
  4192. "\\(`elsif\\>\\)"))
  4193. (defun verilog-set-auto-endcomments (indent-str kill-existing-comment)
  4194. "Add ending comment with given INDENT-STR.
  4195. With KILL-EXISTING-COMMENT, remove what was there before.
  4196. Insert `// case: 7 ' or `// NAME ' on this line if appropriate.
  4197. Insert `// case expr ' if this line ends a case block.
  4198. Insert `// ifdef FOO ' if this line ends code conditional on FOO.
  4199. Insert `// NAME ' if this line ends a function, task, module,
  4200. primitive or interface named NAME."
  4201. (save-excursion
  4202. (cond
  4203. (; Comment close preprocessor directives
  4204. (and
  4205. (looking-at "\\(`endif\\)\\|\\(`else\\)")
  4206. (or kill-existing-comment
  4207. (not (save-excursion
  4208. (end-of-line)
  4209. (search-backward "//" (point-at-bol) t)))))
  4210. (let ((nest 1) b e
  4211. m
  4212. (else (if (match-end 2) "!" " ")))
  4213. (end-of-line)
  4214. (if kill-existing-comment
  4215. (verilog-kill-existing-comment))
  4216. (delete-horizontal-space)
  4217. (save-excursion
  4218. (backward-sexp 1)
  4219. (while (and (/= nest 0)
  4220. (verilog-re-search-backward verilog-directive-nest-re nil 'move))
  4221. (cond
  4222. ((match-end 1) ; `else
  4223. (if (= nest 1)
  4224. (setq else "!")))
  4225. ((match-end 2) ; `endif
  4226. (setq nest (1+ nest)))
  4227. ((match-end 3) ; `if
  4228. (setq nest (1- nest)))
  4229. ((match-end 4) ; `ifdef
  4230. (setq nest (1- nest)))
  4231. ((match-end 5) ; `ifndef
  4232. (setq nest (1- nest)))
  4233. ((match-end 6) ; `elsif
  4234. (if (= nest 1)
  4235. (progn
  4236. (setq else "!")
  4237. (setq nest 0))))))
  4238. (if (match-end 0)
  4239. (setq
  4240. m (buffer-substring
  4241. (match-beginning 0)
  4242. (match-end 0))
  4243. b (progn
  4244. (skip-chars-forward "^ \t")
  4245. (verilog-forward-syntactic-ws)
  4246. (point))
  4247. e (progn
  4248. (skip-chars-forward "a-zA-Z0-9_")
  4249. (point)))))
  4250. (if b
  4251. (if (> (count-lines (point) b) verilog-minimum-comment-distance)
  4252. (insert (concat " // " else m " " (buffer-substring b e))))
  4253. (progn
  4254. (insert " // unmatched `else, `elsif or `endif")
  4255. (ding 't)))))
  4256. (; Comment close case/class/function/task/module and named block
  4257. (and (looking-at "\\<end")
  4258. (or kill-existing-comment
  4259. (not (save-excursion
  4260. (end-of-line)
  4261. (search-backward "//" (point-at-bol) t)))))
  4262. (let ((type (car indent-str)))
  4263. (unless (eq type 'declaration)
  4264. (unless (looking-at (concat "\\(" verilog-end-block-ordered-re "\\)[ \t]*:")) ; ignore named ends
  4265. (if (looking-at verilog-end-block-ordered-re)
  4266. (cond
  4267. (;- This is a case block; search back for the start of this case
  4268. (match-end 1) ; of verilog-end-block-ordered-re
  4269. (let ((err 't)
  4270. (str "UNMATCHED!!"))
  4271. (save-excursion
  4272. (verilog-leap-to-head)
  4273. (cond
  4274. ((looking-at "\\<randcase\\>")
  4275. (setq str "randcase")
  4276. (setq err nil))
  4277. ((looking-at "\\(\\(unique0?\\s-+\\|priority\\s-+\\)?case[xz]?\\)")
  4278. (goto-char (match-end 0))
  4279. (setq str (concat (match-string 0) " " (verilog-get-expr)))
  4280. (setq err nil))
  4281. ))
  4282. (end-of-line)
  4283. (if kill-existing-comment
  4284. (verilog-kill-existing-comment))
  4285. (delete-horizontal-space)
  4286. (insert (concat " // " str ))
  4287. (if err (ding 't))))
  4288. (;- This is a begin..end block
  4289. (match-end 2) ; of verilog-end-block-ordered-re
  4290. (let ((str " // UNMATCHED !!")
  4291. (err 't)
  4292. (here (point))
  4293. there
  4294. cntx)
  4295. (save-excursion
  4296. (verilog-leap-to-head)
  4297. (setq there (point))
  4298. (if (not (match-end 0))
  4299. (progn
  4300. (goto-char here)
  4301. (end-of-line)
  4302. (if kill-existing-comment
  4303. (verilog-kill-existing-comment))
  4304. (delete-horizontal-space)
  4305. (insert str)
  4306. (ding 't))
  4307. (let ((lim
  4308. (save-excursion (verilog-beg-of-defun) (point)))
  4309. (here (point)))
  4310. (cond
  4311. (;-- handle named block differently
  4312. (looking-at verilog-named-block-re)
  4313. (search-forward ":")
  4314. (setq there (point))
  4315. (setq str (verilog-get-expr))
  4316. (setq err nil)
  4317. (setq str (concat " // block: " str )))
  4318. ((verilog-in-case-region-p) ;-- handle case item differently
  4319. (goto-char here)
  4320. (setq str (verilog-backward-case-item lim))
  4321. (setq there (point))
  4322. (setq err nil)
  4323. (setq str (concat " // case: " str )))
  4324. (;- try to find "reason" for this begin
  4325. (cond
  4326. (;
  4327. (eq here (progn
  4328. ;; (verilog-backward-token)
  4329. (verilog-beg-of-statement)
  4330. (point)))
  4331. (setq err nil)
  4332. (setq str ""))
  4333. ((looking-at verilog-endcomment-reason-re)
  4334. (setq there (match-end 0))
  4335. (setq cntx (concat (match-string 0) " "))
  4336. (cond
  4337. (;- begin
  4338. (match-end 1)
  4339. (setq err nil)
  4340. (save-excursion
  4341. (if (and (verilog-continued-line)
  4342. (looking-at "\\<repeat\\>\\|\\<wait\\>\\|\\<always\\>"))
  4343. (progn
  4344. (goto-char (match-end 0))
  4345. (setq there (point))
  4346. (setq str
  4347. (concat " // " (match-string 0) " " (verilog-get-expr))))
  4348. (setq str ""))))
  4349. (;- else
  4350. (match-end 2)
  4351. (let ((nest 0)
  4352. ( reg "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)\\|\\(\\<if\\>\\)\\|\\(assert\\)"))
  4353. (catch 'skip
  4354. (while (verilog-re-search-backward reg nil 'move)
  4355. (cond
  4356. ((match-end 1) ; begin
  4357. (setq nest (1- nest)))
  4358. ((match-end 2) ; end
  4359. (setq nest (1+ nest)))
  4360. ((match-end 3)
  4361. (if (= 0 nest)
  4362. (progn
  4363. (goto-char (match-end 0))
  4364. (setq there (point))
  4365. (setq err nil)
  4366. (setq str (verilog-get-expr))
  4367. (setq str (concat " // else: !if" str ))
  4368. (throw 'skip 1))))
  4369. ((match-end 4)
  4370. (if (= 0 nest)
  4371. (progn
  4372. (goto-char (match-end 0))
  4373. (setq there (point))
  4374. (setq err nil)
  4375. (setq str (verilog-get-expr))
  4376. (setq str (concat " // else: !assert " str ))
  4377. (throw 'skip 1)))))))))
  4378. (;- end else
  4379. (match-end 3)
  4380. (goto-char there)
  4381. (let ((nest 0)
  4382. (reg "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)\\|\\(\\<if\\>\\)\\|\\(assert\\)"))
  4383. (catch 'skip
  4384. (while (verilog-re-search-backward reg nil 'move)
  4385. (cond
  4386. ((match-end 1) ; begin
  4387. (setq nest (1- nest)))
  4388. ((match-end 2) ; end
  4389. (setq nest (1+ nest)))
  4390. ((match-end 3)
  4391. (if (= 0 nest)
  4392. (progn
  4393. (goto-char (match-end 0))
  4394. (setq there (point))
  4395. (setq err nil)
  4396. (setq str (verilog-get-expr))
  4397. (setq str (concat " // else: !if" str ))
  4398. (throw 'skip 1))))
  4399. ((match-end 4)
  4400. (if (= 0 nest)
  4401. (progn
  4402. (goto-char (match-end 0))
  4403. (setq there (point))
  4404. (setq err nil)
  4405. (setq str (verilog-get-expr))
  4406. (setq str (concat " // else: !assert " str ))
  4407. (throw 'skip 1)))))))))
  4408. (; always, always_comb, always_latch w/o @...
  4409. (match-end 5)
  4410. (goto-char (match-end 0))
  4411. (setq there (point))
  4412. (setq err nil)
  4413. (setq str (concat " // " cntx )))
  4414. (;- task/function/initial et cetera
  4415. t
  4416. (match-end 0)
  4417. (goto-char (match-end 0))
  4418. (setq there (point))
  4419. (setq err nil)
  4420. (setq str (concat " // " cntx (verilog-get-expr))))
  4421. (;-- otherwise...
  4422. (setq str " // auto-endcomment confused "))))
  4423. ((and
  4424. (verilog-in-case-region-p) ;-- handle case item differently
  4425. (progn
  4426. (setq there (point))
  4427. (goto-char here)
  4428. (setq str (verilog-backward-case-item lim))))
  4429. (setq err nil)
  4430. (setq str (concat " // case: " str )))
  4431. ((verilog-in-fork-region-p)
  4432. (setq err nil)
  4433. (setq str " // fork branch" ))
  4434. ((looking-at "\\<end\\>")
  4435. ;; HERE
  4436. (forward-word 1)
  4437. (verilog-forward-syntactic-ws)
  4438. (setq err nil)
  4439. (setq str (verilog-get-expr))
  4440. (setq str (concat " // " cntx str )))
  4441. ))))
  4442. (goto-char here)
  4443. (end-of-line)
  4444. (if kill-existing-comment
  4445. (verilog-kill-existing-comment))
  4446. (delete-horizontal-space)
  4447. (if (or err
  4448. (> (count-lines here there) verilog-minimum-comment-distance))
  4449. (insert str))
  4450. (if err (ding 't))
  4451. ))))
  4452. (;- this is endclass, which can be nested
  4453. (match-end 11) ; of verilog-end-block-ordered-re
  4454. ;;(goto-char there)
  4455. (let ((nest 0)
  4456. (reg "\\<\\(class\\)\\|\\(endclass\\)\\|\\(package\\|primitive\\|\\(macro\\)?module\\)\\>")
  4457. string)
  4458. (save-excursion
  4459. (catch 'skip
  4460. (while (verilog-re-search-backward reg nil 'move)
  4461. (cond
  4462. ((match-end 3) ; endclass
  4463. (ding 't)
  4464. (setq string "unmatched endclass")
  4465. (throw 'skip 1))
  4466. ((match-end 2) ; endclass
  4467. (setq nest (1+ nest)))
  4468. ((match-end 1) ; class
  4469. (setq nest (1- nest))
  4470. (if (< nest 0)
  4471. (progn
  4472. (goto-char (match-end 0))
  4473. (let (b e)
  4474. (setq b (progn
  4475. (skip-chars-forward "^ \t")
  4476. (verilog-forward-ws&directives)
  4477. (point))
  4478. e (progn
  4479. (skip-chars-forward "a-zA-Z0-9_")
  4480. (point)))
  4481. (setq string (buffer-substring b e)))
  4482. (throw 'skip 1))))
  4483. ))))
  4484. (end-of-line)
  4485. (if kill-existing-comment
  4486. (verilog-kill-existing-comment))
  4487. (delete-horizontal-space)
  4488. (insert (concat " // " string ))))
  4489. (; - this is end{function,generate,task,module,primitive,table,generate}
  4490. ;; - which can not be nested.
  4491. t
  4492. (let (string reg (name-re nil))
  4493. (end-of-line)
  4494. (if kill-existing-comment
  4495. (save-match-data
  4496. (verilog-kill-existing-comment)))
  4497. (delete-horizontal-space)
  4498. (backward-sexp)
  4499. (cond
  4500. ((match-end 5) ; of verilog-end-block-ordered-re
  4501. (setq reg "\\(\\<function\\>\\)\\|\\(\\<\\(endfunction\\|task\\|\\(macro\\)?module\\|primitive\\)\\>\\)")
  4502. (setq name-re "\\w+\\(?:\n\\|\\s-\\)*[(;]"))
  4503. ((match-end 6) ; of verilog-end-block-ordered-re
  4504. (setq reg "\\(\\<task\\>\\)\\|\\(\\<\\(endtask\\|function\\|\\(macro\\)?module\\|primitive\\)\\>\\)")
  4505. (setq name-re "\\w+\\(?:\n\\|\\s-\\)*[(;]"))
  4506. ((match-end 7) ; of verilog-end-block-ordered-re
  4507. (setq reg "\\(\\<\\(macro\\)?module\\>\\)\\|\\<endmodule\\>"))
  4508. ((match-end 8) ; of verilog-end-block-ordered-re
  4509. (setq reg "\\(\\<primitive\\>\\)\\|\\(\\<\\(endprimitive\\|package\\|interface\\|\\(macro\\)?module\\)\\>\\)"))
  4510. ((match-end 9) ; of verilog-end-block-ordered-re
  4511. (setq reg "\\(\\<interface\\>\\)\\|\\(\\<\\(endinterface\\|package\\|primitive\\|\\(macro\\)?module\\)\\>\\)"))
  4512. ((match-end 10) ; of verilog-end-block-ordered-re
  4513. (setq reg "\\(\\<package\\>\\)\\|\\(\\<\\(endpackage\\|primitive\\|interface\\|\\(macro\\)?module\\)\\>\\)"))
  4514. ((match-end 11) ; of verilog-end-block-ordered-re
  4515. (setq reg "\\(\\<class\\>\\)\\|\\(\\<\\(endclass\\|primitive\\|interface\\|\\(macro\\)?module\\)\\>\\)"))
  4516. ((match-end 12) ; of verilog-end-block-ordered-re
  4517. (setq reg "\\(\\<covergroup\\>\\)\\|\\(\\<\\(endcovergroup\\|primitive\\|interface\\|\\(macro\\)?module\\)\\>\\)"))
  4518. ((match-end 13) ; of verilog-end-block-ordered-re
  4519. (setq reg "\\(\\<program\\>\\)\\|\\(\\<\\(endprogram\\|primitive\\|interface\\|\\(macro\\)?module\\)\\>\\)"))
  4520. ((match-end 14) ; of verilog-end-block-ordered-re
  4521. (setq reg "\\(\\<\\(rand\\)?sequence\\>\\)\\|\\(\\<\\(endsequence\\|primitive\\|interface\\|\\(macro\\)?module\\)\\>\\)"))
  4522. ((match-end 15) ; of verilog-end-block-ordered-re
  4523. (setq reg "\\(\\<clocking\\>\\)\\|\\<endclocking\\>"))
  4524. ((match-end 16) ; of verilog-end-block-ordered-re
  4525. (setq reg "\\(\\<property\\>\\)\\|\\<endproperty\\>"))
  4526. (t (error "Problem in verilog-set-auto-endcomments")))
  4527. (let (b e)
  4528. (save-excursion
  4529. (verilog-re-search-backward reg nil 'move)
  4530. (cond
  4531. ((match-end 1)
  4532. (setq b (progn
  4533. (skip-chars-forward "^ \t")
  4534. (verilog-forward-ws&directives)
  4535. (if (looking-at "static\\|automatic")
  4536. (progn
  4537. (goto-char (match-end 0))
  4538. (verilog-forward-ws&directives)))
  4539. (if (and name-re (verilog-re-search-forward name-re nil 'move))
  4540. (progn
  4541. (goto-char (match-beginning 0))
  4542. (verilog-forward-ws&directives)))
  4543. (point))
  4544. e (progn
  4545. (skip-chars-forward "a-zA-Z0-9_")
  4546. (point)))
  4547. (setq string (buffer-substring b e)))
  4548. (t
  4549. (ding 't)
  4550. (setq string "unmatched end(function|task|module|primitive|interface|package|class|clocking)")))))
  4551. (end-of-line)
  4552. (insert (concat " // " string )))
  4553. ))))))))))
  4554. (defun verilog-get-expr()
  4555. "Grab expression at point, e.g., case ( a | b & (c ^d))."
  4556. (let* ((b (progn
  4557. (verilog-forward-syntactic-ws)
  4558. (skip-chars-forward " \t")
  4559. (point)))
  4560. (e (let ((par 1))
  4561. (cond
  4562. ((looking-at "@")
  4563. (forward-char 1)
  4564. (verilog-forward-syntactic-ws)
  4565. (if (looking-at "(")
  4566. (progn
  4567. (forward-char 1)
  4568. (while (and (/= par 0)
  4569. (verilog-re-search-forward "\\((\\)\\|\\()\\)" nil 'move))
  4570. (cond
  4571. ((match-end 1)
  4572. (setq par (1+ par)))
  4573. ((match-end 2)
  4574. (setq par (1- par)))))))
  4575. (point))
  4576. ((looking-at "(")
  4577. (forward-char 1)
  4578. (while (and (/= par 0)
  4579. (verilog-re-search-forward "\\((\\)\\|\\()\\)" nil 'move))
  4580. (cond
  4581. ((match-end 1)
  4582. (setq par (1+ par)))
  4583. ((match-end 2)
  4584. (setq par (1- par)))))
  4585. (point))
  4586. ((looking-at "\\[")
  4587. (forward-char 1)
  4588. (while (and (/= par 0)
  4589. (verilog-re-search-forward "\\(\\[\\)\\|\\(\\]\\)" nil 'move))
  4590. (cond
  4591. ((match-end 1)
  4592. (setq par (1+ par)))
  4593. ((match-end 2)
  4594. (setq par (1- par)))))
  4595. (verilog-forward-syntactic-ws)
  4596. (skip-chars-forward "^ \t\n\f")
  4597. (point))
  4598. ((looking-at "/[/\\*]")
  4599. b)
  4600. ('t
  4601. (skip-chars-forward "^: \t\n\f")
  4602. (point)))))
  4603. (str (buffer-substring b e)))
  4604. (if (setq e (string-match "[ \t]*\\(\\(\n\\)\\|\\(//\\)\\|\\(/\\*\\)\\)" str))
  4605. (setq str (concat (substring str 0 e) "...")))
  4606. str))
  4607. (defun verilog-expand-vector ()
  4608. "Take a signal vector on the current line and expand it to multiple lines.
  4609. Useful for creating tri's and other expanded fields."
  4610. (interactive)
  4611. (verilog-expand-vector-internal "[" "]"))
  4612. (defun verilog-expand-vector-internal (bra ket)
  4613. "Given BRA, the start brace and KET, the end brace, expand one line into many lines."
  4614. (save-excursion
  4615. (forward-line 0)
  4616. (let ((signal-string (buffer-substring (point)
  4617. (progn
  4618. (end-of-line) (point)))))
  4619. (if (string-match
  4620. (concat "\\(.*\\)"
  4621. (regexp-quote bra)
  4622. "\\([0-9]*\\)\\(:[0-9]*\\|\\)\\(::[0-9---]*\\|\\)"
  4623. (regexp-quote ket)
  4624. "\\(.*\\)$") signal-string)
  4625. (let* ((sig-head (match-string 1 signal-string))
  4626. (vec-start (string-to-number (match-string 2 signal-string)))
  4627. (vec-end (if (= (match-beginning 3) (match-end 3))
  4628. vec-start
  4629. (string-to-number
  4630. (substring signal-string (1+ (match-beginning 3))
  4631. (match-end 3)))))
  4632. (vec-range
  4633. (if (= (match-beginning 4) (match-end 4))
  4634. 1
  4635. (string-to-number
  4636. (substring signal-string (+ 2 (match-beginning 4))
  4637. (match-end 4)))))
  4638. (sig-tail (match-string 5 signal-string))
  4639. vec)
  4640. ;; Decode vectors
  4641. (setq vec nil)
  4642. (if (< vec-range 0)
  4643. (let ((tmp vec-start))
  4644. (setq vec-start vec-end
  4645. vec-end tmp
  4646. vec-range (- vec-range))))
  4647. (if (< vec-end vec-start)
  4648. (while (<= vec-end vec-start)
  4649. (setq vec (append vec (list vec-start)))
  4650. (setq vec-start (- vec-start vec-range)))
  4651. (while (<= vec-start vec-end)
  4652. (setq vec (append vec (list vec-start)))
  4653. (setq vec-start (+ vec-start vec-range))))
  4654. ;;
  4655. ;; Delete current line
  4656. (delete-region (point) (progn (forward-line 0) (point)))
  4657. ;;
  4658. ;; Expand vector
  4659. (while vec
  4660. (insert (concat sig-head bra
  4661. (int-to-string (car vec)) ket sig-tail "\n"))
  4662. (setq vec (cdr vec)))
  4663. (delete-char -1)
  4664. ;;
  4665. )))))
  4666. (defun verilog-strip-comments ()
  4667. "Strip all comments from the Verilog code."
  4668. (interactive)
  4669. (goto-char (point-min))
  4670. (while (re-search-forward "//" nil t)
  4671. (if (verilog-within-string)
  4672. (re-search-forward "\"" nil t)
  4673. (if (verilog-in-star-comment-p)
  4674. (re-search-forward "\\*/" nil t)
  4675. (let ((bpt (- (point) 2)))
  4676. (end-of-line)
  4677. (delete-region bpt (point))))))
  4678. ;;
  4679. (goto-char (point-min))
  4680. (while (re-search-forward "/\\*" nil t)
  4681. (if (verilog-within-string)
  4682. (re-search-forward "\"" nil t)
  4683. (let ((bpt (- (point) 2)))
  4684. (re-search-forward "\\*/")
  4685. (delete-region bpt (point))))))
  4686. (defun verilog-one-line ()
  4687. "Convert structural Verilog instances to occupy one line."
  4688. (interactive)
  4689. (goto-char (point-min))
  4690. (while (re-search-forward "\\([^;]\\)[ \t]*\n[ \t]*" nil t)
  4691. (replace-match "\\1 " nil nil)))
  4692. (defun verilog-linter-name ()
  4693. "Return name of linter, either surelint or verilint."
  4694. (let ((compile-word1 (verilog-string-replace-matches "\\s .*$" "" nil nil
  4695. compile-command))
  4696. (lint-word1 (verilog-string-replace-matches "\\s .*$" "" nil nil
  4697. verilog-linter)))
  4698. (cond ((equal compile-word1 "surelint") `surelint)
  4699. ((equal compile-word1 "verilint") `verilint)
  4700. ((equal lint-word1 "surelint") `surelint)
  4701. ((equal lint-word1 "verilint") `verilint)
  4702. (t `surelint)))) ; back compatibility
  4703. (defun verilog-lint-off ()
  4704. "Convert a Verilog linter warning line into a disable statement.
  4705. For example:
  4706. pci_bfm_null.v, line 46: Unused input: pci_rst_
  4707. becomes a comment for the appropriate tool.
  4708. The first word of the `compile-command' or `verilog-linter'
  4709. variables is used to determine which product is being used.
  4710. See \\[verilog-surelint-off] and \\[verilog-verilint-off]."
  4711. (interactive)
  4712. (let ((linter (verilog-linter-name)))
  4713. (cond ((equal linter `surelint)
  4714. (verilog-surelint-off))
  4715. ((equal linter `verilint)
  4716. (verilog-verilint-off))
  4717. (t (error "Linter name not set")))))
  4718. (defvar compilation-last-buffer)
  4719. (defvar next-error-last-buffer)
  4720. (defun verilog-surelint-off ()
  4721. "Convert a SureLint warning line into a disable statement.
  4722. Run from Verilog source window; assumes there is a *compile* buffer
  4723. with point set appropriately.
  4724. For example:
  4725. WARNING [STD-UDDONX]: xx.v, line 8: output out is never assigned.
  4726. becomes:
  4727. // surefire lint_line_off UDDONX"
  4728. (interactive)
  4729. (let ((buff (if (boundp 'next-error-last-buffer)
  4730. next-error-last-buffer
  4731. compilation-last-buffer)))
  4732. (when (buffer-live-p buff)
  4733. (save-excursion
  4734. (switch-to-buffer buff)
  4735. (beginning-of-line)
  4736. (when
  4737. (looking-at "\\(INFO\\|WARNING\\|ERROR\\) \\[[^-]+-\\([^]]+\\)\\]: \\([^,]+\\), line \\([0-9]+\\): \\(.*\\)$")
  4738. (let* ((code (match-string 2))
  4739. (file (match-string 3))
  4740. (line (match-string 4))
  4741. (buffer (get-file-buffer file))
  4742. dir filename)
  4743. (unless buffer
  4744. (progn
  4745. (setq buffer
  4746. (and (file-exists-p file)
  4747. (find-file-noselect file)))
  4748. (or buffer
  4749. (let* ((pop-up-windows t))
  4750. (let ((name (expand-file-name
  4751. (read-file-name
  4752. (format "Find this error in: (default %s) "
  4753. file)
  4754. dir file t))))
  4755. (if (file-directory-p name)
  4756. (setq name (expand-file-name filename name)))
  4757. (setq buffer
  4758. (and (file-exists-p name)
  4759. (find-file-noselect name))))))))
  4760. (switch-to-buffer buffer)
  4761. (goto-char (point-min))
  4762. (forward-line (- (string-to-number line)))
  4763. (end-of-line)
  4764. (catch 'already
  4765. (cond
  4766. ((verilog-in-slash-comment-p)
  4767. (re-search-backward "//")
  4768. (cond
  4769. ((looking-at "// surefire lint_off_line ")
  4770. (goto-char (match-end 0))
  4771. (let ((lim (point-at-eol)))
  4772. (if (re-search-forward code lim 'move)
  4773. (throw 'already t)
  4774. (insert (concat " " code)))))
  4775. (t
  4776. )))
  4777. ((verilog-in-star-comment-p)
  4778. (re-search-backward "/\\*")
  4779. (insert (format " // surefire lint_off_line %6s" code )))
  4780. (t
  4781. (insert (format " // surefire lint_off_line %6s" code ))
  4782. )))))))))
  4783. (defun verilog-verilint-off ()
  4784. "Convert a Verilint warning line into a disable statement.
  4785. For example:
  4786. (W240) pci_bfm_null.v, line 46: Unused input: pci_rst_
  4787. becomes:
  4788. //Verilint 240 off // WARNING: Unused input"
  4789. (interactive)
  4790. (save-excursion
  4791. (beginning-of-line)
  4792. (when (looking-at "\\(.*\\)([WE]\\([0-9A-Z]+\\)).*,\\s +line\\s +[0-9]+:\\s +\\([^:\n]+\\):?.*$")
  4793. (replace-match (format
  4794. ;; %3s makes numbers 1-999 line up nicely
  4795. "\\1//Verilint %3s off // WARNING: \\3"
  4796. (match-string 2)))
  4797. (beginning-of-line)
  4798. (verilog-indent-line))))
  4799. (defun verilog-auto-save-compile ()
  4800. "Update automatics with \\[verilog-auto], save the buffer, and compile."
  4801. (interactive)
  4802. (verilog-auto) ; Always do it for safety
  4803. (save-buffer)
  4804. (compile compile-command))
  4805. (defun verilog-preprocess (&optional command filename)
  4806. "Preprocess the buffer, similar to `compile', but put output in Verilog-Mode.
  4807. Takes optional COMMAND or defaults to `verilog-preprocessor', and
  4808. FILENAME to find directory to run in, or defaults to `buffer-file-name'."
  4809. (interactive
  4810. (list
  4811. (let ((default (verilog-expand-command verilog-preprocessor)))
  4812. (set (make-local-variable `verilog-preprocessor)
  4813. (read-from-minibuffer "Run Preprocessor (like this): "
  4814. default nil nil
  4815. 'verilog-preprocess-history default)))))
  4816. (unless command (setq command (verilog-expand-command verilog-preprocessor)))
  4817. (let* ((fontlocked (and (boundp 'font-lock-mode) font-lock-mode))
  4818. (dir (file-name-directory (or filename buffer-file-name)))
  4819. (cmd (concat "cd " dir "; " command)))
  4820. (with-output-to-temp-buffer "*Verilog-Preprocessed*"
  4821. (with-current-buffer (get-buffer "*Verilog-Preprocessed*")
  4822. (insert (concat "// " cmd "\n"))
  4823. (call-process shell-file-name nil t nil shell-command-switch cmd)
  4824. (verilog-mode)
  4825. ;; Without this force, it takes a few idle seconds
  4826. ;; to get the color, which is very jarring
  4827. (unless (fboundp 'font-lock-ensure)
  4828. ;; We should use font-lock-ensure in preference to
  4829. ;; font-lock-fontify-buffer, but IIUC the problem this is supposed to
  4830. ;; solve only appears in Emacsen older than font-lock-ensure anyway.
  4831. ;; So avoid bytecomp's interactive-only by going through intern.
  4832. (when fontlocked (funcall (intern "font-lock-fontify-buffer"))))))))
  4833. ;;; Batch:
  4834. ;;
  4835. (defun verilog-warn (string &rest args)
  4836. "Print a warning with `format' using STRING and optional ARGS."
  4837. (apply 'message (concat "%%Warning: " string) args))
  4838. (defun verilog-warn-error (string &rest args)
  4839. "Call `error' using STRING and optional ARGS.
  4840. If `verilog-warn-fatal' is non-nil, call `verilog-warn' instead."
  4841. (if verilog-warn-fatal
  4842. (apply 'error string args)
  4843. (apply 'verilog-warn string args)))
  4844. (defmacro verilog-batch-error-wrapper (&rest body)
  4845. "Execute BODY and add error prefix to any errors found.
  4846. This lets programs calling batch mode to easily extract error messages."
  4847. `(let ((verilog-warn-fatal nil))
  4848. (condition-case err
  4849. (progn ,@body)
  4850. (error
  4851. (error "%%Error: %s%s" (error-message-string err)
  4852. (if (featurep 'xemacs) "\n" "")))))) ; XEmacs forgets to add a newline
  4853. (defun verilog-batch-execute-func (funref &optional no-save)
  4854. "Internal processing of a batch command.
  4855. Runs FUNREF on all command arguments.
  4856. Save the result unless optional NO-SAVE is t."
  4857. (verilog-batch-error-wrapper
  4858. ;; Setting global variables like that is *VERY NASTY* !!! --Stef
  4859. ;; However, this function is called only when Emacs is being used as
  4860. ;; a standalone language instead of as an editor, so we'll live.
  4861. ;;
  4862. ;; General globals needed
  4863. (setq make-backup-files nil)
  4864. (setq-default make-backup-files nil)
  4865. (setq enable-local-variables t)
  4866. (setq enable-local-eval t)
  4867. (setq create-lockfiles nil)
  4868. ;; Make sure any sub-files we read get proper mode
  4869. (setq-default major-mode 'verilog-mode)
  4870. ;; Ditto files already read in
  4871. ;; Remember buffer list, so don't later pickup any verilog-getopt files
  4872. (let ((orig-buffer-list (buffer-list)))
  4873. (mapc (lambda (buf)
  4874. (when (buffer-file-name buf)
  4875. (with-current-buffer buf
  4876. (verilog-mode)
  4877. (verilog-auto-reeval-locals)
  4878. (verilog-getopt-flags))))
  4879. orig-buffer-list)
  4880. ;; Process the files
  4881. (mapcar (lambda (buf)
  4882. (when (buffer-file-name buf)
  4883. (save-excursion
  4884. (if (not (file-exists-p (buffer-file-name buf)))
  4885. (error
  4886. "File not found: %s" (buffer-file-name buf)))
  4887. (message "Processing %s" (buffer-file-name buf))
  4888. (set-buffer buf)
  4889. (funcall funref)
  4890. (when (and (not no-save)
  4891. (buffer-modified-p)) ; Avoid "no changes to be saved"
  4892. (save-buffer)))))
  4893. orig-buffer-list))))
  4894. (defun verilog-batch-auto ()
  4895. "For use with --batch, perform automatic expansions as a stand-alone tool.
  4896. This sets up the appropriate Verilog mode environment, updates automatics
  4897. with \\[verilog-auto] on all command-line files, and saves the buffers.
  4898. For proper results, multiple filenames need to be passed on the command
  4899. line in bottom-up order."
  4900. (unless noninteractive
  4901. (error "Use verilog-batch-auto only with --batch")) ; Otherwise we'd mess up buffer modes
  4902. (verilog-batch-execute-func `verilog-auto))
  4903. (defun verilog-batch-delete-auto ()
  4904. "For use with --batch, perform automatic deletion as a stand-alone tool.
  4905. This sets up the appropriate Verilog mode environment, deletes automatics
  4906. with \\[verilog-delete-auto] on all command-line files, and saves the buffers."
  4907. (unless noninteractive
  4908. (error "Use verilog-batch-delete-auto only with --batch")) ; Otherwise we'd mess up buffer modes
  4909. (verilog-batch-execute-func `verilog-delete-auto))
  4910. (defun verilog-batch-delete-trailing-whitespace ()
  4911. "For use with --batch, perform whitespace deletion as a stand-alone tool.
  4912. This sets up the appropriate Verilog mode environment, removes
  4913. whitespace with \\[verilog-delete-trailing-whitespace] on all
  4914. command-line files, and saves the buffers."
  4915. (unless noninteractive
  4916. (error "Use verilog-batch-delete-trailing-whitespace only with --batch")) ; Otherwise we'd mess up buffer modes
  4917. (verilog-batch-execute-func `verilog-delete-trailing-whitespace))
  4918. (defun verilog-batch-diff-auto ()
  4919. "For use with --batch, perform automatic differences as a stand-alone tool.
  4920. This sets up the appropriate Verilog mode environment, expand automatics
  4921. with \\[verilog-diff-auto] on all command-line files, and reports an error
  4922. if any differences are observed. This is appropriate for adding to regressions
  4923. to insure automatics are always properly maintained."
  4924. (unless noninteractive
  4925. (error "Use verilog-batch-diff-auto only with --batch")) ; Otherwise we'd mess up buffer modes
  4926. (verilog-batch-execute-func `verilog-diff-auto t))
  4927. (defun verilog-batch-inject-auto ()
  4928. "For use with --batch, perform automatic injection as a stand-alone tool.
  4929. This sets up the appropriate Verilog mode environment, injects new automatics
  4930. with \\[verilog-inject-auto] on all command-line files, and saves the buffers.
  4931. For proper results, multiple filenames need to be passed on the command
  4932. line in bottom-up order."
  4933. (unless noninteractive
  4934. (error "Use verilog-batch-inject-auto only with --batch")) ; Otherwise we'd mess up buffer modes
  4935. (verilog-batch-execute-func `verilog-inject-auto))
  4936. (defun verilog-batch-indent ()
  4937. "For use with --batch, reindent an entire file as a stand-alone tool.
  4938. This sets up the appropriate Verilog mode environment, calls
  4939. \\[verilog-indent-buffer] on all command-line files, and saves the buffers."
  4940. (unless noninteractive
  4941. (error "Use verilog-batch-indent only with --batch")) ; Otherwise we'd mess up buffer modes
  4942. (verilog-batch-execute-func `verilog-indent-buffer))
  4943. ;;; Indentation:
  4944. ;;
  4945. (defconst verilog-indent-alist
  4946. '((block . (+ ind verilog-indent-level))
  4947. (case . (+ ind verilog-case-indent))
  4948. (cparenexp . (+ ind verilog-indent-level))
  4949. (cexp . (+ ind verilog-cexp-indent))
  4950. (defun . verilog-indent-level-module)
  4951. (declaration . verilog-indent-level-declaration)
  4952. (directive . (verilog-calculate-indent-directive))
  4953. (tf . verilog-indent-level)
  4954. (behavioral . (+ verilog-indent-level-behavioral verilog-indent-level-module))
  4955. (statement . ind)
  4956. (cpp . 0)
  4957. (comment . (verilog-comment-indent))
  4958. (unknown . 3)
  4959. (string . 0)))
  4960. (defun verilog-continued-line-1 (lim)
  4961. "Return true if this is a continued line.
  4962. Set point to where line starts. Limit search to point LIM."
  4963. (let ((continued 't))
  4964. (if (eq 0 (forward-line -1))
  4965. (progn
  4966. (end-of-line)
  4967. (verilog-backward-ws&directives lim)
  4968. (if (bobp)
  4969. (setq continued nil)
  4970. (setq continued (verilog-backward-token))))
  4971. (setq continued nil))
  4972. continued))
  4973. (defun verilog-calculate-indent ()
  4974. "Calculate the indent of the current Verilog line.
  4975. Examine previous lines. Once a line is found that is definitive as to the
  4976. type of the current line, return that lines' indent level and its type.
  4977. Return a list of two elements: (INDENT-TYPE INDENT-LEVEL)."
  4978. (save-excursion
  4979. (let* ((starting_position (point))
  4980. (case-fold-search nil)
  4981. (par 0)
  4982. (begin (looking-at "[ \t]*begin\\>"))
  4983. (lim (save-excursion (verilog-re-search-backward "\\(\\<begin\\>\\)\\|\\(\\<module\\>\\)" nil t)))
  4984. (structres nil)
  4985. (type (catch 'nesting
  4986. ;; Keep working backwards until we can figure out
  4987. ;; what type of statement this is.
  4988. ;; Basically we need to figure out
  4989. ;; 1) if this is a continuation of the previous line;
  4990. ;; 2) are we in a block scope (begin..end)
  4991. ;; if we are in a comment, done.
  4992. (if (verilog-in-star-comment-p)
  4993. (throw 'nesting 'comment))
  4994. ;; if we have a directive, done.
  4995. (if (save-excursion (beginning-of-line)
  4996. (and (looking-at verilog-directive-re-1)
  4997. (not (or (looking-at "[ \t]*`[ou]vm_")
  4998. (looking-at "[ \t]*`vmm_")))))
  4999. (throw 'nesting 'directive))
  5000. ;; indent structs as if there were module level
  5001. (setq structres (verilog-in-struct-nested-p))
  5002. (cond ((not structres) nil)
  5003. ;;((and structres (equal (char-after) ?\})) (throw 'nesting 'struct-close))
  5004. ((> structres 0) (throw 'nesting 'nested-struct))
  5005. ((= structres 0) (throw 'nesting 'block))
  5006. (t nil))
  5007. ;; if we are in a parenthesized list, and the user likes to indent these, return.
  5008. ;; unless we are in the newfangled coverpoint or constraint blocks
  5009. (if (and
  5010. verilog-indent-lists
  5011. (verilog-in-paren)
  5012. (not (verilog-in-coverage-p))
  5013. )
  5014. (progn (setq par 1)
  5015. (throw 'nesting 'block)))
  5016. ;; See if we are continuing a previous line
  5017. (while t
  5018. ;; trap out if we crawl off the top of the buffer
  5019. (if (bobp) (throw 'nesting 'cpp))
  5020. (if (and (verilog-continued-line-1 lim)
  5021. (or (not (verilog-in-coverage-p))
  5022. (looking-at verilog-in-constraint-re) )) ; may still get hosed if concat in constraint
  5023. (let ((sp (point)))
  5024. (if (and
  5025. (not (looking-at verilog-complete-reg))
  5026. (verilog-continued-line-1 lim))
  5027. (progn (goto-char sp)
  5028. (throw 'nesting 'cexp))
  5029. (goto-char sp))
  5030. (if (and (verilog-in-coverage-p)
  5031. (looking-at verilog-in-constraint-re))
  5032. (progn
  5033. (beginning-of-line)
  5034. (skip-chars-forward " \t")
  5035. (throw 'nesting 'constraint)))
  5036. (if (and begin
  5037. (not verilog-indent-begin-after-if)
  5038. (looking-at verilog-no-indent-begin-re))
  5039. (progn
  5040. (beginning-of-line)
  5041. (skip-chars-forward " \t")
  5042. (throw 'nesting 'statement))
  5043. (progn
  5044. (throw 'nesting 'cexp))))
  5045. ;; not a continued line
  5046. (goto-char starting_position))
  5047. (if (looking-at "\\<else\\>")
  5048. ;; search back for governing if, striding across begin..end pairs
  5049. ;; appropriately
  5050. (let ((elsec 1))
  5051. (while (verilog-re-search-backward verilog-ends-re nil 'move)
  5052. (cond
  5053. ((match-end 1) ; else, we're in deep
  5054. (setq elsec (1+ elsec)))
  5055. ((match-end 2) ; if
  5056. (setq elsec (1- elsec))
  5057. (if (= 0 elsec)
  5058. (if verilog-align-ifelse
  5059. (throw 'nesting 'statement)
  5060. (progn ; back up to first word on this line
  5061. (beginning-of-line)
  5062. (verilog-forward-syntactic-ws)
  5063. (throw 'nesting 'statement)))))
  5064. ((match-end 3) ; assert block
  5065. (setq elsec (1- elsec))
  5066. (verilog-beg-of-statement) ; doesn't get to beginning
  5067. (if (looking-at verilog-property-re)
  5068. (throw 'nesting 'statement) ; We don't need an endproperty for these
  5069. (throw 'nesting 'block) ; We still need an endproperty
  5070. ))
  5071. (t ; endblock
  5072. ;; try to leap back to matching outward block by striding across
  5073. ;; indent level changing tokens then immediately
  5074. ;; previous line governs indentation.
  5075. (let (( reg) (nest 1))
  5076. ;; verilog-ends => else|if|end|join(_any|_none|)|endcase|endclass|endtable|endspecify|endfunction|endtask|endgenerate|endgroup
  5077. (cond
  5078. ((match-end 4) ; end
  5079. ;; Search back for matching begin
  5080. (setq reg "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)" ))
  5081. ((match-end 5) ; endcase
  5082. ;; Search back for matching case
  5083. (setq reg "\\(\\<randcase\\>\\|\\<case[xz]?\\>[^:]\\)\\|\\(\\<endcase\\>\\)" ))
  5084. ((match-end 6) ; endfunction
  5085. ;; Search back for matching function
  5086. (setq reg "\\(\\<function\\>\\)\\|\\(\\<endfunction\\>\\)" ))
  5087. ((match-end 7) ; endtask
  5088. ;; Search back for matching task
  5089. (setq reg "\\(\\<task\\>\\)\\|\\(\\<endtask\\>\\)" ))
  5090. ((match-end 8) ; endspecify
  5091. ;; Search back for matching specify
  5092. (setq reg "\\(\\<specify\\>\\)\\|\\(\\<endspecify\\>\\)" ))
  5093. ((match-end 9) ; endtable
  5094. ;; Search back for matching table
  5095. (setq reg "\\(\\<table\\>\\)\\|\\(\\<endtable\\>\\)" ))
  5096. ((match-end 10) ; endgenerate
  5097. ;; Search back for matching generate
  5098. (setq reg "\\(\\<generate\\>\\)\\|\\(\\<endgenerate\\>\\)" ))
  5099. ((match-end 11) ; joins
  5100. ;; Search back for matching fork
  5101. (setq reg "\\(\\<fork\\>\\)\\|\\(\\<join\\(_any\\|none\\)?\\>\\)" ))
  5102. ((match-end 12) ; class
  5103. ;; Search back for matching class
  5104. (setq reg "\\(\\<class\\>\\)\\|\\(\\<endclass\\>\\)" ))
  5105. ((match-end 13) ; covergroup
  5106. ;; Search back for matching covergroup
  5107. (setq reg "\\(\\<covergroup\\>\\)\\|\\(\\<endgroup\\>\\)" )))
  5108. (catch 'skip
  5109. (while (verilog-re-search-backward reg nil 'move)
  5110. (cond
  5111. ((match-end 1) ; begin
  5112. (setq nest (1- nest))
  5113. (if (= 0 nest)
  5114. (throw 'skip 1)))
  5115. ((match-end 2) ; end
  5116. (setq nest (1+ nest)))))
  5117. )))))))
  5118. (throw 'nesting (verilog-calc-1)))
  5119. ) ; catch nesting
  5120. ) ; type
  5121. )
  5122. ;; Return type of block and indent level.
  5123. (if (not type)
  5124. (setq type 'cpp))
  5125. (if (> par 0) ; Unclosed Parenthesis
  5126. (list 'cparenexp par)
  5127. (cond
  5128. ((eq type 'case)
  5129. (list type (verilog-case-indent-level)))
  5130. ((eq type 'statement)
  5131. (list type (current-column)))
  5132. ((eq type 'defun)
  5133. (list type 0))
  5134. ((eq type 'constraint)
  5135. (list 'block (current-column)))
  5136. ((eq type 'nested-struct)
  5137. (list 'block structres))
  5138. (t
  5139. (list type (verilog-current-indent-level))))))))
  5140. (defun verilog-wai ()
  5141. "Show matching nesting block for debugging."
  5142. (interactive)
  5143. (save-excursion
  5144. (let* ((type (verilog-calc-1))
  5145. depth)
  5146. ;; Return type of block and indent level.
  5147. (if (not type)
  5148. (setq type 'cpp))
  5149. (if (and
  5150. verilog-indent-lists
  5151. (not(or (verilog-in-coverage-p)
  5152. (verilog-in-struct-p)))
  5153. (verilog-in-paren))
  5154. (setq depth 1)
  5155. (cond
  5156. ((eq type 'case)
  5157. (setq depth (verilog-case-indent-level)))
  5158. ((eq type 'statement)
  5159. (setq depth (current-column)))
  5160. ((eq type 'defun)
  5161. (setq depth 0))
  5162. (t
  5163. (setq depth (verilog-current-indent-level)))))
  5164. (message "You are at nesting %s depth %d" type depth))))
  5165. (defun verilog-calc-1 ()
  5166. (catch 'nesting
  5167. (let ((re (concat "\\({\\|}\\|" verilog-indent-re "\\)"))
  5168. (inconstraint (verilog-in-coverage-p)))
  5169. (while (verilog-re-search-backward re nil 'move)
  5170. (catch 'continue
  5171. (cond
  5172. ((equal (char-after) ?\{)
  5173. ;; block type returned based on outer constraint { or inner
  5174. (if (verilog-at-constraint-p)
  5175. (cond (inconstraint
  5176. (beginning-of-line nil)
  5177. (skip-chars-forward " \t")
  5178. (throw 'nesting 'constraint))
  5179. (t
  5180. (throw 'nesting 'statement)))))
  5181. ((equal (char-after) ?\})
  5182. (let (par-pos
  5183. (there (verilog-at-close-constraint-p)))
  5184. (if there ; we are at the } that closes a constraint. Find the { that opens it
  5185. (progn
  5186. (if (> (verilog-in-paren-count) 0)
  5187. (forward-char 1))
  5188. (setq par-pos (verilog-parenthesis-depth))
  5189. (cond (par-pos
  5190. (goto-char par-pos)
  5191. (forward-char 1))
  5192. (t
  5193. (backward-char 1)))))))
  5194. ((looking-at verilog-beg-block-re-ordered)
  5195. (cond
  5196. ((match-end 2) ; *sigh* could be "unique case" or "priority casex"
  5197. (let ((here (point)))
  5198. (verilog-beg-of-statement)
  5199. (if (looking-at verilog-extended-case-re)
  5200. (throw 'nesting 'case)
  5201. (goto-char here)))
  5202. (throw 'nesting 'case))
  5203. ((match-end 4) ; *sigh* could be "disable fork"
  5204. (let ((here (point)))
  5205. (verilog-beg-of-statement)
  5206. (if (looking-at verilog-disable-fork-re)
  5207. t ; this is a normal statement
  5208. (progn ; or is fork, starts a new block
  5209. (goto-char here)
  5210. (throw 'nesting 'block)))))
  5211. ((match-end 27) ; *sigh* might be a clocking declaration
  5212. (let ((here (point)))
  5213. (if (verilog-in-paren)
  5214. t ; this is a normal statement
  5215. (progn ; or is fork, starts a new block
  5216. (goto-char here)
  5217. (throw 'nesting 'block)))))
  5218. ;; need to consider typedef struct here...
  5219. ((looking-at "\\<class\\|struct\\|function\\|task\\>")
  5220. ;; *sigh* These words have an optional prefix:
  5221. ;; extern {virtual|protected}? function a();
  5222. ;; typedef class foo;
  5223. ;; and we don't want to confuse this with
  5224. ;; function a();
  5225. ;; property
  5226. ;; ...
  5227. ;; endfunction
  5228. (verilog-beg-of-statement)
  5229. (cond
  5230. ((looking-at verilog-dpi-import-export-re)
  5231. (throw 'continue 'foo))
  5232. ((looking-at "\\<pure\\>\\s-+\\<virtual\\>\\s-+\\(?:\\<\\(local\\|protected\\|static\\)\\>\\s-+\\)?\\<\\(function\\|task\\)\\>\\s-+")
  5233. (throw 'nesting 'statement))
  5234. ((looking-at verilog-beg-block-re-ordered)
  5235. (throw 'nesting 'block))
  5236. (t
  5237. (throw 'nesting 'defun))))
  5238. ;;
  5239. ((looking-at "\\<property\\>")
  5240. ;; *sigh*
  5241. ;; {assert|assume|cover} property (); are complete
  5242. ;; and could also be labeled: - foo: assert property
  5243. ;; but
  5244. ;; property ID () ... needs end_property
  5245. (verilog-beg-of-statement)
  5246. (if (looking-at verilog-property-re)
  5247. (throw 'continue 'statement) ; We don't need an endproperty for these
  5248. (throw 'nesting 'block) ;We still need an endproperty
  5249. ))
  5250. (t (throw 'nesting 'block))))
  5251. ((looking-at verilog-end-block-re)
  5252. (verilog-leap-to-head)
  5253. (if (verilog-in-case-region-p)
  5254. (progn
  5255. (verilog-leap-to-case-head)
  5256. (if (looking-at verilog-extended-case-re)
  5257. (throw 'nesting 'case)))))
  5258. ((looking-at verilog-defun-level-re)
  5259. (if (looking-at verilog-defun-level-generate-only-re)
  5260. (if (or (verilog-in-generate-region-p)
  5261. (verilog-in-deferred-immediate-final-p))
  5262. (throw 'continue 'foo) ; always block in a generate - keep looking
  5263. (throw 'nesting 'defun))
  5264. (throw 'nesting 'defun)))
  5265. ((looking-at verilog-cpp-level-re)
  5266. (throw 'nesting 'cpp))
  5267. ((bobp)
  5268. (throw 'nesting 'cpp)))))
  5269. (throw 'nesting 'cpp))))
  5270. (defun verilog-calculate-indent-directive ()
  5271. "Return indentation level for directive.
  5272. For speed, the searcher looks at the last directive, not the indent
  5273. of the appropriate enclosing block."
  5274. (let ((base -1) ; Indent of the line that determines our indentation
  5275. (ind 0)) ; Relative offset caused by other directives (like `endif on same line as `else)
  5276. ;; Start at current location, scan back for another directive
  5277. (save-excursion
  5278. (beginning-of-line)
  5279. (while (and (< base 0)
  5280. (verilog-re-search-backward verilog-directive-re nil t))
  5281. (cond ((save-excursion (skip-chars-backward " \t") (bolp))
  5282. (setq base (current-indentation))))
  5283. (cond ((and (looking-at verilog-directive-end) (< base 0)) ; Only matters when not at BOL
  5284. (setq ind (- ind verilog-indent-level-directive)))
  5285. ((and (looking-at verilog-directive-middle) (>= base 0)) ; Only matters when at BOL
  5286. (setq ind (+ ind verilog-indent-level-directive)))
  5287. ((looking-at verilog-directive-begin)
  5288. (setq ind (+ ind verilog-indent-level-directive)))))
  5289. ;; Adjust indent to starting indent of critical line
  5290. (setq ind (max 0 (+ ind base))))
  5291. (save-excursion
  5292. (beginning-of-line)
  5293. (skip-chars-forward " \t")
  5294. (cond ((or (looking-at verilog-directive-middle)
  5295. (looking-at verilog-directive-end))
  5296. (setq ind (max 0 (- ind verilog-indent-level-directive))))))
  5297. ind))
  5298. (defun verilog-leap-to-case-head ()
  5299. (let ((nest 1))
  5300. (while (/= 0 nest)
  5301. (verilog-re-search-backward
  5302. (concat
  5303. "\\(\\<randcase\\>\\|\\(\\<unique0?\\s-+\\|priority\\s-+\\)?\\<case[xz]?\\>\\)"
  5304. "\\|\\(\\<endcase\\>\\)" )
  5305. nil 'move)
  5306. (cond
  5307. ((match-end 1)
  5308. (let ((here (point)))
  5309. (verilog-beg-of-statement)
  5310. (unless (looking-at verilog-extended-case-re)
  5311. (goto-char here)))
  5312. (setq nest (1- nest)))
  5313. ((match-end 3)
  5314. (setq nest (1+ nest)))
  5315. ((bobp)
  5316. (ding 't)
  5317. (setq nest 0))))))
  5318. (defun verilog-leap-to-head ()
  5319. "Move point to the head of this block.
  5320. Jump from end to matching begin, from endcase to matching case, and so on."
  5321. (let ((reg nil)
  5322. snest
  5323. (nesting 'yes)
  5324. (nest 1))
  5325. (cond
  5326. ((looking-at "\\<end\\>")
  5327. ;; 1: Search back for matching begin
  5328. (setq reg (concat "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)\\|"
  5329. "\\(\\<endcase\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)" )))
  5330. ((looking-at "\\<endtask\\>")
  5331. ;; 2: Search back for matching task
  5332. (setq reg "\\(\\<task\\>\\)\\|\\(\\(\\(\\<virtual\\>\\s-+\\)\\|\\(\\<protected\\>\\s-+\\)\\)+\\<task\\>\\)")
  5333. (setq nesting 'no))
  5334. ((looking-at "\\<endcase\\>")
  5335. (catch 'nesting
  5336. (verilog-leap-to-case-head) )
  5337. (setq reg nil) ; to force skip
  5338. )
  5339. ((looking-at "\\<join\\(_any\\|_none\\)?\\>")
  5340. ;; 4: Search back for matching fork
  5341. (setq reg "\\(\\<fork\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)" ))
  5342. ((looking-at "\\<endclass\\>")
  5343. ;; 5: Search back for matching class
  5344. (setq reg "\\(\\<class\\>\\)\\|\\(\\<endclass\\>\\)" ))
  5345. ((looking-at "\\<endtable\\>")
  5346. ;; 6: Search back for matching table
  5347. (setq reg "\\(\\<table\\>\\)\\|\\(\\<endtable\\>\\)" ))
  5348. ((looking-at "\\<endspecify\\>")
  5349. ;; 7: Search back for matching specify
  5350. (setq reg "\\(\\<specify\\>\\)\\|\\(\\<endspecify\\>\\)" ))
  5351. ((looking-at "\\<endfunction\\>")
  5352. ;; 8: Search back for matching function
  5353. (setq reg "\\(\\<function\\>\\)\\|\\(\\(\\(\\<virtual\\>\\s-+\\)\\|\\(\\<protected\\>\\s-+\\)\\)+\\<function\\>\\)")
  5354. (setq nesting 'no))
  5355. ;;(setq reg "\\(\\<function\\>\\)\\|\\(\\<endfunction\\>\\)" ))
  5356. ((looking-at "\\<endgenerate\\>")
  5357. ;; 8: Search back for matching generate
  5358. (setq reg "\\(\\<generate\\>\\)\\|\\(\\<endgenerate\\>\\)" ))
  5359. ((looking-at "\\<endgroup\\>")
  5360. ;; 10: Search back for matching covergroup
  5361. (setq reg "\\(\\<covergroup\\>\\)\\|\\(\\<endgroup\\>\\)" ))
  5362. ((looking-at "\\<endproperty\\>")
  5363. ;; 11: Search back for matching property
  5364. (setq reg "\\(\\<property\\>\\)\\|\\(\\<endproperty\\>\\)" ))
  5365. ((looking-at verilog-uvm-end-re)
  5366. ;; 12: Search back for matching sequence
  5367. (setq reg (concat "\\(" verilog-uvm-begin-re "\\|" verilog-uvm-end-re "\\)")))
  5368. ((looking-at verilog-ovm-end-re)
  5369. ;; 12: Search back for matching sequence
  5370. (setq reg (concat "\\(" verilog-ovm-begin-re "\\|" verilog-ovm-end-re "\\)")))
  5371. ((looking-at verilog-vmm-end-re)
  5372. ;; 12: Search back for matching sequence
  5373. (setq reg (concat "\\(" verilog-vmm-begin-re "\\|" verilog-vmm-end-re "\\)")))
  5374. ((looking-at "\\<endinterface\\>")
  5375. ;; 12: Search back for matching interface
  5376. (setq reg "\\(\\<interface\\>\\)\\|\\(\\<endinterface\\>\\)" ))
  5377. ((looking-at "\\<endsequence\\>")
  5378. ;; 12: Search back for matching sequence
  5379. (setq reg "\\(\\<\\(rand\\)?sequence\\>\\)\\|\\(\\<endsequence\\>\\)" ))
  5380. ((looking-at "\\<endclocking\\>")
  5381. ;; 12: Search back for matching clocking
  5382. (setq reg "\\(\\<clocking\\)\\|\\(\\<endclocking\\>\\)" )))
  5383. (if reg
  5384. (catch 'skip
  5385. (if (eq nesting 'yes)
  5386. (let (sreg)
  5387. (while (verilog-re-search-backward reg nil 'move)
  5388. (cond
  5389. ((match-end 1) ; begin
  5390. (if (looking-at "fork")
  5391. (let ((here (point)))
  5392. (verilog-beg-of-statement)
  5393. (unless (looking-at verilog-disable-fork-re)
  5394. (goto-char here)
  5395. (setq nest (1- nest))))
  5396. (setq nest (1- nest)))
  5397. (if (= 0 nest)
  5398. ;; Now previous line describes syntax
  5399. (throw 'skip 1))
  5400. (if (and snest
  5401. (= snest nest))
  5402. (setq reg sreg)))
  5403. ((match-end 2) ; end
  5404. (setq nest (1+ nest)))
  5405. ((match-end 3)
  5406. ;; endcase, jump to case
  5407. (setq snest nest)
  5408. (setq nest (1+ nest))
  5409. (setq sreg reg)
  5410. (setq reg "\\(\\<randcase\\>\\|\\<case[xz]?\\>[^:]\\)\\|\\(\\<endcase\\>\\)" ))
  5411. ((match-end 4)
  5412. ;; join, jump to fork
  5413. (setq snest nest)
  5414. (setq nest (1+ nest))
  5415. (setq sreg reg)
  5416. (setq reg "\\(\\<fork\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)" ))
  5417. )))
  5418. ;; no nesting
  5419. (if (and
  5420. (verilog-re-search-backward reg nil 'move)
  5421. (match-end 1)) ; task -> could be virtual and/or protected
  5422. (progn
  5423. (verilog-beg-of-statement)
  5424. (throw 'skip 1))
  5425. (throw 'skip 1)))))))
  5426. (defun verilog-continued-line ()
  5427. "Return true if this is a continued line.
  5428. Set point to where line starts."
  5429. (let ((continued 't))
  5430. (if (eq 0 (forward-line -1))
  5431. (progn
  5432. (end-of-line)
  5433. (verilog-backward-ws&directives)
  5434. (if (bobp)
  5435. (setq continued nil)
  5436. (while (and continued
  5437. (save-excursion
  5438. (skip-chars-backward " \t")
  5439. (not (bolp))))
  5440. (setq continued (verilog-backward-token)))))
  5441. (setq continued nil))
  5442. continued))
  5443. (defun verilog-backward-token ()
  5444. "Step backward token, returning true if this is a continued line."
  5445. (interactive)
  5446. (verilog-backward-syntactic-ws)
  5447. (cond
  5448. ((bolp)
  5449. nil)
  5450. (;-- Anything ending in a ; is complete
  5451. (= (preceding-char) ?\;)
  5452. nil)
  5453. (; If a "}" is prefixed by a ";", then this is a complete statement
  5454. ;; i.e.: constraint foo { a = b; }
  5455. (= (preceding-char) ?\})
  5456. (progn
  5457. (backward-char)
  5458. (not(verilog-at-close-constraint-p))))
  5459. (;-- constraint foo { a = b }
  5460. ;; is a complete statement. *sigh*
  5461. (= (preceding-char) ?\{)
  5462. (progn
  5463. (backward-char)
  5464. (not (verilog-at-constraint-p))))
  5465. (;" string "
  5466. (= (preceding-char) ?\")
  5467. (backward-char)
  5468. (verilog-skip-backward-comment-or-string)
  5469. nil)
  5470. (; [3:4]
  5471. (= (preceding-char) ?\])
  5472. (backward-char)
  5473. (verilog-backward-open-bracket)
  5474. t)
  5475. (;-- Could be 'case (foo)' or 'always @(bar)' which is complete
  5476. ;; also could be simply '@(foo)'
  5477. ;; or foo u1 #(a=8)
  5478. ;; (b, ... which ISN'T complete
  5479. ;; Do we need this???
  5480. (= (preceding-char) ?\))
  5481. (progn
  5482. (backward-char)
  5483. (verilog-backward-up-list 1)
  5484. (verilog-backward-syntactic-ws)
  5485. (let ((back (point)))
  5486. (forward-word -1)
  5487. (cond
  5488. ;;XX
  5489. ((looking-at "\\<\\(always\\(_latch\\|_ff\\|_comb\\)?\\|case\\(\\|[xz]\\)\\|for\\(\\|each\\|ever\\)\\|i\\(f\\|nitial\\)\\|repeat\\|while\\)\\>")
  5490. (not (looking-at "\\<randcase\\>\\|\\<case[xz]?\\>[^:]")))
  5491. ((looking-at verilog-uvm-statement-re)
  5492. nil)
  5493. ((looking-at verilog-uvm-begin-re)
  5494. t)
  5495. ((looking-at verilog-uvm-end-re)
  5496. t)
  5497. ((looking-at verilog-ovm-statement-re)
  5498. nil)
  5499. ((looking-at verilog-ovm-begin-re)
  5500. t)
  5501. ((looking-at verilog-ovm-end-re)
  5502. t)
  5503. ;; JBA find VMM macros
  5504. ((looking-at verilog-vmm-statement-re)
  5505. nil )
  5506. ((looking-at verilog-vmm-begin-re)
  5507. t)
  5508. ((looking-at verilog-vmm-end-re)
  5509. nil)
  5510. ;; JBA trying to catch macro lines with no ; at end
  5511. ((looking-at "\\<`")
  5512. nil)
  5513. (t
  5514. (goto-char back)
  5515. (cond
  5516. ((= (preceding-char) ?\@)
  5517. (backward-char)
  5518. (save-excursion
  5519. (verilog-backward-token)
  5520. (not (looking-at "\\<\\(always\\(_latch\\|_ff\\|_comb\\)?\\|initial\\|while\\)\\>"))))
  5521. ((= (preceding-char) ?\#)
  5522. (backward-char))
  5523. (t t)))))))
  5524. (;-- any of begin|initial|while are complete statements; 'begin : foo' is also complete
  5525. t
  5526. (forward-word -1)
  5527. (while (or (= (preceding-char) ?\_)
  5528. (= (preceding-char) ?\@)
  5529. (= (preceding-char) ?\.))
  5530. (forward-word -1))
  5531. (cond
  5532. ((looking-at "\\<else\\>")
  5533. t)
  5534. ((looking-at verilog-behavioral-block-beg-re)
  5535. t)
  5536. ((looking-at verilog-indent-re)
  5537. nil)
  5538. (t
  5539. (let
  5540. ((back (point)))
  5541. (verilog-backward-syntactic-ws)
  5542. (cond
  5543. ((= (preceding-char) ?\:)
  5544. (backward-char)
  5545. (verilog-backward-syntactic-ws)
  5546. (backward-sexp)
  5547. (if (looking-at verilog-nameable-item-re )
  5548. nil
  5549. t))
  5550. ((= (preceding-char) ?\#)
  5551. (backward-char)
  5552. t)
  5553. ((= (preceding-char) ?\`)
  5554. (backward-char)
  5555. t)
  5556. (t
  5557. (goto-char back)
  5558. t))))))))
  5559. (defun verilog-backward-syntactic-ws ()
  5560. "Move backwards putting point after first non-whitespace non-comment."
  5561. (verilog-skip-backward-comments)
  5562. (forward-comment (- (buffer-size))))
  5563. (defun verilog-backward-syntactic-ws-quick ()
  5564. "As with `verilog-backward-syntactic-ws' but use `verilog-scan' cache."
  5565. (while (cond ((bobp)
  5566. nil) ; Done
  5567. ((< (skip-syntax-backward " ") 0)
  5568. t)
  5569. ((eq (preceding-char) ?\n) ; \n's terminate // so aren't space syntax
  5570. (forward-char -1)
  5571. t)
  5572. ((or (verilog-inside-comment-or-string-p (1- (point)))
  5573. (verilog-inside-comment-or-string-p (point)))
  5574. (re-search-backward "[/\"]" nil t) ; Only way a comment or quote can begin
  5575. t))))
  5576. (defun verilog-forward-syntactic-ws ()
  5577. (verilog-skip-forward-comment-p)
  5578. (forward-comment (buffer-size)))
  5579. (defun verilog-backward-ws&directives (&optional bound)
  5580. "Backward skip over syntactic whitespace and compiler directives for Emacs 19.
  5581. Optional BOUND limits search."
  5582. (save-restriction
  5583. (let* ((bound (or bound (point-min)))
  5584. (here bound)
  5585. (p nil) )
  5586. (if (< bound (point))
  5587. (progn
  5588. (let ((state (save-excursion (verilog-syntax-ppss))))
  5589. (cond
  5590. ((nth 7 state) ; in // comment
  5591. (verilog-re-search-backward "//" nil 'move)
  5592. (skip-chars-backward "/"))
  5593. ((nth 4 state) ; in /* */ comment
  5594. (verilog-re-search-backward "/\\*" nil 'move))))
  5595. (narrow-to-region bound (point))
  5596. (while (/= here (point))
  5597. (setq here (point))
  5598. (verilog-skip-backward-comments)
  5599. (setq p
  5600. (save-excursion
  5601. (beginning-of-line)
  5602. ;; for as long as we're right after a continued line, keep moving up
  5603. (while (and (verilog-looking-back "\\\\[\n\r\f]" nil)
  5604. (forward-line -1)))
  5605. (cond
  5606. ((and verilog-highlight-translate-off
  5607. (verilog-within-translate-off))
  5608. (verilog-back-to-start-translate-off (point-min)))
  5609. ((looking-at verilog-directive-re-1)
  5610. (point))
  5611. (t
  5612. nil))))
  5613. (if p (goto-char p))))))))
  5614. (defun verilog-forward-ws&directives (&optional bound)
  5615. "Forward skip over syntactic whitespace and compiler directives for Emacs 19.
  5616. Optional BOUND limits search."
  5617. (save-restriction
  5618. (let* ((bound (or bound (point-max)))
  5619. (here bound)
  5620. jump)
  5621. (if (> bound (point))
  5622. (progn
  5623. (let ((state (save-excursion (verilog-syntax-ppss))))
  5624. (cond
  5625. ((nth 7 state) ; in // comment
  5626. (end-of-line)
  5627. (forward-char 1)
  5628. (skip-chars-forward " \t\n\f")
  5629. )
  5630. ((nth 4 state) ; in /* */ comment
  5631. (verilog-re-search-forward "\\*/\\s-*" nil 'move))))
  5632. (narrow-to-region (point) bound)
  5633. (while (/= here (point))
  5634. (setq here (point)
  5635. jump nil)
  5636. (forward-comment (buffer-size))
  5637. (and (looking-at "\\s-*(\\*.*\\*)\\s-*") ; Attribute
  5638. (goto-char (match-end 0)))
  5639. (save-excursion
  5640. (beginning-of-line)
  5641. (if (looking-at verilog-directive-re-1)
  5642. (setq jump t)))
  5643. (if jump
  5644. (beginning-of-line 2))))))))
  5645. (defun verilog-in-comment-p ()
  5646. "Return true if in a star or // comment."
  5647. (let ((state (save-excursion (verilog-syntax-ppss))))
  5648. (or (nth 4 state) (nth 7 state))))
  5649. (defun verilog-in-star-comment-p ()
  5650. "Return true if in a star comment."
  5651. (let ((state (save-excursion (verilog-syntax-ppss))))
  5652. (and
  5653. (nth 4 state) ; t if in a comment of style a // or b /**/
  5654. (not
  5655. (nth 7 state) ; t if in a comment of style b /**/
  5656. ))))
  5657. (defun verilog-in-slash-comment-p ()
  5658. "Return true if in a slash comment."
  5659. (let ((state (save-excursion (verilog-syntax-ppss))))
  5660. (nth 7 state)))
  5661. (defun verilog-in-comment-or-string-p ()
  5662. "Return true if in a string or comment."
  5663. (let ((state (save-excursion (verilog-syntax-ppss))))
  5664. (or (nth 3 state) (nth 4 state) (nth 7 state)))) ; Inside string or comment)
  5665. (defun verilog-in-attribute-p ()
  5666. "Return true if point is in an attribute (* [] attribute *)."
  5667. (save-match-data
  5668. (save-excursion
  5669. (verilog-re-search-backward "\\((\\*\\)\\|\\(\\*)\\)" nil 'move)
  5670. (cond
  5671. ((match-end 1)
  5672. (progn (goto-char (match-end 1))
  5673. (not (looking-at "\\s-*)")))
  5674. nil)
  5675. ((match-end 2)
  5676. (progn (goto-char (match-beginning 2))
  5677. (not (looking-at "(\\s-*")))
  5678. nil)
  5679. (t nil)))))
  5680. (defun verilog-in-parameter-p ()
  5681. "Return true if point is in a parameter assignment #( p1=1, p2=5)."
  5682. (save-match-data
  5683. (save-excursion
  5684. (verilog-re-search-backward "\\(#(\\)\\|\\()\\)" nil 'move)
  5685. (numberp (match-beginning 1)))))
  5686. (defun verilog-in-escaped-name-p ()
  5687. "Return true if in an escaped name."
  5688. (save-excursion
  5689. (backward-char)
  5690. (skip-chars-backward "^ \t\n\f")
  5691. (if (equal (char-after (point) ) ?\\ )
  5692. t
  5693. nil)))
  5694. (defun verilog-in-directive-p ()
  5695. "Return true if in a directive."
  5696. (save-excursion
  5697. (beginning-of-line)
  5698. (looking-at verilog-directive-re-1)))
  5699. (defun verilog-in-parenthesis-p ()
  5700. "Return true if in a ( ) expression (but not { } or [ ])."
  5701. (save-match-data
  5702. (save-excursion
  5703. (verilog-re-search-backward "\\((\\)\\|\\()\\)" nil 'move)
  5704. (numberp (match-beginning 1)))))
  5705. (defun verilog-in-paren ()
  5706. "Return true if in a parenthetical expression.
  5707. May cache result using `verilog-syntax-ppss'."
  5708. (let ((state (save-excursion (verilog-syntax-ppss))))
  5709. (> (nth 0 state) 0 )))
  5710. (defun verilog-in-paren-count ()
  5711. "Return paren depth, floor to 0.
  5712. May cache result using `verilog-syntax-ppss'."
  5713. (let ((state (save-excursion (verilog-syntax-ppss))))
  5714. (if (> (nth 0 state) 0)
  5715. (nth 0 state)
  5716. 0 )))
  5717. (defun verilog-in-paren-quick ()
  5718. "Return true if in a parenthetical expression.
  5719. Always starts from `point-min', to allow inserts with hooks disabled."
  5720. ;; The -quick refers to its use alongside the other -quick functions,
  5721. ;; not that it's likely to be faster than verilog-in-paren.
  5722. (let ((state (save-excursion (parse-partial-sexp (point-min) (point)))))
  5723. (> (nth 0 state) 0 )))
  5724. (defun verilog-in-struct-p ()
  5725. "Return true if in a struct declaration."
  5726. (interactive)
  5727. (save-excursion
  5728. (if (verilog-in-paren)
  5729. (progn
  5730. (verilog-backward-up-list 1)
  5731. (verilog-at-struct-p)
  5732. )
  5733. nil)))
  5734. (defun verilog-in-struct-nested-p ()
  5735. "Return nil for not in struct.
  5736. Return 0 for in non-nested struct.
  5737. Return >0 for nested struct."
  5738. (interactive)
  5739. (let (col)
  5740. (save-excursion
  5741. (if (verilog-in-paren)
  5742. (progn
  5743. (verilog-backward-up-list 1)
  5744. (setq col (verilog-at-struct-mv-p))
  5745. (if col
  5746. (if (verilog-in-struct-p) (current-column) 0)))
  5747. nil))))
  5748. (defun verilog-in-coverage-p ()
  5749. "Return true if in a constraint or coverpoint expression."
  5750. (interactive)
  5751. (save-excursion
  5752. (if (verilog-in-paren)
  5753. (progn
  5754. (verilog-backward-up-list 1)
  5755. (verilog-at-constraint-p)
  5756. )
  5757. nil)))
  5758. (defun verilog-at-close-constraint-p ()
  5759. "If at the } that closes a constraint or covergroup, return true."
  5760. (if (and
  5761. (equal (char-after) ?\})
  5762. (verilog-in-coverage-p))
  5763. (save-excursion
  5764. (verilog-backward-ws&directives)
  5765. (if (or (equal (char-before) ?\;)
  5766. (equal (char-before) ?\}) ; can end with inner constraint { } block or ;
  5767. (equal (char-before) ?\{)) ; empty constraint block
  5768. (point)
  5769. nil))))
  5770. (defun verilog-at-constraint-p ()
  5771. "If at the { of a constraint or coverpoint definition, return true, moving point to constraint."
  5772. (if (save-excursion
  5773. (let ((p (point)))
  5774. (and
  5775. (equal (char-after) ?\{)
  5776. (forward-list)
  5777. (progn (backward-char 1)
  5778. (verilog-backward-ws&directives)
  5779. (and
  5780. (or (equal (char-before) ?\{) ; empty case
  5781. (equal (char-before) ?\;)
  5782. (equal (char-before) ?\}))
  5783. ;; skip what looks like bus repetition operator {#{
  5784. (not (string-match "^{\\s-*[0-9]+\\s-*{" (buffer-substring p (point)))))))))
  5785. (progn
  5786. (let ( (pt (point)) (pass 0))
  5787. (verilog-backward-ws&directives)
  5788. (verilog-backward-token)
  5789. (if (looking-at (concat "\\<constraint\\|coverpoint\\|cross\\|with\\>\\|" verilog-in-constraint-re))
  5790. (progn (setq pass 1)
  5791. (if (looking-at "\\<with\\>")
  5792. (progn (verilog-backward-ws&directives)
  5793. (beginning-of-line) ; 1
  5794. (verilog-forward-ws&directives)
  5795. 1 )
  5796. (verilog-beg-of-statement)
  5797. ))
  5798. ;; if first word token not keyword, it maybe the instance name
  5799. ;; check next word token
  5800. (if (looking-at "\\<\\w+\\>\\|\\s-*(\\s-*\\S-+")
  5801. (progn (verilog-beg-of-statement)
  5802. (if (looking-at (concat "\\<\\(constraint\\|"
  5803. "\\(?:\\w+\\s-*:\\s-*\\)?\\(coverpoint\\|cross\\)"
  5804. "\\|with\\)\\>\\|" verilog-in-constraint-re))
  5805. (setq pass 1)))))
  5806. (if (eq pass 0)
  5807. (progn (goto-char pt) nil) 1)))
  5808. ;; not
  5809. nil))
  5810. (defun verilog-at-struct-p ()
  5811. "If at the { of a struct, return true, not moving point."
  5812. (save-excursion
  5813. (if (and (equal (char-after) ?\{)
  5814. (verilog-backward-token))
  5815. (looking-at "\\<struct\\|union\\|packed\\|\\(un\\)?signed\\>")
  5816. nil)))
  5817. (defun verilog-at-struct-mv-p ()
  5818. "If at the { of a struct, return true, moving point to struct."
  5819. (let ((pt (point)))
  5820. (if (and (equal (char-after) ?\{)
  5821. (verilog-backward-token))
  5822. (if (looking-at "\\<struct\\|union\\|packed\\|\\(un\\)?signed\\>")
  5823. (progn (verilog-beg-of-statement) (point))
  5824. (progn (goto-char pt) nil))
  5825. (progn (goto-char pt) nil))))
  5826. (defun verilog-at-close-struct-p ()
  5827. "If at the } that closes a struct, return true."
  5828. (if (and
  5829. (equal (char-after) ?\})
  5830. (verilog-in-struct-p))
  5831. ;; true
  5832. (save-excursion
  5833. (if (looking-at "}\\(?:\\s-*\\w+\\s-*\\)?;") 1))
  5834. ;; false
  5835. nil))
  5836. (defun verilog-parenthesis-depth ()
  5837. "Return non zero if in parenthetical-expression."
  5838. (save-excursion (nth 1 (verilog-syntax-ppss))))
  5839. (defun verilog-skip-forward-comment-or-string ()
  5840. "Return true if in a string or comment."
  5841. (let ((state (save-excursion (verilog-syntax-ppss))))
  5842. (cond
  5843. ((nth 3 state) ;Inside string
  5844. (search-forward "\"")
  5845. t)
  5846. ((nth 7 state) ;Inside // comment
  5847. (forward-line 1)
  5848. t)
  5849. ((nth 4 state) ;Inside any comment (hence /**/)
  5850. (search-forward "*/"))
  5851. (t
  5852. nil))))
  5853. (defun verilog-skip-backward-comment-or-string ()
  5854. "Return true if in a string or comment."
  5855. (let ((state (save-excursion (verilog-syntax-ppss))))
  5856. (cond
  5857. ((nth 3 state) ;Inside string
  5858. (search-backward "\"")
  5859. t)
  5860. ((nth 7 state) ;Inside // comment
  5861. (search-backward "//")
  5862. (skip-chars-backward "/")
  5863. t)
  5864. ((nth 4 state) ;Inside /* */ comment
  5865. (search-backward "/*")
  5866. t)
  5867. (t
  5868. nil))))
  5869. (defun verilog-skip-backward-comments ()
  5870. "Return true if a comment was skipped."
  5871. (let ((more t))
  5872. (while more
  5873. (setq more
  5874. (let ((state (save-excursion (verilog-syntax-ppss))))
  5875. (cond
  5876. ((nth 7 state) ;Inside // comment
  5877. (search-backward "//")
  5878. (skip-chars-backward "/")
  5879. (skip-chars-backward " \t\n\f")
  5880. t)
  5881. ((nth 4 state) ;Inside /* */ comment
  5882. (search-backward "/*")
  5883. (skip-chars-backward " \t\n\f")
  5884. t)
  5885. ((and (not (bobp))
  5886. (= (char-before) ?\/)
  5887. (= (char-before (1- (point))) ?\*))
  5888. (goto-char (- (point) 2))
  5889. t) ; Let nth 4 state handle the rest
  5890. ((and (not (bobp))
  5891. ;;(verilog-looking-back "\\*)" nil) ;; super slow, use two char-before instead
  5892. (= (char-before) ?\))
  5893. (= (char-before (1- (point))) ?\*)
  5894. (not (verilog-looking-back "(\\s-*\\*)" nil))) ;; slow but unlikely to be called
  5895. (goto-char (- (point) 2))
  5896. (if (search-backward "(*" nil t)
  5897. (progn
  5898. (skip-chars-backward " \t\n\f")
  5899. t)
  5900. (progn
  5901. (goto-char (+ (point) 2))
  5902. nil)))
  5903. (t
  5904. (/= (skip-chars-backward " \t\n\f") 0))))))))
  5905. (defun verilog-skip-forward-comment-p ()
  5906. "If in comment, move to end and return true."
  5907. (let* (h
  5908. (state (save-excursion (verilog-syntax-ppss)))
  5909. (skip (cond
  5910. ((nth 3 state) ;Inside string
  5911. t)
  5912. ((nth 7 state) ;Inside // comment
  5913. (end-of-line)
  5914. (forward-char 1)
  5915. t)
  5916. ((nth 4 state) ;Inside /* comment
  5917. (search-forward "*/")
  5918. t)
  5919. ((verilog-in-attribute-p) ;Inside (* attribute
  5920. (search-forward "*)" nil t)
  5921. t)
  5922. (t nil))))
  5923. (skip-chars-forward " \t\n\f")
  5924. (while
  5925. (cond
  5926. ((looking-at "\\/\\*")
  5927. (progn
  5928. (setq h (point))
  5929. (goto-char (match-end 0))
  5930. (if (search-forward "*/" nil t)
  5931. (progn
  5932. (skip-chars-forward " \t\n\f")
  5933. (setq skip 't))
  5934. (progn
  5935. (goto-char h)
  5936. nil))))
  5937. ((and (looking-at "(\\*") ; attribute start, but not an event (*) or (* )
  5938. (not (looking-at "(\\*\\s-*)")))
  5939. (progn
  5940. (setq h (point))
  5941. (goto-char (match-end 0))
  5942. (if (search-forward "*)" nil t)
  5943. (progn
  5944. (skip-chars-forward " \t\n\f")
  5945. (setq skip 't))
  5946. (progn
  5947. (goto-char h)
  5948. nil))))
  5949. (t nil)))
  5950. skip))
  5951. (defun verilog-indent-line-relative ()
  5952. "Cheap version of indent line.
  5953. Only look at a few lines to determine indent level."
  5954. (interactive)
  5955. (let ((indent-str)
  5956. (sp (point)))
  5957. (if (looking-at "^[ \t]*$")
  5958. (cond ;- A blank line; No need to be too smart.
  5959. ((bobp)
  5960. (setq indent-str (list 'cpp 0)))
  5961. ((verilog-continued-line)
  5962. (let ((sp1 (point)))
  5963. (if (verilog-continued-line)
  5964. (progn
  5965. (goto-char sp)
  5966. (setq indent-str
  5967. (list 'statement (verilog-current-indent-level))))
  5968. (goto-char sp1)
  5969. (setq indent-str (list 'block (verilog-current-indent-level)))))
  5970. (goto-char sp))
  5971. ((goto-char sp)
  5972. (setq indent-str (verilog-calculate-indent))))
  5973. (progn (skip-chars-forward " \t")
  5974. (setq indent-str (verilog-calculate-indent))))
  5975. (verilog-do-indent indent-str)))
  5976. (defun verilog-indent-line ()
  5977. "Indent for special part of code."
  5978. (verilog-do-indent (verilog-calculate-indent)))
  5979. (defun verilog-do-indent (indent-str)
  5980. (let ((type (car indent-str))
  5981. (ind (car (cdr indent-str))))
  5982. (cond
  5983. (; handle continued exp
  5984. (eq type 'cexp)
  5985. (let ((here (point)))
  5986. (verilog-backward-syntactic-ws)
  5987. (cond
  5988. ((or
  5989. (= (preceding-char) ?\,)
  5990. (save-excursion
  5991. (verilog-beg-of-statement-1)
  5992. (looking-at verilog-declaration-re)))
  5993. (let* ( fst
  5994. (val
  5995. (save-excursion
  5996. (backward-char 1)
  5997. (verilog-beg-of-statement-1)
  5998. (setq fst (point))
  5999. (if (looking-at verilog-declaration-re)
  6000. (progn ; we have multiple words
  6001. (goto-char (match-end 0))
  6002. (skip-chars-forward " \t")
  6003. (cond
  6004. ((and verilog-indent-declaration-macros
  6005. (= (following-char) ?\`))
  6006. (progn
  6007. (forward-char 1)
  6008. (forward-word 1)
  6009. (skip-chars-forward " \t")))
  6010. ((= (following-char) ?\[)
  6011. (progn
  6012. (forward-char 1)
  6013. (verilog-backward-up-list -1)
  6014. (skip-chars-forward " \t"))))
  6015. (current-column))
  6016. (progn
  6017. (goto-char fst)
  6018. (+ (current-column) verilog-cexp-indent))))))
  6019. (goto-char here)
  6020. (indent-line-to val)
  6021. (if (and (not verilog-indent-lists)
  6022. (verilog-in-paren))
  6023. (verilog-pretty-declarations-auto))
  6024. ))
  6025. ((= (preceding-char) ?\) )
  6026. (goto-char here)
  6027. (let ((val (eval (cdr (assoc type verilog-indent-alist)))))
  6028. (indent-line-to val)))
  6029. (t
  6030. (goto-char here)
  6031. (let ((val))
  6032. (verilog-beg-of-statement-1)
  6033. (if (and (< (point) here)
  6034. (verilog-re-search-forward "=[ \\t]*" here 'move)
  6035. ;; not at a |=>, #=#, or [=n] operator
  6036. (not (string-match "\\[=.\\|#=#\\||=>"
  6037. (or (buffer-substring (- (point) 2) (1+ (point)))
  6038. "")))) ; don't let buffer over/under-run spoil the party
  6039. (setq val (current-column))
  6040. (setq val (eval (cdr (assoc type verilog-indent-alist)))))
  6041. (goto-char here)
  6042. (indent-line-to val))))))
  6043. (; handle inside parenthetical expressions
  6044. (eq type 'cparenexp)
  6045. (let* ( here
  6046. (val (save-excursion
  6047. (verilog-backward-up-list 1)
  6048. (forward-char 1)
  6049. (if verilog-indent-lists
  6050. (skip-chars-forward " \t")
  6051. (verilog-forward-syntactic-ws))
  6052. (setq here (point))
  6053. (current-column)))
  6054. (decl (save-excursion
  6055. (goto-char here)
  6056. (verilog-forward-syntactic-ws)
  6057. (setq here (point))
  6058. (looking-at verilog-declaration-re))))
  6059. (indent-line-to val)
  6060. (if decl
  6061. (verilog-pretty-declarations-auto))))
  6062. (;-- Handle the ends
  6063. (or
  6064. (looking-at verilog-end-block-re)
  6065. (verilog-at-close-constraint-p)
  6066. (verilog-at-close-struct-p))
  6067. (let ((val (if (eq type 'statement)
  6068. (- ind verilog-indent-level)
  6069. ind)))
  6070. (indent-line-to val)))
  6071. (;-- Case -- maybe line 'em up
  6072. (and (eq type 'case) (not (looking-at "^[ \t]*$")))
  6073. (progn
  6074. (cond
  6075. ((looking-at "\\<endcase\\>")
  6076. (indent-line-to ind))
  6077. (t
  6078. (let ((val (eval (cdr (assoc type verilog-indent-alist)))))
  6079. (indent-line-to val))))))
  6080. (;-- defun
  6081. (and (eq type 'defun)
  6082. (looking-at verilog-zero-indent-re))
  6083. (indent-line-to 0))
  6084. (;-- declaration
  6085. (and (or
  6086. (eq type 'defun)
  6087. (eq type 'block))
  6088. (looking-at verilog-declaration-re)
  6089. ;; Do not consider "virtual function", "virtual task", "virtual class"
  6090. ;; as declarations
  6091. (not (looking-at (concat verilog-declaration-re
  6092. "\\s-+\\(function\\|task\\|class\\)\\b"))))
  6093. (verilog-indent-declaration ind))
  6094. (;-- form feeds - ignored as bug in indent-line-to in < 24.5
  6095. (looking-at "\f"))
  6096. (;-- Everything else
  6097. t
  6098. (let ((val (eval (cdr (assoc type verilog-indent-alist)))))
  6099. (indent-line-to val))))
  6100. (if (looking-at "[ \t]+$")
  6101. (skip-chars-forward " \t"))
  6102. indent-str ; Return indent data
  6103. ))
  6104. (defun verilog-current-indent-level ()
  6105. "Return the indent-level of the current statement."
  6106. (save-excursion
  6107. (let (par-pos)
  6108. (beginning-of-line)
  6109. (setq par-pos (verilog-parenthesis-depth))
  6110. (while par-pos
  6111. (goto-char par-pos)
  6112. (beginning-of-line)
  6113. (setq par-pos (verilog-parenthesis-depth)))
  6114. (skip-chars-forward " \t")
  6115. (current-column))))
  6116. (defun verilog-case-indent-level ()
  6117. "Return the indent-level of the current statement.
  6118. Do not count named blocks or case-statements."
  6119. (save-excursion
  6120. (skip-chars-forward " \t")
  6121. (cond
  6122. ((looking-at verilog-named-block-re)
  6123. (current-column))
  6124. ((and (not (looking-at verilog-extended-case-re))
  6125. (looking-at "^[^:;]+[ \t]*:"))
  6126. (verilog-re-search-forward ":" nil t)
  6127. (skip-chars-forward " \t")
  6128. (current-column))
  6129. (t
  6130. (current-column)))))
  6131. (defun verilog-indent-comment ()
  6132. "Indent current line as comment."
  6133. (let* ((stcol
  6134. (cond
  6135. ((verilog-in-star-comment-p)
  6136. (save-excursion
  6137. (re-search-backward "/\\*" nil t)
  6138. (1+(current-column))))
  6139. (comment-column
  6140. comment-column )
  6141. (t
  6142. (save-excursion
  6143. (re-search-backward "//" nil t)
  6144. (current-column))))))
  6145. (indent-line-to stcol)
  6146. stcol))
  6147. (defun verilog-more-comment ()
  6148. "Make more comment lines like the previous."
  6149. (let* ((star 0)
  6150. (stcol
  6151. (cond
  6152. ((verilog-in-star-comment-p)
  6153. (save-excursion
  6154. (setq star 1)
  6155. (re-search-backward "/\\*" nil t)
  6156. (1+(current-column))))
  6157. (comment-column
  6158. comment-column )
  6159. (t
  6160. (save-excursion
  6161. (re-search-backward "//" nil t)
  6162. (current-column))))))
  6163. (progn
  6164. (indent-to stcol)
  6165. (if (and star
  6166. (save-excursion
  6167. (forward-line -1)
  6168. (skip-chars-forward " \t")
  6169. (looking-at "\\*")))
  6170. (insert "* ")))))
  6171. (defun verilog-comment-indent (&optional _arg)
  6172. "Return the column number the line should be indented to.
  6173. _ARG is ignored, for `comment-indent-function' compatibility."
  6174. (cond
  6175. ((verilog-in-star-comment-p)
  6176. (save-excursion
  6177. (re-search-backward "/\\*" nil t)
  6178. (1+(current-column))))
  6179. ( comment-column
  6180. comment-column )
  6181. (t
  6182. (save-excursion
  6183. (re-search-backward "//" nil t)
  6184. (current-column)))))
  6185. ;;
  6186. (defun verilog-pretty-declarations-auto (&optional quiet)
  6187. "Call `verilog-pretty-declarations' QUIET based on `verilog-auto-lineup'."
  6188. (when (or (eq 'all verilog-auto-lineup)
  6189. (eq 'declarations verilog-auto-lineup))
  6190. (verilog-pretty-declarations quiet)))
  6191. (defun verilog-pretty-declarations (&optional quiet)
  6192. "Line up declarations around point.
  6193. Be verbose about progress unless optional QUIET set."
  6194. (interactive)
  6195. (let* ((m1 (make-marker))
  6196. (e (point))
  6197. el
  6198. r
  6199. (here (point))
  6200. ind
  6201. start
  6202. startpos
  6203. end
  6204. endpos
  6205. base-ind
  6206. )
  6207. (save-excursion
  6208. (if (progn
  6209. ;; (verilog-beg-of-statement-1)
  6210. (beginning-of-line)
  6211. (verilog-forward-syntactic-ws)
  6212. (and (not (verilog-in-directive-p)) ; could have `define input foo
  6213. (looking-at verilog-declaration-re)))
  6214. (progn
  6215. (if (verilog-parenthesis-depth)
  6216. ;; in an argument list or parameter block
  6217. (setq el (verilog-backward-up-list -1)
  6218. start (progn
  6219. (goto-char e)
  6220. (verilog-backward-up-list 1)
  6221. (forward-line) ; ignore ( input foo,
  6222. (verilog-re-search-forward verilog-declaration-re el 'move)
  6223. (goto-char (match-beginning 0))
  6224. (skip-chars-backward " \t")
  6225. (point))
  6226. startpos (set-marker (make-marker) start)
  6227. end (progn
  6228. (goto-char start)
  6229. (verilog-backward-up-list -1)
  6230. (forward-char -1)
  6231. (verilog-backward-syntactic-ws)
  6232. (point))
  6233. endpos (set-marker (make-marker) end)
  6234. base-ind (progn
  6235. (goto-char start)
  6236. (forward-char 1)
  6237. (skip-chars-forward " \t")
  6238. (current-column)))
  6239. ;; in a declaration block (not in argument list)
  6240. (setq
  6241. start (progn
  6242. (verilog-beg-of-statement-1)
  6243. (while (and (looking-at verilog-declaration-re)
  6244. (not (bobp)))
  6245. (skip-chars-backward " \t")
  6246. (setq e (point))
  6247. (beginning-of-line)
  6248. (verilog-backward-syntactic-ws)
  6249. (backward-char)
  6250. (verilog-beg-of-statement-1))
  6251. e)
  6252. startpos (set-marker (make-marker) start)
  6253. end (progn
  6254. (goto-char here)
  6255. (verilog-end-of-statement)
  6256. (setq e (point)) ;Might be on last line
  6257. (verilog-forward-syntactic-ws)
  6258. (while (looking-at verilog-declaration-re)
  6259. (verilog-end-of-statement)
  6260. (setq e (point))
  6261. (verilog-forward-syntactic-ws))
  6262. e)
  6263. endpos (set-marker (make-marker) end)
  6264. base-ind (progn
  6265. (goto-char start)
  6266. (verilog-do-indent (verilog-calculate-indent))
  6267. (verilog-forward-ws&directives)
  6268. (current-column))))
  6269. ;; OK, start and end are set
  6270. (goto-char (marker-position startpos))
  6271. (if (and (not quiet)
  6272. (> (- end start) 100))
  6273. (message "Lining up declarations..(please stand by)"))
  6274. ;; Get the beginning of line indent first
  6275. (while (progn (setq e (marker-position endpos))
  6276. (< (point) e))
  6277. (cond
  6278. ((save-excursion (skip-chars-backward " \t")
  6279. (bolp))
  6280. (verilog-forward-ws&directives)
  6281. (indent-line-to base-ind)
  6282. (verilog-forward-ws&directives)
  6283. (if (< (point) e)
  6284. (verilog-re-search-forward "[ \t\n\f]" e 'move)))
  6285. (t
  6286. (just-one-space)
  6287. (verilog-re-search-forward "[ \t\n\f]" e 'move)))
  6288. ;;(forward-line)
  6289. )
  6290. ;; Now find biggest prefix
  6291. (setq ind (verilog-get-lineup-indent (marker-position startpos) endpos))
  6292. ;; Now indent each line.
  6293. (goto-char (marker-position startpos))
  6294. (while (progn (setq e (marker-position endpos))
  6295. (setq r (- e (point)))
  6296. (> r 0))
  6297. (setq e (point))
  6298. (unless quiet (message "%d" r))
  6299. ;; (verilog-do-indent (verilog-calculate-indent)))
  6300. (verilog-forward-ws&directives)
  6301. (cond
  6302. ((or (and verilog-indent-declaration-macros
  6303. (looking-at verilog-declaration-re-2-macro))
  6304. (looking-at verilog-declaration-re-2-no-macro))
  6305. (let ((p (match-end 0)))
  6306. (set-marker m1 p)
  6307. (if (verilog-re-search-forward "[[#`]" p 'move)
  6308. (progn
  6309. (forward-char -1)
  6310. (just-one-space)
  6311. (goto-char (marker-position m1))
  6312. (just-one-space)
  6313. (indent-to ind))
  6314. (progn
  6315. (just-one-space)
  6316. (indent-to ind)))))
  6317. ((verilog-continued-line-1 (marker-position startpos))
  6318. (goto-char e)
  6319. (indent-line-to ind))
  6320. ((verilog-in-struct-p)
  6321. ;; could have a declaration of a user defined item
  6322. (goto-char e)
  6323. (verilog-end-of-statement))
  6324. (t ; Must be comment or white space
  6325. (goto-char e)
  6326. (verilog-forward-ws&directives)
  6327. (forward-line -1)))
  6328. (forward-line 1))
  6329. (unless quiet (message "")))))))
  6330. (defun verilog-pretty-expr (&optional quiet _myre)
  6331. "Line up expressions around point, optionally QUIET with regexp _MYRE ignored."
  6332. (interactive)
  6333. (if (not (verilog-in-comment-or-string-p))
  6334. (save-excursion
  6335. (let ( (rexp (concat "^\\s-*" verilog-complete-reg))
  6336. (rexp1 (concat "^\\s-*" verilog-basic-complete-re)))
  6337. (beginning-of-line)
  6338. (if (and (not (looking-at rexp ))
  6339. (looking-at verilog-assignment-operation-re)
  6340. (save-excursion
  6341. (goto-char (match-end 2))
  6342. (and (not (verilog-in-attribute-p))
  6343. (not (verilog-in-parameter-p))
  6344. (not (verilog-in-comment-or-string-p)))))
  6345. (let* ((here (point))
  6346. (e) (r)
  6347. (start
  6348. (progn
  6349. (beginning-of-line)
  6350. (setq e (point))
  6351. (verilog-backward-syntactic-ws)
  6352. (beginning-of-line)
  6353. (while (and (not (looking-at rexp1))
  6354. (looking-at verilog-assignment-operation-re)
  6355. (not (bobp))
  6356. )
  6357. (setq e (point))
  6358. (verilog-backward-syntactic-ws)
  6359. (beginning-of-line)
  6360. ) ;Ack, need to grok `define
  6361. e))
  6362. (end
  6363. (progn
  6364. (goto-char here)
  6365. (end-of-line)
  6366. (setq e (point)) ;Might be on last line
  6367. (verilog-forward-syntactic-ws)
  6368. (beginning-of-line)
  6369. (while (and
  6370. (not (looking-at rexp1 ))
  6371. (looking-at verilog-assignment-operation-re)
  6372. (progn
  6373. (end-of-line)
  6374. (not (eq e (point)))))
  6375. (setq e (point))
  6376. (verilog-forward-syntactic-ws)
  6377. (beginning-of-line)
  6378. )
  6379. e))
  6380. (endpos (set-marker (make-marker) end))
  6381. (ind)
  6382. )
  6383. (goto-char start)
  6384. (verilog-do-indent (verilog-calculate-indent))
  6385. (if (and (not quiet)
  6386. (> (- end start) 100))
  6387. (message "Lining up expressions..(please stand by)"))
  6388. ;; Set indent to minimum throughout region
  6389. (while (< (point) (marker-position endpos))
  6390. (beginning-of-line)
  6391. (verilog-just-one-space verilog-assignment-operation-re)
  6392. (beginning-of-line)
  6393. (verilog-do-indent (verilog-calculate-indent))
  6394. (end-of-line)
  6395. (verilog-forward-syntactic-ws)
  6396. )
  6397. ;; Now find biggest prefix
  6398. (setq ind (verilog-get-lineup-indent-2 verilog-assignment-operation-re start endpos))
  6399. ;; Now indent each line.
  6400. (goto-char start)
  6401. (while (progn (setq e (marker-position endpos))
  6402. (setq r (- e (point)))
  6403. (> r 0))
  6404. (setq e (point))
  6405. (if (not quiet) (message "%d" r))
  6406. (cond
  6407. ((looking-at verilog-assignment-operation-re)
  6408. (goto-char (match-beginning 2))
  6409. (if (not (or (verilog-in-parenthesis-p) ; leave attributes and comparisons alone
  6410. (verilog-in-coverage-p)))
  6411. (if (eq (char-after) ?=)
  6412. (indent-to (1+ ind)) ; line up the = of the <= with surrounding =
  6413. (indent-to ind)
  6414. ))
  6415. )
  6416. ((verilog-continued-line-1 start)
  6417. (goto-char e)
  6418. (indent-line-to ind))
  6419. (t ; Must be comment or white space
  6420. (goto-char e)
  6421. (verilog-forward-ws&directives)
  6422. (forward-line -1))
  6423. )
  6424. (forward-line 1))
  6425. (unless quiet (message ""))
  6426. ))))))
  6427. (defun verilog-just-one-space (myre)
  6428. "Remove extra spaces around regular expression MYRE."
  6429. (interactive)
  6430. (if (and (not(looking-at verilog-complete-reg))
  6431. (looking-at myre))
  6432. (let ((p1 (match-end 1))
  6433. (p2 (match-end 2)))
  6434. (progn
  6435. (goto-char p2)
  6436. (just-one-space)
  6437. (goto-char p1)
  6438. (just-one-space)))))
  6439. (defun verilog-indent-declaration (baseind)
  6440. "Indent current lines as declaration.
  6441. Line up the variable names based on previous declaration's indentation.
  6442. BASEIND is the base indent to offset everything."
  6443. (interactive)
  6444. (let ((pos (point-marker))
  6445. (lim (save-excursion
  6446. ;; (verilog-re-search-backward verilog-declaration-opener nil 'move)
  6447. (verilog-re-search-backward "\\(\\<begin\\>\\)\\|\\(\\<module\\>\\)\\|\\(\\<task\\>\\)" nil 'move)
  6448. (point)))
  6449. (ind)
  6450. (val)
  6451. (m1 (make-marker)))
  6452. (setq val
  6453. (+ baseind (eval (cdr (assoc 'declaration verilog-indent-alist)))))
  6454. (indent-line-to val)
  6455. ;; Use previous declaration (in this module) as template.
  6456. (if (or (eq 'all verilog-auto-lineup)
  6457. (eq 'declarations verilog-auto-lineup))
  6458. (if (verilog-re-search-backward
  6459. (or (and verilog-indent-declaration-macros
  6460. verilog-declaration-re-1-macro)
  6461. verilog-declaration-re-1-no-macro) lim t)
  6462. (progn
  6463. (goto-char (match-end 0))
  6464. (skip-chars-forward " \t")
  6465. (setq ind (current-column))
  6466. (goto-char pos)
  6467. (setq val
  6468. (+ baseind
  6469. (eval (cdr (assoc 'declaration verilog-indent-alist)))))
  6470. (indent-line-to val)
  6471. (if (and verilog-indent-declaration-macros
  6472. (looking-at verilog-declaration-re-2-macro))
  6473. (let ((p (match-end 0)))
  6474. (set-marker m1 p)
  6475. (if (verilog-re-search-forward "[[#`]" p 'move)
  6476. (progn
  6477. (forward-char -1)
  6478. (just-one-space)
  6479. (goto-char (marker-position m1))
  6480. (just-one-space)
  6481. (indent-to ind))
  6482. (if (/= (current-column) ind)
  6483. (progn
  6484. (just-one-space)
  6485. (indent-to ind)))))
  6486. (if (looking-at verilog-declaration-re-2-no-macro)
  6487. (let ((p (match-end 0)))
  6488. (set-marker m1 p)
  6489. (if (verilog-re-search-forward "[[`#]" p 'move)
  6490. (progn
  6491. (forward-char -1)
  6492. (just-one-space)
  6493. (goto-char (marker-position m1))
  6494. (just-one-space)
  6495. (indent-to ind))
  6496. (if (/= (current-column) ind)
  6497. (progn
  6498. (just-one-space)
  6499. (indent-to ind))))))))))
  6500. (goto-char pos)))
  6501. (defun verilog-get-lineup-indent (b edpos)
  6502. "Return the indent level that will line up several lines within the region.
  6503. Region is defined by B and EDPOS."
  6504. (save-excursion
  6505. (let ((ind 0) e)
  6506. (goto-char b)
  6507. ;; Get rightmost position
  6508. (while (progn (setq e (marker-position edpos))
  6509. (< (point) e))
  6510. (if (verilog-re-search-forward
  6511. (or (and verilog-indent-declaration-macros
  6512. verilog-declaration-re-1-macro)
  6513. verilog-declaration-re-1-no-macro) e 'move)
  6514. (progn
  6515. (goto-char (match-end 0))
  6516. (verilog-backward-syntactic-ws)
  6517. (if (> (current-column) ind)
  6518. (setq ind (current-column)))
  6519. (goto-char (match-end 0)))))
  6520. (if (> ind 0)
  6521. (1+ ind)
  6522. ;; No lineup-string found
  6523. (goto-char b)
  6524. (end-of-line)
  6525. (verilog-backward-syntactic-ws)
  6526. ;;(skip-chars-backward " \t")
  6527. (1+ (current-column))))))
  6528. (defun verilog-get-lineup-indent-2 (myre b edpos)
  6529. "Return the indent level that will line up several lines within the region."
  6530. (save-excursion
  6531. (let ((ind 0) e)
  6532. (goto-char b)
  6533. ;; Get rightmost position
  6534. (while (progn (setq e (marker-position edpos))
  6535. (< (point) e))
  6536. (if (and (verilog-re-search-forward myre e 'move)
  6537. (not (verilog-in-attribute-p))) ; skip attribute exprs
  6538. (progn
  6539. (goto-char (match-beginning 2))
  6540. (verilog-backward-syntactic-ws)
  6541. (if (> (current-column) ind)
  6542. (setq ind (current-column)))
  6543. (goto-char (match-end 0)))
  6544. ))
  6545. (if (> ind 0)
  6546. (1+ ind)
  6547. ;; No lineup-string found
  6548. (goto-char b)
  6549. (end-of-line)
  6550. (skip-chars-backward " \t")
  6551. (1+ (current-column))))))
  6552. (defun verilog-comment-depth (type val)
  6553. "A useful mode debugging aide. TYPE and VAL are comments for insertion."
  6554. (save-excursion
  6555. (let
  6556. ((b (prog2
  6557. (beginning-of-line)
  6558. (point-marker)
  6559. (end-of-line))))
  6560. (if (re-search-backward " /\\* [#-]# [a-zA-Z]+ [0-9]+ ## \\*/" b t)
  6561. (progn
  6562. (replace-match " /* -# ## */")
  6563. (end-of-line))
  6564. (progn
  6565. (end-of-line)
  6566. (insert " /* ## ## */"))))
  6567. (backward-char 6)
  6568. (insert
  6569. (format "%s %d" type val))))
  6570. ;;; Completion:
  6571. ;;
  6572. (defvar verilog-str nil)
  6573. (defvar verilog-all nil)
  6574. (defvar verilog-pred nil)
  6575. (defvar verilog-buffer-to-use nil)
  6576. (defvar verilog-flag nil)
  6577. (defvar verilog-toggle-completions nil
  6578. "True means \\<verilog-mode-map>\\[verilog-complete-word] should try all possible completions one by one.
  6579. Repeated use of \\[verilog-complete-word] will show you all of them.
  6580. Normally, when there is more than one possible completion,
  6581. it displays a list of all possible completions.")
  6582. (defvar verilog-type-keywords
  6583. '(
  6584. "and" "buf" "bufif0" "bufif1" "cmos" "defparam" "inout" "input"
  6585. "integer" "localparam" "logic" "mailbox" "nand" "nmos" "nor" "not" "notif0"
  6586. "notif1" "or" "output" "parameter" "pmos" "pull0" "pull1" "pulldown" "pullup"
  6587. "rcmos" "real" "realtime" "reg" "rnmos" "rpmos" "rtran" "rtranif0"
  6588. "rtranif1" "semaphore" "time" "tran" "tranif0" "tranif1" "tri" "tri0" "tri1"
  6589. "triand" "trior" "trireg" "wand" "wire" "wor" "xnor" "xor"
  6590. )
  6591. "Keywords for types used when completing a word in a declaration or parmlist.
  6592. \(integer, real, reg...)")
  6593. (defvar verilog-cpp-keywords
  6594. '("module" "macromodule" "primitive" "timescale" "define" "ifdef" "ifndef" "else"
  6595. "endif")
  6596. "Keywords to complete when at first word of a line in declarative scope.
  6597. \(initial, always, begin, assign...)
  6598. The procedures and variables defined within the Verilog program
  6599. will be completed at runtime and should not be added to this list.")
  6600. (defvar verilog-defun-keywords
  6601. (append
  6602. '(
  6603. "always" "always_comb" "always_ff" "always_latch" "assign"
  6604. "begin" "end" "generate" "endgenerate" "module" "endmodule"
  6605. "specify" "endspecify" "function" "endfunction" "initial" "final"
  6606. "task" "endtask" "primitive" "endprimitive"
  6607. )
  6608. verilog-type-keywords)
  6609. "Keywords to complete when at first word of a line in declarative scope.
  6610. \(initial, always, begin, assign...)
  6611. The procedures and variables defined within the Verilog program
  6612. will be completed at runtime and should not be added to this list.")
  6613. (defvar verilog-block-keywords
  6614. '(
  6615. "begin" "break" "case" "continue" "else" "end" "endfunction"
  6616. "endgenerate" "endinterface" "endpackage" "endspecify" "endtask"
  6617. "for" "fork" "if" "join" "join_any" "join_none" "repeat" "return"
  6618. "while")
  6619. "Keywords to complete when at first word of a line in behavioral scope.
  6620. \(begin, if, then, else, for, fork...)
  6621. The procedures and variables defined within the Verilog program
  6622. will be completed at runtime and should not be added to this list.")
  6623. (defvar verilog-tf-keywords
  6624. '("begin" "break" "fork" "join" "join_any" "join_none" "case" "end" "endtask" "endfunction" "if" "else" "for" "while" "repeat")
  6625. "Keywords to complete when at first word of a line in a task or function.
  6626. \(begin, if, then, else, for, fork.)
  6627. The procedures and variables defined within the Verilog program
  6628. will be completed at runtime and should not be added to this list.")
  6629. (defvar verilog-case-keywords
  6630. '("begin" "fork" "join" "join_any" "join_none" "case" "end" "endcase" "if" "else" "for" "repeat")
  6631. "Keywords to complete when at first word of a line in case scope.
  6632. \(begin, if, then, else, for, fork...)
  6633. The procedures and variables defined within the Verilog program
  6634. will be completed at runtime and should not be added to this list.")
  6635. (defvar verilog-separator-keywords
  6636. '("else" "then" "begin")
  6637. "Keywords to complete when NOT standing at the first word of a statement.
  6638. \(else, then, begin...)
  6639. Variables and function names defined within the Verilog program
  6640. will be completed at runtime and should not be added to this list.")
  6641. (defvar verilog-gate-ios
  6642. ;; All these have an implied {"input"...} at the end
  6643. '(("and" "output")
  6644. ("buf" "output")
  6645. ("bufif0" "output")
  6646. ("bufif1" "output")
  6647. ("cmos" "output")
  6648. ("nand" "output")
  6649. ("nmos" "output")
  6650. ("nor" "output")
  6651. ("not" "output")
  6652. ("notif0" "output")
  6653. ("notif1" "output")
  6654. ("or" "output")
  6655. ("pmos" "output")
  6656. ("pulldown" "output")
  6657. ("pullup" "output")
  6658. ("rcmos" "output")
  6659. ("rnmos" "output")
  6660. ("rpmos" "output")
  6661. ("rtran" "inout" "inout")
  6662. ("rtranif0" "inout" "inout")
  6663. ("rtranif1" "inout" "inout")
  6664. ("tran" "inout" "inout")
  6665. ("tranif0" "inout" "inout")
  6666. ("tranif1" "inout" "inout")
  6667. ("xnor" "output")
  6668. ("xor" "output"))
  6669. "Map of direction for each positional argument to each gate primitive.")
  6670. (defvar verilog-gate-keywords (mapcar `car verilog-gate-ios)
  6671. "Keywords for gate primitives.")
  6672. (defun verilog-string-diff (str1 str2)
  6673. "Return index of first letter where STR1 and STR2 differs."
  6674. (catch 'done
  6675. (let ((diff 0))
  6676. (while t
  6677. (if (or (> (1+ diff) (length str1))
  6678. (> (1+ diff) (length str2)))
  6679. (throw 'done diff))
  6680. (or (equal (aref str1 diff) (aref str2 diff))
  6681. (throw 'done diff))
  6682. (setq diff (1+ diff))))))
  6683. ;; Calculate all possible completions for functions if argument is `function',
  6684. ;; completions for procedures if argument is `procedure' or both functions and
  6685. ;; procedures otherwise.
  6686. (defun verilog-func-completion (type)
  6687. "Build regular expression for module/task/function names.
  6688. TYPE is `module', `tf' for task or function, or t if unknown."
  6689. (if (string= verilog-str "")
  6690. (setq verilog-str "[a-zA-Z_]"))
  6691. (let ((verilog-str (concat (cond
  6692. ((eq type 'module) "\\<\\(module\\)\\s +")
  6693. ((eq type 'tf) "\\<\\(task\\|function\\)\\s +")
  6694. (t "\\<\\(task\\|function\\|module\\)\\s +"))
  6695. "\\<\\(" verilog-str "[a-zA-Z0-9_.]*\\)\\>"))
  6696. match)
  6697. (if (not (looking-at verilog-defun-re))
  6698. (verilog-re-search-backward verilog-defun-re nil t))
  6699. (forward-char 1)
  6700. ;; Search through all reachable functions
  6701. (goto-char (point-min))
  6702. (while (verilog-re-search-forward verilog-str (point-max) t)
  6703. (progn (setq match (buffer-substring (match-beginning 2)
  6704. (match-end 2)))
  6705. (if (or (null verilog-pred)
  6706. (funcall verilog-pred match))
  6707. (setq verilog-all (cons match verilog-all)))))
  6708. (if (match-beginning 0)
  6709. (goto-char (match-beginning 0)))))
  6710. (defun verilog-get-completion-decl (end)
  6711. "Macro for searching through current declaration (var, type or const)
  6712. for matches of `str' and adding the occurrence tp `all' through point END."
  6713. (let ((re (or (and verilog-indent-declaration-macros
  6714. verilog-declaration-re-2-macro)
  6715. verilog-declaration-re-2-no-macro))
  6716. decl-end match)
  6717. ;; Traverse lines
  6718. (while (and (< (point) end)
  6719. (verilog-re-search-forward re end t))
  6720. ;; Traverse current line
  6721. (setq decl-end (save-excursion (verilog-declaration-end)))
  6722. (while (and (verilog-re-search-forward verilog-symbol-re decl-end t)
  6723. (not (match-end 1)))
  6724. (setq match (buffer-substring (match-beginning 0) (match-end 0)))
  6725. (if (string-match (concat "\\<" verilog-str) match)
  6726. (if (or (null verilog-pred)
  6727. (funcall verilog-pred match))
  6728. (setq verilog-all (cons match verilog-all)))))
  6729. (forward-line 1)))
  6730. verilog-all)
  6731. (defun verilog-var-completion ()
  6732. "Calculate all possible completions for variables (or constants)."
  6733. (let ((start (point)))
  6734. ;; Search for all reachable var declarations
  6735. (verilog-beg-of-defun)
  6736. (save-excursion
  6737. ;; Check var declarations
  6738. (verilog-get-completion-decl start))))
  6739. (defun verilog-keyword-completion (keyword-list)
  6740. "Give list of all possible completions of keywords in KEYWORD-LIST."
  6741. (mapcar (lambda (s)
  6742. (if (string-match (concat "\\<" verilog-str) s)
  6743. (if (or (null verilog-pred)
  6744. (funcall verilog-pred s))
  6745. (setq verilog-all (cons s verilog-all)))))
  6746. keyword-list))
  6747. (defun verilog-completion (verilog-str verilog-pred verilog-flag)
  6748. "Function passed to `completing-read', `try-completion' or `all-completions'.
  6749. Called to get completion on VERILOG-STR. If VERILOG-PRED is non-nil, it
  6750. must be a function to be called for every match to check if this should
  6751. really be a match. If VERILOG-FLAG is t, the function returns a list of
  6752. all possible completions. If VERILOG-FLAG is nil it returns a string,
  6753. the longest possible completion, or t if VERILOG-STR is an exact match.
  6754. If VERILOG-FLAG is `lambda', the function returns t if VERILOG-STR is an
  6755. exact match, nil otherwise."
  6756. (save-excursion
  6757. (let ((verilog-all nil))
  6758. ;; Set buffer to use for searching labels. This should be set
  6759. ;; within functions which use verilog-completions
  6760. (set-buffer verilog-buffer-to-use)
  6761. ;; Determine what should be completed
  6762. (let ((state (car (verilog-calculate-indent))))
  6763. (cond ((eq state 'defun)
  6764. (save-excursion (verilog-var-completion))
  6765. (verilog-func-completion 'module)
  6766. (verilog-keyword-completion verilog-defun-keywords))
  6767. ((eq state 'behavioral)
  6768. (save-excursion (verilog-var-completion))
  6769. (verilog-func-completion 'module)
  6770. (verilog-keyword-completion verilog-defun-keywords))
  6771. ((eq state 'block)
  6772. (save-excursion (verilog-var-completion))
  6773. (verilog-func-completion 'tf)
  6774. (verilog-keyword-completion verilog-block-keywords))
  6775. ((eq state 'case)
  6776. (save-excursion (verilog-var-completion))
  6777. (verilog-func-completion 'tf)
  6778. (verilog-keyword-completion verilog-case-keywords))
  6779. ((eq state 'tf)
  6780. (save-excursion (verilog-var-completion))
  6781. (verilog-func-completion 'tf)
  6782. (verilog-keyword-completion verilog-tf-keywords))
  6783. ((eq state 'cpp)
  6784. (save-excursion (verilog-var-completion))
  6785. (verilog-keyword-completion verilog-cpp-keywords))
  6786. ((eq state 'cparenexp)
  6787. (save-excursion (verilog-var-completion)))
  6788. (t;--Anywhere else
  6789. (save-excursion (verilog-var-completion))
  6790. (verilog-func-completion 'both)
  6791. (verilog-keyword-completion verilog-separator-keywords))))
  6792. ;; Now we have built a list of all matches. Give response to caller
  6793. (verilog-completion-response))))
  6794. (defun verilog-completion-response ()
  6795. (cond ((or (equal verilog-flag 'lambda) (null verilog-flag))
  6796. ;; This was not called by all-completions
  6797. (if (null verilog-all)
  6798. ;; Return nil if there was no matching label
  6799. nil
  6800. ;; Get longest string common in the labels
  6801. ;; FIXME: Why not use `try-completion'?
  6802. (let* ((elm (cdr verilog-all))
  6803. (match (car verilog-all))
  6804. (min (length match))
  6805. tmp)
  6806. (if (string= match verilog-str)
  6807. ;; Return t if first match was an exact match
  6808. (setq match t)
  6809. (while (not (null elm))
  6810. ;; Find longest common string
  6811. (if (< (setq tmp (verilog-string-diff match (car elm))) min)
  6812. (progn
  6813. (setq min tmp)
  6814. (setq match (substring match 0 min))))
  6815. ;; Terminate with match=t if this is an exact match
  6816. (if (string= (car elm) verilog-str)
  6817. (progn
  6818. (setq match t)
  6819. (setq elm nil))
  6820. (setq elm (cdr elm)))))
  6821. ;; If this is a test just for exact match, return nil ot t
  6822. (if (and (equal verilog-flag 'lambda) (not (equal match 't)))
  6823. nil
  6824. match))))
  6825. ;; If flag is t, this was called by all-completions. Return
  6826. ;; list of all possible completions
  6827. (verilog-flag
  6828. verilog-all)))
  6829. (defvar verilog-last-word-numb 0)
  6830. (defvar verilog-last-word-shown nil)
  6831. (defvar verilog-last-completions nil)
  6832. (defun verilog-complete-word ()
  6833. "Complete word at current point.
  6834. \(See also `verilog-toggle-completions', `verilog-type-keywords',
  6835. and `verilog-separator-keywords'.)"
  6836. ;; FIXME: Provide completion-at-point-function.
  6837. (interactive)
  6838. (let* ((b (save-excursion (skip-chars-backward "a-zA-Z0-9_") (point)))
  6839. (e (save-excursion (skip-chars-forward "a-zA-Z0-9_") (point)))
  6840. (verilog-str (buffer-substring b e))
  6841. ;; The following variable is used in verilog-completion
  6842. (verilog-buffer-to-use (current-buffer))
  6843. (allcomp (if (and verilog-toggle-completions
  6844. (string= verilog-last-word-shown verilog-str))
  6845. verilog-last-completions
  6846. (all-completions verilog-str 'verilog-completion)))
  6847. (match (if verilog-toggle-completions
  6848. "" (try-completion
  6849. verilog-str (mapcar (lambda (elm)
  6850. (cons elm 0)) allcomp)))))
  6851. ;; Delete old string
  6852. (delete-region b e)
  6853. ;; Toggle-completions inserts whole labels
  6854. (if verilog-toggle-completions
  6855. (progn
  6856. ;; Update entry number in list
  6857. (setq verilog-last-completions allcomp
  6858. verilog-last-word-numb
  6859. (if (>= verilog-last-word-numb (1- (length allcomp)))
  6860. 0
  6861. (1+ verilog-last-word-numb)))
  6862. (setq verilog-last-word-shown (elt allcomp verilog-last-word-numb))
  6863. ;; Display next match or same string if no match was found
  6864. (if (not (null allcomp))
  6865. (insert "" verilog-last-word-shown)
  6866. (insert "" verilog-str)
  6867. (message "(No match)")))
  6868. ;; The other form of completion does not necessarily do that.
  6869. ;; Insert match if found, or the original string if no match
  6870. (if (or (null match) (equal match 't))
  6871. (progn (insert "" verilog-str)
  6872. (message "(No match)"))
  6873. (insert "" match))
  6874. ;; Give message about current status of completion
  6875. (cond ((equal match 't)
  6876. (if (not (null (cdr allcomp)))
  6877. (message "(Complete but not unique)")
  6878. (message "(Sole completion)")))
  6879. ;; Display buffer if the current completion didn't help
  6880. ;; on completing the label.
  6881. ((and (not (null (cdr allcomp))) (= (length verilog-str)
  6882. (length match)))
  6883. (with-output-to-temp-buffer "*Completions*"
  6884. (display-completion-list allcomp))
  6885. ;; Wait for a key press. Then delete *Completion* window
  6886. (momentary-string-display "" (point))
  6887. (delete-window (get-buffer-window (get-buffer "*Completions*")))
  6888. )))))
  6889. (defun verilog-show-completions ()
  6890. "Show all possible completions at current point."
  6891. (interactive)
  6892. (let* ((b (save-excursion (skip-chars-backward "a-zA-Z0-9_") (point)))
  6893. (e (save-excursion (skip-chars-forward "a-zA-Z0-9_") (point)))
  6894. (verilog-str (buffer-substring b e))
  6895. ;; The following variable is used in verilog-completion
  6896. (verilog-buffer-to-use (current-buffer))
  6897. (allcomp (if (and verilog-toggle-completions
  6898. (string= verilog-last-word-shown verilog-str))
  6899. verilog-last-completions
  6900. (all-completions verilog-str 'verilog-completion))))
  6901. ;; Show possible completions in a temporary buffer.
  6902. (with-output-to-temp-buffer "*Completions*"
  6903. (display-completion-list allcomp))
  6904. ;; Wait for a key press. Then delete *Completion* window
  6905. (momentary-string-display "" (point))
  6906. (delete-window (get-buffer-window (get-buffer "*Completions*")))))
  6907. (defun verilog-get-default-symbol ()
  6908. "Return symbol around current point as a string."
  6909. (save-excursion
  6910. (buffer-substring (progn
  6911. (skip-chars-backward " \t")
  6912. (skip-chars-backward "a-zA-Z0-9_")
  6913. (point))
  6914. (progn
  6915. (skip-chars-forward "a-zA-Z0-9_")
  6916. (point)))))
  6917. (defun verilog-build-defun-re (str &optional arg)
  6918. "Return function/task/module starting with STR as regular expression.
  6919. With optional second ARG non-nil, STR is the complete name of the instruction."
  6920. (if arg
  6921. (concat "^\\(function\\|task\\|module\\)[ \t]+\\(" str "\\)\\>")
  6922. (concat "^\\(function\\|task\\|module\\)[ \t]+\\(" str "[a-zA-Z0-9_]*\\)\\>")))
  6923. (defun verilog-comp-defun (verilog-str verilog-pred verilog-flag)
  6924. "Function passed to `completing-read', `try-completion' or `all-completions'.
  6925. Returns a completion on any function name based on VERILOG-STR prefix. If
  6926. VERILOG-PRED is non-nil, it must be a function to be called for every match
  6927. to check if this should really be a match. If VERILOG-FLAG is t, the
  6928. function returns a list of all possible completions. If it is nil it
  6929. returns a string, the longest possible completion, or t if VERILOG-STR is
  6930. an exact match. If VERILOG-FLAG is `lambda', the function returns t if
  6931. VERILOG-STR is an exact match, nil otherwise."
  6932. (save-excursion
  6933. (let ((verilog-all nil)
  6934. match)
  6935. ;; Set buffer to use for searching labels. This should be set
  6936. ;; within functions which use verilog-completions
  6937. (set-buffer verilog-buffer-to-use)
  6938. (let ((verilog-str verilog-str))
  6939. ;; Build regular expression for functions
  6940. (if (string= verilog-str "")
  6941. (setq verilog-str (verilog-build-defun-re "[a-zA-Z_]"))
  6942. (setq verilog-str (verilog-build-defun-re verilog-str)))
  6943. (goto-char (point-min))
  6944. ;; Build a list of all possible completions
  6945. (while (verilog-re-search-forward verilog-str nil t)
  6946. (setq match (buffer-substring (match-beginning 2) (match-end 2)))
  6947. (if (or (null verilog-pred)
  6948. (funcall verilog-pred match))
  6949. (setq verilog-all (cons match verilog-all)))))
  6950. ;; Now we have built a list of all matches. Give response to caller
  6951. (verilog-completion-response))))
  6952. (defun verilog-goto-defun ()
  6953. "Move to specified Verilog module/interface/task/function.
  6954. The default is a name found in the buffer around point.
  6955. If search fails, other files are checked based on
  6956. `verilog-library-flags'."
  6957. (interactive)
  6958. (let* ((default (verilog-get-default-symbol))
  6959. ;; The following variable is used in verilog-comp-function
  6960. (verilog-buffer-to-use (current-buffer))
  6961. (label (if (not (string= default ""))
  6962. ;; Do completion with default
  6963. (completing-read (concat "Goto-Label: (default "
  6964. default ") ")
  6965. 'verilog-comp-defun nil nil "")
  6966. ;; There is no default value. Complete without it
  6967. (completing-read "Goto-Label: "
  6968. 'verilog-comp-defun nil nil "")))
  6969. pt)
  6970. ;; Make sure library paths are correct, in case need to resolve module
  6971. (verilog-auto-reeval-locals)
  6972. (verilog-getopt-flags)
  6973. ;; If there was no response on prompt, use default value
  6974. (if (string= label "")
  6975. (setq label default))
  6976. ;; Goto right place in buffer if label is not an empty string
  6977. (or (string= label "")
  6978. (progn
  6979. (save-excursion
  6980. (goto-char (point-min))
  6981. (setq pt
  6982. (re-search-forward (verilog-build-defun-re label t) nil t)))
  6983. (when pt
  6984. (goto-char pt)
  6985. (beginning-of-line))
  6986. pt)
  6987. (verilog-goto-defun-file label))))
  6988. ;; Eliminate compile warning
  6989. (defvar occur-pos-list)
  6990. (defun verilog-showscopes ()
  6991. "List all scopes in this module."
  6992. (interactive)
  6993. (let ((buffer (current-buffer))
  6994. (linenum 1)
  6995. (nlines 0)
  6996. (first 1)
  6997. (prevpos (point-min))
  6998. (final-context-start (make-marker))
  6999. (regexp "\\(module\\s-+\\w+\\s-*(\\)\\|\\(\\w+\\s-+\\w+\\s-*(\\)"))
  7000. (with-output-to-temp-buffer "*Occur*"
  7001. (save-excursion
  7002. (message "Searching for %s ..." regexp)
  7003. ;; Find next match, but give up if prev match was at end of buffer.
  7004. (while (and (not (= prevpos (point-max)))
  7005. (verilog-re-search-forward regexp nil t))
  7006. (goto-char (match-beginning 0))
  7007. (beginning-of-line)
  7008. (save-match-data
  7009. (setq linenum (+ linenum (count-lines prevpos (point)))))
  7010. (setq prevpos (point))
  7011. (goto-char (match-end 0))
  7012. (let* ((start (save-excursion
  7013. (goto-char (match-beginning 0))
  7014. (forward-line (if (< nlines 0) nlines (- nlines)))
  7015. (point)))
  7016. (end (save-excursion
  7017. (goto-char (match-end 0))
  7018. (if (> nlines 0)
  7019. (forward-line (1+ nlines))
  7020. (forward-line 1))
  7021. (point)))
  7022. (tag (format "%3d" linenum))
  7023. (empty (make-string (length tag) ?\ ))
  7024. tem)
  7025. (save-excursion
  7026. (setq tem (make-marker))
  7027. (set-marker tem (point))
  7028. (set-buffer standard-output)
  7029. (setq occur-pos-list (cons tem occur-pos-list))
  7030. (or first (zerop nlines)
  7031. (insert "--------\n"))
  7032. (setq first nil)
  7033. (insert-buffer-substring buffer start end)
  7034. (backward-char (- end start))
  7035. (setq tem (if (< nlines 0) (- nlines) nlines))
  7036. (while (> tem 0)
  7037. (insert empty ?:)
  7038. (forward-line 1)
  7039. (setq tem (1- tem)))
  7040. (let ((this-linenum linenum))
  7041. (set-marker final-context-start
  7042. (+ (point) (- (match-end 0) (match-beginning 0))))
  7043. (while (< (point) final-context-start)
  7044. (if (null tag)
  7045. (setq tag (format "%3d" this-linenum)))
  7046. (insert tag ?:)))))))
  7047. (set-buffer-modified-p nil))))
  7048. ;; Highlight helper functions
  7049. (defconst verilog-directive-regexp "\\(translate\\|coverage\\|lint\\)_")
  7050. (defun verilog-within-translate-off ()
  7051. "Return point if within translate-off region, else nil."
  7052. (and (save-excursion
  7053. (re-search-backward
  7054. (concat "//\\s-*.*\\s-*" verilog-directive-regexp "\\(on\\|off\\)\\>")
  7055. nil t))
  7056. (equal "off" (match-string 2))
  7057. (point)))
  7058. (defun verilog-start-translate-off (limit)
  7059. "Return point before translate-off directive if before LIMIT, else nil."
  7060. (when (re-search-forward
  7061. (concat "//\\s-*.*\\s-*" verilog-directive-regexp "off\\>")
  7062. limit t)
  7063. (match-beginning 0)))
  7064. (defun verilog-back-to-start-translate-off (limit)
  7065. "Return point before translate-off directive if before LIMIT, else nil."
  7066. (when (re-search-backward
  7067. (concat "//\\s-*.*\\s-*" verilog-directive-regexp "off\\>")
  7068. limit t)
  7069. (match-beginning 0)))
  7070. (defun verilog-end-translate-off (limit)
  7071. "Return point after translate-on directive if before LIMIT, else nil."
  7072. (re-search-forward (concat
  7073. "//\\s-*.*\\s-*" verilog-directive-regexp "on\\>") limit t))
  7074. (defun verilog-match-translate-off (limit)
  7075. "Match a translate-off block, setting `match-data' and returning t, else nil.
  7076. Bound search by LIMIT."
  7077. (when (< (point) limit)
  7078. (let ((start (or (verilog-within-translate-off)
  7079. (verilog-start-translate-off limit)))
  7080. (case-fold-search t))
  7081. (when start
  7082. (let ((end (or (verilog-end-translate-off limit) limit)))
  7083. (set-match-data (list start end))
  7084. (goto-char end))))))
  7085. (defun verilog-font-lock-match-item (limit)
  7086. "Match, and move over, any declaration item after point.
  7087. Bound search by LIMIT. Adapted from
  7088. `font-lock-match-c-style-declaration-item-and-skip-to-next'."
  7089. (condition-case nil
  7090. (save-restriction
  7091. (narrow-to-region (point-min) limit)
  7092. ;; match item
  7093. (when (looking-at "\\s-*\\([a-zA-Z]\\w*\\)")
  7094. (save-match-data
  7095. (goto-char (match-end 1))
  7096. ;; move to next item
  7097. (if (looking-at "\\(\\s-*,\\)")
  7098. (goto-char (match-end 1))
  7099. (end-of-line) t))))
  7100. (error nil)))
  7101. ;; Added by Subbu Meiyappan for Header
  7102. (defun verilog-header ()
  7103. "Insert a standard Verilog file header.
  7104. See also `verilog-sk-header' for an alternative format."
  7105. (interactive)
  7106. (let ((start (point)))
  7107. (insert "\
  7108. //-----------------------------------------------------------------------------
  7109. // Title : <title>
  7110. // Project : <project>
  7111. //-----------------------------------------------------------------------------
  7112. // File : <filename>
  7113. // Author : <author>
  7114. // Created : <credate>
  7115. // Last modified : <moddate>
  7116. //-----------------------------------------------------------------------------
  7117. // Description :
  7118. // <description>
  7119. //-----------------------------------------------------------------------------
  7120. // Copyright (c) <copydate> by <company> This model is the confidential and
  7121. // proprietary property of <company> and the possession or use of this
  7122. // file requires a written license from <company>.
  7123. //------------------------------------------------------------------------------
  7124. // Modification history :
  7125. // <modhist>
  7126. //-----------------------------------------------------------------------------
  7127. ")
  7128. (goto-char start)
  7129. (search-forward "<filename>")
  7130. (replace-match (buffer-name) t t)
  7131. (search-forward "<author>") (replace-match "" t t)
  7132. (insert (user-full-name))
  7133. (insert " <" (user-login-name) "@" (system-name) ">")
  7134. (search-forward "<credate>") (replace-match "" t t)
  7135. (verilog-insert-date)
  7136. (search-forward "<moddate>") (replace-match "" t t)
  7137. (verilog-insert-date)
  7138. (search-forward "<copydate>") (replace-match "" t t)
  7139. (verilog-insert-year)
  7140. (search-forward "<modhist>") (replace-match "" t t)
  7141. (verilog-insert-date)
  7142. (insert " : created")
  7143. (goto-char start)
  7144. (let (string)
  7145. (setq string (read-string "title: "))
  7146. (search-forward "<title>")
  7147. (replace-match string t t)
  7148. (setq string (read-string "project: " verilog-project))
  7149. (setq verilog-project string)
  7150. (search-forward "<project>")
  7151. (replace-match string t t)
  7152. (setq string (read-string "Company: " verilog-company))
  7153. (setq verilog-company string)
  7154. (search-forward "<company>")
  7155. (replace-match string t t)
  7156. (search-forward "<company>")
  7157. (replace-match string t t)
  7158. (search-forward "<company>")
  7159. (replace-match string t t)
  7160. (search-backward "<description>")
  7161. (replace-match "" t t))))
  7162. ;; verilog-header Uses the verilog-insert-date function
  7163. (defun verilog-insert-date ()
  7164. "Insert date from the system."
  7165. (interactive)
  7166. (if verilog-date-scientific-format
  7167. (insert (format-time-string "%Y/%m/%d"))
  7168. (insert (format-time-string "%d.%m.%Y"))))
  7169. (defun verilog-insert-year ()
  7170. "Insert year from the system."
  7171. (interactive)
  7172. (insert (format-time-string "%Y")))
  7173. ;;; Signal list parsing:
  7174. ;;
  7175. ;; Elements of a signal list
  7176. ;; Unfortunately we use 'assoc' on this, so can't be a vector
  7177. (defsubst verilog-sig-new (name bits comment mem enum signed type multidim modport)
  7178. (list name bits comment mem enum signed type multidim modport))
  7179. (defsubst verilog-sig-name (sig)
  7180. (car sig))
  7181. (defsubst verilog-sig-bits (sig) ; First element of packed array (pre signal-name)
  7182. (nth 1 sig))
  7183. (defsubst verilog-sig-comment (sig)
  7184. (nth 2 sig))
  7185. (defsubst verilog-sig-memory (sig) ; Unpacked array (post signal-name)
  7186. (nth 3 sig))
  7187. (defsubst verilog-sig-enum (sig)
  7188. (nth 4 sig))
  7189. (defsubst verilog-sig-signed (sig)
  7190. (nth 5 sig))
  7191. (defsubst verilog-sig-type (sig)
  7192. (nth 6 sig))
  7193. (defsubst verilog-sig-type-set (sig type)
  7194. (setcar (nthcdr 6 sig) type))
  7195. (defsubst verilog-sig-multidim (sig) ; Second and additional elements of packed array
  7196. (nth 7 sig))
  7197. (defsubst verilog-sig-multidim-string (sig)
  7198. (if (verilog-sig-multidim sig)
  7199. (let ((str "") (args (verilog-sig-multidim sig)))
  7200. (while args
  7201. (setq str (concat str (car args)))
  7202. (setq args (cdr args)))
  7203. str)))
  7204. (defsubst verilog-sig-modport (sig)
  7205. (nth 8 sig))
  7206. (defsubst verilog-sig-width (sig)
  7207. (verilog-make-width-expression (verilog-sig-bits sig)))
  7208. (defsubst verilog-alw-new (outputs-del outputs-imm temps inputs)
  7209. (vector outputs-del outputs-imm temps inputs))
  7210. (defsubst verilog-alw-get-outputs-delayed (sigs)
  7211. (aref sigs 0))
  7212. (defsubst verilog-alw-get-outputs-immediate (sigs)
  7213. (aref sigs 1))
  7214. (defsubst verilog-alw-get-temps (sigs)
  7215. (aref sigs 2))
  7216. (defsubst verilog-alw-get-inputs (sigs)
  7217. (aref sigs 3))
  7218. (defsubst verilog-alw-get-uses-delayed (sigs)
  7219. (aref sigs 0))
  7220. (defsubst verilog-modport-new (name clockings decls)
  7221. (list name clockings decls))
  7222. (defsubst verilog-modport-name (sig)
  7223. (car sig))
  7224. (defsubst verilog-modport-clockings (sig)
  7225. (nth 1 sig)) ; Returns list of names
  7226. (defsubst verilog-modport-clockings-add (sig val)
  7227. (setcar (nthcdr 1 sig) (cons val (nth 1 sig))))
  7228. (defsubst verilog-modport-decls (sig)
  7229. (nth 2 sig)) ; Returns verilog-decls-* structure
  7230. (defsubst verilog-modport-decls-set (sig val)
  7231. (setcar (nthcdr 2 sig) val))
  7232. (defsubst verilog-modi-new (name fob pt type)
  7233. (vector name fob pt type))
  7234. (defsubst verilog-modi-name (modi)
  7235. (aref modi 0))
  7236. (defsubst verilog-modi-file-or-buffer (modi)
  7237. (aref modi 1))
  7238. (defsubst verilog-modi-get-point (modi)
  7239. (aref modi 2))
  7240. (defsubst verilog-modi-get-type (modi) ; "module" or "interface"
  7241. (aref modi 3))
  7242. (defsubst verilog-modi-get-decls (modi)
  7243. (verilog-modi-cache-results modi 'verilog-read-decls))
  7244. (defsubst verilog-modi-get-sub-decls (modi)
  7245. (verilog-modi-cache-results modi 'verilog-read-sub-decls))
  7246. ;; Signal reading for given module
  7247. ;; Note these all take modi's - as returned from verilog-modi-current
  7248. (defsubst verilog-decls-new (out inout in vars modports assigns consts gparams interfaces)
  7249. (vector out inout in vars modports assigns consts gparams interfaces))
  7250. (defsubst verilog-decls-append (a b)
  7251. (cond ((not a) b) ((not b) a)
  7252. (t (vector (append (aref a 0) (aref b 0)) (append (aref a 1) (aref b 1))
  7253. (append (aref a 2) (aref b 2)) (append (aref a 3) (aref b 3))
  7254. (append (aref a 4) (aref b 4)) (append (aref a 5) (aref b 5))
  7255. (append (aref a 6) (aref b 6)) (append (aref a 7) (aref b 7))
  7256. (append (aref a 8) (aref b 8))))))
  7257. (defsubst verilog-decls-get-outputs (decls)
  7258. (aref decls 0))
  7259. (defsubst verilog-decls-get-inouts (decls)
  7260. (aref decls 1))
  7261. (defsubst verilog-decls-get-inputs (decls)
  7262. (aref decls 2))
  7263. (defsubst verilog-decls-get-vars (decls)
  7264. (aref decls 3))
  7265. (defsubst verilog-decls-get-modports (decls) ; Also for clocking blocks; contains another verilog-decls struct
  7266. (aref decls 4)) ; Returns verilog-modport* structure
  7267. (defsubst verilog-decls-get-assigns (decls)
  7268. (aref decls 5))
  7269. (defsubst verilog-decls-get-consts (decls)
  7270. (aref decls 6))
  7271. (defsubst verilog-decls-get-gparams (decls)
  7272. (aref decls 7))
  7273. (defsubst verilog-decls-get-interfaces (decls)
  7274. (aref decls 8))
  7275. (defsubst verilog-subdecls-new (out inout in intf intfd)
  7276. (vector out inout in intf intfd))
  7277. (defsubst verilog-subdecls-get-outputs (subdecls)
  7278. (aref subdecls 0))
  7279. (defsubst verilog-subdecls-get-inouts (subdecls)
  7280. (aref subdecls 1))
  7281. (defsubst verilog-subdecls-get-inputs (subdecls)
  7282. (aref subdecls 2))
  7283. (defsubst verilog-subdecls-get-interfaces (subdecls)
  7284. (aref subdecls 3))
  7285. (defsubst verilog-subdecls-get-interfaced (subdecls)
  7286. (aref subdecls 4))
  7287. (defun verilog-signals-from-signame (signame-list)
  7288. "Return signals in standard form from SIGNAME-LIST, a simple list of names."
  7289. (mapcar (lambda (name) (verilog-sig-new name nil nil nil nil nil nil nil nil))
  7290. signame-list))
  7291. (defun verilog-signals-in (in-list not-list)
  7292. "Return list of signals in IN-LIST that are also in NOT-LIST.
  7293. Also remove any duplicates in IN-LIST.
  7294. Signals must be in standard (base vector) form."
  7295. ;; This function is hot, so implemented as O(1)
  7296. (cond ((eval-when-compile (fboundp 'make-hash-table))
  7297. (let ((ht (make-hash-table :test 'equal :rehash-size 4.0))
  7298. (ht-not (make-hash-table :test 'equal :rehash-size 4.0))
  7299. out-list)
  7300. (while not-list
  7301. (puthash (car (car not-list)) t ht-not)
  7302. (setq not-list (cdr not-list)))
  7303. (while in-list
  7304. (when (and (gethash (verilog-sig-name (car in-list)) ht-not)
  7305. (not (gethash (verilog-sig-name (car in-list)) ht)))
  7306. (setq out-list (cons (car in-list) out-list))
  7307. (puthash (verilog-sig-name (car in-list)) t ht))
  7308. (setq in-list (cdr in-list)))
  7309. (nreverse out-list)))
  7310. ;; Slower Fallback if no hash tables (pre Emacs 21.1/XEmacs 21.4)
  7311. (t
  7312. (let (out-list)
  7313. (while in-list
  7314. (if (and (assoc (verilog-sig-name (car in-list)) not-list)
  7315. (not (assoc (verilog-sig-name (car in-list)) out-list)))
  7316. (setq out-list (cons (car in-list) out-list)))
  7317. (setq in-list (cdr in-list)))
  7318. (nreverse out-list)))))
  7319. ;;(verilog-signals-in '(("A" "") ("B" "") ("DEL" "[2:3]")) '(("DEL" "") ("C" "")))
  7320. (defun verilog-signals-not-in (in-list not-list)
  7321. "Return list of signals in IN-LIST that aren't also in NOT-LIST.
  7322. Also remove any duplicates in IN-LIST.
  7323. Signals must be in standard (base vector) form."
  7324. ;; This function is hot, so implemented as O(1)
  7325. (cond ((eval-when-compile (fboundp 'make-hash-table))
  7326. (let ((ht (make-hash-table :test 'equal :rehash-size 4.0))
  7327. out-list)
  7328. (while not-list
  7329. (puthash (car (car not-list)) t ht)
  7330. (setq not-list (cdr not-list)))
  7331. (while in-list
  7332. (when (not (gethash (verilog-sig-name (car in-list)) ht))
  7333. (setq out-list (cons (car in-list) out-list))
  7334. (puthash (verilog-sig-name (car in-list)) t ht))
  7335. (setq in-list (cdr in-list)))
  7336. (nreverse out-list)))
  7337. ;; Slower Fallback if no hash tables (pre Emacs 21.1/XEmacs 21.4)
  7338. (t
  7339. (let (out-list)
  7340. (while in-list
  7341. (if (and (not (assoc (verilog-sig-name (car in-list)) not-list))
  7342. (not (assoc (verilog-sig-name (car in-list)) out-list)))
  7343. (setq out-list (cons (car in-list) out-list)))
  7344. (setq in-list (cdr in-list)))
  7345. (nreverse out-list)))))
  7346. ;;(verilog-signals-not-in '(("A" "") ("B" "") ("DEL" "[2:3]")) '(("DEL" "") ("EXT" "")))
  7347. (defun verilog-signals-not-in-struct (in-list not-list)
  7348. "Return list of signals in IN-LIST that aren't also in NOT-LIST.
  7349. Also remove any duplicates in IN-LIST.
  7350. Any structure in not-list will remove all members in in-list.
  7351. Signals must be in standard (base vector) form."
  7352. (cond ((eval-when-compile (fboundp 'make-hash-table))
  7353. (let ((ht (make-hash-table :test 'equal :rehash-size 4.0))
  7354. out-list addit nm)
  7355. (while not-list
  7356. (puthash (car (car not-list)) t ht)
  7357. (setq not-list (cdr not-list)))
  7358. (while in-list
  7359. (setq nm (verilog-sig-name (car in-list)))
  7360. (when (not (gethash nm ht))
  7361. (setq addit t)
  7362. (while (string-match "^\\([^\\].*\\)\\.[^.]+$" nm)
  7363. (setq nm (match-string 1 nm))
  7364. (setq addit (and addit
  7365. (not (gethash nm ht)))))
  7366. (when addit
  7367. (setq out-list (cons (car in-list) out-list))
  7368. (puthash (verilog-sig-name (car in-list)) t ht)))
  7369. (setq in-list (cdr in-list)))
  7370. (nreverse out-list)))
  7371. ;; Slower Fallback if no hash tables (pre Emacs 21.1/XEmacs 21.4)
  7372. (t
  7373. (let (out-list addit nm)
  7374. (while in-list
  7375. (setq nm (verilog-sig-name (car in-list)))
  7376. (when (and (not (assoc nm not-list))
  7377. (not (assoc nm out-list)))
  7378. (setq addit t)
  7379. (while (string-match "^\\([^\\].*\\)\\.[^.]+$" nm)
  7380. (setq nm (match-string 1 nm))
  7381. (setq addit (and addit
  7382. (not (assoc nm not-list)))))
  7383. (when addit
  7384. (setq out-list (cons (car in-list) out-list))))
  7385. (setq in-list (cdr in-list)))
  7386. (nreverse out-list)))))
  7387. ;;(verilog-signals-not-in-struct '(("A" "") ("B" "") ("DEL.SUB.A" "[2:3]")) '(("DEL.SUB" "") ("EXT" "")))
  7388. (defun verilog-signals-memory (in-list)
  7389. "Return list of signals in IN-LIST that are memorized (multidimensional)."
  7390. (let (out-list)
  7391. (while in-list
  7392. (if (nth 3 (car in-list))
  7393. (setq out-list (cons (car in-list) out-list)))
  7394. (setq in-list (cdr in-list)))
  7395. out-list))
  7396. ;;(verilog-signals-memory '(("A" nil nil "[3:0]")) '(("B" nil nil nil)))
  7397. (defun verilog-signals-sort-compare (a b)
  7398. "Compare signal A and B for sorting."
  7399. (string< (verilog-sig-name a) (verilog-sig-name b)))
  7400. (defun verilog-signals-not-params (in-list)
  7401. "Return list of signals in IN-LIST that aren't parameters or numeric constants."
  7402. (let (out-list)
  7403. (while in-list
  7404. ;; Namespace intentionally short for AUTOs and compatibility
  7405. (unless (boundp (intern (concat "vh-" (verilog-sig-name (car in-list)))))
  7406. (setq out-list (cons (car in-list) out-list)))
  7407. (setq in-list (cdr in-list)))
  7408. (nreverse out-list)))
  7409. (defun verilog-signals-with (func in-list)
  7410. "Return list of signals where FUNC is true executed on each signal in IN-LIST."
  7411. (let (out-list)
  7412. (while in-list
  7413. (when (funcall func (car in-list))
  7414. (setq out-list (cons (car in-list) out-list)))
  7415. (setq in-list (cdr in-list)))
  7416. (nreverse out-list)))
  7417. (defun verilog-signals-combine-bus (in-list)
  7418. "Return a list of signals in IN-LIST, with buses combined.
  7419. Duplicate signals are also removed. For example A[2] and A[1] become A[2:1]."
  7420. (let (combo
  7421. buswarn
  7422. out-list
  7423. sig highbit lowbit ; Temp information about current signal
  7424. sv-name sv-highbit sv-lowbit ; Details about signal we are forming
  7425. sv-comment sv-memory sv-enum sv-signed sv-type sv-multidim sv-busstring
  7426. sv-modport
  7427. bus)
  7428. ;; Shove signals so duplicated signals will be adjacent
  7429. (setq in-list (sort in-list `verilog-signals-sort-compare))
  7430. (while in-list
  7431. (setq sig (car in-list))
  7432. ;; No current signal; form from existing details
  7433. (unless sv-name
  7434. (setq sv-name (verilog-sig-name sig)
  7435. sv-highbit nil
  7436. sv-busstring nil
  7437. sv-comment (verilog-sig-comment sig)
  7438. sv-memory (verilog-sig-memory sig)
  7439. sv-enum (verilog-sig-enum sig)
  7440. sv-signed (verilog-sig-signed sig)
  7441. sv-type (verilog-sig-type sig)
  7442. sv-multidim (verilog-sig-multidim sig)
  7443. sv-modport (verilog-sig-modport sig)
  7444. combo ""
  7445. buswarn ""))
  7446. ;; Extract bus details
  7447. (setq bus (verilog-sig-bits sig))
  7448. (setq bus (and bus (verilog-simplify-range-expression bus)))
  7449. (cond ((and bus
  7450. (or (and (string-match "\\[\\([0-9]+\\):\\([0-9]+\\)\\]" bus)
  7451. (setq highbit (string-to-number (match-string 1 bus))
  7452. lowbit (string-to-number
  7453. (match-string 2 bus))))
  7454. (and (string-match "\\[\\([0-9]+\\)\\]" bus)
  7455. (setq highbit (string-to-number (match-string 1 bus))
  7456. lowbit highbit))))
  7457. ;; Combine bits in bus
  7458. (if sv-highbit
  7459. (setq sv-highbit (max highbit sv-highbit)
  7460. sv-lowbit (min lowbit sv-lowbit))
  7461. (setq sv-highbit highbit
  7462. sv-lowbit lowbit)))
  7463. (bus
  7464. ;; String, probably something like `preproc:0
  7465. (setq sv-busstring bus)))
  7466. ;; Peek ahead to next signal
  7467. (setq in-list (cdr in-list))
  7468. (setq sig (car in-list))
  7469. (cond ((and sig (equal sv-name (verilog-sig-name sig)))
  7470. ;; Combine with this signal
  7471. (when (and sv-busstring
  7472. (not (equal sv-busstring (verilog-sig-bits sig))))
  7473. (when nil ; Debugging
  7474. (message (concat "Warning, can't merge into single bus %s%s"
  7475. ", the AUTOs may be wrong")
  7476. sv-name bus))
  7477. (setq buswarn ", Couldn't Merge"))
  7478. (if (verilog-sig-comment sig) (setq combo ", ..."))
  7479. (setq sv-memory (or sv-memory (verilog-sig-memory sig))
  7480. sv-enum (or sv-enum (verilog-sig-enum sig))
  7481. sv-signed (or sv-signed (verilog-sig-signed sig))
  7482. sv-type (or sv-type (verilog-sig-type sig))
  7483. sv-multidim (or sv-multidim (verilog-sig-multidim sig))
  7484. sv-modport (or sv-modport (verilog-sig-modport sig))))
  7485. ;; Doesn't match next signal, add to queue, zero in prep for next
  7486. ;; Note sig may also be nil for the last signal in the list
  7487. (t
  7488. (setq out-list
  7489. (cons (verilog-sig-new
  7490. sv-name
  7491. (or sv-busstring
  7492. (if sv-highbit
  7493. (concat "[" (int-to-string sv-highbit) ":"
  7494. (int-to-string sv-lowbit) "]")))
  7495. (concat sv-comment combo buswarn)
  7496. sv-memory sv-enum sv-signed sv-type sv-multidim sv-modport)
  7497. out-list)
  7498. sv-name nil))))
  7499. ;;
  7500. out-list))
  7501. (defun verilog-sig-tieoff (sig)
  7502. "Return tieoff expression for given SIG, with appropriate width.
  7503. Tieoff value uses `verilog-active-low-regexp' and
  7504. `verilog-auto-reset-widths'."
  7505. (concat
  7506. (if (and verilog-active-low-regexp
  7507. (verilog-string-match-fold verilog-active-low-regexp (verilog-sig-name sig)))
  7508. "~" "")
  7509. (cond ((not verilog-auto-reset-widths)
  7510. "0")
  7511. ((equal verilog-auto-reset-widths 'unbased)
  7512. "'0")
  7513. ;; Else presume verilog-auto-reset-widths is true
  7514. (t
  7515. (let* ((width (verilog-sig-width sig)))
  7516. (cond ((not width)
  7517. "`0/*NOWIDTH*/")
  7518. ((string-match "^[0-9]+$" width)
  7519. (concat width (if (verilog-sig-signed sig) "'sh0" "'h0")))
  7520. (t
  7521. (concat "{" width "{1'b0}}"))))))))
  7522. ;;
  7523. ;; Dumping
  7524. ;;
  7525. (defun verilog-decls-princ (decls &optional header prefix)
  7526. "For debug, dump the `verilog-read-decls' structure DECLS.
  7527. Use optional HEADER and PREFIX."
  7528. (when decls
  7529. (if header (princ header))
  7530. (setq prefix (or prefix ""))
  7531. (verilog-signals-princ (verilog-decls-get-outputs decls)
  7532. (concat prefix "Outputs:\n") (concat prefix " "))
  7533. (verilog-signals-princ (verilog-decls-get-inouts decls)
  7534. (concat prefix "Inout:\n") (concat prefix " "))
  7535. (verilog-signals-princ (verilog-decls-get-inputs decls)
  7536. (concat prefix "Inputs:\n") (concat prefix " "))
  7537. (verilog-signals-princ (verilog-decls-get-vars decls)
  7538. (concat prefix "Vars:\n") (concat prefix " "))
  7539. (verilog-signals-princ (verilog-decls-get-assigns decls)
  7540. (concat prefix "Assigns:\n") (concat prefix " "))
  7541. (verilog-signals-princ (verilog-decls-get-consts decls)
  7542. (concat prefix "Consts:\n") (concat prefix " "))
  7543. (verilog-signals-princ (verilog-decls-get-gparams decls)
  7544. (concat prefix "Gparams:\n") (concat prefix " "))
  7545. (verilog-signals-princ (verilog-decls-get-interfaces decls)
  7546. (concat prefix "Interfaces:\n") (concat prefix " "))
  7547. (verilog-modport-princ (verilog-decls-get-modports decls)
  7548. (concat prefix "Modports:\n") (concat prefix " "))
  7549. (princ "\n")))
  7550. (defun verilog-signals-princ (signals &optional header prefix)
  7551. "For debug, dump internal SIGNALS structures, with HEADER and PREFIX."
  7552. (when signals
  7553. (if header (princ header))
  7554. (while signals
  7555. (let ((sig (car signals)))
  7556. (setq signals (cdr signals))
  7557. (princ prefix)
  7558. (princ "\"") (princ (verilog-sig-name sig)) (princ "\"")
  7559. (princ " bits=") (princ (verilog-sig-bits sig))
  7560. (princ " cmt=") (princ (verilog-sig-comment sig))
  7561. (princ " mem=") (princ (verilog-sig-memory sig))
  7562. (princ " enum=") (princ (verilog-sig-enum sig))
  7563. (princ " sign=") (princ (verilog-sig-signed sig))
  7564. (princ " type=") (princ (verilog-sig-type sig))
  7565. (princ " dim=") (princ (verilog-sig-multidim sig))
  7566. (princ " modp=") (princ (verilog-sig-modport sig))
  7567. (princ "\n")))))
  7568. (defun verilog-modport-princ (modports &optional header prefix)
  7569. "For debug, dump internal MODPORTS structures, with HEADER and PREFIX."
  7570. (when modports
  7571. (if header (princ header))
  7572. (while modports
  7573. (let ((sig (car modports)))
  7574. (setq modports (cdr modports))
  7575. (princ prefix)
  7576. (princ "\"") (princ (verilog-modport-name sig)) (princ "\"")
  7577. (princ " clockings=") (princ (verilog-modport-clockings sig))
  7578. (princ "\n")
  7579. (verilog-decls-princ (verilog-modport-decls sig)
  7580. (concat prefix " syms:\n")
  7581. (concat prefix " "))))))
  7582. ;;
  7583. ;; Port/Wire/Etc Reading
  7584. ;;
  7585. (defun verilog-read-inst-backward-name ()
  7586. "Internal. Move point back to beginning of inst-name."
  7587. (verilog-backward-open-paren)
  7588. (let (done)
  7589. (while (not done)
  7590. (verilog-re-search-backward-quick "\\()\\|\\b[a-zA-Z0-9`_$]\\|\\]\\)" nil nil) ; ] isn't word boundary
  7591. (cond ((looking-at ")")
  7592. (verilog-backward-open-paren))
  7593. (t (setq done t)))))
  7594. (while (looking-at "\\]")
  7595. (verilog-backward-open-bracket)
  7596. (verilog-re-search-backward-quick "\\(\\b[a-zA-Z0-9`_$]\\|\\]\\)" nil nil))
  7597. (skip-chars-backward "a-zA-Z0-9`_$"))
  7598. (defun verilog-read-inst-module-matcher ()
  7599. "Set match data 0 with module_name when point is inside instantiation."
  7600. (verilog-read-inst-backward-name)
  7601. ;; Skip over instantiation name
  7602. (verilog-re-search-backward-quick "\\(\\b[a-zA-Z0-9`_$]\\|)\\)" nil nil) ; ) isn't word boundary
  7603. ;; Check for parameterized instantiations
  7604. (when (looking-at ")")
  7605. (verilog-backward-open-paren)
  7606. (verilog-re-search-backward-quick "\\b[a-zA-Z0-9`_$]" nil nil))
  7607. (skip-chars-backward "a-zA-Z0-9'_$")
  7608. ;; #1 is legal syntax for gate primitives
  7609. (when (save-excursion
  7610. (verilog-backward-syntactic-ws-quick)
  7611. (eq ?# (char-before)))
  7612. (verilog-re-search-backward-quick "\\b[a-zA-Z0-9`_$]" nil nil)
  7613. (skip-chars-backward "a-zA-Z0-9'_$"))
  7614. (looking-at "[a-zA-Z0-9`_$]+")
  7615. ;; Important: don't use match string, this must work with Emacs 19 font-lock on
  7616. (buffer-substring-no-properties (match-beginning 0) (match-end 0))
  7617. ;; Caller assumes match-beginning/match-end is still set
  7618. )
  7619. (defun verilog-read-inst-module ()
  7620. "Return module_name when point is inside instantiation."
  7621. (save-excursion
  7622. (verilog-read-inst-module-matcher)))
  7623. (defun verilog-read-inst-name ()
  7624. "Return instance_name when point is inside instantiation."
  7625. (save-excursion
  7626. (verilog-read-inst-backward-name)
  7627. (looking-at "[a-zA-Z0-9`_$]+")
  7628. ;; Important: don't use match string, this must work with Emacs 19 font-lock on
  7629. (buffer-substring-no-properties (match-beginning 0) (match-end 0))))
  7630. (defun verilog-read-module-name ()
  7631. "Return module name when after its ( or ;."
  7632. (save-excursion
  7633. (re-search-backward "[(;]")
  7634. ;; Due to "module x import y (" we must search for declaration begin
  7635. (verilog-re-search-backward-quick verilog-defun-re nil nil)
  7636. (goto-char (match-end 0))
  7637. (verilog-re-search-forward-quick "\\b[a-zA-Z0-9`_$]+" nil nil)
  7638. ;; Important: don't use match string, this must work with Emacs 19 font-lock on
  7639. (verilog-symbol-detick
  7640. (buffer-substring-no-properties (match-beginning 0) (match-end 0)) t)))
  7641. (defun verilog-read-inst-param-value ()
  7642. "Return list of parameters and values when point is inside instantiation."
  7643. (save-excursion
  7644. (verilog-read-inst-backward-name)
  7645. ;; Skip over instantiation name
  7646. (verilog-re-search-backward-quick "\\(\\b[a-zA-Z0-9`_$]\\|)\\)" nil nil) ; ) isn't word boundary
  7647. ;; If there are parameterized instantiations
  7648. (when (looking-at ")")
  7649. (let ((end-pt (point))
  7650. params
  7651. param-name paren-beg-pt param-value)
  7652. (verilog-backward-open-paren)
  7653. (while (verilog-re-search-forward-quick "\\." end-pt t)
  7654. (verilog-re-search-forward-quick "\\([a-zA-Z0-9`_$]\\)" nil nil)
  7655. (skip-chars-backward "a-zA-Z0-9'_$")
  7656. (looking-at "[a-zA-Z0-9`_$]+")
  7657. (setq param-name (buffer-substring-no-properties
  7658. (match-beginning 0) (match-end 0)))
  7659. (verilog-re-search-forward-quick "(" nil nil)
  7660. (setq paren-beg-pt (point))
  7661. (verilog-forward-close-paren)
  7662. (setq param-value (verilog-string-remove-spaces
  7663. (buffer-substring-no-properties
  7664. paren-beg-pt (1- (point)))))
  7665. (setq params (cons (list param-name param-value) params)))
  7666. params))))
  7667. (defun verilog-read-auto-params (num-param &optional max-param)
  7668. "Return parameter list inside auto.
  7669. Optional NUM-PARAM and MAX-PARAM check for a specific number of parameters."
  7670. (let ((olist))
  7671. (save-excursion
  7672. ;; /*AUTOPUNT("parameter", "parameter")*/
  7673. (backward-sexp 1)
  7674. (while (looking-at "(?\\s *\"\\([^\"]*\\)\"\\s *,?")
  7675. (setq olist (cons (match-string 1) olist))
  7676. (goto-char (match-end 0))))
  7677. (or (eq nil num-param)
  7678. (<= num-param (length olist))
  7679. (error "%s: Expected %d parameters" (verilog-point-text) num-param))
  7680. (if (eq max-param nil) (setq max-param num-param))
  7681. (or (eq nil max-param)
  7682. (>= max-param (length olist))
  7683. (error "%s: Expected <= %d parameters" (verilog-point-text) max-param))
  7684. (nreverse olist)))
  7685. (defun verilog-read-decls ()
  7686. "Compute signal declaration information for the current module at point.
  7687. Return an array of [outputs inouts inputs wire reg assign const]."
  7688. (let ((end-mod-point (or (verilog-get-end-of-defun) (point-max)))
  7689. (functask 0) (paren 0) (sig-paren 0) (v2kargs-ok t)
  7690. in-modport in-clocking in-ign-to-semi ptype ign-prop
  7691. sigs-in sigs-out sigs-inout sigs-var sigs-assign sigs-const
  7692. sigs-gparam sigs-intf sigs-modports
  7693. vec expect-signal keywd newsig rvalue enum io signed typedefed multidim
  7694. modport
  7695. varstack tmp)
  7696. ;;(if dbg (setq dbg (concat dbg (format "\n\nverilog-read-decls START PT %s END %s\n" (point) end-mod-point))))
  7697. (save-excursion
  7698. (verilog-beg-of-defun-quick)
  7699. (setq sigs-const (verilog-read-auto-constants (point) end-mod-point))
  7700. (while (< (point) end-mod-point)
  7701. ;;(if dbg (setq dbg (concat dbg (format "Pt %s Vec %s C%c Kwd'%s'\n" (point) vec (following-char) keywd))))
  7702. (cond
  7703. ((looking-at "//")
  7704. (if (looking-at "[^\n]*\\(auto\\|synopsys\\)\\s +enum\\s +\\([a-zA-Z0-9_]+\\)")
  7705. (setq enum (match-string 2)))
  7706. (search-forward "\n"))
  7707. ((looking-at "/\\*")
  7708. (forward-char 2)
  7709. (if (looking-at "[^\n]*\\(auto\\|synopsys\\)\\s +enum\\s +\\([a-zA-Z0-9_]+\\)")
  7710. (setq enum (match-string 2)))
  7711. (or (search-forward "*/")
  7712. (error "%s: Unmatched /* */, at char %d" (verilog-point-text) (point))))
  7713. ((looking-at "(\\*")
  7714. ;; To advance past either "(*)" or "(* ... *)" don't forward past first *
  7715. (forward-char 1)
  7716. (or (search-forward "*)")
  7717. (error "%s: Unmatched (* *), at char %d" (verilog-point-text) (point))))
  7718. ((eq ?\" (following-char))
  7719. (or (re-search-forward "[^\\]\"" nil t) ; don't forward-char first, since we look for a non backslash first
  7720. (error "%s: Unmatched quotes, at char %d" (verilog-point-text) (point))))
  7721. ((eq ?\; (following-char))
  7722. (cond (in-ign-to-semi ; Such as inside a "import ...;" in a module header
  7723. (setq in-ign-to-semi nil))
  7724. ((and in-modport (not (eq in-modport t))) ; end of a modport declaration
  7725. (verilog-modport-decls-set
  7726. in-modport
  7727. (verilog-decls-new sigs-out sigs-inout sigs-in
  7728. nil nil nil nil nil nil))
  7729. ;; Pop from varstack to restore state to pre-clocking
  7730. (setq tmp (car varstack)
  7731. varstack (cdr varstack)
  7732. sigs-out (aref tmp 0)
  7733. sigs-inout (aref tmp 1)
  7734. sigs-in (aref tmp 2))
  7735. (setq vec nil io nil expect-signal nil newsig nil paren 0 rvalue nil
  7736. v2kargs-ok nil in-modport nil ign-prop nil))
  7737. (t
  7738. (setq vec nil io nil expect-signal nil newsig nil paren 0 rvalue nil
  7739. v2kargs-ok nil in-modport nil ign-prop nil)))
  7740. (forward-char 1))
  7741. ((eq ?= (following-char))
  7742. (setq rvalue t newsig nil)
  7743. (forward-char 1))
  7744. ((and (eq ?, (following-char))
  7745. (eq paren sig-paren))
  7746. (setq rvalue nil)
  7747. (forward-char 1))
  7748. ;; ,'s can occur inside {} & funcs
  7749. ((looking-at "[{(]")
  7750. (setq paren (1+ paren))
  7751. (forward-char 1))
  7752. ((looking-at "[})]")
  7753. (setq paren (1- paren))
  7754. (forward-char 1)
  7755. (when (< paren sig-paren)
  7756. (setq expect-signal nil rvalue nil))) ; ) that ends variables inside v2k arg list
  7757. ((looking-at "\\s-*\\(\\[[^]]+\\]\\)")
  7758. (goto-char (match-end 0))
  7759. (cond (newsig ; Memory, not just width. Patch last signal added's memory (nth 3)
  7760. (setcar (cdr (cdr (cdr newsig)))
  7761. (if (verilog-sig-memory newsig)
  7762. (concat (verilog-sig-memory newsig) (match-string 1))
  7763. (match-string 1))))
  7764. (vec ; Multidimensional
  7765. (setq multidim (cons vec multidim))
  7766. (setq vec (verilog-string-replace-matches
  7767. "\\s-+" "" nil nil (match-string 1))))
  7768. (t ; Bit width
  7769. (setq vec (verilog-string-replace-matches
  7770. "\\s-+" "" nil nil (match-string 1))))))
  7771. ;; Normal or escaped identifier -- note we remember the \ if escaped
  7772. ((looking-at "\\s-*\\([a-zA-Z0-9`_$]+\\|\\\\[^ \t\n\f]+\\)")
  7773. (goto-char (match-end 0))
  7774. (setq keywd (match-string 1))
  7775. (when (string-match "^\\\\" (match-string 1))
  7776. (setq keywd (concat keywd " "))) ; Escaped ID needs space at end
  7777. ;; Add any :: package names to same identifier
  7778. (while (looking-at "\\s-*::\\s-*\\([a-zA-Z0-9`_$]+\\|\\\\[^ \t\n\f]+\\)")
  7779. (goto-char (match-end 0))
  7780. (setq keywd (concat keywd "::" (match-string 1)))
  7781. (when (string-match "^\\\\" (match-string 1))
  7782. (setq keywd (concat keywd " ")))) ; Escaped ID needs space at end
  7783. (cond ((equal keywd "input")
  7784. (setq vec nil enum nil rvalue nil newsig nil signed nil
  7785. typedefed nil multidim nil ptype nil modport nil
  7786. expect-signal 'sigs-in io t sig-paren paren))
  7787. ((equal keywd "output")
  7788. (setq vec nil enum nil rvalue nil newsig nil signed nil
  7789. typedefed nil multidim nil ptype nil modport nil
  7790. expect-signal 'sigs-out io t sig-paren paren))
  7791. ((equal keywd "inout")
  7792. (setq vec nil enum nil rvalue nil newsig nil signed nil
  7793. typedefed nil multidim nil ptype nil modport nil
  7794. expect-signal 'sigs-inout io t sig-paren paren))
  7795. ((equal keywd "parameter")
  7796. (setq vec nil enum nil rvalue nil signed nil
  7797. typedefed nil multidim nil ptype nil modport nil
  7798. expect-signal 'sigs-gparam io t sig-paren paren))
  7799. ((member keywd '("wire" "reg" ; Fast
  7800. ;; net_type
  7801. "tri" "tri0" "tri1" "triand" "trior" "trireg"
  7802. "uwire" "wand" "wor"
  7803. ;; integer_atom_type
  7804. "byte" "shortint" "int" "longint" "integer" "time"
  7805. "supply0" "supply1"
  7806. ;; integer_vector_type - "reg" above
  7807. "bit" "logic"
  7808. ;; non_integer_type
  7809. "shortreal" "real" "realtime"
  7810. ;; data_type
  7811. "string" "event" "chandle"))
  7812. (cond (io
  7813. (setq typedefed
  7814. (if typedefed (concat typedefed " " keywd) keywd)))
  7815. (t (setq vec nil enum nil rvalue nil signed nil
  7816. typedefed nil multidim nil sig-paren paren
  7817. expect-signal 'sigs-var modport nil))))
  7818. ((equal keywd "assign")
  7819. (setq vec nil enum nil rvalue nil signed nil
  7820. typedefed nil multidim nil ptype nil modport nil
  7821. expect-signal 'sigs-assign sig-paren paren))
  7822. ((member keywd '("localparam" "genvar"))
  7823. (setq vec nil enum nil rvalue nil signed nil
  7824. typedefed nil multidim nil ptype nil modport nil
  7825. expect-signal 'sigs-const sig-paren paren))
  7826. ((member keywd '("signed" "unsigned"))
  7827. (setq signed keywd))
  7828. ((member keywd '("assert" "assume" "cover" "expect" "restrict"))
  7829. (setq ign-prop t))
  7830. ((member keywd '("class" "covergroup" "function"
  7831. "property" "randsequence" "sequence" "task"))
  7832. (unless ign-prop
  7833. (setq functask (1+ functask))))
  7834. ((member keywd '("endclass" "endgroup" "endfunction"
  7835. "endproperty" "endsequence" "endtask"))
  7836. (setq functask (1- functask)))
  7837. ((equal keywd "modport")
  7838. (setq in-modport t))
  7839. ((equal keywd "clocking")
  7840. (setq in-clocking t))
  7841. ((equal keywd "import")
  7842. (if v2kargs-ok ; import in module header, not a modport import
  7843. (setq in-ign-to-semi t rvalue t)))
  7844. ((equal keywd "type")
  7845. (setq ptype t))
  7846. ((equal keywd "var"))
  7847. ;; Ifdef? Ignore name of define
  7848. ((member keywd '("`ifdef" "`ifndef" "`elsif"))
  7849. (setq rvalue t))
  7850. ;; Type?
  7851. ((unless ptype
  7852. (verilog-typedef-name-p keywd))
  7853. (cond (io
  7854. (setq typedefed
  7855. (if typedefed (concat typedefed " " keywd) keywd)))
  7856. (t (setq vec nil enum nil rvalue nil signed nil
  7857. typedefed keywd ; Have a type
  7858. multidim nil sig-paren paren
  7859. expect-signal 'sigs-var modport nil))))
  7860. ;; Interface with optional modport in v2k arglist?
  7861. ;; Skip over parsing modport, and take the interface name as the type
  7862. ((and v2kargs-ok
  7863. (eq paren 1)
  7864. (not rvalue)
  7865. (looking-at "\\s-*\\(\\.\\(\\s-*[a-zA-Z`_$][a-zA-Z0-9`_$]*\\)\\|\\)\\s-*[a-zA-Z`_$][a-zA-Z0-9`_$]*"))
  7866. (when (match-end 2) (goto-char (match-end 2)))
  7867. (setq vec nil enum nil rvalue nil signed nil
  7868. typedefed keywd multidim nil ptype nil modport (match-string 2)
  7869. newsig nil sig-paren paren
  7870. expect-signal 'sigs-intf io t ))
  7871. ;; Ignore dotted LHS assignments: "assign foo.bar = z;"
  7872. ((looking-at "\\s-*\\.")
  7873. (goto-char (match-end 0))
  7874. (when (not rvalue)
  7875. (setq expect-signal nil)))
  7876. ;; "modport <keywd>"
  7877. ((and (eq in-modport t)
  7878. (not (member keywd verilog-keywords)))
  7879. (setq in-modport (verilog-modport-new keywd nil nil))
  7880. (setq sigs-modports (cons in-modport sigs-modports))
  7881. ;; Push old sig values to stack and point to new signal list
  7882. (setq varstack (cons (vector sigs-out sigs-inout sigs-in)
  7883. varstack))
  7884. (setq sigs-in nil sigs-inout nil sigs-out nil))
  7885. ;; "modport x (clocking <keywd>)"
  7886. ((and in-modport in-clocking)
  7887. (verilog-modport-clockings-add in-modport keywd)
  7888. (setq in-clocking nil))
  7889. ;; endclocking
  7890. ((and in-clocking
  7891. (equal keywd "endclocking"))
  7892. (unless (eq in-clocking t)
  7893. (verilog-modport-decls-set
  7894. in-clocking
  7895. (verilog-decls-new sigs-out sigs-inout sigs-in
  7896. nil nil nil nil nil nil))
  7897. ;; Pop from varstack to restore state to pre-clocking
  7898. (setq tmp (car varstack)
  7899. varstack (cdr varstack)
  7900. sigs-out (aref tmp 0)
  7901. sigs-inout (aref tmp 1)
  7902. sigs-in (aref tmp 2)))
  7903. (setq in-clocking nil))
  7904. ;; "clocking <keywd>"
  7905. ((and (eq in-clocking t)
  7906. (not (member keywd verilog-keywords)))
  7907. (setq in-clocking (verilog-modport-new keywd nil nil))
  7908. (setq sigs-modports (cons in-clocking sigs-modports))
  7909. ;; Push old sig values to stack and point to new signal list
  7910. (setq varstack (cons (vector sigs-out sigs-inout sigs-in)
  7911. varstack))
  7912. (setq sigs-in nil sigs-inout nil sigs-out nil))
  7913. ;; New signal, maybe?
  7914. ((and expect-signal
  7915. (not rvalue)
  7916. (eq functask 0)
  7917. (not (member keywd verilog-keywords)))
  7918. ;; Add new signal to expect-signal's variable
  7919. ;;(if dbg (setq dbg (concat dbg (format "Pt %s New sig %s'\n" (point) keywd))))
  7920. (setq newsig (verilog-sig-new keywd vec nil nil enum signed typedefed multidim modport))
  7921. (set expect-signal (cons newsig
  7922. (symbol-value expect-signal))))))
  7923. (t
  7924. (forward-char 1)))
  7925. (skip-syntax-forward " "))
  7926. ;; Return arguments
  7927. (setq tmp (verilog-decls-new (nreverse sigs-out)
  7928. (nreverse sigs-inout)
  7929. (nreverse sigs-in)
  7930. (nreverse sigs-var)
  7931. (nreverse sigs-modports)
  7932. (nreverse sigs-assign)
  7933. (nreverse sigs-const)
  7934. (nreverse sigs-gparam)
  7935. (nreverse sigs-intf)))
  7936. ;;(if dbg (verilog-decls-princ tmp))
  7937. tmp)))
  7938. (defvar verilog-read-sub-decls-in-interfaced nil
  7939. "For `verilog-read-sub-decls', process next signal as under interfaced block.")
  7940. (defvar verilog-read-sub-decls-gate-ios nil
  7941. "For `verilog-read-sub-decls', gate IO pins remaining, nil if non-primitive.")
  7942. (eval-when-compile
  7943. ;; Prevent compile warnings; these are let's, not globals
  7944. ;; Do not remove the eval-when-compile
  7945. ;; - we want an error when we are debugging this code if they are refed.
  7946. (defvar sigs-in)
  7947. (defvar sigs-inout)
  7948. (defvar sigs-intf)
  7949. (defvar sigs-intfd)
  7950. (defvar sigs-out)
  7951. (defvar sigs-out-d)
  7952. (defvar sigs-out-i)
  7953. (defvar sigs-out-unk)
  7954. (defvar sigs-temp)
  7955. ;; These are known to be from other packages and may not be defined
  7956. (defvar diff-command nil)
  7957. ;; There are known to be from newer versions of Emacs
  7958. (defvar create-lockfiles))
  7959. (defun verilog-read-sub-decls-sig (submoddecls comment port sig vec multidim)
  7960. "For `verilog-read-sub-decls-line', add a signal."
  7961. ;; sig eq t to indicate .name syntax
  7962. ;;(message "vrsds: %s(%S)" port sig)
  7963. (let ((dotname (eq sig t))
  7964. portdata)
  7965. (when sig
  7966. (setq port (verilog-symbol-detick-denumber port))
  7967. (setq sig (if dotname port (verilog-symbol-detick-denumber sig)))
  7968. (if vec (setq vec (verilog-symbol-detick-denumber vec)))
  7969. (if multidim (setq multidim (mapcar `verilog-symbol-detick-denumber multidim)))
  7970. (unless (or (not sig)
  7971. (equal sig "")) ; Ignore .foo(1'b1) assignments
  7972. (cond ((or (setq portdata (assoc port (verilog-decls-get-inouts submoddecls)))
  7973. (equal "inout" verilog-read-sub-decls-gate-ios))
  7974. (setq sigs-inout
  7975. (cons (verilog-sig-new
  7976. sig
  7977. (if dotname (verilog-sig-bits portdata) vec)
  7978. (concat "To/From " comment)
  7979. (verilog-sig-memory portdata)
  7980. nil
  7981. (verilog-sig-signed portdata)
  7982. (unless (member (verilog-sig-type portdata) '("wire" "reg"))
  7983. (verilog-sig-type portdata))
  7984. multidim nil)
  7985. sigs-inout)))
  7986. ((or (setq portdata (assoc port (verilog-decls-get-outputs submoddecls)))
  7987. (equal "output" verilog-read-sub-decls-gate-ios))
  7988. (setq sigs-out
  7989. (cons (verilog-sig-new
  7990. sig
  7991. (if dotname (verilog-sig-bits portdata) vec)
  7992. (concat "From " comment)
  7993. (verilog-sig-memory portdata)
  7994. nil
  7995. (verilog-sig-signed portdata)
  7996. ;; Though ok in SV, in V2K code, propagating the
  7997. ;; "reg" in "output reg" upwards isn't legal.
  7998. ;; Also for backwards compatibility we don't propagate
  7999. ;; "input wire" upwards.
  8000. ;; See also `verilog-signals-edit-wire-reg'.
  8001. (unless (member (verilog-sig-type portdata) '("wire" "reg"))
  8002. (verilog-sig-type portdata))
  8003. multidim nil)
  8004. sigs-out)))
  8005. ((or (setq portdata (assoc port (verilog-decls-get-inputs submoddecls)))
  8006. (equal "input" verilog-read-sub-decls-gate-ios))
  8007. (setq sigs-in
  8008. (cons (verilog-sig-new
  8009. sig
  8010. (if dotname (verilog-sig-bits portdata) vec)
  8011. (concat "To " comment)
  8012. (verilog-sig-memory portdata)
  8013. nil
  8014. (verilog-sig-signed portdata)
  8015. (unless (member (verilog-sig-type portdata) '("wire" "reg"))
  8016. (verilog-sig-type portdata))
  8017. multidim nil)
  8018. sigs-in)))
  8019. ((setq portdata (assoc port (verilog-decls-get-interfaces submoddecls)))
  8020. (setq sigs-intf
  8021. (cons (verilog-sig-new
  8022. sig
  8023. (if dotname (verilog-sig-bits portdata) vec)
  8024. (concat "To/From " comment)
  8025. (verilog-sig-memory portdata)
  8026. nil
  8027. (verilog-sig-signed portdata)
  8028. (verilog-sig-type portdata)
  8029. multidim nil)
  8030. sigs-intf)))
  8031. ((setq portdata (and verilog-read-sub-decls-in-interfaced
  8032. (assoc port (verilog-decls-get-vars submoddecls))))
  8033. (setq sigs-intfd
  8034. (cons (verilog-sig-new
  8035. sig
  8036. (if dotname (verilog-sig-bits portdata) vec)
  8037. (concat "To/From " comment)
  8038. (verilog-sig-memory portdata)
  8039. nil
  8040. (verilog-sig-signed portdata)
  8041. (verilog-sig-type portdata)
  8042. multidim nil)
  8043. sigs-intf)))
  8044. ;; (t -- warning pin isn't defined.) ; Leave for lint tool
  8045. )))))
  8046. (defun verilog-read-sub-decls-expr (submoddecls comment port expr)
  8047. "For `verilog-read-sub-decls-line', parse a subexpression and add signals."
  8048. ;;(message "vrsde: `%s'" expr)
  8049. ;; Replace special /*[....]*/ comments inserted by verilog-auto-inst-port
  8050. (setq expr (verilog-string-replace-matches "/\\*\\(\\[[^*]+\\]\\)\\*/" "\\1" nil nil expr))
  8051. ;; Remove front operators
  8052. (setq expr (verilog-string-replace-matches "^\\s-*[---+~!|&]+\\s-*" "" nil nil expr))
  8053. ;;
  8054. (cond
  8055. ;; {..., a, b} requires us to recurse on a,b
  8056. ;; To support {#{},{#{a,b}} we'll just split everything on [{},]
  8057. ((string-match "^\\s-*{\\(.*\\)}\\s-*$" expr)
  8058. (unless verilog-auto-ignore-concat
  8059. (let ((mlst (split-string (match-string 1 expr) "[{},]"))
  8060. mstr)
  8061. (while (setq mstr (pop mlst))
  8062. (verilog-read-sub-decls-expr submoddecls comment port mstr)))))
  8063. (t
  8064. (let (sig vec multidim)
  8065. ;; Remove leading reduction operators, etc
  8066. (setq expr (verilog-string-replace-matches "^\\s-*[---+~!|&]+\\s-*" "" nil nil expr))
  8067. ;;(message "vrsde-ptop: `%s'" expr)
  8068. (cond ; Find \signal. Final space is part of escaped signal name
  8069. ((string-match "^\\s-*\\(\\\\[^ \t\n\f]+\\s-\\)" expr)
  8070. ;;(message "vrsde-s: `%s'" (match-string 1 expr))
  8071. (setq sig (match-string 1 expr)
  8072. expr (substring expr (match-end 0))))
  8073. ;; Find signal
  8074. ((string-match "^\\s-*\\([a-zA-Z_][a-zA-Z_0-9]*\\)" expr)
  8075. ;;(message "vrsde-s: `%s'" (match-string 1 expr))
  8076. (setq sig (verilog-string-remove-spaces (match-string 1 expr))
  8077. expr (substring expr (match-end 0)))))
  8078. ;; Find [vector] or [multi][multi][multi][vector]
  8079. (while (string-match "^\\s-*\\(\\[[^]]+\\]\\)" expr)
  8080. ;;(message "vrsde-v: `%s'" (match-string 1 expr))
  8081. (when vec (setq multidim (cons vec multidim)))
  8082. (setq vec (match-string 1 expr)
  8083. expr (substring expr (match-end 0))))
  8084. ;; If found signal, and nothing unrecognized, add the signal
  8085. ;;(message "vrsde-rem: `%s'" expr)
  8086. (when (and sig (string-match "^\\s-*$" expr))
  8087. (verilog-read-sub-decls-sig submoddecls comment port sig vec multidim))))))
  8088. (defun verilog-read-sub-decls-line (submoddecls comment)
  8089. "For `verilog-read-sub-decls', read lines of port defs until none match.
  8090. Inserts the list of signals found, using submodi to look up each port."
  8091. (let (done port)
  8092. (save-excursion
  8093. (forward-line 1)
  8094. (while (not done)
  8095. ;; Get port name
  8096. (cond ((looking-at "\\s-*\\.\\s-*\\([a-zA-Z0-9`_$]*\\)\\s-*(\\s-*")
  8097. (setq port (match-string 1))
  8098. (goto-char (match-end 0)))
  8099. ;; .\escaped (
  8100. ((looking-at "\\s-*\\.\\s-*\\(\\\\[^ \t\n\f]*\\)\\s-*(\\s-*")
  8101. (setq port (concat (match-string 1) " ")) ; escaped id's need trailing space
  8102. (goto-char (match-end 0)))
  8103. ;; .name
  8104. ((looking-at "\\s-*\\.\\s-*\\([a-zA-Z0-9`_$]*\\)\\s-*[,)/]")
  8105. (verilog-read-sub-decls-sig
  8106. submoddecls comment (match-string 1) t ; sig==t for .name
  8107. nil nil) ; vec multidim
  8108. (setq port nil))
  8109. ;; .\escaped_name
  8110. ((looking-at "\\s-*\\.\\s-*\\(\\\\[^ \t\n\f]*\\)\\s-*[,)/]")
  8111. (verilog-read-sub-decls-sig
  8112. submoddecls comment (concat (match-string 1) " ") t ; sig==t for .name
  8113. nil nil) ; vec multidim
  8114. (setq port nil))
  8115. ;; random
  8116. ((looking-at "\\s-*\\.[^(]*(")
  8117. (setq port nil) ; skip this line
  8118. (goto-char (match-end 0)))
  8119. (t
  8120. (setq port nil done t))) ; Unknown, ignore rest of line
  8121. ;; Get signal name. Point is at the first-non-space after (
  8122. ;; We intentionally ignore (non-escaped) signals with .s in them
  8123. ;; this prevents AUTOWIRE etc from noticing hierarchical sigs.
  8124. (when port
  8125. (cond ((looking-at "\\([a-zA-Z_][a-zA-Z_0-9]*\\)\\s-*)")
  8126. (verilog-read-sub-decls-sig
  8127. submoddecls comment port
  8128. (verilog-string-remove-spaces (match-string 1)) ; sig
  8129. nil nil)) ; vec multidim
  8130. ;;
  8131. ((looking-at "\\([a-zA-Z_][a-zA-Z_0-9]*\\)\\s-*\\(\\[[^]]+\\]\\)\\s-*)")
  8132. (verilog-read-sub-decls-sig
  8133. submoddecls comment port
  8134. (verilog-string-remove-spaces (match-string 1)) ; sig
  8135. (match-string 2) nil)) ; vec multidim
  8136. ;; Fastpath was above looking-at's.
  8137. ;; For something more complicated invoke a parser
  8138. ((looking-at "[^)]+")
  8139. (verilog-read-sub-decls-expr
  8140. submoddecls comment port
  8141. (buffer-substring
  8142. (point) (1- (progn (search-backward "(") ; start at (
  8143. (verilog-forward-sexp-ign-cmt 1)
  8144. (point)))))))) ; expr
  8145. ;;
  8146. (forward-line 1)))))
  8147. (defun verilog-read-sub-decls-gate (submoddecls comment submod end-inst-point)
  8148. "For `verilog-read-sub-decls', read lines of UDP gate decl until none match.
  8149. Inserts the list of signals found."
  8150. (save-excursion
  8151. (let ((iolist (cdr (assoc submod verilog-gate-ios))))
  8152. (while (< (point) end-inst-point)
  8153. ;; Get primitive's signal name, as will never have port, and no trailing )
  8154. (cond ((looking-at "//")
  8155. (search-forward "\n"))
  8156. ((looking-at "/\\*")
  8157. (or (search-forward "*/")
  8158. (error "%s: Unmatched /* */, at char %d" (verilog-point-text) (point))))
  8159. ((looking-at "(\\*")
  8160. ;; To advance past either "(*)" or "(* ... *)" don't forward past first *
  8161. (forward-char 1)
  8162. (or (search-forward "*)")
  8163. (error "%s: Unmatched (* *), at char %d" (verilog-point-text) (point))))
  8164. ;; On pins, parse and advance to next pin
  8165. ;; Looking at pin, but *not* an // Output comment, or ) to end the inst
  8166. ((looking-at "\\s-*[a-zA-Z0-9`_$({}\\\\][^,]*")
  8167. (goto-char (match-end 0))
  8168. (setq verilog-read-sub-decls-gate-ios (or (car iolist) "input")
  8169. iolist (cdr iolist))
  8170. (verilog-read-sub-decls-expr
  8171. submoddecls comment "primitive_port"
  8172. (match-string 0)))
  8173. (t
  8174. (forward-char 1)
  8175. (skip-syntax-forward " ")))))))
  8176. (defun verilog-read-sub-decls ()
  8177. "Internally parse signals going to modules under this module.
  8178. Return an array of [ outputs inouts inputs ] signals for modules that are
  8179. instantiated in this module. For example if declare A A (.B(SIG)) and SIG
  8180. is an output, then SIG will be included in the list.
  8181. This only works on instantiations created with /*AUTOINST*/ converted by
  8182. \\[verilog-auto-inst]. Otherwise, it would have to read in the whole
  8183. component library to determine connectivity of the design.
  8184. One work around for this problem is to manually create // Inputs and //
  8185. Outputs comments above subcell signals, for example:
  8186. module ModuleName (
  8187. // Outputs
  8188. .out (out),
  8189. // Inputs
  8190. .in (in));"
  8191. (save-excursion
  8192. (let ((end-mod-point (verilog-get-end-of-defun))
  8193. st-point end-inst-point
  8194. ;; below 3 modified by verilog-read-sub-decls-line
  8195. sigs-out sigs-inout sigs-in sigs-intf sigs-intfd)
  8196. (verilog-beg-of-defun-quick)
  8197. (while (verilog-re-search-forward-quick "\\(/\\*AUTOINST\\*/\\|\\.\\*\\)" end-mod-point t)
  8198. (save-excursion
  8199. (goto-char (match-beginning 0))
  8200. (unless (verilog-inside-comment-or-string-p)
  8201. ;; Attempt to snarf a comment
  8202. (let* ((submod (verilog-read-inst-module))
  8203. (inst (verilog-read-inst-name))
  8204. (subprim (member submod verilog-gate-keywords))
  8205. (comment (concat inst " of " submod ".v"))
  8206. submodi submoddecls)
  8207. (cond
  8208. (subprim
  8209. (setq submodi `primitive
  8210. submoddecls (verilog-decls-new nil nil nil nil nil nil nil nil nil)
  8211. comment (concat inst " of " submod))
  8212. (verilog-backward-open-paren)
  8213. (setq end-inst-point (save-excursion (verilog-forward-sexp-ign-cmt 1)
  8214. (point))
  8215. st-point (point))
  8216. (forward-char 1)
  8217. (verilog-read-sub-decls-gate submoddecls comment submod end-inst-point))
  8218. ;; Non-primitive
  8219. (t
  8220. (when (setq submodi (verilog-modi-lookup submod t))
  8221. (setq submoddecls (verilog-modi-get-decls submodi)
  8222. verilog-read-sub-decls-gate-ios nil)
  8223. (verilog-backward-open-paren)
  8224. (setq end-inst-point (save-excursion (verilog-forward-sexp-ign-cmt 1)
  8225. (point))
  8226. st-point (point))
  8227. ;; This could have used a list created by verilog-auto-inst
  8228. ;; However I want it to be runnable even on user's manually added signals
  8229. (let ((verilog-read-sub-decls-in-interfaced t))
  8230. (while (re-search-forward "\\s *(?\\s *// Interfaced" end-inst-point t)
  8231. (verilog-read-sub-decls-line submoddecls comment))) ; Modifies sigs-ifd
  8232. (goto-char st-point)
  8233. (while (re-search-forward "\\s *(?\\s *// Interfaces" end-inst-point t)
  8234. (verilog-read-sub-decls-line submoddecls comment)) ; Modifies sigs-out
  8235. (goto-char st-point)
  8236. (while (re-search-forward "\\s *(?\\s *// Outputs" end-inst-point t)
  8237. (verilog-read-sub-decls-line submoddecls comment)) ; Modifies sigs-out
  8238. (goto-char st-point)
  8239. (while (re-search-forward "\\s *(?\\s *// Inouts" end-inst-point t)
  8240. (verilog-read-sub-decls-line submoddecls comment)) ; Modifies sigs-inout
  8241. (goto-char st-point)
  8242. (while (re-search-forward "\\s *(?\\s *// Inputs" end-inst-point t)
  8243. (verilog-read-sub-decls-line submoddecls comment)) ; Modifies sigs-in
  8244. )))))))
  8245. ;; Combine duplicate bits
  8246. ;;(setq rr (vector sigs-out sigs-inout sigs-in))
  8247. (verilog-subdecls-new
  8248. (verilog-signals-combine-bus (nreverse sigs-out))
  8249. (verilog-signals-combine-bus (nreverse sigs-inout))
  8250. (verilog-signals-combine-bus (nreverse sigs-in))
  8251. (verilog-signals-combine-bus (nreverse sigs-intf))
  8252. (verilog-signals-combine-bus (nreverse sigs-intfd))))))
  8253. (defun verilog-read-inst-pins ()
  8254. "Return an array of [ pins ] for the current instantiation at point.
  8255. For example if declare A A (.B(SIG)) then B will be included in the list."
  8256. (save-excursion
  8257. (let ((end-mod-point (point)) ; presume at /*AUTOINST*/ point
  8258. pins pin)
  8259. (verilog-backward-open-paren)
  8260. (while (re-search-forward "\\.\\([^(,) \t\n\f]*\\)\\s-*" end-mod-point t)
  8261. (setq pin (match-string 1))
  8262. (unless (verilog-inside-comment-or-string-p)
  8263. (setq pins (cons (list pin) pins))
  8264. (when (looking-at "(")
  8265. (verilog-forward-sexp-ign-cmt 1))))
  8266. (vector pins))))
  8267. (defun verilog-read-arg-pins ()
  8268. "Return an array of [ pins ] for the current argument declaration at point."
  8269. (save-excursion
  8270. (let ((end-mod-point (point)) ; presume at /*AUTOARG*/ point
  8271. pins pin)
  8272. (verilog-backward-open-paren)
  8273. (while (re-search-forward "\\([a-zA-Z0-9$_.%`]+\\)" end-mod-point t)
  8274. (setq pin (match-string 1))
  8275. (unless (verilog-inside-comment-or-string-p)
  8276. (setq pins (cons (list pin) pins))))
  8277. (vector pins))))
  8278. (defun verilog-read-auto-constants (beg end-mod-point)
  8279. "Return a list of AUTO_CONSTANTs used in the region from BEG to END-MOD-POINT."
  8280. ;; Insert new
  8281. (save-excursion
  8282. (let (sig-list tpl-end-pt)
  8283. (goto-char beg)
  8284. (while (re-search-forward "\\<AUTO_CONSTANT" end-mod-point t)
  8285. (if (not (looking-at "\\s *("))
  8286. (error "%s: Missing () after AUTO_CONSTANT" (verilog-point-text)))
  8287. (search-forward "(" end-mod-point)
  8288. (setq tpl-end-pt (save-excursion
  8289. (backward-char 1)
  8290. (verilog-forward-sexp-cmt 1) ; Moves to paren that closes argdecl's
  8291. (backward-char 1)
  8292. (point)))
  8293. (while (re-search-forward "\\s-*\\([\"a-zA-Z0-9$_.%`]+\\)\\s-*,*" tpl-end-pt t)
  8294. (setq sig-list (cons (list (match-string 1) nil nil) sig-list))))
  8295. sig-list)))
  8296. (defvar verilog-cache-has-lisp nil "True if any AUTO_LISP in buffer.")
  8297. (make-variable-buffer-local 'verilog-cache-has-lisp)
  8298. (defun verilog-read-auto-lisp-present ()
  8299. "Set `verilog-cache-has-lisp' if any AUTO_LISP in this buffer."
  8300. (save-excursion
  8301. (goto-char (point-min))
  8302. (setq verilog-cache-has-lisp (re-search-forward "\\<AUTO_LISP(" nil t))))
  8303. (defun verilog-read-auto-lisp (start end)
  8304. "Look for and evaluate an AUTO_LISP between START and END.
  8305. Must call `verilog-read-auto-lisp-present' before this function."
  8306. ;; This function is expensive for large buffers, so we cache if any AUTO_LISP exists
  8307. (when verilog-cache-has-lisp
  8308. (save-excursion
  8309. (goto-char start)
  8310. (while (re-search-forward "\\<AUTO_LISP(" end t)
  8311. (backward-char)
  8312. (let* ((beg-pt (prog1 (point)
  8313. (verilog-forward-sexp-cmt 1))) ; Closing paren
  8314. (end-pt (point))
  8315. (verilog-in-hooks t))
  8316. (eval-region beg-pt end-pt nil))))))
  8317. (defun verilog-read-always-signals-recurse
  8318. (exit-keywd rvalue temp-next)
  8319. "Recursive routine for parentheses/bracket matching.
  8320. EXIT-KEYWD is expression to stop at, nil if top level.
  8321. RVALUE is true if at right hand side of equal.
  8322. IGNORE-NEXT is true to ignore next token, fake from inside case statement."
  8323. (let* ((semi-rvalue (equal "endcase" exit-keywd)) ; true if after a ; we are looking for rvalue
  8324. keywd last-keywd sig-tolk sig-last-tolk gotend got-sig got-list end-else-check
  8325. ignore-next)
  8326. ;;(if dbg (setq dbg (concat dbg (format "Recursion %S %S %S\n" exit-keywd rvalue temp-next))))
  8327. (while (not (or (eobp) gotend))
  8328. (cond
  8329. ((looking-at "//")
  8330. (search-forward "\n"))
  8331. ((looking-at "/\\*")
  8332. (or (search-forward "*/")
  8333. (error "%s: Unmatched /* */, at char %d" (verilog-point-text) (point))))
  8334. ((looking-at "(\\*")
  8335. ;; To advance past either "(*)" or "(* ... *)" don't forward past first *
  8336. (forward-char 1)
  8337. (or (search-forward "*)")
  8338. (error "%s: Unmatched (* *), at char %d" (verilog-point-text) (point))))
  8339. (t (setq keywd (buffer-substring-no-properties
  8340. (point)
  8341. (save-excursion (when (eq 0 (skip-chars-forward "a-zA-Z0-9$_.%`"))
  8342. (forward-char 1))
  8343. (point)))
  8344. sig-last-tolk sig-tolk
  8345. sig-tolk nil)
  8346. ;;(if dbg (setq dbg (concat dbg (format "\tPt=%S %S\trv=%S in=%S ee=%S gs=%S\n" (point) keywd rvalue ignore-next end-else-check got-sig))))
  8347. (cond
  8348. ((equal keywd "\"")
  8349. (or (re-search-forward "[^\\]\"" nil t)
  8350. (error "%s: Unmatched quotes, at char %d" (verilog-point-text) (point))))
  8351. ;; else at top level loop, keep parsing
  8352. ((and end-else-check (equal keywd "else"))
  8353. ;;(if dbg (setq dbg (concat dbg (format "\tif-check-else %s\n" keywd))))
  8354. ;; no forward movement, want to see else in lower loop
  8355. (setq end-else-check nil))
  8356. ;; End at top level loop
  8357. ((and end-else-check (looking-at "[^ \t\n\f]"))
  8358. ;;(if dbg (setq dbg (concat dbg (format "\tif-check-else-other %s\n" keywd))))
  8359. (setq gotend t))
  8360. ;; Final statement?
  8361. ((and exit-keywd (equal keywd exit-keywd))
  8362. (setq gotend t)
  8363. (forward-char (length keywd)))
  8364. ;; Standard tokens...
  8365. ((equal keywd ";")
  8366. (setq ignore-next nil rvalue semi-rvalue)
  8367. ;; Final statement at top level loop?
  8368. (when (not exit-keywd)
  8369. ;;(if dbg (setq dbg (concat dbg (format "\ttop-end-check %s\n" keywd))))
  8370. (setq end-else-check t))
  8371. (forward-char 1))
  8372. ((equal keywd "'")
  8373. (if (looking-at "'[sS]?[hdxboHDXBO]?[ \t]*[0-9a-fA-F_xzXZ?]+")
  8374. (goto-char (match-end 0))
  8375. (forward-char 1)))
  8376. ((equal keywd ":") ; Case statement, begin/end label, x?y:z
  8377. (cond ((equal "endcase" exit-keywd) ; case x: y=z; statement next
  8378. (setq ignore-next nil rvalue nil))
  8379. ((equal "?" exit-keywd) ; x?y:z rvalue
  8380. ) ; NOP
  8381. ((equal "]" exit-keywd) ; [x:y] rvalue
  8382. ) ; NOP
  8383. (got-sig ; label: statement
  8384. (setq ignore-next nil rvalue semi-rvalue got-sig nil))
  8385. ((not rvalue) ; begin label
  8386. (setq ignore-next t rvalue nil)))
  8387. (forward-char 1))
  8388. ((equal keywd "=")
  8389. (when got-sig
  8390. ;;(if dbg (setq dbg (concat dbg (format "\t\tequal got-sig=%S got-list=%s\n" got-sig got-list))))
  8391. (set got-list (cons got-sig (symbol-value got-list)))
  8392. (setq got-sig nil))
  8393. (when (not rvalue)
  8394. (if (eq (char-before) ?< )
  8395. (setq sigs-out-d (append sigs-out-d sigs-out-unk)
  8396. sigs-out-unk nil)
  8397. (setq sigs-out-i (append sigs-out-i sigs-out-unk)
  8398. sigs-out-unk nil)))
  8399. (setq ignore-next nil rvalue t)
  8400. (forward-char 1))
  8401. ((equal keywd "?")
  8402. (forward-char 1)
  8403. (verilog-read-always-signals-recurse ":" rvalue nil))
  8404. ((equal keywd "[")
  8405. (forward-char 1)
  8406. (verilog-read-always-signals-recurse "]" t nil))
  8407. ((equal keywd "(")
  8408. (forward-char 1)
  8409. (cond (sig-last-tolk ; Function call; zap last signal
  8410. (setq got-sig nil)))
  8411. (cond ((equal last-keywd "for")
  8412. ;; temp-next: Variables on LHS are lvalues, but generally we want
  8413. ;; to ignore them, assuming they are loop increments
  8414. (verilog-read-always-signals-recurse ";" nil t)
  8415. (verilog-read-always-signals-recurse ";" t nil)
  8416. (verilog-read-always-signals-recurse ")" nil nil))
  8417. (t (verilog-read-always-signals-recurse ")" t nil))))
  8418. ((equal keywd "begin")
  8419. (skip-syntax-forward "w_")
  8420. (verilog-read-always-signals-recurse "end" nil nil)
  8421. ;;(if dbg (setq dbg (concat dbg (format "\tgot-end %s\n" exit-keywd))))
  8422. (setq ignore-next nil rvalue semi-rvalue)
  8423. (if (not exit-keywd) (setq end-else-check t)))
  8424. ((member keywd '("case" "casex" "casez"))
  8425. (skip-syntax-forward "w_")
  8426. (verilog-read-always-signals-recurse "endcase" t nil)
  8427. (setq ignore-next nil rvalue semi-rvalue)
  8428. (if (not exit-keywd) (setq gotend t))) ; top level begin/end
  8429. ((string-match "^[$`a-zA-Z_]" keywd) ; not exactly word constituent
  8430. (cond ((member keywd '("`ifdef" "`ifndef" "`elsif"))
  8431. (setq ignore-next t))
  8432. ((or ignore-next
  8433. (member keywd verilog-keywords)
  8434. (string-match "^\\$" keywd)) ; PLI task
  8435. (setq ignore-next nil))
  8436. (t
  8437. (setq keywd (verilog-symbol-detick-denumber keywd))
  8438. (when got-sig
  8439. (set got-list (cons got-sig (symbol-value got-list)))
  8440. ;;(if dbg (setq dbg (concat dbg (format "\t\tgot-sig=%S got-list=%S\n" got-sig got-list))))
  8441. )
  8442. (setq got-list (cond (temp-next 'sigs-temp)
  8443. (rvalue 'sigs-in)
  8444. (t 'sigs-out-unk))
  8445. got-sig (if (or (not keywd)
  8446. (assoc keywd (symbol-value got-list)))
  8447. nil (list keywd nil nil))
  8448. temp-next nil
  8449. sig-tolk t)))
  8450. (skip-chars-forward "a-zA-Z0-9$_.%`"))
  8451. (t
  8452. (forward-char 1)))
  8453. ;; End of non-comment token
  8454. (setq last-keywd keywd)))
  8455. (skip-syntax-forward " "))
  8456. ;; Append the final pending signal
  8457. (when got-sig
  8458. ;;(if dbg (setq dbg (concat dbg (format "\t\tfinal got-sig=%S got-list=%s\n" got-sig got-list))))
  8459. (set got-list (cons got-sig (symbol-value got-list)))
  8460. (setq got-sig nil))
  8461. ;;(if dbg (setq dbg (concat dbg (format "ENDRecursion %s\n" exit-keywd))))
  8462. ))
  8463. (defun verilog-read-always-signals ()
  8464. "Parse always block at point and return list of (outputs inout inputs)."
  8465. (save-excursion
  8466. (let* (;(dbg "")
  8467. sigs-out-d sigs-out-i sigs-out-unk sigs-temp sigs-in)
  8468. (verilog-read-always-signals-recurse nil nil nil)
  8469. (setq sigs-out-i (append sigs-out-i sigs-out-unk)
  8470. sigs-out-unk nil)
  8471. ;;(if dbg (with-current-buffer (get-buffer-create "*vl-dbg*")) (delete-region (point-min) (point-max)) (insert dbg) (setq dbg ""))
  8472. ;; Return what was found
  8473. (verilog-alw-new sigs-out-d sigs-out-i sigs-temp sigs-in))))
  8474. (defun verilog-read-instants ()
  8475. "Parse module at point and return list of ( ( file instance ) ... )."
  8476. (verilog-beg-of-defun-quick)
  8477. (let* ((end-mod-point (verilog-get-end-of-defun))
  8478. (state nil)
  8479. (instants-list nil))
  8480. (save-excursion
  8481. (while (< (point) end-mod-point)
  8482. ;; Stay at level 0, no comments
  8483. (while (progn
  8484. (setq state (parse-partial-sexp (point) end-mod-point 0 t nil))
  8485. (or (> (car state) 0) ; in parens
  8486. (nth 5 state) ; comment
  8487. ))
  8488. (forward-line 1))
  8489. (beginning-of-line)
  8490. (if (looking-at "^\\s-*\\([a-zA-Z0-9`_$]+\\)\\s-+\\([a-zA-Z0-9`_$]+\\)\\s-*(")
  8491. ;;(if (looking-at "^\\(.+\\)$")
  8492. (let ((module (match-string 1))
  8493. (instant (match-string 2)))
  8494. (if (not (member module verilog-keywords))
  8495. (setq instants-list (cons (list module instant) instants-list)))))
  8496. (forward-line 1)))
  8497. instants-list))
  8498. (defun verilog-read-auto-template-middle ()
  8499. "With point in middle of an AUTO_TEMPLATE, parse it.
  8500. Returns REGEXP and list of ( (signal_name connection_name)... )."
  8501. (save-excursion
  8502. ;; Find beginning
  8503. (let ((tpl-regexp "\\([0-9]+\\)")
  8504. (lineno -1) ; -1 to offset for the AUTO_TEMPLATE's newline
  8505. (templateno 0)
  8506. tpl-sig-list tpl-wild-list tpl-end-pt rep)
  8507. ;; Parse "REGEXP"
  8508. ;; We reserve @"..." for future lisp expressions that evaluate
  8509. ;; once-per-AUTOINST
  8510. (when (looking-at "\\s-*\"\\([^\"]*\\)\"")
  8511. (setq tpl-regexp (match-string 1))
  8512. (goto-char (match-end 0)))
  8513. (search-forward "(")
  8514. ;; Parse lines in the template
  8515. (when (or verilog-auto-inst-template-numbers
  8516. verilog-auto-template-warn-unused)
  8517. (save-excursion
  8518. (let ((pre-pt (point)))
  8519. (goto-char (point-min))
  8520. (while (search-forward "AUTO_TEMPLATE" pre-pt t)
  8521. (setq templateno (1+ templateno)))
  8522. (while (< (point) pre-pt)
  8523. (forward-line 1)
  8524. (setq lineno (1+ lineno))))))
  8525. (setq tpl-end-pt (save-excursion
  8526. (backward-char 1)
  8527. (verilog-forward-sexp-cmt 1) ; Moves to paren that closes argdecl's
  8528. (backward-char 1)
  8529. (point)))
  8530. ;;
  8531. (while (< (point) tpl-end-pt)
  8532. (cond ((looking-at "\\s-*\\.\\([a-zA-Z0-9`_$]+\\)\\s-*(\\(.*\\))\\s-*\\(,\\|)\\s-*;\\)")
  8533. (setq tpl-sig-list
  8534. (cons (list
  8535. (match-string-no-properties 1)
  8536. (match-string-no-properties 2)
  8537. templateno lineno)
  8538. tpl-sig-list))
  8539. (goto-char (match-end 0)))
  8540. ;; Regexp form??
  8541. ((looking-at
  8542. ;; Regexp bug in XEmacs disallows ][ inside [], and wants + last
  8543. "\\s-*\\.\\(\\([a-zA-Z0-9`_$+@^.*?|---]+\\|[][]\\|\\\\[()|]\\)+\\)\\s-*(\\(.*\\))\\s-*\\(,\\|)\\s-*;\\)")
  8544. (setq rep (match-string-no-properties 3))
  8545. (goto-char (match-end 0))
  8546. (setq tpl-wild-list
  8547. (cons (list
  8548. (concat "^"
  8549. (verilog-string-replace-matches "@" "\\\\([0-9]+\\\\)" nil nil
  8550. (match-string 1))
  8551. "$")
  8552. rep
  8553. templateno lineno)
  8554. tpl-wild-list)))
  8555. ((looking-at "[ \t\f]+")
  8556. (goto-char (match-end 0)))
  8557. ((looking-at "\n")
  8558. (setq lineno (1+ lineno))
  8559. (goto-char (match-end 0)))
  8560. ((looking-at "//")
  8561. (search-forward "\n")
  8562. (setq lineno (1+ lineno)))
  8563. ((looking-at "/\\*")
  8564. (forward-char 2)
  8565. (or (search-forward "*/")
  8566. (error "%s: Unmatched /* */, at char %d" (verilog-point-text) (point))))
  8567. (t
  8568. (error "%s: AUTO_TEMPLATE parsing error: %s"
  8569. (verilog-point-text)
  8570. (progn (looking-at ".*$") (match-string 0))))))
  8571. ;; Return
  8572. (vector tpl-regexp
  8573. (list tpl-sig-list tpl-wild-list)))))
  8574. (defun verilog-read-auto-template (module)
  8575. "Look for an auto_template for the instantiation of the given MODULE.
  8576. If found returns `verilog-read-auto-template-inside' structure."
  8577. (save-excursion
  8578. ;; Find beginning
  8579. (let ((pt (point)))
  8580. ;; Note this search is expensive, as we hunt from mod-begin to point
  8581. ;; for every instantiation. Likewise in verilog-read-auto-lisp.
  8582. ;; So, we look first for an exact string rather than a slow regexp.
  8583. ;; Someday we may keep a cache of every template, but this would also
  8584. ;; need to record the relative position of each AUTOINST, as multiple
  8585. ;; templates exist for each module, and we're inserting lines.
  8586. (cond ((or
  8587. ;; See also regexp in `verilog-auto-template-lint'
  8588. (verilog-re-search-backward-substr
  8589. "AUTO_TEMPLATE"
  8590. (concat "^\\s-*/?\\*?\\s-*" module "\\s-+AUTO_TEMPLATE") nil t)
  8591. ;; Also try forward of this AUTOINST
  8592. ;; This is for historical support; this isn't speced as working
  8593. (progn
  8594. (goto-char pt)
  8595. (verilog-re-search-forward-substr
  8596. "AUTO_TEMPLATE"
  8597. (concat "^\\s-*/?\\*?\\s-*" module "\\s-+AUTO_TEMPLATE") nil t)))
  8598. (goto-char (match-end 0))
  8599. (verilog-read-auto-template-middle))
  8600. ;; If no template found
  8601. (t (vector "" nil))))))
  8602. ;;(progn (find-file "auto-template.v") (verilog-read-auto-template "ptl_entry"))
  8603. (defvar verilog-auto-template-hits nil "Successful lookups with `verilog-read-auto-template-hit'.")
  8604. (make-variable-buffer-local 'verilog-auto-template-hits)
  8605. (defun verilog-read-auto-template-init ()
  8606. "Initialize `verilog-read-auto-template'."
  8607. (when (eval-when-compile (fboundp 'make-hash-table)) ; else feature not allowed
  8608. (when verilog-auto-template-warn-unused
  8609. (setq verilog-auto-template-hits
  8610. (make-hash-table :test 'equal :rehash-size 4.0)))))
  8611. (defun verilog-read-auto-template-hit (tpl-ass)
  8612. "Record that TPL-ASS template from `verilog-read-auto-template' was used."
  8613. (when (eval-when-compile (fboundp 'make-hash-table)) ; else feature not allowed
  8614. (when verilog-auto-template-warn-unused
  8615. (unless verilog-auto-template-hits
  8616. (verilog-read-auto-template-init))
  8617. (puthash (vector (nth 2 tpl-ass) (nth 3 tpl-ass)) t
  8618. verilog-auto-template-hits))))
  8619. (defun verilog-set-define (defname defvalue &optional buffer enumname)
  8620. "Set the definition DEFNAME to the DEFVALUE in the given BUFFER.
  8621. Optionally associate it with the specified enumeration ENUMNAME."
  8622. (with-current-buffer (or buffer (current-buffer))
  8623. ;; Namespace intentionally short for AUTOs and compatibility
  8624. (let ((mac (intern (concat "vh-" defname))))
  8625. ;;(message "Define %s=%s" defname defvalue) (sleep-for 1)
  8626. ;; Need to define to a constant if no value given
  8627. (set (make-local-variable mac)
  8628. (if (equal defvalue "") "1" defvalue)))
  8629. (if enumname
  8630. ;; Namespace intentionally short for AUTOs and compatibility
  8631. (let ((enumvar (intern (concat "venum-" enumname))))
  8632. ;;(message "Define %s=%s" defname defvalue) (sleep-for 1)
  8633. (unless (boundp enumvar) (set enumvar nil))
  8634. (add-to-list (make-local-variable enumvar) defname)))))
  8635. (defun verilog-read-defines (&optional filename recurse subcall)
  8636. "Read \\=`defines and parameters for the current file, or optional FILENAME.
  8637. If the filename is provided, `verilog-library-flags' will be used to
  8638. resolve it. If optional RECURSE is non-nil, recurse through \\=`includes.
  8639. Parameters must be simple assignments to constants, or have their own
  8640. \"parameter\" label rather than a list of parameters. Thus:
  8641. parameter X = 5, Y = 10; // Ok
  8642. parameter X = {1\\='b1, 2\\='h2}; // Ok
  8643. parameter X = {1\\='b1, 2\\='h2}, Y = 10; // Bad, make into 2 parameter lines
  8644. Defines must be simple text substitutions, one on a line, starting
  8645. at the beginning of the line. Any ifdefs or multiline comments around the
  8646. define are ignored.
  8647. Defines are stored inside Emacs variables using the name vh-{definename}.
  8648. This function is useful for setting vh-* variables. The file variables
  8649. feature can be used to set defines that `verilog-mode' can see; put at the
  8650. *END* of your file something like:
  8651. // Local Variables:
  8652. // vh-macro:\"macro_definition\"
  8653. // End:
  8654. If macros are defined earlier in the same file and you want their values,
  8655. you can read them automatically (provided `enable-local-eval' is on):
  8656. // Local Variables:
  8657. // eval:(verilog-read-defines)
  8658. // eval:(verilog-read-defines \"group_standard_includes.v\")
  8659. // End:
  8660. Note these are only read when the file is first visited, you must use
  8661. \\[find-alternate-file] RET to have these take effect after editing them!
  8662. If you want to disable the \"Process `eval' or hook local variables\"
  8663. warning message, you need to add to your init file:
  8664. (setq enable-local-eval t)"
  8665. (let ((origbuf (current-buffer)))
  8666. (save-excursion
  8667. (unless subcall (verilog-getopt-flags))
  8668. (when filename
  8669. (let ((fns (verilog-library-filenames filename (buffer-file-name))))
  8670. (if fns
  8671. (set-buffer (find-file-noselect (car fns)))
  8672. (error "%s: Can't find verilog-read-defines file: %s"
  8673. (verilog-point-text) filename))))
  8674. (when recurse
  8675. (goto-char (point-min))
  8676. (while (re-search-forward "^\\s-*`include\\s-+\\([^ \t\n\f]+\\)" nil t)
  8677. (let ((inc (verilog-string-replace-matches
  8678. "\"" "" nil nil (match-string-no-properties 1))))
  8679. (unless (verilog-inside-comment-or-string-p)
  8680. (verilog-read-defines inc recurse t)))))
  8681. ;; Read `defines
  8682. ;; note we don't use verilog-re... it's faster this way, and that
  8683. ;; function has problems when comments are at the end of the define
  8684. (goto-char (point-min))
  8685. (while (re-search-forward "^\\s-*`define\\s-+\\([a-zA-Z0-9_$]+\\)\\s-+\\(.*\\)$" nil t)
  8686. (let ((defname (match-string-no-properties 1))
  8687. (defvalue (match-string-no-properties 2)))
  8688. (unless (verilog-inside-comment-or-string-p (match-beginning 0))
  8689. (setq defvalue (verilog-string-replace-matches "\\s-*/[/*].*$" "" nil nil defvalue))
  8690. (verilog-set-define defname defvalue origbuf))))
  8691. ;; Hack: Read parameters
  8692. (goto-char (point-min))
  8693. (while (re-search-forward
  8694. "^\\s-*\\(parameter\\|localparam\\)\\(\\s-*\\[[^]]*\\]\\)?\\s-*" nil t)
  8695. (let (enumname)
  8696. ;; The primary way of getting defines is verilog-read-decls
  8697. ;; However, that isn't called yet for included files, so we'll add another scheme
  8698. (if (looking-at "[^\n]*\\(auto\\|synopsys\\)\\s +enum\\s +\\([a-zA-Z0-9_]+\\)")
  8699. (setq enumname (match-string-no-properties 2)))
  8700. (forward-comment 99999)
  8701. (while (looking-at (concat "\\s-*,?\\s-*\\(?:/[/*].*?$\\)?\\s-*\\([a-zA-Z0-9_$]+\\)"
  8702. "\\s-*=\\s-*\\([^;,]*\\),?\\s-*\\(/[/*].*?$\\)?\\s-*"))
  8703. (unless (verilog-inside-comment-or-string-p (match-beginning 0))
  8704. (verilog-set-define (match-string-no-properties 1)
  8705. (match-string-no-properties 2) origbuf enumname))
  8706. (goto-char (match-end 0))
  8707. (forward-comment 99999)))))))
  8708. (defun verilog-read-includes ()
  8709. "Read \\=`includes for the current file.
  8710. This will find all of the \\=`includes which are at the beginning of lines,
  8711. ignoring any ifdefs or multiline comments around them.
  8712. `verilog-read-defines' is then performed on the current and each included
  8713. file.
  8714. It is often useful put at the *END* of your file something like:
  8715. // Local Variables:
  8716. // eval:(verilog-read-defines)
  8717. // eval:(verilog-read-includes)
  8718. // End:
  8719. Note includes are only read when the file is first visited, you must use
  8720. \\[find-alternate-file] RET to have these take effect after editing them!
  8721. It is good to get in the habit of including all needed files in each .v
  8722. file that needs it, rather than waiting for compile time. This will aid
  8723. this process, Verilint, and readability. To prevent defining the same
  8724. variable over and over when many modules are compiled together, put a test
  8725. around the inside each include file:
  8726. foo.v (an include file):
  8727. \\=`ifdef _FOO_V // include if not already included
  8728. \\=`else
  8729. \\=`define _FOO_V
  8730. ... contents of file
  8731. \\=`endif // _FOO_V"
  8732. ;;slow: (verilog-read-defines nil t)
  8733. (save-excursion
  8734. (verilog-getopt-flags)
  8735. (goto-char (point-min))
  8736. (while (re-search-forward "^\\s-*`include\\s-+\\([^ \t\n\f]+\\)" nil t)
  8737. (let ((inc (verilog-string-replace-matches "\"" "" nil nil (match-string 1))))
  8738. (verilog-read-defines inc nil t)))))
  8739. (defun verilog-read-signals (&optional start end)
  8740. "Return a simple list of all possible signals in the file.
  8741. Bounded by optional region from START to END. Overly aggressive but fast.
  8742. Some macros and such are also found and included. For dinotrace.el."
  8743. (let (sigs-all keywd)
  8744. (progn;save-excursion
  8745. (goto-char (or start (point-min)))
  8746. (setq end (or end (point-max)))
  8747. (while (re-search-forward "[\"/a-zA-Z_.%`]" end t)
  8748. (forward-char -1)
  8749. (cond
  8750. ((looking-at "//")
  8751. (search-forward "\n"))
  8752. ((looking-at "/\\*")
  8753. (search-forward "*/"))
  8754. ((looking-at "(\\*")
  8755. (or (looking-at "(\\*\\s-*)") ; It's an "always @ (*)"
  8756. (search-forward "*)")))
  8757. ((eq ?\" (following-char))
  8758. (re-search-forward "[^\\]\"")) ; don't forward-char first, since we look for a non backslash first
  8759. ((looking-at "\\s-*\\([a-zA-Z0-9$_.%`]+\\)")
  8760. (goto-char (match-end 0))
  8761. (setq keywd (match-string-no-properties 1))
  8762. (or (member keywd verilog-keywords)
  8763. (member keywd sigs-all)
  8764. (setq sigs-all (cons keywd sigs-all))))
  8765. (t (forward-char 1))))
  8766. ;; Return list
  8767. sigs-all)))
  8768. ;;
  8769. ;; Argument file parsing
  8770. ;;
  8771. (defun verilog-getopt (arglist)
  8772. "Parse -f, -v etc arguments in ARGLIST list or string."
  8773. (unless (listp arglist) (setq arglist (list arglist)))
  8774. (let ((space-args '())
  8775. arg next-param)
  8776. ;; Split on spaces, so users can pass whole command lines
  8777. (while arglist
  8778. (setq arg (car arglist)
  8779. arglist (cdr arglist))
  8780. (while (string-match "^\\([^ \t\n\f]+\\)[ \t\n\f]*\\(.*$\\)" arg)
  8781. (setq space-args (append space-args
  8782. (list (match-string-no-properties 1 arg))))
  8783. (setq arg (match-string 2 arg))))
  8784. ;; Parse arguments
  8785. (while space-args
  8786. (setq arg (car space-args)
  8787. space-args (cdr space-args))
  8788. (cond
  8789. ;; Need another arg
  8790. ((equal arg "-f")
  8791. (setq next-param arg))
  8792. ((equal arg "-v")
  8793. (setq next-param arg))
  8794. ((equal arg "-y")
  8795. (setq next-param arg))
  8796. ;; +libext+(ext1)+(ext2)...
  8797. ((string-match "^\\+libext\\+\\(.*\\)" arg)
  8798. (setq arg (match-string 1 arg))
  8799. (while (string-match "\\([^+]+\\)\\+?\\(.*\\)" arg)
  8800. (verilog-add-list-unique `verilog-library-extensions
  8801. (match-string 1 arg))
  8802. (setq arg (match-string 2 arg))))
  8803. ;;
  8804. ((or (string-match "^-D\\([^+=]*\\)[+=]\\(.*\\)" arg) ; -Ddefine=val
  8805. (string-match "^-D\\([^+=]*\\)\\(\\)" arg) ; -Ddefine
  8806. (string-match "^\\+define\\([^+=]*\\)[+=]\\(.*\\)" arg) ; +define+val
  8807. (string-match "^\\+define\\([^+=]*\\)\\(\\)" arg)) ; +define+define
  8808. (verilog-set-define (match-string 1 arg) (match-string 2 arg)))
  8809. ;;
  8810. ((or (string-match "^\\+incdir\\+\\(.*\\)" arg) ; +incdir+dir
  8811. (string-match "^-I\\(.*\\)" arg)) ; -Idir
  8812. (verilog-add-list-unique `verilog-library-directories
  8813. (match-string 1 (substitute-in-file-name arg))))
  8814. ;; Ignore
  8815. ((equal "+librescan" arg))
  8816. ((string-match "^-U\\(.*\\)" arg)) ; -Udefine
  8817. ;; Second parameters
  8818. ((equal next-param "-f")
  8819. (setq next-param nil)
  8820. (verilog-getopt-file (substitute-in-file-name arg)))
  8821. ((equal next-param "-v")
  8822. (setq next-param nil)
  8823. (verilog-add-list-unique `verilog-library-files
  8824. (substitute-in-file-name arg)))
  8825. ((equal next-param "-y")
  8826. (setq next-param nil)
  8827. (verilog-add-list-unique `verilog-library-directories
  8828. (substitute-in-file-name arg)))
  8829. ;; Filename
  8830. ((string-match "^[^-+]" arg)
  8831. (verilog-add-list-unique `verilog-library-files
  8832. (substitute-in-file-name arg)))
  8833. ;; Default - ignore; no warning
  8834. ))))
  8835. ;;(verilog-getopt (list "+libext+.a+.b" "+incdir+foodir" "+define+a+aval" "-f" "otherf" "-v" "library" "-y" "dir"))
  8836. (defun verilog-getopt-file (filename)
  8837. "Read Verilog options from the specified FILENAME."
  8838. (save-excursion
  8839. (let ((fns (verilog-library-filenames filename (buffer-file-name)))
  8840. (orig-buffer (current-buffer))
  8841. line)
  8842. (if fns
  8843. (set-buffer (find-file-noselect (car fns)))
  8844. (error "%s: Can't find verilog-getopt-file -f file: %s"
  8845. (verilog-point-text) filename))
  8846. (goto-char (point-min))
  8847. (while (not (eobp))
  8848. (setq line (buffer-substring (point) (point-at-eol)))
  8849. (forward-line 1)
  8850. (when (string-match "//" line)
  8851. (setq line (substring line 0 (match-beginning 0))))
  8852. (with-current-buffer orig-buffer ; Variables are buffer-local, so need right context.
  8853. (verilog-getopt line))))))
  8854. (defun verilog-getopt-flags ()
  8855. "Convert `verilog-library-flags' into standard library variables."
  8856. ;; If the flags are local, then all the outputs should be local also
  8857. (when (local-variable-p `verilog-library-flags (current-buffer))
  8858. (mapc 'make-local-variable '(verilog-library-extensions
  8859. verilog-library-directories
  8860. verilog-library-files
  8861. verilog-library-flags)))
  8862. ;; Allow user to customize
  8863. (verilog-run-hooks 'verilog-before-getopt-flags-hook)
  8864. ;; Process arguments
  8865. (verilog-getopt verilog-library-flags)
  8866. ;; Allow user to customize
  8867. (verilog-run-hooks 'verilog-getopt-flags-hook))
  8868. (defun verilog-add-list-unique (varref object)
  8869. "Append to VARREF list the given OBJECT,
  8870. unless it is already a member of the variable's list."
  8871. (unless (member object (symbol-value varref))
  8872. (set varref (append (symbol-value varref) (list object))))
  8873. varref)
  8874. ;;(progn (setq l '()) (verilog-add-list-unique `l "a") (verilog-add-list-unique `l "a") l)
  8875. (defun verilog-current-flags ()
  8876. "Convert `verilog-library-flags' and similar variables to command line.
  8877. Used for __FLAGS__ in `verilog-expand-command'."
  8878. (let ((cmd (mapconcat `concat verilog-library-flags " ")))
  8879. (when (equal cmd "")
  8880. (setq cmd (concat
  8881. "+libext+" (mapconcat `concat verilog-library-extensions "+")
  8882. (mapconcat (lambda (i) (concat " -y " i " +incdir+" i))
  8883. verilog-library-directories "")
  8884. (mapconcat (lambda (i) (concat " -v " i))
  8885. verilog-library-files ""))))
  8886. cmd))
  8887. ;;(verilog-current-flags)
  8888. ;;; Cached directory support:
  8889. ;;
  8890. (defvar verilog-dir-cache-preserving nil
  8891. "If true, the directory cache is enabled, and file system changes are ignored.
  8892. See `verilog-dir-exists-p' and `verilog-dir-files'.")
  8893. ;; If adding new cached variable, add also to verilog-preserve-dir-cache
  8894. (defvar verilog-dir-cache-list nil
  8895. "Alist of (((Cwd Dirname) Results)...) for caching `verilog-dir-files'.")
  8896. (defvar verilog-dir-cache-lib-filenames nil
  8897. "Cached data for `verilog-library-filenames'.")
  8898. (defmacro verilog-preserve-dir-cache (&rest body)
  8899. "Execute the BODY forms, allowing directory cache preservation within BODY.
  8900. This means that changes inside BODY made to the file system will not be
  8901. seen by the `verilog-dir-files' and related functions."
  8902. `(let ((verilog-dir-cache-preserving (current-buffer))
  8903. verilog-dir-cache-list
  8904. verilog-dir-cache-lib-filenames)
  8905. (progn ,@body)))
  8906. (defun verilog-dir-files (dirname)
  8907. "Return all filenames in the DIRNAME directory.
  8908. Relative paths depend on the `default-directory'.
  8909. Results are cached if inside `verilog-preserve-dir-cache'."
  8910. (unless verilog-dir-cache-preserving
  8911. (setq verilog-dir-cache-list nil)) ; Cache disabled
  8912. ;; We don't use expand-file-name on the dirname to make key, as it's slow
  8913. (let* ((cache-key (list dirname default-directory))
  8914. (fass (assoc cache-key verilog-dir-cache-list))
  8915. exp-dirname data)
  8916. (cond (fass ; Return data from cache hit
  8917. (nth 1 fass))
  8918. (t
  8919. (setq exp-dirname (expand-file-name dirname)
  8920. data (and (file-directory-p exp-dirname)
  8921. (directory-files exp-dirname nil nil nil)))
  8922. ;; Note we also encache nil for non-existing dirs.
  8923. (setq verilog-dir-cache-list (cons (list cache-key data)
  8924. verilog-dir-cache-list))
  8925. data))))
  8926. ;; Miss-and-hit test:
  8927. ;;(verilog-preserve-dir-cache (prin1 (verilog-dir-files "."))
  8928. ;; (prin1 (verilog-dir-files ".")) nil)
  8929. (defun verilog-dir-file-exists-p (filename)
  8930. "Return true if FILENAME exists.
  8931. Like `file-exists-p' but results are cached if inside
  8932. `verilog-preserve-dir-cache'."
  8933. (let* ((dirname (file-name-directory filename))
  8934. ;; Correct for file-name-nondirectory returning same if no slash.
  8935. (dirnamed (if (or (not dirname) (equal dirname filename))
  8936. default-directory dirname))
  8937. (flist (verilog-dir-files dirnamed)))
  8938. (and flist
  8939. (member (file-name-nondirectory filename) flist)
  8940. t)))
  8941. ;;(verilog-dir-file-exists-p "verilog-mode.el")
  8942. ;;(verilog-dir-file-exists-p "../verilog-mode/verilog-mode.el")
  8943. ;;; Module name lookup:
  8944. ;;
  8945. (defun verilog-module-inside-filename-p (module filename)
  8946. "Return modi if MODULE is specified inside FILENAME, else nil.
  8947. Allows version control to check out the file if need be."
  8948. (and (or (file-exists-p filename)
  8949. (and (fboundp 'vc-backend)
  8950. (vc-backend filename)))
  8951. (let (modi type)
  8952. (with-current-buffer (find-file-noselect filename)
  8953. (save-excursion
  8954. (goto-char (point-min))
  8955. (while (and
  8956. ;; It may be tempting to look for verilog-defun-re,
  8957. ;; don't, it slows things down a lot!
  8958. (verilog-re-search-forward-quick "\\<\\(module\\|interface\\|program\\)\\>" nil t)
  8959. (setq type (match-string-no-properties 0))
  8960. (verilog-re-search-forward-quick "[(;]" nil t))
  8961. (if (equal module (verilog-read-module-name))
  8962. (setq modi (verilog-modi-new module filename (point) type))))
  8963. modi)))))
  8964. (defun verilog-is-number (symbol)
  8965. "Return true if SYMBOL is number-like."
  8966. (or (string-match "^[0-9 \t:]+$" symbol)
  8967. (string-match "^[---]*[0-9]+$" symbol)
  8968. (string-match "^[0-9 \t]+'s?[hdxbo][0-9a-fA-F_xz? \t]*$" symbol)))
  8969. (defun verilog-symbol-detick (symbol wing-it)
  8970. "Return an expanded SYMBOL name without any defines.
  8971. If the variable vh-{symbol} is defined, return that value.
  8972. If undefined, and WING-IT, return just SYMBOL without the tick, else nil."
  8973. (while (and symbol (string-match "^`" symbol))
  8974. (setq symbol (substring symbol 1))
  8975. (setq symbol
  8976. ;; Namespace intentionally short for AUTOs and compatibility
  8977. (if (boundp (intern (concat "vh-" symbol)))
  8978. ;; Emacs has a bug where boundp on a buffer-local
  8979. ;; variable in only one buffer returns t in another.
  8980. ;; This can confuse, so check for nil.
  8981. ;; Namespace intentionally short for AUTOs and compatibility
  8982. (let ((val (eval (intern (concat "vh-" symbol)))))
  8983. (if (eq val nil)
  8984. (if wing-it symbol nil)
  8985. val))
  8986. (if wing-it symbol nil))))
  8987. symbol)
  8988. ;;(verilog-symbol-detick "`mod" nil)
  8989. (defun verilog-symbol-detick-denumber (symbol)
  8990. "Return SYMBOL with defines converted and any numbers dropped to nil."
  8991. (when (string-match "^`" symbol)
  8992. ;; This only will work if the define is a simple signal, not
  8993. ;; something like a[b]. Sorry, it should be substituted into the parser
  8994. (setq symbol
  8995. (verilog-string-replace-matches
  8996. "\\[[^0-9: \t]+\\]" "" nil nil
  8997. (or (verilog-symbol-detick symbol nil)
  8998. (if verilog-auto-sense-defines-constant
  8999. "0"
  9000. symbol)))))
  9001. (if (verilog-is-number symbol)
  9002. nil
  9003. symbol))
  9004. (defun verilog-symbol-detick-text (text)
  9005. "Return TEXT without any known defines.
  9006. If the variable vh-{symbol} is defined, substitute that value."
  9007. (let ((ok t) symbol val)
  9008. (while (and ok (string-match "`\\([a-zA-Z0-9_]+\\)" text))
  9009. (setq symbol (match-string 1 text))
  9010. ;;(message symbol)
  9011. (cond ((and
  9012. ;; Namespace intentionally short for AUTOs and compatibility
  9013. (boundp (intern (concat "vh-" symbol)))
  9014. ;; Emacs has a bug where boundp on a buffer-local
  9015. ;; variable in only one buffer returns t in another.
  9016. ;; This can confuse, so check for nil.
  9017. ;; Namespace intentionally short for AUTOs and compatibility
  9018. (setq val (eval (intern (concat "vh-" symbol)))))
  9019. (setq text (replace-match val nil nil text)))
  9020. (t (setq ok nil)))))
  9021. text)
  9022. ;;(progn (setq vh-mod "`foo" vh-foo "bar") (verilog-symbol-detick-text "bar `mod `undefed"))
  9023. (defun verilog-expand-dirnames (&optional dirnames)
  9024. "Return a list of existing directories given a list of wildcarded DIRNAMES.
  9025. Or, just the existing dirnames themselves if there are no wildcards."
  9026. ;; Note this function is performance critical.
  9027. ;; Do not call anything that requires disk access that cannot be cached.
  9028. (interactive)
  9029. (unless dirnames
  9030. (error "`verilog-library-directories' should include at least `.'"))
  9031. (setq dirnames (reverse dirnames)) ; not nreverse
  9032. (let ((dirlist nil)
  9033. pattern dirfile dirfiles dirname root filename rest basefile)
  9034. (while dirnames
  9035. (setq dirname (substitute-in-file-name (car dirnames))
  9036. dirnames (cdr dirnames))
  9037. (cond ((string-match (concat "^\\(\\|[/\\]*[^*?]*[/\\]\\)" ; root
  9038. "\\([^/\\]*[*?][^/\\]*\\)" ; filename with *?
  9039. "\\(.*\\)") ; rest
  9040. dirname)
  9041. (setq root (match-string 1 dirname)
  9042. filename (match-string 2 dirname)
  9043. rest (match-string 3 dirname)
  9044. pattern filename)
  9045. ;; now replace those * and ? with .+ and .
  9046. ;; use ^ and /> to get only whole file names
  9047. (setq pattern (verilog-string-replace-matches "[*]" ".+" nil nil pattern)
  9048. pattern (verilog-string-replace-matches "[?]" "." nil nil pattern)
  9049. pattern (concat "^" pattern "$")
  9050. dirfiles (verilog-dir-files root))
  9051. (while dirfiles
  9052. (setq basefile (car dirfiles)
  9053. dirfile (expand-file-name (concat root basefile rest))
  9054. dirfiles (cdr dirfiles))
  9055. (if (and (string-match pattern basefile)
  9056. ;; Don't allow abc/*/rtl to match abc/rtl via ..
  9057. (not (equal basefile "."))
  9058. (not (equal basefile ".."))
  9059. (file-directory-p dirfile))
  9060. (setq dirlist (cons dirfile dirlist)))))
  9061. ;; Defaults
  9062. (t
  9063. (if (file-directory-p dirname)
  9064. (setq dirlist (cons dirname dirlist))))))
  9065. dirlist))
  9066. ;;(verilog-expand-dirnames (list "." ".." "nonexist" "../*" "/home/wsnyder/*/v"))
  9067. (defun verilog-library-filenames (filename &optional current check-ext)
  9068. "Return a search path to find the given FILENAME or module name.
  9069. Uses the optional CURRENT filename or variable `buffer-file-name', plus
  9070. `verilog-library-directories' and `verilog-library-extensions'
  9071. variables to build the path. With optional CHECK-EXT also check
  9072. `verilog-library-extensions'."
  9073. (unless current (setq current (buffer-file-name)))
  9074. (unless verilog-dir-cache-preserving
  9075. (setq verilog-dir-cache-lib-filenames nil))
  9076. (let* ((cache-key (list filename current check-ext))
  9077. (fass (assoc cache-key verilog-dir-cache-lib-filenames))
  9078. chkdirs chkdir chkexts fn outlist)
  9079. (cond (fass ; Return data from cache hit
  9080. (nth 1 fass))
  9081. (t
  9082. ;; Note this expand can't be easily cached, as we need to
  9083. ;; pick up buffer-local variables for newly read sub-module files
  9084. (setq chkdirs (verilog-expand-dirnames verilog-library-directories))
  9085. (while chkdirs
  9086. (setq chkdir (expand-file-name (car chkdirs)
  9087. (file-name-directory current))
  9088. chkexts (if check-ext verilog-library-extensions `("")))
  9089. (while chkexts
  9090. (setq fn (expand-file-name (concat filename (car chkexts))
  9091. chkdir))
  9092. ;;(message "Check for %s" fn)
  9093. (if (verilog-dir-file-exists-p fn)
  9094. (setq outlist (cons (expand-file-name
  9095. fn (file-name-directory current))
  9096. outlist)))
  9097. (setq chkexts (cdr chkexts)))
  9098. (setq chkdirs (cdr chkdirs)))
  9099. (setq outlist (nreverse outlist))
  9100. (setq verilog-dir-cache-lib-filenames
  9101. (cons (list cache-key outlist)
  9102. verilog-dir-cache-lib-filenames))
  9103. outlist))))
  9104. (defun verilog-module-filenames (module current)
  9105. "Return a search path to find the given MODULE name.
  9106. Uses the CURRENT filename, `verilog-library-extensions',
  9107. `verilog-library-directories' and `verilog-library-files'
  9108. variables to build the path."
  9109. ;; Return search locations for it
  9110. (append (list current) ; first, current buffer
  9111. (verilog-library-filenames module current t)
  9112. verilog-library-files)) ; finally, any libraries
  9113. ;;
  9114. ;; Module Information
  9115. ;;
  9116. ;; Many of these functions work on "modi" a module information structure
  9117. ;; A modi is: [module-name-string file-name begin-point]
  9118. (defvar verilog-cache-enabled t
  9119. "Non-nil enables caching of signals, etc. Set to nil for debugging to make things SLOW!")
  9120. (defvar verilog-modi-cache-list nil
  9121. "Cache of ((Module Function) Buf-Tick Buf-Modtime Func-Returns)...
  9122. For speeding up verilog-modi-get-* commands.
  9123. Buffer-local.")
  9124. (make-variable-buffer-local 'verilog-modi-cache-list)
  9125. (defvar verilog-modi-cache-preserve-tick nil
  9126. "Modification tick after which the cache is still considered valid.
  9127. Use `verilog-preserve-modi-cache' to set it.")
  9128. (defvar verilog-modi-cache-preserve-buffer nil
  9129. "Modification tick after which the cache is still considered valid.
  9130. Use `verilog-preserve-modi-cache' to set it.")
  9131. (defvar verilog-modi-cache-current-enable nil
  9132. "Non-nil means allow caching `verilog-modi-current', set by let().")
  9133. (defvar verilog-modi-cache-current nil
  9134. "Currently active `verilog-modi-current', if any, set by let().")
  9135. (defvar verilog-modi-cache-current-max nil
  9136. "Current endmodule point for `verilog-modi-cache-current', if any.")
  9137. (defun verilog-modi-current ()
  9138. "Return the modi structure for the module currently at point, possibly cached."
  9139. (cond ((and verilog-modi-cache-current
  9140. (>= (point) (verilog-modi-get-point verilog-modi-cache-current))
  9141. (<= (point) verilog-modi-cache-current-max))
  9142. ;; Slow assertion, for debugging the cache:
  9143. ;;(or (equal verilog-modi-cache-current (verilog-modi-current-get)) (debug))
  9144. verilog-modi-cache-current)
  9145. (verilog-modi-cache-current-enable
  9146. (setq verilog-modi-cache-current (verilog-modi-current-get)
  9147. verilog-modi-cache-current-max
  9148. ;; The cache expires when we pass "endmodule" as then the
  9149. ;; current modi may change to the next module
  9150. ;; This relies on the AUTOs generally inserting, not deleting text
  9151. (save-excursion
  9152. (verilog-re-search-forward-quick verilog-end-defun-re nil nil)))
  9153. verilog-modi-cache-current)
  9154. (t
  9155. (verilog-modi-current-get))))
  9156. (defun verilog-modi-current-get ()
  9157. "Return the modi structure for the module currently at point."
  9158. (let* (name type pt)
  9159. ;; read current module's name
  9160. (save-excursion
  9161. (verilog-re-search-backward-quick verilog-defun-re nil nil)
  9162. (setq type (match-string-no-properties 0))
  9163. (verilog-re-search-forward-quick "(" nil nil)
  9164. (setq name (verilog-read-module-name))
  9165. (setq pt (point)))
  9166. ;; return modi - note this vector built two places
  9167. (verilog-modi-new name (or (buffer-file-name) (current-buffer)) pt type)))
  9168. (defvar verilog-modi-lookup-cache nil "Hash of (modulename modi).")
  9169. (make-variable-buffer-local 'verilog-modi-lookup-cache)
  9170. (defvar verilog-modi-lookup-last-current nil "Cache of `current-buffer' at last lookup.")
  9171. (defvar verilog-modi-lookup-last-tick nil "Cache of `buffer-chars-modified-tick' at last lookup.")
  9172. (defun verilog-modi-lookup (module allow-cache &optional ignore-error)
  9173. "Find the file and point at which MODULE is defined.
  9174. If ALLOW-CACHE is set, check and remember cache of previous lookups.
  9175. Return modi if successful, else print message unless IGNORE-ERROR is true."
  9176. (let* ((current (or (buffer-file-name) (current-buffer)))
  9177. modi)
  9178. ;; Check cache
  9179. ;;(message "verilog-modi-lookup: %s" module)
  9180. (cond ((and verilog-modi-lookup-cache
  9181. verilog-cache-enabled
  9182. allow-cache
  9183. (setq modi (gethash module verilog-modi-lookup-cache))
  9184. (equal verilog-modi-lookup-last-current current)
  9185. ;; If hit is in current buffer, then tick must match
  9186. (or (equal verilog-modi-lookup-last-tick (buffer-chars-modified-tick))
  9187. (not (equal current (verilog-modi-file-or-buffer modi)))))
  9188. ;;(message "verilog-modi-lookup: HIT %S" modi)
  9189. modi)
  9190. ;; Miss
  9191. (t (let* ((realname (verilog-symbol-detick module t))
  9192. (orig-filenames (verilog-module-filenames realname current))
  9193. (filenames orig-filenames)
  9194. mif)
  9195. (while (and filenames (not mif))
  9196. (if (not (setq mif (verilog-module-inside-filename-p realname (car filenames))))
  9197. (setq filenames (cdr filenames))))
  9198. ;; mif has correct form to become later elements of modi
  9199. (setq modi mif)
  9200. (or mif ignore-error
  9201. (error
  9202. (concat
  9203. "%s: Can't locate %s module definition%s"
  9204. "\n Check the verilog-library-directories variable."
  9205. "\n I looked in (if not listed, doesn't exist):\n\t%s")
  9206. (verilog-point-text) module
  9207. (if (not (equal module realname))
  9208. (concat " (Expanded macro to " realname ")")
  9209. "")
  9210. (mapconcat 'concat orig-filenames "\n\t")))
  9211. (when (eval-when-compile (fboundp 'make-hash-table))
  9212. (unless verilog-modi-lookup-cache
  9213. (setq verilog-modi-lookup-cache
  9214. (make-hash-table :test 'equal :rehash-size 4.0)))
  9215. (puthash module modi verilog-modi-lookup-cache))
  9216. (setq verilog-modi-lookup-last-current current
  9217. verilog-modi-lookup-last-tick (buffer-chars-modified-tick)))))
  9218. modi))
  9219. (defun verilog-modi-filename (modi)
  9220. "Filename of MODI, or name of buffer if it's never been saved."
  9221. (if (bufferp (verilog-modi-file-or-buffer modi))
  9222. (or (buffer-file-name (verilog-modi-file-or-buffer modi))
  9223. (buffer-name (verilog-modi-file-or-buffer modi)))
  9224. (verilog-modi-file-or-buffer modi)))
  9225. (defun verilog-modi-goto (modi)
  9226. "Move point/buffer to specified MODI."
  9227. (or modi (error "Passed unfound modi to goto, check earlier"))
  9228. (set-buffer (if (bufferp (verilog-modi-file-or-buffer modi))
  9229. (verilog-modi-file-or-buffer modi)
  9230. (find-file-noselect (verilog-modi-file-or-buffer modi))))
  9231. (or (equal major-mode `verilog-mode) ; Put into Verilog mode to get syntax
  9232. (verilog-mode))
  9233. (goto-char (verilog-modi-get-point modi)))
  9234. (defun verilog-goto-defun-file (module)
  9235. "Move point to the file at which a given MODULE is defined."
  9236. (interactive "sGoto File for Module: ")
  9237. (let* ((modi (verilog-modi-lookup module nil)))
  9238. (when modi
  9239. (verilog-modi-goto modi)
  9240. (switch-to-buffer (current-buffer)))))
  9241. (defun verilog-modi-cache-results (modi function)
  9242. "Run on MODI the given FUNCTION. Locate the module in a file.
  9243. Cache the output of function so next call may have faster access."
  9244. (let (fass)
  9245. (save-excursion ; Cache is buffer-local so can't avoid this.
  9246. (verilog-modi-goto modi)
  9247. (if (and (setq fass (assoc (list modi function)
  9248. verilog-modi-cache-list))
  9249. ;; Destroy caching when incorrect; Modified or file changed
  9250. (not (and verilog-cache-enabled
  9251. (or (equal (buffer-chars-modified-tick) (nth 1 fass))
  9252. (and verilog-modi-cache-preserve-tick
  9253. (<= verilog-modi-cache-preserve-tick (nth 1 fass))
  9254. (equal verilog-modi-cache-preserve-buffer (current-buffer))))
  9255. (equal (visited-file-modtime) (nth 2 fass)))))
  9256. (setq verilog-modi-cache-list nil
  9257. fass nil))
  9258. (cond (fass
  9259. ;; Return data from cache hit
  9260. (nth 3 fass))
  9261. (t
  9262. ;; Read from file
  9263. ;; Clear then restore any highlighting to make emacs19 happy
  9264. (let (func-returns)
  9265. (verilog-save-font-mods
  9266. (setq func-returns (funcall function)))
  9267. ;; Cache for next time
  9268. (setq verilog-modi-cache-list
  9269. (cons (list (list modi function)
  9270. (buffer-chars-modified-tick)
  9271. (visited-file-modtime)
  9272. func-returns)
  9273. verilog-modi-cache-list))
  9274. func-returns))))))
  9275. (defun verilog-modi-cache-add (modi function element sig-list)
  9276. "Add function return results to the module cache.
  9277. Update MODI's cache for given FUNCTION so that the return ELEMENT of that
  9278. function now contains the additional SIG-LIST parameters."
  9279. (let (fass)
  9280. (save-excursion
  9281. (verilog-modi-goto modi)
  9282. (if (setq fass (assoc (list modi function)
  9283. verilog-modi-cache-list))
  9284. (let ((func-returns (nth 3 fass)))
  9285. (aset func-returns element
  9286. (append sig-list (aref func-returns element))))))))
  9287. (defmacro verilog-preserve-modi-cache (&rest body)
  9288. "Execute the BODY forms, allowing cache preservation within BODY.
  9289. This means that changes to the buffer will not result in the cache being
  9290. flushed. If the changes affect the modsig state, they must call the
  9291. modsig-cache-add-* function, else the results of later calls may be
  9292. incorrect. Without this, changes are assumed to be adding/removing signals
  9293. and invalidating the cache."
  9294. `(let ((verilog-modi-cache-preserve-tick (buffer-chars-modified-tick))
  9295. (verilog-modi-cache-preserve-buffer (current-buffer)))
  9296. (progn ,@body)))
  9297. (defun verilog-modi-modport-lookup-one (modi name &optional ignore-error)
  9298. "Given a MODI, return the declarations related to the given modport NAME.
  9299. Report errors unless optional IGNORE-ERROR."
  9300. ;; Recursive routine - see below
  9301. (let* ((realname (verilog-symbol-detick name t))
  9302. (modport (assoc name (verilog-decls-get-modports (verilog-modi-get-decls modi)))))
  9303. (or modport ignore-error
  9304. (error "%s: Can't locate %s modport definition%s"
  9305. (verilog-point-text) name
  9306. (if (not (equal name realname))
  9307. (concat " (Expanded macro to " realname ")")
  9308. "")))
  9309. (let* ((decls (verilog-modport-decls modport))
  9310. (clks (verilog-modport-clockings modport)))
  9311. ;; Now expand any clocking's
  9312. (while clks
  9313. (setq decls (verilog-decls-append
  9314. decls
  9315. (verilog-modi-modport-lookup-one modi (car clks) ignore-error)))
  9316. (setq clks (cdr clks)))
  9317. decls)))
  9318. (defun verilog-modi-modport-lookup (modi name-re &optional ignore-error)
  9319. "Given a MODI, return the declarations related to the given modport NAME-RE.
  9320. If the modport points to any clocking blocks, expand the signals to include
  9321. those clocking block's signals."
  9322. ;; Recursive routine - see below
  9323. (let* ((mod-decls (verilog-modi-get-decls modi))
  9324. (clks (verilog-decls-get-modports mod-decls))
  9325. (name-re (concat "^" name-re "$"))
  9326. (decls (verilog-decls-new nil nil nil nil nil nil nil nil nil)))
  9327. ;; Pull in all modports
  9328. (while clks
  9329. (when (string-match name-re (verilog-modport-name (car clks)))
  9330. (setq decls (verilog-decls-append
  9331. decls
  9332. (verilog-modi-modport-lookup-one modi (verilog-modport-name (car clks)) ignore-error))))
  9333. (setq clks (cdr clks)))
  9334. decls))
  9335. (defun verilog-signals-matching-enum (in-list enum)
  9336. "Return all signals in IN-LIST matching the given ENUM."
  9337. (let (out-list)
  9338. (while in-list
  9339. (if (equal (verilog-sig-enum (car in-list)) enum)
  9340. (setq out-list (cons (car in-list) out-list)))
  9341. (setq in-list (cdr in-list)))
  9342. ;; New scheme
  9343. ;; Namespace intentionally short for AUTOs and compatibility
  9344. (let* ((enumvar (intern (concat "venum-" enum)))
  9345. (enumlist (and (boundp enumvar) (eval enumvar))))
  9346. (while enumlist
  9347. (add-to-list 'out-list (list (car enumlist)))
  9348. (setq enumlist (cdr enumlist))))
  9349. (nreverse out-list)))
  9350. (defun verilog-signals-matching-regexp (in-list regexp)
  9351. "Return all signals in IN-LIST matching the given REGEXP, if non-nil."
  9352. (if (or (not regexp) (equal regexp ""))
  9353. in-list
  9354. (let ((case-fold-search verilog-case-fold)
  9355. out-list)
  9356. (while in-list
  9357. (if (string-match regexp (verilog-sig-name (car in-list)))
  9358. (setq out-list (cons (car in-list) out-list)))
  9359. (setq in-list (cdr in-list)))
  9360. (nreverse out-list))))
  9361. (defun verilog-signals-not-matching-regexp (in-list regexp)
  9362. "Return all signals in IN-LIST not matching the given REGEXP, if non-nil."
  9363. (if (or (not regexp) (equal regexp ""))
  9364. in-list
  9365. (let ((case-fold-search verilog-case-fold)
  9366. out-list)
  9367. (while in-list
  9368. (if (not (string-match regexp (verilog-sig-name (car in-list))))
  9369. (setq out-list (cons (car in-list) out-list)))
  9370. (setq in-list (cdr in-list)))
  9371. (nreverse out-list))))
  9372. (defun verilog-signals-matching-dir-re (in-list decl-type regexp)
  9373. "Return all signals in IN-LIST matching the given DECL-TYPE and REGEXP,
  9374. if non-nil."
  9375. (if (or (not regexp) (equal regexp ""))
  9376. in-list
  9377. (let (out-list to-match)
  9378. (while in-list
  9379. ;; Note verilog-insert-one-definition matches on this order
  9380. (setq to-match (concat
  9381. decl-type
  9382. " " (verilog-sig-signed (car in-list))
  9383. " " (verilog-sig-multidim (car in-list))
  9384. (verilog-sig-bits (car in-list))))
  9385. (if (string-match regexp to-match)
  9386. (setq out-list (cons (car in-list) out-list)))
  9387. (setq in-list (cdr in-list)))
  9388. (nreverse out-list))))
  9389. (defun verilog-signals-edit-wire-reg (in-list)
  9390. "Return all signals in IN-LIST with wire/reg data types made blank."
  9391. (mapcar (lambda (sig)
  9392. (when (member (verilog-sig-type sig) '("wire" "reg"))
  9393. (verilog-sig-type-set sig nil))
  9394. sig) in-list))
  9395. ;; Combined
  9396. (defun verilog-decls-get-signals (decls)
  9397. "Return all declared signals in DECLS, excluding `assign' statements."
  9398. (append
  9399. (verilog-decls-get-outputs decls)
  9400. (verilog-decls-get-inouts decls)
  9401. (verilog-decls-get-inputs decls)
  9402. (verilog-decls-get-vars decls)
  9403. (verilog-decls-get-consts decls)
  9404. (verilog-decls-get-gparams decls)))
  9405. (defun verilog-decls-get-ports (decls)
  9406. (append
  9407. (verilog-decls-get-outputs decls)
  9408. (verilog-decls-get-inouts decls)
  9409. (verilog-decls-get-inputs decls)))
  9410. (defun verilog-decls-get-iovars (decls)
  9411. (append
  9412. (verilog-decls-get-vars decls)
  9413. (verilog-decls-get-outputs decls)
  9414. (verilog-decls-get-inouts decls)
  9415. (verilog-decls-get-inputs decls)))
  9416. (defsubst verilog-modi-cache-add-outputs (modi sig-list)
  9417. (verilog-modi-cache-add modi 'verilog-read-decls 0 sig-list))
  9418. (defsubst verilog-modi-cache-add-inouts (modi sig-list)
  9419. (verilog-modi-cache-add modi 'verilog-read-decls 1 sig-list))
  9420. (defsubst verilog-modi-cache-add-inputs (modi sig-list)
  9421. (verilog-modi-cache-add modi 'verilog-read-decls 2 sig-list))
  9422. (defsubst verilog-modi-cache-add-vars (modi sig-list)
  9423. (verilog-modi-cache-add modi 'verilog-read-decls 3 sig-list))
  9424. (defsubst verilog-modi-cache-add-gparams (modi sig-list)
  9425. (verilog-modi-cache-add modi 'verilog-read-decls 7 sig-list))
  9426. ;;; Auto creation utilities:
  9427. ;;
  9428. (defun verilog-auto-re-search-do (search-for func)
  9429. "Search for the given auto text regexp SEARCH-FOR, and perform FUNC where it occurs."
  9430. (goto-char (point-min))
  9431. (while (verilog-re-search-forward-quick search-for nil t)
  9432. (funcall func)))
  9433. (defun verilog-insert-one-definition (sig type indent-pt)
  9434. "Print out a definition for SIG of the given TYPE,
  9435. with appropriate INDENT-PT indentation."
  9436. (indent-to indent-pt)
  9437. ;; Note verilog-signals-matching-dir-re matches on this order
  9438. (insert type)
  9439. (when (verilog-sig-modport sig)
  9440. (insert "." (verilog-sig-modport sig)))
  9441. (when (verilog-sig-signed sig)
  9442. (insert " " (verilog-sig-signed sig)))
  9443. (when (verilog-sig-multidim sig)
  9444. (insert " " (verilog-sig-multidim-string sig)))
  9445. (when (verilog-sig-bits sig)
  9446. (insert " " (verilog-sig-bits sig)))
  9447. (indent-to (max 24 (+ indent-pt 16)))
  9448. (unless (= (char-syntax (preceding-char)) ?\ )
  9449. (insert " ")) ; Need space between "]name" if indent-to did nothing
  9450. (insert (verilog-sig-name sig))
  9451. (when (verilog-sig-memory sig)
  9452. (insert " " (verilog-sig-memory sig))))
  9453. (defun verilog-insert-definition (modi sigs direction indent-pt v2k &optional dont-sort)
  9454. "Print out a definition for MODI's list of SIGS of the given DIRECTION,
  9455. with appropriate INDENT-PT indentation. If V2K, use Verilog 2001 I/O
  9456. format. Sort unless DONT-SORT. DIRECTION is normally wire/reg/output.
  9457. When MODI is non-null, also add to modi-cache, for tracking."
  9458. (when modi
  9459. (cond ((equal direction "wire")
  9460. (verilog-modi-cache-add-vars modi sigs))
  9461. ((equal direction "reg")
  9462. (verilog-modi-cache-add-vars modi sigs))
  9463. ((equal direction "output")
  9464. (verilog-modi-cache-add-outputs modi sigs)
  9465. (when verilog-auto-declare-nettype
  9466. (verilog-modi-cache-add-vars modi sigs)))
  9467. ((equal direction "input")
  9468. (verilog-modi-cache-add-inputs modi sigs)
  9469. (when verilog-auto-declare-nettype
  9470. (verilog-modi-cache-add-vars modi sigs)))
  9471. ((equal direction "inout")
  9472. (verilog-modi-cache-add-inouts modi sigs)
  9473. (when verilog-auto-declare-nettype
  9474. (verilog-modi-cache-add-vars modi sigs)))
  9475. ((equal direction "interface"))
  9476. ((equal direction "parameter")
  9477. (verilog-modi-cache-add-gparams modi sigs))
  9478. (t
  9479. (error "Unsupported verilog-insert-definition direction: %s" direction))))
  9480. (or dont-sort
  9481. (setq sigs (sort (copy-alist sigs) `verilog-signals-sort-compare)))
  9482. (while sigs
  9483. (let ((sig (car sigs)))
  9484. (verilog-insert-one-definition
  9485. sig
  9486. ;; Want "type x" or "output type x", not "wire type x"
  9487. (cond ((or (verilog-sig-type sig)
  9488. verilog-auto-wire-type)
  9489. (concat
  9490. (when (member direction '("input" "output" "inout"))
  9491. (concat direction " "))
  9492. (or (verilog-sig-type sig)
  9493. verilog-auto-wire-type)))
  9494. ((and verilog-auto-declare-nettype
  9495. (member direction '("input" "output" "inout")))
  9496. (concat direction " " verilog-auto-declare-nettype))
  9497. (t
  9498. direction))
  9499. indent-pt)
  9500. (insert (if v2k "," ";"))
  9501. (if (or (not (verilog-sig-comment sig))
  9502. (equal "" (verilog-sig-comment sig)))
  9503. (insert "\n")
  9504. (indent-to (max 48 (+ indent-pt 40)))
  9505. (verilog-insert "// " (verilog-sig-comment sig) "\n"))
  9506. (setq sigs (cdr sigs)))))
  9507. (eval-when-compile
  9508. (if (not (boundp 'indent-pt))
  9509. (defvar indent-pt nil "Local used by insert-indent")))
  9510. (defun verilog-insert-indent (&rest stuff)
  9511. "Indent to position stored in local `indent-pt' variable, then insert STUFF.
  9512. Presumes that any newlines end a list element."
  9513. (let ((need-indent t))
  9514. (while stuff
  9515. (if need-indent (indent-to indent-pt))
  9516. (setq need-indent nil)
  9517. (verilog-insert (car stuff))
  9518. (setq need-indent (string-match "\n$" (car stuff))
  9519. stuff (cdr stuff)))))
  9520. ;;(let ((indent-pt 10)) (verilog-insert-indent "hello\n" "addon" "there\n"))
  9521. (defun verilog-forward-or-insert-line ()
  9522. "Move forward a line, unless at EOB, then insert a newline."
  9523. (if (eobp) (insert "\n")
  9524. (forward-line)))
  9525. (defun verilog-repair-open-comma ()
  9526. "Insert comma if previous argument is other than an open parenthesis or endif."
  9527. ;; We can't just search backward for ) as it might be inside another expression.
  9528. ;; Also want "`ifdef X input foo `endif" to just leave things to the human to deal with
  9529. (save-excursion
  9530. (verilog-backward-syntactic-ws-quick)
  9531. (when (and (not (save-excursion ; Not beginning (, or existing ,
  9532. (backward-char 1)
  9533. (looking-at "[(,]")))
  9534. (not (save-excursion ; Not `endif, or user define
  9535. (backward-char 1)
  9536. (skip-chars-backward "[a-zA-Z0-9_`]")
  9537. (looking-at "`"))))
  9538. (insert ","))))
  9539. (defun verilog-repair-close-comma ()
  9540. "If point is at a comma followed by a close parenthesis, fix it.
  9541. This repairs those mis-inserted by an AUTOARG."
  9542. ;; It would be much nicer if Verilog allowed extra commas like Perl does!
  9543. (save-excursion
  9544. (verilog-forward-close-paren)
  9545. (backward-char 1)
  9546. (verilog-backward-syntactic-ws-quick)
  9547. (backward-char 1)
  9548. (when (looking-at ",")
  9549. (delete-char 1))))
  9550. (defun verilog-make-width-expression (range-exp)
  9551. "Return an expression calculating the length of a range [x:y] in RANGE-EXP."
  9552. ;; strip off the []
  9553. (cond ((not range-exp)
  9554. "1")
  9555. (t
  9556. (if (string-match "^\\[\\(.*\\)\\]$" range-exp)
  9557. (setq range-exp (match-string 1 range-exp)))
  9558. (cond ((not range-exp)
  9559. "1")
  9560. ;; [#:#] We can compute a numeric result
  9561. ((string-match "^\\s *\\([0-9]+\\)\\s *:\\s *\\([0-9]+\\)\\s *$"
  9562. range-exp)
  9563. (int-to-string
  9564. (1+ (abs (- (string-to-number (match-string 1 range-exp))
  9565. (string-to-number (match-string 2 range-exp)))))))
  9566. ;; [PARAM-1:0] can just return PARAM
  9567. ((string-match "^\\s *\\([a-zA-Z_][a-zA-Z0-9_]*\\)\\s *-\\s *1\\s *:\\s *0\\s *$" range-exp)
  9568. (match-string 1 range-exp))
  9569. ;; [arbitrary] need math
  9570. ((string-match "^\\(.*\\)\\s *:\\s *\\(.*\\)\\s *$" range-exp)
  9571. (concat "(1+(" (match-string 1 range-exp) ")"
  9572. (if (equal "0" (match-string 2 range-exp))
  9573. "" ; Don't bother with -(0)
  9574. (concat "-(" (match-string 2 range-exp) ")"))
  9575. ")"))
  9576. (t nil)))))
  9577. ;;(verilog-make-width-expression "`A:`B")
  9578. (defun verilog-simplify-range-expression (expr)
  9579. "Return a simplified range expression with constants eliminated from EXPR."
  9580. ;; Note this is always called with brackets; ie [z] or [z:z]
  9581. (if (not (string-match "[---+*()]" expr))
  9582. expr ; short-circuit
  9583. (let ((out expr)
  9584. (last-pass ""))
  9585. (while (not (equal last-pass out))
  9586. (setq last-pass out)
  9587. ;; Prefix regexp needs beginning of match, or some symbol of
  9588. ;; lesser or equal precedence. We assume the [:]'s exist in expr.
  9589. ;; Ditto the end.
  9590. (while (string-match
  9591. (concat "\\([[({:*+-]\\)" ; - must be last
  9592. "(\\<\\([0-9A-Za-z_]+\\))"
  9593. "\\([])}:*+-]\\)")
  9594. out)
  9595. (setq out (replace-match "\\1\\2\\3" nil nil out)))
  9596. (while (string-match
  9597. (concat "\\([[({:*+-]\\)" ; - must be last
  9598. "\\$clog2\\s *(\\<\\([0-9]+\\))"
  9599. "\\([])}:*+-]\\)")
  9600. out)
  9601. (setq out (replace-match
  9602. (concat
  9603. (match-string 1 out)
  9604. (int-to-string (verilog-clog2 (string-to-number (match-string 2 out))))
  9605. (match-string 3 out))
  9606. nil nil out)))
  9607. ;; For precedence do * before +/-
  9608. (while (string-match
  9609. (concat "\\([[({:*+-]\\)"
  9610. "\\([0-9]+\\)\\s *\\([*]\\)\\s *\\([0-9]+\\)"
  9611. "\\([])}:*+-]\\)")
  9612. out)
  9613. (setq out (replace-match
  9614. (concat (match-string 1 out)
  9615. (int-to-string (* (string-to-number (match-string 2 out))
  9616. (string-to-number (match-string 4 out))))
  9617. (match-string 5 out))
  9618. nil nil out)))
  9619. (while (string-match
  9620. (concat "\\([[({:+-]\\)" ; No * here as higher prec
  9621. "\\([0-9]+\\)\\s *\\([---+]\\)\\s *\\([0-9]+\\)"
  9622. "\\([])}:+-]\\)")
  9623. out)
  9624. (let ((pre (match-string 1 out))
  9625. (lhs (string-to-number (match-string 2 out)))
  9626. (rhs (string-to-number (match-string 4 out)))
  9627. (post (match-string 5 out))
  9628. val)
  9629. (when (equal pre "-")
  9630. (setq lhs (- lhs)))
  9631. (setq val (if (equal (match-string 3 out) "-")
  9632. (- lhs rhs)
  9633. (+ lhs rhs))
  9634. out (replace-match
  9635. (concat (if (and (equal pre "-")
  9636. (< val 0))
  9637. "" ; Not "--20" but just "-20"
  9638. pre)
  9639. (int-to-string val)
  9640. post)
  9641. nil nil out)) )))
  9642. out)))
  9643. ;;(verilog-simplify-range-expression "[1:3]") ; 1
  9644. ;;(verilog-simplify-range-expression "[(1):3]") ; 1
  9645. ;;(verilog-simplify-range-expression "[(((16)+1)+1+(1+1))]") ; 20
  9646. ;;(verilog-simplify-range-expression "[(2*3+6*7)]") ; 48
  9647. ;;(verilog-simplify-range-expression "[(FOO*4-1*2)]") ; FOO*4-2
  9648. ;;(verilog-simplify-range-expression "[(FOO*4+1-1)]") ; FOO*4+0
  9649. ;;(verilog-simplify-range-expression "[(func(BAR))]") ; func(BAR)
  9650. ;;(verilog-simplify-range-expression "[FOO-1+1-1+1]") ; FOO-0
  9651. ;;(verilog-simplify-range-expression "[$clog2(2)]") ; 1
  9652. ;;(verilog-simplify-range-expression "[$clog2(7)]") ; 3
  9653. (defun verilog-clog2 (value)
  9654. "Compute $clog2 - ceiling log2 of VALUE."
  9655. (if (< value 1)
  9656. 0
  9657. (ceiling (/ (log value) (log 2)))))
  9658. (defun verilog-typedef-name-p (variable-name)
  9659. "Return true if the VARIABLE-NAME is a type definition."
  9660. (when verilog-typedef-regexp
  9661. (verilog-string-match-fold verilog-typedef-regexp variable-name)))
  9662. ;;; Auto deletion:
  9663. ;;
  9664. (defun verilog-delete-autos-lined ()
  9665. "Delete autos that occupy multiple lines, between begin and end comments."
  9666. ;; The newline must not have a comment property, so we must
  9667. ;; delete the end auto's newline, not the first newline
  9668. (forward-line 1)
  9669. (let ((pt (point)))
  9670. (when (and
  9671. (looking-at "\\s-*// Beginning")
  9672. (search-forward "// End of automatic" nil t))
  9673. ;; End exists
  9674. (end-of-line)
  9675. (forward-line 1)
  9676. (delete-region pt (point)))))
  9677. (defun verilog-delete-empty-auto-pair ()
  9678. "Delete begin/end auto pair at point, if empty."
  9679. (forward-line 0)
  9680. (when (looking-at (concat "\\s-*// Beginning of automatic.*\n"
  9681. "\\s-*// End of automatics\n"))
  9682. (delete-region (point) (save-excursion (forward-line 2) (point)))))
  9683. (defun verilog-forward-close-paren ()
  9684. "Find the close parenthesis that match the current point.
  9685. Ignore other close parenthesis with matching open parens."
  9686. (let ((parens 1))
  9687. (while (> parens 0)
  9688. (unless (verilog-re-search-forward-quick "[()]" nil t)
  9689. (error "%s: Mismatching ()" (verilog-point-text)))
  9690. (cond ((= (preceding-char) ?\( )
  9691. (setq parens (1+ parens)))
  9692. ((= (preceding-char) ?\) )
  9693. (setq parens (1- parens)))))))
  9694. (defun verilog-backward-open-paren ()
  9695. "Find the open parenthesis that match the current point.
  9696. Ignore other open parenthesis with matching close parens."
  9697. (let ((parens 1))
  9698. (while (> parens 0)
  9699. (unless (verilog-re-search-backward-quick "[()]" nil t)
  9700. (error "%s: Mismatching ()" (verilog-point-text)))
  9701. (cond ((= (following-char) ?\) )
  9702. (setq parens (1+ parens)))
  9703. ((= (following-char) ?\( )
  9704. (setq parens (1- parens)))))))
  9705. (defun verilog-backward-open-bracket ()
  9706. "Find the open bracket that match the current point.
  9707. Ignore other open bracket with matching close bracket."
  9708. (let ((parens 1))
  9709. (while (> parens 0)
  9710. (unless (verilog-re-search-backward-quick "[][]" nil t)
  9711. (error "%s: Mismatching []" (verilog-point-text)))
  9712. (cond ((= (following-char) ?\] )
  9713. (setq parens (1+ parens)))
  9714. ((= (following-char) ?\[ )
  9715. (setq parens (1- parens)))))))
  9716. (defun verilog-delete-to-paren ()
  9717. "Delete the automatic inst/sense/arg created by autos.
  9718. Deletion stops at the matching end parenthesis, outside comments."
  9719. (delete-region (point)
  9720. (save-excursion
  9721. (verilog-backward-open-paren)
  9722. (verilog-forward-sexp-ign-cmt 1) ; Moves to paren that closes argdecl's
  9723. (backward-char 1)
  9724. (point))))
  9725. (defun verilog-auto-star-safe ()
  9726. "Return if a .* AUTOINST is safe to delete or expand.
  9727. It was created by the AUTOS themselves, or by the user."
  9728. (and verilog-auto-star-expand
  9729. (looking-at
  9730. (concat "[ \t\n\f,]*\\([)]\\|// " verilog-inst-comment-re "\\)"))))
  9731. (defun verilog-delete-auto-star-all ()
  9732. "Delete a .* AUTOINST, if it is safe."
  9733. (when (verilog-auto-star-safe)
  9734. (verilog-delete-to-paren)))
  9735. (defun verilog-delete-auto-star-implicit ()
  9736. "Delete all .* implicit connections created by `verilog-auto-star'.
  9737. This function will be called automatically at save unless
  9738. `verilog-auto-star-save' is set, any non-templated expanded pins will be
  9739. removed."
  9740. (interactive)
  9741. (let (paren-pt indent have-close-paren)
  9742. (save-excursion
  9743. (goto-char (point-min))
  9744. ;; We need to match these even outside of comments.
  9745. ;; For reasonable performance, we don't check if inside comments, sorry.
  9746. (while (re-search-forward "// Implicit \\.\\*" nil t)
  9747. (setq paren-pt (point))
  9748. (beginning-of-line)
  9749. (setq have-close-paren
  9750. (save-excursion
  9751. (when (search-forward ");" paren-pt t)
  9752. (setq indent (current-indentation))
  9753. t)))
  9754. (delete-region (point) (+ 1 paren-pt)) ; Nuke line incl CR
  9755. (when have-close-paren
  9756. ;; Delete extra commentary
  9757. (save-excursion
  9758. (while (progn
  9759. (forward-line -1)
  9760. (looking-at (concat "\\s *//\\s *" verilog-inst-comment-re "\n")))
  9761. (delete-region (match-beginning 0) (match-end 0))))
  9762. ;; If it is simple, we can put the ); on the same line as the last text
  9763. (let ((rtn-pt (point)))
  9764. (save-excursion
  9765. (while (progn (backward-char 1)
  9766. (looking-at "[ \t\n\f]")))
  9767. (when (looking-at ",")
  9768. (delete-region (+ 1 (point)) rtn-pt))))
  9769. (when (bolp)
  9770. (indent-to indent))
  9771. (insert ");\n")
  9772. ;; Still need to kill final comma - always is one as we put one after the .*
  9773. (re-search-backward ",")
  9774. (delete-char 1))))))
  9775. (defun verilog-delete-auto ()
  9776. "Delete the automatic outputs, regs, and wires created by \\[verilog-auto].
  9777. Use \\[verilog-auto] to re-insert the updated AUTOs.
  9778. The hooks `verilog-before-delete-auto-hook' and `verilog-delete-auto-hook' are
  9779. called before and after this function, respectively."
  9780. (interactive)
  9781. (save-excursion
  9782. (if (buffer-file-name)
  9783. (find-file-noselect (buffer-file-name))) ; To check we have latest version
  9784. (verilog-save-no-change-functions
  9785. (verilog-save-scan-cache
  9786. ;; Allow user to customize
  9787. (verilog-run-hooks 'verilog-before-delete-auto-hook)
  9788. ;; Remove those that have multi-line insertions, possibly with parameters
  9789. ;; We allow anything beginning with AUTO, so that users can add their own
  9790. ;; patterns
  9791. (verilog-auto-re-search-do
  9792. (concat "/\\*AUTO[A-Za-z0-9_]+"
  9793. ;; Optional parens or quoted parameter or .* for (((...)))
  9794. "\\(\\|([^)]*)\\|(\"[^\"]*\")\\).*?"
  9795. "\\*/")
  9796. 'verilog-delete-autos-lined)
  9797. ;; Remove those that are in parenthesis
  9798. (verilog-auto-re-search-do
  9799. (concat "/\\*"
  9800. (eval-when-compile
  9801. (verilog-regexp-words
  9802. `("AS" "AUTOARG" "AUTOCONCATWIDTH" "AUTOINST" "AUTOINSTPARAM"
  9803. "AUTOSENSE")))
  9804. "\\*/")
  9805. 'verilog-delete-to-paren)
  9806. ;; Do .* instantiations, but avoid removing any user pins by looking for our magic comments
  9807. (verilog-auto-re-search-do "\\.\\*"
  9808. 'verilog-delete-auto-star-all)
  9809. ;; Remove template comments ... anywhere in case was pasted after AUTOINST removed
  9810. (goto-char (point-min))
  9811. (while (re-search-forward "\\s-*// \\(Templated\\|Implicit \\.\\*\\)\\([ \tLT0-9]*\\| LHS: .*\\)?$" nil t)
  9812. (replace-match ""))
  9813. ;; Final customize
  9814. (verilog-run-hooks 'verilog-delete-auto-hook)))))
  9815. ;;; Auto inject:
  9816. ;;
  9817. (defun verilog-inject-auto ()
  9818. "Examine legacy non-AUTO code and insert AUTOs in appropriate places.
  9819. Any always @ blocks with sensitivity lists that match computed lists will
  9820. be replaced with /*AS*/ comments.
  9821. Any cells will get /*AUTOINST*/ added to the end of the pin list.
  9822. Pins with have identical names will be deleted.
  9823. Argument lists will not be deleted, /*AUTOARG*/ will only be inserted to
  9824. support adding new ports. You may wish to delete older ports yourself.
  9825. For example:
  9826. module ExampInject (i, o);
  9827. input i;
  9828. input j;
  9829. output o;
  9830. always @ (i or j)
  9831. o = i | j;
  9832. InstModule instName
  9833. (.foobar(baz),
  9834. j(j));
  9835. endmodule
  9836. Typing \\[verilog-inject-auto] will make this into:
  9837. module ExampInject (i, o/*AUTOARG*/
  9838. // Inputs
  9839. j);
  9840. input i;
  9841. output o;
  9842. always @ (/*AS*/i or j)
  9843. o = i | j;
  9844. InstModule instName
  9845. (.foobar(baz),
  9846. /*AUTOINST*/
  9847. // Outputs
  9848. j(j));
  9849. endmodule"
  9850. (interactive)
  9851. (verilog-auto t))
  9852. (defun verilog-inject-arg ()
  9853. "Inject AUTOARG into new code. See `verilog-inject-auto'."
  9854. ;; Presume one module per file.
  9855. (save-excursion
  9856. (goto-char (point-min))
  9857. (while (verilog-re-search-forward-quick "\\<module\\>" nil t)
  9858. (let ((endmodp (save-excursion
  9859. (verilog-re-search-forward-quick "\\<endmodule\\>" nil t)
  9860. (point))))
  9861. ;; See if there's already a comment .. inside a comment so not verilog-re-search
  9862. (when (not (re-search-forward "/\\*AUTOARG\\*/" endmodp t))
  9863. (verilog-re-search-forward-quick ";" nil t)
  9864. (backward-char 1)
  9865. (verilog-backward-syntactic-ws-quick)
  9866. (backward-char 1) ; Moves to paren that closes argdecl's
  9867. (when (looking-at ")")
  9868. (verilog-insert "/*AUTOARG*/")))))))
  9869. (defun verilog-inject-sense ()
  9870. "Inject AUTOSENSE into new code. See `verilog-inject-auto'."
  9871. (save-excursion
  9872. (goto-char (point-min))
  9873. (while (verilog-re-search-forward-quick "\\<always\\s *@\\s *(" nil t)
  9874. (let* ((start-pt (point))
  9875. (modi (verilog-modi-current))
  9876. (moddecls (verilog-modi-get-decls modi))
  9877. pre-sigs
  9878. got-sigs)
  9879. (backward-char 1)
  9880. (verilog-forward-sexp-ign-cmt 1)
  9881. (backward-char 1) ; End )
  9882. (when (not (verilog-re-search-backward-quick "/\\*\\(AUTOSENSE\\|AS\\)\\*/" start-pt t))
  9883. (setq pre-sigs (verilog-signals-from-signame
  9884. (verilog-read-signals start-pt (point)))
  9885. got-sigs (verilog-auto-sense-sigs moddecls nil))
  9886. (when (not (or (verilog-signals-not-in pre-sigs got-sigs) ; Both are equal?
  9887. (verilog-signals-not-in got-sigs pre-sigs)))
  9888. (delete-region start-pt (point))
  9889. (verilog-insert "/*AS*/")))))))
  9890. (defun verilog-inject-inst ()
  9891. "Inject AUTOINST into new code. See `verilog-inject-auto'."
  9892. (save-excursion
  9893. (goto-char (point-min))
  9894. ;; It's hard to distinguish modules; we'll instead search for pins.
  9895. (while (verilog-re-search-forward-quick "\\.\\s *[a-zA-Z0-9`_$]+\\s *(\\s *[a-zA-Z0-9`_$]+\\s *)" nil t)
  9896. (verilog-backward-open-paren) ; Inst start
  9897. (cond
  9898. ((= (preceding-char) ?\#) ; #(...) parameter section, not pin. Skip.
  9899. (forward-char 1)
  9900. (verilog-forward-close-paren)) ; Parameters done
  9901. (t
  9902. (forward-char 1)
  9903. (let ((indent-pt (+ (current-column)))
  9904. (end-pt (save-excursion (verilog-forward-close-paren) (point))))
  9905. (cond ((verilog-re-search-forward-quick "\\(/\\*AUTOINST\\*/\\|\\.\\*\\)" end-pt t)
  9906. (goto-char end-pt)) ; Already there, continue search with next instance
  9907. (t
  9908. ;; Delete identical interconnect
  9909. (let ((case-fold-search nil)) ; So we don't convert upper-to-lower, etc
  9910. (while (verilog-re-search-forward-quick "\\.\\s *\\([a-zA-Z0-9`_$]+\\)*\\s *(\\s *\\1\\s *)\\s *" end-pt t)
  9911. (delete-region (match-beginning 0) (match-end 0))
  9912. (setq end-pt (- end-pt (- (match-end 0) (match-beginning 0)))) ; Keep it correct
  9913. (while (or (looking-at "[ \t\n\f,]+")
  9914. (looking-at "//[^\n]*"))
  9915. (delete-region (match-beginning 0) (match-end 0))
  9916. (setq end-pt (- end-pt (- (match-end 0) (match-beginning 0)))))))
  9917. (verilog-forward-close-paren)
  9918. (backward-char 1)
  9919. ;; Not verilog-re-search, as we don't want to strip comments
  9920. (while (re-search-backward "[ \t\n\f]+" (- (point) 1) t)
  9921. (delete-region (match-beginning 0) (match-end 0)))
  9922. (verilog-insert "\n")
  9923. (verilog-insert-indent "/*AUTOINST*/")))))))))
  9924. ;;
  9925. ;; Auto diff:
  9926. ;;
  9927. (defun verilog-diff-buffers-p (b1 b2 &optional whitespace)
  9928. "Return nil if buffers B1 and B2 have same contents.
  9929. Else, return point in B1 that first mismatches.
  9930. If optional WHITESPACE true, ignore whitespace."
  9931. (save-excursion
  9932. (let* ((case-fold-search nil) ; compare-buffer-substrings cares
  9933. (p1 (with-current-buffer b1 (goto-char (point-min))))
  9934. (p2 (with-current-buffer b2 (goto-char (point-min))))
  9935. (maxp1 (with-current-buffer b1 (point-max)))
  9936. (maxp2 (with-current-buffer b2 (point-max)))
  9937. (op1 -1) (op2 -1)
  9938. progress size)
  9939. (while (not (and (eq p1 op1) (eq p2 op2)))
  9940. ;; If both windows have whitespace optionally skip over it.
  9941. (when whitespace
  9942. ;; skip-syntax-* doesn't count \n
  9943. (with-current-buffer b1
  9944. (goto-char p1)
  9945. (skip-chars-forward " \t\n\r\f\v")
  9946. (setq p1 (point)))
  9947. (with-current-buffer b2
  9948. (goto-char p2)
  9949. (skip-chars-forward " \t\n\r\f\v")
  9950. (setq p2 (point))))
  9951. (setq size (min (- maxp1 p1) (- maxp2 p2)))
  9952. (setq progress (compare-buffer-substrings b2 p2 (+ size p2)
  9953. b1 p1 (+ size p1)))
  9954. (setq progress (if (zerop progress) size (1- (abs progress))))
  9955. (setq op1 p1 op2 p2
  9956. p1 (+ p1 progress)
  9957. p2 (+ p2 progress)))
  9958. ;; Return value
  9959. (if (and (eq p1 maxp1) (eq p2 maxp2))
  9960. nil p1))))
  9961. (defun verilog-diff-file-with-buffer (f1 b2 &optional whitespace show)
  9962. "View the differences between file F1 and buffer B2.
  9963. This requires the external program `diff-command' to be in your `exec-path',
  9964. and uses `diff-switches' in which you may want to have \"-u\" flag.
  9965. Ignores WHITESPACE if t, and writes output to stdout if SHOW."
  9966. ;; Similar to `diff-buffer-with-file' but works on XEmacs, and doesn't
  9967. ;; call `diff' as `diff' has different calling semantics on different
  9968. ;; versions of Emacs.
  9969. (if (not (file-exists-p f1))
  9970. (message "Buffer %s has no associated file on disc" (buffer-name b2))
  9971. (with-temp-buffer "*Verilog-Diff*"
  9972. (let ((outbuf (current-buffer))
  9973. (f2 (make-temp-file "vm-diff-auto-")))
  9974. (unwind-protect
  9975. (progn
  9976. (with-current-buffer b2
  9977. (save-restriction
  9978. (widen)
  9979. (write-region (point-min) (point-max) f2 nil 'nomessage)))
  9980. (call-process diff-command nil outbuf t
  9981. diff-switches ; User may want -u in diff-switches
  9982. (if whitespace "-b" "")
  9983. f1 f2)
  9984. ;; Print out results. Alternatively we could have call-processed
  9985. ;; ourself, but this way we can reuse diff switches
  9986. (when show
  9987. (with-current-buffer outbuf (message "%s" (buffer-string))))))
  9988. (sit-for 0)
  9989. (when (file-exists-p f2)
  9990. (delete-file f2))))))
  9991. (defun verilog-diff-report (b1 b2 diffpt)
  9992. "Report differences detected with `verilog-diff-auto'.
  9993. Differences are between buffers B1 and B2, starting at point
  9994. DIFFPT. This function is called via `verilog-diff-function'."
  9995. (let ((name1 (with-current-buffer b1 (buffer-file-name))))
  9996. (verilog-warn "%s:%d: Difference in AUTO expansion found"
  9997. name1 (with-current-buffer b1
  9998. (count-lines (point-min) diffpt)))
  9999. (cond (noninteractive
  10000. (verilog-diff-file-with-buffer name1 b2 t t))
  10001. (t
  10002. (ediff-buffers b1 b2)))))
  10003. (defun verilog-diff-auto ()
  10004. "Expand AUTOs in a temporary buffer and indicate any change.
  10005. Whitespace is ignored when detecting differences, but once a
  10006. difference is detected, whitespace differences may be shown.
  10007. To call this from the command line, see \\[verilog-batch-diff-auto].
  10008. The action on differences is selected with
  10009. `verilog-diff-function'. The default is `verilog-diff-report'
  10010. which will report an error and run `ediff' in interactive mode,
  10011. or `diff' in batch mode."
  10012. (interactive)
  10013. (let ((b1 (current-buffer)) b2 diffpt
  10014. (name1 (buffer-file-name))
  10015. (newname "*Verilog-Diff*"))
  10016. (save-excursion
  10017. (when (get-buffer newname)
  10018. (kill-buffer newname))
  10019. (setq b2 (let (buffer-file-name) ; Else clone is upset
  10020. (clone-buffer newname)))
  10021. (with-current-buffer b2
  10022. ;; auto requires the filename, but can't have same filename in two
  10023. ;; buffers; so override both b1 and b2's names
  10024. (let ((buffer-file-name name1))
  10025. (unwind-protect
  10026. (progn
  10027. (with-current-buffer b1 (setq buffer-file-name nil))
  10028. (verilog-auto)
  10029. (when (not verilog-auto-star-save)
  10030. (verilog-delete-auto-star-implicit)))
  10031. ;; Restore name if unwind
  10032. (with-current-buffer b1 (setq buffer-file-name name1)))))
  10033. ;;
  10034. (setq diffpt (verilog-diff-buffers-p b1 b2 t))
  10035. (cond ((not diffpt)
  10036. (unless noninteractive (message "AUTO expansion identical"))
  10037. (kill-buffer newname)) ; Nice to cleanup after oneself
  10038. (t
  10039. (funcall verilog-diff-function b1 b2 diffpt)))
  10040. ;; Return result of compare
  10041. diffpt)))
  10042. ;;
  10043. ;; Auto save
  10044. ;;
  10045. (defun verilog-auto-save-check ()
  10046. "On saving see if we need auto update."
  10047. (cond ((not verilog-auto-save-policy)) ; disabled
  10048. ((not (save-excursion
  10049. (save-match-data
  10050. (let ((case-fold-search nil))
  10051. (goto-char (point-min))
  10052. (re-search-forward "AUTO" nil t))))))
  10053. ((eq verilog-auto-save-policy 'force)
  10054. (verilog-auto))
  10055. ((not (buffer-modified-p)))
  10056. ((eq verilog-auto-update-tick (buffer-chars-modified-tick))) ; up-to-date
  10057. ((eq verilog-auto-save-policy 'detect)
  10058. (verilog-auto))
  10059. (t
  10060. (when (yes-or-no-p "AUTO statements not recomputed, do it now? ")
  10061. (verilog-auto))
  10062. ;; Don't ask again if didn't update
  10063. (set (make-local-variable 'verilog-auto-update-tick) (buffer-chars-modified-tick))))
  10064. (when (not verilog-auto-star-save)
  10065. (verilog-delete-auto-star-implicit))
  10066. nil) ; Always return nil -- we don't write the file ourselves
  10067. (defun verilog-auto-read-locals ()
  10068. "Return file local variable segment at bottom of file."
  10069. (save-excursion
  10070. (goto-char (point-max))
  10071. (if (re-search-backward "Local Variables:" nil t)
  10072. (buffer-substring-no-properties (point) (point-max))
  10073. "")))
  10074. (defun verilog-auto-reeval-locals (&optional force)
  10075. "Read file local variable segment at bottom of file if it has changed.
  10076. If FORCE, always reread it."
  10077. (let ((curlocal (verilog-auto-read-locals)))
  10078. (when (or force (not (equal verilog-auto-last-file-locals curlocal)))
  10079. (set (make-local-variable 'verilog-auto-last-file-locals) curlocal)
  10080. ;; Note this may cause this function to be recursively invoked,
  10081. ;; because hack-local-variables may call (verilog-mode)
  10082. ;; The above when statement will prevent it from recursing forever.
  10083. (hack-local-variables)
  10084. t)))
  10085. ;;; Auto creation:
  10086. ;;
  10087. (defun verilog-auto-arg-ports (sigs message indent-pt)
  10088. "Print a list of ports for AUTOARG.
  10089. Takes SIGS list, adds MESSAGE to front and inserts each at INDENT-PT."
  10090. (when sigs
  10091. (when verilog-auto-arg-sort
  10092. (setq sigs (sort (copy-alist sigs) `verilog-signals-sort-compare)))
  10093. (insert "\n")
  10094. (indent-to indent-pt)
  10095. (insert message)
  10096. (insert "\n")
  10097. (let ((space ""))
  10098. (indent-to indent-pt)
  10099. (while sigs
  10100. (cond ((equal verilog-auto-arg-format 'single)
  10101. (insert space)
  10102. (indent-to indent-pt)
  10103. (setq space "\n"))
  10104. ;; verilog-auto-arg-format 'packed
  10105. ((> (+ 2 (current-column) (length (verilog-sig-name (car sigs)))) fill-column)
  10106. (insert "\n")
  10107. (indent-to indent-pt)
  10108. (setq space " "))
  10109. (t
  10110. (insert space)
  10111. (setq space " ")))
  10112. (insert (verilog-sig-name (car sigs)) ",")
  10113. (setq sigs (cdr sigs))))))
  10114. (defun verilog-auto-arg ()
  10115. "Expand AUTOARG statements.
  10116. Replace the argument declarations at the beginning of the
  10117. module with ones automatically derived from input and output
  10118. statements. This can be dangerous if the module is instantiated
  10119. using position-based connections, so use only name-based when
  10120. instantiating the resulting module. Long lines are split based
  10121. on the `fill-column', see \\[set-fill-column].
  10122. Limitations:
  10123. Concatenation and outputting partial buses is not supported.
  10124. Typedefs must match `verilog-typedef-regexp', which is disabled by default.
  10125. For example:
  10126. module ExampArg (/*AUTOARG*/);
  10127. input i;
  10128. output o;
  10129. endmodule
  10130. Typing \\[verilog-auto] will make this into:
  10131. module ExampArg (/*AUTOARG*/
  10132. // Outputs
  10133. o,
  10134. // Inputs
  10135. i
  10136. );
  10137. input i;
  10138. output o;
  10139. endmodule
  10140. The argument declarations may be printed in declaration order to
  10141. best suit order based instantiations, or alphabetically, based on
  10142. the `verilog-auto-arg-sort' variable.
  10143. Formatting is controlled with `verilog-auto-arg-format' variable.
  10144. Any ports declared between the ( and /*AUTOARG*/ are presumed to be
  10145. predeclared and are not redeclared by AUTOARG. AUTOARG will make a
  10146. conservative guess on adding a comma for the first signal, if you have
  10147. any ifdefs or complicated expressions before the AUTOARG you will need
  10148. to choose the comma yourself.
  10149. Avoid declaring ports manually, as it makes code harder to maintain."
  10150. (save-excursion
  10151. (let* ((modi (verilog-modi-current))
  10152. (moddecls (verilog-modi-get-decls modi))
  10153. (skip-pins (aref (verilog-read-arg-pins) 0)))
  10154. (verilog-repair-open-comma)
  10155. (verilog-auto-arg-ports (verilog-signals-not-in
  10156. (verilog-decls-get-outputs moddecls)
  10157. skip-pins)
  10158. "// Outputs"
  10159. verilog-indent-level-declaration)
  10160. (verilog-auto-arg-ports (verilog-signals-not-in
  10161. (verilog-decls-get-inouts moddecls)
  10162. skip-pins)
  10163. "// Inouts"
  10164. verilog-indent-level-declaration)
  10165. (verilog-auto-arg-ports (verilog-signals-not-in
  10166. (verilog-decls-get-inputs moddecls)
  10167. skip-pins)
  10168. "// Inputs"
  10169. verilog-indent-level-declaration)
  10170. (verilog-repair-close-comma)
  10171. (unless (eq (char-before) ?/ )
  10172. (insert "\n"))
  10173. (indent-to verilog-indent-level-declaration))))
  10174. (defun verilog-auto-assign-modport ()
  10175. "Expand AUTOASSIGNMODPORT statements, as part of \\[verilog-auto].
  10176. Take input/output/inout statements from the specified interface
  10177. and modport and use to build assignments into the modport, for
  10178. making verification modules that connect to UVM interfaces.
  10179. The first parameter is the name of an interface.
  10180. The second parameter is a regexp of modports to read from in
  10181. that interface.
  10182. The third parameter is the instance name to use to dot reference into.
  10183. The optional fourth parameter is a regular expression, and only
  10184. signals matching the regular expression will be included.
  10185. Limitations:
  10186. Interface names must be resolvable to filenames. See `verilog-auto-inst'.
  10187. Inouts are not supported, as assignments must be unidirectional.
  10188. If a signal is part of the interface header and in both a
  10189. modport and the interface itself, it will not be listed. (As
  10190. this would result in a syntax error when the connections are
  10191. made.)
  10192. See the example in `verilog-auto-inout-modport'."
  10193. (save-excursion
  10194. (let* ((params (verilog-read-auto-params 3 4))
  10195. (submod (nth 0 params))
  10196. (modport-re (nth 1 params))
  10197. (inst-name (nth 2 params))
  10198. (regexp (nth 3 params))
  10199. direction-re submodi) ; direction argument not supported until requested
  10200. ;; Lookup position, etc of co-module
  10201. ;; Note this may raise an error
  10202. (when (setq submodi (verilog-modi-lookup submod t))
  10203. (let* ((indent-pt (current-indentation))
  10204. (submoddecls (verilog-modi-get-decls submodi))
  10205. (submodportdecls (verilog-modi-modport-lookup submodi modport-re))
  10206. (sig-list-i (verilog-signals-in ; Decls doesn't have data types, must resolve
  10207. (verilog-decls-get-vars submoddecls)
  10208. (verilog-signals-not-in
  10209. (verilog-decls-get-inputs submodportdecls)
  10210. (verilog-decls-get-ports submoddecls))))
  10211. (sig-list-o (verilog-signals-in ; Decls doesn't have data types, must resolve
  10212. (verilog-decls-get-vars submoddecls)
  10213. (verilog-signals-not-in
  10214. (verilog-decls-get-outputs submodportdecls)
  10215. (verilog-decls-get-ports submoddecls)))))
  10216. (forward-line 1)
  10217. (setq sig-list-i (verilog-signals-edit-wire-reg
  10218. (verilog-signals-matching-dir-re
  10219. (verilog-signals-matching-regexp sig-list-i regexp)
  10220. "input" direction-re))
  10221. sig-list-o (verilog-signals-edit-wire-reg
  10222. (verilog-signals-matching-dir-re
  10223. (verilog-signals-matching-regexp sig-list-o regexp)
  10224. "output" direction-re)))
  10225. (setq sig-list-i (sort (copy-alist sig-list-i) `verilog-signals-sort-compare))
  10226. (setq sig-list-o (sort (copy-alist sig-list-o) `verilog-signals-sort-compare))
  10227. (when (or sig-list-i sig-list-o)
  10228. (verilog-insert-indent "// Beginning of automatic assignments from modport\n")
  10229. ;; Don't sort them so an upper AUTOINST will match the main module
  10230. (let ((sigs sig-list-o))
  10231. (while sigs
  10232. (verilog-insert-indent "assign " (verilog-sig-name (car sigs))
  10233. " = " inst-name
  10234. "." (verilog-sig-name (car sigs)) ";\n")
  10235. (setq sigs (cdr sigs))))
  10236. (let ((sigs sig-list-i))
  10237. (while sigs
  10238. (verilog-insert-indent "assign " inst-name
  10239. "." (verilog-sig-name (car sigs))
  10240. " = " (verilog-sig-name (car sigs)) ";\n")
  10241. (setq sigs (cdr sigs))))
  10242. (verilog-insert-indent "// End of automatics\n")))))))
  10243. (defun verilog-auto-inst-port-map (_port-st)
  10244. nil)
  10245. (defvar vl-cell-type nil "See `verilog-auto-inst'.") ; Prevent compile warning
  10246. (defvar vl-cell-name nil "See `verilog-auto-inst'.") ; Prevent compile warning
  10247. (defvar vl-modport nil "See `verilog-auto-inst'.") ; Prevent compile warning
  10248. (defvar vl-name nil "See `verilog-auto-inst'.") ; Prevent compile warning
  10249. (defvar vl-width nil "See `verilog-auto-inst'.") ; Prevent compile warning
  10250. (defvar vl-dir nil "See `verilog-auto-inst'.") ; Prevent compile warning
  10251. (defvar vl-bits nil "See `verilog-auto-inst'.") ; Prevent compile warning
  10252. (defvar vl-mbits nil "See `verilog-auto-inst'.") ; Prevent compile warning
  10253. (defun verilog-auto-inst-port (port-st indent-pt moddecls tpl-list tpl-num for-star par-values)
  10254. "Print out an instantiation connection for this PORT-ST.
  10255. Insert to INDENT-PT, use template TPL-LIST.
  10256. @ are instantiation numbers, replaced with TPL-NUM.
  10257. @\"(expression @)\" are evaluated, with @ as a variable.
  10258. If FOR-STAR add comment it is a .* expansion.
  10259. If PAR-VALUES replace final strings with these parameter values."
  10260. (let* ((port (verilog-sig-name port-st))
  10261. (tpl-ass (or (assoc port (car tpl-list))
  10262. (verilog-auto-inst-port-map port-st)))
  10263. ;; vl-* are documented for user use
  10264. (vl-name (verilog-sig-name port-st))
  10265. (vl-width (verilog-sig-width port-st))
  10266. (vl-modport (verilog-sig-modport port-st))
  10267. (vl-mbits (if (verilog-sig-multidim port-st)
  10268. (verilog-sig-multidim-string port-st) ""))
  10269. (vl-bits (if (or verilog-auto-inst-vector
  10270. (not (assoc port (verilog-decls-get-signals moddecls)))
  10271. (not (equal (verilog-sig-bits port-st)
  10272. (verilog-sig-bits
  10273. (assoc port (verilog-decls-get-signals moddecls))))))
  10274. (or (verilog-sig-bits port-st) "")
  10275. ""))
  10276. (case-fold-search nil)
  10277. (check-values par-values)
  10278. tpl-net dflt-bits)
  10279. ;; Replace parameters in bit-width
  10280. (when (and check-values
  10281. (not (equal vl-bits "")))
  10282. (while check-values
  10283. (setq vl-bits (verilog-string-replace-matches
  10284. (concat "\\<" (nth 0 (car check-values)) "\\>")
  10285. (concat "(" (nth 1 (car check-values)) ")")
  10286. t t vl-bits)
  10287. vl-mbits (verilog-string-replace-matches
  10288. (concat "\\<" (nth 0 (car check-values)) "\\>")
  10289. (concat "(" (nth 1 (car check-values)) ")")
  10290. t t vl-mbits)
  10291. check-values (cdr check-values)))
  10292. (setq vl-bits (verilog-simplify-range-expression vl-bits)
  10293. vl-mbits (verilog-simplify-range-expression vl-mbits)
  10294. vl-width (verilog-make-width-expression vl-bits))) ; Not in the loop for speed
  10295. ;; Default net value if not found
  10296. (setq dflt-bits (if (and (verilog-sig-bits port-st)
  10297. (or (verilog-sig-multidim port-st)
  10298. (verilog-sig-memory port-st)))
  10299. (concat "/*" vl-mbits vl-bits "*/")
  10300. (concat vl-bits))
  10301. tpl-net (concat port
  10302. (if (and vl-modport
  10303. ;; .modport cannot be added if attachment is
  10304. ;; already declared as modport, VCS croaks
  10305. (let ((sig (assoc port (verilog-decls-get-interfaces moddecls))))
  10306. (not (and sig (verilog-sig-modport sig)))))
  10307. (concat "." vl-modport) "")
  10308. dflt-bits))
  10309. ;; Find template
  10310. (cond (tpl-ass ; Template of exact port name
  10311. (setq tpl-net (nth 1 tpl-ass)))
  10312. ((nth 1 tpl-list) ; Wildcards in template, search them
  10313. (let ((wildcards (nth 1 tpl-list)))
  10314. (while wildcards
  10315. (when (string-match (nth 0 (car wildcards)) port)
  10316. (setq tpl-ass (car wildcards) ; so allow @ parsing
  10317. tpl-net (replace-match (nth 1 (car wildcards))
  10318. t nil port)))
  10319. (setq wildcards (cdr wildcards))))))
  10320. ;; Parse Templated variable
  10321. (when tpl-ass
  10322. ;; Evaluate @"(lispcode)"
  10323. (when (string-match "@\".*[^\\]\"" tpl-net)
  10324. (while (string-match "@\"\\(\\([^\\\"]*\\(\\\\.\\)*\\)*\\)\"" tpl-net)
  10325. (setq tpl-net
  10326. (concat
  10327. (substring tpl-net 0 (match-beginning 0))
  10328. (save-match-data
  10329. (let* ((expr (match-string 1 tpl-net))
  10330. (value
  10331. (progn
  10332. (setq expr (verilog-string-replace-matches "\\\\\"" "\"" nil nil expr))
  10333. (setq expr (verilog-string-replace-matches "@" tpl-num nil nil expr))
  10334. (prin1 (eval (car (read-from-string expr)))
  10335. (lambda (_ch) ())))))
  10336. (if (numberp value) (setq value (number-to-string value)))
  10337. value))
  10338. (substring tpl-net (match-end 0))))))
  10339. ;; Replace @ and [] magic variables in final output
  10340. (setq tpl-net (verilog-string-replace-matches "@" tpl-num nil nil tpl-net))
  10341. (setq tpl-net (verilog-string-replace-matches "\\[\\]\\[\\]" dflt-bits nil nil tpl-net))
  10342. (setq tpl-net (verilog-string-replace-matches "\\[\\]" vl-bits nil nil tpl-net)))
  10343. ;; Insert it
  10344. (indent-to indent-pt)
  10345. (insert "." port)
  10346. (unless (and verilog-auto-inst-dot-name
  10347. (equal port tpl-net))
  10348. (indent-to verilog-auto-inst-column)
  10349. (insert "(" tpl-net ")"))
  10350. (insert ",")
  10351. (cond (tpl-ass
  10352. (verilog-read-auto-template-hit tpl-ass)
  10353. (indent-to (+ (if (< verilog-auto-inst-column 48) 24 16)
  10354. verilog-auto-inst-column))
  10355. ;; verilog-insert requires the complete comment in one call - including the newline
  10356. (cond ((equal verilog-auto-inst-template-numbers `lhs)
  10357. (verilog-insert " // Templated"
  10358. " LHS: " (nth 0 tpl-ass)
  10359. "\n"))
  10360. (verilog-auto-inst-template-numbers
  10361. (verilog-insert " // Templated"
  10362. " T" (int-to-string (nth 2 tpl-ass))
  10363. " L" (int-to-string (nth 3 tpl-ass))
  10364. "\n"))
  10365. (t
  10366. (verilog-insert " // Templated\n"))))
  10367. (for-star
  10368. (indent-to (+ (if (< verilog-auto-inst-column 48) 24 16)
  10369. verilog-auto-inst-column))
  10370. (verilog-insert " // Implicit .\*\n")) ;For some reason the . or * must be escaped...
  10371. (t
  10372. (insert "\n")))))
  10373. ;;(verilog-auto-inst-port (list "foo" "[5:0]") 10 (list (list "foo" "a@\"(% (+ @ 1) 4)\"a")) "3")
  10374. ;;(x "incom[@\"(+ (* 8 @) 7)\":@\"(* 8 @)\"]")
  10375. ;;(x ".out (outgo[@\"(concat (+ (* 8 @) 7) \\\":\\\" ( * 8 @))\"]));")
  10376. (defun verilog-auto-inst-port-list (sig-list indent-pt moddecls tpl-list tpl-num for-star par-values)
  10377. "For `verilog-auto-inst' print a list of ports using `verilog-auto-inst-port'."
  10378. (when verilog-auto-inst-sort
  10379. (setq sig-list (sort (copy-alist sig-list) `verilog-signals-sort-compare)))
  10380. (mapc (lambda (port)
  10381. (verilog-auto-inst-port port indent-pt moddecls
  10382. tpl-list tpl-num for-star par-values))
  10383. sig-list))
  10384. (defun verilog-auto-inst-first ()
  10385. "Insert , etc before first ever port in this instant, as part of \\[verilog-auto-inst]."
  10386. ;; Do we need a trailing comma?
  10387. ;; There maybe an ifdef or something similar before us. What a mess. Thus
  10388. ;; to avoid trouble we only insert on preceding ) or *.
  10389. ;; Insert first port on new line
  10390. (insert "\n") ; Must insert before search, so point will move forward if insert comma
  10391. (save-excursion
  10392. (verilog-re-search-backward-quick "[^ \t\n\f]" nil nil)
  10393. (when (looking-at ")\\|\\*") ; Generally don't insert, unless we are fairly sure
  10394. (forward-char 1)
  10395. (insert ","))))
  10396. (defun verilog-auto-star ()
  10397. "Expand SystemVerilog .* pins, as part of \\[verilog-auto].
  10398. If `verilog-auto-star-expand' is set, .* pins are treated if they were
  10399. AUTOINST statements, otherwise they are ignored. For safety, Verilog mode
  10400. will also ignore any .* that are not last in your pin list (this prevents
  10401. it from deleting pins following the .* when it expands the AUTOINST.)
  10402. On writing your file, unless `verilog-auto-star-save' is set, any
  10403. non-templated expanded pins will be removed. You may do this at any time
  10404. with \\[verilog-delete-auto-star-implicit].
  10405. If you are converting a module to use .* for the first time, you may wish
  10406. to use \\[verilog-inject-auto] and then replace the created AUTOINST with .*.
  10407. See `verilog-auto-inst' for examples, templates, and more information."
  10408. (when (verilog-auto-star-safe)
  10409. (verilog-auto-inst)))
  10410. (defun verilog-auto-inst ()
  10411. "Expand AUTOINST statements, as part of \\[verilog-auto].
  10412. Replace the pin connections to an instantiation or interface
  10413. declaration with ones automatically derived from the module or
  10414. interface header of the instantiated item.
  10415. If `verilog-auto-star-expand' is set, also expand SystemVerilog .* ports,
  10416. and delete them before saving unless `verilog-auto-star-save' is set.
  10417. See `verilog-auto-star' for more information.
  10418. The pins are printed in declaration order or alphabetically,
  10419. based on the `verilog-auto-inst-sort' variable.
  10420. Limitations:
  10421. Module names must be resolvable to filenames by adding a
  10422. `verilog-library-extensions', and being found in the same directory, or
  10423. by changing the variable `verilog-library-flags' or
  10424. `verilog-library-directories'. Macros `modname are translated through the
  10425. vh-{name} Emacs variable, if that is not found, it just ignores the \\=`.
  10426. In templates you must have one signal per line, ending in a ), or ));,
  10427. and have proper () nesting, including a final ); to end the template.
  10428. Typedefs must match `verilog-typedef-regexp', which is disabled by default.
  10429. SystemVerilog multidimensional input/output has only experimental support.
  10430. SystemVerilog .name syntax is used if `verilog-auto-inst-dot-name' is set.
  10431. Parameters referenced by the instantiation will remain symbolic, unless
  10432. `verilog-auto-inst-param-value' is set.
  10433. Gate primitives (and/or) may have AUTOINST for the purpose of
  10434. AUTOWIRE declarations, etc. Gates are the only case when
  10435. position based connections are passed.
  10436. The array part of arrayed instances are ignored; this may
  10437. result in undesirable default AUTOINST connections; use a
  10438. template instead.
  10439. For example, first take the submodule InstModule.v:
  10440. module InstModule (o,i);
  10441. output [31:0] o;
  10442. input i;
  10443. wire [31:0] o = {32{i}};
  10444. endmodule
  10445. This is then used in an upper level module:
  10446. module ExampInst (o,i);
  10447. output o;
  10448. input i;
  10449. InstModule instName
  10450. (/*AUTOINST*/);
  10451. endmodule
  10452. Typing \\[verilog-auto] will make this into:
  10453. module ExampInst (o,i);
  10454. output o;
  10455. input i;
  10456. InstModule instName
  10457. (/*AUTOINST*/
  10458. // Outputs
  10459. .ov (ov[31:0]),
  10460. // Inputs
  10461. .i (i));
  10462. endmodule
  10463. Where the list of inputs and outputs came from the inst module.
  10464. Exceptions:
  10465. Unless you are instantiating a module multiple times, or the module is
  10466. something trivial like an adder, DO NOT CHANGE SIGNAL NAMES ACROSS HIERARCHY.
  10467. It just makes for unmaintainable code. To sanitize signal names, try
  10468. vrename from URL `http://www.veripool.org'.
  10469. When you need to violate this suggestion there are two ways to list
  10470. exceptions, placing them before the AUTOINST, or using templates.
  10471. Any ports defined before the /*AUTOINST*/ are not included in the list of
  10472. automatics. This is similar to making a template as described below, but
  10473. is restricted to simple connections just like you normally make. Also note
  10474. that any signals before the AUTOINST will only be picked up by AUTOWIRE if
  10475. you have the appropriate // Input or // Output comment, and exactly the
  10476. same line formatting as AUTOINST itself uses.
  10477. InstModule instName
  10478. (// Inputs
  10479. .i (my_i_dont_mess_with_it),
  10480. /*AUTOINST*/
  10481. // Outputs
  10482. .ov (ov[31:0]));
  10483. Templates:
  10484. For multiple instantiations based upon a single template, create a
  10485. commented out template:
  10486. /* InstModule AUTO_TEMPLATE (
  10487. .sig3 (sigz[]),
  10488. );
  10489. */
  10490. Templates go ABOVE the instantiation(s). When an instantiation is
  10491. expanded `verilog-mode' simply searches up for the closest template.
  10492. Thus you can have multiple templates for the same module, just alternate
  10493. between the template for an instantiation and the instantiation itself.
  10494. (For backward compatibility if no template is found above, it
  10495. will also look below, but do not use this behavior in new designs.)
  10496. The module name must be the same as the name of the module in the
  10497. instantiation name, and the code \"AUTO_TEMPLATE\" must be in these exact
  10498. words and capitalized. Only signals that must be different for each
  10499. instantiation need to be listed.
  10500. Inside a template, a [] in a connection name (with nothing else
  10501. inside the brackets) will be replaced by the same bus subscript
  10502. as it is being connected to, or the [] will be removed if it is
  10503. a single bit signal.
  10504. Inside a template, a [][] in a connection name will behave
  10505. similarly to a [] for scalar or single-dimensional connection;
  10506. for a multidimensional connection it will print a comment
  10507. similar to that printed when a template is not used. Generally
  10508. it is a good idea to do this for all connections in a template,
  10509. as then they will work for any width signal, and with AUTOWIRE.
  10510. See PTL_BUS becoming PTL_BUSNEW below.
  10511. Inside a template, a [] in a connection name (with nothing else inside
  10512. the brackets) will be replaced by the same bus subscript as it is being
  10513. connected to, or the [] will be removed if it is a single bit signal.
  10514. Generally it is a good idea to do this for all connections in a template,
  10515. as then they will work for any width signal, and with AUTOWIRE. See
  10516. PTL_BUS becoming PTL_BUSNEW below.
  10517. If you have a complicated template, set `verilog-auto-inst-template-numbers'
  10518. to see which regexps are matching. Don't leave that mode set after
  10519. debugging is completed though, it will result in lots of extra differences
  10520. and merge conflicts.
  10521. Setting `verilog-auto-template-warn-unused' will report errors
  10522. if any template lines are unused.
  10523. For example:
  10524. /* InstModule AUTO_TEMPLATE (
  10525. .ptl_bus (ptl_busnew[]),
  10526. );
  10527. */
  10528. InstModule ms2m (/*AUTOINST*/);
  10529. Typing \\[verilog-auto] will make this into:
  10530. InstModule ms2m (/*AUTOINST*/
  10531. // Outputs
  10532. .NotInTemplate (NotInTemplate),
  10533. .ptl_bus (ptl_busnew[3:0]), // Templated
  10534. ....
  10535. Multiple Module Templates:
  10536. The same template lines can be applied to multiple modules with
  10537. the syntax as follows:
  10538. /* InstModuleA AUTO_TEMPLATE
  10539. InstModuleB AUTO_TEMPLATE
  10540. InstModuleC AUTO_TEMPLATE
  10541. InstModuleD AUTO_TEMPLATE (
  10542. .ptl_bus (ptl_busnew[]),
  10543. );
  10544. */
  10545. Note there is only one AUTO_TEMPLATE opening parenthesis.
  10546. @ Templates:
  10547. It is common to instantiate a cell multiple times, so templates make it
  10548. trivial to substitute part of the cell name into the connection name.
  10549. /* InstName AUTO_TEMPLATE <optional \"REGEXP\"> (
  10550. .sig1 (sigx[@]),
  10551. .sig2 (sigy[@\"(% (+ 1 @) 4)\"]),
  10552. );
  10553. */
  10554. If no regular expression is provided immediately after the AUTO_TEMPLATE
  10555. keyword, then the @ character in any connection names will be replaced
  10556. with the instantiation number; the first digits found in the cell's
  10557. instantiation name.
  10558. If a regular expression is provided, the @ character will be replaced
  10559. with the first () grouping that matches against the cell name. Using a
  10560. regexp of `\\([0-9]+\\)' provides identical values for @ as when no
  10561. regexp is provided. If you use multiple layers of parenthesis,
  10562. `test\\([^0-9]+\\)_\\([0-9]+\\)' would replace @ with non-number
  10563. characters after test and before _, whereas
  10564. `\\(test\\([a-z]+\\)_\\([0-9]+\\)\\)' would replace @ with the entire
  10565. match.
  10566. For example:
  10567. /* InstModule AUTO_TEMPLATE (
  10568. .ptl_mapvalidx (ptl_mapvalid[@]),
  10569. .ptl_mapvalidp1x (ptl_mapvalid[@\"(% (+ 1 @) 4)\"]),
  10570. );
  10571. */
  10572. InstModule ms2m (/*AUTOINST*/);
  10573. Typing \\[verilog-auto] will make this into:
  10574. InstModule ms2m (/*AUTOINST*/
  10575. // Outputs
  10576. .ptl_mapvalidx (ptl_mapvalid[2]),
  10577. .ptl_mapvalidp1x (ptl_mapvalid[3]));
  10578. Note the @ character was replaced with the 2 from \"ms2m\".
  10579. Alternatively, using a regular expression for @:
  10580. /* InstModule AUTO_TEMPLATE \"_\\([a-z]+\\)\" (
  10581. .ptl_mapvalidx (@_ptl_mapvalid),
  10582. .ptl_mapvalidp1x (ptl_mapvalid_@),
  10583. );
  10584. */
  10585. InstModule ms2_FOO (/*AUTOINST*/);
  10586. InstModule ms2_BAR (/*AUTOINST*/);
  10587. Typing \\[verilog-auto] will make this into:
  10588. InstModule ms2_FOO (/*AUTOINST*/
  10589. // Outputs
  10590. .ptl_mapvalidx (FOO_ptl_mapvalid),
  10591. .ptl_mapvalidp1x (ptl_mapvalid_FOO));
  10592. InstModule ms2_BAR (/*AUTOINST*/
  10593. // Outputs
  10594. .ptl_mapvalidx (BAR_ptl_mapvalid),
  10595. .ptl_mapvalidp1x (ptl_mapvalid_BAR));
  10596. Regexp Templates:
  10597. A template entry of the form
  10598. .pci_req\\([0-9]+\\)_l (pci_req_jtag_[\\1]),
  10599. will apply an Emacs style regular expression search for any port beginning
  10600. in pci_req followed by numbers and ending in _l and connecting that to
  10601. the pci_req_jtag_[] net, with the bus subscript coming from what matches
  10602. inside the first set of \\( \\). Thus pci_req2_l becomes pci_req_jtag_[2].
  10603. Since \\([0-9]+\\) is so common and ugly to read, a @ in the port name
  10604. does the same thing. (Note a @ in the connection/replacement text is
  10605. completely different -- still use \\1 there!) Thus this is the same as
  10606. the above template:
  10607. .pci_req@_l (pci_req_jtag_[\\1]),
  10608. Here's another example to remove the _l, useful when naming conventions
  10609. specify _ alone to mean active low. Note the use of [] to keep the bus
  10610. subscript:
  10611. .\\(.*\\)_l (\\1_[]),
  10612. Lisp Templates:
  10613. First any regular expression template is expanded.
  10614. If the syntax @\"( ... )\" is found in a connection, the expression in
  10615. quotes will be evaluated as a Lisp expression, with @ replaced by the
  10616. instantiation number. The MAPVALIDP1X example above would put @+1 modulo
  10617. 4 into the brackets. Quote all double-quotes inside the expression with
  10618. a leading backslash (\\\"...\\\"); or if the Lisp template is also a
  10619. regexp template backslash the backslash quote (\\\\\"...\\\\\").
  10620. There are special variables defined that are useful in these
  10621. Lisp functions:
  10622. vl-name Name portion of the input/output port.
  10623. vl-bits Bus bits portion of the input/output port (`[2:0]').
  10624. vl-mbits Multidimensional array bits for port (`[2:0][3:0]').
  10625. vl-width Width of the input/output port (`3' for [2:0]).
  10626. May be a (...) expression if bits isn't a constant.
  10627. vl-dir Direction of the pin input/output/inout/interface.
  10628. vl-modport The modport, if an interface with a modport.
  10629. vl-cell-type Module name/type of the cell (`InstModule').
  10630. vl-cell-name Instance name of the cell (`instName').
  10631. Normal Lisp variables may be used in expressions. See
  10632. `verilog-read-defines' which can set vh-{definename} variables for use
  10633. here. Also, any comments of the form:
  10634. /*AUTO_LISP(setq foo 1)*/
  10635. will evaluate any Lisp expression inside the parenthesis between the
  10636. beginning of the buffer and the point of the AUTOINST. This allows
  10637. functions to be defined or variables to be changed between instantiations.
  10638. (See also `verilog-auto-insert-lisp' if you want the output from your
  10639. lisp function to be inserted.)
  10640. Note that when using lisp expressions errors may occur when @ is not a
  10641. number; you may need to use the standard Emacs Lisp functions
  10642. `number-to-string' and `string-to-number'.
  10643. After the evaluation is completed, @ substitution and [] substitution
  10644. occur.
  10645. For more information see the \\[verilog-faq] and forums at URL
  10646. `http://www.veripool.org'."
  10647. (save-excursion
  10648. ;; Find beginning
  10649. (let* ((pt (point))
  10650. (for-star (save-excursion (backward-char 2) (looking-at "\\.\\*")))
  10651. (indent-pt (save-excursion (verilog-backward-open-paren)
  10652. (1+ (current-column))))
  10653. (verilog-auto-inst-column (max verilog-auto-inst-column
  10654. (+ 16 (* 8 (/ (+ indent-pt 7) 8)))))
  10655. (modi (verilog-modi-current))
  10656. (moddecls (verilog-modi-get-decls modi))
  10657. submod submodi submoddecls
  10658. inst skip-pins tpl-list tpl-num did-first par-values)
  10659. ;; Find module name that is instantiated
  10660. (setq submod (verilog-read-inst-module)
  10661. inst (verilog-read-inst-name)
  10662. vl-cell-type submod
  10663. vl-cell-name inst
  10664. skip-pins (aref (verilog-read-inst-pins) 0))
  10665. ;; Parse any AUTO_LISP() before here
  10666. (verilog-read-auto-lisp (point-min) pt)
  10667. ;; Read parameters (after AUTO_LISP)
  10668. (setq par-values (and verilog-auto-inst-param-value
  10669. (verilog-read-inst-param-value)))
  10670. ;; Lookup position, etc of submodule
  10671. ;; Note this may raise an error
  10672. (when (and (not (member submod verilog-gate-keywords))
  10673. (setq submodi (verilog-modi-lookup submod t)))
  10674. (setq submoddecls (verilog-modi-get-decls submodi))
  10675. ;; If there's a number in the instantiation, it may be an argument to the
  10676. ;; automatic variable instantiation program.
  10677. (let* ((tpl-info (verilog-read-auto-template submod))
  10678. (tpl-regexp (aref tpl-info 0)))
  10679. (setq tpl-num (if (verilog-string-match-fold tpl-regexp inst)
  10680. (match-string 1 inst)
  10681. "")
  10682. tpl-list (aref tpl-info 1)))
  10683. ;; Find submodule's signals and dump
  10684. (let ((sig-list (and (equal (verilog-modi-get-type submodi) "interface")
  10685. (verilog-signals-not-in
  10686. (verilog-decls-get-vars submoddecls)
  10687. skip-pins)))
  10688. (vl-dir "interfaced"))
  10689. (when (and sig-list
  10690. verilog-auto-inst-interfaced-ports)
  10691. (when (not did-first) (verilog-auto-inst-first) (setq did-first t))
  10692. ;; Note these are searched for in verilog-read-sub-decls.
  10693. (verilog-insert-indent "// Interfaced\n")
  10694. (verilog-auto-inst-port-list sig-list indent-pt moddecls
  10695. tpl-list tpl-num for-star par-values)))
  10696. (let ((sig-list (verilog-signals-not-in
  10697. (verilog-decls-get-interfaces submoddecls)
  10698. skip-pins))
  10699. (vl-dir "interface"))
  10700. (when sig-list
  10701. (when (not did-first) (verilog-auto-inst-first) (setq did-first t))
  10702. ;; Note these are searched for in verilog-read-sub-decls.
  10703. (verilog-insert-indent "// Interfaces\n")
  10704. (verilog-auto-inst-port-list sig-list indent-pt moddecls
  10705. tpl-list tpl-num for-star par-values)))
  10706. (let ((sig-list (verilog-signals-not-in
  10707. (verilog-decls-get-outputs submoddecls)
  10708. skip-pins))
  10709. (vl-dir "output"))
  10710. (when sig-list
  10711. (when (not did-first) (verilog-auto-inst-first) (setq did-first t))
  10712. (verilog-insert-indent "// Outputs\n")
  10713. (verilog-auto-inst-port-list sig-list indent-pt moddecls
  10714. tpl-list tpl-num for-star par-values)))
  10715. (let ((sig-list (verilog-signals-not-in
  10716. (verilog-decls-get-inouts submoddecls)
  10717. skip-pins))
  10718. (vl-dir "inout"))
  10719. (when sig-list
  10720. (when (not did-first) (verilog-auto-inst-first) (setq did-first t))
  10721. (verilog-insert-indent "// Inouts\n")
  10722. (verilog-auto-inst-port-list sig-list indent-pt moddecls
  10723. tpl-list tpl-num for-star par-values)))
  10724. (let ((sig-list (verilog-signals-not-in
  10725. (verilog-decls-get-inputs submoddecls)
  10726. skip-pins))
  10727. (vl-dir "input"))
  10728. (when sig-list
  10729. (when (not did-first) (verilog-auto-inst-first) (setq did-first t))
  10730. (verilog-insert-indent "// Inputs\n")
  10731. (verilog-auto-inst-port-list sig-list indent-pt moddecls
  10732. tpl-list tpl-num for-star par-values)))
  10733. ;; Kill extra semi
  10734. (save-excursion
  10735. (cond (did-first
  10736. (re-search-backward "," pt t)
  10737. (delete-char 1)
  10738. (insert ");")
  10739. (search-forward "\n") ; Added by inst-port
  10740. (delete-char -1)
  10741. (if (search-forward ")" nil t) ; From user, moved up a line
  10742. (delete-char -1))
  10743. (if (search-forward ";" nil t) ; Don't error if user had syntax error and forgot it
  10744. (delete-char -1)))))))))
  10745. (defun verilog-auto-inst-param ()
  10746. "Expand AUTOINSTPARAM statements, as part of \\[verilog-auto].
  10747. Replace the parameter connections to an instantiation with ones
  10748. automatically derived from the module header of the instantiated netlist.
  10749. See \\[verilog-auto-inst] for limitations, and templates to customize the
  10750. output.
  10751. For example, first take the submodule InstModule.v:
  10752. module InstModule (o,i);
  10753. parameter PAR;
  10754. endmodule
  10755. This is then used in an upper level module:
  10756. module ExampInst (o,i);
  10757. parameter PAR;
  10758. InstModule #(/*AUTOINSTPARAM*/)
  10759. instName (/*AUTOINST*/);
  10760. endmodule
  10761. Typing \\[verilog-auto] will make this into:
  10762. module ExampInst (o,i);
  10763. output o;
  10764. input i;
  10765. InstModule #(/*AUTOINSTPARAM*/
  10766. // Parameters
  10767. .PAR (PAR));
  10768. instName (/*AUTOINST*/);
  10769. endmodule
  10770. Where the list of parameter connections come from the inst module.
  10771. Templates:
  10772. You can customize the parameter connections using AUTO_TEMPLATEs,
  10773. just as you would with \\[verilog-auto-inst]."
  10774. (save-excursion
  10775. ;; Find beginning
  10776. (let* ((pt (point))
  10777. (indent-pt (save-excursion (verilog-backward-open-paren)
  10778. (1+ (current-column))))
  10779. (verilog-auto-inst-column (max verilog-auto-inst-column
  10780. (+ 16 (* 8 (/ (+ indent-pt 7) 8)))))
  10781. (modi (verilog-modi-current))
  10782. (moddecls (verilog-modi-get-decls modi))
  10783. submod submodi submoddecls
  10784. inst skip-pins tpl-list tpl-num did-first)
  10785. ;; Find module name that is instantiated
  10786. (setq submod (save-excursion
  10787. ;; Get to the point where AUTOINST normally is to read the module
  10788. (verilog-re-search-forward-quick "[(;]" nil nil)
  10789. (verilog-read-inst-module))
  10790. inst (save-excursion
  10791. ;; Get to the point where AUTOINST normally is to read the module
  10792. (verilog-re-search-forward-quick "[(;]" nil nil)
  10793. (verilog-read-inst-name))
  10794. vl-cell-type submod
  10795. vl-cell-name inst
  10796. skip-pins (aref (verilog-read-inst-pins) 0))
  10797. ;; Parse any AUTO_LISP() before here
  10798. (verilog-read-auto-lisp (point-min) pt)
  10799. ;; Lookup position, etc of submodule
  10800. ;; Note this may raise an error
  10801. (when (setq submodi (verilog-modi-lookup submod t))
  10802. (setq submoddecls (verilog-modi-get-decls submodi))
  10803. ;; If there's a number in the instantiation, it may be an argument to the
  10804. ;; automatic variable instantiation program.
  10805. (let* ((tpl-info (verilog-read-auto-template submod))
  10806. (tpl-regexp (aref tpl-info 0)))
  10807. (setq tpl-num (if (verilog-string-match-fold tpl-regexp inst)
  10808. (match-string 1 inst)
  10809. "")
  10810. tpl-list (aref tpl-info 1)))
  10811. ;; Find submodule's signals and dump
  10812. (let ((sig-list (verilog-signals-not-in
  10813. (verilog-decls-get-gparams submoddecls)
  10814. skip-pins))
  10815. (vl-dir "parameter"))
  10816. (when sig-list
  10817. (when (not did-first) (verilog-auto-inst-first) (setq did-first t))
  10818. ;; Note these are searched for in verilog-read-sub-decls.
  10819. (verilog-insert-indent "// Parameters\n")
  10820. (verilog-auto-inst-port-list sig-list indent-pt moddecls
  10821. tpl-list tpl-num nil nil)))
  10822. ;; Kill extra semi
  10823. (save-excursion
  10824. (cond (did-first
  10825. (re-search-backward "," pt t)
  10826. (delete-char 1)
  10827. (insert ")")
  10828. (search-forward "\n") ; Added by inst-port
  10829. (delete-char -1)
  10830. (if (search-forward ")" nil t) ; From user, moved up a line
  10831. (delete-char -1)))))))))
  10832. (defun verilog-auto-reg ()
  10833. "Expand AUTOREG statements, as part of \\[verilog-auto].
  10834. Make reg statements for any output that isn't already declared,
  10835. and isn't a wire output from a block. `verilog-auto-wire-type'
  10836. may be used to change the datatype of the declarations.
  10837. Limitations:
  10838. This ONLY detects outputs of AUTOINSTants (see `verilog-read-sub-decls').
  10839. This does NOT work on memories, declare those yourself.
  10840. An example:
  10841. module ExampReg (o,i);
  10842. output o;
  10843. input i;
  10844. /*AUTOREG*/
  10845. always o = i;
  10846. endmodule
  10847. Typing \\[verilog-auto] will make this into:
  10848. module ExampReg (o,i);
  10849. output o;
  10850. input i;
  10851. /*AUTOREG*/
  10852. // Beginning of automatic regs (for this module's undeclared outputs)
  10853. reg o;
  10854. // End of automatics
  10855. always o = i;
  10856. endmodule"
  10857. (save-excursion
  10858. ;; Point must be at insertion point.
  10859. (let* ((indent-pt (current-indentation))
  10860. (modi (verilog-modi-current))
  10861. (moddecls (verilog-modi-get-decls modi))
  10862. (modsubdecls (verilog-modi-get-sub-decls modi))
  10863. (sig-list (verilog-signals-not-in
  10864. (verilog-decls-get-outputs moddecls)
  10865. (append (verilog-signals-with ; ignore typed signals
  10866. 'verilog-sig-type
  10867. (verilog-decls-get-outputs moddecls))
  10868. (verilog-decls-get-vars moddecls)
  10869. (verilog-decls-get-assigns moddecls)
  10870. (verilog-decls-get-consts moddecls)
  10871. (verilog-decls-get-gparams moddecls)
  10872. (verilog-subdecls-get-interfaced modsubdecls)
  10873. (verilog-subdecls-get-outputs modsubdecls)
  10874. (verilog-subdecls-get-inouts modsubdecls)))))
  10875. (when sig-list
  10876. (verilog-forward-or-insert-line)
  10877. (verilog-insert-indent "// Beginning of automatic regs (for this module's undeclared outputs)\n")
  10878. (verilog-insert-definition modi sig-list "reg" indent-pt nil)
  10879. (verilog-insert-indent "// End of automatics\n")))))
  10880. (defun verilog-auto-reg-input ()
  10881. "Expand AUTOREGINPUT statements, as part of \\[verilog-auto].
  10882. Make reg statements instantiation inputs that aren't already declared.
  10883. This is useful for making a top level shell for testing the module that is
  10884. to be instantiated.
  10885. Limitations:
  10886. This ONLY detects inputs of AUTOINSTants (see `verilog-read-sub-decls').
  10887. This does NOT work on memories, declare those yourself.
  10888. An example (see `verilog-auto-inst' for what else is going on here):
  10889. module ExampRegInput (o,i);
  10890. output o;
  10891. input i;
  10892. /*AUTOREGINPUT*/
  10893. InstModule instName
  10894. (/*AUTOINST*/);
  10895. endmodule
  10896. Typing \\[verilog-auto] will make this into:
  10897. module ExampRegInput (o,i);
  10898. output o;
  10899. input i;
  10900. /*AUTOREGINPUT*/
  10901. // Beginning of automatic reg inputs (for undeclared ...
  10902. reg [31:0] iv; // From inst of inst.v
  10903. // End of automatics
  10904. InstModule instName
  10905. (/*AUTOINST*/
  10906. // Outputs
  10907. .o (o[31:0]),
  10908. // Inputs
  10909. .iv (iv));
  10910. endmodule"
  10911. (save-excursion
  10912. ;; Point must be at insertion point.
  10913. (let* ((indent-pt (current-indentation))
  10914. (modi (verilog-modi-current))
  10915. (moddecls (verilog-modi-get-decls modi))
  10916. (modsubdecls (verilog-modi-get-sub-decls modi))
  10917. (sig-list (verilog-signals-combine-bus
  10918. (verilog-signals-not-in
  10919. (append (verilog-subdecls-get-inputs modsubdecls)
  10920. (verilog-subdecls-get-inouts modsubdecls))
  10921. (append (verilog-decls-get-signals moddecls)
  10922. (verilog-decls-get-assigns moddecls))))))
  10923. (when sig-list
  10924. (verilog-forward-or-insert-line)
  10925. (verilog-insert-indent "// Beginning of automatic reg inputs (for undeclared instantiated-module inputs)\n")
  10926. (verilog-insert-definition modi sig-list "reg" indent-pt nil)
  10927. (verilog-insert-indent "// End of automatics\n")))))
  10928. (defun verilog-auto-logic-setup ()
  10929. "Prepare variables due to AUTOLOGIC."
  10930. (unless verilog-auto-wire-type
  10931. (set (make-local-variable 'verilog-auto-wire-type)
  10932. "logic")))
  10933. (defun verilog-auto-logic ()
  10934. "Expand AUTOLOGIC statements, as part of \\[verilog-auto].
  10935. Make wire statements using the SystemVerilog logic keyword.
  10936. This is currently equivalent to:
  10937. /*AUTOWIRE*/
  10938. with the below at the bottom of the file
  10939. // Local Variables:
  10940. // verilog-auto-logic-type:\"logic\"
  10941. // End:
  10942. In the future AUTOLOGIC may declare additional identifiers,
  10943. while AUTOWIRE will not."
  10944. (save-excursion
  10945. (verilog-auto-logic-setup)
  10946. (verilog-auto-wire)))
  10947. (defun verilog-auto-wire ()
  10948. "Expand AUTOWIRE statements, as part of \\[verilog-auto].
  10949. Make wire statements for instantiations outputs that aren't
  10950. already declared. `verilog-auto-wire-type' may be used to change
  10951. the datatype of the declarations.
  10952. Limitations:
  10953. This ONLY detects outputs of AUTOINSTants (see `verilog-read-sub-decls'),
  10954. and all buses must have widths, such as those from AUTOINST, or using []
  10955. in AUTO_TEMPLATEs.
  10956. This does NOT work on memories or SystemVerilog .name connections,
  10957. declare those yourself.
  10958. Verilog mode will add \"Couldn't Merge\" comments to signals it cannot
  10959. determine how to bus together. This occurs when you have ports with
  10960. non-numeric or non-sequential bus subscripts. If Verilog mode
  10961. mis-guessed, you'll have to declare them yourself.
  10962. An example (see `verilog-auto-inst' for what else is going on here):
  10963. module ExampWire (o,i);
  10964. output o;
  10965. input i;
  10966. /*AUTOWIRE*/
  10967. InstModule instName
  10968. (/*AUTOINST*/);
  10969. endmodule
  10970. Typing \\[verilog-auto] will make this into:
  10971. module ExampWire (o,i);
  10972. output o;
  10973. input i;
  10974. /*AUTOWIRE*/
  10975. // Beginning of automatic wires
  10976. wire [31:0] ov; // From inst of inst.v
  10977. // End of automatics
  10978. InstModule instName
  10979. (/*AUTOINST*/
  10980. // Outputs
  10981. .ov (ov[31:0]),
  10982. // Inputs
  10983. .i (i));
  10984. wire o = | ov;
  10985. endmodule"
  10986. (save-excursion
  10987. ;; Point must be at insertion point.
  10988. (let* ((indent-pt (current-indentation))
  10989. (modi (verilog-modi-current))
  10990. (moddecls (verilog-modi-get-decls modi))
  10991. (modsubdecls (verilog-modi-get-sub-decls modi))
  10992. (sig-list (verilog-signals-combine-bus
  10993. (verilog-signals-not-in
  10994. (append (verilog-subdecls-get-outputs modsubdecls)
  10995. (verilog-subdecls-get-inouts modsubdecls))
  10996. (verilog-decls-get-signals moddecls)))))
  10997. (when sig-list
  10998. (verilog-forward-or-insert-line)
  10999. (verilog-insert-indent "// Beginning of automatic wires (for undeclared instantiated-module outputs)\n")
  11000. (verilog-insert-definition modi sig-list "wire" indent-pt nil)
  11001. (verilog-insert-indent "// End of automatics\n")
  11002. ;; We used to optionally call verilog-pretty-declarations and
  11003. ;; verilog-pretty-expr here, but it's too slow on huge modules,
  11004. ;; plus makes everyone's module change. Finally those call
  11005. ;; syntax-ppss which is broken when change hooks are disabled.
  11006. ))))
  11007. (defun verilog-auto-output ()
  11008. "Expand AUTOOUTPUT statements, as part of \\[verilog-auto].
  11009. Make output statements for any output signal from an /*AUTOINST*/ that
  11010. isn't an input to another AUTOINST. This is useful for modules which
  11011. only instantiate other modules.
  11012. Limitations:
  11013. This ONLY detects outputs of AUTOINSTants (see `verilog-read-sub-decls').
  11014. If placed inside the parenthesis of a module declaration, it creates
  11015. Verilog 2001 style, else uses Verilog 1995 style.
  11016. If any concatenation, or bit-subscripts are missing in the AUTOINSTant's
  11017. instantiation, all bets are off. (For example due to an AUTO_TEMPLATE).
  11018. Typedefs must match `verilog-typedef-regexp', which is disabled by default.
  11019. Types are added to declarations if an AUTOLOGIC or
  11020. `verilog-auto-wire-type' is set to logic.
  11021. Signals matching `verilog-auto-output-ignore-regexp' are not included.
  11022. An example (see `verilog-auto-inst' for what else is going on here):
  11023. module ExampOutput (ov,i);
  11024. input i;
  11025. /*AUTOOUTPUT*/
  11026. InstModule instName
  11027. (/*AUTOINST*/);
  11028. endmodule
  11029. Typing \\[verilog-auto] will make this into:
  11030. module ExampOutput (ov,i);
  11031. input i;
  11032. /*AUTOOUTPUT*/
  11033. // Beginning of automatic outputs (from unused autoinst outputs)
  11034. output [31:0] ov; // From inst of inst.v
  11035. // End of automatics
  11036. InstModule instName
  11037. (/*AUTOINST*/
  11038. // Outputs
  11039. .ov (ov[31:0]),
  11040. // Inputs
  11041. .i (i));
  11042. endmodule
  11043. You may also provide an optional regular expression, in which case only
  11044. signals matching the regular expression will be included. For example the
  11045. same expansion will result from only extracting outputs starting with ov:
  11046. /*AUTOOUTPUT(\"^ov\")*/"
  11047. (save-excursion
  11048. ;; Point must be at insertion point.
  11049. (let* ((indent-pt (current-indentation))
  11050. (params (verilog-read-auto-params 0 1))
  11051. (regexp (nth 0 params))
  11052. (v2k (verilog-in-paren-quick))
  11053. (modi (verilog-modi-current))
  11054. (moddecls (verilog-modi-get-decls modi))
  11055. (modsubdecls (verilog-modi-get-sub-decls modi))
  11056. (sig-list (verilog-signals-not-in
  11057. (verilog-subdecls-get-outputs modsubdecls)
  11058. (append (verilog-decls-get-outputs moddecls)
  11059. (verilog-decls-get-inouts moddecls)
  11060. (verilog-decls-get-inputs moddecls)
  11061. (verilog-subdecls-get-inputs modsubdecls)
  11062. (verilog-subdecls-get-inouts modsubdecls)))))
  11063. (when regexp
  11064. (setq sig-list (verilog-signals-matching-regexp
  11065. sig-list regexp)))
  11066. (setq sig-list (verilog-signals-not-matching-regexp
  11067. sig-list verilog-auto-output-ignore-regexp))
  11068. (verilog-forward-or-insert-line)
  11069. (when v2k (verilog-repair-open-comma))
  11070. (when sig-list
  11071. (verilog-insert-indent "// Beginning of automatic outputs (from unused autoinst outputs)\n")
  11072. (verilog-insert-definition modi sig-list "output" indent-pt v2k)
  11073. (verilog-insert-indent "// End of automatics\n"))
  11074. (when v2k (verilog-repair-close-comma)))))
  11075. (defun verilog-auto-output-every ()
  11076. "Expand AUTOOUTPUTEVERY statements, as part of \\[verilog-auto].
  11077. Make output statements for any signals that aren't primary inputs or
  11078. outputs already. This makes every signal in the design an output. This is
  11079. useful to get Synopsys to preserve every signal in the design, since it
  11080. won't optimize away the outputs.
  11081. An example:
  11082. module ExampOutputEvery (o,i,tempa,tempb);
  11083. output o;
  11084. input i;
  11085. /*AUTOOUTPUTEVERY*/
  11086. wire tempa = i;
  11087. wire tempb = tempa;
  11088. wire o = tempb;
  11089. endmodule
  11090. Typing \\[verilog-auto] will make this into:
  11091. module ExampOutputEvery (o,i,tempa,tempb);
  11092. output o;
  11093. input i;
  11094. /*AUTOOUTPUTEVERY*/
  11095. // Beginning of automatic outputs (every signal)
  11096. output tempb;
  11097. output tempa;
  11098. // End of automatics
  11099. wire tempa = i;
  11100. wire tempb = tempa;
  11101. wire o = tempb;
  11102. endmodule
  11103. You may also provide an optional regular expression, in which case only
  11104. signals matching the regular expression will be included. For example the
  11105. same expansion will result from only extracting outputs starting with ov:
  11106. /*AUTOOUTPUTEVERY(\"^ov\")*/"
  11107. (save-excursion
  11108. ;;Point must be at insertion point
  11109. (let* ((indent-pt (current-indentation))
  11110. (params (verilog-read-auto-params 0 1))
  11111. (regexp (nth 0 params))
  11112. (v2k (verilog-in-paren-quick))
  11113. (modi (verilog-modi-current))
  11114. (moddecls (verilog-modi-get-decls modi))
  11115. (sig-list (verilog-signals-combine-bus
  11116. (verilog-signals-not-in
  11117. (verilog-decls-get-signals moddecls)
  11118. (verilog-decls-get-ports moddecls)))))
  11119. (when regexp
  11120. (setq sig-list (verilog-signals-matching-regexp
  11121. sig-list regexp)))
  11122. (setq sig-list (verilog-signals-not-matching-regexp
  11123. sig-list verilog-auto-output-ignore-regexp))
  11124. (verilog-forward-or-insert-line)
  11125. (when v2k (verilog-repair-open-comma))
  11126. (when sig-list
  11127. (verilog-insert-indent "// Beginning of automatic outputs (every signal)\n")
  11128. (verilog-insert-definition modi sig-list "output" indent-pt v2k)
  11129. (verilog-insert-indent "// End of automatics\n"))
  11130. (when v2k (verilog-repair-close-comma)))))
  11131. (defun verilog-auto-input ()
  11132. "Expand AUTOINPUT statements, as part of \\[verilog-auto].
  11133. Make input statements for any input signal into an /*AUTOINST*/ that
  11134. isn't declared elsewhere inside the module. This is useful for modules which
  11135. only instantiate other modules.
  11136. Limitations:
  11137. This ONLY detects outputs of AUTOINSTants (see `verilog-read-sub-decls').
  11138. If placed inside the parenthesis of a module declaration, it creates
  11139. Verilog 2001 style, else uses Verilog 1995 style.
  11140. If any concatenation, or bit-subscripts are missing in the AUTOINSTant's
  11141. instantiation, all bets are off. (For example due to an AUTO_TEMPLATE).
  11142. Typedefs must match `verilog-typedef-regexp', which is disabled by default.
  11143. Types are added to declarations if an AUTOLOGIC or
  11144. `verilog-auto-wire-type' is set to logic.
  11145. Signals matching `verilog-auto-input-ignore-regexp' are not included.
  11146. An example (see `verilog-auto-inst' for what else is going on here):
  11147. module ExampInput (ov,i);
  11148. output [31:0] ov;
  11149. /*AUTOINPUT*/
  11150. InstModule instName
  11151. (/*AUTOINST*/);
  11152. endmodule
  11153. Typing \\[verilog-auto] will make this into:
  11154. module ExampInput (ov,i);
  11155. output [31:0] ov;
  11156. /*AUTOINPUT*/
  11157. // Beginning of automatic inputs (from unused autoinst inputs)
  11158. input i; // From inst of inst.v
  11159. // End of automatics
  11160. InstModule instName
  11161. (/*AUTOINST*/
  11162. // Outputs
  11163. .ov (ov[31:0]),
  11164. // Inputs
  11165. .i (i));
  11166. endmodule
  11167. You may also provide an optional regular expression, in which case only
  11168. signals matching the regular expression will be included. For example the
  11169. same expansion will result from only extracting inputs starting with i:
  11170. /*AUTOINPUT(\"^i\")*/"
  11171. (save-excursion
  11172. (let* ((indent-pt (current-indentation))
  11173. (params (verilog-read-auto-params 0 1))
  11174. (regexp (nth 0 params))
  11175. (v2k (verilog-in-paren-quick))
  11176. (modi (verilog-modi-current))
  11177. (moddecls (verilog-modi-get-decls modi))
  11178. (modsubdecls (verilog-modi-get-sub-decls modi))
  11179. (sig-list (verilog-signals-not-in
  11180. (verilog-subdecls-get-inputs modsubdecls)
  11181. (append (verilog-decls-get-inputs moddecls)
  11182. (verilog-decls-get-inouts moddecls)
  11183. (verilog-decls-get-outputs moddecls)
  11184. (verilog-decls-get-vars moddecls)
  11185. (verilog-decls-get-consts moddecls)
  11186. (verilog-decls-get-gparams moddecls)
  11187. (verilog-subdecls-get-interfaced modsubdecls)
  11188. (verilog-subdecls-get-outputs modsubdecls)
  11189. (verilog-subdecls-get-inouts modsubdecls)))))
  11190. (when regexp
  11191. (setq sig-list (verilog-signals-matching-regexp
  11192. sig-list regexp)))
  11193. (setq sig-list (verilog-signals-not-matching-regexp
  11194. sig-list verilog-auto-input-ignore-regexp))
  11195. (verilog-forward-or-insert-line)
  11196. (when v2k (verilog-repair-open-comma))
  11197. (when sig-list
  11198. (verilog-insert-indent "// Beginning of automatic inputs (from unused autoinst inputs)\n")
  11199. (verilog-insert-definition modi sig-list "input" indent-pt v2k)
  11200. (verilog-insert-indent "// End of automatics\n"))
  11201. (when v2k (verilog-repair-close-comma)))))
  11202. (defun verilog-auto-inout ()
  11203. "Expand AUTOINOUT statements, as part of \\[verilog-auto].
  11204. Make inout statements for any inout signal in an /*AUTOINST*/ that
  11205. isn't declared elsewhere inside the module.
  11206. Limitations:
  11207. This ONLY detects outputs of AUTOINSTants (see `verilog-read-sub-decls').
  11208. If placed inside the parenthesis of a module declaration, it creates
  11209. Verilog 2001 style, else uses Verilog 1995 style.
  11210. If any concatenation, or bit-subscripts are missing in the AUTOINSTant's
  11211. instantiation, all bets are off. (For example due to an AUTO_TEMPLATE).
  11212. Typedefs must match `verilog-typedef-regexp', which is disabled by default.
  11213. Types are added to declarations if an AUTOLOGIC or
  11214. `verilog-auto-wire-type' is set to logic.
  11215. Signals matching `verilog-auto-inout-ignore-regexp' are not included.
  11216. An example (see `verilog-auto-inst' for what else is going on here):
  11217. module ExampInout (ov,i);
  11218. input i;
  11219. /*AUTOINOUT*/
  11220. InstModule instName
  11221. (/*AUTOINST*/);
  11222. endmodule
  11223. Typing \\[verilog-auto] will make this into:
  11224. module ExampInout (ov,i);
  11225. input i;
  11226. /*AUTOINOUT*/
  11227. // Beginning of automatic inouts (from unused autoinst inouts)
  11228. inout [31:0] ov; // From inst of inst.v
  11229. // End of automatics
  11230. InstModule instName
  11231. (/*AUTOINST*/
  11232. // Inouts
  11233. .ov (ov[31:0]),
  11234. // Inputs
  11235. .i (i));
  11236. endmodule
  11237. You may also provide an optional regular expression, in which case only
  11238. signals matching the regular expression will be included. For example the
  11239. same expansion will result from only extracting inouts starting with i:
  11240. /*AUTOINOUT(\"^i\")*/"
  11241. (save-excursion
  11242. ;; Point must be at insertion point.
  11243. (let* ((indent-pt (current-indentation))
  11244. (params (verilog-read-auto-params 0 1))
  11245. (regexp (nth 0 params))
  11246. (v2k (verilog-in-paren-quick))
  11247. (modi (verilog-modi-current))
  11248. (moddecls (verilog-modi-get-decls modi))
  11249. (modsubdecls (verilog-modi-get-sub-decls modi))
  11250. (sig-list (verilog-signals-not-in
  11251. (verilog-subdecls-get-inouts modsubdecls)
  11252. (append (verilog-decls-get-outputs moddecls)
  11253. (verilog-decls-get-inouts moddecls)
  11254. (verilog-decls-get-inputs moddecls)
  11255. (verilog-subdecls-get-inputs modsubdecls)
  11256. (verilog-subdecls-get-outputs modsubdecls)))))
  11257. (when regexp
  11258. (setq sig-list (verilog-signals-matching-regexp
  11259. sig-list regexp)))
  11260. (setq sig-list (verilog-signals-not-matching-regexp
  11261. sig-list verilog-auto-inout-ignore-regexp))
  11262. (verilog-forward-or-insert-line)
  11263. (when v2k (verilog-repair-open-comma))
  11264. (when sig-list
  11265. (verilog-insert-indent "// Beginning of automatic inouts (from unused autoinst inouts)\n")
  11266. (verilog-insert-definition modi sig-list "inout" indent-pt v2k)
  11267. (verilog-insert-indent "// End of automatics\n"))
  11268. (when v2k (verilog-repair-close-comma)))))
  11269. (defun verilog-auto-inout-module (&optional complement all-in)
  11270. "Expand AUTOINOUTMODULE statements, as part of \\[verilog-auto].
  11271. Take input/output/inout statements from the specified module and insert
  11272. into the current module. This is useful for making null templates and
  11273. shell modules which need to have identical I/O with another module.
  11274. Any I/O which are already defined in this module will not be redefined.
  11275. For the complement of this function, see `verilog-auto-inout-comp',
  11276. and to make monitors with all inputs, see `verilog-auto-inout-in'.
  11277. Limitations:
  11278. If placed inside the parenthesis of a module declaration, it creates
  11279. Verilog 2001 style, else uses Verilog 1995 style.
  11280. Concatenation and outputting partial buses is not supported.
  11281. Module names must be resolvable to filenames. See `verilog-auto-inst'.
  11282. Signals are not inserted in the same order as in the original module,
  11283. though they will appear to be in the same order to an AUTOINST
  11284. instantiating either module.
  11285. Signals declared as \"output reg\" or \"output wire\" etc will
  11286. lose the wire/reg declaration so that shell modules may
  11287. generate those outputs differently. However, \"output logic\"
  11288. is propagated.
  11289. An example:
  11290. module ExampShell (/*AUTOARG*/);
  11291. /*AUTOINOUTMODULE(\"ExampMain\")*/
  11292. endmodule
  11293. module ExampMain (i,o,io);
  11294. input i;
  11295. output o;
  11296. inout io;
  11297. endmodule
  11298. Typing \\[verilog-auto] will make this into:
  11299. module ExampShell (/*AUTOARG*/i,o,io);
  11300. /*AUTOINOUTMODULE(\"ExampMain\")*/
  11301. // Beginning of automatic in/out/inouts (from specific module)
  11302. output o;
  11303. inout io;
  11304. input i;
  11305. // End of automatics
  11306. endmodule
  11307. You may also provide an optional regular expression, in which case only
  11308. signals matching the regular expression will be included. For example the
  11309. same expansion will result from only extracting signals starting with i:
  11310. /*AUTOINOUTMODULE(\"ExampMain\",\"^i\")*/
  11311. You may also provide an optional third argument regular
  11312. expression, in which case only signals which have that pin
  11313. direction and data type matching that regular expression will be
  11314. included. This matches against everything before the signal name
  11315. in the declaration, for example against \"input\" (single
  11316. bit), \"output logic\" (direction and type) or
  11317. \"output [1:0]\" (direction and implicit type). You also
  11318. probably want to skip spaces in your regexp.
  11319. For example, the below will result in matching the output \"o\"
  11320. against the previous example's module:
  11321. /*AUTOINOUTMODULE(\"ExampMain\",\"\",\"^output.*\")*/
  11322. You may also provide an optional fourth argument regular
  11323. expression, which if not \"\" only signals which do NOT match
  11324. that expression are included."
  11325. ;; Beware spacing of quotes in above as can mess up Emacs indenter
  11326. (save-excursion
  11327. (let* ((params (verilog-read-auto-params 1 4))
  11328. (submod (nth 0 params))
  11329. (regexp (nth 1 params))
  11330. (direction-re (nth 2 params))
  11331. (not-re (nth 3 params))
  11332. submodi)
  11333. ;; Lookup position, etc of co-module
  11334. ;; Note this may raise an error
  11335. (when (setq submodi (verilog-modi-lookup submod t))
  11336. (let* ((indent-pt (current-indentation))
  11337. (v2k (verilog-in-paren-quick))
  11338. (modi (verilog-modi-current))
  11339. (moddecls (verilog-modi-get-decls modi))
  11340. (submoddecls (verilog-modi-get-decls submodi))
  11341. (sig-list-i (verilog-signals-not-in
  11342. (cond (all-in
  11343. (append
  11344. (verilog-decls-get-inputs submoddecls)
  11345. (verilog-decls-get-inouts submoddecls)
  11346. (verilog-decls-get-outputs submoddecls)))
  11347. (complement
  11348. (verilog-decls-get-outputs submoddecls))
  11349. (t (verilog-decls-get-inputs submoddecls)))
  11350. (append (verilog-decls-get-inputs moddecls))))
  11351. (sig-list-o (verilog-signals-not-in
  11352. (cond (all-in nil)
  11353. (complement
  11354. (verilog-decls-get-inputs submoddecls))
  11355. (t (verilog-decls-get-outputs submoddecls)))
  11356. (append (verilog-decls-get-outputs moddecls))))
  11357. (sig-list-io (verilog-signals-not-in
  11358. (cond (all-in nil)
  11359. (t (verilog-decls-get-inouts submoddecls)))
  11360. (append (verilog-decls-get-inouts moddecls))))
  11361. (sig-list-if (verilog-signals-not-in
  11362. (verilog-decls-get-interfaces submoddecls)
  11363. (append (verilog-decls-get-interfaces moddecls)))))
  11364. (forward-line 1)
  11365. (setq sig-list-i (verilog-signals-edit-wire-reg
  11366. (verilog-signals-not-matching-regexp
  11367. (verilog-signals-matching-dir-re
  11368. (verilog-signals-matching-regexp sig-list-i regexp)
  11369. "input" direction-re) not-re))
  11370. sig-list-o (verilog-signals-edit-wire-reg
  11371. (verilog-signals-not-matching-regexp
  11372. (verilog-signals-matching-dir-re
  11373. (verilog-signals-matching-regexp sig-list-o regexp)
  11374. "output" direction-re) not-re))
  11375. sig-list-io (verilog-signals-edit-wire-reg
  11376. (verilog-signals-not-matching-regexp
  11377. (verilog-signals-matching-dir-re
  11378. (verilog-signals-matching-regexp sig-list-io regexp)
  11379. "inout" direction-re) not-re))
  11380. sig-list-if (verilog-signals-not-matching-regexp
  11381. (verilog-signals-matching-dir-re
  11382. (verilog-signals-matching-regexp sig-list-if regexp)
  11383. "interface" direction-re) not-re))
  11384. (when v2k (verilog-repair-open-comma))
  11385. (when (or sig-list-i sig-list-o sig-list-io sig-list-if)
  11386. (verilog-insert-indent "// Beginning of automatic in/out/inouts (from specific module)\n")
  11387. ;; Don't sort them so an upper AUTOINST will match the main module
  11388. (verilog-insert-definition modi sig-list-o "output" indent-pt v2k t)
  11389. (verilog-insert-definition modi sig-list-io "inout" indent-pt v2k t)
  11390. (verilog-insert-definition modi sig-list-i "input" indent-pt v2k t)
  11391. (verilog-insert-definition modi sig-list-if "interface" indent-pt v2k t)
  11392. (verilog-insert-indent "// End of automatics\n"))
  11393. (when v2k (verilog-repair-close-comma)))))))
  11394. (defun verilog-auto-inout-comp ()
  11395. "Expand AUTOINOUTCOMP statements, as part of \\[verilog-auto].
  11396. Take input/output/inout statements from the specified module and
  11397. insert the inverse into the current module (inputs become outputs
  11398. and vice-versa.) This is useful for making test and stimulus
  11399. modules which need to have complementing I/O with another module.
  11400. Any I/O which are already defined in this module will not be
  11401. redefined. For the complement of this function, see
  11402. `verilog-auto-inout-module'.
  11403. Limitations:
  11404. If placed inside the parenthesis of a module declaration, it creates
  11405. Verilog 2001 style, else uses Verilog 1995 style.
  11406. Concatenation and outputting partial buses is not supported.
  11407. Module names must be resolvable to filenames. See `verilog-auto-inst'.
  11408. Signals are not inserted in the same order as in the original module,
  11409. though they will appear to be in the same order to an AUTOINST
  11410. instantiating either module.
  11411. An example:
  11412. module ExampShell (/*AUTOARG*/);
  11413. /*AUTOINOUTCOMP(\"ExampMain\")*/
  11414. endmodule
  11415. module ExampMain (i,o,io);
  11416. input i;
  11417. output o;
  11418. inout io;
  11419. endmodule
  11420. Typing \\[verilog-auto] will make this into:
  11421. module ExampShell (/*AUTOARG*/i,o,io);
  11422. /*AUTOINOUTCOMP(\"ExampMain\")*/
  11423. // Beginning of automatic in/out/inouts (from specific module)
  11424. output i;
  11425. inout io;
  11426. input o;
  11427. // End of automatics
  11428. endmodule
  11429. You may also provide an optional regular expression, in which case only
  11430. signals matching the regular expression will be included. For example the
  11431. same expansion will result from only extracting signals starting with i:
  11432. /*AUTOINOUTCOMP(\"ExampMain\",\"^i\")*/
  11433. You may also provide an optional third argument regular
  11434. expression, in which case only signals which have that pin
  11435. direction and data type matching that regular expression will be
  11436. included. This matches against everything before the signal name
  11437. in the declaration, for example against \"input\" (single
  11438. bit), \"output logic\" (direction and type)
  11439. or \"output [1:0]\" (direction and implicit type). You also
  11440. probably want to skip spaces in your regexp.
  11441. For example, the below will result in matching the output \"o\"
  11442. against the previous example's module:
  11443. /*AUTOINOUTCOMP(\"ExampMain\",\"\",\"^output.*\")*/
  11444. You may also provide an optional fourth argument regular
  11445. expression, which if not \"\" only signals which do NOT match
  11446. that expression are included."
  11447. ;; Beware spacing of quotes in above as can mess up Emacs indenter
  11448. (verilog-auto-inout-module t nil))
  11449. (defun verilog-auto-inout-in ()
  11450. "Expand AUTOINOUTIN statements, as part of \\[verilog-auto].
  11451. Take input/output/inout statements from the specified module and
  11452. insert them as all inputs into the current module. This is
  11453. useful for making monitor modules which need to see all signals
  11454. as inputs based on another module. Any I/O which are already
  11455. defined in this module will not be redefined. See also
  11456. `verilog-auto-inout-module'.
  11457. Limitations:
  11458. If placed inside the parenthesis of a module declaration, it creates
  11459. Verilog 2001 style, else uses Verilog 1995 style.
  11460. Concatenation and outputting partial buses is not supported.
  11461. Module names must be resolvable to filenames. See `verilog-auto-inst'.
  11462. Signals are not inserted in the same order as in the original module,
  11463. though they will appear to be in the same order to an AUTOINST
  11464. instantiating either module.
  11465. An example:
  11466. module ExampShell (/*AUTOARG*/);
  11467. /*AUTOINOUTIN(\"ExampMain\")*/
  11468. endmodule
  11469. module ExampMain (i,o,io);
  11470. input i;
  11471. output o;
  11472. inout io;
  11473. endmodule
  11474. Typing \\[verilog-auto] will make this into:
  11475. module ExampShell (/*AUTOARG*/i,o,io);
  11476. /*AUTOINOUTIN(\"ExampMain\")*/
  11477. // Beginning of automatic in/out/inouts (from specific module)
  11478. input i;
  11479. input io;
  11480. input o;
  11481. // End of automatics
  11482. endmodule
  11483. You may also provide an optional regular expression, in which case only
  11484. signals matching the regular expression will be included. For example the
  11485. same expansion will result from only extracting signals starting with i:
  11486. /*AUTOINOUTIN(\"ExampMain\",\"^i\")*/"
  11487. (verilog-auto-inout-module nil t))
  11488. (defun verilog-auto-inout-param ()
  11489. "Expand AUTOINOUTPARAM statements, as part of \\[verilog-auto].
  11490. Take input/output/inout statements from the specified module and insert
  11491. into the current module. This is useful for making null templates and
  11492. shell modules which need to have identical I/O with another module.
  11493. Any I/O which are already defined in this module will not be redefined.
  11494. For the complement of this function, see `verilog-auto-inout-comp',
  11495. and to make monitors with all inputs, see `verilog-auto-inout-in'.
  11496. Limitations:
  11497. If placed inside the parenthesis of a module declaration, it creates
  11498. Verilog 2001 style, else uses Verilog 1995 style.
  11499. Module names must be resolvable to filenames. See `verilog-auto-inst'.
  11500. Parameters are inserted in the same order as in the original module.
  11501. Parameters do not have values, which is SystemVerilog 2009 syntax.
  11502. An example:
  11503. module ExampShell ();
  11504. /*AUTOINOUTPARAM(\"ExampMain\")*/
  11505. endmodule
  11506. module ExampMain ();
  11507. parameter PARAM = 22;
  11508. endmodule
  11509. Typing \\[verilog-auto] will make this into:
  11510. module ExampShell (/*AUTOARG*/i,o,io);
  11511. /*AUTOINOUTPARAM(\"ExampMain\")*/
  11512. // Beginning of automatic parameters (from specific module)
  11513. parameter PARAM;
  11514. // End of automatics
  11515. endmodule
  11516. You may also provide an optional regular expression, in which case only
  11517. parameters matching the regular expression will be included. For example the
  11518. same expansion will result from only extracting parameters starting with i:
  11519. /*AUTOINOUTPARAM(\"ExampMain\",\"^i\")*/"
  11520. (save-excursion
  11521. (let* ((params (verilog-read-auto-params 1 2))
  11522. (submod (nth 0 params))
  11523. (regexp (nth 1 params))
  11524. submodi)
  11525. ;; Lookup position, etc of co-module
  11526. ;; Note this may raise an error
  11527. (when (setq submodi (verilog-modi-lookup submod t))
  11528. (let* ((indent-pt (current-indentation))
  11529. (v2k (verilog-in-paren-quick))
  11530. (modi (verilog-modi-current))
  11531. (moddecls (verilog-modi-get-decls modi))
  11532. (submoddecls (verilog-modi-get-decls submodi))
  11533. (sig-list-p (verilog-signals-not-in
  11534. (verilog-decls-get-gparams submoddecls)
  11535. (append (verilog-decls-get-gparams moddecls)))))
  11536. (forward-line 1)
  11537. (setq sig-list-p (verilog-signals-matching-regexp sig-list-p regexp))
  11538. (when v2k (verilog-repair-open-comma))
  11539. (when sig-list-p
  11540. (verilog-insert-indent "// Beginning of automatic parameters (from specific module)\n")
  11541. ;; Don't sort them so an upper AUTOINST will match the main module
  11542. (verilog-insert-definition modi sig-list-p "parameter" indent-pt v2k t)
  11543. (verilog-insert-indent "// End of automatics\n"))
  11544. (when v2k (verilog-repair-close-comma)))))))
  11545. (defun verilog-auto-inout-modport ()
  11546. "Expand AUTOINOUTMODPORT statements, as part of \\[verilog-auto].
  11547. Take input/output/inout statements from the specified interface
  11548. and modport and insert into the current module. This is useful
  11549. for making verification modules that connect to UVM interfaces.
  11550. The first parameter is the name of an interface.
  11551. The second parameter is a regexp of modports to read from in
  11552. that interface.
  11553. The optional third parameter is a regular expression, and only
  11554. signals matching the regular expression will be included.
  11555. Limitations:
  11556. If placed inside the parenthesis of a module declaration, it creates
  11557. Verilog 2001 style, else uses Verilog 1995 style.
  11558. Interface names must be resolvable to filenames. See `verilog-auto-inst'.
  11559. As with other autos, any inputs/outputs declared in the module
  11560. will suppress the AUTO from redeclaring an inputs/outputs by
  11561. the same name.
  11562. An example:
  11563. interface ExampIf
  11564. ( input logic clk );
  11565. logic req_val;
  11566. logic [7:0] req_dat;
  11567. clocking mon_clkblk @(posedge clk);
  11568. input req_val;
  11569. input req_dat;
  11570. endclocking
  11571. modport mp(clocking mon_clkblk);
  11572. endinterface
  11573. module ExampMain
  11574. ( input clk,
  11575. /*AUTOINOUTMODPORT(\"ExampIf\" \"mp\")*/
  11576. // Beginning of automatic in/out/inouts (from modport)
  11577. input [7:0] req_dat,
  11578. input req_val
  11579. // End of automatics
  11580. );
  11581. /*AUTOASSIGNMODPORT(\"ExampIf\" \"mp\")*/
  11582. endmodule
  11583. Typing \\[verilog-auto] will make this into:
  11584. ...
  11585. module ExampMain
  11586. ( input clk,
  11587. /*AUTOINOUTMODPORT(\"ExampIf\" \"mp\")*/
  11588. // Beginning of automatic in/out/inouts (from modport)
  11589. input req_dat,
  11590. input req_val
  11591. // End of automatics
  11592. );
  11593. If the modport is part of a UVM monitor/driver class, this
  11594. creates a wrapper module that may be used to instantiate the
  11595. driver/monitor using AUTOINST in the testbench."
  11596. (save-excursion
  11597. (let* ((params (verilog-read-auto-params 2 3))
  11598. (submod (nth 0 params))
  11599. (modport-re (nth 1 params))
  11600. (regexp (nth 2 params))
  11601. direction-re submodi) ; direction argument not supported until requested
  11602. ;; Lookup position, etc of co-module
  11603. ;; Note this may raise an error
  11604. (when (setq submodi (verilog-modi-lookup submod t))
  11605. (let* ((indent-pt (current-indentation))
  11606. (v2k (verilog-in-paren-quick))
  11607. (modi (verilog-modi-current))
  11608. (moddecls (verilog-modi-get-decls modi))
  11609. (submoddecls (verilog-modi-get-decls submodi))
  11610. (submodportdecls (verilog-modi-modport-lookup submodi modport-re))
  11611. (sig-list-i (verilog-signals-in ; Decls doesn't have data types, must resolve
  11612. (verilog-decls-get-vars submoddecls)
  11613. (verilog-signals-not-in
  11614. (verilog-decls-get-inputs submodportdecls)
  11615. (append (verilog-decls-get-ports submoddecls)
  11616. (verilog-decls-get-ports moddecls)))))
  11617. (sig-list-o (verilog-signals-in ; Decls doesn't have data types, must resolve
  11618. (verilog-decls-get-vars submoddecls)
  11619. (verilog-signals-not-in
  11620. (verilog-decls-get-outputs submodportdecls)
  11621. (append (verilog-decls-get-ports submoddecls)
  11622. (verilog-decls-get-ports moddecls)))))
  11623. (sig-list-io (verilog-signals-in ; Decls doesn't have data types, must resolve
  11624. (verilog-decls-get-vars submoddecls)
  11625. (verilog-signals-not-in
  11626. (verilog-decls-get-inouts submodportdecls)
  11627. (append (verilog-decls-get-ports submoddecls)
  11628. (verilog-decls-get-ports moddecls))))))
  11629. (forward-line 1)
  11630. (setq sig-list-i (verilog-signals-edit-wire-reg
  11631. (verilog-signals-matching-dir-re
  11632. (verilog-signals-matching-regexp sig-list-i regexp)
  11633. "input" direction-re))
  11634. sig-list-o (verilog-signals-edit-wire-reg
  11635. (verilog-signals-matching-dir-re
  11636. (verilog-signals-matching-regexp sig-list-o regexp)
  11637. "output" direction-re))
  11638. sig-list-io (verilog-signals-edit-wire-reg
  11639. (verilog-signals-matching-dir-re
  11640. (verilog-signals-matching-regexp sig-list-io regexp)
  11641. "inout" direction-re)))
  11642. (when v2k (verilog-repair-open-comma))
  11643. (when (or sig-list-i sig-list-o sig-list-io)
  11644. (verilog-insert-indent "// Beginning of automatic in/out/inouts (from modport)\n")
  11645. ;; Don't sort them so an upper AUTOINST will match the main module
  11646. (verilog-insert-definition modi sig-list-o "output" indent-pt v2k t)
  11647. (verilog-insert-definition modi sig-list-io "inout" indent-pt v2k t)
  11648. (verilog-insert-definition modi sig-list-i "input" indent-pt v2k t)
  11649. (verilog-insert-indent "// End of automatics\n"))
  11650. (when v2k (verilog-repair-close-comma)))))))
  11651. (defun verilog-auto-insert-lisp ()
  11652. "Expand AUTOINSERTLISP statements, as part of \\[verilog-auto].
  11653. The Lisp code provided is called before other AUTOS are expanded,
  11654. and the Lisp code generally will call `insert' to insert text
  11655. into the current file beginning on the line after the
  11656. AUTOINSERTLISP.
  11657. See also AUTOINSERTLAST and `verilog-auto-insert-last' which
  11658. executes after (as opposed to before) other AUTOs.
  11659. See also AUTO_LISP, which takes a Lisp expression and evaluates
  11660. it during `verilog-auto-inst' but does not insert any text.
  11661. An example:
  11662. module ExampInsertLisp;
  11663. /*AUTOINSERTLISP(my-verilog-insert-hello \"world\")*/
  11664. endmodule
  11665. // For this example we declare the function in the
  11666. // module's file itself. Often you'd define it instead
  11667. // in a site-start.el or init file.
  11668. /*
  11669. Local Variables:
  11670. eval:
  11671. (defun my-verilog-insert-hello (who)
  11672. (insert (concat \"initial $write(\\\"hello \" who \"\\\");\\n\")))
  11673. End:
  11674. */
  11675. Typing \\[verilog-auto] will call my-verilog-insert-hello and
  11676. expand the above into:
  11677. // Beginning of automatic insert lisp
  11678. initial $write(\"hello world\");
  11679. // End of automatics
  11680. You can also call an external program and insert the returned
  11681. text:
  11682. /*AUTOINSERTLISP(insert (shell-command-to-string \"echo //hello\"))*/
  11683. // Beginning of automatic insert lisp
  11684. //hello
  11685. // End of automatics"
  11686. (save-excursion
  11687. ;; Point is at end of /*AUTO...*/
  11688. (let* ((indent-pt (current-indentation))
  11689. (cmd-end-pt (save-excursion (search-backward ")")
  11690. (forward-char)
  11691. (point))) ; Closing paren
  11692. (cmd-beg-pt (save-excursion (goto-char cmd-end-pt)
  11693. (backward-sexp 1) ; Inside comment
  11694. (point))) ; Beginning paren
  11695. (cmd (buffer-substring-no-properties cmd-beg-pt cmd-end-pt)))
  11696. (verilog-forward-or-insert-line)
  11697. ;; Some commands don't move point (like insert-file) so we always
  11698. ;; add the begin/end comments, then delete it if not needed
  11699. (verilog-insert-indent "// Beginning of automatic insert lisp\n")
  11700. (verilog-insert-indent "// End of automatics\n")
  11701. (forward-line -1)
  11702. (eval (read cmd))
  11703. (forward-line -1)
  11704. (setq verilog-scan-cache-tick nil) ; Clear cache; inserted unknown text
  11705. (verilog-delete-empty-auto-pair))))
  11706. (defun verilog-auto-insert-last ()
  11707. "Expand AUTOINSERTLAST statements, as part of \\[verilog-auto].
  11708. The Lisp code provided is called after all other AUTOS have been
  11709. expanded, and the Lisp code generally will call `insert' to
  11710. insert text into the current file beginning on the line after the
  11711. AUTOINSERTLAST.
  11712. Other than when called (after AUTOs are expanded), the functionality
  11713. is otherwise identical to AUTOINSERTLISP and `verilog-auto-insert-lisp' which
  11714. executes before (as opposed to after) other AUTOs.
  11715. See `verilog-auto-insert-lisp' for examples."
  11716. (verilog-auto-insert-lisp))
  11717. (defun verilog-auto-sense-sigs (moddecls presense-sigs)
  11718. "Return list of signals for current AUTOSENSE block."
  11719. (let* ((sigss (save-excursion
  11720. (search-forward ")")
  11721. (verilog-read-always-signals)))
  11722. (sig-list (verilog-signals-not-params
  11723. (verilog-signals-not-in (verilog-alw-get-inputs sigss)
  11724. (append (and (not verilog-auto-sense-include-inputs)
  11725. (verilog-alw-get-outputs-delayed sigss))
  11726. (and (not verilog-auto-sense-include-inputs)
  11727. (verilog-alw-get-outputs-immediate sigss))
  11728. (verilog-alw-get-temps sigss)
  11729. (verilog-decls-get-consts moddecls)
  11730. (verilog-decls-get-gparams moddecls)
  11731. presense-sigs)))))
  11732. sig-list))
  11733. (defun verilog-auto-sense ()
  11734. "Expand AUTOSENSE statements, as part of \\[verilog-auto].
  11735. Replace the always (/*AUTOSENSE*/) sensitivity list (/*AS*/ for short)
  11736. with one automatically derived from all inputs declared in the always
  11737. statement. Signals that are generated within the same always block are NOT
  11738. placed into the sensitivity list (see `verilog-auto-sense-include-inputs').
  11739. Long lines are split based on the `fill-column', see \\[set-fill-column].
  11740. Limitations:
  11741. Verilog does not allow memories (multidimensional arrays) in sensitivity
  11742. lists. AUTOSENSE will thus exclude them, and add a /*memory or*/ comment.
  11743. Constant signals:
  11744. AUTOSENSE cannot always determine if a \\=`define is a constant or a signal
  11745. (it could be in an include file for example). If a \\=`define or other signal
  11746. is put into the AUTOSENSE list and is not desired, use the AUTO_CONSTANT
  11747. declaration anywhere in the module (parenthesis are required):
  11748. /* AUTO_CONSTANT ( \\=`this_is_really_constant_dont_autosense_it ) */
  11749. Better yet, use a parameter, which will be understood to be constant
  11750. automatically.
  11751. OOps!
  11752. If AUTOSENSE makes a mistake, please report it. (First try putting
  11753. a begin/end after your always!) As a workaround, if a signal that
  11754. shouldn't be in the sensitivity list was, use the AUTO_CONSTANT above.
  11755. If a signal should be in the sensitivity list wasn't, placing it before
  11756. the /*AUTOSENSE*/ comment will prevent it from being deleted when the
  11757. autos are updated (or added if it occurs there already).
  11758. An example:
  11759. always @ (/*AS*/) begin
  11760. /* AUTO_CONSTANT (\\=`constant) */
  11761. outin = ina | inb | \\=`constant;
  11762. out = outin;
  11763. end
  11764. Typing \\[verilog-auto] will make this into:
  11765. always @ (/*AS*/ina or inb) begin
  11766. /* AUTO_CONSTANT (\\=`constant) */
  11767. outin = ina | inb | \\=`constant;
  11768. out = outin;
  11769. end
  11770. Note in Verilog 2001, you can often get the same result from the new @*
  11771. operator. (This was added to the language in part due to AUTOSENSE!)
  11772. always @* begin
  11773. outin = ina | inb | \\=`constant;
  11774. out = outin;
  11775. end"
  11776. (save-excursion
  11777. ;; Find beginning
  11778. (let* ((start-pt (save-excursion
  11779. (verilog-re-search-backward-quick "(" nil t)
  11780. (point)))
  11781. (indent-pt (save-excursion
  11782. (or (and (goto-char start-pt) (1+ (current-column)))
  11783. (current-indentation))))
  11784. (modi (verilog-modi-current))
  11785. (moddecls (verilog-modi-get-decls modi))
  11786. (sig-memories (verilog-signals-memory
  11787. (verilog-decls-get-vars moddecls)))
  11788. sig-list not-first presense-sigs)
  11789. ;; Read signals in always, eliminate outputs from sense list
  11790. (setq presense-sigs (verilog-signals-from-signame
  11791. (save-excursion
  11792. (verilog-read-signals start-pt (point)))))
  11793. (setq sig-list (verilog-auto-sense-sigs moddecls presense-sigs))
  11794. (when sig-memories
  11795. (let ((tlen (length sig-list)))
  11796. (setq sig-list (verilog-signals-not-in sig-list sig-memories))
  11797. (if (not (eq tlen (length sig-list))) (verilog-insert " /*memory or*/ "))))
  11798. (if (and presense-sigs ; Add a "or" if not "(.... or /*AUTOSENSE*/"
  11799. (save-excursion (goto-char (point))
  11800. (verilog-re-search-backward-quick "[a-zA-Z0-9$_.%`]+" start-pt t)
  11801. (verilog-re-search-backward-quick "\\s-" start-pt t)
  11802. (while (looking-at "\\s-`endif")
  11803. (verilog-re-search-backward-quick "[a-zA-Z0-9$_.%`]+" start-pt t)
  11804. (verilog-re-search-backward-quick "\\s-" start-pt t))
  11805. (not (looking-at "\\s-or\\b"))))
  11806. (setq not-first t))
  11807. (setq sig-list (sort sig-list `verilog-signals-sort-compare))
  11808. (while sig-list
  11809. (cond ((> (+ 4 (current-column) (length (verilog-sig-name (car sig-list)))) fill-column) ;+4 for width of or
  11810. (insert "\n")
  11811. (indent-to indent-pt)
  11812. (if not-first (insert "or ")))
  11813. (not-first (insert " or ")))
  11814. (insert (verilog-sig-name (car sig-list)))
  11815. (setq sig-list (cdr sig-list)
  11816. not-first t)))))
  11817. (defun verilog-auto-reset ()
  11818. "Expand AUTORESET statements, as part of \\[verilog-auto].
  11819. Replace the /*AUTORESET*/ comment with code to initialize all
  11820. registers set elsewhere in the always block.
  11821. Limitations:
  11822. AUTORESET will not clear memories.
  11823. AUTORESET uses <= if the signal has a <= assignment in the block,
  11824. else it uses =.
  11825. If <= is used, all = assigned variables are ignored if
  11826. `verilog-auto-reset-blocking-in-non' is nil; they are presumed
  11827. to be temporaries.
  11828. /*AUTORESET*/ presumes that any signals mentioned between the previous
  11829. begin/case/if statement and the AUTORESET comment are being reset manually
  11830. and should not be automatically reset. This includes omitting any signals
  11831. used on the right hand side of assignments.
  11832. By default, AUTORESET will include the width of the signal in the
  11833. autos, SystemVerilog designs may want to change this. To control
  11834. this behavior, see `verilog-auto-reset-widths'. In some cases
  11835. AUTORESET must use a '0 assignment and it will print NOWIDTH; use
  11836. `verilog-auto-reset-widths' unbased to prevent this.
  11837. AUTORESET ties signals to deasserted, which is presumed to be zero.
  11838. Signals that match `verilog-active-low-regexp' will be deasserted by tying
  11839. them to a one.
  11840. AUTORESET may try to reset arrays or structures that cannot be
  11841. reset by a simple assignment, resulting in compile errors. This
  11842. is a feature to be taken as a hint that you need to reset these
  11843. signals manually (or put them into a \"\\=`ifdef NEVER signal<=\\=`0;
  11844. \\=`endif\" so Verilog-Mode ignores them.)
  11845. An example:
  11846. always @(posedge clk or negedge reset_l) begin
  11847. if (!reset_l) begin
  11848. c <= 1;
  11849. /*AUTORESET*/
  11850. end
  11851. else begin
  11852. a <= in_a;
  11853. b <= in_b;
  11854. c <= in_c;
  11855. end
  11856. end
  11857. Typing \\[verilog-auto] will make this into:
  11858. always @(posedge core_clk or negedge reset_l) begin
  11859. if (!reset_l) begin
  11860. c <= 1;
  11861. /*AUTORESET*/
  11862. // Beginning of autoreset for uninitialized flops
  11863. a <= 0;
  11864. b = 0; // if `verilog-auto-reset-blocking-in-non' true
  11865. // End of automatics
  11866. end
  11867. else begin
  11868. a <= in_a;
  11869. b = in_b;
  11870. c <= in_c;
  11871. end
  11872. end"
  11873. (interactive)
  11874. (save-excursion
  11875. ;; Find beginning
  11876. (let* ((indent-pt (current-indentation))
  11877. (modi (verilog-modi-current))
  11878. (moddecls (verilog-modi-get-decls modi))
  11879. (all-list (verilog-decls-get-signals moddecls))
  11880. sigss sig-list dly-list prereset-sigs)
  11881. ;; Read signals in always, eliminate outputs from reset list
  11882. (setq prereset-sigs (verilog-signals-from-signame
  11883. (save-excursion
  11884. (verilog-read-signals
  11885. (save-excursion
  11886. (verilog-re-search-backward-quick
  11887. "\\(@\\|\\<\\(begin\\|if\\|case\\|always\\(_latch\\|_ff\\|_comb\\)?\\)\\>\\)" nil t)
  11888. (point))
  11889. (point)))))
  11890. (save-excursion
  11891. (verilog-re-search-backward-quick "\\(@\\|\\<\\(always\\(_latch\\|_ff\\|_comb\\)?\\)\\>\\)" nil t)
  11892. (setq sigss (verilog-read-always-signals)))
  11893. (setq dly-list (verilog-alw-get-outputs-delayed sigss))
  11894. (setq sig-list (verilog-signals-not-in-struct
  11895. (append
  11896. (verilog-alw-get-outputs-delayed sigss)
  11897. (when (or (not (verilog-alw-get-uses-delayed sigss))
  11898. verilog-auto-reset-blocking-in-non)
  11899. (verilog-alw-get-outputs-immediate sigss)))
  11900. (append
  11901. (verilog-alw-get-temps sigss)
  11902. prereset-sigs)))
  11903. (setq sig-list (sort sig-list `verilog-signals-sort-compare))
  11904. (when sig-list
  11905. (insert "\n");
  11906. (verilog-insert-indent "// Beginning of autoreset for uninitialized flops\n");
  11907. (while sig-list
  11908. (let ((sig (or (assoc (verilog-sig-name (car sig-list)) all-list) ; As sig-list has no widths
  11909. (car sig-list))))
  11910. (indent-to indent-pt)
  11911. (insert (verilog-sig-name sig)
  11912. (if (assoc (verilog-sig-name sig) dly-list)
  11913. (concat " <= " verilog-assignment-delay)
  11914. " = ")
  11915. (verilog-sig-tieoff sig)
  11916. ";\n")
  11917. (setq sig-list (cdr sig-list))))
  11918. (verilog-insert-indent "// End of automatics")))))
  11919. (defun verilog-auto-tieoff ()
  11920. "Expand AUTOTIEOFF statements, as part of \\[verilog-auto].
  11921. Replace the /*AUTOTIEOFF*/ comment with code to wire-tie all unused output
  11922. signals to deasserted.
  11923. /*AUTOTIEOFF*/ is used to make stub modules; modules that have the same
  11924. input/output list as another module, but no internals. Specifically, it
  11925. finds all outputs in the module, and if that input is not otherwise declared
  11926. as a register or wire, creates a tieoff.
  11927. AUTORESET ties signals to deasserted, which is presumed to be zero.
  11928. Signals that match `verilog-active-low-regexp' will be deasserted by tying
  11929. them to a one.
  11930. You can add signals you do not want included in AUTOTIEOFF with
  11931. `verilog-auto-tieoff-ignore-regexp'.
  11932. `verilog-auto-wire-type' may be used to change the datatype of
  11933. the declarations.
  11934. `verilog-auto-reset-widths' may be used to change how the tieoff
  11935. value's width is generated.
  11936. An example of making a stub for another module:
  11937. module ExampStub (/*AUTOINST*/);
  11938. /*AUTOINOUTPARAM(\"Foo\")*/
  11939. /*AUTOINOUTMODULE(\"Foo\")*/
  11940. /*AUTOTIEOFF*/
  11941. // verilator lint_off UNUSED
  11942. wire _unused_ok = &{1\\='b0,
  11943. /*AUTOUNUSED*/
  11944. 1\\='b0};
  11945. // verilator lint_on UNUSED
  11946. endmodule
  11947. Typing \\[verilog-auto] will make this into:
  11948. module ExampStub (/*AUTOINST*/...);
  11949. /*AUTOINOUTPARAM(\"Foo\")*/
  11950. /*AUTOINOUTMODULE(\"Foo\")*/
  11951. // Beginning of autotieoff
  11952. output [2:0] foo;
  11953. // End of automatics
  11954. /*AUTOTIEOFF*/
  11955. // Beginning of autotieoff
  11956. wire [2:0] foo = 3\\='b0;
  11957. // End of automatics
  11958. ...
  11959. endmodule"
  11960. (interactive)
  11961. (save-excursion
  11962. ;; Find beginning
  11963. (let* ((indent-pt (current-indentation))
  11964. (modi (verilog-modi-current))
  11965. (moddecls (verilog-modi-get-decls modi))
  11966. (modsubdecls (verilog-modi-get-sub-decls modi))
  11967. (sig-list (verilog-signals-not-in
  11968. (verilog-decls-get-outputs moddecls)
  11969. (append (verilog-decls-get-vars moddecls)
  11970. (verilog-decls-get-assigns moddecls)
  11971. (verilog-decls-get-consts moddecls)
  11972. (verilog-decls-get-gparams moddecls)
  11973. (verilog-subdecls-get-interfaced modsubdecls)
  11974. (verilog-subdecls-get-outputs modsubdecls)
  11975. (verilog-subdecls-get-inouts modsubdecls)))))
  11976. (setq sig-list (verilog-signals-not-matching-regexp
  11977. sig-list verilog-auto-tieoff-ignore-regexp))
  11978. (when sig-list
  11979. (verilog-forward-or-insert-line)
  11980. (verilog-insert-indent "// Beginning of automatic tieoffs (for this module's unterminated outputs)\n")
  11981. (setq sig-list (sort (copy-alist sig-list) `verilog-signals-sort-compare))
  11982. (verilog-modi-cache-add-vars modi sig-list) ; Before we trash list
  11983. (while sig-list
  11984. (let ((sig (car sig-list)))
  11985. (cond ((equal verilog-auto-tieoff-declaration "assign")
  11986. (indent-to indent-pt)
  11987. (insert "assign " (verilog-sig-name sig)))
  11988. (t
  11989. (verilog-insert-one-definition sig verilog-auto-tieoff-declaration indent-pt)))
  11990. (indent-to (max 48 (+ indent-pt 40)))
  11991. (insert "= " (verilog-sig-tieoff sig)
  11992. ";\n")
  11993. (setq sig-list (cdr sig-list))))
  11994. (verilog-insert-indent "// End of automatics\n")))))
  11995. (defun verilog-auto-undef ()
  11996. "Expand AUTOUNDEF statements, as part of \\[verilog-auto].
  11997. Take any \\=`defines since the last AUTOUNDEF in the current file
  11998. and create \\=`undefs for them. This is used to insure that
  11999. file-local defines do not pollute the global \\=`define name space.
  12000. Limitations:
  12001. AUTOUNDEF presumes any identifier following \\=`define is the
  12002. name of a define. Any \\=`ifdefs are ignored.
  12003. AUTOUNDEF suppresses creating an \\=`undef for any define that was
  12004. \\=`undefed before the AUTOUNDEF. This may be used to work around
  12005. the ignoring of \\=`ifdefs as shown below.
  12006. An example:
  12007. \\=`define XX_FOO
  12008. \\=`define M_BAR(x)
  12009. \\=`define M_BAZ
  12010. ...
  12011. \\=`ifdef NEVER
  12012. \\=`undef M_BAZ // Emacs will see this and not \\=`undef M_BAZ
  12013. \\=`endif
  12014. ...
  12015. /*AUTOUNDEF*/
  12016. Typing \\[verilog-auto] will make this into:
  12017. ...
  12018. /*AUTOUNDEF*/
  12019. // Beginning of automatic undefs
  12020. \\=`undef XX_FOO
  12021. \\=`undef M_BAR
  12022. // End of automatics
  12023. You may also provide an optional regular expression, in which case only
  12024. defines the regular expression will be undefed."
  12025. (save-excursion
  12026. (let* ((params (verilog-read-auto-params 0 1))
  12027. (regexp (nth 0 params))
  12028. (indent-pt (current-indentation))
  12029. (end-pt (point))
  12030. defs def)
  12031. (save-excursion
  12032. ;; Scan from start of file, or last AUTOUNDEF
  12033. (or (verilog-re-search-backward-quick "/\\*AUTOUNDEF\\>" end-pt t)
  12034. (goto-char (point-min)))
  12035. (while (verilog-re-search-forward-quick
  12036. "`\\(define\\|undef\\)\\s-*\\([a-zA-Z_][a-zA-Z_0-9]*\\)" end-pt t)
  12037. (cond ((equal (match-string-no-properties 1) "define")
  12038. (setq def (match-string-no-properties 2))
  12039. (when (and (or (not regexp)
  12040. (string-match regexp def))
  12041. (not (member def defs))) ; delete-dups not in 21.1
  12042. (setq defs (cons def defs))))
  12043. (t
  12044. (setq defs (delete (match-string-no-properties 2) defs))))))
  12045. ;; Insert
  12046. (setq defs (sort defs 'string<))
  12047. (when defs
  12048. (verilog-forward-or-insert-line)
  12049. (verilog-insert-indent "// Beginning of automatic undefs\n")
  12050. (while defs
  12051. (verilog-insert-indent "`undef " (car defs) "\n")
  12052. (setq defs (cdr defs)))
  12053. (verilog-insert-indent "// End of automatics\n")))))
  12054. (defun verilog-auto-unused ()
  12055. "Expand AUTOUNUSED statements, as part of \\[verilog-auto].
  12056. Replace the /*AUTOUNUSED*/ comment with a comma separated list of all unused
  12057. input and inout signals.
  12058. /*AUTOUNUSED*/ is used to make stub modules; modules that have the same
  12059. input/output list as another module, but no internals. Specifically, it
  12060. finds all inputs and inouts in the module, and if that input is not otherwise
  12061. used, adds it to a comma separated list.
  12062. The comma separated list is intended to be used to create a _unused_ok
  12063. signal. Using the exact name \"_unused_ok\" for name of the temporary
  12064. signal is recommended as it will insure maximum forward compatibility, it
  12065. also makes lint warnings easy to understand; ignore any unused warnings
  12066. with \"unused\" in the signal name.
  12067. To reduce simulation time, the _unused_ok signal should be forced to a
  12068. constant to prevent wiggling. The easiest thing to do is use a
  12069. reduction-and with 1\\='b0 as shown.
  12070. This way all unused signals are in one place, making it convenient to add
  12071. your tool's specific pragmas around the assignment to disable any unused
  12072. warnings.
  12073. You can add signals you do not want included in AUTOUNUSED with
  12074. `verilog-auto-unused-ignore-regexp'.
  12075. An example of making a stub for another module:
  12076. module ExampStub (/*AUTOINST*/);
  12077. /*AUTOINOUTPARAM(\"Examp\")*/
  12078. /*AUTOINOUTMODULE(\"Examp\")*/
  12079. /*AUTOTIEOFF*/
  12080. // verilator lint_off UNUSED
  12081. wire _unused_ok = &{1\\='b0,
  12082. /*AUTOUNUSED*/
  12083. 1\\='b0};
  12084. // verilator lint_on UNUSED
  12085. endmodule
  12086. Typing \\[verilog-auto] will make this into:
  12087. ...
  12088. // verilator lint_off UNUSED
  12089. wire _unused_ok = &{1\\='b0,
  12090. /*AUTOUNUSED*/
  12091. // Beginning of automatics
  12092. unused_input_a,
  12093. unused_input_b,
  12094. unused_input_c,
  12095. // End of automatics
  12096. 1\\='b0};
  12097. // verilator lint_on UNUSED
  12098. endmodule"
  12099. (interactive)
  12100. (save-excursion
  12101. ;; Find beginning
  12102. (let* ((indent-pt (progn (search-backward "/*") (current-column)))
  12103. (modi (verilog-modi-current))
  12104. (moddecls (verilog-modi-get-decls modi))
  12105. (modsubdecls (verilog-modi-get-sub-decls modi))
  12106. (sig-list (verilog-signals-not-in
  12107. (append (verilog-decls-get-inputs moddecls)
  12108. (verilog-decls-get-inouts moddecls))
  12109. (append (verilog-subdecls-get-inputs modsubdecls)
  12110. (verilog-subdecls-get-inouts modsubdecls)))))
  12111. (setq sig-list (verilog-signals-not-matching-regexp
  12112. sig-list verilog-auto-unused-ignore-regexp))
  12113. (when sig-list
  12114. (verilog-forward-or-insert-line)
  12115. (verilog-insert-indent "// Beginning of automatic unused inputs\n")
  12116. (setq sig-list (sort (copy-alist sig-list) `verilog-signals-sort-compare))
  12117. (while sig-list
  12118. (let ((sig (car sig-list)))
  12119. (indent-to indent-pt)
  12120. (insert (verilog-sig-name sig) ",\n")
  12121. (setq sig-list (cdr sig-list))))
  12122. (verilog-insert-indent "// End of automatics\n")))))
  12123. (defun verilog-enum-ascii (signm elim-regexp)
  12124. "Convert an enum name SIGNM to an ascii string for insertion.
  12125. Remove user provided prefix ELIM-REGEXP."
  12126. (or elim-regexp (setq elim-regexp "_ DONT MATCH IT_"))
  12127. (let ((case-fold-search t))
  12128. ;; All upper becomes all lower for readability
  12129. (downcase (verilog-string-replace-matches elim-regexp "" nil nil signm))))
  12130. (defun verilog-auto-ascii-enum ()
  12131. "Expand AUTOASCIIENUM statements, as part of \\[verilog-auto].
  12132. Create a register to contain the ASCII decode of an enumerated signal type.
  12133. This will allow trace viewers to show the ASCII name of states.
  12134. First, parameters are built into an enumeration using the synopsys enum
  12135. comment. The comment must be between the keyword and the symbol.
  12136. \(Annoying, but that's what Synopsys's dc_shell FSM reader requires.)
  12137. Next, registers which that enum applies to are also tagged with the same
  12138. enum.
  12139. Finally, an AUTOASCIIENUM command is used.
  12140. The first parameter is the name of the signal to be decoded.
  12141. The second parameter is the name to store the ASCII code into. For the
  12142. signal foo, I suggest the name _foo__ascii, where the leading _ indicates
  12143. a signal that is just for simulation, and the magic characters _ascii
  12144. tell viewers like Dinotrace to display in ASCII format.
  12145. The third optional parameter is a string which will be removed
  12146. from the state names. It defaults to \"\" which removes nothing.
  12147. The fourth optional parameter is \"onehot\" to force one-hot
  12148. decoding. If unspecified, if and only if the first parameter
  12149. width is 2^(number of states in enum) and does NOT match the
  12150. width of the enum, the signal is assumed to be a one-hot
  12151. decode. Otherwise, it's a normal encoded state vector.
  12152. `verilog-auto-wire-type' may be used to change the datatype of
  12153. the declarations.
  12154. \"auto enum\" may be used in place of \"synopsys enum\".
  12155. An example:
  12156. //== State enumeration
  12157. parameter [2:0] // synopsys enum state_info
  12158. SM_IDLE = 3\\='b000,
  12159. SM_SEND = 3\\='b001,
  12160. SM_WAIT1 = 3\\='b010;
  12161. //== State variables
  12162. reg [2:0] /* synopsys enum state_info */
  12163. state_r; /* synopsys state_vector state_r */
  12164. reg [2:0] /* synopsys enum state_info */
  12165. state_e1;
  12166. /*AUTOASCIIENUM(\"state_r\", \"state_ascii_r\", \"SM_\")*/
  12167. Typing \\[verilog-auto] will make this into:
  12168. ... same front matter ...
  12169. /*AUTOASCIIENUM(\"state_r\", \"state_ascii_r\", \"SM_\")*/
  12170. // Beginning of automatic ASCII enum decoding
  12171. reg [39:0] state_ascii_r; // Decode of state_r
  12172. always @(state_r) begin
  12173. case ({state_r})
  12174. SM_IDLE: state_ascii_r = \"idle \";
  12175. SM_SEND: state_ascii_r = \"send \";
  12176. SM_WAIT1: state_ascii_r = \"wait1\";
  12177. default: state_ascii_r = \"%Erro\";
  12178. endcase
  12179. end
  12180. // End of automatics"
  12181. (save-excursion
  12182. (let* ((params (verilog-read-auto-params 2 4))
  12183. (undecode-name (nth 0 params))
  12184. (ascii-name (nth 1 params))
  12185. (elim-regexp (and (nth 2 params)
  12186. (not (equal (nth 2 params) ""))
  12187. (nth 2 params)))
  12188. (one-hot-flag (nth 3 params))
  12189. ;;
  12190. (indent-pt (current-indentation))
  12191. (modi (verilog-modi-current))
  12192. (moddecls (verilog-modi-get-decls modi))
  12193. ;;
  12194. (sig-list-consts (append (verilog-decls-get-consts moddecls)
  12195. (verilog-decls-get-gparams moddecls)))
  12196. (sig-list-all (verilog-decls-get-iovars moddecls))
  12197. ;;
  12198. (undecode-sig (or (assoc undecode-name sig-list-all)
  12199. (error "%s: Signal %s not found in design" (verilog-point-text) undecode-name)))
  12200. (undecode-enum (or (verilog-sig-enum undecode-sig)
  12201. (error "%s: Signal %s does not have an enum tag" (verilog-point-text) undecode-name)))
  12202. ;;
  12203. (enum-sigs (verilog-signals-not-in
  12204. (or (verilog-signals-matching-enum sig-list-consts undecode-enum)
  12205. (error "%s: No state definitions for %s" (verilog-point-text) undecode-enum))
  12206. nil))
  12207. ;;
  12208. (one-hot (or
  12209. (string-match "onehot" (or one-hot-flag ""))
  12210. (and ; width(enum) != width(sig)
  12211. (or (not (verilog-sig-bits (car enum-sigs)))
  12212. (not (equal (verilog-sig-width (car enum-sigs))
  12213. (verilog-sig-width undecode-sig))))
  12214. ;; count(enums) == width(sig)
  12215. (equal (number-to-string (length enum-sigs))
  12216. (verilog-sig-width undecode-sig)))))
  12217. (enum-chars 0)
  12218. (ascii-chars 0))
  12219. ;;
  12220. ;; Find number of ascii chars needed
  12221. (let ((tmp-sigs enum-sigs))
  12222. (while tmp-sigs
  12223. (setq enum-chars (max enum-chars (length (verilog-sig-name (car tmp-sigs))))
  12224. ascii-chars (max ascii-chars (length (verilog-enum-ascii
  12225. (verilog-sig-name (car tmp-sigs))
  12226. elim-regexp)))
  12227. tmp-sigs (cdr tmp-sigs))))
  12228. ;;
  12229. (verilog-forward-or-insert-line)
  12230. (verilog-insert-indent "// Beginning of automatic ASCII enum decoding\n")
  12231. (let ((decode-sig-list (list (list ascii-name (format "[%d:0]" (- (* ascii-chars 8) 1))
  12232. (concat "Decode of " undecode-name) nil nil))))
  12233. (verilog-insert-definition modi decode-sig-list "reg" indent-pt nil))
  12234. ;;
  12235. (verilog-insert-indent "always @(" undecode-name ") begin\n")
  12236. (setq indent-pt (+ indent-pt verilog-indent-level))
  12237. (verilog-insert-indent "case ({" undecode-name "})\n")
  12238. (setq indent-pt (+ indent-pt verilog-case-indent))
  12239. ;;
  12240. (let ((tmp-sigs enum-sigs)
  12241. (chrfmt (format "%%-%ds %s = \"%%-%ds\";\n"
  12242. (+ (if one-hot 9 1) (max 8 enum-chars))
  12243. ascii-name ascii-chars))
  12244. (errname (substring "%Error" 0 (min 6 ascii-chars))))
  12245. (while tmp-sigs
  12246. (verilog-insert-indent
  12247. (concat
  12248. (format chrfmt
  12249. (concat (if one-hot "(")
  12250. ;; Use enum-sigs length as that's numeric
  12251. ;; verilog-sig-width undecode-sig might not be.
  12252. (if one-hot (number-to-string (length enum-sigs)))
  12253. ;; We use a shift instead of var[index]
  12254. ;; so that a non-one hot value will show as error.
  12255. (if one-hot "'b1<<")
  12256. (verilog-sig-name (car tmp-sigs))
  12257. (if one-hot ")") ":")
  12258. (verilog-enum-ascii (verilog-sig-name (car tmp-sigs))
  12259. elim-regexp))))
  12260. (setq tmp-sigs (cdr tmp-sigs)))
  12261. (verilog-insert-indent (format chrfmt "default:" errname)))
  12262. ;;
  12263. (setq indent-pt (- indent-pt verilog-case-indent))
  12264. (verilog-insert-indent "endcase\n")
  12265. (setq indent-pt (- indent-pt verilog-indent-level))
  12266. (verilog-insert-indent "end\n"
  12267. "// End of automatics\n"))))
  12268. (defun verilog-auto-templated-rel ()
  12269. "Replace Templated relative line numbers with absolute line numbers.
  12270. Internal use only. This hacks around the line numbers in AUTOINST Templates
  12271. being different from the final output's line numbering."
  12272. (let ((templateno 0) (template-line (list 0)) (buf-line 1))
  12273. ;; Find line number each template is on
  12274. ;; Count lines as we go, as otherwise it's O(n^2) to use count-lines
  12275. (goto-char (point-min))
  12276. (while (not (eobp))
  12277. (when (looking-at ".*AUTO_TEMPLATE")
  12278. (setq templateno (1+ templateno))
  12279. (setq template-line (cons buf-line template-line)))
  12280. (setq buf-line (1+ buf-line))
  12281. (forward-line 1))
  12282. (setq template-line (nreverse template-line))
  12283. ;; Replace T# L# with absolute line number
  12284. (goto-char (point-min))
  12285. (while (re-search-forward " Templated T\\([0-9]+\\) L\\([0-9]+\\)" nil t)
  12286. (replace-match
  12287. (concat " Templated "
  12288. (int-to-string (+ (nth (string-to-number (match-string 1))
  12289. template-line)
  12290. (string-to-number (match-string 2)))))
  12291. t t))))
  12292. (defun verilog-auto-template-lint ()
  12293. "Check AUTO_TEMPLATEs for unused lines.
  12294. Enable with `verilog-auto-template-warn-unused'."
  12295. (let ((name1 (or (buffer-file-name) (buffer-name))))
  12296. (save-excursion
  12297. (goto-char (point-min))
  12298. (while (re-search-forward
  12299. "^\\s-*/?\\*?\\s-*[a-zA-Z0-9`_$]+\\s-+AUTO_TEMPLATE" nil t)
  12300. (let* ((tpl-info (verilog-read-auto-template-middle))
  12301. (tpl-list (aref tpl-info 1))
  12302. (tlines (append (nth 0 tpl-list) (nth 1 tpl-list)))
  12303. tpl-ass)
  12304. (while tlines
  12305. (setq tpl-ass (car tlines)
  12306. tlines (cdr tlines))
  12307. ;;
  12308. (unless (or (not (eval-when-compile (fboundp 'make-hash-table))) ; Not supported, no warning
  12309. (not verilog-auto-template-hits)
  12310. (gethash (vector (nth 2 tpl-ass) (nth 3 tpl-ass))
  12311. verilog-auto-template-hits))
  12312. (verilog-warn-error "%s:%d: AUTO_TEMPLATE line unused: \".%s (%s)\""
  12313. name1
  12314. (+ (elt tpl-ass 3) ; Template line number
  12315. (count-lines (point-min) (point)))
  12316. (elt tpl-ass 0) (elt tpl-ass 1))
  12317. )))))))
  12318. ;;; Auto top level:
  12319. ;;
  12320. (defun verilog-auto (&optional inject) ; Use verilog-inject-auto instead of passing an arg
  12321. "Expand AUTO statements.
  12322. Look for any /*AUTO...*/ commands in the code, as used in
  12323. instantiations or argument headers. Update the list of signals
  12324. following the /*AUTO...*/ command.
  12325. Use \\[verilog-delete-auto] to remove the AUTOs.
  12326. Use \\[verilog-diff-auto] to see differences in AUTO expansion.
  12327. Use \\[verilog-inject-auto] to insert AUTOs for the first time.
  12328. Use \\[verilog-faq] for a pointer to frequently asked questions.
  12329. For new users, we recommend setting `verilog-case-fold' to nil
  12330. and `verilog-auto-arg-sort' to t.
  12331. The hooks `verilog-before-auto-hook' and `verilog-auto-hook' are
  12332. called before and after this function, respectively.
  12333. For example:
  12334. module ModuleName (/*AUTOARG*/);
  12335. /*AUTOINPUT*/
  12336. /*AUTOOUTPUT*/
  12337. /*AUTOWIRE*/
  12338. /*AUTOREG*/
  12339. InstMod instName #(/*AUTOINSTPARAM*/) (/*AUTOINST*/);
  12340. You can also update the AUTOs from the shell using:
  12341. emacs --batch <filenames.v> -f verilog-batch-auto
  12342. Or fix indentation with:
  12343. emacs --batch <filenames.v> -f verilog-batch-indent
  12344. Likewise, you can delete or inject AUTOs with:
  12345. emacs --batch <filenames.v> -f verilog-batch-delete-auto
  12346. emacs --batch <filenames.v> -f verilog-batch-inject-auto
  12347. Or check if AUTOs have the same expansion
  12348. emacs --batch <filenames.v> -f verilog-batch-diff-auto
  12349. Using \\[describe-function], see also:
  12350. `verilog-auto-arg' for AUTOARG module instantiations
  12351. `verilog-auto-ascii-enum' for AUTOASCIIENUM enumeration decoding
  12352. `verilog-auto-assign-modport' for AUTOASSIGNMODPORT assignment to/from modport
  12353. `verilog-auto-inout' for AUTOINOUT making hierarchy inouts
  12354. `verilog-auto-inout-comp' for AUTOINOUTCOMP copy complemented i/o
  12355. `verilog-auto-inout-in' for AUTOINOUTIN inputs for all i/o
  12356. `verilog-auto-inout-modport' for AUTOINOUTMODPORT i/o from an interface modport
  12357. `verilog-auto-inout-module' for AUTOINOUTMODULE copying i/o from elsewhere
  12358. `verilog-auto-inout-param' for AUTOINOUTPARAM copying params from elsewhere
  12359. `verilog-auto-input' for AUTOINPUT making hierarchy inputs
  12360. `verilog-auto-insert-lisp' for AUTOINSERTLISP insert code from lisp function
  12361. `verilog-auto-insert-last' for AUTOINSERTLAST insert code from lisp function
  12362. `verilog-auto-inst' for AUTOINST instantiation pins
  12363. `verilog-auto-star' for AUTOINST .* SystemVerilog pins
  12364. `verilog-auto-inst-param' for AUTOINSTPARAM instantiation params
  12365. `verilog-auto-logic' for AUTOLOGIC declaring logic signals
  12366. `verilog-auto-output' for AUTOOUTPUT making hierarchy outputs
  12367. `verilog-auto-output-every' for AUTOOUTPUTEVERY making all outputs
  12368. `verilog-auto-reg' for AUTOREG registers
  12369. `verilog-auto-reg-input' for AUTOREGINPUT instantiation registers
  12370. `verilog-auto-reset' for AUTORESET flop resets
  12371. `verilog-auto-sense' for AUTOSENSE or AS always sensitivity lists
  12372. `verilog-auto-tieoff' for AUTOTIEOFF output tieoffs
  12373. `verilog-auto-undef' for AUTOUNDEF \\=`undef of local \\=`defines
  12374. `verilog-auto-unused' for AUTOUNUSED unused inputs/inouts
  12375. `verilog-auto-wire' for AUTOWIRE instantiation wires
  12376. `verilog-read-defines' for reading \\=`define values
  12377. `verilog-read-includes' for reading \\=`includes
  12378. If you have bugs with these autos, please file an issue at
  12379. URL `http://www.veripool.org/verilog-mode' or contact the AUTOAUTHOR
  12380. Wilson Snyder (wsnyder@wsnyder.org)."
  12381. (interactive)
  12382. (unless noninteractive (message "Updating AUTOs..."))
  12383. (if (fboundp 'dinotrace-unannotate-all)
  12384. (dinotrace-unannotate-all))
  12385. (verilog-save-font-mods
  12386. (let ((oldbuf (if (not (buffer-modified-p))
  12387. (buffer-string)))
  12388. (case-fold-search verilog-case-fold)
  12389. ;; Cache directories; we don't write new files, so can't change
  12390. (verilog-dir-cache-preserving t)
  12391. ;; Cache current module
  12392. (verilog-modi-cache-current-enable t)
  12393. (verilog-modi-cache-current-max (point-min)) ; IE it's invalid
  12394. verilog-modi-cache-current)
  12395. (unwind-protect
  12396. ;; Disable change hooks for speed
  12397. ;; This let can't be part of above let; must restore
  12398. ;; after-change-functions before font-lock resumes
  12399. (verilog-save-no-change-functions
  12400. (verilog-save-scan-cache
  12401. (save-excursion
  12402. ;; Wipe cache; otherwise if we AUTOed a block above this one,
  12403. ;; we'll misremember we have generated IOs, confusing AUTOOUTPUT
  12404. (setq verilog-modi-cache-list nil)
  12405. ;; Local state
  12406. (verilog-read-auto-template-init)
  12407. ;; If we're not in verilog-mode, change syntax table so parsing works right
  12408. (unless (eq major-mode `verilog-mode) (verilog-mode))
  12409. ;; Allow user to customize
  12410. (verilog-run-hooks 'verilog-before-auto-hook)
  12411. ;; Try to save the user from needing to revert-file to reread file local-variables
  12412. (verilog-auto-reeval-locals)
  12413. (verilog-read-auto-lisp-present)
  12414. (verilog-read-auto-lisp (point-min) (point-max))
  12415. (verilog-getopt-flags)
  12416. ;; From here on out, we can cache anything we read from disk
  12417. (verilog-preserve-dir-cache
  12418. ;; These two may seem obvious to do always, but on large includes it can be way too slow
  12419. (when verilog-auto-read-includes
  12420. (verilog-read-includes)
  12421. (verilog-read-defines nil nil t))
  12422. ;; Setup variables due to SystemVerilog expansion
  12423. (verilog-auto-re-search-do "/\\*AUTOLOGIC\\*/" 'verilog-auto-logic-setup)
  12424. ;; This particular ordering is important
  12425. ;; INST: Lower modules correct, no internal dependencies, FIRST
  12426. (verilog-preserve-modi-cache
  12427. ;; Clear existing autos else we'll be screwed by existing ones
  12428. (verilog-delete-auto)
  12429. ;; Injection if appropriate
  12430. (when inject
  12431. (verilog-inject-inst)
  12432. (verilog-inject-sense)
  12433. (verilog-inject-arg))
  12434. ;;
  12435. ;; Do user inserts first, so their code can insert AUTOs
  12436. (verilog-auto-re-search-do "/\\*AUTOINSERTLISP(.*?)\\*/"
  12437. 'verilog-auto-insert-lisp)
  12438. ;; Expand instances before need the signals the instances input/output
  12439. (verilog-auto-re-search-do "/\\*AUTOINSTPARAM\\*/" 'verilog-auto-inst-param)
  12440. (verilog-auto-re-search-do "/\\*AUTOINST\\*/" 'verilog-auto-inst)
  12441. (verilog-auto-re-search-do "\\.\\*" 'verilog-auto-star)
  12442. ;; Doesn't matter when done, but combine it with a common changer
  12443. (verilog-auto-re-search-do "/\\*\\(AUTOSENSE\\|AS\\)\\*/" 'verilog-auto-sense)
  12444. (verilog-auto-re-search-do "/\\*AUTORESET\\*/" 'verilog-auto-reset)
  12445. ;; Must be done before autoin/out as creates a reg
  12446. (verilog-auto-re-search-do "/\\*AUTOASCIIENUM(.*?)\\*/" 'verilog-auto-ascii-enum)
  12447. ;;
  12448. ;; first in/outs from other files
  12449. (verilog-auto-re-search-do "/\\*AUTOINOUTMODPORT(.*?)\\*/" 'verilog-auto-inout-modport)
  12450. (verilog-auto-re-search-do "/\\*AUTOINOUTMODULE(.*?)\\*/" 'verilog-auto-inout-module)
  12451. (verilog-auto-re-search-do "/\\*AUTOINOUTCOMP(.*?)\\*/" 'verilog-auto-inout-comp)
  12452. (verilog-auto-re-search-do "/\\*AUTOINOUTIN(.*?)\\*/" 'verilog-auto-inout-in)
  12453. (verilog-auto-re-search-do "/\\*AUTOINOUTPARAM(.*?)\\*/" 'verilog-auto-inout-param)
  12454. ;; next in/outs which need previous sucked inputs first
  12455. (verilog-auto-re-search-do "/\\*AUTOOUTPUT\\((.*?)\\)?\\*/" 'verilog-auto-output)
  12456. (verilog-auto-re-search-do "/\\*AUTOINPUT\\((.*?)\\)?\\*/" 'verilog-auto-input)
  12457. (verilog-auto-re-search-do "/\\*AUTOINOUT\\((.*?)\\)?\\*/" 'verilog-auto-inout)
  12458. ;; Then tie off those in/outs
  12459. (verilog-auto-re-search-do "/\\*AUTOTIEOFF\\*/" 'verilog-auto-tieoff)
  12460. ;; These can be anywhere after AUTOINSERTLISP
  12461. (verilog-auto-re-search-do "/\\*AUTOUNDEF\\((.*?)\\)?\\*/" 'verilog-auto-undef)
  12462. ;; Wires/regs must be after inputs/outputs
  12463. (verilog-auto-re-search-do "/\\*AUTOASSIGNMODPORT(.*?)\\*/" 'verilog-auto-assign-modport)
  12464. (verilog-auto-re-search-do "/\\*AUTOLOGIC\\*/" 'verilog-auto-logic)
  12465. (verilog-auto-re-search-do "/\\*AUTOWIRE\\*/" 'verilog-auto-wire)
  12466. (verilog-auto-re-search-do "/\\*AUTOREG\\*/" 'verilog-auto-reg)
  12467. (verilog-auto-re-search-do "/\\*AUTOREGINPUT\\*/" 'verilog-auto-reg-input)
  12468. ;; outputevery needs AUTOOUTPUTs done first
  12469. (verilog-auto-re-search-do "/\\*AUTOOUTPUTEVERY\\((.*?)\\)?\\*/" 'verilog-auto-output-every)
  12470. ;; After we've created all new variables
  12471. (verilog-auto-re-search-do "/\\*AUTOUNUSED\\*/" 'verilog-auto-unused)
  12472. ;; Must be after all inputs outputs are generated
  12473. (verilog-auto-re-search-do "/\\*AUTOARG\\*/" 'verilog-auto-arg)
  12474. ;; User inserts
  12475. (verilog-auto-re-search-do "/\\*AUTOINSERTLAST(.*?)\\*/" 'verilog-auto-insert-last)
  12476. ;; Fix line numbers (comments only)
  12477. (when verilog-auto-inst-template-numbers
  12478. (verilog-auto-templated-rel))
  12479. (when verilog-auto-template-warn-unused
  12480. (verilog-auto-template-lint))))
  12481. ;;
  12482. (verilog-run-hooks 'verilog-auto-hook)
  12483. ;;
  12484. (when verilog-auto-delete-trailing-whitespace
  12485. (verilog-delete-trailing-whitespace))
  12486. ;;
  12487. (set (make-local-variable 'verilog-auto-update-tick) (buffer-chars-modified-tick))
  12488. ;;
  12489. ;; If end result is same as when started, clear modified flag
  12490. (cond ((and oldbuf (equal oldbuf (buffer-string)))
  12491. (set-buffer-modified-p nil)
  12492. (unless noninteractive (message "Updating AUTOs...done (no changes)")))
  12493. (t (unless noninteractive (message "Updating AUTOs...done"))))
  12494. ;; End of after-change protection
  12495. )))
  12496. ;; Unwind forms
  12497. ;; Currently handled in verilog-save-font-mods
  12498. ))))
  12499. ;;; Skeletons:
  12500. ;;
  12501. (defvar verilog-template-map
  12502. (let ((map (make-sparse-keymap)))
  12503. (define-key map "a" 'verilog-sk-always)
  12504. (define-key map "b" 'verilog-sk-begin)
  12505. (define-key map "c" 'verilog-sk-case)
  12506. (define-key map "f" 'verilog-sk-for)
  12507. (define-key map "g" 'verilog-sk-generate)
  12508. (define-key map "h" 'verilog-sk-header)
  12509. (define-key map "i" 'verilog-sk-initial)
  12510. (define-key map "j" 'verilog-sk-fork)
  12511. (define-key map "m" 'verilog-sk-module)
  12512. (define-key map "o" 'verilog-sk-ovm-class)
  12513. (define-key map "p" 'verilog-sk-primitive)
  12514. (define-key map "r" 'verilog-sk-repeat)
  12515. (define-key map "s" 'verilog-sk-specify)
  12516. (define-key map "t" 'verilog-sk-task)
  12517. (define-key map "u" 'verilog-sk-uvm-object)
  12518. (define-key map "w" 'verilog-sk-while)
  12519. (define-key map "x" 'verilog-sk-casex)
  12520. (define-key map "z" 'verilog-sk-casez)
  12521. (define-key map "?" 'verilog-sk-if)
  12522. (define-key map ":" 'verilog-sk-else-if)
  12523. (define-key map "/" 'verilog-sk-comment)
  12524. (define-key map "A" 'verilog-sk-assign)
  12525. (define-key map "F" 'verilog-sk-function)
  12526. (define-key map "I" 'verilog-sk-input)
  12527. (define-key map "O" 'verilog-sk-output)
  12528. (define-key map "S" 'verilog-sk-state-machine)
  12529. (define-key map "=" 'verilog-sk-inout)
  12530. (define-key map "U" 'verilog-sk-uvm-component)
  12531. (define-key map "W" 'verilog-sk-wire)
  12532. (define-key map "R" 'verilog-sk-reg)
  12533. (define-key map "D" 'verilog-sk-define-signal)
  12534. map)
  12535. "Keymap used in Verilog mode for smart template operations.")
  12536. ;;
  12537. ;; Place the templates into Verilog Mode. They may be inserted under any key.
  12538. ;; C-c C-t will be the default. If you use templates a lot, you
  12539. ;; may want to consider moving the binding to another key in your init
  12540. ;; file.
  12541. ;;
  12542. ;; Note \C-c and letter are reserved for users
  12543. (define-key verilog-mode-map "\C-c\C-t" verilog-template-map)
  12544. ;; ---- statement skeletons ------------------------------------------
  12545. (define-skeleton verilog-sk-prompt-condition
  12546. "Prompt for the loop condition."
  12547. "[condition]: " str )
  12548. (define-skeleton verilog-sk-prompt-init
  12549. "Prompt for the loop init statement."
  12550. "[initial statement]: " str )
  12551. (define-skeleton verilog-sk-prompt-inc
  12552. "Prompt for the loop increment statement."
  12553. "[increment statement]: " str )
  12554. (define-skeleton verilog-sk-prompt-name
  12555. "Prompt for the name of something."
  12556. "[name]: " str)
  12557. (define-skeleton verilog-sk-prompt-clock
  12558. "Prompt for the name of something."
  12559. "name and edge of clock(s): " str)
  12560. (defvar verilog-sk-reset nil)
  12561. (defun verilog-sk-prompt-reset ()
  12562. "Prompt for the name of a state machine reset."
  12563. (setq verilog-sk-reset (read-string "name of reset: " "rst")))
  12564. (define-skeleton verilog-sk-prompt-state-selector
  12565. "Prompt for the name of a state machine selector."
  12566. "name of selector (eg {a,b,c,d}): " str )
  12567. (define-skeleton verilog-sk-prompt-output
  12568. "Prompt for the name of something."
  12569. "output: " str)
  12570. (define-skeleton verilog-sk-prompt-msb
  12571. "Prompt for most significant bit specification."
  12572. "msb:" str & ?: & '(verilog-sk-prompt-lsb) | -1 )
  12573. (define-skeleton verilog-sk-prompt-lsb
  12574. "Prompt for least significant bit specification."
  12575. "lsb:" str )
  12576. (defvar verilog-sk-p nil)
  12577. (define-skeleton verilog-sk-prompt-width
  12578. "Prompt for a width specification."
  12579. ()
  12580. (progn
  12581. (setq verilog-sk-p (point))
  12582. (verilog-sk-prompt-msb)
  12583. (if (> (point) verilog-sk-p) "] " " ")))
  12584. (defun verilog-sk-header ()
  12585. "Insert a descriptive header at the top of the file.
  12586. See also `verilog-header' for an alternative format."
  12587. (interactive "*")
  12588. (save-excursion
  12589. (goto-char (point-min))
  12590. (verilog-sk-header-tmpl)))
  12591. (define-skeleton verilog-sk-header-tmpl
  12592. "Insert a comment block containing the module title, author, etc."
  12593. "[Description]: "
  12594. "// -*- Mode: Verilog -*-"
  12595. "\n// Filename : " (buffer-name)
  12596. "\n// Description : " str
  12597. "\n// Author : " (user-full-name)
  12598. "\n// Created On : " (current-time-string)
  12599. "\n// Last Modified By: " (user-full-name)
  12600. "\n// Last Modified On: " (current-time-string)
  12601. "\n// Update Count : 0"
  12602. "\n// Status : Unknown, Use with caution!"
  12603. "\n")
  12604. (define-skeleton verilog-sk-module
  12605. "Insert a module definition."
  12606. ()
  12607. > "module " '(verilog-sk-prompt-name) " (/*AUTOARG*/ ) ;" \n
  12608. > _ \n
  12609. > (- verilog-indent-level-behavioral) "endmodule" (progn (electric-verilog-terminate-line) nil))
  12610. ;; ------------------------------------------------------------------------
  12611. ;; Define a default OVM class, with macros and new()
  12612. ;; ------------------------------------------------------------------------
  12613. (define-skeleton verilog-sk-ovm-class
  12614. "Insert a class definition"
  12615. ()
  12616. > "class " (setq name (skeleton-read "Name: ")) " extends " (skeleton-read "Extends: ") ";" \n
  12617. > _ \n
  12618. > "`ovm_object_utils_begin(" name ")" \n
  12619. > (- verilog-indent-level) " `ovm_object_utils_end" \n
  12620. > _ \n
  12621. > "function new(string name=\"" name "\");" \n
  12622. > "super.new(name);" \n
  12623. > (- verilog-indent-level) "endfunction" \n
  12624. > _ \n
  12625. > "endclass" (progn (electric-verilog-terminate-line) nil))
  12626. (define-skeleton verilog-sk-uvm-object
  12627. "Insert a class definition"
  12628. ()
  12629. > "class " (setq name (skeleton-read "Name: ")) " extends " (skeleton-read "Extends: ") ";" \n
  12630. > _ \n
  12631. > "`uvm_object_utils_begin(" name ")" \n
  12632. > (- verilog-indent-level) "`uvm_object_utils_end" \n
  12633. > _ \n
  12634. > "function new(string name=\"" name "\");" \n
  12635. > "super.new(name);" \n
  12636. > (- verilog-indent-level) "endfunction" \n
  12637. > _ \n
  12638. > "endclass" (progn (electric-verilog-terminate-line) nil))
  12639. (define-skeleton verilog-sk-uvm-component
  12640. "Insert a class definition"
  12641. ()
  12642. > "class " (setq name (skeleton-read "Name: ")) " extends " (skeleton-read "Extends: ") ";" \n
  12643. > _ \n
  12644. > "`uvm_component_utils_begin(" name ")" \n
  12645. > (- verilog-indent-level) "`uvm_component_utils_end" \n
  12646. > _ \n
  12647. > "function new(string name=\"\", uvm_component parent);" \n
  12648. > "super.new(name, parent);" \n
  12649. > (- verilog-indent-level) "endfunction" \n
  12650. > _ \n
  12651. > "endclass" (progn (electric-verilog-terminate-line) nil))
  12652. (define-skeleton verilog-sk-primitive
  12653. "Insert a task definition."
  12654. ()
  12655. > "primitive " '(verilog-sk-prompt-name) " ( " '(verilog-sk-prompt-output) ("input:" ", " str ) " );"\n
  12656. > _ \n
  12657. > (- verilog-indent-level-behavioral) "endprimitive" (progn (electric-verilog-terminate-line) nil))
  12658. (define-skeleton verilog-sk-task
  12659. "Insert a task definition."
  12660. ()
  12661. > "task " '(verilog-sk-prompt-name) & ?; \n
  12662. > _ \n
  12663. > "begin" \n
  12664. > \n
  12665. > (- verilog-indent-level-behavioral) "end" \n
  12666. > (- verilog-indent-level-behavioral) "endtask" (progn (electric-verilog-terminate-line) nil))
  12667. (define-skeleton verilog-sk-function
  12668. "Insert a function definition."
  12669. ()
  12670. > "function [" '(verilog-sk-prompt-width) | -1 '(verilog-sk-prompt-name) ?; \n
  12671. > _ \n
  12672. > "begin" \n
  12673. > \n
  12674. > (- verilog-indent-level-behavioral) "end" \n
  12675. > (- verilog-indent-level-behavioral) "endfunction" (progn (electric-verilog-terminate-line) nil))
  12676. (define-skeleton verilog-sk-always
  12677. "Insert always block. Uses the minibuffer to prompt
  12678. for sensitivity list."
  12679. ()
  12680. > "always @ ( /*AUTOSENSE*/ ) begin\n"
  12681. > _ \n
  12682. > (- verilog-indent-level-behavioral) "end" \n >
  12683. )
  12684. (define-skeleton verilog-sk-initial
  12685. "Insert an initial block."
  12686. ()
  12687. > "initial begin\n"
  12688. > _ \n
  12689. > (- verilog-indent-level-behavioral) "end" \n > )
  12690. (define-skeleton verilog-sk-specify
  12691. "Insert specify block. "
  12692. ()
  12693. > "specify\n"
  12694. > _ \n
  12695. > (- verilog-indent-level-behavioral) "endspecify" \n > )
  12696. (define-skeleton verilog-sk-generate
  12697. "Insert generate block. "
  12698. ()
  12699. > "generate\n"
  12700. > _ \n
  12701. > (- verilog-indent-level-behavioral) "endgenerate" \n > )
  12702. (define-skeleton verilog-sk-begin
  12703. "Insert begin end block. Uses the minibuffer to prompt for name."
  12704. ()
  12705. > "begin" '(verilog-sk-prompt-name) \n
  12706. > _ \n
  12707. > (- verilog-indent-level-behavioral) "end" )
  12708. (define-skeleton verilog-sk-fork
  12709. "Insert a fork join block."
  12710. ()
  12711. > "fork\n"
  12712. > "begin" \n
  12713. > _ \n
  12714. > (- verilog-indent-level-behavioral) "end" \n
  12715. > "begin" \n
  12716. > \n
  12717. > (- verilog-indent-level-behavioral) "end" \n
  12718. > (- verilog-indent-level-behavioral) "join" \n
  12719. > )
  12720. (define-skeleton verilog-sk-case
  12721. "Build skeleton case statement, prompting for the selector expression,
  12722. and the case items."
  12723. "[selector expression]: "
  12724. > "case (" str ") " \n
  12725. > ("case selector: " str ": begin" \n > _ \n > (- verilog-indent-level-behavioral) "end" \n > )
  12726. resume: > (- verilog-case-indent) "endcase" (progn (electric-verilog-terminate-line) nil))
  12727. (define-skeleton verilog-sk-casex
  12728. "Build skeleton casex statement, prompting for the selector expression,
  12729. and the case items."
  12730. "[selector expression]: "
  12731. > "casex (" str ") " \n
  12732. > ("case selector: " str ": begin" \n > _ \n > (- verilog-indent-level-behavioral) "end" \n > )
  12733. resume: > (- verilog-case-indent) "endcase" (progn (electric-verilog-terminate-line) nil))
  12734. (define-skeleton verilog-sk-casez
  12735. "Build skeleton casez statement, prompting for the selector expression,
  12736. and the case items."
  12737. "[selector expression]: "
  12738. > "casez (" str ") " \n
  12739. > ("case selector: " str ": begin" \n > _ \n > (- verilog-indent-level-behavioral) "end" \n > )
  12740. resume: > (- verilog-case-indent) "endcase" (progn (electric-verilog-terminate-line) nil))
  12741. (define-skeleton verilog-sk-if
  12742. "Insert a skeleton if statement."
  12743. > "if (" '(verilog-sk-prompt-condition) & ")" " begin" \n
  12744. > _ \n
  12745. > (- verilog-indent-level-behavioral) "end " \n )
  12746. (define-skeleton verilog-sk-else-if
  12747. "Insert a skeleton else if statement."
  12748. > (verilog-indent-line) "else if ("
  12749. (progn (setq verilog-sk-p (point)) nil) '(verilog-sk-prompt-condition) (if (> (point) verilog-sk-p) ") " -1 ) & " begin" \n
  12750. > _ \n
  12751. > "end" (progn (electric-verilog-terminate-line) nil))
  12752. (define-skeleton verilog-sk-datadef
  12753. "Common routine to get data definition."
  12754. ()
  12755. '(verilog-sk-prompt-width) | -1 ("name (RET to end):" str ", ") -2 ";" \n)
  12756. (define-skeleton verilog-sk-input
  12757. "Insert an input definition."
  12758. ()
  12759. > "input [" '(verilog-sk-datadef))
  12760. (define-skeleton verilog-sk-output
  12761. "Insert an output definition."
  12762. ()
  12763. > "output [" '(verilog-sk-datadef))
  12764. (define-skeleton verilog-sk-inout
  12765. "Insert an inout definition."
  12766. ()
  12767. > "inout [" '(verilog-sk-datadef))
  12768. (defvar verilog-sk-signal nil)
  12769. (define-skeleton verilog-sk-def-reg
  12770. "Insert a reg definition."
  12771. ()
  12772. > "reg [" '(verilog-sk-prompt-width) | -1 verilog-sk-signal ";" \n (verilog-pretty-declarations-auto) )
  12773. (defun verilog-sk-define-signal ()
  12774. "Insert a definition of signal under point at top of module."
  12775. (interactive "*")
  12776. (let* ((sig-re "[a-zA-Z0-9_]*")
  12777. (v1 (buffer-substring
  12778. (save-excursion
  12779. (skip-chars-backward sig-re)
  12780. (point))
  12781. (save-excursion
  12782. (skip-chars-forward sig-re)
  12783. (point)))))
  12784. (if (not (member v1 verilog-keywords))
  12785. (save-excursion
  12786. (setq verilog-sk-signal v1)
  12787. (verilog-beg-of-defun)
  12788. (verilog-end-of-statement)
  12789. (verilog-forward-syntactic-ws)
  12790. (verilog-sk-def-reg)
  12791. (message "signal at point is %s" v1))
  12792. (message "object at point (%s) is a keyword" v1))))
  12793. (define-skeleton verilog-sk-wire
  12794. "Insert a wire definition."
  12795. ()
  12796. > "wire [" '(verilog-sk-datadef))
  12797. (define-skeleton verilog-sk-reg
  12798. "Insert a reg definition."
  12799. ()
  12800. > "reg [" '(verilog-sk-datadef))
  12801. (define-skeleton verilog-sk-assign
  12802. "Insert a skeleton assign statement."
  12803. ()
  12804. > "assign " '(verilog-sk-prompt-name) " = " _ ";" \n)
  12805. (define-skeleton verilog-sk-while
  12806. "Insert a skeleton while loop statement."
  12807. ()
  12808. > "while (" '(verilog-sk-prompt-condition) ") begin" \n
  12809. > _ \n
  12810. > (- verilog-indent-level-behavioral) "end " (progn (electric-verilog-terminate-line) nil))
  12811. (define-skeleton verilog-sk-repeat
  12812. "Insert a skeleton repeat loop statement."
  12813. ()
  12814. > "repeat (" '(verilog-sk-prompt-condition) ") begin" \n
  12815. > _ \n
  12816. > (- verilog-indent-level-behavioral) "end " (progn (electric-verilog-terminate-line) nil))
  12817. (define-skeleton verilog-sk-for
  12818. "Insert a skeleton while loop statement."
  12819. ()
  12820. > "for ("
  12821. '(verilog-sk-prompt-init) "; "
  12822. '(verilog-sk-prompt-condition) "; "
  12823. '(verilog-sk-prompt-inc)
  12824. ") begin" \n
  12825. > _ \n
  12826. > (- verilog-indent-level-behavioral) "end " (progn (electric-verilog-terminate-line) nil))
  12827. (define-skeleton verilog-sk-comment
  12828. "Inserts three comment lines, making a display comment."
  12829. ()
  12830. > "/*\n"
  12831. > "* " _ \n
  12832. > "*/")
  12833. (define-skeleton verilog-sk-state-machine
  12834. "Insert a state machine definition."
  12835. "Name of state variable: "
  12836. '(setq input "state")
  12837. > "// State registers for " str | -23 \n
  12838. '(setq verilog-sk-state str)
  12839. > "reg [" '(verilog-sk-prompt-width) | -1 verilog-sk-state ", next_" verilog-sk-state ?; \n
  12840. '(setq input nil)
  12841. > \n
  12842. > "// State FF for " verilog-sk-state \n
  12843. > "always @ ( " (read-string "clock:" "posedge clk") " or " (verilog-sk-prompt-reset) " ) begin" \n
  12844. > "if ( " verilog-sk-reset " ) " verilog-sk-state " = 0; else" \n
  12845. > verilog-sk-state " = next_" verilog-sk-state ?; \n
  12846. > (- verilog-indent-level-behavioral) "end" (progn (electric-verilog-terminate-line) nil)
  12847. > \n
  12848. > "// Next State Logic for " verilog-sk-state \n
  12849. > "always @ ( /*AUTOSENSE*/ ) begin\n"
  12850. > "case (" '(verilog-sk-prompt-state-selector) ") " \n
  12851. > ("case selector: " str ": begin" \n > "next_" verilog-sk-state " = " _ ";" \n > (- verilog-indent-level-behavioral) "end" \n )
  12852. resume: > (- verilog-case-indent) "endcase" (progn (electric-verilog-terminate-line) nil)
  12853. > (- verilog-indent-level-behavioral) "end" (progn (electric-verilog-terminate-line) nil))
  12854. ;;; Mouse Events:
  12855. ;;
  12856. ;; Include file loading with mouse/return event
  12857. ;;
  12858. ;; idea & first impl.: M. Rouat (eldo-mode.el)
  12859. ;; second (emacs/xemacs) impl.: G. Van der Plas (spice-mode.el)
  12860. (if (featurep 'xemacs)
  12861. (require 'overlay))
  12862. (defconst verilog-include-file-regexp
  12863. "^`include\\s-+\"\\([^\n\"]*\\)\""
  12864. "Regexp that matches the include file.")
  12865. (defvar verilog-mode-mouse-map
  12866. (let ((map (make-sparse-keymap))) ; as described in info pages, make a map
  12867. (set-keymap-parent map verilog-mode-map)
  12868. ;; mouse button bindings
  12869. (define-key map "\r" 'verilog-load-file-at-point)
  12870. (if (featurep 'xemacs)
  12871. (define-key map 'button2 'verilog-load-file-at-mouse);ffap-at-mouse ?
  12872. (define-key map [mouse-2] 'verilog-load-file-at-mouse))
  12873. (if (featurep 'xemacs)
  12874. (define-key map 'Sh-button2 'mouse-yank) ; you wanna paste don't you ?
  12875. (define-key map [S-mouse-2] 'mouse-yank-at-click))
  12876. map)
  12877. "Map containing mouse bindings for `verilog-mode'.")
  12878. (defun verilog-highlight-region (beg end _old-len)
  12879. "Colorize included files and modules in the (changed?) region.
  12880. Clicking on the middle-mouse button loads them in a buffer (as in dired)."
  12881. (when (or verilog-highlight-includes
  12882. verilog-highlight-modules)
  12883. (save-excursion
  12884. (save-match-data ; A query-replace may call this function - do not disturb
  12885. (verilog-save-buffer-state
  12886. (verilog-save-scan-cache
  12887. (let (end-point)
  12888. (goto-char end)
  12889. (setq end-point (point-at-eol))
  12890. (goto-char beg)
  12891. (beginning-of-line) ; scan entire line
  12892. ;; delete overlays existing on this line
  12893. (let ((overlays (overlays-in (point) end-point)))
  12894. (while overlays
  12895. (if (and
  12896. (overlay-get (car overlays) 'detachable)
  12897. (or (overlay-get (car overlays) 'verilog-include-file)
  12898. (overlay-get (car overlays) 'verilog-inst-module)))
  12899. (delete-overlay (car overlays)))
  12900. (setq overlays (cdr overlays))))
  12901. ;;
  12902. ;; make new include overlays
  12903. (when verilog-highlight-includes
  12904. (while (search-forward-regexp verilog-include-file-regexp end-point t)
  12905. (goto-char (match-beginning 1))
  12906. (let ((ov (make-overlay (match-beginning 1) (match-end 1))))
  12907. (overlay-put ov 'start-closed 't)
  12908. (overlay-put ov 'end-closed 't)
  12909. (overlay-put ov 'evaporate 't)
  12910. (overlay-put ov 'verilog-include-file 't)
  12911. (overlay-put ov 'mouse-face 'highlight)
  12912. (overlay-put ov 'local-map verilog-mode-mouse-map))))
  12913. ;;
  12914. ;; make new module overlays
  12915. (goto-char beg)
  12916. ;; This scanner is syntax-fragile, so don't get bent
  12917. (when verilog-highlight-modules
  12918. (condition-case nil
  12919. (while (verilog-re-search-forward-quick "\\(/\\*AUTOINST\\*/\\|\\.\\*\\)" end-point t)
  12920. (save-excursion
  12921. (goto-char (match-beginning 0))
  12922. (unless (verilog-inside-comment-or-string-p)
  12923. (verilog-read-inst-module-matcher) ; sets match 0
  12924. (let* ((ov (make-overlay (match-beginning 0) (match-end 0))))
  12925. (overlay-put ov 'start-closed 't)
  12926. (overlay-put ov 'end-closed 't)
  12927. (overlay-put ov 'evaporate 't)
  12928. (overlay-put ov 'verilog-inst-module 't)
  12929. (overlay-put ov 'mouse-face 'highlight)
  12930. (overlay-put ov 'local-map verilog-mode-mouse-map)))))
  12931. (error nil)))
  12932. ;;
  12933. ;; Future highlights:
  12934. ;; variables - make an Occur buffer of where referenced
  12935. ;; pins - make an Occur buffer of the sig in the declaration module
  12936. )))))))
  12937. (defun verilog-highlight-buffer ()
  12938. "Colorize included files and modules across the whole buffer."
  12939. ;; Invoked via verilog-mode calling font-lock then `font-lock-mode-hook'
  12940. (interactive)
  12941. ;; delete and remake overlays
  12942. (verilog-highlight-region (point-min) (point-max) nil))
  12943. ;; Deprecated, but was interactive, so we'll keep it around
  12944. (defalias 'verilog-colorize-include-files-buffer 'verilog-highlight-buffer)
  12945. ;; ffap-at-mouse isn't useful for Verilog mode. It uses library paths.
  12946. ;; so define this function to do more or less the same as ffap-at-mouse
  12947. ;; but first resolve filename...
  12948. (defun verilog-load-file-at-mouse (event)
  12949. "Load file under button 2 click's EVENT.
  12950. Files are checked based on `verilog-library-flags'."
  12951. (interactive "@e")
  12952. (save-excursion ; implement a Verilog specific ffap-at-mouse
  12953. (mouse-set-point event)
  12954. (verilog-load-file-at-point t)))
  12955. ;; ffap isn't usable for Verilog mode. It uses library paths.
  12956. ;; so define this function to do more or less the same as ffap
  12957. ;; but first resolve filename...
  12958. (defun verilog-load-file-at-point (&optional warn)
  12959. "Load file under point.
  12960. If WARN, throw warning if not found.
  12961. Files are checked based on `verilog-library-flags'."
  12962. (interactive)
  12963. (save-excursion ; implement a Verilog specific ffap
  12964. (let ((overlays (overlays-in (point) (point)))
  12965. hit)
  12966. (while (and overlays (not hit))
  12967. (when (overlay-get (car overlays) 'verilog-inst-module)
  12968. (verilog-goto-defun-file (buffer-substring
  12969. (overlay-start (car overlays))
  12970. (overlay-end (car overlays))))
  12971. (setq hit t))
  12972. (setq overlays (cdr overlays)))
  12973. ;; Include?
  12974. (beginning-of-line)
  12975. (when (and (not hit)
  12976. (looking-at verilog-include-file-regexp))
  12977. (if (and (car (verilog-library-filenames
  12978. (match-string 1) (buffer-file-name)))
  12979. (file-readable-p (car (verilog-library-filenames
  12980. (match-string 1) (buffer-file-name)))))
  12981. (find-file (car (verilog-library-filenames
  12982. (match-string 1) (buffer-file-name))))
  12983. (when warn
  12984. (message
  12985. "File `%s' isn't readable, use shift-mouse2 to paste in this field"
  12986. (match-string 1))))))))
  12987. ;;; Bug reporting:
  12988. ;;
  12989. (defun verilog-faq ()
  12990. "Tell the user their current version, and where to get the FAQ etc."
  12991. (interactive)
  12992. (with-output-to-temp-buffer "*verilog-mode help*"
  12993. (princ (format "You are using verilog-mode %s\n" verilog-mode-version))
  12994. (princ "\n")
  12995. (princ "For new releases, see http://www.verilog.com\n")
  12996. (princ "\n")
  12997. (princ "For frequently asked questions, see http://www.veripool.org/verilog-mode-faq.html\n")
  12998. (princ "\n")
  12999. (princ "To submit a bug, use M-x verilog-submit-bug-report\n")
  13000. (princ "\n")))
  13001. (autoload 'reporter-submit-bug-report "reporter")
  13002. (defvar reporter-prompt-for-summary-p)
  13003. (defun verilog-submit-bug-report ()
  13004. "Submit via mail a bug report on verilog-mode.el."
  13005. (interactive)
  13006. (let ((reporter-prompt-for-summary-p t))
  13007. (reporter-submit-bug-report
  13008. "mac@verilog.com, wsnyder@wsnyder.org"
  13009. (concat "verilog-mode v" verilog-mode-version)
  13010. '(
  13011. verilog-active-low-regexp
  13012. verilog-after-save-font-hook
  13013. verilog-align-ifelse
  13014. verilog-assignment-delay
  13015. verilog-auto-arg-sort
  13016. verilog-auto-declare-nettype
  13017. verilog-auto-delete-trailing-whitespace
  13018. verilog-auto-endcomments
  13019. verilog-auto-hook
  13020. verilog-auto-ignore-concat
  13021. verilog-auto-indent-on-newline
  13022. verilog-auto-inout-ignore-regexp
  13023. verilog-auto-input-ignore-regexp
  13024. verilog-auto-inst-column
  13025. verilog-auto-inst-dot-name
  13026. verilog-auto-inst-interfaced-ports
  13027. verilog-auto-inst-param-value
  13028. verilog-auto-inst-sort
  13029. verilog-auto-inst-template-numbers
  13030. verilog-auto-inst-vector
  13031. verilog-auto-lineup
  13032. verilog-auto-newline
  13033. verilog-auto-output-ignore-regexp
  13034. verilog-auto-read-includes
  13035. verilog-auto-reset-blocking-in-non
  13036. verilog-auto-reset-widths
  13037. verilog-auto-save-policy
  13038. verilog-auto-sense-defines-constant
  13039. verilog-auto-sense-include-inputs
  13040. verilog-auto-star-expand
  13041. verilog-auto-star-save
  13042. verilog-auto-template-warn-unused
  13043. verilog-auto-tieoff-declaration
  13044. verilog-auto-tieoff-ignore-regexp
  13045. verilog-auto-unused-ignore-regexp
  13046. verilog-auto-wire-type
  13047. verilog-before-auto-hook
  13048. verilog-before-delete-auto-hook
  13049. verilog-before-getopt-flags-hook
  13050. verilog-before-save-font-hook
  13051. verilog-cache-enabled
  13052. verilog-case-fold
  13053. verilog-case-indent
  13054. verilog-cexp-indent
  13055. verilog-compiler
  13056. verilog-coverage
  13057. verilog-delete-auto-hook
  13058. verilog-getopt-flags-hook
  13059. verilog-highlight-grouping-keywords
  13060. verilog-highlight-includes
  13061. verilog-highlight-modules
  13062. verilog-highlight-p1800-keywords
  13063. verilog-highlight-translate-off
  13064. verilog-indent-begin-after-if
  13065. verilog-indent-declaration-macros
  13066. verilog-indent-level
  13067. verilog-indent-level-behavioral
  13068. verilog-indent-level-declaration
  13069. verilog-indent-level-directive
  13070. verilog-indent-level-module
  13071. verilog-indent-lists
  13072. verilog-library-directories
  13073. verilog-library-extensions
  13074. verilog-library-files
  13075. verilog-library-flags
  13076. verilog-linter
  13077. verilog-minimum-comment-distance
  13078. verilog-mode-hook
  13079. verilog-mode-release-emacs
  13080. verilog-mode-version
  13081. verilog-preprocessor
  13082. verilog-simulator
  13083. verilog-tab-always-indent
  13084. verilog-tab-to-comment
  13085. verilog-typedef-regexp
  13086. verilog-warn-fatal
  13087. )
  13088. nil nil
  13089. (concat "Hi Mac,
  13090. I want to report a bug.
  13091. Before I go further, I want to say that Verilog mode has changed my life.
  13092. I save so much time, my files are colored nicely, my co workers respect
  13093. my coding ability... until now. I'd really appreciate anything you
  13094. could do to help me out with this minor deficiency in the product.
  13095. I've taken a look at the Verilog-Mode FAQ at
  13096. http://www.veripool.org/verilog-mode-faq.html.
  13097. And, I've considered filing the bug on the issue tracker at
  13098. http://www.veripool.org/verilog-mode-bugs
  13099. since I realize that public bugs are easier for you to track,
  13100. and for others to search, but would prefer to email.
  13101. So, to reproduce the bug, start a fresh Emacs via " invocation-name "
  13102. -no-init-file -no-site-file'. In a new buffer, in Verilog mode, type
  13103. the code included below.
  13104. Given those lines, I expected [[Fill in here]] to happen;
  13105. but instead, [[Fill in here]] happens!.
  13106. == The code: =="))))
  13107. (provide 'verilog-mode)
  13108. ;; Local Variables:
  13109. ;; checkdoc-permit-comma-termination-flag:t
  13110. ;; checkdoc-force-docstrings-flag:nil
  13111. ;; indent-tabs-mode:nil
  13112. ;; End:
  13113. ;;; verilog-mode.el ends here