ppudump.pp 126 KB

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