ppudump.pp 124 KB

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