ppudump.pp 119 KB

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