ppudump.pp 113 KB

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