ppudump.pp 113 KB

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