ppudump.pp 118 KB

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