ppudump.pp 144 KB

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