ppudump.pp 156 KB

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