ppudump.pp 112 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778
  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. proctypeoption:=tproctypeoption(ppufile.getbyte);
  1638. case proctypeoption of
  1639. potype_function: Include(ProcDef.Options, poFunction);
  1640. potype_procedure: Include(ProcDef.Options, poProcedure);
  1641. potype_constructor: Include(ProcDef.Options, poConstructor);
  1642. potype_destructor: Include(ProcDef.Options, poDestructor);
  1643. potype_operator: Include(ProcDef.Options, poOperator);
  1644. end;
  1645. write([space,' TypeOption : ']);
  1646. first:=true;
  1647. for i:=1 to high(proctypeopt) do
  1648. if (proctypeopt[i].mask=proctypeoption) then
  1649. begin
  1650. if first then
  1651. first:=false
  1652. else
  1653. write(', ');
  1654. write(proctypeopt[i].str);
  1655. end;
  1656. writeln;
  1657. proccalloption:=tproccalloption(ppufile.getbyte);
  1658. writeln([space,' CallOption : ',proccalloptionStr[proccalloption]]);
  1659. ppufile.getnormalset(procoptions);
  1660. if procoptions<>[] then
  1661. begin
  1662. if po_classmethod in procoptions then Include(ProcDef.Options, poClassMethod);
  1663. if po_virtualmethod in procoptions then Include(ProcDef.Options, poVirtual);
  1664. if po_abstractmethod in procoptions then Include(ProcDef.Options, poAbstract);
  1665. if po_overridingmethod in procoptions then Include(ProcDef.Options, poOverriding);
  1666. if po_overload in procoptions then Include(ProcDef.Options, poOverload);
  1667. if po_inline in procoptions then Include(ProcDef.Options, poInline);
  1668. if (po_methodpointer in procoptions) and (ProcDef.DefType = dtProcType) then
  1669. TPpuProcTypeDef(ProcDef).MethodPtr:=True;
  1670. write([space,' Options : ']);
  1671. first:=true;
  1672. for i:=1 to high(procopt) do
  1673. if (procopt[i].mask in procoptions) then
  1674. begin
  1675. if first then
  1676. first:=false
  1677. else
  1678. write(', ');
  1679. write(procopt[i].str);
  1680. end;
  1681. writeln;
  1682. end;
  1683. if (po_explicitparaloc in procoptions) then
  1684. begin
  1685. i:=ppufile.getbyte;
  1686. ppufile.getdata(tempbuf,i);
  1687. end;
  1688. end;
  1689. { type tvaroption is in unit symconst }
  1690. { register variable }
  1691. { type tvarregable is in unit symconst }
  1692. procedure readabstractvarsym(const s:string;var varoptions:tvaroptions; VarDef: TPpuVarDef = nil);
  1693. type
  1694. tvaropt=record
  1695. mask : tvaroption;
  1696. str : string[30];
  1697. end;
  1698. const
  1699. varopt : array[1..ord(high(tvaroption))] of tvaropt=(
  1700. (mask:vo_is_external; str:'External'),
  1701. (mask:vo_is_dll_var; str:'DLLVar'),
  1702. (mask:vo_is_thread_var; str:'ThreadVar'),
  1703. (mask:vo_has_local_copy; str:'HasLocalCopy'),
  1704. (mask:vo_is_const; str:'Constant'),
  1705. (mask:vo_is_public; str:'Public'),
  1706. (mask:vo_is_high_para; str:'HighValue'),
  1707. (mask:vo_is_funcret; str:'Funcret'),
  1708. (mask:vo_is_self; str:'Self'),
  1709. (mask:vo_is_vmt; str:'VMT'),
  1710. (mask:vo_is_result; str:'Result'),
  1711. (mask:vo_is_parentfp; str:'ParentFP'),
  1712. (mask:vo_is_loop_counter; str:'LoopCounter'),
  1713. (mask:vo_is_hidden_para; str:'Hidden'),
  1714. (mask:vo_has_explicit_paraloc;str:'ExplicitParaloc'),
  1715. (mask:vo_is_syscall_lib; str:'SysCallLib'),
  1716. (mask:vo_has_mangledname; str:'HasMangledName'),
  1717. (mask:vo_is_typed_const; str:'TypedConst'),
  1718. (mask:vo_is_range_check; str:'RangeCheckSwitch'),
  1719. (mask:vo_is_overflow_check; str:'OverflowCheckSwitch'),
  1720. (mask:vo_is_typinfo_para; str:'TypeInfo'),
  1721. (mask:vo_is_msgsel;str:'MsgSel'),
  1722. (mask:vo_is_weak_external;str:'WeakExternal'),
  1723. (mask:vo_is_first_field;str:'IsFirstField'),
  1724. (mask:vo_volatile; str:'Volatile'),
  1725. (mask:vo_has_section; str:'HasSection'),
  1726. (mask:vo_force_finalize; str:'ForceFinalize'),
  1727. (mask:vo_is_default_var; str:'DefaultIntrinsicVar')
  1728. );
  1729. var
  1730. i : longint;
  1731. first : boolean;
  1732. begin
  1733. readcommonsym(s, VarDef);
  1734. i:=ppufile.getbyte;
  1735. if (VarDef <> nil) and (VarDef.DefType = dtParam) then
  1736. with TPpuParamDef(VarDef) do
  1737. case tvarspez(i) of
  1738. vs_value: Spez:=psValue;
  1739. vs_var: Spez:=psVar;
  1740. vs_out: Spez:=psOut;
  1741. vs_const: Spez:=psConst;
  1742. vs_constref: Spez:=psConstRef;
  1743. end;
  1744. writeln([space,' Spez : ',Varspez2Str(i)]);
  1745. writeln([space,' Regable : ',Varregable2Str(ppufile.getbyte)]);
  1746. writeln([space,' Addr Taken : ',(ppufile.getbyte<>0)]);
  1747. write ([space,' Var Type : ']);
  1748. if VarDef <> nil then
  1749. readderef('',VarDef.VarType)
  1750. else
  1751. readderef('');
  1752. ppufile.getsmallset(varoptions);
  1753. if varoptions<>[] then
  1754. begin
  1755. if (VarDef <> nil) and (VarDef.DefType = dtParam) and (vo_is_hidden_para in varoptions) then
  1756. TPpuParamDef(VarDef).Spez:=psHidden;
  1757. write([space,' Options : ']);
  1758. first:=true;
  1759. for i:=1 to high(varopt) do
  1760. if (varopt[i].mask in varoptions) then
  1761. begin
  1762. if first then
  1763. first:=false
  1764. else
  1765. write(', ');
  1766. write(varopt[i].str);
  1767. end;
  1768. writeln;
  1769. end;
  1770. end;
  1771. procedure readobjectdefoptions(ObjDef: TPpuObjectDef = nil);
  1772. type
  1773. tsymopt=record
  1774. mask : tobjectoption;
  1775. str : string[30];
  1776. end;
  1777. const
  1778. symopt : array[1..ord(high(tobjectoption))] of tsymopt=(
  1779. (mask:oo_is_forward; str:'IsForward'),
  1780. (mask:oo_is_abstract; str:'IsAbstract'),
  1781. (mask:oo_is_sealed; str:'IsSealed'),
  1782. (mask:oo_has_virtual; str:'HasVirtual'),
  1783. (mask:oo_has_private; str:'HasPrivate'),
  1784. (mask:oo_has_protected; str:'HasProtected'),
  1785. (mask:oo_has_strictprivate; str:'HasStrictPrivate'),
  1786. (mask:oo_has_strictprotected;str:'HasStrictProtected'),
  1787. (mask:oo_has_constructor; str:'HasConstructor'),
  1788. (mask:oo_has_destructor; str:'HasDestructor'),
  1789. (mask:oo_has_vmt; str:'HasVMT'),
  1790. (mask:oo_has_msgstr; str:'HasMsgStr'),
  1791. (mask:oo_has_msgint; str:'HasMsgInt'),
  1792. (mask:oo_can_have_published; str:'CanHavePublished'),
  1793. (mask:oo_has_default_property;str:'HasDefaultProperty'),
  1794. (mask:oo_has_valid_guid; str:'HasValidGUID'),
  1795. (mask:oo_has_enumerator_movenext; str:'HasEnumeratorMoveNext'),
  1796. (mask:oo_has_enumerator_current; str:'HasEnumeratorCurrent'),
  1797. (mask:oo_is_external; str:'External'),
  1798. (mask:oo_is_formal; str:'Formal'),
  1799. (mask:oo_is_classhelper; str:'Class Helper/Category'),
  1800. (mask:oo_has_class_constructor; str:'HasClassConstructor'),
  1801. (mask:oo_has_class_destructor; str:'HasClassDestructor'),
  1802. (mask:oo_is_enum_class; str:'JvmEnumClass'),
  1803. (mask:oo_has_new_destructor; str:'HasNewDestructor')
  1804. );
  1805. var
  1806. i : longint;
  1807. first : boolean;
  1808. begin
  1809. ppufile.getsmallset(current_objectoptions);
  1810. if current_objectoptions<>[] then
  1811. begin
  1812. if ObjDef <> nil then
  1813. begin
  1814. if oo_is_abstract in current_objectoptions then
  1815. Include(ObjDef.Options, ooIsAbstract);
  1816. end;
  1817. first:=true;
  1818. for i:=1 to high(symopt) do
  1819. if (symopt[i].mask in current_objectoptions) then
  1820. begin
  1821. if first then
  1822. first:=false
  1823. else
  1824. write(', ');
  1825. write(symopt[i].str);
  1826. end;
  1827. end;
  1828. writeln;
  1829. end;
  1830. procedure readprocimploptions(const space: string; out implprocoptions: timplprocoptions);
  1831. type
  1832. tpiopt=record
  1833. mask : timplprocoption;
  1834. str : string[30];
  1835. end;
  1836. const
  1837. piopt : array[low(timplprocoption)..high(timplprocoption)] of tpiopt=(
  1838. (mask:pio_empty; str:'IsEmpty'),
  1839. (mask:pio_has_inlininginfo; str:'HasInliningInfo')
  1840. );
  1841. var
  1842. i: timplprocoption;
  1843. first: boolean;
  1844. begin
  1845. ppufile.getsmallset(implprocoptions);
  1846. if implprocoptions<>[] then
  1847. begin
  1848. first:=true;
  1849. write([space,' Options : ']);
  1850. for i:=low(piopt) to high(piopt) do
  1851. begin
  1852. if i in implprocoptions then
  1853. begin
  1854. if first then
  1855. first:=false
  1856. else
  1857. write(', ');
  1858. write(piopt[i].str);
  1859. end;
  1860. end;
  1861. writeln;
  1862. end;
  1863. end;
  1864. procedure readarraydefoptions(ArrayDef: TPpuArrayDef);
  1865. { type tarraydefoption is in unit symconst }
  1866. const
  1867. symopt : array[tarraydefoption] of string = (
  1868. { ado_IsConvertedPointer } 'ConvertedPointer',
  1869. { ado_IsDynamicArray } 'IsDynamicArray',
  1870. { ado_IsVariant } 'IsVariant',
  1871. { ado_IsConstructor } 'IsConstructor',
  1872. { ado_IsArrayOfConst } 'ArrayOfConst',
  1873. { ado_IsConstString } 'ConstString',
  1874. { ado_IsBitPacked } 'BitPacked'
  1875. );
  1876. var
  1877. symoptions: tarraydefoptions;
  1878. i: tarraydefoption;
  1879. first: boolean;
  1880. begin
  1881. ppufile.getsmallset(symoptions);
  1882. if symoptions<>[] then
  1883. begin
  1884. if ado_IsDynamicArray in symoptions then Include(ArrayDef.Options, aoDynamic);
  1885. first:=true;
  1886. for i:=Low(symopt) to high(symopt) do
  1887. if (i in symoptions) then
  1888. begin
  1889. if first then
  1890. first:=false
  1891. else
  1892. write(', ');
  1893. write(symopt[i]);
  1894. end;
  1895. end;
  1896. writeln;
  1897. end;
  1898. (* options for properties
  1899. tpropertyoption=(ppo_none,
  1900. ppo_indexed,
  1901. ppo_defaultproperty,
  1902. ppo_stored,
  1903. ppo_hasparameters,
  1904. ppo_implements,
  1905. ppo_enumerator_current,
  1906. ppo_overrides,
  1907. ppo_dispid_write { no longer used }
  1908. );
  1909. tpropertyoptions=set of tpropertyoption;
  1910. *)
  1911. function readpropertyoptions:tpropertyoptions;
  1912. { type tarraydefoption is in unit symconst }
  1913. type
  1914. tpropopt=record
  1915. mask : tpropertyoption;
  1916. str : string[30];
  1917. end;
  1918. const
  1919. symopt : array[1..ord(high(tpropertyoption))] of tpropopt=(
  1920. (mask:ppo_indexed;str:'indexed'),
  1921. (mask:ppo_defaultproperty;str:'default'),
  1922. (mask:ppo_stored;str:'stored'),
  1923. (mask:ppo_hasparameters;str:'has parameters'),
  1924. (mask:ppo_implements;str:'implements'),
  1925. (mask:ppo_enumerator_current;str:'enumerator current'),
  1926. (mask:ppo_overrides;str:'overrides'),
  1927. (mask:ppo_dispid_write;str:'dispid write') { no longer used }
  1928. );
  1929. var
  1930. i : longint;
  1931. first : boolean;
  1932. begin
  1933. ppufile.getsmallset(result);
  1934. if result<>[] then
  1935. begin
  1936. first:=true;
  1937. for i:=1 to high(symopt) do
  1938. if (symopt[i].mask in result) then
  1939. begin
  1940. if first then
  1941. first:=false
  1942. else
  1943. write(', ');
  1944. write(symopt[i].str);
  1945. end;
  1946. end;
  1947. writeln;
  1948. end;
  1949. procedure readnodetree;
  1950. var
  1951. l : longint;
  1952. p : pointer;
  1953. begin
  1954. with ppufile do
  1955. begin
  1956. if space<>'' then
  1957. Writeln([space,'------ nodetree ------']);
  1958. if readentry=ibnodetree then
  1959. begin
  1960. l:=entrysize;
  1961. Writeln([space,'Tree size : ',l]);
  1962. { Read data to prevent error that entry is not completly read }
  1963. getmem(p,l);
  1964. getdata(p^,l);
  1965. freemem(p);
  1966. end
  1967. else
  1968. begin
  1969. WriteError('!! ibnodetree not found');
  1970. end;
  1971. end;
  1972. end;
  1973. procedure ReadCreatedObjTypes;
  1974. var
  1975. i,j,
  1976. len,
  1977. bssize: longint;
  1978. bs: pbyte;
  1979. begin
  1980. if ppufile.readentry<>ibcreatedobjtypes then
  1981. begin
  1982. WriteError('!! ibcreatedobjtypes entry not found');
  1983. ppufile.skipdata(ppufile.entrysize);
  1984. exit
  1985. end;
  1986. writeln;
  1987. writeln([space,'WPO info']);
  1988. writeln([space,'--------']);
  1989. len:=ppufile.getlongint;
  1990. writeln([space,'** Instantiated Object/Class types: ',len,' **']);
  1991. space:=space+' ';
  1992. for i:=0 to len-1 do
  1993. readderef(space);
  1994. setlength(space,length(space)-2);
  1995. len:=ppufile.getlongint;
  1996. writeln([space,'** Instantiated ClassRef types: ',len,' **']);
  1997. space:=space+' ';
  1998. for i:=0 to len-1 do
  1999. readderef(space);
  2000. setlength(space,length(space)-2);
  2001. len:=ppufile.getlongint;
  2002. writeln([space,'** Possibly instantiated ClassRef types : ',len,' **']);
  2003. space:=space+' ';
  2004. for i:=0 to len-1 do
  2005. readderef(space);
  2006. setlength(space,length(space)-2);
  2007. len:=ppufile.getlongint;
  2008. writeln([space,'** Class types with called virtual methods info : ',len,' **']);
  2009. space:=space+' ';
  2010. for i:=0 to len-1 do
  2011. begin
  2012. write([space,'Class def : ']);
  2013. readderef('');
  2014. write([space+' ','Called vmtentries : ']);
  2015. bssize:=ppufile.getlongint;
  2016. getmem(bs,bssize);
  2017. ppufile.readdata(bs^,bssize);
  2018. for j:=0 to bssize*8-1 do
  2019. if (((bs+j shr 3)^ shr (j and 7)) and 1) <> 0 then
  2020. write([j,', ']);
  2021. writeln;
  2022. freemem(bs);
  2023. end;
  2024. setlength(space,length(space)-2);
  2025. end;
  2026. {****************************************************************************
  2027. Read Symbols Part
  2028. ****************************************************************************}
  2029. procedure readsymbols(const s:string; ParentDef: TPpuContainerDef = nil);
  2030. function _finddef(symdef: TPpuDef): TPpuDef;
  2031. begin
  2032. Result:=nil;
  2033. if symdef.Ref.IsCurUnit then
  2034. begin;
  2035. Result:=CurUnit.FindById(symdef.Ref.Id);
  2036. if (Result <> nil) and (Result.Ref.Id = symdef.Id) then
  2037. begin
  2038. Result.Name:=symdef.Name;
  2039. Result.FilePos:=symdef.FilePos;
  2040. end
  2041. else
  2042. Result:=nil;
  2043. end;
  2044. end;
  2045. type
  2046. pguid = ^tguid;
  2047. tguid = packed record
  2048. D1: LongWord;
  2049. D2: Word;
  2050. D3: Word;
  2051. D4: array[0..7] of Byte;
  2052. end;
  2053. var
  2054. b : byte;
  2055. pc : pchar;
  2056. ch : dword;
  2057. startnewline : boolean;
  2058. i,j,len : longint;
  2059. prettyname, ss : ansistring;
  2060. ws: widestring;
  2061. guid : tguid;
  2062. realvalue : ppureal;
  2063. doublevalue : double;
  2064. singlevalue : single;
  2065. extended : TSplit80bitReal;
  2066. tempbuf : array[0..127] of char;
  2067. pw : pcompilerwidestring;
  2068. varoptions : tvaroptions;
  2069. propoptions : tpropertyoptions;
  2070. iexp: Tconstexprint;
  2071. def: TPpuDef;
  2072. constdef: TPpuConstDef absolute def;
  2073. begin
  2074. with ppufile do
  2075. begin
  2076. if space<>'' then
  2077. Writeln([space,'------ ',s,' ------']);
  2078. if readentry=ibstartsyms then
  2079. begin
  2080. Writeln([space,'Symtable datasize : ',getlongint]);
  2081. Writeln([space,'Symtable alignment: ',getlongint]);
  2082. end
  2083. else
  2084. Writeln('!! ibstartsym not found');
  2085. repeat
  2086. def:=nil;
  2087. b:=readentry;
  2088. case b of
  2089. ibunitsym :
  2090. readcommonsym('Unit symbol ');
  2091. ibnamespacesym :
  2092. begin
  2093. readcommonsym('NameSpace symbol ');
  2094. write([space,' Hidden Unit : ']);
  2095. readderef('');
  2096. end;
  2097. iblabelsym :
  2098. readcommonsym('Label symbol ');
  2099. ibtypesym :
  2100. begin
  2101. def:=TPpuTypeRef.Create(nil);
  2102. readcommonsym('Type symbol ',def);
  2103. write([space,' Result Type : ']);
  2104. readderef('', def.Ref);
  2105. if _finddef(def) = nil then
  2106. def.Parent:=ParentDef;
  2107. prettyname:=getansistring;
  2108. if prettyname<>'' then
  2109. begin
  2110. write([space,' Pretty Name : ']);
  2111. Writeln(prettyname);
  2112. end;
  2113. end;
  2114. ibprocsym :
  2115. begin
  2116. def:=TPpuDef.Create(nil);
  2117. readcommonsym('Procedure symbol ', def);
  2118. len:=ppufile.getword;
  2119. for i:=1 to len do
  2120. begin
  2121. write([space,' Definition : ']);
  2122. readderef('', def.Ref);
  2123. _finddef(def);
  2124. end;
  2125. end;
  2126. ibconstsym :
  2127. begin
  2128. constdef:=TPpuConstDef.Create(ParentDef);
  2129. readcommonsym('Constant symbol ',constdef);
  2130. b:=getbyte;
  2131. case tconsttyp(b) of
  2132. constord :
  2133. begin
  2134. write ([space,' OrdinalType : ']);
  2135. readderef('',constdef.TypeRef);
  2136. iexp:=getexprint;
  2137. constdef.ConstType:=ctInt;
  2138. constdef.VInt:=iexp.svalue;
  2139. writeln([space,' Value : ',constexp.tostr(iexp)]);
  2140. end;
  2141. constpointer :
  2142. begin
  2143. write ([space,' PointerType : ']);
  2144. readderef('',constdef.TypeRef);
  2145. constdef.ConstType:=ctInt;
  2146. constdef.VInt:=getaint;
  2147. writeln([space,' Value : ',constdef.VInt])
  2148. end;
  2149. conststring,
  2150. constresourcestring :
  2151. begin
  2152. len:=getlongint;
  2153. getmem(pc,len+1);
  2154. getdata(pc^,len);
  2155. (pc+len)^:= #0;
  2156. writeln([space,' Length : ',len]);
  2157. writeln([space,' Value : "',pc,'"']);
  2158. constdef.ConstType:=ctStr;
  2159. SetString(constdef.VStr, pc, len);
  2160. constdef.VStr:=UTF8Encode(constdef.VStr);
  2161. freemem(pc,len+1);
  2162. end;
  2163. constreal :
  2164. begin
  2165. constdef.ConstType:=ctFloat;
  2166. write ([space,' RealType : ']);
  2167. readderef('',constdef.TypeRef);
  2168. write([space,' Value : ']);
  2169. if entryleft=sizeof(ppureal) then
  2170. begin
  2171. realvalue:=getrealsize(sizeof(ppureal));
  2172. constdef.VFloat:=realvalue;
  2173. writeln([realvalue]);
  2174. end
  2175. else if entryleft=sizeof(double) then
  2176. begin
  2177. doublevalue:=getrealsize(sizeof(double));
  2178. constdef.VFloat:=doublevalue;
  2179. writeln([doublevalue]);
  2180. end
  2181. else if entryleft=sizeof(single) then
  2182. begin
  2183. singlevalue:=getrealsize(sizeof(single));
  2184. constdef.VFloat:=singlevalue;
  2185. writeln([singlevalue]);
  2186. end
  2187. else if entryleft=10 then
  2188. begin
  2189. getdata(extended,entryleft);
  2190. ss:=Real80bitToStr(extended);
  2191. constdef.VFloat:=StrToFloat(ss);
  2192. writeln(ss);
  2193. end
  2194. else
  2195. begin
  2196. realvalue:=0.0;
  2197. WriteError('Error reading real value');
  2198. end;
  2199. end;
  2200. constset :
  2201. begin
  2202. constdef.ConstType:=ctSet;
  2203. write ([space,' Set Type : ']);
  2204. readderef('',constdef.TypeRef);
  2205. for i:=1to 4 do
  2206. begin
  2207. write ([space,' Value : ']);
  2208. for j:=1to 8 do
  2209. begin
  2210. if j>1 then
  2211. write(',');
  2212. b:=getbyte;
  2213. write(hexstr(b,2));
  2214. constdef.VSet[i*j-1]:=b;
  2215. end;
  2216. writeln;
  2217. end;
  2218. end;
  2219. constnil:
  2220. begin
  2221. writeln([space,' NIL pointer.']);
  2222. constdef.ConstType:=ctPtr;
  2223. constdef.VInt:=0;
  2224. end;
  2225. constwstring :
  2226. begin
  2227. initwidestring(pw);
  2228. setlengthwidestring(pw,getlongint);
  2229. if widecharsize=2 then
  2230. { don't use getdata, because the compilerwidechars may have to
  2231. be byteswapped
  2232. }
  2233. begin
  2234. for i:=0 to pw^.len-1 do
  2235. pw^.data[i]:=ppufile.getword;
  2236. SetString(ws, PWideChar(pw^.data), pw^.len);
  2237. constdef.VStr:=UTF8Encode(ws);
  2238. constdef.ConstType:=ctStr;
  2239. end
  2240. else if widecharsize=4 then
  2241. begin
  2242. for i:=0 to pw^.len-1 do
  2243. pw^.data[i]:=cardinal(ppufile.getlongint);
  2244. end
  2245. else
  2246. begin
  2247. WriteError('Unsupported tcompilerwidechar size');
  2248. end;
  2249. Write([space,'Wide string type']);
  2250. startnewline:=true;
  2251. for i:=0 to pw^.len-1 do
  2252. begin
  2253. if startnewline then
  2254. begin
  2255. writeln;
  2256. write(space);
  2257. startnewline:=false;
  2258. end;
  2259. ch:=pw^.data[i];
  2260. if widecharsize=2 then
  2261. write(hexstr(ch,4))
  2262. else
  2263. write(hexstr(ch,8));
  2264. if ((i + 1) mod 8)= 0 then
  2265. startnewline:=true
  2266. else
  2267. if i <> pw^.len-1 then
  2268. write(', ');
  2269. end;
  2270. donewidestring(pw);
  2271. Writeln;
  2272. end;
  2273. constguid:
  2274. begin
  2275. getdata(guid,sizeof(guid));
  2276. write ([space,' IID String: {',hexstr(guid.d1,8),'-',hexstr(guid.d2,4),'-',hexstr(guid.d3,4),'-']);
  2277. for i:=0 to 7 do
  2278. begin
  2279. write(hexstr(guid.d4[i],2));
  2280. if i=1 then write('-');
  2281. end;
  2282. writeln('}');
  2283. end
  2284. else
  2285. Writeln (['!! Invalid unit format : Invalid const type encountered: ',b]);
  2286. end;
  2287. end;
  2288. ibabsolutevarsym :
  2289. begin
  2290. def:=TPpuVarDef.Create(ParentDef);
  2291. readabstractvarsym('Absolute variable symbol ',varoptions,TPpuVarDef(def));
  2292. Write ([space,' Relocated to ']);
  2293. b:=getbyte;
  2294. case absolutetyp(b) of
  2295. tovar :
  2296. readpropaccesslist(space+' Sym : ');
  2297. toasm :
  2298. Writeln(['Assembler name : ',getstring]);
  2299. toaddr :
  2300. begin
  2301. Write(['Address : ',getaword]);
  2302. if tsystemcpu(ppufile.header.cpu)=cpu_i386 then
  2303. Write([' (Far: ',getbyte<>0,')']);
  2304. if tsystemcpu(ppufile.header.cpu)=cpu_i8086 then
  2305. if getbyte<>0 then
  2306. Write([' (Far: TRUE, Segment=',getaword,')'])
  2307. else
  2308. Write([' (Far: FALSE)']);
  2309. Writeln;
  2310. end;
  2311. else
  2312. Writeln (['!! Invalid unit format : Invalid absolute type encountered: ',b]);
  2313. end;
  2314. end;
  2315. ibfieldvarsym :
  2316. begin
  2317. def:=TPpuFieldDef.Create(ParentDef);
  2318. readabstractvarsym('Field Variable symbol ',varoptions,TPpuVarDef(def));
  2319. writeln([space,' Address : ',getaint]);
  2320. end;
  2321. ibstaticvarsym :
  2322. begin
  2323. def:=TPpuVarDef.Create(ParentDef);
  2324. readabstractvarsym('Global Variable symbol ',varoptions,TPpuVarDef(def));
  2325. write ([space,' DefaultConst : ']);
  2326. readderef('');
  2327. if (vo_has_mangledname in varoptions) then
  2328. {$ifdef symansistr}
  2329. writeln([space,' Mangledname : ',getansistring]);
  2330. {$else symansistr}
  2331. writeln([space,' Mangledname : ',getstring]);
  2332. {$endif symansistr}
  2333. if vo_has_section in varoptions then
  2334. writeln(['Section name:',ppufile.getansistring]);
  2335. write ([space,' FieldVarSymDeref: ']);
  2336. readderef('');
  2337. end;
  2338. iblocalvarsym :
  2339. begin
  2340. readabstractvarsym('Local Variable symbol ',varoptions);
  2341. write ([space,' DefaultConst : ']);
  2342. readderef('');
  2343. end;
  2344. ibparavarsym :
  2345. begin
  2346. def:=TPpuParamDef.Create(ParentDef);
  2347. readabstractvarsym('Parameter Variable symbol ',varoptions,TPpuVarDef(def));
  2348. write ([space,' DefaultConst : ']);
  2349. readderef('',TPpuParamDef(def).DefaultValue);
  2350. writeln([space,' ParaNr : ',getword]);
  2351. writeln([space,' Univ : ',boolean(getbyte)]);
  2352. writeln([space,' VarState : ',getbyte]);
  2353. writeln([space,' Refs : ',getbyte]);
  2354. if (vo_has_explicit_paraloc in varoptions) then
  2355. begin
  2356. i:=getbyte;
  2357. getdata(tempbuf,i);
  2358. end;
  2359. end;
  2360. ibenumsym :
  2361. begin
  2362. def:=TPpuConstDef.Create(nil);
  2363. readcommonsym('Enumeration symbol ',def);
  2364. write ([space,' Definition : ']);
  2365. readderef('');
  2366. TPpuConstDef(def).ConstType:=ctInt;
  2367. TPpuConstDef(def).VInt:=getlongint;
  2368. writeln([space,' Value : ',TPpuConstDef(def).VInt]);
  2369. if (ParentDef <> nil) and (ParentDef.DefType = dtEnum) then
  2370. def.Parent:=ParentDef;
  2371. end;
  2372. ibsyssym :
  2373. begin
  2374. readcommonsym('Internal system symbol ');
  2375. writeln([space,' Internal Nr : ',getlongint]);
  2376. end;
  2377. ibmacrosym :
  2378. begin
  2379. readcommonsym('Macro symbol ');
  2380. writeln([space,' Name: ',getstring]);
  2381. writeln([space,' Defined: ',getbyte]);
  2382. writeln([space,' Compiler var: ',getbyte]);
  2383. len:=getlongint;
  2384. writeln([space,' Value length: ',len]);
  2385. if len > 0 then
  2386. begin
  2387. getmem(pc,len+1);
  2388. getdata(pc^,len);
  2389. (pc+len)^:= #0;
  2390. writeln([space,' Value: "',pc,'"']);
  2391. freemem(pc,len+1);
  2392. end;
  2393. end;
  2394. ibpropertysym :
  2395. begin
  2396. def:=TPpuPropDef.Create(ParentDef);
  2397. readcommonsym('Property ',def);
  2398. propoptions:=readpropertyoptions;
  2399. if ppo_overrides in propoptions then
  2400. begin
  2401. write ([space,' OverrideProp : ']);
  2402. readderef('');
  2403. end;
  2404. if ppo_defaultproperty in propoptions then
  2405. Include(TPpuPropDef(def).Options, poDefault);
  2406. write ([space,' Prop Type : ']);
  2407. readderef('',TPpuPropDef(def).PropType);
  2408. writeln([space,' Index : ',getlongint]);
  2409. writeln([space,' Default : ',getlongint]);
  2410. write ([space,' Index Type : ']);
  2411. readderef('');
  2412. { palt_none }
  2413. readpropaccesslist('');
  2414. write ([space,' Readaccess : ']);
  2415. readpropaccesslist(space+' Sym: ',TPpuPropDef(def).Getter);
  2416. write ([space,' Writeaccess : ']);
  2417. readpropaccesslist(space+' Sym: ',TPpuPropDef(def).Setter);
  2418. write ([space,' Storedaccess : ']);
  2419. readpropaccesslist(space+' Sym: ');
  2420. if [ppo_hasparameters,ppo_overrides]*propoptions=[ppo_hasparameters] then
  2421. begin
  2422. space:=' '+space;
  2423. readsymtable('parast',TPpuPropDef(def));
  2424. delete(space,1,4);
  2425. end;
  2426. end;
  2427. iberror :
  2428. begin
  2429. WriteError('!! Error in PPU');
  2430. exit;
  2431. end;
  2432. ibendsyms :
  2433. break;
  2434. else
  2435. begin
  2436. WriteError('!! Skipping unsupported PPU Entry in Symbols: '+IntToStr(b));
  2437. end;
  2438. end;
  2439. if (def <> nil) and (def.Parent = nil) then
  2440. def.Free;
  2441. if not EndOfEntry then
  2442. HasMoreInfos;
  2443. until false;
  2444. end;
  2445. end;
  2446. {****************************************************************************
  2447. Read defintions Part
  2448. ****************************************************************************}
  2449. procedure readdefinitions(const s:string; ParentDef: TPpuContainerDef);
  2450. { type tordtype is in symconst unit }
  2451. {
  2452. uvoid,
  2453. u8bit,u16bit,u32bit,u64bit,
  2454. s8bit,s16bit,s32bit,s64bit,
  2455. bool8bit,bool16bit,bool32bit,bool64bit,
  2456. uchar,uwidechar,scurrency
  2457. ); }
  2458. { type tobjecttyp is in symconst unit }
  2459. { type tvarianttype is in symconst unit }
  2460. var
  2461. b : byte;
  2462. l,j : longint;
  2463. calloption : tproccalloption;
  2464. procoptions : tprocoptions;
  2465. implprocoptions: timplprocoptions;
  2466. defoptions: tdefoptions;
  2467. iexpr: Tconstexprint;
  2468. def: TPpuDef;
  2469. objdef: TPpuObjectDef absolute def;
  2470. arrdef: TPpuArrayDef absolute def;
  2471. enumdef: TPpuEnumDef absolute def;
  2472. setdef: TPpuSetDef absolute def;
  2473. orddef: TPpuOrdDef absolute def;
  2474. floatdef: TPpuFloatDef absolute def;
  2475. strdef: TPpuStringDef absolute def;
  2476. filedef: TPpuFileDef absolute def;
  2477. begin
  2478. with ppufile do
  2479. begin
  2480. if space<>'' then
  2481. Writeln([space,'------ ',s,' ------']);
  2482. if readentry<>ibstartdefs then
  2483. Writeln('!! ibstartdefs not found');
  2484. repeat
  2485. def:=nil;
  2486. b:=readentry;
  2487. case b of
  2488. ibpointerdef :
  2489. begin
  2490. def:=TPpuPointerDef.Create(ParentDef);
  2491. readcommondef('Pointer definition',defoptions,def);
  2492. write ([space,' Pointed Type : ']);
  2493. readderef('',TPpuPointerDef(def).Ptr);
  2494. writeln([space,' Has Pointer Math : ',(getbyte<>0)]);
  2495. if tsystemcpu(ppufile.header.cpu) in [cpu_i8086,cpu_i386,cpu_x86_64] then
  2496. begin
  2497. write([space,' X86 Pointer Type : ']);
  2498. b:=getbyte;
  2499. case tx86pointertyp(b) of
  2500. x86pt_near: writeln('Near');
  2501. x86pt_near_cs: writeln('Near ''CS''');
  2502. x86pt_near_ds: writeln('Near ''DS''');
  2503. x86pt_near_ss: writeln('Near ''SS''');
  2504. x86pt_near_es: writeln('Near ''ES''');
  2505. x86pt_near_fs: writeln('Near ''FS''');
  2506. x86pt_near_gs: writeln('Near ''GS''');
  2507. x86pt_far: writeln('Far');
  2508. x86pt_huge: writeln('Huge');
  2509. else
  2510. WriteWarning('Invalid x86 pointer type: ' + IntToStr(b));
  2511. end;
  2512. end;
  2513. end;
  2514. iborddef :
  2515. begin
  2516. orddef:=TPpuOrdDef.Create(ParentDef);
  2517. readcommondef('Ordinal definition',defoptions,orddef);
  2518. write ([space,' Base type : ']);
  2519. b:=getbyte;
  2520. case tordtype(b) of
  2521. uvoid:
  2522. begin
  2523. writeln('uvoid');
  2524. orddef.OrdType:=otVoid;
  2525. end;
  2526. u8bit:
  2527. begin
  2528. writeln('u8bit');
  2529. orddef.OrdType:=otUInt;
  2530. orddef.Size:=1;
  2531. end;
  2532. u16bit:
  2533. begin
  2534. writeln('u16bit');
  2535. orddef.OrdType:=otUInt;
  2536. orddef.Size:=2;
  2537. end;
  2538. u32bit:
  2539. begin
  2540. writeln('u32bit');
  2541. orddef.OrdType:=otUInt;
  2542. orddef.Size:=4;
  2543. end;
  2544. u64bit:
  2545. begin
  2546. writeln('u64bit');
  2547. orddef.OrdType:=otUInt;
  2548. orddef.Size:=8;
  2549. end;
  2550. s8bit:
  2551. begin
  2552. writeln('s8bit');
  2553. orddef.OrdType:=otSInt;
  2554. orddef.Size:=1;
  2555. end;
  2556. s16bit:
  2557. begin
  2558. writeln('s16bit');
  2559. orddef.OrdType:=otSInt;
  2560. orddef.Size:=2;
  2561. end;
  2562. s32bit:
  2563. begin
  2564. writeln('s32bit');
  2565. orddef.OrdType:=otSInt;
  2566. orddef.Size:=4;
  2567. end;
  2568. s64bit:
  2569. begin
  2570. writeln('s64bit');
  2571. orddef.OrdType:=otSInt;
  2572. orddef.Size:=8;
  2573. end;
  2574. pasbool8:
  2575. begin
  2576. writeln('pasbool8');
  2577. orddef.OrdType:=otPasBool;
  2578. orddef.Size:=1;
  2579. end;
  2580. pasbool16:
  2581. begin
  2582. writeln('pasbool16');
  2583. orddef.OrdType:=otPasBool;
  2584. orddef.Size:=2;
  2585. end;
  2586. pasbool32:
  2587. begin
  2588. writeln('pasbool32');
  2589. orddef.OrdType:=otPasBool;
  2590. orddef.Size:=4;
  2591. end;
  2592. pasbool64:
  2593. begin
  2594. writeln('pasbool64');
  2595. orddef.OrdType:=otPasBool;
  2596. orddef.Size:=8;
  2597. end;
  2598. bool8bit:
  2599. begin
  2600. writeln('bool8bit');
  2601. orddef.OrdType:=otBool;
  2602. orddef.Size:=1;
  2603. end;
  2604. bool16bit:
  2605. begin
  2606. writeln('bool16bit');
  2607. orddef.OrdType:=otBool;
  2608. orddef.Size:=2;
  2609. end;
  2610. bool32bit:
  2611. begin
  2612. writeln('bool32bit');
  2613. orddef.OrdType:=otBool;
  2614. orddef.Size:=4;
  2615. end;
  2616. bool64bit:
  2617. begin
  2618. writeln('bool64bit');
  2619. orddef.OrdType:=otBool;
  2620. orddef.Size:=8;
  2621. end;
  2622. uchar:
  2623. begin
  2624. writeln('uchar');
  2625. orddef.OrdType:=otChar;
  2626. orddef.Size:=1;
  2627. end;
  2628. uwidechar:
  2629. begin
  2630. writeln('uwidechar');
  2631. orddef.OrdType:=otChar;
  2632. orddef.Size:=2;
  2633. end;
  2634. scurrency:
  2635. begin
  2636. writeln('scurrency');
  2637. orddef.OrdType:=otCurrency;
  2638. orddef.Size:=8;
  2639. end;
  2640. else
  2641. WriteWarning('Invalid base type: ' + IntToStr(b));
  2642. end;
  2643. iexpr:=getexprint;
  2644. orddef.RangeLow:=iexpr.svalue;
  2645. write([space,' Range : ',constexp.tostr(iexpr)]);
  2646. iexpr:=getexprint;
  2647. orddef.RangeHigh:=iexpr.svalue;
  2648. writeln([' to ',constexp.tostr(iexpr)]);
  2649. end;
  2650. ibfloatdef :
  2651. begin
  2652. floatdef:=TPpuFloatDef.Create(ParentDef);
  2653. readcommondef('Float definition',defoptions,floatdef);
  2654. write ([space,' Float type : ']);
  2655. b:=getbyte;
  2656. case b of
  2657. ftSingle:
  2658. begin
  2659. writeln('Single');
  2660. floatdef.FloatType:=pftSingle;
  2661. end;
  2662. ftDouble:
  2663. begin
  2664. writeln('Double');
  2665. floatdef.FloatType:=pftDouble;
  2666. end;
  2667. ftExtended:
  2668. begin
  2669. writeln('Extended');
  2670. floatdef.FloatType:=pftExtended;
  2671. end;
  2672. ftComp:
  2673. begin
  2674. writeln('Comp');
  2675. floatdef.FloatType:=pftComp;
  2676. end;
  2677. ftCurr:
  2678. begin
  2679. writeln('Currency');
  2680. floatdef.FloatType:=pftCurrency;
  2681. end;
  2682. ftFloat128:
  2683. begin
  2684. writeln('Float128');
  2685. floatdef.FloatType:=pftFloat128;
  2686. end;
  2687. else
  2688. WriteWarning('Invalid float type: ' + IntToStr(b));
  2689. end;
  2690. end;
  2691. ibarraydef :
  2692. begin
  2693. arrdef:=TPpuArrayDef.Create(ParentDef);
  2694. readcommondef('Array definition',defoptions,arrdef);
  2695. write ([space,' Element type : ']);
  2696. readderef('',arrdef.ElType);
  2697. write ([space,' Range Type : ']);
  2698. readderef('',arrdef.RangeType);
  2699. arrdef.RangeLow:=getasizeint;
  2700. arrdef.RangeHigh:=getasizeint;
  2701. writeln([space,' Range : ',arrdef.RangeLow,' to ',arrdef.RangeHigh]);
  2702. write ([space,' Options : ']);
  2703. readarraydefoptions(arrdef);
  2704. readsymtable('symbols', arrdef);
  2705. end;
  2706. ibprocdef :
  2707. begin
  2708. def:=TPpuProcDef.Create(ParentDef);
  2709. readcommondef('Procedure definition',defoptions,def);
  2710. read_abstract_proc_def(calloption,procoptions,TPpuProcDef(def));
  2711. if (po_has_mangledname in procoptions) then
  2712. {$ifdef symansistr}
  2713. writeln([space,' Mangled name : ',getansistring]);
  2714. {$else symansistr}
  2715. writeln([space,' Mangled name : ',getstring]);
  2716. {$endif symansistr}
  2717. writeln([space,' Number : ',getword]);
  2718. writeln([space,' Level : ',getbyte]);
  2719. write ([space,' Class : ']);
  2720. readderef('');
  2721. write ([space,' Procsym : ']);
  2722. readderef('', def.Ref);
  2723. write ([space,' File Pos : ']);
  2724. readposinfo(def);
  2725. write ([space,' Visibility : ']);
  2726. readvisibility(def);
  2727. write ([space,' SymOptions : ']);
  2728. readsymoptions(space+' ');
  2729. writeln ([space,' Synthetic kind : ',Synthetic2Str(ppufile.getbyte)]);
  2730. if tsystemcpu(ppufile.header.cpu)=cpu_powerpc then
  2731. begin
  2732. { library symbol for AmigaOS/MorphOS }
  2733. write ([space,' Library symbol : ']);
  2734. readderef('');
  2735. end;
  2736. if (po_has_importdll in procoptions) then
  2737. writeln([space,' Import DLL : ',getstring]);
  2738. if (po_has_importname in procoptions) then
  2739. writeln([space,' Import Name : ',getstring]);
  2740. writeln([space,' Import Nr : ',getword]);
  2741. if (po_msgint in procoptions) then
  2742. writeln([space,' MsgInt : ',getlongint]);
  2743. if (po_msgstr in procoptions) then
  2744. writeln([space,' MsgStr : ',getstring]);
  2745. if (po_dispid in procoptions) then
  2746. writeln([space,' DispID: ',ppufile.getlongint]);
  2747. readprocimploptions(space,implprocoptions);
  2748. if (pio_has_inlininginfo in implprocoptions) then
  2749. begin
  2750. write ([space,' FuncretSym : ']);
  2751. readderef('');
  2752. readprocinfooptions(space);
  2753. end;
  2754. b:=ppufile.getbyte;
  2755. if b<>0 then
  2756. begin
  2757. write ([space,' Alias names : ']);
  2758. for j:=1 to b do
  2759. begin
  2760. write(ppufile.getstring);
  2761. if j<b then
  2762. write(', ');
  2763. end;
  2764. writeln;
  2765. end;
  2766. if not EndOfEntry then
  2767. HasMoreInfos;
  2768. space:=' '+space;
  2769. { parast }
  2770. readsymtable('parast', TPpuProcDef(def));
  2771. { localst }
  2772. if (pio_has_inlininginfo in implprocoptions) then
  2773. readsymtable('localst');
  2774. if (pio_has_inlininginfo in implprocoptions) then
  2775. readnodetree;
  2776. delete(space,1,4);
  2777. end;
  2778. ibprocvardef :
  2779. begin
  2780. def:=TPpuProcTypeDef.Create(ParentDef);
  2781. readcommondef('Procedural type (ProcVar) definition',defoptions,def);
  2782. read_abstract_proc_def(calloption,procoptions, TPpuProcDef(def));
  2783. writeln([space,' Symtable level :',ppufile.getbyte]);
  2784. if not EndOfEntry then
  2785. HasMoreInfos;
  2786. space:=' '+space;
  2787. { parast }
  2788. readsymtable('parast',TPpuProcDef(def));
  2789. delete(space,1,4);
  2790. end;
  2791. ibshortstringdef :
  2792. begin
  2793. strdef:=TPpuStringDef.Create(ParentDef);
  2794. strdef.StrType:=stShort;
  2795. readcommondef('ShortString definition',defoptions,strdef);
  2796. strdef.Len:=getbyte;
  2797. writeln([space,' Length : ',strdef.Len]);
  2798. end;
  2799. ibwidestringdef :
  2800. begin
  2801. strdef:=TPpuStringDef.Create(ParentDef);
  2802. strdef.StrType:=stWide;
  2803. readcommondef('WideString definition',defoptions,strdef);
  2804. strdef.Len:=getaint;
  2805. writeln([space,' Length : ',strdef.Len]);
  2806. end;
  2807. ibunicodestringdef :
  2808. begin
  2809. strdef:=TPpuStringDef.Create(ParentDef);
  2810. strdef.StrType:=stUnicode;
  2811. readcommondef('UnicodeString definition',defoptions,strdef);
  2812. strdef.Len:=getaint;
  2813. writeln([space,' Length : ',strdef.Len]);
  2814. writeln([space,' Encoding : ',getword]);
  2815. end;
  2816. ibansistringdef :
  2817. begin
  2818. strdef:=TPpuStringDef.Create(ParentDef);
  2819. strdef.StrType:=stAnsi;
  2820. readcommondef('AnsiString definition',defoptions,strdef);
  2821. strdef.Len:=getaint;
  2822. writeln([space,' Length : ',strdef.Len]);
  2823. writeln([space,' Encoding : ',getword]);
  2824. end;
  2825. iblongstringdef :
  2826. begin
  2827. strdef:=TPpuStringDef.Create(ParentDef);
  2828. strdef.StrType:=stLong;
  2829. readcommondef('Longstring definition',defoptions,strdef);
  2830. strdef.Len:=getaint;
  2831. writeln([space,' Length : ',strdef.Len]);
  2832. end;
  2833. ibrecorddef :
  2834. begin
  2835. objdef:=TPpuRecordDef.Create(ParentDef);
  2836. readcommondef('Record definition',defoptions, objdef);
  2837. def.Name:=getstring;
  2838. writeln([space,' Name of Record : ',objdef.Name]);
  2839. writeln([space,' Import lib/pkg : ',getstring]);
  2840. write ([space,' Options : ']);
  2841. readobjectdefoptions(objdef);
  2842. if (df_copied_def in defoptions) then
  2843. begin
  2844. Include(TPpuRecordDef(def).Options, ooCopied);
  2845. write([space,' Copied from : ']);
  2846. readderef('',objdef.Ancestor);
  2847. end
  2848. else
  2849. begin
  2850. writeln([space,' FieldAlign : ',shortint(getbyte)]);
  2851. writeln([space,' RecordAlign : ',shortint(getbyte)]);
  2852. writeln([space,' PadAlign : ',shortint(getbyte)]);
  2853. writeln([space,'UseFieldAlignment : ',shortint(getbyte)]);
  2854. objdef.Size:=getasizeint;
  2855. writeln([space,' DataSize : ',objdef.Size]);
  2856. writeln([space,' PaddingSize : ',getword]);
  2857. end;
  2858. if not EndOfEntry then
  2859. HasMoreInfos;
  2860. {read the record definitions and symbols}
  2861. if not(df_copied_def in current_defoptions) then
  2862. begin
  2863. space:=' '+space;
  2864. readrecsymtableoptions;
  2865. readsymtable('fields',TPpuRecordDef(def));
  2866. Delete(space,1,4);
  2867. end;
  2868. end;
  2869. ibobjectdef :
  2870. begin
  2871. objdef:=TPpuObjectDef.Create(ParentDef);
  2872. readcommondef('Object/Class definition',defoptions,objdef);
  2873. objdef.Name:=getstring;
  2874. writeln([space,' Name of Class : ',objdef.Name]);
  2875. writeln([space,' Import lib/pkg : ',getstring]);
  2876. write ([space,' Options : ']);
  2877. readobjectdefoptions(objdef);
  2878. b:=getbyte;
  2879. write ([space,' Type : ']);
  2880. case tobjecttyp(b) of
  2881. odt_class : writeln('class');
  2882. odt_object : writeln('object');
  2883. odt_interfacecom : writeln('interfacecom');
  2884. odt_interfacecorba : writeln('interfacecorba');
  2885. odt_cppclass : writeln('cppclass');
  2886. odt_dispinterface : writeln('dispinterface');
  2887. odt_objcclass : writeln('objcclass');
  2888. odt_objcprotocol : writeln('objcprotocol');
  2889. odt_helper : writeln('helper');
  2890. odt_objccategory : writeln('objccategory');
  2891. odt_javaclass : writeln('Java class');
  2892. odt_interfacejava : writeln('Java interface');
  2893. else WriteWarning('Invalid object type: ' + IntToStr(b));
  2894. end;
  2895. case tobjecttyp(b) of
  2896. odt_class, odt_cppclass, odt_objcclass, odt_javaclass:
  2897. objdef.ObjType:=otClass;
  2898. odt_object:
  2899. objdef.ObjType:=otObject;
  2900. odt_interfacecom, odt_interfacecorba, odt_interfacejava, odt_dispinterface:
  2901. objdef.ObjType:=otInterface;
  2902. odt_helper:
  2903. objdef.ObjType:=otHelper;
  2904. end;
  2905. writeln([space,' External name : ',getstring]);
  2906. objdef.Size:=getasizeint;
  2907. writeln([space,' DataSize : ',objdef.Size]);
  2908. writeln([space,' PaddingSize : ',getword]);
  2909. writeln([space,' FieldAlign : ',shortint(getbyte)]);
  2910. writeln([space,' RecordAlign : ',shortint(getbyte)]);
  2911. writeln([space,' Vmt offset : ',getlongint]);
  2912. write ([space, ' Ancestor Class : ']);
  2913. readderef('',objdef.Ancestor);
  2914. if tobjecttyp(b) in [odt_interfacecom,odt_interfacecorba,odt_dispinterface] then
  2915. begin
  2916. { IIDGUID }
  2917. for j:=1to 16 do
  2918. getbyte;
  2919. objdef.IID:=getstring;
  2920. writeln([space,' IID String : ',objdef.IID]);
  2921. end;
  2922. writeln([space,' Abstract methods : ',getlongint]);
  2923. if (tobjecttyp(b)=odt_helper) or
  2924. (oo_is_classhelper in current_objectoptions) then
  2925. begin
  2926. write([space,' Helper parent : ']);
  2927. readderef('',objdef.HelperParent);
  2928. end;
  2929. l:=getlongint;
  2930. writeln([space,' VMT entries: ',l]);
  2931. for j:=1 to l do
  2932. begin
  2933. write([space,' ']);
  2934. readderef('');
  2935. write([space,' Visibility: ']);
  2936. readvisibility;
  2937. end;
  2938. if tobjecttyp(b) in [odt_class,odt_objcclass,odt_objcprotocol,odt_javaclass,odt_interfacejava] then
  2939. begin
  2940. l:=getlongint;
  2941. writeln([space,' Impl Intf Count : ',l]);
  2942. for j:=1 to l do
  2943. begin
  2944. write ([space,' - Definition : ']);
  2945. readderef('');
  2946. write ([space,' - Getter Def : ']);
  2947. readderef('');
  2948. writeln([space,' IOffset : ',getlongint]);
  2949. writeln([space,' Entry type : ',IntfEntryType2Str(getbyte)]);
  2950. end;
  2951. end;
  2952. if df_copied_def in current_defoptions then
  2953. begin
  2954. Include(objdef.Options, ooCopied);
  2955. writeln(' Copy of def: ');
  2956. readderef('',objdef.Ancestor);
  2957. end;
  2958. if not EndOfEntry then
  2959. HasMoreInfos;
  2960. if not(df_copied_def in current_defoptions) then
  2961. begin
  2962. {read the record definitions and symbols}
  2963. space:=' '+space;
  2964. readrecsymtableoptions;
  2965. readsymtable('fields',objdef);
  2966. Delete(space,1,4);
  2967. end;
  2968. end;
  2969. ibfiledef :
  2970. begin
  2971. filedef:=TPpuFileDef.Create(ParentDef);
  2972. ReadCommonDef('File definition',defoptions,filedef);
  2973. write ([space,' Type : ']);
  2974. case getbyte of
  2975. 0 : begin
  2976. writeln('Text');
  2977. filedef.FileType:=ftText;
  2978. end;
  2979. 1 : begin
  2980. writeln('Typed');
  2981. filedef.FileType:=ftTyped;
  2982. write ([space,' File of Type : ']);
  2983. readderef('',filedef.TypeRef);
  2984. end;
  2985. 2 : begin
  2986. writeln('Untyped');
  2987. filedef.FileType:=ftUntyped;
  2988. end;
  2989. end;
  2990. end;
  2991. ibformaldef :
  2992. begin
  2993. def:=TPpuFormalDef.Create(ParentDef);
  2994. readcommondef('Generic definition (void-typ)',defoptions,def);
  2995. TPpuFormalDef(def).IsTyped:=(getbyte<>0);
  2996. writeln([space,' Is Typed : ',TPpuFormalDef(def).IsTyped]);
  2997. end;
  2998. ibundefineddef :
  2999. begin
  3000. def:=TPpuUndefinedDef.Create(ParentDef);
  3001. readcommondef('Undefined definition (generic parameter)',defoptions,def);
  3002. end;
  3003. ibenumdef :
  3004. begin
  3005. enumdef:=TPpuEnumDef.Create(ParentDef);
  3006. readcommondef('Enumeration type definition',defoptions,enumdef);
  3007. enumdef.ElLow:=getaint;
  3008. writeln([space,' Smallest element : ',enumdef.ElLow]);
  3009. enumdef.ElHigh:=getaint;
  3010. writeln([space,' Largest element : ',enumdef.ElHigh]);
  3011. enumdef.Size:=byte(getaint);
  3012. writeln([space,' Size : ',enumdef.Size]);
  3013. {$ifdef jvm}
  3014. write([space,' Class def : ']);
  3015. readderef('');
  3016. {$endif}
  3017. if df_copied_def in defoptions then
  3018. begin
  3019. write([space,'Base enumeration type : ']);
  3020. readderef('',enumdef.CopyFrom);
  3021. end
  3022. else
  3023. begin
  3024. space:=' '+space;
  3025. readsymtable('elements',enumdef);
  3026. delete(space,1,4);
  3027. end;
  3028. end;
  3029. ibclassrefdef :
  3030. begin
  3031. def:=TPpuClassRefDef.Create(ParentDef);
  3032. readcommondef('Class reference definition',defoptions,def);
  3033. write ([space,' Pointed Type : ']);
  3034. readderef('',TPpuClassRefDef(def).ClassRef);
  3035. end;
  3036. ibsetdef :
  3037. begin
  3038. setdef:=TPpuSetDef.Create(ParentDef);
  3039. readcommondef('Set definition',defoptions,setdef);
  3040. write ([space,' Element type : ']);
  3041. readderef('',setdef.ElType);
  3042. setdef.Size:=getaint;
  3043. writeln([space,' Size : ',setdef.Size]);
  3044. setdef.SetBase:=getaint;
  3045. writeln([space,' Set Base : ',setdef.SetBase]);
  3046. setdef.SetMax:=getaint;
  3047. writeln([space,' Set Max : ',setdef.SetMax]);
  3048. end;
  3049. ibvariantdef :
  3050. begin
  3051. def:=TPpuVariantDef.Create(ParentDef);
  3052. readcommondef('Variant definition',defoptions,def);
  3053. write ([space,' Varianttype : ']);
  3054. b:=getbyte;
  3055. case tvarianttype(b) of
  3056. vt_normalvariant :
  3057. writeln('Normal');
  3058. vt_olevariant :
  3059. begin
  3060. TPpuVariantDef(def).IsOLE:=True;
  3061. writeln('OLE');
  3062. end
  3063. else
  3064. WriteWarning('Invalid varianttype: ' + IntToStr(b));
  3065. end;
  3066. end;
  3067. iberror :
  3068. begin
  3069. WriteError('!! Error in PPU');
  3070. exit;
  3071. end;
  3072. ibenddefs :
  3073. break;
  3074. else
  3075. begin
  3076. WriteError('!! Skipping unsupported PPU Entry in definitions: '+IntToStr(b));
  3077. end;
  3078. end;
  3079. if (def <> nil) and (def.Parent = nil) then
  3080. def.Free;
  3081. if not EndOfEntry then
  3082. HasMoreInfos;
  3083. until false;
  3084. end;
  3085. end;
  3086. procedure readmoduleoptions(space : string);
  3087. type
  3088. { tmoduleoption type is in unit fmodule }
  3089. tmoduleoption = (mo_none,
  3090. mo_hint_deprecated,
  3091. mo_hint_platform,
  3092. mo_hint_library,
  3093. mo_hint_unimplemented,
  3094. mo_hint_experimental,
  3095. mo_has_deprecated_msg
  3096. );
  3097. tmoduleoptions = set of tmoduleoption;
  3098. tmoduleopt=record
  3099. mask : tmoduleoption;
  3100. str : string[30];
  3101. end;
  3102. const
  3103. moduleopts=ord(high(tmoduleoption));
  3104. moduleopt : array[1..moduleopts] of tmoduleopt=(
  3105. (mask:mo_hint_deprecated; str:'Hint Deprecated'),
  3106. (mask:mo_hint_platform; str:'Hint Platform'),
  3107. (mask:mo_hint_library; str:'Hint Library'),
  3108. (mask:mo_hint_unimplemented; str:'Hint Unimplemented'),
  3109. (mask:mo_hint_experimental; str:'Hint Experimental'),
  3110. (mask:mo_has_deprecated_msg; str:'Has Deprecated Message')
  3111. );
  3112. var
  3113. moduleoptions : tmoduleoptions;
  3114. i : longint;
  3115. first : boolean;
  3116. begin
  3117. ppufile.getsmallset(moduleoptions);
  3118. if moduleoptions<>[] then
  3119. begin
  3120. first:=true;
  3121. for i:=1to moduleopts do
  3122. if (moduleopt[i].mask in moduleoptions) then
  3123. begin
  3124. if first then
  3125. first:=false
  3126. else
  3127. write(', ');
  3128. write(moduleopt[i].str);
  3129. end;
  3130. end;
  3131. writeln;
  3132. if mo_has_deprecated_msg in moduleoptions then
  3133. writeln([space,'Deprecated : ', ppufile.getstring]);
  3134. end;
  3135. {****************************************************************************
  3136. Read General Part
  3137. ****************************************************************************}
  3138. procedure readinterface;
  3139. var
  3140. b : byte;
  3141. sourcenumber, i : longint;
  3142. begin
  3143. with ppufile do
  3144. begin
  3145. repeat
  3146. b:=readentry;
  3147. case b of
  3148. ibmodulename :
  3149. begin
  3150. CurUnit.Name:=getstring;
  3151. Writeln(['Module Name: ',CurUnit.Name]);
  3152. end;
  3153. ibmoduleoptions:
  3154. readmoduleoptions(' ');
  3155. ibsourcefiles :
  3156. begin
  3157. sourcenumber:=1;
  3158. while not EndOfEntry do
  3159. begin
  3160. with TPpuSrcFile.Create(CurUnit.SourceFiles) do begin
  3161. Name:=getstring;
  3162. i:=getlongint;
  3163. if i >= 0 then
  3164. FileTime:=FileDateToDateTime(i);
  3165. Writeln(['Source file ',sourcenumber,' : ',Name,' ',filetimestring(i)]);
  3166. end;
  3167. inc(sourcenumber);
  3168. end;
  3169. end;
  3170. {$IFDEF MACRO_DIFF_HINT}
  3171. ibusedmacros :
  3172. begin
  3173. while not EndOfEntry do
  3174. begin
  3175. Write('Conditional ',getstring);
  3176. b:=getbyte;
  3177. if boolean(b)=true then
  3178. write(' defined at startup')
  3179. else
  3180. write(' not defined at startup');
  3181. b:=getbyte;
  3182. if boolean(b)=true then
  3183. writeln(' was used')
  3184. else
  3185. writeln;
  3186. end;
  3187. end;
  3188. {$ENDIF}
  3189. ibloadunit :
  3190. ReadLoadUnit;
  3191. iblinkunitofiles :
  3192. ReadLinkContainer('Link unit object file: ');
  3193. iblinkunitstaticlibs :
  3194. ReadLinkContainer('Link unit static lib: ');
  3195. iblinkunitsharedlibs :
  3196. ReadLinkContainer('Link unit shared lib: ');
  3197. iblinkotherofiles :
  3198. ReadLinkContainer('Link other object file: ');
  3199. iblinkotherstaticlibs :
  3200. ReadLinkContainer('Link other static lib: ');
  3201. iblinkothersharedlibs :
  3202. ReadLinkContainer('Link other shared lib: ');
  3203. iblinkotherframeworks:
  3204. ReadLinkContainer('Link framework: ');
  3205. ibmainname:
  3206. Writeln(['Specified main program symbol name: ',getstring]);
  3207. ibImportSymbols :
  3208. ReadImportSymbols;
  3209. ibderefdata :
  3210. ReadDerefData;
  3211. ibderefmap :
  3212. ReadDerefMap;
  3213. ibwpofile :
  3214. ReadWpoFileInfo;
  3215. ibresources :
  3216. ReadLinkContainer('Resource file: ');
  3217. iberror :
  3218. begin
  3219. WriteError('Error in PPU');
  3220. exit;
  3221. end;
  3222. ibendinterface :
  3223. break;
  3224. else
  3225. begin
  3226. WriteError('!! Skipping unsupported PPU Entry in General Part: '+IntToStr(b));
  3227. end;
  3228. end;
  3229. until false;
  3230. end;
  3231. end;
  3232. {****************************************************************************
  3233. Read Implementation Part
  3234. ****************************************************************************}
  3235. procedure readimplementation;
  3236. var
  3237. b : byte;
  3238. begin
  3239. with ppufile do
  3240. begin
  3241. repeat
  3242. b:=readentry;
  3243. case b of
  3244. ibasmsymbols :
  3245. ReadAsmSymbols;
  3246. ibloadunit :
  3247. ReadLoadUnit;
  3248. iberror :
  3249. begin
  3250. WriteError('Error in PPU');
  3251. exit;
  3252. end;
  3253. ibendimplementation :
  3254. break;
  3255. else
  3256. begin
  3257. WriteError('!! Skipping unsupported PPU Entry in Implementation: '+IntToStr(b));
  3258. end;
  3259. end;
  3260. until false;
  3261. end;
  3262. end;
  3263. procedure dofile (filename : string);
  3264. begin
  3265. { reset }
  3266. space:='';
  3267. { fix filename }
  3268. if pos('.',filename)=0 then
  3269. filename:=filename+'.ppu';
  3270. ppufile:=tppufile.create(filename);
  3271. if not ppufile.openfile then
  3272. begin
  3273. WriteError('IO-Error when opening : '+filename+', Skipping');
  3274. exit;
  3275. end;
  3276. { PPU File is open, check for PPU Id }
  3277. if not ppufile.CheckPPUID then
  3278. begin
  3279. WriteError(Filename+' : Not a valid PPU file, Skipping');
  3280. exit;
  3281. end;
  3282. { Check PPU Version }
  3283. ppuversion:=ppufile.GetPPUVersion;
  3284. Writeln(['Analyzing ',filename,' (v',PPUVersion,')']);
  3285. if PPUVersion<16 then
  3286. begin
  3287. WriteError(Filename+' : Old PPU Formats (<v16) are not supported, Skipping');
  3288. exit;
  3289. end;
  3290. if not SkipVersionCheck and (PPUVersion <> CurrentPPUVersion) then
  3291. begin
  3292. WriteError(Format('Unsupported PPU version %d. Expecting PPU version %d.', [PPUVersion, CurrentPPUVersion]));
  3293. exit;
  3294. end;
  3295. CurUnit:=TPpuUnitDef.Create(UnitList);
  3296. CurUnit.Version:=ppuversion;
  3297. { Write PPU Header Information }
  3298. if (verbose and v_header)<>0 then
  3299. begin
  3300. Writeln;
  3301. Writeln('Header');
  3302. Writeln('-------');
  3303. with ppufile.header do
  3304. begin
  3305. Writeln(['Compiler version : ',ppufile.header.compiler shr 14,'.',
  3306. (ppufile.header.compiler shr 7) and $7f,'.',
  3307. ppufile.header.compiler and $7f]);
  3308. WriteLn(['Target processor : ',Cpu2Str(cpu)]);
  3309. WriteLn(['Target operating system : ',Target2Str(target)]);
  3310. Writeln(['Unit flags : ',PPUFlags2Str(flags)]);
  3311. Writeln(['FileSize (w/o header) : ',size]);
  3312. Writeln(['Checksum : ',hexstr(checksum,8)]);
  3313. Writeln(['Interface Checksum : ',hexstr(interface_checksum,8)]);
  3314. Writeln(['Indirect Checksum : ',hexstr(indirect_checksum,8)]);
  3315. Writeln(['Definitions stored : ',tostr(deflistsize)]);
  3316. Writeln(['Symbols stored : ',tostr(symlistsize)]);
  3317. end;
  3318. end;
  3319. with ppufile.header do
  3320. begin
  3321. CurUnit.Crc:=checksum;
  3322. CurUnit.IntfCrc:=interface_checksum;
  3323. CurUnit.TargetCPU:=Cpu2Str(cpu);
  3324. CurUnit.TargetOS:=Target2Str(target);
  3325. end;
  3326. {read the general stuff}
  3327. if (verbose and v_interface)<>0 then
  3328. begin
  3329. Writeln;
  3330. Writeln('Interface section');
  3331. Writeln('------------------');
  3332. readinterface;
  3333. end
  3334. else
  3335. ppufile.skipuntilentry(ibendinterface);
  3336. Writeln;
  3337. Writeln('Interface symtable');
  3338. Writeln('----------------------');
  3339. readsymtableoptions('interface');
  3340. {read the definitions}
  3341. if (verbose and v_defs)<>0 then
  3342. begin
  3343. Writeln;
  3344. Writeln('Interface definitions');
  3345. Writeln('----------------------');
  3346. readdefinitions('interface', CurUnit);
  3347. end
  3348. else
  3349. ppufile.skipuntilentry(ibenddefs);
  3350. {read the symbols}
  3351. if (verbose and v_syms)<>0 then
  3352. begin
  3353. Writeln;
  3354. Writeln('Interface Symbols');
  3355. Writeln('------------------');
  3356. readsymbols('interface',CurUnit);
  3357. end
  3358. else
  3359. ppufile.skipuntilentry(ibendsyms);
  3360. {read the macro symbols}
  3361. if (verbose and v_syms)<>0 then
  3362. begin
  3363. Writeln;
  3364. Writeln('Interface Macro Symbols');
  3365. Writeln('-----------------------');
  3366. end;
  3367. if ppufile.readentry<>ibexportedmacros then
  3368. begin
  3369. WriteError('!! Error in PPU');
  3370. exit;
  3371. end;
  3372. if boolean(ppufile.getbyte) then
  3373. begin
  3374. readsymtableoptions('interface macro');
  3375. {skip the definition section for macros (since they are never used) }
  3376. ppufile.skipuntilentry(ibenddefs);
  3377. {read the macro symbols}
  3378. if (verbose and v_syms)<>0 then
  3379. readsymbols('interface macro')
  3380. else
  3381. ppufile.skipuntilentry(ibendsyms);
  3382. end
  3383. else
  3384. Writeln('(no exported macros)');
  3385. {read the implementation stuff}
  3386. if (verbose and v_implementation)<>0 then
  3387. begin
  3388. Writeln;
  3389. Writeln('Implementation section');
  3390. Writeln('-----------------------');
  3391. readimplementation;
  3392. end
  3393. else
  3394. ppufile.skipuntilentry(ibendimplementation);
  3395. {read the static symtable}
  3396. Writeln;
  3397. Writeln('Implementation symtable');
  3398. Writeln('----------------------');
  3399. readsymtableoptions('implementation');
  3400. if (ppufile.header.flags and uf_local_symtable)<>0 then
  3401. begin
  3402. if (verbose and v_defs)<>0 then
  3403. begin
  3404. Writeln;
  3405. Writeln('Static definitions');
  3406. Writeln('----------------------');
  3407. readdefinitions('implementation', nil);
  3408. end
  3409. else
  3410. ppufile.skipuntilentry(ibenddefs);
  3411. {read the symbols}
  3412. if (verbose and v_syms)<>0 then
  3413. begin
  3414. Writeln;
  3415. Writeln('Static Symbols');
  3416. Writeln('------------------');
  3417. readsymbols('implementation');
  3418. end
  3419. else
  3420. ppufile.skipuntilentry(ibendsyms);
  3421. end;
  3422. ReadCreatedObjTypes;
  3423. FreeDerefdata;
  3424. {shutdown ppufile}
  3425. ppufile.closefile;
  3426. ppufile.free;
  3427. Writeln;
  3428. end;
  3429. procedure WriteLogo;
  3430. begin
  3431. writeln(Title+' Version '+version_string);
  3432. writeln(Copyright);
  3433. writeln;
  3434. end;
  3435. procedure help;
  3436. begin
  3437. WriteLogo;
  3438. writeln('usage: ppudump [options] <filename1> <filename2>...');
  3439. writeln;
  3440. writeln('[options] can be:');
  3441. writeln(' -F<format> Set output format to <format>');
  3442. writeln(' t - text format (default)');
  3443. writeln(' j - JSON format');
  3444. writeln(' x - XML format');
  3445. writeln(' -M Exit with ExitCode=2 if more information is available');
  3446. writeln(' -S Skip PPU version check. May lead to reading errors');
  3447. writeln(' -V<verbose> Set verbosity to <verbose>');
  3448. writeln(' H - Show header info');
  3449. writeln(' I - Show interface');
  3450. writeln(' M - Show implementation');
  3451. writeln(' S - Show interface symbols');
  3452. writeln(' D - Show interface definitions');
  3453. writeln(' A - Show all');
  3454. writeln(' -h, -? This helpscreen');
  3455. halt;
  3456. end;
  3457. var
  3458. startpara,
  3459. nrfile,i : longint;
  3460. para : string;
  3461. const
  3462. error_on_more : boolean = false;
  3463. begin
  3464. if paramcount<1 then
  3465. help;
  3466. { turn verbose on by default }
  3467. verbose:=v_all;
  3468. { read options }
  3469. startpara:=1;
  3470. while copy(paramstr(startpara),1,1)='-' do
  3471. begin
  3472. para:=paramstr(startpara);
  3473. case upcase(para[2]) of
  3474. 'F' : begin
  3475. FreeAndNil(pout);
  3476. if Length(para) > 2 then
  3477. case upcase(para[3]) of
  3478. 'T':
  3479. nostdout:=False;
  3480. 'J':
  3481. begin
  3482. nostdout:=True;
  3483. pout:=TPpuJsonOutput.Create(Output);
  3484. end;
  3485. 'X':
  3486. begin
  3487. nostdout:=True;
  3488. pout:=TPpuXmlOutput.Create(Output);
  3489. end;
  3490. else
  3491. begin
  3492. WriteError('Invalid output format: ' + para[3]);
  3493. Halt(1);
  3494. end;
  3495. end;
  3496. end;
  3497. 'M' : error_on_more:=true;
  3498. 'S' : SkipVersionCheck:=True;
  3499. 'V' : begin
  3500. verbose:=0;
  3501. for i:=3 to length(para) do
  3502. case upcase(para[i]) of
  3503. 'H' : verbose:=verbose or v_header;
  3504. 'I' : verbose:=verbose or v_interface;
  3505. 'M' : verbose:=verbose or v_implementation;
  3506. 'D' : verbose:=verbose or v_defs;
  3507. 'S' : verbose:=verbose or v_syms;
  3508. 'A' : verbose:=verbose or v_all;
  3509. end;
  3510. end;
  3511. 'H' : help;
  3512. '?' : help;
  3513. else
  3514. begin
  3515. WriteError('Invalid option: ' + para);
  3516. Halt(1);
  3517. end;
  3518. end;
  3519. inc(startpara);
  3520. end;
  3521. if not nostdout then
  3522. WriteLogo;
  3523. UnitList:=TPpuContainerDef.Create(nil);
  3524. try
  3525. UnitList.ItemsName:='';
  3526. { process files }
  3527. for nrfile:=startpara to paramcount do
  3528. dofile (paramstr(nrfile));
  3529. if not has_errors and (pout <> nil) then
  3530. begin
  3531. pout.Init;
  3532. UnitList.Write(pout);
  3533. pout.Done;
  3534. end;
  3535. finally
  3536. UnitList.Free;
  3537. pout.Free;
  3538. end;
  3539. if has_errors then
  3540. Halt(1);
  3541. if error_on_more and has_more_infos then
  3542. Halt(2);
  3543. end.