ppudump.pp 113 KB

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