ppudump.pp 118 KB

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