ppudump.pp 126 KB

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