ppudump.pp 122 KB

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