ppudump.pp 111 KB

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