2
0

ppudump.pp 116 KB

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