ppudump.pp 172 KB

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