ppudump.pp 127 KB

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