2
0

ppudump.pp 115 KB

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