ppudump.pp 117 KB

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