ppudump.pp 112 KB

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