ppudump.pp 107 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636
  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. const
  36. Title = 'PPU-Analyser';
  37. Copyright = 'Copyright (c) 1998-2013 by the Free Pascal Development Team';
  38. { verbosity }
  39. v_none = $0;
  40. v_header = $1;
  41. v_defs = $2;
  42. v_syms = $4;
  43. v_interface = $8;
  44. v_implementation = $10;
  45. // v_browser = $20;
  46. v_all = $ff;
  47. { not needed anymore $i systems.inc }
  48. { List of all supported cpus }
  49. const
  50. CpuTxt : array[tsystemcpu] of string[9]=
  51. (
  52. { 0 } 'none',
  53. { 1 } 'i386',
  54. { 2 } 'm68k',
  55. { 3 } 'alpha',
  56. { 4 } 'powerpc',
  57. { 5 } 'sparc',
  58. { 6 } 'vis',
  59. { 7 } 'ia64',
  60. { 8 } 'x86_64',
  61. { 9 } 'mipseb',
  62. { 10 } 'arm',
  63. { 11 } 'powerpc64',
  64. { 12 } 'avr',
  65. { 13 } 'mipsel',
  66. { 14 } 'jvm',
  67. { 15 } 'i8086'
  68. );
  69. { List of all supported system-cpu couples }
  70. const
  71. Targets : array[tsystem] of string[18]=(
  72. { 0 } 'none',
  73. { 1 } 'GO32V1 (obsolete)',
  74. { 2 } 'GO32V2',
  75. { 3 } 'Linux-i386',
  76. { 4 } 'OS/2',
  77. { 5 } 'Win32',
  78. { 6 } 'FreeBSD-i386',
  79. { 7 } 'Amiga',
  80. { 8 } 'Atari',
  81. { 9 } 'MacOS-m68k',
  82. { 10 } 'Linux-m68k',
  83. { 11 } 'PalmOS-m68k',
  84. { 12 } 'Linux-alpha',
  85. { 13 } 'Linux-ppc',
  86. { 14 } 'MacOS-ppc',
  87. { 15 } 'Solaris-i386',
  88. { 16 } 'BeOS-i386',
  89. { 17 } 'NetBSD-i386',
  90. { 18 } 'NetBSD-m68k',
  91. { 19 } 'Netware-i386-clib',
  92. { 20 } 'Qnx-i386',
  93. { 21 } 'WDOSX-i386',
  94. { 22 } 'Solaris-sparc',
  95. { 23 } 'Linux-sparc',
  96. { 24 } 'OpenBSD-i386',
  97. { 25 } 'OpenBSD-m68k',
  98. { 26 } 'Linux-x86-64',
  99. { 27 } 'MacOSX-ppc',
  100. { 28 } 'OS/2 via EMX',
  101. { 29 } 'NetBSD-powerpc',
  102. { 30 } 'OpenBSD-powerpc',
  103. { 31 } 'Linux-arm',
  104. { 32 } 'Watcom-i386',
  105. { 33 } 'MorphOS-powerpc',
  106. { 34 } 'FreeBSD-x86-64',
  107. { 35 } 'Netware-i386-libc',
  108. { 36 } 'Amiga-PowerPC',
  109. { 37 } 'Win64-x64',
  110. { 38 } 'WinCE-ARM',
  111. { 39 } 'Win64-iA64',
  112. { 40 } 'WinCE-i386',
  113. { 41 } 'Linux-x64',
  114. { 42 } 'GBA-arm',
  115. { 43 } 'Linux-powerpc64',
  116. { 44 } 'Darwin-i386',
  117. { 45 } 'PalmOS-arm',
  118. { 46 } 'MacOSX-powerpc64',
  119. { 47 } 'NDS-arm',
  120. { 48 } 'Embedded-i386',
  121. { 49 } 'Embedded-m68k',
  122. { 50 } 'Embedded-alpha',
  123. { 51 } 'Embedded-powerpc',
  124. { 52 } 'Embedded-sparc',
  125. { 53 } 'Embedded-vm',
  126. { 54 } 'Embedded-iA64',
  127. { 55 } 'Embedded-x64',
  128. { 56 } 'Embedded-mips',
  129. { 57 } 'Embedded-arm',
  130. { 58 } 'Embedded-powerpc64',
  131. { 59 } 'Symbian-i386',
  132. { 60 } 'Symbian-arm',
  133. { 61 } 'MacOSX-x64',
  134. { 62 } 'Embedded-avr',
  135. { 63 } 'Haiku-i386',
  136. { 64 } 'Darwin-ARM',
  137. { 65 } 'Solaris-x86-64',
  138. { 66 } 'Linux-MIPS',
  139. { 67 } 'Linux-MIPSel',
  140. { 68 } 'NativeNT-i386',
  141. { 69 } 'iPhoneSim-i386',
  142. { 70 } 'Wii-powerpc',
  143. { 71 } 'OpenBSD-x86-64',
  144. { 72 } 'NetBSD-x86-64',
  145. { 73 } 'AIX-powerpc',
  146. { 74 } 'AIX-powerpc64',
  147. { 75 } 'Java-JVM',
  148. { 76 } 'Android-JVM',
  149. { 77 } 'Android-arm',
  150. { 78 } 'Android-i386',
  151. { 79 } 'MSDOS-i8086'
  152. );
  153. const
  154. { in widestr, we have the following definition
  155. type
  156. tcompilerwidechar = word;
  157. thus widecharsize seems to always be 2 bytes }
  158. widecharsize : longint = 2;
  159. cpu : tsystemcpu = cpu_no;
  160. { This type is defined in scanner.pas unit }
  161. type
  162. tspecialgenerictoken = (
  163. ST_LOADSETTINGS,
  164. ST_LINE,
  165. ST_COLUMN,
  166. ST_FILEINDEX,
  167. ST_LOADMESSAGES);
  168. var
  169. ppufile : tppufile;
  170. ppuversion : dword;
  171. space : string;
  172. verbose : longint;
  173. derefdata : pbyte;
  174. derefdatalen : longint;
  175. pout: TPpuOutput;
  176. nostdout: boolean;
  177. UnitList: TPpuContainerDef;
  178. CurUnit: TPpuUnitDef;
  179. {****************************************************************************
  180. Helper Routines
  181. ****************************************************************************}
  182. {****************************************************************************
  183. Routine to read 80-bit reals
  184. ****************************************************************************
  185. }
  186. type
  187. TSplit80bitReal = packed record
  188. case byte of
  189. 0: (bytes: Array[0..9] of byte);
  190. 1: (words: Array[0..4] of word);
  191. 2: (cards: Array[0..1] of cardinal; w: word);
  192. end;
  193. const
  194. maxDigits = 17;
  195. function Real80bitToStr(var e : TSplit80bitReal) : string;
  196. var
  197. Temp : string;
  198. new : TSplit80bitReal;
  199. fraczero, expmaximal, sign, outside_double : boolean;
  200. exp : smallint;
  201. ext : extended;
  202. d : double;
  203. i : longint;
  204. mantval : qword;
  205. begin
  206. if ppufile.change_endian then
  207. begin
  208. for i:=0 to 9 do
  209. new.bytes[i]:=e.bytes[9-i];
  210. e:=new;
  211. end;
  212. if sizeof(ext)=10 then
  213. begin
  214. ext:=pextended(@e)^;
  215. str(ext,result);
  216. exit;
  217. end;
  218. { extended, format (MSB): 1 Sign bit, 15 bit exponent, 64 bit mantissa }
  219. sign := (e.w and $8000) <> 0;
  220. expMaximal := (e.w and $7fff) = 32767;
  221. exp:=(e.w and $7fff) - 16383 - 63;
  222. fraczero := (e.cards[0] = 0) and
  223. ((e.cards[1] and $7fffffff) = 0);
  224. mantval := qword(e.cards[0]) or (qword(e.cards[1]) shl 32);
  225. if expMaximal then
  226. if fraczero then
  227. if sign then
  228. temp := '-Inf'
  229. else temp := '+Inf'
  230. else temp := 'Nan'
  231. else
  232. begin
  233. d:=double(mantval);
  234. if sign then
  235. d:=-d;
  236. outside_double:=false;
  237. Try
  238. if exp > 0 then
  239. begin
  240. for i:=1 to exp do
  241. d:=d *2.0;
  242. end
  243. else if exp < 0 then
  244. begin
  245. for i:=1 to -exp do
  246. d:=d /2.0;
  247. end;
  248. Except
  249. outside_double:=true;
  250. end;
  251. if (mantval<>0) and (d=0.0) then
  252. outside_double:=true;
  253. if outside_double then
  254. Temp:='Extended value outside double bound'
  255. else
  256. system.str(d,temp);
  257. end;
  258. result:=temp;
  259. end;
  260. const has_errors : boolean = false;
  261. has_more_infos : boolean = false;
  262. procedure Write(const s: string);
  263. begin
  264. if nostdout then exit;
  265. system.write(s);
  266. end;
  267. procedure Write(const params: array of const);
  268. var
  269. i: integer;
  270. begin
  271. if nostdout then exit;
  272. for i:=Low(params) to High(params) do
  273. with TVarRec(params[i]) do
  274. case VType of
  275. vtInteger: system.write(VInteger);
  276. vtInt64: system.write(VInt64^);
  277. vtQWord: system.write(VQWord^);
  278. vtString: system.write(VString^);
  279. vtAnsiString: system.write(ansistring(VAnsiString));
  280. vtPChar: system.write(VPChar);
  281. vtChar: system.write(VChar);
  282. vtBoolean: system.write(VBoolean);
  283. vtExtended: system.write(VExtended^);
  284. else
  285. begin
  286. system.writeln;
  287. system.writeln('Unsupported var type: ', VType);
  288. Halt(10);
  289. end;
  290. end;
  291. end;
  292. procedure Writeln(const s: string = '');
  293. begin
  294. if nostdout then exit;
  295. system.writeln(s);
  296. end;
  297. procedure Writeln(const params: array of const);
  298. begin
  299. if nostdout then exit;
  300. Write(params);
  301. system.writeln;
  302. end;
  303. Procedure HasMoreInfos;
  304. begin
  305. Writeln('!! Entry has more information stored');
  306. has_more_infos:=true;
  307. end;
  308. procedure SetHasErrors;
  309. begin
  310. has_errors:=true;
  311. end;
  312. Procedure WriteError(const S : string);
  313. Begin
  314. system.Writeln(StdErr, S);
  315. SetHasErrors;
  316. End;
  317. Procedure WriteWarning(const S : string);
  318. var
  319. ss: string;
  320. Begin
  321. ss:='!! Warning: ' + S;
  322. if nostdout then
  323. system.Writeln(StdErr, ss)
  324. else
  325. system.Writeln(ss);
  326. End;
  327. function Unknown(const st : string; val :longint) : string;
  328. Begin
  329. Unknown:='<!! Unknown'+st+' value '+tostr(val)+'>';
  330. SetHasErrors;
  331. end;
  332. function ToStr(w:longint):String;
  333. begin
  334. Str(w,ToStr);
  335. end;
  336. Function Target2Str(w:longint):string;
  337. begin
  338. if w<=ord(high(tsystem)) then
  339. Target2Str:=Targets[tsystem(w)]
  340. else
  341. Target2Str:=Unknown('target',w);
  342. end;
  343. Function Cpu2Str(w:longint):string;
  344. begin
  345. if w<=ord(high(tsystemcpu)) then
  346. begin
  347. cpu:=tsystemcpu(w);
  348. Cpu2Str:=CpuTxt[cpu];
  349. end
  350. else
  351. Cpu2Str:=Unknown('cpu',w);
  352. end;
  353. Function Varspez2Str(w:longint):string;
  354. const
  355. { in symconst unit
  356. tvarspez = (vs_value,vs_const,vs_var,vs_out,vs_constref); }
  357. varspezstr : array[tvarspez] of string[8]=('Value','Const','Var','Out','ConstRef','Final');
  358. begin
  359. if w<=ord(high(varspezstr)) then
  360. Varspez2Str:=varspezstr[tvarspez(w)]
  361. else
  362. Varspez2Str:=Unknown('varspez',w);
  363. end;
  364. Function VarRegable2Str(w:longint):string;
  365. { tvarregable type is defined in symconst unit }
  366. const
  367. varregableStr : array[tvarregable] of string[6]=('None','IntReg','FPUReg','MMReg','Addr');
  368. begin
  369. if w<=ord(high(varregablestr)) then
  370. Varregable2Str:=varregablestr[tvarregable(w)]
  371. else
  372. Varregable2Str:=Unknown('regable',w);
  373. end;
  374. Function Visibility2Str(w:longint):string;
  375. const
  376. { tvisibility type is defined in symconst unit }
  377. visibilityName : array[tvisibility] of string[16] = (
  378. 'hidden','strict private','private','strict protected','protected',
  379. 'public','published','<none>'
  380. );
  381. begin
  382. if w<=ord(high(visibilityName)) then
  383. result:=visibilityName[tvisibility(w)]
  384. else
  385. result:=Unknown('visibility',w);
  386. end;
  387. Function IntfEntryType2Str(w:longint):string;
  388. const
  389. { tinterfaceentrytype type is defined in symconst unit }
  390. Name : array[tinterfaceentrytype] of string = (
  391. 'standard','virtual method result','static method result','field value','virtual method class',
  392. 'static method class','field value class'
  393. );
  394. begin
  395. if w<=ord(high(Name)) then
  396. result:=Name[tinterfaceentrytype(w)]
  397. else
  398. result:=Unknown('entry type',w);
  399. end;
  400. Function Synthetic2Str(w: byte): string;
  401. const
  402. syntheticName : array[tsynthetickind] of string[length('jvm procvar intf constructor')] = (
  403. '<none>','anon inherited','jvm clone','record deep copy',
  404. 'record initilializer', 'empty routine', 'typed const initializer',
  405. 'callthough', 'callthrough if not abstract', 'jvm enum values',
  406. 'jvm enum valueof', 'jvm enum class constructor',
  407. 'jvm enum jumps constructor', 'jvm enum fpcordinal',
  408. 'jvm enum fpcvalueof', 'jvm enum long2set',
  409. 'jvm enum bitset2set', 'jvm enum set2set',
  410. 'jvm procvar invoke', 'jvm procvar intf constructor',
  411. 'jvm virtual class method', 'jvm field getter', 'jvm field setter');
  412. begin
  413. if w<=ord(high(syntheticName)) then
  414. result:=syntheticName[tsynthetickind(w)]
  415. else
  416. result:=Unknown('synthetickind',w);
  417. end;
  418. function PPUFlags2Str(flags:longint):string;
  419. type
  420. tflagopt=record
  421. mask : longint;
  422. str : string[30];
  423. end;
  424. const
  425. flagopts=24;
  426. flagopt : array[1..flagopts] of tflagopt=(
  427. (mask: $1 ;str:'init'),
  428. (mask: $2 ;str:'final'),
  429. (mask: $4 ;str:'big_endian'),
  430. (mask: $8 ;str:'dbx'),
  431. // (mask: $10 ;str:'browser'),
  432. (mask: $20 ;str:'in_library'),
  433. (mask: $40 ;str:'smart_linked'),
  434. (mask: $80 ;str:'static_linked'),
  435. (mask: $100 ;str:'shared_linked'),
  436. // (mask: $200 ;str:'local_browser'),
  437. (mask: $400 ;str:'no_link'),
  438. (mask: $800 ;str:'has_resources'),
  439. (mask: $1000 ;str:'little_endian'),
  440. (mask: $2000 ;str:'release'),
  441. (mask: $4000 ;str:'local_threadvars'),
  442. (mask: $8000 ;str:'fpu_emulation_on'),
  443. (mask: $210000 ;str:'has_debug_info'),
  444. (mask: $10000 ;str:'stabs_debug_info'),
  445. (mask: $200000 ;str:'dwarf_debug_info'),
  446. (mask: $20000 ;str:'local_symtable'),
  447. (mask: $40000 ;str:'uses_variants'),
  448. (mask: $80000 ;str:'has_resourcefiles'),
  449. (mask: $100000 ;str:'has_exports'),
  450. (mask: $400000 ;str:'has_wideinits'),
  451. (mask: $800000 ;str:'has_classinits'),
  452. (mask: $1000000 ;str:'has_resstrinits')
  453. );
  454. var
  455. i,ntflags : longint;
  456. first : boolean;
  457. s : string;
  458. begin
  459. s:='';
  460. if flags<>0 then
  461. begin
  462. ntflags:=flags;
  463. first:=true;
  464. for i:=1to flagopts do
  465. if (flags and flagopt[i].mask)<>0 then
  466. begin
  467. if first then
  468. first:=false
  469. else
  470. s:=s+', ';
  471. s:=s+flagopt[i].str;
  472. ntflags:=ntflags and (not flagopt[i].mask);
  473. end;
  474. end
  475. else
  476. s:='none';
  477. if ntflags<>0 then
  478. begin
  479. s:=s+' unknown '+hexstr(ntflags,8);
  480. SetHasErrors;
  481. end;
  482. PPUFlags2Str:=s;
  483. end;
  484. Function L0(l:longint):string;
  485. {
  486. return the string of value l, if l<10 then insert a zero, so
  487. the string is always at least 2 chars '01','02',etc
  488. }
  489. var
  490. s : string;
  491. begin
  492. Str(l,s);
  493. if l<10 then
  494. s:='0'+s;
  495. L0:=s;
  496. end;
  497. function filetimestring( t : longint) : string;
  498. {
  499. convert dos datetime t to a string YY/MM/DD HH:MM:SS
  500. }
  501. var
  502. DT : TDateTime;
  503. hsec : word;
  504. Year,Month,Day: Word;
  505. hour,min,sec : word;
  506. begin
  507. if t=-1 then
  508. begin
  509. Result := 'Not Found';
  510. SetHasErrors;
  511. exit;
  512. end;
  513. DT := FileDateToDateTime(t);
  514. DecodeTime(DT,hour,min,sec,hsec);
  515. DecodeDate(DT,year,month,day);
  516. Result := L0(Year)+'/'+L0(Month)+'/'+L0(Day)+' '+L0(Hour)+':'+L0(min)+':'+L0(sec);
  517. end;
  518. {****************************************************************************
  519. Read Routines
  520. ****************************************************************************}
  521. procedure readrecsymtableoptions;
  522. var
  523. usefieldalignment : shortint;
  524. begin
  525. if ppufile.readentry<>ibrecsymtableoptions then
  526. begin
  527. SetHasErrors;
  528. exit;
  529. end;
  530. writeln([space,' recordalignment: ',shortint(ppufile.getbyte)]);
  531. usefieldalignment:=shortint(ppufile.getbyte);
  532. writeln([space,' usefieldalignment: ',usefieldalignment]);
  533. if (usefieldalignment=C_alignment) then
  534. writeln([space,' fieldalignment: ',shortint(ppufile.getbyte)]);
  535. end;
  536. procedure readsymtableoptions(const s: string);
  537. type
  538. tsymtblopt=record
  539. mask : tsymtableoption;
  540. str : string[30];
  541. end;
  542. const
  543. symtblopts=ord(high(tsymtableoption)) + 1;
  544. symtblopt : array[1..symtblopts] of tsymtblopt=(
  545. (mask:sto_has_helper; str:'Has helper'),
  546. (mask:sto_has_generic; str:'Has generic'),
  547. (mask:sto_has_operator; str:'Has operator')
  548. );
  549. var
  550. options : tsymtableoptions;
  551. first : boolean;
  552. i : integer;
  553. begin
  554. if ppufile.readentry<>ibsymtableoptions then
  555. begin
  556. SetHasErrors;
  557. exit;
  558. end;
  559. ppufile.getsmallset(options);
  560. if space<>'' then
  561. writeln([space,'------ ',s,' ------']);
  562. write([space,'Symtable options: ']);
  563. if options<>[] then
  564. begin
  565. first:=true;
  566. for i:=1 to symtblopts do
  567. if (symtblopt[i].mask in options) then
  568. begin
  569. if first then
  570. first:=false
  571. else
  572. write(', ');
  573. write(symtblopt[i].str);
  574. end;
  575. end
  576. else
  577. write('none');
  578. writeln;
  579. end;
  580. procedure readdefinitions(const s:string; ParentDef: TPpuContainerDef); forward;
  581. procedure readsymbols(const s:string; ParentDef: TPpuContainerDef = nil); forward;
  582. procedure readsymtable(const s: string; ParentDef: TPpuContainerDef = nil);
  583. begin
  584. readsymtableoptions(s);
  585. readdefinitions(s, ParentDef);
  586. readsymbols(s, ParentDef);
  587. end;
  588. Procedure ReadLinkContainer(const prefix:string);
  589. {
  590. Read a serie of strings and write to the screen starting every line
  591. with prefix
  592. }
  593. function maskstr(m:longint):string;
  594. { link options are in globtype unit
  595. const
  596. link_none = $0;
  597. link_always = $1;
  598. link_static = $2;
  599. link_smart = $4;
  600. link_shared = $8; }
  601. var
  602. s : string;
  603. begin
  604. s:='';
  605. if (m and link_always)<>0 then
  606. s:=s+'always ';
  607. if (m and link_static)<>0 then
  608. s:=s+'static ';
  609. if (m and link_smart)<>0 then
  610. s:=s+'smart ';
  611. if (m and link_shared)<>0 then
  612. s:=s+'shared ';
  613. maskstr:=s;
  614. end;
  615. var
  616. s : string;
  617. m : longint;
  618. begin
  619. while not ppufile.endofentry do
  620. begin
  621. s:=ppufile.getstring;
  622. m:=ppufile.getlongint;
  623. WriteLn([prefix,s,' (',maskstr(m),')']);
  624. end;
  625. end;
  626. Procedure ReadContainer(const prefix:string);
  627. {
  628. Read a serie of strings and write to the screen starting every line
  629. with prefix
  630. }
  631. begin
  632. while not ppufile.endofentry do
  633. WriteLn([prefix,ppufile.getstring]);
  634. end;
  635. procedure ReadLoadUnit;
  636. var
  637. ucrc,uintfcrc, indcrc : cardinal;
  638. un: TPpuUnitDef;
  639. begin
  640. while not ppufile.EndOfEntry do
  641. begin
  642. un:=TPpuUnitDef.Create(CurUnit.UsedUnits);
  643. un.Name:=ppufile.getstring;
  644. write(['Uses unit: ',un.Name]);
  645. ucrc:=cardinal(ppufile.getlongint);
  646. uintfcrc:=cardinal(ppufile.getlongint);
  647. indcrc:=cardinal(ppufile.getlongint);
  648. writeln([' (Crc: ',hexstr(ucrc,8),', IntfcCrc: ',hexstr(uintfcrc,8),', IndCrc: ',hexstr(indcrc,8),')']);
  649. un.Crc:=ucrc;
  650. un.IntfCrc:=uintfcrc;
  651. end;
  652. end;
  653. Procedure ReadDerefmap;
  654. var
  655. i,mapsize : longint;
  656. s: string;
  657. begin
  658. mapsize:=ppufile.getlongint;
  659. writeln(['DerefMapsize: ',mapsize]);
  660. SetLength(CurUnit.RefUnits, mapsize);
  661. for i:=0 to mapsize-1 do
  662. begin
  663. s:=ppufile.getstring;
  664. writeln(['DerefMap[',i,'] = ',s]);
  665. CurUnit.RefUnits[i]:=LowerCase(s);
  666. end;
  667. end;
  668. Procedure ReadImportSymbols;
  669. var
  670. extlibname : string;
  671. j,
  672. extsymcnt : longint;
  673. extsymname : string;
  674. extsymmangledname : string;
  675. extsymordnr : longint;
  676. extsymisvar : boolean;
  677. begin
  678. while not ppufile.endofentry do
  679. begin
  680. extlibname:=ppufile.getstring;
  681. extsymcnt:=ppufile.getlongint;
  682. writeln(['External Library: ',extlibname,' (',extsymcnt,' imports)']);
  683. for j:=0 to extsymcnt-1 do
  684. begin
  685. extsymname:=ppufile.getstring;
  686. if ppuversion>130 then
  687. extsymmangledname:=ppufile.getstring
  688. else
  689. extsymmangledname:=extsymname;
  690. extsymordnr:=ppufile.getlongint;
  691. extsymisvar:=ppufile.getbyte<>0;
  692. writeln([' ',extsymname,' as ',extsymmangledname,
  693. '(OrdNr: ',extsymordnr,' IsVar: ',extsymisvar,')']);
  694. end;
  695. end;
  696. end;
  697. Procedure ReadDerefdata;
  698. begin
  699. derefdatalen:=ppufile.entrysize;
  700. if derefdatalen=0 then
  701. begin
  702. WriteError('!! Error: derefdatalen=0');
  703. exit;
  704. end;
  705. Writeln(['Derefdata length: ',derefdatalen]);
  706. derefdata:=allocmem(derefdatalen);
  707. ppufile.getdata(derefdata^,derefdatalen);
  708. end;
  709. Procedure FreeDerefdata;
  710. begin
  711. if assigned(derefdata) then
  712. begin
  713. FreeMem(derefdata);
  714. derefdata:=nil;
  715. derefdatalen:=0;
  716. end;
  717. end;
  718. Procedure ReadWpoFileInfo;
  719. begin
  720. Writeln(['Compiled with input whole-program optimisation from ',ppufile.getstring,' ',filetimestring(ppufile.getlongint)]);
  721. end;
  722. Procedure ReadAsmSymbols;
  723. type
  724. { Copied from aasmbase.pas }
  725. TAsmsymbind=(
  726. AB_NONE,AB_EXTERNAL,AB_COMMON,AB_LOCAL,AB_GLOBAL,AB_WEAK_EXTERNAL,
  727. { global in the current program/library, but not visible outside it }
  728. AB_PRIVATE_EXTERN,AB_LAZY,AB_IMPORT);
  729. TAsmsymtype=(
  730. AT_NONE,AT_FUNCTION,AT_DATA,AT_SECTION,AT_LABEL,
  731. {
  732. the address of this code label is taken somewhere in the code
  733. so it must be taken care of it when creating pic
  734. }
  735. AT_ADDR
  736. );
  737. var
  738. s,
  739. bindstr,
  740. typestr : string;
  741. i : longint;
  742. begin
  743. writeln([space,'Number of AsmSymbols: ',ppufile.getlongint]);
  744. i:=0;
  745. while (not ppufile.endofentry) and (not ppufile.error) do
  746. begin
  747. s:=ppufile.getstring;
  748. case tasmsymbind(ppufile.getbyte) of
  749. AB_EXTERNAL :
  750. bindstr:='External';
  751. AB_COMMON :
  752. bindstr:='Common';
  753. AB_LOCAL :
  754. bindstr:='Local';
  755. AB_GLOBAL :
  756. bindstr:='Global';
  757. AB_WEAK_EXTERNAL :
  758. bindstr:='Weak external';
  759. AB_PRIVATE_EXTERN :
  760. bindstr:='Private extern';
  761. AB_LAZY :
  762. bindstr:='Lazy';
  763. AB_IMPORT :
  764. bindstr:='Import';
  765. else
  766. begin
  767. bindstr:='<Error !!>';
  768. SetHasErrors;
  769. end;
  770. end;
  771. case tasmsymtype(ppufile.getbyte) of
  772. AT_FUNCTION :
  773. typestr:='Function';
  774. AT_DATA :
  775. typestr:='Data';
  776. AT_SECTION :
  777. typestr:='Section';
  778. AT_LABEL :
  779. typestr:='Label';
  780. AT_ADDR :
  781. typestr:='Label (with address taken)';
  782. else
  783. begin
  784. typestr:='<Error !!>';
  785. SetHasErrors;
  786. end;
  787. end;
  788. Writeln([space,' ',i,' : ',s,' [',bindstr,',',typestr,']']);
  789. inc(i);
  790. end;
  791. end;
  792. function getexprint:Tconstexprint;
  793. begin
  794. getexprint.overflow:=false;
  795. getexprint.signed:=boolean(ppufile.getbyte);
  796. getexprint.svalue:=ppufile.getint64;
  797. end;
  798. Procedure ReadPosInfo(Def: TPpuDef = nil);
  799. var
  800. info : byte;
  801. fileindex,line,column : longint;
  802. begin
  803. with ppufile do
  804. begin
  805. {
  806. info byte layout in bits:
  807. 0-1 - amount of bytes for fileindex
  808. 2-3 - amount of bytes for line
  809. 4-5 - amount of bytes for column
  810. }
  811. info:=getbyte;
  812. case (info and $03) of
  813. 0 : fileindex:=getbyte;
  814. 1 : fileindex:=getword;
  815. 2 : fileindex:=(getbyte shl 16) or getword;
  816. 3 : fileindex:=getlongint;
  817. end;
  818. case ((info shr 2) and $03) of
  819. 0 : line:=getbyte;
  820. 1 : line:=getword;
  821. 2 : line:=(getbyte shl 16) or getword;
  822. 3 : line:=getlongint;
  823. end;
  824. case ((info shr 4) and $03) of
  825. 0 : column:=getbyte;
  826. 1 : column:=getword;
  827. 2 : column:=(getbyte shl 16) or getword;
  828. 3 : column:=getlongint;
  829. end;
  830. Writeln([fileindex,' (',line,',',column,')']);
  831. if Def <> nil then
  832. begin
  833. Def.FilePos.FileIndex:=fileindex - 1;
  834. Def.FilePos.Line:=line;
  835. Def.FilePos.Col:=column;
  836. end;
  837. end;
  838. end;
  839. procedure readderef(const derefspace: string; Ref: TPpuRef = nil);
  840. var
  841. b : tdereftype;
  842. first : boolean;
  843. idx : longint;
  844. i,n : byte;
  845. pdata : pbyte;
  846. begin
  847. if not assigned(derefdata) then
  848. exit;
  849. first:=true;
  850. idx:=ppufile.getlongint;
  851. if (idx>derefdatalen) then
  852. begin
  853. writeln(['!! Error: Deref idx ',idx,' > ',derefdatalen]);
  854. SetHasErrors;
  855. exit;
  856. end;
  857. write([derefspace,'(',idx,') ']);
  858. pdata:=@derefdata[idx];
  859. i:=0;
  860. n:=pdata[i];
  861. inc(i);
  862. if n<1 then
  863. begin
  864. WriteError('!! Error: Deref len < 1');
  865. exit;
  866. end;
  867. while (i<=n) do
  868. begin
  869. if not first then
  870. write(', ')
  871. else
  872. first:=false;
  873. b:=tdereftype(pdata[i]);
  874. inc(i);
  875. case b of
  876. deref_nil :
  877. write('Nil');
  878. deref_symid :
  879. begin
  880. idx:=pdata[i] shl 24 or pdata[i+1] shl 16 or pdata[i+2] shl 8 or pdata[i+3];
  881. inc(i,4);
  882. write(['SymId ',idx]);
  883. if Ref <> nil then
  884. Ref.Id:=idx;
  885. end;
  886. deref_defid :
  887. begin
  888. idx:=pdata[i] shl 24 or pdata[i+1] shl 16 or pdata[i+2] shl 8 or pdata[i+3];
  889. inc(i,4);
  890. write(['DefId ',idx]);
  891. if Ref <> nil then
  892. Ref.Id:=idx;
  893. end;
  894. deref_unit :
  895. begin
  896. idx:=pdata[i] shl 8 or pdata[i+1];
  897. inc(i,2);
  898. write(['Unit ',idx]);
  899. if Ref <> nil then
  900. Ref.UnitIndex:=idx;
  901. end;
  902. else
  903. begin
  904. writeln(['!! unsupported dereftyp: ',ord(b)]);
  905. SetHasErrors;
  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. type
  1774. tsymopt=record
  1775. mask : tarraydefoption;
  1776. str : string[30];
  1777. end;
  1778. const
  1779. symopt : array[1..ord(high(tarraydefoption))] of tsymopt=(
  1780. (mask:ado_IsConvertedPointer;str:'ConvertedPointer'),
  1781. (mask:ado_IsDynamicArray; str:'IsDynamicArray'),
  1782. (mask:ado_IsVariant; str:'IsVariant'),
  1783. (mask:ado_IsConstructor; str:'IsConstructor'),
  1784. (mask:ado_IsArrayOfConst; str:'ArrayOfConst'),
  1785. (mask:ado_IsConstString; str:'ConstString'),
  1786. (mask:ado_IsBitPacked; str:'BitPacked')
  1787. );
  1788. var
  1789. symoptions : tarraydefoptions;
  1790. i : longint;
  1791. first : boolean;
  1792. begin
  1793. ppufile.getsmallset(symoptions);
  1794. if symoptions<>[] then
  1795. begin
  1796. if ado_IsDynamicArray in symoptions then Include(ArrayDef.Options, aoDynamic);
  1797. first:=true;
  1798. for i:=1 to high(symopt) do
  1799. if (symopt[i].mask in symoptions) then
  1800. begin
  1801. if first then
  1802. first:=false
  1803. else
  1804. write(', ');
  1805. write(symopt[i].str);
  1806. end;
  1807. end;
  1808. writeln;
  1809. end;
  1810. (* options for properties
  1811. tpropertyoption=(ppo_none,
  1812. ppo_indexed,
  1813. ppo_defaultproperty,
  1814. ppo_stored,
  1815. ppo_hasparameters,
  1816. ppo_implements,
  1817. ppo_enumerator_current,
  1818. ppo_overrides,
  1819. ppo_dispid_write { no longer used }
  1820. );
  1821. tpropertyoptions=set of tpropertyoption;
  1822. *)
  1823. function readpropertyoptions:tpropertyoptions;
  1824. { type tarraydefoption is in unit symconst }
  1825. type
  1826. tpropopt=record
  1827. mask : tpropertyoption;
  1828. str : string[30];
  1829. end;
  1830. const
  1831. symopt : array[1..ord(high(tpropertyoption))] of tpropopt=(
  1832. (mask:ppo_indexed;str:'indexed'),
  1833. (mask:ppo_defaultproperty;str:'default'),
  1834. (mask:ppo_stored;str:'stored'),
  1835. (mask:ppo_hasparameters;str:'has parameters'),
  1836. (mask:ppo_implements;str:'implements'),
  1837. (mask:ppo_enumerator_current;str:'enumerator current'),
  1838. (mask:ppo_overrides;str:'overrides'),
  1839. (mask:ppo_dispid_write;str:'dispid write') { no longer used }
  1840. );
  1841. var
  1842. i : longint;
  1843. first : boolean;
  1844. begin
  1845. ppufile.getsmallset(result);
  1846. if result<>[] then
  1847. begin
  1848. first:=true;
  1849. for i:=1 to high(symopt) do
  1850. if (symopt[i].mask in result) then
  1851. begin
  1852. if first then
  1853. first:=false
  1854. else
  1855. write(', ');
  1856. write(symopt[i].str);
  1857. end;
  1858. end;
  1859. writeln;
  1860. end;
  1861. procedure readnodetree;
  1862. var
  1863. l : longint;
  1864. p : pointer;
  1865. begin
  1866. with ppufile do
  1867. begin
  1868. if space<>'' then
  1869. Writeln([space,'------ nodetree ------']);
  1870. if readentry=ibnodetree then
  1871. begin
  1872. l:=entrysize;
  1873. Writeln([space,'Tree size : ',l]);
  1874. { Read data to prevent error that entry is not completly read }
  1875. getmem(p,l);
  1876. getdata(p^,l);
  1877. freemem(p);
  1878. end
  1879. else
  1880. begin
  1881. WriteError('!! ibnodetree not found');
  1882. end;
  1883. end;
  1884. end;
  1885. procedure ReadCreatedObjTypes;
  1886. var
  1887. i,j,
  1888. len,
  1889. bssize: longint;
  1890. bs: pbyte;
  1891. begin
  1892. if ppufile.readentry<>ibcreatedobjtypes then
  1893. begin
  1894. writeln('!! ibcreatedobjtypes entry not found');
  1895. ppufile.skipdata(ppufile.entrysize);
  1896. SetHasErrors;
  1897. exit
  1898. end;
  1899. writeln;
  1900. writeln([space,'WPO info']);
  1901. writeln([space,'--------']);
  1902. len:=ppufile.getlongint;
  1903. writeln([space,'** Instantiated Object/Class 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,'** 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,'** Possibly instantiated ClassRef types : ',len,' **']);
  1916. space:=space+' ';
  1917. for i:=0 to len-1 do
  1918. readderef(space);
  1919. setlength(space,length(space)-2);
  1920. len:=ppufile.getlongint;
  1921. writeln([space,'** Class types with called virtual methods info : ',len,' **']);
  1922. space:=space+' ';
  1923. for i:=0 to len-1 do
  1924. begin
  1925. write([space,'Class def : ']);
  1926. readderef('');
  1927. write([space+' ','Called vmtentries : ']);
  1928. bssize:=ppufile.getlongint;
  1929. getmem(bs,bssize);
  1930. ppufile.readdata(bs^,bssize);
  1931. for j:=0 to bssize*8-1 do
  1932. if (((bs+j shr 3)^ shr (j and 7)) and 1) <> 0 then
  1933. write([j,', ']);
  1934. writeln;
  1935. freemem(bs);
  1936. end;
  1937. setlength(space,length(space)-2);
  1938. end;
  1939. {****************************************************************************
  1940. Read Symbols Part
  1941. ****************************************************************************}
  1942. procedure readsymbols(const s:string; ParentDef: TPpuContainerDef = nil);
  1943. function _finddef(symdef: TPpuDef): TPpuDef;
  1944. begin
  1945. Result:=nil;
  1946. if symdef.Ref.IsCurUnit then
  1947. begin;
  1948. Result:=CurUnit.FindById(symdef.Ref.Id);
  1949. if (Result <> nil) and (Result.Ref.Id = symdef.Id) then
  1950. begin
  1951. Result.Name:=symdef.Name;
  1952. Result.FilePos:=symdef.FilePos;
  1953. end
  1954. else
  1955. Result:=nil;
  1956. end;
  1957. end;
  1958. type
  1959. pguid = ^tguid;
  1960. tguid = packed record
  1961. D1: LongWord;
  1962. D2: Word;
  1963. D3: Word;
  1964. D4: array[0..7] of Byte;
  1965. end;
  1966. var
  1967. b : byte;
  1968. pc : pchar;
  1969. ch : dword;
  1970. startnewline : boolean;
  1971. i,j,len : longint;
  1972. prettyname, ss : ansistring;
  1973. guid : tguid;
  1974. realvalue : ppureal;
  1975. doublevalue : double;
  1976. singlevalue : single;
  1977. extended : TSplit80bitReal;
  1978. tempbuf : array[0..127] of char;
  1979. pw : pcompilerwidestring;
  1980. varoptions : tvaroptions;
  1981. propoptions : tpropertyoptions;
  1982. iexp: Tconstexprint;
  1983. def: TPpuDef;
  1984. constdef: TPpuConstDef absolute def;
  1985. begin
  1986. with ppufile do
  1987. begin
  1988. if space<>'' then
  1989. Writeln([space,'------ ',s,' ------']);
  1990. if readentry=ibstartsyms then
  1991. begin
  1992. Writeln([space,'Symtable datasize : ',getlongint]);
  1993. Writeln([space,'Symtable alignment: ',getlongint]);
  1994. end
  1995. else
  1996. Writeln('!! ibstartsym not found');
  1997. repeat
  1998. def:=nil;
  1999. b:=readentry;
  2000. case b of
  2001. ibunitsym :
  2002. readcommonsym('Unit symbol ');
  2003. ibnamespacesym :
  2004. begin
  2005. readcommonsym('NameSpace symbol ');
  2006. write([space,' Hidden Unit : ']);
  2007. readderef('');
  2008. end;
  2009. iblabelsym :
  2010. readcommonsym('Label symbol ');
  2011. ibtypesym :
  2012. begin
  2013. def:=TPpuTypeRef.Create(nil);
  2014. readcommonsym('Type symbol ',def);
  2015. write([space,' Result Type : ']);
  2016. readderef('', def.Ref);
  2017. if _finddef(def) = nil then
  2018. def.Parent:=ParentDef;
  2019. prettyname:=getansistring;
  2020. if prettyname<>'' then
  2021. begin
  2022. write([space,' Pretty Name : ']);
  2023. Writeln(prettyname);
  2024. end;
  2025. end;
  2026. ibprocsym :
  2027. begin
  2028. def:=TPpuDef.Create(nil);
  2029. readcommonsym('Procedure symbol ', def);
  2030. len:=ppufile.getword;
  2031. for i:=1 to len do
  2032. begin
  2033. write([space,' Definition : ']);
  2034. readderef('', def.Ref);
  2035. _finddef(def);
  2036. end;
  2037. end;
  2038. ibconstsym :
  2039. begin
  2040. constdef:=TPpuConstDef.Create(ParentDef);
  2041. readcommonsym('Constant symbol ',constdef);
  2042. b:=getbyte;
  2043. case tconsttyp(b) of
  2044. constord :
  2045. begin
  2046. write ([space,' OrdinalType : ']);
  2047. readderef('',constdef.TypeRef);
  2048. iexp:=getexprint;
  2049. constdef.ConstType:=ctInt;
  2050. constdef.VInt:=iexp.svalue;
  2051. writeln([space,' Value : ',constexp.tostr(iexp)]);
  2052. end;
  2053. constpointer :
  2054. begin
  2055. write ([space,' PointerType : ']);
  2056. readderef('',constdef.TypeRef);
  2057. constdef.ConstType:=ctInt;
  2058. constdef.VInt:=getaint;
  2059. writeln([space,' Value : ',constdef.VInt])
  2060. end;
  2061. conststring,
  2062. constresourcestring :
  2063. begin
  2064. len:=getlongint;
  2065. getmem(pc,len+1);
  2066. getdata(pc^,len);
  2067. (pc+len)^:= #0;
  2068. writeln([space,' Length : ',len]);
  2069. writeln([space,' Value : "',pc,'"']);
  2070. constdef.ConstType:=ctStr;
  2071. SetString(constdef.VStr, pc, len);
  2072. freemem(pc,len+1);
  2073. end;
  2074. constreal :
  2075. begin
  2076. constdef.ConstType:=ctFloat;
  2077. write ([space,' RealType : ']);
  2078. readderef('',constdef.TypeRef);
  2079. write([space,' Value : ']);
  2080. if entryleft=sizeof(ppureal) then
  2081. begin
  2082. realvalue:=getrealsize(sizeof(ppureal));
  2083. constdef.VFloat:=realvalue;
  2084. writeln([realvalue]);
  2085. end
  2086. else if entryleft=sizeof(double) then
  2087. begin
  2088. doublevalue:=getrealsize(sizeof(double));
  2089. constdef.VFloat:=doublevalue;
  2090. writeln([doublevalue]);
  2091. end
  2092. else if entryleft=sizeof(single) then
  2093. begin
  2094. singlevalue:=getrealsize(sizeof(single));
  2095. constdef.VFloat:=singlevalue;
  2096. writeln([singlevalue]);
  2097. end
  2098. else if entryleft=10 then
  2099. begin
  2100. getdata(extended,entryleft);
  2101. ss:=Real80bitToStr(extended);
  2102. constdef.VFloat:=StrToFloat(ss);
  2103. writeln(ss);
  2104. end
  2105. else
  2106. begin
  2107. realvalue:=0.0;
  2108. writeln([realvalue,' Error reading real value']);
  2109. SetHasErrors;
  2110. end;
  2111. end;
  2112. constset :
  2113. begin
  2114. constdef.ConstType:=ctSet;
  2115. write ([space,' Set Type : ']);
  2116. readderef('',constdef.TypeRef);
  2117. for i:=1to 4 do
  2118. begin
  2119. write ([space,' Value : ']);
  2120. for j:=1to 8 do
  2121. begin
  2122. if j>1 then
  2123. write(',');
  2124. b:=getbyte;
  2125. write(hexstr(b,2));
  2126. constdef.VSet[i*j-1]:=b;
  2127. end;
  2128. writeln;
  2129. end;
  2130. end;
  2131. constnil:
  2132. begin
  2133. writeln([space,' NIL pointer.']);
  2134. constdef.ConstType:=ctPtr;
  2135. constdef.VInt:=0;
  2136. end;
  2137. constwstring :
  2138. begin
  2139. initwidestring(pw);
  2140. setlengthwidestring(pw,getlongint);
  2141. if widecharsize=2 then
  2142. { don't use getdata, because the compilerwidechars may have to
  2143. be byteswapped
  2144. }
  2145. begin
  2146. for i:=0 to pw^.len-1 do
  2147. pw^.data[i]:=ppufile.getword;
  2148. end
  2149. else if widecharsize=4 then
  2150. begin
  2151. for i:=0 to pw^.len-1 do
  2152. pw^.data[i]:=cardinal(ppufile.getlongint);
  2153. end
  2154. else
  2155. begin
  2156. WriteError('Unsupported tcompilerwidechar size');
  2157. end;
  2158. Writeln([space,'Wide string type']);
  2159. startnewline:=true;
  2160. for i:=0 to pw^.len-1 do
  2161. begin
  2162. if startnewline then
  2163. begin
  2164. write(space);
  2165. startnewline:=false;
  2166. end;
  2167. ch:=pw^.data[i];
  2168. if widecharsize=2 then
  2169. write(hexstr(ch,4))
  2170. else
  2171. write(hexstr(ch,8));
  2172. if (i mod 8)= 0 then
  2173. startnewline:=true
  2174. else
  2175. write(', ');
  2176. end;
  2177. donewidestring(pw);
  2178. end;
  2179. constguid:
  2180. begin
  2181. getdata(guid,sizeof(guid));
  2182. write ([space,' IID String: {',hexstr(guid.d1,8),'-',hexstr(guid.d2,4),'-',hexstr(guid.d3,4),'-']);
  2183. for i:=0 to 7 do
  2184. begin
  2185. write(hexstr(guid.d4[i],2));
  2186. if i=1 then write('-');
  2187. end;
  2188. writeln('}');
  2189. end
  2190. else
  2191. Writeln (['!! Invalid unit format : Invalid const type encountered: ',b]);
  2192. end;
  2193. end;
  2194. ibabsolutevarsym :
  2195. begin
  2196. def:=TPpuVarDef.Create(ParentDef);
  2197. readabstractvarsym('Absolute variable symbol ',varoptions,TPpuVarDef(def));
  2198. Write ([space,' Relocated to ']);
  2199. b:=getbyte;
  2200. case absolutetyp(b) of
  2201. tovar :
  2202. readpropaccesslist(space+' Sym : ');
  2203. toasm :
  2204. Writeln(['Assembler name : ',getstring]);
  2205. toaddr :
  2206. begin
  2207. Write(['Address : ',getlongint]);
  2208. if tsystemcpu(ppufile.header.cpu)=cpu_i386 then
  2209. WriteLn([' (Far: ',getbyte<>0,')']);
  2210. end;
  2211. else
  2212. Writeln (['!! Invalid unit format : Invalid absolute type encountered: ',b]);
  2213. end;
  2214. end;
  2215. ibfieldvarsym :
  2216. begin
  2217. def:=TPpuFieldDef.Create(ParentDef);
  2218. readabstractvarsym('Field Variable symbol ',varoptions,TPpuVarDef(def));
  2219. writeln([space,' Address : ',getaint]);
  2220. end;
  2221. ibstaticvarsym :
  2222. begin
  2223. def:=TPpuVarDef.Create(ParentDef);
  2224. readabstractvarsym('Global Variable symbol ',varoptions,TPpuVarDef(def));
  2225. write ([space,' DefaultConst : ']);
  2226. readderef('');
  2227. if (vo_has_mangledname in varoptions) then
  2228. {$ifdef symansistr}
  2229. writeln([space,' Mangledname : ',getansistring]);
  2230. {$else symansistr}
  2231. writeln([space,' Mangledname : ',getstring]);
  2232. {$endif symansistr}
  2233. end;
  2234. iblocalvarsym :
  2235. begin
  2236. readabstractvarsym('Local Variable symbol ',varoptions);
  2237. write ([space,' DefaultConst : ']);
  2238. readderef('');
  2239. end;
  2240. ibparavarsym :
  2241. begin
  2242. def:=TPpuParamDef.Create(ParentDef);
  2243. readabstractvarsym('Parameter Variable symbol ',varoptions,TPpuVarDef(def));
  2244. write ([space,' DefaultConst : ']);
  2245. readderef('',TPpuParamDef(def).DefaultValue);
  2246. writeln([space,' ParaNr : ',getword]);
  2247. writeln([space,' Univ : ',boolean(getbyte)]);
  2248. writeln([space,' VarState : ',getbyte]);
  2249. writeln([space,' Refs : ',getbyte]);
  2250. if (vo_has_explicit_paraloc in varoptions) then
  2251. begin
  2252. i:=getbyte;
  2253. getdata(tempbuf,i);
  2254. end;
  2255. end;
  2256. ibenumsym :
  2257. begin
  2258. def:=TPpuConstDef.Create(nil);
  2259. readcommonsym('Enumeration symbol ',def);
  2260. write ([space,' Definition : ']);
  2261. readderef('');
  2262. TPpuConstDef(def).ConstType:=ctInt;
  2263. TPpuConstDef(def).VInt:=getlongint;
  2264. writeln([space,' Value : ',TPpuConstDef(def).VInt]);
  2265. if (ParentDef <> nil) and (ParentDef.DefType = dtEnum) then
  2266. def.Parent:=ParentDef;
  2267. end;
  2268. ibsyssym :
  2269. begin
  2270. readcommonsym('Internal system symbol ');
  2271. writeln([space,' Internal Nr : ',getlongint]);
  2272. end;
  2273. ibmacrosym :
  2274. begin
  2275. readcommonsym('Macro symbol ');
  2276. writeln([space,' Name: ',getstring]);
  2277. writeln([space,' Defined: ',getbyte]);
  2278. writeln([space,' Compiler var: ',getbyte]);
  2279. len:=getlongint;
  2280. writeln([space,' Value length: ',len]);
  2281. if len > 0 then
  2282. begin
  2283. getmem(pc,len+1);
  2284. getdata(pc^,len);
  2285. (pc+len)^:= #0;
  2286. writeln([space,' Value: "',pc,'"']);
  2287. freemem(pc,len+1);
  2288. end;
  2289. end;
  2290. ibpropertysym :
  2291. begin
  2292. def:=TPpuPropDef.Create(ParentDef);
  2293. readcommonsym('Property ',def);
  2294. propoptions:=readpropertyoptions;
  2295. if ppo_overrides in propoptions then
  2296. begin
  2297. write ([space,' OverrideProp : ']);
  2298. readderef('');
  2299. end;
  2300. write ([space,' Prop Type : ']);
  2301. readderef('',TPpuPropDef(def).PropType);
  2302. writeln([space,' Index : ',getlongint]);
  2303. writeln([space,' Default : ',getlongint]);
  2304. write ([space,' Index Type : ']);
  2305. readderef('');
  2306. { palt_none }
  2307. readpropaccesslist('');
  2308. write ([space,' Readaccess : ']);
  2309. readpropaccesslist(space+' Sym: ',TPpuPropDef(def).Getter);
  2310. write ([space,' Writeaccess : ']);
  2311. readpropaccesslist(space+' Sym: ',TPpuPropDef(def).Setter);
  2312. write ([space,' Storedaccess : ']);
  2313. readpropaccesslist(space+' Sym: ');
  2314. if [ppo_hasparameters,ppo_overrides]*propoptions=[ppo_hasparameters] then
  2315. begin
  2316. space:=' '+space;
  2317. readsymtable('parast',TPpuPropDef(def));
  2318. delete(space,1,4);
  2319. end;
  2320. end;
  2321. iberror :
  2322. begin
  2323. WriteError('!! Error in PPU');
  2324. exit;
  2325. end;
  2326. ibendsyms :
  2327. break;
  2328. else
  2329. begin
  2330. WriteLn(['!! Skipping unsupported PPU Entry in Symbols: ',b]);
  2331. SetHasErrors;
  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. WriteLn(['!! Skipping unsupported PPU Entry in definitions: ',b]);
  2950. SetHasErrors;
  2951. end;
  2952. end;
  2953. if (def <> nil) and (def.Parent = nil) then
  2954. def.Free;
  2955. if not EndOfEntry then
  2956. HasMoreInfos;
  2957. until false;
  2958. end;
  2959. end;
  2960. procedure readmoduleoptions(space : string);
  2961. type
  2962. { tmoduleoption type is in unit fmodule }
  2963. tmoduleoption = (mo_none,
  2964. mo_hint_deprecated,
  2965. mo_hint_platform,
  2966. mo_hint_library,
  2967. mo_hint_unimplemented,
  2968. mo_hint_experimental,
  2969. mo_has_deprecated_msg
  2970. );
  2971. tmoduleoptions = set of tmoduleoption;
  2972. tmoduleopt=record
  2973. mask : tmoduleoption;
  2974. str : string[30];
  2975. end;
  2976. const
  2977. moduleopts=ord(high(tmoduleoption));
  2978. moduleopt : array[1..moduleopts] of tmoduleopt=(
  2979. (mask:mo_hint_deprecated; str:'Hint Deprecated'),
  2980. (mask:mo_hint_platform; str:'Hint Platform'),
  2981. (mask:mo_hint_library; str:'Hint Library'),
  2982. (mask:mo_hint_unimplemented; str:'Hint Unimplemented'),
  2983. (mask:mo_hint_experimental; str:'Hint Experimental'),
  2984. (mask:mo_has_deprecated_msg; str:'Has Deprecated Message')
  2985. );
  2986. var
  2987. moduleoptions : tmoduleoptions;
  2988. i : longint;
  2989. first : boolean;
  2990. begin
  2991. ppufile.getsmallset(moduleoptions);
  2992. if moduleoptions<>[] then
  2993. begin
  2994. first:=true;
  2995. for i:=1to moduleopts do
  2996. if (moduleopt[i].mask in moduleoptions) then
  2997. begin
  2998. if first then
  2999. first:=false
  3000. else
  3001. write(', ');
  3002. write(moduleopt[i].str);
  3003. end;
  3004. end;
  3005. writeln;
  3006. if mo_has_deprecated_msg in moduleoptions then
  3007. writeln([space,'Deprecated : ', ppufile.getstring]);
  3008. end;
  3009. {****************************************************************************
  3010. Read General Part
  3011. ****************************************************************************}
  3012. procedure readinterface;
  3013. var
  3014. b : byte;
  3015. sourcenumber, i : longint;
  3016. begin
  3017. with ppufile do
  3018. begin
  3019. repeat
  3020. b:=readentry;
  3021. case b of
  3022. ibmodulename :
  3023. begin
  3024. CurUnit.Name:=getstring;
  3025. Writeln(['Module Name: ',CurUnit.Name]);
  3026. end;
  3027. ibmoduleoptions:
  3028. readmoduleoptions(' ');
  3029. ibsourcefiles :
  3030. begin
  3031. sourcenumber:=1;
  3032. while not EndOfEntry do
  3033. begin
  3034. with TPpuSrcFile.Create(CurUnit.SourceFiles) do begin
  3035. Name:=getstring;
  3036. i:=getlongint;
  3037. if i >= 0 then
  3038. FileTime:=FileDateToDateTime(i);
  3039. Writeln(['Source file ',sourcenumber,' : ',Name,' ',filetimestring(i)]);
  3040. end;
  3041. inc(sourcenumber);
  3042. end;
  3043. end;
  3044. {$IFDEF MACRO_DIFF_HINT}
  3045. ibusedmacros :
  3046. begin
  3047. while not EndOfEntry do
  3048. begin
  3049. Write('Conditional ',getstring);
  3050. b:=getbyte;
  3051. if boolean(b)=true then
  3052. write(' defined at startup')
  3053. else
  3054. write(' not defined at startup');
  3055. b:=getbyte;
  3056. if boolean(b)=true then
  3057. writeln(' was used')
  3058. else
  3059. writeln;
  3060. end;
  3061. end;
  3062. {$ENDIF}
  3063. ibloadunit :
  3064. ReadLoadUnit;
  3065. iblinkunitofiles :
  3066. ReadLinkContainer('Link unit object file: ');
  3067. iblinkunitstaticlibs :
  3068. ReadLinkContainer('Link unit static lib: ');
  3069. iblinkunitsharedlibs :
  3070. ReadLinkContainer('Link unit shared lib: ');
  3071. iblinkotherofiles :
  3072. ReadLinkContainer('Link other object file: ');
  3073. iblinkotherstaticlibs :
  3074. ReadLinkContainer('Link other static lib: ');
  3075. iblinkothersharedlibs :
  3076. ReadLinkContainer('Link other shared lib: ');
  3077. iblinkotherframeworks:
  3078. ReadLinkContainer('Link framework: ');
  3079. ibmainname:
  3080. Writeln(['Specified main program symbol name: ',getstring]);
  3081. ibImportSymbols :
  3082. ReadImportSymbols;
  3083. ibderefdata :
  3084. ReadDerefData;
  3085. ibderefmap :
  3086. ReadDerefMap;
  3087. ibwpofile :
  3088. ReadWpoFileInfo;
  3089. ibresources :
  3090. ReadLinkContainer('Resource file: ');
  3091. iberror :
  3092. begin
  3093. WriteError('Error in PPU');
  3094. exit;
  3095. end;
  3096. ibendinterface :
  3097. break;
  3098. else
  3099. begin
  3100. WriteLn(['!! Skipping unsupported PPU Entry in General Part: ',b]);
  3101. SetHasErrors;
  3102. end;
  3103. end;
  3104. until false;
  3105. end;
  3106. end;
  3107. {****************************************************************************
  3108. Read Implementation Part
  3109. ****************************************************************************}
  3110. procedure readimplementation;
  3111. var
  3112. b : byte;
  3113. begin
  3114. with ppufile do
  3115. begin
  3116. repeat
  3117. b:=readentry;
  3118. case b of
  3119. ibasmsymbols :
  3120. ReadAsmSymbols;
  3121. ibloadunit :
  3122. ReadLoadUnit;
  3123. iberror :
  3124. begin
  3125. WriteError('Error in PPU');
  3126. exit;
  3127. end;
  3128. ibendimplementation :
  3129. break;
  3130. else
  3131. begin
  3132. WriteLn(['!! Skipping unsupported PPU Entry in Implementation: ',b]);
  3133. SetHasErrors;
  3134. end;
  3135. end;
  3136. until false;
  3137. end;
  3138. end;
  3139. procedure dofile (filename : string);
  3140. begin
  3141. { reset }
  3142. space:='';
  3143. { fix filename }
  3144. if pos('.',filename)=0 then
  3145. filename:=filename+'.ppu';
  3146. ppufile:=tppufile.create(filename);
  3147. if not ppufile.openfile then
  3148. begin
  3149. WriteError('IO-Error when opening : '+filename+', Skipping');
  3150. exit;
  3151. end;
  3152. { PPU File is open, check for PPU Id }
  3153. if not ppufile.CheckPPUID then
  3154. begin
  3155. writeln([Filename,' : Not a valid PPU file, Skipping']);
  3156. SetHasErrors;
  3157. exit;
  3158. end;
  3159. { Check PPU Version }
  3160. ppuversion:=ppufile.GetPPUVersion;
  3161. Writeln(['Analyzing ',filename,' (v',PPUVersion,')']);
  3162. if PPUVersion<16 then
  3163. begin
  3164. writeln([Filename,' : Old PPU Formats (<v16) are not supported, Skipping']);
  3165. SetHasErrors;
  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(' -M Exit with ExitCode=2 if more information is available');
  3318. writeln(' -V<verbose> Set verbosity to <verbose>');
  3319. writeln(' H - Show header info');
  3320. writeln(' I - Show interface');
  3321. writeln(' M - Show implementation');
  3322. writeln(' S - Show interface symbols');
  3323. writeln(' D - Show interface definitions');
  3324. // writeln(' B - Show browser info');
  3325. writeln(' A - Show all');
  3326. writeln(' -h, -? This helpscreen');
  3327. halt;
  3328. end;
  3329. var
  3330. startpara,
  3331. nrfile,i : longint;
  3332. para : string;
  3333. const
  3334. error_on_more : boolean = false;
  3335. begin
  3336. if paramcount<1 then
  3337. help;
  3338. { turn verbose on by default }
  3339. verbose:=v_all;
  3340. { read options }
  3341. startpara:=1;
  3342. while copy(paramstr(startpara),1,1)='-' do
  3343. begin
  3344. para:=paramstr(startpara);
  3345. case upcase(para[2]) of
  3346. 'F' : begin
  3347. FreeAndNil(pout);
  3348. if Length(para) > 2 then
  3349. case upcase(para[3]) of
  3350. 'T':
  3351. nostdout:=False;
  3352. 'J':
  3353. begin
  3354. nostdout:=True;
  3355. pout:=TPpuJsonOutput.Create(Output);
  3356. end;
  3357. else
  3358. begin
  3359. WriteError('Invalid output format: ' + para[3]);
  3360. Halt(1);
  3361. end;
  3362. end;
  3363. end;
  3364. 'M' : error_on_more:=true;
  3365. 'V' : begin
  3366. verbose:=0;
  3367. for i:=3 to length(para) do
  3368. case upcase(para[i]) of
  3369. 'H' : verbose:=verbose or v_header;
  3370. 'I' : verbose:=verbose or v_interface;
  3371. 'M' : verbose:=verbose or v_implementation;
  3372. 'D' : verbose:=verbose or v_defs;
  3373. 'S' : verbose:=verbose or v_syms;
  3374. 'A' : verbose:=verbose or v_all;
  3375. end;
  3376. end;
  3377. 'H' : help;
  3378. '?' : help;
  3379. else
  3380. begin
  3381. WriteError('Invalid option: ' + para);
  3382. Halt(1);
  3383. end;
  3384. end;
  3385. inc(startpara);
  3386. end;
  3387. if not nostdout then
  3388. WriteLogo;
  3389. UnitList:=TPpuContainerDef.Create(nil);
  3390. try
  3391. UnitList.ItemsName:='';
  3392. { process files }
  3393. for nrfile:=startpara to paramcount do
  3394. dofile (paramstr(nrfile));
  3395. if not has_errors and (pout <> nil) then
  3396. UnitList.Write(pout);
  3397. finally
  3398. UnitList.Free;
  3399. pout.Free;
  3400. end;
  3401. if has_errors then
  3402. Halt(1);
  3403. if error_on_more and has_more_infos then
  3404. Halt(2);
  3405. end.