ppudump.pp 113 KB

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