ppudump.pp 126 KB

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