ppudump.pp 115 KB

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