ppudump.pp 125 KB

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