2
0

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