ppudump.pp 122 KB

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