ppudump.pp 110 KB

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