ppudump.pp 125 KB

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