ppudump.pp 125 KB

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