ppudump.pp 122 KB

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