ppudump.pp 127 KB

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