ppudump.pp 113 KB

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