ppudump.pp 118 KB

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