ppudump.pp 108 KB

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