ppudump.pp 127 KB

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