ppudump.pp 116 KB

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