verilog-mode.el 469 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010
  1. ;; verilog-mode.el --- major mode for editing verilog source in Emacs
  2. ;; Copyright (C) 1996-2012 Free Software Foundation, Inc.
  3. ;; Author: Michael McNamara (mac@verilog.com),
  4. ;; Wilson Snyder (wsnyder@wsnyder.org)
  5. ;; Please see our web sites:
  6. ;; http://www.verilog.com
  7. ;; http://www.veripool.org
  8. ;;
  9. ;; Keywords: languages
  10. ;; Yoni Rabkin <yoni@rabkins.net> contacted the maintainer of this
  11. ;; file on 19/3/2008, and the maintainer agreed that when a bug is
  12. ;; filed in the Emacs bug reporting system against this file, a copy
  13. ;; of the bug report be sent to the maintainer's email address.
  14. ;; This code supports Emacs 21.1 and later
  15. ;; And XEmacs 21.1 and later
  16. ;; Please do not make changes that break Emacs 21. Thanks!
  17. ;;
  18. ;;
  19. ;; This file is part of GNU Emacs.
  20. ;; GNU Emacs is free software: you can redistribute it and/or modify
  21. ;; it under the terms of the GNU General Public License as published by
  22. ;; the Free Software Foundation, either version 3 of the License, or
  23. ;; (at your option) any later version.
  24. ;; GNU Emacs is distributed in the hope that it will be useful,
  25. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  26. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  27. ;; GNU General Public License for more details.
  28. ;; You should have received a copy of the GNU General Public License
  29. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  30. ;;; Commentary:
  31. ;; This mode borrows heavily from the Pascal-mode and the cc-mode of Emacs
  32. ;; USAGE
  33. ;; =====
  34. ;; A major mode for editing Verilog HDL source code. When you have
  35. ;; entered Verilog mode, you may get more info by pressing C-h m. You
  36. ;; may also get online help describing various functions by: C-h f
  37. ;; <Name of function you want described>
  38. ;; KNOWN BUGS / BUG REPORTS
  39. ;; =======================
  40. ;; Verilog is a rapidly evolving language, and hence this mode is
  41. ;; under continuous development. Hence this is beta code, and likely
  42. ;; has bugs. Please report any issues to the issue tracker at
  43. ;; http://www.veripool.org/verilog-mode
  44. ;; Please use verilog-submit-bug-report to submit a report; type C-c
  45. ;; C-b to invoke this and as a result I will have a much easier time
  46. ;; of reproducing the bug you find, and hence fixing it.
  47. ;; INSTALLING THE MODE
  48. ;; ===================
  49. ;; An older version of this mode may be already installed as a part of
  50. ;; your environment, and one method of updating would be to update
  51. ;; your Emacs environment. Sometimes this is difficult for local
  52. ;; political/control reasons, and hence you can always install a
  53. ;; private copy (or even a shared copy) which overrides the system
  54. ;; default.
  55. ;; You can get step by step help in installing this file by going to
  56. ;; <http://www.verilog.com/emacs_install.html>
  57. ;; The short list of installation instructions are: To set up
  58. ;; automatic Verilog mode, put this file in your load path, and put
  59. ;; the following in code (please un comment it first!) in your
  60. ;; .emacs, or in your site's site-load.el
  61. ; (autoload 'verilog-mode "verilog-mode" "Verilog mode" t )
  62. ; (add-to-list 'auto-mode-alist '("\\.[ds]?vh?\\'" . verilog-mode))
  63. ;; Be sure to examine at the help for verilog-auto, and the other
  64. ;; verilog-auto-* functions for some major coding time savers.
  65. ;;
  66. ;; If you want to customize Verilog mode to fit your needs better,
  67. ;; you may add the below lines (the values of the variables presented
  68. ;; here are the defaults). Note also that if you use an Emacs that
  69. ;; supports custom, it's probably better to use the custom menu to
  70. ;; edit these. If working as a member of a large team these settings
  71. ;; should be common across all users (in a site-start file), or set
  72. ;; in Local Variables in every file. Otherwise, different people's
  73. ;; AUTO expansion may result different whitespace changes.
  74. ;;
  75. ; ;; Enable syntax highlighting of **all** languages
  76. ; (global-font-lock-mode t)
  77. ;
  78. ; ;; User customization for Verilog mode
  79. ; (setq verilog-indent-level 3
  80. ; verilog-indent-level-module 3
  81. ; verilog-indent-level-declaration 3
  82. ; verilog-indent-level-behavioral 3
  83. ; verilog-indent-level-directive 1
  84. ; verilog-case-indent 2
  85. ; verilog-auto-newline t
  86. ; verilog-auto-indent-on-newline t
  87. ; verilog-tab-always-indent t
  88. ; verilog-auto-endcomments t
  89. ; verilog-minimum-comment-distance 40
  90. ; verilog-indent-begin-after-if t
  91. ; verilog-auto-lineup 'declarations
  92. ; verilog-highlight-p1800-keywords nil
  93. ; verilog-linter "my_lint_shell_command"
  94. ; )
  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. ;; This variable will always hold the version number of the mode
  102. (defconst verilog-mode-version "725"
  103. "Version of this Verilog mode.")
  104. (defconst verilog-mode-release-date "2011-11-27-GNU"
  105. "Release date of this Verilog mode.")
  106. (defconst verilog-mode-release-emacs t
  107. "If non-nil, this version of Verilog mode was released with Emacs itself.")
  108. (defun verilog-version ()
  109. "Inform caller of the version of this file."
  110. (interactive)
  111. (message "Using verilog-mode version %s" verilog-mode-version))
  112. ;; Insure we have certain packages, and deal with it if we don't
  113. ;; Be sure to note which Emacs flavor and version added each feature.
  114. (eval-when-compile
  115. ;; Provide stuff if we are XEmacs
  116. (when (featurep 'xemacs)
  117. (condition-case nil
  118. (require 'easymenu)
  119. (error nil))
  120. (condition-case nil
  121. (require 'regexp-opt)
  122. (error nil))
  123. ;; Bug in 19.28 through 19.30 skeleton.el, not provided.
  124. (condition-case nil
  125. (load "skeleton")
  126. (error nil))
  127. (condition-case nil
  128. (if (fboundp 'when)
  129. nil ;; fab
  130. (defmacro when (cond &rest body)
  131. (list 'if cond (cons 'progn body))))
  132. (error nil))
  133. (condition-case nil
  134. (if (fboundp 'unless)
  135. nil ;; fab
  136. (defmacro unless (cond &rest body)
  137. (cons 'if (cons cond (cons nil body)))))
  138. (error nil))
  139. (condition-case nil
  140. (if (fboundp 'store-match-data)
  141. nil ;; fab
  142. (defmacro store-match-data (&rest args) nil))
  143. (error nil))
  144. (condition-case nil
  145. (if (fboundp 'char-before)
  146. nil ;; great
  147. (defmacro char-before (&rest body)
  148. (char-after (1- (point)))))
  149. (error nil))
  150. (condition-case nil
  151. (if (fboundp 'when)
  152. nil ;; fab
  153. (defsubst point-at-bol (&optional N)
  154. (save-excursion (beginning-of-line N) (point))))
  155. (error nil))
  156. (condition-case nil
  157. (if (fboundp 'when)
  158. nil ;; fab
  159. (defsubst point-at-eol (&optional N)
  160. (save-excursion (end-of-line N) (point))))
  161. (error nil))
  162. (condition-case nil
  163. (require 'custom)
  164. (error nil))
  165. (condition-case nil
  166. (if (fboundp 'match-string-no-properties)
  167. nil ;; great
  168. (defsubst match-string-no-properties (num &optional string)
  169. "Return string of text matched by last search, without text properties.
  170. NUM specifies which parenthesized expression in the last regexp.
  171. Value is nil if NUMth pair didn't match, or there were less than NUM pairs.
  172. Zero means the entire text matched by the whole regexp or whole string.
  173. STRING should be given if the last search was by `string-match' on STRING."
  174. (if (match-beginning num)
  175. (if string
  176. (let ((result
  177. (substring string
  178. (match-beginning num) (match-end num))))
  179. (set-text-properties 0 (length result) nil result)
  180. result)
  181. (buffer-substring-no-properties (match-beginning num)
  182. (match-end num)
  183. (current-buffer)))))
  184. )
  185. (error nil))
  186. (if (and (featurep 'custom) (fboundp 'custom-declare-variable))
  187. nil ;; We've got what we needed
  188. ;; We have the old custom-library, hack around it!
  189. (defmacro defgroup (&rest args) nil)
  190. (defmacro customize (&rest args)
  191. (message
  192. "Sorry, Customize is not available with this version of Emacs"))
  193. (defmacro defcustom (var value doc &rest args)
  194. `(defvar ,var ,value ,doc))
  195. )
  196. (if (fboundp 'defface)
  197. nil ; great!
  198. (defmacro defface (var values doc &rest args)
  199. `(make-face ,var))
  200. )
  201. (if (and (featurep 'custom) (fboundp 'customize-group))
  202. nil ;; We've got what we needed
  203. ;; We have an intermediate custom-library, hack around it!
  204. (defmacro customize-group (var &rest args)
  205. `(customize ,var))
  206. )
  207. (unless (boundp 'inhibit-point-motion-hooks)
  208. (defvar inhibit-point-motion-hooks nil))
  209. (unless (boundp 'deactivate-mark)
  210. (defvar deactivate-mark nil))
  211. )
  212. ;;
  213. ;; OK, do this stuff if we are NOT XEmacs:
  214. (unless (featurep 'xemacs)
  215. (unless (fboundp 'region-active-p)
  216. (defmacro region-active-p ()
  217. `(and transient-mark-mode mark-active))))
  218. )
  219. ;; Provide a regular expression optimization routine, using regexp-opt
  220. ;; if provided by the user's elisp libraries
  221. (eval-and-compile
  222. ;; The below were disabled when GNU Emacs 22 was released;
  223. ;; perhaps some still need to be there to support Emacs 21.
  224. (if (featurep 'xemacs)
  225. (if (fboundp 'regexp-opt)
  226. ;; regexp-opt is defined, does it take 3 or 2 arguments?
  227. (if (fboundp 'function-max-args)
  228. (let ((args (function-max-args `regexp-opt)))
  229. (cond
  230. ((eq args 3) ;; It takes 3
  231. (condition-case nil ; Hide this defun from emacses
  232. ;with just a two input regexp
  233. (defun verilog-regexp-opt (a b)
  234. "Deal with differing number of required arguments for `regexp-opt'.
  235. Call 'regexp-opt' on A and B."
  236. (regexp-opt a b 't))
  237. (error nil))
  238. )
  239. ((eq args 2) ;; It takes 2
  240. (defun verilog-regexp-opt (a b)
  241. "Call 'regexp-opt' on A and B."
  242. (regexp-opt a b))
  243. )
  244. (t nil)))
  245. ;; We can't tell; assume it takes 2
  246. (defun verilog-regexp-opt (a b)
  247. "Call 'regexp-opt' on A and B."
  248. (regexp-opt a b))
  249. )
  250. ;; There is no regexp-opt, provide our own
  251. (defun verilog-regexp-opt (strings &optional paren shy)
  252. (let ((open (if paren "\\(" "")) (close (if paren "\\)" "")))
  253. (concat open (mapconcat 'regexp-quote strings "\\|") close)))
  254. )
  255. ;; Emacs.
  256. (defalias 'verilog-regexp-opt 'regexp-opt)))
  257. (eval-and-compile
  258. ;; Both xemacs and emacs
  259. (condition-case nil
  260. (require 'diff) ;; diff-command and diff-switches
  261. (error nil))
  262. (condition-case nil
  263. (require 'compile) ;; compilation-error-regexp-alist-alist
  264. (error nil))
  265. (condition-case nil
  266. (unless (fboundp 'buffer-chars-modified-tick) ;; Emacs 22 added
  267. (defmacro buffer-chars-modified-tick () (buffer-modified-tick)))
  268. (error nil))
  269. ;; Added in Emacs 24.1
  270. (condition-case nil
  271. (unless (fboundp 'prog-mode)
  272. (define-derived-mode prog-mode fundamental-mode "Prog"))
  273. (error nil)))
  274. (eval-when-compile
  275. (defun verilog-regexp-words (a)
  276. "Call 'regexp-opt' with word delimiters for the words A."
  277. (concat "\\<" (verilog-regexp-opt a t) "\\>")))
  278. (defun verilog-regexp-words (a)
  279. "Call 'regexp-opt' with word delimiters for the words A."
  280. ;; The FAQ references this function, so user LISP sometimes calls it
  281. (concat "\\<" (verilog-regexp-opt a t) "\\>"))
  282. (defun verilog-easy-menu-filter (menu)
  283. "Filter `easy-menu-define' MENU to support new features."
  284. (cond ((not (featurep 'xemacs))
  285. menu) ;; GNU Emacs - passthru
  286. ;; XEmacs doesn't support :help. Strip it.
  287. ;; Recursively filter the a submenu
  288. ((listp menu)
  289. (mapcar 'verilog-easy-menu-filter menu))
  290. ;; Look for [:help "blah"] and remove
  291. ((vectorp menu)
  292. (let ((i 0) (out []))
  293. (while (< i (length menu))
  294. (if (equal `:help (aref menu i))
  295. (setq i (+ 2 i))
  296. (setq out (vconcat out (vector (aref menu i)))
  297. i (1+ i))))
  298. out))
  299. (t menu))) ;; Default - ok
  300. ;;(verilog-easy-menu-filter
  301. ;; `("Verilog" ("MA" ["SAA" nil :help "Help SAA"] ["SAB" nil :help "Help SAA"])
  302. ;; "----" ["MB" nil :help "Help MB"]))
  303. (defun verilog-define-abbrev (table name expansion &optional hook)
  304. "Filter `define-abbrev' TABLE NAME EXPANSION and call HOOK.
  305. Provides SYSTEM-FLAG in newer Emacs."
  306. (condition-case nil
  307. (define-abbrev table name expansion hook 0 t)
  308. (error
  309. (define-abbrev table name expansion hook))))
  310. (defun verilog-customize ()
  311. "Customize variables and other settings used by Verilog-Mode."
  312. (interactive)
  313. (customize-group 'verilog-mode))
  314. (defun verilog-font-customize ()
  315. "Customize fonts used by Verilog-Mode."
  316. (interactive)
  317. (if (fboundp 'customize-apropos)
  318. (customize-apropos "font-lock-*" 'faces)))
  319. (defun verilog-booleanp (value)
  320. "Return t if VALUE is boolean.
  321. This implements GNU Emacs 22.1's `booleanp' function in earlier Emacs.
  322. This function may be removed when Emacs 21 is no longer supported."
  323. (or (equal value t) (equal value nil)))
  324. (defun verilog-insert-last-command-event ()
  325. "Insert the `last-command-event'."
  326. (insert (if (featurep 'xemacs)
  327. ;; XEmacs 21.5 doesn't like last-command-event
  328. last-command-char
  329. ;; And GNU Emacs 22 has obsoleted last-command-char
  330. last-command-event)))
  331. (defvar verilog-no-change-functions nil
  332. "True if `after-change-functions' is disabled.
  333. Use of `syntax-ppss' may break, as ppss's cache may get corrupted.")
  334. (defvar verilog-in-hooks nil
  335. "True when within a `verilog-run-hooks' block.")
  336. (defmacro verilog-run-hooks (&rest hooks)
  337. "Run each hook in HOOKS using `run-hooks'.
  338. Set `verilog-in-hooks' during this time, to assist AUTO caches."
  339. `(let ((verilog-in-hooks t))
  340. (run-hooks ,@hooks)))
  341. (defun verilog-syntax-ppss (&optional pos)
  342. (when verilog-no-change-functions
  343. (if verilog-in-hooks
  344. (verilog-scan-cache-flush)
  345. ;; else don't let the AUTO code itself get away with flushing the cache,
  346. ;; as that'll make things very slow
  347. (backtrace)
  348. (error "%s: Internal problem; use of syntax-ppss when cache may be corrupt"
  349. (verilog-point-text))))
  350. (if (fboundp 'syntax-ppss)
  351. (syntax-ppss pos)
  352. (parse-partial-sexp (point-min) (or pos (point)))))
  353. (defgroup verilog-mode nil
  354. "Facilitates easy editing of Verilog source text."
  355. :version "22.2"
  356. :group 'languages)
  357. ; (defgroup verilog-mode-fonts nil
  358. ; "Facilitates easy customization fonts used in Verilog source text"
  359. ; :link '(customize-apropos "font-lock-*" 'faces)
  360. ; :group 'verilog-mode)
  361. (defgroup verilog-mode-indent nil
  362. "Customize indentation and highlighting of Verilog source text."
  363. :group 'verilog-mode)
  364. (defgroup verilog-mode-actions nil
  365. "Customize actions on Verilog source text."
  366. :group 'verilog-mode)
  367. (defgroup verilog-mode-auto nil
  368. "Customize AUTO actions when expanding Verilog source text."
  369. :group 'verilog-mode)
  370. (defvar verilog-debug nil
  371. "If set, enable debug messages for `verilog-mode' internals.")
  372. (defcustom verilog-linter
  373. "echo 'No verilog-linter set, see \"M-x describe-variable verilog-linter\"'"
  374. "*Unix program and arguments to call to run a lint checker on Verilog source.
  375. Depending on the `verilog-set-compile-command', this may be invoked when
  376. you type \\[compile]. When the compile completes, \\[next-error] will take
  377. you to the next lint error."
  378. :type 'string
  379. :group 'verilog-mode-actions)
  380. ;; We don't mark it safe, as it's used as a shell command
  381. (defcustom verilog-coverage
  382. "echo 'No verilog-coverage set, see \"M-x describe-variable verilog-coverage\"'"
  383. "*Program and arguments to use to annotate for coverage Verilog source.
  384. Depending on the `verilog-set-compile-command', this may be invoked when
  385. you type \\[compile]. When the compile completes, \\[next-error] will take
  386. you to the next lint error."
  387. :type 'string
  388. :group 'verilog-mode-actions)
  389. ;; We don't mark it safe, as it's used as a shell command
  390. (defcustom verilog-simulator
  391. "echo 'No verilog-simulator set, see \"M-x describe-variable verilog-simulator\"'"
  392. "*Program and arguments to use to interpret Verilog source.
  393. Depending on the `verilog-set-compile-command', this may be invoked when
  394. you type \\[compile]. When the compile completes, \\[next-error] will take
  395. you to the next lint error."
  396. :type 'string
  397. :group 'verilog-mode-actions)
  398. ;; We don't mark it safe, as it's used as a shell command
  399. (defcustom verilog-compiler
  400. "echo 'No verilog-compiler set, see \"M-x describe-variable verilog-compiler\"'"
  401. "*Program and arguments to use to compile Verilog source.
  402. Depending on the `verilog-set-compile-command', this may be invoked when
  403. you type \\[compile]. When the compile completes, \\[next-error] will take
  404. you to the next lint error."
  405. :type 'string
  406. :group 'verilog-mode-actions)
  407. ;; We don't mark it safe, as it's used as a shell command
  408. (defcustom verilog-preprocessor
  409. ;; Very few tools give preprocessed output, so we'll default to Verilog-Perl
  410. "vppreproc __FLAGS__ __FILE__"
  411. "*Program and arguments to use to preprocess Verilog source.
  412. This is invoked with `verilog-preprocess', and depending on the
  413. `verilog-set-compile-command', may also be invoked when you type
  414. \\[compile]. When the compile completes, \\[next-error] will
  415. take you to the next lint error."
  416. :type 'string
  417. :group 'verilog-mode-actions)
  418. ;; We don't mark it safe, as it's used as a shell command
  419. (defvar verilog-preprocess-history nil
  420. "History for `verilog-preprocess'.")
  421. (defvar verilog-tool 'verilog-linter
  422. "Which tool to use for building compiler-command.
  423. Either nil, `verilog-linter, `verilog-compiler,
  424. `verilog-coverage, `verilog-preprocessor, or `verilog-simulator.
  425. Alternatively use the \"Choose Compilation Action\" menu. See
  426. `verilog-set-compile-command' for more information.")
  427. (defcustom verilog-highlight-translate-off nil
  428. "*Non-nil means background-highlight code excluded from translation.
  429. That is, all code between \"// synopsys translate_off\" and
  430. \"// synopsys translate_on\" is highlighted using a different background color
  431. \(face `verilog-font-lock-translate-off-face').
  432. Note: This will slow down on-the-fly fontification (and thus editing).
  433. Note: Activate the new setting in a Verilog buffer by re-fontifying it (menu
  434. entry \"Fontify Buffer\"). XEmacs: turn off and on font locking."
  435. :type 'boolean
  436. :group 'verilog-mode-indent)
  437. ;; Note we don't use :safe, as that would break on Emacsen before 22.0.
  438. (put 'verilog-highlight-translate-off 'safe-local-variable 'verilog-booleanp)
  439. (defcustom verilog-auto-lineup 'declarations
  440. "*Type of statements to lineup across multiple lines.
  441. If 'all' is selected, then all line ups described below are done.
  442. If 'declaration', then just declarations are lined up with any
  443. preceding declarations, taking into account widths and the like,
  444. so or example the code:
  445. reg [31:0] a;
  446. reg b;
  447. would become
  448. reg [31:0] a;
  449. reg b;
  450. If 'assignment', then assignments are lined up with any preceding
  451. assignments, so for example the code
  452. a_long_variable <= b + c;
  453. d = e + f;
  454. would become
  455. a_long_variable <= b + c;
  456. d = e + f;
  457. In order to speed up editing, large blocks of statements are lined up
  458. only when a \\[verilog-pretty-expr] is typed; and large blocks of declarations
  459. are lineup only when \\[verilog-pretty-declarations] is typed."
  460. :type '(radio (const :tag "Line up Assignments and Declarations" all)
  461. (const :tag "Line up Assignment statements" assignments )
  462. (const :tag "Line up Declarations" declarations)
  463. (function :tag "Other"))
  464. :group 'verilog-mode-indent )
  465. (defcustom verilog-indent-level 3
  466. "*Indentation of Verilog statements with respect to containing block."
  467. :group 'verilog-mode-indent
  468. :type 'integer)
  469. (put 'verilog-indent-level 'safe-local-variable 'integerp)
  470. (defcustom verilog-indent-level-module 3
  471. "*Indentation of Module level Verilog statements (eg always, initial).
  472. Set to 0 to get initial and always statements lined up on the left side of
  473. your screen."
  474. :group 'verilog-mode-indent
  475. :type 'integer)
  476. (put 'verilog-indent-level-module 'safe-local-variable 'integerp)
  477. (defcustom verilog-indent-level-declaration 3
  478. "*Indentation of declarations with respect to containing block.
  479. Set to 0 to get them list right under containing block."
  480. :group 'verilog-mode-indent
  481. :type 'integer)
  482. (put 'verilog-indent-level-declaration 'safe-local-variable 'integerp)
  483. (defcustom verilog-indent-declaration-macros nil
  484. "*How to treat macro expansions in a declaration.
  485. If nil, indent as:
  486. input [31:0] a;
  487. input `CP;
  488. output c;
  489. If non nil, treat as:
  490. input [31:0] a;
  491. input `CP ;
  492. output c;"
  493. :group 'verilog-mode-indent
  494. :type 'boolean)
  495. (put 'verilog-indent-declaration-macros 'safe-local-variable 'verilog-booleanp)
  496. (defcustom verilog-indent-lists t
  497. "*How to treat indenting items in a list.
  498. If t (the default), indent as:
  499. always @( posedge a or
  500. reset ) begin
  501. If nil, treat as:
  502. always @( posedge a or
  503. reset ) begin"
  504. :group 'verilog-mode-indent
  505. :type 'boolean)
  506. (put 'verilog-indent-lists 'safe-local-variable 'verilog-booleanp)
  507. (defcustom verilog-indent-level-behavioral 3
  508. "*Absolute indentation of first begin in a task or function block.
  509. Set to 0 to get such code to start at the left side of the screen."
  510. :group 'verilog-mode-indent
  511. :type 'integer)
  512. (put 'verilog-indent-level-behavioral 'safe-local-variable 'integerp)
  513. (defcustom verilog-indent-level-directive 1
  514. "*Indentation to add to each level of `ifdef declarations.
  515. Set to 0 to have all directives start at the left side of the screen."
  516. :group 'verilog-mode-indent
  517. :type 'integer)
  518. (put 'verilog-indent-level-directive 'safe-local-variable 'integerp)
  519. (defcustom verilog-cexp-indent 2
  520. "*Indentation of Verilog statements split across lines."
  521. :group 'verilog-mode-indent
  522. :type 'integer)
  523. (put 'verilog-cexp-indent 'safe-local-variable 'integerp)
  524. (defcustom verilog-case-indent 2
  525. "*Indentation for case statements."
  526. :group 'verilog-mode-indent
  527. :type 'integer)
  528. (put 'verilog-case-indent 'safe-local-variable 'integerp)
  529. (defcustom verilog-auto-newline t
  530. "*True means automatically newline after semicolons."
  531. :group 'verilog-mode-indent
  532. :type 'boolean)
  533. (put 'verilog-auto-newline 'safe-local-variable 'verilog-booleanp)
  534. (defcustom verilog-auto-indent-on-newline t
  535. "*True means automatically indent line after newline."
  536. :group 'verilog-mode-indent
  537. :type 'boolean)
  538. (put 'verilog-auto-indent-on-newline 'safe-local-variable 'verilog-booleanp)
  539. (defcustom verilog-tab-always-indent t
  540. "*True means TAB should always re-indent the current line.
  541. A nil value means TAB will only reindent when at the beginning of the line."
  542. :group 'verilog-mode-indent
  543. :type 'boolean)
  544. (put 'verilog-tab-always-indent 'safe-local-variable 'verilog-booleanp)
  545. (defcustom verilog-tab-to-comment nil
  546. "*True means TAB moves to the right hand column in preparation for a comment."
  547. :group 'verilog-mode-actions
  548. :type 'boolean)
  549. (put 'verilog-tab-to-comment 'safe-local-variable 'verilog-booleanp)
  550. (defcustom verilog-indent-begin-after-if t
  551. "*If true, indent begin statements following if, else, while, for and repeat.
  552. Otherwise, line them up."
  553. :group 'verilog-mode-indent
  554. :type 'boolean)
  555. (put 'verilog-indent-begin-after-if 'safe-local-variable 'verilog-booleanp)
  556. (defcustom verilog-align-ifelse nil
  557. "*If true, align `else' under matching `if'.
  558. Otherwise else is lined up with first character on line holding matching if."
  559. :group 'verilog-mode-indent
  560. :type 'boolean)
  561. (put 'verilog-align-ifelse 'safe-local-variable 'verilog-booleanp)
  562. (defcustom verilog-minimum-comment-distance 10
  563. "*Minimum distance (in lines) between begin and end required before a comment.
  564. Setting this variable to zero results in every end acquiring a comment; the
  565. default avoids too many redundant comments in tight quarters."
  566. :group 'verilog-mode-indent
  567. :type 'integer)
  568. (put 'verilog-minimum-comment-distance 'safe-local-variable 'integerp)
  569. (defcustom verilog-highlight-p1800-keywords nil
  570. "*True means highlight words newly reserved by IEEE-1800.
  571. These will appear in `verilog-font-lock-p1800-face' in order to gently
  572. suggest changing where these words are used as variables to something else.
  573. A nil value means highlight these words as appropriate for the SystemVerilog
  574. IEEE-1800 standard. Note that changing this will require restarting Emacs
  575. to see the effect as font color choices are cached by Emacs."
  576. :group 'verilog-mode-indent
  577. :type 'boolean)
  578. (put 'verilog-highlight-p1800-keywords 'safe-local-variable 'verilog-booleanp)
  579. (defcustom verilog-highlight-grouping-keywords nil
  580. "*True means highlight grouping keywords 'begin' and 'end' more dramatically.
  581. If false, these words are in the `font-lock-type-face'; if True then they are in
  582. `verilog-font-lock-ams-face'. Some find that special highlighting on these
  583. grouping constructs allow the structure of the code to be understood at a glance."
  584. :group 'verilog-mode-indent
  585. :type 'boolean)
  586. (put 'verilog-highlight-grouping-keywords 'safe-local-variable 'verilog-booleanp)
  587. (defcustom verilog-highlight-modules nil
  588. "*True means highlight module statements for `verilog-load-file-at-point'.
  589. When true, mousing over module names will allow jumping to the
  590. module definition. If false, this is not supported. Setting
  591. this is experimental, and may lead to bad performance."
  592. :group 'verilog-mode-indent
  593. :type 'boolean)
  594. (put 'verilog-highlight-modules 'safe-local-variable 'verilog-booleanp)
  595. (defcustom verilog-highlight-includes t
  596. "*True means highlight module statements for `verilog-load-file-at-point'.
  597. When true, mousing over include file names will allow jumping to the
  598. file referenced. If false, this is not supported."
  599. :group 'verilog-mode-indent
  600. :type 'boolean)
  601. (put 'verilog-highlight-includes 'safe-local-variable 'verilog-booleanp)
  602. (defcustom verilog-auto-declare-nettype nil
  603. "*Non-nil specifies the data type to use with `verilog-auto-input' etc.
  604. Set this to \"wire\" if the Verilog code uses \"`default_nettype
  605. none\". Note using `default_nettype none isn't recommended practice; this
  606. mode is experimental."
  607. :version "24.1"
  608. :group 'verilog-mode-actions
  609. :type 'boolean)
  610. (put 'verilog-auto-declare-nettype 'safe-local-variable `stringp)
  611. (defcustom verilog-auto-wire-type nil
  612. "*Non-nil specifies the data type to use with `verilog-auto-wire' etc.
  613. Set this to \"logic\" for SystemVerilog code, or use `verilog-auto-logic'."
  614. :version "24.1"
  615. :group 'verilog-mode-actions
  616. :type 'boolean)
  617. (put 'verilog-auto-wire-type 'safe-local-variable `stringp)
  618. (defcustom verilog-auto-endcomments t
  619. "*True means insert a comment /* ... */ after 'end's.
  620. The name of the function or case will be set between the braces."
  621. :group 'verilog-mode-actions
  622. :type 'boolean)
  623. (put 'verilog-auto-endcomments 'safe-local-variable 'verilog-booleanp)
  624. (defcustom verilog-auto-delete-trailing-whitespace nil
  625. "*True means to `delete-trailing-whitespace' in `verilog-auto'."
  626. :version "24.1"
  627. :group 'verilog-mode-actions
  628. :type 'boolean)
  629. (put 'verilog-auto-delete-trailing-whitespace 'safe-local-variable 'verilog-booleanp)
  630. (defcustom verilog-auto-ignore-concat nil
  631. "*True means ignore signals in {...} concatenations for AUTOWIRE etc.
  632. This will exclude signals referenced as pin connections in {...}
  633. from AUTOWIRE, AUTOOUTPUT and friends. This flag should be set
  634. for backward compatibility only and not set in new designs; it
  635. may be removed in future versions."
  636. :group 'verilog-mode-actions
  637. :type 'boolean)
  638. (put 'verilog-auto-ignore-concat 'safe-local-variable 'verilog-booleanp)
  639. (defcustom verilog-auto-read-includes nil
  640. "*True means to automatically read includes before AUTOs.
  641. This will do a `verilog-read-defines' and `verilog-read-includes' before
  642. each AUTO expansion. This makes it easier to embed defines and includes,
  643. but can result in very slow reading times if there are many or large
  644. include files."
  645. :group 'verilog-mode-actions
  646. :type 'boolean)
  647. (put 'verilog-auto-read-includes 'safe-local-variable 'verilog-booleanp)
  648. (defcustom verilog-auto-save-policy nil
  649. "*Non-nil indicates action to take when saving a Verilog buffer with AUTOs.
  650. A value of `force' will always do a \\[verilog-auto] automatically if
  651. needed on every save. A value of `detect' will do \\[verilog-auto]
  652. automatically when it thinks necessary. A value of `ask' will query the
  653. user when it thinks updating is needed.
  654. You should not rely on the 'ask or 'detect policies, they are safeguards
  655. only. They do not detect when AUTOINSTs need to be updated because a
  656. sub-module's port list has changed."
  657. :group 'verilog-mode-actions
  658. :type '(choice (const nil) (const ask) (const detect) (const force)))
  659. (defcustom verilog-auto-star-expand t
  660. "*Non-nil indicates to expand a SystemVerilog .* instance ports.
  661. They will be expanded in the same way as if there was a AUTOINST in the
  662. instantiation. See also `verilog-auto-star' and `verilog-auto-star-save'."
  663. :group 'verilog-mode-actions
  664. :type 'boolean)
  665. (put 'verilog-auto-star-expand 'safe-local-variable 'verilog-booleanp)
  666. (defcustom verilog-auto-star-save nil
  667. "*Non-nil indicates to save to disk SystemVerilog .* instance expansions.
  668. A nil value indicates direct connections will be removed before saving.
  669. Only meaningful to those created due to `verilog-auto-star-expand' being set.
  670. Instead of setting this, you may want to use /*AUTOINST*/, which will
  671. always be saved."
  672. :group 'verilog-mode-actions
  673. :type 'boolean)
  674. (put 'verilog-auto-star-save 'safe-local-variable 'verilog-booleanp)
  675. (defvar verilog-auto-update-tick nil
  676. "Modification tick at which autos were last performed.")
  677. (defvar verilog-auto-last-file-locals nil
  678. "Text from file-local-variables during last evaluation.")
  679. (defvar verilog-diff-function 'verilog-diff-report
  680. "*Function to run when `verilog-diff-auto' detects differences.
  681. Function takes three arguments, the original buffer, the
  682. difference buffer, and the point in original buffer with the
  683. first difference.")
  684. ;;; Compile support
  685. (require 'compile)
  686. (defvar verilog-error-regexp-added nil)
  687. (defvar verilog-error-regexp-emacs-alist
  688. '(
  689. (verilog-xl-1
  690. "\\(Error\\|Warning\\)!.*\n?.*\"\\([^\"]+\\)\", \\([0-9]+\\)" 2 3)
  691. (verilog-xl-2
  692. "([WE][0-9A-Z]+)[ \t]+\\([^ \t\n,]+\\)[, \t]+\\(line[ \t]+\\)?\\([0-9]+\\):.*$" 1 3)
  693. (verilog-IES
  694. ".*\\*[WE],[0-9A-Z]+\\(\[[0-9A-Z_,]+\]\\)? (\\([^ \t,]+\\),\\([0-9]+\\)" 2 3)
  695. (verilog-surefire-1
  696. "[^\n]*\\[\\([^:]+\\):\\([0-9]+\\)\\]" 1 2)
  697. (verilog-surefire-2
  698. "\\(WARNING\\|ERROR\\|INFO\\)[^:]*: \\([^,]+\\),\\s-+\\(line \\)?\\([0-9]+\\):" 2 4 )
  699. (verilog-verbose
  700. "\
  701. \\([a-zA-Z]?:?[^:( \t\n]+\\)[:(][ \t]*\\([0-9]+\\)\\([) \t]\\|\
  702. :\\([^0-9\n]\\|\\([0-9]+:\\)\\)\\)" 1 2 5)
  703. (verilog-xsim
  704. "\\(Error\\|Warning\\).*in file (\\([^ \t]+\\) at line *\\([0-9]+\\))" 2 3)
  705. (verilog-vcs-1
  706. "\\(Error\\|Warning\\):[^(]*(\\([^ \t]+\\) line *\\([0-9]+\\))" 2 3)
  707. (verilog-vcs-2
  708. "Warning:.*(port.*(\\([^ \t]+\\) line \\([0-9]+\\))" 1 2)
  709. (verilog-vcs-3
  710. "\\(Error\\|Warning\\):[\n.]*\\([^ \t]+\\) *\\([0-9]+\\):" 2 3)
  711. (verilog-vcs-4
  712. "syntax error:.*\n\\([^ \t]+\\) *\\([0-9]+\\):" 1 2)
  713. (verilog-verilator
  714. "%?\\(Error\\|Warning\\)\\(-[^:]+\\|\\):[\n ]*\\([^ \t:]+\\):\\([0-9]+\\):" 3 4)
  715. (verilog-leda
  716. "^In file \\([^ \t]+\\)[ \t]+line[ \t]+\\([0-9]+\\):\n[^\n]*\n[^\n]*\n\\(Warning\\|Error\\|Failure\\)[^\n]*" 1 2)
  717. )
  718. "List of regexps for Verilog compilers.
  719. See `compilation-error-regexp-alist' for the formatting. For Emacs 22+.")
  720. (defvar verilog-error-regexp-xemacs-alist
  721. ;; Emacs form is '((v-tool "re" 1 2) ...)
  722. ;; XEmacs form is '(verilog ("re" 1 2) ...)
  723. ;; So we can just map from Emacs to XEmacs
  724. (cons 'verilog (mapcar 'cdr verilog-error-regexp-emacs-alist))
  725. "List of regexps for Verilog compilers.
  726. See `compilation-error-regexp-alist-alist' for the formatting. For XEmacs.")
  727. (defvar verilog-error-font-lock-keywords
  728. '(
  729. ;; verilog-xl-1
  730. ("\\(Error\\|Warning\\)!.*\n?.*\"\\([^\"]+\\)\", \\([0-9]+\\)" 2 bold t)
  731. ("\\(Error\\|Warning\\)!.*\n?.*\"\\([^\"]+\\)\", \\([0-9]+\\)" 2 bold t)
  732. ;; verilog-xl-2
  733. ("([WE][0-9A-Z]+)[ \t]+\\([^ \t\n,]+\\)[, \t]+\\(line[ \t]+\\)?\\([0-9]+\\):.*$" 1 bold t)
  734. ("([WE][0-9A-Z]+)[ \t]+\\([^ \t\n,]+\\)[, \t]+\\(line[ \t]+\\)?\\([0-9]+\\):.*$" 3 bold t)
  735. ;; verilog-IES (nc-verilog)
  736. (".*\\*[WE],[0-9A-Z]+\\(\[[0-9A-Z_,]+\]\\)? (\\([^ \t,]+\\),\\([0-9]+\\)|" 2 bold t)
  737. (".*\\*[WE],[0-9A-Z]+\\(\[[0-9A-Z_,]+\]\\)? (\\([^ \t,]+\\),\\([0-9]+\\)|" 3 bold t)
  738. ;; verilog-surefire-1
  739. ("[^\n]*\\[\\([^:]+\\):\\([0-9]+\\)\\]" 1 bold t)
  740. ("[^\n]*\\[\\([^:]+\\):\\([0-9]+\\)\\]" 2 bold t)
  741. ;; verilog-surefire-2
  742. ("\\(WARNING\\|ERROR\\|INFO\\): \\([^,]+\\), line \\([0-9]+\\):" 2 bold t)
  743. ("\\(WARNING\\|ERROR\\|INFO\\): \\([^,]+\\), line \\([0-9]+\\):" 3 bold t)
  744. ;; verilog-verbose
  745. ("\
  746. \\([a-zA-Z]?:?[^:( \t\n]+\\)[:(][ \t]*\\([0-9]+\\)\\([) \t]\\|\
  747. :\\([^0-9\n]\\|\\([0-9]+:\\)\\)\\)" 1 bold t)
  748. ("\
  749. \\([a-zA-Z]?:?[^:( \t\n]+\\)[:(][ \t]*\\([0-9]+\\)\\([) \t]\\|\
  750. :\\([^0-9\n]\\|\\([0-9]+:\\)\\)\\)" 1 bold t)
  751. ;; verilog-vcs-1
  752. ("\\(Error\\|Warning\\):[^(]*(\\([^ \t]+\\) line *\\([0-9]+\\))" 2 bold t)
  753. ("\\(Error\\|Warning\\):[^(]*(\\([^ \t]+\\) line *\\([0-9]+\\))" 3 bold t)
  754. ;; verilog-vcs-2
  755. ("Warning:.*(port.*(\\([^ \t]+\\) line \\([0-9]+\\))" 1 bold t)
  756. ("Warning:.*(port.*(\\([^ \t]+\\) line \\([0-9]+\\))" 1 bold t)
  757. ;; verilog-vcs-3
  758. ("\\(Error\\|Warning\\):[\n.]*\\([^ \t]+\\) *\\([0-9]+\\):" 2 bold t)
  759. ("\\(Error\\|Warning\\):[\n.]*\\([^ \t]+\\) *\\([0-9]+\\):" 3 bold t)
  760. ;; verilog-vcs-4
  761. ("syntax error:.*\n\\([^ \t]+\\) *\\([0-9]+\\):" 1 bold t)
  762. ("syntax error:.*\n\\([^ \t]+\\) *\\([0-9]+\\):" 2 bold t)
  763. ;; verilog-verilator
  764. (".*%?\\(Error\\|Warning\\)\\(-[^:]+\\|\\):[\n ]*\\([^ \t:]+\\):\\([0-9]+\\):" 3 bold t)
  765. (".*%?\\(Error\\|Warning\\)\\(-[^:]+\\|\\):[\n ]*\\([^ \t:]+\\):\\([0-9]+\\):" 4 bold t)
  766. ;; verilog-leda
  767. ("^In file \\([^ \t]+\\)[ \t]+line[ \t]+\\([0-9]+\\):\n[^\n]*\n[^\n]*\n\\(Warning\\|Error\\|Failure\\)[^\n]*" 1 bold t)
  768. ("^In file \\([^ \t]+\\)[ \t]+line[ \t]+\\([0-9]+\\):\n[^\n]*\n[^\n]*\n\\(Warning\\|Error\\|Failure\\)[^\n]*" 2 bold t)
  769. )
  770. "*Keywords to also highlight in Verilog *compilation* buffers.
  771. Only used in XEmacs; GNU Emacs uses `verilog-error-regexp-emacs-alist'.")
  772. (defcustom verilog-library-flags '("")
  773. "*List of standard Verilog arguments to use for /*AUTOINST*/.
  774. These arguments are used to find files for `verilog-auto', and match
  775. the flags accepted by a standard Verilog-XL simulator.
  776. -f filename Reads more `verilog-library-flags' from the filename.
  777. +incdir+dir Adds the directory to `verilog-library-directories'.
  778. -Idir Adds the directory to `verilog-library-directories'.
  779. -y dir Adds the directory to `verilog-library-directories'.
  780. +libext+.v Adds the extensions to `verilog-library-extensions'.
  781. -v filename Adds the filename to `verilog-library-files'.
  782. filename Adds the filename to `verilog-library-files'.
  783. This is not recommended, -v is a better choice.
  784. You might want these defined in each file; put at the *END* of your file
  785. something like:
  786. // Local Variables:
  787. // verilog-library-flags:(\"-y dir -y otherdir\")
  788. // End:
  789. Verilog-mode attempts to detect changes to this local variable, but they
  790. are only insured to be correct when the file is first visited. Thus if you
  791. have problems, use \\[find-alternate-file] RET to have these take effect.
  792. See also the variables mentioned above."
  793. :group 'verilog-mode-auto
  794. :type '(repeat string))
  795. (put 'verilog-library-flags 'safe-local-variable 'listp)
  796. (defcustom verilog-library-directories '(".")
  797. "*List of directories when looking for files for /*AUTOINST*/.
  798. The directory may be relative to the current file, or absolute.
  799. Environment variables are also expanded in the directory names.
  800. Having at least the current directory is a good idea.
  801. You might want these defined in each file; put at the *END* of your file
  802. something like:
  803. // Local Variables:
  804. // verilog-library-directories:(\".\" \"subdir\" \"subdir2\")
  805. // End:
  806. Verilog-mode attempts to detect changes to this local variable, but they
  807. are only insured to be correct when the file is first visited. Thus if you
  808. have problems, use \\[find-alternate-file] RET to have these take effect.
  809. See also `verilog-library-flags', `verilog-library-files'
  810. and `verilog-library-extensions'."
  811. :group 'verilog-mode-auto
  812. :type '(repeat file))
  813. (put 'verilog-library-directories 'safe-local-variable 'listp)
  814. (defcustom verilog-library-files '()
  815. "*List of files to search for modules.
  816. AUTOINST will use this when it needs to resolve a module name.
  817. This is a complete path, usually to a technology file with many standard
  818. cells defined in it.
  819. You might want these defined in each file; put at the *END* of your file
  820. something like:
  821. // Local Variables:
  822. // verilog-library-files:(\"/some/path/technology.v\" \"/some/path/tech2.v\")
  823. // End:
  824. Verilog-mode attempts to detect changes to this local variable, but they
  825. are only insured to be correct when the file is first visited. Thus if you
  826. have problems, use \\[find-alternate-file] RET to have these take effect.
  827. See also `verilog-library-flags', `verilog-library-directories'."
  828. :group 'verilog-mode-auto
  829. :type '(repeat directory))
  830. (put 'verilog-library-files 'safe-local-variable 'listp)
  831. (defcustom verilog-library-extensions '(".v" ".sv")
  832. "*List of extensions to use when looking for files for /*AUTOINST*/.
  833. See also `verilog-library-flags', `verilog-library-directories'."
  834. :type '(repeat string)
  835. :group 'verilog-mode-auto)
  836. (put 'verilog-library-extensions 'safe-local-variable 'listp)
  837. (defcustom verilog-active-low-regexp nil
  838. "*If set, treat signals matching this regexp as active low.
  839. This is used for AUTORESET and AUTOTIEOFF. For proper behavior,
  840. you will probably also need `verilog-auto-reset-widths' set."
  841. :group 'verilog-mode-auto
  842. :type 'string)
  843. (put 'verilog-active-low-regexp 'safe-local-variable 'stringp)
  844. (defcustom verilog-auto-sense-include-inputs nil
  845. "*If true, AUTOSENSE should include all inputs.
  846. If nil, only inputs that are NOT output signals in the same block are
  847. included."
  848. :group 'verilog-mode-auto
  849. :type 'boolean)
  850. (put 'verilog-auto-sense-include-inputs 'safe-local-variable 'verilog-booleanp)
  851. (defcustom verilog-auto-sense-defines-constant nil
  852. "*If true, AUTOSENSE should assume all defines represent constants.
  853. When true, the defines will not be included in sensitivity lists. To
  854. maintain compatibility with other sites, this should be set at the bottom
  855. of each Verilog file that requires it, rather than being set globally."
  856. :group 'verilog-mode-auto
  857. :type 'boolean)
  858. (put 'verilog-auto-sense-defines-constant 'safe-local-variable 'verilog-booleanp)
  859. (defcustom verilog-auto-reset-blocking-in-non t
  860. "*If true, AUTORESET will reset those signals which were
  861. assigned with blocking assignments (=) even in a block with
  862. non-blocking assignments (<=).
  863. If nil, all blocking assigned signals are ignored when any
  864. non-blocking assignment is in the AUTORESET block. This allows
  865. blocking assignments to be used for temporary values and not have
  866. those temporaries reset. See example in `verilog-auto-reset'."
  867. :version "24.1"
  868. :type 'boolean
  869. :group 'verilog-mode-auto)
  870. (put 'verilog-auto-reset-blocking-in-non 'safe-local-variable 'verilog-booleanp)
  871. (defcustom verilog-auto-reset-widths t
  872. "*If true, AUTORESET should determine the width of signals.
  873. This is then used to set the width of the zero (32'h0 for example). This
  874. is required by some lint tools that aren't smart enough to ignore widths of
  875. the constant zero. This may result in ugly code when parameters determine
  876. the MSB or LSB of a signal inside an AUTORESET."
  877. :type 'boolean
  878. :group 'verilog-mode-auto)
  879. (put 'verilog-auto-reset-widths 'safe-local-variable 'verilog-booleanp)
  880. (defcustom verilog-assignment-delay ""
  881. "*Text used for delays in delayed assignments. Add a trailing space if set."
  882. :group 'verilog-mode-auto
  883. :type 'string)
  884. (put 'verilog-assignment-delay 'safe-local-variable 'stringp)
  885. (defcustom verilog-auto-arg-sort nil
  886. "*If set, AUTOARG signal names will be sorted, not in declaration order.
  887. Declaration order is advantageous with order based instantiations
  888. and is the default for backward compatibility. Sorted order
  889. reduces changes when declarations are moved around in a file, and
  890. it's bad practice to rely on order based instantiations anyhow.
  891. See also `verilog-auto-inst-sort'."
  892. :group 'verilog-mode-auto
  893. :type 'boolean)
  894. (put 'verilog-auto-arg-sort 'safe-local-variable 'verilog-booleanp)
  895. (defcustom verilog-auto-inst-dot-name nil
  896. "*If true, when creating ports with AUTOINST, use .name syntax.
  897. This will use \".port\" instead of \".port(port)\" when possible.
  898. This is only legal in SystemVerilog files, and will confuse older
  899. simulators. Setting `verilog-auto-inst-vector' to nil may also
  900. be desirable to increase how often .name will be used."
  901. :group 'verilog-mode-auto
  902. :type 'boolean)
  903. (put 'verilog-auto-inst-dot-name 'safe-local-variable 'verilog-booleanp)
  904. (defcustom verilog-auto-inst-param-value nil
  905. "*If set, AUTOINST will replace parameters with the parameter value.
  906. If nil, leave parameters as symbolic names.
  907. Parameters must be in Verilog 2001 format #(...), and if a parameter is not
  908. listed as such there (as when the default value is acceptable), it will not
  909. be replaced, and will remain symbolic.
  910. For example, imagine a submodule uses parameters to declare the size of its
  911. inputs. This is then used by a upper module:
  912. module InstModule (o,i);
  913. parameter WIDTH;
  914. input [WIDTH-1:0] i;
  915. endmodule
  916. module ExampInst;
  917. InstModule
  918. #(PARAM(10))
  919. instName
  920. (/*AUTOINST*/
  921. .i (i[PARAM-1:0]));
  922. Note even though PARAM=10, the AUTOINST has left the parameter as a
  923. symbolic name. If `verilog-auto-inst-param-value' is set, this will
  924. instead expand to:
  925. module ExampInst;
  926. InstModule
  927. #(PARAM(10))
  928. instName
  929. (/*AUTOINST*/
  930. .i (i[9:0]));"
  931. :group 'verilog-mode-auto
  932. :type 'boolean)
  933. (put 'verilog-auto-inst-param-value 'safe-local-variable 'verilog-booleanp)
  934. (defcustom verilog-auto-inst-sort nil
  935. "*If set, AUTOINST signal names will be sorted, not in declaration order.
  936. Also affects AUTOINSTPARAM. Declaration order is the default for
  937. backward compatibility, and as some teams prefer signals that are
  938. declared together to remain together. Sorted order reduces
  939. changes when declarations are moved around in a file.
  940. See also `verilog-auto-arg-sort'."
  941. :version "24.1"
  942. :group 'verilog-mode-auto
  943. :type 'boolean)
  944. (put 'verilog-auto-inst-sort 'safe-local-variable 'verilog-booleanp)
  945. (defcustom verilog-auto-inst-vector t
  946. "*If true, when creating default ports with AUTOINST, use bus subscripts.
  947. If nil, skip the subscript when it matches the entire bus as declared in
  948. the module (AUTOWIRE signals always are subscripted, you must manually
  949. declare the wire to have the subscripts removed.) Setting this to nil may
  950. speed up some simulators, but is less general and harder to read, so avoid."
  951. :group 'verilog-mode-auto
  952. :type 'boolean)
  953. (put 'verilog-auto-inst-vector 'safe-local-variable 'verilog-booleanp)
  954. (defcustom verilog-auto-inst-template-numbers nil
  955. "*If true, when creating templated ports with AUTOINST, add a comment.
  956. If t, the comment will add the line number of the template that
  957. was used for that port declaration. This setting is suggested
  958. only for debugging use, as regular use may cause a large numbers
  959. of merge conflicts.
  960. If 'lhs', the comment will show the left hand side of the
  961. AUTO_TEMPLATE rule that is matched. This is less precise than
  962. numbering (t) when multiple rules have the same pin name, but
  963. won't merge conflict."
  964. :group 'verilog-mode-auto
  965. :type '(choice (const nil) (const t) (const lhs)))
  966. (put 'verilog-auto-inst-template-numbers 'safe-local-variable
  967. '(lambda (x) (memq x '(nil t lhs))))
  968. (defcustom verilog-auto-inst-column 40
  969. "*Indent-to column number for net name part of AUTOINST created pin."
  970. :group 'verilog-mode-indent
  971. :type 'integer)
  972. (put 'verilog-auto-inst-column 'safe-local-variable 'integerp)
  973. (defcustom verilog-auto-input-ignore-regexp nil
  974. "*If set, when creating AUTOINPUT list, ignore signals matching this regexp.
  975. See the \\[verilog-faq] for examples on using this."
  976. :group 'verilog-mode-auto
  977. :type 'string)
  978. (put 'verilog-auto-input-ignore-regexp 'safe-local-variable 'stringp)
  979. (defcustom verilog-auto-inout-ignore-regexp nil
  980. "*If set, when creating AUTOINOUT list, ignore signals matching this regexp.
  981. See the \\[verilog-faq] for examples on using this."
  982. :group 'verilog-mode-auto
  983. :type 'string)
  984. (put 'verilog-auto-inout-ignore-regexp 'safe-local-variable 'stringp)
  985. (defcustom verilog-auto-output-ignore-regexp nil
  986. "*If set, when creating AUTOOUTPUT list, ignore signals matching this regexp.
  987. See the \\[verilog-faq] for examples on using this."
  988. :group 'verilog-mode-auto
  989. :type 'string)
  990. (put 'verilog-auto-output-ignore-regexp 'safe-local-variable 'stringp)
  991. (defcustom verilog-auto-tieoff-declaration "wire"
  992. "*Data type used for the declaration for AUTOTIEOFF. If \"wire\" then
  993. create a wire, if \"assign\" create an assignment, else the data type for
  994. variable creation."
  995. :version "24.1"
  996. :group 'verilog-mode-auto
  997. :type 'string)
  998. (put 'verilog-auto-tieoff-declaration 'safe-local-variable 'stringp)
  999. (defcustom verilog-auto-tieoff-ignore-regexp nil
  1000. "*If set, when creating AUTOTIEOFF list, ignore signals matching this regexp.
  1001. See the \\[verilog-faq] for examples on using this."
  1002. :group 'verilog-mode-auto
  1003. :type 'string)
  1004. (put 'verilog-auto-tieoff-ignore-regexp 'safe-local-variable 'stringp)
  1005. (defcustom verilog-auto-unused-ignore-regexp nil
  1006. "*If set, when creating AUTOUNUSED list, ignore signals matching this regexp.
  1007. See the \\[verilog-faq] for examples on using this."
  1008. :group 'verilog-mode-auto
  1009. :type 'string)
  1010. (put 'verilog-auto-unused-ignore-regexp 'safe-local-variable 'stringp)
  1011. (defcustom verilog-typedef-regexp nil
  1012. "*If non-nil, regular expression that matches Verilog-2001 typedef names.
  1013. For example, \"_t$\" matches typedefs named with _t, as in the C language."
  1014. :group 'verilog-mode-auto
  1015. :type 'string)
  1016. (put 'verilog-typedef-regexp 'safe-local-variable 'stringp)
  1017. (defcustom verilog-mode-hook 'verilog-set-compile-command
  1018. "*Hook run after Verilog mode is loaded."
  1019. :type 'hook
  1020. :group 'verilog-mode)
  1021. (defcustom verilog-auto-hook nil
  1022. "*Hook run after `verilog-mode' updates AUTOs."
  1023. :group 'verilog-mode-auto
  1024. :type 'hook)
  1025. (defcustom verilog-before-auto-hook nil
  1026. "*Hook run before `verilog-mode' updates AUTOs."
  1027. :group 'verilog-mode-auto
  1028. :type 'hook)
  1029. (defcustom verilog-delete-auto-hook nil
  1030. "*Hook run after `verilog-mode' deletes AUTOs."
  1031. :group 'verilog-mode-auto
  1032. :type 'hook)
  1033. (defcustom verilog-before-delete-auto-hook nil
  1034. "*Hook run before `verilog-mode' deletes AUTOs."
  1035. :group 'verilog-mode-auto
  1036. :type 'hook)
  1037. (defcustom verilog-getopt-flags-hook nil
  1038. "*Hook run after `verilog-getopt-flags' determines the Verilog option lists."
  1039. :group 'verilog-mode-auto
  1040. :type 'hook)
  1041. (defcustom verilog-before-getopt-flags-hook nil
  1042. "*Hook run before `verilog-getopt-flags' determines the Verilog option lists."
  1043. :group 'verilog-mode-auto
  1044. :type 'hook)
  1045. (defvar verilog-imenu-generic-expression
  1046. '((nil "^\\s-*\\(\\(m\\(odule\\|acromodule\\)\\)\\|primitive\\)\\s-+\\([a-zA-Z0-9_.:]+\\)" 4)
  1047. ("*Vars*" "^\\s-*\\(reg\\|wire\\)\\s-+\\(\\|\\[[^]]+\\]\\s-+\\)\\([A-Za-z0-9_]+\\)" 3))
  1048. "Imenu expression for Verilog mode. See `imenu-generic-expression'.")
  1049. ;;
  1050. ;; provide a verilog-header function.
  1051. ;; Customization variables:
  1052. ;;
  1053. (defvar verilog-date-scientific-format nil
  1054. "*If non-nil, dates are written in scientific format (e.g. 1997/09/17).
  1055. If nil, in European format (e.g. 17.09.1997). The brain-dead American
  1056. format (e.g. 09/17/1997) is not supported.")
  1057. (defvar verilog-company nil
  1058. "*Default name of Company for Verilog header.
  1059. If set will become buffer local.")
  1060. (make-variable-buffer-local 'verilog-company)
  1061. (defvar verilog-project nil
  1062. "*Default name of Project for Verilog header.
  1063. If set will become buffer local.")
  1064. (make-variable-buffer-local 'verilog-project)
  1065. (defvar verilog-mode-map
  1066. (let ((map (make-sparse-keymap)))
  1067. (define-key map ";" 'electric-verilog-semi)
  1068. (define-key map [(control 59)] 'electric-verilog-semi-with-comment)
  1069. (define-key map ":" 'electric-verilog-colon)
  1070. ;;(define-key map "=" 'electric-verilog-equal)
  1071. (define-key map "\`" 'electric-verilog-tick)
  1072. (define-key map "\t" 'electric-verilog-tab)
  1073. (define-key map "\r" 'electric-verilog-terminate-line)
  1074. ;; backspace/delete key bindings
  1075. (define-key map [backspace] 'backward-delete-char-untabify)
  1076. (unless (boundp 'delete-key-deletes-forward) ; XEmacs variable
  1077. (define-key map [delete] 'delete-char)
  1078. (define-key map [(meta delete)] 'kill-word))
  1079. (define-key map "\M-\C-b" 'electric-verilog-backward-sexp)
  1080. (define-key map "\M-\C-f" 'electric-verilog-forward-sexp)
  1081. (define-key map "\M-\r" `electric-verilog-terminate-and-indent)
  1082. (define-key map "\M-\t" 'verilog-complete-word)
  1083. (define-key map "\M-?" 'verilog-show-completions)
  1084. ;; Note \C-c and letter are reserved for users
  1085. (define-key map "\C-c\`" 'verilog-lint-off)
  1086. (define-key map "\C-c\*" 'verilog-delete-auto-star-implicit)
  1087. (define-key map "\C-c\?" 'verilog-diff-auto)
  1088. (define-key map "\C-c\C-r" 'verilog-label-be)
  1089. (define-key map "\C-c\C-i" 'verilog-pretty-declarations)
  1090. (define-key map "\C-c=" 'verilog-pretty-expr)
  1091. (define-key map "\C-c\C-b" 'verilog-submit-bug-report)
  1092. (define-key map "\M-*" 'verilog-star-comment)
  1093. (define-key map "\C-c\C-c" 'verilog-comment-region)
  1094. (define-key map "\C-c\C-u" 'verilog-uncomment-region)
  1095. (when (featurep 'xemacs)
  1096. (define-key map [(meta control h)] 'verilog-mark-defun)
  1097. (define-key map "\M-\C-a" 'verilog-beg-of-defun)
  1098. (define-key map "\M-\C-e" 'verilog-end-of-defun))
  1099. (define-key map "\C-c\C-d" 'verilog-goto-defun)
  1100. (define-key map "\C-c\C-k" 'verilog-delete-auto)
  1101. (define-key map "\C-c\C-a" 'verilog-auto)
  1102. (define-key map "\C-c\C-s" 'verilog-auto-save-compile)
  1103. (define-key map "\C-c\C-p" 'verilog-preprocess)
  1104. (define-key map "\C-c\C-z" 'verilog-inject-auto)
  1105. (define-key map "\C-c\C-e" 'verilog-expand-vector)
  1106. (define-key map "\C-c\C-h" 'verilog-header)
  1107. map)
  1108. "Keymap used in Verilog mode.")
  1109. ;; menus
  1110. (easy-menu-define
  1111. verilog-menu verilog-mode-map "Menu for Verilog mode"
  1112. (verilog-easy-menu-filter
  1113. '("Verilog"
  1114. ("Choose Compilation Action"
  1115. ["None"
  1116. (progn
  1117. (setq verilog-tool nil)
  1118. (verilog-set-compile-command))
  1119. :style radio
  1120. :selected (equal verilog-tool nil)
  1121. :help "When invoking compilation, use compile-command"]
  1122. ["Lint"
  1123. (progn
  1124. (setq verilog-tool 'verilog-linter)
  1125. (verilog-set-compile-command))
  1126. :style radio
  1127. :selected (equal verilog-tool `verilog-linter)
  1128. :help "When invoking compilation, use lint checker"]
  1129. ["Coverage"
  1130. (progn
  1131. (setq verilog-tool 'verilog-coverage)
  1132. (verilog-set-compile-command))
  1133. :style radio
  1134. :selected (equal verilog-tool `verilog-coverage)
  1135. :help "When invoking compilation, annotate for coverage"]
  1136. ["Simulator"
  1137. (progn
  1138. (setq verilog-tool 'verilog-simulator)
  1139. (verilog-set-compile-command))
  1140. :style radio
  1141. :selected (equal verilog-tool `verilog-simulator)
  1142. :help "When invoking compilation, interpret Verilog source"]
  1143. ["Compiler"
  1144. (progn
  1145. (setq verilog-tool 'verilog-compiler)
  1146. (verilog-set-compile-command))
  1147. :style radio
  1148. :selected (equal verilog-tool `verilog-compiler)
  1149. :help "When invoking compilation, compile Verilog source"]
  1150. ["Preprocessor"
  1151. (progn
  1152. (setq verilog-tool 'verilog-preprocessor)
  1153. (verilog-set-compile-command))
  1154. :style radio
  1155. :selected (equal verilog-tool `verilog-preprocessor)
  1156. :help "When invoking compilation, preprocess Verilog source, see also `verilog-preprocess'"]
  1157. )
  1158. ("Move"
  1159. ["Beginning of function" verilog-beg-of-defun
  1160. :keys "C-M-a"
  1161. :help "Move backward to the beginning of the current function or procedure"]
  1162. ["End of function" verilog-end-of-defun
  1163. :keys "C-M-e"
  1164. :help "Move forward to the end of the current function or procedure"]
  1165. ["Mark function" verilog-mark-defun
  1166. :keys "C-M-h"
  1167. :help "Mark the current Verilog function or procedure"]
  1168. ["Goto function/module" verilog-goto-defun
  1169. :help "Move to specified Verilog module/task/function"]
  1170. ["Move to beginning of block" electric-verilog-backward-sexp
  1171. :help "Move backward over one balanced expression"]
  1172. ["Move to end of block" electric-verilog-forward-sexp
  1173. :help "Move forward over one balanced expression"]
  1174. )
  1175. ("Comments"
  1176. ["Comment Region" verilog-comment-region
  1177. :help "Put marked area into a comment"]
  1178. ["UnComment Region" verilog-uncomment-region
  1179. :help "Uncomment an area commented with Comment Region"]
  1180. ["Multi-line comment insert" verilog-star-comment
  1181. :help "Insert Verilog /* */ comment at point"]
  1182. ["Lint error to comment" verilog-lint-off
  1183. :help "Convert a Verilog linter warning line into a disable statement"]
  1184. )
  1185. "----"
  1186. ["Compile" compile
  1187. :help "Perform compilation-action (above) on the current buffer"]
  1188. ["AUTO, Save, Compile" verilog-auto-save-compile
  1189. :help "Recompute AUTOs, save buffer, and compile"]
  1190. ["Next Compile Error" next-error
  1191. :help "Visit next compilation error message and corresponding source code"]
  1192. ["Ignore Lint Warning at point" verilog-lint-off
  1193. :help "Convert a Verilog linter warning line into a disable statement"]
  1194. "----"
  1195. ["Line up declarations around point" verilog-pretty-declarations
  1196. :help "Line up declarations around point"]
  1197. ["Line up equations around point" verilog-pretty-expr
  1198. :help "Line up expressions around point"]
  1199. ["Redo/insert comments on every end" verilog-label-be
  1200. :help "Label matching begin ... end statements"]
  1201. ["Expand [x:y] vector line" verilog-expand-vector
  1202. :help "Take a signal vector on the current line and expand it to multiple lines"]
  1203. ["Insert begin-end block" verilog-insert-block
  1204. :help "Insert begin ... end"]
  1205. ["Complete word" verilog-complete-word
  1206. :help "Complete word at point"]
  1207. "----"
  1208. ["Recompute AUTOs" verilog-auto
  1209. :help "Expand AUTO meta-comment statements"]
  1210. ["Kill AUTOs" verilog-delete-auto
  1211. :help "Remove AUTO expansions"]
  1212. ["Diff AUTOs" verilog-diff-auto
  1213. :help "Show differences in AUTO expansions"]
  1214. ["Inject AUTOs" verilog-inject-auto
  1215. :help "Inject AUTOs into legacy non-AUTO buffer"]
  1216. ("AUTO Help..."
  1217. ["AUTO General" (describe-function 'verilog-auto)
  1218. :help "Help introduction on AUTOs"]
  1219. ["AUTO Library Flags" (describe-variable 'verilog-library-flags)
  1220. :help "Help on verilog-library-flags"]
  1221. ["AUTO Library Path" (describe-variable 'verilog-library-directories)
  1222. :help "Help on verilog-library-directories"]
  1223. ["AUTO Library Files" (describe-variable 'verilog-library-files)
  1224. :help "Help on verilog-library-files"]
  1225. ["AUTO Library Extensions" (describe-variable 'verilog-library-extensions)
  1226. :help "Help on verilog-library-extensions"]
  1227. ["AUTO `define Reading" (describe-function 'verilog-read-defines)
  1228. :help "Help on reading `defines"]
  1229. ["AUTO `include Reading" (describe-function 'verilog-read-includes)
  1230. :help "Help on parsing `includes"]
  1231. ["AUTOARG" (describe-function 'verilog-auto-arg)
  1232. :help "Help on AUTOARG - declaring module port list"]
  1233. ["AUTOASCIIENUM" (describe-function 'verilog-auto-ascii-enum)
  1234. :help "Help on AUTOASCIIENUM - creating ASCII for enumerations"]
  1235. ["AUTOINOUTCOMP" (describe-function 'verilog-auto-inout-comp)
  1236. :help "Help on AUTOINOUTCOMP - copying complemented i/o from another file"]
  1237. ["AUTOINOUTIN" (describe-function 'verilog-auto-inout-in)
  1238. :help "Help on AUTOINOUTCOMP - copying i/o from another file as all inputs"]
  1239. ["AUTOINOUTMODULE" (describe-function 'verilog-auto-inout-module)
  1240. :help "Help on AUTOINOUTMODULE - copying i/o from another file"]
  1241. ["AUTOINSERTLISP" (describe-function 'verilog-auto-insert-lisp)
  1242. :help "Help on AUTOINSERTLISP - insert text from a lisp function"]
  1243. ["AUTOINOUT" (describe-function 'verilog-auto-inout)
  1244. :help "Help on AUTOINOUT - adding inouts from cells"]
  1245. ["AUTOINPUT" (describe-function 'verilog-auto-input)
  1246. :help "Help on AUTOINPUT - adding inputs from cells"]
  1247. ["AUTOINST" (describe-function 'verilog-auto-inst)
  1248. :help "Help on AUTOINST - adding pins for cells"]
  1249. ["AUTOINST (.*)" (describe-function 'verilog-auto-star)
  1250. :help "Help on expanding Verilog-2001 .* pins"]
  1251. ["AUTOINSTPARAM" (describe-function 'verilog-auto-inst-param)
  1252. :help "Help on AUTOINSTPARAM - adding parameter pins to cells"]
  1253. ["AUTOLOGIC" (describe-function 'verilog-auto-logic)
  1254. :help "Help on AUTOLOGIC - declaring logic signals"]
  1255. ["AUTOOUTPUT" (describe-function 'verilog-auto-output)
  1256. :help "Help on AUTOOUTPUT - adding outputs from cells"]
  1257. ["AUTOOUTPUTEVERY" (describe-function 'verilog-auto-output-every)
  1258. :help "Help on AUTOOUTPUTEVERY - adding outputs of all signals"]
  1259. ["AUTOREG" (describe-function 'verilog-auto-reg)
  1260. :help "Help on AUTOREG - declaring registers for non-wires"]
  1261. ["AUTOREGINPUT" (describe-function 'verilog-auto-reg-input)
  1262. :help "Help on AUTOREGINPUT - declaring inputs for non-wires"]
  1263. ["AUTORESET" (describe-function 'verilog-auto-reset)
  1264. :help "Help on AUTORESET - resetting always blocks"]
  1265. ["AUTOSENSE" (describe-function 'verilog-auto-sense)
  1266. :help "Help on AUTOSENSE - sensitivity lists for always blocks"]
  1267. ["AUTOTIEOFF" (describe-function 'verilog-auto-tieoff)
  1268. :help "Help on AUTOTIEOFF - tying off unused outputs"]
  1269. ["AUTOUNUSED" (describe-function 'verilog-auto-unused)
  1270. :help "Help on AUTOUNUSED - terminating unused inputs"]
  1271. ["AUTOWIRE" (describe-function 'verilog-auto-wire)
  1272. :help "Help on AUTOWIRE - declaring wires for cells"]
  1273. )
  1274. "----"
  1275. ["Submit bug report" verilog-submit-bug-report
  1276. :help "Submit via mail a bug report on verilog-mode.el"]
  1277. ["Version and FAQ" verilog-faq
  1278. :help "Show the current version, and where to get the FAQ etc"]
  1279. ["Customize Verilog Mode..." verilog-customize
  1280. :help "Customize variables and other settings used by Verilog-Mode"]
  1281. ["Customize Verilog Fonts & Colors" verilog-font-customize
  1282. :help "Customize fonts used by Verilog-Mode."])))
  1283. (easy-menu-define
  1284. verilog-stmt-menu verilog-mode-map "Menu for statement templates in Verilog."
  1285. (verilog-easy-menu-filter
  1286. '("Statements"
  1287. ["Header" verilog-sk-header
  1288. :help "Insert a header block at the top of file"]
  1289. ["Comment" verilog-sk-comment
  1290. :help "Insert a comment block"]
  1291. "----"
  1292. ["Module" verilog-sk-module
  1293. :help "Insert a module .. (/*AUTOARG*/);.. endmodule block"]
  1294. ["OVM Class" verilog-sk-ovm-class
  1295. :help "Insert an OVM class block"]
  1296. ["UVM Class" verilog-sk-uvm-class
  1297. :help "Insert an UVM class block"]
  1298. ["Primitive" verilog-sk-primitive
  1299. :help "Insert a primitive .. (.. );.. endprimitive block"]
  1300. "----"
  1301. ["Input" verilog-sk-input
  1302. :help "Insert an input declaration"]
  1303. ["Output" verilog-sk-output
  1304. :help "Insert an output declaration"]
  1305. ["Inout" verilog-sk-inout
  1306. :help "Insert an inout declaration"]
  1307. ["Wire" verilog-sk-wire
  1308. :help "Insert a wire declaration"]
  1309. ["Reg" verilog-sk-reg
  1310. :help "Insert a register declaration"]
  1311. ["Define thing under point as a register" verilog-sk-define-signal
  1312. :help "Define signal under point as a register at the top of the module"]
  1313. "----"
  1314. ["Initial" verilog-sk-initial
  1315. :help "Insert an initial begin .. end block"]
  1316. ["Always" verilog-sk-always
  1317. :help "Insert an always @(AS) begin .. end block"]
  1318. ["Function" verilog-sk-function
  1319. :help "Insert a function .. begin .. end endfunction block"]
  1320. ["Task" verilog-sk-task
  1321. :help "Insert a task .. begin .. end endtask block"]
  1322. ["Specify" verilog-sk-specify
  1323. :help "Insert a specify .. endspecify block"]
  1324. ["Generate" verilog-sk-generate
  1325. :help "Insert a generate .. endgenerate block"]
  1326. "----"
  1327. ["Begin" verilog-sk-begin
  1328. :help "Insert a begin .. end block"]
  1329. ["If" verilog-sk-if
  1330. :help "Insert an if (..) begin .. end block"]
  1331. ["(if) else" verilog-sk-else-if
  1332. :help "Insert an else if (..) begin .. end block"]
  1333. ["For" verilog-sk-for
  1334. :help "Insert a for (...) begin .. end block"]
  1335. ["While" verilog-sk-while
  1336. :help "Insert a while (...) begin .. end block"]
  1337. ["Fork" verilog-sk-fork
  1338. :help "Insert a fork begin .. end .. join block"]
  1339. ["Repeat" verilog-sk-repeat
  1340. :help "Insert a repeat (..) begin .. end block"]
  1341. ["Case" verilog-sk-case
  1342. :help "Insert a case block, prompting for details"]
  1343. ["Casex" verilog-sk-casex
  1344. :help "Insert a casex (...) item: begin.. end endcase block"]
  1345. ["Casez" verilog-sk-casez
  1346. :help "Insert a casez (...) item: begin.. end endcase block"])))
  1347. (defvar verilog-mode-abbrev-table nil
  1348. "Abbrev table in use in Verilog-mode buffers.")
  1349. (define-abbrev-table 'verilog-mode-abbrev-table ())
  1350. (verilog-define-abbrev verilog-mode-abbrev-table "class" "" 'verilog-sk-ovm-class)
  1351. (verilog-define-abbrev verilog-mode-abbrev-table "always" "" 'verilog-sk-always)
  1352. (verilog-define-abbrev verilog-mode-abbrev-table "begin" nil `verilog-sk-begin)
  1353. (verilog-define-abbrev verilog-mode-abbrev-table "case" "" `verilog-sk-case)
  1354. (verilog-define-abbrev verilog-mode-abbrev-table "for" "" `verilog-sk-for)
  1355. (verilog-define-abbrev verilog-mode-abbrev-table "generate" "" `verilog-sk-generate)
  1356. (verilog-define-abbrev verilog-mode-abbrev-table "initial" "" `verilog-sk-initial)
  1357. (verilog-define-abbrev verilog-mode-abbrev-table "fork" "" `verilog-sk-fork)
  1358. (verilog-define-abbrev verilog-mode-abbrev-table "module" "" `verilog-sk-module)
  1359. (verilog-define-abbrev verilog-mode-abbrev-table "primitive" "" `verilog-sk-primitive)
  1360. (verilog-define-abbrev verilog-mode-abbrev-table "repeat" "" `verilog-sk-repeat)
  1361. (verilog-define-abbrev verilog-mode-abbrev-table "specify" "" `verilog-sk-specify)
  1362. (verilog-define-abbrev verilog-mode-abbrev-table "task" "" `verilog-sk-task)
  1363. (verilog-define-abbrev verilog-mode-abbrev-table "while" "" `verilog-sk-while)
  1364. (verilog-define-abbrev verilog-mode-abbrev-table "casex" "" `verilog-sk-casex)
  1365. (verilog-define-abbrev verilog-mode-abbrev-table "casez" "" `verilog-sk-casez)
  1366. (verilog-define-abbrev verilog-mode-abbrev-table "if" "" `verilog-sk-if)
  1367. (verilog-define-abbrev verilog-mode-abbrev-table "else if" "" `verilog-sk-else-if)
  1368. (verilog-define-abbrev verilog-mode-abbrev-table "assign" "" `verilog-sk-assign)
  1369. (verilog-define-abbrev verilog-mode-abbrev-table "function" "" `verilog-sk-function)
  1370. (verilog-define-abbrev verilog-mode-abbrev-table "input" "" `verilog-sk-input)
  1371. (verilog-define-abbrev verilog-mode-abbrev-table "output" "" `verilog-sk-output)
  1372. (verilog-define-abbrev verilog-mode-abbrev-table "inout" "" `verilog-sk-inout)
  1373. (verilog-define-abbrev verilog-mode-abbrev-table "wire" "" `verilog-sk-wire)
  1374. (verilog-define-abbrev verilog-mode-abbrev-table "reg" "" `verilog-sk-reg)
  1375. ;;
  1376. ;; Macros
  1377. ;;
  1378. (defsubst verilog-within-string ()
  1379. (nth 3 (parse-partial-sexp (point-at-bol) (point))))
  1380. (defsubst verilog-string-replace-matches (from-string to-string fixedcase literal string)
  1381. "Replace occurrences of FROM-STRING with TO-STRING.
  1382. FIXEDCASE and LITERAL as in `replace-match`. STRING is what to replace.
  1383. The case (verilog-string-replace-matches \"o\" \"oo\" nil nil \"foobar\")
  1384. will break, as the o's continuously replace. xa -> x works ok though."
  1385. ;; Hopefully soon to a emacs built-in
  1386. ;; Also note \ in the replacement prevent multiple replacements; IE
  1387. ;; (verilog-string-replace-matches "@" "\\\\([0-9]+\\\\)" nil nil "wire@_@")
  1388. ;; Gives "wire\([0-9]+\)_@" not "wire\([0-9]+\)_\([0-9]+\)"
  1389. (let ((start 0))
  1390. (while (string-match from-string string start)
  1391. (setq string (replace-match to-string fixedcase literal string)
  1392. start (min (length string) (+ (match-beginning 0) (length to-string)))))
  1393. string))
  1394. (defsubst verilog-string-remove-spaces (string)
  1395. "Remove spaces surrounding STRING."
  1396. (save-match-data
  1397. (setq string (verilog-string-replace-matches "^\\s-+" "" nil nil string))
  1398. (setq string (verilog-string-replace-matches "\\s-+$" "" nil nil string))
  1399. string))
  1400. (defsubst verilog-re-search-forward (REGEXP BOUND NOERROR)
  1401. ; checkdoc-params: (REGEXP BOUND NOERROR)
  1402. "Like `re-search-forward', but skips over match in comments or strings."
  1403. (let ((mdata '(nil nil))) ;; So match-end will return nil if no matches found
  1404. (while (and
  1405. (re-search-forward REGEXP BOUND NOERROR)
  1406. (setq mdata (match-data))
  1407. (and (verilog-skip-forward-comment-or-string)
  1408. (progn
  1409. (setq mdata '(nil nil))
  1410. (if BOUND
  1411. (< (point) BOUND)
  1412. t)))))
  1413. (store-match-data mdata)
  1414. (match-end 0)))
  1415. (defsubst verilog-re-search-backward (REGEXP BOUND NOERROR)
  1416. ; checkdoc-params: (REGEXP BOUND NOERROR)
  1417. "Like `re-search-backward', but skips over match in comments or strings."
  1418. (let ((mdata '(nil nil))) ;; So match-end will return nil if no matches found
  1419. (while (and
  1420. (re-search-backward REGEXP BOUND NOERROR)
  1421. (setq mdata (match-data))
  1422. (and (verilog-skip-backward-comment-or-string)
  1423. (progn
  1424. (setq mdata '(nil nil))
  1425. (if BOUND
  1426. (> (point) BOUND)
  1427. t)))))
  1428. (store-match-data mdata)
  1429. (match-end 0)))
  1430. (defsubst verilog-re-search-forward-quick (regexp bound noerror)
  1431. "Like `verilog-re-search-forward', including use of REGEXP BOUND and NOERROR,
  1432. but trashes match data and is faster for REGEXP that doesn't match often.
  1433. This uses `verilog-scan' and text properties to ignore comments,
  1434. so there may be a large up front penalty for the first search."
  1435. (let (pt)
  1436. (while (and (not pt)
  1437. (re-search-forward regexp bound noerror))
  1438. (if (verilog-inside-comment-or-string-p)
  1439. (re-search-forward "[/\"\n]" nil t) ;; Only way a comment or quote can end
  1440. (setq pt (match-end 0))))
  1441. pt))
  1442. (defsubst verilog-re-search-backward-quick (regexp bound noerror)
  1443. ; checkdoc-params: (REGEXP BOUND NOERROR)
  1444. "Like `verilog-re-search-backward', including use of REGEXP BOUND and NOERROR,
  1445. but trashes match data and is faster for REGEXP that doesn't match often.
  1446. This uses `verilog-scan' and text properties to ignore comments,
  1447. so there may be a large up front penalty for the first search."
  1448. (let (pt)
  1449. (while (and (not pt)
  1450. (re-search-backward regexp bound noerror))
  1451. (if (verilog-inside-comment-or-string-p)
  1452. (re-search-backward "[/\"]" nil t) ;; Only way a comment or quote can begin
  1453. (setq pt (match-beginning 0))))
  1454. pt))
  1455. (defsubst verilog-re-search-forward-substr (substr regexp bound noerror)
  1456. "Like `re-search-forward', but first search for SUBSTR constant.
  1457. Then searched for the normal REGEXP (which contains SUBSTR), with given
  1458. BOUND and NOERROR. The REGEXP must fit within a single line.
  1459. This speeds up complicated regexp matches."
  1460. ;; Problem with overlap: search-forward BAR then FOOBARBAZ won't match.
  1461. ;; thus require matches to be on one line, and use beginning-of-line.
  1462. (let (done)
  1463. (while (and (not done)
  1464. (search-forward substr bound noerror))
  1465. (save-excursion
  1466. (beginning-of-line)
  1467. (setq done (re-search-forward regexp (point-at-eol) noerror)))
  1468. (unless (and (<= (match-beginning 0) (point))
  1469. (>= (match-end 0) (point)))
  1470. (setq done nil)))
  1471. (when done (goto-char done))
  1472. done))
  1473. ;;(verilog-re-search-forward-substr "-end" "get-end-of" nil t) ;;-end (test bait)
  1474. (defsubst verilog-re-search-backward-substr (substr regexp bound noerror)
  1475. "Like `re-search-backward', but first search for SUBSTR constant.
  1476. Then searched for the normal REGEXP (which contains SUBSTR), with given
  1477. BOUND and NOERROR. The REGEXP must fit within a single line.
  1478. This speeds up complicated regexp matches."
  1479. ;; Problem with overlap: search-backward BAR then FOOBARBAZ won't match.
  1480. ;; thus require matches to be on one line, and use beginning-of-line.
  1481. (let (done)
  1482. (while (and (not done)
  1483. (search-backward substr bound noerror))
  1484. (save-excursion
  1485. (end-of-line)
  1486. (setq done (re-search-backward regexp (point-at-bol) noerror)))
  1487. (unless (and (<= (match-beginning 0) (point))
  1488. (>= (match-end 0) (point)))
  1489. (setq done nil)))
  1490. (when done (goto-char done))
  1491. done))
  1492. ;;(verilog-re-search-backward-substr "-end" "get-end-of" nil t) ;;-end (test bait)
  1493. (defun verilog-delete-trailing-whitespace ()
  1494. "Delete trailing spaces or tabs, but not newlines nor linefeeds."
  1495. ;; Similar to `delete-trailing-whitespace' but that's not present in XEmacs
  1496. (save-excursion
  1497. (goto-char (point-min))
  1498. (while (re-search-forward "[ \t]+$" nil t) ;; Not syntactic WS as no formfeed
  1499. (replace-match "" nil nil))))
  1500. (defvar compile-command)
  1501. ;; compilation program
  1502. (defun verilog-set-compile-command ()
  1503. "Function to compute shell command to compile Verilog.
  1504. This reads `verilog-tool' and sets `compile-command'. This specifies the
  1505. program that executes when you type \\[compile] or
  1506. \\[verilog-auto-save-compile].
  1507. By default `verilog-tool' uses a Makefile if one exists in the
  1508. current directory. If not, it is set to the `verilog-linter',
  1509. `verilog-compiler', `verilog-coverage', `verilog-preprocessor',
  1510. or `verilog-simulator' variables, as selected with the Verilog ->
  1511. \"Choose Compilation Action\" menu.
  1512. You should set `verilog-tool' or the other variables to the path and
  1513. arguments for your Verilog simulator. For example:
  1514. \"vcs -p123 -O\"
  1515. or a string like:
  1516. \"(cd /tmp; surecov %s)\".
  1517. In the former case, the path to the current buffer is concat'ed to the
  1518. value of `verilog-tool'; in the later, the path to the current buffer is
  1519. substituted for the %s.
  1520. Where __FLAGS__ appears in the string `verilog-current-flags'
  1521. will be substituted.
  1522. Where __FILE__ appears in the string, the variable
  1523. `buffer-file-name' of the current buffer, without the directory
  1524. portion, will be substituted."
  1525. (interactive)
  1526. (cond
  1527. ((or (file-exists-p "makefile") ;If there is a makefile, use it
  1528. (file-exists-p "Makefile"))
  1529. (set (make-local-variable 'compile-command) "make "))
  1530. (t
  1531. (set (make-local-variable 'compile-command)
  1532. (if verilog-tool
  1533. (if (string-match "%s" (eval verilog-tool))
  1534. (format (eval verilog-tool) (or buffer-file-name ""))
  1535. (concat (eval verilog-tool) " " (or buffer-file-name "")))
  1536. ""))))
  1537. (verilog-modify-compile-command))
  1538. (defun verilog-expand-command (command)
  1539. "Replace meta-information in COMMAND and return it.
  1540. Where __FLAGS__ appears in the string `verilog-current-flags'
  1541. will be substituted. Where __FILE__ appears in the string, the
  1542. current buffer's file-name, without the directory portion, will
  1543. be substituted."
  1544. (setq command (verilog-string-replace-matches
  1545. ;; Note \\b only works if under verilog syntax table
  1546. "\\b__FLAGS__\\b" (verilog-current-flags)
  1547. t t command))
  1548. (setq command (verilog-string-replace-matches
  1549. "\\b__FILE__\\b" (file-name-nondirectory
  1550. (or (buffer-file-name) ""))
  1551. t t command))
  1552. command)
  1553. (defun verilog-modify-compile-command ()
  1554. "Update `compile-command' using `verilog-expand-command'."
  1555. (when (and
  1556. (stringp compile-command)
  1557. (string-match "\\b\\(__FLAGS__\\|__FILE__\\)\\b" compile-command))
  1558. (set (make-local-variable 'compile-command)
  1559. (verilog-expand-command compile-command))))
  1560. (if (featurep 'xemacs)
  1561. ;; Following code only gets called from compilation-mode-hook on XEmacs to add error handling.
  1562. (defun verilog-error-regexp-add-xemacs ()
  1563. "Teach XEmacs about verilog errors.
  1564. Called by `compilation-mode-hook'. This allows \\[next-error] to
  1565. find the errors."
  1566. (interactive)
  1567. (if (boundp 'compilation-error-regexp-systems-alist)
  1568. (if (and
  1569. (not (equal compilation-error-regexp-systems-list 'all))
  1570. (not (member compilation-error-regexp-systems-list 'verilog)))
  1571. (push 'verilog compilation-error-regexp-systems-list)))
  1572. (if (boundp 'compilation-error-regexp-alist-alist)
  1573. (if (not (assoc 'verilog compilation-error-regexp-alist-alist))
  1574. (setcdr compilation-error-regexp-alist-alist
  1575. (cons verilog-error-regexp-xemacs-alist
  1576. (cdr compilation-error-regexp-alist-alist)))))
  1577. (if (boundp 'compilation-font-lock-keywords)
  1578. (progn
  1579. (set (make-local-variable 'compilation-font-lock-keywords)
  1580. verilog-error-font-lock-keywords)
  1581. (font-lock-set-defaults)))
  1582. ;; Need to re-run compilation-error-regexp builder
  1583. (if (fboundp 'compilation-build-compilation-error-regexp-alist)
  1584. (compilation-build-compilation-error-regexp-alist))
  1585. ))
  1586. ;; Following code only gets called from compilation-mode-hook on Emacs to add error handling.
  1587. (defun verilog-error-regexp-add-emacs ()
  1588. "Tell Emacs compile that we are Verilog.
  1589. Called by `compilation-mode-hook'. This allows \\[next-error] to
  1590. find the errors."
  1591. (interactive)
  1592. (if (boundp 'compilation-error-regexp-alist-alist)
  1593. (progn
  1594. (if (not (assoc 'verilog-xl-1 compilation-error-regexp-alist-alist))
  1595. (mapcar
  1596. (lambda (item)
  1597. (push (car item) compilation-error-regexp-alist)
  1598. (push item compilation-error-regexp-alist-alist)
  1599. )
  1600. verilog-error-regexp-emacs-alist)))))
  1601. (if (featurep 'xemacs) (add-hook 'compilation-mode-hook 'verilog-error-regexp-add-xemacs))
  1602. (if (featurep 'emacs) (add-hook 'compilation-mode-hook 'verilog-error-regexp-add-emacs))
  1603. (defconst verilog-directive-re
  1604. (eval-when-compile
  1605. (verilog-regexp-words
  1606. '(
  1607. "`case" "`default" "`define" "`else" "`elsif" "`endfor" "`endif"
  1608. "`endprotect" "`endswitch" "`endwhile" "`for" "`format" "`if" "`ifdef"
  1609. "`ifndef" "`include" "`let" "`protect" "`switch" "`timescale"
  1610. "`time_scale" "`undef" "`while" ))))
  1611. (defconst verilog-directive-re-1
  1612. (concat "[ \t]*" verilog-directive-re))
  1613. (defconst verilog-directive-begin
  1614. "\\<`\\(for\\|i\\(f\\|fdef\\|fndef\\)\\|switch\\|while\\)\\>")
  1615. (defconst verilog-directive-middle
  1616. "\\<`\\(else\\|elsif\\|default\\|case\\)\\>")
  1617. (defconst verilog-directive-end
  1618. "`\\(endfor\\|endif\\|endswitch\\|endwhile\\)\\>")
  1619. (defconst verilog-ovm-begin-re
  1620. (eval-when-compile
  1621. (verilog-regexp-opt
  1622. '(
  1623. "`ovm_component_utils_begin"
  1624. "`ovm_component_param_utils_begin"
  1625. "`ovm_field_utils_begin"
  1626. "`ovm_object_utils_begin"
  1627. "`ovm_object_param_utils_begin"
  1628. "`ovm_sequence_utils_begin"
  1629. "`ovm_sequencer_utils_begin"
  1630. ) nil )))
  1631. (defconst verilog-ovm-end-re
  1632. (eval-when-compile
  1633. (verilog-regexp-opt
  1634. '(
  1635. "`ovm_component_utils_end"
  1636. "`ovm_field_utils_end"
  1637. "`ovm_object_utils_end"
  1638. "`ovm_sequence_utils_end"
  1639. "`ovm_sequencer_utils_end"
  1640. ) nil )))
  1641. (defconst verilog-uvm-begin-re
  1642. (eval-when-compile
  1643. (verilog-regexp-opt
  1644. '(
  1645. "`uvm_component_utils_begin"
  1646. "`uvm_component_param_utils_begin"
  1647. "`uvm_field_utils_begin"
  1648. "`uvm_object_utils_begin"
  1649. "`uvm_object_param_utils_begin"
  1650. "`uvm_sequence_utils_begin"
  1651. "`uvm_sequencer_utils_begin"
  1652. ) nil )))
  1653. (defconst verilog-uvm-end-re
  1654. (eval-when-compile
  1655. (verilog-regexp-opt
  1656. '(
  1657. "`uvm_component_utils_end"
  1658. "`uvm_field_utils_end"
  1659. "`uvm_object_utils_end"
  1660. "`uvm_sequence_utils_end"
  1661. "`uvm_sequencer_utils_end"
  1662. ) nil )))
  1663. (defconst verilog-vmm-begin-re
  1664. (eval-when-compile
  1665. (verilog-regexp-opt
  1666. '(
  1667. "`vmm_data_member_begin"
  1668. "`vmm_env_member_begin"
  1669. "`vmm_scenario_member_begin"
  1670. "`vmm_subenv_member_begin"
  1671. "`vmm_xactor_member_begin"
  1672. ) nil ) ) )
  1673. (defconst verilog-vmm-end-re
  1674. (eval-when-compile
  1675. (verilog-regexp-opt
  1676. '(
  1677. "`vmm_data_member_end"
  1678. "`vmm_env_member_end"
  1679. "`vmm_scenario_member_end"
  1680. "`vmm_subenv_member_end"
  1681. "`vmm_xactor_member_end"
  1682. ) nil ) ) )
  1683. (defconst verilog-vmm-statement-re
  1684. (eval-when-compile
  1685. (verilog-regexp-opt
  1686. '(
  1687. ;; "`vmm_xactor_member_enum_array"
  1688. "`vmm_\\(data\\|env\\|scenario\\|subenv\\|xactor\\)_member_\\(scalar\\|string\\|enum\\|vmm_data\\|channel\\|xactor\\|subenv\\|user_defined\\)\\(_array\\)?"
  1689. ;; "`vmm_xactor_member_scalar_array"
  1690. ;; "`vmm_xactor_member_scalar"
  1691. ) nil )))
  1692. (defconst verilog-ovm-statement-re
  1693. (eval-when-compile
  1694. (verilog-regexp-opt
  1695. '(
  1696. ;; Statements
  1697. "`DUT_ERROR"
  1698. "`MESSAGE"
  1699. "`dut_error"
  1700. "`message"
  1701. "`ovm_analysis_imp_decl"
  1702. "`ovm_blocking_get_imp_decl"
  1703. "`ovm_blocking_get_peek_imp_decl"
  1704. "`ovm_blocking_master_imp_decl"
  1705. "`ovm_blocking_peek_imp_decl"
  1706. "`ovm_blocking_put_imp_decl"
  1707. "`ovm_blocking_slave_imp_decl"
  1708. "`ovm_blocking_transport_imp_decl"
  1709. "`ovm_component_registry"
  1710. "`ovm_component_registry_param"
  1711. "`ovm_component_utils"
  1712. "`ovm_create"
  1713. "`ovm_create_seq"
  1714. "`ovm_declare_sequence_lib"
  1715. "`ovm_do"
  1716. "`ovm_do_seq"
  1717. "`ovm_do_seq_with"
  1718. "`ovm_do_with"
  1719. "`ovm_error"
  1720. "`ovm_fatal"
  1721. "`ovm_field_aa_int_byte"
  1722. "`ovm_field_aa_int_byte_unsigned"
  1723. "`ovm_field_aa_int_int"
  1724. "`ovm_field_aa_int_int_unsigned"
  1725. "`ovm_field_aa_int_integer"
  1726. "`ovm_field_aa_int_integer_unsigned"
  1727. "`ovm_field_aa_int_key"
  1728. "`ovm_field_aa_int_longint"
  1729. "`ovm_field_aa_int_longint_unsigned"
  1730. "`ovm_field_aa_int_shortint"
  1731. "`ovm_field_aa_int_shortint_unsigned"
  1732. "`ovm_field_aa_int_string"
  1733. "`ovm_field_aa_object_int"
  1734. "`ovm_field_aa_object_string"
  1735. "`ovm_field_aa_string_int"
  1736. "`ovm_field_aa_string_string"
  1737. "`ovm_field_array_int"
  1738. "`ovm_field_array_object"
  1739. "`ovm_field_array_string"
  1740. "`ovm_field_enum"
  1741. "`ovm_field_event"
  1742. "`ovm_field_int"
  1743. "`ovm_field_object"
  1744. "`ovm_field_queue_int"
  1745. "`ovm_field_queue_object"
  1746. "`ovm_field_queue_string"
  1747. "`ovm_field_sarray_int"
  1748. "`ovm_field_string"
  1749. "`ovm_field_utils"
  1750. "`ovm_file"
  1751. "`ovm_get_imp_decl"
  1752. "`ovm_get_peek_imp_decl"
  1753. "`ovm_info"
  1754. "`ovm_info1"
  1755. "`ovm_info2"
  1756. "`ovm_info3"
  1757. "`ovm_info4"
  1758. "`ovm_line"
  1759. "`ovm_master_imp_decl"
  1760. "`ovm_msg_detail"
  1761. "`ovm_non_blocking_transport_imp_decl"
  1762. "`ovm_nonblocking_get_imp_decl"
  1763. "`ovm_nonblocking_get_peek_imp_decl"
  1764. "`ovm_nonblocking_master_imp_decl"
  1765. "`ovm_nonblocking_peek_imp_decl"
  1766. "`ovm_nonblocking_put_imp_decl"
  1767. "`ovm_nonblocking_slave_imp_decl"
  1768. "`ovm_object_registry"
  1769. "`ovm_object_registry_param"
  1770. "`ovm_object_utils"
  1771. "`ovm_peek_imp_decl"
  1772. "`ovm_phase_func_decl"
  1773. "`ovm_phase_task_decl"
  1774. "`ovm_print_aa_int_object"
  1775. "`ovm_print_aa_string_int"
  1776. "`ovm_print_aa_string_object"
  1777. "`ovm_print_aa_string_string"
  1778. "`ovm_print_array_int"
  1779. "`ovm_print_array_object"
  1780. "`ovm_print_array_string"
  1781. "`ovm_print_object_queue"
  1782. "`ovm_print_queue_int"
  1783. "`ovm_print_string_queue"
  1784. "`ovm_put_imp_decl"
  1785. "`ovm_rand_send"
  1786. "`ovm_rand_send_with"
  1787. "`ovm_send"
  1788. "`ovm_sequence_utils"
  1789. "`ovm_slave_imp_decl"
  1790. "`ovm_transport_imp_decl"
  1791. "`ovm_update_sequence_lib"
  1792. "`ovm_update_sequence_lib_and_item"
  1793. "`ovm_warning"
  1794. "`static_dut_error"
  1795. "`static_message") nil )))
  1796. (defconst verilog-uvm-statement-re
  1797. (eval-when-compile
  1798. (verilog-regexp-opt
  1799. '(
  1800. ;; Statements
  1801. "`uvm_analysis_imp_decl"
  1802. "`uvm_blocking_get_imp_decl"
  1803. "`uvm_blocking_get_peek_imp_decl"
  1804. "`uvm_blocking_master_imp_decl"
  1805. "`uvm_blocking_peek_imp_decl"
  1806. "`uvm_blocking_put_imp_decl"
  1807. "`uvm_blocking_slave_imp_decl"
  1808. "`uvm_blocking_transport_imp_decl"
  1809. "`uvm_component_param_utils"
  1810. "`uvm_component_registry"
  1811. "`uvm_component_registry_param"
  1812. "`uvm_component_utils"
  1813. "`uvm_create"
  1814. "`uvm_create_on"
  1815. "`uvm_create_seq" ;; Undocumented in 1.1
  1816. "`uvm_declare_p_sequencer"
  1817. "`uvm_declare_sequence_lib" ;; Deprecated in 1.1
  1818. "`uvm_do"
  1819. "`uvm_do_callbacks"
  1820. "`uvm_do_callbacks_exit_on"
  1821. "`uvm_do_obj_callbacks"
  1822. "`uvm_do_obj_callbacks_exit_on"
  1823. "`uvm_do_on"
  1824. "`uvm_do_on_pri"
  1825. "`uvm_do_on_pri_with"
  1826. "`uvm_do_on_with"
  1827. "`uvm_do_pri"
  1828. "`uvm_do_pri_with"
  1829. "`uvm_do_seq" ;; Undocumented in 1.1
  1830. "`uvm_do_seq_with" ;; Undocumented in 1.1
  1831. "`uvm_do_with"
  1832. "`uvm_error"
  1833. "`uvm_error_context"
  1834. "`uvm_fatal"
  1835. "`uvm_fatal_context"
  1836. "`uvm_field_aa_int_byte"
  1837. "`uvm_field_aa_int_byte_unsigned"
  1838. "`uvm_field_aa_int_enum"
  1839. "`uvm_field_aa_int_int"
  1840. "`uvm_field_aa_int_int_unsigned"
  1841. "`uvm_field_aa_int_integer"
  1842. "`uvm_field_aa_int_integer_unsigned"
  1843. "`uvm_field_aa_int_key"
  1844. "`uvm_field_aa_int_longint"
  1845. "`uvm_field_aa_int_longint_unsigned"
  1846. "`uvm_field_aa_int_shortint"
  1847. "`uvm_field_aa_int_shortint_unsigned"
  1848. "`uvm_field_aa_int_string"
  1849. "`uvm_field_aa_object_int"
  1850. "`uvm_field_aa_object_string"
  1851. "`uvm_field_aa_string_int"
  1852. "`uvm_field_aa_string_string"
  1853. "`uvm_field_array_enum"
  1854. "`uvm_field_array_int"
  1855. "`uvm_field_array_object"
  1856. "`uvm_field_array_string"
  1857. "`uvm_field_enum"
  1858. "`uvm_field_event"
  1859. "`uvm_field_int"
  1860. "`uvm_field_object"
  1861. "`uvm_field_queue_enum"
  1862. "`uvm_field_queue_int"
  1863. "`uvm_field_queue_object"
  1864. "`uvm_field_queue_string"
  1865. "`uvm_field_real"
  1866. "`uvm_field_sarray_enum"
  1867. "`uvm_field_sarray_int"
  1868. "`uvm_field_sarray_object"
  1869. "`uvm_field_sarray_string"
  1870. "`uvm_field_string"
  1871. "`uvm_field_utils"
  1872. "`uvm_file" ;; Undocumented in 1.1, use `__FILE__
  1873. "`uvm_get_imp_decl"
  1874. "`uvm_get_peek_imp_decl"
  1875. "`uvm_info"
  1876. "`uvm_info_context"
  1877. "`uvm_line" ;; Undocumented in 1.1, use `__LINE__
  1878. "`uvm_master_imp_decl"
  1879. "`uvm_non_blocking_transport_imp_decl" ;; Deprecated in 1.1
  1880. "`uvm_nonblocking_get_imp_decl"
  1881. "`uvm_nonblocking_get_peek_imp_decl"
  1882. "`uvm_nonblocking_master_imp_decl"
  1883. "`uvm_nonblocking_peek_imp_decl"
  1884. "`uvm_nonblocking_put_imp_decl"
  1885. "`uvm_nonblocking_slave_imp_decl"
  1886. "`uvm_nonblocking_transport_imp_decl"
  1887. "`uvm_object_param_utils"
  1888. "`uvm_object_registry"
  1889. "`uvm_object_registry_param" ;; Undocumented in 1.1
  1890. "`uvm_object_utils"
  1891. "`uvm_pack_array"
  1892. "`uvm_pack_arrayN"
  1893. "`uvm_pack_enum"
  1894. "`uvm_pack_enumN"
  1895. "`uvm_pack_int"
  1896. "`uvm_pack_intN"
  1897. "`uvm_pack_queue"
  1898. "`uvm_pack_queueN"
  1899. "`uvm_pack_real"
  1900. "`uvm_pack_sarray"
  1901. "`uvm_pack_sarrayN"
  1902. "`uvm_pack_string"
  1903. "`uvm_peek_imp_decl"
  1904. "`uvm_put_imp_decl"
  1905. "`uvm_rand_send"
  1906. "`uvm_rand_send_pri"
  1907. "`uvm_rand_send_pri_with"
  1908. "`uvm_rand_send_with"
  1909. "`uvm_record_attribute"
  1910. "`uvm_record_field"
  1911. "`uvm_register_cb"
  1912. "`uvm_send"
  1913. "`uvm_send_pri"
  1914. "`uvm_sequence_utils" ;; Deprecated in 1.1
  1915. "`uvm_set_super_type"
  1916. "`uvm_slave_imp_decl"
  1917. "`uvm_transport_imp_decl"
  1918. "`uvm_unpack_array"
  1919. "`uvm_unpack_arrayN"
  1920. "`uvm_unpack_enum"
  1921. "`uvm_unpack_enumN"
  1922. "`uvm_unpack_int"
  1923. "`uvm_unpack_intN"
  1924. "`uvm_unpack_queue"
  1925. "`uvm_unpack_queueN"
  1926. "`uvm_unpack_real"
  1927. "`uvm_unpack_sarray"
  1928. "`uvm_unpack_sarrayN"
  1929. "`uvm_unpack_string"
  1930. "`uvm_update_sequence_lib" ;; Deprecated in 1.1
  1931. "`uvm_update_sequence_lib_and_item" ;; Deprecated in 1.1
  1932. "`uvm_warning"
  1933. "`uvm_warning_context") nil )))
  1934. ;;
  1935. ;; Regular expressions used to calculate indent, etc.
  1936. ;;
  1937. (defconst verilog-symbol-re "\\<[a-zA-Z_][a-zA-Z_0-9.]*\\>")
  1938. ;; Want to match
  1939. ;; aa :
  1940. ;; aa,bb :
  1941. ;; a[34:32] :
  1942. ;; a,
  1943. ;; b :
  1944. (defconst verilog-assignment-operator-re
  1945. (eval-when-compile
  1946. (verilog-regexp-opt
  1947. `(
  1948. ;; blocking assignment_operator
  1949. "=" "+=" "-=" "*=" "/=" "%=" "&=" "|=" "^=" "<<=" ">>=" "<<<=" ">>>="
  1950. ;; non blocking assignment operator
  1951. "<="
  1952. ;; comparison
  1953. "==" "!=" "===" "!===" "<=" ">=" "==\?" "!=\?"
  1954. ;; event_trigger
  1955. "->" "->>"
  1956. ;; property_expr
  1957. "|->" "|=>"
  1958. ;; Is this a legal verilog operator?
  1959. ":="
  1960. ) 't
  1961. )))
  1962. (defconst verilog-assignment-operation-re
  1963. (concat
  1964. ; "\\(^\\s-*[A-Za-z0-9_]+\\(\\[\\([A-Za-z0-9_]+\\)\\]\\)*\\s-*\\)"
  1965. ; "\\(^\\s-*[^=<>+-*/%&|^:\\s-]+[^=<>+-*/%&|^\n]*?\\)"
  1966. "\\(^.*?\\)" "\\B" verilog-assignment-operator-re "\\B" ))
  1967. (defconst verilog-label-re (concat verilog-symbol-re "\\s-*:\\s-*"))
  1968. (defconst verilog-property-re
  1969. (concat "\\(" verilog-label-re "\\)?"
  1970. "\\(\\(assert\\|assume\\|cover\\)\\>\\s-+\\<property\\>\\)\\|\\(assert\\)"))
  1971. ;; "\\(assert\\|assume\\|cover\\)\\s-+property\\>"
  1972. (defconst verilog-no-indent-begin-re
  1973. "\\<\\(if\\|else\\|while\\|for\\|repeat\\|always\\|always_comb\\|always_ff\\|always_latch\\)\\>")
  1974. (defconst verilog-ends-re
  1975. ;; Parenthesis indicate type of keyword found
  1976. (concat
  1977. "\\(\\<else\\>\\)\\|" ; 1
  1978. "\\(\\<if\\>\\)\\|" ; 2
  1979. "\\(\\<assert\\>\\)\\|" ; 3
  1980. "\\(\\<end\\>\\)\\|" ; 3.1
  1981. "\\(\\<endcase\\>\\)\\|" ; 4
  1982. "\\(\\<endfunction\\>\\)\\|" ; 5
  1983. "\\(\\<endtask\\>\\)\\|" ; 6
  1984. "\\(\\<endspecify\\>\\)\\|" ; 7
  1985. "\\(\\<endtable\\>\\)\\|" ; 8
  1986. "\\(\\<endgenerate\\>\\)\\|" ; 9
  1987. "\\(\\<join\\(_any\\|_none\\)?\\>\\)\\|" ; 10
  1988. "\\(\\<endclass\\>\\)\\|" ; 11
  1989. "\\(\\<endgroup\\>\\)\\|" ; 12
  1990. ;; VMM
  1991. "\\(\\<`vmm_data_member_end\\>\\)\\|"
  1992. "\\(\\<`vmm_env_member_end\\>\\)\\|"
  1993. "\\(\\<`vmm_scenario_member_end\\>\\)\\|"
  1994. "\\(\\<`vmm_subenv_member_end\\>\\)\\|"
  1995. "\\(\\<`vmm_xactor_member_end\\>\\)\\|"
  1996. ;; OVM
  1997. "\\(\\<`ovm_component_utils_end\\>\\)\\|"
  1998. "\\(\\<`ovm_field_utils_end\\>\\)\\|"
  1999. "\\(\\<`ovm_object_utils_end\\>\\)\\|"
  2000. "\\(\\<`ovm_sequence_utils_end\\>\\)\\|"
  2001. "\\(\\<`ovm_sequencer_utils_end\\>\\)"
  2002. ;; UVM
  2003. "\\(\\<`uvm_component_utils_end\\>\\)\\|"
  2004. "\\(\\<`uvm_field_utils_end\\>\\)\\|"
  2005. "\\(\\<`uvm_object_utils_end\\>\\)\\|"
  2006. "\\(\\<`uvm_sequence_utils_end\\>\\)\\|"
  2007. "\\(\\<`uvm_sequencer_utils_end\\>\\)"
  2008. ))
  2009. (defconst verilog-auto-end-comment-lines-re
  2010. ;; Matches to names in this list cause auto-end-commenting
  2011. (concat "\\("
  2012. verilog-directive-re "\\)\\|\\("
  2013. (eval-when-compile
  2014. (verilog-regexp-words
  2015. `( "begin"
  2016. "else"
  2017. "end"
  2018. "endcase"
  2019. "endclass"
  2020. "endclocking"
  2021. "endgroup"
  2022. "endfunction"
  2023. "endmodule"
  2024. "endprogram"
  2025. "endprimitive"
  2026. "endinterface"
  2027. "endpackage"
  2028. "endsequence"
  2029. "endspecify"
  2030. "endtable"
  2031. "endtask"
  2032. "join"
  2033. "join_any"
  2034. "join_none"
  2035. "module"
  2036. "macromodule"
  2037. "primitive"
  2038. "interface"
  2039. "package")))
  2040. "\\)"))
  2041. ;;; NOTE: verilog-leap-to-head expects that verilog-end-block-re and
  2042. ;;; verilog-end-block-ordered-re matches exactly the same strings.
  2043. (defconst verilog-end-block-ordered-re
  2044. ;; Parenthesis indicate type of keyword found
  2045. (concat "\\(\\<endcase\\>\\)\\|" ; 1
  2046. "\\(\\<end\\>\\)\\|" ; 2
  2047. "\\(\\<end" ; 3, but not used
  2048. "\\(" ; 4, but not used
  2049. "\\(function\\)\\|" ; 5
  2050. "\\(task\\)\\|" ; 6
  2051. "\\(module\\)\\|" ; 7
  2052. "\\(primitive\\)\\|" ; 8
  2053. "\\(interface\\)\\|" ; 9
  2054. "\\(package\\)\\|" ; 10
  2055. "\\(class\\)\\|" ; 11
  2056. "\\(group\\)\\|" ; 12
  2057. "\\(program\\)\\|" ; 13
  2058. "\\(sequence\\)\\|" ; 14
  2059. "\\(clocking\\)\\|" ; 15
  2060. "\\)\\>\\)"))
  2061. (defconst verilog-end-block-re
  2062. (eval-when-compile
  2063. (verilog-regexp-words
  2064. `("end" ;; closes begin
  2065. "endcase" ;; closes any of case, casex casez or randcase
  2066. "join" "join_any" "join_none" ;; closes fork
  2067. "endclass"
  2068. "endtable"
  2069. "endspecify"
  2070. "endfunction"
  2071. "endgenerate"
  2072. "endtask"
  2073. "endgroup"
  2074. "endproperty"
  2075. "endinterface"
  2076. "endpackage"
  2077. "endprogram"
  2078. "endsequence"
  2079. "endclocking"
  2080. ;; OVM
  2081. "`ovm_component_utils_end"
  2082. "`ovm_field_utils_end"
  2083. "`ovm_object_utils_end"
  2084. "`ovm_sequence_utils_end"
  2085. "`ovm_sequencer_utils_end"
  2086. ;; UVM
  2087. "`uvm_component_utils_end"
  2088. "`uvm_field_utils_end"
  2089. "`uvm_object_utils_end"
  2090. "`uvm_sequence_utils_end"
  2091. "`uvm_sequencer_utils_end"
  2092. ;; VMM
  2093. "`vmm_data_member_end"
  2094. "`vmm_env_member_end"
  2095. "`vmm_scenario_member_end"
  2096. "`vmm_subenv_member_end"
  2097. "`vmm_xactor_member_end"
  2098. ))))
  2099. (defconst verilog-endcomment-reason-re
  2100. ;; Parenthesis indicate type of keyword found
  2101. (concat
  2102. "\\(\\<begin\\>\\)\\|" ; 1
  2103. "\\(\\<else\\>\\)\\|" ; 2
  2104. "\\(\\<end\\>\\s-+\\<else\\>\\)\\|" ; 3
  2105. "\\(\\<always_comb\\>\\(\[ \t\]*@\\)?\\)\\|" ; 4
  2106. "\\(\\<always_ff\\>\\(\[ \t\]*@\\)?\\)\\|" ; 5
  2107. "\\(\\<always_latch\\>\\(\[ \t\]*@\\)?\\)\\|" ; 6
  2108. "\\(\\<fork\\>\\)\\|" ; 7
  2109. "\\(\\<always\\>\\(\[ \t\]*@\\)?\\)\\|"
  2110. "\\(\\<if\\>\\)\\|"
  2111. verilog-property-re "\\|"
  2112. "\\(\\(" verilog-label-re "\\)?\\<assert\\>\\)\\|"
  2113. "\\(\\<clocking\\>\\)\\|"
  2114. "\\(\\<task\\>\\)\\|"
  2115. "\\(\\<function\\>\\)\\|"
  2116. "\\(\\<initial\\>\\)\\|"
  2117. "\\(\\<interface\\>\\)\\|"
  2118. "\\(\\<package\\>\\)\\|"
  2119. "\\(\\<final\\>\\)\\|"
  2120. "\\(@\\)\\|"
  2121. "\\(\\<while\\>\\)\\|"
  2122. "\\(\\<for\\(ever\\|each\\)?\\>\\)\\|"
  2123. "\\(\\<repeat\\>\\)\\|\\(\\<wait\\>\\)\\|"
  2124. "#"))
  2125. (defconst verilog-named-block-re "begin[ \t]*:")
  2126. ;; These words begin a block which can occur inside a module which should be indented,
  2127. ;; and closed with the respective word from the end-block list
  2128. (defconst verilog-beg-block-re
  2129. (eval-when-compile
  2130. (verilog-regexp-words
  2131. `("begin"
  2132. "case" "casex" "casez" "randcase"
  2133. "clocking"
  2134. "generate"
  2135. "fork"
  2136. "function"
  2137. "property"
  2138. "specify"
  2139. "table"
  2140. "task"
  2141. ;; OVM
  2142. "`ovm_component_utils_begin"
  2143. "`ovm_component_param_utils_begin"
  2144. "`ovm_field_utils_begin"
  2145. "`ovm_object_utils_begin"
  2146. "`ovm_object_param_utils_begin"
  2147. "`ovm_sequence_utils_begin"
  2148. "`ovm_sequencer_utils_begin"
  2149. ;; UVM
  2150. "`uvm_component_utils_begin"
  2151. "`uvm_component_param_utils_begin"
  2152. "`uvm_field_utils_begin"
  2153. "`uvm_object_utils_begin"
  2154. "`uvm_object_param_utils_begin"
  2155. "`uvm_sequence_utils_begin"
  2156. "`uvm_sequencer_utils_begin"
  2157. ;; VMM
  2158. "`vmm_data_member_begin"
  2159. "`vmm_env_member_begin"
  2160. "`vmm_scenario_member_begin"
  2161. "`vmm_subenv_member_begin"
  2162. "`vmm_xactor_member_begin"
  2163. ))))
  2164. ;; These are the same words, in a specific order in the regular
  2165. ;; expression so that matching will work nicely for
  2166. ;; verilog-forward-sexp and verilog-calc-indent
  2167. (defconst verilog-beg-block-re-ordered
  2168. ( concat "\\(\\<begin\\>\\)" ;1
  2169. "\\|\\(\\<randcase\\>\\|\\(\\<unique\\s-+\\|priority\\s-+\\)?case[xz]?\\>\\)" ; 2,3
  2170. "\\|\\(\\(\\<disable\\>\\s-+\\|\\<wait\\>\\s-+\\)?fork\\>\\)" ;4,5
  2171. "\\|\\(\\<class\\>\\)" ;6
  2172. "\\|\\(\\<table\\>\\)" ;7
  2173. "\\|\\(\\<specify\\>\\)" ;8
  2174. "\\|\\(\\<function\\>\\)" ;9
  2175. "\\|\\(\\(\\(\\<virtual\\>\\s-+\\)\\|\\(\\<protected\\>\\s-+\\)\\)*\\<function\\>\\)" ;10
  2176. "\\|\\(\\<task\\>\\)" ;14
  2177. "\\|\\(\\(\\(\\<virtual\\>\\s-+\\)\\|\\(\\<protected\\>\\s-+\\)\\)*\\<task\\>\\)" ;15
  2178. "\\|\\(\\<generate\\>\\)" ;18
  2179. "\\|\\(\\<covergroup\\>\\)" ;16 20
  2180. "\\|\\(\\(\\(\\<cover\\>\\s-+\\)\\|\\(\\<assert\\>\\s-+\\)\\)*\\<property\\>\\)" ;17 21
  2181. "\\|\\(\\<\\(rand\\)?sequence\\>\\)" ;21 25
  2182. "\\|\\(\\<clocking\\>\\)" ;22 27
  2183. "\\|\\(\\<`[ou]vm_[a-z_]+_begin\\>\\)" ;28
  2184. "\\|\\(\\<`vmm_[a-z_]+_member_begin\\>\\)"
  2185. ;;
  2186. ))
  2187. (defconst verilog-end-block-ordered-rry
  2188. [ "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)\\|\\(\\<endcase\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)"
  2189. "\\(\\<randcase\\>\\|\\<case[xz]?\\>\\)\\|\\(\\<endcase\\>\\)"
  2190. "\\(\\<fork\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)"
  2191. "\\(\\<class\\>\\)\\|\\(\\<endclass\\>\\)"
  2192. "\\(\\<table\\>\\)\\|\\(\\<endtable\\>\\)"
  2193. "\\(\\<specify\\>\\)\\|\\(\\<endspecify\\>\\)"
  2194. "\\(\\<function\\>\\)\\|\\(\\<endfunction\\>\\)"
  2195. "\\(\\<generate\\>\\)\\|\\(\\<endgenerate\\>\\)"
  2196. "\\(\\<task\\>\\)\\|\\(\\<endtask\\>\\)"
  2197. "\\(\\<covergroup\\>\\)\\|\\(\\<endgroup\\>\\)"
  2198. "\\(\\<property\\>\\)\\|\\(\\<endproperty\\>\\)"
  2199. "\\(\\<\\(rand\\)?sequence\\>\\)\\|\\(\\<endsequence\\>\\)"
  2200. "\\(\\<clocking\\>\\)\\|\\(\\<endclocking\\>\\)"
  2201. ] )
  2202. (defconst verilog-nameable-item-re
  2203. (eval-when-compile
  2204. (verilog-regexp-words
  2205. `("begin"
  2206. "fork"
  2207. "join" "join_any" "join_none"
  2208. "end"
  2209. "endcase"
  2210. "endconfig"
  2211. "endclass"
  2212. "endclocking"
  2213. "endfunction"
  2214. "endgenerate"
  2215. "endmodule"
  2216. "endprimitive"
  2217. "endinterface"
  2218. "endpackage"
  2219. "endspecify"
  2220. "endtable"
  2221. "endtask" )
  2222. )))
  2223. (defconst verilog-declaration-opener
  2224. (eval-when-compile
  2225. (verilog-regexp-words
  2226. `("module" "begin" "task" "function"))))
  2227. (defconst verilog-declaration-prefix-re
  2228. (eval-when-compile
  2229. (verilog-regexp-words
  2230. `(
  2231. ;; port direction
  2232. "inout" "input" "output" "ref"
  2233. ;; changeableness
  2234. "const" "static" "protected" "local"
  2235. ;; parameters
  2236. "localparam" "parameter" "var"
  2237. ;; type creation
  2238. "typedef"
  2239. ))))
  2240. (defconst verilog-declaration-core-re
  2241. (eval-when-compile
  2242. (verilog-regexp-words
  2243. `(
  2244. ;; port direction (by themselves)
  2245. "inout" "input" "output"
  2246. ;; integer_atom_type
  2247. "byte" "shortint" "int" "longint" "integer" "time"
  2248. ;; integer_vector_type
  2249. "bit" "logic" "reg"
  2250. ;; non_integer_type
  2251. "shortreal" "real" "realtime"
  2252. ;; net_type
  2253. "supply0" "supply1" "tri" "triand" "trior" "trireg" "tri0" "tri1" "uwire" "wire" "wand" "wor"
  2254. ;; misc
  2255. "string" "event" "chandle" "virtual" "enum" "genvar"
  2256. "struct" "union"
  2257. ;; builtin classes
  2258. "mailbox" "semaphore"
  2259. ))))
  2260. (defconst verilog-declaration-re
  2261. (concat "\\(" verilog-declaration-prefix-re "\\s-*\\)?" verilog-declaration-core-re))
  2262. (defconst verilog-range-re "\\(\\[[^]]*\\]\\s-*\\)+")
  2263. (defconst verilog-optional-signed-re "\\s-*\\(signed\\)?")
  2264. (defconst verilog-optional-signed-range-re
  2265. (concat
  2266. "\\s-*\\(\\<\\(reg\\|wire\\)\\>\\s-*\\)?\\(\\<signed\\>\\s-*\\)?\\(" verilog-range-re "\\)?"))
  2267. (defconst verilog-macroexp-re "`\\sw+")
  2268. (defconst verilog-delay-re "#\\s-*\\(\\([0-9_]+\\('s?[hdxbo][0-9a-fA-F_xz]+\\)?\\)\\|\\(([^()]*)\\)\\|\\(\\sw+\\)\\)")
  2269. (defconst verilog-declaration-re-2-no-macro
  2270. (concat "\\s-*" verilog-declaration-re
  2271. "\\s-*\\(\\(" verilog-optional-signed-range-re "\\)\\|\\(" verilog-delay-re "\\)"
  2272. "\\)?"))
  2273. (defconst verilog-declaration-re-2-macro
  2274. (concat "\\s-*" verilog-declaration-re
  2275. "\\s-*\\(\\(" verilog-optional-signed-range-re "\\)\\|\\(" verilog-delay-re "\\)"
  2276. "\\|\\(" verilog-macroexp-re "\\)"
  2277. "\\)?"))
  2278. (defconst verilog-declaration-re-1-macro
  2279. (concat "^" verilog-declaration-re-2-macro))
  2280. (defconst verilog-declaration-re-1-no-macro (concat "^" verilog-declaration-re-2-no-macro))
  2281. (defconst verilog-defun-re
  2282. (eval-when-compile (verilog-regexp-words `("macromodule" "module" "class" "program" "interface" "package" "primitive" "config"))))
  2283. (defconst verilog-end-defun-re
  2284. (eval-when-compile (verilog-regexp-words `("endmodule" "endclass" "endprogram" "endinterface" "endpackage" "endprimitive" "endconfig"))))
  2285. (defconst verilog-zero-indent-re
  2286. (concat verilog-defun-re "\\|" verilog-end-defun-re))
  2287. (defconst verilog-inst-comment-re
  2288. (eval-when-compile (verilog-regexp-words `("Outputs" "Inouts" "Inputs" "Interfaces" "Interfaced"))))
  2289. (defconst verilog-behavioral-block-beg-re
  2290. (eval-when-compile (verilog-regexp-words `("initial" "final" "always" "always_comb" "always_latch" "always_ff"
  2291. "function" "task"))))
  2292. (defconst verilog-coverpoint-re "\\w+\\s*:\\s*\\(coverpoint\\|cross\\constraint\\)" )
  2293. (defconst verilog-indent-re
  2294. (eval-when-compile
  2295. (verilog-regexp-words
  2296. `(
  2297. "{"
  2298. "always" "always_latch" "always_ff" "always_comb"
  2299. "begin" "end"
  2300. ; "unique" "priority"
  2301. "case" "casex" "casez" "randcase" "endcase"
  2302. "class" "endclass"
  2303. "clocking" "endclocking"
  2304. "config" "endconfig"
  2305. "covergroup" "endgroup"
  2306. "fork" "join" "join_any" "join_none"
  2307. "function" "endfunction"
  2308. "final"
  2309. "generate" "endgenerate"
  2310. "initial"
  2311. "interface" "endinterface"
  2312. "module" "macromodule" "endmodule"
  2313. "package" "endpackage"
  2314. "primitive" "endprimitive"
  2315. "program" "endprogram"
  2316. "property" "endproperty"
  2317. "sequence" "randsequence" "endsequence"
  2318. "specify" "endspecify"
  2319. "table" "endtable"
  2320. "task" "endtask"
  2321. "virtual"
  2322. "`case"
  2323. "`default"
  2324. "`define" "`undef"
  2325. "`if" "`ifdef" "`ifndef" "`else" "`elsif" "`endif"
  2326. "`while" "`endwhile"
  2327. "`for" "`endfor"
  2328. "`format"
  2329. "`include"
  2330. "`let"
  2331. "`protect" "`endprotect"
  2332. "`switch" "`endswitch"
  2333. "`timescale"
  2334. "`time_scale"
  2335. ;; OVM Begin tokens
  2336. "`ovm_component_utils_begin"
  2337. "`ovm_component_param_utils_begin"
  2338. "`ovm_field_utils_begin"
  2339. "`ovm_object_utils_begin"
  2340. "`ovm_object_param_utils_begin"
  2341. "`ovm_sequence_utils_begin"
  2342. "`ovm_sequencer_utils_begin"
  2343. ;; OVM End tokens
  2344. "`ovm_component_utils_end"
  2345. "`ovm_field_utils_end"
  2346. "`ovm_object_utils_end"
  2347. "`ovm_sequence_utils_end"
  2348. "`ovm_sequencer_utils_end"
  2349. ;; UVM Begin tokens
  2350. "`uvm_component_utils_begin"
  2351. "`uvm_component_param_utils_begin"
  2352. "`uvm_field_utils_begin"
  2353. "`uvm_object_utils_begin"
  2354. "`uvm_object_param_utils_begin"
  2355. "`uvm_sequence_utils_begin"
  2356. "`uvm_sequencer_utils_begin"
  2357. ;; UVM End tokens
  2358. "`uvm_component_utils_end" ;; Typo in spec, it's not uvm_component_end
  2359. "`uvm_field_utils_end"
  2360. "`uvm_object_utils_end"
  2361. "`uvm_sequence_utils_end"
  2362. "`uvm_sequencer_utils_end"
  2363. ;; VMM Begin tokens
  2364. "`vmm_data_member_begin"
  2365. "`vmm_env_member_begin"
  2366. "`vmm_scenario_member_begin"
  2367. "`vmm_subenv_member_begin"
  2368. "`vmm_xactor_member_begin"
  2369. ;; VMM End tokens
  2370. "`vmm_data_member_end"
  2371. "`vmm_env_member_end"
  2372. "`vmm_scenario_member_end"
  2373. "`vmm_subenv_member_end"
  2374. "`vmm_xactor_member_end"
  2375. ))))
  2376. (defconst verilog-defun-level-not-generate-re
  2377. (eval-when-compile
  2378. (verilog-regexp-words
  2379. `( "module" "macromodule" "primitive" "class" "program"
  2380. "interface" "package" "config"))))
  2381. (defconst verilog-defun-level-re
  2382. (eval-when-compile
  2383. (verilog-regexp-words
  2384. (append
  2385. `( "module" "macromodule" "primitive" "class" "program"
  2386. "interface" "package" "config")
  2387. `( "initial" "final" "always" "always_comb" "always_ff"
  2388. "always_latch" "endtask" "endfunction" )))))
  2389. (defconst verilog-defun-level-generate-only-re
  2390. (eval-when-compile
  2391. (verilog-regexp-words
  2392. `( "initial" "final" "always" "always_comb" "always_ff"
  2393. "always_latch" "endtask" "endfunction" ))))
  2394. (defconst verilog-cpp-level-re
  2395. (eval-when-compile
  2396. (verilog-regexp-words
  2397. `(
  2398. "endmodule" "endprimitive" "endinterface" "endpackage" "endprogram" "endclass"
  2399. ))))
  2400. (defconst verilog-disable-fork-re "\\(disable\\|wait\\)\\s-+fork\\>")
  2401. (defconst verilog-extended-case-re "\\(unique\\s-+\\|priority\\s-+\\)?case[xz]?")
  2402. (defconst verilog-extended-complete-re
  2403. (concat "\\(\\<extern\\s-+\\|\\<\\(\\<pure\\>\\s-+\\)?virtual\\s-+\\|\\<protected\\s-+\\)*\\(\\<function\\>\\|\\<task\\>\\)"
  2404. "\\|\\(\\<typedef\\>\\s-+\\)*\\(\\<struct\\>\\|\\<union\\>\\|\\<class\\>\\)"
  2405. "\\|\\(\\<import\\>\\s-+\\)?\"DPI-C\"\\s-+\\(function\\>\\|task\\>\\)"
  2406. "\\|" verilog-extended-case-re ))
  2407. (defconst verilog-basic-complete-re
  2408. (eval-when-compile
  2409. (verilog-regexp-words
  2410. `(
  2411. "always" "assign" "always_latch" "always_ff" "always_comb" "constraint"
  2412. "import" "initial" "final" "module" "macromodule" "repeat" "randcase" "while"
  2413. "if" "for" "forever" "foreach" "else" "parameter" "do" "localparam" "assert"
  2414. ))))
  2415. (defconst verilog-complete-reg
  2416. (concat
  2417. verilog-extended-complete-re
  2418. "\\|"
  2419. verilog-basic-complete-re))
  2420. (defconst verilog-end-statement-re
  2421. (concat "\\(" verilog-beg-block-re "\\)\\|\\("
  2422. verilog-end-block-re "\\)"))
  2423. (defconst verilog-endcase-re
  2424. (concat verilog-extended-case-re "\\|"
  2425. "\\(endcase\\)\\|"
  2426. verilog-defun-re
  2427. ))
  2428. (defconst verilog-exclude-str-start "/* -----\\/----- EXCLUDED -----\\/-----"
  2429. "String used to mark beginning of excluded text.")
  2430. (defconst verilog-exclude-str-end " -----/\\----- EXCLUDED -----/\\----- */"
  2431. "String used to mark end of excluded text.")
  2432. (defconst verilog-preprocessor-re
  2433. (eval-when-compile
  2434. (verilog-regexp-words
  2435. `(
  2436. "`define" "`include" "`ifdef" "`ifndef" "`if" "`endif" "`else"
  2437. ))))
  2438. (defconst verilog-keywords
  2439. '( "`case" "`default" "`define" "`else" "`endfor" "`endif"
  2440. "`endprotect" "`endswitch" "`endwhile" "`for" "`format" "`if" "`ifdef"
  2441. "`ifndef" "`include" "`let" "`protect" "`switch" "`timescale"
  2442. "`time_scale" "`undef" "`while"
  2443. "after" "alias" "always" "always_comb" "always_ff" "always_latch" "and"
  2444. "assert" "assign" "assume" "automatic" "before" "begin" "bind"
  2445. "bins" "binsof" "bit" "break" "buf" "bufif0" "bufif1" "byte"
  2446. "case" "casex" "casez" "cell" "chandle" "class" "clocking" "cmos"
  2447. "config" "const" "constraint" "context" "continue" "cover"
  2448. "covergroup" "coverpoint" "cross" "deassign" "default" "defparam"
  2449. "design" "disable" "dist" "do" "edge" "else" "end" "endcase"
  2450. "endclass" "endclocking" "endconfig" "endfunction" "endgenerate"
  2451. "endgroup" "endinterface" "endmodule" "endpackage" "endprimitive"
  2452. "endprogram" "endproperty" "endspecify" "endsequence" "endtable"
  2453. "endtask" "enum" "event" "expect" "export" "extends" "extern"
  2454. "final" "first_match" "for" "force" "foreach" "forever" "fork"
  2455. "forkjoin" "function" "generate" "genvar" "highz0" "highz1" "if"
  2456. "iff" "ifnone" "ignore_bins" "illegal_bins" "import" "incdir"
  2457. "include" "initial" "inout" "input" "inside" "instance" "int"
  2458. "integer" "interface" "intersect" "join" "join_any" "join_none"
  2459. "large" "liblist" "library" "local" "localparam" "logic"
  2460. "longint" "macromodule" "mailbox" "matches" "medium" "modport" "module"
  2461. "nand" "negedge" "new" "nmos" "nor" "noshowcancelled" "not"
  2462. "notif0" "notif1" "null" "or" "output" "package" "packed"
  2463. "parameter" "pmos" "posedge" "primitive" "priority" "program"
  2464. "property" "protected" "pull0" "pull1" "pulldown" "pullup"
  2465. "pulsestyle_onevent" "pulsestyle_ondetect" "pure" "rand" "randc"
  2466. "randcase" "randsequence" "rcmos" "real" "realtime" "ref" "reg"
  2467. "release" "repeat" "return" "rnmos" "rpmos" "rtran" "rtranif0"
  2468. "rtranif1" "scalared" "semaphore" "sequence" "shortint" "shortreal"
  2469. "showcancelled" "signed" "small" "solve" "specify" "specparam"
  2470. "static" "string" "strong0" "strong1" "struct" "super" "supply0"
  2471. "supply1" "table" "tagged" "task" "this" "throughout" "time"
  2472. "timeprecision" "timeunit" "tran" "tranif0" "tranif1" "tri"
  2473. "tri0" "tri1" "triand" "trior" "trireg" "type" "typedef" "union"
  2474. "unique" "unsigned" "use" "uwire" "var" "vectored" "virtual" "void"
  2475. "wait" "wait_order" "wand" "weak0" "weak1" "while" "wildcard"
  2476. "wire" "with" "within" "wor" "xnor" "xor"
  2477. ;; 1800-2009
  2478. "accept_on" "checker" "endchecker" "eventually" "global" "implies"
  2479. "let" "nexttime" "reject_on" "restrict" "s_always" "s_eventually"
  2480. "s_nexttime" "s_until" "s_until_with" "strong" "sync_accept_on"
  2481. "sync_reject_on" "unique0" "until" "until_with" "untyped" "weak"
  2482. )
  2483. "List of Verilog keywords.")
  2484. (defconst verilog-comment-start-regexp "//\\|/\\*"
  2485. "Dual comment value for `comment-start-regexp'.")
  2486. (defvar verilog-mode-syntax-table
  2487. (let ((table (make-syntax-table)))
  2488. ;; Populate the syntax TABLE.
  2489. (modify-syntax-entry ?\\ "\\" table)
  2490. (modify-syntax-entry ?+ "." table)
  2491. (modify-syntax-entry ?- "." table)
  2492. (modify-syntax-entry ?= "." table)
  2493. (modify-syntax-entry ?% "." table)
  2494. (modify-syntax-entry ?< "." table)
  2495. (modify-syntax-entry ?> "." table)
  2496. (modify-syntax-entry ?& "." table)
  2497. (modify-syntax-entry ?| "." table)
  2498. (modify-syntax-entry ?` "w" table)
  2499. (modify-syntax-entry ?_ "w" table)
  2500. (modify-syntax-entry ?\' "." table)
  2501. ;; Set up TABLE to handle block and line style comments.
  2502. (if (featurep 'xemacs)
  2503. (progn
  2504. ;; XEmacs (formerly Lucid) has the best implementation
  2505. (modify-syntax-entry ?/ ". 1456" table)
  2506. (modify-syntax-entry ?* ". 23" table)
  2507. (modify-syntax-entry ?\n "> b" table))
  2508. ;; Emacs does things differently, but we can work with it
  2509. (modify-syntax-entry ?/ ". 124b" table)
  2510. (modify-syntax-entry ?* ". 23" table)
  2511. (modify-syntax-entry ?\n "> b" table))
  2512. table)
  2513. "Syntax table used in Verilog mode buffers.")
  2514. (defvar verilog-font-lock-keywords nil
  2515. "Default highlighting for Verilog mode.")
  2516. (defvar verilog-font-lock-keywords-1 nil
  2517. "Subdued level highlighting for Verilog mode.")
  2518. (defvar verilog-font-lock-keywords-2 nil
  2519. "Medium level highlighting for Verilog mode.
  2520. See also `verilog-font-lock-extra-types'.")
  2521. (defvar verilog-font-lock-keywords-3 nil
  2522. "Gaudy level highlighting for Verilog mode.
  2523. See also `verilog-font-lock-extra-types'.")
  2524. (defvar verilog-font-lock-translate-off-face
  2525. 'verilog-font-lock-translate-off-face
  2526. "Font to use for translated off regions.")
  2527. (defface verilog-font-lock-translate-off-face
  2528. '((((class color)
  2529. (background light))
  2530. (:background "gray90" :italic t ))
  2531. (((class color)
  2532. (background dark))
  2533. (:background "gray10" :italic t ))
  2534. (((class grayscale) (background light))
  2535. (:foreground "DimGray" :italic t))
  2536. (((class grayscale) (background dark))
  2537. (:foreground "LightGray" :italic t))
  2538. (t (:italis t)))
  2539. "Font lock mode face used to background highlight translate-off regions."
  2540. :group 'font-lock-highlighting-faces)
  2541. (defvar verilog-font-lock-p1800-face
  2542. 'verilog-font-lock-p1800-face
  2543. "Font to use for p1800 keywords.")
  2544. (defface verilog-font-lock-p1800-face
  2545. '((((class color)
  2546. (background light))
  2547. (:foreground "DarkOrange3" :bold t ))
  2548. (((class color)
  2549. (background dark))
  2550. (:foreground "orange1" :bold t ))
  2551. (t (:italic t)))
  2552. "Font lock mode face used to highlight P1800 keywords."
  2553. :group 'font-lock-highlighting-faces)
  2554. (defvar verilog-font-lock-ams-face
  2555. 'verilog-font-lock-ams-face
  2556. "Font to use for Analog/Mixed Signal keywords.")
  2557. (defface verilog-font-lock-ams-face
  2558. '((((class color)
  2559. (background light))
  2560. (:foreground "Purple" :bold t ))
  2561. (((class color)
  2562. (background dark))
  2563. (:foreground "orange1" :bold t ))
  2564. (t (:italic t)))
  2565. "Font lock mode face used to highlight AMS keywords."
  2566. :group 'font-lock-highlighting-faces)
  2567. (defvar verilog-font-grouping-keywords-face
  2568. 'verilog-font-lock-grouping-keywords-face
  2569. "Font to use for Verilog Grouping Keywords (such as begin..end).")
  2570. (defface verilog-font-lock-grouping-keywords-face
  2571. '((((class color)
  2572. (background light))
  2573. (:foreground "red4" :bold t ))
  2574. (((class color)
  2575. (background dark))
  2576. (:foreground "red4" :bold t ))
  2577. (t (:italic t)))
  2578. "Font lock mode face used to highlight verilog grouping keywords."
  2579. :group 'font-lock-highlighting-faces)
  2580. (let* ((verilog-type-font-keywords
  2581. (eval-when-compile
  2582. (verilog-regexp-opt
  2583. '(
  2584. "and" "bit" "buf" "bufif0" "bufif1" "cmos" "defparam"
  2585. "event" "genvar" "inout" "input" "integer" "localparam"
  2586. "logic" "mailbox" "nand" "nmos" "not" "notif0" "notif1" "or"
  2587. "output" "parameter" "pmos" "pull0" "pull1" "pulldown" "pullup"
  2588. "rcmos" "real" "realtime" "reg" "rnmos" "rpmos" "rtran"
  2589. "rtranif0" "rtranif1" "semaphore" "signed" "struct" "supply"
  2590. "supply0" "supply1" "time" "tran" "tranif0" "tranif1"
  2591. "tri" "tri0" "tri1" "triand" "trior" "trireg" "typedef"
  2592. "uwire" "vectored" "wand" "wire" "wor" "xnor" "xor"
  2593. ) nil )))
  2594. (verilog-pragma-keywords
  2595. (eval-when-compile
  2596. (verilog-regexp-opt
  2597. '("surefire" "synopsys" "rtl_synthesis" "verilint" "leda" "0in") nil
  2598. )))
  2599. (verilog-1800-2005-keywords
  2600. (eval-when-compile
  2601. (verilog-regexp-opt
  2602. '("alias" "assert" "assume" "automatic" "before" "bind"
  2603. "bins" "binsof" "break" "byte" "cell" "chandle" "class"
  2604. "clocking" "config" "const" "constraint" "context" "continue"
  2605. "cover" "covergroup" "coverpoint" "cross" "deassign" "design"
  2606. "dist" "do" "edge" "endclass" "endclocking" "endconfig"
  2607. "endgroup" "endprogram" "endproperty" "endsequence" "enum"
  2608. "expect" "export" "extends" "extern" "first_match" "foreach"
  2609. "forkjoin" "genvar" "highz0" "highz1" "ifnone" "ignore_bins"
  2610. "illegal_bins" "import" "incdir" "include" "inside" "instance"
  2611. "int" "intersect" "large" "liblist" "library" "local" "longint"
  2612. "matches" "medium" "modport" "new" "noshowcancelled" "null"
  2613. "packed" "program" "property" "protected" "pull0" "pull1"
  2614. "pulsestyle_onevent" "pulsestyle_ondetect" "pure" "rand" "randc"
  2615. "randcase" "randsequence" "ref" "release" "return" "scalared"
  2616. "sequence" "shortint" "shortreal" "showcancelled" "small" "solve"
  2617. "specparam" "static" "string" "strong0" "strong1" "struct"
  2618. "super" "tagged" "this" "throughout" "timeprecision" "timeunit"
  2619. "type" "union" "unsigned" "use" "var" "virtual" "void"
  2620. "wait_order" "weak0" "weak1" "wildcard" "with" "within"
  2621. ) nil )))
  2622. (verilog-1800-2009-keywords
  2623. (eval-when-compile
  2624. (verilog-regexp-opt
  2625. '("accept_on" "checker" "endchecker" "eventually" "global"
  2626. "implies" "let" "nexttime" "reject_on" "restrict" "s_always"
  2627. "s_eventually" "s_nexttime" "s_until" "s_until_with" "strong"
  2628. "sync_accept_on" "sync_reject_on" "unique0" "until"
  2629. "until_with" "untyped" "weak" ) nil )))
  2630. (verilog-ams-keywords
  2631. (eval-when-compile
  2632. (verilog-regexp-opt
  2633. '("above" "abs" "absdelay" "acos" "acosh" "ac_stim"
  2634. "aliasparam" "analog" "analysis" "asin" "asinh" "atan" "atan2" "atanh"
  2635. "branch" "ceil" "connectmodule" "connectrules" "cos" "cosh" "ddt"
  2636. "ddx" "discipline" "driver_update" "enddiscipline" "endconnectrules"
  2637. "endnature" "endparamset" "exclude" "exp" "final_step" "flicker_noise"
  2638. "floor" "flow" "from" "ground" "hypot" "idt" "idtmod" "inf"
  2639. "initial_step" "laplace_nd" "laplace_np" "laplace_zd" "laplace_zp"
  2640. "last_crossing" "limexp" "ln" "log" "max" "min" "nature"
  2641. "net_resolution" "noise_table" "paramset" "potential" "pow" "sin"
  2642. "sinh" "slew" "sqrt" "tan" "tanh" "timer" "transition" "white_noise"
  2643. "wreal" "zi_nd" "zi_np" "zi_zd" ) nil )))
  2644. (verilog-font-keywords
  2645. (eval-when-compile
  2646. (verilog-regexp-opt
  2647. '(
  2648. "assign" "case" "casex" "casez" "randcase" "deassign"
  2649. "default" "disable" "else" "endcase" "endfunction"
  2650. "endgenerate" "endinterface" "endmodule" "endprimitive"
  2651. "endspecify" "endtable" "endtask" "final" "for" "force" "return" "break"
  2652. "continue" "forever" "fork" "function" "generate" "if" "iff" "initial"
  2653. "interface" "join" "join_any" "join_none" "macromodule" "module" "negedge"
  2654. "package" "endpackage" "always" "always_comb" "always_ff"
  2655. "always_latch" "posedge" "primitive" "priority" "release"
  2656. "repeat" "specify" "table" "task" "unique" "wait" "while"
  2657. "class" "program" "endclass" "endprogram"
  2658. ) nil )))
  2659. (verilog-font-grouping-keywords
  2660. (eval-when-compile
  2661. (verilog-regexp-opt
  2662. '( "begin" "end" ) nil ))))
  2663. (setq verilog-font-lock-keywords
  2664. (list
  2665. ;; Fontify all builtin keywords
  2666. (concat "\\<\\(" verilog-font-keywords "\\|"
  2667. ;; And user/system tasks and functions
  2668. "\\$[a-zA-Z][a-zA-Z0-9_\\$]*"
  2669. "\\)\\>")
  2670. ;; Fontify all types
  2671. (if verilog-highlight-grouping-keywords
  2672. (cons (concat "\\<\\(" verilog-font-grouping-keywords "\\)\\>")
  2673. 'verilog-font-lock-ams-face)
  2674. (cons (concat "\\<\\(" verilog-font-grouping-keywords "\\)\\>")
  2675. 'font-lock-type-face))
  2676. (cons (concat "\\<\\(" verilog-type-font-keywords "\\)\\>")
  2677. 'font-lock-type-face)
  2678. ;; Fontify IEEE-1800-2005 keywords appropriately
  2679. (if verilog-highlight-p1800-keywords
  2680. (cons (concat "\\<\\(" verilog-1800-2005-keywords "\\)\\>")
  2681. 'verilog-font-lock-p1800-face)
  2682. (cons (concat "\\<\\(" verilog-1800-2005-keywords "\\)\\>")
  2683. 'font-lock-type-face))
  2684. ;; Fontify IEEE-1800-2009 keywords appropriately
  2685. (if verilog-highlight-p1800-keywords
  2686. (cons (concat "\\<\\(" verilog-1800-2009-keywords "\\)\\>")
  2687. 'verilog-font-lock-p1800-face)
  2688. (cons (concat "\\<\\(" verilog-1800-2009-keywords "\\)\\>")
  2689. 'font-lock-type-face))
  2690. ;; Fontify Verilog-AMS keywords
  2691. (cons (concat "\\<\\(" verilog-ams-keywords "\\)\\>")
  2692. 'verilog-font-lock-ams-face)))
  2693. (setq verilog-font-lock-keywords-1
  2694. (append verilog-font-lock-keywords
  2695. (list
  2696. ;; Fontify module definitions
  2697. (list
  2698. "\\<\\(\\(macro\\)?module\\|primitive\\|class\\|program\\|interface\\|package\\|task\\)\\>\\s-*\\(\\sw+\\)"
  2699. '(1 font-lock-keyword-face)
  2700. '(3 font-lock-function-name-face 'prepend))
  2701. ;; Fontify function definitions
  2702. (list
  2703. (concat "\\<function\\>\\s-+\\(integer\\|real\\(time\\)?\\|time\\)\\s-+\\(\\sw+\\)" )
  2704. '(1 font-lock-keyword-face)
  2705. '(3 font-lock-constant-face prepend))
  2706. '("\\<function\\>\\s-+\\(\\[[^]]+\\]\\)\\s-+\\(\\sw+\\)"
  2707. (1 font-lock-keyword-face)
  2708. (2 font-lock-constant-face append))
  2709. '("\\<function\\>\\s-+\\(\\sw+\\)"
  2710. 1 'font-lock-constant-face append))))
  2711. (setq verilog-font-lock-keywords-2
  2712. (append verilog-font-lock-keywords-1
  2713. (list
  2714. ;; Fontify pragmas
  2715. (concat "\\(//\\s-*" verilog-pragma-keywords "\\s-.*\\)")
  2716. ;; Fontify escaped names
  2717. '("\\(\\\\\\S-*\\s-\\)" 0 font-lock-function-name-face)
  2718. ;; Fontify macro definitions/ uses
  2719. '("`\\s-*[A-Za-z][A-Za-z0-9_]*" 0 (if (boundp 'font-lock-preprocessor-face)
  2720. 'font-lock-preprocessor-face
  2721. 'font-lock-type-face))
  2722. ;; Fontify delays/numbers
  2723. '("\\(@\\)\\|\\(#\\s-*\\(\\(\[0-9_.\]+\\('s?[hdxbo][0-9a-fA-F_xz]*\\)?\\)\\|\\(([^()]+)\\|\\sw+\\)\\)\\)"
  2724. 0 font-lock-type-face append)
  2725. ;; Fontify instantiation names
  2726. '("\\([A-Za-z][A-Za-z0-9_]*\\)\\s-*(" 1 font-lock-function-name-face)
  2727. )))
  2728. (setq verilog-font-lock-keywords-3
  2729. (append verilog-font-lock-keywords-2
  2730. (when verilog-highlight-translate-off
  2731. (list
  2732. ;; Fontify things in translate off regions
  2733. '(verilog-match-translate-off
  2734. (0 'verilog-font-lock-translate-off-face prepend))
  2735. )))))
  2736. ;;
  2737. ;; Buffer state preservation
  2738. (defmacro verilog-save-buffer-state (&rest body)
  2739. "Execute BODY forms, saving state around insignificant change.
  2740. Changes in text properties like `face' or `syntax-table' are
  2741. considered insignificant. This macro allows text properties to
  2742. be changed, even in a read-only buffer.
  2743. A change is considered significant if it affects the buffer text
  2744. in any way that isn't completely restored again. Any
  2745. user-visible changes to the buffer must not be within a
  2746. `verilog-save-buffer-state'."
  2747. ;; From c-save-buffer-state
  2748. `(let* ((modified (buffer-modified-p))
  2749. (buffer-undo-list t)
  2750. (inhibit-read-only t)
  2751. (inhibit-point-motion-hooks t)
  2752. (verilog-no-change-functions t)
  2753. before-change-functions
  2754. after-change-functions
  2755. deactivate-mark
  2756. buffer-file-name ; Prevent primitives checking
  2757. buffer-file-truename) ; for file modification
  2758. (unwind-protect
  2759. (progn ,@body)
  2760. (and (not modified)
  2761. (buffer-modified-p)
  2762. (set-buffer-modified-p nil)))))
  2763. (defmacro verilog-save-no-change-functions (&rest body)
  2764. "Execute BODY forms, disabling all change hooks in BODY.
  2765. For insignificant changes, see instead `verilog-save-buffer-state'."
  2766. `(let* ((inhibit-point-motion-hooks t)
  2767. (verilog-no-change-functions t)
  2768. before-change-functions
  2769. after-change-functions)
  2770. (progn ,@body)))
  2771. ;;
  2772. ;; Comment detection and caching
  2773. (defvar verilog-scan-cache-preserving nil
  2774. "If set, the specified buffer's comment properties are static.
  2775. Buffer changes will be ignored. See `verilog-inside-comment-or-string-p'
  2776. and `verilog-scan'.")
  2777. (defvar verilog-scan-cache-tick nil
  2778. "Modification tick at which `verilog-scan' was last completed.")
  2779. (make-variable-buffer-local 'verilog-scan-cache-tick)
  2780. (defun verilog-scan-cache-flush ()
  2781. "Flush the `verilog-scan' cache."
  2782. (setq verilog-scan-cache-tick nil))
  2783. (defun verilog-scan-cache-ok-p ()
  2784. "Return t iff the scan cache is up to date."
  2785. (or (and verilog-scan-cache-preserving
  2786. (eq verilog-scan-cache-preserving (current-buffer))
  2787. verilog-scan-cache-tick)
  2788. (equal verilog-scan-cache-tick (buffer-chars-modified-tick))))
  2789. (defmacro verilog-save-scan-cache (&rest body)
  2790. "Execute the BODY forms, allowing scan cache preservation within BODY.
  2791. This requires that insertions must use `verilog-insert'."
  2792. ;; If the buffer is out of date, trash it, as we'll not check later the tick
  2793. ;; Note this must work properly if there's multiple layers of calls
  2794. ;; to verilog-save-scan-cache even with differing ticks.
  2795. `(progn
  2796. (unless (verilog-scan-cache-ok-p) ;; Must be before let
  2797. (setq verilog-scan-cache-tick nil))
  2798. (let* ((verilog-scan-cache-preserving (current-buffer)))
  2799. (progn ,@body))))
  2800. (defun verilog-scan-region (beg end)
  2801. "Parse between BEG and END for `verilog-inside-comment-or-string-p'.
  2802. This creates v-cmts properties where comments are in force."
  2803. ;; Why properties and not overlays? Overlays have much slower non O(1)
  2804. ;; lookup times.
  2805. ;; This function is warm - called on every verilog-insert
  2806. (save-excursion
  2807. (save-match-data
  2808. (verilog-save-buffer-state
  2809. (let (pt)
  2810. (goto-char beg)
  2811. (while (< (point) end)
  2812. (cond ((looking-at "//")
  2813. (setq pt (point))
  2814. (or (search-forward "\n" end t)
  2815. (goto-char end))
  2816. ;; "1+": The leading // or /* itself isn't considered as
  2817. ;; being "inside" the comment, so that a (search-backward)
  2818. ;; that lands at the start of the // won't mis-indicate
  2819. ;; it's inside a comment. Also otherwise it would be
  2820. ;; hard to find a commented out /*AS*/ vs one that isn't
  2821. (put-text-property (1+ pt) (point) 'v-cmts t))
  2822. ((looking-at "/\\*")
  2823. (setq pt (point))
  2824. (or (search-forward "*/" end t)
  2825. ;; No error - let later code indicate it so we can
  2826. ;; use inside functions on-the-fly
  2827. ;;(error "%s: Unmatched /* */, at char %d"
  2828. ;; (verilog-point-text) (point))
  2829. (goto-char end))
  2830. (put-text-property (1+ pt) (point) 'v-cmts t))
  2831. ((looking-at "\"")
  2832. (setq pt (point))
  2833. (or (re-search-forward "[^\\]\"" end t) ;; don't forward-char first, since we look for a non backslash first
  2834. ;; No error - let later code indicate it so we can
  2835. (goto-char end))
  2836. (put-text-property (1+ pt) (point) 'v-cmts t))
  2837. (t
  2838. (forward-char 1)
  2839. (if (re-search-forward "[/\"]" end t)
  2840. (backward-char 1)
  2841. (goto-char end))))))))))
  2842. (defun verilog-scan ()
  2843. "Parse the buffer, marking all comments with properties.
  2844. Also assumes any text inserted since `verilog-scan-cache-tick'
  2845. either is ok to parse as a non-comment, or `verilog-insert' was used."
  2846. ;; See also `verilog-scan-debug' and `verilog-scan-and-debug'
  2847. (unless (verilog-scan-cache-ok-p)
  2848. (save-excursion
  2849. (verilog-save-buffer-state
  2850. (when verilog-debug
  2851. (message "Scanning %s cache=%s cachetick=%S tick=%S" (current-buffer)
  2852. verilog-scan-cache-preserving verilog-scan-cache-tick
  2853. (buffer-chars-modified-tick)))
  2854. (remove-text-properties (point-min) (point-max) '(v-cmts nil))
  2855. (verilog-scan-region (point-min) (point-max))
  2856. (setq verilog-scan-cache-tick (buffer-chars-modified-tick))
  2857. (when verilog-debug (message "Scanning... done"))))))
  2858. (defun verilog-scan-debug ()
  2859. "For debugging, show with display face results of `verilog-scan'."
  2860. (font-lock-mode 0)
  2861. ;;(if dbg (setq dbg (concat dbg (format "verilog-scan-debug\n"))))
  2862. (save-excursion
  2863. (goto-char (point-min))
  2864. (remove-text-properties (point-min) (point-max) '(face nil))
  2865. (while (not (eobp))
  2866. (cond ((get-text-property (point) 'v-cmts)
  2867. (put-text-property (point) (1+ (point)) `face 'underline)
  2868. ;;(if dbg (setq dbg (concat dbg (format " v-cmts at %S\n" (point)))))
  2869. (forward-char 1))
  2870. (t
  2871. (goto-char (or (next-property-change (point)) (point-max))))))))
  2872. (defun verilog-scan-and-debug ()
  2873. "For debugging, run `verilog-scan' and `verilog-scan-debug'."
  2874. (let (verilog-scan-cache-preserving
  2875. verilog-scan-cache-tick)
  2876. (goto-char (point-min))
  2877. (verilog-scan)
  2878. (verilog-scan-debug)))
  2879. (defun verilog-inside-comment-or-string-p (&optional pos)
  2880. "Check if optional point POS is inside a comment.
  2881. This may require a slow pre-parse of the buffer with `verilog-scan'
  2882. to establish comment properties on all text."
  2883. ;; This function is very hot
  2884. (verilog-scan)
  2885. (if pos
  2886. (and (>= pos (point-min))
  2887. (get-text-property pos 'v-cmts))
  2888. (get-text-property (point) 'v-cmts)))
  2889. (defun verilog-insert (&rest stuff)
  2890. "Insert STUFF arguments, tracking for `verilog-inside-comment-or-string-p'.
  2891. Any insert that includes a comment must have the entire commente
  2892. inserted using a single call to `verilog-insert'."
  2893. (let ((pt (point)))
  2894. (while stuff
  2895. (insert (car stuff))
  2896. (setq stuff (cdr stuff)))
  2897. (verilog-scan-region pt (point))))
  2898. ;; More searching
  2899. (defun verilog-declaration-end ()
  2900. (search-forward ";"))
  2901. (defun verilog-point-text (&optional pointnum)
  2902. "Return text describing where POINTNUM or current point is (for errors).
  2903. Use filename, if current buffer being edited shorten to just buffer name."
  2904. (concat (or (and (equal (window-buffer (selected-window)) (current-buffer))
  2905. (buffer-name))
  2906. buffer-file-name
  2907. (buffer-name))
  2908. ":" (int-to-string (1+ (count-lines (point-min) (or pointnum (point)))))))
  2909. (defun electric-verilog-backward-sexp ()
  2910. "Move backward over one balanced expression."
  2911. (interactive)
  2912. ;; before that see if we are in a comment
  2913. (verilog-backward-sexp))
  2914. (defun electric-verilog-forward-sexp ()
  2915. "Move forward over one balanced expression."
  2916. (interactive)
  2917. ;; before that see if we are in a comment
  2918. (verilog-forward-sexp))
  2919. ;;;used by hs-minor-mode
  2920. (defun verilog-forward-sexp-function (arg)
  2921. (if (< arg 0)
  2922. (verilog-backward-sexp)
  2923. (verilog-forward-sexp)))
  2924. (defun verilog-backward-sexp ()
  2925. (let ((reg)
  2926. (elsec 1)
  2927. (found nil)
  2928. (st (point)))
  2929. (if (not (looking-at "\\<"))
  2930. (forward-word -1))
  2931. (cond
  2932. ((verilog-skip-backward-comment-or-string))
  2933. ((looking-at "\\<else\\>")
  2934. (setq reg (concat
  2935. verilog-end-block-re
  2936. "\\|\\(\\<else\\>\\)"
  2937. "\\|\\(\\<if\\>\\)"))
  2938. (while (and (not found)
  2939. (verilog-re-search-backward reg nil 'move))
  2940. (cond
  2941. ((match-end 1) ; matched verilog-end-block-re
  2942. ; try to leap back to matching outward block by striding across
  2943. ; indent level changing tokens then immediately
  2944. ; previous line governs indentation.
  2945. (verilog-leap-to-head))
  2946. ((match-end 2) ; else, we're in deep
  2947. (setq elsec (1+ elsec)))
  2948. ((match-end 3) ; found it
  2949. (setq elsec (1- elsec))
  2950. (if (= 0 elsec)
  2951. ;; Now previous line describes syntax
  2952. (setq found 't))))))
  2953. ((looking-at verilog-end-block-re)
  2954. (verilog-leap-to-head))
  2955. ((looking-at "\\(endmodule\\>\\)\\|\\(\\<endprimitive\\>\\)\\|\\(\\<endclass\\>\\)\\|\\(\\<endprogram\\>\\)\\|\\(\\<endinterface\\>\\)\\|\\(\\<endpackage\\>\\)")
  2956. (cond
  2957. ((match-end 1)
  2958. (verilog-re-search-backward "\\<\\(macro\\)?module\\>" nil 'move))
  2959. ((match-end 2)
  2960. (verilog-re-search-backward "\\<primitive\\>" nil 'move))
  2961. ((match-end 3)
  2962. (verilog-re-search-backward "\\<class\\>" nil 'move))
  2963. ((match-end 4)
  2964. (verilog-re-search-backward "\\<program\\>" nil 'move))
  2965. ((match-end 5)
  2966. (verilog-re-search-backward "\\<interface\\>" nil 'move))
  2967. ((match-end 6)
  2968. (verilog-re-search-backward "\\<package\\>" nil 'move))
  2969. (t
  2970. (goto-char st)
  2971. (backward-sexp 1))))
  2972. (t
  2973. (goto-char st)
  2974. (backward-sexp)))))
  2975. (defun verilog-forward-sexp ()
  2976. (let ((reg)
  2977. (md 2)
  2978. (st (point))
  2979. (nest 'yes))
  2980. (if (not (looking-at "\\<"))
  2981. (forward-word -1))
  2982. (cond
  2983. ((verilog-skip-forward-comment-or-string)
  2984. (verilog-forward-syntactic-ws))
  2985. ((looking-at verilog-beg-block-re-ordered)
  2986. (cond
  2987. ((match-end 1);
  2988. ;; Search forward for matching end
  2989. (setq reg "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)" ))
  2990. ((match-end 2)
  2991. ;; Search forward for matching endcase
  2992. (setq reg "\\(\\<randcase\\>\\|\\(\\<unique\\>\\s-+\\|\\<priority\\>\\s-+\\)?\\<case[xz]?\\>[^:]\\)\\|\\(\\<endcase\\>\\)" )
  2993. (setq md 3) ;; ender is third item in regexp
  2994. )
  2995. ((match-end 4)
  2996. ;; might be "disable fork" or "wait fork"
  2997. (let
  2998. (here)
  2999. (if (or
  3000. (looking-at verilog-disable-fork-re)
  3001. (and (looking-at "fork")
  3002. (progn
  3003. (setq here (point)) ;; sometimes a fork is just a fork
  3004. (forward-word -1)
  3005. (looking-at verilog-disable-fork-re))))
  3006. (progn ;; it is a disable fork; ignore it
  3007. (goto-char (match-end 0))
  3008. (forward-word 1)
  3009. (setq reg nil))
  3010. (progn ;; it is a nice simple fork
  3011. (goto-char here) ;; return from looking for "disable fork"
  3012. ;; Search forward for matching join
  3013. (setq reg "\\(\\<fork\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)" )))))
  3014. ((match-end 6)
  3015. ;; Search forward for matching endclass
  3016. (setq reg "\\(\\<class\\>\\)\\|\\(\\<endclass\\>\\)" ))
  3017. ((match-end 7)
  3018. ;; Search forward for matching endtable
  3019. (setq reg "\\<endtable\\>" )
  3020. (setq nest 'no))
  3021. ((match-end 8)
  3022. ;; Search forward for matching endspecify
  3023. (setq reg "\\(\\<specify\\>\\)\\|\\(\\<endspecify\\>\\)" ))
  3024. ((match-end 9)
  3025. ;; Search forward for matching endfunction
  3026. (setq reg "\\<endfunction\\>" )
  3027. (setq nest 'no))
  3028. ((match-end 10)
  3029. ;; Search forward for matching endfunction
  3030. (setq reg "\\<endfunction\\>" )
  3031. (setq nest 'no))
  3032. ((match-end 14)
  3033. ;; Search forward for matching endtask
  3034. (setq reg "\\<endtask\\>" )
  3035. (setq nest 'no))
  3036. ((match-end 15)
  3037. ;; Search forward for matching endtask
  3038. (setq reg "\\<endtask\\>" )
  3039. (setq nest 'no))
  3040. ((match-end 19)
  3041. ;; Search forward for matching endgenerate
  3042. (setq reg "\\(\\<generate\\>\\)\\|\\(\\<endgenerate\\>\\)" ))
  3043. ((match-end 20)
  3044. ;; Search forward for matching endgroup
  3045. (setq reg "\\(\\<covergroup\\>\\)\\|\\(\\<endgroup\\>\\)" ))
  3046. ((match-end 21)
  3047. ;; Search forward for matching endproperty
  3048. (setq reg "\\(\\<property\\>\\)\\|\\(\\<endproperty\\>\\)" ))
  3049. ((match-end 25)
  3050. ;; Search forward for matching endsequence
  3051. (setq reg "\\(\\<\\(rand\\)?sequence\\>\\)\\|\\(\\<endsequence\\>\\)" )
  3052. (setq md 3)) ; 3 to get to endsequence in the reg above
  3053. ((match-end 27)
  3054. ;; Search forward for matching endclocking
  3055. (setq reg "\\(\\<clocking\\>\\)\\|\\(\\<endclocking\\>\\)" )))
  3056. (if (and reg
  3057. (forward-word 1))
  3058. (catch 'skip
  3059. (if (eq nest 'yes)
  3060. (let ((depth 1)
  3061. here)
  3062. (while (verilog-re-search-forward reg nil 'move)
  3063. (cond
  3064. ((match-end md) ; a closer in regular expression, so we are climbing out
  3065. (setq depth (1- depth))
  3066. (if (= 0 depth) ; we are out!
  3067. (throw 'skip 1)))
  3068. ((match-end 1) ; an opener in the r-e, so we are in deeper now
  3069. (setq here (point)) ; remember where we started
  3070. (goto-char (match-beginning 1))
  3071. (cond
  3072. ((if (or
  3073. (looking-at verilog-disable-fork-re)
  3074. (and (looking-at "fork")
  3075. (progn
  3076. (forward-word -1)
  3077. (looking-at verilog-disable-fork-re))))
  3078. (progn ;; it is a disable fork; another false alarm
  3079. (goto-char (match-end 0)))
  3080. (progn ;; it is a simple fork (or has nothing to do with fork)
  3081. (goto-char here)
  3082. (setq depth (1+ depth))))))))))
  3083. (if (verilog-re-search-forward reg nil 'move)
  3084. (throw 'skip 1))))))
  3085. ((looking-at (concat
  3086. "\\(\\<\\(macro\\)?module\\>\\)\\|"
  3087. "\\(\\<primitive\\>\\)\\|"
  3088. "\\(\\<class\\>\\)\\|"
  3089. "\\(\\<program\\>\\)\\|"
  3090. "\\(\\<interface\\>\\)\\|"
  3091. "\\(\\<package\\>\\)"))
  3092. (cond
  3093. ((match-end 1)
  3094. (verilog-re-search-forward "\\<endmodule\\>" nil 'move))
  3095. ((match-end 2)
  3096. (verilog-re-search-forward "\\<endprimitive\\>" nil 'move))
  3097. ((match-end 3)
  3098. (verilog-re-search-forward "\\<endclass\\>" nil 'move))
  3099. ((match-end 4)
  3100. (verilog-re-search-forward "\\<endprogram\\>" nil 'move))
  3101. ((match-end 5)
  3102. (verilog-re-search-forward "\\<endinterface\\>" nil 'move))
  3103. ((match-end 6)
  3104. (verilog-re-search-forward "\\<endpackage\\>" nil 'move))
  3105. (t
  3106. (goto-char st)
  3107. (if (= (following-char) ?\) )
  3108. (forward-char 1)
  3109. (forward-sexp 1)))))
  3110. (t
  3111. (goto-char st)
  3112. (if (= (following-char) ?\) )
  3113. (forward-char 1)
  3114. (forward-sexp 1))))))
  3115. (defun verilog-declaration-beg ()
  3116. (verilog-re-search-backward verilog-declaration-re (bobp) t))
  3117. ;;
  3118. ;;
  3119. ;; Mode
  3120. ;;
  3121. (defvar verilog-which-tool 1)
  3122. ;;;###autoload
  3123. (define-derived-mode verilog-mode prog-mode "Verilog"
  3124. "Major mode for editing Verilog code.
  3125. \\<verilog-mode-map>
  3126. See \\[describe-function] verilog-auto (\\[verilog-auto]) for details on how
  3127. AUTOs can improve coding efficiency.
  3128. Use \\[verilog-faq] for a pointer to frequently asked questions.
  3129. NEWLINE, TAB indents for Verilog code.
  3130. Delete converts tabs to spaces as it moves back.
  3131. Supports highlighting.
  3132. Turning on Verilog mode calls the value of the variable `verilog-mode-hook'
  3133. with no args, if that value is non-nil.
  3134. Variables controlling indentation/edit style:
  3135. variable `verilog-indent-level' (default 3)
  3136. Indentation of Verilog statements with respect to containing block.
  3137. `verilog-indent-level-module' (default 3)
  3138. Absolute indentation of Module level Verilog statements.
  3139. Set to 0 to get initial and always statements lined up
  3140. on the left side of your screen.
  3141. `verilog-indent-level-declaration' (default 3)
  3142. Indentation of declarations with respect to containing block.
  3143. Set to 0 to get them list right under containing block.
  3144. `verilog-indent-level-behavioral' (default 3)
  3145. Indentation of first begin in a task or function block
  3146. Set to 0 to get such code to lined up underneath the task or
  3147. function keyword.
  3148. `verilog-indent-level-directive' (default 1)
  3149. Indentation of `ifdef/`endif blocks.
  3150. `verilog-cexp-indent' (default 1)
  3151. Indentation of Verilog statements broken across lines i.e.:
  3152. if (a)
  3153. begin
  3154. `verilog-case-indent' (default 2)
  3155. Indentation for case statements.
  3156. `verilog-auto-newline' (default nil)
  3157. Non-nil means automatically newline after semicolons and the punctuation
  3158. mark after an end.
  3159. `verilog-auto-indent-on-newline' (default t)
  3160. Non-nil means automatically indent line after newline.
  3161. `verilog-tab-always-indent' (default t)
  3162. Non-nil means TAB in Verilog mode should always reindent the current line,
  3163. regardless of where in the line point is when the TAB command is used.
  3164. `verilog-indent-begin-after-if' (default t)
  3165. Non-nil means to indent begin statements following a preceding
  3166. if, else, while, for and repeat statements, if any. Otherwise,
  3167. the begin is lined up with the preceding token. If t, you get:
  3168. if (a)
  3169. begin // amount of indent based on `verilog-cexp-indent'
  3170. otherwise you get:
  3171. if (a)
  3172. begin
  3173. `verilog-auto-endcomments' (default t)
  3174. Non-nil means a comment /* ... */ is set after the ends which ends
  3175. cases, tasks, functions and modules.
  3176. The type and name of the object will be set between the braces.
  3177. `verilog-minimum-comment-distance' (default 10)
  3178. Minimum distance (in lines) between begin and end required before a comment
  3179. will be inserted. Setting this variable to zero results in every
  3180. end acquiring a comment; the default avoids too many redundant
  3181. comments in tight quarters.
  3182. `verilog-auto-lineup' (default 'declarations)
  3183. List of contexts where auto lineup of code should be done.
  3184. Variables controlling other actions:
  3185. `verilog-linter' (default surelint)
  3186. Unix program to call to run the lint checker. This is the default
  3187. command for \\[compile-command] and \\[verilog-auto-save-compile].
  3188. See \\[customize] for the complete list of variables.
  3189. AUTO expansion functions are, in part:
  3190. \\[verilog-auto] Expand AUTO statements.
  3191. \\[verilog-delete-auto] Remove the AUTOs.
  3192. \\[verilog-inject-auto] Insert AUTOs for the first time.
  3193. Some other functions are:
  3194. \\[verilog-complete-word] Complete word with appropriate possibilities.
  3195. \\[verilog-mark-defun] Mark function.
  3196. \\[verilog-beg-of-defun] Move to beginning of current function.
  3197. \\[verilog-end-of-defun] Move to end of current function.
  3198. \\[verilog-label-be] Label matching begin ... end, fork ... join, etc statements.
  3199. \\[verilog-comment-region] Put marked area in a comment.
  3200. \\[verilog-uncomment-region] Uncomment an area commented with \\[verilog-comment-region].
  3201. \\[verilog-insert-block] Insert begin ... end.
  3202. \\[verilog-star-comment] Insert /* ... */.
  3203. \\[verilog-sk-always] Insert an always @(AS) begin .. end block.
  3204. \\[verilog-sk-begin] Insert a begin .. end block.
  3205. \\[verilog-sk-case] Insert a case block, prompting for details.
  3206. \\[verilog-sk-for] Insert a for (...) begin .. end block, prompting for details.
  3207. \\[verilog-sk-generate] Insert a generate .. endgenerate block.
  3208. \\[verilog-sk-header] Insert a header block at the top of file.
  3209. \\[verilog-sk-initial] Insert an initial begin .. end block.
  3210. \\[verilog-sk-fork] Insert a fork begin .. end .. join block.
  3211. \\[verilog-sk-module] Insert a module .. (/*AUTOARG*/);.. endmodule block.
  3212. \\[verilog-sk-ovm-class] Insert an OVM Class block.
  3213. \\[verilog-sk-uvm-class] Insert an UVM Class block.
  3214. \\[verilog-sk-primitive] Insert a primitive .. (.. );.. endprimitive block.
  3215. \\[verilog-sk-repeat] Insert a repeat (..) begin .. end block.
  3216. \\[verilog-sk-specify] Insert a specify .. endspecify block.
  3217. \\[verilog-sk-task] Insert a task .. begin .. end endtask block.
  3218. \\[verilog-sk-while] Insert a while (...) begin .. end block, prompting for details.
  3219. \\[verilog-sk-casex] Insert a casex (...) item: begin.. end endcase block, prompting for details.
  3220. \\[verilog-sk-casez] Insert a casez (...) item: begin.. end endcase block, prompting for details.
  3221. \\[verilog-sk-if] Insert an if (..) begin .. end block.
  3222. \\[verilog-sk-else-if] Insert an else if (..) begin .. end block.
  3223. \\[verilog-sk-comment] Insert a comment block.
  3224. \\[verilog-sk-assign] Insert an assign .. = ..; statement.
  3225. \\[verilog-sk-function] Insert a function .. begin .. end endfunction block.
  3226. \\[verilog-sk-input] Insert an input declaration, prompting for details.
  3227. \\[verilog-sk-output] Insert an output declaration, prompting for details.
  3228. \\[verilog-sk-state-machine] Insert a state machine definition, prompting for details.
  3229. \\[verilog-sk-inout] Insert an inout declaration, prompting for details.
  3230. \\[verilog-sk-wire] Insert a wire declaration, prompting for details.
  3231. \\[verilog-sk-reg] Insert a register declaration, prompting for details.
  3232. \\[verilog-sk-define-signal] Define signal under point as a register at the top of the module.
  3233. All key bindings can be seen in a Verilog-buffer with \\[describe-bindings].
  3234. Key bindings specific to `verilog-mode-map' are:
  3235. \\{verilog-mode-map}"
  3236. :abbrev-table verilog-mode-abbrev-table
  3237. (set (make-local-variable 'beginning-of-defun-function)
  3238. 'verilog-beg-of-defun)
  3239. (set (make-local-variable 'end-of-defun-function)
  3240. 'verilog-end-of-defun)
  3241. (set-syntax-table verilog-mode-syntax-table)
  3242. (set (make-local-variable 'indent-line-function)
  3243. #'verilog-indent-line-relative)
  3244. (setq comment-indent-function 'verilog-comment-indent)
  3245. (set (make-local-variable 'parse-sexp-ignore-comments) nil)
  3246. (set (make-local-variable 'comment-start) "// ")
  3247. (set (make-local-variable 'comment-end) "")
  3248. (set (make-local-variable 'comment-start-skip) "/\\*+ *\\|// *")
  3249. (set (make-local-variable 'comment-multi-line) nil)
  3250. ;; Set up for compilation
  3251. (setq verilog-which-tool 1)
  3252. (setq verilog-tool 'verilog-linter)
  3253. (verilog-set-compile-command)
  3254. (when (boundp 'hack-local-variables-hook) ;; Also modify any file-local-variables
  3255. (add-hook 'hack-local-variables-hook 'verilog-modify-compile-command t))
  3256. ;; Setting up menus
  3257. (when (featurep 'xemacs)
  3258. (easy-menu-add verilog-stmt-menu)
  3259. (easy-menu-add verilog-menu)
  3260. (setq mode-popup-menu (cons "Verilog Mode" verilog-stmt-menu)))
  3261. ;; Stuff for GNU Emacs
  3262. (set (make-local-variable 'font-lock-defaults)
  3263. `((verilog-font-lock-keywords verilog-font-lock-keywords-1
  3264. verilog-font-lock-keywords-2
  3265. verilog-font-lock-keywords-3)
  3266. nil nil nil
  3267. ,(if (functionp 'syntax-ppss)
  3268. ;; verilog-beg-of-defun uses syntax-ppss, and syntax-ppss uses
  3269. ;; font-lock-beginning-of-syntax-function, so
  3270. ;; font-lock-beginning-of-syntax-function, can't use
  3271. ;; verilog-beg-of-defun.
  3272. nil
  3273. 'verilog-beg-of-defun)))
  3274. ;;------------------------------------------------------------
  3275. ;; now hook in 'verilog-highlight-include-files (eldo-mode.el&spice-mode.el)
  3276. ;; all buffer local:
  3277. (unless noninteractive ;; Else can't see the result, and change hooks are slow
  3278. (when (featurep 'xemacs)
  3279. (make-local-hook 'font-lock-mode-hook)
  3280. (make-local-hook 'font-lock-after-fontify-buffer-hook); doesn't exist in Emacs
  3281. (make-local-hook 'after-change-functions))
  3282. (add-hook 'font-lock-mode-hook 'verilog-highlight-buffer t t)
  3283. (add-hook 'font-lock-after-fontify-buffer-hook 'verilog-highlight-buffer t t) ; not in Emacs
  3284. (add-hook 'after-change-functions 'verilog-highlight-region t t))
  3285. ;; Tell imenu how to handle Verilog.
  3286. (set (make-local-variable 'imenu-generic-expression)
  3287. verilog-imenu-generic-expression)
  3288. ;; Tell which-func-modes that imenu knows about verilog
  3289. (when (boundp 'which-func-modes)
  3290. (add-to-list 'which-func-modes 'verilog-mode))
  3291. ;; hideshow support
  3292. (when (boundp 'hs-special-modes-alist)
  3293. (unless (assq 'verilog-mode hs-special-modes-alist)
  3294. (setq hs-special-modes-alist
  3295. (cons '(verilog-mode-mode "\\<begin\\>" "\\<end\\>" nil
  3296. verilog-forward-sexp-function)
  3297. hs-special-modes-alist))))
  3298. ;; Stuff for autos
  3299. (add-hook 'write-contents-hooks 'verilog-auto-save-check nil 'local)
  3300. ;; verilog-mode-hook call added by define-derived-mode
  3301. )
  3302. ;;
  3303. ;; Electric functions
  3304. ;;
  3305. (defun electric-verilog-terminate-line (&optional arg)
  3306. "Terminate line and indent next line.
  3307. With optional ARG, remove existing end of line comments."
  3308. (interactive)
  3309. ;; before that see if we are in a comment
  3310. (let ((state (save-excursion (verilog-syntax-ppss))))
  3311. (cond
  3312. ((nth 7 state) ; Inside // comment
  3313. (if (eolp)
  3314. (progn
  3315. (delete-horizontal-space)
  3316. (newline))
  3317. (progn
  3318. (newline)
  3319. (insert "// ")
  3320. (beginning-of-line)))
  3321. (verilog-indent-line))
  3322. ((nth 4 state) ; Inside any comment (hence /**/)
  3323. (newline)
  3324. (verilog-more-comment))
  3325. ((eolp)
  3326. ;; First, check if current line should be indented
  3327. (if (save-excursion
  3328. (delete-horizontal-space)
  3329. (beginning-of-line)
  3330. (skip-chars-forward " \t")
  3331. (if (looking-at verilog-auto-end-comment-lines-re)
  3332. (let ((indent-str (verilog-indent-line)))
  3333. ;; Maybe we should set some endcomments
  3334. (if verilog-auto-endcomments
  3335. (verilog-set-auto-endcomments indent-str arg))
  3336. (end-of-line)
  3337. (delete-horizontal-space)
  3338. (if arg
  3339. ()
  3340. (newline))
  3341. nil)
  3342. (progn
  3343. (end-of-line)
  3344. (delete-horizontal-space)
  3345. 't)))
  3346. ;; see if we should line up assignments
  3347. (progn
  3348. (if (or (eq 'all verilog-auto-lineup)
  3349. (eq 'assignments verilog-auto-lineup))
  3350. (verilog-pretty-expr t "\\(<\\|:\\)?=" ))
  3351. (newline))
  3352. (forward-line 1))
  3353. ;; Indent next line
  3354. (if verilog-auto-indent-on-newline
  3355. (verilog-indent-line)))
  3356. (t
  3357. (newline)))))
  3358. (defun electric-verilog-terminate-and-indent ()
  3359. "Insert a newline and indent for the next statement."
  3360. (interactive)
  3361. (electric-verilog-terminate-line 1))
  3362. (defun electric-verilog-semi ()
  3363. "Insert `;' character and reindent the line."
  3364. (interactive)
  3365. (verilog-insert-last-command-event)
  3366. (if (or (verilog-in-comment-or-string-p)
  3367. (verilog-in-escaped-name-p))
  3368. ()
  3369. (save-excursion
  3370. (beginning-of-line)
  3371. (verilog-forward-ws&directives)
  3372. (verilog-indent-line))
  3373. (if (and verilog-auto-newline
  3374. (not (verilog-parenthesis-depth)))
  3375. (electric-verilog-terminate-line))))
  3376. (defun electric-verilog-semi-with-comment ()
  3377. "Insert `;' character, reindent the line and indent for comment."
  3378. (interactive)
  3379. (insert "\;")
  3380. (save-excursion
  3381. (beginning-of-line)
  3382. (verilog-indent-line))
  3383. (indent-for-comment))
  3384. (defun electric-verilog-colon ()
  3385. "Insert `:' and do all indentations except line indent on this line."
  3386. (interactive)
  3387. (verilog-insert-last-command-event)
  3388. ;; Do nothing if within string.
  3389. (if (or
  3390. (verilog-within-string)
  3391. (not (verilog-in-case-region-p)))
  3392. ()
  3393. (save-excursion
  3394. (let ((p (point))
  3395. (lim (progn (verilog-beg-of-statement) (point))))
  3396. (goto-char p)
  3397. (verilog-backward-case-item lim)
  3398. (verilog-indent-line)))
  3399. ;; (let ((verilog-tab-always-indent nil))
  3400. ;; (verilog-indent-line))
  3401. ))
  3402. ;;(defun electric-verilog-equal ()
  3403. ;; "Insert `=', and do indentation if within block."
  3404. ;; (interactive)
  3405. ;; (verilog-insert-last-command-event)
  3406. ;; Could auto line up expressions, but not yet
  3407. ;; (if (eq (car (verilog-calculate-indent)) 'block)
  3408. ;; (let ((verilog-tab-always-indent nil))
  3409. ;; (verilog-indent-command)))
  3410. ;; )
  3411. (defun electric-verilog-tick ()
  3412. "Insert back-tick, and indent to column 0 if this is a CPP directive."
  3413. (interactive)
  3414. (verilog-insert-last-command-event)
  3415. (save-excursion
  3416. (if (verilog-in-directive-p)
  3417. (verilog-indent-line))))
  3418. (defun electric-verilog-tab ()
  3419. "Function called when TAB is pressed in Verilog mode."
  3420. (interactive)
  3421. ;; If verilog-tab-always-indent, indent the beginning of the line.
  3422. (cond
  3423. ;; The region is active, indent it.
  3424. ((and (region-active-p)
  3425. (not (eq (region-beginning) (region-end))))
  3426. (indent-region (region-beginning) (region-end) nil))
  3427. ((or verilog-tab-always-indent
  3428. (save-excursion
  3429. (skip-chars-backward " \t")
  3430. (bolp)))
  3431. (let* ((oldpnt (point))
  3432. (boi-point
  3433. (save-excursion
  3434. (beginning-of-line)
  3435. (skip-chars-forward " \t")
  3436. (verilog-indent-line)
  3437. (back-to-indentation)
  3438. (point))))
  3439. (if (< (point) boi-point)
  3440. (back-to-indentation)
  3441. (cond ((not verilog-tab-to-comment))
  3442. ((not (eolp))
  3443. (end-of-line))
  3444. (t
  3445. (indent-for-comment)
  3446. (when (and (eolp) (= oldpnt (point)))
  3447. ; kill existing comment
  3448. (beginning-of-line)
  3449. (re-search-forward comment-start-skip oldpnt 'move)
  3450. (goto-char (match-beginning 0))
  3451. (skip-chars-backward " \t")
  3452. (kill-region (point) oldpnt)))))))
  3453. (t (progn (insert "\t")))))
  3454. ;;
  3455. ;; Interactive functions
  3456. ;;
  3457. (defun verilog-indent-buffer ()
  3458. "Indent-region the entire buffer as Verilog code.
  3459. To call this from the command line, see \\[verilog-batch-indent]."
  3460. (interactive)
  3461. (verilog-mode)
  3462. (indent-region (point-min) (point-max) nil))
  3463. (defun verilog-insert-block ()
  3464. "Insert Verilog begin ... end; block in the code with right indentation."
  3465. (interactive)
  3466. (verilog-indent-line)
  3467. (insert "begin")
  3468. (electric-verilog-terminate-line)
  3469. (save-excursion
  3470. (electric-verilog-terminate-line)
  3471. (insert "end")
  3472. (beginning-of-line)
  3473. (verilog-indent-line)))
  3474. (defun verilog-star-comment ()
  3475. "Insert Verilog star comment at point."
  3476. (interactive)
  3477. (verilog-indent-line)
  3478. (insert "/*")
  3479. (save-excursion
  3480. (newline)
  3481. (insert " */"))
  3482. (newline)
  3483. (insert " * "))
  3484. (defun verilog-insert-1 (fmt max)
  3485. "Use format string FMT to insert integers 0 to MAX - 1.
  3486. Inserts one integer per line, at the current column. Stops early
  3487. if it reaches the end of the buffer."
  3488. (let ((col (current-column))
  3489. (n 0))
  3490. (save-excursion
  3491. (while (< n max)
  3492. (insert (format fmt n))
  3493. (forward-line 1)
  3494. ;; Note that this function does not bother to check for lines
  3495. ;; shorter than col.
  3496. (if (eobp)
  3497. (setq n max)
  3498. (setq n (1+ n))
  3499. (move-to-column col))))))
  3500. (defun verilog-insert-indices (max)
  3501. "Insert a set of indices into a rectangle.
  3502. The upper left corner is defined by point. Indices begin with 0
  3503. and extend to the MAX - 1. If no prefix arg is given, the user
  3504. is prompted for a value. The indices are surrounded by square
  3505. brackets \[]. For example, the following code with the point
  3506. located after the first 'a' gives:
  3507. a = b a[ 0] = b
  3508. a = b a[ 1] = b
  3509. a = b a[ 2] = b
  3510. a = b a[ 3] = b
  3511. a = b ==> insert-indices ==> a[ 4] = b
  3512. a = b a[ 5] = b
  3513. a = b a[ 6] = b
  3514. a = b a[ 7] = b
  3515. a = b a[ 8] = b"
  3516. (interactive "NMAX: ")
  3517. (verilog-insert-1 "[%3d]" max))
  3518. (defun verilog-generate-numbers (max)
  3519. "Insert a set of generated numbers into a rectangle.
  3520. The upper left corner is defined by point. The numbers are padded to three
  3521. digits, starting with 000 and extending to (MAX - 1). If no prefix argument
  3522. is supplied, then the user is prompted for the MAX number. Consider the
  3523. following code fragment:
  3524. buf buf buf buf000
  3525. buf buf buf buf001
  3526. buf buf buf buf002
  3527. buf buf buf buf003
  3528. buf buf ==> generate-numbers ==> buf buf004
  3529. buf buf buf buf005
  3530. buf buf buf buf006
  3531. buf buf buf buf007
  3532. buf buf buf buf008"
  3533. (interactive "NMAX: ")
  3534. (verilog-insert-1 "%3.3d" max))
  3535. (defun verilog-mark-defun ()
  3536. "Mark the current Verilog function (or procedure).
  3537. This puts the mark at the end, and point at the beginning."
  3538. (interactive)
  3539. (if (featurep 'xemacs)
  3540. (progn
  3541. (push-mark (point))
  3542. (verilog-end-of-defun)
  3543. (push-mark (point))
  3544. (verilog-beg-of-defun)
  3545. (if (fboundp 'zmacs-activate-region)
  3546. (zmacs-activate-region)))
  3547. (mark-defun)))
  3548. (defun verilog-comment-region (start end)
  3549. ; checkdoc-params: (start end)
  3550. "Put the region into a Verilog comment.
  3551. The comments that are in this area are \"deformed\":
  3552. `*)' becomes `!(*' and `}' becomes `!{'.
  3553. These deformed comments are returned to normal if you use
  3554. \\[verilog-uncomment-region] to undo the commenting.
  3555. The commented area starts with `verilog-exclude-str-start', and ends with
  3556. `verilog-exclude-str-end'. But if you change these variables,
  3557. \\[verilog-uncomment-region] won't recognize the comments."
  3558. (interactive "r")
  3559. (save-excursion
  3560. ;; Insert start and endcomments
  3561. (goto-char end)
  3562. (if (and (save-excursion (skip-chars-forward " \t") (eolp))
  3563. (not (save-excursion (skip-chars-backward " \t") (bolp))))
  3564. (forward-line 1)
  3565. (beginning-of-line))
  3566. (insert verilog-exclude-str-end)
  3567. (setq end (point))
  3568. (newline)
  3569. (goto-char start)
  3570. (beginning-of-line)
  3571. (insert verilog-exclude-str-start)
  3572. (newline)
  3573. ;; Replace end-comments within commented area
  3574. (goto-char end)
  3575. (save-excursion
  3576. (while (re-search-backward "\\*/" start t)
  3577. (replace-match "*-/" t t)))
  3578. (save-excursion
  3579. (let ((s+1 (1+ start)))
  3580. (while (re-search-backward "/\\*" s+1 t)
  3581. (replace-match "/-*" t t))))))
  3582. (defun verilog-uncomment-region ()
  3583. "Uncomment a commented area; change deformed comments back to normal.
  3584. This command does nothing if the pointer is not in a commented
  3585. area. See also `verilog-comment-region'."
  3586. (interactive)
  3587. (save-excursion
  3588. (let ((start (point))
  3589. (end (point)))
  3590. ;; Find the boundaries of the comment
  3591. (save-excursion
  3592. (setq start (progn (search-backward verilog-exclude-str-start nil t)
  3593. (point)))
  3594. (setq end (progn (search-forward verilog-exclude-str-end nil t)
  3595. (point))))
  3596. ;; Check if we're really inside a comment
  3597. (if (or (equal start (point)) (<= end (point)))
  3598. (message "Not standing within commented area.")
  3599. (progn
  3600. ;; Remove endcomment
  3601. (goto-char end)
  3602. (beginning-of-line)
  3603. (let ((pos (point)))
  3604. (end-of-line)
  3605. (delete-region pos (1+ (point))))
  3606. ;; Change comments back to normal
  3607. (save-excursion
  3608. (while (re-search-backward "\\*-/" start t)
  3609. (replace-match "*/" t t)))
  3610. (save-excursion
  3611. (while (re-search-backward "/-\\*" start t)
  3612. (replace-match "/*" t t)))
  3613. ;; Remove start comment
  3614. (goto-char start)
  3615. (beginning-of-line)
  3616. (let ((pos (point)))
  3617. (end-of-line)
  3618. (delete-region pos (1+ (point)))))))))
  3619. (defun verilog-beg-of-defun ()
  3620. "Move backward to the beginning of the current function or procedure."
  3621. (interactive)
  3622. (verilog-re-search-backward verilog-defun-re nil 'move))
  3623. (defun verilog-beg-of-defun-quick ()
  3624. "Move backward to the beginning of the current function or procedure.
  3625. Uses `verilog-scan' cache."
  3626. (interactive)
  3627. (verilog-re-search-backward-quick verilog-defun-re nil 'move))
  3628. (defun verilog-end-of-defun ()
  3629. "Move forward to the end of the current function or procedure."
  3630. (interactive)
  3631. (verilog-re-search-forward verilog-end-defun-re nil 'move))
  3632. (defun verilog-get-beg-of-defun (&optional warn)
  3633. (save-excursion
  3634. (cond ((verilog-re-search-forward-quick verilog-defun-re nil t)
  3635. (point))
  3636. (t
  3637. (error "%s: Can't find module beginning" (verilog-point-text))
  3638. (point-max)))))
  3639. (defun verilog-get-end-of-defun (&optional warn)
  3640. (save-excursion
  3641. (cond ((verilog-re-search-forward-quick verilog-end-defun-re nil t)
  3642. (point))
  3643. (t
  3644. (error "%s: Can't find endmodule" (verilog-point-text))
  3645. (point-max)))))
  3646. (defun verilog-label-be (&optional arg)
  3647. "Label matching begin ... end, fork ... join and case ... endcase statements.
  3648. With ARG, first kill any existing labels."
  3649. (interactive)
  3650. (let ((cnt 0)
  3651. (oldpos (point))
  3652. (b (progn
  3653. (verilog-beg-of-defun)
  3654. (point-marker)))
  3655. (e (progn
  3656. (verilog-end-of-defun)
  3657. (point-marker))))
  3658. (goto-char (marker-position b))
  3659. (if (> (- e b) 200)
  3660. (message "Relabeling module..."))
  3661. (while (and
  3662. (> (marker-position e) (point))
  3663. (verilog-re-search-forward
  3664. (concat
  3665. "\\<end\\(\\(function\\)\\|\\(task\\)\\|\\(module\\)\\|\\(primitive\\)\\|\\(interface\\)\\|\\(package\\)\\|\\(case\\)\\)?\\>"
  3666. "\\|\\(`endif\\)\\|\\(`else\\)")
  3667. nil 'move))
  3668. (goto-char (match-beginning 0))
  3669. (let ((indent-str (verilog-indent-line)))
  3670. (verilog-set-auto-endcomments indent-str 't)
  3671. (end-of-line)
  3672. (delete-horizontal-space))
  3673. (setq cnt (1+ cnt))
  3674. (if (= 9 (% cnt 10))
  3675. (message "%d..." cnt)))
  3676. (goto-char oldpos)
  3677. (if (or
  3678. (> (- e b) 200)
  3679. (> cnt 20))
  3680. (message "%d lines auto commented" cnt))))
  3681. (defun verilog-beg-of-statement ()
  3682. "Move backward to beginning of statement."
  3683. (interactive)
  3684. ;; Move back token by token until we see the end
  3685. ;; of some earlier line.
  3686. (let (h)
  3687. (while
  3688. ;; If the current point does not begin a new
  3689. ;; statement, as in the character ahead of us is a ';', or SOF
  3690. ;; or the string after us unambiguously starts a statement,
  3691. ;; or the token before us unambiguously ends a statement,
  3692. ;; then move back a token and test again.
  3693. (not (or
  3694. ;; stop if beginning of buffer
  3695. (bolp)
  3696. ;; stop if we find a ;
  3697. (= (preceding-char) ?\;)
  3698. ;; stop if we see a named coverpoint
  3699. (looking-at "\\w+\\W*:\\W*\\(coverpoint\\|cross\\|constraint\\)")
  3700. ;; keep going if we are in the middle of a word
  3701. (not (or (looking-at "\\<") (forward-word -1)))
  3702. ;; stop if we see an assertion (perhaps labeled)
  3703. (and
  3704. (looking-at "\\(\\<\\(assert\\|assume\\|cover\\)\\>\\s-+\\<property\\>\\)\\|\\(\\<assert\\>\\)")
  3705. (progn
  3706. (setq h (point))
  3707. (save-excursion
  3708. (verilog-backward-token)
  3709. (if (looking-at verilog-label-re)
  3710. (setq h (point))))
  3711. (goto-char h)))
  3712. ;; stop if we see a complete reg, perhaps an extended one
  3713. (and
  3714. (looking-at verilog-complete-reg)
  3715. (let* ((p (point)))
  3716. (while (and (looking-at verilog-extended-complete-re)
  3717. (progn (setq p (point))
  3718. (verilog-backward-token)
  3719. (/= p (point)))))
  3720. (goto-char p)))
  3721. ;; stop if we see a complete reg (previous found extended ones)
  3722. (looking-at verilog-basic-complete-re)
  3723. ;; stop if previous token is an ender
  3724. (save-excursion
  3725. (verilog-backward-token)
  3726. (or
  3727. (looking-at verilog-end-block-re)
  3728. (looking-at verilog-preprocessor-re))))) ;; end of test
  3729. (verilog-backward-syntactic-ws)
  3730. (verilog-backward-token))
  3731. ;; Now point is where the previous line ended.
  3732. (verilog-forward-syntactic-ws)))
  3733. (defun verilog-beg-of-statement-1 ()
  3734. "Move backward to beginning of statement."
  3735. (interactive)
  3736. (if (verilog-in-comment-p)
  3737. (verilog-backward-syntactic-ws))
  3738. (let ((pt (point)))
  3739. (catch 'done
  3740. (while (not (looking-at verilog-complete-reg))
  3741. (setq pt (point))
  3742. (verilog-backward-syntactic-ws)
  3743. (if (or (bolp)
  3744. (= (preceding-char) ?\;)
  3745. (save-excursion
  3746. (verilog-backward-token)
  3747. (looking-at verilog-ends-re)))
  3748. (progn
  3749. (goto-char pt)
  3750. (throw 'done t))
  3751. (verilog-backward-token))))
  3752. (verilog-forward-syntactic-ws)))
  3753. ;
  3754. ; (while (and
  3755. ; (not (looking-at verilog-complete-reg))
  3756. ; (not (bolp))
  3757. ; (not (= (preceding-char) ?\;)))
  3758. ; (verilog-backward-token)
  3759. ; (verilog-backward-syntactic-ws)
  3760. ; (setq pt (point)))
  3761. ; (goto-char pt)
  3762. ; ;(verilog-forward-syntactic-ws)
  3763. (defun verilog-end-of-statement ()
  3764. "Move forward to end of current statement."
  3765. (interactive)
  3766. (let ((nest 0) pos)
  3767. (cond
  3768. ((verilog-in-directive-p)
  3769. (forward-line 1)
  3770. (backward-char 1))
  3771. ((looking-at verilog-beg-block-re)
  3772. (verilog-forward-sexp))
  3773. ((equal (char-after) ?\})
  3774. (forward-char))
  3775. ;; Skip to end of statement
  3776. ((condition-case nil
  3777. (setq pos
  3778. (catch 'found
  3779. (while t
  3780. (forward-sexp 1)
  3781. (verilog-skip-forward-comment-or-string)
  3782. (if (eolp)
  3783. (forward-line 1))
  3784. (cond ((looking-at "[ \t]*;")
  3785. (skip-chars-forward "^;")
  3786. (forward-char 1)
  3787. (throw 'found (point)))
  3788. ((save-excursion
  3789. (forward-sexp -1)
  3790. (looking-at verilog-beg-block-re))
  3791. (goto-char (match-beginning 0))
  3792. (throw 'found nil))
  3793. ((looking-at "[ \t]*)")
  3794. (throw 'found (point)))
  3795. ((eobp)
  3796. (throw 'found (point)))
  3797. )))
  3798. )
  3799. (error nil))
  3800. (if (not pos)
  3801. ;; Skip a whole block
  3802. (catch 'found
  3803. (while t
  3804. (verilog-re-search-forward verilog-end-statement-re nil 'move)
  3805. (setq nest (if (match-end 1)
  3806. (1+ nest)
  3807. (1- nest)))
  3808. (cond ((eobp)
  3809. (throw 'found (point)))
  3810. ((= 0 nest)
  3811. (throw 'found (verilog-end-of-statement))))))
  3812. pos)))))
  3813. (defun verilog-in-case-region-p ()
  3814. "Return true if in a case region.
  3815. More specifically, point @ in the line foo : @ begin"
  3816. (interactive)
  3817. (save-excursion
  3818. (if (and
  3819. (progn (verilog-forward-syntactic-ws)
  3820. (looking-at "\\<begin\\>"))
  3821. (progn (verilog-backward-syntactic-ws)
  3822. (= (preceding-char) ?\:)))
  3823. (catch 'found
  3824. (let ((nest 1))
  3825. (while t
  3826. (verilog-re-search-backward
  3827. (concat "\\(\\<module\\>\\)\\|\\(\\<randcase\\>\\|\\<case[xz]?\\>[^:]\\)\\|"
  3828. "\\(\\<endcase\\>\\)\\>")
  3829. nil 'move)
  3830. (cond
  3831. ((match-end 3)
  3832. (setq nest (1+ nest)))
  3833. ((match-end 2)
  3834. (if (= nest 1)
  3835. (throw 'found 1))
  3836. (setq nest (1- nest)))
  3837. (t
  3838. (throw 'found (= nest 0)))))))
  3839. nil)))
  3840. (defun verilog-backward-up-list (arg)
  3841. "Like `backward-up-list', but deal with comments."
  3842. (let ((parse-sexp-ignore-comments t))
  3843. (backward-up-list arg)))
  3844. (defun verilog-forward-sexp-cmt (arg)
  3845. "Call `forward-sexp', inside comments."
  3846. (let ((parse-sexp-ignore-comments nil))
  3847. (forward-sexp arg)))
  3848. (defun verilog-forward-sexp-ign-cmt (arg)
  3849. "Call `forward-sexp', ignoring comments."
  3850. (let ((parse-sexp-ignore-comments t))
  3851. (forward-sexp arg)))
  3852. (defun verilog-in-struct-region-p ()
  3853. "Return true if in a struct region.
  3854. More specifically, in a list after a struct|union keyword."
  3855. (interactive)
  3856. (save-excursion
  3857. (let* ((state (verilog-syntax-ppss))
  3858. (depth (nth 0 state)))
  3859. (if depth
  3860. (progn (verilog-backward-up-list depth)
  3861. (verilog-beg-of-statement)
  3862. (looking-at "\\<typedef\\>?\\s-*\\<struct\\|union\\>"))))))
  3863. (defun verilog-in-generate-region-p ()
  3864. "Return true if in a generate region.
  3865. More specifically, after a generate and before an endgenerate."
  3866. (interactive)
  3867. (let ((nest 1))
  3868. (save-excursion
  3869. (catch 'done
  3870. (while (and
  3871. (/= nest 0)
  3872. (verilog-re-search-backward
  3873. "\\<\\(module\\)\\|\\(generate\\)\\|\\(endgenerate\\)\\>" nil 'move)
  3874. (cond
  3875. ((match-end 1) ; module - we have crawled out
  3876. (throw 'done 1))
  3877. ((match-end 2) ; generate
  3878. (setq nest (1- nest)))
  3879. ((match-end 3) ; endgenerate
  3880. (setq nest (1+ nest))))))))
  3881. (= nest 0) )) ; return nest
  3882. (defun verilog-in-fork-region-p ()
  3883. "Return true if between a fork and join."
  3884. (interactive)
  3885. (let ((lim (save-excursion (verilog-beg-of-defun) (point)))
  3886. (nest 1))
  3887. (save-excursion
  3888. (while (and
  3889. (/= nest 0)
  3890. (verilog-re-search-backward "\\<\\(fork\\)\\|\\(join\\(_any\\|_none\\)?\\)\\>" lim 'move)
  3891. (cond
  3892. ((match-end 1) ; fork
  3893. (setq nest (1- nest)))
  3894. ((match-end 2) ; join
  3895. (setq nest (1+ nest)))))))
  3896. (= nest 0) )) ; return nest
  3897. (defun verilog-backward-case-item (lim)
  3898. "Skip backward to nearest enclosing case item.
  3899. Limit search to point LIM."
  3900. (interactive)
  3901. (let ((str 'nil)
  3902. (lim1
  3903. (progn
  3904. (save-excursion
  3905. (verilog-re-search-backward verilog-endcomment-reason-re
  3906. lim 'move)
  3907. (point)))))
  3908. ;; Try to find the real :
  3909. (if (save-excursion (search-backward ":" lim1 t))
  3910. (let ((colon 0)
  3911. b e )
  3912. (while
  3913. (and
  3914. (< colon 1)
  3915. (verilog-re-search-backward "\\(\\[\\)\\|\\(\\]\\)\\|\\(:\\)"
  3916. lim1 'move))
  3917. (cond
  3918. ((match-end 1) ;; [
  3919. (setq colon (1+ colon))
  3920. (if (>= colon 0)
  3921. (error "%s: unbalanced [" (verilog-point-text))))
  3922. ((match-end 2) ;; ]
  3923. (setq colon (1- colon)))
  3924. ((match-end 3) ;; :
  3925. (setq colon (1+ colon)))))
  3926. ;; Skip back to beginning of case item
  3927. (skip-chars-backward "\t ")
  3928. (verilog-skip-backward-comment-or-string)
  3929. (setq e (point))
  3930. (setq b
  3931. (progn
  3932. (if
  3933. (verilog-re-search-backward
  3934. "\\<\\(case[zx]?\\)\\>\\|;\\|\\<end\\>" nil 'move)
  3935. (progn
  3936. (cond
  3937. ((match-end 1)
  3938. (goto-char (match-end 1))
  3939. (verilog-forward-ws&directives)
  3940. (if (looking-at "(")
  3941. (progn
  3942. (forward-sexp)
  3943. (verilog-forward-ws&directives)))
  3944. (point))
  3945. (t
  3946. (goto-char (match-end 0))
  3947. (verilog-forward-ws&directives)
  3948. (point))))
  3949. (error "Malformed case item"))))
  3950. (setq str (buffer-substring b e))
  3951. (if
  3952. (setq e
  3953. (string-match
  3954. "[ \t]*\\(\\(\n\\)\\|\\(//\\)\\|\\(/\\*\\)\\)" str))
  3955. (setq str (concat (substring str 0 e) "...")))
  3956. str)
  3957. 'nil)))
  3958. ;;
  3959. ;; Other functions
  3960. ;;
  3961. (defun verilog-kill-existing-comment ()
  3962. "Kill auto comment on this line."
  3963. (save-excursion
  3964. (let* (
  3965. (e (progn
  3966. (end-of-line)
  3967. (point)))
  3968. (b (progn
  3969. (beginning-of-line)
  3970. (search-forward "//" e t))))
  3971. (if b
  3972. (delete-region (- b 2) e)))))
  3973. (defconst verilog-directive-nest-re
  3974. (concat "\\(`else\\>\\)\\|"
  3975. "\\(`endif\\>\\)\\|"
  3976. "\\(`if\\>\\)\\|"
  3977. "\\(`ifdef\\>\\)\\|"
  3978. "\\(`ifndef\\>\\)\\|"
  3979. "\\(`elsif\\>\\)"))
  3980. (defun verilog-set-auto-endcomments (indent-str kill-existing-comment)
  3981. "Add ending comment with given INDENT-STR.
  3982. With KILL-EXISTING-COMMENT, remove what was there before.
  3983. Insert `// case: 7 ' or `// NAME ' on this line if appropriate.
  3984. Insert `// case expr ' if this line ends a case block.
  3985. Insert `// ifdef FOO ' if this line ends code conditional on FOO.
  3986. Insert `// NAME ' if this line ends a function, task, module,
  3987. primitive or interface named NAME."
  3988. (save-excursion
  3989. (cond
  3990. (; Comment close preprocessor directives
  3991. (and
  3992. (looking-at "\\(`endif\\)\\|\\(`else\\)")
  3993. (or kill-existing-comment
  3994. (not (save-excursion
  3995. (end-of-line)
  3996. (search-backward "//" (point-at-bol) t)))))
  3997. (let ((nest 1) b e
  3998. m
  3999. (else (if (match-end 2) "!" " ")))
  4000. (end-of-line)
  4001. (if kill-existing-comment
  4002. (verilog-kill-existing-comment))
  4003. (delete-horizontal-space)
  4004. (save-excursion
  4005. (backward-sexp 1)
  4006. (while (and (/= nest 0)
  4007. (verilog-re-search-backward verilog-directive-nest-re nil 'move))
  4008. (cond
  4009. ((match-end 1) ; `else
  4010. (if (= nest 1)
  4011. (setq else "!")))
  4012. ((match-end 2) ; `endif
  4013. (setq nest (1+ nest)))
  4014. ((match-end 3) ; `if
  4015. (setq nest (1- nest)))
  4016. ((match-end 4) ; `ifdef
  4017. (setq nest (1- nest)))
  4018. ((match-end 5) ; `ifndef
  4019. (setq nest (1- nest)))
  4020. ((match-end 6) ; `elsif
  4021. (if (= nest 1)
  4022. (progn
  4023. (setq else "!")
  4024. (setq nest 0))))))
  4025. (if (match-end 0)
  4026. (setq
  4027. m (buffer-substring
  4028. (match-beginning 0)
  4029. (match-end 0))
  4030. b (progn
  4031. (skip-chars-forward "^ \t")
  4032. (verilog-forward-syntactic-ws)
  4033. (point))
  4034. e (progn
  4035. (skip-chars-forward "a-zA-Z0-9_")
  4036. (point)))))
  4037. (if b
  4038. (if (> (count-lines (point) b) verilog-minimum-comment-distance)
  4039. (insert (concat " // " else m " " (buffer-substring b e))))
  4040. (progn
  4041. (insert " // unmatched `else, `elsif or `endif")
  4042. (ding 't)))))
  4043. (; Comment close case/class/function/task/module and named block
  4044. (and (looking-at "\\<end")
  4045. (or kill-existing-comment
  4046. (not (save-excursion
  4047. (end-of-line)
  4048. (search-backward "//" (point-at-bol) t)))))
  4049. (let ((type (car indent-str)))
  4050. (unless (eq type 'declaration)
  4051. (unless (looking-at (concat "\\(" verilog-end-block-ordered-re "\\)[ \t]*:")) ;; ignore named ends
  4052. (if (looking-at verilog-end-block-ordered-re)
  4053. (cond
  4054. (;- This is a case block; search back for the start of this case
  4055. (match-end 1) ;; of verilog-end-block-ordered-re
  4056. (let ((err 't)
  4057. (str "UNMATCHED!!"))
  4058. (save-excursion
  4059. (verilog-leap-to-head)
  4060. (cond
  4061. ((looking-at "\\<randcase\\>")
  4062. (setq str "randcase")
  4063. (setq err nil))
  4064. ((looking-at "\\(\\(unique\\s-+\\|priority\\s-+\\)?case[xz]?\\)")
  4065. (goto-char (match-end 0))
  4066. (setq str (concat (match-string 0) " " (verilog-get-expr)))
  4067. (setq err nil))
  4068. ))
  4069. (end-of-line)
  4070. (if kill-existing-comment
  4071. (verilog-kill-existing-comment))
  4072. (delete-horizontal-space)
  4073. (insert (concat " // " str ))
  4074. (if err (ding 't))))
  4075. (;- This is a begin..end block
  4076. (match-end 2) ;; of verilog-end-block-ordered-re
  4077. (let ((str " // UNMATCHED !!")
  4078. (err 't)
  4079. (here (point))
  4080. there
  4081. cntx)
  4082. (save-excursion
  4083. (verilog-leap-to-head)
  4084. (setq there (point))
  4085. (if (not (match-end 0))
  4086. (progn
  4087. (goto-char here)
  4088. (end-of-line)
  4089. (if kill-existing-comment
  4090. (verilog-kill-existing-comment))
  4091. (delete-horizontal-space)
  4092. (insert str)
  4093. (ding 't))
  4094. (let ((lim
  4095. (save-excursion (verilog-beg-of-defun) (point)))
  4096. (here (point)))
  4097. (cond
  4098. (;-- handle named block differently
  4099. (looking-at verilog-named-block-re)
  4100. (search-forward ":")
  4101. (setq there (point))
  4102. (setq str (verilog-get-expr))
  4103. (setq err nil)
  4104. (setq str (concat " // block: " str )))
  4105. ((verilog-in-case-region-p) ;-- handle case item differently
  4106. (goto-char here)
  4107. (setq str (verilog-backward-case-item lim))
  4108. (setq there (point))
  4109. (setq err nil)
  4110. (setq str (concat " // case: " str )))
  4111. (;- try to find "reason" for this begin
  4112. (cond
  4113. (;
  4114. (eq here (progn
  4115. ;; (verilog-backward-token)
  4116. (verilog-beg-of-statement)
  4117. (point)))
  4118. (setq err nil)
  4119. (setq str ""))
  4120. ((looking-at verilog-endcomment-reason-re)
  4121. (setq there (match-end 0))
  4122. (setq cntx (concat (match-string 0) " "))
  4123. (cond
  4124. (;- begin
  4125. (match-end 1)
  4126. (setq err nil)
  4127. (save-excursion
  4128. (if (and (verilog-continued-line)
  4129. (looking-at "\\<repeat\\>\\|\\<wait\\>\\|\\<always\\>"))
  4130. (progn
  4131. (goto-char (match-end 0))
  4132. (setq there (point))
  4133. (setq str
  4134. (concat " // " (match-string 0) " " (verilog-get-expr))))
  4135. (setq str ""))))
  4136. (;- else
  4137. (match-end 2)
  4138. (let ((nest 0)
  4139. ( reg "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)\\|\\(\\<if\\>\\)\\|\\(assert\\)"))
  4140. (catch 'skip
  4141. (while (verilog-re-search-backward reg nil 'move)
  4142. (cond
  4143. ((match-end 1) ; begin
  4144. (setq nest (1- nest)))
  4145. ((match-end 2) ; end
  4146. (setq nest (1+ nest)))
  4147. ((match-end 3)
  4148. (if (= 0 nest)
  4149. (progn
  4150. (goto-char (match-end 0))
  4151. (setq there (point))
  4152. (setq err nil)
  4153. (setq str (verilog-get-expr))
  4154. (setq str (concat " // else: !if" str ))
  4155. (throw 'skip 1))))
  4156. ((match-end 4)
  4157. (if (= 0 nest)
  4158. (progn
  4159. (goto-char (match-end 0))
  4160. (setq there (point))
  4161. (setq err nil)
  4162. (setq str (verilog-get-expr))
  4163. (setq str (concat " // else: !assert " str ))
  4164. (throw 'skip 1)))))))))
  4165. (;- end else
  4166. (match-end 3)
  4167. (goto-char there)
  4168. (let ((nest 0)
  4169. (reg "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)\\|\\(\\<if\\>\\)\\|\\(assert\\)"))
  4170. (catch 'skip
  4171. (while (verilog-re-search-backward reg nil 'move)
  4172. (cond
  4173. ((match-end 1) ; begin
  4174. (setq nest (1- nest)))
  4175. ((match-end 2) ; end
  4176. (setq nest (1+ nest)))
  4177. ((match-end 3)
  4178. (if (= 0 nest)
  4179. (progn
  4180. (goto-char (match-end 0))
  4181. (setq there (point))
  4182. (setq err nil)
  4183. (setq str (verilog-get-expr))
  4184. (setq str (concat " // else: !if" str ))
  4185. (throw 'skip 1))))
  4186. ((match-end 4)
  4187. (if (= 0 nest)
  4188. (progn
  4189. (goto-char (match-end 0))
  4190. (setq there (point))
  4191. (setq err nil)
  4192. (setq str (verilog-get-expr))
  4193. (setq str (concat " // else: !assert " str ))
  4194. (throw 'skip 1)))))))))
  4195. (; always_comb, always_ff, always_latch
  4196. (or (match-end 4) (match-end 5) (match-end 6))
  4197. (goto-char (match-end 0))
  4198. (setq there (point))
  4199. (setq err nil)
  4200. (setq str (concat " // " cntx )))
  4201. (;- task/function/initial et cetera
  4202. t
  4203. (match-end 0)
  4204. (goto-char (match-end 0))
  4205. (setq there (point))
  4206. (setq err nil)
  4207. (setq str (concat " // " cntx (verilog-get-expr))))
  4208. (;-- otherwise...
  4209. (setq str " // auto-endcomment confused "))))
  4210. ((and
  4211. (verilog-in-case-region-p) ;-- handle case item differently
  4212. (progn
  4213. (setq there (point))
  4214. (goto-char here)
  4215. (setq str (verilog-backward-case-item lim))))
  4216. (setq err nil)
  4217. (setq str (concat " // case: " str )))
  4218. ((verilog-in-fork-region-p)
  4219. (setq err nil)
  4220. (setq str " // fork branch" ))
  4221. ((looking-at "\\<end\\>")
  4222. ;; HERE
  4223. (forward-word 1)
  4224. (verilog-forward-syntactic-ws)
  4225. (setq err nil)
  4226. (setq str (verilog-get-expr))
  4227. (setq str (concat " // " cntx str )))
  4228. ))))
  4229. (goto-char here)
  4230. (end-of-line)
  4231. (if kill-existing-comment
  4232. (verilog-kill-existing-comment))
  4233. (delete-horizontal-space)
  4234. (if (or err
  4235. (> (count-lines here there) verilog-minimum-comment-distance))
  4236. (insert str))
  4237. (if err (ding 't))
  4238. ))))
  4239. (;- this is endclass, which can be nested
  4240. (match-end 11) ;; of verilog-end-block-ordered-re
  4241. ;;(goto-char there)
  4242. (let ((nest 0)
  4243. (reg "\\<\\(class\\)\\|\\(endclass\\)\\|\\(package\\|primitive\\|\\(macro\\)?module\\)\\>")
  4244. string)
  4245. (save-excursion
  4246. (catch 'skip
  4247. (while (verilog-re-search-backward reg nil 'move)
  4248. (cond
  4249. ((match-end 3) ; endclass
  4250. (ding 't)
  4251. (setq string "unmatched endclass")
  4252. (throw 'skip 1))
  4253. ((match-end 2) ; endclass
  4254. (setq nest (1+ nest)))
  4255. ((match-end 1) ; class
  4256. (setq nest (1- nest))
  4257. (if (< nest 0)
  4258. (progn
  4259. (goto-char (match-end 0))
  4260. (let (b e)
  4261. (setq b (progn
  4262. (skip-chars-forward "^ \t")
  4263. (verilog-forward-ws&directives)
  4264. (point))
  4265. e (progn
  4266. (skip-chars-forward "a-zA-Z0-9_")
  4267. (point)))
  4268. (setq string (buffer-substring b e)))
  4269. (throw 'skip 1))))
  4270. ))))
  4271. (end-of-line)
  4272. (insert (concat " // " string ))))
  4273. (;- this is end{function,generate,task,module,primitive,table,generate}
  4274. ;- which can not be nested.
  4275. t
  4276. (let (string reg (name-re nil))
  4277. (end-of-line)
  4278. (if kill-existing-comment
  4279. (save-match-data
  4280. (verilog-kill-existing-comment)))
  4281. (delete-horizontal-space)
  4282. (backward-sexp)
  4283. (cond
  4284. ((match-end 5) ;; of verilog-end-block-ordered-re
  4285. (setq reg "\\(\\<function\\>\\)\\|\\(\\<\\(endfunction\\|task\\|\\(macro\\)?module\\|primitive\\)\\>\\)")
  4286. (setq name-re "\\w+\\s-*(")
  4287. )
  4288. ((match-end 6) ;; of verilog-end-block-ordered-re
  4289. (setq reg "\\(\\<task\\>\\)\\|\\(\\<\\(endtask\\|function\\|\\(macro\\)?module\\|primitive\\)\\>\\)"))
  4290. ((match-end 7) ;; of verilog-end-block-ordered-re
  4291. (setq reg "\\(\\<\\(macro\\)?module\\>\\)\\|\\<endmodule\\>"))
  4292. ((match-end 8) ;; of verilog-end-block-ordered-re
  4293. (setq reg "\\(\\<primitive\\>\\)\\|\\(\\<\\(endprimitive\\|package\\|interface\\|\\(macro\\)?module\\)\\>\\)"))
  4294. ((match-end 9) ;; of verilog-end-block-ordered-re
  4295. (setq reg "\\(\\<interface\\>\\)\\|\\(\\<\\(endinterface\\|package\\|primitive\\|\\(macro\\)?module\\)\\>\\)"))
  4296. ((match-end 10) ;; of verilog-end-block-ordered-re
  4297. (setq reg "\\(\\<package\\>\\)\\|\\(\\<\\(endpackage\\|primitive\\|interface\\|\\(macro\\)?module\\)\\>\\)"))
  4298. ((match-end 11) ;; of verilog-end-block-ordered-re
  4299. (setq reg "\\(\\<class\\>\\)\\|\\(\\<\\(endclass\\|primitive\\|interface\\|\\(macro\\)?module\\)\\>\\)"))
  4300. ((match-end 12) ;; of verilog-end-block-ordered-re
  4301. (setq reg "\\(\\<covergroup\\>\\)\\|\\(\\<\\(endcovergroup\\|primitive\\|interface\\|\\(macro\\)?module\\)\\>\\)"))
  4302. ((match-end 13) ;; of verilog-end-block-ordered-re
  4303. (setq reg "\\(\\<program\\>\\)\\|\\(\\<\\(endprogram\\|primitive\\|interface\\|\\(macro\\)?module\\)\\>\\)"))
  4304. ((match-end 14) ;; of verilog-end-block-ordered-re
  4305. (setq reg "\\(\\<\\(rand\\)?sequence\\>\\)\\|\\(\\<\\(endsequence\\|primitive\\|interface\\|\\(macro\\)?module\\)\\>\\)"))
  4306. ((match-end 15) ;; of verilog-end-block-ordered-re
  4307. (setq reg "\\(\\<clocking\\>\\)\\|\\<endclocking\\>"))
  4308. (t (error "Problem in verilog-set-auto-endcomments")))
  4309. (let (b e)
  4310. (save-excursion
  4311. (verilog-re-search-backward reg nil 'move)
  4312. (cond
  4313. ((match-end 1)
  4314. (setq b (progn
  4315. (skip-chars-forward "^ \t")
  4316. (verilog-forward-ws&directives)
  4317. (if (looking-at "static\\|automatic")
  4318. (progn
  4319. (goto-char (match-end 0))
  4320. (verilog-forward-ws&directives)))
  4321. (if (and name-re (verilog-re-search-forward name-re nil 'move))
  4322. (progn
  4323. (goto-char (match-beginning 0))
  4324. (verilog-forward-ws&directives)))
  4325. (point))
  4326. e (progn
  4327. (skip-chars-forward "a-zA-Z0-9_")
  4328. (point)))
  4329. (setq string (buffer-substring b e)))
  4330. (t
  4331. (ding 't)
  4332. (setq string "unmatched end(function|task|module|primitive|interface|package|class|clocking)")))))
  4333. (end-of-line)
  4334. (insert (concat " // " string )))
  4335. ))))))))))
  4336. (defun verilog-get-expr()
  4337. "Grab expression at point, e.g, case ( a | b & (c ^d))."
  4338. (let* ((b (progn
  4339. (verilog-forward-syntactic-ws)
  4340. (skip-chars-forward " \t")
  4341. (point)))
  4342. (e (let ((par 1))
  4343. (cond
  4344. ((looking-at "@")
  4345. (forward-char 1)
  4346. (verilog-forward-syntactic-ws)
  4347. (if (looking-at "(")
  4348. (progn
  4349. (forward-char 1)
  4350. (while (and (/= par 0)
  4351. (verilog-re-search-forward "\\((\\)\\|\\()\\)" nil 'move))
  4352. (cond
  4353. ((match-end 1)
  4354. (setq par (1+ par)))
  4355. ((match-end 2)
  4356. (setq par (1- par)))))))
  4357. (point))
  4358. ((looking-at "(")
  4359. (forward-char 1)
  4360. (while (and (/= par 0)
  4361. (verilog-re-search-forward "\\((\\)\\|\\()\\)" nil 'move))
  4362. (cond
  4363. ((match-end 1)
  4364. (setq par (1+ par)))
  4365. ((match-end 2)
  4366. (setq par (1- par)))))
  4367. (point))
  4368. ((looking-at "\\[")
  4369. (forward-char 1)
  4370. (while (and (/= par 0)
  4371. (verilog-re-search-forward "\\(\\[\\)\\|\\(\\]\\)" nil 'move))
  4372. (cond
  4373. ((match-end 1)
  4374. (setq par (1+ par)))
  4375. ((match-end 2)
  4376. (setq par (1- par)))))
  4377. (verilog-forward-syntactic-ws)
  4378. (skip-chars-forward "^ \t\n\f")
  4379. (point))
  4380. ((looking-at "/[/\\*]")
  4381. b)
  4382. ('t
  4383. (skip-chars-forward "^: \t\n\f")
  4384. (point)))))
  4385. (str (buffer-substring b e)))
  4386. (if (setq e (string-match "[ \t]*\\(\\(\n\\)\\|\\(//\\)\\|\\(/\\*\\)\\)" str))
  4387. (setq str (concat (substring str 0 e) "...")))
  4388. str))
  4389. (defun verilog-expand-vector ()
  4390. "Take a signal vector on the current line and expand it to multiple lines.
  4391. Useful for creating tri's and other expanded fields."
  4392. (interactive)
  4393. (verilog-expand-vector-internal "[" "]"))
  4394. (defun verilog-expand-vector-internal (bra ket)
  4395. "Given BRA, the start brace and KET, the end brace, expand one line into many lines."
  4396. (save-excursion
  4397. (forward-line 0)
  4398. (let ((signal-string (buffer-substring (point)
  4399. (progn
  4400. (end-of-line) (point)))))
  4401. (if (string-match
  4402. (concat "\\(.*\\)"
  4403. (regexp-quote bra)
  4404. "\\([0-9]*\\)\\(:[0-9]*\\|\\)\\(::[0-9---]*\\|\\)"
  4405. (regexp-quote ket)
  4406. "\\(.*\\)$") signal-string)
  4407. (let* ((sig-head (match-string 1 signal-string))
  4408. (vec-start (string-to-number (match-string 2 signal-string)))
  4409. (vec-end (if (= (match-beginning 3) (match-end 3))
  4410. vec-start
  4411. (string-to-number
  4412. (substring signal-string (1+ (match-beginning 3))
  4413. (match-end 3)))))
  4414. (vec-range
  4415. (if (= (match-beginning 4) (match-end 4))
  4416. 1
  4417. (string-to-number
  4418. (substring signal-string (+ 2 (match-beginning 4))
  4419. (match-end 4)))))
  4420. (sig-tail (match-string 5 signal-string))
  4421. vec)
  4422. ;; Decode vectors
  4423. (setq vec nil)
  4424. (if (< vec-range 0)
  4425. (let ((tmp vec-start))
  4426. (setq vec-start vec-end
  4427. vec-end tmp
  4428. vec-range (- vec-range))))
  4429. (if (< vec-end vec-start)
  4430. (while (<= vec-end vec-start)
  4431. (setq vec (append vec (list vec-start)))
  4432. (setq vec-start (- vec-start vec-range)))
  4433. (while (<= vec-start vec-end)
  4434. (setq vec (append vec (list vec-start)))
  4435. (setq vec-start (+ vec-start vec-range))))
  4436. ;;
  4437. ;; Delete current line
  4438. (delete-region (point) (progn (forward-line 0) (point)))
  4439. ;;
  4440. ;; Expand vector
  4441. (while vec
  4442. (insert (concat sig-head bra
  4443. (int-to-string (car vec)) ket sig-tail "\n"))
  4444. (setq vec (cdr vec)))
  4445. (delete-char -1)
  4446. ;;
  4447. )))))
  4448. (defun verilog-strip-comments ()
  4449. "Strip all comments from the Verilog code."
  4450. (interactive)
  4451. (goto-char (point-min))
  4452. (while (re-search-forward "//" nil t)
  4453. (if (verilog-within-string)
  4454. (re-search-forward "\"" nil t)
  4455. (if (verilog-in-star-comment-p)
  4456. (re-search-forward "\*/" nil t)
  4457. (let ((bpt (- (point) 2)))
  4458. (end-of-line)
  4459. (delete-region bpt (point))))))
  4460. ;;
  4461. (goto-char (point-min))
  4462. (while (re-search-forward "/\\*" nil t)
  4463. (if (verilog-within-string)
  4464. (re-search-forward "\"" nil t)
  4465. (let ((bpt (- (point) 2)))
  4466. (re-search-forward "\\*/")
  4467. (delete-region bpt (point))))))
  4468. (defun verilog-one-line ()
  4469. "Convert structural Verilog instances to occupy one line."
  4470. (interactive)
  4471. (goto-char (point-min))
  4472. (while (re-search-forward "\\([^;]\\)[ \t]*\n[ \t]*" nil t)
  4473. (replace-match "\\1 " nil nil)))
  4474. (defun verilog-linter-name ()
  4475. "Return name of linter, either surelint or verilint."
  4476. (let ((compile-word1 (verilog-string-replace-matches "\\s .*$" "" nil nil
  4477. compile-command))
  4478. (lint-word1 (verilog-string-replace-matches "\\s .*$" "" nil nil
  4479. verilog-linter)))
  4480. (cond ((equal compile-word1 "surelint") `surelint)
  4481. ((equal compile-word1 "verilint") `verilint)
  4482. ((equal lint-word1 "surelint") `surelint)
  4483. ((equal lint-word1 "verilint") `verilint)
  4484. (t `surelint)))) ;; back compatibility
  4485. (defun verilog-lint-off ()
  4486. "Convert a Verilog linter warning line into a disable statement.
  4487. For example:
  4488. pci_bfm_null.v, line 46: Unused input: pci_rst_
  4489. becomes a comment for the appropriate tool.
  4490. The first word of the `compile-command' or `verilog-linter'
  4491. variables is used to determine which product is being used.
  4492. See \\[verilog-surelint-off] and \\[verilog-verilint-off]."
  4493. (interactive)
  4494. (let ((linter (verilog-linter-name)))
  4495. (cond ((equal linter `surelint)
  4496. (verilog-surelint-off))
  4497. ((equal linter `verilint)
  4498. (verilog-verilint-off))
  4499. (t (error "Linter name not set")))))
  4500. (defvar compilation-last-buffer)
  4501. (defvar next-error-last-buffer)
  4502. (defun verilog-surelint-off ()
  4503. "Convert a SureLint warning line into a disable statement.
  4504. Run from Verilog source window; assumes there is a *compile* buffer
  4505. with point set appropriately.
  4506. For example:
  4507. WARNING [STD-UDDONX]: xx.v, line 8: output out is never assigned.
  4508. becomes:
  4509. // surefire lint_line_off UDDONX"
  4510. (interactive)
  4511. (let ((buff (if (boundp 'next-error-last-buffer)
  4512. next-error-last-buffer
  4513. compilation-last-buffer)))
  4514. (when (buffer-live-p buff)
  4515. (save-excursion
  4516. (switch-to-buffer buff)
  4517. (beginning-of-line)
  4518. (when
  4519. (looking-at "\\(INFO\\|WARNING\\|ERROR\\) \\[[^-]+-\\([^]]+\\)\\]: \\([^,]+\\), line \\([0-9]+\\): \\(.*\\)$")
  4520. (let* ((code (match-string 2))
  4521. (file (match-string 3))
  4522. (line (match-string 4))
  4523. (buffer (get-file-buffer file))
  4524. dir filename)
  4525. (unless buffer
  4526. (progn
  4527. (setq buffer
  4528. (and (file-exists-p file)
  4529. (find-file-noselect file)))
  4530. (or buffer
  4531. (let* ((pop-up-windows t))
  4532. (let ((name (expand-file-name
  4533. (read-file-name
  4534. (format "Find this error in: (default %s) "
  4535. file)
  4536. dir file t))))
  4537. (if (file-directory-p name)
  4538. (setq name (expand-file-name filename name)))
  4539. (setq buffer
  4540. (and (file-exists-p name)
  4541. (find-file-noselect name))))))))
  4542. (switch-to-buffer buffer)
  4543. (goto-char (point-min))
  4544. (forward-line (- (string-to-number line)))
  4545. (end-of-line)
  4546. (catch 'already
  4547. (cond
  4548. ((verilog-in-slash-comment-p)
  4549. (re-search-backward "//")
  4550. (cond
  4551. ((looking-at "// surefire lint_off_line ")
  4552. (goto-char (match-end 0))
  4553. (let ((lim (point-at-eol)))
  4554. (if (re-search-forward code lim 'move)
  4555. (throw 'already t)
  4556. (insert (concat " " code)))))
  4557. (t
  4558. )))
  4559. ((verilog-in-star-comment-p)
  4560. (re-search-backward "/\*")
  4561. (insert (format " // surefire lint_off_line %6s" code )))
  4562. (t
  4563. (insert (format " // surefire lint_off_line %6s" code ))
  4564. )))))))))
  4565. (defun verilog-verilint-off ()
  4566. "Convert a Verilint warning line into a disable statement.
  4567. For example:
  4568. (W240) pci_bfm_null.v, line 46: Unused input: pci_rst_
  4569. becomes:
  4570. //Verilint 240 off // WARNING: Unused input"
  4571. (interactive)
  4572. (save-excursion
  4573. (beginning-of-line)
  4574. (when (looking-at "\\(.*\\)([WE]\\([0-9A-Z]+\\)).*,\\s +line\\s +[0-9]+:\\s +\\([^:\n]+\\):?.*$")
  4575. (replace-match (format
  4576. ;; %3s makes numbers 1-999 line up nicely
  4577. "\\1//Verilint %3s off // WARNING: \\3"
  4578. (match-string 2)))
  4579. (beginning-of-line)
  4580. (verilog-indent-line))))
  4581. (defun verilog-auto-save-compile ()
  4582. "Update automatics with \\[verilog-auto], save the buffer, and compile."
  4583. (interactive)
  4584. (verilog-auto) ; Always do it for safety
  4585. (save-buffer)
  4586. (compile compile-command))
  4587. (defun verilog-preprocess (&optional command filename)
  4588. "Preprocess the buffer, similar to `compile', but leave output in Verilog-Mode.
  4589. Takes optional COMMAND or defaults to `verilog-preprocessor', and
  4590. FILENAME or defaults to `buffer-file-name`."
  4591. (interactive
  4592. (list
  4593. (let ((default (verilog-expand-command verilog-preprocessor)))
  4594. (set (make-local-variable `verilog-preprocessor)
  4595. (read-from-minibuffer "Run Preprocessor (like this): "
  4596. default nil nil
  4597. 'verilog-preprocess-history default)))))
  4598. (unless command (setq command (verilog-expand-command verilog-preprocessor)))
  4599. (let* ((fontlocked (and (boundp 'font-lock-mode) font-lock-mode))
  4600. (dir (file-name-directory (or filename buffer-file-name)))
  4601. (file (file-name-nondirectory (or filename buffer-file-name)))
  4602. (cmd (concat "cd " dir "; " command " " file)))
  4603. (with-output-to-temp-buffer "*Verilog-Preprocessed*"
  4604. (with-current-buffer (get-buffer "*Verilog-Preprocessed*")
  4605. (insert (concat "// " cmd "\n"))
  4606. (shell-command cmd "*Verilog-Preprocessed*")
  4607. (verilog-mode)
  4608. ;; Without this force, it takes a few idle seconds
  4609. ;; to get the color, which is very jarring
  4610. (when fontlocked (font-lock-fontify-buffer))))))
  4611. ;;
  4612. ;; Batch
  4613. ;;
  4614. (defmacro verilog-batch-error-wrapper (&rest body)
  4615. "Execute BODY and add error prefix to any errors found.
  4616. This lets programs calling batch mode to easily extract error messages."
  4617. `(condition-case err
  4618. (progn ,@body)
  4619. (error
  4620. (error "%%Error: %s%s" (error-message-string err)
  4621. (if (featurep 'xemacs) "\n" ""))))) ;; XEmacs forgets to add a newline
  4622. (defun verilog-batch-execute-func (funref &optional no-save)
  4623. "Internal processing of a batch command, running FUNREF on all command arguments.
  4624. Save the result unless optional NO-SAVE is t."
  4625. (verilog-batch-error-wrapper
  4626. ;; Setting global variables like that is *VERY NASTY* !!! --Stef
  4627. ;; However, this function is called only when Emacs is being used as
  4628. ;; a standalone language instead of as an editor, so we'll live.
  4629. ;;
  4630. ;; General globals needed
  4631. (setq make-backup-files nil)
  4632. (setq-default make-backup-files nil)
  4633. (setq enable-local-variables t)
  4634. (setq enable-local-eval t)
  4635. ;; Make sure any sub-files we read get proper mode
  4636. (setq-default major-mode 'verilog-mode)
  4637. ;; Ditto files already read in
  4638. (mapc (lambda (buf)
  4639. (when (buffer-file-name buf)
  4640. (with-current-buffer buf
  4641. (verilog-mode))))
  4642. (buffer-list))
  4643. ;; Process the files
  4644. (mapcar (lambda (buf)
  4645. (when (buffer-file-name buf)
  4646. (save-excursion
  4647. (if (not (file-exists-p (buffer-file-name buf)))
  4648. (error
  4649. (concat "File not found: " (buffer-file-name buf))))
  4650. (message (concat "Processing " (buffer-file-name buf)))
  4651. (set-buffer buf)
  4652. (funcall funref)
  4653. (unless no-save (save-buffer)))))
  4654. (buffer-list))))
  4655. (defun verilog-batch-auto ()
  4656. "For use with --batch, perform automatic expansions as a stand-alone tool.
  4657. This sets up the appropriate Verilog mode environment, updates automatics
  4658. with \\[verilog-auto] on all command-line files, and saves the buffers.
  4659. For proper results, multiple filenames need to be passed on the command
  4660. line in bottom-up order."
  4661. (unless noninteractive
  4662. (error "Use verilog-batch-auto only with --batch")) ;; Otherwise we'd mess up buffer modes
  4663. (verilog-batch-execute-func `verilog-auto))
  4664. (defun verilog-batch-delete-auto ()
  4665. "For use with --batch, perform automatic deletion as a stand-alone tool.
  4666. This sets up the appropriate Verilog mode environment, deletes automatics
  4667. with \\[verilog-delete-auto] on all command-line files, and saves the buffers."
  4668. (unless noninteractive
  4669. (error "Use verilog-batch-delete-auto only with --batch")) ;; Otherwise we'd mess up buffer modes
  4670. (verilog-batch-execute-func `verilog-delete-auto))
  4671. (defun verilog-batch-diff-auto ()
  4672. "For use with --batch, perform automatic differences as a stand-alone tool.
  4673. This sets up the appropriate Verilog mode environment, expand automatics
  4674. with \\[verilog-diff-auto] on all command-line files, and reports an error
  4675. if any differences are observed. This is appropriate for adding to regressions
  4676. to insure automatics are always properly maintained."
  4677. (unless noninteractive
  4678. (error "Use verilog-batch-diff-auto only with --batch")) ;; Otherwise we'd mess up buffer modes
  4679. (verilog-batch-execute-func `verilog-diff-auto t))
  4680. (defun verilog-batch-inject-auto ()
  4681. "For use with --batch, perform automatic injection as a stand-alone tool.
  4682. This sets up the appropriate Verilog mode environment, injects new automatics
  4683. with \\[verilog-inject-auto] on all command-line files, and saves the buffers.
  4684. For proper results, multiple filenames need to be passed on the command
  4685. line in bottom-up order."
  4686. (unless noninteractive
  4687. (error "Use verilog-batch-inject-auto only with --batch")) ;; Otherwise we'd mess up buffer modes
  4688. (verilog-batch-execute-func `verilog-inject-auto))
  4689. (defun verilog-batch-indent ()
  4690. "For use with --batch, reindent an a entire file as a stand-alone tool.
  4691. This sets up the appropriate Verilog mode environment, calls
  4692. \\[verilog-indent-buffer] on all command-line files, and saves the buffers."
  4693. (unless noninteractive
  4694. (error "Use verilog-batch-indent only with --batch")) ;; Otherwise we'd mess up buffer modes
  4695. (verilog-batch-execute-func `verilog-indent-buffer))
  4696. ;;
  4697. ;; Indentation
  4698. ;;
  4699. (defconst verilog-indent-alist
  4700. '((block . (+ ind verilog-indent-level))
  4701. (case . (+ ind verilog-case-indent))
  4702. (cparenexp . (+ ind verilog-indent-level))
  4703. (cexp . (+ ind verilog-cexp-indent))
  4704. (defun . verilog-indent-level-module)
  4705. (declaration . verilog-indent-level-declaration)
  4706. (directive . (verilog-calculate-indent-directive))
  4707. (tf . verilog-indent-level)
  4708. (behavioral . (+ verilog-indent-level-behavioral verilog-indent-level-module))
  4709. (statement . ind)
  4710. (cpp . 0)
  4711. (comment . (verilog-comment-indent))
  4712. (unknown . 3)
  4713. (string . 0)))
  4714. (defun verilog-continued-line-1 (lim)
  4715. "Return true if this is a continued line.
  4716. Set point to where line starts. Limit search to point LIM."
  4717. (let ((continued 't))
  4718. (if (eq 0 (forward-line -1))
  4719. (progn
  4720. (end-of-line)
  4721. (verilog-backward-ws&directives lim)
  4722. (if (bobp)
  4723. (setq continued nil)
  4724. (setq continued (verilog-backward-token))))
  4725. (setq continued nil))
  4726. continued))
  4727. (defun verilog-calculate-indent ()
  4728. "Calculate the indent of the current Verilog line.
  4729. Examine previous lines. Once a line is found that is definitive as to the
  4730. type of the current line, return that lines' indent level and its type.
  4731. Return a list of two elements: (INDENT-TYPE INDENT-LEVEL)."
  4732. (save-excursion
  4733. (let* ((starting_position (point))
  4734. (par 0)
  4735. (begin (looking-at "[ \t]*begin\\>"))
  4736. (lim (save-excursion (verilog-re-search-backward "\\(\\<begin\\>\\)\\|\\(\\<module\\>\\)" nil t)))
  4737. (type (catch 'nesting
  4738. ;; Keep working backwards until we can figure out
  4739. ;; what type of statement this is.
  4740. ;; Basically we need to figure out
  4741. ;; 1) if this is a continuation of the previous line;
  4742. ;; 2) are we in a block scope (begin..end)
  4743. ;; if we are in a comment, done.
  4744. (if (verilog-in-star-comment-p)
  4745. (throw 'nesting 'comment))
  4746. ;; if we have a directive, done.
  4747. (if (save-excursion (beginning-of-line)
  4748. (and (looking-at verilog-directive-re-1)
  4749. (not (or (looking-at "[ \t]*`[ou]vm_")
  4750. (looking-at "[ \t]*`vmm_")))))
  4751. (throw 'nesting 'directive))
  4752. ;; indent structs as if there were module level
  4753. (if (verilog-in-struct-p)
  4754. (throw 'nesting 'block))
  4755. ;; if we are in a parenthesized list, and the user likes to indent these, return.
  4756. ;; unless we are in the newfangled coverpoint or constraint blocks
  4757. (if (and
  4758. verilog-indent-lists
  4759. (verilog-in-paren)
  4760. (not (verilog-in-coverage-p))
  4761. )
  4762. (progn (setq par 1)
  4763. (throw 'nesting 'block)))
  4764. ;; See if we are continuing a previous line
  4765. (while t
  4766. ;; trap out if we crawl off the top of the buffer
  4767. (if (bobp) (throw 'nesting 'cpp))
  4768. (if (verilog-continued-line-1 lim)
  4769. (let ((sp (point)))
  4770. (if (and
  4771. (not (looking-at verilog-complete-reg))
  4772. (verilog-continued-line-1 lim))
  4773. (progn (goto-char sp)
  4774. (throw 'nesting 'cexp))
  4775. (goto-char sp))
  4776. (if (and begin
  4777. (not verilog-indent-begin-after-if)
  4778. (looking-at verilog-no-indent-begin-re))
  4779. (progn
  4780. (beginning-of-line)
  4781. (skip-chars-forward " \t")
  4782. (throw 'nesting 'statement))
  4783. (progn
  4784. (throw 'nesting 'cexp))))
  4785. ;; not a continued line
  4786. (goto-char starting_position))
  4787. (if (looking-at "\\<else\\>")
  4788. ;; search back for governing if, striding across begin..end pairs
  4789. ;; appropriately
  4790. (let ((elsec 1))
  4791. (while (verilog-re-search-backward verilog-ends-re nil 'move)
  4792. (cond
  4793. ((match-end 1) ; else, we're in deep
  4794. (setq elsec (1+ elsec)))
  4795. ((match-end 2) ; if
  4796. (setq elsec (1- elsec))
  4797. (if (= 0 elsec)
  4798. (if verilog-align-ifelse
  4799. (throw 'nesting 'statement)
  4800. (progn ;; back up to first word on this line
  4801. (beginning-of-line)
  4802. (verilog-forward-syntactic-ws)
  4803. (throw 'nesting 'statement)))))
  4804. ((match-end 3) ; assert block
  4805. (setq elsec (1- elsec))
  4806. (verilog-beg-of-statement) ;; doesn't get to beginning
  4807. (if (looking-at verilog-property-re)
  4808. (throw 'nesting 'statement) ; We don't need an endproperty for these
  4809. (throw 'nesting 'block) ;We still need a endproperty
  4810. ))
  4811. (t ; endblock
  4812. ; try to leap back to matching outward block by striding across
  4813. ; indent level changing tokens then immediately
  4814. ; previous line governs indentation.
  4815. (let (( reg) (nest 1))
  4816. ;; verilog-ends => else|if|end|join(_any|_none|)|endcase|endclass|endtable|endspecify|endfunction|endtask|endgenerate|endgroup
  4817. (cond
  4818. ((match-end 4) ; end
  4819. ;; Search back for matching begin
  4820. (setq reg "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)" ))
  4821. ((match-end 5) ; endcase
  4822. ;; Search back for matching case
  4823. (setq reg "\\(\\<randcase\\>\\|\\<case[xz]?\\>[^:]\\)\\|\\(\\<endcase\\>\\)" ))
  4824. ((match-end 6) ; endfunction
  4825. ;; Search back for matching function
  4826. (setq reg "\\(\\<function\\>\\)\\|\\(\\<endfunction\\>\\)" ))
  4827. ((match-end 7) ; endtask
  4828. ;; Search back for matching task
  4829. (setq reg "\\(\\<task\\>\\)\\|\\(\\<endtask\\>\\)" ))
  4830. ((match-end 8) ; endspecify
  4831. ;; Search back for matching specify
  4832. (setq reg "\\(\\<specify\\>\\)\\|\\(\\<endspecify\\>\\)" ))
  4833. ((match-end 9) ; endtable
  4834. ;; Search back for matching table
  4835. (setq reg "\\(\\<table\\>\\)\\|\\(\\<endtable\\>\\)" ))
  4836. ((match-end 10) ; endgenerate
  4837. ;; Search back for matching generate
  4838. (setq reg "\\(\\<generate\\>\\)\\|\\(\\<endgenerate\\>\\)" ))
  4839. ((match-end 11) ; joins
  4840. ;; Search back for matching fork
  4841. (setq reg "\\(\\<fork\\>\\)\\|\\(\\<join\\(_any\\|none\\)?\\>\\)" ))
  4842. ((match-end 12) ; class
  4843. ;; Search back for matching class
  4844. (setq reg "\\(\\<class\\>\\)\\|\\(\\<endclass\\>\\)" ))
  4845. ((match-end 13) ; covergroup
  4846. ;; Search back for matching covergroup
  4847. (setq reg "\\(\\<covergroup\\>\\)\\|\\(\\<endgroup\\>\\)" )))
  4848. (catch 'skip
  4849. (while (verilog-re-search-backward reg nil 'move)
  4850. (cond
  4851. ((match-end 1) ; begin
  4852. (setq nest (1- nest))
  4853. (if (= 0 nest)
  4854. (throw 'skip 1)))
  4855. ((match-end 2) ; end
  4856. (setq nest (1+ nest)))))
  4857. )))))))
  4858. (throw 'nesting (verilog-calc-1)))
  4859. );; catch nesting
  4860. );; type
  4861. )
  4862. ;; Return type of block and indent level.
  4863. (if (not type)
  4864. (setq type 'cpp))
  4865. (if (> par 0) ; Unclosed Parenthesis
  4866. (list 'cparenexp par)
  4867. (cond
  4868. ((eq type 'case)
  4869. (list type (verilog-case-indent-level)))
  4870. ((eq type 'statement)
  4871. (list type (current-column)))
  4872. ((eq type 'defun)
  4873. (list type 0))
  4874. (t
  4875. (list type (verilog-current-indent-level))))))))
  4876. (defun verilog-wai ()
  4877. "Show matching nesting block for debugging."
  4878. (interactive)
  4879. (save-excursion
  4880. (let* ((type (verilog-calc-1))
  4881. depth)
  4882. ;; Return type of block and indent level.
  4883. (if (not type)
  4884. (setq type 'cpp))
  4885. (if (and
  4886. verilog-indent-lists
  4887. (not(or (verilog-in-coverage-p)
  4888. (verilog-in-struct-p)))
  4889. (verilog-in-paren))
  4890. (setq depth 1)
  4891. (cond
  4892. ((eq type 'case)
  4893. (setq depth (verilog-case-indent-level)))
  4894. ((eq type 'statement)
  4895. (setq depth (current-column)))
  4896. ((eq type 'defun)
  4897. (setq depth 0))
  4898. (t
  4899. (setq depth (verilog-current-indent-level)))))
  4900. (message "You are at nesting %s depth %d" type depth))))
  4901. (defun verilog-calc-1 ()
  4902. (catch 'nesting
  4903. (let ((re (concat "\\({\\|}\\|" verilog-indent-re "\\)")))
  4904. (while (verilog-re-search-backward re nil 'move)
  4905. (catch 'continue
  4906. (cond
  4907. ((equal (char-after) ?\{)
  4908. (if (verilog-at-constraint-p)
  4909. (throw 'nesting 'block)))
  4910. ((equal (char-after) ?\})
  4911. (let ((there (verilog-at-close-constraint-p)))
  4912. (if there ;; we are at the } that closes a constraint. Find the { that opens it
  4913. (progn
  4914. (forward-char 1)
  4915. (backward-list 1)
  4916. (verilog-beg-of-statement)))))
  4917. ((looking-at verilog-beg-block-re-ordered)
  4918. (cond
  4919. ((match-end 2) ; *sigh* could be "unique case" or "priority casex"
  4920. (let ((here (point)))
  4921. (verilog-beg-of-statement)
  4922. (if (looking-at verilog-extended-case-re)
  4923. (throw 'nesting 'case)
  4924. (goto-char here)))
  4925. (throw 'nesting 'case))
  4926. ((match-end 4) ; *sigh* could be "disable fork"
  4927. (let ((here (point)))
  4928. (verilog-beg-of-statement)
  4929. (if (looking-at verilog-disable-fork-re)
  4930. t ; this is a normal statement
  4931. (progn ; or is fork, starts a new block
  4932. (goto-char here)
  4933. (throw 'nesting 'block)))))
  4934. ((match-end 27) ; *sigh* might be a clocking declaration
  4935. (let ((here (point)))
  4936. (if (verilog-in-paren)
  4937. t ; this is a normal statement
  4938. (progn ; or is fork, starts a new block
  4939. (goto-char here)
  4940. (throw 'nesting 'block)))))
  4941. ;; need to consider typedef struct here...
  4942. ((looking-at "\\<class\\|struct\\|function\\|task\\>")
  4943. ; *sigh* These words have an optional prefix:
  4944. ; extern {virtual|protected}? function a();
  4945. ; typedef class foo;
  4946. ; and we don't want to confuse this with
  4947. ; function a();
  4948. ; property
  4949. ; ...
  4950. ; endfunction
  4951. (verilog-beg-of-statement)
  4952. (if (looking-at verilog-beg-block-re-ordered)
  4953. (throw 'nesting 'block)
  4954. (throw 'nesting 'defun)))
  4955. ((looking-at "\\<property\\>")
  4956. ; *sigh*
  4957. ; {assert|assume|cover} property (); are complete
  4958. ; and could also be labeled: - foo: assert property
  4959. ; but
  4960. ; property ID () ... needs end_property
  4961. (verilog-beg-of-statement)
  4962. (if (looking-at verilog-property-re)
  4963. (throw 'continue 'statement) ; We don't need an endproperty for these
  4964. (throw 'nesting 'block) ;We still need a endproperty
  4965. ))
  4966. (t (throw 'nesting 'block))))
  4967. ((looking-at verilog-end-block-re)
  4968. (verilog-leap-to-head)
  4969. (if (verilog-in-case-region-p)
  4970. (progn
  4971. (verilog-leap-to-case-head)
  4972. (if (looking-at verilog-extended-case-re)
  4973. (throw 'nesting 'case)))))
  4974. ((looking-at verilog-defun-level-re)
  4975. (if (looking-at verilog-defun-level-generate-only-re)
  4976. (if (verilog-in-generate-region-p)
  4977. (throw 'continue 'foo) ; always block in a generate - keep looking
  4978. (throw 'nesting 'defun))
  4979. (throw 'nesting 'defun)))
  4980. ((looking-at verilog-cpp-level-re)
  4981. (throw 'nesting 'cpp))
  4982. ((bobp)
  4983. (throw 'nesting 'cpp)))))
  4984. (throw 'nesting 'cpp))))
  4985. (defun verilog-calculate-indent-directive ()
  4986. "Return indentation level for directive.
  4987. For speed, the searcher looks at the last directive, not the indent
  4988. of the appropriate enclosing block."
  4989. (let ((base -1) ;; Indent of the line that determines our indentation
  4990. (ind 0)) ;; Relative offset caused by other directives (like `endif on same line as `else)
  4991. ;; Start at current location, scan back for another directive
  4992. (save-excursion
  4993. (beginning-of-line)
  4994. (while (and (< base 0)
  4995. (verilog-re-search-backward verilog-directive-re nil t))
  4996. (cond ((save-excursion (skip-chars-backward " \t") (bolp))
  4997. (setq base (current-indentation))))
  4998. (cond ((and (looking-at verilog-directive-end) (< base 0)) ;; Only matters when not at BOL
  4999. (setq ind (- ind verilog-indent-level-directive)))
  5000. ((and (looking-at verilog-directive-middle) (>= base 0)) ;; Only matters when at BOL
  5001. (setq ind (+ ind verilog-indent-level-directive)))
  5002. ((looking-at verilog-directive-begin)
  5003. (setq ind (+ ind verilog-indent-level-directive)))))
  5004. ;; Adjust indent to starting indent of critical line
  5005. (setq ind (max 0 (+ ind base))))
  5006. (save-excursion
  5007. (beginning-of-line)
  5008. (skip-chars-forward " \t")
  5009. (cond ((or (looking-at verilog-directive-middle)
  5010. (looking-at verilog-directive-end))
  5011. (setq ind (max 0 (- ind verilog-indent-level-directive))))))
  5012. ind))
  5013. (defun verilog-leap-to-case-head ()
  5014. (let ((nest 1))
  5015. (while (/= 0 nest)
  5016. (verilog-re-search-backward
  5017. (concat
  5018. "\\(\\<randcase\\>\\|\\(\\<unique\\s-+\\|priority\\s-+\\)?\\<case[xz]?\\>\\)"
  5019. "\\|\\(\\<endcase\\>\\)" )
  5020. nil 'move)
  5021. (cond
  5022. ((match-end 1)
  5023. (let ((here (point)))
  5024. (verilog-beg-of-statement)
  5025. (unless (looking-at verilog-extended-case-re)
  5026. (goto-char here)))
  5027. (setq nest (1- nest)))
  5028. ((match-end 3)
  5029. (setq nest (1+ nest)))
  5030. ((bobp)
  5031. (ding 't)
  5032. (setq nest 0))))))
  5033. (defun verilog-leap-to-head ()
  5034. "Move point to the head of this block.
  5035. Jump from end to matching begin, from endcase to matching case, and so on."
  5036. (let ((reg nil)
  5037. snest
  5038. (nesting 'yes)
  5039. (nest 1))
  5040. (cond
  5041. ((looking-at "\\<end\\>")
  5042. ;; 1: Search back for matching begin
  5043. (setq reg (concat "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)\\|"
  5044. "\\(\\<endcase\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)" )))
  5045. ((looking-at "\\<endtask\\>")
  5046. ;; 2: Search back for matching task
  5047. (setq reg "\\(\\<task\\>\\)\\|\\(\\(\\(\\<virtual\\>\\s-+\\)\\|\\(\\<protected\\>\\s-+\\)\\)+\\<task\\>\\)")
  5048. (setq nesting 'no))
  5049. ((looking-at "\\<endcase\\>")
  5050. (catch 'nesting
  5051. (verilog-leap-to-case-head) )
  5052. (setq reg nil) ; to force skip
  5053. )
  5054. ((looking-at "\\<join\\(_any\\|_none\\)?\\>")
  5055. ;; 4: Search back for matching fork
  5056. (setq reg "\\(\\<fork\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)" ))
  5057. ((looking-at "\\<endclass\\>")
  5058. ;; 5: Search back for matching class
  5059. (setq reg "\\(\\<class\\>\\)\\|\\(\\<endclass\\>\\)" ))
  5060. ((looking-at "\\<endtable\\>")
  5061. ;; 6: Search back for matching table
  5062. (setq reg "\\(\\<table\\>\\)\\|\\(\\<endtable\\>\\)" ))
  5063. ((looking-at "\\<endspecify\\>")
  5064. ;; 7: Search back for matching specify
  5065. (setq reg "\\(\\<specify\\>\\)\\|\\(\\<endspecify\\>\\)" ))
  5066. ((looking-at "\\<endfunction\\>")
  5067. ;; 8: Search back for matching function
  5068. (setq reg "\\(\\<function\\>\\)\\|\\(\\(\\(\\<virtual\\>\\s-+\\)\\|\\(\\<protected\\>\\s-+\\)\\)+\\<function\\>\\)")
  5069. (setq nesting 'no))
  5070. ;;(setq reg "\\(\\<function\\>\\)\\|\\(\\<endfunction\\>\\)" ))
  5071. ((looking-at "\\<endgenerate\\>")
  5072. ;; 8: Search back for matching generate
  5073. (setq reg "\\(\\<generate\\>\\)\\|\\(\\<endgenerate\\>\\)" ))
  5074. ((looking-at "\\<endgroup\\>")
  5075. ;; 10: Search back for matching covergroup
  5076. (setq reg "\\(\\<covergroup\\>\\)\\|\\(\\<endgroup\\>\\)" ))
  5077. ((looking-at "\\<endproperty\\>")
  5078. ;; 11: Search back for matching property
  5079. (setq reg "\\(\\<property\\>\\)\\|\\(\\<endproperty\\>\\)" ))
  5080. ((looking-at verilog-uvm-end-re)
  5081. ;; 12: Search back for matching sequence
  5082. (setq reg (concat "\\(" verilog-uvm-begin-re "\\|" verilog-uvm-end-re "\\)")))
  5083. ((looking-at verilog-ovm-end-re)
  5084. ;; 12: Search back for matching sequence
  5085. (setq reg (concat "\\(" verilog-ovm-begin-re "\\|" verilog-ovm-end-re "\\)")))
  5086. ((looking-at verilog-vmm-end-re)
  5087. ;; 12: Search back for matching sequence
  5088. (setq reg (concat "\\(" verilog-vmm-begin-re "\\|" verilog-vmm-end-re "\\)")))
  5089. ((looking-at "\\<endinterface\\>")
  5090. ;; 12: Search back for matching interface
  5091. (setq reg "\\(\\<interface\\>\\)\\|\\(\\<endinterface\\>\\)" ))
  5092. ((looking-at "\\<endsequence\\>")
  5093. ;; 12: Search back for matching sequence
  5094. (setq reg "\\(\\<\\(rand\\)?sequence\\>\\)\\|\\(\\<endsequence\\>\\)" ))
  5095. ((looking-at "\\<endclocking\\>")
  5096. ;; 12: Search back for matching clocking
  5097. (setq reg "\\(\\<clocking\\)\\|\\(\\<endclocking\\>\\)" )))
  5098. (if reg
  5099. (catch 'skip
  5100. (if (eq nesting 'yes)
  5101. (let (sreg)
  5102. (while (verilog-re-search-backward reg nil 'move)
  5103. (cond
  5104. ((match-end 1) ; begin
  5105. (if (looking-at "fork")
  5106. (let ((here (point)))
  5107. (verilog-beg-of-statement)
  5108. (unless (looking-at verilog-disable-fork-re)
  5109. (goto-char here)
  5110. (setq nest (1- nest))))
  5111. (setq nest (1- nest)))
  5112. (if (= 0 nest)
  5113. ;; Now previous line describes syntax
  5114. (throw 'skip 1))
  5115. (if (and snest
  5116. (= snest nest))
  5117. (setq reg sreg)))
  5118. ((match-end 2) ; end
  5119. (setq nest (1+ nest)))
  5120. ((match-end 3)
  5121. ;; endcase, jump to case
  5122. (setq snest nest)
  5123. (setq nest (1+ nest))
  5124. (setq sreg reg)
  5125. (setq reg "\\(\\<randcase\\>\\|\\<case[xz]?\\>[^:]\\)\\|\\(\\<endcase\\>\\)" ))
  5126. ((match-end 4)
  5127. ;; join, jump to fork
  5128. (setq snest nest)
  5129. (setq nest (1+ nest))
  5130. (setq sreg reg)
  5131. (setq reg "\\(\\<fork\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)" ))
  5132. )))
  5133. ;no nesting
  5134. (if (and
  5135. (verilog-re-search-backward reg nil 'move)
  5136. (match-end 1)) ; task -> could be virtual and/or protected
  5137. (progn
  5138. (verilog-beg-of-statement)
  5139. (throw 'skip 1))
  5140. (throw 'skip 1)))))))
  5141. (defun verilog-continued-line ()
  5142. "Return true if this is a continued line.
  5143. Set point to where line starts."
  5144. (let ((continued 't))
  5145. (if (eq 0 (forward-line -1))
  5146. (progn
  5147. (end-of-line)
  5148. (verilog-backward-ws&directives)
  5149. (if (bobp)
  5150. (setq continued nil)
  5151. (while (and continued
  5152. (save-excursion
  5153. (skip-chars-backward " \t")
  5154. (not (bolp))))
  5155. (setq continued (verilog-backward-token)))))
  5156. (setq continued nil))
  5157. continued))
  5158. (defun verilog-backward-token ()
  5159. "Step backward token, returning true if this is a continued line."
  5160. (interactive)
  5161. (verilog-backward-syntactic-ws)
  5162. (cond
  5163. ((bolp)
  5164. nil)
  5165. (;-- Anything ending in a ; is complete
  5166. (= (preceding-char) ?\;)
  5167. nil)
  5168. (; If a "}" is prefixed by a ";", then this is a complete statement
  5169. ; i.e.: constraint foo { a = b; }
  5170. (= (preceding-char) ?\})
  5171. (progn
  5172. (backward-char)
  5173. (not(verilog-at-close-constraint-p))))
  5174. (;-- constraint foo { a = b }
  5175. ; is a complete statement. *sigh*
  5176. (= (preceding-char) ?\{)
  5177. (progn
  5178. (backward-char)
  5179. (not (verilog-at-constraint-p))))
  5180. (;" string "
  5181. (= (preceding-char) ?\")
  5182. (backward-char)
  5183. (verilog-skip-backward-comment-or-string)
  5184. nil)
  5185. (; [3:4]
  5186. (= (preceding-char) ?\])
  5187. (backward-char)
  5188. (verilog-backward-open-bracket)
  5189. t)
  5190. (;-- Could be 'case (foo)' or 'always @(bar)' which is complete
  5191. ; also could be simply '@(foo)'
  5192. ; or foo u1 #(a=8)
  5193. ; (b, ... which ISN'T complete
  5194. ;;;; Do we need this???
  5195. (= (preceding-char) ?\))
  5196. (progn
  5197. (backward-char)
  5198. (verilog-backward-up-list 1)
  5199. (verilog-backward-syntactic-ws)
  5200. (let ((back (point)))
  5201. (forward-word -1)
  5202. (cond
  5203. ;;XX
  5204. ((looking-at "\\<\\(always\\(_latch\\|_ff\\|_comb\\)?\\|case\\(\\|[xz]\\)\\|for\\(\\|each\\|ever\\)\\|i\\(f\\|nitial\\)\\|repeat\\|while\\)\\>")
  5205. (not (looking-at "\\<randcase\\>\\|\\<case[xz]?\\>[^:]")))
  5206. ((looking-at verilog-uvm-statement-re)
  5207. nil)
  5208. ((looking-at verilog-uvm-begin-re)
  5209. t)
  5210. ((looking-at verilog-uvm-end-re)
  5211. t)
  5212. ((looking-at verilog-ovm-statement-re)
  5213. nil)
  5214. ((looking-at verilog-ovm-begin-re)
  5215. t)
  5216. ((looking-at verilog-ovm-end-re)
  5217. t)
  5218. ;; JBA find VMM macros
  5219. ((looking-at verilog-vmm-statement-re)
  5220. nil )
  5221. ((looking-at verilog-vmm-begin-re)
  5222. t)
  5223. ((looking-at verilog-vmm-end-re)
  5224. nil)
  5225. ;; JBA trying to catch macro lines with no ; at end
  5226. ((looking-at "\\<`")
  5227. nil)
  5228. (t
  5229. (goto-char back)
  5230. (cond
  5231. ((= (preceding-char) ?\@)
  5232. (backward-char)
  5233. (save-excursion
  5234. (verilog-backward-token)
  5235. (not (looking-at "\\<\\(always\\(_latch\\|_ff\\|_comb\\)?\\|initial\\|while\\)\\>"))))
  5236. ((= (preceding-char) ?\#)
  5237. (backward-char))
  5238. (t t)))))))
  5239. (;-- any of begin|initial|while are complete statements; 'begin : foo' is also complete
  5240. t
  5241. (forward-word -1)
  5242. (while (= (preceding-char) ?\_)
  5243. (forward-word -1))
  5244. (cond
  5245. ((looking-at "\\<else\\>")
  5246. t)
  5247. ((looking-at verilog-behavioral-block-beg-re)
  5248. t)
  5249. ((looking-at verilog-indent-re)
  5250. nil)
  5251. (t
  5252. (let
  5253. ((back (point)))
  5254. (verilog-backward-syntactic-ws)
  5255. (cond
  5256. ((= (preceding-char) ?\:)
  5257. (backward-char)
  5258. (verilog-backward-syntactic-ws)
  5259. (backward-sexp)
  5260. (if (looking-at verilog-nameable-item-re )
  5261. nil
  5262. t))
  5263. ((= (preceding-char) ?\#)
  5264. (backward-char)
  5265. t)
  5266. ((= (preceding-char) ?\`)
  5267. (backward-char)
  5268. t)
  5269. (t
  5270. (goto-char back)
  5271. t))))))))
  5272. (defun verilog-backward-syntactic-ws ()
  5273. "Move backwards putting point after first non-whitespace non-comment."
  5274. (verilog-skip-backward-comments)
  5275. (forward-comment (- (buffer-size))))
  5276. (defun verilog-backward-syntactic-ws-quick ()
  5277. "As with `verilog-backward-syntactic-ws' but uses `verilog-scan' cache."
  5278. (while (cond ((bobp)
  5279. nil) ; Done
  5280. ((> (skip-syntax-backward " ") 0)
  5281. t)
  5282. ((eq (preceding-char) ?\n) ;; \n's terminate // so aren't space syntax
  5283. (forward-char -1)
  5284. t)
  5285. ((or (verilog-inside-comment-or-string-p (1- (point)))
  5286. (verilog-inside-comment-or-string-p (point)))
  5287. (re-search-backward "[/\"]" nil t) ;; Only way a comment or quote can begin
  5288. t))))
  5289. (defun verilog-forward-syntactic-ws ()
  5290. (verilog-skip-forward-comment-p)
  5291. (forward-comment (buffer-size)))
  5292. (defun verilog-backward-ws&directives (&optional bound)
  5293. "Backward skip over syntactic whitespace and compiler directives for Emacs 19.
  5294. Optional BOUND limits search."
  5295. (save-restriction
  5296. (let* ((bound (or bound (point-min)))
  5297. (here bound)
  5298. (p nil) )
  5299. (if (< bound (point))
  5300. (progn
  5301. (let ((state (save-excursion (verilog-syntax-ppss))))
  5302. (cond
  5303. ((nth 7 state) ;; in // comment
  5304. (verilog-re-search-backward "//" nil 'move)
  5305. (skip-chars-backward "/"))
  5306. ((nth 4 state) ;; in /* */ comment
  5307. (verilog-re-search-backward "/\*" nil 'move))))
  5308. (narrow-to-region bound (point))
  5309. (while (/= here (point))
  5310. (setq here (point))
  5311. (verilog-skip-backward-comments)
  5312. (setq p
  5313. (save-excursion
  5314. (beginning-of-line)
  5315. (cond
  5316. ((and verilog-highlight-translate-off
  5317. (verilog-within-translate-off))
  5318. (verilog-back-to-start-translate-off (point-min)))
  5319. ((looking-at verilog-directive-re-1)
  5320. (point))
  5321. (t
  5322. nil))))
  5323. (if p (goto-char p))))))))
  5324. (defun verilog-forward-ws&directives (&optional bound)
  5325. "Forward skip over syntactic whitespace and compiler directives for Emacs 19.
  5326. Optional BOUND limits search."
  5327. (save-restriction
  5328. (let* ((bound (or bound (point-max)))
  5329. (here bound)
  5330. jump)
  5331. (if (> bound (point))
  5332. (progn
  5333. (let ((state (save-excursion (verilog-syntax-ppss))))
  5334. (cond
  5335. ((nth 7 state) ;; in // comment
  5336. (end-of-line)
  5337. (forward-char 1)
  5338. (skip-chars-forward " \t\n\f")
  5339. )
  5340. ((nth 4 state) ;; in /* */ comment
  5341. (verilog-re-search-forward "\*\/\\s-*" nil 'move))))
  5342. (narrow-to-region (point) bound)
  5343. (while (/= here (point))
  5344. (setq here (point)
  5345. jump nil)
  5346. (forward-comment (buffer-size))
  5347. (and (looking-at "\\s-*(\\*.*\\*)\\s-*") ;; Attribute
  5348. (goto-char (match-end 0)))
  5349. (save-excursion
  5350. (beginning-of-line)
  5351. (if (looking-at verilog-directive-re-1)
  5352. (setq jump t)))
  5353. (if jump
  5354. (beginning-of-line 2))))))))
  5355. (defun verilog-in-comment-p ()
  5356. "Return true if in a star or // comment."
  5357. (let ((state (save-excursion (verilog-syntax-ppss))))
  5358. (or (nth 4 state) (nth 7 state))))
  5359. (defun verilog-in-star-comment-p ()
  5360. "Return true if in a star comment."
  5361. (let ((state (save-excursion (verilog-syntax-ppss))))
  5362. (and
  5363. (nth 4 state) ; t if in a comment of style a // or b /**/
  5364. (not
  5365. (nth 7 state) ; t if in a comment of style b /**/
  5366. ))))
  5367. (defun verilog-in-slash-comment-p ()
  5368. "Return true if in a slash comment."
  5369. (let ((state (save-excursion (verilog-syntax-ppss))))
  5370. (nth 7 state)))
  5371. (defun verilog-in-comment-or-string-p ()
  5372. "Return true if in a string or comment."
  5373. (let ((state (save-excursion (verilog-syntax-ppss))))
  5374. (or (nth 3 state) (nth 4 state) (nth 7 state)))) ; Inside string or comment)
  5375. (defun verilog-in-attribute-p ()
  5376. "Return true if point is in an attribute (* [] attribute *)."
  5377. (save-match-data
  5378. (save-excursion
  5379. (verilog-re-search-backward "\\((\\*\\)\\|\\(\\*)\\)" nil 'move)
  5380. (numberp (match-beginning 1)))))
  5381. (defun verilog-in-parameter-p ()
  5382. "Return true if point is in a parameter assignment #( p1=1, p2=5)."
  5383. (save-match-data
  5384. (save-excursion
  5385. (verilog-re-search-backward "\\(#(\\)\\|\\()\\)" nil 'move)
  5386. (numberp (match-beginning 1)))))
  5387. (defun verilog-in-escaped-name-p ()
  5388. "Return true if in an escaped name."
  5389. (save-excursion
  5390. (backward-char)
  5391. (skip-chars-backward "^ \t\n\f")
  5392. (if (equal (char-after (point) ) ?\\ )
  5393. t
  5394. nil)))
  5395. (defun verilog-in-directive-p ()
  5396. "Return true if in a directive."
  5397. (save-excursion
  5398. (beginning-of-line)
  5399. (looking-at verilog-directive-re-1)))
  5400. (defun verilog-in-parenthesis-p ()
  5401. "Return true if in a ( ) expression (but not { } or [ ])."
  5402. (save-match-data
  5403. (save-excursion
  5404. (verilog-re-search-backward "\\((\\)\\|\\()\\)" nil 'move)
  5405. (numberp (match-beginning 1)))))
  5406. (defun verilog-in-paren ()
  5407. "Return true if in a parenthetical expression.
  5408. May cache result using `verilog-syntax-ppss'."
  5409. (let ((state (save-excursion (verilog-syntax-ppss))))
  5410. (> (nth 0 state) 0 )))
  5411. (defun verilog-in-paren-quick ()
  5412. "Return true if in a parenthetical expression.
  5413. Always starts from point-min, to allow inserts with hooks disabled."
  5414. ;; The -quick refers to its use alongside the other -quick functions,
  5415. ;; not that it's likely to be faster than verilog-in-paren.
  5416. (let ((state (save-excursion (parse-partial-sexp (point-min) (point)))))
  5417. (> (nth 0 state) 0 )))
  5418. (defun verilog-in-struct-p ()
  5419. "Return true if in a struct declaration."
  5420. (interactive)
  5421. (save-excursion
  5422. (if (verilog-in-paren)
  5423. (progn
  5424. (verilog-backward-up-list 1)
  5425. (verilog-at-struct-p)
  5426. )
  5427. nil)))
  5428. (defun verilog-in-coverage-p ()
  5429. "Return true if in a constraint or coverpoint expression."
  5430. (interactive)
  5431. (save-excursion
  5432. (if (verilog-in-paren)
  5433. (progn
  5434. (verilog-backward-up-list 1)
  5435. (verilog-at-constraint-p)
  5436. )
  5437. nil)))
  5438. (defun verilog-at-close-constraint-p ()
  5439. "If at the } that closes a constraint or covergroup, return true."
  5440. (if (and
  5441. (equal (char-after) ?\})
  5442. (verilog-in-paren))
  5443. (save-excursion
  5444. (verilog-backward-ws&directives)
  5445. (if (equal (char-before) ?\;)
  5446. (point)
  5447. nil))))
  5448. (defun verilog-at-constraint-p ()
  5449. "If at the { of a constraint or coverpoint definition, return true, moving point to constraint."
  5450. (if (save-excursion
  5451. (and
  5452. (equal (char-after) ?\{)
  5453. (forward-list)
  5454. (progn (backward-char 1)
  5455. (verilog-backward-ws&directives)
  5456. (equal (char-before) ?\;))))
  5457. ;; maybe
  5458. (verilog-re-search-backward "\\<constraint\\|coverpoint\\|cross\\>" nil 'move)
  5459. ;; not
  5460. nil))
  5461. (defun verilog-at-struct-p ()
  5462. "If at the { of a struct, return true, moving point to struct."
  5463. (save-excursion
  5464. (if (and (equal (char-after) ?\{)
  5465. (verilog-backward-token))
  5466. (looking-at "\\<struct\\|union\\|packed\\|\\(un\\)?signed\\>")
  5467. nil)))
  5468. (defun verilog-parenthesis-depth ()
  5469. "Return non zero if in parenthetical-expression."
  5470. (save-excursion (nth 1 (verilog-syntax-ppss))))
  5471. (defun verilog-skip-forward-comment-or-string ()
  5472. "Return true if in a string or comment."
  5473. (let ((state (save-excursion (verilog-syntax-ppss))))
  5474. (cond
  5475. ((nth 3 state) ;Inside string
  5476. (search-forward "\"")
  5477. t)
  5478. ((nth 7 state) ;Inside // comment
  5479. (forward-line 1)
  5480. t)
  5481. ((nth 4 state) ;Inside any comment (hence /**/)
  5482. (search-forward "*/"))
  5483. (t
  5484. nil))))
  5485. (defun verilog-skip-backward-comment-or-string ()
  5486. "Return true if in a string or comment."
  5487. (let ((state (save-excursion (verilog-syntax-ppss))))
  5488. (cond
  5489. ((nth 3 state) ;Inside string
  5490. (search-backward "\"")
  5491. t)
  5492. ((nth 7 state) ;Inside // comment
  5493. (search-backward "//")
  5494. (skip-chars-backward "/")
  5495. t)
  5496. ((nth 4 state) ;Inside /* */ comment
  5497. (search-backward "/*")
  5498. t)
  5499. (t
  5500. nil))))
  5501. (defun verilog-skip-backward-comments ()
  5502. "Return true if a comment was skipped."
  5503. (let ((more t))
  5504. (while more
  5505. (setq more
  5506. (let ((state (save-excursion (verilog-syntax-ppss))))
  5507. (cond
  5508. ((nth 7 state) ;Inside // comment
  5509. (search-backward "//")
  5510. (skip-chars-backward "/")
  5511. (skip-chars-backward " \t\n\f")
  5512. t)
  5513. ((nth 4 state) ;Inside /* */ comment
  5514. (search-backward "/*")
  5515. (skip-chars-backward " \t\n\f")
  5516. t)
  5517. ((and (not (bobp))
  5518. (= (char-before) ?\/)
  5519. (= (char-before (1- (point))) ?\*))
  5520. (goto-char (- (point) 2))
  5521. t) ;; Let nth 4 state handle the rest
  5522. ((and (not (bobp))
  5523. (= (char-before) ?\))
  5524. (= (char-before (1- (point))) ?\*))
  5525. (goto-char (- (point) 2))
  5526. (if (search-backward "(*" nil t)
  5527. (progn
  5528. (skip-chars-backward " \t\n\f")
  5529. t)
  5530. (progn
  5531. (goto-char (+ (point) 2))
  5532. nil)))
  5533. (t
  5534. (/= (skip-chars-backward " \t\n\f") 0))))))))
  5535. (defun verilog-skip-forward-comment-p ()
  5536. "If in comment, move to end and return true."
  5537. (let* (h
  5538. (state (save-excursion (verilog-syntax-ppss)))
  5539. (skip (cond
  5540. ((nth 3 state) ;Inside string
  5541. t)
  5542. ((nth 7 state) ;Inside // comment
  5543. (end-of-line)
  5544. (forward-char 1)
  5545. t)
  5546. ((nth 4 state) ;Inside /* comment
  5547. (search-forward "*/")
  5548. t)
  5549. ((verilog-in-attribute-p) ;Inside (* attribute
  5550. (search-forward "*)" nil t)
  5551. t)
  5552. (t nil))))
  5553. (skip-chars-forward " \t\n\f")
  5554. (while
  5555. (cond
  5556. ((looking-at "\\/\\*")
  5557. (progn
  5558. (setq h (point))
  5559. (goto-char (match-end 0))
  5560. (if (search-forward "*/" nil t)
  5561. (progn
  5562. (skip-chars-forward " \t\n\f")
  5563. (setq skip 't))
  5564. (progn
  5565. (goto-char h)
  5566. nil))))
  5567. ((looking-at "(\\*")
  5568. (progn
  5569. (setq h (point))
  5570. (goto-char (match-end 0))
  5571. (if (search-forward "*)" nil t)
  5572. (progn
  5573. (skip-chars-forward " \t\n\f")
  5574. (setq skip 't))
  5575. (progn
  5576. (goto-char h)
  5577. nil))))
  5578. (t nil)))
  5579. skip))
  5580. (defun verilog-indent-line-relative ()
  5581. "Cheap version of indent line.
  5582. Only look at a few lines to determine indent level."
  5583. (interactive)
  5584. (let ((indent-str)
  5585. (sp (point)))
  5586. (if (looking-at "^[ \t]*$")
  5587. (cond ;- A blank line; No need to be too smart.
  5588. ((bobp)
  5589. (setq indent-str (list 'cpp 0)))
  5590. ((verilog-continued-line)
  5591. (let ((sp1 (point)))
  5592. (if (verilog-continued-line)
  5593. (progn
  5594. (goto-char sp)
  5595. (setq indent-str
  5596. (list 'statement (verilog-current-indent-level))))
  5597. (goto-char sp1)
  5598. (setq indent-str (list 'block (verilog-current-indent-level)))))
  5599. (goto-char sp))
  5600. ((goto-char sp)
  5601. (setq indent-str (verilog-calculate-indent))))
  5602. (progn (skip-chars-forward " \t")
  5603. (setq indent-str (verilog-calculate-indent))))
  5604. (verilog-do-indent indent-str)))
  5605. (defun verilog-indent-line ()
  5606. "Indent for special part of code."
  5607. (verilog-do-indent (verilog-calculate-indent)))
  5608. (defun verilog-do-indent (indent-str)
  5609. (let ((type (car indent-str))
  5610. (ind (car (cdr indent-str))))
  5611. (cond
  5612. (; handle continued exp
  5613. (eq type 'cexp)
  5614. (let ((here (point)))
  5615. (verilog-backward-syntactic-ws)
  5616. (cond
  5617. ((or
  5618. (= (preceding-char) ?\,)
  5619. (= (preceding-char) ?\])
  5620. (save-excursion
  5621. (verilog-beg-of-statement-1)
  5622. (looking-at verilog-declaration-re)))
  5623. (let* ( fst
  5624. (val
  5625. (save-excursion
  5626. (backward-char 1)
  5627. (verilog-beg-of-statement-1)
  5628. (setq fst (point))
  5629. (if (looking-at verilog-declaration-re)
  5630. (progn ;; we have multiple words
  5631. (goto-char (match-end 0))
  5632. (skip-chars-forward " \t")
  5633. (cond
  5634. ((and verilog-indent-declaration-macros
  5635. (= (following-char) ?\`))
  5636. (progn
  5637. (forward-char 1)
  5638. (forward-word 1)
  5639. (skip-chars-forward " \t")))
  5640. ((= (following-char) ?\[)
  5641. (progn
  5642. (forward-char 1)
  5643. (verilog-backward-up-list -1)
  5644. (skip-chars-forward " \t"))))
  5645. (current-column))
  5646. (progn
  5647. (goto-char fst)
  5648. (+ (current-column) verilog-cexp-indent))))))
  5649. (goto-char here)
  5650. (indent-line-to val)
  5651. (if (and (not verilog-indent-lists)
  5652. (verilog-in-paren))
  5653. (verilog-pretty-declarations))
  5654. ))
  5655. ((= (preceding-char) ?\) )
  5656. (goto-char here)
  5657. (let ((val (eval (cdr (assoc type verilog-indent-alist)))))
  5658. (indent-line-to val)))
  5659. (t
  5660. (goto-char here)
  5661. (let ((val))
  5662. (verilog-beg-of-statement-1)
  5663. (if (and (< (point) here)
  5664. (verilog-re-search-forward "=[ \\t]*" here 'move))
  5665. (setq val (current-column))
  5666. (setq val (eval (cdr (assoc type verilog-indent-alist)))))
  5667. (goto-char here)
  5668. (indent-line-to val))))))
  5669. (; handle inside parenthetical expressions
  5670. (eq type 'cparenexp)
  5671. (let* ( here
  5672. (val (save-excursion
  5673. (verilog-backward-up-list 1)
  5674. (forward-char 1)
  5675. (if verilog-indent-lists
  5676. (skip-chars-forward " \t")
  5677. (verilog-forward-syntactic-ws))
  5678. (setq here (point))
  5679. (current-column)))
  5680. (decl (save-excursion
  5681. (goto-char here)
  5682. (verilog-forward-syntactic-ws)
  5683. (setq here (point))
  5684. (looking-at verilog-declaration-re))))
  5685. (indent-line-to val)
  5686. (if decl
  5687. (verilog-pretty-declarations))))
  5688. (;-- Handle the ends
  5689. (or
  5690. (looking-at verilog-end-block-re )
  5691. (verilog-at-close-constraint-p))
  5692. (let ((val (if (eq type 'statement)
  5693. (- ind verilog-indent-level)
  5694. ind)))
  5695. (indent-line-to val)))
  5696. (;-- Case -- maybe line 'em up
  5697. (and (eq type 'case) (not (looking-at "^[ \t]*$")))
  5698. (progn
  5699. (cond
  5700. ((looking-at "\\<endcase\\>")
  5701. (indent-line-to ind))
  5702. (t
  5703. (let ((val (eval (cdr (assoc type verilog-indent-alist)))))
  5704. (indent-line-to val))))))
  5705. (;-- defun
  5706. (and (eq type 'defun)
  5707. (looking-at verilog-zero-indent-re))
  5708. (indent-line-to 0))
  5709. (;-- declaration
  5710. (and (or
  5711. (eq type 'defun)
  5712. (eq type 'block))
  5713. (looking-at verilog-declaration-re))
  5714. (verilog-indent-declaration ind))
  5715. (;-- Everything else
  5716. t
  5717. (let ((val (eval (cdr (assoc type verilog-indent-alist)))))
  5718. (indent-line-to val))))
  5719. (if (looking-at "[ \t]+$")
  5720. (skip-chars-forward " \t"))
  5721. indent-str ; Return indent data
  5722. ))
  5723. (defun verilog-current-indent-level ()
  5724. "Return the indent-level of the current statement."
  5725. (save-excursion
  5726. (let (par-pos)
  5727. (beginning-of-line)
  5728. (setq par-pos (verilog-parenthesis-depth))
  5729. (while par-pos
  5730. (goto-char par-pos)
  5731. (beginning-of-line)
  5732. (setq par-pos (verilog-parenthesis-depth)))
  5733. (skip-chars-forward " \t")
  5734. (current-column))))
  5735. (defun verilog-case-indent-level ()
  5736. "Return the indent-level of the current statement.
  5737. Do not count named blocks or case-statements."
  5738. (save-excursion
  5739. (skip-chars-forward " \t")
  5740. (cond
  5741. ((looking-at verilog-named-block-re)
  5742. (current-column))
  5743. ((and (not (looking-at verilog-extended-case-re))
  5744. (looking-at "^[^:;]+[ \t]*:"))
  5745. (verilog-re-search-forward ":" nil t)
  5746. (skip-chars-forward " \t")
  5747. (current-column))
  5748. (t
  5749. (current-column)))))
  5750. (defun verilog-indent-comment ()
  5751. "Indent current line as comment."
  5752. (let* ((stcol
  5753. (cond
  5754. ((verilog-in-star-comment-p)
  5755. (save-excursion
  5756. (re-search-backward "/\\*" nil t)
  5757. (1+(current-column))))
  5758. (comment-column
  5759. comment-column )
  5760. (t
  5761. (save-excursion
  5762. (re-search-backward "//" nil t)
  5763. (current-column))))))
  5764. (indent-line-to stcol)
  5765. stcol))
  5766. (defun verilog-more-comment ()
  5767. "Make more comment lines like the previous."
  5768. (let* ((star 0)
  5769. (stcol
  5770. (cond
  5771. ((verilog-in-star-comment-p)
  5772. (save-excursion
  5773. (setq star 1)
  5774. (re-search-backward "/\\*" nil t)
  5775. (1+(current-column))))
  5776. (comment-column
  5777. comment-column )
  5778. (t
  5779. (save-excursion
  5780. (re-search-backward "//" nil t)
  5781. (current-column))))))
  5782. (progn
  5783. (indent-to stcol)
  5784. (if (and star
  5785. (save-excursion
  5786. (forward-line -1)
  5787. (skip-chars-forward " \t")
  5788. (looking-at "\*")))
  5789. (insert "* ")))))
  5790. (defun verilog-comment-indent (&optional arg)
  5791. "Return the column number the line should be indented to.
  5792. ARG is ignored, for `comment-indent-function' compatibility."
  5793. (cond
  5794. ((verilog-in-star-comment-p)
  5795. (save-excursion
  5796. (re-search-backward "/\\*" nil t)
  5797. (1+(current-column))))
  5798. ( comment-column
  5799. comment-column )
  5800. (t
  5801. (save-excursion
  5802. (re-search-backward "//" nil t)
  5803. (current-column)))))
  5804. ;;
  5805. (defun verilog-pretty-declarations (&optional quiet)
  5806. "Line up declarations around point.
  5807. Be verbose about progress unless optional QUIET set."
  5808. (interactive)
  5809. (let* ((m1 (make-marker))
  5810. (e (point))
  5811. el
  5812. r
  5813. (here (point))
  5814. ind
  5815. start
  5816. startpos
  5817. end
  5818. endpos
  5819. base-ind
  5820. )
  5821. (save-excursion
  5822. (if (progn
  5823. ; (verilog-beg-of-statement-1)
  5824. (beginning-of-line)
  5825. (verilog-forward-syntactic-ws)
  5826. (and (not (verilog-in-directive-p)) ;; could have `define input foo
  5827. (looking-at verilog-declaration-re)))
  5828. (progn
  5829. (if (verilog-parenthesis-depth)
  5830. ;; in an argument list or parameter block
  5831. (setq el (verilog-backward-up-list -1)
  5832. start (progn
  5833. (goto-char e)
  5834. (verilog-backward-up-list 1)
  5835. (forward-line) ;; ignore ( input foo,
  5836. (verilog-re-search-forward verilog-declaration-re el 'move)
  5837. (goto-char (match-beginning 0))
  5838. (skip-chars-backward " \t")
  5839. (point))
  5840. startpos (set-marker (make-marker) start)
  5841. end (progn
  5842. (goto-char start)
  5843. (verilog-backward-up-list -1)
  5844. (forward-char -1)
  5845. (verilog-backward-syntactic-ws)
  5846. (point))
  5847. endpos (set-marker (make-marker) end)
  5848. base-ind (progn
  5849. (goto-char start)
  5850. (forward-char 1)
  5851. (skip-chars-forward " \t")
  5852. (current-column))
  5853. )
  5854. ;; in a declaration block (not in argument list)
  5855. (setq
  5856. start (progn
  5857. (verilog-beg-of-statement-1)
  5858. (while (and (looking-at verilog-declaration-re)
  5859. (not (bobp)))
  5860. (skip-chars-backward " \t")
  5861. (setq e (point))
  5862. (beginning-of-line)
  5863. (verilog-backward-syntactic-ws)
  5864. (backward-char)
  5865. (verilog-beg-of-statement-1))
  5866. e)
  5867. startpos (set-marker (make-marker) start)
  5868. end (progn
  5869. (goto-char here)
  5870. (verilog-end-of-statement)
  5871. (setq e (point)) ;Might be on last line
  5872. (verilog-forward-syntactic-ws)
  5873. (while (looking-at verilog-declaration-re)
  5874. (verilog-end-of-statement)
  5875. (setq e (point))
  5876. (verilog-forward-syntactic-ws))
  5877. e)
  5878. endpos (set-marker (make-marker) end)
  5879. base-ind (progn
  5880. (goto-char start)
  5881. (verilog-do-indent (verilog-calculate-indent))
  5882. (verilog-forward-ws&directives)
  5883. (current-column))))
  5884. ;; OK, start and end are set
  5885. (goto-char (marker-position startpos))
  5886. (if (and (not quiet)
  5887. (> (- end start) 100))
  5888. (message "Lining up declarations..(please stand by)"))
  5889. ;; Get the beginning of line indent first
  5890. (while (progn (setq e (marker-position endpos))
  5891. (< (point) e))
  5892. (cond
  5893. ((save-excursion (skip-chars-backward " \t")
  5894. (bolp))
  5895. (verilog-forward-ws&directives)
  5896. (indent-line-to base-ind)
  5897. (verilog-forward-ws&directives)
  5898. (if (< (point) e)
  5899. (verilog-re-search-forward "[ \t\n\f]" e 'move)))
  5900. (t
  5901. (just-one-space)
  5902. (verilog-re-search-forward "[ \t\n\f]" e 'move)))
  5903. ;;(forward-line)
  5904. )
  5905. ;; Now find biggest prefix
  5906. (setq ind (verilog-get-lineup-indent (marker-position startpos) endpos))
  5907. ;; Now indent each line.
  5908. (goto-char (marker-position startpos))
  5909. (while (progn (setq e (marker-position endpos))
  5910. (setq r (- e (point)))
  5911. (> r 0))
  5912. (setq e (point))
  5913. (unless quiet (message "%d" r))
  5914. ;;(verilog-do-indent (verilog-calculate-indent)))
  5915. (verilog-forward-ws&directives)
  5916. (cond
  5917. ((or (and verilog-indent-declaration-macros
  5918. (looking-at verilog-declaration-re-2-macro))
  5919. (looking-at verilog-declaration-re-2-no-macro))
  5920. (let ((p (match-end 0)))
  5921. (set-marker m1 p)
  5922. (if (verilog-re-search-forward "[[#`]" p 'move)
  5923. (progn
  5924. (forward-char -1)
  5925. (just-one-space)
  5926. (goto-char (marker-position m1))
  5927. (just-one-space)
  5928. (indent-to ind))
  5929. (progn
  5930. (just-one-space)
  5931. (indent-to ind)))))
  5932. ((verilog-continued-line-1 (marker-position startpos))
  5933. (goto-char e)
  5934. (indent-line-to ind))
  5935. ((verilog-in-struct-p)
  5936. ;; could have a declaration of a user defined item
  5937. (goto-char e)
  5938. (verilog-end-of-statement))
  5939. (t ; Must be comment or white space
  5940. (goto-char e)
  5941. (verilog-forward-ws&directives)
  5942. (forward-line -1)))
  5943. (forward-line 1))
  5944. (unless quiet (message "")))))))
  5945. (defun verilog-pretty-expr (&optional quiet myre)
  5946. "Line up expressions around point, optionally QUIET with regexp MYRE ignored."
  5947. (interactive)
  5948. (if (not (verilog-in-comment-or-string-p))
  5949. (save-excursion
  5950. (let ((rexp (concat "^\\s-*" verilog-complete-reg)))
  5951. (beginning-of-line)
  5952. (if (and (not (looking-at rexp ))
  5953. (looking-at verilog-assignment-operation-re)
  5954. (save-excursion
  5955. (goto-char (match-end 2))
  5956. (and (not (verilog-in-attribute-p))
  5957. (not (verilog-in-parameter-p))
  5958. (not (verilog-in-comment-or-string-p)))))
  5959. (let* ((here (point))
  5960. (e) (r)
  5961. (start
  5962. (progn
  5963. (beginning-of-line)
  5964. (setq e (point))
  5965. (verilog-backward-syntactic-ws)
  5966. (beginning-of-line)
  5967. (while (and (not (looking-at rexp ))
  5968. (looking-at verilog-assignment-operation-re)
  5969. (not (bobp))
  5970. )
  5971. (setq e (point))
  5972. (verilog-backward-syntactic-ws)
  5973. (beginning-of-line)
  5974. ) ;Ack, need to grok `define
  5975. e))
  5976. (end
  5977. (progn
  5978. (goto-char here)
  5979. (end-of-line)
  5980. (setq e (point)) ;Might be on last line
  5981. (verilog-forward-syntactic-ws)
  5982. (beginning-of-line)
  5983. (while (and
  5984. (not (looking-at rexp ))
  5985. (looking-at verilog-assignment-operation-re)
  5986. (progn
  5987. (end-of-line)
  5988. (not (eq e (point)))))
  5989. (setq e (point))
  5990. (verilog-forward-syntactic-ws)
  5991. (beginning-of-line)
  5992. )
  5993. e))
  5994. (endpos (set-marker (make-marker) end))
  5995. (ind)
  5996. )
  5997. (goto-char start)
  5998. (verilog-do-indent (verilog-calculate-indent))
  5999. (if (and (not quiet)
  6000. (> (- end start) 100))
  6001. (message "Lining up expressions..(please stand by)"))
  6002. ;; Set indent to minimum throughout region
  6003. (while (< (point) (marker-position endpos))
  6004. (beginning-of-line)
  6005. (verilog-just-one-space verilog-assignment-operation-re)
  6006. (beginning-of-line)
  6007. (verilog-do-indent (verilog-calculate-indent))
  6008. (end-of-line)
  6009. (verilog-forward-syntactic-ws)
  6010. )
  6011. ;; Now find biggest prefix
  6012. (setq ind (verilog-get-lineup-indent-2 verilog-assignment-operation-re start endpos))
  6013. ;; Now indent each line.
  6014. (goto-char start)
  6015. (while (progn (setq e (marker-position endpos))
  6016. (setq r (- e (point)))
  6017. (> r 0))
  6018. (setq e (point))
  6019. (if (not quiet) (message "%d" r))
  6020. (cond
  6021. ((looking-at verilog-assignment-operation-re)
  6022. (goto-char (match-beginning 2))
  6023. (if (not (or (verilog-in-parenthesis-p) ;; leave attributes and comparisons alone
  6024. (verilog-in-coverage-p)))
  6025. (if (eq (char-after) ?=)
  6026. (indent-to (1+ ind)) ; line up the = of the <= with surrounding =
  6027. (indent-to ind)
  6028. ))
  6029. )
  6030. ((verilog-continued-line-1 start)
  6031. (goto-char e)
  6032. (indent-line-to ind))
  6033. (t ; Must be comment or white space
  6034. (goto-char e)
  6035. (verilog-forward-ws&directives)
  6036. (forward-line -1))
  6037. )
  6038. (forward-line 1))
  6039. (unless quiet (message ""))
  6040. ))))))
  6041. (defun verilog-just-one-space (myre)
  6042. "Remove extra spaces around regular expression MYRE."
  6043. (interactive)
  6044. (if (and (not(looking-at verilog-complete-reg))
  6045. (looking-at myre))
  6046. (let ((p1 (match-end 1))
  6047. (p2 (match-end 2)))
  6048. (progn
  6049. (goto-char p2)
  6050. (just-one-space)
  6051. (goto-char p1)
  6052. (just-one-space)))))
  6053. (defun verilog-indent-declaration (baseind)
  6054. "Indent current lines as declaration.
  6055. Line up the variable names based on previous declaration's indentation.
  6056. BASEIND is the base indent to offset everything."
  6057. (interactive)
  6058. (let ((pos (point-marker))
  6059. (lim (save-excursion
  6060. ;; (verilog-re-search-backward verilog-declaration-opener nil 'move)
  6061. (verilog-re-search-backward "\\(\\<begin\\>\\)\\|\\(\\<module\\>\\)\\|\\(\\<task\\>\\)" nil 'move)
  6062. (point)))
  6063. (ind)
  6064. (val)
  6065. (m1 (make-marker)))
  6066. (setq val
  6067. (+ baseind (eval (cdr (assoc 'declaration verilog-indent-alist)))))
  6068. (indent-line-to val)
  6069. ;; Use previous declaration (in this module) as template.
  6070. (if (or (eq 'all verilog-auto-lineup)
  6071. (eq 'declarations verilog-auto-lineup))
  6072. (if (verilog-re-search-backward
  6073. (or (and verilog-indent-declaration-macros
  6074. verilog-declaration-re-1-macro)
  6075. verilog-declaration-re-1-no-macro) lim t)
  6076. (progn
  6077. (goto-char (match-end 0))
  6078. (skip-chars-forward " \t")
  6079. (setq ind (current-column))
  6080. (goto-char pos)
  6081. (setq val
  6082. (+ baseind
  6083. (eval (cdr (assoc 'declaration verilog-indent-alist)))))
  6084. (indent-line-to val)
  6085. (if (and verilog-indent-declaration-macros
  6086. (looking-at verilog-declaration-re-2-macro))
  6087. (let ((p (match-end 0)))
  6088. (set-marker m1 p)
  6089. (if (verilog-re-search-forward "[[#`]" p 'move)
  6090. (progn
  6091. (forward-char -1)
  6092. (just-one-space)
  6093. (goto-char (marker-position m1))
  6094. (just-one-space)
  6095. (indent-to ind))
  6096. (if (/= (current-column) ind)
  6097. (progn
  6098. (just-one-space)
  6099. (indent-to ind)))))
  6100. (if (looking-at verilog-declaration-re-2-no-macro)
  6101. (let ((p (match-end 0)))
  6102. (set-marker m1 p)
  6103. (if (verilog-re-search-forward "[[`#]" p 'move)
  6104. (progn
  6105. (forward-char -1)
  6106. (just-one-space)
  6107. (goto-char (marker-position m1))
  6108. (just-one-space)
  6109. (indent-to ind))
  6110. (if (/= (current-column) ind)
  6111. (progn
  6112. (just-one-space)
  6113. (indent-to ind))))))))))
  6114. (goto-char pos)))
  6115. (defun verilog-get-lineup-indent (b edpos)
  6116. "Return the indent level that will line up several lines within the region.
  6117. Region is defined by B and EDPOS."
  6118. (save-excursion
  6119. (let ((ind 0) e)
  6120. (goto-char b)
  6121. ;; Get rightmost position
  6122. (while (progn (setq e (marker-position edpos))
  6123. (< (point) e))
  6124. (if (verilog-re-search-forward
  6125. (or (and verilog-indent-declaration-macros
  6126. verilog-declaration-re-1-macro)
  6127. verilog-declaration-re-1-no-macro) e 'move)
  6128. (progn
  6129. (goto-char (match-end 0))
  6130. (verilog-backward-syntactic-ws)
  6131. (if (> (current-column) ind)
  6132. (setq ind (current-column)))
  6133. (goto-char (match-end 0)))))
  6134. (if (> ind 0)
  6135. (1+ ind)
  6136. ;; No lineup-string found
  6137. (goto-char b)
  6138. (end-of-line)
  6139. (verilog-backward-syntactic-ws)
  6140. ;;(skip-chars-backward " \t")
  6141. (1+ (current-column))))))
  6142. (defun verilog-get-lineup-indent-2 (myre b edpos)
  6143. "Return the indent level that will line up several lines within the region."
  6144. (save-excursion
  6145. (let ((ind 0) e)
  6146. (goto-char b)
  6147. ;; Get rightmost position
  6148. (while (progn (setq e (marker-position edpos))
  6149. (< (point) e))
  6150. (if (and (verilog-re-search-forward myre e 'move)
  6151. (not (verilog-in-attribute-p))) ;; skip attribute exprs
  6152. (progn
  6153. (goto-char (match-beginning 2))
  6154. (verilog-backward-syntactic-ws)
  6155. (if (> (current-column) ind)
  6156. (setq ind (current-column)))
  6157. (goto-char (match-end 0)))
  6158. ))
  6159. (if (> ind 0)
  6160. (1+ ind)
  6161. ;; No lineup-string found
  6162. (goto-char b)
  6163. (end-of-line)
  6164. (skip-chars-backward " \t")
  6165. (1+ (current-column))))))
  6166. (defun verilog-comment-depth (type val)
  6167. "A useful mode debugging aide. TYPE and VAL are comments for insertion."
  6168. (save-excursion
  6169. (let
  6170. ((b (prog2
  6171. (beginning-of-line)
  6172. (point-marker)
  6173. (end-of-line)))
  6174. (e (point-marker)))
  6175. (if (re-search-backward " /\\* \[#-\]# \[a-zA-Z\]+ \[0-9\]+ ## \\*/" b t)
  6176. (progn
  6177. (replace-match " /* -# ## */")
  6178. (end-of-line))
  6179. (progn
  6180. (end-of-line)
  6181. (insert " /* ## ## */"))))
  6182. (backward-char 6)
  6183. (insert
  6184. (format "%s %d" type val))))
  6185. ;;
  6186. ;;
  6187. ;; Completion
  6188. ;;
  6189. (defvar verilog-str nil)
  6190. (defvar verilog-all nil)
  6191. (defvar verilog-pred nil)
  6192. (defvar verilog-buffer-to-use nil)
  6193. (defvar verilog-flag nil)
  6194. (defvar verilog-toggle-completions nil
  6195. "*True means \\<verilog-mode-map>\\[verilog-complete-word] should try all possible completions one by one.
  6196. Repeated use of \\[verilog-complete-word] will show you all of them.
  6197. Normally, when there is more than one possible completion,
  6198. it displays a list of all possible completions.")
  6199. (defvar verilog-type-keywords
  6200. '(
  6201. "and" "buf" "bufif0" "bufif1" "cmos" "defparam" "inout" "input"
  6202. "integer" "localparam" "logic" "mailbox" "nand" "nmos" "nor" "not" "notif0"
  6203. "notif1" "or" "output" "parameter" "pmos" "pull0" "pull1" "pulldown" "pullup"
  6204. "rcmos" "real" "realtime" "reg" "rnmos" "rpmos" "rtran" "rtranif0"
  6205. "rtranif1" "semaphore" "time" "tran" "tranif0" "tranif1" "tri" "tri0" "tri1"
  6206. "triand" "trior" "trireg" "wand" "wire" "wor" "xnor" "xor"
  6207. )
  6208. "*Keywords for types used when completing a word in a declaration or parmlist.
  6209. \(integer, real, reg...)")
  6210. (defvar verilog-cpp-keywords
  6211. '("module" "macromodule" "primitive" "timescale" "define" "ifdef" "ifndef" "else"
  6212. "endif")
  6213. "*Keywords to complete when at first word of a line in declarative scope.
  6214. \(initial, always, begin, assign...)
  6215. The procedures and variables defined within the Verilog program
  6216. will be completed at runtime and should not be added to this list.")
  6217. (defvar verilog-defun-keywords
  6218. (append
  6219. '(
  6220. "always" "always_comb" "always_ff" "always_latch" "assign"
  6221. "begin" "end" "generate" "endgenerate" "module" "endmodule"
  6222. "specify" "endspecify" "function" "endfunction" "initial" "final"
  6223. "task" "endtask" "primitive" "endprimitive"
  6224. )
  6225. verilog-type-keywords)
  6226. "*Keywords to complete when at first word of a line in declarative scope.
  6227. \(initial, always, begin, assign...)
  6228. The procedures and variables defined within the Verilog program
  6229. will be completed at runtime and should not be added to this list.")
  6230. (defvar verilog-block-keywords
  6231. '(
  6232. "begin" "break" "case" "continue" "else" "end" "endfunction"
  6233. "endgenerate" "endinterface" "endpackage" "endspecify" "endtask"
  6234. "for" "fork" "if" "join" "join_any" "join_none" "repeat" "return"
  6235. "while")
  6236. "*Keywords to complete when at first word of a line in behavioral scope.
  6237. \(begin, if, then, else, for, fork...)
  6238. The procedures and variables defined within the Verilog program
  6239. will be completed at runtime and should not be added to this list.")
  6240. (defvar verilog-tf-keywords
  6241. '("begin" "break" "fork" "join" "join_any" "join_none" "case" "end" "endtask" "endfunction" "if" "else" "for" "while" "repeat")
  6242. "*Keywords to complete when at first word of a line in a task or function.
  6243. \(begin, if, then, else, for, fork.)
  6244. The procedures and variables defined within the Verilog program
  6245. will be completed at runtime and should not be added to this list.")
  6246. (defvar verilog-case-keywords
  6247. '("begin" "fork" "join" "join_any" "join_none" "case" "end" "endcase" "if" "else" "for" "repeat")
  6248. "*Keywords to complete when at first word of a line in case scope.
  6249. \(begin, if, then, else, for, fork...)
  6250. The procedures and variables defined within the Verilog program
  6251. will be completed at runtime and should not be added to this list.")
  6252. (defvar verilog-separator-keywords
  6253. '("else" "then" "begin")
  6254. "*Keywords to complete when NOT standing at the first word of a statement.
  6255. \(else, then, begin...)
  6256. Variables and function names defined within the Verilog program
  6257. will be completed at runtime and should not be added to this list.")
  6258. (defvar verilog-gate-ios
  6259. ;; All these have an implied {"input"...} at the end
  6260. '(("and" "output")
  6261. ("buf" "output")
  6262. ("bufif0" "output")
  6263. ("bufif1" "output")
  6264. ("cmos" "output")
  6265. ("nand" "output")
  6266. ("nmos" "output")
  6267. ("nor" "output")
  6268. ("not" "output")
  6269. ("notif0" "output")
  6270. ("notif1" "output")
  6271. ("or" "output")
  6272. ("pmos" "output")
  6273. ("pulldown" "output")
  6274. ("pullup" "output")
  6275. ("rcmos" "output")
  6276. ("rnmos" "output")
  6277. ("rpmos" "output")
  6278. ("rtran" "inout" "inout")
  6279. ("rtranif0" "inout" "inout")
  6280. ("rtranif1" "inout" "inout")
  6281. ("tran" "inout" "inout")
  6282. ("tranif0" "inout" "inout")
  6283. ("tranif1" "inout" "inout")
  6284. ("xnor" "output")
  6285. ("xor" "output"))
  6286. "*Map of direction for each positional argument to each gate primitive.")
  6287. (defvar verilog-gate-keywords (mapcar `car verilog-gate-ios)
  6288. "*Keywords for gate primitives.")
  6289. (defun verilog-string-diff (str1 str2)
  6290. "Return index of first letter where STR1 and STR2 differs."
  6291. (catch 'done
  6292. (let ((diff 0))
  6293. (while t
  6294. (if (or (> (1+ diff) (length str1))
  6295. (> (1+ diff) (length str2)))
  6296. (throw 'done diff))
  6297. (or (equal (aref str1 diff) (aref str2 diff))
  6298. (throw 'done diff))
  6299. (setq diff (1+ diff))))))
  6300. ;; Calculate all possible completions for functions if argument is `function',
  6301. ;; completions for procedures if argument is `procedure' or both functions and
  6302. ;; procedures otherwise.
  6303. (defun verilog-func-completion (type)
  6304. "Build regular expression for module/task/function names.
  6305. TYPE is 'module, 'tf for task or function, or t if unknown."
  6306. (if (string= verilog-str "")
  6307. (setq verilog-str "[a-zA-Z_]"))
  6308. (let ((verilog-str (concat (cond
  6309. ((eq type 'module) "\\<\\(module\\)\\s +")
  6310. ((eq type 'tf) "\\<\\(task\\|function\\)\\s +")
  6311. (t "\\<\\(task\\|function\\|module\\)\\s +"))
  6312. "\\<\\(" verilog-str "[a-zA-Z0-9_.]*\\)\\>"))
  6313. match)
  6314. (if (not (looking-at verilog-defun-re))
  6315. (verilog-re-search-backward verilog-defun-re nil t))
  6316. (forward-char 1)
  6317. ;; Search through all reachable functions
  6318. (goto-char (point-min))
  6319. (while (verilog-re-search-forward verilog-str (point-max) t)
  6320. (progn (setq match (buffer-substring (match-beginning 2)
  6321. (match-end 2)))
  6322. (if (or (null verilog-pred)
  6323. (funcall verilog-pred match))
  6324. (setq verilog-all (cons match verilog-all)))))
  6325. (if (match-beginning 0)
  6326. (goto-char (match-beginning 0)))))
  6327. (defun verilog-get-completion-decl (end)
  6328. "Macro for searching through current declaration (var, type or const)
  6329. for matches of `str' and adding the occurrence tp `all' through point END."
  6330. (let ((re (or (and verilog-indent-declaration-macros
  6331. verilog-declaration-re-2-macro)
  6332. verilog-declaration-re-2-no-macro))
  6333. decl-end match)
  6334. ;; Traverse lines
  6335. (while (and (< (point) end)
  6336. (verilog-re-search-forward re end t))
  6337. ;; Traverse current line
  6338. (setq decl-end (save-excursion (verilog-declaration-end)))
  6339. (while (and (verilog-re-search-forward verilog-symbol-re decl-end t)
  6340. (not (match-end 1)))
  6341. (setq match (buffer-substring (match-beginning 0) (match-end 0)))
  6342. (if (string-match (concat "\\<" verilog-str) match)
  6343. (if (or (null verilog-pred)
  6344. (funcall verilog-pred match))
  6345. (setq verilog-all (cons match verilog-all)))))
  6346. (forward-line 1)))
  6347. verilog-all)
  6348. (defun verilog-type-completion ()
  6349. "Calculate all possible completions for types."
  6350. (let ((start (point))
  6351. goon)
  6352. ;; Search for all reachable type declarations
  6353. (while (or (verilog-beg-of-defun)
  6354. (setq goon (not goon)))
  6355. (save-excursion
  6356. (if (and (< start (prog1 (save-excursion (verilog-end-of-defun)
  6357. (point))
  6358. (forward-char 1)))
  6359. (verilog-re-search-forward
  6360. "\\<type\\>\\|\\<\\(begin\\|function\\|procedure\\)\\>"
  6361. start t)
  6362. (not (match-end 1)))
  6363. ;; Check current type declaration
  6364. (verilog-get-completion-decl start))))))
  6365. (defun verilog-var-completion ()
  6366. "Calculate all possible completions for variables (or constants)."
  6367. (let ((start (point)))
  6368. ;; Search for all reachable var declarations
  6369. (verilog-beg-of-defun)
  6370. (save-excursion
  6371. ;; Check var declarations
  6372. (verilog-get-completion-decl start))))
  6373. (defun verilog-keyword-completion (keyword-list)
  6374. "Give list of all possible completions of keywords in KEYWORD-LIST."
  6375. (mapcar (lambda (s)
  6376. (if (string-match (concat "\\<" verilog-str) s)
  6377. (if (or (null verilog-pred)
  6378. (funcall verilog-pred s))
  6379. (setq verilog-all (cons s verilog-all)))))
  6380. keyword-list))
  6381. (defun verilog-completion (verilog-str verilog-pred verilog-flag)
  6382. "Function passed to `completing-read', `try-completion' or `all-completions'.
  6383. Called to get completion on VERILOG-STR. If VERILOG-PRED is non-nil, it
  6384. must be a function to be called for every match to check if this should
  6385. really be a match. If VERILOG-FLAG is t, the function returns a list of
  6386. all possible completions. If VERILOG-FLAG is nil it returns a string,
  6387. the longest possible completion, or t if VERILOG-STR is an exact match.
  6388. If VERILOG-FLAG is 'lambda, the function returns t if VERILOG-STR is an
  6389. exact match, nil otherwise."
  6390. (save-excursion
  6391. (let ((verilog-all nil))
  6392. ;; Set buffer to use for searching labels. This should be set
  6393. ;; within functions which use verilog-completions
  6394. (set-buffer verilog-buffer-to-use)
  6395. ;; Determine what should be completed
  6396. (let ((state (car (verilog-calculate-indent))))
  6397. (cond ((eq state 'defun)
  6398. (save-excursion (verilog-var-completion))
  6399. (verilog-func-completion 'module)
  6400. (verilog-keyword-completion verilog-defun-keywords))
  6401. ((eq state 'behavioral)
  6402. (save-excursion (verilog-var-completion))
  6403. (verilog-func-completion 'module)
  6404. (verilog-keyword-completion verilog-defun-keywords))
  6405. ((eq state 'block)
  6406. (save-excursion (verilog-var-completion))
  6407. (verilog-func-completion 'tf)
  6408. (verilog-keyword-completion verilog-block-keywords))
  6409. ((eq state 'case)
  6410. (save-excursion (verilog-var-completion))
  6411. (verilog-func-completion 'tf)
  6412. (verilog-keyword-completion verilog-case-keywords))
  6413. ((eq state 'tf)
  6414. (save-excursion (verilog-var-completion))
  6415. (verilog-func-completion 'tf)
  6416. (verilog-keyword-completion verilog-tf-keywords))
  6417. ((eq state 'cpp)
  6418. (save-excursion (verilog-var-completion))
  6419. (verilog-keyword-completion verilog-cpp-keywords))
  6420. ((eq state 'cparenexp)
  6421. (save-excursion (verilog-var-completion)))
  6422. (t;--Anywhere else
  6423. (save-excursion (verilog-var-completion))
  6424. (verilog-func-completion 'both)
  6425. (verilog-keyword-completion verilog-separator-keywords))))
  6426. ;; Now we have built a list of all matches. Give response to caller
  6427. (verilog-completion-response))))
  6428. (defun verilog-completion-response ()
  6429. (cond ((or (equal verilog-flag 'lambda) (null verilog-flag))
  6430. ;; This was not called by all-completions
  6431. (if (null verilog-all)
  6432. ;; Return nil if there was no matching label
  6433. nil
  6434. ;; Get longest string common in the labels
  6435. (let* ((elm (cdr verilog-all))
  6436. (match (car verilog-all))
  6437. (min (length match))
  6438. tmp)
  6439. (if (string= match verilog-str)
  6440. ;; Return t if first match was an exact match
  6441. (setq match t)
  6442. (while (not (null elm))
  6443. ;; Find longest common string
  6444. (if (< (setq tmp (verilog-string-diff match (car elm))) min)
  6445. (progn
  6446. (setq min tmp)
  6447. (setq match (substring match 0 min))))
  6448. ;; Terminate with match=t if this is an exact match
  6449. (if (string= (car elm) verilog-str)
  6450. (progn
  6451. (setq match t)
  6452. (setq elm nil))
  6453. (setq elm (cdr elm)))))
  6454. ;; If this is a test just for exact match, return nil ot t
  6455. (if (and (equal verilog-flag 'lambda) (not (equal match 't)))
  6456. nil
  6457. match))))
  6458. ;; If flag is t, this was called by all-completions. Return
  6459. ;; list of all possible completions
  6460. (verilog-flag
  6461. verilog-all)))
  6462. (defvar verilog-last-word-numb 0)
  6463. (defvar verilog-last-word-shown nil)
  6464. (defvar verilog-last-completions nil)
  6465. (defun verilog-complete-word ()
  6466. "Complete word at current point.
  6467. \(See also `verilog-toggle-completions', `verilog-type-keywords',
  6468. and `verilog-separator-keywords'.)"
  6469. (interactive)
  6470. (let* ((b (save-excursion (skip-chars-backward "a-zA-Z0-9_") (point)))
  6471. (e (save-excursion (skip-chars-forward "a-zA-Z0-9_") (point)))
  6472. (verilog-str (buffer-substring b e))
  6473. ;; The following variable is used in verilog-completion
  6474. (verilog-buffer-to-use (current-buffer))
  6475. (allcomp (if (and verilog-toggle-completions
  6476. (string= verilog-last-word-shown verilog-str))
  6477. verilog-last-completions
  6478. (all-completions verilog-str 'verilog-completion)))
  6479. (match (if verilog-toggle-completions
  6480. "" (try-completion
  6481. verilog-str (mapcar (lambda (elm)
  6482. (cons elm 0)) allcomp)))))
  6483. ;; Delete old string
  6484. (delete-region b e)
  6485. ;; Toggle-completions inserts whole labels
  6486. (if verilog-toggle-completions
  6487. (progn
  6488. ;; Update entry number in list
  6489. (setq verilog-last-completions allcomp
  6490. verilog-last-word-numb
  6491. (if (>= verilog-last-word-numb (1- (length allcomp)))
  6492. 0
  6493. (1+ verilog-last-word-numb)))
  6494. (setq verilog-last-word-shown (elt allcomp verilog-last-word-numb))
  6495. ;; Display next match or same string if no match was found
  6496. (if (not (null allcomp))
  6497. (insert "" verilog-last-word-shown)
  6498. (insert "" verilog-str)
  6499. (message "(No match)")))
  6500. ;; The other form of completion does not necessarily do that.
  6501. ;; Insert match if found, or the original string if no match
  6502. (if (or (null match) (equal match 't))
  6503. (progn (insert "" verilog-str)
  6504. (message "(No match)"))
  6505. (insert "" match))
  6506. ;; Give message about current status of completion
  6507. (cond ((equal match 't)
  6508. (if (not (null (cdr allcomp)))
  6509. (message "(Complete but not unique)")
  6510. (message "(Sole completion)")))
  6511. ;; Display buffer if the current completion didn't help
  6512. ;; on completing the label.
  6513. ((and (not (null (cdr allcomp))) (= (length verilog-str)
  6514. (length match)))
  6515. (with-output-to-temp-buffer "*Completions*"
  6516. (display-completion-list allcomp))
  6517. ;; Wait for a key press. Then delete *Completion* window
  6518. (momentary-string-display "" (point))
  6519. (delete-window (get-buffer-window (get-buffer "*Completions*")))
  6520. )))))
  6521. (defun verilog-show-completions ()
  6522. "Show all possible completions at current point."
  6523. (interactive)
  6524. (let* ((b (save-excursion (skip-chars-backward "a-zA-Z0-9_") (point)))
  6525. (e (save-excursion (skip-chars-forward "a-zA-Z0-9_") (point)))
  6526. (verilog-str (buffer-substring b e))
  6527. ;; The following variable is used in verilog-completion
  6528. (verilog-buffer-to-use (current-buffer))
  6529. (allcomp (if (and verilog-toggle-completions
  6530. (string= verilog-last-word-shown verilog-str))
  6531. verilog-last-completions
  6532. (all-completions verilog-str 'verilog-completion))))
  6533. ;; Show possible completions in a temporary buffer.
  6534. (with-output-to-temp-buffer "*Completions*"
  6535. (display-completion-list allcomp))
  6536. ;; Wait for a key press. Then delete *Completion* window
  6537. (momentary-string-display "" (point))
  6538. (delete-window (get-buffer-window (get-buffer "*Completions*")))))
  6539. (defun verilog-get-default-symbol ()
  6540. "Return symbol around current point as a string."
  6541. (save-excursion
  6542. (buffer-substring (progn
  6543. (skip-chars-backward " \t")
  6544. (skip-chars-backward "a-zA-Z0-9_")
  6545. (point))
  6546. (progn
  6547. (skip-chars-forward "a-zA-Z0-9_")
  6548. (point)))))
  6549. (defun verilog-build-defun-re (str &optional arg)
  6550. "Return function/task/module starting with STR as regular expression.
  6551. With optional second ARG non-nil, STR is the complete name of the instruction."
  6552. (if arg
  6553. (concat "^\\(function\\|task\\|module\\)[ \t]+\\(" str "\\)\\>")
  6554. (concat "^\\(function\\|task\\|module\\)[ \t]+\\(" str "[a-zA-Z0-9_]*\\)\\>")))
  6555. (defun verilog-comp-defun (verilog-str verilog-pred verilog-flag)
  6556. "Function passed to `completing-read', `try-completion' or `all-completions'.
  6557. Returns a completion on any function name based on VERILOG-STR prefix. If
  6558. VERILOG-PRED is non-nil, it must be a function to be called for every match
  6559. to check if this should really be a match. If VERILOG-FLAG is t, the
  6560. function returns a list of all possible completions. If it is nil it
  6561. returns a string, the longest possible completion, or t if VERILOG-STR is
  6562. an exact match. If VERILOG-FLAG is 'lambda, the function returns t if
  6563. VERILOG-STR is an exact match, nil otherwise."
  6564. (save-excursion
  6565. (let ((verilog-all nil)
  6566. match)
  6567. ;; Set buffer to use for searching labels. This should be set
  6568. ;; within functions which use verilog-completions
  6569. (set-buffer verilog-buffer-to-use)
  6570. (let ((verilog-str verilog-str))
  6571. ;; Build regular expression for functions
  6572. (if (string= verilog-str "")
  6573. (setq verilog-str (verilog-build-defun-re "[a-zA-Z_]"))
  6574. (setq verilog-str (verilog-build-defun-re verilog-str)))
  6575. (goto-char (point-min))
  6576. ;; Build a list of all possible completions
  6577. (while (verilog-re-search-forward verilog-str nil t)
  6578. (setq match (buffer-substring (match-beginning 2) (match-end 2)))
  6579. (if (or (null verilog-pred)
  6580. (funcall verilog-pred match))
  6581. (setq verilog-all (cons match verilog-all)))))
  6582. ;; Now we have built a list of all matches. Give response to caller
  6583. (verilog-completion-response))))
  6584. (defun verilog-goto-defun ()
  6585. "Move to specified Verilog module/interface/task/function.
  6586. The default is a name found in the buffer around point.
  6587. If search fails, other files are checked based on
  6588. `verilog-library-flags'."
  6589. (interactive)
  6590. (let* ((default (verilog-get-default-symbol))
  6591. ;; The following variable is used in verilog-comp-function
  6592. (verilog-buffer-to-use (current-buffer))
  6593. (label (if (not (string= default ""))
  6594. ;; Do completion with default
  6595. (completing-read (concat "Goto-Label: (default "
  6596. default ") ")
  6597. 'verilog-comp-defun nil nil "")
  6598. ;; There is no default value. Complete without it
  6599. (completing-read "Goto-Label: "
  6600. 'verilog-comp-defun nil nil "")))
  6601. pt)
  6602. ;; Make sure library paths are correct, in case need to resolve module
  6603. (verilog-auto-reeval-locals)
  6604. (verilog-getopt-flags)
  6605. ;; If there was no response on prompt, use default value
  6606. (if (string= label "")
  6607. (setq label default))
  6608. ;; Goto right place in buffer if label is not an empty string
  6609. (or (string= label "")
  6610. (progn
  6611. (save-excursion
  6612. (goto-char (point-min))
  6613. (setq pt
  6614. (re-search-forward (verilog-build-defun-re label t) nil t)))
  6615. (when pt
  6616. (goto-char pt)
  6617. (beginning-of-line))
  6618. pt)
  6619. (verilog-goto-defun-file label))))
  6620. ;; Eliminate compile warning
  6621. (defvar occur-pos-list)
  6622. (defun verilog-showscopes ()
  6623. "List all scopes in this module."
  6624. (interactive)
  6625. (let ((buffer (current-buffer))
  6626. (linenum 1)
  6627. (nlines 0)
  6628. (first 1)
  6629. (prevpos (point-min))
  6630. (final-context-start (make-marker))
  6631. (regexp "\\(module\\s-+\\w+\\s-*(\\)\\|\\(\\w+\\s-+\\w+\\s-*(\\)"))
  6632. (with-output-to-temp-buffer "*Occur*"
  6633. (save-excursion
  6634. (message (format "Searching for %s ..." regexp))
  6635. ;; Find next match, but give up if prev match was at end of buffer.
  6636. (while (and (not (= prevpos (point-max)))
  6637. (verilog-re-search-forward regexp nil t))
  6638. (goto-char (match-beginning 0))
  6639. (beginning-of-line)
  6640. (save-match-data
  6641. (setq linenum (+ linenum (count-lines prevpos (point)))))
  6642. (setq prevpos (point))
  6643. (goto-char (match-end 0))
  6644. (let* ((start (save-excursion
  6645. (goto-char (match-beginning 0))
  6646. (forward-line (if (< nlines 0) nlines (- nlines)))
  6647. (point)))
  6648. (end (save-excursion
  6649. (goto-char (match-end 0))
  6650. (if (> nlines 0)
  6651. (forward-line (1+ nlines))
  6652. (forward-line 1))
  6653. (point)))
  6654. (tag (format "%3d" linenum))
  6655. (empty (make-string (length tag) ?\ ))
  6656. tem)
  6657. (save-excursion
  6658. (setq tem (make-marker))
  6659. (set-marker tem (point))
  6660. (set-buffer standard-output)
  6661. (setq occur-pos-list (cons tem occur-pos-list))
  6662. (or first (zerop nlines)
  6663. (insert "--------\n"))
  6664. (setq first nil)
  6665. (insert-buffer-substring buffer start end)
  6666. (backward-char (- end start))
  6667. (setq tem (if (< nlines 0) (- nlines) nlines))
  6668. (while (> tem 0)
  6669. (insert empty ?:)
  6670. (forward-line 1)
  6671. (setq tem (1- tem)))
  6672. (let ((this-linenum linenum))
  6673. (set-marker final-context-start
  6674. (+ (point) (- (match-end 0) (match-beginning 0))))
  6675. (while (< (point) final-context-start)
  6676. (if (null tag)
  6677. (setq tag (format "%3d" this-linenum)))
  6678. (insert tag ?:)))))))
  6679. (set-buffer-modified-p nil))))
  6680. ;; Highlight helper functions
  6681. (defconst verilog-directive-regexp "\\(translate\\|coverage\\|lint\\)_")
  6682. (defun verilog-within-translate-off ()
  6683. "Return point if within translate-off region, else nil."
  6684. (and (save-excursion
  6685. (re-search-backward
  6686. (concat "//\\s-*.*\\s-*" verilog-directive-regexp "\\(on\\|off\\)\\>")
  6687. nil t))
  6688. (equal "off" (match-string 2))
  6689. (point)))
  6690. (defun verilog-start-translate-off (limit)
  6691. "Return point before translate-off directive if before LIMIT, else nil."
  6692. (when (re-search-forward
  6693. (concat "//\\s-*.*\\s-*" verilog-directive-regexp "off\\>")
  6694. limit t)
  6695. (match-beginning 0)))
  6696. (defun verilog-back-to-start-translate-off (limit)
  6697. "Return point before translate-off directive if before LIMIT, else nil."
  6698. (when (re-search-backward
  6699. (concat "//\\s-*.*\\s-*" verilog-directive-regexp "off\\>")
  6700. limit t)
  6701. (match-beginning 0)))
  6702. (defun verilog-end-translate-off (limit)
  6703. "Return point after translate-on directive if before LIMIT, else nil."
  6704. (re-search-forward (concat
  6705. "//\\s-*.*\\s-*" verilog-directive-regexp "on\\>") limit t))
  6706. (defun verilog-match-translate-off (limit)
  6707. "Match a translate-off block, setting `match-data' and returning t, else nil.
  6708. Bound search by LIMIT."
  6709. (when (< (point) limit)
  6710. (let ((start (or (verilog-within-translate-off)
  6711. (verilog-start-translate-off limit)))
  6712. (case-fold-search t))
  6713. (when start
  6714. (let ((end (or (verilog-end-translate-off limit) limit)))
  6715. (set-match-data (list start end))
  6716. (goto-char end))))))
  6717. (defun verilog-font-lock-match-item (limit)
  6718. "Match, and move over, any declaration item after point.
  6719. Bound search by LIMIT. Adapted from
  6720. `font-lock-match-c-style-declaration-item-and-skip-to-next'."
  6721. (condition-case nil
  6722. (save-restriction
  6723. (narrow-to-region (point-min) limit)
  6724. ;; match item
  6725. (when (looking-at "\\s-*\\([a-zA-Z]\\w*\\)")
  6726. (save-match-data
  6727. (goto-char (match-end 1))
  6728. ;; move to next item
  6729. (if (looking-at "\\(\\s-*,\\)")
  6730. (goto-char (match-end 1))
  6731. (end-of-line) t))))
  6732. (error nil)))
  6733. ;; Added by Subbu Meiyappan for Header
  6734. (defun verilog-header ()
  6735. "Insert a standard Verilog file header.
  6736. See also `verilog-sk-header' for an alternative format."
  6737. (interactive)
  6738. (let ((start (point)))
  6739. (insert "\
  6740. //-----------------------------------------------------------------------------
  6741. // Title : <title>
  6742. // Project : <project>
  6743. //-----------------------------------------------------------------------------
  6744. // File : <filename>
  6745. // Author : <author>
  6746. // Created : <credate>
  6747. // Last modified : <moddate>
  6748. //-----------------------------------------------------------------------------
  6749. // Description :
  6750. // <description>
  6751. //-----------------------------------------------------------------------------
  6752. // Copyright (c) <copydate> by <company> This model is the confidential and
  6753. // proprietary property of <company> and the possession or use of this
  6754. // file requires a written license from <company>.
  6755. //------------------------------------------------------------------------------
  6756. // Modification history :
  6757. // <modhist>
  6758. //-----------------------------------------------------------------------------
  6759. ")
  6760. (goto-char start)
  6761. (search-forward "<filename>")
  6762. (replace-match (buffer-name) t t)
  6763. (search-forward "<author>") (replace-match "" t t)
  6764. (insert (user-full-name))
  6765. (insert " <" (user-login-name) "@" (system-name) ">")
  6766. (search-forward "<credate>") (replace-match "" t t)
  6767. (verilog-insert-date)
  6768. (search-forward "<moddate>") (replace-match "" t t)
  6769. (verilog-insert-date)
  6770. (search-forward "<copydate>") (replace-match "" t t)
  6771. (verilog-insert-year)
  6772. (search-forward "<modhist>") (replace-match "" t t)
  6773. (verilog-insert-date)
  6774. (insert " : created")
  6775. (goto-char start)
  6776. (let (string)
  6777. (setq string (read-string "title: "))
  6778. (search-forward "<title>")
  6779. (replace-match string t t)
  6780. (setq string (read-string "project: " verilog-project))
  6781. (setq verilog-project string)
  6782. (search-forward "<project>")
  6783. (replace-match string t t)
  6784. (setq string (read-string "Company: " verilog-company))
  6785. (setq verilog-company string)
  6786. (search-forward "<company>")
  6787. (replace-match string t t)
  6788. (search-forward "<company>")
  6789. (replace-match string t t)
  6790. (search-forward "<company>")
  6791. (replace-match string t t)
  6792. (search-backward "<description>")
  6793. (replace-match "" t t))))
  6794. ;; verilog-header Uses the verilog-insert-date function
  6795. (defun verilog-insert-date ()
  6796. "Insert date from the system."
  6797. (interactive)
  6798. (if verilog-date-scientific-format
  6799. (insert (format-time-string "%Y/%m/%d"))
  6800. (insert (format-time-string "%d.%m.%Y"))))
  6801. (defun verilog-insert-year ()
  6802. "Insert year from the system."
  6803. (interactive)
  6804. (insert (format-time-string "%Y")))
  6805. ;;
  6806. ;; Signal list parsing
  6807. ;;
  6808. ;; Elements of a signal list
  6809. (defsubst verilog-sig-new (name bits comment mem enum signed type multidim modport)
  6810. (list name bits comment mem enum signed type multidim modport))
  6811. (defsubst verilog-sig-name (sig)
  6812. (car sig))
  6813. (defsubst verilog-sig-bits (sig)
  6814. (nth 1 sig))
  6815. (defsubst verilog-sig-comment (sig)
  6816. (nth 2 sig))
  6817. (defsubst verilog-sig-memory (sig)
  6818. (nth 3 sig))
  6819. (defsubst verilog-sig-enum (sig)
  6820. (nth 4 sig))
  6821. (defsubst verilog-sig-signed (sig)
  6822. (nth 5 sig))
  6823. (defsubst verilog-sig-type (sig)
  6824. (nth 6 sig))
  6825. (defsubst verilog-sig-multidim (sig)
  6826. (nth 7 sig))
  6827. (defsubst verilog-sig-multidim-string (sig)
  6828. (if (verilog-sig-multidim sig)
  6829. (let ((str "") (args (verilog-sig-multidim sig)))
  6830. (while args
  6831. (setq str (concat str (car args)))
  6832. (setq args (cdr args)))
  6833. str)))
  6834. (defsubst verilog-sig-modport (sig)
  6835. (nth 8 sig))
  6836. (defsubst verilog-sig-width (sig)
  6837. (verilog-make-width-expression (verilog-sig-bits sig)))
  6838. (defsubst verilog-alw-new (outputs-del outputs-imm temps inputs)
  6839. (list outputs-del outputs-imm temps inputs))
  6840. (defsubst verilog-alw-get-outputs-delayed (sigs)
  6841. (nth 0 sigs))
  6842. (defsubst verilog-alw-get-outputs-immediate (sigs)
  6843. (nth 1 sigs))
  6844. (defsubst verilog-alw-get-temps (sigs)
  6845. (nth 2 sigs))
  6846. (defsubst verilog-alw-get-inputs (sigs)
  6847. (nth 3 sigs))
  6848. (defsubst verilog-alw-get-uses-delayed (sigs)
  6849. (nth 0 sigs))
  6850. (defsubst verilog-modi-new (name fob pt type)
  6851. (vector name fob pt type))
  6852. (defsubst verilog-modi-name (modi)
  6853. (aref modi 0))
  6854. (defsubst verilog-modi-file-or-buffer (modi)
  6855. (aref modi 1))
  6856. (defsubst verilog-modi-get-point (modi)
  6857. (aref modi 2))
  6858. (defsubst verilog-modi-get-type (modi) ;; "module" or "interface"
  6859. (aref modi 3))
  6860. (defsubst verilog-modi-get-decls (modi)
  6861. (verilog-modi-cache-results modi 'verilog-read-decls))
  6862. (defsubst verilog-modi-get-sub-decls (modi)
  6863. (verilog-modi-cache-results modi 'verilog-read-sub-decls))
  6864. ;; Signal reading for given module
  6865. ;; Note these all take modi's - as returned from verilog-modi-current
  6866. (defsubst verilog-decls-new (out inout in vars unuseds assigns consts gparams interfaces)
  6867. (vector out inout in vars unuseds assigns consts gparams interfaces))
  6868. (defsubst verilog-decls-get-outputs (decls)
  6869. (aref decls 0))
  6870. (defsubst verilog-decls-get-inouts (decls)
  6871. (aref decls 1))
  6872. (defsubst verilog-decls-get-inputs (decls)
  6873. (aref decls 2))
  6874. (defsubst verilog-decls-get-vars (decls)
  6875. (aref decls 3))
  6876. ;;(defsubst verilog-decls-get-unused (decls)
  6877. ;; (aref decls 4))
  6878. (defsubst verilog-decls-get-assigns (decls)
  6879. (aref decls 5))
  6880. (defsubst verilog-decls-get-consts (decls)
  6881. (aref decls 6))
  6882. (defsubst verilog-decls-get-gparams (decls)
  6883. (aref decls 7))
  6884. (defsubst verilog-decls-get-interfaces (decls)
  6885. (aref decls 8))
  6886. (defsubst verilog-subdecls-new (out inout in intf intfd)
  6887. (vector out inout in intf intfd))
  6888. (defsubst verilog-subdecls-get-outputs (subdecls)
  6889. (aref subdecls 0))
  6890. (defsubst verilog-subdecls-get-inouts (subdecls)
  6891. (aref subdecls 1))
  6892. (defsubst verilog-subdecls-get-inputs (subdecls)
  6893. (aref subdecls 2))
  6894. (defsubst verilog-subdecls-get-interfaces (subdecls)
  6895. (aref subdecls 3))
  6896. (defsubst verilog-subdecls-get-interfaced (subdecls)
  6897. (aref subdecls 4))
  6898. (defun verilog-signals-not-in (in-list not-list)
  6899. "Return list of signals in IN-LIST that aren't also in NOT-LIST.
  6900. Also remove any duplicates in IN-LIST.
  6901. Signals must be in standard (base vector) form."
  6902. ;; This function is hot, so implemented as O(1)
  6903. (cond ((eval-when-compile (fboundp 'make-hash-table))
  6904. (let ((ht (make-hash-table :test 'equal :rehash-size 4.0))
  6905. out-list)
  6906. (while not-list
  6907. (puthash (car (car not-list)) t ht)
  6908. (setq not-list (cdr not-list)))
  6909. (while in-list
  6910. (when (not (gethash (car (car in-list)) ht))
  6911. (setq out-list (cons (car in-list) out-list))
  6912. (puthash (car (car in-list)) t ht))
  6913. (setq in-list (cdr in-list)))
  6914. (nreverse out-list)))
  6915. ;; Slower Fallback if no hash tables (pre Emacs 21.1/XEmacs 21.4)
  6916. (t
  6917. (let (out-list)
  6918. (while in-list
  6919. (if (not (or (assoc (car (car in-list)) not-list)
  6920. (assoc (car (car in-list)) out-list)))
  6921. (setq out-list (cons (car in-list) out-list)))
  6922. (setq in-list (cdr in-list)))
  6923. (nreverse out-list)))))
  6924. ;;(verilog-signals-not-in '(("A" "") ("B" "") ("DEL" "[2:3]")) '(("DEL" "") ("EXT" "")))
  6925. (defun verilog-signals-memory (in-list)
  6926. "Return list of signals in IN-LIST that are memorized (multidimensional)."
  6927. (let (out-list)
  6928. (while in-list
  6929. (if (nth 3 (car in-list))
  6930. (setq out-list (cons (car in-list) out-list)))
  6931. (setq in-list (cdr in-list)))
  6932. out-list))
  6933. ;;(verilog-signals-memory '(("A" nil nil "[3:0]")) '(("B" nil nil nil)))
  6934. (defun verilog-signals-sort-compare (a b)
  6935. "Compare signal A and B for sorting."
  6936. (string< (car a) (car b)))
  6937. (defun verilog-signals-not-params (in-list)
  6938. "Return list of signals in IN-LIST that aren't parameters or numeric constants."
  6939. (let (out-list)
  6940. (while in-list
  6941. (unless (boundp (intern (concat "vh-" (car (car in-list)))))
  6942. (setq out-list (cons (car in-list) out-list)))
  6943. (setq in-list (cdr in-list)))
  6944. (nreverse out-list)))
  6945. (defun verilog-signals-combine-bus (in-list)
  6946. "Return a list of signals in IN-LIST, with buses combined.
  6947. Duplicate signals are also removed. For example A[2] and A[1] become A[2:1]."
  6948. (let (combo buswarn
  6949. out-list
  6950. sig highbit lowbit ; Temp information about current signal
  6951. sv-name sv-highbit sv-lowbit ; Details about signal we are forming
  6952. sv-comment sv-memory sv-enum sv-signed sv-type sv-multidim sv-busstring
  6953. sv-modport
  6954. bus)
  6955. ;; Shove signals so duplicated signals will be adjacent
  6956. (setq in-list (sort in-list `verilog-signals-sort-compare))
  6957. (while in-list
  6958. (setq sig (car in-list))
  6959. ;; No current signal; form from existing details
  6960. (unless sv-name
  6961. (setq sv-name (verilog-sig-name sig)
  6962. sv-highbit nil
  6963. sv-busstring nil
  6964. sv-comment (verilog-sig-comment sig)
  6965. sv-memory (verilog-sig-memory sig)
  6966. sv-enum (verilog-sig-enum sig)
  6967. sv-signed (verilog-sig-signed sig)
  6968. sv-type (verilog-sig-type sig)
  6969. sv-multidim (verilog-sig-multidim sig)
  6970. sv-modport (verilog-sig-modport sig)
  6971. combo ""
  6972. buswarn ""))
  6973. ;; Extract bus details
  6974. (setq bus (verilog-sig-bits sig))
  6975. (setq bus (and bus (verilog-simplify-range-expression bus)))
  6976. (cond ((and bus
  6977. (or (and (string-match "\\[\\([0-9]+\\):\\([0-9]+\\)\\]" bus)
  6978. (setq highbit (string-to-number (match-string 1 bus))
  6979. lowbit (string-to-number
  6980. (match-string 2 bus))))
  6981. (and (string-match "\\[\\([0-9]+\\)\\]" bus)
  6982. (setq highbit (string-to-number (match-string 1 bus))
  6983. lowbit highbit))))
  6984. ;; Combine bits in bus
  6985. (if sv-highbit
  6986. (setq sv-highbit (max highbit sv-highbit)
  6987. sv-lowbit (min lowbit sv-lowbit))
  6988. (setq sv-highbit highbit
  6989. sv-lowbit lowbit)))
  6990. (bus
  6991. ;; String, probably something like `preproc:0
  6992. (setq sv-busstring bus)))
  6993. ;; Peek ahead to next signal
  6994. (setq in-list (cdr in-list))
  6995. (setq sig (car in-list))
  6996. (cond ((and sig (equal sv-name (verilog-sig-name sig)))
  6997. ;; Combine with this signal
  6998. (when (and sv-busstring
  6999. (not (equal sv-busstring (verilog-sig-bits sig))))
  7000. (when nil ;; Debugging
  7001. (message (concat "Warning, can't merge into single bus "
  7002. sv-name bus
  7003. ", the AUTOs may be wrong")))
  7004. (setq buswarn ", Couldn't Merge"))
  7005. (if (verilog-sig-comment sig) (setq combo ", ..."))
  7006. (setq sv-memory (or sv-memory (verilog-sig-memory sig))
  7007. sv-enum (or sv-enum (verilog-sig-enum sig))
  7008. sv-signed (or sv-signed (verilog-sig-signed sig))
  7009. sv-type (or sv-type (verilog-sig-type sig))
  7010. sv-multidim (or sv-multidim (verilog-sig-multidim sig))
  7011. sv-modport (or sv-modport (verilog-sig-modport sig))))
  7012. ;; Doesn't match next signal, add to queue, zero in prep for next
  7013. ;; Note sig may also be nil for the last signal in the list
  7014. (t
  7015. (setq out-list
  7016. (cons (verilog-sig-new
  7017. sv-name
  7018. (or sv-busstring
  7019. (if sv-highbit
  7020. (concat "[" (int-to-string sv-highbit) ":"
  7021. (int-to-string sv-lowbit) "]")))
  7022. (concat sv-comment combo buswarn)
  7023. sv-memory sv-enum sv-signed sv-type sv-multidim sv-modport)
  7024. out-list)
  7025. sv-name nil))))
  7026. ;;
  7027. out-list))
  7028. (defun verilog-sig-tieoff (sig &optional no-width)
  7029. "Return tieoff expression for given SIG, with appropriate width.
  7030. Ignore width if optional NO-WIDTH is set."
  7031. (let* ((width (if no-width nil (verilog-sig-width sig))))
  7032. (concat
  7033. (if (and verilog-active-low-regexp
  7034. (string-match verilog-active-low-regexp (verilog-sig-name sig)))
  7035. "~" "")
  7036. (cond ((not width)
  7037. "0")
  7038. ((string-match "^[0-9]+$" width)
  7039. (concat width (if (verilog-sig-signed sig) "'sh0" "'h0")))
  7040. (t
  7041. (concat "{" width "{1'b0}}"))))))
  7042. ;;
  7043. ;; Port/Wire/Etc Reading
  7044. ;;
  7045. (defun verilog-read-inst-backward-name ()
  7046. "Internal. Move point back to beginning of inst-name."
  7047. (verilog-backward-open-paren)
  7048. (let (done)
  7049. (while (not done)
  7050. (verilog-re-search-backward-quick "\\()\\|\\b[a-zA-Z0-9`_\$]\\|\\]\\)" nil nil) ; ] isn't word boundary
  7051. (cond ((looking-at ")")
  7052. (verilog-backward-open-paren))
  7053. (t (setq done t)))))
  7054. (while (looking-at "\\]")
  7055. (verilog-backward-open-bracket)
  7056. (verilog-re-search-backward-quick "\\(\\b[a-zA-Z0-9`_\$]\\|\\]\\)" nil nil))
  7057. (skip-chars-backward "a-zA-Z0-9`_$"))
  7058. (defun verilog-read-inst-module-matcher ()
  7059. "Set match data 0 with module_name when point is inside instantiation."
  7060. (verilog-read-inst-backward-name)
  7061. ;; Skip over instantiation name
  7062. (verilog-re-search-backward-quick "\\(\\b[a-zA-Z0-9`_\$]\\|)\\)" nil nil) ; ) isn't word boundary
  7063. ;; Check for parameterized instantiations
  7064. (when (looking-at ")")
  7065. (verilog-backward-open-paren)
  7066. (verilog-re-search-backward-quick "\\b[a-zA-Z0-9`_\$]" nil nil))
  7067. (skip-chars-backward "a-zA-Z0-9'_$")
  7068. (looking-at "[a-zA-Z0-9`_\$]+")
  7069. ;; Important: don't use match string, this must work with Emacs 19 font-lock on
  7070. (buffer-substring-no-properties (match-beginning 0) (match-end 0))
  7071. ;; Caller assumes match-beginning/match-end is still set
  7072. )
  7073. (defun verilog-read-inst-module ()
  7074. "Return module_name when point is inside instantiation."
  7075. (save-excursion
  7076. (verilog-read-inst-module-matcher)))
  7077. (defun verilog-read-inst-name ()
  7078. "Return instance_name when point is inside instantiation."
  7079. (save-excursion
  7080. (verilog-read-inst-backward-name)
  7081. (looking-at "[a-zA-Z0-9`_\$]+")
  7082. ;; Important: don't use match string, this must work with Emacs 19 font-lock on
  7083. (buffer-substring-no-properties (match-beginning 0) (match-end 0))))
  7084. (defun verilog-read-module-name ()
  7085. "Return module name when after its ( or ;."
  7086. (save-excursion
  7087. (re-search-backward "[(;]")
  7088. ;; Due to "module x import y (" we must search for declaration begin
  7089. (verilog-re-search-backward-quick verilog-defun-re nil nil)
  7090. (goto-char (match-end 0))
  7091. (verilog-re-search-forward-quick "\\b[a-zA-Z0-9`_\$]+" nil nil)
  7092. ;; Important: don't use match string, this must work with Emacs 19 font-lock on
  7093. (verilog-symbol-detick
  7094. (buffer-substring-no-properties (match-beginning 0) (match-end 0)) t)))
  7095. (defun verilog-read-inst-param-value ()
  7096. "Return list of parameters and values when point is inside instantiation."
  7097. (save-excursion
  7098. (verilog-read-inst-backward-name)
  7099. ;; Skip over instantiation name
  7100. (verilog-re-search-backward-quick "\\(\\b[a-zA-Z0-9`_\$]\\|)\\)" nil nil) ; ) isn't word boundary
  7101. ;; If there are parameterized instantiations
  7102. (when (looking-at ")")
  7103. (let ((end-pt (point))
  7104. params
  7105. param-name paren-beg-pt param-value)
  7106. (verilog-backward-open-paren)
  7107. (while (verilog-re-search-forward-quick "\\." end-pt t)
  7108. (verilog-re-search-forward-quick "\\([a-zA-Z0-9`_\$]\\)" nil nil)
  7109. (skip-chars-backward "a-zA-Z0-9'_$")
  7110. (looking-at "[a-zA-Z0-9`_\$]+")
  7111. (setq param-name (buffer-substring-no-properties
  7112. (match-beginning 0) (match-end 0)))
  7113. (verilog-re-search-forward-quick "(" nil nil)
  7114. (setq paren-beg-pt (point))
  7115. (verilog-forward-close-paren)
  7116. (setq param-value (verilog-string-remove-spaces
  7117. (buffer-substring-no-properties
  7118. paren-beg-pt (1- (point)))))
  7119. (setq params (cons (list param-name param-value) params)))
  7120. params))))
  7121. (defun verilog-read-auto-params (num-param &optional max-param)
  7122. "Return parameter list inside auto.
  7123. Optional NUM-PARAM and MAX-PARAM check for a specific number of parameters."
  7124. (let ((olist))
  7125. (save-excursion
  7126. ;; /*AUTOPUNT("parameter", "parameter")*/
  7127. (search-backward "(")
  7128. (while (looking-at "(?\\s *\"\\([^\"]*\\)\"\\s *,?")
  7129. (setq olist (cons (match-string 1) olist))
  7130. (goto-char (match-end 0))))
  7131. (or (eq nil num-param)
  7132. (<= num-param (length olist))
  7133. (error "%s: Expected %d parameters" (verilog-point-text) num-param))
  7134. (if (eq max-param nil) (setq max-param num-param))
  7135. (or (eq nil max-param)
  7136. (>= max-param (length olist))
  7137. (error "%s: Expected <= %d parameters" (verilog-point-text) max-param))
  7138. (nreverse olist)))
  7139. (defun verilog-read-decls ()
  7140. "Compute signal declaration information for the current module at point.
  7141. Return a array of [outputs inouts inputs wire reg assign const]."
  7142. (let ((end-mod-point (or (verilog-get-end-of-defun t) (point-max)))
  7143. (functask 0) (paren 0) (sig-paren 0) (v2kargs-ok t)
  7144. in-modport ign-prop
  7145. sigs-in sigs-out sigs-inout sigs-var sigs-assign sigs-const
  7146. sigs-gparam sigs-intf
  7147. vec expect-signal keywd newsig rvalue enum io signed typedefed multidim
  7148. modport)
  7149. (save-excursion
  7150. (verilog-beg-of-defun-quick)
  7151. (setq sigs-const (verilog-read-auto-constants (point) end-mod-point))
  7152. (while (< (point) end-mod-point)
  7153. ;;(if dbg (setq dbg (concat dbg (format "Pt %s Vec %s C%c Kwd'%s'\n" (point) vec (following-char) keywd))))
  7154. (cond
  7155. ((looking-at "//")
  7156. (if (looking-at "[^\n]*synopsys\\s +enum\\s +\\([a-zA-Z0-9_]+\\)")
  7157. (setq enum (match-string 1)))
  7158. (search-forward "\n"))
  7159. ((looking-at "/\\*")
  7160. (forward-char 2)
  7161. (if (looking-at "[^\n]*synopsys\\s +enum\\s +\\([a-zA-Z0-9_]+\\)")
  7162. (setq enum (match-string 1)))
  7163. (or (search-forward "*/")
  7164. (error "%s: Unmatched /* */, at char %d" (verilog-point-text) (point))))
  7165. ((looking-at "(\\*")
  7166. ;; To advance past either "(*)" or "(* ... *)" don't forward past first *
  7167. (forward-char 1)
  7168. (or (search-forward "*)")
  7169. (error "%s: Unmatched (* *), at char %d" (verilog-point-text) (point))))
  7170. ((eq ?\" (following-char))
  7171. (or (re-search-forward "[^\\]\"" nil t) ;; don't forward-char first, since we look for a non backslash first
  7172. (error "%s: Unmatched quotes, at char %d" (verilog-point-text) (point))))
  7173. ((eq ?\; (following-char))
  7174. (setq vec nil io nil expect-signal nil newsig nil paren 0 rvalue nil
  7175. v2kargs-ok nil in-modport nil ign-prop nil)
  7176. (forward-char 1))
  7177. ((eq ?= (following-char))
  7178. (setq rvalue t newsig nil)
  7179. (forward-char 1))
  7180. ((and (eq ?, (following-char))
  7181. (eq paren sig-paren))
  7182. (setq rvalue nil)
  7183. (forward-char 1))
  7184. ;; ,'s can occur inside {} & funcs
  7185. ((looking-at "[{(]")
  7186. (setq paren (1+ paren))
  7187. (forward-char 1))
  7188. ((looking-at "[})]")
  7189. (setq paren (1- paren))
  7190. (forward-char 1)
  7191. (when (< paren sig-paren)
  7192. (setq expect-signal nil))) ; ) that ends variables inside v2k arg list
  7193. ((looking-at "\\s-*\\(\\[[^]]+\\]\\)")
  7194. (goto-char (match-end 0))
  7195. (cond (newsig ; Memory, not just width. Patch last signal added's memory (nth 3)
  7196. (setcar (cdr (cdr (cdr newsig)))
  7197. (if (verilog-sig-memory newsig)
  7198. (concat (verilog-sig-memory newsig) (match-string 1))
  7199. (match-string 1))))
  7200. (vec ;; Multidimensional
  7201. (setq multidim (cons vec multidim))
  7202. (setq vec (verilog-string-replace-matches
  7203. "\\s-+" "" nil nil (match-string 1))))
  7204. (t ;; Bit width
  7205. (setq vec (verilog-string-replace-matches
  7206. "\\s-+" "" nil nil (match-string 1))))))
  7207. ;; Normal or escaped identifier -- note we remember the \ if escaped
  7208. ((looking-at "\\s-*\\([a-zA-Z0-9`_$]+\\|\\\\[^ \t\n\f]+\\)")
  7209. (goto-char (match-end 0))
  7210. (setq keywd (match-string 1))
  7211. (when (string-match "^\\\\" (match-string 1))
  7212. (setq keywd (concat keywd " "))) ;; Escaped ID needs space at end
  7213. ;; Add any :: package names to same identifier
  7214. (while (looking-at "\\s-*::\\s-*\\([a-zA-Z0-9`_$]+\\|\\\\[^ \t\n\f]+\\)")
  7215. (goto-char (match-end 0))
  7216. (setq keywd (concat keywd "::" (match-string 1)))
  7217. (when (string-match "^\\\\" (match-string 1))
  7218. (setq keywd (concat keywd " ")))) ;; Escaped ID needs space at end
  7219. (cond ((equal keywd "input")
  7220. (setq vec nil enum nil rvalue nil newsig nil signed nil typedefed nil multidim nil sig-paren paren
  7221. expect-signal 'sigs-in io t modport nil))
  7222. ((equal keywd "output")
  7223. (setq vec nil enum nil rvalue nil newsig nil signed nil typedefed nil multidim nil sig-paren paren
  7224. expect-signal 'sigs-out io t modport nil))
  7225. ((equal keywd "inout")
  7226. (setq vec nil enum nil rvalue nil newsig nil signed nil typedefed nil multidim nil sig-paren paren
  7227. expect-signal 'sigs-inout io t modport nil))
  7228. ((equal keywd "parameter")
  7229. (setq vec nil enum nil rvalue nil signed nil typedefed nil multidim nil sig-paren paren
  7230. expect-signal 'sigs-gparam io t modport nil))
  7231. ((member keywd '("wire"
  7232. "tri" "tri0" "tri1" "triand" "trior" "wand" "wor"
  7233. "reg" "trireg"
  7234. "byte" "shortint" "int" "longint" "integer" "time"
  7235. "bit" "logic"
  7236. "shortreal" "real" "realtime"
  7237. "string" "event" "chandle"))
  7238. (unless io (setq vec nil enum nil rvalue nil signed nil typedefed nil multidim nil sig-paren paren
  7239. expect-signal 'sigs-var modport nil)))
  7240. ((equal keywd "assign")
  7241. (setq vec nil enum nil rvalue nil signed nil typedefed nil multidim nil sig-paren paren
  7242. expect-signal 'sigs-assign modport nil))
  7243. ((member keywd '("supply0" "supply1" "supply"
  7244. "localparam" "genvar"))
  7245. (unless io (setq vec nil enum nil rvalue nil signed nil typedefed nil multidim nil sig-paren paren
  7246. expect-signal 'sigs-const modport nil)))
  7247. ((member keywd '("signed" "unsigned"))
  7248. (setq signed keywd))
  7249. ((member keywd '("assert" "assume" "cover" "expect" "restrict"))
  7250. (setq ign-prop t))
  7251. ((member keywd '("class" "clocking" "covergroup" "function"
  7252. "property" "randsequence" "sequence" "task"))
  7253. (unless ign-prop
  7254. (setq functask (1+ functask))))
  7255. ((member keywd '("endclass" "endclocking" "endgroup" "endfunction"
  7256. "endproperty" "endsequence" "endtask"))
  7257. (setq functask (1- functask)))
  7258. ((equal keywd "modport")
  7259. (setq in-modport t))
  7260. ;; Ifdef? Ignore name of define
  7261. ((member keywd '("`ifdef" "`ifndef" "`elsif"))
  7262. (setq rvalue t))
  7263. ;; Type?
  7264. ((verilog-typedef-name-p keywd)
  7265. (setq typedefed keywd))
  7266. ;; Interface with optional modport in v2k arglist?
  7267. ;; Skip over parsing modport, and take the interface name as the type
  7268. ((and v2kargs-ok
  7269. (eq paren 1)
  7270. (not rvalue)
  7271. (looking-at "\\s-*\\(\\.\\(\\s-*[a-zA-Z`_$][a-zA-Z0-9`_$]*\\)\\|\\)\\s-*[a-zA-Z`_$][a-zA-Z0-9`_$]*"))
  7272. (when (match-end 2) (goto-char (match-end 2)))
  7273. (setq vec nil enum nil rvalue nil newsig nil signed nil typedefed keywd multidim nil sig-paren paren
  7274. expect-signal 'sigs-intf io t modport (match-string 2)))
  7275. ;; Ignore dotted LHS assignments: "assign foo.bar = z;"
  7276. ((looking-at "\\s-*\\.")
  7277. (goto-char (match-end 0))
  7278. (when (not rvalue)
  7279. (setq expect-signal nil)))
  7280. ;; New signal, maybe?
  7281. ((and expect-signal
  7282. (not rvalue)
  7283. (eq functask 0)
  7284. (not in-modport)
  7285. (not (member keywd verilog-keywords)))
  7286. ;; Add new signal to expect-signal's variable
  7287. (setq newsig (verilog-sig-new keywd vec nil nil enum signed typedefed multidim modport))
  7288. (set expect-signal (cons newsig
  7289. (symbol-value expect-signal))))))
  7290. (t
  7291. (forward-char 1)))
  7292. (skip-syntax-forward " "))
  7293. ;; Return arguments
  7294. (verilog-decls-new (nreverse sigs-out)
  7295. (nreverse sigs-inout)
  7296. (nreverse sigs-in)
  7297. (nreverse sigs-var)
  7298. nil
  7299. (nreverse sigs-assign)
  7300. (nreverse sigs-const)
  7301. (nreverse sigs-gparam)
  7302. (nreverse sigs-intf)))))
  7303. (defvar verilog-read-sub-decls-in-interfaced nil
  7304. "For `verilog-read-sub-decls', process next signal as under interfaced block.")
  7305. (defvar verilog-read-sub-decls-gate-ios nil
  7306. "For `verilog-read-sub-decls', gate IO pins remaining, nil if non-primitive.")
  7307. (eval-when-compile
  7308. ;; Prevent compile warnings; these are let's, not globals
  7309. ;; Do not remove the eval-when-compile
  7310. ;; - we want a error when we are debugging this code if they are refed.
  7311. (defvar sigs-in)
  7312. (defvar sigs-inout)
  7313. (defvar sigs-out)
  7314. (defvar sigs-intf)
  7315. (defvar sigs-intfd))
  7316. (defun verilog-read-sub-decls-sig (submoddecls comment port sig vec multidim)
  7317. "For `verilog-read-sub-decls-line', add a signal."
  7318. ;; sig eq t to indicate .name syntax
  7319. ;;(message "vrsds: %s(%S)" port sig)
  7320. (let ((dotname (eq sig t))
  7321. portdata)
  7322. (when sig
  7323. (setq port (verilog-symbol-detick-denumber port))
  7324. (setq sig (if dotname port (verilog-symbol-detick-denumber sig)))
  7325. (if vec (setq vec (verilog-symbol-detick-denumber vec)))
  7326. (if multidim (setq multidim (mapcar `verilog-symbol-detick-denumber multidim)))
  7327. (unless (or (not sig)
  7328. (equal sig "")) ;; Ignore .foo(1'b1) assignments
  7329. (cond ((or (setq portdata (assoc port (verilog-decls-get-inouts submoddecls)))
  7330. (equal "inout" verilog-read-sub-decls-gate-ios))
  7331. (setq sigs-inout
  7332. (cons (verilog-sig-new
  7333. sig
  7334. (if dotname (verilog-sig-bits portdata) vec)
  7335. (concat "To/From " comment)
  7336. (verilog-sig-memory portdata)
  7337. nil
  7338. (verilog-sig-signed portdata)
  7339. (verilog-sig-type portdata)
  7340. multidim nil)
  7341. sigs-inout)))
  7342. ((or (setq portdata (assoc port (verilog-decls-get-outputs submoddecls)))
  7343. (equal "output" verilog-read-sub-decls-gate-ios))
  7344. (setq sigs-out
  7345. (cons (verilog-sig-new
  7346. sig
  7347. (if dotname (verilog-sig-bits portdata) vec)
  7348. (concat "From " comment)
  7349. (verilog-sig-memory portdata)
  7350. nil
  7351. (verilog-sig-signed portdata)
  7352. (verilog-sig-type portdata)
  7353. multidim nil)
  7354. sigs-out)))
  7355. ((or (setq portdata (assoc port (verilog-decls-get-inputs submoddecls)))
  7356. (equal "input" verilog-read-sub-decls-gate-ios))
  7357. (setq sigs-in
  7358. (cons (verilog-sig-new
  7359. sig
  7360. (if dotname (verilog-sig-bits portdata) vec)
  7361. (concat "To " comment)
  7362. (verilog-sig-memory portdata)
  7363. nil
  7364. (verilog-sig-signed portdata)
  7365. (verilog-sig-type portdata)
  7366. multidim nil)
  7367. sigs-in)))
  7368. ((setq portdata (assoc port (verilog-decls-get-interfaces submoddecls)))
  7369. (setq sigs-intf
  7370. (cons (verilog-sig-new
  7371. sig
  7372. (if dotname (verilog-sig-bits portdata) vec)
  7373. (concat "To/From " comment)
  7374. (verilog-sig-memory portdata)
  7375. nil
  7376. (verilog-sig-signed portdata)
  7377. (verilog-sig-type portdata)
  7378. multidim nil)
  7379. sigs-intf)))
  7380. ((setq portdata (and verilog-read-sub-decls-in-interfaced
  7381. (assoc port (verilog-decls-get-vars submoddecls))))
  7382. (setq sigs-intfd
  7383. (cons (verilog-sig-new
  7384. sig
  7385. (if dotname (verilog-sig-bits portdata) vec)
  7386. (concat "To/From " comment)
  7387. (verilog-sig-memory portdata)
  7388. nil
  7389. (verilog-sig-signed portdata)
  7390. (verilog-sig-type portdata)
  7391. multidim nil)
  7392. sigs-intf)))
  7393. ;; (t -- warning pin isn't defined.) ; Leave for lint tool
  7394. )))))
  7395. (defun verilog-read-sub-decls-expr (submoddecls comment port expr)
  7396. "For `verilog-read-sub-decls-line', parse a subexpression and add signals."
  7397. ;;(message "vrsde: '%s'" expr)
  7398. ;; Replace special /*[....]*/ comments inserted by verilog-auto-inst-port
  7399. (setq expr (verilog-string-replace-matches "/\\*\\(\\[[^*]+\\]\\)\\*/" "\\1" nil nil expr))
  7400. ;; Remove front operators
  7401. (setq expr (verilog-string-replace-matches "^\\s-*[---+~!|&]+\\s-*" "" nil nil expr))
  7402. ;;
  7403. (cond
  7404. ;; {..., a, b} requires us to recurse on a,b
  7405. ;; To support {#{},{#{a,b}} we'll just split everything on [{},]
  7406. ((string-match "^\\s-*{\\(.*\\)}\\s-*$" expr)
  7407. (unless verilog-auto-ignore-concat
  7408. (let ((mlst (split-string (match-string 1 expr) "[{},]"))
  7409. mstr)
  7410. (while (setq mstr (pop mlst))
  7411. (verilog-read-sub-decls-expr submoddecls comment port mstr)))))
  7412. (t
  7413. (let (sig vec multidim)
  7414. ;; Remove leading reduction operators, etc
  7415. (setq expr (verilog-string-replace-matches "^\\s-*[---+~!|&]+\\s-*" "" nil nil expr))
  7416. ;;(message "vrsde-ptop: '%s'" expr)
  7417. (cond ;; Find \signal. Final space is part of escaped signal name
  7418. ((string-match "^\\s-*\\(\\\\[^ \t\n\f]+\\s-\\)" expr)
  7419. ;;(message "vrsde-s: '%s'" (match-string 1 expr))
  7420. (setq sig (match-string 1 expr)
  7421. expr (substring expr (match-end 0))))
  7422. ;; Find signal
  7423. ((string-match "^\\s-*\\([a-zA-Z_][a-zA-Z_0-9]*\\)" expr)
  7424. ;;(message "vrsde-s: '%s'" (match-string 1 expr))
  7425. (setq sig (verilog-string-remove-spaces (match-string 1 expr))
  7426. expr (substring expr (match-end 0)))))
  7427. ;; Find [vector] or [multi][multi][multi][vector]
  7428. (while (string-match "^\\s-*\\(\\[[^]]+\\]\\)" expr)
  7429. ;;(message "vrsde-v: '%s'" (match-string 1 expr))
  7430. (when vec (setq multidim (cons vec multidim)))
  7431. (setq vec (match-string 1 expr)
  7432. expr (substring expr (match-end 0))))
  7433. ;; If found signal, and nothing unrecognized, add the signal
  7434. ;;(message "vrsde-rem: '%s'" expr)
  7435. (when (and sig (string-match "^\\s-*$" expr))
  7436. (verilog-read-sub-decls-sig submoddecls comment port sig vec multidim))))))
  7437. (defun verilog-read-sub-decls-line (submoddecls comment)
  7438. "For `verilog-read-sub-decls', read lines of port defs until none match.
  7439. Inserts the list of signals found, using submodi to look up each port."
  7440. (let (done port)
  7441. (save-excursion
  7442. (forward-line 1)
  7443. (while (not done)
  7444. ;; Get port name
  7445. (cond ((looking-at "\\s-*\\.\\s-*\\([a-zA-Z0-9`_$]*\\)\\s-*(\\s-*")
  7446. (setq port (match-string 1))
  7447. (goto-char (match-end 0)))
  7448. ;; .\escaped (
  7449. ((looking-at "\\s-*\\.\\s-*\\(\\\\[^ \t\n\f]*\\)\\s-*(\\s-*")
  7450. (setq port (concat (match-string 1) " ")) ;; escaped id's need trailing space
  7451. (goto-char (match-end 0)))
  7452. ;; .name
  7453. ((looking-at "\\s-*\\.\\s-*\\([a-zA-Z0-9`_$]*\\)\\s-*[,)/]")
  7454. (verilog-read-sub-decls-sig
  7455. submoddecls comment (match-string 1) t ; sig==t for .name
  7456. nil nil) ; vec multidim
  7457. (setq port nil))
  7458. ;; .\escaped_name
  7459. ((looking-at "\\s-*\\.\\s-*\\(\\\\[^ \t\n\f]*\\)\\s-*[,)/]")
  7460. (verilog-read-sub-decls-sig
  7461. submoddecls comment (concat (match-string 1) " ") t ; sig==t for .name
  7462. nil nil) ; vec multidim
  7463. (setq port nil))
  7464. ;; random
  7465. ((looking-at "\\s-*\\.[^(]*(")
  7466. (setq port nil) ;; skip this line
  7467. (goto-char (match-end 0)))
  7468. (t
  7469. (setq port nil done t))) ;; Unknown, ignore rest of line
  7470. ;; Get signal name. Point is at the first-non-space after (
  7471. ;; We intentionally ignore (non-escaped) signals with .s in them
  7472. ;; this prevents AUTOWIRE etc from noticing hierarchical sigs.
  7473. (when port
  7474. (cond ((looking-at "\\([a-zA-Z_][a-zA-Z_0-9]*\\)\\s-*)")
  7475. (verilog-read-sub-decls-sig
  7476. submoddecls comment port
  7477. (verilog-string-remove-spaces (match-string 1)) ; sig
  7478. nil nil)) ; vec multidim
  7479. ;;
  7480. ((looking-at "\\([a-zA-Z_][a-zA-Z_0-9]*\\)\\s-*\\(\\[[^]]+\\]\\)\\s-*)")
  7481. (verilog-read-sub-decls-sig
  7482. submoddecls comment port
  7483. (verilog-string-remove-spaces (match-string 1)) ; sig
  7484. (match-string 2) nil)) ; vec multidim
  7485. ;; Fastpath was above looking-at's.
  7486. ;; For something more complicated invoke a parser
  7487. ((looking-at "[^)]+")
  7488. (verilog-read-sub-decls-expr
  7489. submoddecls comment port
  7490. (buffer-substring
  7491. (point) (1- (progn (search-backward "(") ; start at (
  7492. (verilog-forward-sexp-ign-cmt 1)
  7493. (point)))))))) ; expr
  7494. ;;
  7495. (forward-line 1)))))
  7496. (defun verilog-read-sub-decls-gate (submoddecls comment submod end-inst-point)
  7497. "For `verilog-read-sub-decls', read lines of UDP gate decl until none match.
  7498. Inserts the list of signals found."
  7499. (save-excursion
  7500. (let ((iolist (cdr (assoc submod verilog-gate-ios))))
  7501. (while (< (point) end-inst-point)
  7502. ;; Get primitive's signal name, as will never have port, and no trailing )
  7503. (cond ((looking-at "//")
  7504. (search-forward "\n"))
  7505. ((looking-at "/\\*")
  7506. (or (search-forward "*/")
  7507. (error "%s: Unmatched /* */, at char %d" (verilog-point-text) (point))))
  7508. ((looking-at "(\\*")
  7509. ;; To advance past either "(*)" or "(* ... *)" don't forward past first *
  7510. (forward-char 1)
  7511. (or (search-forward "*)")
  7512. (error "%s: Unmatched (* *), at char %d" (verilog-point-text) (point))))
  7513. ;; On pins, parse and advance to next pin
  7514. ;; Looking at pin, but *not* an // Output comment, or ) to end the inst
  7515. ((looking-at "\\s-*[a-zA-Z0-9`_$({}\\\\][^,]*")
  7516. (goto-char (match-end 0))
  7517. (setq verilog-read-sub-decls-gate-ios (or (car iolist) "input")
  7518. iolist (cdr iolist))
  7519. (verilog-read-sub-decls-expr
  7520. submoddecls comment "primitive_port"
  7521. (match-string 0)))
  7522. (t
  7523. (forward-char 1)
  7524. (skip-syntax-forward " ")))))))
  7525. (defun verilog-read-sub-decls ()
  7526. "Internally parse signals going to modules under this module.
  7527. Return a array of [ outputs inouts inputs ] signals for modules that are
  7528. instantiated in this module. For example if declare A A (.B(SIG)) and SIG
  7529. is a output, then SIG will be included in the list.
  7530. This only works on instantiations created with /*AUTOINST*/ converted by
  7531. \\[verilog-auto-inst]. Otherwise, it would have to read in the whole
  7532. component library to determine connectivity of the design.
  7533. One work around for this problem is to manually create // Inputs and //
  7534. Outputs comments above subcell signals, for example:
  7535. module ModuleName (
  7536. // Outputs
  7537. .out (out),
  7538. // Inputs
  7539. .in (in));"
  7540. (save-excursion
  7541. (let ((end-mod-point (verilog-get-end-of-defun t))
  7542. st-point end-inst-point
  7543. ;; below 3 modified by verilog-read-sub-decls-line
  7544. sigs-out sigs-inout sigs-in sigs-intf sigs-intfd)
  7545. (verilog-beg-of-defun-quick)
  7546. (while (verilog-re-search-forward-quick "\\(/\\*AUTOINST\\*/\\|\\.\\*\\)" end-mod-point t)
  7547. (save-excursion
  7548. (goto-char (match-beginning 0))
  7549. (unless (verilog-inside-comment-or-string-p)
  7550. ;; Attempt to snarf a comment
  7551. (let* ((submod (verilog-read-inst-module))
  7552. (inst (verilog-read-inst-name))
  7553. (subprim (member submod verilog-gate-keywords))
  7554. (comment (concat inst " of " submod ".v"))
  7555. submodi submoddecls)
  7556. (cond
  7557. (subprim
  7558. (setq submodi `primitive
  7559. submoddecls (verilog-decls-new nil nil nil nil nil nil nil nil nil)
  7560. comment (concat inst " of " submod))
  7561. (verilog-backward-open-paren)
  7562. (setq end-inst-point (save-excursion (verilog-forward-sexp-ign-cmt 1)
  7563. (point))
  7564. st-point (point))
  7565. (forward-char 1)
  7566. (verilog-read-sub-decls-gate submoddecls comment submod end-inst-point))
  7567. ;; Non-primitive
  7568. (t
  7569. (when (setq submodi (verilog-modi-lookup submod t))
  7570. (setq submoddecls (verilog-modi-get-decls submodi)
  7571. verilog-read-sub-decls-gate-ios nil)
  7572. (verilog-backward-open-paren)
  7573. (setq end-inst-point (save-excursion (verilog-forward-sexp-ign-cmt 1)
  7574. (point))
  7575. st-point (point))
  7576. ;; This could have used a list created by verilog-auto-inst
  7577. ;; However I want it to be runnable even on user's manually added signals
  7578. (let ((verilog-read-sub-decls-in-interfaced t))
  7579. (while (re-search-forward "\\s *(?\\s *// Interfaced" end-inst-point t)
  7580. (verilog-read-sub-decls-line submoddecls comment))) ;; Modifies sigs-ifd
  7581. (goto-char st-point)
  7582. (while (re-search-forward "\\s *(?\\s *// Interfaces" end-inst-point t)
  7583. (verilog-read-sub-decls-line submoddecls comment)) ;; Modifies sigs-out
  7584. (goto-char st-point)
  7585. (while (re-search-forward "\\s *(?\\s *// Outputs" end-inst-point t)
  7586. (verilog-read-sub-decls-line submoddecls comment)) ;; Modifies sigs-out
  7587. (goto-char st-point)
  7588. (while (re-search-forward "\\s *(?\\s *// Inouts" end-inst-point t)
  7589. (verilog-read-sub-decls-line submoddecls comment)) ;; Modifies sigs-inout
  7590. (goto-char st-point)
  7591. (while (re-search-forward "\\s *(?\\s *// Inputs" end-inst-point t)
  7592. (verilog-read-sub-decls-line submoddecls comment)) ;; Modifies sigs-in
  7593. )))))))
  7594. ;; Combine duplicate bits
  7595. ;;(setq rr (vector sigs-out sigs-inout sigs-in))
  7596. (verilog-subdecls-new
  7597. (verilog-signals-combine-bus (nreverse sigs-out))
  7598. (verilog-signals-combine-bus (nreverse sigs-inout))
  7599. (verilog-signals-combine-bus (nreverse sigs-in))
  7600. (verilog-signals-combine-bus (nreverse sigs-intf))
  7601. (verilog-signals-combine-bus (nreverse sigs-intfd))))))
  7602. (defun verilog-read-inst-pins ()
  7603. "Return an array of [ pins ] for the current instantiation at point.
  7604. For example if declare A A (.B(SIG)) then B will be included in the list."
  7605. (save-excursion
  7606. (let ((end-mod-point (point)) ;; presume at /*AUTOINST*/ point
  7607. pins pin)
  7608. (verilog-backward-open-paren)
  7609. (while (re-search-forward "\\.\\([^(,) \t\n\f]*\\)\\s-*" end-mod-point t)
  7610. (setq pin (match-string 1))
  7611. (unless (verilog-inside-comment-or-string-p)
  7612. (setq pins (cons (list pin) pins))
  7613. (when (looking-at "(")
  7614. (verilog-forward-sexp-ign-cmt 1))))
  7615. (vector pins))))
  7616. (defun verilog-read-arg-pins ()
  7617. "Return an array of [ pins ] for the current argument declaration at point."
  7618. (save-excursion
  7619. (let ((end-mod-point (point)) ;; presume at /*AUTOARG*/ point
  7620. pins pin)
  7621. (verilog-backward-open-paren)
  7622. (while (re-search-forward "\\([a-zA-Z0-9$_.%`]+\\)" end-mod-point t)
  7623. (setq pin (match-string 1))
  7624. (unless (verilog-inside-comment-or-string-p)
  7625. (setq pins (cons (list pin) pins))))
  7626. (vector pins))))
  7627. (defun verilog-read-auto-constants (beg end-mod-point)
  7628. "Return a list of AUTO_CONSTANTs used in the region from BEG to END-MOD-POINT."
  7629. ;; Insert new
  7630. (save-excursion
  7631. (let (sig-list tpl-end-pt)
  7632. (goto-char beg)
  7633. (while (re-search-forward "\\<AUTO_CONSTANT" end-mod-point t)
  7634. (if (not (looking-at "\\s *("))
  7635. (error "%s: Missing () after AUTO_CONSTANT" (verilog-point-text)))
  7636. (search-forward "(" end-mod-point)
  7637. (setq tpl-end-pt (save-excursion
  7638. (backward-char 1)
  7639. (verilog-forward-sexp-cmt 1) ;; Moves to paren that closes argdecl's
  7640. (backward-char 1)
  7641. (point)))
  7642. (while (re-search-forward "\\s-*\\([\"a-zA-Z0-9$_.%`]+\\)\\s-*,*" tpl-end-pt t)
  7643. (setq sig-list (cons (list (match-string 1) nil nil) sig-list))))
  7644. sig-list)))
  7645. (defvar verilog-cache-has-lisp nil "True if any AUTO_LISP in buffer.")
  7646. (make-variable-buffer-local 'verilog-cache-has-lisp)
  7647. (defun verilog-read-auto-lisp-present ()
  7648. "Set `verilog-cache-has-lisp' if any AUTO_LISP in this buffer."
  7649. (save-excursion
  7650. (goto-char (point-min))
  7651. (setq verilog-cache-has-lisp (re-search-forward "\\<AUTO_LISP(" nil t))))
  7652. (defun verilog-read-auto-lisp (start end)
  7653. "Look for and evaluate a AUTO_LISP between START and END.
  7654. Must call `verilog-read-auto-lisp-present' before this function."
  7655. ;; This function is expensive for large buffers, so we cache if any AUTO_LISP exists
  7656. (when verilog-cache-has-lisp
  7657. (save-excursion
  7658. (goto-char start)
  7659. (while (re-search-forward "\\<AUTO_LISP(" end t)
  7660. (backward-char)
  7661. (let* ((beg-pt (prog1 (point)
  7662. (verilog-forward-sexp-cmt 1))) ;; Closing paren
  7663. (end-pt (point)))
  7664. (eval-region beg-pt end-pt nil))))))
  7665. (eval-when-compile
  7666. ;; Prevent compile warnings; these are let's, not globals
  7667. ;; Do not remove the eval-when-compile
  7668. ;; - we want a error when we are debugging this code if they are refed.
  7669. (defvar sigs-in)
  7670. (defvar sigs-out-d)
  7671. (defvar sigs-out-i)
  7672. (defvar sigs-out-unk)
  7673. (defvar sigs-temp)
  7674. (defvar vector-skip-list))
  7675. (defun verilog-read-always-signals-recurse
  7676. (exit-keywd rvalue temp-next)
  7677. "Recursive routine for parentheses/bracket matching.
  7678. EXIT-KEYWD is expression to stop at, nil if top level.
  7679. RVALUE is true if at right hand side of equal.
  7680. IGNORE-NEXT is true to ignore next token, fake from inside case statement."
  7681. (let* ((semi-rvalue (equal "endcase" exit-keywd)) ;; true if after a ; we are looking for rvalue
  7682. keywd last-keywd sig-tolk sig-last-tolk gotend got-sig got-list end-else-check
  7683. ignore-next)
  7684. ;;(if dbg (setq dbg (concat dbg (format "Recursion %S %S %S\n" exit-keywd rvalue temp-next))))
  7685. (while (not (or (eobp) gotend))
  7686. (cond
  7687. ((looking-at "//")
  7688. (search-forward "\n"))
  7689. ((looking-at "/\\*")
  7690. (or (search-forward "*/")
  7691. (error "%s: Unmatched /* */, at char %d" (verilog-point-text) (point))))
  7692. ((looking-at "(\\*")
  7693. ;; To advance past either "(*)" or "(* ... *)" don't forward past first *
  7694. (forward-char 1)
  7695. (or (search-forward "*)")
  7696. (error "%s: Unmatched (* *), at char %d" (verilog-point-text) (point))))
  7697. (t (setq keywd (buffer-substring-no-properties
  7698. (point)
  7699. (save-excursion (when (eq 0 (skip-chars-forward "a-zA-Z0-9$_.%`"))
  7700. (forward-char 1))
  7701. (point)))
  7702. sig-last-tolk sig-tolk
  7703. sig-tolk nil)
  7704. ;;(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))))
  7705. (cond
  7706. ((equal keywd "\"")
  7707. (or (re-search-forward "[^\\]\"" nil t)
  7708. (error "%s: Unmatched quotes, at char %d" (verilog-point-text) (point))))
  7709. ;; else at top level loop, keep parsing
  7710. ((and end-else-check (equal keywd "else"))
  7711. ;;(if dbg (setq dbg (concat dbg (format "\tif-check-else %s\n" keywd))))
  7712. ;; no forward movement, want to see else in lower loop
  7713. (setq end-else-check nil))
  7714. ;; End at top level loop
  7715. ((and end-else-check (looking-at "[^ \t\n\f]"))
  7716. ;;(if dbg (setq dbg (concat dbg (format "\tif-check-else-other %s\n" keywd))))
  7717. (setq gotend t))
  7718. ;; Final statement?
  7719. ((and exit-keywd (equal keywd exit-keywd))
  7720. (setq gotend t)
  7721. (forward-char (length keywd)))
  7722. ;; Standard tokens...
  7723. ((equal keywd ";")
  7724. (setq ignore-next nil rvalue semi-rvalue)
  7725. ;; Final statement at top level loop?
  7726. (when (not exit-keywd)
  7727. ;;(if dbg (setq dbg (concat dbg (format "\ttop-end-check %s\n" keywd))))
  7728. (setq end-else-check t))
  7729. (forward-char 1))
  7730. ((equal keywd "'")
  7731. (if (looking-at "'[sS]?[hdxboHDXBO]?[ \t]*[0-9a-fA-F_xzXZ?]+")
  7732. (goto-char (match-end 0))
  7733. (forward-char 1)))
  7734. ((equal keywd ":") ;; Case statement, begin/end label, x?y:z
  7735. (cond ((equal "endcase" exit-keywd) ;; case x: y=z; statement next
  7736. (setq ignore-next nil rvalue nil))
  7737. ((equal "?" exit-keywd) ;; x?y:z rvalue
  7738. ) ;; NOP
  7739. ((equal "]" exit-keywd) ;; [x:y] rvalue
  7740. ) ;; NOP
  7741. (got-sig ;; label: statement
  7742. (setq ignore-next nil rvalue semi-rvalue got-sig nil))
  7743. ((not rvalue) ;; begin label
  7744. (setq ignore-next t rvalue nil)))
  7745. (forward-char 1))
  7746. ((equal keywd "=")
  7747. (when got-sig
  7748. ;;(if dbg (setq dbg (concat dbg (format "\t\tequal got-sig=%S got-list=%s\n" got-sig got-list))))
  7749. (set got-list (cons got-sig (symbol-value got-list)))
  7750. (setq got-sig nil))
  7751. (when (not rvalue)
  7752. (if (eq (char-before) ?< )
  7753. (setq sigs-out-d (append sigs-out-d sigs-out-unk)
  7754. sigs-out-unk nil)
  7755. (setq sigs-out-i (append sigs-out-i sigs-out-unk)
  7756. sigs-out-unk nil)))
  7757. (setq ignore-next nil rvalue t)
  7758. (forward-char 1))
  7759. ((equal keywd "?")
  7760. (forward-char 1)
  7761. (verilog-read-always-signals-recurse ":" rvalue nil))
  7762. ((equal keywd "[")
  7763. (forward-char 1)
  7764. (verilog-read-always-signals-recurse "]" t nil))
  7765. ((equal keywd "(")
  7766. (forward-char 1)
  7767. (cond (sig-last-tolk ;; Function call; zap last signal
  7768. (setq got-sig nil)))
  7769. (cond ((equal last-keywd "for")
  7770. ;; temp-next: Variables on LHS are lvalues, but generally we want
  7771. ;; to ignore them, assuming they are loop increments
  7772. (verilog-read-always-signals-recurse ";" nil t)
  7773. (verilog-read-always-signals-recurse ";" t nil)
  7774. (verilog-read-always-signals-recurse ")" nil nil))
  7775. (t (verilog-read-always-signals-recurse ")" t nil))))
  7776. ((equal keywd "begin")
  7777. (skip-syntax-forward "w_")
  7778. (verilog-read-always-signals-recurse "end" nil nil)
  7779. ;;(if dbg (setq dbg (concat dbg (format "\tgot-end %s\n" exit-keywd))))
  7780. (setq ignore-next nil rvalue semi-rvalue)
  7781. (if (not exit-keywd) (setq end-else-check t)))
  7782. ((member keywd '("case" "casex" "casez"))
  7783. (skip-syntax-forward "w_")
  7784. (verilog-read-always-signals-recurse "endcase" t nil)
  7785. (setq ignore-next nil rvalue semi-rvalue)
  7786. (if (not exit-keywd) (setq gotend t))) ;; top level begin/end
  7787. ((string-match "^[$`a-zA-Z_]" keywd) ;; not exactly word constituent
  7788. (cond ((member keywd '("`ifdef" "`ifndef" "`elsif"))
  7789. (setq ignore-next t))
  7790. ((or ignore-next
  7791. (member keywd verilog-keywords)
  7792. (string-match "^\\$" keywd)) ;; PLI task
  7793. (setq ignore-next nil))
  7794. (t
  7795. (setq keywd (verilog-symbol-detick-denumber keywd))
  7796. (when got-sig
  7797. (set got-list (cons got-sig (symbol-value got-list)))
  7798. ;;(if dbg (setq dbg (concat dbg (format "\t\tgot-sig=%S got-list=%S\n" got-sig got-list))))
  7799. )
  7800. (setq got-list (cond (temp-next 'sigs-temp)
  7801. (rvalue 'sigs-in)
  7802. (t 'sigs-out-unk))
  7803. got-sig (if (or (not keywd)
  7804. (assoc keywd (symbol-value got-list)))
  7805. nil (list keywd nil nil))
  7806. temp-next nil
  7807. sig-tolk t)))
  7808. (skip-chars-forward "a-zA-Z0-9$_.%`"))
  7809. (t
  7810. (forward-char 1)))
  7811. ;; End of non-comment token
  7812. (setq last-keywd keywd)))
  7813. (skip-syntax-forward " "))
  7814. ;; Append the final pending signal
  7815. (when got-sig
  7816. ;;(if dbg (setq dbg (concat dbg (format "\t\tfinal got-sig=%S got-list=%s\n" got-sig got-list))))
  7817. (set got-list (cons got-sig (symbol-value got-list)))
  7818. (setq got-sig nil))
  7819. ;;(if dbg (setq dbg (concat dbg (format "ENDRecursion %s\n" exit-keywd))))
  7820. ))
  7821. (defun verilog-read-always-signals ()
  7822. "Parse always block at point and return list of (outputs inout inputs)."
  7823. (save-excursion
  7824. (let* (;;(dbg "")
  7825. sigs-out-d sigs-out-i sigs-out-unk sigs-temp sigs-in)
  7826. (search-forward ")")
  7827. (verilog-read-always-signals-recurse nil nil nil)
  7828. (setq sigs-out-i (append sigs-out-i sigs-out-unk)
  7829. sigs-out-unk nil)
  7830. ;;(if dbg (with-current-buffer (get-buffer-create "*vl-dbg*")) (delete-region (point-min) (point-max)) (insert dbg) (setq dbg ""))
  7831. ;; Return what was found
  7832. (verilog-alw-new sigs-out-d sigs-out-i sigs-temp sigs-in))))
  7833. (defun verilog-read-instants ()
  7834. "Parse module at point and return list of ( ( file instance ) ... )."
  7835. (verilog-beg-of-defun-quick)
  7836. (let* ((end-mod-point (verilog-get-end-of-defun t))
  7837. (state nil)
  7838. (instants-list nil))
  7839. (save-excursion
  7840. (while (< (point) end-mod-point)
  7841. ;; Stay at level 0, no comments
  7842. (while (progn
  7843. (setq state (parse-partial-sexp (point) end-mod-point 0 t nil))
  7844. (or (> (car state) 0) ; in parens
  7845. (nth 5 state) ; comment
  7846. ))
  7847. (forward-line 1))
  7848. (beginning-of-line)
  7849. (if (looking-at "^\\s-*\\([a-zA-Z0-9`_$]+\\)\\s-+\\([a-zA-Z0-9`_$]+\\)\\s-*(")
  7850. ;;(if (looking-at "^\\(.+\\)$")
  7851. (let ((module (match-string 1))
  7852. (instant (match-string 2)))
  7853. (if (not (member module verilog-keywords))
  7854. (setq instants-list (cons (list module instant) instants-list)))))
  7855. (forward-line 1)))
  7856. instants-list))
  7857. (defun verilog-read-auto-template (module)
  7858. "Look for a auto_template for the instantiation of the given MODULE.
  7859. If found returns the signal name connections. Return REGEXP and
  7860. list of ( (signal_name connection_name)... )."
  7861. (save-excursion
  7862. ;; Find beginning
  7863. (let ((tpl-regexp "\\([0-9]+\\)")
  7864. (lineno -1) ; -1 to offset for the AUTO_TEMPLATE's newline
  7865. (templateno 0)
  7866. (pt (point))
  7867. tpl-sig-list tpl-wild-list tpl-end-pt rep)
  7868. ;; Note this search is expensive, as we hunt from mod-begin to point
  7869. ;; for every instantiation. Likewise in verilog-read-auto-lisp.
  7870. ;; So, we look first for an exact string rather than a slow regexp.
  7871. ;; Someday we may keep a cache of every template, but this would also
  7872. ;; need to record the relative position of each AUTOINST, as multiple
  7873. ;; templates exist for each module, and we're inserting lines.
  7874. (cond ((or
  7875. (verilog-re-search-backward-substr
  7876. "AUTO_TEMPLATE"
  7877. (concat "^\\s-*/?\\*?\\s-*" module "\\s-+AUTO_TEMPLATE") nil t)
  7878. ;; Also try forward of this AUTOINST
  7879. ;; This is for historical support; this isn't speced as working
  7880. (progn
  7881. (goto-char pt)
  7882. (verilog-re-search-forward-substr
  7883. "AUTO_TEMPLATE"
  7884. (concat "^\\s-*/?\\*?\\s-*" module "\\s-+AUTO_TEMPLATE") nil t)))
  7885. (goto-char (match-end 0))
  7886. ;; Parse "REGEXP"
  7887. ;; We reserve @"..." for future lisp expressions that evaluate
  7888. ;; once-per-AUTOINST
  7889. (when (looking-at "\\s-*\"\\([^\"]*\\)\"")
  7890. (setq tpl-regexp (match-string 1))
  7891. (goto-char (match-end 0)))
  7892. (search-forward "(")
  7893. ;; Parse lines in the template
  7894. (when verilog-auto-inst-template-numbers
  7895. (save-excursion
  7896. (let ((pre-pt (point)))
  7897. (goto-char (point-min))
  7898. (while (search-forward "AUTO_TEMPLATE" pre-pt t)
  7899. (setq templateno (1+ templateno)))
  7900. (while (< (point) pre-pt)
  7901. (forward-line 1)
  7902. (setq lineno (1+ lineno))))))
  7903. (setq tpl-end-pt (save-excursion
  7904. (backward-char 1)
  7905. (verilog-forward-sexp-cmt 1) ;; Moves to paren that closes argdecl's
  7906. (backward-char 1)
  7907. (point)))
  7908. ;;
  7909. (while (< (point) tpl-end-pt)
  7910. (cond ((looking-at "\\s-*\\.\\([a-zA-Z0-9`_$]+\\)\\s-*(\\(.*\\))\\s-*\\(,\\|)\\s-*;\\)")
  7911. (setq tpl-sig-list
  7912. (cons (list
  7913. (match-string-no-properties 1)
  7914. (match-string-no-properties 2)
  7915. templateno lineno)
  7916. tpl-sig-list))
  7917. (goto-char (match-end 0)))
  7918. ;; Regexp form??
  7919. ((looking-at
  7920. ;; Regexp bug in XEmacs disallows ][ inside [], and wants + last
  7921. "\\s-*\\.\\(\\([a-zA-Z0-9`_$+@^.*?|---]+\\|[][]\\|\\\\[()|]\\)+\\)\\s-*(\\(.*\\))\\s-*\\(,\\|)\\s-*;\\)")
  7922. (setq rep (match-string-no-properties 3))
  7923. (goto-char (match-end 0))
  7924. (setq tpl-wild-list
  7925. (cons (list
  7926. (concat "^"
  7927. (verilog-string-replace-matches "@" "\\\\([0-9]+\\\\)" nil nil
  7928. (match-string 1))
  7929. "$")
  7930. rep
  7931. templateno lineno)
  7932. tpl-wild-list)))
  7933. ((looking-at "[ \t\f]+")
  7934. (goto-char (match-end 0)))
  7935. ((looking-at "\n")
  7936. (setq lineno (1+ lineno))
  7937. (goto-char (match-end 0)))
  7938. ((looking-at "//")
  7939. (search-forward "\n")
  7940. (setq lineno (1+ lineno)))
  7941. ((looking-at "/\\*")
  7942. (forward-char 2)
  7943. (or (search-forward "*/")
  7944. (error "%s: Unmatched /* */, at char %d" (verilog-point-text) (point))))
  7945. (t
  7946. (error "%s: AUTO_TEMPLATE parsing error: %s"
  7947. (verilog-point-text)
  7948. (progn (looking-at ".*$") (match-string 0))))))
  7949. ;; Return
  7950. (vector tpl-regexp
  7951. (list tpl-sig-list tpl-wild-list)))
  7952. ;; If no template found
  7953. (t (vector tpl-regexp nil))))))
  7954. ;;(progn (find-file "auto-template.v") (verilog-read-auto-template "ptl_entry"))
  7955. (defun verilog-set-define (defname defvalue &optional buffer enumname)
  7956. "Set the definition DEFNAME to the DEFVALUE in the given BUFFER.
  7957. Optionally associate it with the specified enumeration ENUMNAME."
  7958. (with-current-buffer (or buffer (current-buffer))
  7959. (let ((mac (intern (concat "vh-" defname))))
  7960. ;;(message "Define %s=%s" defname defvalue) (sleep-for 1)
  7961. ;; Need to define to a constant if no value given
  7962. (set (make-local-variable mac)
  7963. (if (equal defvalue "") "1" defvalue)))
  7964. (if enumname
  7965. (let ((enumvar (intern (concat "venum-" enumname))))
  7966. ;;(message "Define %s=%s" defname defvalue) (sleep-for 1)
  7967. (unless (boundp enumvar) (set enumvar nil))
  7968. (add-to-list (make-local-variable enumvar) defname)))))
  7969. (defun verilog-read-defines (&optional filename recurse subcall)
  7970. "Read `defines and parameters for the current file, or optional FILENAME.
  7971. If the filename is provided, `verilog-library-flags' will be used to
  7972. resolve it. If optional RECURSE is non-nil, recurse through `includes.
  7973. Parameters must be simple assignments to constants, or have their own
  7974. \"parameter\" label rather than a list of parameters. Thus:
  7975. parameter X = 5, Y = 10; // Ok
  7976. parameter X = {1'b1, 2'h2}; // Ok
  7977. parameter X = {1'b1, 2'h2}, Y = 10; // Bad, make into 2 parameter lines
  7978. Defines must be simple text substitutions, one on a line, starting
  7979. at the beginning of the line. Any ifdefs or multiline comments around the
  7980. define are ignored.
  7981. Defines are stored inside Emacs variables using the name vh-{definename}.
  7982. This function is useful for setting vh-* variables. The file variables
  7983. feature can be used to set defines that `verilog-mode' can see; put at the
  7984. *END* of your file something like:
  7985. // Local Variables:
  7986. // vh-macro:\"macro_definition\"
  7987. // End:
  7988. If macros are defined earlier in the same file and you want their values,
  7989. you can read them automatically (provided `enable-local-eval' is on):
  7990. // Local Variables:
  7991. // eval:(verilog-read-defines)
  7992. // eval:(verilog-read-defines \"group_standard_includes.v\")
  7993. // End:
  7994. Note these are only read when the file is first visited, you must use
  7995. \\[find-alternate-file] RET to have these take effect after editing them!
  7996. If you want to disable the \"Process `eval' or hook local variables\"
  7997. warning message, you need to add to your .emacs file:
  7998. (setq enable-local-eval t)"
  7999. (let ((origbuf (current-buffer)))
  8000. (save-excursion
  8001. (unless subcall (verilog-getopt-flags))
  8002. (when filename
  8003. (let ((fns (verilog-library-filenames filename (buffer-file-name))))
  8004. (if fns
  8005. (set-buffer (find-file-noselect (car fns)))
  8006. (error (concat (verilog-point-text)
  8007. ": Can't find verilog-read-defines file: " filename)))))
  8008. (when recurse
  8009. (goto-char (point-min))
  8010. (while (re-search-forward "^\\s-*`include\\s-+\\([^ \t\n\f]+\\)" nil t)
  8011. (let ((inc (verilog-string-replace-matches
  8012. "\"" "" nil nil (match-string-no-properties 1))))
  8013. (unless (verilog-inside-comment-or-string-p)
  8014. (verilog-read-defines inc recurse t)))))
  8015. ;; Read `defines
  8016. ;; note we don't use verilog-re... it's faster this way, and that
  8017. ;; function has problems when comments are at the end of the define
  8018. (goto-char (point-min))
  8019. (while (re-search-forward "^\\s-*`define\\s-+\\([a-zA-Z0-9_$]+\\)\\s-+\\(.*\\)$" nil t)
  8020. (let ((defname (match-string-no-properties 1))
  8021. (defvalue (match-string-no-properties 2)))
  8022. (setq defvalue (verilog-string-replace-matches "\\s-*/[/*].*$" "" nil nil defvalue))
  8023. (verilog-set-define defname defvalue origbuf)))
  8024. ;; Hack: Read parameters
  8025. (goto-char (point-min))
  8026. (while (re-search-forward
  8027. "^\\s-*\\(parameter\\|localparam\\)\\(\\s-*\\[[^]]*\\]\\)?\\s-*" nil t)
  8028. (let (enumname)
  8029. ;; The primary way of getting defines is verilog-read-decls
  8030. ;; However, that isn't called yet for included files, so we'll add another scheme
  8031. (if (looking-at "[^\n]*synopsys\\s +enum\\s +\\([a-zA-Z0-9_]+\\)")
  8032. (setq enumname (match-string-no-properties 1)))
  8033. (forward-comment 999)
  8034. (while (looking-at (concat "\\s-*,?\\s-*\\(?:/[/*].*?$\\)?\\s-*\\([a-zA-Z0-9_$]+\\)"
  8035. "\\s-*=\\s-*\\([^;,]*\\),?\\s-*\\(/[/*].*?$\\)?\\s-*"))
  8036. (verilog-set-define (match-string-no-properties 1)
  8037. (match-string-no-properties 2) origbuf enumname)
  8038. (goto-char (match-end 0))
  8039. (forward-comment 999)))))))
  8040. (defun verilog-read-includes ()
  8041. "Read `includes for the current file.
  8042. This will find all of the `includes which are at the beginning of lines,
  8043. ignoring any ifdefs or multiline comments around them.
  8044. `verilog-read-defines' is then performed on the current and each included
  8045. file.
  8046. It is often useful put at the *END* of your file something like:
  8047. // Local Variables:
  8048. // eval:(verilog-read-defines)
  8049. // eval:(verilog-read-includes)
  8050. // End:
  8051. Note includes are only read when the file is first visited, you must use
  8052. \\[find-alternate-file] RET to have these take effect after editing them!
  8053. It is good to get in the habit of including all needed files in each .v
  8054. file that needs it, rather than waiting for compile time. This will aid
  8055. this process, Verilint, and readability. To prevent defining the same
  8056. variable over and over when many modules are compiled together, put a test
  8057. around the inside each include file:
  8058. foo.v (a include):
  8059. `ifdef _FOO_V // include if not already included
  8060. `else
  8061. `define _FOO_V
  8062. ... contents of file
  8063. `endif // _FOO_V"
  8064. ;;slow: (verilog-read-defines nil t))
  8065. (save-excursion
  8066. (verilog-getopt-flags)
  8067. (goto-char (point-min))
  8068. (while (re-search-forward "^\\s-*`include\\s-+\\([^ \t\n\f]+\\)" nil t)
  8069. (let ((inc (verilog-string-replace-matches "\"" "" nil nil (match-string 1))))
  8070. (verilog-read-defines inc nil t)))))
  8071. (defun verilog-read-signals (&optional start end)
  8072. "Return a simple list of all possible signals in the file.
  8073. Bounded by optional region from START to END. Overly aggressive but fast.
  8074. Some macros and such are also found and included. For dinotrace.el."
  8075. (let (sigs-all keywd)
  8076. (progn;save-excursion
  8077. (goto-char (or start (point-min)))
  8078. (setq end (or end (point-max)))
  8079. (while (re-search-forward "[\"/a-zA-Z_.%`]" end t)
  8080. (forward-char -1)
  8081. (cond
  8082. ((looking-at "//")
  8083. (search-forward "\n"))
  8084. ((looking-at "/\\*")
  8085. (search-forward "*/"))
  8086. ((looking-at "(\\*")
  8087. (or (looking-at "(\\*\\s-*)") ; It's a "always @ (*)"
  8088. (search-forward "*)")))
  8089. ((eq ?\" (following-char))
  8090. (re-search-forward "[^\\]\"")) ;; don't forward-char first, since we look for a non backslash first
  8091. ((looking-at "\\s-*\\([a-zA-Z0-9$_.%`]+\\)")
  8092. (goto-char (match-end 0))
  8093. (setq keywd (match-string-no-properties 1))
  8094. (or (member keywd verilog-keywords)
  8095. (member keywd sigs-all)
  8096. (setq sigs-all (cons keywd sigs-all))))
  8097. (t (forward-char 1))))
  8098. ;; Return list
  8099. sigs-all)))
  8100. ;;
  8101. ;; Argument file parsing
  8102. ;;
  8103. (defun verilog-getopt (arglist)
  8104. "Parse -f, -v etc arguments in ARGLIST list or string."
  8105. (unless (listp arglist) (setq arglist (list arglist)))
  8106. (let ((space-args '())
  8107. arg next-param)
  8108. ;; Split on spaces, so users can pass whole command lines
  8109. (while arglist
  8110. (setq arg (car arglist)
  8111. arglist (cdr arglist))
  8112. (while (string-match "^\\([^ \t\n\f]+\\)[ \t\n\f]*\\(.*$\\)" arg)
  8113. (setq space-args (append space-args
  8114. (list (match-string-no-properties 1 arg))))
  8115. (setq arg (match-string 2 arg))))
  8116. ;; Parse arguments
  8117. (while space-args
  8118. (setq arg (car space-args)
  8119. space-args (cdr space-args))
  8120. (cond
  8121. ;; Need another arg
  8122. ((equal arg "-f")
  8123. (setq next-param arg))
  8124. ((equal arg "-v")
  8125. (setq next-param arg))
  8126. ((equal arg "-y")
  8127. (setq next-param arg))
  8128. ;; +libext+(ext1)+(ext2)...
  8129. ((string-match "^\\+libext\\+\\(.*\\)" arg)
  8130. (setq arg (match-string 1 arg))
  8131. (while (string-match "\\([^+]+\\)\\+?\\(.*\\)" arg)
  8132. (verilog-add-list-unique `verilog-library-extensions
  8133. (match-string 1 arg))
  8134. (setq arg (match-string 2 arg))))
  8135. ;;
  8136. ((or (string-match "^-D\\([^+=]*\\)[+=]\\(.*\\)" arg) ;; -Ddefine=val
  8137. (string-match "^-D\\([^+=]*\\)\\(\\)" arg) ;; -Ddefine
  8138. (string-match "^\\+define\\([^+=]*\\)[+=]\\(.*\\)" arg) ;; +define+val
  8139. (string-match "^\\+define\\([^+=]*\\)\\(\\)" arg)) ;; +define+define
  8140. (verilog-set-define (match-string 1 arg) (match-string 2 arg)))
  8141. ;;
  8142. ((or (string-match "^\\+incdir\\+\\(.*\\)" arg) ;; +incdir+dir
  8143. (string-match "^-I\\(.*\\)" arg)) ;; -Idir
  8144. (verilog-add-list-unique `verilog-library-directories
  8145. (match-string 1 (substitute-in-file-name arg))))
  8146. ;; Ignore
  8147. ((equal "+librescan" arg))
  8148. ((string-match "^-U\\(.*\\)" arg)) ;; -Udefine
  8149. ;; Second parameters
  8150. ((equal next-param "-f")
  8151. (setq next-param nil)
  8152. (verilog-getopt-file (substitute-in-file-name arg)))
  8153. ((equal next-param "-v")
  8154. (setq next-param nil)
  8155. (verilog-add-list-unique `verilog-library-files
  8156. (substitute-in-file-name arg)))
  8157. ((equal next-param "-y")
  8158. (setq next-param nil)
  8159. (verilog-add-list-unique `verilog-library-directories
  8160. (substitute-in-file-name arg)))
  8161. ;; Filename
  8162. ((string-match "^[^-+]" arg)
  8163. (verilog-add-list-unique `verilog-library-files
  8164. (substitute-in-file-name arg)))
  8165. ;; Default - ignore; no warning
  8166. ))))
  8167. ;;(verilog-getopt (list "+libext+.a+.b" "+incdir+foodir" "+define+a+aval" "-f" "otherf" "-v" "library" "-y" "dir"))
  8168. (defun verilog-getopt-file (filename)
  8169. "Read Verilog options from the specified FILENAME."
  8170. (save-excursion
  8171. (let ((fns (verilog-library-filenames filename (buffer-file-name)))
  8172. (orig-buffer (current-buffer))
  8173. line)
  8174. (if fns
  8175. (set-buffer (find-file-noselect (car fns)))
  8176. (error (concat (verilog-point-text)
  8177. ": Can't find verilog-getopt-file -f file: " filename)))
  8178. (goto-char (point-min))
  8179. (while (not (eobp))
  8180. (setq line (buffer-substring (point) (point-at-eol)))
  8181. (forward-line 1)
  8182. (when (string-match "//" line)
  8183. (setq line (substring line 0 (match-beginning 0))))
  8184. (with-current-buffer orig-buffer ; Variables are buffer-local, so need right context.
  8185. (verilog-getopt line))))))
  8186. (defun verilog-getopt-flags ()
  8187. "Convert `verilog-library-flags' into standard library variables."
  8188. ;; If the flags are local, then all the outputs should be local also
  8189. (when (local-variable-p `verilog-library-flags (current-buffer))
  8190. (mapc 'make-local-variable '(verilog-library-extensions
  8191. verilog-library-directories
  8192. verilog-library-files
  8193. verilog-library-flags)))
  8194. ;; Allow user to customize
  8195. (verilog-run-hooks 'verilog-before-getopt-flags-hook)
  8196. ;; Process arguments
  8197. (verilog-getopt verilog-library-flags)
  8198. ;; Allow user to customize
  8199. (verilog-run-hooks 'verilog-getopt-flags-hook))
  8200. (defun verilog-add-list-unique (varref object)
  8201. "Append to VARREF list the given OBJECT,
  8202. unless it is already a member of the variable's list."
  8203. (unless (member object (symbol-value varref))
  8204. (set varref (append (symbol-value varref) (list object))))
  8205. varref)
  8206. ;;(progn (setq l '()) (verilog-add-list-unique `l "a") (verilog-add-list-unique `l "a") l)
  8207. (defun verilog-current-flags ()
  8208. "Convert `verilog-library-flags' and similar variables to command line.
  8209. Used for __FLAGS__ in `verilog-expand-command'."
  8210. (let ((cmd (mapconcat `concat verilog-library-flags " ")))
  8211. (when (equal cmd "")
  8212. (setq cmd (concat
  8213. "+libext+" (mapconcat `concat verilog-library-extensions "+")
  8214. (mapconcat (lambda (i) (concat " -y " i " +incdir+" i))
  8215. verilog-library-directories "")
  8216. (mapconcat (lambda (i) (concat " -v " i))
  8217. verilog-library-files ""))))
  8218. cmd))
  8219. ;;(verilog-current-flags)
  8220. ;;
  8221. ;; Cached directory support
  8222. ;;
  8223. (defvar verilog-dir-cache-preserving nil
  8224. "If set, the directory cache is enabled, and file system changes are ignored.
  8225. See `verilog-dir-exists-p' and `verilog-dir-files'.")
  8226. ;; If adding new cached variable, add also to verilog-preserve-dir-cache
  8227. (defvar verilog-dir-cache-list nil
  8228. "Alist of (((Cwd Dirname) Results)...) for caching `verilog-dir-files'.")
  8229. (defvar verilog-dir-cache-lib-filenames nil
  8230. "Cached data for `verilog-library-filenames'.")
  8231. (defmacro verilog-preserve-dir-cache (&rest body)
  8232. "Execute the BODY forms, allowing directory cache preservation within BODY.
  8233. This means that changes inside BODY made to the file system will not be
  8234. seen by the `verilog-dir-files' and related functions."
  8235. `(let ((verilog-dir-cache-preserving (current-buffer))
  8236. verilog-dir-cache-list
  8237. verilog-dir-cache-lib-filenames)
  8238. (progn ,@body)))
  8239. (defun verilog-dir-files (dirname)
  8240. "Return all filenames in the DIRNAME directory.
  8241. Relative paths depend on the `default-directory'.
  8242. Results are cached if inside `verilog-preserve-dir-cache'."
  8243. (unless verilog-dir-cache-preserving
  8244. (setq verilog-dir-cache-list nil)) ;; Cache disabled
  8245. ;; We don't use expand-file-name on the dirname to make key, as it's slow
  8246. (let* ((cache-key (list dirname default-directory))
  8247. (fass (assoc cache-key verilog-dir-cache-list))
  8248. exp-dirname data)
  8249. (cond (fass ;; Return data from cache hit
  8250. (nth 1 fass))
  8251. (t
  8252. (setq exp-dirname (expand-file-name dirname)
  8253. data (and (file-directory-p exp-dirname)
  8254. (directory-files exp-dirname nil nil nil)))
  8255. ;; Note we also encache nil for non-existing dirs.
  8256. (setq verilog-dir-cache-list (cons (list cache-key data)
  8257. verilog-dir-cache-list))
  8258. data))))
  8259. ;; Miss-and-hit test:
  8260. ;;(verilog-preserve-dir-cache (prin1 (verilog-dir-files "."))
  8261. ;; (prin1 (verilog-dir-files ".")) nil)
  8262. (defun verilog-dir-file-exists-p (filename)
  8263. "Return true if FILENAME exists.
  8264. Like `file-exists-p' but results are cached if inside
  8265. `verilog-preserve-dir-cache'."
  8266. (let* ((dirname (file-name-directory filename))
  8267. ;; Correct for file-name-nondirectory returning same if no slash.
  8268. (dirnamed (if (or (not dirname) (equal dirname filename))
  8269. default-directory dirname))
  8270. (flist (verilog-dir-files dirnamed)))
  8271. (and flist
  8272. (member (file-name-nondirectory filename) flist)
  8273. t)))
  8274. ;;(verilog-dir-file-exists-p "verilog-mode.el")
  8275. ;;(verilog-dir-file-exists-p "../verilog-mode/verilog-mode.el")
  8276. ;;
  8277. ;; Module name lookup
  8278. ;;
  8279. (defun verilog-module-inside-filename-p (module filename)
  8280. "Return modi if MODULE is specified inside FILENAME, else nil.
  8281. Allows version control to check out the file if need be."
  8282. (and (or (file-exists-p filename)
  8283. (and (fboundp 'vc-backend)
  8284. (vc-backend filename)))
  8285. (let (modi type)
  8286. (with-current-buffer (find-file-noselect filename)
  8287. (save-excursion
  8288. (goto-char (point-min))
  8289. (while (and
  8290. ;; It may be tempting to look for verilog-defun-re,
  8291. ;; don't, it slows things down a lot!
  8292. (verilog-re-search-forward-quick "\\<\\(module\\|interface\\|program\\)\\>" nil t)
  8293. (setq type (match-string-no-properties 0))
  8294. (verilog-re-search-forward-quick "[(;]" nil t))
  8295. (if (equal module (verilog-read-module-name))
  8296. (setq modi (verilog-modi-new module filename (point) type))))
  8297. modi)))))
  8298. (defun verilog-is-number (symbol)
  8299. "Return true if SYMBOL is number-like."
  8300. (or (string-match "^[0-9 \t:]+$" symbol)
  8301. (string-match "^[---]*[0-9]+$" symbol)
  8302. (string-match "^[0-9 \t]+'s?[hdxbo][0-9a-fA-F_xz? \t]*$" symbol)))
  8303. (defun verilog-symbol-detick (symbol wing-it)
  8304. "Return an expanded SYMBOL name without any defines.
  8305. If the variable vh-{symbol} is defined, return that value.
  8306. If undefined, and WING-IT, return just SYMBOL without the tick, else nil."
  8307. (while (and symbol (string-match "^`" symbol))
  8308. (setq symbol (substring symbol 1))
  8309. (setq symbol
  8310. (if (boundp (intern (concat "vh-" symbol)))
  8311. ;; Emacs has a bug where boundp on a buffer-local
  8312. ;; variable in only one buffer returns t in another.
  8313. ;; This can confuse, so check for nil.
  8314. (let ((val (eval (intern (concat "vh-" symbol)))))
  8315. (if (eq val nil)
  8316. (if wing-it symbol nil)
  8317. val))
  8318. (if wing-it symbol nil))))
  8319. symbol)
  8320. ;;(verilog-symbol-detick "`mod" nil)
  8321. (defun verilog-symbol-detick-denumber (symbol)
  8322. "Return SYMBOL with defines converted and any numbers dropped to nil."
  8323. (when (string-match "^`" symbol)
  8324. ;; This only will work if the define is a simple signal, not
  8325. ;; something like a[b]. Sorry, it should be substituted into the parser
  8326. (setq symbol
  8327. (verilog-string-replace-matches
  8328. "\[[^0-9: \t]+\]" "" nil nil
  8329. (or (verilog-symbol-detick symbol nil)
  8330. (if verilog-auto-sense-defines-constant
  8331. "0"
  8332. symbol)))))
  8333. (if (verilog-is-number symbol)
  8334. nil
  8335. symbol))
  8336. (defun verilog-symbol-detick-text (text)
  8337. "Return TEXT without any known defines.
  8338. If the variable vh-{symbol} is defined, substitute that value."
  8339. (let ((ok t) symbol val)
  8340. (while (and ok (string-match "`\\([a-zA-Z0-9_]+\\)" text))
  8341. (setq symbol (match-string 1 text))
  8342. ;;(message symbol)
  8343. (cond ((and
  8344. (boundp (intern (concat "vh-" symbol)))
  8345. ;; Emacs has a bug where boundp on a buffer-local
  8346. ;; variable in only one buffer returns t in another.
  8347. ;; This can confuse, so check for nil.
  8348. (setq val (eval (intern (concat "vh-" symbol)))))
  8349. (setq text (replace-match val nil nil text)))
  8350. (t (setq ok nil)))))
  8351. text)
  8352. ;;(progn (setq vh-mod "`foo" vh-foo "bar") (verilog-symbol-detick-text "bar `mod `undefed"))
  8353. (defun verilog-expand-dirnames (&optional dirnames)
  8354. "Return a list of existing directories given a list of wildcarded DIRNAMES.
  8355. Or, just the existing dirnames themselves if there are no wildcards."
  8356. ;; Note this function is performance critical.
  8357. ;; Do not call anything that requires disk access that cannot be cached.
  8358. (interactive)
  8359. (unless dirnames (error "`verilog-library-directories' should include at least '.'"))
  8360. (setq dirnames (reverse dirnames)) ; not nreverse
  8361. (let ((dirlist nil)
  8362. pattern dirfile dirfiles dirname root filename rest basefile)
  8363. (while dirnames
  8364. (setq dirname (substitute-in-file-name (car dirnames))
  8365. dirnames (cdr dirnames))
  8366. (cond ((string-match (concat "^\\(\\|[/\\]*[^*?]*[/\\]\\)" ;; root
  8367. "\\([^/\\]*[*?][^/\\]*\\)" ;; filename with *?
  8368. "\\(.*\\)") ;; rest
  8369. dirname)
  8370. (setq root (match-string 1 dirname)
  8371. filename (match-string 2 dirname)
  8372. rest (match-string 3 dirname)
  8373. pattern filename)
  8374. ;; now replace those * and ? with .+ and .
  8375. ;; use ^ and /> to get only whole file names
  8376. (setq pattern (verilog-string-replace-matches "[*]" ".+" nil nil pattern)
  8377. pattern (verilog-string-replace-matches "[?]" "." nil nil pattern)
  8378. pattern (concat "^" pattern "$")
  8379. dirfiles (verilog-dir-files root))
  8380. (while dirfiles
  8381. (setq basefile (car dirfiles)
  8382. dirfile (expand-file-name (concat root basefile rest))
  8383. dirfiles (cdr dirfiles))
  8384. (if (and (string-match pattern basefile)
  8385. ;; Don't allow abc/*/rtl to match abc/rtl via ..
  8386. (not (equal basefile "."))
  8387. (not (equal basefile ".."))
  8388. (file-directory-p dirfile))
  8389. (setq dirlist (cons dirfile dirlist)))))
  8390. ;; Defaults
  8391. (t
  8392. (if (file-directory-p dirname)
  8393. (setq dirlist (cons dirname dirlist))))))
  8394. dirlist))
  8395. ;;(verilog-expand-dirnames (list "." ".." "nonexist" "../*" "/home/wsnyder/*/v"))
  8396. (defun verilog-library-filenames (filename &optional current check-ext)
  8397. "Return a search path to find the given FILENAME or module name.
  8398. Uses the optional CURRENT filename or buffer-file-name, plus
  8399. `verilog-library-directories' and `verilog-library-extensions'
  8400. variables to build the path. With optional CHECK-EXT also check
  8401. `verilog-library-extensions'."
  8402. (unless current (setq current (buffer-file-name)))
  8403. (unless verilog-dir-cache-preserving
  8404. (setq verilog-dir-cache-lib-filenames nil))
  8405. (let* ((cache-key (list filename current check-ext))
  8406. (fass (assoc cache-key verilog-dir-cache-lib-filenames))
  8407. chkdirs chkdir chkexts fn outlist)
  8408. (cond (fass ;; Return data from cache hit
  8409. (nth 1 fass))
  8410. (t
  8411. ;; Note this expand can't be easily cached, as we need to
  8412. ;; pick up buffer-local variables for newly read sub-module files
  8413. (setq chkdirs (verilog-expand-dirnames verilog-library-directories))
  8414. (while chkdirs
  8415. (setq chkdir (expand-file-name (car chkdirs)
  8416. (file-name-directory current))
  8417. chkexts (if check-ext verilog-library-extensions `("")))
  8418. (while chkexts
  8419. (setq fn (expand-file-name (concat filename (car chkexts))
  8420. chkdir))
  8421. ;;(message "Check for %s" fn)
  8422. (if (verilog-dir-file-exists-p fn)
  8423. (setq outlist (cons (expand-file-name
  8424. fn (file-name-directory current))
  8425. outlist)))
  8426. (setq chkexts (cdr chkexts)))
  8427. (setq chkdirs (cdr chkdirs)))
  8428. (setq outlist (nreverse outlist))
  8429. (setq verilog-dir-cache-lib-filenames
  8430. (cons (list cache-key outlist)
  8431. verilog-dir-cache-lib-filenames))
  8432. outlist))))
  8433. (defun verilog-module-filenames (module current)
  8434. "Return a search path to find the given MODULE name.
  8435. Uses the CURRENT filename, `verilog-library-extensions',
  8436. `verilog-library-directories' and `verilog-library-files'
  8437. variables to build the path."
  8438. ;; Return search locations for it
  8439. (append (list current) ; first, current buffer
  8440. (verilog-library-filenames module current t)
  8441. verilog-library-files)) ; finally, any libraries
  8442. ;;
  8443. ;; Module Information
  8444. ;;
  8445. ;; Many of these functions work on "modi" a module information structure
  8446. ;; A modi is: [module-name-string file-name begin-point]
  8447. (defvar verilog-cache-enabled t
  8448. "If true, enable caching of signals, etc. Set to nil for debugging to make things SLOW!")
  8449. (defvar verilog-modi-cache-list nil
  8450. "Cache of ((Module Function) Buf-Tick Buf-Modtime Func-Returns)...
  8451. For speeding up verilog-modi-get-* commands.
  8452. Buffer-local.")
  8453. (make-variable-buffer-local 'verilog-modi-cache-list)
  8454. (defvar verilog-modi-cache-preserve-tick nil
  8455. "Modification tick after which the cache is still considered valid.
  8456. Use `verilog-preserve-modi-cache' to set it.")
  8457. (defvar verilog-modi-cache-preserve-buffer nil
  8458. "Modification tick after which the cache is still considered valid.
  8459. Use `verilog-preserve-modi-cache' to set it.")
  8460. (defvar verilog-modi-cache-current-enable nil
  8461. "If true, allow caching `verilog-modi-current', set by let().")
  8462. (defvar verilog-modi-cache-current nil
  8463. "Currently active `verilog-modi-current', if any, set by let().")
  8464. (defvar verilog-modi-cache-current-max nil
  8465. "Current endmodule point for `verilog-modi-cache-current', if any.")
  8466. (defun verilog-modi-current ()
  8467. "Return the modi structure for the module currently at point, possibly cached."
  8468. (cond ((and verilog-modi-cache-current
  8469. (>= (point) (verilog-modi-get-point verilog-modi-cache-current))
  8470. (<= (point) verilog-modi-cache-current-max))
  8471. ;; Slow assertion, for debugging the cache:
  8472. ;;(or (equal verilog-modi-cache-current (verilog-modi-current-get)) (debug))
  8473. verilog-modi-cache-current)
  8474. (verilog-modi-cache-current-enable
  8475. (setq verilog-modi-cache-current (verilog-modi-current-get)
  8476. verilog-modi-cache-current-max
  8477. ;; The cache expires when we pass "endmodule" as then the
  8478. ;; current modi may change to the next module
  8479. ;; This relies on the AUTOs generally inserting, not deleting text
  8480. (save-excursion
  8481. (verilog-re-search-forward-quick verilog-end-defun-re nil nil)))
  8482. verilog-modi-cache-current)
  8483. (t
  8484. (verilog-modi-current-get))))
  8485. (defun verilog-modi-current-get ()
  8486. "Return the modi structure for the module currently at point."
  8487. (let* (name type pt)
  8488. ;; read current module's name
  8489. (save-excursion
  8490. (verilog-re-search-backward-quick verilog-defun-re nil nil)
  8491. (setq type (match-string-no-properties 0))
  8492. (verilog-re-search-forward-quick "(" nil nil)
  8493. (setq name (verilog-read-module-name))
  8494. (setq pt (point)))
  8495. ;; return modi - note this vector built two places
  8496. (verilog-modi-new name (or (buffer-file-name) (current-buffer)) pt type)))
  8497. (defvar verilog-modi-lookup-cache nil "Hash of (modulename modi).")
  8498. (make-variable-buffer-local 'verilog-modi-lookup-cache)
  8499. (defvar verilog-modi-lookup-last-current nil "Cache of `current-buffer' at last lookup.")
  8500. (defvar verilog-modi-lookup-last-tick nil "Cache of `buffer-chars-modified-tick' at last lookup.")
  8501. (defun verilog-modi-lookup (module allow-cache &optional ignore-error)
  8502. "Find the file and point at which MODULE is defined.
  8503. If ALLOW-CACHE is set, check and remember cache of previous lookups.
  8504. Return modi if successful, else print message unless IGNORE-ERROR is true."
  8505. (let* ((current (or (buffer-file-name) (current-buffer)))
  8506. modi)
  8507. ;; Check cache
  8508. ;;(message "verilog-modi-lookup: %s" module)
  8509. (cond ((and verilog-modi-lookup-cache
  8510. verilog-cache-enabled
  8511. allow-cache
  8512. (setq modi (gethash module verilog-modi-lookup-cache))
  8513. (equal verilog-modi-lookup-last-current current)
  8514. ;; Iff hit is in current buffer, then tick must match
  8515. (or (equal verilog-modi-lookup-last-tick (buffer-chars-modified-tick))
  8516. (not (equal current (verilog-modi-file-or-buffer modi)))))
  8517. ;;(message "verilog-modi-lookup: HIT %S" modi)
  8518. modi)
  8519. ;; Miss
  8520. (t (let* ((realmod (verilog-symbol-detick module t))
  8521. (orig-filenames (verilog-module-filenames realmod current))
  8522. (filenames orig-filenames)
  8523. mif)
  8524. (while (and filenames (not mif))
  8525. (if (not (setq mif (verilog-module-inside-filename-p realmod (car filenames))))
  8526. (setq filenames (cdr filenames))))
  8527. ;; mif has correct form to become later elements of modi
  8528. (cond (mif (setq modi mif))
  8529. (t (setq modi nil)
  8530. (or ignore-error
  8531. (error (concat (verilog-point-text)
  8532. ": Can't locate " module " module definition"
  8533. (if (not (equal module realmod))
  8534. (concat " (Expanded macro to " realmod ")")
  8535. "")
  8536. "\n Check the verilog-library-directories variable."
  8537. "\n I looked in (if not listed, doesn't exist):\n\t"
  8538. (mapconcat 'concat orig-filenames "\n\t"))))))
  8539. (when (eval-when-compile (fboundp 'make-hash-table))
  8540. (unless verilog-modi-lookup-cache
  8541. (setq verilog-modi-lookup-cache
  8542. (make-hash-table :test 'equal :rehash-size 4.0)))
  8543. (puthash module modi verilog-modi-lookup-cache))
  8544. (setq verilog-modi-lookup-last-current current
  8545. verilog-modi-lookup-last-tick (buffer-chars-modified-tick)))))
  8546. modi))
  8547. (defun verilog-modi-filename (modi)
  8548. "Filename of MODI, or name of buffer if it's never been saved."
  8549. (if (bufferp (verilog-modi-file-or-buffer modi))
  8550. (or (buffer-file-name (verilog-modi-file-or-buffer modi))
  8551. (buffer-name (verilog-modi-file-or-buffer modi)))
  8552. (verilog-modi-file-or-buffer modi)))
  8553. (defun verilog-modi-goto (modi)
  8554. "Move point/buffer to specified MODI."
  8555. (or modi (error "Passed unfound modi to goto, check earlier"))
  8556. (set-buffer (if (bufferp (verilog-modi-file-or-buffer modi))
  8557. (verilog-modi-file-or-buffer modi)
  8558. (find-file-noselect (verilog-modi-file-or-buffer modi))))
  8559. (or (equal major-mode `verilog-mode) ;; Put into Verilog mode to get syntax
  8560. (verilog-mode))
  8561. (goto-char (verilog-modi-get-point modi)))
  8562. (defun verilog-goto-defun-file (module)
  8563. "Move point to the file at which a given MODULE is defined."
  8564. (interactive "sGoto File for Module: ")
  8565. (let* ((modi (verilog-modi-lookup module nil)))
  8566. (when modi
  8567. (verilog-modi-goto modi)
  8568. (switch-to-buffer (current-buffer)))))
  8569. (defun verilog-modi-cache-results (modi function)
  8570. "Run on MODI the given FUNCTION. Locate the module in a file.
  8571. Cache the output of function so next call may have faster access."
  8572. (let (fass)
  8573. (save-excursion ;; Cache is buffer-local so can't avoid this.
  8574. (verilog-modi-goto modi)
  8575. (if (and (setq fass (assoc (list modi function)
  8576. verilog-modi-cache-list))
  8577. ;; Destroy caching when incorrect; Modified or file changed
  8578. (not (and verilog-cache-enabled
  8579. (or (equal (buffer-chars-modified-tick) (nth 1 fass))
  8580. (and verilog-modi-cache-preserve-tick
  8581. (<= verilog-modi-cache-preserve-tick (nth 1 fass))
  8582. (equal verilog-modi-cache-preserve-buffer (current-buffer))))
  8583. (equal (visited-file-modtime) (nth 2 fass)))))
  8584. (setq verilog-modi-cache-list nil
  8585. fass nil))
  8586. (cond (fass
  8587. ;; Return data from cache hit
  8588. (nth 3 fass))
  8589. (t
  8590. ;; Read from file
  8591. ;; Clear then restore any highlighting to make emacs19 happy
  8592. (let ((fontlocked (when (and (boundp 'font-lock-mode)
  8593. font-lock-mode)
  8594. (font-lock-mode 0)
  8595. t))
  8596. func-returns)
  8597. (setq func-returns (funcall function))
  8598. (when fontlocked (font-lock-mode t))
  8599. ;; Cache for next time
  8600. (setq verilog-modi-cache-list
  8601. (cons (list (list modi function)
  8602. (buffer-chars-modified-tick)
  8603. (visited-file-modtime)
  8604. func-returns)
  8605. verilog-modi-cache-list))
  8606. func-returns))))))
  8607. (defun verilog-modi-cache-add (modi function element sig-list)
  8608. "Add function return results to the module cache.
  8609. Update MODI's cache for given FUNCTION so that the return ELEMENT of that
  8610. function now contains the additional SIG-LIST parameters."
  8611. (let (fass)
  8612. (save-excursion
  8613. (verilog-modi-goto modi)
  8614. (if (setq fass (assoc (list modi function)
  8615. verilog-modi-cache-list))
  8616. (let ((func-returns (nth 3 fass)))
  8617. (aset func-returns element
  8618. (append sig-list (aref func-returns element))))))))
  8619. (defmacro verilog-preserve-modi-cache (&rest body)
  8620. "Execute the BODY forms, allowing cache preservation within BODY.
  8621. This means that changes to the buffer will not result in the cache being
  8622. flushed. If the changes affect the modsig state, they must call the
  8623. modsig-cache-add-* function, else the results of later calls may be
  8624. incorrect. Without this, changes are assumed to be adding/removing signals
  8625. and invalidating the cache."
  8626. `(let ((verilog-modi-cache-preserve-tick (buffer-chars-modified-tick))
  8627. (verilog-modi-cache-preserve-buffer (current-buffer)))
  8628. (progn ,@body)))
  8629. (defun verilog-signals-matching-enum (in-list enum)
  8630. "Return all signals in IN-LIST matching the given ENUM."
  8631. (let (out-list)
  8632. (while in-list
  8633. (if (equal (verilog-sig-enum (car in-list)) enum)
  8634. (setq out-list (cons (car in-list) out-list)))
  8635. (setq in-list (cdr in-list)))
  8636. ;; New scheme
  8637. (let* ((enumvar (intern (concat "venum-" enum)))
  8638. (enumlist (and (boundp enumvar) (eval enumvar))))
  8639. (while enumlist
  8640. (add-to-list 'out-list (list (car enumlist)))
  8641. (setq enumlist (cdr enumlist))))
  8642. (nreverse out-list)))
  8643. (defun verilog-signals-matching-regexp (in-list regexp)
  8644. "Return all signals in IN-LIST matching the given REGEXP, if non-nil."
  8645. (if (or (not regexp) (equal regexp ""))
  8646. in-list
  8647. (let (out-list)
  8648. (while in-list
  8649. (if (string-match regexp (verilog-sig-name (car in-list)))
  8650. (setq out-list (cons (car in-list) out-list)))
  8651. (setq in-list (cdr in-list)))
  8652. (nreverse out-list))))
  8653. (defun verilog-signals-not-matching-regexp (in-list regexp)
  8654. "Return all signals in IN-LIST not matching the given REGEXP, if non-nil."
  8655. (if (or (not regexp) (equal regexp ""))
  8656. in-list
  8657. (let (out-list)
  8658. (while in-list
  8659. (if (not (string-match regexp (verilog-sig-name (car in-list))))
  8660. (setq out-list (cons (car in-list) out-list)))
  8661. (setq in-list (cdr in-list)))
  8662. (nreverse out-list))))
  8663. (defun verilog-signals-matching-dir-re (in-list decl-type regexp)
  8664. "Return all signals in IN-LIST matching the given DECL-TYPE and REGEXP,
  8665. if non-nil."
  8666. (if (or (not regexp) (equal regexp ""))
  8667. in-list
  8668. (let (out-list to-match)
  8669. (while in-list
  8670. ;; Note verilog-insert-one-definition matches on this order
  8671. (setq to-match (concat
  8672. decl-type
  8673. " " (verilog-sig-signed (car in-list))
  8674. " " (verilog-sig-multidim (car in-list))
  8675. (verilog-sig-bits (car in-list))))
  8676. (if (string-match regexp to-match)
  8677. (setq out-list (cons (car in-list) out-list)))
  8678. (setq in-list (cdr in-list)))
  8679. (nreverse out-list))))
  8680. ;; Combined
  8681. (defun verilog-decls-get-signals (decls)
  8682. "Return all declared signals, excluding 'assign' statements."
  8683. (append
  8684. (verilog-decls-get-outputs decls)
  8685. (verilog-decls-get-inouts decls)
  8686. (verilog-decls-get-inputs decls)
  8687. (verilog-decls-get-vars decls)
  8688. (verilog-decls-get-consts decls)
  8689. (verilog-decls-get-gparams decls)))
  8690. (defun verilog-decls-get-ports (decls)
  8691. (append
  8692. (verilog-decls-get-outputs decls)
  8693. (verilog-decls-get-inouts decls)
  8694. (verilog-decls-get-inputs decls)))
  8695. (defsubst verilog-modi-cache-add-outputs (modi sig-list)
  8696. (verilog-modi-cache-add modi 'verilog-read-decls 0 sig-list))
  8697. (defsubst verilog-modi-cache-add-inouts (modi sig-list)
  8698. (verilog-modi-cache-add modi 'verilog-read-decls 1 sig-list))
  8699. (defsubst verilog-modi-cache-add-inputs (modi sig-list)
  8700. (verilog-modi-cache-add modi 'verilog-read-decls 2 sig-list))
  8701. (defsubst verilog-modi-cache-add-vars (modi sig-list)
  8702. (verilog-modi-cache-add modi 'verilog-read-decls 3 sig-list))
  8703. (defun verilog-signals-from-signame (signame-list)
  8704. "Return signals in standard form from SIGNAME-LIST, a simple list of signal names."
  8705. (mapcar (function (lambda (name) (list name nil nil)))
  8706. signame-list))
  8707. ;;
  8708. ;; Auto creation utilities
  8709. ;;
  8710. (defun verilog-auto-re-search-do (search-for func)
  8711. "Search for the given auto text regexp SEARCH-FOR, and perform FUNC where it occurs."
  8712. (goto-char (point-min))
  8713. (while (verilog-re-search-forward-quick search-for nil t)
  8714. (funcall func)))
  8715. (defun verilog-insert-one-definition (sig type indent-pt)
  8716. "Print out a definition for SIG of the given TYPE,
  8717. with appropriate INDENT-PT indentation."
  8718. (indent-to indent-pt)
  8719. ;; Note verilog-signals-matching-dir-re matches on this order
  8720. (insert type)
  8721. (when (verilog-sig-modport sig)
  8722. (insert "." (verilog-sig-modport sig)))
  8723. (when (verilog-sig-signed sig)
  8724. (insert " " (verilog-sig-signed sig)))
  8725. (when (verilog-sig-multidim sig)
  8726. (insert " " (verilog-sig-multidim-string sig)))
  8727. (when (verilog-sig-bits sig)
  8728. (insert " " (verilog-sig-bits sig)))
  8729. (indent-to (max 24 (+ indent-pt 16)))
  8730. (unless (= (char-syntax (preceding-char)) ?\ )
  8731. (insert " ")) ; Need space between "]name" if indent-to did nothing
  8732. (insert (verilog-sig-name sig))
  8733. (when (verilog-sig-memory sig)
  8734. (insert " " (verilog-sig-memory sig))))
  8735. (defun verilog-insert-definition (modi sigs direction indent-pt v2k &optional dont-sort)
  8736. "Print out a definition for MODI's list of SIGS of the given DIRECTION,
  8737. with appropriate INDENT-PT indentation. If V2K, use Verilog 2001 I/O
  8738. format. Sort unless DONT-SORT. DIRECTION is normally wire/reg/output.
  8739. When MODI is non-null, also add to modi-cache, for tracking."
  8740. (when modi
  8741. (cond ((equal direction "wire")
  8742. (verilog-modi-cache-add-vars modi sigs))
  8743. ((equal direction "reg")
  8744. (verilog-modi-cache-add-vars modi sigs))
  8745. ((equal direction "output")
  8746. (verilog-modi-cache-add-outputs modi sigs)
  8747. (when verilog-auto-declare-nettype
  8748. (verilog-modi-cache-add-vars modi sigs)))
  8749. ((equal direction "input")
  8750. (verilog-modi-cache-add-inputs modi sigs)
  8751. (when verilog-auto-declare-nettype
  8752. (verilog-modi-cache-add-vars modi sigs)))
  8753. ((equal direction "inout")
  8754. (verilog-modi-cache-add-inouts modi sigs)
  8755. (when verilog-auto-declare-nettype
  8756. (verilog-modi-cache-add-vars modi sigs)))
  8757. ((equal direction "interface"))
  8758. (t
  8759. (error "Unsupported verilog-insert-definition direction: %s" direction))))
  8760. (or dont-sort
  8761. (setq sigs (sort (copy-alist sigs) `verilog-signals-sort-compare)))
  8762. (while sigs
  8763. (let ((sig (car sigs)))
  8764. (verilog-insert-one-definition
  8765. sig
  8766. ;; Want "type x" or "output type x", not "wire type x"
  8767. (cond ((or (verilog-sig-type sig)
  8768. verilog-auto-wire-type)
  8769. (concat
  8770. (when (member direction '("input" "output" "inout"))
  8771. (concat direction " "))
  8772. (or (verilog-sig-type sig)
  8773. verilog-auto-wire-type)))
  8774. ((and verilog-auto-declare-nettype
  8775. (member direction '("input" "output" "inout")))
  8776. (concat direction " " verilog-auto-declare-nettype))
  8777. (t
  8778. direction))
  8779. indent-pt)
  8780. (insert (if v2k "," ";"))
  8781. (if (or (not (verilog-sig-comment sig))
  8782. (equal "" (verilog-sig-comment sig)))
  8783. (insert "\n")
  8784. (indent-to (max 48 (+ indent-pt 40)))
  8785. (verilog-insert "// " (verilog-sig-comment sig) "\n"))
  8786. (setq sigs (cdr sigs)))))
  8787. (eval-when-compile
  8788. (if (not (boundp 'indent-pt))
  8789. (defvar indent-pt nil "Local used by insert-indent")))
  8790. (defun verilog-insert-indent (&rest stuff)
  8791. "Indent to position stored in local `indent-pt' variable, then insert STUFF.
  8792. Presumes that any newlines end a list element."
  8793. (let ((need-indent t))
  8794. (while stuff
  8795. (if need-indent (indent-to indent-pt))
  8796. (setq need-indent nil)
  8797. (verilog-insert (car stuff))
  8798. (setq need-indent (string-match "\n$" (car stuff))
  8799. stuff (cdr stuff)))))
  8800. ;;(let ((indent-pt 10)) (verilog-insert-indent "hello\n" "addon" "there\n"))
  8801. (defun verilog-repair-open-comma ()
  8802. "Insert comma if previous argument is other than a open parenthesis or endif."
  8803. ;; We can't just search backward for ) as it might be inside another expression.
  8804. ;; Also want "`ifdef X input foo `endif" to just leave things to the human to deal with
  8805. (save-excursion
  8806. (verilog-backward-syntactic-ws-quick)
  8807. (when (and (not (save-excursion ;; Not beginning (, or existing ,
  8808. (backward-char 1)
  8809. (looking-at "[(,]")))
  8810. (not (save-excursion ;; Not `endif, or user define
  8811. (backward-char 1)
  8812. (skip-chars-backward "[a-zA-Z0-9_`]")
  8813. (looking-at "`"))))
  8814. (insert ","))))
  8815. (defun verilog-repair-close-comma ()
  8816. "If point is at a comma followed by a close parenthesis, fix it.
  8817. This repairs those mis-inserted by a AUTOARG."
  8818. ;; It would be much nicer if Verilog allowed extra commas like Perl does!
  8819. (save-excursion
  8820. (verilog-forward-close-paren)
  8821. (backward-char 1)
  8822. (verilog-backward-syntactic-ws-quick)
  8823. (backward-char 1)
  8824. (when (looking-at ",")
  8825. (delete-char 1))))
  8826. (defun verilog-get-list (start end)
  8827. "Return the elements of a comma separated list between START and END."
  8828. (interactive)
  8829. (let ((my-list (list))
  8830. my-string)
  8831. (save-excursion
  8832. (while (< (point) end)
  8833. (when (re-search-forward "\\([^,{]+\\)" end t)
  8834. (setq my-string (verilog-string-remove-spaces (match-string 1)))
  8835. (setq my-list (nconc my-list (list my-string) ))
  8836. (goto-char (match-end 0))))
  8837. my-list)))
  8838. (defun verilog-make-width-expression (range-exp)
  8839. "Return an expression calculating the length of a range [x:y] in RANGE-EXP."
  8840. ;; strip off the []
  8841. (cond ((not range-exp)
  8842. "1")
  8843. (t
  8844. (if (string-match "^\\[\\(.*\\)\\]$" range-exp)
  8845. (setq range-exp (match-string 1 range-exp)))
  8846. (cond ((not range-exp)
  8847. "1")
  8848. ;; [#:#] We can compute a numeric result
  8849. ((string-match "^\\s *\\([0-9]+\\)\\s *:\\s *\\([0-9]+\\)\\s *$"
  8850. range-exp)
  8851. (int-to-string
  8852. (1+ (abs (- (string-to-number (match-string 1 range-exp))
  8853. (string-to-number (match-string 2 range-exp)))))))
  8854. ;; [PARAM-1:0] can just return PARAM
  8855. ((string-match "^\\s *\\([a-zA-Z_][a-zA-Z0-9_]*\\)\\s *-\\s *1\\s *:\\s *0\\s *$" range-exp)
  8856. (match-string 1 range-exp))
  8857. ;; [arbitrary] need math
  8858. ((string-match "^\\(.*\\)\\s *:\\s *\\(.*\\)\\s *$" range-exp)
  8859. (concat "(1+(" (match-string 1 range-exp) ")"
  8860. (if (equal "0" (match-string 2 range-exp))
  8861. "" ;; Don't bother with -(0)
  8862. (concat "-(" (match-string 2 range-exp) ")"))
  8863. ")"))
  8864. (t nil)))))
  8865. ;;(verilog-make-width-expression "`A:`B")
  8866. (defun verilog-simplify-range-expression (expr)
  8867. "Return a simplified range expression with constants eliminated from EXPR."
  8868. ;; Note this is always called with brackets; ie [z] or [z:z]
  8869. (if (not (string-match "[---+*()]" expr))
  8870. expr ;; short-circuit
  8871. (let ((out expr)
  8872. (last-pass ""))
  8873. (while (not (equal last-pass out))
  8874. (setq last-pass out)
  8875. ;; Prefix regexp needs beginning of match, or some symbol of
  8876. ;; lesser or equal precedence. We assume the [:]'s exist in expr.
  8877. ;; Ditto the end.
  8878. (while (string-match
  8879. (concat "\\([[({:*+-]\\)" ; - must be last
  8880. "(\\<\\([0-9A-Za-z_]+\\))"
  8881. "\\([])}:*+-]\\)")
  8882. out)
  8883. (setq out (replace-match "\\1\\2\\3" nil nil out)))
  8884. ;; For precedence do * before +/-
  8885. (while (string-match
  8886. (concat "\\([[({:*+-]\\)"
  8887. "\\([0-9]+\\)\\s *\\([*]\\)\\s *\\([0-9]+\\)"
  8888. "\\([])}:*+-]\\)")
  8889. out)
  8890. (setq out (replace-match
  8891. (concat (match-string 1 out)
  8892. (int-to-string (* (string-to-number (match-string 2 out))
  8893. (string-to-number (match-string 4 out))))
  8894. (match-string 5 out))
  8895. nil nil out)))
  8896. (while (string-match
  8897. (concat "\\([[({:+-]\\)" ; No * here as higher prec
  8898. "\\([0-9]+\\)\\s *\\([---+]\\)\\s *\\([0-9]+\\)"
  8899. "\\([])}:+-]\\)")
  8900. out)
  8901. (let ((pre (match-string 1 out))
  8902. (lhs (string-to-number (match-string 2 out)))
  8903. (rhs (string-to-number (match-string 4 out)))
  8904. (post (match-string 5 out))
  8905. val)
  8906. (when (equal pre "-")
  8907. (setq lhs (- lhs)))
  8908. (setq val (if (equal (match-string 3 out) "-")
  8909. (- lhs rhs)
  8910. (+ lhs rhs))
  8911. out (replace-match
  8912. (concat (if (and (equal pre "-")
  8913. (< val 0))
  8914. "" ;; Not "--20" but just "-20"
  8915. pre)
  8916. (int-to-string val)
  8917. post)
  8918. nil nil out)) )))
  8919. out)))
  8920. ;;(verilog-simplify-range-expression "[1:3]") ;; 1
  8921. ;;(verilog-simplify-range-expression "[(1):3]") ;; 1
  8922. ;;(verilog-simplify-range-expression "[(((16)+1)+1+(1+1))]") ;;20
  8923. ;;(verilog-simplify-range-expression "[(2*3+6*7)]") ;; 48
  8924. ;;(verilog-simplify-range-expression "[(FOO*4-1*2)]") ;; FOO*4-2
  8925. ;;(verilog-simplify-range-expression "[(FOO*4+1-1)]") ;; FOO*4+0
  8926. ;;(verilog-simplify-range-expression "[(func(BAR))]") ;; func(BAR)
  8927. ;;(verilog-simplify-range-expression "[FOO-1+1-1+1]") ;; FOO-0
  8928. (defun verilog-typedef-name-p (variable-name)
  8929. "Return true if the VARIABLE-NAME is a type definition."
  8930. (when verilog-typedef-regexp
  8931. (string-match verilog-typedef-regexp variable-name)))
  8932. ;;
  8933. ;; Auto deletion
  8934. ;;
  8935. (defun verilog-delete-autos-lined ()
  8936. "Delete autos that occupy multiple lines, between begin and end comments."
  8937. ;; The newline must not have a comment property, so we must
  8938. ;; delete the end auto's newline, not the first newline
  8939. (forward-line 1)
  8940. (let ((pt (point)))
  8941. (when (and
  8942. (looking-at "\\s-*// Beginning")
  8943. (search-forward "// End of automatic" nil t))
  8944. ;; End exists
  8945. (end-of-line)
  8946. (forward-line 1)
  8947. (delete-region pt (point)))))
  8948. (defun verilog-delete-empty-auto-pair ()
  8949. "Delete begin/end auto pair at point, if empty."
  8950. (forward-line 0)
  8951. (when (looking-at (concat "\\s-*// Beginning of automatic.*\n"
  8952. "\\s-*// End of automatics\n"))
  8953. (delete-region (point) (save-excursion (forward-line 2) (point)))))
  8954. (defun verilog-forward-close-paren ()
  8955. "Find the close parenthesis that match the current point.
  8956. Ignore other close parenthesis with matching open parens."
  8957. (let ((parens 1))
  8958. (while (> parens 0)
  8959. (unless (verilog-re-search-forward-quick "[()]" nil t)
  8960. (error "%s: Mismatching ()" (verilog-point-text)))
  8961. (cond ((= (preceding-char) ?\( )
  8962. (setq parens (1+ parens)))
  8963. ((= (preceding-char) ?\) )
  8964. (setq parens (1- parens)))))))
  8965. (defun verilog-backward-open-paren ()
  8966. "Find the open parenthesis that match the current point.
  8967. Ignore other open parenthesis with matching close parens."
  8968. (let ((parens 1))
  8969. (while (> parens 0)
  8970. (unless (verilog-re-search-backward-quick "[()]" nil t)
  8971. (error "%s: Mismatching ()" (verilog-point-text)))
  8972. (cond ((= (following-char) ?\) )
  8973. (setq parens (1+ parens)))
  8974. ((= (following-char) ?\( )
  8975. (setq parens (1- parens)))))))
  8976. (defun verilog-backward-open-bracket ()
  8977. "Find the open bracket that match the current point.
  8978. Ignore other open bracket with matching close bracket."
  8979. (let ((parens 1))
  8980. (while (> parens 0)
  8981. (unless (verilog-re-search-backward-quick "[][]" nil t)
  8982. (error "%s: Mismatching []" (verilog-point-text)))
  8983. (cond ((= (following-char) ?\] )
  8984. (setq parens (1+ parens)))
  8985. ((= (following-char) ?\[ )
  8986. (setq parens (1- parens)))))))
  8987. (defun verilog-delete-to-paren ()
  8988. "Delete the automatic inst/sense/arg created by autos.
  8989. Deletion stops at the matching end parenthesis, outside comments."
  8990. (delete-region (point)
  8991. (save-excursion
  8992. (verilog-backward-open-paren)
  8993. (verilog-forward-sexp-ign-cmt 1) ;; Moves to paren that closes argdecl's
  8994. (backward-char 1)
  8995. (point))))
  8996. (defun verilog-auto-star-safe ()
  8997. "Return if a .* AUTOINST is safe to delete or expand.
  8998. It was created by the AUTOS themselves, or by the user."
  8999. (and verilog-auto-star-expand
  9000. (looking-at
  9001. (concat "[ \t\n\f,]*\\([)]\\|// " verilog-inst-comment-re "\\)"))))
  9002. (defun verilog-delete-auto-star-all ()
  9003. "Delete a .* AUTOINST, if it is safe."
  9004. (when (verilog-auto-star-safe)
  9005. (verilog-delete-to-paren)))
  9006. (defun verilog-delete-auto-star-implicit ()
  9007. "Delete all .* implicit connections created by `verilog-auto-star'.
  9008. This function will be called automatically at save unless
  9009. `verilog-auto-star-save' is set, any non-templated expanded pins will be
  9010. removed."
  9011. (interactive)
  9012. (let (paren-pt indent have-close-paren)
  9013. (save-excursion
  9014. (goto-char (point-min))
  9015. ;; We need to match these even outside of comments.
  9016. ;; For reasonable performance, we don't check if inside comments, sorry.
  9017. (while (re-search-forward "// Implicit \\.\\*" nil t)
  9018. (setq paren-pt (point))
  9019. (beginning-of-line)
  9020. (setq have-close-paren
  9021. (save-excursion
  9022. (when (search-forward ");" paren-pt t)
  9023. (setq indent (current-indentation))
  9024. t)))
  9025. (delete-region (point) (+ 1 paren-pt)) ; Nuke line incl CR
  9026. (when have-close-paren
  9027. ;; Delete extra commentary
  9028. (save-excursion
  9029. (while (progn
  9030. (forward-line -1)
  9031. (looking-at (concat "\\s *//\\s *" verilog-inst-comment-re "\n")))
  9032. (delete-region (match-beginning 0) (match-end 0))))
  9033. ;; If it is simple, we can put the ); on the same line as the last text
  9034. (let ((rtn-pt (point)))
  9035. (save-excursion
  9036. (while (progn (backward-char 1)
  9037. (looking-at "[ \t\n\f]")))
  9038. (when (looking-at ",")
  9039. (delete-region (+ 1 (point)) rtn-pt))))
  9040. (when (bolp)
  9041. (indent-to indent))
  9042. (insert ");\n")
  9043. ;; Still need to kill final comma - always is one as we put one after the .*
  9044. (re-search-backward ",")
  9045. (delete-char 1))))))
  9046. (defun verilog-delete-auto ()
  9047. "Delete the automatic outputs, regs, and wires created by \\[verilog-auto].
  9048. Use \\[verilog-auto] to re-insert the updated AUTOs.
  9049. The hooks `verilog-before-delete-auto-hook' and `verilog-delete-auto-hook' are
  9050. called before and after this function, respectively."
  9051. (interactive)
  9052. (save-excursion
  9053. (if (buffer-file-name)
  9054. (find-file-noselect (buffer-file-name))) ;; To check we have latest version
  9055. (verilog-save-no-change-functions
  9056. (verilog-save-scan-cache
  9057. ;; Allow user to customize
  9058. (verilog-run-hooks 'verilog-before-delete-auto-hook)
  9059. ;; Remove those that have multi-line insertions, possibly with parameters
  9060. ;; We allow anything beginning with AUTO, so that users can add their own
  9061. ;; patterns
  9062. (verilog-auto-re-search-do
  9063. (concat "/\\*AUTO[A-Za-z0-9_]+"
  9064. ;; Optional parens or quoted parameter or .* for (((...)))
  9065. "\\(\\|([^)]*)\\|(\"[^\"]*\")\\).*?"
  9066. "\\*/")
  9067. 'verilog-delete-autos-lined)
  9068. ;; Remove those that are in parenthesis
  9069. (verilog-auto-re-search-do
  9070. (concat "/\\*"
  9071. (eval-when-compile
  9072. (verilog-regexp-words
  9073. `("AS" "AUTOARG" "AUTOCONCATWIDTH" "AUTOINST" "AUTOINSTPARAM"
  9074. "AUTOSENSE")))
  9075. "\\*/")
  9076. 'verilog-delete-to-paren)
  9077. ;; Do .* instantiations, but avoid removing any user pins by looking for our magic comments
  9078. (verilog-auto-re-search-do "\\.\\*"
  9079. 'verilog-delete-auto-star-all)
  9080. ;; Remove template comments ... anywhere in case was pasted after AUTOINST removed
  9081. (goto-char (point-min))
  9082. (while (re-search-forward "\\s-*// \\(Templated\\|Implicit \\.\\*\\)\\([ \tLT0-9]*\\| LHS: .*\\)?$" nil t)
  9083. (replace-match ""))
  9084. ;; Final customize
  9085. (verilog-run-hooks 'verilog-delete-auto-hook)))))
  9086. ;;
  9087. ;; Auto inject
  9088. ;;
  9089. (defun verilog-inject-auto ()
  9090. "Examine legacy non-AUTO code and insert AUTOs in appropriate places.
  9091. Any always @ blocks with sensitivity lists that match computed lists will
  9092. be replaced with /*AS*/ comments.
  9093. Any cells will get /*AUTOINST*/ added to the end of the pin list.
  9094. Pins with have identical names will be deleted.
  9095. Argument lists will not be deleted, /*AUTOARG*/ will only be inserted to
  9096. support adding new ports. You may wish to delete older ports yourself.
  9097. For example:
  9098. module ExampInject (i, o);
  9099. input i;
  9100. input j;
  9101. output o;
  9102. always @ (i or j)
  9103. o = i | j;
  9104. InstModule instName
  9105. (.foobar(baz),
  9106. j(j));
  9107. endmodule
  9108. Typing \\[verilog-inject-auto] will make this into:
  9109. module ExampInject (i, o/*AUTOARG*/
  9110. // Inputs
  9111. j);
  9112. input i;
  9113. output o;
  9114. always @ (/*AS*/i or j)
  9115. o = i | j;
  9116. InstModule instName
  9117. (.foobar(baz),
  9118. /*AUTOINST*/
  9119. // Outputs
  9120. j(j));
  9121. endmodule"
  9122. (interactive)
  9123. (verilog-auto t))
  9124. (defun verilog-inject-arg ()
  9125. "Inject AUTOARG into new code. See `verilog-inject-auto'."
  9126. ;; Presume one module per file.
  9127. (save-excursion
  9128. (goto-char (point-min))
  9129. (while (verilog-re-search-forward-quick "\\<module\\>" nil t)
  9130. (let ((endmodp (save-excursion
  9131. (verilog-re-search-forward-quick "\\<endmodule\\>" nil t)
  9132. (point))))
  9133. ;; See if there's already a comment .. inside a comment so not verilog-re-search
  9134. (when (not (re-search-forward "/\\*AUTOARG\\*/" endmodp t))
  9135. (verilog-re-search-forward-quick ";" nil t)
  9136. (backward-char 1)
  9137. (verilog-backward-syntactic-ws-quick)
  9138. (backward-char 1) ; Moves to paren that closes argdecl's
  9139. (when (looking-at ")")
  9140. (verilog-insert "/*AUTOARG*/")))))))
  9141. (defun verilog-inject-sense ()
  9142. "Inject AUTOSENSE into new code. See `verilog-inject-auto'."
  9143. (save-excursion
  9144. (goto-char (point-min))
  9145. (while (verilog-re-search-forward-quick "\\<always\\s *@\\s *(" nil t)
  9146. (let* ((start-pt (point))
  9147. (modi (verilog-modi-current))
  9148. (moddecls (verilog-modi-get-decls modi))
  9149. pre-sigs
  9150. got-sigs)
  9151. (backward-char 1)
  9152. (verilog-forward-sexp-ign-cmt 1)
  9153. (backward-char 1) ;; End )
  9154. (when (not (verilog-re-search-backward-quick "/\\*\\(AUTOSENSE\\|AS\\)\\*/" start-pt t))
  9155. (setq pre-sigs (verilog-signals-from-signame
  9156. (verilog-read-signals start-pt (point)))
  9157. got-sigs (verilog-auto-sense-sigs moddecls nil))
  9158. (when (not (or (verilog-signals-not-in pre-sigs got-sigs) ; Both are equal?
  9159. (verilog-signals-not-in got-sigs pre-sigs)))
  9160. (delete-region start-pt (point))
  9161. (verilog-insert "/*AS*/")))))))
  9162. (defun verilog-inject-inst ()
  9163. "Inject AUTOINST into new code. See `verilog-inject-auto'."
  9164. (save-excursion
  9165. (goto-char (point-min))
  9166. ;; It's hard to distinguish modules; we'll instead search for pins.
  9167. (while (verilog-re-search-forward-quick "\\.\\s *[a-zA-Z0-9`_\$]+\\s *(\\s *[a-zA-Z0-9`_\$]+\\s *)" nil t)
  9168. (verilog-backward-open-paren) ;; Inst start
  9169. (cond
  9170. ((= (preceding-char) ?\#) ;; #(...) parameter section, not pin. Skip.
  9171. (forward-char 1)
  9172. (verilog-forward-close-paren)) ;; Parameters done
  9173. (t
  9174. (forward-char 1)
  9175. (let ((indent-pt (+ (current-column)))
  9176. (end-pt (save-excursion (verilog-forward-close-paren) (point))))
  9177. (cond ((verilog-re-search-forward-quick "\\(/\\*AUTOINST\\*/\\|\\.\\*\\)" end-pt t)
  9178. (goto-char end-pt)) ;; Already there, continue search with next instance
  9179. (t
  9180. ;; Delete identical interconnect
  9181. (let ((case-fold-search nil)) ;; So we don't convert upper-to-lower, etc
  9182. (while (verilog-re-search-forward-quick "\\.\\s *\\([a-zA-Z0-9`_\$]+\\)*\\s *(\\s *\\1\\s *)\\s *" end-pt t)
  9183. (delete-region (match-beginning 0) (match-end 0))
  9184. (setq end-pt (- end-pt (- (match-end 0) (match-beginning 0)))) ;; Keep it correct
  9185. (while (or (looking-at "[ \t\n\f,]+")
  9186. (looking-at "//[^\n]*"))
  9187. (delete-region (match-beginning 0) (match-end 0))
  9188. (setq end-pt (- end-pt (- (match-end 0) (match-beginning 0)))))))
  9189. (verilog-forward-close-paren)
  9190. (backward-char 1)
  9191. ;; Not verilog-re-search, as we don't want to strip comments
  9192. (while (re-search-backward "[ \t\n\f]+" (- (point) 1) t)
  9193. (delete-region (match-beginning 0) (match-end 0)))
  9194. (verilog-insert "\n")
  9195. (verilog-insert-indent "/*AUTOINST*/")))))))))
  9196. ;;
  9197. ;; Auto diff
  9198. ;;
  9199. (defun verilog-diff-buffers-p (b1 b2 &optional whitespace)
  9200. "Return nil if buffers B1 and B2 have same contents.
  9201. Else, return point in B1 that first mismatches.
  9202. If optional WHITESPACE true, ignore whitespace."
  9203. (save-excursion
  9204. (let* ((case-fold-search nil) ;; compare-buffer-substrings cares
  9205. (p1 (with-current-buffer b1 (goto-char (point-min))))
  9206. (p2 (with-current-buffer b2 (goto-char (point-min))))
  9207. (maxp1 (with-current-buffer b1 (point-max)))
  9208. (maxp2 (with-current-buffer b2 (point-max)))
  9209. (op1 -1) (op2 -1)
  9210. progress size)
  9211. (while (not (and (eq p1 op1) (eq p2 op2)))
  9212. ;; If both windows have whitespace optionally skip over it.
  9213. (when whitespace
  9214. ;; skip-syntax-* doesn't count \n
  9215. (with-current-buffer b1
  9216. (goto-char p1)
  9217. (skip-chars-forward " \t\n\r\f\v")
  9218. (setq p1 (point)))
  9219. (with-current-buffer b2
  9220. (goto-char p2)
  9221. (skip-chars-forward " \t\n\r\f\v")
  9222. (setq p2 (point))))
  9223. (setq size (min (- maxp1 p1) (- maxp2 p2)))
  9224. (setq progress (compare-buffer-substrings b2 p2 (+ size p2)
  9225. b1 p1 (+ size p1)))
  9226. (setq progress (if (zerop progress) size (1- (abs progress))))
  9227. (setq op1 p1 op2 p2
  9228. p1 (+ p1 progress)
  9229. p2 (+ p2 progress)))
  9230. ;; Return value
  9231. (if (and (eq p1 maxp1) (eq p2 maxp2))
  9232. nil p1))))
  9233. (defun verilog-diff-file-with-buffer (f1 b2 &optional whitespace show)
  9234. "View the differences between file F1 and buffer B2.
  9235. This requires the external program `diff-command' to be in your `exec-path',
  9236. and uses `diff-switches' in which you may want to have \"-u\" flag.
  9237. Ignores WHITESPACE if t, and writes output to stdout if SHOW."
  9238. ;; Similar to `diff-buffer-with-file' but works on XEmacs, and doesn't
  9239. ;; call `diff' as `diff' has different calling semantics on different
  9240. ;; versions of Emacs.
  9241. (if (not (file-exists-p f1))
  9242. (message "Buffer %s has no associated file on disc" (buffer-name b2))
  9243. (with-temp-buffer "*Verilog-Diff*"
  9244. (let ((outbuf (current-buffer))
  9245. (f2 (make-temp-file "vm-diff-auto-")))
  9246. (unwind-protect
  9247. (progn
  9248. (with-current-buffer b2
  9249. (save-restriction
  9250. (widen)
  9251. (write-region (point-min) (point-max) f2 nil 'nomessage)))
  9252. (call-process diff-command nil outbuf t
  9253. diff-switches ;; User may want -u in diff-switches
  9254. (if whitespace "-b" "")
  9255. f1 f2)
  9256. ;; Print out results. Alternatively we could have call-processed
  9257. ;; ourself, but this way we can reuse diff switches
  9258. (when show
  9259. (with-current-buffer outbuf (message "%s" (buffer-string))))))
  9260. (sit-for 0)
  9261. (when (file-exists-p f2)
  9262. (delete-file f2))))))
  9263. (defun verilog-diff-report (b1 b2 diffpt)
  9264. "Report differences detected with `verilog-diff-auto'.
  9265. Differences are between buffers B1 and B2, starting at point
  9266. DIFFPT. This function is called via `verilog-diff-function'."
  9267. (let ((name1 (with-current-buffer b1 (buffer-file-name))))
  9268. (message "%%Warning: %s:%d: Difference in AUTO expansion found"
  9269. name1 (with-current-buffer b1 (1+ (count-lines (point-min) (point)))))
  9270. (cond (noninteractive
  9271. (verilog-diff-file-with-buffer name1 b2 t t))
  9272. (t
  9273. (ediff-buffers b1 b2)))))
  9274. (defun verilog-diff-auto ()
  9275. "Expand AUTOs in a temporary buffer and indicate any changes.
  9276. Whitespace differences are ignored to determine identicalness, but
  9277. once a difference is detected, whitespace differences may be shown.
  9278. To call this from the command line, see \\[verilog-batch-diff-auto].
  9279. The action on differences is selected with
  9280. `verilog-diff-function'. The default is `verilog-diff-report'
  9281. which will report an error and run `ediff' in interactive mode,
  9282. or `diff' in batch mode."
  9283. (interactive)
  9284. (let ((b1 (current-buffer)) b2 diffpt
  9285. (name1 (buffer-file-name))
  9286. (newname "*Verilog-Diff*"))
  9287. (save-excursion
  9288. (when (get-buffer newname)
  9289. (kill-buffer newname))
  9290. (setq b2 (let (buffer-file-name) ;; Else clone is upset
  9291. (clone-buffer newname)))
  9292. (with-current-buffer b2
  9293. ;; auto requires the filename, but can't have same filename in two
  9294. ;; buffers; so override both b1 and b2's names
  9295. (let ((buffer-file-name name1))
  9296. (unwind-protect
  9297. (progn
  9298. (with-current-buffer b1 (setq buffer-file-name nil))
  9299. (verilog-auto)
  9300. (when (not verilog-auto-star-save)
  9301. (verilog-delete-auto-star-implicit)))
  9302. ;; Restore name if unwind
  9303. (with-current-buffer b1 (setq buffer-file-name name1)))))
  9304. ;;
  9305. (setq diffpt (verilog-diff-buffers-p b1 b2 t))
  9306. (cond ((not diffpt)
  9307. (unless noninteractive (message "AUTO expansion identical"))
  9308. (kill-buffer newname)) ;; Nice to cleanup after oneself
  9309. (t
  9310. (funcall verilog-diff-function b1 b2 diffpt)))
  9311. ;; Return result of compare
  9312. diffpt)))
  9313. ;;
  9314. ;; Auto save
  9315. ;;
  9316. (defun verilog-auto-save-check ()
  9317. "On saving see if we need auto update."
  9318. (cond ((not verilog-auto-save-policy)) ; disabled
  9319. ((not (save-excursion
  9320. (save-match-data
  9321. (let ((case-fold-search nil))
  9322. (goto-char (point-min))
  9323. (re-search-forward "AUTO" nil t))))))
  9324. ((eq verilog-auto-save-policy 'force)
  9325. (verilog-auto))
  9326. ((not (buffer-modified-p)))
  9327. ((eq verilog-auto-update-tick (buffer-chars-modified-tick))) ; up-to-date
  9328. ((eq verilog-auto-save-policy 'detect)
  9329. (verilog-auto))
  9330. (t
  9331. (when (yes-or-no-p "AUTO statements not recomputed, do it now? ")
  9332. (verilog-auto))
  9333. ;; Don't ask again if didn't update
  9334. (set (make-local-variable 'verilog-auto-update-tick) (buffer-chars-modified-tick))))
  9335. (when (not verilog-auto-star-save)
  9336. (verilog-delete-auto-star-implicit))
  9337. nil) ;; Always return nil -- we don't write the file ourselves
  9338. (defun verilog-auto-read-locals ()
  9339. "Return file local variable segment at bottom of file."
  9340. (save-excursion
  9341. (goto-char (point-max))
  9342. (if (re-search-backward "Local Variables:" nil t)
  9343. (buffer-substring-no-properties (point) (point-max))
  9344. "")))
  9345. (defun verilog-auto-reeval-locals (&optional force)
  9346. "Read file local variable segment at bottom of file if it has changed.
  9347. If FORCE, always reread it."
  9348. (let ((curlocal (verilog-auto-read-locals)))
  9349. (when (or force (not (equal verilog-auto-last-file-locals curlocal)))
  9350. (set (make-local-variable 'verilog-auto-last-file-locals) curlocal)
  9351. ;; Note this may cause this function to be recursively invoked,
  9352. ;; because hack-local-variables may call (verilog-mode)
  9353. ;; The above when statement will prevent it from recursing forever.
  9354. (hack-local-variables)
  9355. t)))
  9356. ;;
  9357. ;; Auto creation
  9358. ;;
  9359. (defun verilog-auto-arg-ports (sigs message indent-pt)
  9360. "Print a list of ports for a AUTOINST.
  9361. Takes SIGS list, adds MESSAGE to front and inserts each at INDENT-PT."
  9362. (when sigs
  9363. (when verilog-auto-arg-sort
  9364. (setq sigs (sort (copy-alist sigs) `verilog-signals-sort-compare)))
  9365. (insert "\n")
  9366. (indent-to indent-pt)
  9367. (insert message)
  9368. (insert "\n")
  9369. (let ((space ""))
  9370. (indent-to indent-pt)
  9371. (while sigs
  9372. (cond ((> (+ 2 (current-column) (length (verilog-sig-name (car sigs)))) fill-column)
  9373. (insert "\n")
  9374. (indent-to indent-pt))
  9375. (t (insert space)))
  9376. (insert (verilog-sig-name (car sigs)) ",")
  9377. (setq sigs (cdr sigs)
  9378. space " ")))))
  9379. (defun verilog-auto-arg ()
  9380. "Expand AUTOARG statements.
  9381. Replace the argument declarations at the beginning of the
  9382. module with ones automatically derived from input and output
  9383. statements. This can be dangerous if the module is instantiated
  9384. using position-based connections, so use only name-based when
  9385. instantiating the resulting module. Long lines are split based
  9386. on the `fill-column', see \\[set-fill-column].
  9387. Limitations:
  9388. Concatenation and outputting partial buses is not supported.
  9389. Typedefs must match `verilog-typedef-regexp', which is disabled by default.
  9390. For example:
  9391. module ExampArg (/*AUTOARG*/);
  9392. input i;
  9393. output o;
  9394. endmodule
  9395. Typing \\[verilog-auto] will make this into:
  9396. module ExampArg (/*AUTOARG*/
  9397. // Outputs
  9398. o,
  9399. // Inputs
  9400. i
  9401. );
  9402. input i;
  9403. output o;
  9404. endmodule
  9405. The argument declarations may be printed in declaration order to best suit
  9406. order based instantiations, or alphabetically, based on the
  9407. `verilog-auto-arg-sort' variable.
  9408. Any ports declared between the ( and /*AUTOARG*/ are presumed to be
  9409. predeclared and are not redeclared by AUTOARG. AUTOARG will make a
  9410. conservative guess on adding a comma for the first signal, if you have
  9411. any ifdefs or complicated expressions before the AUTOARG you will need
  9412. to choose the comma yourself.
  9413. Avoid declaring ports manually, as it makes code harder to maintain."
  9414. (save-excursion
  9415. (let* ((modi (verilog-modi-current))
  9416. (moddecls (verilog-modi-get-decls modi))
  9417. (skip-pins (aref (verilog-read-arg-pins) 0)))
  9418. (verilog-repair-open-comma)
  9419. (verilog-auto-arg-ports (verilog-signals-not-in
  9420. (verilog-decls-get-outputs moddecls)
  9421. skip-pins)
  9422. "// Outputs"
  9423. verilog-indent-level-declaration)
  9424. (verilog-auto-arg-ports (verilog-signals-not-in
  9425. (verilog-decls-get-inouts moddecls)
  9426. skip-pins)
  9427. "// Inouts"
  9428. verilog-indent-level-declaration)
  9429. (verilog-auto-arg-ports (verilog-signals-not-in
  9430. (verilog-decls-get-inputs moddecls)
  9431. skip-pins)
  9432. "// Inputs"
  9433. verilog-indent-level-declaration)
  9434. (verilog-repair-close-comma)
  9435. (unless (eq (char-before) ?/ )
  9436. (insert "\n"))
  9437. (indent-to verilog-indent-level-declaration))))
  9438. (defun verilog-auto-inst-port-map (port-st)
  9439. nil)
  9440. (defvar vl-cell-type nil "See `verilog-auto-inst'.") ; Prevent compile warning
  9441. (defvar vl-cell-name nil "See `verilog-auto-inst'.") ; Prevent compile warning
  9442. (defvar vl-modport nil "See `verilog-auto-inst'.") ; Prevent compile warning
  9443. (defvar vl-name nil "See `verilog-auto-inst'.") ; Prevent compile warning
  9444. (defvar vl-width nil "See `verilog-auto-inst'.") ; Prevent compile warning
  9445. (defvar vl-dir nil "See `verilog-auto-inst'.") ; Prevent compile warning
  9446. (defvar vl-bits nil "See `verilog-auto-inst'.") ; Prevent compile warning
  9447. (defvar vl-mbits nil "See `verilog-auto-inst'.") ; Prevent compile warning
  9448. (defun verilog-auto-inst-port (port-st indent-pt tpl-list tpl-num for-star par-values)
  9449. "Print out a instantiation connection for this PORT-ST.
  9450. Insert to INDENT-PT, use template TPL-LIST.
  9451. @ are instantiation numbers, replaced with TPL-NUM.
  9452. @\"(expression @)\" are evaluated, with @ as a variable.
  9453. If FOR-STAR add comment it is a .* expansion.
  9454. If PAR-VALUES replace final strings with these parameter values."
  9455. (let* ((port (verilog-sig-name port-st))
  9456. (tpl-ass (or (assoc port (car tpl-list))
  9457. (verilog-auto-inst-port-map port-st)))
  9458. ;; vl-* are documented for user use
  9459. (vl-name (verilog-sig-name port-st))
  9460. (vl-width (verilog-sig-width port-st))
  9461. (vl-modport (verilog-sig-modport port-st))
  9462. (vl-mbits (if (verilog-sig-multidim port-st)
  9463. (verilog-sig-multidim-string port-st) ""))
  9464. (vl-bits (if (or verilog-auto-inst-vector
  9465. (not (assoc port vector-skip-list))
  9466. (not (equal (verilog-sig-bits port-st)
  9467. (verilog-sig-bits (assoc port vector-skip-list)))))
  9468. (or (verilog-sig-bits port-st) "")
  9469. ""))
  9470. (case-fold-search nil)
  9471. (check-values par-values)
  9472. tpl-net)
  9473. ;; Replace parameters in bit-width
  9474. (when (and check-values
  9475. (not (equal vl-bits "")))
  9476. (while check-values
  9477. (setq vl-bits (verilog-string-replace-matches
  9478. (concat "\\<" (nth 0 (car check-values)) "\\>")
  9479. (concat "(" (nth 1 (car check-values)) ")")
  9480. t t vl-bits)
  9481. vl-mbits (verilog-string-replace-matches
  9482. (concat "\\<" (nth 0 (car check-values)) "\\>")
  9483. (concat "(" (nth 1 (car check-values)) ")")
  9484. t t vl-mbits)
  9485. check-values (cdr check-values)))
  9486. (setq vl-bits (verilog-simplify-range-expression vl-bits)
  9487. vl-mbits (verilog-simplify-range-expression vl-mbits)
  9488. vl-width (verilog-make-width-expression vl-bits))) ; Not in the loop for speed
  9489. ;; Default net value if not found
  9490. (setq tpl-net (concat port
  9491. (if vl-modport (concat "." vl-modport) "")
  9492. (if (verilog-sig-multidim port-st)
  9493. (concat "/*" vl-mbits vl-bits "*/")
  9494. (concat vl-bits))))
  9495. ;; Find template
  9496. (cond (tpl-ass ; Template of exact port name
  9497. (setq tpl-net (nth 1 tpl-ass)))
  9498. ((nth 1 tpl-list) ; Wildcards in template, search them
  9499. (let ((wildcards (nth 1 tpl-list)))
  9500. (while wildcards
  9501. (when (string-match (nth 0 (car wildcards)) port)
  9502. (setq tpl-ass (car wildcards) ; so allow @ parsing
  9503. tpl-net (replace-match (nth 1 (car wildcards))
  9504. t nil port)))
  9505. (setq wildcards (cdr wildcards))))))
  9506. ;; Parse Templated variable
  9507. (when tpl-ass
  9508. ;; Evaluate @"(lispcode)"
  9509. (when (string-match "@\".*[^\\]\"" tpl-net)
  9510. (while (string-match "@\"\\(\\([^\\\"]*\\(\\\\.\\)*\\)*\\)\"" tpl-net)
  9511. (setq tpl-net
  9512. (concat
  9513. (substring tpl-net 0 (match-beginning 0))
  9514. (save-match-data
  9515. (let* ((expr (match-string 1 tpl-net))
  9516. (value
  9517. (progn
  9518. (setq expr (verilog-string-replace-matches "\\\\\"" "\"" nil nil expr))
  9519. (setq expr (verilog-string-replace-matches "@" tpl-num nil nil expr))
  9520. (prin1 (eval (car (read-from-string expr)))
  9521. (lambda (ch) ())))))
  9522. (if (numberp value) (setq value (number-to-string value)))
  9523. value))
  9524. (substring tpl-net (match-end 0))))))
  9525. ;; Replace @ and [] magic variables in final output
  9526. (setq tpl-net (verilog-string-replace-matches "@" tpl-num nil nil tpl-net))
  9527. (setq tpl-net (verilog-string-replace-matches "\\[\\]" vl-bits nil nil tpl-net)))
  9528. ;; Insert it
  9529. (indent-to indent-pt)
  9530. (insert "." port)
  9531. (unless (and verilog-auto-inst-dot-name
  9532. (equal port tpl-net))
  9533. (indent-to verilog-auto-inst-column)
  9534. (insert "(" tpl-net ")"))
  9535. (insert ",")
  9536. (cond (tpl-ass
  9537. (indent-to (+ (if (< verilog-auto-inst-column 48) 24 16)
  9538. verilog-auto-inst-column))
  9539. ;; verilog-insert requires the complete comment in one call - including the newline
  9540. (cond ((equal verilog-auto-inst-template-numbers `lhs)
  9541. (verilog-insert " // Templated"
  9542. " LHS: " (nth 0 tpl-ass)
  9543. "\n"))
  9544. (verilog-auto-inst-template-numbers
  9545. (verilog-insert " // Templated"
  9546. " T" (int-to-string (nth 2 tpl-ass))
  9547. " L" (int-to-string (nth 3 tpl-ass))
  9548. "\n"))
  9549. (t
  9550. (verilog-insert " // Templated\n"))))
  9551. (for-star
  9552. (indent-to (+ (if (< verilog-auto-inst-column 48) 24 16)
  9553. verilog-auto-inst-column))
  9554. (verilog-insert " // Implicit .\*\n")) ;For some reason the . or * must be escaped...
  9555. (t
  9556. (insert "\n")))))
  9557. ;;(verilog-auto-inst-port (list "foo" "[5:0]") 10 (list (list "foo" "a@\"(% (+ @ 1) 4)\"a")) "3")
  9558. ;;(x "incom[@\"(+ (* 8 @) 7)\":@\"(* 8 @)\"]")
  9559. ;;(x ".out (outgo[@\"(concat (+ (* 8 @) 7) \\\":\\\" ( * 8 @))\"]));")
  9560. (defun verilog-auto-inst-port-list (sig-list indent-pt tpl-list tpl-num for-star par-values)
  9561. "For `verilog-auto-inst' print a list of ports using `verilog-auto-inst-port'."
  9562. (when verilog-auto-inst-sort
  9563. (setq sig-list (sort (copy-alist sig-list) `verilog-signals-sort-compare)))
  9564. (mapc (lambda (port)
  9565. (verilog-auto-inst-port port indent-pt
  9566. tpl-list tpl-num for-star par-values))
  9567. sig-list))
  9568. (defun verilog-auto-inst-first ()
  9569. "Insert , etc before first ever port in this instant, as part of \\[verilog-auto-inst]."
  9570. ;; Do we need a trailing comma?
  9571. ;; There maybe a ifdef or something similar before us. What a mess. Thus
  9572. ;; to avoid trouble we only insert on preceding ) or *.
  9573. ;; Insert first port on new line
  9574. (insert "\n") ;; Must insert before search, so point will move forward if insert comma
  9575. (save-excursion
  9576. (verilog-re-search-backward-quick "[^ \t\n\f]" nil nil)
  9577. (when (looking-at ")\\|\\*") ;; Generally don't insert, unless we are fairly sure
  9578. (forward-char 1)
  9579. (insert ","))))
  9580. (defun verilog-auto-star ()
  9581. "Expand SystemVerilog .* pins, as part of \\[verilog-auto].
  9582. If `verilog-auto-star-expand' is set, .* pins are treated if they were
  9583. AUTOINST statements, otherwise they are ignored. For safety, Verilog mode
  9584. will also ignore any .* that are not last in your pin list (this prevents
  9585. it from deleting pins following the .* when it expands the AUTOINST.)
  9586. On writing your file, unless `verilog-auto-star-save' is set, any
  9587. non-templated expanded pins will be removed. You may do this at any time
  9588. with \\[verilog-delete-auto-star-implicit].
  9589. If you are converting a module to use .* for the first time, you may wish
  9590. to use \\[verilog-inject-auto] and then replace the created AUTOINST with .*.
  9591. See `verilog-auto-inst' for examples, templates, and more information."
  9592. (when (verilog-auto-star-safe)
  9593. (verilog-auto-inst)))
  9594. (defun verilog-auto-inst ()
  9595. "Expand AUTOINST statements, as part of \\[verilog-auto].
  9596. Replace the pin connections to an instantiation or interface
  9597. declaration with ones automatically derived from the module or
  9598. interface header of the instantiated item.
  9599. If `verilog-auto-star-expand' is set, also expand SystemVerilog .* ports,
  9600. and delete them before saving unless `verilog-auto-star-save' is set.
  9601. See `verilog-auto-star' for more information.
  9602. The pins are printed in declaration order or alphabetically,
  9603. based on the `verilog-auto-inst-sort' variable.
  9604. Limitations:
  9605. Module names must be resolvable to filenames by adding a
  9606. `verilog-library-extensions', and being found in the same directory, or
  9607. by changing the variable `verilog-library-flags' or
  9608. `verilog-library-directories'. Macros `modname are translated through the
  9609. vh-{name} Emacs variable, if that is not found, it just ignores the `.
  9610. In templates you must have one signal per line, ending in a ), or ));,
  9611. and have proper () nesting, including a final ); to end the template.
  9612. Typedefs must match `verilog-typedef-regexp', which is disabled by default.
  9613. SystemVerilog multidimensional input/output has only experimental support.
  9614. SystemVerilog .name syntax is used if `verilog-auto-inst-dot-name' is set.
  9615. Parameters referenced by the instantiation will remain symbolic, unless
  9616. `verilog-auto-inst-param-value' is set.
  9617. Gate primitives (and/or) may have AUTOINST for the purpose of
  9618. AUTOWIRE declarations, etc. Gates are the only case when
  9619. position based connections are passed.
  9620. For example, first take the submodule InstModule.v:
  9621. module InstModule (o,i);
  9622. output [31:0] o;
  9623. input i;
  9624. wire [31:0] o = {32{i}};
  9625. endmodule
  9626. This is then used in a upper level module:
  9627. module ExampInst (o,i);
  9628. output o;
  9629. input i;
  9630. InstModule instName
  9631. (/*AUTOINST*/);
  9632. endmodule
  9633. Typing \\[verilog-auto] will make this into:
  9634. module ExampInst (o,i);
  9635. output o;
  9636. input i;
  9637. InstModule instName
  9638. (/*AUTOINST*/
  9639. // Outputs
  9640. .ov (ov[31:0]),
  9641. // Inputs
  9642. .i (i));
  9643. endmodule
  9644. Where the list of inputs and outputs came from the inst module.
  9645. Exceptions:
  9646. Unless you are instantiating a module multiple times, or the module is
  9647. something trivial like an adder, DO NOT CHANGE SIGNAL NAMES ACROSS HIERARCHY.
  9648. It just makes for unmaintainable code. To sanitize signal names, try
  9649. vrename from URL `http://www.veripool.org'.
  9650. When you need to violate this suggestion there are two ways to list
  9651. exceptions, placing them before the AUTOINST, or using templates.
  9652. Any ports defined before the /*AUTOINST*/ are not included in the list of
  9653. automatics. This is similar to making a template as described below, but
  9654. is restricted to simple connections just like you normally make. Also note
  9655. that any signals before the AUTOINST will only be picked up by AUTOWIRE if
  9656. you have the appropriate // Input or // Output comment, and exactly the
  9657. same line formatting as AUTOINST itself uses.
  9658. InstModule instName
  9659. (// Inputs
  9660. .i (my_i_dont_mess_with_it),
  9661. /*AUTOINST*/
  9662. // Outputs
  9663. .ov (ov[31:0]));
  9664. Templates:
  9665. For multiple instantiations based upon a single template, create a
  9666. commented out template:
  9667. /* InstModule AUTO_TEMPLATE (
  9668. .sig3 (sigz[]),
  9669. );
  9670. */
  9671. Templates go ABOVE the instantiation(s). When an instantiation is
  9672. expanded `verilog-mode' simply searches up for the closest template.
  9673. Thus you can have multiple templates for the same module, just alternate
  9674. between the template for an instantiation and the instantiation itself.
  9675. The module name must be the same as the name of the module in the
  9676. instantiation name, and the code \"AUTO_TEMPLATE\" must be in these exact
  9677. words and capitalized. Only signals that must be different for each
  9678. instantiation need to be listed.
  9679. Inside a template, a [] in a connection name (with nothing else inside
  9680. the brackets) will be replaced by the same bus subscript as it is being
  9681. connected to, or the [] will be removed if it is a single bit signal.
  9682. Generally it is a good idea to do this for all connections in a template,
  9683. as then they will work for any width signal, and with AUTOWIRE. See
  9684. PTL_BUS becoming PTL_BUSNEW below.
  9685. If you have a complicated template, set `verilog-auto-inst-template-numbers'
  9686. to see which regexps are matching. Don't leave that mode set after
  9687. debugging is completed though, it will result in lots of extra differences
  9688. and merge conflicts.
  9689. For example:
  9690. /* InstModule AUTO_TEMPLATE (
  9691. .ptl_bus (ptl_busnew[]),
  9692. );
  9693. */
  9694. InstModule ms2m (/*AUTOINST*/);
  9695. Typing \\[verilog-auto] will make this into:
  9696. InstModule ms2m (/*AUTOINST*/
  9697. // Outputs
  9698. .NotInTemplate (NotInTemplate),
  9699. .ptl_bus (ptl_busnew[3:0]), // Templated
  9700. ....
  9701. Multiple Module Templates:
  9702. The same template lines can be applied to multiple modules with
  9703. the syntax as follows:
  9704. /* InstModuleA AUTO_TEMPLATE
  9705. InstModuleB AUTO_TEMPLATE
  9706. InstModuleC AUTO_TEMPLATE
  9707. InstModuleD AUTO_TEMPLATE (
  9708. .ptl_bus (ptl_busnew[]),
  9709. );
  9710. */
  9711. Note there is only one AUTO_TEMPLATE opening parenthesis.
  9712. @ Templates:
  9713. It is common to instantiate a cell multiple times, so templates make it
  9714. trivial to substitute part of the cell name into the connection name.
  9715. /* InstName AUTO_TEMPLATE <optional \"REGEXP\"> (
  9716. .sig1 (sigx[@]),
  9717. .sig2 (sigy[@\"(% (+ 1 @) 4)\"]),
  9718. );
  9719. */
  9720. If no regular expression is provided immediately after the AUTO_TEMPLATE
  9721. keyword, then the @ character in any connection names will be replaced
  9722. with the instantiation number; the first digits found in the cell's
  9723. instantiation name.
  9724. If a regular expression is provided, the @ character will be replaced
  9725. with the first \(\) grouping that matches against the cell name. Using a
  9726. regexp of \"\\([0-9]+\\)\" provides identical values for @ as when no
  9727. regexp is provided. If you use multiple layers of parenthesis,
  9728. \"test\\([^0-9]+\\)_\\([0-9]+\\)\" would replace @ with non-number
  9729. characters after test and before _, whereas
  9730. \"\\(test\\([a-z]+\\)_\\([0-9]+\\)\\)\" would replace @ with the entire
  9731. match.
  9732. For example:
  9733. /* InstModule AUTO_TEMPLATE (
  9734. .ptl_mapvalidx (ptl_mapvalid[@]),
  9735. .ptl_mapvalidp1x (ptl_mapvalid[@\"(% (+ 1 @) 4)\"]),
  9736. );
  9737. */
  9738. InstModule ms2m (/*AUTOINST*/);
  9739. Typing \\[verilog-auto] will make this into:
  9740. InstModule ms2m (/*AUTOINST*/
  9741. // Outputs
  9742. .ptl_mapvalidx (ptl_mapvalid[2]),
  9743. .ptl_mapvalidp1x (ptl_mapvalid[3]));
  9744. Note the @ character was replaced with the 2 from \"ms2m\".
  9745. Alternatively, using a regular expression for @:
  9746. /* InstModule AUTO_TEMPLATE \"_\\([a-z]+\\)\" (
  9747. .ptl_mapvalidx (@_ptl_mapvalid),
  9748. .ptl_mapvalidp1x (ptl_mapvalid_@),
  9749. );
  9750. */
  9751. InstModule ms2_FOO (/*AUTOINST*/);
  9752. InstModule ms2_BAR (/*AUTOINST*/);
  9753. Typing \\[verilog-auto] will make this into:
  9754. InstModule ms2_FOO (/*AUTOINST*/
  9755. // Outputs
  9756. .ptl_mapvalidx (FOO_ptl_mapvalid),
  9757. .ptl_mapvalidp1x (ptl_mapvalid_FOO));
  9758. InstModule ms2_BAR (/*AUTOINST*/
  9759. // Outputs
  9760. .ptl_mapvalidx (BAR_ptl_mapvalid),
  9761. .ptl_mapvalidp1x (ptl_mapvalid_BAR));
  9762. Regexp Templates:
  9763. A template entry of the form
  9764. .pci_req\\([0-9]+\\)_l (pci_req_jtag_[\\1]),
  9765. will apply an Emacs style regular expression search for any port beginning
  9766. in pci_req followed by numbers and ending in _l and connecting that to
  9767. the pci_req_jtag_[] net, with the bus subscript coming from what matches
  9768. inside the first set of \\( \\). Thus pci_req2_l becomes pci_req_jtag_[2].
  9769. Since \\([0-9]+\\) is so common and ugly to read, a @ in the port name
  9770. does the same thing. (Note a @ in the connection/replacement text is
  9771. completely different -- still use \\1 there!) Thus this is the same as
  9772. the above template:
  9773. .pci_req@_l (pci_req_jtag_[\\1]),
  9774. Here's another example to remove the _l, useful when naming conventions
  9775. specify _ alone to mean active low. Note the use of [] to keep the bus
  9776. subscript:
  9777. .\\(.*\\)_l (\\1_[]),
  9778. Lisp Templates:
  9779. First any regular expression template is expanded.
  9780. If the syntax @\"( ... )\" is found in a connection, the expression in
  9781. quotes will be evaluated as a Lisp expression, with @ replaced by the
  9782. instantiation number. The MAPVALIDP1X example above would put @+1 modulo
  9783. 4 into the brackets. Quote all double-quotes inside the expression with
  9784. a leading backslash (\\\"...\\\"); or if the Lisp template is also a
  9785. regexp template backslash the backslash quote (\\\\\"...\\\\\").
  9786. There are special variables defined that are useful in these
  9787. Lisp functions:
  9788. vl-name Name portion of the input/output port.
  9789. vl-bits Bus bits portion of the input/output port ('[2:0]').
  9790. vl-mbits Multidimensional array bits for port ('[2:0][3:0]').
  9791. vl-width Width of the input/output port ('3' for [2:0]).
  9792. May be a (...) expression if bits isn't a constant.
  9793. vl-dir Direction of the pin input/output/inout/interface.
  9794. vl-modport The modport, if an interface with a modport.
  9795. vl-cell-type Module name/type of the cell ('InstModule').
  9796. vl-cell-name Instance name of the cell ('instName').
  9797. Normal Lisp variables may be used in expressions. See
  9798. `verilog-read-defines' which can set vh-{definename} variables for use
  9799. here. Also, any comments of the form:
  9800. /*AUTO_LISP(setq foo 1)*/
  9801. will evaluate any Lisp expression inside the parenthesis between the
  9802. beginning of the buffer and the point of the AUTOINST. This allows
  9803. functions to be defined or variables to be changed between instantiations.
  9804. (See also `verilog-auto-insert-lisp' if you want the output from your
  9805. lisp function to be inserted.)
  9806. Note that when using lisp expressions errors may occur when @ is not a
  9807. number; you may need to use the standard Emacs Lisp functions
  9808. `number-to-string' and `string-to-number'.
  9809. After the evaluation is completed, @ substitution and [] substitution
  9810. occur.
  9811. For more information see the \\[verilog-faq] and forums at URL
  9812. `http://www.veripool.org'."
  9813. (save-excursion
  9814. ;; Find beginning
  9815. (let* ((pt (point))
  9816. (for-star (save-excursion (backward-char 2) (looking-at "\\.\\*")))
  9817. (indent-pt (save-excursion (verilog-backward-open-paren)
  9818. (1+ (current-column))))
  9819. (verilog-auto-inst-column (max verilog-auto-inst-column
  9820. (+ 16 (* 8 (/ (+ indent-pt 7) 8)))))
  9821. (modi (verilog-modi-current))
  9822. (moddecls (verilog-modi-get-decls modi))
  9823. (vector-skip-list (unless verilog-auto-inst-vector
  9824. (verilog-decls-get-signals moddecls)))
  9825. submod submodi submoddecls
  9826. inst skip-pins tpl-list tpl-num did-first par-values)
  9827. ;; Find module name that is instantiated
  9828. (setq submod (verilog-read-inst-module)
  9829. inst (verilog-read-inst-name)
  9830. vl-cell-type submod
  9831. vl-cell-name inst
  9832. skip-pins (aref (verilog-read-inst-pins) 0))
  9833. ;; Parse any AUTO_LISP() before here
  9834. (verilog-read-auto-lisp (point-min) pt)
  9835. ;; Read parameters (after AUTO_LISP)
  9836. (setq par-values (and verilog-auto-inst-param-value
  9837. (verilog-read-inst-param-value)))
  9838. ;; Lookup position, etc of submodule
  9839. ;; Note this may raise an error
  9840. (when (and (not (member submod verilog-gate-keywords))
  9841. (setq submodi (verilog-modi-lookup submod t)))
  9842. (setq submoddecls (verilog-modi-get-decls submodi))
  9843. ;; If there's a number in the instantiation, it may be a argument to the
  9844. ;; automatic variable instantiation program.
  9845. (let* ((tpl-info (verilog-read-auto-template submod))
  9846. (tpl-regexp (aref tpl-info 0)))
  9847. (setq tpl-num (if (string-match tpl-regexp inst)
  9848. (match-string 1 inst)
  9849. "")
  9850. tpl-list (aref tpl-info 1)))
  9851. ;; Find submodule's signals and dump
  9852. (let ((sig-list (and (equal (verilog-modi-get-type submodi) "interface")
  9853. (verilog-signals-not-in
  9854. (verilog-decls-get-vars submoddecls)
  9855. skip-pins)))
  9856. (vl-dir "interfaced"))
  9857. (when sig-list
  9858. (when (not did-first) (verilog-auto-inst-first) (setq did-first t))
  9859. ;; Note these are searched for in verilog-read-sub-decls.
  9860. (verilog-insert-indent "// Interfaced\n")
  9861. (verilog-auto-inst-port-list sig-list indent-pt
  9862. tpl-list tpl-num for-star par-values)))
  9863. (let ((sig-list (verilog-signals-not-in
  9864. (verilog-decls-get-interfaces submoddecls)
  9865. skip-pins))
  9866. (vl-dir "interface"))
  9867. (when sig-list
  9868. (when (not did-first) (verilog-auto-inst-first) (setq did-first t))
  9869. ;; Note these are searched for in verilog-read-sub-decls.
  9870. (verilog-insert-indent "// Interfaces\n")
  9871. (verilog-auto-inst-port-list sig-list indent-pt
  9872. tpl-list tpl-num for-star par-values)))
  9873. (let ((sig-list (verilog-signals-not-in
  9874. (verilog-decls-get-outputs submoddecls)
  9875. skip-pins))
  9876. (vl-dir "output"))
  9877. (when sig-list
  9878. (when (not did-first) (verilog-auto-inst-first) (setq did-first t))
  9879. (verilog-insert-indent "// Outputs\n")
  9880. (verilog-auto-inst-port-list sig-list indent-pt
  9881. tpl-list tpl-num for-star par-values)))
  9882. (let ((sig-list (verilog-signals-not-in
  9883. (verilog-decls-get-inouts submoddecls)
  9884. skip-pins))
  9885. (vl-dir "inout"))
  9886. (when sig-list
  9887. (when (not did-first) (verilog-auto-inst-first) (setq did-first t))
  9888. (verilog-insert-indent "// Inouts\n")
  9889. (verilog-auto-inst-port-list sig-list indent-pt
  9890. tpl-list tpl-num for-star par-values)))
  9891. (let ((sig-list (verilog-signals-not-in
  9892. (verilog-decls-get-inputs submoddecls)
  9893. skip-pins))
  9894. (vl-dir "input"))
  9895. (when sig-list
  9896. (when (not did-first) (verilog-auto-inst-first) (setq did-first t))
  9897. (verilog-insert-indent "// Inputs\n")
  9898. (verilog-auto-inst-port-list sig-list indent-pt
  9899. tpl-list tpl-num for-star par-values)))
  9900. ;; Kill extra semi
  9901. (save-excursion
  9902. (cond (did-first
  9903. (re-search-backward "," pt t)
  9904. (delete-char 1)
  9905. (insert ");")
  9906. (search-forward "\n") ;; Added by inst-port
  9907. (delete-char -1)
  9908. (if (search-forward ")" nil t) ;; From user, moved up a line
  9909. (delete-char -1))
  9910. (if (search-forward ";" nil t) ;; Don't error if user had syntax error and forgot it
  9911. (delete-char -1)))))))))
  9912. (defun verilog-auto-inst-param ()
  9913. "Expand AUTOINSTPARAM statements, as part of \\[verilog-auto].
  9914. Replace the parameter connections to an instantiation with ones
  9915. automatically derived from the module header of the instantiated netlist.
  9916. See \\[verilog-auto-inst] for limitations, and templates to customize the
  9917. output.
  9918. For example, first take the submodule InstModule.v:
  9919. module InstModule (o,i);
  9920. parameter PAR;
  9921. endmodule
  9922. This is then used in a upper level module:
  9923. module ExampInst (o,i);
  9924. parameter PAR;
  9925. InstModule #(/*AUTOINSTPARAM*/)
  9926. instName (/*AUTOINST*/);
  9927. endmodule
  9928. Typing \\[verilog-auto] will make this into:
  9929. module ExampInst (o,i);
  9930. output o;
  9931. input i;
  9932. InstModule #(/*AUTOINSTPARAM*/
  9933. // Parameters
  9934. .PAR (PAR));
  9935. instName (/*AUTOINST*/);
  9936. endmodule
  9937. Where the list of parameter connections come from the inst module.
  9938. Templates:
  9939. You can customize the parameter connections using AUTO_TEMPLATEs,
  9940. just as you would with \\[verilog-auto-inst]."
  9941. (save-excursion
  9942. ;; Find beginning
  9943. (let* ((pt (point))
  9944. (indent-pt (save-excursion (verilog-backward-open-paren)
  9945. (1+ (current-column))))
  9946. (verilog-auto-inst-column (max verilog-auto-inst-column
  9947. (+ 16 (* 8 (/ (+ indent-pt 7) 8)))))
  9948. (modi (verilog-modi-current))
  9949. (moddecls (verilog-modi-get-decls modi))
  9950. (vector-skip-list (unless verilog-auto-inst-vector
  9951. (verilog-decls-get-signals moddecls)))
  9952. submod submodi submoddecls
  9953. inst skip-pins tpl-list tpl-num did-first)
  9954. ;; Find module name that is instantiated
  9955. (setq submod (save-excursion
  9956. ;; Get to the point where AUTOINST normally is to read the module
  9957. (verilog-re-search-forward-quick "[(;]" nil nil)
  9958. (verilog-read-inst-module))
  9959. inst (save-excursion
  9960. ;; Get to the point where AUTOINST normally is to read the module
  9961. (verilog-re-search-forward-quick "[(;]" nil nil)
  9962. (verilog-read-inst-name))
  9963. vl-cell-type submod
  9964. vl-cell-name inst
  9965. skip-pins (aref (verilog-read-inst-pins) 0))
  9966. ;; Parse any AUTO_LISP() before here
  9967. (verilog-read-auto-lisp (point-min) pt)
  9968. ;; Lookup position, etc of submodule
  9969. ;; Note this may raise an error
  9970. (when (setq submodi (verilog-modi-lookup submod t))
  9971. (setq submoddecls (verilog-modi-get-decls submodi))
  9972. ;; If there's a number in the instantiation, it may be a argument to the
  9973. ;; automatic variable instantiation program.
  9974. (let* ((tpl-info (verilog-read-auto-template submod))
  9975. (tpl-regexp (aref tpl-info 0)))
  9976. (setq tpl-num (if (string-match tpl-regexp inst)
  9977. (match-string 1 inst)
  9978. "")
  9979. tpl-list (aref tpl-info 1)))
  9980. ;; Find submodule's signals and dump
  9981. (let ((sig-list (verilog-signals-not-in
  9982. (verilog-decls-get-gparams submoddecls)
  9983. skip-pins))
  9984. (vl-dir "parameter"))
  9985. (when sig-list
  9986. (when (not did-first) (verilog-auto-inst-first) (setq did-first t))
  9987. ;; Note these are searched for in verilog-read-sub-decls.
  9988. (verilog-insert-indent "// Parameters\n")
  9989. (verilog-auto-inst-port-list sig-list indent-pt
  9990. tpl-list tpl-num nil nil)))
  9991. ;; Kill extra semi
  9992. (save-excursion
  9993. (cond (did-first
  9994. (re-search-backward "," pt t)
  9995. (delete-char 1)
  9996. (insert ")")
  9997. (search-forward "\n") ;; Added by inst-port
  9998. (delete-char -1)
  9999. (if (search-forward ")" nil t) ;; From user, moved up a line
  10000. (delete-char -1)))))))))
  10001. (defun verilog-auto-reg ()
  10002. "Expand AUTOREG statements, as part of \\[verilog-auto].
  10003. Make reg statements for any output that isn't already declared,
  10004. and isn't a wire output from a block. `verilog-auto-wire-type'
  10005. may be used to change the datatype of the declarations.
  10006. Limitations:
  10007. This ONLY detects outputs of AUTOINSTants (see `verilog-read-sub-decls').
  10008. This does NOT work on memories, declare those yourself.
  10009. An example:
  10010. module ExampReg (o,i);
  10011. output o;
  10012. input i;
  10013. /*AUTOREG*/
  10014. always o = i;
  10015. endmodule
  10016. Typing \\[verilog-auto] will make this into:
  10017. module ExampReg (o,i);
  10018. output o;
  10019. input i;
  10020. /*AUTOREG*/
  10021. // Beginning of automatic regs (for this module's undeclared outputs)
  10022. reg o;
  10023. // End of automatics
  10024. always o = i;
  10025. endmodule"
  10026. (save-excursion
  10027. ;; Point must be at insertion point.
  10028. (let* ((indent-pt (current-indentation))
  10029. (modi (verilog-modi-current))
  10030. (moddecls (verilog-modi-get-decls modi))
  10031. (modsubdecls (verilog-modi-get-sub-decls modi))
  10032. (sig-list (verilog-signals-not-in
  10033. (verilog-decls-get-outputs moddecls)
  10034. (append (verilog-decls-get-vars moddecls)
  10035. (verilog-decls-get-assigns moddecls)
  10036. (verilog-decls-get-consts moddecls)
  10037. (verilog-decls-get-gparams moddecls)
  10038. (verilog-subdecls-get-interfaced modsubdecls)
  10039. (verilog-subdecls-get-outputs modsubdecls)
  10040. (verilog-subdecls-get-inouts modsubdecls)))))
  10041. (forward-line 1)
  10042. (when sig-list
  10043. (verilog-insert-indent "// Beginning of automatic regs (for this module's undeclared outputs)\n")
  10044. (verilog-insert-definition modi sig-list "reg" indent-pt nil)
  10045. (verilog-insert-indent "// End of automatics\n")))))
  10046. (defun verilog-auto-reg-input ()
  10047. "Expand AUTOREGINPUT statements, as part of \\[verilog-auto].
  10048. Make reg statements instantiation inputs that aren't already declared.
  10049. This is useful for making a top level shell for testing the module that is
  10050. to be instantiated.
  10051. Limitations:
  10052. This ONLY detects inputs of AUTOINSTants (see `verilog-read-sub-decls').
  10053. This does NOT work on memories, declare those yourself.
  10054. An example (see `verilog-auto-inst' for what else is going on here):
  10055. module ExampRegInput (o,i);
  10056. output o;
  10057. input i;
  10058. /*AUTOREGINPUT*/
  10059. InstModule instName
  10060. (/*AUTOINST*/);
  10061. endmodule
  10062. Typing \\[verilog-auto] will make this into:
  10063. module ExampRegInput (o,i);
  10064. output o;
  10065. input i;
  10066. /*AUTOREGINPUT*/
  10067. // Beginning of automatic reg inputs (for undeclared ...
  10068. reg [31:0] iv; // From inst of inst.v
  10069. // End of automatics
  10070. InstModule instName
  10071. (/*AUTOINST*/
  10072. // Outputs
  10073. .o (o[31:0]),
  10074. // Inputs
  10075. .iv (iv));
  10076. endmodule"
  10077. (save-excursion
  10078. ;; Point must be at insertion point.
  10079. (let* ((indent-pt (current-indentation))
  10080. (modi (verilog-modi-current))
  10081. (moddecls (verilog-modi-get-decls modi))
  10082. (modsubdecls (verilog-modi-get-sub-decls modi))
  10083. (sig-list (verilog-signals-combine-bus
  10084. (verilog-signals-not-in
  10085. (append (verilog-subdecls-get-inputs modsubdecls)
  10086. (verilog-subdecls-get-inouts modsubdecls))
  10087. (append (verilog-decls-get-signals moddecls)
  10088. (verilog-decls-get-assigns moddecls))))))
  10089. (forward-line 1)
  10090. (when sig-list
  10091. (verilog-insert-indent "// Beginning of automatic reg inputs (for undeclared instantiated-module inputs)\n")
  10092. (verilog-insert-definition modi sig-list "reg" indent-pt nil)
  10093. (verilog-insert-indent "// End of automatics\n")))))
  10094. (defun verilog-auto-logic ()
  10095. "Expand AUTOLOGIC statements, as part of \\[verilog-auto].
  10096. Make wire statements using the SystemVerilog logic keyword.
  10097. This is currently equivalent to:
  10098. /*AUTOWIRE*/
  10099. with the below at the bottom of the file
  10100. // Local Variables:
  10101. // verilog-auto-logic-type:\"logic\"
  10102. // End:
  10103. In the future AUTOLOGIC may declare additional identifiers,
  10104. while AUTOWIRE will not."
  10105. (save-excursion
  10106. (unless verilog-auto-wire-type
  10107. (set (make-local-variable 'verilog-auto-wire-type)
  10108. "logic"))
  10109. (verilog-auto-wire)))
  10110. (defun verilog-auto-wire ()
  10111. "Expand AUTOWIRE statements, as part of \\[verilog-auto].
  10112. Make wire statements for instantiations outputs that aren't
  10113. already declared. `verilog-auto-wire-type' may be used to change
  10114. the datatype of the declarations.
  10115. Limitations:
  10116. This ONLY detects outputs of AUTOINSTants (see `verilog-read-sub-decls'),
  10117. and all buses must have widths, such as those from AUTOINST, or using []
  10118. in AUTO_TEMPLATEs.
  10119. This does NOT work on memories or SystemVerilog .name connections,
  10120. declare those yourself.
  10121. Verilog mode will add \"Couldn't Merge\" comments to signals it cannot
  10122. determine how to bus together. This occurs when you have ports with
  10123. non-numeric or non-sequential bus subscripts. If Verilog mode
  10124. mis-guessed, you'll have to declare them yourself.
  10125. An example (see `verilog-auto-inst' for what else is going on here):
  10126. module ExampWire (o,i);
  10127. output o;
  10128. input i;
  10129. /*AUTOWIRE*/
  10130. InstModule instName
  10131. (/*AUTOINST*/);
  10132. endmodule
  10133. Typing \\[verilog-auto] will make this into:
  10134. module ExampWire (o,i);
  10135. output o;
  10136. input i;
  10137. /*AUTOWIRE*/
  10138. // Beginning of automatic wires
  10139. wire [31:0] ov; // From inst of inst.v
  10140. // End of automatics
  10141. InstModule instName
  10142. (/*AUTOINST*/
  10143. // Outputs
  10144. .ov (ov[31:0]),
  10145. // Inputs
  10146. .i (i));
  10147. wire o = | ov;
  10148. endmodule"
  10149. (save-excursion
  10150. ;; Point must be at insertion point.
  10151. (let* ((indent-pt (current-indentation))
  10152. (modi (verilog-modi-current))
  10153. (moddecls (verilog-modi-get-decls modi))
  10154. (modsubdecls (verilog-modi-get-sub-decls modi))
  10155. (sig-list (verilog-signals-combine-bus
  10156. (verilog-signals-not-in
  10157. (append (verilog-subdecls-get-outputs modsubdecls)
  10158. (verilog-subdecls-get-inouts modsubdecls))
  10159. (verilog-decls-get-signals moddecls)))))
  10160. (forward-line 1)
  10161. (when sig-list
  10162. (verilog-insert-indent "// Beginning of automatic wires (for undeclared instantiated-module outputs)\n")
  10163. (verilog-insert-definition modi sig-list "wire" indent-pt nil)
  10164. (verilog-insert-indent "// End of automatics\n")
  10165. ;; We used to optionally call verilog-pretty-declarations and
  10166. ;; verilog-pretty-expr here, but it's too slow on huge modules,
  10167. ;; plus makes everyone's module change. Finally those call
  10168. ;; syntax-ppss which is broken when change hooks are disabled.
  10169. ))))
  10170. (defun verilog-auto-output (&optional with-params)
  10171. "Expand AUTOOUTPUT statements, as part of \\[verilog-auto].
  10172. Make output statements for any output signal from an /*AUTOINST*/ that
  10173. isn't a input to another AUTOINST. This is useful for modules which
  10174. only instantiate other modules.
  10175. Limitations:
  10176. This ONLY detects outputs of AUTOINSTants (see `verilog-read-sub-decls').
  10177. If placed inside the parenthesis of a module declaration, it creates
  10178. Verilog 2001 style, else uses Verilog 1995 style.
  10179. If any concatenation, or bit-subscripts are missing in the AUTOINSTant's
  10180. instantiation, all bets are off. (For example due to a AUTO_TEMPLATE).
  10181. Typedefs must match `verilog-typedef-regexp', which is disabled by default.
  10182. Signals matching `verilog-auto-output-ignore-regexp' are not included.
  10183. An example (see `verilog-auto-inst' for what else is going on here):
  10184. module ExampOutput (ov,i);
  10185. input i;
  10186. /*AUTOOUTPUT*/
  10187. InstModule instName
  10188. (/*AUTOINST*/);
  10189. endmodule
  10190. Typing \\[verilog-auto] will make this into:
  10191. module ExampOutput (ov,i);
  10192. input i;
  10193. /*AUTOOUTPUT*/
  10194. // Beginning of automatic outputs (from unused autoinst outputs)
  10195. output [31:0] ov; // From inst of inst.v
  10196. // End of automatics
  10197. InstModule instName
  10198. (/*AUTOINST*/
  10199. // Outputs
  10200. .ov (ov[31:0]),
  10201. // Inputs
  10202. .i (i));
  10203. endmodule
  10204. You may also provide an optional regular expression, in which case only
  10205. signals matching the regular expression will be included. For example the
  10206. same expansion will result from only extracting outputs starting with ov:
  10207. /*AUTOOUTPUT(\"^ov\")*/"
  10208. (save-excursion
  10209. ;; Point must be at insertion point.
  10210. (let* ((indent-pt (current-indentation))
  10211. (regexp (and with-params
  10212. (nth 0 (verilog-read-auto-params 1))))
  10213. (v2k (verilog-in-paren-quick))
  10214. (modi (verilog-modi-current))
  10215. (moddecls (verilog-modi-get-decls modi))
  10216. (modsubdecls (verilog-modi-get-sub-decls modi))
  10217. (sig-list (verilog-signals-not-in
  10218. (verilog-subdecls-get-outputs modsubdecls)
  10219. (append (verilog-decls-get-outputs moddecls)
  10220. (verilog-decls-get-inouts moddecls)
  10221. (verilog-subdecls-get-inputs modsubdecls)
  10222. (verilog-subdecls-get-inouts modsubdecls)))))
  10223. (when regexp
  10224. (setq sig-list (verilog-signals-matching-regexp
  10225. sig-list regexp)))
  10226. (setq sig-list (verilog-signals-not-matching-regexp
  10227. sig-list verilog-auto-output-ignore-regexp))
  10228. (forward-line 1)
  10229. (when v2k (verilog-repair-open-comma))
  10230. (when sig-list
  10231. (verilog-insert-indent "// Beginning of automatic outputs (from unused autoinst outputs)\n")
  10232. (verilog-insert-definition modi sig-list "output" indent-pt v2k)
  10233. (verilog-insert-indent "// End of automatics\n"))
  10234. (when v2k (verilog-repair-close-comma)))))
  10235. (defun verilog-auto-output-every ()
  10236. "Expand AUTOOUTPUTEVERY statements, as part of \\[verilog-auto].
  10237. Make output statements for any signals that aren't primary inputs or
  10238. outputs already. This makes every signal in the design a output. This is
  10239. useful to get Synopsys to preserve every signal in the design, since it
  10240. won't optimize away the outputs.
  10241. An example:
  10242. module ExampOutputEvery (o,i,tempa,tempb);
  10243. output o;
  10244. input i;
  10245. /*AUTOOUTPUTEVERY*/
  10246. wire tempa = i;
  10247. wire tempb = tempa;
  10248. wire o = tempb;
  10249. endmodule
  10250. Typing \\[verilog-auto] will make this into:
  10251. module ExampOutputEvery (o,i,tempa,tempb);
  10252. output o;
  10253. input i;
  10254. /*AUTOOUTPUTEVERY*/
  10255. // Beginning of automatic outputs (every signal)
  10256. output tempb;
  10257. output tempa;
  10258. // End of automatics
  10259. wire tempa = i;
  10260. wire tempb = tempa;
  10261. wire o = tempb;
  10262. endmodule"
  10263. (save-excursion
  10264. ;;Point must be at insertion point
  10265. (let* ((indent-pt (current-indentation))
  10266. (v2k (verilog-in-paren-quick))
  10267. (modi (verilog-modi-current))
  10268. (moddecls (verilog-modi-get-decls modi))
  10269. (sig-list (verilog-signals-combine-bus
  10270. (verilog-signals-not-in
  10271. (verilog-decls-get-signals moddecls)
  10272. (verilog-decls-get-ports moddecls)))))
  10273. (forward-line 1)
  10274. (when v2k (verilog-repair-open-comma))
  10275. (when sig-list
  10276. (verilog-insert-indent "// Beginning of automatic outputs (every signal)\n")
  10277. (verilog-insert-definition modi sig-list "output" indent-pt v2k)
  10278. (verilog-insert-indent "// End of automatics\n"))
  10279. (when v2k (verilog-repair-close-comma)))))
  10280. (defun verilog-auto-input (&optional with-params)
  10281. "Expand AUTOINPUT statements, as part of \\[verilog-auto].
  10282. Make input statements for any input signal into an /*AUTOINST*/ that
  10283. isn't declared elsewhere inside the module. This is useful for modules which
  10284. only instantiate other modules.
  10285. Limitations:
  10286. This ONLY detects outputs of AUTOINSTants (see `verilog-read-sub-decls').
  10287. If placed inside the parenthesis of a module declaration, it creates
  10288. Verilog 2001 style, else uses Verilog 1995 style.
  10289. If any concatenation, or bit-subscripts are missing in the AUTOINSTant's
  10290. instantiation, all bets are off. (For example due to a AUTO_TEMPLATE).
  10291. Typedefs must match `verilog-typedef-regexp', which is disabled by default.
  10292. Signals matching `verilog-auto-input-ignore-regexp' are not included.
  10293. An example (see `verilog-auto-inst' for what else is going on here):
  10294. module ExampInput (ov,i);
  10295. output [31:0] ov;
  10296. /*AUTOINPUT*/
  10297. InstModule instName
  10298. (/*AUTOINST*/);
  10299. endmodule
  10300. Typing \\[verilog-auto] will make this into:
  10301. module ExampInput (ov,i);
  10302. output [31:0] ov;
  10303. /*AUTOINPUT*/
  10304. // Beginning of automatic inputs (from unused autoinst inputs)
  10305. input i; // From inst of inst.v
  10306. // End of automatics
  10307. InstModule instName
  10308. (/*AUTOINST*/
  10309. // Outputs
  10310. .ov (ov[31:0]),
  10311. // Inputs
  10312. .i (i));
  10313. endmodule
  10314. You may also provide an optional regular expression, in which case only
  10315. signals matching the regular expression will be included. For example the
  10316. same expansion will result from only extracting inputs starting with i:
  10317. /*AUTOINPUT(\"^i\")*/"
  10318. (save-excursion
  10319. (let* ((indent-pt (current-indentation))
  10320. (regexp (and with-params
  10321. (nth 0 (verilog-read-auto-params 1))))
  10322. (v2k (verilog-in-paren-quick))
  10323. (modi (verilog-modi-current))
  10324. (moddecls (verilog-modi-get-decls modi))
  10325. (modsubdecls (verilog-modi-get-sub-decls modi))
  10326. (sig-list (verilog-signals-not-in
  10327. (verilog-subdecls-get-inputs modsubdecls)
  10328. (append (verilog-decls-get-inputs moddecls)
  10329. (verilog-decls-get-inouts moddecls)
  10330. (verilog-decls-get-vars moddecls)
  10331. (verilog-decls-get-consts moddecls)
  10332. (verilog-decls-get-gparams moddecls)
  10333. (verilog-subdecls-get-interfaced modsubdecls)
  10334. (verilog-subdecls-get-outputs modsubdecls)
  10335. (verilog-subdecls-get-inouts modsubdecls)))))
  10336. (when regexp
  10337. (setq sig-list (verilog-signals-matching-regexp
  10338. sig-list regexp)))
  10339. (setq sig-list (verilog-signals-not-matching-regexp
  10340. sig-list verilog-auto-input-ignore-regexp))
  10341. (forward-line 1)
  10342. (when v2k (verilog-repair-open-comma))
  10343. (when sig-list
  10344. (verilog-insert-indent "// Beginning of automatic inputs (from unused autoinst inputs)\n")
  10345. (verilog-insert-definition modi sig-list "input" indent-pt v2k)
  10346. (verilog-insert-indent "// End of automatics\n"))
  10347. (when v2k (verilog-repair-close-comma)))))
  10348. (defun verilog-auto-inout (&optional with-params)
  10349. "Expand AUTOINOUT statements, as part of \\[verilog-auto].
  10350. Make inout statements for any inout signal in an /*AUTOINST*/ that
  10351. isn't declared elsewhere inside the module.
  10352. Limitations:
  10353. This ONLY detects outputs of AUTOINSTants (see `verilog-read-sub-decls').
  10354. If placed inside the parenthesis of a module declaration, it creates
  10355. Verilog 2001 style, else uses Verilog 1995 style.
  10356. If any concatenation, or bit-subscripts are missing in the AUTOINSTant's
  10357. instantiation, all bets are off. (For example due to a AUTO_TEMPLATE).
  10358. Typedefs must match `verilog-typedef-regexp', which is disabled by default.
  10359. Signals matching `verilog-auto-inout-ignore-regexp' are not included.
  10360. An example (see `verilog-auto-inst' for what else is going on here):
  10361. module ExampInout (ov,i);
  10362. input i;
  10363. /*AUTOINOUT*/
  10364. InstModule instName
  10365. (/*AUTOINST*/);
  10366. endmodule
  10367. Typing \\[verilog-auto] will make this into:
  10368. module ExampInout (ov,i);
  10369. input i;
  10370. /*AUTOINOUT*/
  10371. // Beginning of automatic inouts (from unused autoinst inouts)
  10372. inout [31:0] ov; // From inst of inst.v
  10373. // End of automatics
  10374. InstModule instName
  10375. (/*AUTOINST*/
  10376. // Inouts
  10377. .ov (ov[31:0]),
  10378. // Inputs
  10379. .i (i));
  10380. endmodule
  10381. You may also provide an optional regular expression, in which case only
  10382. signals matching the regular expression will be included. For example the
  10383. same expansion will result from only extracting inouts starting with i:
  10384. /*AUTOINOUT(\"^i\")*/"
  10385. (save-excursion
  10386. ;; Point must be at insertion point.
  10387. (let* ((indent-pt (current-indentation))
  10388. (regexp (and with-params
  10389. (nth 0 (verilog-read-auto-params 1))))
  10390. (v2k (verilog-in-paren-quick))
  10391. (modi (verilog-modi-current))
  10392. (moddecls (verilog-modi-get-decls modi))
  10393. (modsubdecls (verilog-modi-get-sub-decls modi))
  10394. (sig-list (verilog-signals-not-in
  10395. (verilog-subdecls-get-inouts modsubdecls)
  10396. (append (verilog-decls-get-outputs moddecls)
  10397. (verilog-decls-get-inouts moddecls)
  10398. (verilog-decls-get-inputs moddecls)
  10399. (verilog-subdecls-get-inputs modsubdecls)
  10400. (verilog-subdecls-get-outputs modsubdecls)))))
  10401. (when regexp
  10402. (setq sig-list (verilog-signals-matching-regexp
  10403. sig-list regexp)))
  10404. (setq sig-list (verilog-signals-not-matching-regexp
  10405. sig-list verilog-auto-inout-ignore-regexp))
  10406. (forward-line 1)
  10407. (when v2k (verilog-repair-open-comma))
  10408. (when sig-list
  10409. (verilog-insert-indent "// Beginning of automatic inouts (from unused autoinst inouts)\n")
  10410. (verilog-insert-definition modi sig-list "inout" indent-pt v2k)
  10411. (verilog-insert-indent "// End of automatics\n"))
  10412. (when v2k (verilog-repair-close-comma)))))
  10413. (defun verilog-auto-inout-module (&optional complement all-in)
  10414. "Expand AUTOINOUTMODULE statements, as part of \\[verilog-auto].
  10415. Take input/output/inout statements from the specified module and insert
  10416. into the current module. This is useful for making null templates and
  10417. shell modules which need to have identical I/O with another module.
  10418. Any I/O which are already defined in this module will not be redefined.
  10419. For the complement of this function, see `verilog-auto-inout-comp',
  10420. and to make monitors with all inputs, see `verilog-auto-inout-in'.
  10421. Limitations:
  10422. If placed inside the parenthesis of a module declaration, it creates
  10423. Verilog 2001 style, else uses Verilog 1995 style.
  10424. Concatenation and outputting partial buses is not supported.
  10425. Module names must be resolvable to filenames. See `verilog-auto-inst'.
  10426. Signals are not inserted in the same order as in the original module,
  10427. though they will appear to be in the same order to a AUTOINST
  10428. instantiating either module.
  10429. An example:
  10430. module ExampShell (/*AUTOARG*/);
  10431. /*AUTOINOUTMODULE(\"ExampMain\")*/
  10432. endmodule
  10433. module ExampMain (i,o,io);
  10434. input i;
  10435. output o;
  10436. inout io;
  10437. endmodule
  10438. Typing \\[verilog-auto] will make this into:
  10439. module ExampShell (/*AUTOARG*/i,o,io);
  10440. /*AUTOINOUTMODULE(\"ExampMain\")*/
  10441. // Beginning of automatic in/out/inouts (from specific module)
  10442. output o;
  10443. inout io;
  10444. input i;
  10445. // End of automatics
  10446. endmodule
  10447. You may also provide an optional regular expression, in which case only
  10448. signals matching the regular expression will be included. For example the
  10449. same expansion will result from only extracting signals starting with i:
  10450. /*AUTOINOUTMODULE(\"ExampMain\",\"^i\")*/
  10451. You may also provide an optional second regular expression, in
  10452. which case only signals which have that pin direction and data
  10453. type will be included. This matches against everything before
  10454. the signal name in the declaration, for example against
  10455. \"input\" (single bit), \"output logic\" (direction and type) or
  10456. \"output [1:0]\" (direction and implicit type). You also
  10457. probably want to skip spaces in your regexp.
  10458. For example, the below will result in matching the output \"o\"
  10459. against the previous example's module:
  10460. /*AUTOINOUTMODULE(\"ExampMain\",\"\",\"^output.*\")*/"
  10461. (save-excursion
  10462. (let* ((params (verilog-read-auto-params 1 3))
  10463. (submod (nth 0 params))
  10464. (regexp (nth 1 params))
  10465. (direction-re (nth 2 params))
  10466. submodi)
  10467. ;; Lookup position, etc of co-module
  10468. ;; Note this may raise an error
  10469. (when (setq submodi (verilog-modi-lookup submod t))
  10470. (let* ((indent-pt (current-indentation))
  10471. (v2k (verilog-in-paren-quick))
  10472. (modi (verilog-modi-current))
  10473. (moddecls (verilog-modi-get-decls modi))
  10474. (submoddecls (verilog-modi-get-decls submodi))
  10475. (sig-list-i (verilog-signals-not-in
  10476. (cond (all-in
  10477. (append
  10478. (verilog-decls-get-inputs submoddecls)
  10479. (verilog-decls-get-inouts submoddecls)
  10480. (verilog-decls-get-outputs submoddecls)))
  10481. (complement
  10482. (verilog-decls-get-outputs submoddecls))
  10483. (t (verilog-decls-get-inputs submoddecls)))
  10484. (append (verilog-decls-get-inputs moddecls))))
  10485. (sig-list-o (verilog-signals-not-in
  10486. (cond (all-in nil)
  10487. (complement
  10488. (verilog-decls-get-inputs submoddecls))
  10489. (t (verilog-decls-get-outputs submoddecls)))
  10490. (append (verilog-decls-get-outputs moddecls))))
  10491. (sig-list-io (verilog-signals-not-in
  10492. (cond (all-in nil)
  10493. (t (verilog-decls-get-inouts submoddecls)))
  10494. (append (verilog-decls-get-inouts moddecls))))
  10495. (sig-list-if (verilog-signals-not-in
  10496. (verilog-decls-get-interfaces submoddecls)
  10497. (append (verilog-decls-get-interfaces moddecls)))))
  10498. (forward-line 1)
  10499. (setq sig-list-i (verilog-signals-matching-dir-re
  10500. (verilog-signals-matching-regexp sig-list-i regexp)
  10501. "input" direction-re)
  10502. sig-list-o (verilog-signals-matching-dir-re
  10503. (verilog-signals-matching-regexp sig-list-o regexp)
  10504. "output" direction-re)
  10505. sig-list-io (verilog-signals-matching-dir-re
  10506. (verilog-signals-matching-regexp sig-list-io regexp)
  10507. "inout" direction-re)
  10508. sig-list-if (verilog-signals-matching-dir-re
  10509. (verilog-signals-matching-regexp sig-list-if regexp)
  10510. "interface" direction-re))
  10511. (when v2k (verilog-repair-open-comma))
  10512. (when (or sig-list-i sig-list-o sig-list-io)
  10513. (verilog-insert-indent "// Beginning of automatic in/out/inouts (from specific module)\n")
  10514. ;; Don't sort them so a upper AUTOINST will match the main module
  10515. (verilog-insert-definition modi sig-list-o "output" indent-pt v2k t)
  10516. (verilog-insert-definition modi sig-list-io "inout" indent-pt v2k t)
  10517. (verilog-insert-definition modi sig-list-i "input" indent-pt v2k t)
  10518. (verilog-insert-definition modi sig-list-if "interface" indent-pt v2k t)
  10519. (verilog-insert-indent "// End of automatics\n"))
  10520. (when v2k (verilog-repair-close-comma)))))))
  10521. (defun verilog-auto-inout-comp ()
  10522. "Expand AUTOINOUTCOMP statements, as part of \\[verilog-auto].
  10523. Take input/output/inout statements from the specified module and
  10524. insert the inverse into the current module (inputs become outputs
  10525. and vice-versa.) This is useful for making test and stimulus
  10526. modules which need to have complementing I/O with another module.
  10527. Any I/O which are already defined in this module will not be
  10528. redefined. For the complement of this function, see
  10529. `verilog-auto-inout-module'.
  10530. Limitations:
  10531. If placed inside the parenthesis of a module declaration, it creates
  10532. Verilog 2001 style, else uses Verilog 1995 style.
  10533. Concatenation and outputting partial buses is not supported.
  10534. Module names must be resolvable to filenames. See `verilog-auto-inst'.
  10535. Signals are not inserted in the same order as in the original module,
  10536. though they will appear to be in the same order to a AUTOINST
  10537. instantiating either module.
  10538. An example:
  10539. module ExampShell (/*AUTOARG*/);
  10540. /*AUTOINOUTCOMP(\"ExampMain\")*/
  10541. endmodule
  10542. module ExampMain (i,o,io);
  10543. input i;
  10544. output o;
  10545. inout io;
  10546. endmodule
  10547. Typing \\[verilog-auto] will make this into:
  10548. module ExampShell (/*AUTOARG*/i,o,io);
  10549. /*AUTOINOUTCOMP(\"ExampMain\")*/
  10550. // Beginning of automatic in/out/inouts (from specific module)
  10551. output i;
  10552. inout io;
  10553. input o;
  10554. // End of automatics
  10555. endmodule
  10556. You may also provide an optional regular expression, in which case only
  10557. signals matching the regular expression will be included. For example the
  10558. same expansion will result from only extracting signals starting with i:
  10559. /*AUTOINOUTCOMP(\"ExampMain\",\"^i\")*/"
  10560. (verilog-auto-inout-module t nil))
  10561. (defun verilog-auto-inout-in ()
  10562. "Expand AUTOINOUTIN statements, as part of \\[verilog-auto].
  10563. Take input/output/inout statements from the specified module and
  10564. insert them as all inputs into the current module. This is
  10565. useful for making monitor modules which need to see all signals
  10566. as inputs based on another module. Any I/O which are already
  10567. defined in this module will not be redefined. See also
  10568. `verilog-auto-inout-module'.
  10569. Limitations:
  10570. If placed inside the parenthesis of a module declaration, it creates
  10571. Verilog 2001 style, else uses Verilog 1995 style.
  10572. Concatenation and outputting partial buses is not supported.
  10573. Module names must be resolvable to filenames. See `verilog-auto-inst'.
  10574. Signals are not inserted in the same order as in the original module,
  10575. though they will appear to be in the same order to a AUTOINST
  10576. instantiating either module.
  10577. An example:
  10578. module ExampShell (/*AUTOARG*/);
  10579. /*AUTOINOUTIN(\"ExampMain\")*/
  10580. endmodule
  10581. module ExampMain (i,o,io);
  10582. input i;
  10583. output o;
  10584. inout io;
  10585. endmodule
  10586. Typing \\[verilog-auto] will make this into:
  10587. module ExampShell (/*AUTOARG*/i,o,io);
  10588. /*AUTOINOUTIN(\"ExampMain\")*/
  10589. // Beginning of automatic in/out/inouts (from specific module)
  10590. input i;
  10591. input io;
  10592. input o;
  10593. // End of automatics
  10594. endmodule
  10595. You may also provide an optional regular expression, in which case only
  10596. signals matching the regular expression will be included. For example the
  10597. same expansion will result from only extracting signals starting with i:
  10598. /*AUTOINOUTCOMP(\"ExampMain\",\"^i\")*/"
  10599. (verilog-auto-inout-module nil t))
  10600. (defun verilog-auto-insert-lisp ()
  10601. "Expand AUTOINSERTLISP statements, as part of \\[verilog-auto].
  10602. The Lisp code provided is called, and the Lisp code calls
  10603. `insert` to insert text into the current file beginning on the
  10604. line after the AUTOINSERTLISP.
  10605. See also AUTO_LISP, which takes a Lisp expression and evaluates
  10606. it during `verilog-auto-inst' but does not insert any text.
  10607. An example:
  10608. module ExampInsertLisp;
  10609. /*AUTOINSERTLISP(my-verilog-insert-hello \"world\")*/
  10610. endmodule
  10611. // For this example we declare the function in the
  10612. // module's file itself. Often you'd define it instead
  10613. // in a site-start.el or .emacs file.
  10614. /*
  10615. Local Variables:
  10616. eval:
  10617. (defun my-verilog-insert-hello (who)
  10618. (insert (concat \"initial $write(\\\"hello \" who \"\\\");\\n\")))
  10619. End:
  10620. */
  10621. Typing \\[verilog-auto] will call my-verilog-insert-hello and
  10622. expand the above into:
  10623. // Beginning of automatic insert lisp
  10624. initial $write(\"hello world\");
  10625. // End of automatics
  10626. You can also call an external program and insert the returned
  10627. text:
  10628. /*AUTOINSERTLISP(insert (shell-command-to-string \"echo //hello\"))*/
  10629. // Beginning of automatic insert lisp
  10630. //hello
  10631. // End of automatics"
  10632. (save-excursion
  10633. ;; Point is at end of /*AUTO...*/
  10634. (let* ((indent-pt (current-indentation))
  10635. (cmd-end-pt (save-excursion (search-backward ")")
  10636. (forward-char)
  10637. (point))) ;; Closing paren
  10638. (cmd-beg-pt (save-excursion (goto-char cmd-end-pt)
  10639. (backward-sexp 1) ;; Inside comment
  10640. (point))) ;; Beginning paren
  10641. (cmd (buffer-substring-no-properties cmd-beg-pt cmd-end-pt)))
  10642. (forward-line 1)
  10643. ;; Some commands don't move point (like insert-file) so we always
  10644. ;; add the begin/end comments, then delete it if not needed
  10645. (verilog-insert-indent "// Beginning of automatic insert lisp\n")
  10646. (verilog-insert-indent "// End of automatics\n")
  10647. (forward-line -1)
  10648. (eval (read cmd))
  10649. (forward-line -1)
  10650. (setq verilog-scan-cache-tick nil) ;; Clear cache; inserted unknown text
  10651. (verilog-delete-empty-auto-pair))))
  10652. (defun verilog-auto-sense-sigs (moddecls presense-sigs)
  10653. "Return list of signals for current AUTOSENSE block."
  10654. (let* ((sigss (verilog-read-always-signals))
  10655. (sig-list (verilog-signals-not-params
  10656. (verilog-signals-not-in (verilog-alw-get-inputs sigss)
  10657. (append (and (not verilog-auto-sense-include-inputs)
  10658. (verilog-alw-get-outputs-delayed sigss))
  10659. (and (not verilog-auto-sense-include-inputs)
  10660. (verilog-alw-get-outputs-immediate sigss))
  10661. (verilog-alw-get-temps sigss)
  10662. (verilog-decls-get-consts moddecls)
  10663. (verilog-decls-get-gparams moddecls)
  10664. presense-sigs)))))
  10665. sig-list))
  10666. (defun verilog-auto-sense ()
  10667. "Expand AUTOSENSE statements, as part of \\[verilog-auto].
  10668. Replace the always (/*AUTOSENSE*/) sensitivity list (/*AS*/ for short)
  10669. with one automatically derived from all inputs declared in the always
  10670. statement. Signals that are generated within the same always block are NOT
  10671. placed into the sensitivity list (see `verilog-auto-sense-include-inputs').
  10672. Long lines are split based on the `fill-column', see \\[set-fill-column].
  10673. Limitations:
  10674. Verilog does not allow memories (multidimensional arrays) in sensitivity
  10675. lists. AUTOSENSE will thus exclude them, and add a /*memory or*/ comment.
  10676. Constant signals:
  10677. AUTOSENSE cannot always determine if a `define is a constant or a signal
  10678. (it could be in a include file for example). If a `define or other signal
  10679. is put into the AUTOSENSE list and is not desired, use the AUTO_CONSTANT
  10680. declaration anywhere in the module (parenthesis are required):
  10681. /* AUTO_CONSTANT ( `this_is_really_constant_dont_autosense_it ) */
  10682. Better yet, use a parameter, which will be understood to be constant
  10683. automatically.
  10684. OOps!
  10685. If AUTOSENSE makes a mistake, please report it. (First try putting
  10686. a begin/end after your always!) As a workaround, if a signal that
  10687. shouldn't be in the sensitivity list was, use the AUTO_CONSTANT above.
  10688. If a signal should be in the sensitivity list wasn't, placing it before
  10689. the /*AUTOSENSE*/ comment will prevent it from being deleted when the
  10690. autos are updated (or added if it occurs there already).
  10691. An example:
  10692. always @ (/*AS*/) begin
  10693. /* AUTO_CONSTANT (`constant) */
  10694. outin = ina | inb | `constant;
  10695. out = outin;
  10696. end
  10697. Typing \\[verilog-auto] will make this into:
  10698. always @ (/*AS*/ina or inb) begin
  10699. /* AUTO_CONSTANT (`constant) */
  10700. outin = ina | inb | `constant;
  10701. out = outin;
  10702. end
  10703. Note in Verilog 2001, you can often get the same result from the new @*
  10704. operator. (This was added to the language in part due to AUTOSENSE!)
  10705. always @* begin
  10706. outin = ina | inb | `constant;
  10707. out = outin;
  10708. end"
  10709. (save-excursion
  10710. ;; Find beginning
  10711. (let* ((start-pt (save-excursion
  10712. (verilog-re-search-backward-quick "(" nil t)
  10713. (point)))
  10714. (indent-pt (save-excursion
  10715. (or (and (goto-char start-pt) (1+ (current-column)))
  10716. (current-indentation))))
  10717. (modi (verilog-modi-current))
  10718. (moddecls (verilog-modi-get-decls modi))
  10719. (sig-memories (verilog-signals-memory
  10720. (verilog-decls-get-vars moddecls)))
  10721. sig-list not-first presense-sigs)
  10722. ;; Read signals in always, eliminate outputs from sense list
  10723. (setq presense-sigs (verilog-signals-from-signame
  10724. (save-excursion
  10725. (verilog-read-signals start-pt (point)))))
  10726. (setq sig-list (verilog-auto-sense-sigs moddecls presense-sigs))
  10727. (when sig-memories
  10728. (let ((tlen (length sig-list)))
  10729. (setq sig-list (verilog-signals-not-in sig-list sig-memories))
  10730. (if (not (eq tlen (length sig-list))) (verilog-insert " /*memory or*/ "))))
  10731. (if (and presense-sigs ;; Add a "or" if not "(.... or /*AUTOSENSE*/"
  10732. (save-excursion (goto-char (point))
  10733. (verilog-re-search-backward-quick "[a-zA-Z0-9$_.%`]+" start-pt t)
  10734. (verilog-re-search-backward-quick "\\s-" start-pt t)
  10735. (while (looking-at "\\s-`endif")
  10736. (verilog-re-search-backward-quick "[a-zA-Z0-9$_.%`]+" start-pt t)
  10737. (verilog-re-search-backward-quick "\\s-" start-pt t))
  10738. (not (looking-at "\\s-or\\b"))))
  10739. (setq not-first t))
  10740. (setq sig-list (sort sig-list `verilog-signals-sort-compare))
  10741. (while sig-list
  10742. (cond ((> (+ 4 (current-column) (length (verilog-sig-name (car sig-list)))) fill-column) ;+4 for width of or
  10743. (insert "\n")
  10744. (indent-to indent-pt)
  10745. (if not-first (insert "or ")))
  10746. (not-first (insert " or ")))
  10747. (insert (verilog-sig-name (car sig-list)))
  10748. (setq sig-list (cdr sig-list)
  10749. not-first t)))))
  10750. (defun verilog-auto-reset ()
  10751. "Expand AUTORESET statements, as part of \\[verilog-auto].
  10752. Replace the /*AUTORESET*/ comment with code to initialize all
  10753. registers set elsewhere in the always block.
  10754. Limitations:
  10755. AUTORESET will not clear memories.
  10756. AUTORESET uses <= if the signal has a <= assignment in the block,
  10757. else it uses =.
  10758. If <= is used, all = assigned variables are ignored if
  10759. `verilog-auto-reset-blocking-in-non' is nil; they are presumed
  10760. to be temporaries.
  10761. /*AUTORESET*/ presumes that any signals mentioned between the previous
  10762. begin/case/if statement and the AUTORESET comment are being reset manually
  10763. and should not be automatically reset. This includes omitting any signals
  10764. used on the right hand side of assignments.
  10765. By default, AUTORESET will include the width of the signal in the autos,
  10766. this is a recent change. To control this behavior, see
  10767. `verilog-auto-reset-widths'.
  10768. AUTORESET ties signals to deasserted, which is presumed to be zero.
  10769. Signals that match `verilog-active-low-regexp' will be deasserted by tying
  10770. them to a one.
  10771. An example:
  10772. always @(posedge clk or negedge reset_l) begin
  10773. if (!reset_l) begin
  10774. c <= 1;
  10775. /*AUTORESET*/
  10776. end
  10777. else begin
  10778. a <= in_a;
  10779. b <= in_b;
  10780. c <= in_c;
  10781. end
  10782. end
  10783. Typing \\[verilog-auto] will make this into:
  10784. always @(posedge core_clk or negedge reset_l) begin
  10785. if (!reset_l) begin
  10786. c <= 1;
  10787. /*AUTORESET*/
  10788. // Beginning of autoreset for uninitialized flops
  10789. a <= 0;
  10790. b = 0; // if `verilog-auto-reset-blocking-in-non' true
  10791. // End of automatics
  10792. end
  10793. else begin
  10794. a <= in_a;
  10795. b = in_b;
  10796. c <= in_c;
  10797. end
  10798. end"
  10799. (interactive)
  10800. (save-excursion
  10801. ;; Find beginning
  10802. (let* ((indent-pt (current-indentation))
  10803. (modi (verilog-modi-current))
  10804. (moddecls (verilog-modi-get-decls modi))
  10805. (all-list (verilog-decls-get-signals moddecls))
  10806. sigss sig-list dly-list prereset-sigs)
  10807. ;; Read signals in always, eliminate outputs from reset list
  10808. (setq prereset-sigs (verilog-signals-from-signame
  10809. (save-excursion
  10810. (verilog-read-signals
  10811. (save-excursion
  10812. (verilog-re-search-backward-quick "\\(@\\|\\<begin\\>\\|\\<if\\>\\|\\<case\\>\\)" nil t)
  10813. (point))
  10814. (point)))))
  10815. (save-excursion
  10816. (verilog-re-search-backward-quick "@" nil t)
  10817. (setq sigss (verilog-read-always-signals)))
  10818. (setq dly-list (verilog-alw-get-outputs-delayed sigss))
  10819. (setq sig-list (verilog-signals-not-in (append
  10820. (verilog-alw-get-outputs-delayed sigss)
  10821. (when (or (not (verilog-alw-get-uses-delayed sigss))
  10822. verilog-auto-reset-blocking-in-non)
  10823. (verilog-alw-get-outputs-immediate sigss)))
  10824. (append
  10825. (verilog-alw-get-temps sigss)
  10826. prereset-sigs)))
  10827. (setq sig-list (sort sig-list `verilog-signals-sort-compare))
  10828. (when sig-list
  10829. (insert "\n");
  10830. (verilog-insert-indent "// Beginning of autoreset for uninitialized flops\n");
  10831. (while sig-list
  10832. (let ((sig (or (assoc (verilog-sig-name (car sig-list)) all-list) ;; As sig-list has no widths
  10833. (car sig-list))))
  10834. (indent-to indent-pt)
  10835. (insert (verilog-sig-name sig)
  10836. (if (assoc (verilog-sig-name sig) dly-list)
  10837. (concat " <= " verilog-assignment-delay)
  10838. " = ")
  10839. (verilog-sig-tieoff sig (not verilog-auto-reset-widths))
  10840. ";\n")
  10841. (setq sig-list (cdr sig-list))))
  10842. (verilog-insert-indent "// End of automatics")))))
  10843. (defun verilog-auto-tieoff ()
  10844. "Expand AUTOTIEOFF statements, as part of \\[verilog-auto].
  10845. Replace the /*AUTOTIEOFF*/ comment with code to wire-tie all unused output
  10846. signals to deasserted.
  10847. /*AUTOTIEOFF*/ is used to make stub modules; modules that have the same
  10848. input/output list as another module, but no internals. Specifically, it
  10849. finds all outputs in the module, and if that input is not otherwise declared
  10850. as a register or wire, creates a tieoff.
  10851. AUTORESET ties signals to deasserted, which is presumed to be zero.
  10852. Signals that match `verilog-active-low-regexp' will be deasserted by tying
  10853. them to a one.
  10854. You can add signals you do not want included in AUTOTIEOFF with
  10855. `verilog-auto-tieoff-ignore-regexp'.
  10856. `verilog-auto-wire-type' may be used to change the datatype of
  10857. the declarations.
  10858. An example of making a stub for another module:
  10859. module ExampStub (/*AUTOINST*/);
  10860. /*AUTOINOUTMODULE(\"Foo\")*/
  10861. /*AUTOTIEOFF*/
  10862. // verilator lint_off UNUSED
  10863. wire _unused_ok = &{1'b0,
  10864. /*AUTOUNUSED*/
  10865. 1'b0};
  10866. // verilator lint_on UNUSED
  10867. endmodule
  10868. Typing \\[verilog-auto] will make this into:
  10869. module ExampStub (/*AUTOINST*/...);
  10870. /*AUTOINOUTMODULE(\"Foo\")*/
  10871. // Beginning of autotieoff
  10872. output [2:0] foo;
  10873. // End of automatics
  10874. /*AUTOTIEOFF*/
  10875. // Beginning of autotieoff
  10876. wire [2:0] foo = 3'b0;
  10877. // End of automatics
  10878. ...
  10879. endmodule"
  10880. (interactive)
  10881. (save-excursion
  10882. ;; Find beginning
  10883. (let* ((indent-pt (current-indentation))
  10884. (modi (verilog-modi-current))
  10885. (moddecls (verilog-modi-get-decls modi))
  10886. (modsubdecls (verilog-modi-get-sub-decls modi))
  10887. (sig-list (verilog-signals-not-in
  10888. (verilog-decls-get-outputs moddecls)
  10889. (append (verilog-decls-get-vars moddecls)
  10890. (verilog-decls-get-assigns moddecls)
  10891. (verilog-decls-get-consts moddecls)
  10892. (verilog-decls-get-gparams moddecls)
  10893. (verilog-subdecls-get-interfaced modsubdecls)
  10894. (verilog-subdecls-get-outputs modsubdecls)
  10895. (verilog-subdecls-get-inouts modsubdecls)))))
  10896. (setq sig-list (verilog-signals-not-matching-regexp
  10897. sig-list verilog-auto-tieoff-ignore-regexp))
  10898. (when sig-list
  10899. (forward-line 1)
  10900. (verilog-insert-indent "// Beginning of automatic tieoffs (for this module's unterminated outputs)\n")
  10901. (setq sig-list (sort (copy-alist sig-list) `verilog-signals-sort-compare))
  10902. (verilog-modi-cache-add-vars modi sig-list) ; Before we trash list
  10903. (while sig-list
  10904. (let ((sig (car sig-list)))
  10905. (cond ((equal verilog-auto-tieoff-declaration "assign")
  10906. (indent-to indent-pt)
  10907. (insert "assign " (verilog-sig-name sig)))
  10908. (t
  10909. (verilog-insert-one-definition sig verilog-auto-tieoff-declaration indent-pt)))
  10910. (indent-to (max 48 (+ indent-pt 40)))
  10911. (insert "= " (verilog-sig-tieoff sig)
  10912. ";\n")
  10913. (setq sig-list (cdr sig-list))))
  10914. (verilog-insert-indent "// End of automatics\n")))))
  10915. (defun verilog-auto-unused ()
  10916. "Expand AUTOUNUSED statements, as part of \\[verilog-auto].
  10917. Replace the /*AUTOUNUSED*/ comment with a comma separated list of all unused
  10918. input and inout signals.
  10919. /*AUTOUNUSED*/ is used to make stub modules; modules that have the same
  10920. input/output list as another module, but no internals. Specifically, it
  10921. finds all inputs and inouts in the module, and if that input is not otherwise
  10922. used, adds it to a comma separated list.
  10923. The comma separated list is intended to be used to create a _unused_ok
  10924. signal. Using the exact name \"_unused_ok\" for name of the temporary
  10925. signal is recommended as it will insure maximum forward compatibility, it
  10926. also makes lint warnings easy to understand; ignore any unused warnings
  10927. with \"unused\" in the signal name.
  10928. To reduce simulation time, the _unused_ok signal should be forced to a
  10929. constant to prevent wiggling. The easiest thing to do is use a
  10930. reduction-and with 1'b0 as shown.
  10931. This way all unused signals are in one place, making it convenient to add
  10932. your tool's specific pragmas around the assignment to disable any unused
  10933. warnings.
  10934. You can add signals you do not want included in AUTOUNUSED with
  10935. `verilog-auto-unused-ignore-regexp'.
  10936. An example of making a stub for another module:
  10937. module ExampStub (/*AUTOINST*/);
  10938. /*AUTOINOUTMODULE(\"Examp\")*/
  10939. /*AUTOTIEOFF*/
  10940. // verilator lint_off UNUSED
  10941. wire _unused_ok = &{1'b0,
  10942. /*AUTOUNUSED*/
  10943. 1'b0};
  10944. // verilator lint_on UNUSED
  10945. endmodule
  10946. Typing \\[verilog-auto] will make this into:
  10947. ...
  10948. // verilator lint_off UNUSED
  10949. wire _unused_ok = &{1'b0,
  10950. /*AUTOUNUSED*/
  10951. // Beginning of automatics
  10952. unused_input_a,
  10953. unused_input_b,
  10954. unused_input_c,
  10955. // End of automatics
  10956. 1'b0};
  10957. // verilator lint_on UNUSED
  10958. endmodule"
  10959. (interactive)
  10960. (save-excursion
  10961. ;; Find beginning
  10962. (let* ((indent-pt (progn (search-backward "/*") (current-column)))
  10963. (modi (verilog-modi-current))
  10964. (moddecls (verilog-modi-get-decls modi))
  10965. (modsubdecls (verilog-modi-get-sub-decls modi))
  10966. (sig-list (verilog-signals-not-in
  10967. (append (verilog-decls-get-inputs moddecls)
  10968. (verilog-decls-get-inouts moddecls))
  10969. (append (verilog-subdecls-get-inputs modsubdecls)
  10970. (verilog-subdecls-get-inouts modsubdecls)))))
  10971. (setq sig-list (verilog-signals-not-matching-regexp
  10972. sig-list verilog-auto-unused-ignore-regexp))
  10973. (when sig-list
  10974. (forward-line 1)
  10975. (verilog-insert-indent "// Beginning of automatic unused inputs\n")
  10976. (setq sig-list (sort (copy-alist sig-list) `verilog-signals-sort-compare))
  10977. (while sig-list
  10978. (let ((sig (car sig-list)))
  10979. (indent-to indent-pt)
  10980. (insert (verilog-sig-name sig) ",\n")
  10981. (setq sig-list (cdr sig-list))))
  10982. (verilog-insert-indent "// End of automatics\n")))))
  10983. (defun verilog-enum-ascii (signm elim-regexp)
  10984. "Convert an enum name SIGNM to an ascii string for insertion.
  10985. Remove user provided prefix ELIM-REGEXP."
  10986. (or elim-regexp (setq elim-regexp "_ DONT MATCH IT_"))
  10987. (let ((case-fold-search t))
  10988. ;; All upper becomes all lower for readability
  10989. (downcase (verilog-string-replace-matches elim-regexp "" nil nil signm))))
  10990. (defun verilog-auto-ascii-enum ()
  10991. "Expand AUTOASCIIENUM statements, as part of \\[verilog-auto].
  10992. Create a register to contain the ASCII decode of a enumerated signal type.
  10993. This will allow trace viewers to show the ASCII name of states.
  10994. First, parameters are built into a enumeration using the synopsys enum
  10995. comment. The comment must be between the keyword and the symbol.
  10996. \(Annoying, but that's what Synopsys's dc_shell FSM reader requires.)
  10997. Next, registers which that enum applies to are also tagged with the same
  10998. enum.
  10999. Finally, a AUTOASCIIENUM command is used.
  11000. The first parameter is the name of the signal to be decoded.
  11001. The second parameter is the name to store the ASCII code into. For the
  11002. signal foo, I suggest the name _foo__ascii, where the leading _ indicates
  11003. a signal that is just for simulation, and the magic characters _ascii
  11004. tell viewers like Dinotrace to display in ASCII format.
  11005. The third optional parameter is a string which will be removed
  11006. from the state names. It defaults to "" which removes nothing.
  11007. The fourth optional parameter is \"onehot\" to force one-hot
  11008. decoding. If unspecified, if and only if the first parameter
  11009. width is 2^(number of states in enum) and does NOT match the
  11010. width of the enum, the signal is assumed to be a one hot
  11011. decode. Otherwise, it's a normal encoded state vector.
  11012. `verilog-auto-wire-type' may be used to change the datatype of
  11013. the declarations.
  11014. An example:
  11015. //== State enumeration
  11016. parameter [2:0] // synopsys enum state_info
  11017. SM_IDLE = 3'b000,
  11018. SM_SEND = 3'b001,
  11019. SM_WAIT1 = 3'b010;
  11020. //== State variables
  11021. reg [2:0] /* synopsys enum state_info */
  11022. state_r; /* synopsys state_vector state_r */
  11023. reg [2:0] /* synopsys enum state_info */
  11024. state_e1;
  11025. /*AUTOASCIIENUM(\"state_r\", \"state_ascii_r\", \"SM_\")*/
  11026. Typing \\[verilog-auto] will make this into:
  11027. ... same front matter ...
  11028. /*AUTOASCIIENUM(\"state_r\", \"state_ascii_r\", \"SM_\")*/
  11029. // Beginning of automatic ASCII enum decoding
  11030. reg [39:0] state_ascii_r; // Decode of state_r
  11031. always @(state_r) begin
  11032. case ({state_r})
  11033. SM_IDLE: state_ascii_r = \"idle \";
  11034. SM_SEND: state_ascii_r = \"send \";
  11035. SM_WAIT1: state_ascii_r = \"wait1\";
  11036. default: state_ascii_r = \"%Erro\";
  11037. endcase
  11038. end
  11039. // End of automatics"
  11040. (save-excursion
  11041. (let* ((params (verilog-read-auto-params 2 4))
  11042. (undecode-name (nth 0 params))
  11043. (ascii-name (nth 1 params))
  11044. (elim-regexp (and (nth 2 params)
  11045. (not (equal (nth 2 params) ""))
  11046. (nth 2 params)))
  11047. (one-hot-flag (nth 3 params))
  11048. ;;
  11049. (indent-pt (current-indentation))
  11050. (modi (verilog-modi-current))
  11051. (moddecls (verilog-modi-get-decls modi))
  11052. ;;
  11053. (sig-list-consts (append (verilog-decls-get-consts moddecls)
  11054. (verilog-decls-get-gparams moddecls)))
  11055. (sig-list-all (append (verilog-decls-get-vars moddecls)
  11056. (verilog-decls-get-outputs moddecls)
  11057. (verilog-decls-get-inouts moddecls)
  11058. (verilog-decls-get-inputs moddecls)))
  11059. ;;
  11060. (undecode-sig (or (assoc undecode-name sig-list-all)
  11061. (error "%s: Signal %s not found in design" (verilog-point-text) undecode-name)))
  11062. (undecode-enum (or (verilog-sig-enum undecode-sig)
  11063. (error "%s: Signal %s does not have a enum tag" (verilog-point-text) undecode-name)))
  11064. ;;
  11065. (enum-sigs (verilog-signals-not-in
  11066. (or (verilog-signals-matching-enum sig-list-consts undecode-enum)
  11067. (error "%s: No state definitions for %s" (verilog-point-text) undecode-enum))
  11068. nil))
  11069. ;;
  11070. (one-hot (or
  11071. (string-match "onehot" (or one-hot-flag ""))
  11072. (and ;; width(enum) != width(sig)
  11073. (or (not (verilog-sig-bits (car enum-sigs)))
  11074. (not (equal (verilog-sig-width (car enum-sigs))
  11075. (verilog-sig-width undecode-sig))))
  11076. ;; count(enums) == width(sig)
  11077. (equal (number-to-string (length enum-sigs))
  11078. (verilog-sig-width undecode-sig)))))
  11079. (enum-chars 0)
  11080. (ascii-chars 0))
  11081. ;;
  11082. ;; Find number of ascii chars needed
  11083. (let ((tmp-sigs enum-sigs))
  11084. (while tmp-sigs
  11085. (setq enum-chars (max enum-chars (length (verilog-sig-name (car tmp-sigs))))
  11086. ascii-chars (max ascii-chars (length (verilog-enum-ascii
  11087. (verilog-sig-name (car tmp-sigs))
  11088. elim-regexp)))
  11089. tmp-sigs (cdr tmp-sigs))))
  11090. ;;
  11091. (forward-line 1)
  11092. (verilog-insert-indent "// Beginning of automatic ASCII enum decoding\n")
  11093. (let ((decode-sig-list (list (list ascii-name (format "[%d:0]" (- (* ascii-chars 8) 1))
  11094. (concat "Decode of " undecode-name) nil nil))))
  11095. (verilog-insert-definition modi decode-sig-list "reg" indent-pt nil))
  11096. ;;
  11097. (verilog-insert-indent "always @(" undecode-name ") begin\n")
  11098. (setq indent-pt (+ indent-pt verilog-indent-level))
  11099. (verilog-insert-indent "case ({" undecode-name "})\n")
  11100. (setq indent-pt (+ indent-pt verilog-case-indent))
  11101. ;;
  11102. (let ((tmp-sigs enum-sigs)
  11103. (chrfmt (format "%%-%ds %s = \"%%-%ds\";\n"
  11104. (+ (if one-hot 9 1) (max 8 enum-chars))
  11105. ascii-name ascii-chars))
  11106. (errname (substring "%Error" 0 (min 6 ascii-chars))))
  11107. (while tmp-sigs
  11108. (verilog-insert-indent
  11109. (concat
  11110. (format chrfmt
  11111. (concat (if one-hot "(")
  11112. ;; Use enum-sigs length as that's numeric
  11113. ;; verilog-sig-width undecode-sig might not be.
  11114. (if one-hot (number-to-string (length enum-sigs)))
  11115. ;; We use a shift instead of var[index]
  11116. ;; so that a non-one hot value will show as error.
  11117. (if one-hot "'b1<<")
  11118. (verilog-sig-name (car tmp-sigs))
  11119. (if one-hot ")") ":")
  11120. (verilog-enum-ascii (verilog-sig-name (car tmp-sigs))
  11121. elim-regexp))))
  11122. (setq tmp-sigs (cdr tmp-sigs)))
  11123. (verilog-insert-indent (format chrfmt "default:" errname)))
  11124. ;;
  11125. (setq indent-pt (- indent-pt verilog-case-indent))
  11126. (verilog-insert-indent "endcase\n")
  11127. (setq indent-pt (- indent-pt verilog-indent-level))
  11128. (verilog-insert-indent "end\n"
  11129. "// End of automatics\n"))))
  11130. (defun verilog-auto-templated-rel ()
  11131. "Replace Templated relative line numbers with absolute line numbers.
  11132. Internal use only. This hacks around the line numbers in AUTOINST Templates
  11133. being different from the final output's line numbering."
  11134. (let ((templateno 0) (template-line (list 0)) (buf-line 1))
  11135. ;; Find line number each template is on
  11136. ;; Count lines as we go, as otherwise it's O(n^2) to use count-lines
  11137. (goto-char (point-min))
  11138. (while (not (eobp))
  11139. (when (looking-at ".*AUTO_TEMPLATE")
  11140. (setq templateno (1+ templateno))
  11141. (setq template-line (cons buf-line template-line)))
  11142. (setq buf-line (1+ buf-line))
  11143. (forward-line 1))
  11144. (setq template-line (nreverse template-line))
  11145. ;; Replace T# L# with absolute line number
  11146. (goto-char (point-min))
  11147. (while (re-search-forward " Templated T\\([0-9]+\\) L\\([0-9]+\\)" nil t)
  11148. (replace-match
  11149. (concat " Templated "
  11150. (int-to-string (+ (nth (string-to-number (match-string 1))
  11151. template-line)
  11152. (string-to-number (match-string 2)))))
  11153. t t))))
  11154. ;;
  11155. ;; Auto top level
  11156. ;;
  11157. (defun verilog-auto (&optional inject) ; Use verilog-inject-auto instead of passing a arg
  11158. "Expand AUTO statements.
  11159. Look for any /*AUTO...*/ commands in the code, as used in
  11160. instantiations or argument headers. Update the list of signals
  11161. following the /*AUTO...*/ command.
  11162. Use \\[verilog-delete-auto] to remove the AUTOs.
  11163. Use \\[verilog-diff-auto] to see differences in AUTO expansion.
  11164. Use \\[verilog-inject-auto] to insert AUTOs for the first time.
  11165. Use \\[verilog-faq] for a pointer to frequently asked questions.
  11166. The hooks `verilog-before-auto-hook' and `verilog-auto-hook' are
  11167. called before and after this function, respectively.
  11168. For example:
  11169. module ModuleName (/*AUTOARG*/);
  11170. /*AUTOINPUT*/
  11171. /*AUTOOUTPUT*/
  11172. /*AUTOWIRE*/
  11173. /*AUTOREG*/
  11174. InstMod instName #(/*AUTOINSTPARAM*/) (/*AUTOINST*/);
  11175. You can also update the AUTOs from the shell using:
  11176. emacs --batch <filenames.v> -f verilog-batch-auto
  11177. Or fix indentation with:
  11178. emacs --batch <filenames.v> -f verilog-batch-indent
  11179. Likewise, you can delete or inject AUTOs with:
  11180. emacs --batch <filenames.v> -f verilog-batch-delete-auto
  11181. emacs --batch <filenames.v> -f verilog-batch-inject-auto
  11182. Or check if AUTOs have the same expansion
  11183. emacs --batch <filenames.v> -f verilog-batch-diff-auto
  11184. Using \\[describe-function], see also:
  11185. `verilog-auto-arg' for AUTOARG module instantiations
  11186. `verilog-auto-ascii-enum' for AUTOASCIIENUM enumeration decoding
  11187. `verilog-auto-inout-comp' for AUTOINOUTCOMP copy complemented i/o
  11188. `verilog-auto-inout-in' for AUTOINOUTIN inputs for all i/o
  11189. `verilog-auto-inout-module' for AUTOINOUTMODULE copying i/o from elsewhere
  11190. `verilog-auto-inout' for AUTOINOUT making hierarchy inouts
  11191. `verilog-auto-input' for AUTOINPUT making hierarchy inputs
  11192. `verilog-auto-insert-lisp' for AUTOINSERTLISP insert code from lisp function
  11193. `verilog-auto-inst' for AUTOINST instantiation pins
  11194. `verilog-auto-star' for AUTOINST .* SystemVerilog pins
  11195. `verilog-auto-inst-param' for AUTOINSTPARAM instantiation params
  11196. `verilog-auto-logic' for AUTOLOGIC declaring logic signals
  11197. `verilog-auto-output' for AUTOOUTPUT making hierarchy outputs
  11198. `verilog-auto-output-every' for AUTOOUTPUTEVERY making all outputs
  11199. `verilog-auto-reg' for AUTOREG registers
  11200. `verilog-auto-reg-input' for AUTOREGINPUT instantiation registers
  11201. `verilog-auto-reset' for AUTORESET flop resets
  11202. `verilog-auto-sense' for AUTOSENSE always sensitivity lists
  11203. `verilog-auto-tieoff' for AUTOTIEOFF output tieoffs
  11204. `verilog-auto-unused' for AUTOUNUSED unused inputs/inouts
  11205. `verilog-auto-wire' for AUTOWIRE instantiation wires
  11206. `verilog-read-defines' for reading `define values
  11207. `verilog-read-includes' for reading `includes
  11208. If you have bugs with these autos, please file an issue at
  11209. URL `http://www.veripool.org/verilog-mode' or contact the AUTOAUTHOR
  11210. Wilson Snyder (wsnyder@wsnyder.org)."
  11211. (interactive)
  11212. (unless noninteractive (message "Updating AUTOs..."))
  11213. (if (fboundp 'dinotrace-unannotate-all)
  11214. (dinotrace-unannotate-all))
  11215. (let ((oldbuf (if (not (buffer-modified-p))
  11216. (buffer-string)))
  11217. ;; Before version 20, match-string with font-lock returns a
  11218. ;; vector that is not equal to the string. IE if on "input"
  11219. ;; nil==(equal "input" (progn (looking-at "input") (match-string 0)))
  11220. (fontlocked (when (and (boundp 'font-lock-mode)
  11221. font-lock-mode)
  11222. (font-lock-mode 0)
  11223. t))
  11224. ;; Cache directories; we don't write new files, so can't change
  11225. (verilog-dir-cache-preserving t)
  11226. ;; Cache current module
  11227. (verilog-modi-cache-current-enable t)
  11228. (verilog-modi-cache-current-max (point-min)) ; IE it's invalid
  11229. verilog-modi-cache-current)
  11230. (unwind-protect
  11231. ;; Disable change hooks for speed
  11232. ;; This let can't be part of above let; must restore
  11233. ;; after-change-functions before font-lock resumes
  11234. (verilog-save-no-change-functions
  11235. (verilog-save-scan-cache
  11236. (save-excursion
  11237. ;; Wipe cache; otherwise if we AUTOed a block above this one,
  11238. ;; we'll misremember we have generated IOs, confusing AUTOOUTPUT
  11239. (setq verilog-modi-cache-list nil)
  11240. ;; If we're not in verilog-mode, change syntax table so parsing works right
  11241. (unless (eq major-mode `verilog-mode) (verilog-mode))
  11242. ;; Allow user to customize
  11243. (verilog-run-hooks 'verilog-before-auto-hook)
  11244. ;; Try to save the user from needing to revert-file to reread file local-variables
  11245. (verilog-auto-reeval-locals)
  11246. (verilog-read-auto-lisp-present)
  11247. (verilog-read-auto-lisp (point-min) (point-max))
  11248. (verilog-getopt-flags)
  11249. ;; From here on out, we can cache anything we read from disk
  11250. (verilog-preserve-dir-cache
  11251. ;; These two may seem obvious to do always, but on large includes it can be way too slow
  11252. (when verilog-auto-read-includes
  11253. (verilog-read-includes)
  11254. (verilog-read-defines nil nil t))
  11255. ;; This particular ordering is important
  11256. ;; INST: Lower modules correct, no internal dependencies, FIRST
  11257. (verilog-preserve-modi-cache
  11258. ;; Clear existing autos else we'll be screwed by existing ones
  11259. (verilog-delete-auto)
  11260. ;; Injection if appropriate
  11261. (when inject
  11262. (verilog-inject-inst)
  11263. (verilog-inject-sense)
  11264. (verilog-inject-arg))
  11265. ;;
  11266. ;; Do user inserts first, so their code can insert AUTOs
  11267. ;; We may provide a AUTOINSERTLISPLAST if another cleanup pass is needed
  11268. (verilog-auto-re-search-do "/\\*AUTOINSERTLISP(.*?)\\*/"
  11269. 'verilog-auto-insert-lisp)
  11270. ;; Expand instances before need the signals the instances input/output
  11271. (verilog-auto-re-search-do "/\\*AUTOINSTPARAM\\*/" 'verilog-auto-inst-param)
  11272. (verilog-auto-re-search-do "/\\*AUTOINST\\*/" 'verilog-auto-inst)
  11273. (verilog-auto-re-search-do "\\.\\*" 'verilog-auto-star)
  11274. ;; Doesn't matter when done, but combine it with a common changer
  11275. (verilog-auto-re-search-do "/\\*\\(AUTOSENSE\\|AS\\)\\*/" 'verilog-auto-sense)
  11276. (verilog-auto-re-search-do "/\\*AUTORESET\\*/" 'verilog-auto-reset)
  11277. ;; Must be done before autoin/out as creates a reg
  11278. (verilog-auto-re-search-do "/\\*AUTOASCIIENUM([^)]*)\\*/" 'verilog-auto-ascii-enum)
  11279. ;;
  11280. ;; first in/outs from other files
  11281. (verilog-auto-re-search-do "/\\*AUTOINOUTMODULE([^)]*)\\*/" 'verilog-auto-inout-module)
  11282. (verilog-auto-re-search-do "/\\*AUTOINOUTCOMP([^)]*)\\*/" 'verilog-auto-inout-comp)
  11283. (verilog-auto-re-search-do "/\\*AUTOINOUTIN([^)]*)\\*/" 'verilog-auto-inout-in)
  11284. ;; next in/outs which need previous sucked inputs first
  11285. (verilog-auto-re-search-do "/\\*AUTOOUTPUT\\((\"[^\"]*\")\\)\\*/"
  11286. (lambda () (verilog-auto-output t)))
  11287. (verilog-auto-re-search-do "/\\*AUTOOUTPUT\\*/" 'verilog-auto-output)
  11288. (verilog-auto-re-search-do "/\\*AUTOINPUT\\((\"[^\"]*\")\\)\\*/"
  11289. (lambda () (verilog-auto-input t)))
  11290. (verilog-auto-re-search-do "/\\*AUTOINPUT\\*/" 'verilog-auto-input)
  11291. (verilog-auto-re-search-do "/\\*AUTOINOUT\\((\"[^\"]*\")\\)\\*/"
  11292. (lambda () (verilog-auto-inout t)))
  11293. (verilog-auto-re-search-do "/\\*AUTOINOUT\\*/" 'verilog-auto-inout)
  11294. ;; Then tie off those in/outs
  11295. (verilog-auto-re-search-do "/\\*AUTOTIEOFF\\*/" 'verilog-auto-tieoff)
  11296. ;; Wires/regs must be after inputs/outputs
  11297. (verilog-auto-re-search-do "/\\*AUTOLOGIC\\*/" 'verilog-auto-logic)
  11298. (verilog-auto-re-search-do "/\\*AUTOWIRE\\*/" 'verilog-auto-wire)
  11299. (verilog-auto-re-search-do "/\\*AUTOREG\\*/" 'verilog-auto-reg)
  11300. (verilog-auto-re-search-do "/\\*AUTOREGINPUT\\*/" 'verilog-auto-reg-input)
  11301. ;; outputevery needs AUTOOUTPUTs done first
  11302. (verilog-auto-re-search-do "/\\*AUTOOUTPUTEVERY\\*/" 'verilog-auto-output-every)
  11303. ;; After we've created all new variables
  11304. (verilog-auto-re-search-do "/\\*AUTOUNUSED\\*/" 'verilog-auto-unused)
  11305. ;; Must be after all inputs outputs are generated
  11306. (verilog-auto-re-search-do "/\\*AUTOARG\\*/" 'verilog-auto-arg)
  11307. ;; Fix line numbers (comments only)
  11308. (when verilog-auto-inst-template-numbers
  11309. (verilog-auto-templated-rel))))
  11310. ;;
  11311. (verilog-run-hooks 'verilog-auto-hook)
  11312. ;;
  11313. (when verilog-auto-delete-trailing-whitespace
  11314. (verilog-delete-trailing-whitespace))
  11315. ;;
  11316. (set (make-local-variable 'verilog-auto-update-tick) (buffer-chars-modified-tick))
  11317. ;;
  11318. ;; If end result is same as when started, clear modified flag
  11319. (cond ((and oldbuf (equal oldbuf (buffer-string)))
  11320. (set-buffer-modified-p nil)
  11321. (unless noninteractive (message "Updating AUTOs...done (no changes)")))
  11322. (t (unless noninteractive (message "Updating AUTOs...done"))))
  11323. ;; End of after-change protection
  11324. )))
  11325. ;; Unwind forms
  11326. (progn
  11327. ;; Restore font-lock
  11328. (when fontlocked (font-lock-mode t))))))
  11329. ;;
  11330. ;; Skeleton based code insertion
  11331. ;;
  11332. (defvar verilog-template-map
  11333. (let ((map (make-sparse-keymap)))
  11334. (define-key map "a" 'verilog-sk-always)
  11335. (define-key map "b" 'verilog-sk-begin)
  11336. (define-key map "c" 'verilog-sk-case)
  11337. (define-key map "f" 'verilog-sk-for)
  11338. (define-key map "g" 'verilog-sk-generate)
  11339. (define-key map "h" 'verilog-sk-header)
  11340. (define-key map "i" 'verilog-sk-initial)
  11341. (define-key map "j" 'verilog-sk-fork)
  11342. (define-key map "m" 'verilog-sk-module)
  11343. (define-key map "o" 'verilog-sk-ovm-class)
  11344. (define-key map "p" 'verilog-sk-primitive)
  11345. (define-key map "r" 'verilog-sk-repeat)
  11346. (define-key map "s" 'verilog-sk-specify)
  11347. (define-key map "t" 'verilog-sk-task)
  11348. (define-key map "u" 'verilog-sk-uvm-class)
  11349. (define-key map "w" 'verilog-sk-while)
  11350. (define-key map "x" 'verilog-sk-casex)
  11351. (define-key map "z" 'verilog-sk-casez)
  11352. (define-key map "?" 'verilog-sk-if)
  11353. (define-key map ":" 'verilog-sk-else-if)
  11354. (define-key map "/" 'verilog-sk-comment)
  11355. (define-key map "A" 'verilog-sk-assign)
  11356. (define-key map "F" 'verilog-sk-function)
  11357. (define-key map "I" 'verilog-sk-input)
  11358. (define-key map "O" 'verilog-sk-output)
  11359. (define-key map "S" 'verilog-sk-state-machine)
  11360. (define-key map "=" 'verilog-sk-inout)
  11361. (define-key map "W" 'verilog-sk-wire)
  11362. (define-key map "R" 'verilog-sk-reg)
  11363. (define-key map "D" 'verilog-sk-define-signal)
  11364. map)
  11365. "Keymap used in Verilog mode for smart template operations.")
  11366. ;;
  11367. ;; Place the templates into Verilog Mode. They may be inserted under any key.
  11368. ;; C-c C-t will be the default. If you use templates a lot, you
  11369. ;; may want to consider moving the binding to another key in your .emacs
  11370. ;; file.
  11371. ;;
  11372. ;; Note \C-c and letter are reserved for users
  11373. (define-key verilog-mode-map "\C-c\C-t" verilog-template-map)
  11374. ;;; ---- statement skeletons ------------------------------------------
  11375. (define-skeleton verilog-sk-prompt-condition
  11376. "Prompt for the loop condition."
  11377. "[condition]: " str )
  11378. (define-skeleton verilog-sk-prompt-init
  11379. "Prompt for the loop init statement."
  11380. "[initial statement]: " str )
  11381. (define-skeleton verilog-sk-prompt-inc
  11382. "Prompt for the loop increment statement."
  11383. "[increment statement]: " str )
  11384. (define-skeleton verilog-sk-prompt-name
  11385. "Prompt for the name of something."
  11386. "[name]: " str)
  11387. (define-skeleton verilog-sk-prompt-clock
  11388. "Prompt for the name of something."
  11389. "name and edge of clock(s): " str)
  11390. (defvar verilog-sk-reset nil)
  11391. (defun verilog-sk-prompt-reset ()
  11392. "Prompt for the name of a state machine reset."
  11393. (setq verilog-sk-reset (read-string "name of reset: " "rst")))
  11394. (define-skeleton verilog-sk-prompt-state-selector
  11395. "Prompt for the name of a state machine selector."
  11396. "name of selector (eg {a,b,c,d}): " str )
  11397. (define-skeleton verilog-sk-prompt-output
  11398. "Prompt for the name of something."
  11399. "output: " str)
  11400. (define-skeleton verilog-sk-prompt-msb
  11401. "Prompt for most significant bit specification."
  11402. "msb:" str & ?: & '(verilog-sk-prompt-lsb) | -1 )
  11403. (define-skeleton verilog-sk-prompt-lsb
  11404. "Prompt for least significant bit specification."
  11405. "lsb:" str )
  11406. (defvar verilog-sk-p nil)
  11407. (define-skeleton verilog-sk-prompt-width
  11408. "Prompt for a width specification."
  11409. ()
  11410. (progn
  11411. (setq verilog-sk-p (point))
  11412. (verilog-sk-prompt-msb)
  11413. (if (> (point) verilog-sk-p) "] " " ")))
  11414. (defun verilog-sk-header ()
  11415. "Insert a descriptive header at the top of the file.
  11416. See also `verilog-header' for an alternative format."
  11417. (interactive "*")
  11418. (save-excursion
  11419. (goto-char (point-min))
  11420. (verilog-sk-header-tmpl)))
  11421. (define-skeleton verilog-sk-header-tmpl
  11422. "Insert a comment block containing the module title, author, etc."
  11423. "[Description]: "
  11424. "// -*- Mode: Verilog -*-"
  11425. "\n// Filename : " (buffer-name)
  11426. "\n// Description : " str
  11427. "\n// Author : " (user-full-name)
  11428. "\n// Created On : " (current-time-string)
  11429. "\n// Last Modified By: " (user-full-name)
  11430. "\n// Last Modified On: " (current-time-string)
  11431. "\n// Update Count : 0"
  11432. "\n// Status : Unknown, Use with caution!"
  11433. "\n")
  11434. (define-skeleton verilog-sk-module
  11435. "Insert a module definition."
  11436. ()
  11437. > "module " '(verilog-sk-prompt-name) " (/*AUTOARG*/ ) ;" \n
  11438. > _ \n
  11439. > (- verilog-indent-level-behavioral) "endmodule" (progn (electric-verilog-terminate-line) nil))
  11440. ;;; ------------------------------------------------------------------------
  11441. ;;; Define a default OVM class, with macros and new()
  11442. ;;; ------------------------------------------------------------------------
  11443. (define-skeleton verilog-sk-ovm-class
  11444. "Insert a class definition"
  11445. ()
  11446. > "class " (setq name (skeleton-read "Name: ")) " extends " (skeleton-read "Extends: ") ";" \n
  11447. > _ \n
  11448. > "`ovm_object_utils_begin(" name ")" \n
  11449. > (- verilog-indent-level) " `ovm_object_utils_end" \n
  11450. > _ \n
  11451. > "function new(name=\"" name "\");" \n
  11452. > "super.new(name);" \n
  11453. > (- verilog-indent-level) "endfunction" \n
  11454. > _ \n
  11455. > "endclass" (progn (electric-verilog-terminate-line) nil))
  11456. (define-skeleton verilog-sk-uvm-class
  11457. "Insert a class definition"
  11458. ()
  11459. > "class " (setq name (skeleton-read "Name: ")) " extends " (skeleton-read "Extends: ") ";" \n
  11460. > _ \n
  11461. > "`uvm_object_utils_begin(" name ")" \n
  11462. > (- verilog-indent-level) " `uvm_object_utils_end" \n
  11463. > _ \n
  11464. > "function new(name=\"" name "\");" \n
  11465. > "super.new(name);" \n
  11466. > (- verilog-indent-level) "endfunction" \n
  11467. > _ \n
  11468. > "endclass" (progn (electric-verilog-terminate-line) nil))
  11469. (define-skeleton verilog-sk-primitive
  11470. "Insert a task definition."
  11471. ()
  11472. > "primitive " '(verilog-sk-prompt-name) " ( " '(verilog-sk-prompt-output) ("input:" ", " str ) " );"\n
  11473. > _ \n
  11474. > (- verilog-indent-level-behavioral) "endprimitive" (progn (electric-verilog-terminate-line) nil))
  11475. (define-skeleton verilog-sk-task
  11476. "Insert a task definition."
  11477. ()
  11478. > "task " '(verilog-sk-prompt-name) & ?; \n
  11479. > _ \n
  11480. > "begin" \n
  11481. > \n
  11482. > (- verilog-indent-level-behavioral) "end" \n
  11483. > (- verilog-indent-level-behavioral) "endtask" (progn (electric-verilog-terminate-line) nil))
  11484. (define-skeleton verilog-sk-function
  11485. "Insert a function definition."
  11486. ()
  11487. > "function [" '(verilog-sk-prompt-width) | -1 '(verilog-sk-prompt-name) ?; \n
  11488. > _ \n
  11489. > "begin" \n
  11490. > \n
  11491. > (- verilog-indent-level-behavioral) "end" \n
  11492. > (- verilog-indent-level-behavioral) "endfunction" (progn (electric-verilog-terminate-line) nil))
  11493. (define-skeleton verilog-sk-always
  11494. "Insert always block. Uses the minibuffer to prompt
  11495. for sensitivity list."
  11496. ()
  11497. > "always @ ( /*AUTOSENSE*/ ) begin\n"
  11498. > _ \n
  11499. > (- verilog-indent-level-behavioral) "end" \n >
  11500. )
  11501. (define-skeleton verilog-sk-initial
  11502. "Insert an initial block."
  11503. ()
  11504. > "initial begin\n"
  11505. > _ \n
  11506. > (- verilog-indent-level-behavioral) "end" \n > )
  11507. (define-skeleton verilog-sk-specify
  11508. "Insert specify block. "
  11509. ()
  11510. > "specify\n"
  11511. > _ \n
  11512. > (- verilog-indent-level-behavioral) "endspecify" \n > )
  11513. (define-skeleton verilog-sk-generate
  11514. "Insert generate block. "
  11515. ()
  11516. > "generate\n"
  11517. > _ \n
  11518. > (- verilog-indent-level-behavioral) "endgenerate" \n > )
  11519. (define-skeleton verilog-sk-begin
  11520. "Insert begin end block. Uses the minibuffer to prompt for name."
  11521. ()
  11522. > "begin" '(verilog-sk-prompt-name) \n
  11523. > _ \n
  11524. > (- verilog-indent-level-behavioral) "end"
  11525. )
  11526. (define-skeleton verilog-sk-fork
  11527. "Insert a fork join block."
  11528. ()
  11529. > "fork\n"
  11530. > "begin" \n
  11531. > _ \n
  11532. > (- verilog-indent-level-behavioral) "end" \n
  11533. > "begin" \n
  11534. > \n
  11535. > (- verilog-indent-level-behavioral) "end" \n
  11536. > (- verilog-indent-level-behavioral) "join" \n
  11537. > )
  11538. (define-skeleton verilog-sk-case
  11539. "Build skeleton case statement, prompting for the selector expression,
  11540. and the case items."
  11541. "[selector expression]: "
  11542. > "case (" str ") " \n
  11543. > ("case selector: " str ": begin" \n > _ \n > (- verilog-indent-level-behavioral) "end" \n > )
  11544. resume: > (- verilog-case-indent) "endcase" (progn (electric-verilog-terminate-line) nil))
  11545. (define-skeleton verilog-sk-casex
  11546. "Build skeleton casex statement, prompting for the selector expression,
  11547. and the case items."
  11548. "[selector expression]: "
  11549. > "casex (" str ") " \n
  11550. > ("case selector: " str ": begin" \n > _ \n > (- verilog-indent-level-behavioral) "end" \n > )
  11551. resume: > (- verilog-case-indent) "endcase" (progn (electric-verilog-terminate-line) nil))
  11552. (define-skeleton verilog-sk-casez
  11553. "Build skeleton casez statement, prompting for the selector expression,
  11554. and the case items."
  11555. "[selector expression]: "
  11556. > "casez (" str ") " \n
  11557. > ("case selector: " str ": begin" \n > _ \n > (- verilog-indent-level-behavioral) "end" \n > )
  11558. resume: > (- verilog-case-indent) "endcase" (progn (electric-verilog-terminate-line) nil))
  11559. (define-skeleton verilog-sk-if
  11560. "Insert a skeleton if statement."
  11561. > "if (" '(verilog-sk-prompt-condition) & ")" " begin" \n
  11562. > _ \n
  11563. > (- verilog-indent-level-behavioral) "end " \n )
  11564. (define-skeleton verilog-sk-else-if
  11565. "Insert a skeleton else if statement."
  11566. > (verilog-indent-line) "else if ("
  11567. (progn (setq verilog-sk-p (point)) nil) '(verilog-sk-prompt-condition) (if (> (point) verilog-sk-p) ") " -1 ) & " begin" \n
  11568. > _ \n
  11569. > "end" (progn (electric-verilog-terminate-line) nil))
  11570. (define-skeleton verilog-sk-datadef
  11571. "Common routine to get data definition."
  11572. ()
  11573. '(verilog-sk-prompt-width) | -1 ("name (RET to end):" str ", ") -2 ";" \n)
  11574. (define-skeleton verilog-sk-input
  11575. "Insert an input definition."
  11576. ()
  11577. > "input [" '(verilog-sk-datadef))
  11578. (define-skeleton verilog-sk-output
  11579. "Insert an output definition."
  11580. ()
  11581. > "output [" '(verilog-sk-datadef))
  11582. (define-skeleton verilog-sk-inout
  11583. "Insert an inout definition."
  11584. ()
  11585. > "inout [" '(verilog-sk-datadef))
  11586. (defvar verilog-sk-signal nil)
  11587. (define-skeleton verilog-sk-def-reg
  11588. "Insert a reg definition."
  11589. ()
  11590. > "reg [" '(verilog-sk-prompt-width) | -1 verilog-sk-signal ";" \n (verilog-pretty-declarations) )
  11591. (defun verilog-sk-define-signal ()
  11592. "Insert a definition of signal under point at top of module."
  11593. (interactive "*")
  11594. (let* ((sig-re "[a-zA-Z0-9_]*")
  11595. (v1 (buffer-substring
  11596. (save-excursion
  11597. (skip-chars-backward sig-re)
  11598. (point))
  11599. (save-excursion
  11600. (skip-chars-forward sig-re)
  11601. (point)))))
  11602. (if (not (member v1 verilog-keywords))
  11603. (save-excursion
  11604. (setq verilog-sk-signal v1)
  11605. (verilog-beg-of-defun)
  11606. (verilog-end-of-statement)
  11607. (verilog-forward-syntactic-ws)
  11608. (verilog-sk-def-reg)
  11609. (message "signal at point is %s" v1))
  11610. (message "object at point (%s) is a keyword" v1))))
  11611. (define-skeleton verilog-sk-wire
  11612. "Insert a wire definition."
  11613. ()
  11614. > "wire [" '(verilog-sk-datadef))
  11615. (define-skeleton verilog-sk-reg
  11616. "Insert a reg definition."
  11617. ()
  11618. > "reg [" '(verilog-sk-datadef))
  11619. (define-skeleton verilog-sk-assign
  11620. "Insert a skeleton assign statement."
  11621. ()
  11622. > "assign " '(verilog-sk-prompt-name) " = " _ ";" \n)
  11623. (define-skeleton verilog-sk-while
  11624. "Insert a skeleton while loop statement."
  11625. ()
  11626. > "while (" '(verilog-sk-prompt-condition) ") begin" \n
  11627. > _ \n
  11628. > (- verilog-indent-level-behavioral) "end " (progn (electric-verilog-terminate-line) nil))
  11629. (define-skeleton verilog-sk-repeat
  11630. "Insert a skeleton repeat loop statement."
  11631. ()
  11632. > "repeat (" '(verilog-sk-prompt-condition) ") begin" \n
  11633. > _ \n
  11634. > (- verilog-indent-level-behavioral) "end " (progn (electric-verilog-terminate-line) nil))
  11635. (define-skeleton verilog-sk-for
  11636. "Insert a skeleton while loop statement."
  11637. ()
  11638. > "for ("
  11639. '(verilog-sk-prompt-init) "; "
  11640. '(verilog-sk-prompt-condition) "; "
  11641. '(verilog-sk-prompt-inc)
  11642. ") begin" \n
  11643. > _ \n
  11644. > (- verilog-indent-level-behavioral) "end " (progn (electric-verilog-terminate-line) nil))
  11645. (define-skeleton verilog-sk-comment
  11646. "Inserts three comment lines, making a display comment."
  11647. ()
  11648. > "/*\n"
  11649. > "* " _ \n
  11650. > "*/")
  11651. (define-skeleton verilog-sk-state-machine
  11652. "Insert a state machine definition."
  11653. "Name of state variable: "
  11654. '(setq input "state")
  11655. > "// State registers for " str | -23 \n
  11656. '(setq verilog-sk-state str)
  11657. > "reg [" '(verilog-sk-prompt-width) | -1 verilog-sk-state ", next_" verilog-sk-state ?; \n
  11658. '(setq input nil)
  11659. > \n
  11660. > "// State FF for " verilog-sk-state \n
  11661. > "always @ ( " (read-string "clock:" "posedge clk") " or " (verilog-sk-prompt-reset) " ) begin" \n
  11662. > "if ( " verilog-sk-reset " ) " verilog-sk-state " = 0; else" \n
  11663. > verilog-sk-state " = next_" verilog-sk-state ?; \n
  11664. > (- verilog-indent-level-behavioral) "end" (progn (electric-verilog-terminate-line) nil)
  11665. > \n
  11666. > "// Next State Logic for " verilog-sk-state \n
  11667. > "always @ ( /*AUTOSENSE*/ ) begin\n"
  11668. > "case (" '(verilog-sk-prompt-state-selector) ") " \n
  11669. > ("case selector: " str ": begin" \n > "next_" verilog-sk-state " = " _ ";" \n > (- verilog-indent-level-behavioral) "end" \n )
  11670. resume: > (- verilog-case-indent) "endcase" (progn (electric-verilog-terminate-line) nil)
  11671. > (- verilog-indent-level-behavioral) "end" (progn (electric-verilog-terminate-line) nil))
  11672. ;;
  11673. ;; Include file loading with mouse/return event
  11674. ;;
  11675. ;; idea & first impl.: M. Rouat (eldo-mode.el)
  11676. ;; second (emacs/xemacs) impl.: G. Van der Plas (spice-mode.el)
  11677. (if (featurep 'xemacs)
  11678. (require 'overlay))
  11679. (defconst verilog-include-file-regexp
  11680. "^`include\\s-+\"\\([^\n\"]*\\)\""
  11681. "Regexp that matches the include file.")
  11682. (defvar verilog-mode-mouse-map
  11683. (let ((map (make-sparse-keymap))) ; as described in info pages, make a map
  11684. (set-keymap-parent map verilog-mode-map)
  11685. ;; mouse button bindings
  11686. (define-key map "\r" 'verilog-load-file-at-point)
  11687. (if (featurep 'xemacs)
  11688. (define-key map 'button2 'verilog-load-file-at-mouse);ffap-at-mouse ?
  11689. (define-key map [mouse-2] 'verilog-load-file-at-mouse))
  11690. (if (featurep 'xemacs)
  11691. (define-key map 'Sh-button2 'mouse-yank) ; you wanna paste don't you ?
  11692. (define-key map [S-mouse-2] 'mouse-yank-at-click))
  11693. map)
  11694. "Map containing mouse bindings for `verilog-mode'.")
  11695. (defun verilog-highlight-region (beg end old-len)
  11696. "Colorize included files and modules in the (changed?) region.
  11697. Clicking on the middle-mouse button loads them in a buffer (as in dired)."
  11698. (when (or verilog-highlight-includes
  11699. verilog-highlight-modules)
  11700. (save-excursion
  11701. (save-match-data ;; A query-replace may call this function - do not disturb
  11702. (verilog-save-buffer-state
  11703. (verilog-save-scan-cache
  11704. (let (end-point)
  11705. (goto-char end)
  11706. (setq end-point (point-at-eol))
  11707. (goto-char beg)
  11708. (beginning-of-line) ; scan entire line
  11709. ;; delete overlays existing on this line
  11710. (let ((overlays (overlays-in (point) end-point)))
  11711. (while overlays
  11712. (if (and
  11713. (overlay-get (car overlays) 'detachable)
  11714. (or (overlay-get (car overlays) 'verilog-include-file)
  11715. (overlay-get (car overlays) 'verilog-inst-module)))
  11716. (delete-overlay (car overlays)))
  11717. (setq overlays (cdr overlays))))
  11718. ;;
  11719. ;; make new include overlays
  11720. (when verilog-highlight-includes
  11721. (while (search-forward-regexp verilog-include-file-regexp end-point t)
  11722. (goto-char (match-beginning 1))
  11723. (let ((ov (make-overlay (match-beginning 1) (match-end 1))))
  11724. (overlay-put ov 'start-closed 't)
  11725. (overlay-put ov 'end-closed 't)
  11726. (overlay-put ov 'evaporate 't)
  11727. (overlay-put ov 'verilog-include-file 't)
  11728. (overlay-put ov 'mouse-face 'highlight)
  11729. (overlay-put ov 'local-map verilog-mode-mouse-map))))
  11730. ;;
  11731. ;; make new module overlays
  11732. (goto-char beg)
  11733. ;; This scanner is syntax-fragile, so don't get bent
  11734. (when verilog-highlight-modules
  11735. (condition-case nil
  11736. (while (verilog-re-search-forward-quick "\\(/\\*AUTOINST\\*/\\|\\.\\*\\)" end-point t)
  11737. (save-excursion
  11738. (goto-char (match-beginning 0))
  11739. (unless (verilog-inside-comment-or-string-p)
  11740. (verilog-read-inst-module-matcher) ;; sets match 0
  11741. (let* ((ov (make-overlay (match-beginning 0) (match-end 0))))
  11742. (overlay-put ov 'start-closed 't)
  11743. (overlay-put ov 'end-closed 't)
  11744. (overlay-put ov 'evaporate 't)
  11745. (overlay-put ov 'verilog-inst-module 't)
  11746. (overlay-put ov 'mouse-face 'highlight)
  11747. (overlay-put ov 'local-map verilog-mode-mouse-map)))))
  11748. (error nil)))
  11749. ;;
  11750. ;; Future highlights:
  11751. ;; variables - make an Occur buffer of where referenced
  11752. ;; pins - make an Occur buffer of the sig in the declaration module
  11753. )))))))
  11754. (defun verilog-highlight-buffer ()
  11755. "Colorize included files and modules across the whole buffer."
  11756. ;; Invoked via verilog-mode calling font-lock then `font-lock-mode-hook'
  11757. (interactive)
  11758. ;; delete and remake overlays
  11759. (verilog-highlight-region (point-min) (point-max) nil))
  11760. ;; Deprecated, but was interactive, so we'll keep it around
  11761. (defalias 'verilog-colorize-include-files-buffer 'verilog-highlight-buffer)
  11762. ;; ffap-at-mouse isn't useful for Verilog mode. It uses library paths.
  11763. ;; so define this function to do more or less the same as ffap-at-mouse
  11764. ;; but first resolve filename...
  11765. (defun verilog-load-file-at-mouse (event)
  11766. "Load file under button 2 click's EVENT.
  11767. Files are checked based on `verilog-library-flags'."
  11768. (interactive "@e")
  11769. (save-excursion ;; implement a Verilog specific ffap-at-mouse
  11770. (mouse-set-point event)
  11771. (verilog-load-file-at-point t)))
  11772. ;; ffap isn't usable for Verilog mode. It uses library paths.
  11773. ;; so define this function to do more or less the same as ffap
  11774. ;; but first resolve filename...
  11775. (defun verilog-load-file-at-point (&optional warn)
  11776. "Load file under point.
  11777. If WARN, throw warning if not found.
  11778. Files are checked based on `verilog-library-flags'."
  11779. (interactive)
  11780. (save-excursion ;; implement a Verilog specific ffap
  11781. (let ((overlays (overlays-in (point) (point)))
  11782. hit)
  11783. (while (and overlays (not hit))
  11784. (when (overlay-get (car overlays) 'verilog-inst-module)
  11785. (verilog-goto-defun-file (buffer-substring
  11786. (overlay-start (car overlays))
  11787. (overlay-end (car overlays))))
  11788. (setq hit t))
  11789. (setq overlays (cdr overlays)))
  11790. ;; Include?
  11791. (beginning-of-line)
  11792. (when (and (not hit)
  11793. (looking-at verilog-include-file-regexp))
  11794. (if (and (car (verilog-library-filenames
  11795. (match-string 1) (buffer-file-name)))
  11796. (file-readable-p (car (verilog-library-filenames
  11797. (match-string 1) (buffer-file-name)))))
  11798. (find-file (car (verilog-library-filenames
  11799. (match-string 1) (buffer-file-name))))
  11800. (when warn
  11801. (message
  11802. "File '%s' isn't readable, use shift-mouse2 to paste in this field"
  11803. (match-string 1))))))))
  11804. ;;
  11805. ;; Bug reporting
  11806. ;;
  11807. (defun verilog-faq ()
  11808. "Tell the user their current version, and where to get the FAQ etc."
  11809. (interactive)
  11810. (with-output-to-temp-buffer "*verilog-mode help*"
  11811. (princ (format "You are using verilog-mode %s\n" verilog-mode-version))
  11812. (princ "\n")
  11813. (princ "For new releases, see http://www.verilog.com\n")
  11814. (princ "\n")
  11815. (princ "For frequently asked questions, see http://www.veripool.org/verilog-mode-faq.html\n")
  11816. (princ "\n")
  11817. (princ "To submit a bug, use M-x verilog-submit-bug-report\n")
  11818. (princ "\n")))
  11819. (autoload 'reporter-submit-bug-report "reporter")
  11820. (defvar reporter-prompt-for-summary-p)
  11821. (defun verilog-submit-bug-report ()
  11822. "Submit via mail a bug report on verilog-mode.el."
  11823. (interactive)
  11824. (let ((reporter-prompt-for-summary-p t))
  11825. (reporter-submit-bug-report
  11826. "mac@verilog.com, wsnyder@wsnyder.org"
  11827. (concat "verilog-mode v" verilog-mode-version)
  11828. '(
  11829. verilog-active-low-regexp
  11830. verilog-align-ifelse
  11831. verilog-assignment-delay
  11832. verilog-auto-arg-sort
  11833. verilog-auto-endcomments
  11834. verilog-auto-hook
  11835. verilog-auto-ignore-concat
  11836. verilog-auto-indent-on-newline
  11837. verilog-auto-inout-ignore-regexp
  11838. verilog-auto-input-ignore-regexp
  11839. verilog-auto-inst-column
  11840. verilog-auto-inst-dot-name
  11841. verilog-auto-inst-param-value
  11842. verilog-auto-inst-template-numbers
  11843. verilog-auto-inst-vector
  11844. verilog-auto-lineup
  11845. verilog-auto-newline
  11846. verilog-auto-output-ignore-regexp
  11847. verilog-auto-read-includes
  11848. verilog-auto-reset-widths
  11849. verilog-auto-save-policy
  11850. verilog-auto-sense-defines-constant
  11851. verilog-auto-sense-include-inputs
  11852. verilog-auto-star-expand
  11853. verilog-auto-star-save
  11854. verilog-auto-unused-ignore-regexp
  11855. verilog-before-auto-hook
  11856. verilog-before-delete-auto-hook
  11857. verilog-before-getopt-flags-hook
  11858. verilog-case-indent
  11859. verilog-cexp-indent
  11860. verilog-compiler
  11861. verilog-coverage
  11862. verilog-delete-auto-hook
  11863. verilog-getopt-flags-hook
  11864. verilog-highlight-grouping-keywords
  11865. verilog-highlight-p1800-keywords
  11866. verilog-highlight-translate-off
  11867. verilog-indent-begin-after-if
  11868. verilog-indent-declaration-macros
  11869. verilog-indent-level
  11870. verilog-indent-level-behavioral
  11871. verilog-indent-level-declaration
  11872. verilog-indent-level-directive
  11873. verilog-indent-level-module
  11874. verilog-indent-lists
  11875. verilog-library-directories
  11876. verilog-library-extensions
  11877. verilog-library-files
  11878. verilog-library-flags
  11879. verilog-linter
  11880. verilog-minimum-comment-distance
  11881. verilog-mode-hook
  11882. verilog-preprocessor
  11883. verilog-simulator
  11884. verilog-tab-always-indent
  11885. verilog-tab-to-comment
  11886. verilog-typedef-regexp
  11887. )
  11888. nil nil
  11889. (concat "Hi Mac,
  11890. I want to report a bug.
  11891. Before I go further, I want to say that Verilog mode has changed my life.
  11892. I save so much time, my files are colored nicely, my co workers respect
  11893. my coding ability... until now. I'd really appreciate anything you
  11894. could do to help me out with this minor deficiency in the product.
  11895. I've taken a look at the Verilog-Mode FAQ at
  11896. http://www.veripool.org/verilog-mode-faq.html.
  11897. And, I've considered filing the bug on the issue tracker at
  11898. http://www.veripool.org/verilog-mode-bugs
  11899. since I realize that public bugs are easier for you to track,
  11900. and for others to search, but would prefer to email.
  11901. So, to reproduce the bug, start a fresh Emacs via " invocation-name "
  11902. -no-init-file -no-site-file'. In a new buffer, in Verilog mode, type
  11903. the code included below.
  11904. Given those lines, I expected [[Fill in here]] to happen;
  11905. but instead, [[Fill in here]] happens!.
  11906. == The code: =="))))
  11907. (provide 'verilog-mode)
  11908. ;; Local Variables:
  11909. ;; checkdoc-permit-comma-termination-flag:t
  11910. ;; checkdoc-force-docstrings-flag:nil
  11911. ;; End:
  11912. ;;; verilog-mode.el ends here