ppudump.pp 173 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436
  1. {
  2. Copyright (c) 1998-2020 by the FPC Development Team
  3. Dumps the contents of a FPC unit file (PPU File)
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************}
  16. program ppudump;
  17. {$i fpcdefs.inc}
  18. {$H+}
  19. {$packenum 1}
  20. {$define IN_PPUDUMP}
  21. uses
  22. { do NOT add symconst or globtype to make merging easier }
  23. { do include symconst and globtype now before splitting 2.5 PM 2011-06-15 }
  24. cutils,
  25. SysUtils,
  26. constexp,
  27. symconst,
  28. ppu,
  29. entfile,
  30. systems,
  31. cpuinfo,
  32. globals,
  33. globtype,
  34. widestr,
  35. tokens,
  36. version,
  37. ppuout,
  38. ppujson,
  39. ppuxml;
  40. const
  41. Title = 'PPU-Analyser';
  42. Copyright = 'Copyright (c) 1998-2020 by the Free Pascal Development Team';
  43. { verbosity }
  44. v_none = $0;
  45. v_header = $1;
  46. v_defs = $2;
  47. v_syms = $4;
  48. v_interface = $8;
  49. v_implementation = $10;
  50. // v_browser = $20;
  51. v_all = $ff;
  52. { not needed anymore $i systems.inc }
  53. { List of all supported cpus }
  54. const
  55. CpuTxt : array[tsystemcpu] of string[16]=
  56. (
  57. { 0 } 'none',
  58. { 1 } 'i386',
  59. { 2 } 'm68k',
  60. { 3 } 'alpha (obsolete)',
  61. { 4 } 'powerpc',
  62. { 5 } 'sparc',
  63. { 6 } 'vis (obsolete)',
  64. { 7 } 'ia64 (obsolete)',
  65. { 8 } 'x86_64',
  66. { 9 } 'mipseb',
  67. { 10 } 'arm',
  68. { 11 } 'powerpc64',
  69. { 12 } 'avr',
  70. { 13 } 'mipsel',
  71. { 14 } 'jvm',
  72. { 15 } 'i8086',
  73. { 16 } 'aarch64',
  74. { 17 } 'wasm32',
  75. { 18 } 'sparc64',
  76. { 19 } 'riscv32',
  77. { 20 } 'riscv64',
  78. { 21 } 'xtensa',
  79. { 22 } 'z80',
  80. { 23 } 'mips64',
  81. { 24 } 'mips64el',
  82. { 25 } 'loongarch64'
  83. );
  84. CpuHasController : array[tsystemcpu] of boolean =
  85. (
  86. { 0 } false {'none'},
  87. { 1 } false {'i386'},
  88. { 2 } false {'m68k'},
  89. { 3 } false {'alpha (obsolete)'},
  90. { 4 } false {'powerpc'},
  91. { 5 } false {'sparc'},
  92. { 6 } false {'vis (obsolete)'},
  93. { 7 } false {'ia64 (obsolete)'},
  94. { 8 } false {'x86_64'},
  95. { 9 } false {'mipseb'},
  96. { 10 } true {'arm'},
  97. { 11 } false {'powerpc64'},
  98. { 12 } true {'avr'},
  99. { 13 } true {'mipsel'},
  100. { 14 } false {'jvm'},
  101. { 15 } false {'i8086'},
  102. { 16 } false {'aarch64'},
  103. { 17 } false {'wasm32'},
  104. { 18 } false {'sparc64'},
  105. { 19 } false {'riscv32'},
  106. { 20 } false {'riscv64'},
  107. { 21 } true {'xtensa'},
  108. { 22 } true {'z80'},
  109. { 23 } false {'mips64'},
  110. { 24 } false {'mips64el'},
  111. { 25 } false {'loongarch64'}
  112. );
  113. { List of all supported system-cpu couples }
  114. const
  115. Targets : array[tsystem] of string[26]=(
  116. { 0 } 'none',
  117. { 1 } 'GO32V1 (obsolete)',
  118. { 2 } 'GO32V2',
  119. { 3 } 'Linux-i386',
  120. { 4 } 'OS/2',
  121. { 5 } 'Win32',
  122. { 6 } 'FreeBSD-i386',
  123. { 7 } 'Amiga',
  124. { 8 } 'Atari',
  125. { 9 } 'MacOSClassic-m68k',
  126. { 10 } 'Linux-m68k',
  127. { 11 } 'PalmOS-m68k',
  128. { 12 } 'Linux-alpha (obsolete)',
  129. { 13 } 'Linux-ppc',
  130. { 14 } 'MacOSClassic-ppc',
  131. { 15 } 'Solaris-i386',
  132. { 16 } 'BeOS-i386',
  133. { 17 } 'NetBSD-i386',
  134. { 18 } 'NetBSD-m68k',
  135. { 19 } 'Netware-i386-clib',
  136. { 20 } 'Qnx-i386',
  137. { 21 } 'WDOSX-i386',
  138. { 22 } 'Solaris-sparc',
  139. { 23 } 'Linux-sparc',
  140. { 24 } 'OpenBSD-i386',
  141. { 25 } 'OpenBSD-m68k (obsolete)',
  142. { 26 } 'Linux-x86-64',
  143. { 27 } 'Darwin-ppc',
  144. { 28 } 'OS/2 via EMX',
  145. { 29 } 'NetBSD-powerpc',
  146. { 30 } 'OpenBSD-powerpc',
  147. { 31 } 'Linux-arm',
  148. { 32 } 'Watcom-i386',
  149. { 33 } 'MorphOS-powerpc',
  150. { 34 } 'FreeBSD-x86-64',
  151. { 35 } 'Netware-i386-libc',
  152. { 36 } 'Amiga-PowerPC',
  153. { 37 } 'Win64-x64',
  154. { 38 } 'WinCE-ARM',
  155. { 39 } 'Win64-iA64 (obsolete)',
  156. { 40 } 'WinCE-i386',
  157. { 41 } 'Linux-x64',
  158. { 42 } 'GBA-arm',
  159. { 43 } 'Linux-powerpc64',
  160. { 44 } 'Darwin-i386',
  161. { 45 } 'PalmOS-arm',
  162. { 46 } 'Darwin-powerpc64',
  163. { 47 } 'NDS-arm',
  164. { 48 } 'Embedded-i386',
  165. { 49 } 'Embedded-m68k',
  166. { 50 } 'Embedded-alpha (obsolete)',
  167. { 51 } 'Embedded-powerpc',
  168. { 52 } 'Embedded-sparc',
  169. { 53 } 'Embedded-vm (obsolete)',
  170. { 54 } 'Embedded-iA64 (obsolete)',
  171. { 55 } 'Embedded-x64',
  172. { 56 } 'Embedded-mips',
  173. { 57 } 'Embedded-arm',
  174. { 58 } 'Embedded-powerpc64',
  175. { 59 } 'Symbian-i386',
  176. { 60 } 'Symbian-arm',
  177. { 61 } 'Darwin-x64',
  178. { 62 } 'Embedded-avr',
  179. { 63 } 'Haiku-i386',
  180. { 64 } 'iOS-ARM',
  181. { 65 } 'Solaris-x86-64',
  182. { 66 } 'Linux-MIPS',
  183. { 67 } 'Linux-MIPSel',
  184. { 68 } 'NativeNT-i386',
  185. { 69 } 'iPhoneSim-i386',
  186. { 70 } 'Wii-powerpc',
  187. { 71 } 'OpenBSD-x86-64',
  188. { 72 } 'NetBSD-x86-64',
  189. { 73 } 'AIX-powerpc',
  190. { 74 } 'AIX-powerpc64',
  191. { 75 } 'Java-JVM',
  192. { 76 } 'Android-JVM',
  193. { 77 } 'Android-arm',
  194. { 78 } 'Android-i386',
  195. { 79 } 'MSDOS-i8086',
  196. { 80 } 'Android-MIPSel',
  197. { 81 } 'Embedded-mipseb',
  198. { 82 } 'Embedded-mipsel',
  199. { 83 } 'AROS-i386',
  200. { 84 } 'AROS-x86-64',
  201. { 85 } 'DragonFly-x86-64',
  202. { 86 } 'iOS-AArch64',
  203. { 87 } 'iPhoneSim-x86-64',
  204. { 88 } 'Linux-AArch64',
  205. { 89 } 'Win16',
  206. { 90 } 'Embedded-i8086',
  207. { 91 } 'AROS-arm',
  208. { 92 } 'WebAssembly-wasm',
  209. { 93 } 'Linux-sparc64',
  210. { 94 } 'Solaris-sparc64',
  211. { 95 } 'NetBSD-arm',
  212. { 96 } 'Linux-RiscV32',
  213. { 97 } 'Linux-RiscV64',
  214. { 98 } 'Embedded-RiscV32',
  215. { 99 } 'Embedded-RiscV64',
  216. { 100 } 'Android-AArch64',
  217. { 101 } 'Android-x86-64',
  218. { 102 } 'Haiku-x86-64',
  219. { 103 } 'Embedded-Xtensa',
  220. { 104 } 'FreeRTos-Xtensa',
  221. { 105 } 'Linux-Xtensa',
  222. { 106 } 'FreeRTos-arm',
  223. { 107 } 'Win64-AArch64',
  224. { 108 } 'Embedded-Z80',
  225. { 109 } 'ZXSpectrum-Z80',
  226. { 110 } 'MSX-DOS-Z80',
  227. { 111 } 'Darwin-AArch64',
  228. { 112 } 'AmstradCPC-Z80',
  229. { 113 } 'SinclairQL-m68k',
  230. { 114 } 'WASIp1-WASM32',
  231. { 115 } 'FreeBSD-AArch64',
  232. { 116 } 'Embedded-aarch64',
  233. { 117 } 'Linux-MIPS64',
  234. { 118 } 'Linux-MIPS64el',
  235. { 119 } 'FreeRTos-RiscV32',
  236. { 120 } 'Linux-LoongArch64',
  237. { 121 } 'iPhoneSim-AArch64',
  238. { 122 } 'Human68k-m68k',
  239. { 123 } 'PS1-mipsel',
  240. { 124 } 'WASIp1threads-WASM32',
  241. { 125 } 'WASIp2-WASM32',
  242. { 126 } 'FreeBSD-powerpc64'
  243. );
  244. const
  245. { in widestr, we have the following definition
  246. type
  247. tcompilerwidechar = word;
  248. thus widecharsize seems to always be 2 bytes }
  249. widecharsize : longint = 2;
  250. cpu : tsystemcpu = cpu_no;
  251. { This type is defined in scanner.pas unit }
  252. type
  253. tspecialgenerictoken = (
  254. ST_LOADSETTINGS,
  255. ST_LINE,
  256. ST_COLUMN,
  257. ST_FILEINDEX,
  258. ST_LOADMESSAGES,
  259. ST_INVALID);
  260. type
  261. tcpu_i386 = (
  262. cpu_variant_i386_none,
  263. cpu_variant_386,
  264. cpu_variant_486,
  265. cpu_variant_Pentium,
  266. cpu_variant_Pentium2,
  267. cpu_variant_Pentium3,
  268. cpu_variant_Pentium4,
  269. cpu_variant_PentiumM,
  270. cpu_variant_core_i,
  271. cpu_variant_core_avx,
  272. cpu_variant_core_avx2);
  273. tcpu_m68k = (
  274. cpu_variant_m68k_none,
  275. cpu_variant_MC68000,
  276. cpu_variant_MC68020,
  277. cpu_variant_MC68040,
  278. cpu_variant_MC68060,
  279. cpu_variant_isa_a,
  280. cpu_variant_isa_a_p,
  281. cpu_variant_isa_b,
  282. cpu_variant_isa_c,
  283. cpu_variant_cfv4e
  284. );
  285. tcpu_powerpc = (
  286. cpu_variant_powerpc_none,
  287. cpu_variant_ppc604,
  288. cpu_variant_ppc750,
  289. cpu_variant_ppc7400,
  290. cpu_variant_ppc970
  291. );
  292. tcpu_sparc = (
  293. cpu_variant_sparc_none,
  294. cpu_variant_SPARC_V7,
  295. cpu_variant_SPARC_V8,
  296. cpu_variant_SPARC_V9
  297. );
  298. tcpu_x86_64 = (
  299. cpu_variant_x86_64_none,
  300. cpu_variant_athlon64,
  301. cpu_variant_x86_64_core_i,
  302. cpu_variant_x86_64_core_avx,
  303. cpu_variant_x86_64_core_avx2
  304. );
  305. tcpu_mipseb = (
  306. cpu_variant_mipseb_none,
  307. cpu_variant_mips1,
  308. cpu_variant_mips2,
  309. cpu_variant_mips3,
  310. cpu_variant_mips4,
  311. cpu_variant_mips5,
  312. cpu_variant_mips32,
  313. cpu_variant_mips32r2,
  314. cpu_variant_pic32mx
  315. );
  316. tcpu_arm = (
  317. cpu_variant_arm_none,
  318. cpu_variant_armv3,
  319. cpu_variant_armv4,
  320. cpu_variant_armv4t,
  321. cpu_variant_armv5,
  322. cpu_variant_armv5t,
  323. cpu_variant_armv5te,
  324. cpu_variant_armv5tej,
  325. cpu_variant_armv6,
  326. cpu_variant_armv6k,
  327. cpu_variant_armv6t2,
  328. cpu_variant_armv6z,
  329. cpu_variant_armv6m,
  330. cpu_variant_armv7,
  331. cpu_variant_armv7a,
  332. cpu_variant_armv7r,
  333. cpu_variant_armv7m,
  334. cpu_variant_armv7em
  335. );
  336. tcpu_powerpc64 = (
  337. cpu_variant_powerpc64_none,
  338. cpu_variant_powerpc64_ppc970
  339. );
  340. tcpu_avr = (
  341. cpu_variant_avr_none,
  342. cpu_variant_avr1,
  343. cpu_variant_avr2,
  344. cpu_variant_avr25,
  345. cpu_variant_avr3,
  346. cpu_variant_avr31,
  347. cpu_variant_avr35,
  348. cpu_variant_avr4,
  349. cpu_variant_avr5,
  350. cpu_variant_avr51,
  351. cpu_variant_avr6
  352. );
  353. tcpu_mipsel = tcpu_mipseb;
  354. tcpu_jvm = (
  355. cpu_variant_jvm_none,
  356. { jvm, same as cpu_none }
  357. cpu_variant_jvm,
  358. { jvm byte code to be translated into Dalvik bytecode: more type-
  359. sensitive }
  360. cpu_variant_dalvik
  361. );
  362. tcpu_i8086 = (
  363. cpu_variant_i8086_none,
  364. cpu_variant_8086,
  365. cpu_variant_186,
  366. cpu_variant_286,
  367. cpu_variant_i8086_386,
  368. cpu_variant_i8086_486,
  369. cpu_variant_i8086_Pentium,
  370. cpu_variant_i8086_Pentium2,
  371. cpu_variant_i8086_Pentium3,
  372. cpu_variant_i8086_Pentium4,
  373. cpu_variant_i8086_PentiumM
  374. );
  375. tcpu_aarch64 = (
  376. cpu_variant_aarch64_none,
  377. cpu_variant_armv8
  378. );
  379. tcpu_wasm32 = (
  380. cpu_variant_wasm32_none);
  381. tcpu_sparc64 = (
  382. cpu_variant_sparc64_none,
  383. cpu_variant_SPARC64_V9
  384. );
  385. tcpu_riscv32 = (
  386. cpu_variant_riscv32_none,
  387. cpu_variant_rv32imafd,
  388. cpu_variant_rv32ima,
  389. cpu_variant_rv32im,
  390. cpu_variant_rv32i
  391. );
  392. tcpu_riscv64 = (
  393. cpu_variant_riscv64_none,
  394. cpu_variant_rv64imafdc,
  395. cpu_variant_rv64imafd,
  396. cpu_variant_rv64ima,
  397. cpu_variant_rv64im,
  398. cpu_variant_rv64i
  399. );
  400. tcpu_type = record
  401. case tsystemcpu of
  402. cpu_no: { 0 }
  403. ();
  404. cpu_i386: { 1 }
  405. (cpu_i386 : tcpu_i386;);
  406. cpu_m68k: { 2 }
  407. (cpu_m68k : tcpu_m68k;);
  408. obsolete_cpu_alpha: { 3 }
  409. ();
  410. cpu_powerpc: { 4 }
  411. (cpu_powerpc : tcpu_powerpc;);
  412. cpu_sparc: { 5 }
  413. (cpu_sparc : tcpu_sparc;);
  414. obsolete_cpu_vm: { 6 }
  415. ();
  416. obsolete_cpu_ia64: { 7 }
  417. ();
  418. cpu_x86_64: { 8 }
  419. (cpu_x86_64 : tcpu_x86_64;);
  420. cpu_mipseb: { 9 }
  421. (cpu_mipseb : tcpu_mipseb;);
  422. cpu_arm: { 10 }
  423. (cpu_arm : tcpu_arm;);
  424. cpu_powerpc64: { 11 }
  425. (cpu_powerpc64 : tcpu_powerpc64;);
  426. cpu_avr: { 12 }
  427. (cpu_avr : tcpu_avr;);
  428. cpu_mipsel: { 13 }
  429. (cpu_mipsel : tcpu_mipsel;);
  430. cpu_jvm: { 14 }
  431. (cpu_jvm : tcpu_jvm;);
  432. cpu_i8086: { 15 }
  433. (cpu_i8086 : tcpu_i8086;);
  434. cpu_aarch64: { 16 }
  435. (cpu_aarch64 : tcpu_aarch64;);
  436. cpu_wasm32: { 17 }
  437. (cpu_wasm32 : tcpu_wasm32;);
  438. cpu_sparc64: { 18 }
  439. (cpu_sparc64 : tcpu_sparc64;);
  440. cpu_riscv32: { 19 }
  441. (cpu_riscv32 : tcpu_riscv32;);
  442. cpu_riscv64: { 20 }
  443. (cpu_riscv64 : tcpu_riscv64;);
  444. end;
  445. TPpuModuleDef = class(TPpuUnitDef)
  446. ModuleFlags: tmoduleflags;
  447. end;
  448. type
  449. t_ppu_endian = (ppu_unknown_endian, ppu_little_endian, ppu_big_endian );
  450. tppudumpfile = class(tppufile)
  451. internal_endian : t_ppu_endian;
  452. protected
  453. procedure RaiseAssertion(Code: Longint); override;
  454. end;
  455. var
  456. ppufile : tppudumpfile;
  457. ppuversion : dword;
  458. space : string;
  459. verbose : longint;
  460. derefdata : pbyte;
  461. derefdatalen : longint;
  462. pout: TPpuOutput;
  463. nostdout: boolean;
  464. UnitList: TPpuContainerDef;
  465. CurUnit: TPpuModuleDef;
  466. SkipVersionCheck: boolean;
  467. SymAnsiStr: boolean;
  468. var
  469. { needed during tobjectdef parsing... }
  470. current_defoptions : tdefoptions;
  471. current_objectoptions : tobjectoptions;
  472. current_symtable_options : tsymtableoptions;
  473. {****************************************************************************
  474. Helper Routines
  475. ****************************************************************************}
  476. {****************************************************************************
  477. Routine to read 80-bit reals
  478. ****************************************************************************
  479. }
  480. {$PUSH}
  481. {$WARN 6018 OFF} { Turn off unreachable code warning }
  482. { On platforms with sizeof(ext) <> 10 the code below will cause an unreachable
  483. code warning, which will cause compilation failures with -Sew (KB) }
  484. type
  485. TSplit80bitReal = packed record
  486. case byte of
  487. 0: (bytes: Array[0..9] of byte);
  488. 1: (words: Array[0..4] of word);
  489. end;
  490. const
  491. maxDigits = 17;
  492. function Real80bitToStr(var e : TSplit80bitReal;var ext : extended) : string;
  493. var
  494. Temp : string;
  495. new : TSplit80bitReal;
  496. fraczero, expmaximal, sign, outside_double : boolean;
  497. exp : smallint;
  498. d : double;
  499. i : longint;
  500. e_qw, mantval : qword;
  501. e_w : word;
  502. begin
  503. if sizeof(ext)=10 then
  504. begin
  505. ext:=pextended(@e)^;
  506. str(ext,result);
  507. exit;
  508. end;
  509. { extended, format (MSB): 1 Sign bit, 15 bit exponent, 64 bit mantissa }
  510. if (ppufile.internal_endian=ppu_big_endian) then
  511. begin
  512. e_w:=pword(@(e.bytes[0]))^;
  513. e_qw:=unaligned(pqword(@(e.bytes[2]))^);
  514. end
  515. else
  516. begin
  517. e_w:=pword(@(e.bytes[8]))^;
  518. e_qw:=pqword(@(e.bytes[0]))^;
  519. end;
  520. if ppufile.change_endian then
  521. begin
  522. e_w:=swapendian(e_w);
  523. e_qw:=swapendian(e_qw);
  524. end;
  525. sign := (e_w and $8000) <> 0;
  526. expMaximal := (e_w and $7fff) = 32767;
  527. exp:=(e_w and $7fff) - 16383 - 63;
  528. fraczero := ((e_qw and qword($7fffffffffffffff)) = 0);
  529. mantval:=e_qw;
  530. if expMaximal then
  531. if fraczero then
  532. if sign then
  533. temp := '-Inf'
  534. else temp := '+Inf'
  535. else temp := 'Nan'
  536. else
  537. begin
  538. d:=double(mantval);
  539. if sign then
  540. d:=-d;
  541. outside_double:=false;
  542. Try
  543. if exp > 0 then
  544. begin
  545. for i:=1 to exp do
  546. d:=d *2.0;
  547. end
  548. else if exp < 0 then
  549. begin
  550. for i:=1 to -exp do
  551. d:=d /2.0;
  552. end;
  553. Except
  554. outside_double:=true;
  555. end;
  556. if (mantval<>0) and (d=0.0) then
  557. outside_double:=true;
  558. if outside_double then
  559. begin
  560. Temp:='Extended value outside double bound';
  561. ext:=0.0;
  562. end
  563. else
  564. begin
  565. ext:=d;
  566. system.str(d,temp);
  567. end;
  568. end;
  569. temp:=temp+' w=$'+hexstr(e_w,4)+',qw=$'+hexstr(e_qw,16);
  570. result:=temp;
  571. end;
  572. {$POP}
  573. const has_errors : boolean = false;
  574. has_warnings : boolean = false;
  575. has_more_infos : boolean = false;
  576. procedure SetHasErrors;
  577. begin
  578. has_errors:=true;
  579. end;
  580. Procedure WriteError(const S : string);
  581. Begin
  582. system.Writeln(StdErr, S);
  583. SetHasErrors;
  584. End;
  585. procedure StrAppend(var st : string; const st2 : string);
  586. begin
  587. st:=st+st2;
  588. end;
  589. procedure tppudumpfile.RaiseAssertion(Code: Longint);
  590. begin
  591. WriteError('Internal Error ' + ToStr(Code));
  592. inherited RaiseAssertion(Code);
  593. end;
  594. Procedure WriteWarning(const S : string);
  595. var
  596. ss: string;
  597. Begin
  598. ss:='!! Warning: ' + S;
  599. if nostdout then
  600. system.Writeln(StdErr, ss)
  601. else
  602. system.Writeln(ss);
  603. has_warnings:=true;
  604. End;
  605. procedure Write(const s: string);
  606. begin
  607. if nostdout then exit;
  608. system.write(s);
  609. end;
  610. procedure Write(const params: array of const);
  611. var
  612. i: integer;
  613. { Last vtType define in rtl/inc/objpash.inc }
  614. const
  615. max_vttype = vtUnicodeString;
  616. begin
  617. if nostdout then exit;
  618. for i:=Low(params) to High(params) do
  619. { All vtType in
  620. vtInteger = 0;
  621. vtBoolean = 1;
  622. vtChar = 2;
  623. vtExtended = 3;
  624. vtString = 4;
  625. vtPointer = 5;
  626. vtPChar = 6;
  627. vtObject = 7;
  628. vtClass = 8;
  629. vtWideChar = 9;
  630. vtPWideChar = 10;
  631. vtAnsiString32 = 11; called vtAnsiString in objpas unit
  632. vtCurrency = 12;
  633. vtVariant = 13;
  634. vtInterface = 14;
  635. vtWideString = 15;
  636. vtInt64 = 16;
  637. vtQWord = 17;
  638. vtUnicodeString = 18;
  639. // vtAnsiString16 = 19; not yet used
  640. // vtAnsiString64 = 20; not yet used
  641. }
  642. with TVarRec(params[i]) do
  643. case VType of
  644. vtInteger: system.write(VInteger);
  645. vtBoolean: system.write(VBoolean);
  646. vtChar: system.write(VChar);
  647. vtExtended: system.write(VExtended^);
  648. vtString: system.write(VString^);
  649. vtPointer:
  650. begin
  651. { Not sure the display will be correct
  652. if sizeof pointer is not native }
  653. WriteWarning('Pointer constant');
  654. end;
  655. vtPChar: system.write(VPChar);
  656. vtObject:
  657. begin
  658. { Not sure the display will be correct
  659. if sizeof pointer is not native }
  660. WriteWarning('Object constant');
  661. end;
  662. vtClass:
  663. begin
  664. { Not sure the display will be correct
  665. if sizeof pointer is not native }
  666. WriteWarning('Class constant');
  667. end;
  668. vtWideChar: system.write(VWideChar);
  669. vtPWideChar:
  670. begin
  671. WriteWarning('PWideChar constant');
  672. end;
  673. vtAnsiString: system.write(ansistring(VAnsiString));
  674. vtCurrency : system.write(VCurrency^);
  675. vtVariant :
  676. begin
  677. { Not sure the display will be correct
  678. if sizeof pointer is not native }
  679. WriteWarning('Variant constant');
  680. end;
  681. vtInterface :
  682. begin
  683. { Not sure the display will be correct
  684. if sizeof pointer is not native }
  685. WriteWarning('Interface constant');
  686. end;
  687. vtWideString : system.write(widestring(VWideString));
  688. vtInt64: system.write(VInt64^);
  689. vtQWord: system.write(VQWord^);
  690. vtUnicodeString : system.write(unicodestring(VUnicodeString));
  691. else
  692. begin
  693. system.writeln;
  694. system.writeln('Unsupported var type: ', VType);
  695. Halt(10);
  696. end;
  697. end;
  698. end;
  699. procedure Writeln(const s: string = '');
  700. begin
  701. if nostdout then exit;
  702. system.writeln(s);
  703. end;
  704. procedure Writeln(const params: array of const);
  705. begin
  706. if nostdout then exit;
  707. Write(params);
  708. system.writeln;
  709. end;
  710. Procedure HasMoreInfos;
  711. begin
  712. Writeln('!! Entry has more information stored');
  713. has_more_infos:=true;
  714. end;
  715. function Unknown(const st : string; val :longint) : string;
  716. Begin
  717. Unknown:='<!! Unknown'+st+' value '+tostr(val)+'>';
  718. SetHasErrors;
  719. end;
  720. function ToStr(w:longint):String;
  721. begin
  722. Str(w,ToStr);
  723. end;
  724. Function Target2Str(w:longint):string;
  725. begin
  726. if w<=ord(high(tsystem)) then
  727. Target2Str:=Targets[tsystem(w)]
  728. else
  729. Target2Str:=Unknown('target',w);
  730. end;
  731. Function Cpu2Str(w:longint):string;
  732. begin
  733. if w<=ord(high(tsystemcpu)) then
  734. begin
  735. cpu:=tsystemcpu(w);
  736. Cpu2Str:=CpuTxt[cpu];
  737. end
  738. else
  739. Cpu2Str:=Unknown('cpu',w);
  740. end;
  741. Function Varspez2Str(w:longint):string;
  742. const
  743. { in symconst unit
  744. tvarspez = (vs_value,vs_const,vs_var,vs_out,vs_constref); }
  745. varspezstr : array[tvarspez] of string[8]=('Value','Const','Var','Out','ConstRef','Final');
  746. begin
  747. if w<=ord(high(varspezstr)) then
  748. Varspez2Str:=varspezstr[tvarspez(w)]
  749. else
  750. Varspez2Str:=Unknown('varspez',w);
  751. end;
  752. Function VarRegable2Str(w:longint):string;
  753. { tvarregable type is defined in symconst unit }
  754. const
  755. varregableStr : array[tvarregable] of string[6]=('None','IntReg','FPUReg','MMReg','Addr');
  756. begin
  757. if w<=ord(high(varregablestr)) then
  758. Varregable2Str:=varregablestr[tvarregable(w)]
  759. else
  760. Varregable2Str:=Unknown('regable',w);
  761. end;
  762. Function Visibility2Str(w:longint):string;
  763. const
  764. { tvisibility type is defined in symconst unit }
  765. visibilityName : array[tvisibility] of string[16] = (
  766. 'hidden','strict private','private','strict protected','protected',
  767. 'public','published','<none>'
  768. );
  769. begin
  770. if w<=ord(high(visibilityName)) then
  771. result:=visibilityName[tvisibility(w)]
  772. else
  773. result:=Unknown('visibility',w);
  774. end;
  775. Function IntfEntryType2Str(w:longint):string;
  776. const
  777. { tinterfaceentrytype type is defined in symconst unit }
  778. Name : array[tinterfaceentrytype] of string = (
  779. 'standard','virtual method result','static method result','field value','virtual method class',
  780. 'static method class','field value class'
  781. );
  782. begin
  783. if w<=ord(high(Name)) then
  784. result:=Name[tinterfaceentrytype(w)]
  785. else
  786. result:=Unknown('entry type',w);
  787. end;
  788. function PPUFlags2Str(flags:dword):string;
  789. type
  790. tflagopt=record
  791. mask : dword;
  792. str : string[30];
  793. end;
  794. const
  795. flagopts=8;
  796. mask_big_endian = $4;
  797. mask_little_endian = $1000;
  798. flagopt : array[1..flagopts] of tflagopt=(
  799. (mask: $4 ;str:'big_endian'),
  800. // (mask: $10 ;str:'browser'),
  801. (mask: $20 ;str:'in_library'),
  802. (mask: $40 ;str:'smart_linked'),
  803. (mask: $80 ;str:'static_linked'),
  804. (mask: $100 ;str:'shared_linked'),
  805. (mask: $400 ;str:'no_link'),
  806. (mask: $1000 ;str:'little_endian'),
  807. (mask: $8000 ;str:'fpu_emulation_on')
  808. );
  809. var
  810. i : longint;
  811. ntflags : dword;
  812. first : boolean;
  813. s : string;
  814. begin
  815. s:='';
  816. ntflags:=flags;
  817. ppufile.internal_endian:=ppu_unknown_endian;
  818. if flags<>0 then
  819. begin
  820. first:=true;
  821. for i:=1to flagopts do
  822. if (flags and flagopt[i].mask)<>0 then
  823. begin
  824. if first then
  825. first:=false
  826. else
  827. s:=s+', ';
  828. s:=s+flagopt[i].str;
  829. if flagopt[i].mask=mask_big_endian then
  830. begin
  831. if (ppufile.internal_endian<>ppu_unknown_endian) then
  832. begin
  833. s:=s+' endianess explicitly set twice';
  834. SetHasErrors;
  835. end;
  836. ppufile.internal_endian:=ppu_big_endian;
  837. end;
  838. if flagopt[i].mask=mask_little_endian then
  839. begin
  840. if (ppufile.internal_endian<>ppu_unknown_endian) then
  841. begin
  842. s:=s+' endianess explicitly set twice';
  843. SetHasErrors;
  844. end;
  845. ppufile.internal_endian:=ppu_little_endian;
  846. end;
  847. ntflags:=ntflags and (not flagopt[i].mask);
  848. end;
  849. end
  850. else
  851. s:='none';
  852. if ntflags<>0 then
  853. begin
  854. s:=s+' unknown '+hexstr(ntflags,8);
  855. SetHasErrors;
  856. end;
  857. if (ppufile.internal_endian=ppu_unknown_endian) then
  858. begin
  859. s:=s+' endianess not explicitly set';
  860. SetHasErrors;
  861. end;
  862. PPUFlags2Str:=s;
  863. end;
  864. Function L0(l:longint):string;
  865. {
  866. return the string of value l, if l<10 then insert a zero, so
  867. the string is always at least 2 chars '01','02',etc
  868. }
  869. var
  870. s : string;
  871. begin
  872. Str(l,s);
  873. if l<10 then
  874. s:='0'+s;
  875. L0:=s;
  876. end;
  877. function filetimestring( t : longint) : string;
  878. {
  879. convert dos datetime t to a string YY/MM/DD HH:MM:SS
  880. }
  881. var
  882. DT : TDateTime;
  883. hsec : word;
  884. Year,Month,Day: Word;
  885. hour,min,sec : word;
  886. begin
  887. if t=-1 then
  888. begin
  889. Result := 'Not Found';
  890. SetHasErrors;
  891. exit;
  892. end;
  893. DT := FileDateToDateTime(t);
  894. DecodeTime(DT,hour,min,sec,hsec);
  895. DecodeDate(DT,year,month,day);
  896. Result := L0(Year)+'/'+L0(Month)+'/'+L0(Day)+' '+L0(Hour)+':'+L0(min)+':'+L0(sec);
  897. end;
  898. {****************************************************************************
  899. Read Routines
  900. ****************************************************************************}
  901. function readsymstr(ppufile: tppufile): ansistring;
  902. begin
  903. if not(mf_symansistr in CurUnit.ModuleFlags) then
  904. result:=ppufile.getstring
  905. else
  906. result:=ppufile.getansistring;
  907. end;
  908. function readmanagementoperatoroptions(const space : string;const name : string):tmanagementoperators;forward;
  909. procedure readrecsymtableoptions;
  910. var
  911. usefieldalignment : shortint;
  912. begin
  913. if ppufile.readentry<>ibrecsymtableoptions then
  914. begin
  915. SetHasErrors;
  916. exit;
  917. end;
  918. writeln([space,' recordalignment: ',shortint(ppufile.getbyte)]);
  919. usefieldalignment:=shortint(ppufile.getbyte);
  920. writeln([space,' usefieldalignment: ',usefieldalignment]);
  921. writeln([space,' recordalignmin: ',shortint(ppufile.getbyte)]);
  922. if (usefieldalignment=C_alignment) then
  923. writeln([space,' fieldalignment: ',shortint(ppufile.getbyte)]);
  924. readmanagementoperatoroptions(space,'Fields have MOPs');
  925. end;
  926. function readsymtableoptions(const s: string) : tsymtableoptions;
  927. type
  928. tsymtblopt=record
  929. mask : tsymtableoption;
  930. str : string[30];
  931. end;
  932. const
  933. symtblopts=ord(high(tsymtableoption)) + 1;
  934. symtblopt : array[1..symtblopts] of tsymtblopt=(
  935. (mask:sto_has_helper; str:'Has helper'),
  936. (mask:sto_has_generic; str:'Has generic'),
  937. (mask:sto_has_operator; str:'Has operator'),
  938. (mask:sto_needs_init_final;str:'Needs init final table'),
  939. (mask:sto_has_non_trivial_init;str:'Has non trivial init')
  940. );
  941. var
  942. options : tsymtableoptions;
  943. first : boolean;
  944. i : integer;
  945. begin
  946. if ppufile.readentry<>ibsymtableoptions then
  947. begin
  948. SetHasErrors;
  949. exit;
  950. end;
  951. ppufile.getset(tppuset1(options));
  952. if space<>'' then
  953. writeln([space,'------ ',s,' ------']);
  954. write([space,'Symtable options: ']);
  955. if options<>[] then
  956. begin
  957. first:=true;
  958. for i:=1 to symtblopts do
  959. if (symtblopt[i].mask in options) then
  960. begin
  961. if first then
  962. first:=false
  963. else
  964. write(', ');
  965. write(symtblopt[i].str);
  966. end;
  967. end
  968. else
  969. write('none');
  970. writeln;
  971. readsymtableoptions:=options;
  972. end;
  973. procedure readdefinitions(const s:string; ParentDef: TPpuContainerDef); forward;
  974. procedure readsymbols(const s:string; ParentDef: TPpuContainerDef = nil); forward;
  975. procedure readsymtable(const s: string; ParentDef: TPpuContainerDef = nil);
  976. var
  977. stored_symtable_options : tsymtableoptions;
  978. begin
  979. stored_symtable_options:=current_symtable_options;
  980. current_symtable_options:=readsymtableoptions(s);
  981. readdefinitions(s, ParentDef);
  982. readsymbols(s, ParentDef);
  983. current_symtable_options:=stored_symtable_options;
  984. end;
  985. procedure readrecordsymtable(const s: string; ParentDef: TPpuContainerDef = nil);
  986. begin
  987. readrecsymtableoptions;
  988. readsymtable(s, ParentDef);
  989. end;
  990. Procedure ReadLinkContainer(const prefix:string);
  991. {
  992. Read a serie of strings and write to the screen starting every line
  993. with prefix
  994. }
  995. function maskstr(m:longint):string;
  996. { link options are in globtype unit
  997. const
  998. link_none = $0;
  999. link_always = $1;
  1000. link_static = $2;
  1001. link_smart = $4;
  1002. link_shared = $8; }
  1003. var
  1004. s : string;
  1005. begin
  1006. s:='';
  1007. if (m and link_always)<>0 then
  1008. s:=s+'always ';
  1009. if (m and link_static)<>0 then
  1010. s:=s+'static ';
  1011. if (m and link_smart)<>0 then
  1012. s:=s+'smart ';
  1013. if (m and link_shared)<>0 then
  1014. s:=s+'shared ';
  1015. maskstr:=s;
  1016. end;
  1017. var
  1018. s : string;
  1019. m : longint;
  1020. begin
  1021. while not ppufile.endofentry do
  1022. begin
  1023. s:=ppufile.getstring;
  1024. m:=ppufile.getlongint;
  1025. WriteLn([prefix,s,' (',maskstr(m),')']);
  1026. end;
  1027. end;
  1028. Procedure ReadContainer(const prefix:string);
  1029. {
  1030. Read a series of strings and write to the screen starting every line
  1031. with prefix
  1032. }
  1033. begin
  1034. while not ppufile.endofentry do
  1035. WriteLn([prefix,ppufile.getstring]);
  1036. end;
  1037. procedure ReadLoadUnit;
  1038. var
  1039. ucrc,uintfcrc, indcrc : cardinal;
  1040. un: TPpuUnitDef;
  1041. begin
  1042. while not ppufile.EndOfEntry do
  1043. begin
  1044. un:=TPpuUnitDef.Create(CurUnit.UsedUnits);
  1045. un.Name:=ppufile.getstring;
  1046. write(['Uses unit: ',un.Name]);
  1047. ucrc:=cardinal(ppufile.getlongint);
  1048. uintfcrc:=cardinal(ppufile.getlongint);
  1049. indcrc:=cardinal(ppufile.getlongint);
  1050. writeln([' (Crc: ',hexstr(ucrc,8),', IntfcCrc: ',hexstr(uintfcrc,8),', IndCrc: ',hexstr(indcrc,8),')']);
  1051. un.Crc:=ucrc;
  1052. un.IntfCrc:=uintfcrc;
  1053. end;
  1054. end;
  1055. Procedure ReadDerefmap;
  1056. var
  1057. i,mapsize : longint;
  1058. s: string;
  1059. begin
  1060. mapsize:=ppufile.getlongint;
  1061. writeln(['DerefMapsize: ',mapsize]);
  1062. SetLength(CurUnit.RefUnits, mapsize);
  1063. for i:=0 to mapsize-1 do
  1064. begin
  1065. s:=ppufile.getstring;
  1066. writeln(['DerefMap[',i,'] = ',s]);
  1067. CurUnit.RefUnits[i]:=LowerCase(s);
  1068. end;
  1069. end;
  1070. Procedure ReadImportSymbols;
  1071. var
  1072. extlibname : string;
  1073. j,
  1074. extsymcnt : longint;
  1075. extsymname : string;
  1076. extsymmangledname : string;
  1077. extsymordnr : longint;
  1078. extsymisvar : boolean;
  1079. begin
  1080. while not ppufile.endofentry do
  1081. begin
  1082. extlibname:=ppufile.getstring;
  1083. extsymcnt:=ppufile.getlongint;
  1084. writeln(['External Library: ',extlibname,' (',extsymcnt,' imports)']);
  1085. for j:=0 to extsymcnt-1 do
  1086. begin
  1087. extsymname:=ppufile.getstring;
  1088. extsymmangledname:=ppufile.getstring;
  1089. extsymordnr:=ppufile.getlongint;
  1090. extsymisvar:=ppufile.getbyte<>0;
  1091. writeln([' ',extsymname,' as ',extsymmangledname,
  1092. '(OrdNr: ',extsymordnr,' IsVar: ',extsymisvar,')']);
  1093. end;
  1094. end;
  1095. end;
  1096. Procedure ReadDerefdata;
  1097. begin
  1098. derefdatalen:=ppufile.entrysize;
  1099. if derefdatalen=0 then
  1100. begin
  1101. Writeln(['No Derefdata length=0']);
  1102. derefdata:=nil;
  1103. exit;
  1104. end;
  1105. Writeln(['Derefdata length: ',derefdatalen]);
  1106. derefdata:=allocmem(derefdatalen);
  1107. ppufile.getdata(derefdata^,derefdatalen);
  1108. end;
  1109. Procedure FreeDerefdata;
  1110. begin
  1111. if assigned(derefdata) then
  1112. begin
  1113. FreeMem(derefdata);
  1114. derefdata:=nil;
  1115. derefdatalen:=0;
  1116. end;
  1117. end;
  1118. Procedure ReadWpoFileInfo;
  1119. begin
  1120. Writeln(['Compiled with input whole-program optimisation from ',ppufile.getstring,' ',filetimestring(ppufile.getlongint)]);
  1121. end;
  1122. Procedure ReadAsmSymbols;
  1123. const
  1124. unitasmlisttype: array[tunitasmlisttype] of string[6]=(
  1125. 'PUBLIC',
  1126. 'EXTERN'
  1127. );
  1128. type
  1129. { Copied from aasmbase.pas }
  1130. TAsmsymbind=(
  1131. AB_NONE,AB_EXTERNAL,AB_COMMON,AB_LOCAL,AB_GLOBAL,AB_WEAK_EXTERNAL,
  1132. { global in the current program/library, but not visible outside it }
  1133. AB_PRIVATE_EXTERN,AB_LAZY,AB_IMPORT,
  1134. { a symbol that's internal to the compiler and used as a temp }
  1135. AB_TEMP,
  1136. { a global symbol that points to another global symbol and is only used
  1137. to allow indirect loading in case of packages and indirect imports }
  1138. AB_INDIRECT,AB_EXTERNAL_INDIRECT,
  1139. AB_WEAK);
  1140. TAsmsymtype=(
  1141. AT_NONE,AT_FUNCTION,AT_DATA,AT_SECTION,AT_LABEL,
  1142. {
  1143. the address of this code label is taken somewhere in the code
  1144. so it must be taken care of it when creating pic
  1145. }
  1146. AT_ADDR,
  1147. { Label for debug or other non-program information }
  1148. AT_METADATA,
  1149. { label for data that must always be accessed indirectly, because it
  1150. is handled explicitly in the system unit or (e.g. RTTI and threadvar
  1151. tables) -- never seen in an assembler/assembler writer, always
  1152. changed to AT_DATA }
  1153. AT_DATA_FORCEINDIRECT,
  1154. { don't generate an implicit indirect symbol as that might be provided
  1155. by other means (e.g. the typed const builder) to ensure a correct
  1156. section name }
  1157. AT_DATA_NOINDIRECT,
  1158. { Thread-local symbol (ELF targets) }
  1159. AT_TLS,
  1160. { GNU indirect function (ELF targets) }
  1161. AT_GNU_IFUNC,
  1162. { WebAssembly global variable }
  1163. AT_WASM_GLOBAL,
  1164. { WebAssembly exception tag (used as a parameter for the 'throw' and
  1165. 'catch' instructions) }
  1166. AT_WASM_EXCEPTION_TAG
  1167. );
  1168. var
  1169. s,
  1170. bindstr,
  1171. typestr : string;
  1172. i : longint;
  1173. t: tunitasmlisttype;
  1174. begin
  1175. writeln([space,'Assembler Symbols']);
  1176. writeln([space,'-----------------']);
  1177. t:=tunitasmlisttype(ppufile.getbyte);
  1178. if (t>=Low(tunitasmlisttype)) and (t<=High(tunitasmlisttype)) then
  1179. typestr:=unitasmlisttype[t]
  1180. else
  1181. typestr:='UNKNOWN';
  1182. writeln([space,'Type: ',typestr]);
  1183. writeln([space,'Count: ',ppufile.getlongint]);
  1184. i:=0;
  1185. while (not ppufile.endofentry) and (not ppufile.error) do
  1186. begin
  1187. s:=ppufile.getstring;
  1188. case tasmsymbind(ppufile.getbyte) of
  1189. AB_EXTERNAL :
  1190. bindstr:='External';
  1191. AB_COMMON :
  1192. bindstr:='Common';
  1193. AB_LOCAL :
  1194. bindstr:='Local';
  1195. AB_GLOBAL :
  1196. bindstr:='Global';
  1197. AB_WEAK_EXTERNAL :
  1198. bindstr:='Weak external';
  1199. AB_PRIVATE_EXTERN :
  1200. bindstr:='Private extern';
  1201. AB_LAZY :
  1202. bindstr:='Lazy';
  1203. AB_IMPORT :
  1204. bindstr:='Import';
  1205. AB_TEMP :
  1206. bindstr:='Temp';
  1207. AB_INDIRECT :
  1208. bindstr:='Indirect';
  1209. AB_EXTERNAL_INDIRECT :
  1210. bindstr:='Indirect external';
  1211. AB_WEAK:
  1212. bindstr:='Weak';
  1213. else
  1214. begin
  1215. bindstr:='<Error !!>';
  1216. SetHasErrors;
  1217. end;
  1218. end;
  1219. case tasmsymtype(ppufile.getbyte) of
  1220. AT_FUNCTION :
  1221. typestr:='Function';
  1222. AT_DATA :
  1223. typestr:='Data';
  1224. AT_SECTION :
  1225. typestr:='Section';
  1226. AT_LABEL :
  1227. typestr:='Label';
  1228. AT_ADDR :
  1229. typestr:='Label (with address taken)';
  1230. AT_METADATA :
  1231. typestr:='Metadata';
  1232. { this shouldn't appear in a PPU }
  1233. AT_DATA_FORCEINDIRECT :
  1234. typestr:='Data (ForceIndirect)';
  1235. { this shouldn't appear in a PPU }
  1236. AT_DATA_NOINDIRECT:
  1237. typestr:='Data (NoIndirect)';
  1238. AT_TLS :
  1239. typestr:='TLS';
  1240. AT_GNU_IFUNC :
  1241. typestr:='GNU IFUNC';
  1242. AT_WASM_GLOBAL:
  1243. typestr:='WebAssembly global variable';
  1244. AT_WASM_EXCEPTION_TAG:
  1245. typestr:='WebAssembly exception tag';
  1246. else
  1247. begin
  1248. typestr:='<Error !!>';
  1249. SetHasErrors;
  1250. end;
  1251. end;
  1252. Writeln([space,' ',i,' : ',s,' [',bindstr,',',typestr,']']);
  1253. inc(i);
  1254. end;
  1255. writeln([space]);
  1256. end;
  1257. function getexprint:Tconstexprint;
  1258. begin
  1259. getexprint.overflow:=false;
  1260. getexprint.signed:=ppufile.getboolean;
  1261. getexprint.svalue:=ppufile.getint64;
  1262. end;
  1263. Procedure ReadPosInfo(Def: TPpuDef = nil);
  1264. var
  1265. info : byte;
  1266. fileindex,line,column : longint;
  1267. begin
  1268. with ppufile do
  1269. begin
  1270. fileindex:=0;
  1271. line:=0;
  1272. column:=0;
  1273. {
  1274. info byte layout in bits:
  1275. 0-1 - amount of bytes for fileindex
  1276. 2-3 - amount of bytes for line
  1277. 4-5 - amount of bytes for column
  1278. }
  1279. info:=getbyte;
  1280. case (info and $03) of
  1281. 0 : fileindex:=getbyte;
  1282. 1 : fileindex:=getword;
  1283. 2 : fileindex:=(getbyte shl 16) or getword;
  1284. 3 : fileindex:=getlongint;
  1285. end;
  1286. case ((info shr 2) and $03) of
  1287. 0 : line:=getbyte;
  1288. 1 : line:=getword;
  1289. 2 : line:=(getbyte shl 16) or getword;
  1290. 3 : line:=getlongint;
  1291. end;
  1292. case ((info shr 4) and $03) of
  1293. 0 : column:=getbyte;
  1294. 1 : column:=getword;
  1295. 2 : column:=(getbyte shl 16) or getword;
  1296. 3 : column:=getlongint;
  1297. end;
  1298. Writeln([fileindex,' (',line,',',column,')']);
  1299. if Def <> nil then
  1300. begin
  1301. Def.FilePos.FileIndex:=fileindex;
  1302. Def.FilePos.Line:=line;
  1303. Def.FilePos.Col:=column;
  1304. end;
  1305. end;
  1306. end;
  1307. procedure readderef(const derefspace: string; Ref: TPpuRef = nil);
  1308. var
  1309. b : tdereftype;
  1310. first : boolean;
  1311. idx : longint;
  1312. i,n : byte;
  1313. pdata : pbyte;
  1314. begin
  1315. if not assigned(derefdata) then
  1316. exit;
  1317. first:=true;
  1318. idx:=ppufile.getlongint;
  1319. if idx = -1 then
  1320. begin
  1321. writeln('Nil');
  1322. exit;
  1323. end;
  1324. if (idx>derefdatalen) then
  1325. begin
  1326. WriteError('!! Error: Deref idx '+IntToStr(idx)+' > '+IntToStr(derefdatalen));
  1327. exit;
  1328. end;
  1329. write([derefspace,'(',idx,') ']);
  1330. pdata:=@derefdata[idx];
  1331. i:=0;
  1332. n:=pdata[i];
  1333. inc(i);
  1334. if n<1 then
  1335. begin
  1336. WriteError('!! Error: Deref len < 1');
  1337. exit;
  1338. end;
  1339. while (i<=n) do
  1340. begin
  1341. if not first then
  1342. write(', ')
  1343. else
  1344. first:=false;
  1345. b:=tdereftype(pdata[i]);
  1346. inc(i);
  1347. case b of
  1348. deref_nil :
  1349. write('Nil');
  1350. deref_symid :
  1351. begin
  1352. idx:=BEtoN(unaligned(PInt32(@pdata[i{..i+3}])^));
  1353. inc(i,4);
  1354. write(['SymId ',idx]);
  1355. if Ref <> nil then
  1356. Ref.Id:=idx;
  1357. end;
  1358. deref_defid :
  1359. begin
  1360. idx:=BEtoN(unaligned(PInt32(@pdata[i{..i+3}])^));
  1361. inc(i,4);
  1362. write(['DefId ',idx]);
  1363. if Ref <> nil then
  1364. Ref.Id:=idx;
  1365. end;
  1366. deref_unit :
  1367. begin
  1368. idx:=BEtoN(unaligned(PUint16(@pdata[i{..i+1}])^));
  1369. inc(i,2);
  1370. write(['Unit ',idx]);
  1371. if Ref <> nil then
  1372. Ref.UnitIndex:=idx;
  1373. end;
  1374. else
  1375. begin
  1376. WriteError('!! unsupported dereftyp: '+IntToStr(ord(b)));
  1377. break;
  1378. end;
  1379. end;
  1380. end;
  1381. writeln;
  1382. end;
  1383. Procedure ReadUnitImportSyms;
  1384. var
  1385. c,i : longint;
  1386. begin
  1387. writeln([space,'Imported Symbols']);
  1388. writeln([space,'----------------']);
  1389. c:=ppufile.getlongint;
  1390. for i:=0 to c-1 do
  1391. readderef(space);
  1392. writeln([space]);
  1393. end;
  1394. procedure readpropaccesslist(const s:string; Ref: TPpuRef = nil);
  1395. { type tsltype is in symconst unit }
  1396. const
  1397. slstr : array[tsltype] of string[12] = (
  1398. '',
  1399. 'load',
  1400. 'call',
  1401. 'subscript',
  1402. 'vec',
  1403. 'typeconv',
  1404. 'absolutetype'
  1405. );
  1406. var
  1407. sl : tsltype;
  1408. begin
  1409. readderef('',Ref);
  1410. repeat
  1411. sl:=tsltype(ppufile.getbyte);
  1412. if sl=sl_none then
  1413. break;
  1414. write([s,'(',slstr[sl],') ']);
  1415. case sl of
  1416. sl_none : ;
  1417. sl_call,
  1418. sl_load,
  1419. sl_subscript :
  1420. if (Ref <> nil) and (Ref.IsNull) then
  1421. begin
  1422. readderef('',Ref);
  1423. Ref.IsSymId:=True;
  1424. end
  1425. else
  1426. readderef('');
  1427. sl_absolutetype,
  1428. sl_typeconv :
  1429. readderef('');
  1430. sl_vec :
  1431. begin
  1432. writeln([ppufile.getlongint]);
  1433. readderef('');
  1434. end;
  1435. end;
  1436. until false;
  1437. end;
  1438. (*
  1439. talignmentinfo = packed record
  1440. procalign,
  1441. loopalign,
  1442. jumpalign,
  1443. constalignmin,
  1444. constalignmax,
  1445. varalignmin,
  1446. varalignmax,
  1447. localalignmin,
  1448. localalignmax,
  1449. recordalignmin,
  1450. recordalignmax,
  1451. maxCrecordalign : longint;
  1452. end;
  1453. tsettings = packed record
  1454. alignment : talignmentinfo;
  1455. globalswitches : tglobalswitches;
  1456. moduleswitches : tmoduleswitches;
  1457. localswitches : tlocalswitches;
  1458. modeswitches : tmodeswitches;
  1459. optimizerswitches : toptimizerswitches;
  1460. { generate information necessary to perform these wpo's during a subsequent compilation }
  1461. genwpoptimizerswitches: twpoptimizerswitches;
  1462. { perform these wpo's using information generated during a previous compilation }
  1463. dowpoptimizerswitches: twpoptimizerswitches;
  1464. debugswitches : tdebugswitches;
  1465. { 0: old behaviour for sets <=256 elements
  1466. >0: round to this size }
  1467. setalloc,
  1468. packenum : shortint;
  1469. packrecords : shortint;
  1470. maxfpuregisters : shortint;
  1471. verbosity : longint;
  1472. cputype,
  1473. optimizecputype : tcputype;
  1474. fputype : tfputype;
  1475. asmmode : tasmmode;
  1476. interfacetype : tinterfacetypes;
  1477. defproccall : tproccalloption;
  1478. sourcecodepage : tcodepagestring;
  1479. minfpconstprec : tfloattype;
  1480. disabledircache : boolean;
  1481. { CPU targets with microcontroller support can add a controller specific unit }
  1482. controllertype : tcontrollertype;
  1483. { WARNING: this pointer cannot be written as such in record token }
  1484. pmessage : pmessagestaterecord;
  1485. end;
  1486. *)
  1487. procedure readprocinfooptions(space : string);
  1488. (*
  1489. tprocinfoflag=(
  1490. { procedure has at least one assembler block }
  1491. pi_has_assembler_block,
  1492. { procedure does a call }
  1493. pi_do_call,
  1494. { procedure has a try statement = no register optimization }
  1495. pi_uses_exceptions,
  1496. { procedure is declared as @var(assembler), don't optimize}
  1497. pi_is_assembler,
  1498. { procedure contains data which needs to be finalized }
  1499. pi_needs_implicit_finally,
  1500. { procedure has the implicit try..finally generated }
  1501. pi_has_implicit_finally,
  1502. { procedure uses fpu}
  1503. pi_uses_fpu,
  1504. { procedure uses GOT for PIC code }
  1505. pi_needs_got,
  1506. { references var/proc/type/const in static symtable,
  1507. i.e. not allowed for inlining from other units }
  1508. pi_uses_static_symtable,
  1509. { set if the procedure has to push parameters onto the stack }
  1510. pi_has_stackparameter,
  1511. { set if the procedure has at least one label }
  1512. pi_has_label,
  1513. { calls itself recursive }
  1514. pi_is_recursive,
  1515. { stack frame optimization not possible (only on x86 probably) }
  1516. pi_needs_stackframe,
  1517. { set if the procedure has at least one register saved on the stack }
  1518. pi_has_saved_regs,
  1519. { dfa was generated for this proc }
  1520. pi_dfaavailable,
  1521. { subroutine contains interprocedural used labels }
  1522. pi_has_interproclabel,
  1523. { subroutine contains interprocedural gotos }
  1524. pi_has_global_goto
  1525. ); *)
  1526. type
  1527. tprocinfoopt=record
  1528. mask : tprocinfoflag;
  1529. str : string[82];
  1530. end;
  1531. const
  1532. procinfoopts=ord(high(tprocinfoflag)) - ord(low(tprocinfoflag));
  1533. procinfoopt : array[0..procinfoopts] of tprocinfoopt=(
  1534. (mask:pi_has_assembler_block;
  1535. str:' has at least one assembler block'),
  1536. (mask:pi_do_call;
  1537. str:' does a call'),
  1538. (mask:pi_uses_exceptions;
  1539. str:' has a try statement = no register optimization '),
  1540. (mask:pi_is_assembler;
  1541. str:' is declared as @var(assembler), don''t optimize'),
  1542. (mask:pi_needs_implicit_finally;
  1543. str:' contains data which needs to be finalized '),
  1544. (mask:pi_has_implicit_finally;
  1545. str:' has the implicit try..finally generated '),
  1546. (mask:pi_uses_fpu;
  1547. str:' uses fpu'),
  1548. (mask:pi_needs_got;
  1549. str:' uses GOT for PIC code '),
  1550. (mask:pi_uses_static_symtable;
  1551. str:' references var/proc/type/const in static symtable'),
  1552. (mask:pi_has_stackparameter;
  1553. str:' set if the procedure has to push parameters onto the stack '),
  1554. (mask:pi_has_label;
  1555. str:' set if the procedure has at least one label '),
  1556. (mask:pi_is_recursive;
  1557. str:' calls itself recursive '),
  1558. (mask:pi_needs_stackframe;
  1559. str:' stack frame optimization not possible (only on x86 probably) '),
  1560. (mask:pi_has_saved_regs;
  1561. str:' set if the procedure has at least one register saved on the stack '),
  1562. (mask:pi_dfaavailable;
  1563. str:' dfa was generated for this proc '),
  1564. (mask:pi_has_interproclabel;
  1565. str:' subroutine contains interprocedural used labels '),
  1566. (mask:pi_has_unwind_info;
  1567. str:' unwinding info was generated for this proc '),
  1568. (mask:pi_has_global_goto;
  1569. str:' subroutine contains interprocedural goto '),
  1570. (mask:pi_has_inherited;
  1571. str:' subroutine contains inherited call '),
  1572. (mask:pi_has_nested_exit;
  1573. str:' subroutine contains a nested subroutine which calls the exit of the current one '),
  1574. (mask:pi_has_stack_allocs;
  1575. str:' allocates memory on stack, so stack may be unbalanced on exit '),
  1576. (mask:pi_estimatestacksize;
  1577. str:' stack size is estimated before subroutine is compiled '),
  1578. (mask:pi_calls_c_varargs;
  1579. str:' calls function with C-style varargs '),
  1580. (mask:pi_has_open_array_parameter;
  1581. str:' has open array parameter '),
  1582. (mask:pi_uses_threadvar;
  1583. str:' uses threadvars '),
  1584. (mask:pi_has_except_table_data;
  1585. str:' has except table data '),
  1586. (mask:pi_needs_tls;
  1587. str:' uses TLS data pointer '),
  1588. (mask:pi_uses_get_frame;
  1589. str:' uses get_frame'),
  1590. (mask:pi_uses_ymm;
  1591. str:' uses ymm register (x86 only)'),
  1592. (mask:pi_no_framepointer_needed;
  1593. str:' set if no frame pointer is needed, the rules when this applies is target specific'),
  1594. (mask:pi_normalized;
  1595. str:' has been normalized so no expressions contain block nodes ')
  1596. );
  1597. var
  1598. procinfooptions : tprocinfoflags;
  1599. i : longint;
  1600. first : boolean;
  1601. begin
  1602. ppufile.getset(tppuset4(procinfooptions));
  1603. if procinfooptions<>[] then
  1604. begin
  1605. first:=true;
  1606. for i:=0 to procinfoopts do
  1607. if (procinfoopt[i].mask in procinfooptions) then
  1608. begin
  1609. if first then
  1610. first:=false
  1611. else
  1612. write(', ');
  1613. write(procinfoopt[i].str);
  1614. end;
  1615. end;
  1616. writeln;
  1617. end;
  1618. procedure readsymoptions(space : string; Def: TPpuDef = nil);
  1619. type
  1620. tsymopt=record
  1621. mask : tsymoption;
  1622. str : string[30];
  1623. end;
  1624. const
  1625. symopts=ord(high(tsymoption)) - ord(low(tsymoption));
  1626. { sp_none = 0 corresponds to nothing }
  1627. symopt : array[1..symopts] of tsymopt=(
  1628. (mask:sp_static; str:'Static'),
  1629. (mask:sp_hint_deprecated; str:'Hint Deprecated'),
  1630. (mask:sp_hint_platform; str:'Hint Platform'),
  1631. (mask:sp_hint_library; str:'Hint Library'),
  1632. (mask:sp_hint_unimplemented; str:'Hint Unimplemented'),
  1633. (mask:sp_hint_experimental; str:'Hint Experimental'),
  1634. (mask:sp_has_overloaded; str:'Has overloaded'),
  1635. (mask:sp_internal; str:'Internal'),
  1636. (mask:sp_implicitrename; str:'Implicit Rename'),
  1637. (mask:sp_generic_para; str:'Generic Parameter'),
  1638. (mask:sp_has_deprecated_msg; str:'Has Deprecated Message'),
  1639. (mask:sp_generic_dummy; str:'Generic Dummy'),
  1640. (mask:sp_explicitrename; str:'Explicit Rename'),
  1641. (mask:sp_generic_const; str:'Generic Constant Parameter'),
  1642. (mask:sp_generic_unnamed_type;str:'Generic Unnamed Type')
  1643. );
  1644. var
  1645. symoptions : tsymoptions;
  1646. i : longint;
  1647. first : boolean;
  1648. begin
  1649. ppufile.getset(tppuset2(symoptions));
  1650. if symoptions<>[] then
  1651. begin
  1652. if Def <> nil then
  1653. begin
  1654. if sp_internal in symoptions then
  1655. Def.Visibility:=dvHidden;
  1656. if sp_generic_dummy in symoptions then
  1657. Def.GenericDummy:=true;
  1658. end;
  1659. first:=true;
  1660. for i:=1to symopts do
  1661. if (symopt[i].mask in symoptions) then
  1662. begin
  1663. if first then
  1664. first:=false
  1665. else
  1666. write(', ');
  1667. write(symopt[i].str);
  1668. end;
  1669. end;
  1670. writeln;
  1671. if sp_has_deprecated_msg in symoptions then
  1672. writeln([space,'Deprecated : ', ppufile.getstring]);
  1673. end;
  1674. procedure readvisibility(Def: TPpuDef = nil);
  1675. var
  1676. i: byte;
  1677. begin
  1678. i:=ppufile.getbyte;
  1679. if Def <> nil then
  1680. case tvisibility(i) of
  1681. vis_public: Def.Visibility:=dvPublic;
  1682. vis_published: Def.Visibility:=dvPublished;
  1683. vis_protected, vis_strictprotected: Def.Visibility:=dvProtected;
  1684. else Def.Visibility:=dvPrivate;
  1685. end;
  1686. writeln(Visibility2Str(i));
  1687. end;
  1688. procedure readattrs(def: TPpuDef);
  1689. var
  1690. i,cnt,paras: longint;
  1691. begin
  1692. cnt:=ppufile.getlongint;
  1693. if cnt>0 then
  1694. begin
  1695. writeln([space,' Attributes : ']);
  1696. space:=' '+space;
  1697. if assigned(def) then
  1698. SetLength(def.Attrs,cnt);
  1699. for i:=0 to cnt-1 do
  1700. begin
  1701. writeln([space,'** Custom Attribute ',i,' **']);
  1702. write ([space,' Type symbol : ']);
  1703. if assigned(def) then
  1704. begin
  1705. def.Attrs[i].TypeSym:=TPpuRef.Create;
  1706. readderef('',def.Attrs[i].TypeSym);
  1707. end
  1708. else
  1709. readderef('');
  1710. write ([space,' Type constructor : ']);
  1711. if assigned(def) then
  1712. begin
  1713. def.Attrs[i].TypeConstr:=TPpuRef.Create;
  1714. readderef('',def.Attrs[i].TypeConstr);
  1715. end
  1716. else
  1717. readderef('');
  1718. paras:=ppufile.getlongint;
  1719. writeln([space,' Parameters : ',paras]);
  1720. if assigned(def) then
  1721. def.Attrs[i].ParaCount:=paras;
  1722. end;
  1723. delete(space,1,4);
  1724. end;
  1725. end;
  1726. procedure readnodetree; forward;
  1727. procedure readattrparas(def: TPpuDef);
  1728. var
  1729. attr,para: LongInt;
  1730. begin
  1731. if Length(def.Attrs) > 0 then
  1732. writeln([space,' Attr Paras : ']);
  1733. space:=' '+space;
  1734. for attr:=0 to High(def.Attrs) do
  1735. begin
  1736. writeln([space,'** Custom Attribute ',attr,' Arguments **']);
  1737. space:=' '+space;
  1738. for para:=0 to def.Attrs[attr].ParaCount-1 do
  1739. begin
  1740. readnodetree;
  1741. end;
  1742. delete(space,1,4);
  1743. end;
  1744. delete(space,1,4);
  1745. end;
  1746. procedure readdefsubentries(def: TPpuDef);
  1747. begin
  1748. space:=' '+space;
  1749. readattrparas(def);
  1750. delete(space,1,4);
  1751. end;
  1752. procedure readsymsubentries(def: TPpuDef);
  1753. begin
  1754. readattrparas(def);
  1755. end;
  1756. procedure readcommonsym(const s:string; Def: TPpuDef = nil);
  1757. var
  1758. i: integer;
  1759. n: ansistring;
  1760. begin
  1761. n:=readsymstr(ppufile);
  1762. if Def <> nil then
  1763. Def.Name:=n;
  1764. i:=ppufile.getlongint;
  1765. if Def <> nil then
  1766. Def.SetSymId(i);
  1767. writeln([space,'** Symbol Id ',i,' **']);
  1768. writeln([space,s,n]);
  1769. write ([space,' File Pos : ']);
  1770. readposinfo(Def);
  1771. write ([space,' Visibility : ']);
  1772. readvisibility(Def);
  1773. write ([space,' SymOptions : ']);
  1774. readsymoptions(space+' ',Def);
  1775. readattrs(Def);
  1776. end;
  1777. procedure readcgpara(const space:string);
  1778. { this is originally in cgbase.pas }
  1779. type
  1780. TCGLoc=(LOC_INVALID, LOC_VOID, LOC_CONSTANT, LOC_JUMP, LOC_FLAGS,
  1781. LOC_REGISTER, LOC_CREGISTER, LOC_FPUREGISTER, LOC_CFPUREGISTER,
  1782. LOC_MMXREGISTER, LOC_CMMXREGISTER, LOC_MMREGISTER, LOC_CMMREGISTER,
  1783. LOC_SUBSETREG, LOC_CSUBSETREG, LOC_SUBSETREF, LOC_CSUBSETREF,
  1784. LOC_CREFERENCE, LOC_REFERENCE);
  1785. const
  1786. tcgloc2str : array[TCGLoc] of string[12] = (
  1787. 'LOC_INVALID', 'LOC_VOID', 'LOC_CONST', 'LOC_JUMP', 'LOC_FLAGS',
  1788. 'LOC_REG', 'LOC_CREG', 'LOC_FPUREG', 'LOC_CFPUREG',
  1789. 'LOC_MMXREG', 'LOC_CMMXREG', 'LOC_MMREG', 'LOC_CMMREG',
  1790. 'LOC_SSETREG', 'LOC_CSSETREG', 'LOC_SSETREF', 'LOC_CSSETREF',
  1791. 'LOC_CREF', 'LOC_REF');
  1792. var
  1793. i: byte;
  1794. ii: longint;
  1795. np: byte;
  1796. loc: tcgloc;
  1797. begin
  1798. i:=ppufile.getbyte;
  1799. writeln([space,' Alignment : ',i]);
  1800. i:=ppufile.getbyte;
  1801. writeln([space,' Size : ',i]);
  1802. ii:=ppufile.getaint;
  1803. writeln([space,' IntSize : ',ii]);
  1804. readderef(space+' ');
  1805. np:=ppufile.getbyte;
  1806. writeln([space,' NumParaloc : ',np]);
  1807. while np > 0 do
  1808. begin
  1809. i:=ppufile.getbyte;
  1810. writeln([space,' Paraloc Size : ',i]);
  1811. loc:=tcgloc(ppufile.getbyte);
  1812. if loc > high(tcgloc) then
  1813. begin
  1814. WriteError('!! Location is out of range! '+IntToStr(ord(loc)));
  1815. loc:=LOC_INVALID;
  1816. end;
  1817. writeln([space,' Paraloc Loc : (',ord(loc),') ',tcgloc2str[loc]]);
  1818. case loc of
  1819. LOC_REFERENCE:
  1820. begin
  1821. writeln([space,' RegIndex : $',hexstr(ppufile.getdword,8)]);
  1822. writeln([space,' Offset : ',ppufile.getaint]);
  1823. end;
  1824. LOC_FPUREGISTER,
  1825. LOC_CFPUREGISTER,
  1826. LOC_MMREGISTER,
  1827. LOC_CMMREGISTER,
  1828. LOC_REGISTER,
  1829. LOC_CREGISTER :
  1830. begin
  1831. writeln([space,' ShiftVal : ',ppufile.getbyte]);
  1832. writeln([space,' Register : $',hexstr(ppufile.getdword,8)]);
  1833. end;
  1834. LOC_VOID:
  1835. begin end
  1836. else
  1837. WriteError('!! Invalid location error')
  1838. end;
  1839. dec(np);
  1840. end;
  1841. end;
  1842. procedure displaytokenbuffer(tokenbuf : pbyte;tokenbufsize : longint);
  1843. type
  1844. ptoken=^ttoken;
  1845. pmsgstate =^tmsgstate;
  1846. var
  1847. tbi : longint;
  1848. state : tmsgstate;
  1849. prev_settings, new_settings : Tsettings;
  1850. nb, msgvalue, mesgnb : longint;
  1851. function readtoken: ttoken;
  1852. var
  1853. b,b2 : byte;
  1854. begin
  1855. b:=tokenbuf[tbi];
  1856. inc(tbi);
  1857. if (b and $80)<>0 then
  1858. begin
  1859. b2:=tokenbuf[tbi];
  1860. inc(tbi);
  1861. result:=ttoken(((b and $7f) shl 8) or b2);
  1862. end
  1863. else
  1864. result:=ttoken(b);
  1865. end;
  1866. function gettokenbufdword : dword;
  1867. var
  1868. var32 : dword;
  1869. begin
  1870. var32:=unaligned(pdword(@tokenbuf[tbi])^);
  1871. inc(tbi,sizeof(dword));
  1872. if ppufile.change_endian then
  1873. var32:=swapendian(var32);
  1874. result:=var32;
  1875. end;
  1876. function gettokenbufword : word;
  1877. var
  1878. var16 : word;
  1879. begin
  1880. var16:=unaligned(pword(@tokenbuf[tbi])^);
  1881. inc(tbi,sizeof(word));
  1882. if ppufile.change_endian then
  1883. var16:=swapendian(var16);
  1884. result:=var16;
  1885. end;
  1886. function gettokenbuflongint : longint;
  1887. var
  1888. var32 : longint;
  1889. begin
  1890. var32:=unaligned(plongint(@tokenbuf[tbi])^);
  1891. inc(tbi,sizeof(longint));
  1892. if ppufile.change_endian then
  1893. var32:=swapendian(var32);
  1894. result:=var32;
  1895. end;
  1896. function gettokenbufshortint : shortint;
  1897. var
  1898. var8 : shortint;
  1899. begin
  1900. var8:=pshortint(@tokenbuf[tbi])^;
  1901. inc(tbi,sizeof(shortint));
  1902. result:=var8;
  1903. end;
  1904. procedure tokenreadset(var b;size : longint);
  1905. var
  1906. i : longint;
  1907. begin
  1908. move(tokenbuf[tbi],b,size);
  1909. inc(tbi,size);
  1910. if ppufile.change_endian then
  1911. for i:=0 to size-1 do
  1912. Pbyte(@b)[i]:=reverse_byte(Pbyte(@b)[i]);
  1913. end;
  1914. function gettokenbufbyte : byte;
  1915. begin
  1916. result:=pbyte(@tokenbuf[tbi])^;
  1917. inc(tbi);
  1918. end;
  1919. function tokenreadenum(size : longint) : longword;
  1920. begin
  1921. if size=1 then
  1922. result:=gettokenbufbyte
  1923. else if size=2 then
  1924. result:=gettokenbufword
  1925. else if size=4 then
  1926. result:=gettokenbufdword;
  1927. end;
  1928. function gettokenbufsizeint : int64;
  1929. var
  1930. var64 : int64;
  1931. var32 : longint;
  1932. var16 : smallint;
  1933. begin
  1934. if CpuAddrBitSize[cpu]=64 then
  1935. begin
  1936. var64:=unaligned(pint64(@tokenbuf[tbi])^);
  1937. inc(tbi,sizeof(int64));
  1938. if ppufile.change_endian then
  1939. var64:=swapendian(var64);
  1940. result:=var64;
  1941. end
  1942. else if CpuAddrBitSize[cpu]=32 then
  1943. begin
  1944. var32:=unaligned(plongint(@tokenbuf[tbi])^);
  1945. inc(tbi,sizeof(longint));
  1946. if ppufile.change_endian then
  1947. var32:=swapendian(var32);
  1948. result:=var32;
  1949. end
  1950. else if CpuAddrBitSize[cpu]=16 then
  1951. begin
  1952. { ASizeInt is still a longint, see globtype.pas unit }
  1953. var32:=unaligned(plongint(@tokenbuf[tbi])^);
  1954. inc(tbi,sizeof(longint));
  1955. if ppufile.change_endian then
  1956. var32:=swapendian(var32);
  1957. result:=var32;
  1958. end
  1959. else
  1960. begin
  1961. WriteError('Wrong CpuAddrBitSize');
  1962. result:=0;
  1963. end;
  1964. end;
  1965. procedure tokenreadsettings(var asettings : tsettings; expected_size : asizeint);
  1966. { This procedure
  1967. needs to be changed whenever
  1968. globals.tsettings type is changed,
  1969. the problem is that no error will appear
  1970. before tests with generics are tested. PM }
  1971. var
  1972. startpos, endpos : longword;
  1973. begin
  1974. { WARNING all those fields need to be in the correct
  1975. order otherwise cross_endian PPU reading will fail }
  1976. startpos:=tbi;
  1977. with asettings do
  1978. begin
  1979. alignment.procalign:=gettokenbuflongint;
  1980. alignment.loopalign:=gettokenbuflongint;
  1981. alignment.jumpalign:=gettokenbuflongint;
  1982. alignment.jumpalignskipmax:=gettokenbuflongint;
  1983. alignment.coalescealign:=gettokenbuflongint;
  1984. alignment.coalescealignskipmax:=gettokenbuflongint;
  1985. alignment.constalignmin:=gettokenbuflongint;
  1986. alignment.constalignmax:=gettokenbuflongint;
  1987. alignment.varalignmin:=gettokenbuflongint;
  1988. alignment.varalignmax:=gettokenbuflongint;
  1989. alignment.localalignmin:=gettokenbuflongint;
  1990. alignment.localalignmax:=gettokenbuflongint;
  1991. alignment.recordalignmin:=gettokenbuflongint;
  1992. alignment.recordalignmax:=gettokenbuflongint;
  1993. alignment.maxCrecordalign:=gettokenbuflongint;
  1994. tokenreadset(globalswitches,sizeof(globalswitches));
  1995. tokenreadset(targetswitches,sizeof(targetswitches));
  1996. tokenreadset(moduleswitches,sizeof(moduleswitches));
  1997. tokenreadset(localswitches,sizeof(localswitches));
  1998. tokenreadset(modeswitches,sizeof(modeswitches));
  1999. tokenreadset(optimizerswitches,sizeof(optimizerswitches));
  2000. tokenreadset(genwpoptimizerswitches,sizeof(genwpoptimizerswitches));
  2001. tokenreadset(dowpoptimizerswitches,sizeof(dowpoptimizerswitches));
  2002. tokenreadset(debugswitches,sizeof(debugswitches));
  2003. { 0: old behaviour for sets <=256 elements
  2004. >0: round to this size }
  2005. setalloc:=gettokenbufshortint;
  2006. packenum:=gettokenbufshortint;
  2007. packrecords:=gettokenbufshortint;
  2008. maxfpuregisters:=gettokenbufshortint;
  2009. verbosity:=gettokenbuflongint;
  2010. cputype:=tcputype(tokenreadenum(sizeof(tcputype)));
  2011. optimizecputype:=tcputype(tokenreadenum(sizeof(tcputype)));
  2012. fputype:=tfputype(tokenreadenum(sizeof(tfputype)));
  2013. asmmode:=tasmmode(tokenreadenum(sizeof(tasmmode)));
  2014. interfacetype:=tinterfacetypes(tokenreadenum(sizeof(tinterfacetypes)));
  2015. defproccall:=tproccalloption(tokenreadenum(sizeof(tproccalloption)));
  2016. { tstringencoding is word type,
  2017. thus this should be OK here }
  2018. sourcecodepage:=tstringEncoding(gettokenbufword);
  2019. minfpconstprec:=tfloattype(tokenreadenum(sizeof(tfloattype)));
  2020. disabledircache:=boolean(gettokenbufbyte);
  2021. tlsmodel:=ttlsmodel(tokenreadenum(sizeof(ttlsmodel)));
  2022. { TH: Since the field was conditional originally, it was not stored in PPUs. }
  2023. { While adding ControllerSupport constant, I decided not to store ct_none }
  2024. { on targets not supporting controllers, but this might be changed here and }
  2025. { in tokenwritesettings in the future to unify the PPU structure and handling }
  2026. { of this field in the compiler. }
  2027. {$PUSH}
  2028. {$WARN 6018 OFF} (* Unreachable code due to compile time evaluation *)
  2029. if CpuHasController[cpu] then
  2030. controllertype:=tcontrollertype(tokenreadenum(sizeof(tcontrollertype)))
  2031. else
  2032. ControllerType:=ct_none;
  2033. lineendingtype:=tlineendingtype(tokenreadenum(sizeof(tlineendingtype)));
  2034. whitespacetrimcount:=gettokenbufword;
  2035. whitespacetrimauto:=boolean(gettokenbufbyte);
  2036. {$POP}
  2037. endpos:=tbi;
  2038. if endpos-startpos<>expected_size then
  2039. Writeln(['Wrong size of Settings read-in: ',expected_size,' expected, but got ',endpos-startpos]);
  2040. end;
  2041. end;
  2042. procedure dump_new_settings;
  2043. (* tsettings = record
  2044. alignment : talignmentinfo;
  2045. globalswitches : tglobalswitches;
  2046. targetswitches : ttargetswitches;
  2047. moduleswitches : tmoduleswitches;
  2048. localswitches : tlocalswitches;
  2049. modeswitches : tmodeswitches;
  2050. optimizerswitches : toptimizerswitches;
  2051. { generate information necessary to perform these wpo's during a subsequent compilation }
  2052. genwpoptimizerswitches: twpoptimizerswitches;
  2053. { perform these wpo's using information generated during a previous compilation }
  2054. dowpoptimizerswitches: twpoptimizerswitches;
  2055. debugswitches : tdebugswitches;
  2056. { 0: old behaviour for sets <=256 elements
  2057. >0: round to this size }
  2058. setalloc,
  2059. packenum : shortint;
  2060. packrecords : shortint;
  2061. maxfpuregisters : shortint;
  2062. verbosity : longint;
  2063. cputype,
  2064. optimizecputype,
  2065. asmcputype : tcputype;
  2066. fputype : tfputype;
  2067. asmmode : tasmmode;
  2068. interfacetype : tinterfacetypes;
  2069. defproccall : tproccalloption;
  2070. sourcecodepage : tstringencoding;
  2071. minfpconstprec : tfloattype;
  2072. disabledircache : boolean;
  2073. tlsmodel : ttlsmodel;
  2074. {$if defined(i8086)}
  2075. x86memorymodel : tx86memorymodel;
  2076. {$endif defined(i8086)}
  2077. {$if defined(ARM)}
  2078. instructionset : tinstructionset;
  2079. {$endif defined(ARM)}
  2080. {$if defined(LLVM) and not defined(GENERIC_CPU)}
  2081. llvmversion: tllvmversion;
  2082. {$endif defined(LLVM) and not defined(GENERIC_CPU)}
  2083. { CPU targets with microcontroller support can add a controller specific unit }
  2084. controllertype : tcontrollertype;
  2085. { WARNING: this pointer cannot be written as such in record token }
  2086. pmessage : pmessagestaterecord;
  2087. end; *)
  2088. const
  2089. targetswitchname : array[ttargetswitch] of string[77] =
  2090. { global target-specific switches }
  2091. ('Target None', {ts_none}
  2092. { generate code that results in smaller TOCs than normal (AIX) }
  2093. 'Small TOC', {ts_small_toc}
  2094. { for the JVM target: generate integer array initializations via string
  2095. constants in order to reduce the generated code size (Java routines
  2096. are limited to 64kb of bytecode) }
  2097. 'JVM compact int array init', {ts_compact_int_array_init}
  2098. { for the JVM target: initialize enum fields in constructors with the
  2099. enum class instance corresponding to ordinal value 0 (not done by
  2100. default because this initialization can only be performed after the
  2101. inherited constructors have run, and if they call a virtual method
  2102. of the current class, then this virtual method may already have
  2103. initialized that field with another value and the constructor
  2104. initialization will result in data loss }
  2105. 'JVM enum field init', {ts_jvm_enum_field_init}
  2106. { when automatically generating getters/setters for properties, use
  2107. these strings as prefixes for the generated getters/setter names }
  2108. 'Auto getter prefix', {ts_auto_getter_prefix}
  2109. 'Auto setter prefix', {ts_auto_setter_predix}
  2110. 'Thumb interworking', {ts_thumb_interworking,}
  2111. { lowercase the first character of routine names, used to generate
  2112. names that are compliant with Java coding standards from code
  2113. written according to Delphi coding standards }
  2114. 'LowerCase proc start', {ts_lowercase_proc_start,}
  2115. { initialise local variables on the JVM target so you won't get
  2116. accidental uses of uninitialised values }
  2117. 'Init locals', {ts_init_locals}
  2118. { emit a CLD instruction before using the x86 string instructions }
  2119. 'Emit CLD instruction', {ts_cld}
  2120. { increment BP before pushing it in the function prologue and decrement
  2121. it after popping it in the function epilogue, iff the function is
  2122. going to terminate with a far ret. Thus, the BP value pushed on the
  2123. stack becomes odd if the function is far and even if the function is
  2124. near. This allows walking the BP chain on the stack and e.g.
  2125. obtaining a stack trace even if the program uses a mixture of near
  2126. and far calls. This is also required for Win16 real mode, because it
  2127. allows Windows to move code segments around (in order to defragment
  2128. memory) and then walk through the stacks of all running programs and
  2129. update the segment values of the segment that has moved. }
  2130. 'Use odd BP for far procs', {ts_x86_far_procs_push_odd_bp}
  2131. 'No exception support', {ts_wasm_no_exceptions}
  2132. 'Branchful exceptions support', {ts_wasm_bf_exceptions}
  2133. 'Native WebAssembly exceptions with exnref support', {ts_wasm_native_exnref_exceptions}
  2134. 'Native WebAssembly legacy exceptions support', {ts_wasm_native_legacy_exceptions}
  2135. 'WebAssembly threads support', {ts_wasm_threads}
  2136. 'Use WebAssembly saturating (nontrapping) float to int conversion instructions' {ts_wasm_saturating_float_to_int}
  2137. );
  2138. moduleswitchname : array[tmoduleswitch] of string[40] =
  2139. ('Module None', {cs_modulenone,}
  2140. { parser }
  2141. 'Floating Point Emulation',{ cs_fp_emulation}
  2142. 'Extended syntax', {cs_extsyntax}
  2143. { support }
  2144. 'Goto allowed', {cs_support_goto}
  2145. 'Macro support', {cs_support_macro}
  2146. 'C operator support', {cs_support_c_operators}
  2147. { generation }
  2148. 'Profile', {cs_profile}
  2149. 'Debug information', {cs_debuginfo}
  2150. 'Compilation of System unit', {cs_compilesystem}
  2151. 'Line information', {cs_lineinfo}
  2152. 'Implicit exceptions', {cs_implicit_exceptions}
  2153. 'Explicit CodePage', {cs_explicit_codepage}
  2154. 'System CodePage', {cs_system_codepage}
  2155. { linking }
  2156. 'Create smart units', {cs_create_smart}
  2157. 'Create dynamic', {cs_create_dynamic}
  2158. 'Create PIC code', {cs_create_pic}
  2159. { browser switches are back }
  2160. 'Browser', {cs_browser}
  2161. 'Local Browser', {cs_local_browser}
  2162. { target specific }
  2163. 'Executable Stack', {cs_executable_stack}
  2164. { i8086 specific }
  2165. 'Huge code', {cs_huge_code}
  2166. 'Win16 smart callbacks', {cs_win16_smartcallbacks}
  2167. { Record usage of checkpointer experimental feature }
  2168. 'CheckPointer used', {cs_checkpointer_called}
  2169. 'Supports LLVM Link-Time Optimization' {cs_lto}
  2170. ,'Enable LLVM Address Sanitizer'
  2171. );
  2172. globalswitchname : array[tglobalswitch] of string[73] =
  2173. ('Global None',{cs_globalnone}
  2174. { parameter switches }
  2175. 'Check unit name', {cs_check_unit_name}
  2176. 'Constructor name', {cs_constructor_name}
  2177. 'Support exceptions',{cs_support_exceptions}
  2178. 'Support Objective-C pas',{ cs_support_c_objectivepas}
  2179. 'Transparent file names', {cs_transparent_file_names}
  2180. { units }
  2181. 'Load Objpas Unit', {cs_load_objpas_unit}
  2182. 'Load GPC unit', {cs_load_gpc_unit}
  2183. 'Load FPCKylix unit', {cs_load_fpcylix_unit}
  2184. 'Support Vectors', {cs_support_vectors}
  2185. { debuginfo }
  2186. 'Use HeapTRc unit', {cs_use_heaptrc}
  2187. 'Use line information', {cs_use_lineinfo}
  2188. 'Use GDB Valgrind', {cs_gdb_valgrind}
  2189. 'No regalloc', {cs_no_regalloc}
  2190. 'Stabs preserve cases', {cs_stabs_preservecase}
  2191. { assembling }
  2192. 'Leave assembler file', {cs_asm_leave}
  2193. 'Use external assembler', {cs_asm_extern}
  2194. 'Use pipes to call assembler', {cs_asm_pipe}
  2195. 'Add source infos into assembler files', {cs_asm_source}
  2196. 'Add RTTI infos into assembler files', {cs_asm_rtti_source}
  2197. 'Add register allocation into assembler files', {cs_asm_regalloc}
  2198. 'Add temporary allocation into assmebler files', {cs_asm_tempalloc}
  2199. 'Add node information into assembler files', {cs_asm_nodes}
  2200. 'Adapt assembler call to GNU version <= 2.25', {cs_asm_pre_binutils_2_25}
  2201. { linking }
  2202. 'Skip linking stage', {cs_link_nolink}
  2203. 'Link static', {cs_link_static}
  2204. 'Link smart', {cs_link_smart}
  2205. 'Link shared', {cs_link_shared}
  2206. 'Link deffile', {cs_link_deffile}
  2207. 'Strip after linking', {cs_link_strip}
  2208. 'Use linker static flag',{cs_link_staticflag}
  2209. 'Link on target OS',{cs_link_on_target}
  2210. 'Use external linker', {cs_link_extern}
  2211. 'Link opt vtable', {cs_link_opt_vtable}
  2212. 'Link opt used sections', {cs_link_opt_used_sections}
  2213. 'Link debug to separate file',{cs_link_separate_dbg_file}
  2214. 'Create linker map', {cs_link_map}
  2215. 'Link to pthread', {cs_link_pthread}
  2216. 'Link no default lib order', {cs_link_no_default_lib_order}
  2217. 'Link using native linker', {cs_link_native}
  2218. 'Link for GNU linker version <=2.19', {cs_link_pre_binutils_2_19}
  2219. 'Link using vlink', {cs_link_vlink}
  2220. 'Discard _START code', {cs_link_discard_start}
  2221. 'Discard code initializing the zero register and stack pointer', {cs_link_discard_zeroreg_sp}
  2222. 'Discard initializing data', {cs_link_discard_copydata}
  2223. 'Discard jump to PASCALMAIN', {cs_link_discard_jmp_main}
  2224. 'Link-Time Optimization disabled for system unit', {cs_lto_nosystem}
  2225. 'Assemble on target OS', {cs_assemble_on_target}
  2226. 'Use a memory model to support >2GB static data on 64 Bit target', {cs_large}
  2227. 'Generate UF2 binary', {cs_generate_uf2}
  2228. 'Link using ld.lld GNU compatible LLVM linker' {cs_link_lld}
  2229. );
  2230. localswitchname : array[tlocalswitch] of string[50] =
  2231. { Switches which can be changed locally }
  2232. ('Local None', {cs_localnone}
  2233. { codegen }
  2234. 'Check overflow', {cs_check_overflow}
  2235. 'Check range', {cs_check_range}
  2236. 'Check object error', {cs_check_object}
  2237. 'Check I/O error', {cs_check_io}
  2238. 'Check stack', {cs_check_stack}
  2239. 'Check pointer', {cs_checkpointer}
  2240. 'Check ordinal size', {cs_check_ordinal_size}
  2241. 'Generate stackframes', {cs_generate_stackframes}
  2242. 'Do assertions', {cs_do_assertion}
  2243. 'Generate RTTI', {cs_generate_rtti}
  2244. 'Full boolean evaluaion', {cs_full_boolean_eval}
  2245. 'Typed constant are writable', {cs_typed_const_writable}
  2246. 'Allow calcuation on enum types', {cs_allow_enum_calc}
  2247. 'Do inline', {cs_do_inline}
  2248. 'Add FWAIT instruction for FPU 8087', {cs_fpu_fwait}
  2249. 'IEEE errors', {cs_ieee_errors}
  2250. 'Check low address loading', {cs_check_low_addr_load}
  2251. 'Imported data', {cs_imported_data}
  2252. 'Excess precision', {cs_excessprecision}
  2253. 'Check fpu exceptions', {cs_check_fpu_exceptions}
  2254. 'Check all case coverage', {cs_check_all_case_coverage}
  2255. { mmx }
  2256. 'Allow MMX instructions', {cs_mmx}
  2257. 'Use MMX saturation', {cs_mmx_saturation}
  2258. { parser }
  2259. 'Use typed addresses', {cs_typed_addresses}
  2260. 'Use strict var strings', {cs_strict_var_strings}
  2261. 'Use reference counted strings', {cs_refcountedstrings}
  2262. 'Use bit-packing', {cs_bitpacking}
  2263. 'Use var property setter', {cs_varpropsetter}
  2264. 'Use scoped enums',{cs_scopedenums}
  2265. 'Use pointer math', {cs_pointermath}
  2266. 'Open string', {cs_openstring}
  2267. { macpas specific}
  2268. 'MACPAS exteranl variable', {cs_external_var}
  2269. 'MACPAS externally visible', {cs_externally_visible}
  2270. { jvm specific }
  2271. 'JVM check var copyout', {cs_check_var_copyout}
  2272. 'Zero based strings', {cs_zerobasedstrings}
  2273. { i8086 specific }
  2274. 'i8086 force FAR calls', {cs_force_far_calls}
  2275. 'i8086 huge pointer arithmetic', {cs_hugeptr_arithmetic_normalization}
  2276. 'i8086 huge pointer comparison', {cs_hugeptr_comparison_normalization}
  2277. 'enforce legacy ifend behaviour' {cs_legacyifend}
  2278. );
  2279. { Switches which can be changed by a mode (fpc,tp7,delphi) }
  2280. modeswitchname : array[tmodeswitch] of string[50] =
  2281. ('m_none',
  2282. { generic }
  2283. 'm_fpc','m_objfpc','m_delphi','m_tp7','m_mac','m_iso','m_extpas',
  2284. {$ifdef gpc_mode}'m_gpc',{$endif}
  2285. { more specific }
  2286. 'm_class', { delphi class model }
  2287. 'm_objpas', { load objpas unit }
  2288. 'm_result', { result in functions }
  2289. 'm_string_pchar', { pchar 2 string conversion }
  2290. 'm_cvar_support', { cvar variable directive }
  2291. 'm_nested_comment', { nested comments }
  2292. 'm_tp_procvar', { tp style procvars (no @ needed) }
  2293. 'm_mac_procvar', { macpas style procvars }
  2294. 'm_repeat_forward', { repeating forward declarations is needed }
  2295. 'm_pointer_2_procedure', { allows the assignment of pointers to
  2296. procedure variables }
  2297. 'm_autoderef', { does auto dereferencing of struct. vars }
  2298. 'm_initfinal', { initialization/finalization for units }
  2299. 'm_default_ansistring', { ansistring turned on by default }
  2300. 'm_out', { support the calling convention OUT }
  2301. 'm_default_para', { support default parameters }
  2302. 'm_hintdirective', { support hint directives }
  2303. 'm_duplicate_names', { allow locals/paras to have duplicate names of globals }
  2304. 'm_property', { allow properties }
  2305. 'm_default_inline', { allow inline proc directive }
  2306. 'm_except', { allow exception-related keywords }
  2307. 'm_objectivec1', { support interfacing with Objective-C (1.0) }
  2308. 'm_objectivec2', { support interfacing with Objective-C (2.0) }
  2309. 'm_nested_procvars', { support nested procedural variables }
  2310. 'm_non_local_goto', { support non local gotos (like iso pascal) }
  2311. 'm_advanced_records', { advanced record syntax with visibility sections, methods and properties }
  2312. 'm_isolike_unary_minus', { unary minus like in iso pascal: same precedence level as binary minus/plus }
  2313. 'm_systemcodepage', { use system codepage as compiler codepage by default, emit ansistrings with system codepage }
  2314. 'm_final_fields', { allows declaring fields as "final", which means they must be initialised
  2315. in the (class) constructor and are constant from then on (same as final
  2316. fields in Java) }
  2317. 'm_default_unicodestring', { makes the default string type in $h+ mode unicodestring rather than
  2318. ansistring; similarly, char becomes unicodechar rather than ansichar }
  2319. 'm_type_helpers', { allows the declaration of "type helper" for all supported types
  2320. (primitive types, records, classes, interfaces) }
  2321. 'm_blocks', { support for http://en.wikipedia.org/wiki/Blocks_(C_language_extension) }
  2322. 'm_isolike_io', { I/O as it required by an ISO compatible compiler }
  2323. 'm_isolike_program_para',{ program parameters as it required by an ISO compatible compiler }
  2324. 'm_isolike_mod', { mod operation as it is required by an iso compatible compiler }
  2325. 'm_array_operators', { use Delphi compatible array operators instead of custom ones ("+") }
  2326. 'm_multi_helpers', { helpers can appear in multiple scopes simultaneously }
  2327. 'm_array2dynarray', { regular arrays can be implicitly converted to dynamic arrays }
  2328. 'm_prefixed_attributes', { enable attributes that are defined before the type they belong to }
  2329. 'm_underscoreisseparator',{ _ can be used as separator to group digits in numbers }
  2330. 'm_implicit_function_specialization', { attempt to specialize generic function by inferring types from parameters }
  2331. 'm_function_references', { enable Delphi-style function references }
  2332. 'm_anonymous_functions', { enable Delphi-style anonymous functions }
  2333. 'm_multiline_strings' { multi-line strings denoted with '`' are enabled and valid }
  2334. );
  2335. { optimizer }
  2336. optimizerswitchname : array[toptimizerswitch] of string[50] =
  2337. ('cs_opt_level1',
  2338. 'cs_opt_level2',
  2339. 'cs_opt_level3',
  2340. 'cs_opt_level4',
  2341. 'cs_opt_regvar',
  2342. 'cs_opt_uncertain',
  2343. 'cs_opt_size',
  2344. 'cs_opt_stackframe',
  2345. 'cs_opt_peephole',
  2346. 'cs_opt_loopunroll',
  2347. 'cs_opt_tailrecursion',
  2348. 'cs_opt_nodecse',
  2349. 'cs_opt_nodedfa',
  2350. 'cs_opt_loopstrength',
  2351. 'cs_opt_scheduler',
  2352. 'cs_opt_autoinline',
  2353. 'cs_useebp',
  2354. 'cs_userbp',
  2355. 'cs_opt_reorder_fields',
  2356. 'cs_opt_fastmath',
  2357. { Allow removing expressions whose result is not used, even when this
  2358. can change program behaviour (range check errors disappear',
  2359. access violations due to invalid pointer derefences disappear, ...).
  2360. Note: it does not (and must not) remove expressions that have
  2361. explicit side-effects, only implicit side-effects (like the ones
  2362. mentioned before) can disappear.
  2363. }
  2364. 'cs_opt_dead_values',
  2365. { compiler checks for empty procedures/methods and removes calls to them if possible }
  2366. 'cs_opt_remove_empty_proc',
  2367. 'cs_opt_constant_propagate',
  2368. 'cs_opt_dead_store_eliminate',
  2369. 'cs_opt_forcenostackframe',
  2370. 'cs_opt_use_load_modify_store',
  2371. 'cs_opt_unused_para',
  2372. 'cs_opt_consts',
  2373. 'cs_opt_forloop'
  2374. );
  2375. var
  2376. globalswitch : tglobalswitch;
  2377. targetswitch : ttargetswitch;
  2378. moduleswitch : tmoduleswitch;
  2379. localswitch : tlocalswitch;
  2380. modeswitch : tmodeswitch;
  2381. optimizerswitch : toptimizerswitch;
  2382. globalswitches : tglobalswitches;
  2383. targetswitches : ttargetswitches;
  2384. moduleswitches : tmoduleswitches;
  2385. localswitches : tlocalswitches;
  2386. modeswitches : tmodeswitches;
  2387. optimizerswitches : toptimizerswitches;
  2388. begin
  2389. {alignment : talignmentinfo;}
  2390. {talignmentinfo = packed record}
  2391. writeln('Procedure alignment: '+tostr(new_settings.alignment.procalign));
  2392. writeln('Loop alignment: '+tostr(new_settings.alignment.loopalign));
  2393. { alignment for labels after unconditional jumps, this must be a power of two }
  2394. writeln('Jump alignment: '+tostr(new_settings.alignment.jumpalign));
  2395. { max. alignment for labels after unconditional jumps:
  2396. the compiler tries to align jumpalign, however, to do so it inserts at maximum jumpalignskipmax bytes or uses
  2397. the next smaller power of two of jumpalign }
  2398. writeln('Jump skip max alignment: '+tostr(new_settings.alignment.jumpalignskipmax));
  2399. { alignment for labels where two flows of the program flow coalesce, this must be a power of two }
  2400. writeln('Coalescence alignment: '+tostr(new_settings.alignment.coalescealign));
  2401. { max. alignment for labels where two flows of the program flow coalesce
  2402. the compiler tries to align to coalescealign, however, to do so it inserts at maximum coalescealignskipmax bytes or uses
  2403. the next smaller power of two of coalescealign }
  2404. writeln('Coalescence skip max alignment: '+tostr(new_settings.alignment.coalescealignskipmax));
  2405. writeln('Const min alignment: '+tostr(new_settings.alignment.constalignmin));
  2406. writeln('Const max alignment: '+tostr(new_settings.alignment.constalignmax));
  2407. writeln('Var min alignment: '+tostr(new_settings.alignment.varalignmin));
  2408. writeln('Var max alignment: '+tostr(new_settings.alignment.varalignmax));
  2409. writeln('Local min alignment: '+tostr(new_settings.alignment.localalignmin));
  2410. writeln('Local max alignment: '+tostr(new_settings.alignment.localalignmax));
  2411. writeln('Min record alignment: '+tostr(new_settings.alignment.recordalignmin));
  2412. writeln('Max record alignment: '+tostr(new_settings.alignment.recordalignmax));
  2413. writeln('Max C record alignment: '+tostr(new_settings.alignment.maxCrecordalign));
  2414. globalswitches:=new_settings.globalswitches;
  2415. for globalswitch:=low(tglobalswitch) to high(tglobalswitch) do
  2416. if globalswitch in globalswitches then
  2417. begin
  2418. writeln('global switch: '+globalswitchname[globalswitch]);
  2419. exclude(globalswitches,globalswitch);
  2420. end;
  2421. if (globalswitches <> []) then
  2422. writeln('Unknown global switch');
  2423. targetswitches:=new_settings.targetswitches;
  2424. for targetswitch:=low(ttargetswitch) to high(ttargetswitch) do
  2425. if targetswitch in targetswitches then
  2426. begin
  2427. writeln('target switch: '+targetswitchname[targetswitch]);
  2428. exclude(targetswitches,targetswitch);
  2429. end;
  2430. if (targetswitches <> []) then
  2431. writeln('Unknown target switch');
  2432. moduleswitches:=new_settings.moduleswitches;
  2433. for moduleswitch:=low(tmoduleswitch) to high(tmoduleswitch) do
  2434. if moduleswitch in moduleswitches then
  2435. begin
  2436. writeln('module switch: '+moduleswitchname[moduleswitch]);
  2437. exclude(moduleswitches,moduleswitch);
  2438. end;
  2439. if (moduleswitches <> []) then
  2440. writeln('Unknown module switch');
  2441. localswitches:=new_settings.localswitches;
  2442. for localswitch:=low(tlocalswitch) to high(tlocalswitch) do
  2443. if localswitch in localswitches then
  2444. begin
  2445. writeln('local switch: '+localswitchname[localswitch]);
  2446. exclude(localswitches,localswitch);
  2447. end;
  2448. if (localswitches <> []) then
  2449. writeln('Unknown local switch');
  2450. modeswitches:=new_settings.modeswitches;
  2451. for modeswitch:=low(tmodeswitch) to high(tmodeswitch) do
  2452. if modeswitch in modeswitches then
  2453. begin
  2454. writeln(['mode switch: ',modeswitchname[modeswitch]]);
  2455. exclude(modeswitches,modeswitch);
  2456. end;
  2457. if (modeswitches <> []) then
  2458. writeln('Unknown mode switch');
  2459. optimizerswitches:=new_settings.optimizerswitches;
  2460. for optimizerswitch:=low(toptimizerswitch) to high(toptimizerswitch) do
  2461. if optimizerswitch in optimizerswitches then
  2462. begin
  2463. writeln(['optimizer switch: ',optimizerswitchname[optimizerswitch]]);
  2464. exclude(optimizerswitches,optimizerswitch);
  2465. end;
  2466. if (optimizerswitches <> []) then
  2467. writeln('Unknown optimizer switch');
  2468. writeln(['Set allocation size ',new_settings.setalloc]);
  2469. writeln(['Pack enums ',new_settings.packenum]);
  2470. writeln(['Pack records ',new_settings.packrecords]);
  2471. writeln(['Max FPU registers ',new_settings.maxfpuregisters]);
  2472. writeln('Verbosity '+hexstr(new_settings.verbosity,8));
  2473. writeln(['CPU type ',new_settings.cputype]);
  2474. writeln(['CPU optimize type ',new_settings.optimizecputype]);
  2475. writeln(['FPU type ',new_settings.fputype]);
  2476. writeln(['ASM mode ',new_settings.asmmode]);
  2477. end;
  2478. var
  2479. linestr,genstr : string;
  2480. token : ttoken;
  2481. copy_size, stbi, last_col, new_col : longint;
  2482. last_line,new_line : dword;
  2483. len : sizeint;
  2484. wstring : widestring;
  2485. astring : ansistring;
  2486. begin
  2487. tbi:=0;
  2488. last_line:=0;
  2489. last_col:=0;
  2490. linestr:='';
  2491. genstr:='';
  2492. fillchar(new_settings,sizeof(new_settings),#0);
  2493. fillchar(prev_settings,sizeof(prev_settings),#0);
  2494. write([space,' Tokens: ']);
  2495. while tbi<tokenbufsize do
  2496. begin
  2497. token:=readtoken;
  2498. if token<>_GENERICSPECIALTOKEN then
  2499. begin
  2500. if token <= high(ttoken) then
  2501. begin
  2502. write(arraytokeninfo[token].str);
  2503. if not (token in [_CWCHAR, _CWSTRING, _CSTRING, _CCHAR,
  2504. _INTCONST,_REALNUMBER, _ID]) then
  2505. StrAppend(linestr,lowercase(arraytokeninfo[token].str));
  2506. end
  2507. else
  2508. begin
  2509. HasMoreInfos;
  2510. write('Error in Token List');
  2511. break;
  2512. end;
  2513. {idtoken:=}readtoken;
  2514. end;
  2515. case token of
  2516. _CWCHAR,
  2517. _CWSTRING :
  2518. begin
  2519. len:=gettokenbufsizeint;
  2520. setlength(wstring,len);
  2521. move(tokenbuf[tbi],wstring[1],len*2);
  2522. write([' ''',wstring,'''']);
  2523. StrAppend(linestr,' ''');
  2524. StrAppend(linestr,wstring);
  2525. StrAppend(linestr,'''');
  2526. inc(tbi,len*2);
  2527. end;
  2528. _CSTRING:
  2529. begin
  2530. len:=gettokenbufsizeint;
  2531. setlength(astring,len);
  2532. if len>0 then
  2533. move(tokenbuf[tbi],astring[1],len);
  2534. write([' ''',astring,'''']);
  2535. StrAppend(linestr,' ''');
  2536. StrAppend(linestr,astring);
  2537. StrAppend(linestr,'''');
  2538. inc(tbi,len);
  2539. end;
  2540. _CCHAR:
  2541. begin
  2542. write([' ''',unaligned(pshortstring(@tokenbuf[tbi])^),'''']);
  2543. StrAppend(linestr,' ''');
  2544. StrAppend(linestr,unaligned(pshortstring(@tokenbuf[tbi])^));
  2545. StrAppend(linestr,'''');
  2546. inc(tbi,tokenbuf[tbi]+1);
  2547. end;
  2548. _INTCONST,
  2549. _REALNUMBER :
  2550. begin
  2551. write([' ',unaligned(pshortstring(@tokenbuf[tbi])^)]);
  2552. StrAppend(linestr,unaligned(pshortstring(@tokenbuf[tbi])^));
  2553. inc(tbi,tokenbuf[tbi]+1);
  2554. end;
  2555. _ID :
  2556. begin
  2557. write([' ',unaligned(pshortstring(@tokenbuf[tbi])^)]);
  2558. StrAppend(linestr,unaligned(pshortstring(@tokenbuf[tbi])^));
  2559. inc(tbi,tokenbuf[tbi]+1);
  2560. end;
  2561. _GENERICSPECIALTOKEN:
  2562. begin
  2563. { Short version of column change,
  2564. byte or $80 used }
  2565. if (tokenbuf[tbi] and $80)<>0 then
  2566. begin
  2567. new_col:=tokenbuf[tbi] and $7f;
  2568. write(['Col: ',new_col]);
  2569. if length(linestr)<new_col-1 then
  2570. StrAppend(linestr,StringOfChar(' ',new_col - 1 - length(linestr)));
  2571. inc(tbi);
  2572. last_col:=new_col;
  2573. end
  2574. else
  2575. case tspecialgenerictoken(tokenbuf[tbi]) of
  2576. ST_LOADSETTINGS:
  2577. begin
  2578. inc(tbi);
  2579. write([space,'Settings: ']);
  2580. fillchar(new_settings,sizeof(new_settings),#0);
  2581. { This does not load pmessage pointer }
  2582. new_settings.pmessage:=nil;
  2583. { TSettings size depends in target...
  2584. We first read the size of the copied part }
  2585. { Still not cross endian ready :( }
  2586. copy_size:=gettokenbufsizeint;
  2587. stbi:=tbi;
  2588. tokenreadsettings(new_settings, copy_size);
  2589. tbi:=stbi+copy_size;
  2590. if CompareByte(new_settings,prev_settings,copy_size)<>0 then
  2591. begin
  2592. dump_new_settings;
  2593. writeln;
  2594. end
  2595. else
  2596. begin
  2597. writeln('Unchanged');
  2598. end;
  2599. prev_settings:=new_settings;
  2600. end;
  2601. ST_LOADMESSAGES:
  2602. begin
  2603. inc(tbi);
  2604. mesgnb:=gettokenbufsizeint;;
  2605. writeln([space,mesgnb,' messages: ']);
  2606. if (tbi+2*sizeof(longint)*mesgnb>tokenbufsize) then
  2607. begin
  2608. WriteError('!! Error: number of messages incompatible with token buffer size');
  2609. end;
  2610. for nb:=1 to mesgnb do
  2611. begin
  2612. msgvalue:=gettokenbuflongint;
  2613. state:=tmsgstate(gettokenbuflongint);
  2614. writeln(['#',msgvalue,' ',state]);
  2615. end;
  2616. end;
  2617. ST_LINE:
  2618. begin
  2619. inc(tbi);
  2620. new_line:=gettokenbufdword;
  2621. if (new_line<>last_line) then
  2622. begin
  2623. StrAppend(genstr,linestr+LineEnding);
  2624. linestr:='';
  2625. end;
  2626. writeln(['Line: ',new_line]);
  2627. last_line:=new_line;
  2628. end;
  2629. ST_COLUMN:
  2630. begin
  2631. inc(tbi);
  2632. new_col:=gettokenbufword;
  2633. write(['Col: ',new_col]);
  2634. if length(linestr)<new_col - 1 then
  2635. StrAppend(linestr,StringOfChar(' ',new_col - 1 - length(linestr)));
  2636. last_col:=new_col;
  2637. end;
  2638. ST_FILEINDEX:
  2639. begin
  2640. inc(tbi);
  2641. StrAppend(genstr,linestr+LineEnding);
  2642. linestr:='';
  2643. write(['File: ',gettokenbufword]);
  2644. end;
  2645. else
  2646. begin
  2647. HasMoreInfos;
  2648. write('Error in Token List');
  2649. break;
  2650. end;
  2651. end;
  2652. end;
  2653. else ; { empty else to avoid warning }
  2654. end;
  2655. if tbi<tokenbufsize then
  2656. write(',');
  2657. end;
  2658. if (tbi>tokenbufsize) then
  2659. begin
  2660. WriteError('!! Error: read past of token buffer size');
  2661. end
  2662. else
  2663. writeln;
  2664. StrAppend(genstr,linestr);
  2665. writeln(['##',genstr,'##']);
  2666. end;
  2667. procedure readcommondef(const s:string; out defoptions: tdefoptions; Def: TPpuDef = nil);
  2668. type
  2669. tdefopt=record
  2670. mask : tdefoption;
  2671. str : string[30];
  2672. end;
  2673. tdefstateinfo=record
  2674. mask : tdefstate;
  2675. str : string[30];
  2676. end;
  2677. tgenconstrflag=record
  2678. mask : tgenericconstraintflag;
  2679. str : string[30];
  2680. end;
  2681. const
  2682. defopt : array[1..ord(high(tdefoption))] of tdefopt=(
  2683. (mask:df_unique; str:'Unique Type'),
  2684. (mask:df_generic; str:'Generic'),
  2685. (mask:df_specialization; str:'Specialization'),
  2686. (mask:df_copied_def; str:'Copied Typedef'),
  2687. (mask:df_genconstraint; str:'Generic Constraint'),
  2688. { this should never happen for defs stored to a ppu file }
  2689. (mask:df_not_registered_no_free; str:'Unregistered/No free (invalid)'),
  2690. (mask:df_llvm_no_struct_packing; str:'LLVM unpacked struct'),
  2691. (mask:df_internal; str:'Internal'),
  2692. (mask:df_has_global_ref; str:'Has Global Ref'),
  2693. (mask:df_has_generic_fields; str:'Has generic fields'),
  2694. (mask:df_llvm_no_typename; str:'LLVM no typename')
  2695. );
  2696. defstate : array[1..ord(high(tdefstate))] of tdefstateinfo=(
  2697. (mask:ds_vmt_written; str:'VMT Written'),
  2698. (mask:ds_rtti_table_used; str:'RTTITable Used'),
  2699. (mask:ds_init_table_used; str:'InitTable Used'),
  2700. (mask:ds_rtti_table_written; str:'RTTITable Written'),
  2701. (mask:ds_init_table_written; str:'InitTable Written'),
  2702. (mask:ds_dwarf_dbg_info_used; str:'Dwarf DbgInfo Used'),
  2703. (mask:ds_dwarf_dbg_info_written;str:'Dwarf DbgInfo Written')
  2704. );
  2705. genconstrflag : array[1..ord(high(tgenericconstraintflag))] of tgenconstrflag=(
  2706. (mask:gcf_constructor; str:'Constructor'),
  2707. (mask:gcf_class; str:'Class'),
  2708. (mask:gcf_record; str:'Record')
  2709. );
  2710. var
  2711. defstates : tdefstates;
  2712. i, nb, len : longint;
  2713. first : boolean;
  2714. min_size, tokenbufsize : longint;
  2715. tokenbuf : pbyte;
  2716. genconstr : tgenericconstraintflags;
  2717. begin
  2718. i:=ppufile.getlongint;
  2719. if Def <> nil then
  2720. Def.Id:=i;
  2721. writeln([space,'** Definition Id ',i,' **']);
  2722. writeln([space,s]);
  2723. write ([space,' Type symbol : ']);
  2724. if Def <> nil then
  2725. readderef('', Def.Ref)
  2726. else
  2727. readderef('');
  2728. write ([space,' DefOptions : ']);
  2729. ppufile.getset(tppuset2(defoptions));
  2730. if defoptions<>[] then
  2731. begin
  2732. first:=true;
  2733. for i:=1to high(defopt) do
  2734. if (defopt[i].mask in defoptions) then
  2735. begin
  2736. if first then
  2737. first:=false
  2738. else
  2739. write(', ');
  2740. write(defopt[i].str);
  2741. end;
  2742. end;
  2743. writeln;
  2744. write ([space,' DefStates : ']);
  2745. ppufile.getset(tppuset1(defstates));
  2746. if defstates<>[] then
  2747. begin
  2748. first:=true;
  2749. for i:=1 to high(defstate) do
  2750. if (defstate[i].mask in defstates) then
  2751. begin
  2752. if first then
  2753. first:=false
  2754. else
  2755. write(', ');
  2756. write(defstate[i].str);
  2757. end;
  2758. end;
  2759. writeln;
  2760. if df_unique in defoptions then
  2761. begin
  2762. write ([space,' OriginalDef : ']);
  2763. readderef(space);
  2764. end;
  2765. if df_genconstraint in defoptions then
  2766. begin
  2767. ppufile.getset(tppuset1(genconstr));
  2768. write ([space,' GenConstraints : ']);
  2769. if genconstr<>[] then
  2770. begin
  2771. first:=true;
  2772. for i:=1 to high(genconstrflag) do
  2773. if (genconstrflag[i].mask in genconstr) then
  2774. begin
  2775. if first then
  2776. first:=false
  2777. else
  2778. write(', ');
  2779. write(genconstrflag[i].str);
  2780. end;
  2781. end;
  2782. writeln;
  2783. len:=ppufile.getlongint;
  2784. if len>0 then
  2785. begin
  2786. space:=' '+space;
  2787. writeln([space,'------ constraint defs begin ------']);
  2788. for i:=0 to len-1 do
  2789. begin
  2790. writeln([space,'------ constraint def ',i,' ------']);
  2791. readderef(space);
  2792. end;
  2793. writeln([space,'------ constraint defs end ------']);
  2794. delete(space,1,4);
  2795. end;
  2796. end;
  2797. if [df_generic,df_specialization]*defoptions<>[] then
  2798. begin
  2799. nb:=ppufile.getlongint;
  2800. writeln([space,'has ',nb,' parameters']);
  2801. if nb>0 then
  2802. begin
  2803. for i:=0 to nb-1 do
  2804. begin
  2805. writeln([space,'parameter ',i,': ',ppufile.getstring]);
  2806. readderef(space);
  2807. end;
  2808. end;
  2809. end;
  2810. if df_generic in defoptions then
  2811. begin
  2812. tokenbufsize:=ppufile.getlongint;
  2813. writeln([space,' Tokenbuffer size : ',tokenbufsize]);
  2814. tokenbuf:=allocmem(tokenbufsize);
  2815. ppufile.getdata(tokenbuf^,tokenbufsize);
  2816. displaytokenbuffer(tokenbuf,tokenbufsize);
  2817. freemem(tokenbuf);
  2818. end;
  2819. if df_specialization in defoptions then
  2820. begin
  2821. write ([space,' Orig. GenericDef : ']);
  2822. readderef('');
  2823. end;
  2824. space:=space+' ';
  2825. readattrs(def);
  2826. delete(space,1,4);
  2827. current_defoptions:=defoptions;
  2828. end;
  2829. { Read abstract procdef and return if inline procdef }
  2830. { type tproccalloption is in globtype unit }
  2831. { type tproctypeoption is in globtype unit }
  2832. { type tprocoption is in globtype unit }
  2833. procedure read_abstract_proc_def(var proccalloption:tproccalloption;var procoptions:tprocoptions; ProcDef: TPpuProcDef);
  2834. type
  2835. tproccallopt=record
  2836. mask : tproccalloption;
  2837. str : string[30];
  2838. end;
  2839. tproctypeopt=record
  2840. mask : tproctypeoption;
  2841. str : string[30];
  2842. end;
  2843. tprocopt=record
  2844. mask : tprocoption;
  2845. str : string[34];
  2846. end;
  2847. const
  2848. {proccalloptionStr is also in globtype unit }
  2849. proctypeopt : array[1..ord(high(tproctypeoption))] of tproctypeopt=(
  2850. (mask:potype_proginit; str:'ProgInit'),
  2851. (mask:potype_unitinit; str:'UnitInit'),
  2852. (mask:potype_unitfinalize; str:'UnitFinalize'),
  2853. (mask:potype_constructor; str:'Constructor'),
  2854. (mask:potype_destructor; str:'Destructor'),
  2855. (mask:potype_operator; str:'Operator'),
  2856. (mask:potype_procedure; str:'Procedure'),
  2857. (mask:potype_function; str:'Function'),
  2858. (mask:potype_class_constructor; str:'Class Constructor'),
  2859. (mask:potype_class_destructor; str:'Class Destructor'),
  2860. { Dispinterface property accessors }
  2861. (mask:potype_propgetter; str:'Property Getter'),
  2862. (mask:potype_propsetter; str:'Property Setter'),
  2863. (mask:potype_exceptfilter; str:'SEH filter'),
  2864. (mask:potype_mainstub; str:'main stub'),
  2865. (mask:potype_pkgstub; str:'package stub'),
  2866. (mask:potype_libmainstub; str:'library main stub')
  2867. );
  2868. procopt : array[1..ord(high(tprocoption))] of tprocopt=(
  2869. (mask:po_classmethod; str:'ClassMethod'),
  2870. (mask:po_virtualmethod; str:'VirtualMethod'),
  2871. (mask:po_abstractmethod; str:'AbstractMethod'),
  2872. (mask:po_finalmethod; str:'FinalMethod'),
  2873. (mask:po_staticmethod; str:'StaticMethod'),
  2874. (mask:po_overridingmethod;str:'OverridingMethod'),
  2875. (mask:po_methodpointer; str:'MethodPointer'),
  2876. (mask:po_interrupt; str:'Interrupt'),
  2877. (mask:po_iocheck; str:'IOCheck'),
  2878. (mask:po_assembler; str:'Assembler'),
  2879. (mask:po_msgstr; str:'MsgStr'),
  2880. (mask:po_msgint; str:'MsgInt'),
  2881. (mask:po_exports; str:'Exports'),
  2882. (mask:po_external; str:'External'),
  2883. (mask:po_overload; str:'Overload'),
  2884. (mask:po_varargs; str:'VarArgs'),
  2885. (mask:po_internconst; str:'InternConst'),
  2886. (mask:po_addressonly; str:'AddressOnly'),
  2887. (mask:po_public; str:'Public'),
  2888. (mask:po_hascallingconvention;str:'HasCallingConvention'),
  2889. (mask:po_reintroduce; str:'ReIntroduce'),
  2890. (mask:po_explicitparaloc; str:'ExplicitParaloc'),
  2891. (mask:po_nostackframe; str:'NoStackFrame'),
  2892. (mask:po_has_mangledname; str:'HasMangledName'),
  2893. (mask:po_has_public_name; str:'HasPublicName'),
  2894. (mask:po_forward; str:'Forward'),
  2895. (mask:po_global; str:'Global'),
  2896. (mask:po_syscall; str:'Syscall'),
  2897. (mask:po_syscall_legacy; str:'SyscallLegacy'),
  2898. (mask:po_syscall_basenone;str:'SyscallBaseNone'),
  2899. (mask:po_syscall_basefirst;str:'SyscallBaseFirst'),
  2900. (mask:po_syscall_baselast;str:'SyscallBaseLast'),
  2901. (mask:po_syscall_basereg; str:'SyscallBaseReg'),
  2902. (mask:po_syscall_has_libsym; str:'Has LibSym'),
  2903. (mask:po_syscall_has_importnr; str:'Uses ImportNr'),
  2904. (mask:po_inline; str:'Inline'),
  2905. (mask:po_compilerproc; str:'CompilerProc'),
  2906. (mask:po_has_importdll; str:'HasImportDLL'),
  2907. (mask:po_has_importname; str:'HasImportName'),
  2908. (mask:po_kylixlocal; str:'KylixLocal'),
  2909. (mask:po_dispid; str:'DispId'),
  2910. (mask:po_weakexternal; str:'WeakExternal'),
  2911. (mask:po_objc; str:'ObjC'),
  2912. (mask:po_enumerator_movenext; str:'EnumeratorMoveNext'),
  2913. (mask:po_optional; str: 'Optional'),
  2914. (mask:po_delphi_nested_cc;str: 'Delphi-style nested frameptr'),
  2915. (mask:po_java_nonvirtual; str: 'Java non-virtual method'),
  2916. (mask:po_ignore_for_overload_resolution;str: 'Ignored for overload resolution'),
  2917. (mask:po_rtlproc; str: 'RTL procedure'),
  2918. (mask:po_auto_raised_visibility; str: 'Visibility raised by compiler'),
  2919. (mask:po_far; str: 'Far'),
  2920. (mask:po_hasnearfarcallmodel; str: 'Near/Far explicit'),
  2921. (mask:po_noreturn; str: 'No return'),
  2922. (mask:po_is_function_ref; str: 'Function reference'),
  2923. (mask:po_is_block; str: 'C "Block"'),
  2924. (mask:po_is_auto_getter; str: 'Automatically generated getter'),
  2925. (mask:po_is_auto_setter; str: 'Automatically generated setter'),
  2926. (mask:po_noinline; str: 'Never inline'),
  2927. (mask:po_variadic; str: 'C VarArgs with array-of-const para'),
  2928. (mask:po_objc_related_result_type; str: 'Objective-C related result type'),
  2929. (mask:po_anonymous; str: 'Anonymous'),
  2930. (mask:po_wasm_funcref; str: 'WebAssembly funcref'),
  2931. (mask:po_wasm_suspending; str: 'WebAssembly suspending')
  2932. );
  2933. var
  2934. proctypeoption : tproctypeoption;
  2935. i : longint;
  2936. first : boolean;
  2937. begin
  2938. write([space,' Return type : ']);
  2939. readderef('', ProcDef.ReturnType);
  2940. proctypeoption:=tproctypeoption(ppufile.getbyte);
  2941. case proctypeoption of
  2942. potype_function: Include(ProcDef.Options, poFunction);
  2943. potype_procedure: Include(ProcDef.Options, poProcedure);
  2944. potype_constructor: Include(ProcDef.Options, poConstructor);
  2945. potype_destructor: Include(ProcDef.Options, poDestructor);
  2946. potype_operator: Include(ProcDef.Options, poOperator);
  2947. end;
  2948. write([space,' TypeOption : ']);
  2949. first:=true;
  2950. for i:=1 to high(proctypeopt) do
  2951. if (proctypeopt[i].mask=proctypeoption) then
  2952. begin
  2953. if first then
  2954. first:=false
  2955. else
  2956. write(', ');
  2957. write(proctypeopt[i].str);
  2958. end;
  2959. writeln;
  2960. proccalloption:=tproccalloption(ppufile.getbyte);
  2961. writeln([space,' CallOption : ',proccalloptionStr[proccalloption]]);
  2962. ppufile.getset(tppuset8(procoptions));
  2963. if procoptions<>[] then
  2964. begin
  2965. if po_classmethod in procoptions then Include(ProcDef.Options, poClassMethod);
  2966. if po_virtualmethod in procoptions then Include(ProcDef.Options, poVirtual);
  2967. if po_abstractmethod in procoptions then Include(ProcDef.Options, poAbstract);
  2968. if po_overridingmethod in procoptions then Include(ProcDef.Options, poOverriding);
  2969. if po_overload in procoptions then Include(ProcDef.Options, poOverload);
  2970. if po_inline in procoptions then Include(ProcDef.Options, poInline);
  2971. if (po_methodpointer in procoptions) and (ProcDef.DefType = dtProcType) then
  2972. TPpuProcTypeDef(ProcDef).MethodPtr:=True;
  2973. write([space,' Options : ']);
  2974. first:=true;
  2975. for i:=1 to high(procopt) do
  2976. if (procopt[i].mask in procoptions) then
  2977. begin
  2978. if first then
  2979. first:=false
  2980. else
  2981. write(', ');
  2982. write(procopt[i].str);
  2983. end;
  2984. writeln;
  2985. end;
  2986. if (po_explicitparaloc in procoptions) then
  2987. begin
  2988. readcgpara(space);
  2989. end;
  2990. end;
  2991. { type tvaroption is in unit symconst }
  2992. { register variable }
  2993. { type tvarregable is in unit symconst }
  2994. procedure readabstractvarsym(const s:string;var varoptions:tvaroptions; VarDef: TPpuVarDef = nil);
  2995. type
  2996. tvaropt=record
  2997. mask : tvaroption;
  2998. str : string[30];
  2999. end;
  3000. const
  3001. varopt : array[1..ord(high(tvaroption))] of tvaropt=(
  3002. (mask:vo_is_external; str:'External'),
  3003. (mask:vo_is_dll_var; str:'DLLVar'),
  3004. (mask:vo_is_thread_var; str:'ThreadVar'),
  3005. (mask:vo_has_local_copy; str:'HasLocalCopy'),
  3006. (mask:vo_is_const; str:'Constant'),
  3007. (mask:vo_is_public; str:'Public'),
  3008. (mask:vo_is_high_para; str:'HighValue'),
  3009. (mask:vo_is_funcret; str:'Funcret'),
  3010. (mask:vo_is_self; str:'Self'),
  3011. (mask:vo_is_vmt; str:'VMT'),
  3012. (mask:vo_is_result; str:'Result'),
  3013. (mask:vo_is_parentfp; str:'ParentFP'),
  3014. (mask:vo_is_loop_counter; str:'LoopCounter'),
  3015. (mask:vo_is_hidden_para; str:'Hidden'),
  3016. (mask:vo_has_explicit_paraloc;str:'ExplicitParaloc'),
  3017. (mask:vo_is_syscall_lib; str:'SysCallLib'),
  3018. (mask:vo_has_mangledname; str:'HasMangledName'),
  3019. (mask:vo_is_typed_const; str:'TypedConst'),
  3020. (mask:vo_is_range_check; str:'RangeCheckSwitch'),
  3021. (mask:vo_is_overflow_check; str:'OverflowCheckSwitch'),
  3022. (mask:vo_is_typinfo_para; str:'TypeInfo'),
  3023. (mask:vo_is_msgsel;str:'MsgSel'),
  3024. (mask:vo_is_weak_external;str:'WeakExternal'),
  3025. (mask:vo_is_first_field;str:'IsFirstField'),
  3026. (mask:vo_volatile; str:'Volatile'),
  3027. (mask:vo_has_section; str:'HasSection'),
  3028. (mask:vo_force_finalize; str:'ForceFinalize'),
  3029. (mask:vo_is_default_var; str:'DefaultIntrinsicVar'),
  3030. (mask:vo_is_far; str:'IsFar'),
  3031. (mask:vo_has_global_ref; str:'HasGlobalRef'),
  3032. (mask:vo_is_internal; str:'IsInternal')
  3033. );
  3034. type
  3035. tvaraccessdesc=record
  3036. mask: tvarsymaccessflag;
  3037. str: string[30];
  3038. end;
  3039. const
  3040. varaccessstr : array[ord(low(tvarsymaccessflag))..ord(high(tvarsymaccessflag))] of tvaraccessdesc=(
  3041. (mask: vsa_addr_taken; str:'Address taken'),
  3042. (mask: vsa_different_scope; str:'Accessed from different scope')
  3043. );
  3044. var
  3045. i : longint;
  3046. accessflag: tvarsymaccessflag;
  3047. varsymaccessflags: tvarsymaccessflags;
  3048. first : boolean;
  3049. begin
  3050. readcommonsym(s, VarDef);
  3051. i:=ppufile.getbyte;
  3052. if (VarDef <> nil) and (VarDef.DefType = dtParam) then
  3053. with TPpuParamDef(VarDef) do
  3054. case tvarspez(i) of
  3055. vs_value: Spez:=psValue;
  3056. vs_var: Spez:=psVar;
  3057. vs_out: Spez:=psOut;
  3058. vs_const: Spez:=psConst;
  3059. vs_constref: Spez:=psConstRef;
  3060. end;
  3061. writeln([space,' Spez : ',Varspez2Str(i)]);
  3062. writeln([space,' Regable : ',Varregable2Str(ppufile.getbyte)]);
  3063. ppufile.getset(tppuset1(varsymaccessflags));
  3064. write([space, ' Access Flags : ']);
  3065. first:=true;
  3066. for i:=low(varaccessstr) to high(varaccessstr) do
  3067. begin
  3068. if varaccessstr[i].mask in varsymaccessflags then
  3069. begin
  3070. if first then
  3071. first:=false
  3072. else
  3073. write([', ']);
  3074. write([varaccessstr[i].str]);
  3075. end
  3076. end;
  3077. writeln;
  3078. write ([space,' Var Type : ']);
  3079. if VarDef <> nil then
  3080. readderef('',VarDef.VarType)
  3081. else
  3082. readderef('');
  3083. ppufile.getset(tppuset4(varoptions));
  3084. if varoptions<>[] then
  3085. begin
  3086. if (VarDef <> nil) and (VarDef.DefType = dtParam) and (vo_is_hidden_para in varoptions) then
  3087. TPpuParamDef(VarDef).Spez:=psHidden;
  3088. write([space,' Options : ']);
  3089. first:=true;
  3090. for i:=1 to high(varopt) do
  3091. if (varopt[i].mask in varoptions) then
  3092. begin
  3093. if first then
  3094. first:=false
  3095. else
  3096. write(', ');
  3097. write(varopt[i].str);
  3098. end;
  3099. writeln;
  3100. end;
  3101. end;
  3102. procedure readobjectdefoptions(ObjDef: TPpuObjectDef = nil);
  3103. type
  3104. tsymopt=record
  3105. mask : tobjectoption;
  3106. str : string[30];
  3107. end;
  3108. const
  3109. symopt : array[1..ord(high(tobjectoption))] of tsymopt=(
  3110. (mask:oo_is_forward; str:'IsForward'),
  3111. (mask:oo_is_abstract; str:'IsAbstract'),
  3112. (mask:oo_is_sealed; str:'IsSealed'),
  3113. (mask:oo_has_virtual; str:'HasVirtual'),
  3114. (mask:oo_has_private; str:'HasPrivate'),
  3115. (mask:oo_has_protected; str:'HasProtected'),
  3116. (mask:oo_has_strictprivate; str:'HasStrictPrivate'),
  3117. (mask:oo_has_strictprotected;str:'HasStrictProtected'),
  3118. (mask:oo_has_constructor; str:'HasConstructor'),
  3119. (mask:oo_has_destructor; str:'HasDestructor'),
  3120. (mask:oo_has_vmt; str:'HasVMT'),
  3121. (mask:oo_has_msgstr; str:'HasMsgStr'),
  3122. (mask:oo_has_msgint; str:'HasMsgInt'),
  3123. (mask:oo_can_have_published; str:'CanHavePublished'),
  3124. (mask:oo_has_default_property;str:'HasDefaultProperty'),
  3125. (mask:oo_has_valid_guid; str:'HasValidGUID'),
  3126. (mask:oo_has_enumerator_movenext; str:'HasEnumeratorMoveNext'),
  3127. (mask:oo_has_enumerator_current; str:'HasEnumeratorCurrent'),
  3128. (mask:oo_is_external; str:'External'),
  3129. (mask:oo_is_formal; str:'Formal'),
  3130. (mask:oo_is_classhelper; str:'Class Helper/Category'),
  3131. (mask:oo_has_class_constructor; str:'HasClassConstructor'),
  3132. (mask:oo_has_class_destructor; str:'HasClassDestructor'),
  3133. (mask:oo_is_enum_class; str:'JvmEnumClass'),
  3134. (mask:oo_has_new_destructor; str:'HasNewDestructor'),
  3135. (mask:oo_is_funcref; str:'IsFuncRef'),
  3136. (mask:oo_is_invokable; str:'IsInvokable'),
  3137. (mask:oo_is_capturer; str:'IsCapturer'),
  3138. (mask:oo_inherits_not_specialized; str:'InheritedNotSpecialized')
  3139. );
  3140. var
  3141. i : longint;
  3142. first : boolean;
  3143. begin
  3144. ppufile.getset(tppuset4(current_objectoptions));
  3145. if current_objectoptions<>[] then
  3146. begin
  3147. if ObjDef <> nil then
  3148. begin
  3149. if oo_is_abstract in current_objectoptions then
  3150. Include(ObjDef.Options, ooIsAbstract);
  3151. end;
  3152. first:=true;
  3153. for i:=1 to high(symopt) do
  3154. if (symopt[i].mask in current_objectoptions) then
  3155. begin
  3156. if first then
  3157. first:=false
  3158. else
  3159. write(', ');
  3160. write(symopt[i].str);
  3161. end;
  3162. end;
  3163. writeln;
  3164. end;
  3165. procedure readextendedrtti;
  3166. type
  3167. tvisopt=record
  3168. mask : trtti_visibility;
  3169. str : string[10];
  3170. end;
  3171. const
  3172. visopt : array[0..ord(high(trtti_visibility))] of tvisopt=(
  3173. (mask:rv_private; str:'Private'),
  3174. (mask:rv_protected; str:'Protected'),
  3175. (mask:rv_public; str:'Public'),
  3176. (mask:rv_published; str:'Published')
  3177. );
  3178. type
  3179. toptionopt=record
  3180. mask : trtti_option;
  3181. str : string[10];
  3182. end;
  3183. const
  3184. voptionopt : array[0..ord(high(trtti_option))] of toptionopt=(
  3185. (mask:ro_methods; str:'Methods'),
  3186. (mask:ro_fields; str:'Fields'),
  3187. (mask:ro_properties; str:'Properties')
  3188. );
  3189. var
  3190. clause: string;
  3191. visibilities: trtti_visibilities;
  3192. first: boolean;
  3193. i, ro: integer;
  3194. begin
  3195. clause:='';
  3196. case trtti_clause(ppufile.getbyte) of
  3197. rtc_none: clause:='None';
  3198. rtc_inherit: clause:='Inherit';
  3199. rtc_explicit: clause:='Explicit';
  3200. end;
  3201. writeln([space,' Clause : ',clause]);
  3202. for ro:=0 to high(voptionopt) do
  3203. begin
  3204. ppufile.getset(tppuset1(visibilities));
  3205. if visibilities<>[] then
  3206. begin
  3207. write([space,' ',voptionopt[ro].str,' : ']);
  3208. first:=true;
  3209. for i:=0 to high(visopt) do
  3210. if visopt[i].mask in visibilities then
  3211. begin
  3212. if first then
  3213. first:=false
  3214. else
  3215. write(', ');
  3216. write(visopt[i].str);
  3217. end;
  3218. if not first then
  3219. writeln;
  3220. end;
  3221. end;
  3222. end;
  3223. procedure readprocimploptions(const space: string; out implprocoptions: timplprocoptions);
  3224. type
  3225. tpiopt=record
  3226. mask : timplprocoption;
  3227. str : string[30];
  3228. end;
  3229. const
  3230. piopt : array[low(timplprocoption)..high(timplprocoption)] of tpiopt=(
  3231. (mask:pio_empty; str:'IsEmpty'),
  3232. (mask:pio_has_inlininginfo; str:'HasInliningInfo'),
  3233. (mask:pio_inline_not_possible; str:'InlineNotPossible'),
  3234. (mask:pio_nested_access; str:'NestedAccess'),
  3235. (mask:pio_thunk; str:'Thunk'),
  3236. (mask:pio_fastmath; str:'FastMath'),
  3237. (mask:pio_inline_forbidden; str:'InlineForbidden')
  3238. );
  3239. var
  3240. i: timplprocoption;
  3241. first: boolean;
  3242. begin
  3243. ppufile.getset(tppuset1(implprocoptions));
  3244. if implprocoptions<>[] then
  3245. begin
  3246. first:=true;
  3247. write([space,' Options : ']);
  3248. for i:=low(piopt) to high(piopt) do
  3249. begin
  3250. if i in implprocoptions then
  3251. begin
  3252. if first then
  3253. first:=false
  3254. else
  3255. write(', ');
  3256. write(piopt[i].str);
  3257. end;
  3258. end;
  3259. writeln;
  3260. end;
  3261. end;
  3262. procedure readarraydefoptions(ArrayDef: TPpuArrayDef);
  3263. { type tarraydefoption is in unit symconst }
  3264. const
  3265. symopt : array[tarraydefoption] of string = (
  3266. { ado_IsConvertedPointer } 'ConvertedPointer',
  3267. { ado_IsDynamicArray } 'IsDynamicArray',
  3268. { ado_IsVariant } 'IsVariant',
  3269. { ado_IsConstructor } 'IsConstructor',
  3270. { ado_IsArrayOfConst } 'ArrayOfConst',
  3271. { ado_IsConstString } 'ConstString',
  3272. { ado_IsBitPacked } 'BitPacked',
  3273. { ado_IsVector } 'Vector',
  3274. { ado_IsGeneric } 'Generic',
  3275. { ado_OpenArray } 'OpenArray'
  3276. );
  3277. var
  3278. symoptions: tarraydefoptions;
  3279. i: tarraydefoption;
  3280. first: boolean;
  3281. begin
  3282. ppufile.getset(tppuset2(symoptions));
  3283. if symoptions<>[] then
  3284. begin
  3285. if ado_IsDynamicArray in symoptions then Include(ArrayDef.Options, aoDynamic);
  3286. first:=true;
  3287. for i:=Low(symopt) to high(symopt) do
  3288. if (i in symoptions) then
  3289. begin
  3290. if first then
  3291. first:=false
  3292. else
  3293. write(', ');
  3294. write(symopt[i]);
  3295. end;
  3296. end;
  3297. writeln;
  3298. end;
  3299. (* options for properties
  3300. tpropertyoption=(ppo_none,
  3301. ppo_indexed,
  3302. ppo_defaultproperty,
  3303. ppo_stored,
  3304. ppo_hasparameters,
  3305. ppo_implements,
  3306. ppo_enumerator_current,
  3307. ppo_overrides,
  3308. ppo_dispid_write { no longer used }
  3309. );
  3310. tpropertyoptions=set of tpropertyoption;
  3311. *)
  3312. function readpropertyoptions:tpropertyoptions;
  3313. { type tarraydefoption is in unit symconst }
  3314. type
  3315. tpropopt=record
  3316. mask : tpropertyoption;
  3317. str : string[30];
  3318. end;
  3319. const
  3320. symopt : array[1..ord(high(tpropertyoption))] of tpropopt=(
  3321. (mask:ppo_indexed;str:'indexed'),
  3322. (mask:ppo_defaultproperty;str:'default'),
  3323. (mask:ppo_stored;str:'stored'),
  3324. (mask:ppo_hasparameters;str:'has parameters'),
  3325. (mask:ppo_implements;str:'implements'),
  3326. (mask:ppo_enumerator_current;str:'enumerator current'),
  3327. (mask:ppo_overrides;str:'overrides'),
  3328. (mask:ppo_dispid_write;str:'dispid write') { no longer used }
  3329. );
  3330. var
  3331. i : longint;
  3332. first : boolean;
  3333. begin
  3334. ppufile.getset(tppuset2(result));
  3335. if result<>[] then
  3336. begin
  3337. first:=true;
  3338. for i:=1 to high(symopt) do
  3339. if (symopt[i].mask in result) then
  3340. begin
  3341. if first then
  3342. first:=false
  3343. else
  3344. write(', ');
  3345. write(symopt[i].str);
  3346. end;
  3347. end;
  3348. writeln;
  3349. end;
  3350. function readmanagementoperatoroptions(const space : string;const name : string):tmanagementoperators;
  3351. { type is in unit symconst }
  3352. { Management operator options
  3353. tmanagementoperator=(
  3354. mop_none,
  3355. mop_initialize,
  3356. mop_finalize,
  3357. mop_addref,
  3358. mop_copy);
  3359. }
  3360. type
  3361. tmopopt=record
  3362. mask : tmanagementoperator;
  3363. str : string[10];
  3364. end;
  3365. const
  3366. managementoperatoropt : array[1..ord(high(tmanagementoperator))] of tmopopt=(
  3367. (mask:mop_initialize;str:'initialize'),
  3368. (mask:mop_finalize;str:'finalize'),
  3369. (mask:mop_addref;str:'addref'),
  3370. (mask:mop_copy;str:'copy')
  3371. );
  3372. var
  3373. i : longint;
  3374. first : boolean;
  3375. begin
  3376. ppufile.getset(tppuset1(result));
  3377. if result<>[] then
  3378. begin
  3379. first:=true;
  3380. for i:=1 to high(managementoperatoropt) do
  3381. if (managementoperatoropt[i].mask in result) then
  3382. begin
  3383. if first then
  3384. begin
  3385. write(space);
  3386. write(name);
  3387. write(': ');
  3388. first:=false;
  3389. end
  3390. else
  3391. write(', ');
  3392. write(managementoperatoropt[i].str);
  3393. end;
  3394. if not first then
  3395. writeln;
  3396. end;
  3397. end;
  3398. procedure readnodetree;
  3399. var
  3400. l : longint;
  3401. p : pointer;
  3402. begin
  3403. with ppufile do
  3404. begin
  3405. if space<>'' then
  3406. Writeln([space,'------ nodetree ------']);
  3407. if readentry=ibnodetree then
  3408. begin
  3409. l:=entrysize;
  3410. Writeln([space,'Tree size : ',l]);
  3411. { Read data to prevent error that entry is not completly read }
  3412. getmem(p,l);
  3413. getdata(p^,l);
  3414. freemem(p);
  3415. end
  3416. else
  3417. begin
  3418. WriteError('!! ibnodetree not found');
  3419. end;
  3420. end;
  3421. end;
  3422. procedure ReadCreatedObjTypes;
  3423. var
  3424. i,j,
  3425. len,
  3426. bssize: longint;
  3427. bs: pbyte;
  3428. begin
  3429. if ppufile.readentry<>ibcreatedobjtypes then
  3430. begin
  3431. WriteError('!! ibcreatedobjtypes entry not found');
  3432. ppufile.skipdata(ppufile.entrysize);
  3433. exit
  3434. end;
  3435. writeln;
  3436. writeln([space,'WPO info']);
  3437. writeln([space,'--------']);
  3438. len:=ppufile.getlongint;
  3439. writeln([space,'** Instantiated Object/Class types: ',len,' **']);
  3440. space:=space+' ';
  3441. for i:=0 to len-1 do
  3442. readderef(space);
  3443. setlength(space,length(space)-2);
  3444. len:=ppufile.getlongint;
  3445. writeln([space,'** Instantiated ClassRef types: ',len,' **']);
  3446. space:=space+' ';
  3447. for i:=0 to len-1 do
  3448. readderef(space);
  3449. setlength(space,length(space)-2);
  3450. len:=ppufile.getlongint;
  3451. writeln([space,'** Possibly instantiated ClassRef types : ',len,' **']);
  3452. space:=space+' ';
  3453. for i:=0 to len-1 do
  3454. readderef(space);
  3455. setlength(space,length(space)-2);
  3456. len:=ppufile.getlongint;
  3457. writeln([space,'** Class types with called virtual methods info : ',len,' **']);
  3458. space:=space+' ';
  3459. for i:=0 to len-1 do
  3460. begin
  3461. write([space,'Class def : ']);
  3462. readderef('');
  3463. write([space+' ','Called vmtentries : ']);
  3464. bssize:=ppufile.getlongint;
  3465. getmem(bs,bssize);
  3466. ppufile.readdata(bs^,bssize);
  3467. for j:=0 to bssize*8-1 do
  3468. if (((bs+j shr 3)^ shr (j and 7)) and 1) <> 0 then
  3469. write([j,', ']);
  3470. writeln;
  3471. freemem(bs);
  3472. end;
  3473. setlength(space,length(space)-2);
  3474. end;
  3475. {****************************************************************************
  3476. Read Symbols Part
  3477. ****************************************************************************}
  3478. procedure readsymbols(const s:string; ParentDef: TPpuContainerDef = nil);
  3479. function _finddef(symdef: TPpuDef): TPpuDef;
  3480. begin
  3481. Result:=nil;
  3482. if symdef.Ref.IsCurUnit then
  3483. begin;
  3484. Result:=CurUnit.FindById(symdef.Ref.Id);
  3485. if (Result <> nil) and (Result.Ref.Id = symdef.Id) then
  3486. begin
  3487. Result.Name:=symdef.Name;
  3488. Result.FilePos:=symdef.FilePos;
  3489. end
  3490. else
  3491. Result:=nil;
  3492. end;
  3493. end;
  3494. type
  3495. pguid = ^tguid;
  3496. tguid = packed record
  3497. D1: LongWord;
  3498. D2: Word;
  3499. D3: Word;
  3500. D4: array[0..7] of Byte;
  3501. end;
  3502. var
  3503. b : byte;
  3504. pc : pchar;
  3505. ch : dword;
  3506. startnewline : boolean;
  3507. i,j,len : longint;
  3508. prettyname, ss : ansistring;
  3509. ws: widestring;
  3510. guid : tguid;
  3511. realvalue : ppureal;
  3512. doublevalue : double;
  3513. singlevalue : single;
  3514. realstr : shortstring;
  3515. extended : TSplit80bitReal;
  3516. pw : tcompilerwidestring;
  3517. varoptions : tvaroptions;
  3518. propoptions : tpropertyoptions;
  3519. iexp: Tconstexprint;
  3520. def: TPpuDef;
  3521. constdef: TPpuConstDef absolute def;
  3522. begin
  3523. with ppufile do
  3524. begin
  3525. if space<>'' then
  3526. Writeln([space,'------ ',s,' ------']);
  3527. if readentry=ibstartsyms then
  3528. begin
  3529. Writeln([space,'Symtable count: ',getlongint]);
  3530. end
  3531. else
  3532. Writeln('!! ibstartsym not found');
  3533. repeat
  3534. def:=nil;
  3535. b:=readentry;
  3536. case b of
  3537. ibunitsym :
  3538. readcommonsym('Unit symbol ');
  3539. ibnamespacesym :
  3540. begin
  3541. readcommonsym('NameSpace symbol ');
  3542. write([space,' Hidden Unit : ']);
  3543. readderef('');
  3544. end;
  3545. iblabelsym :
  3546. readcommonsym('Label symbol ');
  3547. ibtypesym :
  3548. begin
  3549. def:=TPpuTypeRef.Create(nil);
  3550. readcommonsym('Type symbol ',def);
  3551. write([space,' Result Type : ']);
  3552. readderef('', def.Ref);
  3553. if _finddef(def) = nil then
  3554. def.Parent:=ParentDef;
  3555. prettyname:=getansistring;
  3556. if prettyname<>'' then
  3557. begin
  3558. write([space,' Pretty Name : ']);
  3559. Writeln(prettyname);
  3560. end;
  3561. end;
  3562. ibprocsym :
  3563. begin
  3564. def:=TPpuDef.Create(nil);
  3565. readcommonsym('Procedure symbol ', def);
  3566. len:=ppufile.getword;
  3567. for i:=1 to len do
  3568. begin
  3569. write([space,' Definition : ']);
  3570. readderef('', def.Ref);
  3571. _finddef(def);
  3572. end;
  3573. if def.GenericDummy then
  3574. begin
  3575. len:=ppufile.getword;
  3576. for i:=1 to len do
  3577. begin
  3578. write([space,' Gen Ovld : ']);
  3579. readderef('',def.Ref);
  3580. _finddef(def);
  3581. end;
  3582. end;
  3583. end;
  3584. ibconstsym :
  3585. begin
  3586. constdef:=TPpuConstDef.Create(ParentDef);
  3587. readcommonsym('Constant symbol ',constdef);
  3588. b:=getbyte;
  3589. case tconsttyp(b) of
  3590. constord :
  3591. begin
  3592. write ([space,' OrdinalType : ']);
  3593. readderef('',constdef.TypeRef);
  3594. iexp:=getexprint;
  3595. constdef.ConstType:=ctInt;
  3596. constdef.VInt:=iexp.svalue;
  3597. writeln([space,' Value : ',constexp.tostr(iexp)]);
  3598. end;
  3599. constpointer :
  3600. begin
  3601. write ([space,' PointerType : ']);
  3602. readderef('',constdef.TypeRef);
  3603. constdef.ConstType:=ctInt;
  3604. constdef.VInt:=int64(getptruint);
  3605. writeln([space,' Value : ',constdef.VInt])
  3606. end;
  3607. conststring,
  3608. constresourcestring :
  3609. begin
  3610. write ([space,' StringType : ']);
  3611. readderef('',constdef.TypeRef);
  3612. len:=getlongint;
  3613. getmem(pc,len+1);
  3614. getdata(pc^,len);
  3615. (pc+len)^:= #0;
  3616. writeln([space,' Length : ',len]);
  3617. writeln([space,' Value : "',pc,'"']);
  3618. constdef.ConstType:=ctStr;
  3619. SetString(constdef.VStr, pc, len);
  3620. constdef.VStr:=UTF8Encode(constdef.VStr);
  3621. freemem(pc,len+1);
  3622. end;
  3623. constreal :
  3624. begin
  3625. constdef.ConstType:=ctFloat;
  3626. write ([space,' RealType : ']);
  3627. readderef('',constdef.TypeRef);
  3628. write([space,' Value : ']);
  3629. if entryleft=sizeof(ppureal) then
  3630. begin
  3631. realvalue:=getrealsize(sizeof(ppureal));
  3632. constdef.VFloat:=realvalue;
  3633. system.str(realvalue,realstr);
  3634. writeln([realstr]);
  3635. end
  3636. else if entryleft=sizeof(double) then
  3637. begin
  3638. doublevalue:=getrealsize(sizeof(double));
  3639. constdef.VFloat:=doublevalue;
  3640. system.str(doublevalue,realstr);
  3641. writeln([realstr]);
  3642. end
  3643. else if entryleft=sizeof(single) then
  3644. begin
  3645. singlevalue:=getrealsize(sizeof(single));
  3646. constdef.VFloat:=singlevalue;
  3647. system.str(singlevalue,realstr);
  3648. writeln([realstr]);
  3649. end
  3650. else if entryleft=10 then
  3651. begin
  3652. getdata(extended,entryleft);
  3653. ss:=Real80bitToStr(extended,constdef.VFloat);
  3654. writeln(ss);
  3655. end
  3656. else
  3657. begin
  3658. realvalue:=0.0;
  3659. WriteError('Error reading real value');
  3660. end;
  3661. end;
  3662. constset :
  3663. begin
  3664. constdef.ConstType:=ctSet;
  3665. write ([space,' Set Type : ']);
  3666. readderef('',constdef.TypeRef);
  3667. for i:=1to 4 do
  3668. begin
  3669. write ([space,' Value : ']);
  3670. for j:=1to 8 do
  3671. begin
  3672. if j>1 then
  3673. write(',');
  3674. b:=getbyte;
  3675. if ppufile.change_endian then
  3676. b:=reverse_byte(b);
  3677. write(hexstr(b,2));
  3678. constdef.VSet[i*j-1]:=b;
  3679. end;
  3680. writeln;
  3681. end;
  3682. end;
  3683. constnil:
  3684. begin
  3685. write([space,' NIL pointer :']);
  3686. readderef('',constdef.TypeRef);
  3687. constdef.ConstType:=ctPtr;
  3688. constdef.VInt:=0;
  3689. end;
  3690. constwstring :
  3691. begin
  3692. initwidestring(pw);
  3693. setlengthwidestring(pw,getlongint);
  3694. if widecharsize=2 then
  3695. { don't use getdata, because the compilerwidechars may have to
  3696. be byteswapped
  3697. }
  3698. begin
  3699. for i:=0 to pw.len-1 do
  3700. pw.data[i]:=ppufile.getword;
  3701. SetString(ws, PWideChar(pw.data), pw.len);
  3702. constdef.VStr:=UTF8Encode(ws);
  3703. constdef.ConstType:=ctStr;
  3704. end
  3705. else if widecharsize=4 then
  3706. begin
  3707. for i:=0 to pw.len-1 do
  3708. pw.data[i]:=cardinal(ppufile.getlongint);
  3709. end
  3710. else
  3711. begin
  3712. WriteError('Unsupported tcompilerwidechar size');
  3713. end;
  3714. Write([space,'Wide string type']);
  3715. startnewline:=true;
  3716. for i:=0 to pw.len-1 do
  3717. begin
  3718. if startnewline then
  3719. begin
  3720. writeln;
  3721. write(space);
  3722. startnewline:=false;
  3723. end;
  3724. ch:=pw.data[i];
  3725. if widecharsize=2 then
  3726. write(hexstr(ch,4))
  3727. else
  3728. write(hexstr(ch,8));
  3729. if ((i + 1) mod 8)= 0 then
  3730. startnewline:=true
  3731. else
  3732. if i <> pw.len-1 then
  3733. write(', ');
  3734. end;
  3735. donewidestring(pw);
  3736. Writeln;
  3737. end;
  3738. constguid:
  3739. begin
  3740. write ([space,' IntfType : ']);
  3741. readderef('',constdef.TypeRef);
  3742. getdata(guid,sizeof(guid));
  3743. write ([space,' IID String: {',hexstr(guid.d1,8),'-',hexstr(guid.d2,4),'-',hexstr(guid.d3,4),'-']);
  3744. for i:=0 to 7 do
  3745. begin
  3746. write(hexstr(guid.d4[i],2));
  3747. if i=1 then write('-');
  3748. end;
  3749. writeln('}');
  3750. end
  3751. else
  3752. Writeln (['!! Invalid unit format : Invalid const type encountered: ',b]);
  3753. end;
  3754. end;
  3755. ibabsolutevarsym :
  3756. begin
  3757. def:=TPpuVarDef.Create(ParentDef);
  3758. readabstractvarsym('Absolute variable symbol ',varoptions,TPpuVarDef(def));
  3759. Write ([space,' Relocated to ']);
  3760. b:=getbyte;
  3761. case absolutetyp(b) of
  3762. tovar :
  3763. readpropaccesslist(space+' Sym : ');
  3764. toasm :
  3765. Writeln(['Assembler name : ',getstring]);
  3766. toaddr :
  3767. begin
  3768. Write(['Address : ',getpuint]);
  3769. if tsystemcpu(ppufile.header.common.cpu)=cpu_i386 then
  3770. Write([' (Far: ',getbyte<>0,')']);
  3771. if tsystemcpu(ppufile.header.common.cpu)=cpu_i8086 then
  3772. if getbyte<>0 then
  3773. Write([' (Far: TRUE, Segment=',getaword,')'])
  3774. else
  3775. Write([' (Far: FALSE)']);
  3776. Writeln;
  3777. end;
  3778. else
  3779. Writeln (['!! Invalid unit format : Invalid absolute type encountered: ',b]);
  3780. end;
  3781. end;
  3782. ibfieldvarsym :
  3783. begin
  3784. def:=TPpuFieldDef.Create(ParentDef);
  3785. readabstractvarsym('Field Variable symbol ',varoptions,TPpuVarDef(def));
  3786. writeln([space,' Address : ',getasizeint]);
  3787. if vo_has_mangledname in varoptions then
  3788. writeln([space,' Mangled name : ',getstring]);
  3789. end;
  3790. ibstaticvarsym :
  3791. begin
  3792. def:=TPpuVarDef.Create(ParentDef);
  3793. readabstractvarsym('Global Variable symbol ',varoptions,TPpuVarDef(def));
  3794. write ([space,' DefaultConst : ']);
  3795. readderef('');
  3796. if (vo_has_mangledname in varoptions) then
  3797. writeln([space,'Mangledname : ',readsymstr(ppufile)]);
  3798. if vo_has_section in varoptions then
  3799. writeln(['Section name:',ppufile.getansistring]);
  3800. write ([space,' FieldVarSymDeref: ']);
  3801. readderef('');
  3802. end;
  3803. iblocalvarsym :
  3804. begin
  3805. readabstractvarsym('Local Variable symbol ',varoptions);
  3806. write ([space,' DefaultConst : ']);
  3807. readderef('');
  3808. end;
  3809. ibparavarsym :
  3810. begin
  3811. def:=TPpuParamDef.Create(ParentDef);
  3812. readabstractvarsym('Parameter Variable symbol ',varoptions,TPpuVarDef(def));
  3813. write ([space,' DefaultConst : ']);
  3814. readderef('',TPpuParamDef(def).DefaultValue);
  3815. writeln([space,' ParaNr : ',getword]);
  3816. writeln([space,' Univ : ',getboolean]);
  3817. writeln([space,' VarState : ',getbyte]);
  3818. writeln([space,' Refs : ',getbyte]);
  3819. if (vo_has_explicit_paraloc in varoptions) then
  3820. begin
  3821. readcgpara(space+' ');
  3822. end;
  3823. end;
  3824. ibenumsym :
  3825. begin
  3826. def:=TPpuConstDef.Create(nil);
  3827. readcommonsym('Enumeration symbol ',def);
  3828. write ([space,' Definition : ']);
  3829. readderef('');
  3830. TPpuConstDef(def).ConstType:=ctInt;
  3831. TPpuConstDef(def).VInt:=getlongint;
  3832. writeln([space,' Value : ',TPpuConstDef(def).VInt]);
  3833. if (ParentDef <> nil) and (ParentDef.DefType = dtEnum) then
  3834. def.Parent:=ParentDef;
  3835. end;
  3836. ibsyssym :
  3837. begin
  3838. readcommonsym('Internal system symbol ');
  3839. writeln([space,' Internal Nr : ',getlongint]);
  3840. end;
  3841. ibmacrosym :
  3842. begin
  3843. readcommonsym('Macro symbol ');
  3844. writeln([space,' Defined: ',getboolean]);
  3845. writeln([space,' Compiler var: ',getboolean]);
  3846. len:=getlongint;
  3847. writeln([space,' Value length: ',len]);
  3848. if len > 0 then
  3849. begin
  3850. getmem(pc,len+1);
  3851. getdata(pc^,len);
  3852. (pc+len)^:= #0;
  3853. writeln([space,' Value: "',pc,'"']);
  3854. freemem(pc,len+1);
  3855. end;
  3856. end;
  3857. ibpropertysym :
  3858. begin
  3859. def:=TPpuPropDef.Create(ParentDef);
  3860. readcommonsym('Property ',def);
  3861. write ([space,' Prop Options : ']);
  3862. propoptions:=readpropertyoptions;
  3863. if ppo_overrides in propoptions then
  3864. begin
  3865. write ([space,' OverrideProp : ']);
  3866. readderef('');
  3867. end;
  3868. if ppo_defaultproperty in propoptions then
  3869. Include(TPpuPropDef(def).Options, poDefault);
  3870. write ([space,' Prop Type : ']);
  3871. readderef('',TPpuPropDef(def).PropType);
  3872. writeln([space,' Index : ',getlongint]);
  3873. writeln([space,' Default : ',getlongint]);
  3874. write ([space,' Index Type : ']);
  3875. readderef('');
  3876. { palt_none }
  3877. write ([space,' Noneaccess : ']);
  3878. readpropaccesslist('');
  3879. write ([space,' Readaccess : ']);
  3880. readpropaccesslist(space+' Sym: ',TPpuPropDef(def).Getter);
  3881. write ([space,' Writeaccess : ']);
  3882. readpropaccesslist(space+' Sym: ',TPpuPropDef(def).Setter);
  3883. write ([space,' Storedaccess : ']);
  3884. readpropaccesslist(space+' Sym: ');
  3885. if [ppo_hasparameters,ppo_overrides]*propoptions=[ppo_hasparameters] then
  3886. begin
  3887. space:=' '+space;
  3888. readsymtable('parast',TPpuPropDef(def));
  3889. delete(space,1,4);
  3890. end;
  3891. end;
  3892. iberror :
  3893. begin
  3894. WriteError('!! Error in PPU');
  3895. exit;
  3896. end;
  3897. ibendsyms :
  3898. break;
  3899. else
  3900. begin
  3901. WriteError('!! Skipping unsupported PPU Entry in Symbols: '+IntToStr(b));
  3902. end;
  3903. end;
  3904. if assigned(def) then
  3905. readsymsubentries(def);
  3906. if (def <> nil) and (def.Parent = nil) then
  3907. def.Free;
  3908. if not EndOfEntry then
  3909. HasMoreInfos;
  3910. until false;
  3911. end;
  3912. end;
  3913. {****************************************************************************
  3914. Read definitions Part
  3915. ****************************************************************************}
  3916. procedure readdefinitions(const s:string; ParentDef: TPpuContainerDef);
  3917. { type tordtype is in symconst unit }
  3918. {
  3919. uvoid,
  3920. u8bit,u16bit,u32bit,u64bit,u128bit,
  3921. s8bit,s16bit,s32bit,s64bit,s128bit,
  3922. bool8bit,bool16bit,bool32bit,bool64bit,
  3923. uchar,uwidechar,scurrency,customint
  3924. ); }
  3925. { type tobjecttyp is in symconst unit }
  3926. { type tvarianttype is in symconst unit }
  3927. { type thelpertype is in symconst unit }
  3928. var
  3929. b : byte;
  3930. otb : byte; { Object Type byte, needed later again }
  3931. l,j,tokenbufsize : longint;
  3932. tokenbuf : pbyte;
  3933. calloption : tproccalloption;
  3934. procoptions : tprocoptions;
  3935. implprocoptions: timplprocoptions;
  3936. defoptions: tdefoptions;
  3937. iexpr: Tconstexprint;
  3938. def: TPpuDef;
  3939. objdef: TPpuObjectDef absolute def;
  3940. arrdef: TPpuArrayDef absolute def;
  3941. enumdef: TPpuEnumDef absolute def;
  3942. setdef: TPpuSetDef absolute def;
  3943. orddef: TPpuOrdDef absolute def;
  3944. floatdef: TPpuFloatDef absolute def;
  3945. strdef: TPpuStringDef absolute def;
  3946. filedef: TPpuFileDef absolute def;
  3947. begin
  3948. with ppufile do
  3949. begin
  3950. if space<>'' then
  3951. Writeln([space,'------ ',s,' ------']);
  3952. if readentry<>ibstartdefs then
  3953. Writeln('!! ibstartdefs not found');
  3954. repeat
  3955. def:=nil;
  3956. b:=readentry;
  3957. case b of
  3958. ibpointerdef :
  3959. begin
  3960. def:=TPpuPointerDef.Create(ParentDef);
  3961. readcommondef('Pointer definition',defoptions,def);
  3962. write ([space,' Pointed Type : ']);
  3963. readderef('',TPpuPointerDef(def).Ptr);
  3964. writeln([space,' Has Pointer Math : ',(getbyte<>0)]);
  3965. if tsystemcpu(ppufile.header.common.cpu) in [cpu_i8086,cpu_i386,cpu_x86_64] then
  3966. begin
  3967. write([space,' X86 Pointer Type : ']);
  3968. b:=getbyte;
  3969. case tx86pointertyp(b) of
  3970. x86pt_near: writeln('Near');
  3971. x86pt_near_cs: writeln('Near ''CS''');
  3972. x86pt_near_ds: writeln('Near ''DS''');
  3973. x86pt_near_ss: writeln('Near ''SS''');
  3974. x86pt_near_es: writeln('Near ''ES''');
  3975. x86pt_near_fs: writeln('Near ''FS''');
  3976. x86pt_near_gs: writeln('Near ''GS''');
  3977. x86pt_far: writeln('Far');
  3978. x86pt_huge: writeln('Huge');
  3979. else
  3980. WriteWarning('Invalid x86 pointer type: ' + IntToStr(b));
  3981. end;
  3982. end;
  3983. if tsystemcpu(ppufile.header.common.cpu)=cpu_wasm32 then
  3984. writeln([space,' WASM externref : ',(getbyte<>0)]);
  3985. end;
  3986. iborddef :
  3987. begin
  3988. orddef:=TPpuOrdDef.Create(ParentDef);
  3989. readcommondef('Ordinal definition',defoptions,orddef);
  3990. write ([space,' Base type : ']);
  3991. b:=getbyte;
  3992. case tordtype(b) of
  3993. uvoid:
  3994. begin
  3995. writeln('uvoid');
  3996. orddef.OrdType:=otVoid;
  3997. end;
  3998. u8bit:
  3999. begin
  4000. writeln('u8bit');
  4001. orddef.OrdType:=otUInt;
  4002. orddef.Size:=1;
  4003. end;
  4004. u16bit:
  4005. begin
  4006. writeln('u16bit');
  4007. orddef.OrdType:=otUInt;
  4008. orddef.Size:=2;
  4009. end;
  4010. u32bit:
  4011. begin
  4012. writeln('u32bit');
  4013. orddef.OrdType:=otUInt;
  4014. orddef.Size:=4;
  4015. end;
  4016. u64bit:
  4017. begin
  4018. writeln('u64bit');
  4019. orddef.OrdType:=otUInt;
  4020. orddef.Size:=8;
  4021. end;
  4022. u128bit:
  4023. begin
  4024. writeln('u128bit');
  4025. orddef.OrdType:=otUInt;
  4026. orddef.Size:=16;
  4027. end;
  4028. s8bit:
  4029. begin
  4030. writeln('s8bit');
  4031. orddef.OrdType:=otSInt;
  4032. orddef.Size:=1;
  4033. end;
  4034. s16bit:
  4035. begin
  4036. writeln('s16bit');
  4037. orddef.OrdType:=otSInt;
  4038. orddef.Size:=2;
  4039. end;
  4040. s32bit:
  4041. begin
  4042. writeln('s32bit');
  4043. orddef.OrdType:=otSInt;
  4044. orddef.Size:=4;
  4045. end;
  4046. s64bit:
  4047. begin
  4048. writeln('s64bit');
  4049. orddef.OrdType:=otSInt;
  4050. orddef.Size:=8;
  4051. end;
  4052. s128bit:
  4053. begin
  4054. writeln('s128bit');
  4055. orddef.OrdType:=otSInt;
  4056. orddef.Size:=16;
  4057. end;
  4058. pasbool1:
  4059. begin
  4060. writeln('pasbool1');
  4061. orddef.OrdType:=otPasBool;
  4062. orddef.Size:=1;
  4063. end;
  4064. pasbool8:
  4065. begin
  4066. writeln('pasbool8');
  4067. orddef.OrdType:=otPasBool;
  4068. orddef.Size:=1;
  4069. end;
  4070. pasbool16:
  4071. begin
  4072. writeln('pasbool16');
  4073. orddef.OrdType:=otPasBool;
  4074. orddef.Size:=2;
  4075. end;
  4076. pasbool32:
  4077. begin
  4078. writeln('pasbool32');
  4079. orddef.OrdType:=otPasBool;
  4080. orddef.Size:=4;
  4081. end;
  4082. pasbool64:
  4083. begin
  4084. writeln('pasbool64');
  4085. orddef.OrdType:=otPasBool;
  4086. orddef.Size:=8;
  4087. end;
  4088. bool8bit:
  4089. begin
  4090. writeln('bool8bit');
  4091. orddef.OrdType:=otBool;
  4092. orddef.Size:=1;
  4093. end;
  4094. bool16bit:
  4095. begin
  4096. writeln('bool16bit');
  4097. orddef.OrdType:=otBool;
  4098. orddef.Size:=2;
  4099. end;
  4100. bool32bit:
  4101. begin
  4102. writeln('bool32bit');
  4103. orddef.OrdType:=otBool;
  4104. orddef.Size:=4;
  4105. end;
  4106. bool64bit:
  4107. begin
  4108. writeln('bool64bit');
  4109. orddef.OrdType:=otBool;
  4110. orddef.Size:=8;
  4111. end;
  4112. uchar:
  4113. begin
  4114. writeln('uchar');
  4115. orddef.OrdType:=otChar;
  4116. orddef.Size:=1;
  4117. end;
  4118. uwidechar:
  4119. begin
  4120. writeln('uwidechar');
  4121. orddef.OrdType:=otChar;
  4122. orddef.Size:=2;
  4123. end;
  4124. scurrency:
  4125. begin
  4126. writeln('scurrency');
  4127. orddef.OrdType:=otCurrency;
  4128. orddef.Size:=8;
  4129. end;
  4130. customint:
  4131. begin
  4132. writeln('customint');
  4133. orddef.OrdType:=otSint;
  4134. orddef.Size:=sizeof(ASizeInt);
  4135. end
  4136. else
  4137. WriteWarning('Invalid base type: ' + IntToStr(b));
  4138. end;
  4139. iexpr:=getexprint;
  4140. orddef.RangeLow:=iexpr.svalue;
  4141. write([space,' Range : ',constexp.tostr(iexpr)]);
  4142. iexpr:=getexprint;
  4143. orddef.RangeHigh:=iexpr.svalue;
  4144. writeln([' to ',constexp.tostr(iexpr)]);
  4145. end;
  4146. ibfloatdef :
  4147. begin
  4148. floatdef:=TPpuFloatDef.Create(ParentDef);
  4149. readcommondef('Float definition',defoptions,floatdef);
  4150. write ([space,' Float type : ']);
  4151. b:=getbyte;
  4152. case b of
  4153. ftSingle:
  4154. begin
  4155. writeln('Single');
  4156. floatdef.FloatType:=pftSingle;
  4157. end;
  4158. ftDouble:
  4159. begin
  4160. writeln('Double');
  4161. floatdef.FloatType:=pftDouble;
  4162. end;
  4163. ftExtended:
  4164. begin
  4165. writeln('Extended');
  4166. floatdef.FloatType:=pftExtended;
  4167. end;
  4168. ftComp:
  4169. begin
  4170. writeln('Comp');
  4171. floatdef.FloatType:=pftComp;
  4172. end;
  4173. ftCurr:
  4174. begin
  4175. writeln('Currency');
  4176. floatdef.FloatType:=pftCurrency;
  4177. end;
  4178. ftFloat128:
  4179. begin
  4180. writeln('Float128');
  4181. floatdef.FloatType:=pftFloat128;
  4182. end;
  4183. else
  4184. WriteWarning('Invalid float type: ' + IntToStr(b));
  4185. end;
  4186. end;
  4187. ibarraydef :
  4188. begin
  4189. arrdef:=TPpuArrayDef.Create(ParentDef);
  4190. readcommondef('Array definition',defoptions,arrdef);
  4191. write ([space,' Element type : ']);
  4192. readderef('',arrdef.ElType);
  4193. write ([space,' Range Type : ']);
  4194. readderef('',arrdef.RangeType);
  4195. arrdef.RangeLow:=getasizeint;
  4196. arrdef.RangeHigh:=getasizeint;
  4197. writeln([space,' Range : ',arrdef.RangeLow,' to ',arrdef.RangeHigh]);
  4198. write ([space,' Options : ']);
  4199. readarraydefoptions(arrdef);
  4200. if tsystemcpu(ppufile.header.common.cpu)=cpu_i8086 then
  4201. writeln([space,' Huge : ',(getbyte<>0)]);
  4202. readsymtable('symbols', arrdef);
  4203. end;
  4204. ibprocdef :
  4205. begin
  4206. def:=TPpuProcDef.Create(ParentDef);
  4207. readcommondef('Procedure definition',defoptions,def);
  4208. read_abstract_proc_def(calloption,procoptions,TPpuProcDef(def));
  4209. if (po_has_mangledname in procoptions) then
  4210. writeln([space,' Mangled name : ',readsymstr(ppufile)]);
  4211. writeln([space,' Number : ',getword]);
  4212. writeln([space,' Level : ',getbyte]);
  4213. write ([space,' Class : ']);
  4214. readderef('');
  4215. write ([space,' Procsym : ']);
  4216. readderef('', def.Ref);
  4217. write ([space,' File Pos : ']);
  4218. readposinfo(def);
  4219. write ([space,' Visibility : ']);
  4220. readvisibility(def);
  4221. write ([space,' SymOptions : ']);
  4222. readsymoptions(space+' ');
  4223. if (po_has_importdll in procoptions) then
  4224. writeln([space,' Import DLL : ',getstring]);
  4225. if (po_has_importname in procoptions) then
  4226. writeln([space,' Import Name : ',getstring]);
  4227. writeln([space,' Import Nr : ',getword]);
  4228. if (po_msgint in procoptions) then
  4229. writeln([space,' MsgInt : ',getlongint]);
  4230. if (po_msgstr in procoptions) then
  4231. writeln([space,' MsgStr : ',getstring]);
  4232. if (po_dispid in procoptions) then
  4233. writeln([space,' DispID: ',ppufile.getlongint]);
  4234. readprocimploptions(space,implprocoptions);
  4235. if (pio_has_inlininginfo in implprocoptions) then
  4236. begin
  4237. write ([space,' FuncretSym : ']);
  4238. readderef('');
  4239. readprocinfooptions(space);
  4240. end;
  4241. b:=ppufile.getbyte;
  4242. if b<>0 then
  4243. begin
  4244. write ([space,' Alias names : ']);
  4245. for j:=1 to b do
  4246. begin
  4247. write(ppufile.getstring);
  4248. if j<b then
  4249. write(', ');
  4250. end;
  4251. writeln;
  4252. end;
  4253. tokenbufsize:=ppufile.getlongint;
  4254. if tokenbufsize<>0 then
  4255. begin
  4256. space:=space + ' ';
  4257. write ([space,'Declaration token buffer : size = ',tokenbufsize]);
  4258. tokenbuf:=allocmem(tokenbufsize);
  4259. ppufile.getdata(tokenbuf^,tokenbufsize);
  4260. displaytokenbuffer(tokenbuf,tokenbufsize);
  4261. freemem(tokenbuf);
  4262. delete(space,1,4);
  4263. end;
  4264. if po_syscall_has_libsym in procoptions then
  4265. begin
  4266. { library symbol for AmigaOS/MorphOS/AROS }
  4267. write ([space,' Library symbol : ']);
  4268. readderef('');
  4269. end;
  4270. if not EndOfEntry then
  4271. HasMoreInfos;
  4272. space:=' '+space;
  4273. { parast }
  4274. readsymtable('parast', TPpuProcDef(def));
  4275. { localst }
  4276. if (pio_has_inlininginfo in implprocoptions) then
  4277. readsymtable('inline localst')
  4278. else if (df_generic in defoptions) then
  4279. readsymtable('generic localst');
  4280. if (pio_has_inlininginfo in implprocoptions) then
  4281. readnodetree;
  4282. delete(space,1,4);
  4283. end;
  4284. ibprocvardef :
  4285. begin
  4286. def:=TPpuProcTypeDef.Create(ParentDef);
  4287. readcommondef('Procedural type (ProcVar) definition',defoptions,def);
  4288. read_abstract_proc_def(calloption,procoptions, TPpuProcDef(def));
  4289. writeln([space,' Symtable level :',ppufile.getbyte]);
  4290. if tsystemcpu(ppufile.header.common.cpu)=cpu_jvm then
  4291. readderef('');
  4292. if not EndOfEntry then
  4293. HasMoreInfos;
  4294. space:=' '+space;
  4295. { parast }
  4296. readsymtable('parast',TPpuProcDef(def));
  4297. delete(space,1,4);
  4298. end;
  4299. ibshortstringdef :
  4300. begin
  4301. strdef:=TPpuStringDef.Create(ParentDef);
  4302. strdef.StrType:=stShort;
  4303. readcommondef('ShortString definition',defoptions,strdef);
  4304. strdef.Len:=getbyte;
  4305. writeln([space,' Length : ',strdef.Len]);
  4306. end;
  4307. ibwidestringdef :
  4308. begin
  4309. strdef:=TPpuStringDef.Create(ParentDef);
  4310. strdef.StrType:=stWide;
  4311. readcommondef('WideString definition',defoptions,strdef);
  4312. strdef.Len:=getasizeint;
  4313. writeln([space,' Length : ',strdef.Len]);
  4314. end;
  4315. ibunicodestringdef :
  4316. begin
  4317. strdef:=TPpuStringDef.Create(ParentDef);
  4318. strdef.StrType:=stUnicode;
  4319. readcommondef('UnicodeString definition',defoptions,strdef);
  4320. strdef.Len:=getasizeint;
  4321. writeln([space,' Length : ',strdef.Len]);
  4322. writeln([space,' Encoding : ',getword]);
  4323. end;
  4324. ibansistringdef :
  4325. begin
  4326. strdef:=TPpuStringDef.Create(ParentDef);
  4327. strdef.StrType:=stAnsi;
  4328. readcommondef('AnsiString definition',defoptions,strdef);
  4329. strdef.Len:=getasizeint;
  4330. writeln([space,' Length : ',strdef.Len]);
  4331. writeln([space,' Encoding : ',getword]);
  4332. end;
  4333. iblongstringdef :
  4334. begin
  4335. strdef:=TPpuStringDef.Create(ParentDef);
  4336. strdef.StrType:=stLong;
  4337. readcommondef('Longstring definition',defoptions,strdef);
  4338. strdef.Len:=getasizeint;
  4339. writeln([space,' Length : ',strdef.Len]);
  4340. end;
  4341. ibrecorddef :
  4342. begin
  4343. objdef:=TPpuRecordDef.Create(ParentDef);
  4344. readcommondef('Record definition',defoptions, objdef);
  4345. def.Name:=getstring;
  4346. writeln([space,' Name of Record : ',objdef.Name]);
  4347. writeln([space,' Import lib/pkg : ',getstring]);
  4348. write ([space,' Options : ']);
  4349. readobjectdefoptions(objdef);
  4350. writeln([space,' Extended RTTI : ']);
  4351. readextendedrtti;
  4352. if (df_copied_def in defoptions) then
  4353. begin
  4354. Include(TPpuRecordDef(def).Options, ooCopied);
  4355. write([space,' Copied from : ']);
  4356. readderef('',objdef.Ancestor);
  4357. end
  4358. else
  4359. begin
  4360. writeln([space,' FieldAlign : ',shortint(getbyte)]);
  4361. writeln([space,' RecordAlign : ',shortint(getbyte)]);
  4362. writeln([space,' PadAlign : ',shortint(getbyte)]);
  4363. writeln([space,'UseFieldAlignment : ',shortint(getbyte)]);
  4364. writeln([space,' RecordAlignMin : ',shortint(getbyte)]);
  4365. objdef.Size:=getasizeint;
  4366. writeln([space,' DataSize : ',objdef.Size]);
  4367. writeln([space,' PaddingSize : ',getword]);
  4368. readmanagementoperatoroptions(space,'Management operators');
  4369. end;
  4370. {read the record definitions and symbols}
  4371. if not(df_copied_def in current_defoptions) then
  4372. begin
  4373. space:=' '+space;
  4374. readrecordsymtable('fields',TPpuRecordDef(def));
  4375. Delete(space,1,4);
  4376. end;
  4377. if not EndOfEntry then
  4378. HasMoreInfos;
  4379. end;
  4380. ibobjectdef :
  4381. begin
  4382. objdef:=TPpuObjectDef.Create(ParentDef);
  4383. readcommondef('Object/Class definition',defoptions,objdef);
  4384. objdef.Name:=getstring;
  4385. writeln([space,' Name of Class : ',objdef.Name]);
  4386. writeln([space,' Import lib/pkg : ',getstring]);
  4387. write ([space,' Options : ']);
  4388. readobjectdefoptions(objdef);
  4389. writeln([space,' Extended RTTI : ']);
  4390. readextendedrtti;
  4391. otb:=getbyte;
  4392. write ([space,' Type : ']);
  4393. case tobjecttyp(otb) of
  4394. odt_class : writeln('class');
  4395. odt_object : writeln('object');
  4396. odt_interfacecom : writeln('interfacecom');
  4397. odt_interfacecorba : writeln('interfacecorba');
  4398. odt_cppclass : writeln('cppclass');
  4399. odt_dispinterface : writeln('dispinterface');
  4400. odt_objcclass : writeln('objcclass');
  4401. odt_objcprotocol : writeln('objcprotocol');
  4402. odt_helper : writeln('helper');
  4403. odt_objccategory : writeln('objccategory');
  4404. odt_javaclass : writeln('Java class');
  4405. odt_interfacejava : writeln('Java interface');
  4406. else WriteWarning('Invalid object type: ' + IntToStr(b));
  4407. end;
  4408. case tobjecttyp(otb) of
  4409. odt_class, odt_cppclass, odt_objcclass, odt_javaclass:
  4410. objdef.ObjType:=otClass;
  4411. odt_object:
  4412. objdef.ObjType:=otObject;
  4413. odt_interfacecom, odt_interfacecorba, odt_interfacejava, odt_dispinterface:
  4414. objdef.ObjType:=otInterface;
  4415. odt_helper:
  4416. objdef.ObjType:=otHelper;
  4417. end;
  4418. b:=getbyte;
  4419. write ([space,' Helper Type : ']);
  4420. case thelpertype(b) of
  4421. ht_none : writeln('none');
  4422. ht_class : writeln('class helper');
  4423. ht_record : writeln('record helper');
  4424. ht_type : writeln('type helper');
  4425. else WriteWarning('Invalid helper type: ' + IntToStr(b));
  4426. end;
  4427. writeln([space,' External name : ',getstring]);
  4428. objdef.Size:=getasizeint;
  4429. writeln([space,' DataSize : ',objdef.Size]);
  4430. writeln([space,' PaddingSize : ',getword]);
  4431. writeln([space,' FieldAlign : ',shortint(getbyte)]);
  4432. writeln([space,' RecordAlign : ',shortint(getbyte)]);
  4433. writeln([space,' RecordAlignMin : ',shortint(getbyte)]);
  4434. write ([space, ' VmtField : ']);
  4435. readderef('',nil);
  4436. write ([space, ' Ancestor Class : ']);
  4437. readderef('',objdef.Ancestor);
  4438. if tobjecttyp(otb) in [odt_interfacecom,odt_interfacecorba,odt_dispinterface] then
  4439. begin
  4440. { IIDGUID }
  4441. for j:=1to 16 do
  4442. getbyte;
  4443. objdef.IID:=getstring;
  4444. writeln([space,' IID String : ',objdef.IID]);
  4445. end;
  4446. l:=getlongint;
  4447. if l > 0 then
  4448. objdef.Options:=objdef.Options + [ooAbstractMethods];
  4449. writeln([space,' Abstract methods : ',l]);
  4450. if tobjecttyp(otb)=odt_helper then
  4451. begin
  4452. write([space,' Helper parent : ']);
  4453. readderef('',objdef.HelperParent);
  4454. end;
  4455. l:=getlongint;
  4456. writeln([space,' VMT entries: ',l]);
  4457. for j:=1 to l do
  4458. begin
  4459. write([space,' ']);
  4460. readderef('');
  4461. write([space,' Visibility: ']);
  4462. readvisibility;
  4463. end;
  4464. if tobjecttyp(otb) in [odt_class,odt_objcclass,odt_objcprotocol,odt_javaclass,odt_interfacejava] then
  4465. begin
  4466. l:=getlongint;
  4467. writeln([space,' Impl Intf Count : ',l]);
  4468. for j:=1 to l do
  4469. begin
  4470. write ([space,' - Definition : ']);
  4471. readderef('');
  4472. write ([space,' - Getter Def : ']);
  4473. readderef('');
  4474. writeln([space,' IOffset : ',getlongint]);
  4475. writeln([space,' Entry type : ',IntfEntryType2Str(getbyte)]);
  4476. end;
  4477. end;
  4478. if df_copied_def in current_defoptions then
  4479. begin
  4480. Include(objdef.Options, ooCopied);
  4481. writeln(' Copy of def: ');
  4482. readderef('',objdef.Ancestor);
  4483. end
  4484. else
  4485. begin
  4486. {read the record definitions and symbols}
  4487. space:=' '+space;
  4488. readrecordsymtable('fields',objdef);
  4489. Delete(space,1,4);
  4490. end;
  4491. if not EndOfEntry then
  4492. HasMoreInfos;
  4493. end;
  4494. ibfiledef :
  4495. begin
  4496. filedef:=TPpuFileDef.Create(ParentDef);
  4497. ReadCommonDef('File definition',defoptions,filedef);
  4498. write ([space,' Type : ']);
  4499. case getbyte of
  4500. 0 : begin
  4501. writeln('Text');
  4502. filedef.FileType:=ftText;
  4503. end;
  4504. 1 : begin
  4505. writeln('Typed');
  4506. filedef.FileType:=ftTyped;
  4507. write ([space,' File of Type : ']);
  4508. readderef('',filedef.TypeRef);
  4509. end;
  4510. 2 : begin
  4511. writeln('Untyped');
  4512. filedef.FileType:=ftUntyped;
  4513. end;
  4514. end;
  4515. end;
  4516. ibformaldef :
  4517. begin
  4518. def:=TPpuFormalDef.Create(ParentDef);
  4519. readcommondef('Generic definition (void-typ)',defoptions,def);
  4520. TPpuFormalDef(def).IsTyped:=(getbyte<>0);
  4521. writeln([space,' Is Typed : ',TPpuFormalDef(def).IsTyped]);
  4522. end;
  4523. ibundefineddef :
  4524. begin
  4525. def:=TPpuUndefinedDef.Create(ParentDef);
  4526. readcommondef('Undefined definition (generic parameter)',defoptions,def);
  4527. end;
  4528. ibenumdef :
  4529. begin
  4530. enumdef:=TPpuEnumDef.Create(ParentDef);
  4531. readcommondef('Enumeration type definition',defoptions,enumdef);
  4532. enumdef.ElLow:=getaint;
  4533. writeln([space,' Smallest element : ',enumdef.ElLow]);
  4534. enumdef.ElHigh:=getaint;
  4535. writeln([space,' Largest element : ',enumdef.ElHigh]);
  4536. enumdef.Size:=byte(getaint);
  4537. writeln([space,' Size : ',enumdef.Size]);
  4538. if df_copied_def in defoptions then
  4539. begin
  4540. write([space,'Base enumeration type : ']);
  4541. readderef('',enumdef.CopyFrom);
  4542. end
  4543. else
  4544. begin
  4545. space:=' '+space;
  4546. readsymtable('elements',enumdef);
  4547. delete(space,1,4);
  4548. end;
  4549. if tsystemcpu(ppufile.header.common.cpu)=cpu_jvm then
  4550. begin
  4551. write([space,' Class def : ']);
  4552. readderef('');
  4553. end;
  4554. end;
  4555. ibclassrefdef :
  4556. begin
  4557. def:=TPpuClassRefDef.Create(ParentDef);
  4558. readcommondef('Class reference definition',defoptions,def);
  4559. write ([space,' Pointed Type : ']);
  4560. readderef('',TPpuClassRefDef(def).ClassRef);
  4561. end;
  4562. ibsetdef :
  4563. begin
  4564. setdef:=TPpuSetDef.Create(ParentDef);
  4565. readcommondef('Set definition',defoptions,setdef);
  4566. write ([space,' Element type : ']);
  4567. readderef('',setdef.ElType);
  4568. setdef.Size:=getasizeint;
  4569. writeln([space,' Size : ',setdef.Size]);
  4570. setdef.SetBase:=getasizeint;
  4571. writeln([space,' Set Base : ',setdef.SetBase]);
  4572. setdef.SetLow:=getasizeint;
  4573. writeln([space,' Set Low : ',setdef.SetLow]);
  4574. setdef.SetMax:=getasizeint;
  4575. writeln([space,' Set Max : ',setdef.SetMax]);
  4576. end;
  4577. ibvariantdef :
  4578. begin
  4579. def:=TPpuVariantDef.Create(ParentDef);
  4580. readcommondef('Variant definition',defoptions,def);
  4581. write ([space,' Varianttype : ']);
  4582. b:=getbyte;
  4583. case tvarianttype(b) of
  4584. vt_normalvariant :
  4585. writeln('Normal');
  4586. vt_olevariant :
  4587. begin
  4588. TPpuVariantDef(def).IsOLE:=True;
  4589. writeln('OLE');
  4590. end
  4591. else
  4592. WriteWarning('Invalid varianttype: ' + IntToStr(b));
  4593. end;
  4594. end;
  4595. iberror :
  4596. begin
  4597. WriteError('!! Error in PPU');
  4598. exit;
  4599. end;
  4600. ibenddefs :
  4601. break;
  4602. else
  4603. begin
  4604. WriteError('!! Skipping unsupported PPU Entry in definitions: '+IntToStr(b));
  4605. end;
  4606. end;
  4607. if assigned(def) then
  4608. readdefsubentries(def);
  4609. if (def <> nil) and (def.Parent = nil) then
  4610. def.Free;
  4611. if not EndOfEntry then
  4612. HasMoreInfos;
  4613. until false;
  4614. end;
  4615. end;
  4616. procedure readmoduleoptions(space : string);
  4617. type
  4618. { tmoduleoption type is in unit fmodule }
  4619. tmoduleoption = (mo_none,
  4620. mo_hint_deprecated,
  4621. mo_hint_platform,
  4622. mo_hint_library,
  4623. mo_hint_unimplemented,
  4624. mo_hint_experimental,
  4625. mo_has_deprecated_msg
  4626. );
  4627. tmoduleoptions = set of tmoduleoption;
  4628. tmoduleopt=record
  4629. mask : tmoduleoption;
  4630. str : string[30];
  4631. end;
  4632. const
  4633. moduleopts=ord(high(tmoduleoption));
  4634. moduleopt : array[1..moduleopts] of tmoduleopt=(
  4635. (mask:mo_hint_deprecated; str:'Hint Deprecated'),
  4636. (mask:mo_hint_platform; str:'Hint Platform'),
  4637. (mask:mo_hint_library; str:'Hint Library'),
  4638. (mask:mo_hint_unimplemented; str:'Hint Unimplemented'),
  4639. (mask:mo_hint_experimental; str:'Hint Experimental'),
  4640. (mask:mo_has_deprecated_msg; str:'Has Deprecated Message')
  4641. );
  4642. var
  4643. moduleoptions : tmoduleoptions;
  4644. i : longint;
  4645. first : boolean;
  4646. begin
  4647. ppufile.getset(tppuset1(moduleoptions));
  4648. if moduleoptions<>[] then
  4649. begin
  4650. first:=true;
  4651. for i:=1to moduleopts do
  4652. if (moduleopt[i].mask in moduleoptions) then
  4653. begin
  4654. if first then
  4655. first:=false
  4656. else
  4657. write(', ');
  4658. write(moduleopt[i].str);
  4659. end;
  4660. end;
  4661. writeln;
  4662. if mo_has_deprecated_msg in moduleoptions then
  4663. writeln([space,'Deprecated : ', ppufile.getstring]);
  4664. end;
  4665. {****************************************************************************
  4666. Read General Part
  4667. ****************************************************************************}
  4668. procedure readinterface(silent : boolean);
  4669. var
  4670. b : byte;
  4671. sourcenumber, i : longint;
  4672. feature : tfeature;
  4673. features : tfeatures;
  4674. s : string;
  4675. begin
  4676. with ppufile do
  4677. begin
  4678. repeat
  4679. b:=readentry;
  4680. case b of
  4681. ibmodulename :
  4682. begin
  4683. CurUnit.Name:=getstring;
  4684. if not silent then
  4685. Writeln(['Module Name: ',CurUnit.Name]);
  4686. end;
  4687. ibfeatures :
  4688. begin
  4689. getset(tppuset4(features));
  4690. Writeln('Features: ');
  4691. for feature:=low(tfeatures) to high(tfeature) do
  4692. if feature in features then
  4693. begin
  4694. str(feature,s);
  4695. s:=copy(s,3,255);
  4696. writeln([s]);
  4697. end;
  4698. end;
  4699. ibmoduleoptions:
  4700. if not silent then
  4701. readmoduleoptions(' ');
  4702. ibsourcefiles :
  4703. begin
  4704. sourcenumber:=1;
  4705. if not silent then
  4706. while not EndOfEntry do
  4707. begin
  4708. with TPpuSrcFile.Create(CurUnit.SourceFiles) do begin
  4709. Name:=getstring;
  4710. i:=getlongint;
  4711. try
  4712. if i >= 0 then
  4713. FileTime:=FileDateToDateTime(i);
  4714. Writeln(['Source file ',sourcenumber,' : ',Name,' ',filetimestring(i)]);
  4715. except
  4716. end;
  4717. end;
  4718. inc(sourcenumber);
  4719. end;
  4720. end;
  4721. {$IFDEF MACRO_DIFF_HINT}
  4722. ibusedmacros :
  4723. begin
  4724. if not silent then
  4725. while not EndOfEntry do
  4726. begin
  4727. Write('Conditional ',getstring);
  4728. if getboolean then
  4729. write(' defined at startup')
  4730. else
  4731. write(' not defined at startup');
  4732. if getboolean then
  4733. writeln(' was used')
  4734. else
  4735. writeln;
  4736. end;
  4737. end;
  4738. {$ENDIF}
  4739. ibloadunit :
  4740. if not silent then
  4741. ReadLoadUnit;
  4742. iblinkunitofiles :
  4743. if not silent then
  4744. ReadLinkContainer('Link unit object file: ');
  4745. iblinkunitstaticlibs :
  4746. if not silent then
  4747. ReadLinkContainer('Link unit static lib: ');
  4748. iblinkunitsharedlibs :
  4749. if not silent then
  4750. ReadLinkContainer('Link unit shared lib: ');
  4751. iblinkotherofiles :
  4752. if not silent then
  4753. ReadLinkContainer('Link other object file: ');
  4754. iblinkotherstaticlibs :
  4755. if not silent then
  4756. ReadLinkContainer('Link other static lib: ');
  4757. iblinkothersharedlibs :
  4758. if not silent then
  4759. ReadLinkContainer('Link other shared lib: ');
  4760. iblinkotherframeworks:
  4761. if not silent then
  4762. ReadLinkContainer('Link framework: ');
  4763. ibjvmnamespace:
  4764. Writeln('JVM name space: '+getString);
  4765. ibmainname:
  4766. if not silent then
  4767. Writeln(['Specified main program symbol name: ',getstring]);
  4768. ibImportSymbols :
  4769. if not silent then
  4770. ReadImportSymbols;
  4771. ibderefdata :
  4772. ReadDerefData;
  4773. ibderefmap :
  4774. ReadDerefMap;
  4775. ibwpofile :
  4776. if not silent then
  4777. ReadWpoFileInfo;
  4778. ibresources :
  4779. if not silent then
  4780. ReadContainer('Resource file: ');
  4781. iborderedsymbols:
  4782. if not silent then
  4783. ReadContainer('Ordered symbol: ');
  4784. iberror :
  4785. begin
  4786. WriteError('Error in PPU');
  4787. exit;
  4788. end;
  4789. ibendinterface :
  4790. break;
  4791. else
  4792. begin
  4793. WriteError('!! Skipping unsupported PPU Entry in General Part: '+IntToStr(b));
  4794. end;
  4795. end;
  4796. until false;
  4797. end;
  4798. end;
  4799. {****************************************************************************
  4800. Read Implementation Part
  4801. ****************************************************************************}
  4802. procedure readimplementation;
  4803. var
  4804. b : byte;
  4805. begin
  4806. with ppufile do
  4807. begin
  4808. repeat
  4809. b:=readentry;
  4810. case b of
  4811. ibasmsymbols :
  4812. ReadAsmSymbols;
  4813. ibloadunit :
  4814. ReadLoadUnit;
  4815. ibunitimportsyms :
  4816. ReadUnitImportSyms;
  4817. iberror :
  4818. begin
  4819. WriteError('Error in PPU');
  4820. exit;
  4821. end;
  4822. ibendimplementation :
  4823. break;
  4824. else
  4825. begin
  4826. WriteError('!! Skipping unsupported PPU Entry in Implementation: '+IntToStr(b));
  4827. end;
  4828. end;
  4829. until false;
  4830. end;
  4831. end;
  4832. function parseextraheader(module: TPpuModuleDef; ppufile: tppufile): boolean;
  4833. var
  4834. b: byte;
  4835. begin
  4836. result:=false;
  4837. b:=ppufile.readentry;
  4838. if b<>ibextraheader then
  4839. exit;
  4840. CurUnit.LongVersion:=cardinal(ppufile.getlongint);
  4841. Writeln(['LongVersion: ',CurUnit.LongVersion]);
  4842. ppufile.getset(tppuset4(CurUnit.ModuleFlags));
  4843. result:=ppufile.EndOfEntry and (CurUnit.LongVersion=CurrentPPULongVersion);
  4844. if mf_symansistr in CurUnit.ModuleFlags then
  4845. SymAnsiStr:=true;
  4846. end;
  4847. procedure dofile (filename : string);
  4848. begin
  4849. { reset }
  4850. space:='';
  4851. { fix filename }
  4852. if pos('.',filename)=0 then
  4853. filename:=filename+'.ppu';
  4854. ppufile:=tppudumpfile.create(filename);
  4855. if not ppufile.openfile then
  4856. begin
  4857. WriteError('IO-Error when opening : '+filename+', Skipping');
  4858. exit;
  4859. end;
  4860. { PPU File is open, check for PPU Id }
  4861. if not ppufile.CheckPPUID then
  4862. begin
  4863. WriteError(Filename+' : Not a valid PPU file, Skipping');
  4864. exit;
  4865. end;
  4866. { Check PPU Version }
  4867. ppuversion:=ppufile.getversion;
  4868. Writeln(['Analyzing ',filename,' (v',PPUVersion,')']);
  4869. if not SkipVersionCheck and (PPUVersion <> CurrentPPUVersion) then
  4870. begin
  4871. WriteError(Format('Unsupported PPU version %d. Expecting PPU version %d.', [PPUVersion, CurrentPPUVersion]));
  4872. exit;
  4873. end;
  4874. CurUnit:=TPpuModuleDef.Create(UnitList);
  4875. CurUnit.Version:=ppuversion;
  4876. if not parseextraheader(CurUnit, ppufile) then
  4877. begin
  4878. WriteError(Format('Unsupported PPU sub-version %d. Expecting PPU sub-version %d.', [CurUnit.LongVersion, CurrentPPULongVersion]));
  4879. end;
  4880. { Write PPU Header Information }
  4881. if (verbose and v_header)<>0 then
  4882. begin
  4883. Writeln;
  4884. Writeln('Header');
  4885. Writeln('-------');
  4886. with ppufile.header do
  4887. begin
  4888. Writeln(['Compiler version : ',ppufile.header.common.compiler shr 14,'.',
  4889. (ppufile.header.common.compiler shr 7) and $7f,'.',
  4890. ppufile.header.common.compiler and $7f]);
  4891. WriteLn(['Target processor : ',Cpu2Str(common.cpu)]);
  4892. WriteLn(['Target operating system : ',Target2Str(common.target)]);
  4893. Writeln(['Unit flags : ',PPUFlags2Str(common.flags)]);
  4894. Writeln(['FileSize (w/o header) : ',common.size]);
  4895. Writeln(['Checksum : ',hexstr(checksum,8)]);
  4896. Writeln(['Interface Checksum : ',hexstr(interface_checksum,8)]);
  4897. Writeln(['Indirect Checksum : ',hexstr(indirect_checksum,8)]);
  4898. Writeln(['Definitions stored : ',tostr(deflistsize)]);
  4899. Writeln(['Symbols stored : ',tostr(symlistsize)]);
  4900. end;
  4901. end;
  4902. with ppufile.header do
  4903. begin
  4904. CurUnit.Crc:=checksum;
  4905. CurUnit.IntfCrc:=interface_checksum;
  4906. CurUnit.TargetCPU:=Cpu2Str(common.cpu);
  4907. CurUnit.TargetOS:=Target2Str(common.target);
  4908. end;
  4909. {read the general stuff}
  4910. if (verbose and v_interface)<>0 then
  4911. begin
  4912. Writeln;
  4913. Writeln('Interface section');
  4914. Writeln('------------------');
  4915. readinterface(false);
  4916. end
  4917. { We need derefdata from Interface }
  4918. else if verbose and (v_defs or v_syms or v_implementation)<>0 then
  4919. readinterface(true)
  4920. else
  4921. ppufile.skipuntilentry(ibendinterface);
  4922. Writeln;
  4923. Writeln('Interface symtable');
  4924. Writeln('----------------------');
  4925. readsymtableoptions('interface');
  4926. {read the definitions}
  4927. if (verbose and v_defs)<>0 then
  4928. begin
  4929. Writeln;
  4930. Writeln('Interface definitions');
  4931. Writeln('----------------------');
  4932. readdefinitions('interface', CurUnit);
  4933. end
  4934. else
  4935. ppufile.skipuntilentry(ibenddefs);
  4936. {read the symbols}
  4937. if (verbose and v_syms)<>0 then
  4938. begin
  4939. Writeln;
  4940. Writeln('Interface Symbols');
  4941. Writeln('------------------');
  4942. readsymbols('interface',CurUnit);
  4943. end
  4944. else
  4945. ppufile.skipuntilentry(ibendsyms);
  4946. {read the macro symbols}
  4947. if (verbose and v_syms)<>0 then
  4948. begin
  4949. Writeln;
  4950. Writeln('Interface Macro Symbols');
  4951. Writeln('-----------------------');
  4952. end;
  4953. if ppufile.readentry<>ibexportedmacros then
  4954. begin
  4955. WriteError('!! Error in PPU');
  4956. exit;
  4957. end;
  4958. if ppufile.getboolean then
  4959. begin
  4960. readsymtableoptions('interface macro');
  4961. {skip the definition section for macros (since they are never used) }
  4962. ppufile.skipuntilentry(ibenddefs);
  4963. {read the macro symbols}
  4964. if (verbose and v_syms)<>0 then
  4965. readsymbols('interface macro')
  4966. else
  4967. ppufile.skipuntilentry(ibendsyms);
  4968. end
  4969. else
  4970. Writeln('(no exported macros)');
  4971. {read the implementation stuff}
  4972. if (verbose and v_implementation)<>0 then
  4973. begin
  4974. Writeln;
  4975. Writeln('Implementation section');
  4976. Writeln('-----------------------');
  4977. readimplementation;
  4978. end
  4979. else
  4980. ppufile.skipuntilentry(ibendimplementation);
  4981. {read the static symtable}
  4982. Writeln;
  4983. Writeln('Implementation symtable');
  4984. Writeln('----------------------');
  4985. readsymtableoptions('implementation');
  4986. if (mf_local_symtable in CurUnit.ModuleFlags) then
  4987. begin
  4988. if (verbose and v_defs)<>0 then
  4989. begin
  4990. Writeln;
  4991. Writeln('Static definitions');
  4992. Writeln('----------------------');
  4993. readdefinitions('implementation', nil);
  4994. end
  4995. else
  4996. ppufile.skipuntilentry(ibenddefs);
  4997. {read the symbols}
  4998. if (verbose and v_syms)<>0 then
  4999. begin
  5000. Writeln;
  5001. Writeln('Static Symbols');
  5002. Writeln('------------------');
  5003. readsymbols('implementation');
  5004. end
  5005. else
  5006. ppufile.skipuntilentry(ibendsyms);
  5007. end;
  5008. ReadCreatedObjTypes;
  5009. FreeDerefdata;
  5010. {shutdown ppufile}
  5011. ppufile.closefile;
  5012. ppufile.free;
  5013. Writeln;
  5014. end;
  5015. procedure WriteLogo;
  5016. begin
  5017. writeln(Title+' Version '+version_string);
  5018. writeln(Copyright);
  5019. writeln;
  5020. end;
  5021. procedure help;
  5022. begin
  5023. WriteLogo;
  5024. writeln('usage: ppudump [options] <filename1> <filename2>...');
  5025. writeln;
  5026. writeln('[options] can be:');
  5027. writeln(' -F<format> Set output format to <format>');
  5028. writeln(' t - text format (default)');
  5029. writeln(' j - JSON format');
  5030. writeln(' x - XML format');
  5031. writeln(' -M Exit with ExitCode=2 if more information is available');
  5032. writeln(' -S Skip PPU version check. May lead to reading errors');
  5033. writeln(' -V<verbose> Set verbosity to <verbose>');
  5034. writeln(' H - Show header info');
  5035. writeln(' I - Show interface');
  5036. writeln(' M - Show implementation');
  5037. writeln(' S - Show interface symbols');
  5038. writeln(' D - Show interface definitions');
  5039. writeln(' A - Show all');
  5040. writeln(' -h, -? This helpscreen');
  5041. halt;
  5042. end;
  5043. var
  5044. startpara,
  5045. nrfile,i : longint;
  5046. para : string;
  5047. const
  5048. error_on_more : boolean = false;
  5049. begin
  5050. if paramcount<1 then
  5051. help;
  5052. { turn verbose on by default }
  5053. verbose:=v_all;
  5054. { read options }
  5055. startpara:=1;
  5056. while copy(paramstr(startpara),1,1)='-' do
  5057. begin
  5058. para:=paramstr(startpara);
  5059. case upcase(para[2]) of
  5060. 'F' : begin
  5061. FreeAndNil(pout);
  5062. if Length(para) > 2 then
  5063. case upcase(para[3]) of
  5064. 'T':
  5065. nostdout:=False;
  5066. 'J':
  5067. begin
  5068. nostdout:=True;
  5069. pout:=TPpuJsonOutput.Create(StdOutputHandle);
  5070. end;
  5071. 'X':
  5072. begin
  5073. nostdout:=True;
  5074. pout:=TPpuXmlOutput.Create(StdOutputHandle);
  5075. end;
  5076. else
  5077. begin
  5078. WriteError('Invalid output format: ' + para[3]);
  5079. Halt(1);
  5080. end;
  5081. end;
  5082. end;
  5083. 'M' : error_on_more:=true;
  5084. 'S' : SkipVersionCheck:=True;
  5085. 'V' : begin
  5086. verbose:=0;
  5087. for i:=3 to length(para) do
  5088. case upcase(para[i]) of
  5089. 'H' : verbose:=verbose or v_header;
  5090. 'I' : verbose:=verbose or v_interface;
  5091. 'M' : verbose:=verbose or v_implementation;
  5092. 'D' : verbose:=verbose or v_defs;
  5093. 'S' : verbose:=verbose or v_syms;
  5094. 'A' : verbose:=verbose or v_all;
  5095. end;
  5096. end;
  5097. 'H' : help;
  5098. '?' : help;
  5099. else
  5100. begin
  5101. WriteError('Invalid option: ' + para);
  5102. Halt(1);
  5103. end;
  5104. end;
  5105. inc(startpara);
  5106. end;
  5107. if not nostdout then
  5108. WriteLogo;
  5109. UnitList:=TPpuContainerDef.Create(nil);
  5110. try
  5111. UnitList.ItemsName:='';
  5112. { process files }
  5113. for nrfile:=startpara to paramcount do
  5114. dofile (paramstr(nrfile));
  5115. if not has_errors and (pout <> nil) then
  5116. begin
  5117. pout.Init;
  5118. UnitList.Write(pout);
  5119. pout.Done;
  5120. end;
  5121. finally
  5122. UnitList.Free;
  5123. pout.Free;
  5124. end;
  5125. if has_errors then
  5126. Halt(1);
  5127. if error_on_more and
  5128. (has_more_infos or has_warnings) then
  5129. Halt(2);
  5130. end.