ppudump.pp 112 KB

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