ppudump.pp 115 KB

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