ppudump.pp 143 KB

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