ppudump.pp 113 KB

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