ppudump.pp 113 KB

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