ppudump.pp 124 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113
  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. // idtoken,
  1472. token : ttoken;
  1473. // state : tmsgstate;
  1474. new_settings : Tsettings;
  1475. len : sizeint;
  1476. wstring : widestring;
  1477. astring : ansistring;
  1478. genconstr : tgenericconstraintflags;
  1479. function readtoken: ttoken;
  1480. var
  1481. b,b2 : byte;
  1482. begin
  1483. b:=tokenbuf[i];
  1484. inc(i);
  1485. if (b and $80)<>0 then
  1486. begin
  1487. b2:=tokenbuf[i];
  1488. inc(i);
  1489. result:=ttoken(((b and $7f) shl 8) or b2);
  1490. end
  1491. else
  1492. result:=ttoken(b);
  1493. end;
  1494. function gettokenbufdword : dword;
  1495. var
  1496. var32 : dword;
  1497. begin
  1498. var32:=pdword(@tokenbuf[i])^;
  1499. inc(i,sizeof(dword));
  1500. if ppufile.change_endian then
  1501. var32:=swapendian(var32);
  1502. result:=var32;
  1503. end;
  1504. function gettokenbufword : word;
  1505. var
  1506. var16 : word;
  1507. begin
  1508. var16:=pword(@tokenbuf[i])^;
  1509. inc(i,sizeof(word));
  1510. if ppufile.change_endian then
  1511. var16:=swapendian(var16);
  1512. result:=var16;
  1513. end;
  1514. function gettokenbufsizeint : int64;
  1515. var
  1516. var64 : int64;
  1517. var32 : longint;
  1518. var16 : smallint;
  1519. begin
  1520. if CpuAddrBitSize[cpu]=64 then
  1521. begin
  1522. var64:=pint64(@tokenbuf[i])^;
  1523. inc(i,sizeof(int64));
  1524. if ppufile.change_endian then
  1525. var64:=swapendian(var64);
  1526. result:=var64;
  1527. end
  1528. else if CpuAddrBitSize[cpu]=32 then
  1529. begin
  1530. var32:=plongint(@tokenbuf[i])^;
  1531. inc(i,sizeof(longint));
  1532. if ppufile.change_endian then
  1533. var32:=swapendian(var32);
  1534. result:=var32;
  1535. end
  1536. else if CpuAddrBitSize[cpu]=16 then
  1537. begin
  1538. var16:=psmallint(@tokenbuf[i])^;
  1539. inc(i,sizeof(smallint));
  1540. if ppufile.change_endian then
  1541. var16:=swapendian(var16);
  1542. result:=var16;
  1543. end
  1544. else
  1545. begin
  1546. WriteError('Wrong CpuAddrBitSize');
  1547. result:=0;
  1548. end;
  1549. end;
  1550. begin
  1551. i:=ppufile.getlongint;
  1552. if Def <> nil then
  1553. Def.Id:=i;
  1554. writeln([space,'** Definition Id ',i,' **']);
  1555. writeln([space,s]);
  1556. write ([space,' Type symbol : ']);
  1557. if Def <> nil then
  1558. readderef('', Def.Ref)
  1559. else
  1560. readderef('');
  1561. write ([space,' DefOptions : ']);
  1562. ppufile.getsmallset(defoptions);
  1563. if defoptions<>[] then
  1564. begin
  1565. first:=true;
  1566. for i:=1to high(defopt) do
  1567. if (defopt[i].mask in defoptions) then
  1568. begin
  1569. if first then
  1570. first:=false
  1571. else
  1572. write(', ');
  1573. write(defopt[i].str);
  1574. end;
  1575. end;
  1576. writeln;
  1577. write ([space,' DefStates : ']);
  1578. ppufile.getsmallset(defstates);
  1579. if defstates<>[] then
  1580. begin
  1581. first:=true;
  1582. for i:=1 to high(defstate) do
  1583. if (defstate[i].mask in defstates) then
  1584. begin
  1585. if first then
  1586. first:=false
  1587. else
  1588. write(', ');
  1589. write(defstate[i].str);
  1590. end;
  1591. end;
  1592. writeln;
  1593. if df_genconstraint in defoptions then
  1594. begin
  1595. ppufile.getsmallset(genconstr);
  1596. write ([space,' GenConstraints : ']);
  1597. if genconstr<>[] then
  1598. begin
  1599. first:=true;
  1600. for i:=1 to high(genconstrflag) do
  1601. if (genconstrflag[i].mask in genconstr) then
  1602. begin
  1603. if first then
  1604. first:=false
  1605. else
  1606. write(', ');
  1607. write(genconstrflag[i].str);
  1608. end;
  1609. end;
  1610. writeln;
  1611. len:=ppufile.getasizeint;
  1612. if len>0 then
  1613. begin
  1614. space:=' '+space;
  1615. writeln([space,'------ constraint defs begin ------']);
  1616. for i:=0 to len-1 do
  1617. begin
  1618. writeln([space,'------ constraint def ',i,' ------']);
  1619. readderef(space);
  1620. end;
  1621. writeln([space,'------ constraint defs end ------']);
  1622. delete(space,1,4);
  1623. end;
  1624. end;
  1625. if [df_generic,df_specialization]*defoptions<>[] then
  1626. begin
  1627. nb:=ppufile.getlongint;
  1628. writeln([space,'has ',nb,' parameters']);
  1629. if nb>0 then
  1630. begin
  1631. for i:=0 to nb-1 do
  1632. begin
  1633. writeln([space,'parameter ',i,': ',ppufile.getstring]);
  1634. readderef(space);
  1635. end;
  1636. end;
  1637. end;
  1638. if df_generic in defoptions then
  1639. begin
  1640. tokenbufsize:=ppufile.getlongint;
  1641. writeln([space,' Tokenbuffer size : ',tokenbufsize]);
  1642. tokenbuf:=allocmem(tokenbufsize);
  1643. ppufile.getdata(tokenbuf^,tokenbufsize);
  1644. i:=0;
  1645. write([space,' Tokens: ']);
  1646. while i<tokenbufsize do
  1647. begin
  1648. token:=readtoken;
  1649. if token<>_GENERICSPECIALTOKEN then
  1650. begin
  1651. if token <= high(ttoken) then
  1652. write(arraytokeninfo[token].str)
  1653. else
  1654. begin
  1655. HasMoreInfos;
  1656. write('Error in Token List');
  1657. break;
  1658. end;
  1659. {idtoken:=}readtoken;
  1660. end;
  1661. case token of
  1662. _CWCHAR,
  1663. _CWSTRING :
  1664. begin
  1665. len:=gettokenbufsizeint;
  1666. setlength(wstring,len);
  1667. move(tokenbuf[i],wstring[1],len*2);
  1668. write([' ',wstring]);
  1669. inc(i,len*2);
  1670. end;
  1671. _CSTRING:
  1672. begin
  1673. len:=gettokenbufsizeint;
  1674. setlength(astring,len);
  1675. move(tokenbuf[i],astring[1],len);
  1676. write([' ',astring]);
  1677. inc(i,len);
  1678. end;
  1679. _CCHAR,
  1680. _INTCONST,
  1681. _REALNUMBER :
  1682. begin
  1683. write([' ',pshortstring(@tokenbuf[i])^]);
  1684. inc(i,tokenbuf[i]+1);
  1685. end;
  1686. _ID :
  1687. begin
  1688. write([' ',pshortstring(@tokenbuf[i])^]);
  1689. inc(i,tokenbuf[i]+1);
  1690. end;
  1691. _GENERICSPECIALTOKEN:
  1692. begin
  1693. { Short version of column change,
  1694. byte or $80 used }
  1695. if (tokenbuf[i] and $80)<>0 then
  1696. begin
  1697. write(['Col: ',tokenbuf[i] and $7f]);
  1698. inc(i);
  1699. end
  1700. else
  1701. case tspecialgenerictoken(tokenbuf[i]) of
  1702. ST_LOADSETTINGS:
  1703. begin
  1704. inc(i);
  1705. write('Settings');
  1706. { This does not load pmessage pointer }
  1707. new_settings.pmessage:=nil;
  1708. { TSettings size depends in target...
  1709. We first read the size of the copied part }
  1710. { Still not cross endian ready :( }
  1711. copy_size:=gettokenbufsizeint;
  1712. if copy_size < sizeof(tsettings)-sizeof(pointer) then
  1713. min_size:=copy_size
  1714. else
  1715. min_size:= sizeof(tsettings)-sizeof(pointer);
  1716. move(tokenbuf[i],new_settings, min_size);
  1717. inc(i,copy_size);
  1718. end;
  1719. ST_LOADMESSAGES:
  1720. begin
  1721. inc(i);
  1722. write('Messages:');
  1723. mesgnb:=tokenbuf[i];
  1724. inc(i);
  1725. for nb:=1 to mesgnb do
  1726. begin
  1727. {msgvalue:=}gettokenbufsizeint;
  1728. inc(i,sizeof(sizeint));
  1729. //state:=tmsgstate(gettokenbufsizeint);
  1730. end;
  1731. end;
  1732. ST_LINE:
  1733. begin
  1734. inc(i);
  1735. write(['Line: ',gettokenbufdword]);
  1736. end;
  1737. ST_COLUMN:
  1738. begin
  1739. inc(i);
  1740. write(['Col: ',gettokenbufword]);
  1741. end;
  1742. ST_FILEINDEX:
  1743. begin
  1744. inc(i);
  1745. write(['File: ',gettokenbufword]);
  1746. end;
  1747. end;
  1748. end;
  1749. end;
  1750. if i<tokenbufsize then
  1751. write(',');
  1752. end;
  1753. writeln;
  1754. freemem(tokenbuf);
  1755. end;
  1756. if df_specialization in defoptions then
  1757. begin
  1758. write ([space,' Orig. GenericDef : ']);
  1759. readderef('');
  1760. end;
  1761. current_defoptions:=defoptions;
  1762. end;
  1763. { Read abstract procdef and return if inline procdef }
  1764. { type tproccalloption is in globtype unit }
  1765. { type tproctypeoption is in globtype unit }
  1766. { type tprocoption is in globtype unit }
  1767. procedure read_abstract_proc_def(var proccalloption:tproccalloption;var procoptions:tprocoptions; ProcDef: TPpuProcDef);
  1768. type
  1769. tproccallopt=record
  1770. mask : tproccalloption;
  1771. str : string[30];
  1772. end;
  1773. tproctypeopt=record
  1774. mask : tproctypeoption;
  1775. str : string[30];
  1776. end;
  1777. tprocopt=record
  1778. mask : tprocoption;
  1779. str : string[31];
  1780. end;
  1781. const
  1782. {proccalloptionStr is also in globtype unit }
  1783. proctypeopt : array[1..ord(high(tproctypeoption))] of tproctypeopt=(
  1784. (mask:potype_proginit; str:'ProgInit'),
  1785. (mask:potype_unitinit; str:'UnitInit'),
  1786. (mask:potype_unitfinalize; str:'UnitFinalize'),
  1787. (mask:potype_constructor; str:'Constructor'),
  1788. (mask:potype_destructor; str:'Destructor'),
  1789. (mask:potype_operator; str:'Operator'),
  1790. (mask:potype_procedure; str:'Procedure'),
  1791. (mask:potype_function; str:'Function'),
  1792. (mask:potype_class_constructor; str:'Class Constructor'),
  1793. (mask:potype_class_destructor; str:'Class Destructor'),
  1794. { Dispinterface property accessors }
  1795. (mask:potype_propgetter; str:'Property Getter'),
  1796. (mask:potype_propsetter; str:'Property Setter'),
  1797. (mask:potype_exceptfilter; str:'SEH filter'),
  1798. (mask:potype_mainstub; str:'main stub'),
  1799. (mask:potype_pkgstub; str:'package stub')
  1800. );
  1801. procopt : array[1..ord(high(tprocoption))] of tprocopt=(
  1802. (mask:po_classmethod; str:'ClassMethod'),
  1803. (mask:po_virtualmethod; str:'VirtualMethod'),
  1804. (mask:po_abstractmethod; str:'AbstractMethod'),
  1805. (mask:po_finalmethod; str:'FinalMethod'),
  1806. (mask:po_staticmethod; str:'StaticMethod'),
  1807. (mask:po_overridingmethod;str:'OverridingMethod'),
  1808. (mask:po_methodpointer; str:'MethodPointer'),
  1809. (mask:po_interrupt; str:'Interrupt'),
  1810. (mask:po_iocheck; str:'IOCheck'),
  1811. (mask:po_assembler; str:'Assembler'),
  1812. (mask:po_msgstr; str:'MsgStr'),
  1813. (mask:po_msgint; str:'MsgInt'),
  1814. (mask:po_exports; str:'Exports'),
  1815. (mask:po_external; str:'External'),
  1816. (mask:po_overload; str:'Overload'),
  1817. (mask:po_varargs; str:'VarArgs'),
  1818. (mask:po_internconst; str:'InternConst'),
  1819. (mask:po_addressonly; str:'AddressOnly'),
  1820. (mask:po_public; str:'Public'),
  1821. (mask:po_hascallingconvention;str:'HasCallingConvention'),
  1822. (mask:po_reintroduce; str:'ReIntroduce'),
  1823. (mask:po_explicitparaloc; str:'ExplicitParaloc'),
  1824. (mask:po_nostackframe; str:'NoStackFrame'),
  1825. (mask:po_has_mangledname; str:'HasMangledName'),
  1826. (mask:po_has_public_name; str:'HasPublicName'),
  1827. (mask:po_forward; str:'Forward'),
  1828. (mask:po_global; str:'Global'),
  1829. (mask:po_syscall; str:'Syscall'),
  1830. (mask:po_syscall_legacy; str:'SyscallLegacy'),
  1831. (mask:po_syscall_basenone;str:'SyscallBaseNone'),
  1832. (mask:po_syscall_basefirst;str:'SyscallBaseFirst'),
  1833. (mask:po_syscall_baselast;str:'SyscallBaseLast'),
  1834. (mask:po_syscall_basereg; str:'SyscallBaseReg'),
  1835. (mask:po_syscall_has_libsym; str:'Has LibSym'),
  1836. (mask:po_syscall_has_importnr; str:'Uses ImportNr'),
  1837. (mask:po_inline; str:'Inline'),
  1838. (mask:po_compilerproc; str:'CompilerProc'),
  1839. (mask:po_has_importdll; str:'HasImportDLL'),
  1840. (mask:po_has_importname; str:'HasImportName'),
  1841. (mask:po_kylixlocal; str:'KylixLocal'),
  1842. (mask:po_dispid; str:'DispId'),
  1843. (mask:po_weakexternal; str:'WeakExternal'),
  1844. (mask:po_objc; str:'ObjC'),
  1845. (mask:po_enumerator_movenext; str:'EnumeratorMoveNext'),
  1846. (mask:po_optional; str: 'Optional'),
  1847. (mask:po_delphi_nested_cc;str: 'Delphi-style nested frameptr'),
  1848. (mask:po_java_nonvirtual; str: 'Java non-virtual method'),
  1849. (mask:po_ignore_for_overload_resolution;str: 'Ignored for overload resolution'),
  1850. (mask:po_rtlproc; str: 'RTL procedure'),
  1851. (mask:po_auto_raised_visibility; str: 'Visibility raised by compiler'),
  1852. (mask:po_far; str: 'Far'),
  1853. (mask:po_noreturn; str: 'No return'),
  1854. (mask:po_is_function_ref; str: 'Function reference'),
  1855. (mask:po_is_block; str: 'C "Block"'),
  1856. (mask:po_is_auto_getter; str: 'Automatically generated getter'),
  1857. (mask:po_is_auto_setter; str: 'Automatically generated setter')
  1858. );
  1859. var
  1860. proctypeoption : tproctypeoption;
  1861. i : longint;
  1862. first : boolean;
  1863. begin
  1864. write([space,' Return type : ']);
  1865. readderef('', ProcDef.ReturnType);
  1866. proctypeoption:=tproctypeoption(ppufile.getbyte);
  1867. case proctypeoption of
  1868. potype_function: Include(ProcDef.Options, poFunction);
  1869. potype_procedure: Include(ProcDef.Options, poProcedure);
  1870. potype_constructor: Include(ProcDef.Options, poConstructor);
  1871. potype_destructor: Include(ProcDef.Options, poDestructor);
  1872. potype_operator: Include(ProcDef.Options, poOperator);
  1873. end;
  1874. write([space,' TypeOption : ']);
  1875. first:=true;
  1876. for i:=1 to high(proctypeopt) do
  1877. if (proctypeopt[i].mask=proctypeoption) then
  1878. begin
  1879. if first then
  1880. first:=false
  1881. else
  1882. write(', ');
  1883. write(proctypeopt[i].str);
  1884. end;
  1885. writeln;
  1886. proccalloption:=tproccalloption(ppufile.getbyte);
  1887. writeln([space,' CallOption : ',proccalloptionStr[proccalloption]]);
  1888. ppufile.getnormalset(procoptions);
  1889. if procoptions<>[] then
  1890. begin
  1891. if po_classmethod in procoptions then Include(ProcDef.Options, poClassMethod);
  1892. if po_virtualmethod in procoptions then Include(ProcDef.Options, poVirtual);
  1893. if po_abstractmethod in procoptions then Include(ProcDef.Options, poAbstract);
  1894. if po_overridingmethod in procoptions then Include(ProcDef.Options, poOverriding);
  1895. if po_overload in procoptions then Include(ProcDef.Options, poOverload);
  1896. if po_inline in procoptions then Include(ProcDef.Options, poInline);
  1897. if (po_methodpointer in procoptions) and (ProcDef.DefType = dtProcType) then
  1898. TPpuProcTypeDef(ProcDef).MethodPtr:=True;
  1899. write([space,' Options : ']);
  1900. first:=true;
  1901. for i:=1 to high(procopt) do
  1902. if (procopt[i].mask in procoptions) then
  1903. begin
  1904. if first then
  1905. first:=false
  1906. else
  1907. write(', ');
  1908. write(procopt[i].str);
  1909. end;
  1910. writeln;
  1911. end;
  1912. if (po_explicitparaloc in procoptions) then
  1913. begin
  1914. readcgpara(space);
  1915. end;
  1916. end;
  1917. { type tvaroption is in unit symconst }
  1918. { register variable }
  1919. { type tvarregable is in unit symconst }
  1920. procedure readabstractvarsym(const s:string;var varoptions:tvaroptions; VarDef: TPpuVarDef = nil);
  1921. type
  1922. tvaropt=record
  1923. mask : tvaroption;
  1924. str : string[30];
  1925. end;
  1926. const
  1927. varopt : array[1..ord(high(tvaroption))] of tvaropt=(
  1928. (mask:vo_is_external; str:'External'),
  1929. (mask:vo_is_dll_var; str:'DLLVar'),
  1930. (mask:vo_is_thread_var; str:'ThreadVar'),
  1931. (mask:vo_has_local_copy; str:'HasLocalCopy'),
  1932. (mask:vo_is_const; str:'Constant'),
  1933. (mask:vo_is_public; str:'Public'),
  1934. (mask:vo_is_high_para; str:'HighValue'),
  1935. (mask:vo_is_funcret; str:'Funcret'),
  1936. (mask:vo_is_self; str:'Self'),
  1937. (mask:vo_is_vmt; str:'VMT'),
  1938. (mask:vo_is_result; str:'Result'),
  1939. (mask:vo_is_parentfp; str:'ParentFP'),
  1940. (mask:vo_is_loop_counter; str:'LoopCounter'),
  1941. (mask:vo_is_hidden_para; str:'Hidden'),
  1942. (mask:vo_has_explicit_paraloc;str:'ExplicitParaloc'),
  1943. (mask:vo_is_syscall_lib; str:'SysCallLib'),
  1944. (mask:vo_has_mangledname; str:'HasMangledName'),
  1945. (mask:vo_is_typed_const; str:'TypedConst'),
  1946. (mask:vo_is_range_check; str:'RangeCheckSwitch'),
  1947. (mask:vo_is_overflow_check; str:'OverflowCheckSwitch'),
  1948. (mask:vo_is_typinfo_para; str:'TypeInfo'),
  1949. (mask:vo_is_msgsel;str:'MsgSel'),
  1950. (mask:vo_is_weak_external;str:'WeakExternal'),
  1951. (mask:vo_is_first_field;str:'IsFirstField'),
  1952. (mask:vo_volatile; str:'Volatile'),
  1953. (mask:vo_has_section; str:'HasSection'),
  1954. (mask:vo_force_finalize; str:'ForceFinalize'),
  1955. (mask:vo_is_default_var; str:'DefaultIntrinsicVar')
  1956. );
  1957. var
  1958. i : longint;
  1959. first : boolean;
  1960. begin
  1961. readcommonsym(s, VarDef);
  1962. i:=ppufile.getbyte;
  1963. if (VarDef <> nil) and (VarDef.DefType = dtParam) then
  1964. with TPpuParamDef(VarDef) do
  1965. case tvarspez(i) of
  1966. vs_value: Spez:=psValue;
  1967. vs_var: Spez:=psVar;
  1968. vs_out: Spez:=psOut;
  1969. vs_const: Spez:=psConst;
  1970. vs_constref: Spez:=psConstRef;
  1971. end;
  1972. writeln([space,' Spez : ',Varspez2Str(i)]);
  1973. writeln([space,' Regable : ',Varregable2Str(ppufile.getbyte)]);
  1974. writeln([space,' Addr Taken : ',(ppufile.getbyte<>0)]);
  1975. write ([space,' Var Type : ']);
  1976. if VarDef <> nil then
  1977. readderef('',VarDef.VarType)
  1978. else
  1979. readderef('');
  1980. ppufile.getsmallset(varoptions);
  1981. if varoptions<>[] then
  1982. begin
  1983. if (VarDef <> nil) and (VarDef.DefType = dtParam) and (vo_is_hidden_para in varoptions) then
  1984. TPpuParamDef(VarDef).Spez:=psHidden;
  1985. write([space,' Options : ']);
  1986. first:=true;
  1987. for i:=1 to high(varopt) do
  1988. if (varopt[i].mask in varoptions) then
  1989. begin
  1990. if first then
  1991. first:=false
  1992. else
  1993. write(', ');
  1994. write(varopt[i].str);
  1995. end;
  1996. writeln;
  1997. end;
  1998. end;
  1999. procedure readobjectdefoptions(ObjDef: TPpuObjectDef = nil);
  2000. type
  2001. tsymopt=record
  2002. mask : tobjectoption;
  2003. str : string[30];
  2004. end;
  2005. const
  2006. symopt : array[1..ord(high(tobjectoption))] of tsymopt=(
  2007. (mask:oo_is_forward; str:'IsForward'),
  2008. (mask:oo_is_abstract; str:'IsAbstract'),
  2009. (mask:oo_is_sealed; str:'IsSealed'),
  2010. (mask:oo_has_virtual; str:'HasVirtual'),
  2011. (mask:oo_has_private; str:'HasPrivate'),
  2012. (mask:oo_has_protected; str:'HasProtected'),
  2013. (mask:oo_has_strictprivate; str:'HasStrictPrivate'),
  2014. (mask:oo_has_strictprotected;str:'HasStrictProtected'),
  2015. (mask:oo_has_constructor; str:'HasConstructor'),
  2016. (mask:oo_has_destructor; str:'HasDestructor'),
  2017. (mask:oo_has_vmt; str:'HasVMT'),
  2018. (mask:oo_has_msgstr; str:'HasMsgStr'),
  2019. (mask:oo_has_msgint; str:'HasMsgInt'),
  2020. (mask:oo_can_have_published; str:'CanHavePublished'),
  2021. (mask:oo_has_default_property;str:'HasDefaultProperty'),
  2022. (mask:oo_has_valid_guid; str:'HasValidGUID'),
  2023. (mask:oo_has_enumerator_movenext; str:'HasEnumeratorMoveNext'),
  2024. (mask:oo_has_enumerator_current; str:'HasEnumeratorCurrent'),
  2025. (mask:oo_is_external; str:'External'),
  2026. (mask:oo_is_formal; str:'Formal'),
  2027. (mask:oo_is_classhelper; str:'Class Helper/Category'),
  2028. (mask:oo_has_class_constructor; str:'HasClassConstructor'),
  2029. (mask:oo_has_class_destructor; str:'HasClassDestructor'),
  2030. (mask:oo_is_enum_class; str:'JvmEnumClass'),
  2031. (mask:oo_has_new_destructor; str:'HasNewDestructor')
  2032. );
  2033. var
  2034. i : longint;
  2035. first : boolean;
  2036. begin
  2037. ppufile.getsmallset(current_objectoptions);
  2038. if current_objectoptions<>[] then
  2039. begin
  2040. if ObjDef <> nil then
  2041. begin
  2042. if oo_is_abstract in current_objectoptions then
  2043. Include(ObjDef.Options, ooIsAbstract);
  2044. end;
  2045. first:=true;
  2046. for i:=1 to high(symopt) do
  2047. if (symopt[i].mask in current_objectoptions) then
  2048. begin
  2049. if first then
  2050. first:=false
  2051. else
  2052. write(', ');
  2053. write(symopt[i].str);
  2054. end;
  2055. end;
  2056. writeln;
  2057. end;
  2058. procedure readprocimploptions(const space: string; out implprocoptions: timplprocoptions);
  2059. type
  2060. tpiopt=record
  2061. mask : timplprocoption;
  2062. str : string[30];
  2063. end;
  2064. const
  2065. piopt : array[low(timplprocoption)..high(timplprocoption)] of tpiopt=(
  2066. (mask:pio_empty; str:'IsEmpty'),
  2067. (mask:pio_has_inlininginfo; str:'HasInliningInfo')
  2068. );
  2069. var
  2070. i: timplprocoption;
  2071. first: boolean;
  2072. begin
  2073. ppufile.getsmallset(implprocoptions);
  2074. if implprocoptions<>[] then
  2075. begin
  2076. first:=true;
  2077. write([space,' Options : ']);
  2078. for i:=low(piopt) to high(piopt) do
  2079. begin
  2080. if i in implprocoptions then
  2081. begin
  2082. if first then
  2083. first:=false
  2084. else
  2085. write(', ');
  2086. write(piopt[i].str);
  2087. end;
  2088. end;
  2089. writeln;
  2090. end;
  2091. end;
  2092. procedure readarraydefoptions(ArrayDef: TPpuArrayDef);
  2093. { type tarraydefoption is in unit symconst }
  2094. const
  2095. symopt : array[tarraydefoption] of string = (
  2096. { ado_IsConvertedPointer } 'ConvertedPointer',
  2097. { ado_IsDynamicArray } 'IsDynamicArray',
  2098. { ado_IsVariant } 'IsVariant',
  2099. { ado_IsConstructor } 'IsConstructor',
  2100. { ado_IsArrayOfConst } 'ArrayOfConst',
  2101. { ado_IsConstString } 'ConstString',
  2102. { ado_IsBitPacked } 'BitPacked'
  2103. );
  2104. var
  2105. symoptions: tarraydefoptions;
  2106. i: tarraydefoption;
  2107. first: boolean;
  2108. begin
  2109. ppufile.getsmallset(symoptions);
  2110. if symoptions<>[] then
  2111. begin
  2112. if ado_IsDynamicArray in symoptions then Include(ArrayDef.Options, aoDynamic);
  2113. first:=true;
  2114. for i:=Low(symopt) to high(symopt) do
  2115. if (i in symoptions) then
  2116. begin
  2117. if first then
  2118. first:=false
  2119. else
  2120. write(', ');
  2121. write(symopt[i]);
  2122. end;
  2123. end;
  2124. writeln;
  2125. end;
  2126. (* options for properties
  2127. tpropertyoption=(ppo_none,
  2128. ppo_indexed,
  2129. ppo_defaultproperty,
  2130. ppo_stored,
  2131. ppo_hasparameters,
  2132. ppo_implements,
  2133. ppo_enumerator_current,
  2134. ppo_overrides,
  2135. ppo_dispid_write { no longer used }
  2136. );
  2137. tpropertyoptions=set of tpropertyoption;
  2138. *)
  2139. function readpropertyoptions:tpropertyoptions;
  2140. { type tarraydefoption is in unit symconst }
  2141. type
  2142. tpropopt=record
  2143. mask : tpropertyoption;
  2144. str : string[30];
  2145. end;
  2146. const
  2147. symopt : array[1..ord(high(tpropertyoption))] of tpropopt=(
  2148. (mask:ppo_indexed;str:'indexed'),
  2149. (mask:ppo_defaultproperty;str:'default'),
  2150. (mask:ppo_stored;str:'stored'),
  2151. (mask:ppo_hasparameters;str:'has parameters'),
  2152. (mask:ppo_implements;str:'implements'),
  2153. (mask:ppo_enumerator_current;str:'enumerator current'),
  2154. (mask:ppo_overrides;str:'overrides'),
  2155. (mask:ppo_dispid_write;str:'dispid write') { no longer used }
  2156. );
  2157. var
  2158. i : longint;
  2159. first : boolean;
  2160. begin
  2161. ppufile.getsmallset(result);
  2162. if result<>[] then
  2163. begin
  2164. first:=true;
  2165. for i:=1 to high(symopt) do
  2166. if (symopt[i].mask in result) then
  2167. begin
  2168. if first then
  2169. first:=false
  2170. else
  2171. write(', ');
  2172. write(symopt[i].str);
  2173. end;
  2174. end;
  2175. writeln;
  2176. end;
  2177. function readmanagementoperatoroptions(const space : string):tmanagementoperators;
  2178. { type is in unit symconst }
  2179. { Management operator options
  2180. tmanagementoperator=(
  2181. mop_none,
  2182. mop_initialize,
  2183. mop_finalize,
  2184. mop_addref,
  2185. mop_copy);
  2186. }
  2187. type
  2188. tmopopt=record
  2189. mask : tmanagementoperator;
  2190. str : string[10];
  2191. end;
  2192. const
  2193. managementoperatoropt : array[1..ord(high(tmanagementoperator))] of tmopopt=(
  2194. (mask:mop_initialize;str:'initialize'),
  2195. (mask:mop_finalize;str:'finalize'),
  2196. (mask:mop_addref;str:'addref'),
  2197. (mask:mop_copy;str:'copy')
  2198. );
  2199. var
  2200. i : longint;
  2201. first : boolean;
  2202. begin
  2203. ppufile.getsmallset(result);
  2204. if result<>[] then
  2205. begin
  2206. first:=true;
  2207. for i:=1 to high(managementoperatoropt) do
  2208. if (managementoperatoropt[i].mask in result) then
  2209. begin
  2210. if first then
  2211. begin
  2212. write(space);
  2213. write('Management operators: ');
  2214. first:=false;
  2215. end
  2216. else
  2217. write(', ');
  2218. write(managementoperatoropt[i].str);
  2219. end;
  2220. end;
  2221. if not first then
  2222. writeln;
  2223. end;
  2224. procedure readnodetree;
  2225. var
  2226. l : longint;
  2227. p : pointer;
  2228. begin
  2229. with ppufile do
  2230. begin
  2231. if space<>'' then
  2232. Writeln([space,'------ nodetree ------']);
  2233. if readentry=ibnodetree then
  2234. begin
  2235. l:=entrysize;
  2236. Writeln([space,'Tree size : ',l]);
  2237. { Read data to prevent error that entry is not completly read }
  2238. getmem(p,l);
  2239. getdata(p^,l);
  2240. freemem(p);
  2241. end
  2242. else
  2243. begin
  2244. WriteError('!! ibnodetree not found');
  2245. end;
  2246. end;
  2247. end;
  2248. procedure ReadCreatedObjTypes;
  2249. var
  2250. i,j,
  2251. len,
  2252. bssize: longint;
  2253. bs: pbyte;
  2254. begin
  2255. if ppufile.readentry<>ibcreatedobjtypes then
  2256. begin
  2257. WriteError('!! ibcreatedobjtypes entry not found');
  2258. ppufile.skipdata(ppufile.entrysize);
  2259. exit
  2260. end;
  2261. writeln;
  2262. writeln([space,'WPO info']);
  2263. writeln([space,'--------']);
  2264. len:=ppufile.getlongint;
  2265. writeln([space,'** Instantiated Object/Class types: ',len,' **']);
  2266. space:=space+' ';
  2267. for i:=0 to len-1 do
  2268. readderef(space);
  2269. setlength(space,length(space)-2);
  2270. len:=ppufile.getlongint;
  2271. writeln([space,'** Instantiated ClassRef types: ',len,' **']);
  2272. space:=space+' ';
  2273. for i:=0 to len-1 do
  2274. readderef(space);
  2275. setlength(space,length(space)-2);
  2276. len:=ppufile.getlongint;
  2277. writeln([space,'** Possibly instantiated ClassRef types : ',len,' **']);
  2278. space:=space+' ';
  2279. for i:=0 to len-1 do
  2280. readderef(space);
  2281. setlength(space,length(space)-2);
  2282. len:=ppufile.getlongint;
  2283. writeln([space,'** Class types with called virtual methods info : ',len,' **']);
  2284. space:=space+' ';
  2285. for i:=0 to len-1 do
  2286. begin
  2287. write([space,'Class def : ']);
  2288. readderef('');
  2289. write([space+' ','Called vmtentries : ']);
  2290. bssize:=ppufile.getlongint;
  2291. getmem(bs,bssize);
  2292. ppufile.readdata(bs^,bssize);
  2293. for j:=0 to bssize*8-1 do
  2294. if (((bs+j shr 3)^ shr (j and 7)) and 1) <> 0 then
  2295. write([j,', ']);
  2296. writeln;
  2297. freemem(bs);
  2298. end;
  2299. setlength(space,length(space)-2);
  2300. end;
  2301. {****************************************************************************
  2302. Read Symbols Part
  2303. ****************************************************************************}
  2304. procedure readsymbols(const s:string; ParentDef: TPpuContainerDef = nil);
  2305. function _finddef(symdef: TPpuDef): TPpuDef;
  2306. begin
  2307. Result:=nil;
  2308. if symdef.Ref.IsCurUnit then
  2309. begin;
  2310. Result:=CurUnit.FindById(symdef.Ref.Id);
  2311. if (Result <> nil) and (Result.Ref.Id = symdef.Id) then
  2312. begin
  2313. Result.Name:=symdef.Name;
  2314. Result.FilePos:=symdef.FilePos;
  2315. end
  2316. else
  2317. Result:=nil;
  2318. end;
  2319. end;
  2320. type
  2321. pguid = ^tguid;
  2322. tguid = packed record
  2323. D1: LongWord;
  2324. D2: Word;
  2325. D3: Word;
  2326. D4: array[0..7] of Byte;
  2327. end;
  2328. var
  2329. b : byte;
  2330. pc : pchar;
  2331. ch : dword;
  2332. startnewline : boolean;
  2333. i,j,len : longint;
  2334. prettyname, ss : ansistring;
  2335. ws: widestring;
  2336. guid : tguid;
  2337. realvalue : ppureal;
  2338. doublevalue : double;
  2339. singlevalue : single;
  2340. extended : TSplit80bitReal;
  2341. pw : pcompilerwidestring;
  2342. varoptions : tvaroptions;
  2343. propoptions : tpropertyoptions;
  2344. iexp: Tconstexprint;
  2345. def: TPpuDef;
  2346. constdef: TPpuConstDef absolute def;
  2347. begin
  2348. with ppufile do
  2349. begin
  2350. if space<>'' then
  2351. Writeln([space,'------ ',s,' ------']);
  2352. if readentry=ibstartsyms then
  2353. begin
  2354. Writeln([space,'Symtable count: ',getlongint]);
  2355. end
  2356. else
  2357. Writeln('!! ibstartsym not found');
  2358. repeat
  2359. def:=nil;
  2360. b:=readentry;
  2361. case b of
  2362. ibunitsym :
  2363. readcommonsym('Unit symbol ');
  2364. ibnamespacesym :
  2365. begin
  2366. readcommonsym('NameSpace symbol ');
  2367. write([space,' Hidden Unit : ']);
  2368. readderef('');
  2369. end;
  2370. iblabelsym :
  2371. readcommonsym('Label symbol ');
  2372. ibtypesym :
  2373. begin
  2374. def:=TPpuTypeRef.Create(nil);
  2375. readcommonsym('Type symbol ',def);
  2376. write([space,' Result Type : ']);
  2377. readderef('', def.Ref);
  2378. if _finddef(def) = nil then
  2379. def.Parent:=ParentDef;
  2380. prettyname:=getansistring;
  2381. if prettyname<>'' then
  2382. begin
  2383. write([space,' Pretty Name : ']);
  2384. Writeln(prettyname);
  2385. end;
  2386. end;
  2387. ibprocsym :
  2388. begin
  2389. def:=TPpuDef.Create(nil);
  2390. readcommonsym('Procedure symbol ', def);
  2391. len:=ppufile.getword;
  2392. for i:=1 to len do
  2393. begin
  2394. write([space,' Definition : ']);
  2395. readderef('', def.Ref);
  2396. _finddef(def);
  2397. end;
  2398. end;
  2399. ibconstsym :
  2400. begin
  2401. constdef:=TPpuConstDef.Create(ParentDef);
  2402. readcommonsym('Constant symbol ',constdef);
  2403. b:=getbyte;
  2404. case tconsttyp(b) of
  2405. constord :
  2406. begin
  2407. write ([space,' OrdinalType : ']);
  2408. readderef('',constdef.TypeRef);
  2409. iexp:=getexprint;
  2410. constdef.ConstType:=ctInt;
  2411. constdef.VInt:=iexp.svalue;
  2412. writeln([space,' Value : ',constexp.tostr(iexp)]);
  2413. end;
  2414. constpointer :
  2415. begin
  2416. write ([space,' PointerType : ']);
  2417. readderef('',constdef.TypeRef);
  2418. constdef.ConstType:=ctInt;
  2419. constdef.VInt:=getaint;
  2420. writeln([space,' Value : ',constdef.VInt])
  2421. end;
  2422. conststring,
  2423. constresourcestring :
  2424. begin
  2425. write ([space,' StringType : ']);
  2426. readderef('',constdef.TypeRef);
  2427. len:=getlongint;
  2428. getmem(pc,len+1);
  2429. getdata(pc^,len);
  2430. (pc+len)^:= #0;
  2431. writeln([space,' Length : ',len]);
  2432. writeln([space,' Value : "',pc,'"']);
  2433. constdef.ConstType:=ctStr;
  2434. SetString(constdef.VStr, pc, len);
  2435. constdef.VStr:=UTF8Encode(constdef.VStr);
  2436. freemem(pc,len+1);
  2437. end;
  2438. constreal :
  2439. begin
  2440. constdef.ConstType:=ctFloat;
  2441. write ([space,' RealType : ']);
  2442. readderef('',constdef.TypeRef);
  2443. write([space,' Value : ']);
  2444. if entryleft=sizeof(ppureal) then
  2445. begin
  2446. realvalue:=getrealsize(sizeof(ppureal));
  2447. constdef.VFloat:=realvalue;
  2448. writeln([realvalue]);
  2449. end
  2450. else if entryleft=sizeof(double) then
  2451. begin
  2452. doublevalue:=getrealsize(sizeof(double));
  2453. constdef.VFloat:=doublevalue;
  2454. writeln([doublevalue]);
  2455. end
  2456. else if entryleft=sizeof(single) then
  2457. begin
  2458. singlevalue:=getrealsize(sizeof(single));
  2459. constdef.VFloat:=singlevalue;
  2460. writeln([singlevalue]);
  2461. end
  2462. else if entryleft=10 then
  2463. begin
  2464. getdata(extended,entryleft);
  2465. ss:=Real80bitToStr(extended);
  2466. constdef.VFloat:=StrToFloat(ss);
  2467. writeln(ss);
  2468. end
  2469. else
  2470. begin
  2471. realvalue:=0.0;
  2472. WriteError('Error reading real value');
  2473. end;
  2474. end;
  2475. constset :
  2476. begin
  2477. constdef.ConstType:=ctSet;
  2478. write ([space,' Set Type : ']);
  2479. readderef('',constdef.TypeRef);
  2480. for i:=1to 4 do
  2481. begin
  2482. write ([space,' Value : ']);
  2483. for j:=1to 8 do
  2484. begin
  2485. if j>1 then
  2486. write(',');
  2487. b:=getbyte;
  2488. write(hexstr(b,2));
  2489. constdef.VSet[i*j-1]:=b;
  2490. end;
  2491. writeln;
  2492. end;
  2493. end;
  2494. constnil:
  2495. begin
  2496. write([space,' NIL pointer :']);
  2497. readderef('',constdef.TypeRef);
  2498. constdef.ConstType:=ctPtr;
  2499. constdef.VInt:=0;
  2500. end;
  2501. constwstring :
  2502. begin
  2503. initwidestring(pw);
  2504. setlengthwidestring(pw,getlongint);
  2505. if widecharsize=2 then
  2506. { don't use getdata, because the compilerwidechars may have to
  2507. be byteswapped
  2508. }
  2509. begin
  2510. for i:=0 to pw^.len-1 do
  2511. pw^.data[i]:=ppufile.getword;
  2512. SetString(ws, PWideChar(pw^.data), pw^.len);
  2513. constdef.VStr:=UTF8Encode(ws);
  2514. constdef.ConstType:=ctStr;
  2515. end
  2516. else if widecharsize=4 then
  2517. begin
  2518. for i:=0 to pw^.len-1 do
  2519. pw^.data[i]:=cardinal(ppufile.getlongint);
  2520. end
  2521. else
  2522. begin
  2523. WriteError('Unsupported tcompilerwidechar size');
  2524. end;
  2525. Write([space,'Wide string type']);
  2526. startnewline:=true;
  2527. for i:=0 to pw^.len-1 do
  2528. begin
  2529. if startnewline then
  2530. begin
  2531. writeln;
  2532. write(space);
  2533. startnewline:=false;
  2534. end;
  2535. ch:=pw^.data[i];
  2536. if widecharsize=2 then
  2537. write(hexstr(ch,4))
  2538. else
  2539. write(hexstr(ch,8));
  2540. if ((i + 1) mod 8)= 0 then
  2541. startnewline:=true
  2542. else
  2543. if i <> pw^.len-1 then
  2544. write(', ');
  2545. end;
  2546. donewidestring(pw);
  2547. Writeln;
  2548. end;
  2549. constguid:
  2550. begin
  2551. write ([space,' IntfType : ']);
  2552. readderef('',constdef.TypeRef);
  2553. getdata(guid,sizeof(guid));
  2554. write ([space,' IID String: {',hexstr(guid.d1,8),'-',hexstr(guid.d2,4),'-',hexstr(guid.d3,4),'-']);
  2555. for i:=0 to 7 do
  2556. begin
  2557. write(hexstr(guid.d4[i],2));
  2558. if i=1 then write('-');
  2559. end;
  2560. writeln('}');
  2561. end
  2562. else
  2563. Writeln (['!! Invalid unit format : Invalid const type encountered: ',b]);
  2564. end;
  2565. end;
  2566. ibabsolutevarsym :
  2567. begin
  2568. def:=TPpuVarDef.Create(ParentDef);
  2569. readabstractvarsym('Absolute variable symbol ',varoptions,TPpuVarDef(def));
  2570. Write ([space,' Relocated to ']);
  2571. b:=getbyte;
  2572. case absolutetyp(b) of
  2573. tovar :
  2574. readpropaccesslist(space+' Sym : ');
  2575. toasm :
  2576. Writeln(['Assembler name : ',getstring]);
  2577. toaddr :
  2578. begin
  2579. Write(['Address : ',getaword]);
  2580. if tsystemcpu(ppufile.header.common.cpu)=cpu_i386 then
  2581. Write([' (Far: ',getbyte<>0,')']);
  2582. if tsystemcpu(ppufile.header.common.cpu)=cpu_i8086 then
  2583. if getbyte<>0 then
  2584. Write([' (Far: TRUE, Segment=',getaword,')'])
  2585. else
  2586. Write([' (Far: FALSE)']);
  2587. Writeln;
  2588. end;
  2589. else
  2590. Writeln (['!! Invalid unit format : Invalid absolute type encountered: ',b]);
  2591. end;
  2592. end;
  2593. ibfieldvarsym :
  2594. begin
  2595. def:=TPpuFieldDef.Create(ParentDef);
  2596. readabstractvarsym('Field Variable symbol ',varoptions,TPpuVarDef(def));
  2597. writeln([space,' Address : ',getaint]);
  2598. if vo_has_mangledname in varoptions then
  2599. writeln([space,' Mangled name : ',getstring]);
  2600. end;
  2601. ibstaticvarsym :
  2602. begin
  2603. def:=TPpuVarDef.Create(ParentDef);
  2604. readabstractvarsym('Global Variable symbol ',varoptions,TPpuVarDef(def));
  2605. write ([space,' DefaultConst : ']);
  2606. readderef('');
  2607. if (vo_has_mangledname in varoptions) then
  2608. if tsystemcpu(ppufile.header.common.cpu)=cpu_jvm then
  2609. writeln([space,'AMangledname : ',getansistring])
  2610. else
  2611. writeln([space,'SMangledname : ',getstring]);
  2612. if vo_has_section in varoptions then
  2613. writeln(['Section name:',ppufile.getansistring]);
  2614. write ([space,' FieldVarSymDeref: ']);
  2615. readderef('');
  2616. end;
  2617. iblocalvarsym :
  2618. begin
  2619. readabstractvarsym('Local Variable symbol ',varoptions);
  2620. write ([space,' DefaultConst : ']);
  2621. readderef('');
  2622. end;
  2623. ibparavarsym :
  2624. begin
  2625. def:=TPpuParamDef.Create(ParentDef);
  2626. readabstractvarsym('Parameter Variable symbol ',varoptions,TPpuVarDef(def));
  2627. write ([space,' DefaultConst : ']);
  2628. readderef('',TPpuParamDef(def).DefaultValue);
  2629. writeln([space,' ParaNr : ',getword]);
  2630. writeln([space,' Univ : ',boolean(getbyte)]);
  2631. writeln([space,' VarState : ',getbyte]);
  2632. writeln([space,' Refs : ',getbyte]);
  2633. if (vo_has_explicit_paraloc in varoptions) then
  2634. begin
  2635. readcgpara(space+' ');
  2636. end;
  2637. end;
  2638. ibenumsym :
  2639. begin
  2640. def:=TPpuConstDef.Create(nil);
  2641. readcommonsym('Enumeration symbol ',def);
  2642. write ([space,' Definition : ']);
  2643. readderef('');
  2644. TPpuConstDef(def).ConstType:=ctInt;
  2645. TPpuConstDef(def).VInt:=getlongint;
  2646. writeln([space,' Value : ',TPpuConstDef(def).VInt]);
  2647. if (ParentDef <> nil) and (ParentDef.DefType = dtEnum) then
  2648. def.Parent:=ParentDef;
  2649. end;
  2650. ibsyssym :
  2651. begin
  2652. readcommonsym('Internal system symbol ');
  2653. writeln([space,' Internal Nr : ',getlongint]);
  2654. end;
  2655. ibmacrosym :
  2656. begin
  2657. readcommonsym('Macro symbol ');
  2658. writeln([space,' Defined: ',boolean(getbyte)]);
  2659. writeln([space,' Compiler var: ',boolean(getbyte)]);
  2660. len:=getlongint;
  2661. writeln([space,' Value length: ',len]);
  2662. if len > 0 then
  2663. begin
  2664. getmem(pc,len+1);
  2665. getdata(pc^,len);
  2666. (pc+len)^:= #0;
  2667. writeln([space,' Value: "',pc,'"']);
  2668. freemem(pc,len+1);
  2669. end;
  2670. end;
  2671. ibpropertysym :
  2672. begin
  2673. def:=TPpuPropDef.Create(ParentDef);
  2674. readcommonsym('Property ',def);
  2675. propoptions:=readpropertyoptions;
  2676. if ppo_overrides in propoptions then
  2677. begin
  2678. write ([space,' OverrideProp : ']);
  2679. readderef('');
  2680. end;
  2681. if ppo_defaultproperty in propoptions then
  2682. Include(TPpuPropDef(def).Options, poDefault);
  2683. write ([space,' Prop Type : ']);
  2684. readderef('',TPpuPropDef(def).PropType);
  2685. writeln([space,' Index : ',getlongint]);
  2686. writeln([space,' Default : ',getlongint]);
  2687. write ([space,' Index Type : ']);
  2688. readderef('');
  2689. { palt_none }
  2690. readpropaccesslist('');
  2691. write ([space,' Readaccess : ']);
  2692. readpropaccesslist(space+' Sym: ',TPpuPropDef(def).Getter);
  2693. write ([space,' Writeaccess : ']);
  2694. readpropaccesslist(space+' Sym: ',TPpuPropDef(def).Setter);
  2695. write ([space,' Storedaccess : ']);
  2696. readpropaccesslist(space+' Sym: ');
  2697. if [ppo_hasparameters,ppo_overrides]*propoptions=[ppo_hasparameters] then
  2698. begin
  2699. space:=' '+space;
  2700. readsymtable('parast',TPpuPropDef(def));
  2701. delete(space,1,4);
  2702. end;
  2703. end;
  2704. iberror :
  2705. begin
  2706. WriteError('!! Error in PPU');
  2707. exit;
  2708. end;
  2709. ibendsyms :
  2710. break;
  2711. else
  2712. begin
  2713. WriteError('!! Skipping unsupported PPU Entry in Symbols: '+IntToStr(b));
  2714. end;
  2715. end;
  2716. if (def <> nil) and (def.Parent = nil) then
  2717. def.Free;
  2718. if not EndOfEntry then
  2719. HasMoreInfos;
  2720. until false;
  2721. end;
  2722. end;
  2723. {****************************************************************************
  2724. Read defintions Part
  2725. ****************************************************************************}
  2726. procedure readdefinitions(const s:string; ParentDef: TPpuContainerDef);
  2727. { type tordtype is in symconst unit }
  2728. {
  2729. uvoid,
  2730. u8bit,u16bit,u32bit,u64bit,u128bit,
  2731. s8bit,s16bit,s32bit,s64bit,s128bit,
  2732. bool8bit,bool16bit,bool32bit,bool64bit,
  2733. uchar,uwidechar,scurrency
  2734. ); }
  2735. { type tobjecttyp is in symconst unit }
  2736. { type tvarianttype is in symconst unit }
  2737. var
  2738. b : byte;
  2739. l,j,tokenbufsize : longint;
  2740. tokenbuf : pbyte;
  2741. calloption : tproccalloption;
  2742. procoptions : tprocoptions;
  2743. implprocoptions: timplprocoptions;
  2744. defoptions: tdefoptions;
  2745. iexpr: Tconstexprint;
  2746. def: TPpuDef;
  2747. objdef: TPpuObjectDef absolute def;
  2748. arrdef: TPpuArrayDef absolute def;
  2749. enumdef: TPpuEnumDef absolute def;
  2750. setdef: TPpuSetDef absolute def;
  2751. orddef: TPpuOrdDef absolute def;
  2752. floatdef: TPpuFloatDef absolute def;
  2753. strdef: TPpuStringDef absolute def;
  2754. filedef: TPpuFileDef absolute def;
  2755. begin
  2756. with ppufile do
  2757. begin
  2758. if space<>'' then
  2759. Writeln([space,'------ ',s,' ------']);
  2760. if readentry<>ibstartdefs then
  2761. Writeln('!! ibstartdefs not found');
  2762. repeat
  2763. def:=nil;
  2764. b:=readentry;
  2765. case b of
  2766. ibpointerdef :
  2767. begin
  2768. def:=TPpuPointerDef.Create(ParentDef);
  2769. readcommondef('Pointer definition',defoptions,def);
  2770. write ([space,' Pointed Type : ']);
  2771. readderef('',TPpuPointerDef(def).Ptr);
  2772. writeln([space,' Has Pointer Math : ',(getbyte<>0)]);
  2773. if tsystemcpu(ppufile.header.common.cpu) in [cpu_i8086,cpu_i386,cpu_x86_64] then
  2774. begin
  2775. write([space,' X86 Pointer Type : ']);
  2776. b:=getbyte;
  2777. case tx86pointertyp(b) of
  2778. x86pt_near: writeln('Near');
  2779. x86pt_near_cs: writeln('Near ''CS''');
  2780. x86pt_near_ds: writeln('Near ''DS''');
  2781. x86pt_near_ss: writeln('Near ''SS''');
  2782. x86pt_near_es: writeln('Near ''ES''');
  2783. x86pt_near_fs: writeln('Near ''FS''');
  2784. x86pt_near_gs: writeln('Near ''GS''');
  2785. x86pt_far: writeln('Far');
  2786. x86pt_huge: writeln('Huge');
  2787. else
  2788. WriteWarning('Invalid x86 pointer type: ' + IntToStr(b));
  2789. end;
  2790. end;
  2791. end;
  2792. iborddef :
  2793. begin
  2794. orddef:=TPpuOrdDef.Create(ParentDef);
  2795. readcommondef('Ordinal definition',defoptions,orddef);
  2796. write ([space,' Base type : ']);
  2797. b:=getbyte;
  2798. case tordtype(b) of
  2799. uvoid:
  2800. begin
  2801. writeln('uvoid');
  2802. orddef.OrdType:=otVoid;
  2803. end;
  2804. u8bit:
  2805. begin
  2806. writeln('u8bit');
  2807. orddef.OrdType:=otUInt;
  2808. orddef.Size:=1;
  2809. end;
  2810. u16bit:
  2811. begin
  2812. writeln('u16bit');
  2813. orddef.OrdType:=otUInt;
  2814. orddef.Size:=2;
  2815. end;
  2816. u32bit:
  2817. begin
  2818. writeln('u32bit');
  2819. orddef.OrdType:=otUInt;
  2820. orddef.Size:=4;
  2821. end;
  2822. u64bit:
  2823. begin
  2824. writeln('u64bit');
  2825. orddef.OrdType:=otUInt;
  2826. orddef.Size:=8;
  2827. end;
  2828. u128bit:
  2829. begin
  2830. writeln('u128bit');
  2831. orddef.OrdType:=otUInt;
  2832. orddef.Size:=16;
  2833. end;
  2834. s8bit:
  2835. begin
  2836. writeln('s8bit');
  2837. orddef.OrdType:=otSInt;
  2838. orddef.Size:=1;
  2839. end;
  2840. s16bit:
  2841. begin
  2842. writeln('s16bit');
  2843. orddef.OrdType:=otSInt;
  2844. orddef.Size:=2;
  2845. end;
  2846. s32bit:
  2847. begin
  2848. writeln('s32bit');
  2849. orddef.OrdType:=otSInt;
  2850. orddef.Size:=4;
  2851. end;
  2852. s64bit:
  2853. begin
  2854. writeln('s64bit');
  2855. orddef.OrdType:=otSInt;
  2856. orddef.Size:=8;
  2857. end;
  2858. s128bit:
  2859. begin
  2860. writeln('s128bit');
  2861. orddef.OrdType:=otSInt;
  2862. orddef.Size:=16;
  2863. end;
  2864. pasbool8:
  2865. begin
  2866. writeln('pasbool8');
  2867. orddef.OrdType:=otPasBool;
  2868. orddef.Size:=1;
  2869. end;
  2870. pasbool16:
  2871. begin
  2872. writeln('pasbool16');
  2873. orddef.OrdType:=otPasBool;
  2874. orddef.Size:=2;
  2875. end;
  2876. pasbool32:
  2877. begin
  2878. writeln('pasbool32');
  2879. orddef.OrdType:=otPasBool;
  2880. orddef.Size:=4;
  2881. end;
  2882. pasbool64:
  2883. begin
  2884. writeln('pasbool64');
  2885. orddef.OrdType:=otPasBool;
  2886. orddef.Size:=8;
  2887. end;
  2888. bool8bit:
  2889. begin
  2890. writeln('bool8bit');
  2891. orddef.OrdType:=otBool;
  2892. orddef.Size:=1;
  2893. end;
  2894. bool16bit:
  2895. begin
  2896. writeln('bool16bit');
  2897. orddef.OrdType:=otBool;
  2898. orddef.Size:=2;
  2899. end;
  2900. bool32bit:
  2901. begin
  2902. writeln('bool32bit');
  2903. orddef.OrdType:=otBool;
  2904. orddef.Size:=4;
  2905. end;
  2906. bool64bit:
  2907. begin
  2908. writeln('bool64bit');
  2909. orddef.OrdType:=otBool;
  2910. orddef.Size:=8;
  2911. end;
  2912. uchar:
  2913. begin
  2914. writeln('uchar');
  2915. orddef.OrdType:=otChar;
  2916. orddef.Size:=1;
  2917. end;
  2918. uwidechar:
  2919. begin
  2920. writeln('uwidechar');
  2921. orddef.OrdType:=otChar;
  2922. orddef.Size:=2;
  2923. end;
  2924. scurrency:
  2925. begin
  2926. writeln('scurrency');
  2927. orddef.OrdType:=otCurrency;
  2928. orddef.Size:=8;
  2929. end;
  2930. else
  2931. WriteWarning('Invalid base type: ' + IntToStr(b));
  2932. end;
  2933. iexpr:=getexprint;
  2934. orddef.RangeLow:=iexpr.svalue;
  2935. write([space,' Range : ',constexp.tostr(iexpr)]);
  2936. iexpr:=getexprint;
  2937. orddef.RangeHigh:=iexpr.svalue;
  2938. writeln([' to ',constexp.tostr(iexpr)]);
  2939. end;
  2940. ibfloatdef :
  2941. begin
  2942. floatdef:=TPpuFloatDef.Create(ParentDef);
  2943. readcommondef('Float definition',defoptions,floatdef);
  2944. write ([space,' Float type : ']);
  2945. b:=getbyte;
  2946. case b of
  2947. ftSingle:
  2948. begin
  2949. writeln('Single');
  2950. floatdef.FloatType:=pftSingle;
  2951. end;
  2952. ftDouble:
  2953. begin
  2954. writeln('Double');
  2955. floatdef.FloatType:=pftDouble;
  2956. end;
  2957. ftExtended:
  2958. begin
  2959. writeln('Extended');
  2960. floatdef.FloatType:=pftExtended;
  2961. end;
  2962. ftComp:
  2963. begin
  2964. writeln('Comp');
  2965. floatdef.FloatType:=pftComp;
  2966. end;
  2967. ftCurr:
  2968. begin
  2969. writeln('Currency');
  2970. floatdef.FloatType:=pftCurrency;
  2971. end;
  2972. ftFloat128:
  2973. begin
  2974. writeln('Float128');
  2975. floatdef.FloatType:=pftFloat128;
  2976. end;
  2977. else
  2978. WriteWarning('Invalid float type: ' + IntToStr(b));
  2979. end;
  2980. end;
  2981. ibarraydef :
  2982. begin
  2983. arrdef:=TPpuArrayDef.Create(ParentDef);
  2984. readcommondef('Array definition',defoptions,arrdef);
  2985. write ([space,' Element type : ']);
  2986. readderef('',arrdef.ElType);
  2987. write ([space,' Range Type : ']);
  2988. readderef('',arrdef.RangeType);
  2989. arrdef.RangeLow:=getasizeint;
  2990. arrdef.RangeHigh:=getasizeint;
  2991. writeln([space,' Range : ',arrdef.RangeLow,' to ',arrdef.RangeHigh]);
  2992. write ([space,' Options : ']);
  2993. readarraydefoptions(arrdef);
  2994. if tsystemcpu(ppufile.header.common.cpu)=cpu_i8086 then
  2995. writeln([space,' Huge : ',(getbyte<>0)]);
  2996. readsymtable('symbols', arrdef);
  2997. end;
  2998. ibprocdef :
  2999. begin
  3000. def:=TPpuProcDef.Create(ParentDef);
  3001. readcommondef('Procedure definition',defoptions,def);
  3002. read_abstract_proc_def(calloption,procoptions,TPpuProcDef(def));
  3003. if (po_has_mangledname in procoptions) then
  3004. if tsystemcpu(ppufile.header.common.cpu)=cpu_jvm then
  3005. writeln([space,' Mangled name : ',getansistring])
  3006. else
  3007. writeln([space,' Mangled name : ',getstring]);
  3008. writeln([space,' Number : ',getword]);
  3009. writeln([space,' Level : ',getbyte]);
  3010. write ([space,' Class : ']);
  3011. readderef('');
  3012. write ([space,' Procsym : ']);
  3013. readderef('', def.Ref);
  3014. write ([space,' File Pos : ']);
  3015. readposinfo(def);
  3016. write ([space,' Visibility : ']);
  3017. readvisibility(def);
  3018. write ([space,' SymOptions : ']);
  3019. readsymoptions(space+' ');
  3020. if (po_has_importdll in procoptions) then
  3021. writeln([space,' Import DLL : ',getstring]);
  3022. if (po_has_importname in procoptions) then
  3023. writeln([space,' Import Name : ',getstring]);
  3024. writeln([space,' Import Nr : ',getword]);
  3025. if (po_msgint in procoptions) then
  3026. writeln([space,' MsgInt : ',getlongint]);
  3027. if (po_msgstr in procoptions) then
  3028. writeln([space,' MsgStr : ',getstring]);
  3029. if (po_dispid in procoptions) then
  3030. writeln([space,' DispID: ',ppufile.getlongint]);
  3031. readprocimploptions(space,implprocoptions);
  3032. if (pio_has_inlininginfo in implprocoptions) then
  3033. begin
  3034. write ([space,' FuncretSym : ']);
  3035. readderef('');
  3036. readprocinfooptions(space);
  3037. end;
  3038. b:=ppufile.getbyte;
  3039. if b<>0 then
  3040. begin
  3041. write ([space,' Alias names : ']);
  3042. for j:=1 to b do
  3043. begin
  3044. write(ppufile.getstring);
  3045. if j<b then
  3046. write(', ');
  3047. end;
  3048. writeln;
  3049. end;
  3050. tokenbufsize:=ppufile.getlongint;
  3051. if tokenbufsize<>0 then
  3052. begin
  3053. write ([space,' Declaration token buffer : TODO']);
  3054. tokenbuf:=allocmem(tokenbufsize);
  3055. ppufile.getdata(tokenbuf^,tokenbufsize);
  3056. freemem(tokenbuf);
  3057. end;
  3058. if po_syscall_has_libsym in procoptions then
  3059. begin
  3060. { library symbol for AmigaOS/MorphOS/AROS }
  3061. write ([space,' Library symbol : ']);
  3062. readderef('');
  3063. end;
  3064. if not EndOfEntry then
  3065. HasMoreInfos;
  3066. space:=' '+space;
  3067. { parast }
  3068. readsymtable('parast', TPpuProcDef(def));
  3069. { localst }
  3070. if (pio_has_inlininginfo in implprocoptions) then
  3071. readsymtable('localst');
  3072. if (pio_has_inlininginfo in implprocoptions) then
  3073. readnodetree;
  3074. delete(space,1,4);
  3075. end;
  3076. ibprocvardef :
  3077. begin
  3078. def:=TPpuProcTypeDef.Create(ParentDef);
  3079. readcommondef('Procedural type (ProcVar) definition',defoptions,def);
  3080. read_abstract_proc_def(calloption,procoptions, TPpuProcDef(def));
  3081. writeln([space,' Symtable level :',ppufile.getbyte]);
  3082. if not EndOfEntry then
  3083. HasMoreInfos;
  3084. space:=' '+space;
  3085. { parast }
  3086. readsymtable('parast',TPpuProcDef(def));
  3087. delete(space,1,4);
  3088. if tsystemcpu(ppufile.header.common.cpu)=cpu_jvm then
  3089. readderef('');
  3090. end;
  3091. ibshortstringdef :
  3092. begin
  3093. strdef:=TPpuStringDef.Create(ParentDef);
  3094. strdef.StrType:=stShort;
  3095. readcommondef('ShortString definition',defoptions,strdef);
  3096. strdef.Len:=getbyte;
  3097. writeln([space,' Length : ',strdef.Len]);
  3098. end;
  3099. ibwidestringdef :
  3100. begin
  3101. strdef:=TPpuStringDef.Create(ParentDef);
  3102. strdef.StrType:=stWide;
  3103. readcommondef('WideString definition',defoptions,strdef);
  3104. strdef.Len:=getaint;
  3105. writeln([space,' Length : ',strdef.Len]);
  3106. end;
  3107. ibunicodestringdef :
  3108. begin
  3109. strdef:=TPpuStringDef.Create(ParentDef);
  3110. strdef.StrType:=stUnicode;
  3111. readcommondef('UnicodeString definition',defoptions,strdef);
  3112. strdef.Len:=getaint;
  3113. writeln([space,' Length : ',strdef.Len]);
  3114. writeln([space,' Encoding : ',getword]);
  3115. end;
  3116. ibansistringdef :
  3117. begin
  3118. strdef:=TPpuStringDef.Create(ParentDef);
  3119. strdef.StrType:=stAnsi;
  3120. readcommondef('AnsiString definition',defoptions,strdef);
  3121. strdef.Len:=getaint;
  3122. writeln([space,' Length : ',strdef.Len]);
  3123. writeln([space,' Encoding : ',getword]);
  3124. end;
  3125. iblongstringdef :
  3126. begin
  3127. strdef:=TPpuStringDef.Create(ParentDef);
  3128. strdef.StrType:=stLong;
  3129. readcommondef('Longstring definition',defoptions,strdef);
  3130. strdef.Len:=getaint;
  3131. writeln([space,' Length : ',strdef.Len]);
  3132. end;
  3133. ibrecorddef :
  3134. begin
  3135. objdef:=TPpuRecordDef.Create(ParentDef);
  3136. readcommondef('Record definition',defoptions, objdef);
  3137. def.Name:=getstring;
  3138. writeln([space,' Name of Record : ',objdef.Name]);
  3139. writeln([space,' Import lib/pkg : ',getstring]);
  3140. write ([space,' Options : ']);
  3141. readobjectdefoptions(objdef);
  3142. if (df_copied_def in defoptions) then
  3143. begin
  3144. Include(TPpuRecordDef(def).Options, ooCopied);
  3145. write([space,' Copied from : ']);
  3146. readderef('',objdef.Ancestor);
  3147. end
  3148. else
  3149. begin
  3150. writeln([space,' FieldAlign : ',shortint(getbyte)]);
  3151. writeln([space,' RecordAlign : ',shortint(getbyte)]);
  3152. writeln([space,' PadAlign : ',shortint(getbyte)]);
  3153. writeln([space,'UseFieldAlignment : ',shortint(getbyte)]);
  3154. writeln([space,' RecordAlignMin : ',shortint(getbyte)]);
  3155. objdef.Size:=getasizeint;
  3156. writeln([space,' DataSize : ',objdef.Size]);
  3157. writeln([space,' PaddingSize : ',getword]);
  3158. readmanagementoperatoroptions(space);
  3159. end;
  3160. if not EndOfEntry then
  3161. HasMoreInfos;
  3162. {read the record definitions and symbols}
  3163. if not(df_copied_def in current_defoptions) then
  3164. begin
  3165. space:=' '+space;
  3166. readrecsymtableoptions;
  3167. readsymtable('fields',TPpuRecordDef(def));
  3168. Delete(space,1,4);
  3169. end;
  3170. end;
  3171. ibobjectdef :
  3172. begin
  3173. objdef:=TPpuObjectDef.Create(ParentDef);
  3174. readcommondef('Object/Class definition',defoptions,objdef);
  3175. objdef.Name:=getstring;
  3176. writeln([space,' Name of Class : ',objdef.Name]);
  3177. writeln([space,' Import lib/pkg : ',getstring]);
  3178. write ([space,' Options : ']);
  3179. readobjectdefoptions(objdef);
  3180. b:=getbyte;
  3181. write ([space,' Type : ']);
  3182. case tobjecttyp(b) of
  3183. odt_class : writeln('class');
  3184. odt_object : writeln('object');
  3185. odt_interfacecom : writeln('interfacecom');
  3186. odt_interfacecorba : writeln('interfacecorba');
  3187. odt_cppclass : writeln('cppclass');
  3188. odt_dispinterface : writeln('dispinterface');
  3189. odt_objcclass : writeln('objcclass');
  3190. odt_objcprotocol : writeln('objcprotocol');
  3191. odt_helper : writeln('helper');
  3192. odt_objccategory : writeln('objccategory');
  3193. odt_javaclass : writeln('Java class');
  3194. odt_interfacejava : writeln('Java interface');
  3195. else WriteWarning('Invalid object type: ' + IntToStr(b));
  3196. end;
  3197. case tobjecttyp(b) of
  3198. odt_class, odt_cppclass, odt_objcclass, odt_javaclass:
  3199. objdef.ObjType:=otClass;
  3200. odt_object:
  3201. objdef.ObjType:=otObject;
  3202. odt_interfacecom, odt_interfacecorba, odt_interfacejava, odt_dispinterface:
  3203. objdef.ObjType:=otInterface;
  3204. odt_helper:
  3205. objdef.ObjType:=otHelper;
  3206. end;
  3207. writeln([space,' External name : ',getstring]);
  3208. objdef.Size:=getasizeint;
  3209. writeln([space,' DataSize : ',objdef.Size]);
  3210. writeln([space,' PaddingSize : ',getword]);
  3211. writeln([space,' FieldAlign : ',shortint(getbyte)]);
  3212. writeln([space,' RecordAlign : ',shortint(getbyte)]);
  3213. writeln([space,' RecordAlignMin : ',shortint(getbyte)]);
  3214. write ([space, ' VmtField : ']);
  3215. readderef('',nil);
  3216. write ([space, ' Ancestor Class : ']);
  3217. readderef('',objdef.Ancestor);
  3218. if tobjecttyp(b) in [odt_interfacecom,odt_interfacecorba,odt_dispinterface] then
  3219. begin
  3220. { IIDGUID }
  3221. for j:=1to 16 do
  3222. getbyte;
  3223. objdef.IID:=getstring;
  3224. writeln([space,' IID String : ',objdef.IID]);
  3225. end;
  3226. l:=getlongint;
  3227. if l > 0 then
  3228. objdef.Options:=objdef.Options + [ooAbstractMethods];
  3229. writeln([space,' Abstract methods : ',l]);
  3230. if tobjecttyp(b)=odt_helper then
  3231. begin
  3232. write([space,' Helper parent : ']);
  3233. readderef('',objdef.HelperParent);
  3234. end;
  3235. l:=getlongint;
  3236. writeln([space,' VMT entries: ',l]);
  3237. for j:=1 to l do
  3238. begin
  3239. write([space,' ']);
  3240. readderef('');
  3241. write([space,' Visibility: ']);
  3242. readvisibility;
  3243. end;
  3244. if tobjecttyp(b) in [odt_class,odt_objcclass,odt_objcprotocol,odt_javaclass,odt_interfacejava] then
  3245. begin
  3246. l:=getlongint;
  3247. writeln([space,' Impl Intf Count : ',l]);
  3248. for j:=1 to l do
  3249. begin
  3250. write ([space,' - Definition : ']);
  3251. readderef('');
  3252. write ([space,' - Getter Def : ']);
  3253. readderef('');
  3254. writeln([space,' IOffset : ',getlongint]);
  3255. writeln([space,' Entry type : ',IntfEntryType2Str(getbyte)]);
  3256. end;
  3257. end;
  3258. if df_copied_def in current_defoptions then
  3259. begin
  3260. Include(objdef.Options, ooCopied);
  3261. writeln(' Copy of def: ');
  3262. readderef('',objdef.Ancestor);
  3263. end;
  3264. if not EndOfEntry then
  3265. HasMoreInfos;
  3266. if not(df_copied_def in current_defoptions) then
  3267. begin
  3268. {read the record definitions and symbols}
  3269. space:=' '+space;
  3270. readrecsymtableoptions;
  3271. readsymtable('fields',objdef);
  3272. Delete(space,1,4);
  3273. end;
  3274. end;
  3275. ibfiledef :
  3276. begin
  3277. filedef:=TPpuFileDef.Create(ParentDef);
  3278. ReadCommonDef('File definition',defoptions,filedef);
  3279. write ([space,' Type : ']);
  3280. case getbyte of
  3281. 0 : begin
  3282. writeln('Text');
  3283. filedef.FileType:=ftText;
  3284. end;
  3285. 1 : begin
  3286. writeln('Typed');
  3287. filedef.FileType:=ftTyped;
  3288. write ([space,' File of Type : ']);
  3289. readderef('',filedef.TypeRef);
  3290. end;
  3291. 2 : begin
  3292. writeln('Untyped');
  3293. filedef.FileType:=ftUntyped;
  3294. end;
  3295. end;
  3296. end;
  3297. ibformaldef :
  3298. begin
  3299. def:=TPpuFormalDef.Create(ParentDef);
  3300. readcommondef('Generic definition (void-typ)',defoptions,def);
  3301. TPpuFormalDef(def).IsTyped:=(getbyte<>0);
  3302. writeln([space,' Is Typed : ',TPpuFormalDef(def).IsTyped]);
  3303. end;
  3304. ibundefineddef :
  3305. begin
  3306. def:=TPpuUndefinedDef.Create(ParentDef);
  3307. readcommondef('Undefined definition (generic parameter)',defoptions,def);
  3308. end;
  3309. ibenumdef :
  3310. begin
  3311. enumdef:=TPpuEnumDef.Create(ParentDef);
  3312. readcommondef('Enumeration type definition',defoptions,enumdef);
  3313. enumdef.ElLow:=getaint;
  3314. writeln([space,' Smallest element : ',enumdef.ElLow]);
  3315. enumdef.ElHigh:=getaint;
  3316. writeln([space,' Largest element : ',enumdef.ElHigh]);
  3317. enumdef.Size:=byte(getaint);
  3318. writeln([space,' Size : ',enumdef.Size]);
  3319. if df_copied_def in defoptions then
  3320. begin
  3321. write([space,'Base enumeration type : ']);
  3322. readderef('',enumdef.CopyFrom);
  3323. end
  3324. else
  3325. begin
  3326. space:=' '+space;
  3327. readsymtable('elements',enumdef);
  3328. delete(space,1,4);
  3329. end;
  3330. if tsystemcpu(ppufile.header.common.cpu)=cpu_jvm then
  3331. begin
  3332. write([space,' Class def : ']);
  3333. readderef('');
  3334. end;
  3335. end;
  3336. ibclassrefdef :
  3337. begin
  3338. def:=TPpuClassRefDef.Create(ParentDef);
  3339. readcommondef('Class reference definition',defoptions,def);
  3340. write ([space,' Pointed Type : ']);
  3341. readderef('',TPpuClassRefDef(def).ClassRef);
  3342. end;
  3343. ibsetdef :
  3344. begin
  3345. setdef:=TPpuSetDef.Create(ParentDef);
  3346. readcommondef('Set definition',defoptions,setdef);
  3347. write ([space,' Element type : ']);
  3348. readderef('',setdef.ElType);
  3349. setdef.Size:=getasizeint;
  3350. writeln([space,' Size : ',setdef.Size]);
  3351. setdef.SetBase:=getasizeint;
  3352. writeln([space,' Set Base : ',setdef.SetBase]);
  3353. setdef.SetMax:=getasizeint;
  3354. writeln([space,' Set Max : ',setdef.SetMax]);
  3355. end;
  3356. ibvariantdef :
  3357. begin
  3358. def:=TPpuVariantDef.Create(ParentDef);
  3359. readcommondef('Variant definition',defoptions,def);
  3360. write ([space,' Varianttype : ']);
  3361. b:=getbyte;
  3362. case tvarianttype(b) of
  3363. vt_normalvariant :
  3364. writeln('Normal');
  3365. vt_olevariant :
  3366. begin
  3367. TPpuVariantDef(def).IsOLE:=True;
  3368. writeln('OLE');
  3369. end
  3370. else
  3371. WriteWarning('Invalid varianttype: ' + IntToStr(b));
  3372. end;
  3373. end;
  3374. iberror :
  3375. begin
  3376. WriteError('!! Error in PPU');
  3377. exit;
  3378. end;
  3379. ibenddefs :
  3380. break;
  3381. else
  3382. begin
  3383. WriteError('!! Skipping unsupported PPU Entry in definitions: '+IntToStr(b));
  3384. end;
  3385. end;
  3386. if (def <> nil) and (def.Parent = nil) then
  3387. def.Free;
  3388. if not EndOfEntry then
  3389. HasMoreInfos;
  3390. until false;
  3391. end;
  3392. end;
  3393. procedure readmoduleoptions(space : string);
  3394. type
  3395. { tmoduleoption type is in unit fmodule }
  3396. tmoduleoption = (mo_none,
  3397. mo_hint_deprecated,
  3398. mo_hint_platform,
  3399. mo_hint_library,
  3400. mo_hint_unimplemented,
  3401. mo_hint_experimental,
  3402. mo_has_deprecated_msg
  3403. );
  3404. tmoduleoptions = set of tmoduleoption;
  3405. tmoduleopt=record
  3406. mask : tmoduleoption;
  3407. str : string[30];
  3408. end;
  3409. const
  3410. moduleopts=ord(high(tmoduleoption));
  3411. moduleopt : array[1..moduleopts] of tmoduleopt=(
  3412. (mask:mo_hint_deprecated; str:'Hint Deprecated'),
  3413. (mask:mo_hint_platform; str:'Hint Platform'),
  3414. (mask:mo_hint_library; str:'Hint Library'),
  3415. (mask:mo_hint_unimplemented; str:'Hint Unimplemented'),
  3416. (mask:mo_hint_experimental; str:'Hint Experimental'),
  3417. (mask:mo_has_deprecated_msg; str:'Has Deprecated Message')
  3418. );
  3419. var
  3420. moduleoptions : tmoduleoptions;
  3421. i : longint;
  3422. first : boolean;
  3423. begin
  3424. ppufile.getsmallset(moduleoptions);
  3425. if moduleoptions<>[] then
  3426. begin
  3427. first:=true;
  3428. for i:=1to moduleopts do
  3429. if (moduleopt[i].mask in moduleoptions) then
  3430. begin
  3431. if first then
  3432. first:=false
  3433. else
  3434. write(', ');
  3435. write(moduleopt[i].str);
  3436. end;
  3437. end;
  3438. writeln;
  3439. if mo_has_deprecated_msg in moduleoptions then
  3440. writeln([space,'Deprecated : ', ppufile.getstring]);
  3441. end;
  3442. {****************************************************************************
  3443. Read General Part
  3444. ****************************************************************************}
  3445. procedure readinterface(silent : boolean);
  3446. var
  3447. b : byte;
  3448. sourcenumber, i : longint;
  3449. begin
  3450. with ppufile do
  3451. begin
  3452. repeat
  3453. b:=readentry;
  3454. case b of
  3455. ibmodulename :
  3456. begin
  3457. CurUnit.Name:=getstring;
  3458. if not silent then
  3459. Writeln(['Module Name: ',CurUnit.Name]);
  3460. end;
  3461. ibmoduleoptions:
  3462. if not silent then
  3463. readmoduleoptions(' ');
  3464. ibsourcefiles :
  3465. begin
  3466. sourcenumber:=1;
  3467. if not silent then
  3468. while not EndOfEntry do
  3469. begin
  3470. with TPpuSrcFile.Create(CurUnit.SourceFiles) do begin
  3471. Name:=getstring;
  3472. i:=getlongint;
  3473. if i >= 0 then
  3474. FileTime:=FileDateToDateTime(i);
  3475. Writeln(['Source file ',sourcenumber,' : ',Name,' ',filetimestring(i)]);
  3476. end;
  3477. inc(sourcenumber);
  3478. end;
  3479. end;
  3480. {$IFDEF MACRO_DIFF_HINT}
  3481. ibusedmacros :
  3482. begin
  3483. if not silent then
  3484. while not EndOfEntry do
  3485. begin
  3486. Write('Conditional ',getstring);
  3487. b:=getbyte;
  3488. if boolean(b)=true then
  3489. write(' defined at startup')
  3490. else
  3491. write(' not defined at startup');
  3492. b:=getbyte;
  3493. if boolean(b)=true then
  3494. writeln(' was used')
  3495. else
  3496. writeln;
  3497. end;
  3498. end;
  3499. {$ENDIF}
  3500. ibloadunit :
  3501. if not silent then
  3502. ReadLoadUnit;
  3503. iblinkunitofiles :
  3504. if not silent then
  3505. ReadLinkContainer('Link unit object file: ');
  3506. iblinkunitstaticlibs :
  3507. if not silent then
  3508. ReadLinkContainer('Link unit static lib: ');
  3509. iblinkunitsharedlibs :
  3510. if not silent then
  3511. ReadLinkContainer('Link unit shared lib: ');
  3512. iblinkotherofiles :
  3513. if not silent then
  3514. ReadLinkContainer('Link other object file: ');
  3515. iblinkotherstaticlibs :
  3516. if not silent then
  3517. ReadLinkContainer('Link other static lib: ');
  3518. iblinkothersharedlibs :
  3519. if not silent then
  3520. ReadLinkContainer('Link other shared lib: ');
  3521. iblinkotherframeworks:
  3522. if not silent then
  3523. ReadLinkContainer('Link framework: ');
  3524. ibmainname:
  3525. if not silent then
  3526. Writeln(['Specified main program symbol name: ',getstring]);
  3527. ibImportSymbols :
  3528. if not silent then
  3529. ReadImportSymbols;
  3530. ibderefdata :
  3531. ReadDerefData;
  3532. ibderefmap :
  3533. ReadDerefMap;
  3534. ibwpofile :
  3535. if not silent then
  3536. ReadWpoFileInfo;
  3537. ibresources :
  3538. if not silent then
  3539. ReadLinkContainer('Resource file: ');
  3540. iberror :
  3541. begin
  3542. WriteError('Error in PPU');
  3543. exit;
  3544. end;
  3545. ibendinterface :
  3546. break;
  3547. else
  3548. begin
  3549. WriteError('!! Skipping unsupported PPU Entry in General Part: '+IntToStr(b));
  3550. end;
  3551. end;
  3552. until false;
  3553. end;
  3554. end;
  3555. {****************************************************************************
  3556. Read Implementation Part
  3557. ****************************************************************************}
  3558. procedure readimplementation;
  3559. var
  3560. b : byte;
  3561. begin
  3562. with ppufile do
  3563. begin
  3564. repeat
  3565. b:=readentry;
  3566. case b of
  3567. ibasmsymbols :
  3568. ReadAsmSymbols;
  3569. ibloadunit :
  3570. ReadLoadUnit;
  3571. ibunitimportsyms :
  3572. ReadUnitImportSyms;
  3573. iberror :
  3574. begin
  3575. WriteError('Error in PPU');
  3576. exit;
  3577. end;
  3578. ibendimplementation :
  3579. break;
  3580. else
  3581. begin
  3582. WriteError('!! Skipping unsupported PPU Entry in Implementation: '+IntToStr(b));
  3583. end;
  3584. end;
  3585. until false;
  3586. end;
  3587. end;
  3588. procedure dofile (filename : string);
  3589. begin
  3590. { reset }
  3591. space:='';
  3592. { fix filename }
  3593. if pos('.',filename)=0 then
  3594. filename:=filename+'.ppu';
  3595. ppufile:=tppufile.create(filename);
  3596. if not ppufile.openfile then
  3597. begin
  3598. WriteError('IO-Error when opening : '+filename+', Skipping');
  3599. exit;
  3600. end;
  3601. { PPU File is open, check for PPU Id }
  3602. if not ppufile.CheckPPUID then
  3603. begin
  3604. WriteError(Filename+' : Not a valid PPU file, Skipping');
  3605. exit;
  3606. end;
  3607. { Check PPU Version }
  3608. ppuversion:=ppufile.getversion;
  3609. Writeln(['Analyzing ',filename,' (v',PPUVersion,')']);
  3610. if PPUVersion<16 then
  3611. begin
  3612. WriteError(Filename+' : Old PPU Formats (<v16) are not supported, Skipping');
  3613. exit;
  3614. end;
  3615. if not SkipVersionCheck and (PPUVersion <> CurrentPPUVersion) then
  3616. begin
  3617. WriteError(Format('Unsupported PPU version %d. Expecting PPU version %d.', [PPUVersion, CurrentPPUVersion]));
  3618. exit;
  3619. end;
  3620. CurUnit:=TPpuUnitDef.Create(UnitList);
  3621. CurUnit.Version:=ppuversion;
  3622. { Write PPU Header Information }
  3623. if (verbose and v_header)<>0 then
  3624. begin
  3625. Writeln;
  3626. Writeln('Header');
  3627. Writeln('-------');
  3628. with ppufile.header do
  3629. begin
  3630. Writeln(['Compiler version : ',ppufile.header.common.compiler shr 14,'.',
  3631. (ppufile.header.common.compiler shr 7) and $7f,'.',
  3632. ppufile.header.common.compiler and $7f]);
  3633. WriteLn(['Target processor : ',Cpu2Str(common.cpu)]);
  3634. WriteLn(['Target operating system : ',Target2Str(common.target)]);
  3635. Writeln(['Unit flags : ',PPUFlags2Str(common.flags)]);
  3636. Writeln(['FileSize (w/o header) : ',common.size]);
  3637. Writeln(['Checksum : ',hexstr(checksum,8)]);
  3638. Writeln(['Interface Checksum : ',hexstr(interface_checksum,8)]);
  3639. Writeln(['Indirect Checksum : ',hexstr(indirect_checksum,8)]);
  3640. Writeln(['Definitions stored : ',tostr(deflistsize)]);
  3641. Writeln(['Symbols stored : ',tostr(symlistsize)]);
  3642. end;
  3643. end;
  3644. with ppufile.header do
  3645. begin
  3646. CurUnit.Crc:=checksum;
  3647. CurUnit.IntfCrc:=interface_checksum;
  3648. CurUnit.TargetCPU:=Cpu2Str(common.cpu);
  3649. CurUnit.TargetOS:=Target2Str(common.target);
  3650. end;
  3651. {read the general stuff}
  3652. if (verbose and v_interface)<>0 then
  3653. begin
  3654. Writeln;
  3655. Writeln('Interface section');
  3656. Writeln('------------------');
  3657. readinterface(false);
  3658. end
  3659. { We need derefdata from Interface }
  3660. else if verbose and (v_defs or v_syms or v_implementation)<>0 then
  3661. readinterface(true)
  3662. else
  3663. ppufile.skipuntilentry(ibendinterface);
  3664. Writeln;
  3665. Writeln('Interface symtable');
  3666. Writeln('----------------------');
  3667. readsymtableoptions('interface');
  3668. {read the definitions}
  3669. if (verbose and v_defs)<>0 then
  3670. begin
  3671. Writeln;
  3672. Writeln('Interface definitions');
  3673. Writeln('----------------------');
  3674. readdefinitions('interface', CurUnit);
  3675. end
  3676. else
  3677. ppufile.skipuntilentry(ibenddefs);
  3678. {read the symbols}
  3679. if (verbose and v_syms)<>0 then
  3680. begin
  3681. Writeln;
  3682. Writeln('Interface Symbols');
  3683. Writeln('------------------');
  3684. readsymbols('interface',CurUnit);
  3685. end
  3686. else
  3687. ppufile.skipuntilentry(ibendsyms);
  3688. {read the macro symbols}
  3689. if (verbose and v_syms)<>0 then
  3690. begin
  3691. Writeln;
  3692. Writeln('Interface Macro Symbols');
  3693. Writeln('-----------------------');
  3694. end;
  3695. if ppufile.readentry<>ibexportedmacros then
  3696. begin
  3697. WriteError('!! Error in PPU');
  3698. exit;
  3699. end;
  3700. if boolean(ppufile.getbyte) then
  3701. begin
  3702. readsymtableoptions('interface macro');
  3703. {skip the definition section for macros (since they are never used) }
  3704. ppufile.skipuntilentry(ibenddefs);
  3705. {read the macro symbols}
  3706. if (verbose and v_syms)<>0 then
  3707. readsymbols('interface macro')
  3708. else
  3709. ppufile.skipuntilentry(ibendsyms);
  3710. end
  3711. else
  3712. Writeln('(no exported macros)');
  3713. {read the implementation stuff}
  3714. if (verbose and v_implementation)<>0 then
  3715. begin
  3716. Writeln;
  3717. Writeln('Implementation section');
  3718. Writeln('-----------------------');
  3719. readimplementation;
  3720. end
  3721. else
  3722. ppufile.skipuntilentry(ibendimplementation);
  3723. {read the static symtable}
  3724. Writeln;
  3725. Writeln('Implementation symtable');
  3726. Writeln('----------------------');
  3727. readsymtableoptions('implementation');
  3728. if (ppufile.header.common.flags and uf_local_symtable)<>0 then
  3729. begin
  3730. if (verbose and v_defs)<>0 then
  3731. begin
  3732. Writeln;
  3733. Writeln('Static definitions');
  3734. Writeln('----------------------');
  3735. readdefinitions('implementation', nil);
  3736. end
  3737. else
  3738. ppufile.skipuntilentry(ibenddefs);
  3739. {read the symbols}
  3740. if (verbose and v_syms)<>0 then
  3741. begin
  3742. Writeln;
  3743. Writeln('Static Symbols');
  3744. Writeln('------------------');
  3745. readsymbols('implementation');
  3746. end
  3747. else
  3748. ppufile.skipuntilentry(ibendsyms);
  3749. end;
  3750. ReadCreatedObjTypes;
  3751. FreeDerefdata;
  3752. {shutdown ppufile}
  3753. ppufile.closefile;
  3754. ppufile.free;
  3755. Writeln;
  3756. end;
  3757. procedure WriteLogo;
  3758. begin
  3759. writeln(Title+' Version '+version_string);
  3760. writeln(Copyright);
  3761. writeln;
  3762. end;
  3763. procedure help;
  3764. begin
  3765. WriteLogo;
  3766. writeln('usage: ppudump [options] <filename1> <filename2>...');
  3767. writeln;
  3768. writeln('[options] can be:');
  3769. writeln(' -F<format> Set output format to <format>');
  3770. writeln(' t - text format (default)');
  3771. writeln(' j - JSON format');
  3772. writeln(' x - XML format');
  3773. writeln(' -M Exit with ExitCode=2 if more information is available');
  3774. writeln(' -S Skip PPU version check. May lead to reading errors');
  3775. writeln(' -V<verbose> Set verbosity to <verbose>');
  3776. writeln(' H - Show header info');
  3777. writeln(' I - Show interface');
  3778. writeln(' M - Show implementation');
  3779. writeln(' S - Show interface symbols');
  3780. writeln(' D - Show interface definitions');
  3781. writeln(' A - Show all');
  3782. writeln(' -h, -? This helpscreen');
  3783. halt;
  3784. end;
  3785. var
  3786. startpara,
  3787. nrfile,i : longint;
  3788. para : string;
  3789. const
  3790. error_on_more : boolean = false;
  3791. begin
  3792. if paramcount<1 then
  3793. help;
  3794. { turn verbose on by default }
  3795. verbose:=v_all;
  3796. { read options }
  3797. startpara:=1;
  3798. while copy(paramstr(startpara),1,1)='-' do
  3799. begin
  3800. para:=paramstr(startpara);
  3801. case upcase(para[2]) of
  3802. 'F' : begin
  3803. FreeAndNil(pout);
  3804. if Length(para) > 2 then
  3805. case upcase(para[3]) of
  3806. 'T':
  3807. nostdout:=False;
  3808. 'J':
  3809. begin
  3810. nostdout:=True;
  3811. pout:=TPpuJsonOutput.Create(Output);
  3812. end;
  3813. 'X':
  3814. begin
  3815. nostdout:=True;
  3816. pout:=TPpuXmlOutput.Create(Output);
  3817. end;
  3818. else
  3819. begin
  3820. WriteError('Invalid output format: ' + para[3]);
  3821. Halt(1);
  3822. end;
  3823. end;
  3824. end;
  3825. 'M' : error_on_more:=true;
  3826. 'S' : SkipVersionCheck:=True;
  3827. 'V' : begin
  3828. verbose:=0;
  3829. for i:=3 to length(para) do
  3830. case upcase(para[i]) of
  3831. 'H' : verbose:=verbose or v_header;
  3832. 'I' : verbose:=verbose or v_interface;
  3833. 'M' : verbose:=verbose or v_implementation;
  3834. 'D' : verbose:=verbose or v_defs;
  3835. 'S' : verbose:=verbose or v_syms;
  3836. 'A' : verbose:=verbose or v_all;
  3837. end;
  3838. end;
  3839. 'H' : help;
  3840. '?' : help;
  3841. else
  3842. begin
  3843. WriteError('Invalid option: ' + para);
  3844. Halt(1);
  3845. end;
  3846. end;
  3847. inc(startpara);
  3848. end;
  3849. if not nostdout then
  3850. WriteLogo;
  3851. UnitList:=TPpuContainerDef.Create(nil);
  3852. try
  3853. UnitList.ItemsName:='';
  3854. { process files }
  3855. for nrfile:=startpara to paramcount do
  3856. dofile (paramstr(nrfile));
  3857. if not has_errors and (pout <> nil) then
  3858. begin
  3859. pout.Init;
  3860. UnitList.Write(pout);
  3861. pout.Done;
  3862. end;
  3863. finally
  3864. UnitList.Free;
  3865. pout.Free;
  3866. end;
  3867. if has_errors then
  3868. Halt(1);
  3869. if error_on_more and
  3870. (has_more_infos or has_warnings) then
  3871. Halt(2);
  3872. end.