ppudump.pp 119 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955
  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. writeln([space,'Imported Symbols']);
  1013. writeln([space,'----------------']);
  1014. c:=ppufile.getlongint;
  1015. for i:=0 to c-1 do
  1016. readderef(space);
  1017. writeln([space]);
  1018. end;
  1019. procedure readpropaccesslist(const s:string; Ref: TPpuRef = nil);
  1020. { type tsltype is in symconst unit }
  1021. const
  1022. slstr : array[tsltype] of string[12] = (
  1023. '',
  1024. 'load',
  1025. 'call',
  1026. 'subscript',
  1027. 'vec',
  1028. 'typeconv',
  1029. 'absolutetype'
  1030. );
  1031. var
  1032. sl : tsltype;
  1033. begin
  1034. readderef('',Ref);
  1035. repeat
  1036. sl:=tsltype(ppufile.getbyte);
  1037. if sl=sl_none then
  1038. break;
  1039. write([s,'(',slstr[sl],') ']);
  1040. case sl of
  1041. sl_call,
  1042. sl_load,
  1043. sl_subscript :
  1044. if (Ref <> nil) and (Ref.IsNull) then
  1045. begin
  1046. readderef('',Ref);
  1047. Ref.IsSymId:=True;
  1048. end
  1049. else
  1050. readderef('');
  1051. sl_absolutetype,
  1052. sl_typeconv :
  1053. readderef('');
  1054. sl_vec :
  1055. begin
  1056. writeln([ppufile.getlongint]);
  1057. readderef('');
  1058. end;
  1059. end;
  1060. until false;
  1061. end;
  1062. (*
  1063. talignmentinfo = packed record
  1064. procalign,
  1065. loopalign,
  1066. jumpalign,
  1067. constalignmin,
  1068. constalignmax,
  1069. varalignmin,
  1070. varalignmax,
  1071. localalignmin,
  1072. localalignmax,
  1073. recordalignmin,
  1074. recordalignmax,
  1075. maxCrecordalign : longint;
  1076. end;
  1077. tsettings = packed record
  1078. alignment : talignmentinfo;
  1079. globalswitches : tglobalswitches;
  1080. moduleswitches : tmoduleswitches;
  1081. localswitches : tlocalswitches;
  1082. modeswitches : tmodeswitches;
  1083. optimizerswitches : toptimizerswitches;
  1084. { generate information necessary to perform these wpo's during a subsequent compilation }
  1085. genwpoptimizerswitches: twpoptimizerswitches;
  1086. { perform these wpo's using information generated during a previous compilation }
  1087. dowpoptimizerswitches: twpoptimizerswitches;
  1088. debugswitches : tdebugswitches;
  1089. { 0: old behaviour for sets <=256 elements
  1090. >0: round to this size }
  1091. setalloc,
  1092. packenum : shortint;
  1093. packrecords : shortint;
  1094. maxfpuregisters : shortint;
  1095. cputype,
  1096. optimizecputype : tcputype;
  1097. fputype : tfputype;
  1098. asmmode : tasmmode;
  1099. interfacetype : tinterfacetypes;
  1100. defproccall : tproccalloption;
  1101. sourcecodepage : tcodepagestring;
  1102. minfpconstprec : tfloattype;
  1103. disabledircache : boolean;
  1104. { CPU targets with microcontroller support can add a controller specific unit }
  1105. controllertype : tcontrollertype;
  1106. { WARNING: this pointer cannot be written as such in record token }
  1107. pmessage : pmessagestaterecord;
  1108. end;
  1109. *)
  1110. procedure readprocinfooptions(space : string);
  1111. (*
  1112. tprocinfoflag=(
  1113. { procedure has at least one assembler block }
  1114. pi_has_assembler_block,
  1115. { procedure does a call }
  1116. pi_do_call,
  1117. { procedure has a try statement = no register optimization }
  1118. pi_uses_exceptions,
  1119. { procedure is declared as @var(assembler), don't optimize}
  1120. pi_is_assembler,
  1121. { procedure contains data which needs to be finalized }
  1122. pi_needs_implicit_finally,
  1123. { procedure has the implicit try..finally generated }
  1124. pi_has_implicit_finally,
  1125. { procedure uses fpu}
  1126. pi_uses_fpu,
  1127. { procedure uses GOT for PIC code }
  1128. pi_needs_got,
  1129. { references var/proc/type/const in static symtable,
  1130. i.e. not allowed for inlining from other units }
  1131. pi_uses_static_symtable,
  1132. { set if the procedure has to push parameters onto the stack }
  1133. pi_has_stackparameter,
  1134. { set if the procedure has at least one label }
  1135. pi_has_label,
  1136. { calls itself recursive }
  1137. pi_is_recursive,
  1138. { stack frame optimization not possible (only on x86 probably) }
  1139. pi_needs_stackframe,
  1140. { set if the procedure has at least one register saved on the stack }
  1141. pi_has_saved_regs,
  1142. { dfa was generated for this proc }
  1143. pi_dfaavailable,
  1144. { subroutine contains interprocedural used labels }
  1145. pi_has_interproclabel,
  1146. { subroutine contains interprocedural gotos }
  1147. pi_has_global_goto
  1148. ); *)
  1149. type
  1150. tprocinfoopt=record
  1151. mask : tprocinfoflag;
  1152. str : string[81];
  1153. end;
  1154. const
  1155. procinfoopts=ord(high(tprocinfoflag)) - ord(low(tprocinfoflag));
  1156. procinfoopt : array[0..procinfoopts] of tprocinfoopt=(
  1157. (mask:pi_has_assembler_block;
  1158. str:' has at least one assembler block'),
  1159. (mask:pi_do_call;
  1160. str:' does a call'),
  1161. (mask:pi_uses_exceptions;
  1162. str:' has a try statement = no register optimization '),
  1163. (mask:pi_is_assembler;
  1164. str:' is declared as @var(assembler), don''t optimize'),
  1165. (mask:pi_needs_implicit_finally;
  1166. str:' contains data which needs to be finalized '),
  1167. (mask:pi_has_implicit_finally;
  1168. str:' has the implicit try..finally generated '),
  1169. (mask:pi_uses_fpu;
  1170. str:' uses fpu'),
  1171. (mask:pi_needs_got;
  1172. str:' uses GOT for PIC code '),
  1173. (mask:pi_uses_static_symtable;
  1174. str:' references var/proc/type/const in static symtable'),
  1175. (mask:pi_has_stackparameter;
  1176. str:' set if the procedure has to push parameters onto the stack '),
  1177. (mask:pi_has_label;
  1178. str:' set if the procedure has at least one label '),
  1179. (mask:pi_is_recursive;
  1180. str:' calls itself recursive '),
  1181. (mask:pi_needs_stackframe;
  1182. str:' stack frame optimization not possible (only on x86 probably) '),
  1183. (mask:pi_has_saved_regs;
  1184. str:' set if the procedure has at least one register saved on the stack '),
  1185. (mask:pi_dfaavailable;
  1186. str:' dfa was generated for this proc '),
  1187. (mask:pi_has_interproclabel;
  1188. str:' subroutine contains interprocedural used labels '),
  1189. (mask:pi_has_unwind_info;
  1190. str:' unwinding info was generated for this proc '),
  1191. (mask:pi_has_global_goto;
  1192. str:' subroutine contains interprocedural goto '),
  1193. (mask:pi_has_inherited;
  1194. str:' subroutine contains inherited call '),
  1195. (mask:pi_has_nested_exit;
  1196. str:' subroutine contains a nested subroutine which calls the exit of the current one '),
  1197. (mask:pi_has_stack_allocs;
  1198. str:' allocates memory on stack, so stack may be unbalanced on exit '),
  1199. (mask:pi_estimatestacksize;
  1200. str:' stack size is estimated before subroutine is compiled '),
  1201. (mask:pi_calls_c_varargs;
  1202. str:' calls function with C-style varargs '),
  1203. (mask:pi_has_open_array_parameter;
  1204. str:' has open array parameter ')
  1205. );
  1206. var
  1207. procinfooptions : tprocinfoflags;
  1208. i : longint;
  1209. first : boolean;
  1210. begin
  1211. ppufile.getsmallset(procinfooptions);
  1212. if procinfooptions<>[] then
  1213. begin
  1214. first:=true;
  1215. for i:=0 to procinfoopts do
  1216. if (procinfoopt[i].mask in procinfooptions) then
  1217. begin
  1218. if first then
  1219. first:=false
  1220. else
  1221. write(', ');
  1222. write(procinfoopt[i].str);
  1223. end;
  1224. end;
  1225. writeln;
  1226. end;
  1227. procedure readsymoptions(space : string; Def: TPpuDef = nil);
  1228. type
  1229. tsymopt=record
  1230. mask : tsymoption;
  1231. str : string[30];
  1232. end;
  1233. const
  1234. symopts=ord(high(tsymoption)) - ord(low(tsymoption));
  1235. { sp_none = 0 corresponds to nothing }
  1236. symopt : array[1..symopts] of tsymopt=(
  1237. (mask:sp_static; str:'Static'),
  1238. (mask:sp_hint_deprecated; str:'Hint Deprecated'),
  1239. (mask:sp_hint_platform; str:'Hint Platform'),
  1240. (mask:sp_hint_library; str:'Hint Library'),
  1241. (mask:sp_hint_unimplemented; str:'Hint Unimplemented'),
  1242. (mask:sp_hint_experimental; str:'Hint Experimental'),
  1243. (mask:sp_has_overloaded; str:'Has overloaded'),
  1244. (mask:sp_internal; str:'Internal'),
  1245. (mask:sp_implicitrename; str:'Implicit Rename'),
  1246. (mask:sp_generic_para; str:'Generic Parameter'),
  1247. (mask:sp_has_deprecated_msg; str:'Has Deprecated Message'),
  1248. (mask:sp_generic_dummy; str:'Generic Dummy'),
  1249. (mask:sp_explicitrename; str:'Explicit Rename')
  1250. );
  1251. var
  1252. symoptions : tsymoptions;
  1253. i : longint;
  1254. first : boolean;
  1255. begin
  1256. ppufile.getsmallset(symoptions);
  1257. if symoptions<>[] then
  1258. begin
  1259. if Def <> nil then
  1260. if sp_internal in symoptions then
  1261. Def.Visibility:=dvHidden;
  1262. first:=true;
  1263. for i:=1to symopts do
  1264. if (symopt[i].mask in symoptions) then
  1265. begin
  1266. if first then
  1267. first:=false
  1268. else
  1269. write(', ');
  1270. write(symopt[i].str);
  1271. end;
  1272. end;
  1273. writeln;
  1274. if sp_has_deprecated_msg in symoptions then
  1275. writeln([space,'Deprecated : ', ppufile.getstring]);
  1276. end;
  1277. procedure readvisibility(Def: TPpuDef = nil);
  1278. var
  1279. i: byte;
  1280. begin
  1281. i:=ppufile.getbyte;
  1282. if Def <> nil then
  1283. case tvisibility(i) of
  1284. vis_public: Def.Visibility:=dvPublic;
  1285. vis_published: Def.Visibility:=dvPublished;
  1286. vis_protected, vis_strictprotected: Def.Visibility:=dvProtected;
  1287. else Def.Visibility:=dvPrivate;
  1288. end;
  1289. writeln(Visibility2Str(i));
  1290. end;
  1291. procedure readcommonsym(const s:string; Def: TPpuDef = nil);
  1292. var
  1293. i: integer;
  1294. n: string;
  1295. begin
  1296. n:=ppufile.getstring;
  1297. if Def <> nil then
  1298. Def.Name:=n;
  1299. i:=ppufile.getlongint;
  1300. if Def <> nil then
  1301. Def.SetSymId(i);
  1302. writeln([space,'** Symbol Id ',i,' **']);
  1303. writeln([space,s,n]);
  1304. write ([space,' File Pos : ']);
  1305. readposinfo(Def);
  1306. write ([space,' Visibility : ']);
  1307. readvisibility(Def);
  1308. write ([space,' SymOptions : ']);
  1309. readsymoptions(space+' ',Def);
  1310. end;
  1311. var
  1312. { needed during tobjectdef parsing... }
  1313. current_defoptions : tdefoptions;
  1314. current_objectoptions : tobjectoptions;
  1315. procedure readcommondef(const s:string; out defoptions: tdefoptions; Def: TPpuDef = nil);
  1316. type
  1317. tdefopt=record
  1318. mask : tdefoption;
  1319. str : string[30];
  1320. end;
  1321. tdefstateinfo=record
  1322. mask : tdefstate;
  1323. str : string[30];
  1324. end;
  1325. tgenconstrflag=record
  1326. mask : tgenericconstraintflag;
  1327. str : string[30];
  1328. end;
  1329. ptoken=^ttoken;
  1330. pmsgstate =^tmsgstate;
  1331. const
  1332. defopt : array[1..ord(high(tdefoption))] of tdefopt=(
  1333. (mask:df_unique; str:'Unique Type'),
  1334. (mask:df_generic; str:'Generic'),
  1335. (mask:df_specialization; str:'Specialization'),
  1336. (mask:df_copied_def; str:'Copied Typedef'),
  1337. (mask:df_genconstraint; str:'Generic Constraint'),
  1338. { this should never happen for defs stored to a ppu file }
  1339. (mask:df_not_registered_no_free; str:'Unregistered/No free (invalid)'),
  1340. (mask:df_llvm_no_struct_packing; str:'LLVM unpacked struct')
  1341. );
  1342. defstate : array[1..ord(high(tdefstate))] of tdefstateinfo=(
  1343. (mask:ds_vmt_written; str:'VMT Written'),
  1344. (mask:ds_rtti_table_used; str:'RTTITable Used'),
  1345. (mask:ds_init_table_used; str:'InitTable Used'),
  1346. (mask:ds_rtti_table_written; str:'RTTITable Written'),
  1347. (mask:ds_init_table_written; str:'InitTable Written'),
  1348. (mask:ds_dwarf_dbg_info_used; str:'Dwarf DbgInfo Used'),
  1349. (mask:ds_dwarf_dbg_info_written;str:'Dwarf DbgInfo Written')
  1350. );
  1351. genconstrflag : array[1..ord(high(tgenericconstraintflag))] of tgenconstrflag=(
  1352. (mask:gcf_constructor; str:'Constructor'),
  1353. (mask:gcf_class; str:'Class'),
  1354. (mask:gcf_record; str:'Record')
  1355. );
  1356. var
  1357. defstates : tdefstates;
  1358. i, nb{, msgvalue}, mesgnb : longint;
  1359. first : boolean;
  1360. copy_size, min_size, tokenbufsize : longint;
  1361. tokenbuf : pbyte;
  1362. // idtoken,
  1363. token : ttoken;
  1364. // state : tmsgstate;
  1365. new_settings : Tsettings;
  1366. len : sizeint;
  1367. wstring : widestring;
  1368. astring : ansistring;
  1369. genconstr : tgenericconstraintflags;
  1370. function readtoken: ttoken;
  1371. var
  1372. b,b2 : byte;
  1373. begin
  1374. b:=tokenbuf[i];
  1375. inc(i);
  1376. if (b and $80)<>0 then
  1377. begin
  1378. b2:=tokenbuf[i];
  1379. inc(i);
  1380. result:=ttoken(((b and $7f) shl 8) or b2);
  1381. end
  1382. else
  1383. result:=ttoken(b);
  1384. end;
  1385. function gettokenbufdword : dword;
  1386. var
  1387. var32 : dword;
  1388. begin
  1389. var32:=pdword(@tokenbuf[i])^;
  1390. inc(i,sizeof(dword));
  1391. if ppufile.change_endian then
  1392. var32:=swapendian(var32);
  1393. result:=var32;
  1394. end;
  1395. function gettokenbufword : word;
  1396. var
  1397. var16 : word;
  1398. begin
  1399. var16:=pword(@tokenbuf[i])^;
  1400. inc(i,sizeof(word));
  1401. if ppufile.change_endian then
  1402. var16:=swapendian(var16);
  1403. result:=var16;
  1404. end;
  1405. function gettokenbufsizeint : int64;
  1406. var
  1407. var64 : int64;
  1408. var32 : longint;
  1409. var16 : smallint;
  1410. begin
  1411. if CpuAddrBitSize[cpu]=64 then
  1412. begin
  1413. var64:=pint64(@tokenbuf[i])^;
  1414. inc(i,sizeof(int64));
  1415. if ppufile.change_endian then
  1416. var64:=swapendian(var64);
  1417. result:=var64;
  1418. end
  1419. else if CpuAddrBitSize[cpu]=32 then
  1420. begin
  1421. var32:=plongint(@tokenbuf[i])^;
  1422. inc(i,sizeof(longint));
  1423. if ppufile.change_endian then
  1424. var32:=swapendian(var32);
  1425. result:=var32;
  1426. end
  1427. else if CpuAddrBitSize[cpu]=16 then
  1428. begin
  1429. var16:=psmallint(@tokenbuf[i])^;
  1430. inc(i,sizeof(smallint));
  1431. if ppufile.change_endian then
  1432. var16:=swapendian(var16);
  1433. result:=var16;
  1434. end
  1435. else
  1436. begin
  1437. WriteError('Wrong CpuAddrBitSize');
  1438. result:=0;
  1439. end;
  1440. end;
  1441. begin
  1442. i:=ppufile.getlongint;
  1443. if Def <> nil then
  1444. Def.Id:=i;
  1445. writeln([space,'** Definition Id ',i,' **']);
  1446. writeln([space,s]);
  1447. write ([space,' Type symbol : ']);
  1448. if Def <> nil then
  1449. readderef('', Def.Ref)
  1450. else
  1451. readderef('');
  1452. write ([space,' DefOptions : ']);
  1453. ppufile.getsmallset(defoptions);
  1454. if defoptions<>[] then
  1455. begin
  1456. first:=true;
  1457. for i:=1to high(defopt) do
  1458. if (defopt[i].mask in defoptions) then
  1459. begin
  1460. if first then
  1461. first:=false
  1462. else
  1463. write(', ');
  1464. write(defopt[i].str);
  1465. end;
  1466. end;
  1467. writeln;
  1468. write ([space,' DefStates : ']);
  1469. ppufile.getsmallset(defstates);
  1470. if defstates<>[] then
  1471. begin
  1472. first:=true;
  1473. for i:=1 to high(defstate) do
  1474. if (defstate[i].mask in defstates) then
  1475. begin
  1476. if first then
  1477. first:=false
  1478. else
  1479. write(', ');
  1480. write(defstate[i].str);
  1481. end;
  1482. end;
  1483. writeln;
  1484. if df_genconstraint in defoptions then
  1485. begin
  1486. ppufile.getsmallset(genconstr);
  1487. write ([space,' GenConstraints : ']);
  1488. if genconstr<>[] then
  1489. begin
  1490. first:=true;
  1491. for i:=1 to high(genconstrflag) do
  1492. if (genconstrflag[i].mask in genconstr) then
  1493. begin
  1494. if first then
  1495. first:=false
  1496. else
  1497. write(', ');
  1498. write(genconstrflag[i].str);
  1499. end;
  1500. end;
  1501. writeln;
  1502. len:=ppufile.getasizeint;
  1503. if len>0 then
  1504. begin
  1505. space:=' '+space;
  1506. writeln([space,'------ constraint defs begin ------']);
  1507. for i:=0 to len-1 do
  1508. begin
  1509. writeln([space,'------ constraint def ',i,' ------']);
  1510. readderef(space);
  1511. end;
  1512. writeln([space,'------ constraint defs end ------']);
  1513. delete(space,1,4);
  1514. end;
  1515. end;
  1516. if [df_generic,df_specialization]*defoptions<>[] then
  1517. begin
  1518. nb:=ppufile.getlongint;
  1519. writeln([space,'has ',nb,' parameters']);
  1520. if nb>0 then
  1521. begin
  1522. for i:=0 to nb-1 do
  1523. begin
  1524. writeln([space,'parameter ',i,': ',ppufile.getstring]);
  1525. readderef(space);
  1526. end;
  1527. end;
  1528. end;
  1529. if df_generic in defoptions then
  1530. begin
  1531. tokenbufsize:=ppufile.getlongint;
  1532. writeln([space,' Tokenbuffer size : ',tokenbufsize]);
  1533. tokenbuf:=allocmem(tokenbufsize);
  1534. ppufile.getdata(tokenbuf^,tokenbufsize);
  1535. i:=0;
  1536. write([space,' Tokens: ']);
  1537. while i<tokenbufsize do
  1538. begin
  1539. token:=readtoken;
  1540. if token<>_GENERICSPECIALTOKEN then
  1541. begin
  1542. if token <= high(ttoken) then
  1543. write(arraytokeninfo[token].str)
  1544. else
  1545. begin
  1546. HasMoreInfos;
  1547. write('Error in Token List');
  1548. break;
  1549. end;
  1550. {idtoken:=}readtoken;
  1551. end;
  1552. case token of
  1553. _CWCHAR,
  1554. _CWSTRING :
  1555. begin
  1556. len:=gettokenbufsizeint;
  1557. setlength(wstring,len);
  1558. move(tokenbuf[i],wstring[1],len*2);
  1559. write([' ',wstring]);
  1560. inc(i,len*2);
  1561. end;
  1562. _CSTRING:
  1563. begin
  1564. len:=gettokenbufsizeint;
  1565. setlength(astring,len);
  1566. move(tokenbuf[i],astring[1],len);
  1567. write([' ',astring]);
  1568. inc(i,len);
  1569. end;
  1570. _CCHAR,
  1571. _INTCONST,
  1572. _REALNUMBER :
  1573. begin
  1574. write([' ',pshortstring(@tokenbuf[i])^]);
  1575. inc(i,tokenbuf[i]+1);
  1576. end;
  1577. _ID :
  1578. begin
  1579. write([' ',pshortstring(@tokenbuf[i])^]);
  1580. inc(i,tokenbuf[i]+1);
  1581. end;
  1582. _GENERICSPECIALTOKEN:
  1583. begin
  1584. { Short version of column change,
  1585. byte or $80 used }
  1586. if (tokenbuf[i] and $80)<>0 then
  1587. begin
  1588. write(['Col: ',tokenbuf[i] and $7f]);
  1589. inc(i);
  1590. end
  1591. else
  1592. case tspecialgenerictoken(tokenbuf[i]) of
  1593. ST_LOADSETTINGS:
  1594. begin
  1595. inc(i);
  1596. write('Settings');
  1597. { This does not load pmessage pointer }
  1598. new_settings.pmessage:=nil;
  1599. { TSettings size depends in target...
  1600. We first read the size of the copied part }
  1601. { Still not cross endian ready :( }
  1602. copy_size:=gettokenbufsizeint;
  1603. if copy_size < sizeof(tsettings)-sizeof(pointer) then
  1604. min_size:=copy_size
  1605. else
  1606. min_size:= sizeof(tsettings)-sizeof(pointer);
  1607. move(tokenbuf[i],new_settings, min_size);
  1608. inc(i,copy_size);
  1609. end;
  1610. ST_LOADMESSAGES:
  1611. begin
  1612. inc(i);
  1613. write('Messages:');
  1614. mesgnb:=tokenbuf[i];
  1615. inc(i);
  1616. for nb:=1 to mesgnb do
  1617. begin
  1618. {msgvalue:=}gettokenbufsizeint;
  1619. inc(i,sizeof(sizeint));
  1620. //state:=tmsgstate(gettokenbufsizeint);
  1621. end;
  1622. end;
  1623. ST_LINE:
  1624. begin
  1625. inc(i);
  1626. write(['Line: ',gettokenbufdword]);
  1627. end;
  1628. ST_COLUMN:
  1629. begin
  1630. inc(i);
  1631. write(['Col: ',gettokenbufword]);
  1632. end;
  1633. ST_FILEINDEX:
  1634. begin
  1635. inc(i);
  1636. write(['File: ',gettokenbufword]);
  1637. end;
  1638. end;
  1639. end;
  1640. end;
  1641. if i<tokenbufsize then
  1642. write(',');
  1643. end;
  1644. writeln;
  1645. freemem(tokenbuf);
  1646. end;
  1647. if df_specialization in defoptions then
  1648. begin
  1649. write ([space,' Orig. GenericDef : ']);
  1650. readderef('');
  1651. end;
  1652. current_defoptions:=defoptions;
  1653. end;
  1654. { Read abstract procdef and return if inline procdef }
  1655. { type tproccalloption is in globtype unit }
  1656. { type tproctypeoption is in globtype unit }
  1657. { type tprocoption is in globtype unit }
  1658. procedure read_abstract_proc_def(var proccalloption:tproccalloption;var procoptions:tprocoptions; ProcDef: TPpuProcDef);
  1659. type
  1660. tproccallopt=record
  1661. mask : tproccalloption;
  1662. str : string[30];
  1663. end;
  1664. tproctypeopt=record
  1665. mask : tproctypeoption;
  1666. str : string[30];
  1667. end;
  1668. tprocopt=record
  1669. mask : tprocoption;
  1670. str : string[31];
  1671. end;
  1672. const
  1673. {proccalloptionStr is also in globtype unit }
  1674. proctypeopt : array[1..ord(high(tproctypeoption))] of tproctypeopt=(
  1675. (mask:potype_proginit; str:'ProgInit'),
  1676. (mask:potype_unitinit; str:'UnitInit'),
  1677. (mask:potype_unitfinalize; str:'UnitFinalize'),
  1678. (mask:potype_constructor; str:'Constructor'),
  1679. (mask:potype_destructor; str:'Destructor'),
  1680. (mask:potype_operator; str:'Operator'),
  1681. (mask:potype_procedure; str:'Procedure'),
  1682. (mask:potype_function; str:'Function'),
  1683. (mask:potype_class_constructor; str:'Class Constructor'),
  1684. (mask:potype_class_destructor; str:'Class Destructor'),
  1685. { Dispinterface property accessors }
  1686. (mask:potype_propgetter; str:'Property Getter'),
  1687. (mask:potype_propsetter; str:'Property Setter'),
  1688. (mask:potype_exceptfilter; str:'SEH filter'),
  1689. (mask:potype_mainstub; str:'main stub')
  1690. );
  1691. procopt : array[1..ord(high(tprocoption))] of tprocopt=(
  1692. (mask:po_classmethod; str:'ClassMethod'),
  1693. (mask:po_virtualmethod; str:'VirtualMethod'),
  1694. (mask:po_abstractmethod; str:'AbstractMethod'),
  1695. (mask:po_finalmethod; str:'FinalMethod'),
  1696. (mask:po_staticmethod; str:'StaticMethod'),
  1697. (mask:po_overridingmethod;str:'OverridingMethod'),
  1698. (mask:po_methodpointer; str:'MethodPointer'),
  1699. (mask:po_interrupt; str:'Interrupt'),
  1700. (mask:po_iocheck; str:'IOCheck'),
  1701. (mask:po_assembler; str:'Assembler'),
  1702. (mask:po_msgstr; str:'MsgStr'),
  1703. (mask:po_msgint; str:'MsgInt'),
  1704. (mask:po_exports; str:'Exports'),
  1705. (mask:po_external; str:'External'),
  1706. (mask:po_overload; str:'Overload'),
  1707. (mask:po_varargs; str:'VarArgs'),
  1708. (mask:po_internconst; str:'InternConst'),
  1709. (mask:po_addressonly; str:'AddressOnly'),
  1710. (mask:po_public; str:'Public'),
  1711. (mask:po_hascallingconvention;str:'HasCallingConvention'),
  1712. (mask:po_reintroduce; str:'ReIntroduce'),
  1713. (mask:po_explicitparaloc; str:'ExplicitParaloc'),
  1714. (mask:po_nostackframe; str:'NoStackFrame'),
  1715. (mask:po_has_mangledname; str:'HasMangledName'),
  1716. (mask:po_has_public_name; str:'HasPublicName'),
  1717. (mask:po_forward; str:'Forward'),
  1718. (mask:po_global; str:'Global'),
  1719. (mask:po_syscall_legacy; str:'SyscallLegacy'),
  1720. (mask:po_syscall_sysv; str:'SyscallSysV'),
  1721. (mask:po_syscall_basesysv;str:'SyscallBaseSysV'),
  1722. (mask:po_syscall_sysvbase;str:'SyscallSysVBase'),
  1723. (mask:po_syscall_r12base; str:'SyscallR12Base'),
  1724. (mask:po_syscall_has_libsym; str:'Has LibSym'),
  1725. (mask:po_inline; str:'Inline'),
  1726. (mask:po_compilerproc; str:'CompilerProc'),
  1727. (mask:po_has_importdll; str:'HasImportDLL'),
  1728. (mask:po_has_importname; str:'HasImportName'),
  1729. (mask:po_kylixlocal; str:'KylixLocal'),
  1730. (mask:po_dispid; str:'DispId'),
  1731. (mask:po_weakexternal; str:'WeakExternal'),
  1732. (mask:po_objc; str:'ObjC'),
  1733. (mask:po_enumerator_movenext; str:'EnumeratorMoveNext'),
  1734. (mask:po_optional; str: 'Optional'),
  1735. (mask:po_delphi_nested_cc;str: 'Delphi-style nested frameptr'),
  1736. (mask:po_java_nonvirtual; str: 'Java non-virtual method'),
  1737. (mask:po_ignore_for_overload_resolution;str: 'Ignored for overload resolution'),
  1738. (mask:po_rtlproc; str: 'RTL procedure'),
  1739. (mask:po_auto_raised_visibility; str: 'Visibility raised by compiler'),
  1740. (mask:po_far; str: 'Far'),
  1741. (mask:po_noreturn; str: 'No return'),
  1742. (mask:po_is_function_ref; str: 'Function reference'),
  1743. (mask:po_is_block; str: 'C "Block"')
  1744. );
  1745. var
  1746. proctypeoption : tproctypeoption;
  1747. i : longint;
  1748. first : boolean;
  1749. tempbuf : array[0..255] of byte;
  1750. begin
  1751. write([space,' Return type : ']);
  1752. readderef('', ProcDef.ReturnType);
  1753. proctypeoption:=tproctypeoption(ppufile.getbyte);
  1754. case proctypeoption of
  1755. potype_function: Include(ProcDef.Options, poFunction);
  1756. potype_procedure: Include(ProcDef.Options, poProcedure);
  1757. potype_constructor: Include(ProcDef.Options, poConstructor);
  1758. potype_destructor: Include(ProcDef.Options, poDestructor);
  1759. potype_operator: Include(ProcDef.Options, poOperator);
  1760. end;
  1761. write([space,' TypeOption : ']);
  1762. first:=true;
  1763. for i:=1 to high(proctypeopt) do
  1764. if (proctypeopt[i].mask=proctypeoption) then
  1765. begin
  1766. if first then
  1767. first:=false
  1768. else
  1769. write(', ');
  1770. write(proctypeopt[i].str);
  1771. end;
  1772. writeln;
  1773. proccalloption:=tproccalloption(ppufile.getbyte);
  1774. writeln([space,' CallOption : ',proccalloptionStr[proccalloption]]);
  1775. ppufile.getnormalset(procoptions);
  1776. if procoptions<>[] then
  1777. begin
  1778. if po_classmethod in procoptions then Include(ProcDef.Options, poClassMethod);
  1779. if po_virtualmethod in procoptions then Include(ProcDef.Options, poVirtual);
  1780. if po_abstractmethod in procoptions then Include(ProcDef.Options, poAbstract);
  1781. if po_overridingmethod in procoptions then Include(ProcDef.Options, poOverriding);
  1782. if po_overload in procoptions then Include(ProcDef.Options, poOverload);
  1783. if po_inline in procoptions then Include(ProcDef.Options, poInline);
  1784. if (po_methodpointer in procoptions) and (ProcDef.DefType = dtProcType) then
  1785. TPpuProcTypeDef(ProcDef).MethodPtr:=True;
  1786. write([space,' Options : ']);
  1787. first:=true;
  1788. for i:=1 to high(procopt) do
  1789. if (procopt[i].mask in procoptions) then
  1790. begin
  1791. if first then
  1792. first:=false
  1793. else
  1794. write(', ');
  1795. write(procopt[i].str);
  1796. end;
  1797. writeln;
  1798. end;
  1799. if (po_explicitparaloc in procoptions) then
  1800. begin
  1801. i:=ppufile.getbyte;
  1802. ppufile.getdata(tempbuf,i);
  1803. end;
  1804. if po_syscall_has_libsym in procoptions then
  1805. readderef(space);
  1806. end;
  1807. { type tvaroption is in unit symconst }
  1808. { register variable }
  1809. { type tvarregable is in unit symconst }
  1810. procedure readabstractvarsym(const s:string;var varoptions:tvaroptions; VarDef: TPpuVarDef = nil);
  1811. type
  1812. tvaropt=record
  1813. mask : tvaroption;
  1814. str : string[30];
  1815. end;
  1816. const
  1817. varopt : array[1..ord(high(tvaroption))] of tvaropt=(
  1818. (mask:vo_is_external; str:'External'),
  1819. (mask:vo_is_dll_var; str:'DLLVar'),
  1820. (mask:vo_is_thread_var; str:'ThreadVar'),
  1821. (mask:vo_has_local_copy; str:'HasLocalCopy'),
  1822. (mask:vo_is_const; str:'Constant'),
  1823. (mask:vo_is_public; str:'Public'),
  1824. (mask:vo_is_high_para; str:'HighValue'),
  1825. (mask:vo_is_funcret; str:'Funcret'),
  1826. (mask:vo_is_self; str:'Self'),
  1827. (mask:vo_is_vmt; str:'VMT'),
  1828. (mask:vo_is_result; str:'Result'),
  1829. (mask:vo_is_parentfp; str:'ParentFP'),
  1830. (mask:vo_is_loop_counter; str:'LoopCounter'),
  1831. (mask:vo_is_hidden_para; str:'Hidden'),
  1832. (mask:vo_has_explicit_paraloc;str:'ExplicitParaloc'),
  1833. (mask:vo_is_syscall_lib; str:'SysCallLib'),
  1834. (mask:vo_has_mangledname; str:'HasMangledName'),
  1835. (mask:vo_is_typed_const; str:'TypedConst'),
  1836. (mask:vo_is_range_check; str:'RangeCheckSwitch'),
  1837. (mask:vo_is_overflow_check; str:'OverflowCheckSwitch'),
  1838. (mask:vo_is_typinfo_para; str:'TypeInfo'),
  1839. (mask:vo_is_msgsel;str:'MsgSel'),
  1840. (mask:vo_is_weak_external;str:'WeakExternal'),
  1841. (mask:vo_is_first_field;str:'IsFirstField'),
  1842. (mask:vo_volatile; str:'Volatile'),
  1843. (mask:vo_has_section; str:'HasSection'),
  1844. (mask:vo_force_finalize; str:'ForceFinalize'),
  1845. (mask:vo_is_default_var; str:'DefaultIntrinsicVar')
  1846. );
  1847. var
  1848. i : longint;
  1849. first : boolean;
  1850. begin
  1851. readcommonsym(s, VarDef);
  1852. i:=ppufile.getbyte;
  1853. if (VarDef <> nil) and (VarDef.DefType = dtParam) then
  1854. with TPpuParamDef(VarDef) do
  1855. case tvarspez(i) of
  1856. vs_value: Spez:=psValue;
  1857. vs_var: Spez:=psVar;
  1858. vs_out: Spez:=psOut;
  1859. vs_const: Spez:=psConst;
  1860. vs_constref: Spez:=psConstRef;
  1861. end;
  1862. writeln([space,' Spez : ',Varspez2Str(i)]);
  1863. writeln([space,' Regable : ',Varregable2Str(ppufile.getbyte)]);
  1864. writeln([space,' Addr Taken : ',(ppufile.getbyte<>0)]);
  1865. write ([space,' Var Type : ']);
  1866. if VarDef <> nil then
  1867. readderef('',VarDef.VarType)
  1868. else
  1869. readderef('');
  1870. ppufile.getsmallset(varoptions);
  1871. if varoptions<>[] then
  1872. begin
  1873. if (VarDef <> nil) and (VarDef.DefType = dtParam) and (vo_is_hidden_para in varoptions) then
  1874. TPpuParamDef(VarDef).Spez:=psHidden;
  1875. write([space,' Options : ']);
  1876. first:=true;
  1877. for i:=1 to high(varopt) do
  1878. if (varopt[i].mask in varoptions) then
  1879. begin
  1880. if first then
  1881. first:=false
  1882. else
  1883. write(', ');
  1884. write(varopt[i].str);
  1885. end;
  1886. writeln;
  1887. end;
  1888. end;
  1889. procedure readobjectdefoptions(ObjDef: TPpuObjectDef = nil);
  1890. type
  1891. tsymopt=record
  1892. mask : tobjectoption;
  1893. str : string[30];
  1894. end;
  1895. const
  1896. symopt : array[1..ord(high(tobjectoption))] of tsymopt=(
  1897. (mask:oo_is_forward; str:'IsForward'),
  1898. (mask:oo_is_abstract; str:'IsAbstract'),
  1899. (mask:oo_is_sealed; str:'IsSealed'),
  1900. (mask:oo_has_virtual; str:'HasVirtual'),
  1901. (mask:oo_has_private; str:'HasPrivate'),
  1902. (mask:oo_has_protected; str:'HasProtected'),
  1903. (mask:oo_has_strictprivate; str:'HasStrictPrivate'),
  1904. (mask:oo_has_strictprotected;str:'HasStrictProtected'),
  1905. (mask:oo_has_constructor; str:'HasConstructor'),
  1906. (mask:oo_has_destructor; str:'HasDestructor'),
  1907. (mask:oo_has_vmt; str:'HasVMT'),
  1908. (mask:oo_has_msgstr; str:'HasMsgStr'),
  1909. (mask:oo_has_msgint; str:'HasMsgInt'),
  1910. (mask:oo_can_have_published; str:'CanHavePublished'),
  1911. (mask:oo_has_default_property;str:'HasDefaultProperty'),
  1912. (mask:oo_has_valid_guid; str:'HasValidGUID'),
  1913. (mask:oo_has_enumerator_movenext; str:'HasEnumeratorMoveNext'),
  1914. (mask:oo_has_enumerator_current; str:'HasEnumeratorCurrent'),
  1915. (mask:oo_is_external; str:'External'),
  1916. (mask:oo_is_formal; str:'Formal'),
  1917. (mask:oo_is_classhelper; str:'Class Helper/Category'),
  1918. (mask:oo_has_class_constructor; str:'HasClassConstructor'),
  1919. (mask:oo_has_class_destructor; str:'HasClassDestructor'),
  1920. (mask:oo_is_enum_class; str:'JvmEnumClass'),
  1921. (mask:oo_has_new_destructor; str:'HasNewDestructor')
  1922. );
  1923. var
  1924. i : longint;
  1925. first : boolean;
  1926. begin
  1927. ppufile.getsmallset(current_objectoptions);
  1928. if current_objectoptions<>[] then
  1929. begin
  1930. if ObjDef <> nil then
  1931. begin
  1932. if oo_is_abstract in current_objectoptions then
  1933. Include(ObjDef.Options, ooIsAbstract);
  1934. end;
  1935. first:=true;
  1936. for i:=1 to high(symopt) do
  1937. if (symopt[i].mask in current_objectoptions) then
  1938. begin
  1939. if first then
  1940. first:=false
  1941. else
  1942. write(', ');
  1943. write(symopt[i].str);
  1944. end;
  1945. end;
  1946. writeln;
  1947. end;
  1948. procedure readprocimploptions(const space: string; out implprocoptions: timplprocoptions);
  1949. type
  1950. tpiopt=record
  1951. mask : timplprocoption;
  1952. str : string[30];
  1953. end;
  1954. const
  1955. piopt : array[low(timplprocoption)..high(timplprocoption)] of tpiopt=(
  1956. (mask:pio_empty; str:'IsEmpty'),
  1957. (mask:pio_has_inlininginfo; str:'HasInliningInfo')
  1958. );
  1959. var
  1960. i: timplprocoption;
  1961. first: boolean;
  1962. begin
  1963. ppufile.getsmallset(implprocoptions);
  1964. if implprocoptions<>[] then
  1965. begin
  1966. first:=true;
  1967. write([space,' Options : ']);
  1968. for i:=low(piopt) to high(piopt) do
  1969. begin
  1970. if i in implprocoptions then
  1971. begin
  1972. if first then
  1973. first:=false
  1974. else
  1975. write(', ');
  1976. write(piopt[i].str);
  1977. end;
  1978. end;
  1979. writeln;
  1980. end;
  1981. end;
  1982. procedure readarraydefoptions(ArrayDef: TPpuArrayDef);
  1983. { type tarraydefoption is in unit symconst }
  1984. const
  1985. symopt : array[tarraydefoption] of string = (
  1986. { ado_IsConvertedPointer } 'ConvertedPointer',
  1987. { ado_IsDynamicArray } 'IsDynamicArray',
  1988. { ado_IsVariant } 'IsVariant',
  1989. { ado_IsConstructor } 'IsConstructor',
  1990. { ado_IsArrayOfConst } 'ArrayOfConst',
  1991. { ado_IsConstString } 'ConstString',
  1992. { ado_IsBitPacked } 'BitPacked'
  1993. );
  1994. var
  1995. symoptions: tarraydefoptions;
  1996. i: tarraydefoption;
  1997. first: boolean;
  1998. begin
  1999. ppufile.getsmallset(symoptions);
  2000. if symoptions<>[] then
  2001. begin
  2002. if ado_IsDynamicArray in symoptions then Include(ArrayDef.Options, aoDynamic);
  2003. first:=true;
  2004. for i:=Low(symopt) to high(symopt) do
  2005. if (i in symoptions) then
  2006. begin
  2007. if first then
  2008. first:=false
  2009. else
  2010. write(', ');
  2011. write(symopt[i]);
  2012. end;
  2013. end;
  2014. writeln;
  2015. end;
  2016. (* options for properties
  2017. tpropertyoption=(ppo_none,
  2018. ppo_indexed,
  2019. ppo_defaultproperty,
  2020. ppo_stored,
  2021. ppo_hasparameters,
  2022. ppo_implements,
  2023. ppo_enumerator_current,
  2024. ppo_overrides,
  2025. ppo_dispid_write { no longer used }
  2026. );
  2027. tpropertyoptions=set of tpropertyoption;
  2028. *)
  2029. function readpropertyoptions:tpropertyoptions;
  2030. { type tarraydefoption is in unit symconst }
  2031. type
  2032. tpropopt=record
  2033. mask : tpropertyoption;
  2034. str : string[30];
  2035. end;
  2036. const
  2037. symopt : array[1..ord(high(tpropertyoption))] of tpropopt=(
  2038. (mask:ppo_indexed;str:'indexed'),
  2039. (mask:ppo_defaultproperty;str:'default'),
  2040. (mask:ppo_stored;str:'stored'),
  2041. (mask:ppo_hasparameters;str:'has parameters'),
  2042. (mask:ppo_implements;str:'implements'),
  2043. (mask:ppo_enumerator_current;str:'enumerator current'),
  2044. (mask:ppo_overrides;str:'overrides'),
  2045. (mask:ppo_dispid_write;str:'dispid write') { no longer used }
  2046. );
  2047. var
  2048. i : longint;
  2049. first : boolean;
  2050. begin
  2051. ppufile.getsmallset(result);
  2052. if result<>[] then
  2053. begin
  2054. first:=true;
  2055. for i:=1 to high(symopt) do
  2056. if (symopt[i].mask in result) then
  2057. begin
  2058. if first then
  2059. first:=false
  2060. else
  2061. write(', ');
  2062. write(symopt[i].str);
  2063. end;
  2064. end;
  2065. writeln;
  2066. end;
  2067. procedure readnodetree;
  2068. var
  2069. l : longint;
  2070. p : pointer;
  2071. begin
  2072. with ppufile do
  2073. begin
  2074. if space<>'' then
  2075. Writeln([space,'------ nodetree ------']);
  2076. if readentry=ibnodetree then
  2077. begin
  2078. l:=entrysize;
  2079. Writeln([space,'Tree size : ',l]);
  2080. { Read data to prevent error that entry is not completly read }
  2081. getmem(p,l);
  2082. getdata(p^,l);
  2083. freemem(p);
  2084. end
  2085. else
  2086. begin
  2087. WriteError('!! ibnodetree not found');
  2088. end;
  2089. end;
  2090. end;
  2091. procedure ReadCreatedObjTypes;
  2092. var
  2093. i,j,
  2094. len,
  2095. bssize: longint;
  2096. bs: pbyte;
  2097. begin
  2098. if ppufile.readentry<>ibcreatedobjtypes then
  2099. begin
  2100. WriteError('!! ibcreatedobjtypes entry not found');
  2101. ppufile.skipdata(ppufile.entrysize);
  2102. exit
  2103. end;
  2104. writeln;
  2105. writeln([space,'WPO info']);
  2106. writeln([space,'--------']);
  2107. len:=ppufile.getlongint;
  2108. writeln([space,'** Instantiated Object/Class types: ',len,' **']);
  2109. space:=space+' ';
  2110. for i:=0 to len-1 do
  2111. readderef(space);
  2112. setlength(space,length(space)-2);
  2113. len:=ppufile.getlongint;
  2114. writeln([space,'** Instantiated ClassRef types: ',len,' **']);
  2115. space:=space+' ';
  2116. for i:=0 to len-1 do
  2117. readderef(space);
  2118. setlength(space,length(space)-2);
  2119. len:=ppufile.getlongint;
  2120. writeln([space,'** Possibly instantiated ClassRef types : ',len,' **']);
  2121. space:=space+' ';
  2122. for i:=0 to len-1 do
  2123. readderef(space);
  2124. setlength(space,length(space)-2);
  2125. len:=ppufile.getlongint;
  2126. writeln([space,'** Class types with called virtual methods info : ',len,' **']);
  2127. space:=space+' ';
  2128. for i:=0 to len-1 do
  2129. begin
  2130. write([space,'Class def : ']);
  2131. readderef('');
  2132. write([space+' ','Called vmtentries : ']);
  2133. bssize:=ppufile.getlongint;
  2134. getmem(bs,bssize);
  2135. ppufile.readdata(bs^,bssize);
  2136. for j:=0 to bssize*8-1 do
  2137. if (((bs+j shr 3)^ shr (j and 7)) and 1) <> 0 then
  2138. write([j,', ']);
  2139. writeln;
  2140. freemem(bs);
  2141. end;
  2142. setlength(space,length(space)-2);
  2143. end;
  2144. {****************************************************************************
  2145. Read Symbols Part
  2146. ****************************************************************************}
  2147. procedure readsymbols(const s:string; ParentDef: TPpuContainerDef = nil);
  2148. function _finddef(symdef: TPpuDef): TPpuDef;
  2149. begin
  2150. Result:=nil;
  2151. if symdef.Ref.IsCurUnit then
  2152. begin;
  2153. Result:=CurUnit.FindById(symdef.Ref.Id);
  2154. if (Result <> nil) and (Result.Ref.Id = symdef.Id) then
  2155. begin
  2156. Result.Name:=symdef.Name;
  2157. Result.FilePos:=symdef.FilePos;
  2158. end
  2159. else
  2160. Result:=nil;
  2161. end;
  2162. end;
  2163. type
  2164. pguid = ^tguid;
  2165. tguid = packed record
  2166. D1: LongWord;
  2167. D2: Word;
  2168. D3: Word;
  2169. D4: array[0..7] of Byte;
  2170. end;
  2171. var
  2172. b : byte;
  2173. pc : pchar;
  2174. ch : dword;
  2175. startnewline : boolean;
  2176. i,j,len : longint;
  2177. prettyname, ss : ansistring;
  2178. ws: widestring;
  2179. guid : tguid;
  2180. realvalue : ppureal;
  2181. doublevalue : double;
  2182. singlevalue : single;
  2183. extended : TSplit80bitReal;
  2184. tempbuf : array[0..127] of char;
  2185. pw : pcompilerwidestring;
  2186. varoptions : tvaroptions;
  2187. propoptions : tpropertyoptions;
  2188. iexp: Tconstexprint;
  2189. def: TPpuDef;
  2190. constdef: TPpuConstDef absolute def;
  2191. begin
  2192. with ppufile do
  2193. begin
  2194. if space<>'' then
  2195. Writeln([space,'------ ',s,' ------']);
  2196. if readentry=ibstartsyms then
  2197. begin
  2198. Writeln([space,'Symtable count: ',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 (po_has_importdll in procoptions) then
  2867. writeln([space,' Import DLL : ',getstring]);
  2868. if (po_has_importname in procoptions) then
  2869. writeln([space,' Import Name : ',getstring]);
  2870. writeln([space,' Import Nr : ',getword]);
  2871. if (po_msgint in procoptions) then
  2872. writeln([space,' MsgInt : ',getlongint]);
  2873. if (po_msgstr in procoptions) then
  2874. writeln([space,' MsgStr : ',getstring]);
  2875. if (po_dispid in procoptions) then
  2876. writeln([space,' DispID: ',ppufile.getlongint]);
  2877. readprocimploptions(space,implprocoptions);
  2878. if (pio_has_inlininginfo in implprocoptions) then
  2879. begin
  2880. write ([space,' FuncretSym : ']);
  2881. readderef('');
  2882. readprocinfooptions(space);
  2883. end;
  2884. b:=ppufile.getbyte;
  2885. if b<>0 then
  2886. begin
  2887. write ([space,' Alias names : ']);
  2888. for j:=1 to b do
  2889. begin
  2890. write(ppufile.getstring);
  2891. if j<b then
  2892. write(', ');
  2893. end;
  2894. writeln;
  2895. end;
  2896. tokenbufsize:=ppufile.getlongint;
  2897. if tokenbufsize<>0 then
  2898. begin
  2899. write ([space,' Declaration token buffer : TODO']);
  2900. tokenbuf:=allocmem(tokenbufsize);
  2901. ppufile.getdata(tokenbuf^,tokenbufsize);
  2902. freemem(tokenbuf);
  2903. end;
  2904. if tsystemcpu(ppufile.header.common.cpu)=cpu_powerpc then
  2905. begin
  2906. if po_syscall_has_libsym in procoptions then
  2907. begin
  2908. { library symbol for AmigaOS/MorphOS }
  2909. write ([space,' Library symbol : ']);
  2910. readderef('');
  2911. end;
  2912. end;
  2913. if not EndOfEntry then
  2914. HasMoreInfos;
  2915. space:=' '+space;
  2916. { parast }
  2917. readsymtable('parast', TPpuProcDef(def));
  2918. { localst }
  2919. if (pio_has_inlininginfo in implprocoptions) then
  2920. readsymtable('localst');
  2921. if (pio_has_inlininginfo in implprocoptions) then
  2922. readnodetree;
  2923. delete(space,1,4);
  2924. end;
  2925. ibprocvardef :
  2926. begin
  2927. def:=TPpuProcTypeDef.Create(ParentDef);
  2928. readcommondef('Procedural type (ProcVar) definition',defoptions,def);
  2929. read_abstract_proc_def(calloption,procoptions, TPpuProcDef(def));
  2930. writeln([space,' Symtable level :',ppufile.getbyte]);
  2931. if not EndOfEntry then
  2932. HasMoreInfos;
  2933. space:=' '+space;
  2934. { parast }
  2935. readsymtable('parast',TPpuProcDef(def));
  2936. delete(space,1,4);
  2937. if tsystemcpu(ppufile.header.common.cpu)=cpu_jvm then
  2938. readderef('');
  2939. end;
  2940. ibshortstringdef :
  2941. begin
  2942. strdef:=TPpuStringDef.Create(ParentDef);
  2943. strdef.StrType:=stShort;
  2944. readcommondef('ShortString definition',defoptions,strdef);
  2945. strdef.Len:=getbyte;
  2946. writeln([space,' Length : ',strdef.Len]);
  2947. end;
  2948. ibwidestringdef :
  2949. begin
  2950. strdef:=TPpuStringDef.Create(ParentDef);
  2951. strdef.StrType:=stWide;
  2952. readcommondef('WideString definition',defoptions,strdef);
  2953. strdef.Len:=getaint;
  2954. writeln([space,' Length : ',strdef.Len]);
  2955. end;
  2956. ibunicodestringdef :
  2957. begin
  2958. strdef:=TPpuStringDef.Create(ParentDef);
  2959. strdef.StrType:=stUnicode;
  2960. readcommondef('UnicodeString definition',defoptions,strdef);
  2961. strdef.Len:=getaint;
  2962. writeln([space,' Length : ',strdef.Len]);
  2963. writeln([space,' Encoding : ',getword]);
  2964. end;
  2965. ibansistringdef :
  2966. begin
  2967. strdef:=TPpuStringDef.Create(ParentDef);
  2968. strdef.StrType:=stAnsi;
  2969. readcommondef('AnsiString definition',defoptions,strdef);
  2970. strdef.Len:=getaint;
  2971. writeln([space,' Length : ',strdef.Len]);
  2972. writeln([space,' Encoding : ',getword]);
  2973. end;
  2974. iblongstringdef :
  2975. begin
  2976. strdef:=TPpuStringDef.Create(ParentDef);
  2977. strdef.StrType:=stLong;
  2978. readcommondef('Longstring definition',defoptions,strdef);
  2979. strdef.Len:=getaint;
  2980. writeln([space,' Length : ',strdef.Len]);
  2981. end;
  2982. ibrecorddef :
  2983. begin
  2984. objdef:=TPpuRecordDef.Create(ParentDef);
  2985. readcommondef('Record definition',defoptions, objdef);
  2986. def.Name:=getstring;
  2987. writeln([space,' Name of Record : ',objdef.Name]);
  2988. writeln([space,' Import lib/pkg : ',getstring]);
  2989. write ([space,' Options : ']);
  2990. readobjectdefoptions(objdef);
  2991. if (df_copied_def in defoptions) then
  2992. begin
  2993. Include(TPpuRecordDef(def).Options, ooCopied);
  2994. write([space,' Copied from : ']);
  2995. readderef('',objdef.Ancestor);
  2996. end
  2997. else
  2998. begin
  2999. writeln([space,' FieldAlign : ',shortint(getbyte)]);
  3000. writeln([space,' RecordAlign : ',shortint(getbyte)]);
  3001. writeln([space,' PadAlign : ',shortint(getbyte)]);
  3002. writeln([space,'UseFieldAlignment : ',shortint(getbyte)]);
  3003. writeln([space,' RecordAlignMin : ',shortint(getbyte)]);
  3004. objdef.Size:=getasizeint;
  3005. writeln([space,' DataSize : ',objdef.Size]);
  3006. writeln([space,' PaddingSize : ',getword]);
  3007. end;
  3008. if not EndOfEntry then
  3009. HasMoreInfos;
  3010. {read the record definitions and symbols}
  3011. if not(df_copied_def in current_defoptions) then
  3012. begin
  3013. space:=' '+space;
  3014. readrecsymtableoptions;
  3015. readsymtable('fields',TPpuRecordDef(def));
  3016. Delete(space,1,4);
  3017. end;
  3018. end;
  3019. ibobjectdef :
  3020. begin
  3021. objdef:=TPpuObjectDef.Create(ParentDef);
  3022. readcommondef('Object/Class definition',defoptions,objdef);
  3023. objdef.Name:=getstring;
  3024. writeln([space,' Name of Class : ',objdef.Name]);
  3025. writeln([space,' Import lib/pkg : ',getstring]);
  3026. write ([space,' Options : ']);
  3027. readobjectdefoptions(objdef);
  3028. b:=getbyte;
  3029. write ([space,' Type : ']);
  3030. case tobjecttyp(b) of
  3031. odt_class : writeln('class');
  3032. odt_object : writeln('object');
  3033. odt_interfacecom : writeln('interfacecom');
  3034. odt_interfacecorba : writeln('interfacecorba');
  3035. odt_cppclass : writeln('cppclass');
  3036. odt_dispinterface : writeln('dispinterface');
  3037. odt_objcclass : writeln('objcclass');
  3038. odt_objcprotocol : writeln('objcprotocol');
  3039. odt_helper : writeln('helper');
  3040. odt_objccategory : writeln('objccategory');
  3041. odt_javaclass : writeln('Java class');
  3042. odt_interfacejava : writeln('Java interface');
  3043. else WriteWarning('Invalid object type: ' + IntToStr(b));
  3044. end;
  3045. case tobjecttyp(b) of
  3046. odt_class, odt_cppclass, odt_objcclass, odt_javaclass:
  3047. objdef.ObjType:=otClass;
  3048. odt_object:
  3049. objdef.ObjType:=otObject;
  3050. odt_interfacecom, odt_interfacecorba, odt_interfacejava, odt_dispinterface:
  3051. objdef.ObjType:=otInterface;
  3052. odt_helper:
  3053. objdef.ObjType:=otHelper;
  3054. end;
  3055. writeln([space,' External name : ',getstring]);
  3056. objdef.Size:=getasizeint;
  3057. writeln([space,' DataSize : ',objdef.Size]);
  3058. writeln([space,' PaddingSize : ',getword]);
  3059. writeln([space,' FieldAlign : ',shortint(getbyte)]);
  3060. writeln([space,' RecordAlign : ',shortint(getbyte)]);
  3061. writeln([space,' RecordAlignMin : ',shortint(getbyte)]);
  3062. write ([space, ' VmtField : ']);
  3063. readderef('',nil);
  3064. write ([space, ' Ancestor Class : ']);
  3065. readderef('',objdef.Ancestor);
  3066. if tobjecttyp(b) in [odt_interfacecom,odt_interfacecorba,odt_dispinterface] then
  3067. begin
  3068. { IIDGUID }
  3069. for j:=1to 16 do
  3070. getbyte;
  3071. objdef.IID:=getstring;
  3072. writeln([space,' IID String : ',objdef.IID]);
  3073. end;
  3074. writeln([space,' Abstract methods : ',getlongint]);
  3075. if tobjecttyp(b)=odt_helper then
  3076. begin
  3077. write([space,' Helper parent : ']);
  3078. readderef('',objdef.HelperParent);
  3079. end;
  3080. l:=getlongint;
  3081. writeln([space,' VMT entries: ',l]);
  3082. for j:=1 to l do
  3083. begin
  3084. write([space,' ']);
  3085. readderef('');
  3086. write([space,' Visibility: ']);
  3087. readvisibility;
  3088. end;
  3089. if tobjecttyp(b) in [odt_class,odt_objcclass,odt_objcprotocol,odt_javaclass,odt_interfacejava] then
  3090. begin
  3091. l:=getlongint;
  3092. writeln([space,' Impl Intf Count : ',l]);
  3093. for j:=1 to l do
  3094. begin
  3095. write ([space,' - Definition : ']);
  3096. readderef('');
  3097. write ([space,' - Getter Def : ']);
  3098. readderef('');
  3099. writeln([space,' IOffset : ',getlongint]);
  3100. writeln([space,' Entry type : ',IntfEntryType2Str(getbyte)]);
  3101. end;
  3102. end;
  3103. if df_copied_def in current_defoptions then
  3104. begin
  3105. Include(objdef.Options, ooCopied);
  3106. writeln(' Copy of def: ');
  3107. readderef('',objdef.Ancestor);
  3108. end;
  3109. if not EndOfEntry then
  3110. HasMoreInfos;
  3111. if not(df_copied_def in current_defoptions) then
  3112. begin
  3113. {read the record definitions and symbols}
  3114. space:=' '+space;
  3115. readrecsymtableoptions;
  3116. readsymtable('fields',objdef);
  3117. Delete(space,1,4);
  3118. end;
  3119. end;
  3120. ibfiledef :
  3121. begin
  3122. filedef:=TPpuFileDef.Create(ParentDef);
  3123. ReadCommonDef('File definition',defoptions,filedef);
  3124. write ([space,' Type : ']);
  3125. case getbyte of
  3126. 0 : begin
  3127. writeln('Text');
  3128. filedef.FileType:=ftText;
  3129. end;
  3130. 1 : begin
  3131. writeln('Typed');
  3132. filedef.FileType:=ftTyped;
  3133. write ([space,' File of Type : ']);
  3134. readderef('',filedef.TypeRef);
  3135. end;
  3136. 2 : begin
  3137. writeln('Untyped');
  3138. filedef.FileType:=ftUntyped;
  3139. end;
  3140. end;
  3141. end;
  3142. ibformaldef :
  3143. begin
  3144. def:=TPpuFormalDef.Create(ParentDef);
  3145. readcommondef('Generic definition (void-typ)',defoptions,def);
  3146. TPpuFormalDef(def).IsTyped:=(getbyte<>0);
  3147. writeln([space,' Is Typed : ',TPpuFormalDef(def).IsTyped]);
  3148. end;
  3149. ibundefineddef :
  3150. begin
  3151. def:=TPpuUndefinedDef.Create(ParentDef);
  3152. readcommondef('Undefined definition (generic parameter)',defoptions,def);
  3153. end;
  3154. ibenumdef :
  3155. begin
  3156. enumdef:=TPpuEnumDef.Create(ParentDef);
  3157. readcommondef('Enumeration type definition',defoptions,enumdef);
  3158. enumdef.ElLow:=getaint;
  3159. writeln([space,' Smallest element : ',enumdef.ElLow]);
  3160. enumdef.ElHigh:=getaint;
  3161. writeln([space,' Largest element : ',enumdef.ElHigh]);
  3162. enumdef.Size:=byte(getaint);
  3163. writeln([space,' Size : ',enumdef.Size]);
  3164. if df_copied_def in defoptions then
  3165. begin
  3166. write([space,'Base enumeration type : ']);
  3167. readderef('',enumdef.CopyFrom);
  3168. end
  3169. else
  3170. begin
  3171. space:=' '+space;
  3172. readsymtable('elements',enumdef);
  3173. delete(space,1,4);
  3174. end;
  3175. if tsystemcpu(ppufile.header.common.cpu)=cpu_jvm then
  3176. begin
  3177. write([space,' Class def : ']);
  3178. readderef('');
  3179. end;
  3180. end;
  3181. ibclassrefdef :
  3182. begin
  3183. def:=TPpuClassRefDef.Create(ParentDef);
  3184. readcommondef('Class reference definition',defoptions,def);
  3185. write ([space,' Pointed Type : ']);
  3186. readderef('',TPpuClassRefDef(def).ClassRef);
  3187. end;
  3188. ibsetdef :
  3189. begin
  3190. setdef:=TPpuSetDef.Create(ParentDef);
  3191. readcommondef('Set definition',defoptions,setdef);
  3192. write ([space,' Element type : ']);
  3193. readderef('',setdef.ElType);
  3194. setdef.Size:=getasizeint;
  3195. writeln([space,' Size : ',setdef.Size]);
  3196. setdef.SetBase:=getasizeint;
  3197. writeln([space,' Set Base : ',setdef.SetBase]);
  3198. setdef.SetMax:=getasizeint;
  3199. writeln([space,' Set Max : ',setdef.SetMax]);
  3200. end;
  3201. ibvariantdef :
  3202. begin
  3203. def:=TPpuVariantDef.Create(ParentDef);
  3204. readcommondef('Variant definition',defoptions,def);
  3205. write ([space,' Varianttype : ']);
  3206. b:=getbyte;
  3207. case tvarianttype(b) of
  3208. vt_normalvariant :
  3209. writeln('Normal');
  3210. vt_olevariant :
  3211. begin
  3212. TPpuVariantDef(def).IsOLE:=True;
  3213. writeln('OLE');
  3214. end
  3215. else
  3216. WriteWarning('Invalid varianttype: ' + IntToStr(b));
  3217. end;
  3218. end;
  3219. iberror :
  3220. begin
  3221. WriteError('!! Error in PPU');
  3222. exit;
  3223. end;
  3224. ibenddefs :
  3225. break;
  3226. else
  3227. begin
  3228. WriteError('!! Skipping unsupported PPU Entry in definitions: '+IntToStr(b));
  3229. end;
  3230. end;
  3231. if (def <> nil) and (def.Parent = nil) then
  3232. def.Free;
  3233. if not EndOfEntry then
  3234. HasMoreInfos;
  3235. until false;
  3236. end;
  3237. end;
  3238. procedure readmoduleoptions(space : string);
  3239. type
  3240. { tmoduleoption type is in unit fmodule }
  3241. tmoduleoption = (mo_none,
  3242. mo_hint_deprecated,
  3243. mo_hint_platform,
  3244. mo_hint_library,
  3245. mo_hint_unimplemented,
  3246. mo_hint_experimental,
  3247. mo_has_deprecated_msg
  3248. );
  3249. tmoduleoptions = set of tmoduleoption;
  3250. tmoduleopt=record
  3251. mask : tmoduleoption;
  3252. str : string[30];
  3253. end;
  3254. const
  3255. moduleopts=ord(high(tmoduleoption));
  3256. moduleopt : array[1..moduleopts] of tmoduleopt=(
  3257. (mask:mo_hint_deprecated; str:'Hint Deprecated'),
  3258. (mask:mo_hint_platform; str:'Hint Platform'),
  3259. (mask:mo_hint_library; str:'Hint Library'),
  3260. (mask:mo_hint_unimplemented; str:'Hint Unimplemented'),
  3261. (mask:mo_hint_experimental; str:'Hint Experimental'),
  3262. (mask:mo_has_deprecated_msg; str:'Has Deprecated Message')
  3263. );
  3264. var
  3265. moduleoptions : tmoduleoptions;
  3266. i : longint;
  3267. first : boolean;
  3268. begin
  3269. ppufile.getsmallset(moduleoptions);
  3270. if moduleoptions<>[] then
  3271. begin
  3272. first:=true;
  3273. for i:=1to moduleopts do
  3274. if (moduleopt[i].mask in moduleoptions) then
  3275. begin
  3276. if first then
  3277. first:=false
  3278. else
  3279. write(', ');
  3280. write(moduleopt[i].str);
  3281. end;
  3282. end;
  3283. writeln;
  3284. if mo_has_deprecated_msg in moduleoptions then
  3285. writeln([space,'Deprecated : ', ppufile.getstring]);
  3286. end;
  3287. {****************************************************************************
  3288. Read General Part
  3289. ****************************************************************************}
  3290. procedure readinterface(silent : boolean);
  3291. var
  3292. b : byte;
  3293. sourcenumber, i : longint;
  3294. begin
  3295. with ppufile do
  3296. begin
  3297. repeat
  3298. b:=readentry;
  3299. case b of
  3300. ibmodulename :
  3301. begin
  3302. CurUnit.Name:=getstring;
  3303. if not silent then
  3304. Writeln(['Module Name: ',CurUnit.Name]);
  3305. end;
  3306. ibmoduleoptions:
  3307. if not silent then
  3308. readmoduleoptions(' ');
  3309. ibsourcefiles :
  3310. begin
  3311. sourcenumber:=1;
  3312. if not silent then
  3313. while not EndOfEntry do
  3314. begin
  3315. with TPpuSrcFile.Create(CurUnit.SourceFiles) do begin
  3316. Name:=getstring;
  3317. i:=getlongint;
  3318. if i >= 0 then
  3319. FileTime:=FileDateToDateTime(i);
  3320. Writeln(['Source file ',sourcenumber,' : ',Name,' ',filetimestring(i)]);
  3321. end;
  3322. inc(sourcenumber);
  3323. end;
  3324. end;
  3325. {$IFDEF MACRO_DIFF_HINT}
  3326. ibusedmacros :
  3327. begin
  3328. if not silent then
  3329. while not EndOfEntry do
  3330. begin
  3331. Write('Conditional ',getstring);
  3332. b:=getbyte;
  3333. if boolean(b)=true then
  3334. write(' defined at startup')
  3335. else
  3336. write(' not defined at startup');
  3337. b:=getbyte;
  3338. if boolean(b)=true then
  3339. writeln(' was used')
  3340. else
  3341. writeln;
  3342. end;
  3343. end;
  3344. {$ENDIF}
  3345. ibloadunit :
  3346. if not silent then
  3347. ReadLoadUnit;
  3348. iblinkunitofiles :
  3349. if not silent then
  3350. ReadLinkContainer('Link unit object file: ');
  3351. iblinkunitstaticlibs :
  3352. if not silent then
  3353. ReadLinkContainer('Link unit static lib: ');
  3354. iblinkunitsharedlibs :
  3355. if not silent then
  3356. ReadLinkContainer('Link unit shared lib: ');
  3357. iblinkotherofiles :
  3358. if not silent then
  3359. ReadLinkContainer('Link other object file: ');
  3360. iblinkotherstaticlibs :
  3361. if not silent then
  3362. ReadLinkContainer('Link other static lib: ');
  3363. iblinkothersharedlibs :
  3364. if not silent then
  3365. ReadLinkContainer('Link other shared lib: ');
  3366. iblinkotherframeworks:
  3367. if not silent then
  3368. ReadLinkContainer('Link framework: ');
  3369. ibmainname:
  3370. if not silent then
  3371. Writeln(['Specified main program symbol name: ',getstring]);
  3372. ibImportSymbols :
  3373. if not silent then
  3374. ReadImportSymbols;
  3375. ibderefdata :
  3376. ReadDerefData;
  3377. ibderefmap :
  3378. ReadDerefMap;
  3379. ibwpofile :
  3380. if not silent then
  3381. ReadWpoFileInfo;
  3382. ibresources :
  3383. if not silent then
  3384. ReadLinkContainer('Resource file: ');
  3385. iberror :
  3386. begin
  3387. WriteError('Error in PPU');
  3388. exit;
  3389. end;
  3390. ibendinterface :
  3391. break;
  3392. else
  3393. begin
  3394. WriteError('!! Skipping unsupported PPU Entry in General Part: '+IntToStr(b));
  3395. end;
  3396. end;
  3397. until false;
  3398. end;
  3399. end;
  3400. {****************************************************************************
  3401. Read Implementation Part
  3402. ****************************************************************************}
  3403. procedure readimplementation;
  3404. var
  3405. b : byte;
  3406. begin
  3407. with ppufile do
  3408. begin
  3409. repeat
  3410. b:=readentry;
  3411. case b of
  3412. ibasmsymbols :
  3413. ReadAsmSymbols;
  3414. ibloadunit :
  3415. ReadLoadUnit;
  3416. ibunitimportsyms :
  3417. ReadUnitImportSyms;
  3418. iberror :
  3419. begin
  3420. WriteError('Error in PPU');
  3421. exit;
  3422. end;
  3423. ibendimplementation :
  3424. break;
  3425. else
  3426. begin
  3427. WriteError('!! Skipping unsupported PPU Entry in Implementation: '+IntToStr(b));
  3428. end;
  3429. end;
  3430. until false;
  3431. end;
  3432. end;
  3433. procedure dofile (filename : string);
  3434. begin
  3435. { reset }
  3436. space:='';
  3437. { fix filename }
  3438. if pos('.',filename)=0 then
  3439. filename:=filename+'.ppu';
  3440. ppufile:=tppufile.create(filename);
  3441. if not ppufile.openfile then
  3442. begin
  3443. WriteError('IO-Error when opening : '+filename+', Skipping');
  3444. exit;
  3445. end;
  3446. { PPU File is open, check for PPU Id }
  3447. if not ppufile.CheckPPUID then
  3448. begin
  3449. WriteError(Filename+' : Not a valid PPU file, Skipping');
  3450. exit;
  3451. end;
  3452. { Check PPU Version }
  3453. ppuversion:=ppufile.getversion;
  3454. Writeln(['Analyzing ',filename,' (v',PPUVersion,')']);
  3455. if PPUVersion<16 then
  3456. begin
  3457. WriteError(Filename+' : Old PPU Formats (<v16) are not supported, Skipping');
  3458. exit;
  3459. end;
  3460. if not SkipVersionCheck and (PPUVersion <> CurrentPPUVersion) then
  3461. begin
  3462. WriteError(Format('Unsupported PPU version %d. Expecting PPU version %d.', [PPUVersion, CurrentPPUVersion]));
  3463. exit;
  3464. end;
  3465. CurUnit:=TPpuUnitDef.Create(UnitList);
  3466. CurUnit.Version:=ppuversion;
  3467. { Write PPU Header Information }
  3468. if (verbose and v_header)<>0 then
  3469. begin
  3470. Writeln;
  3471. Writeln('Header');
  3472. Writeln('-------');
  3473. with ppufile.header do
  3474. begin
  3475. Writeln(['Compiler version : ',ppufile.header.common.compiler shr 14,'.',
  3476. (ppufile.header.common.compiler shr 7) and $7f,'.',
  3477. ppufile.header.common.compiler and $7f]);
  3478. WriteLn(['Target processor : ',Cpu2Str(common.cpu)]);
  3479. WriteLn(['Target operating system : ',Target2Str(common.target)]);
  3480. Writeln(['Unit flags : ',PPUFlags2Str(common.flags)]);
  3481. Writeln(['FileSize (w/o header) : ',common.size]);
  3482. Writeln(['Checksum : ',hexstr(checksum,8)]);
  3483. Writeln(['Interface Checksum : ',hexstr(interface_checksum,8)]);
  3484. Writeln(['Indirect Checksum : ',hexstr(indirect_checksum,8)]);
  3485. Writeln(['Definitions stored : ',tostr(deflistsize)]);
  3486. Writeln(['Symbols stored : ',tostr(symlistsize)]);
  3487. end;
  3488. end;
  3489. with ppufile.header do
  3490. begin
  3491. CurUnit.Crc:=checksum;
  3492. CurUnit.IntfCrc:=interface_checksum;
  3493. CurUnit.TargetCPU:=Cpu2Str(common.cpu);
  3494. CurUnit.TargetOS:=Target2Str(common.target);
  3495. end;
  3496. {read the general stuff}
  3497. if (verbose and v_interface)<>0 then
  3498. begin
  3499. Writeln;
  3500. Writeln('Interface section');
  3501. Writeln('------------------');
  3502. readinterface(false);
  3503. end
  3504. { We need derefdata from Interface }
  3505. else if verbose and (v_defs or v_syms or v_implementation)<>0 then
  3506. readinterface(true)
  3507. else
  3508. ppufile.skipuntilentry(ibendinterface);
  3509. Writeln;
  3510. Writeln('Interface symtable');
  3511. Writeln('----------------------');
  3512. readsymtableoptions('interface');
  3513. {read the definitions}
  3514. if (verbose and v_defs)<>0 then
  3515. begin
  3516. Writeln;
  3517. Writeln('Interface definitions');
  3518. Writeln('----------------------');
  3519. readdefinitions('interface', CurUnit);
  3520. end
  3521. else
  3522. ppufile.skipuntilentry(ibenddefs);
  3523. {read the symbols}
  3524. if (verbose and v_syms)<>0 then
  3525. begin
  3526. Writeln;
  3527. Writeln('Interface Symbols');
  3528. Writeln('------------------');
  3529. readsymbols('interface',CurUnit);
  3530. end
  3531. else
  3532. ppufile.skipuntilentry(ibendsyms);
  3533. {read the macro symbols}
  3534. if (verbose and v_syms)<>0 then
  3535. begin
  3536. Writeln;
  3537. Writeln('Interface Macro Symbols');
  3538. Writeln('-----------------------');
  3539. end;
  3540. if ppufile.readentry<>ibexportedmacros then
  3541. begin
  3542. WriteError('!! Error in PPU');
  3543. exit;
  3544. end;
  3545. if boolean(ppufile.getbyte) then
  3546. begin
  3547. readsymtableoptions('interface macro');
  3548. {skip the definition section for macros (since they are never used) }
  3549. ppufile.skipuntilentry(ibenddefs);
  3550. {read the macro symbols}
  3551. if (verbose and v_syms)<>0 then
  3552. readsymbols('interface macro')
  3553. else
  3554. ppufile.skipuntilentry(ibendsyms);
  3555. end
  3556. else
  3557. Writeln('(no exported macros)');
  3558. {read the implementation stuff}
  3559. if (verbose and v_implementation)<>0 then
  3560. begin
  3561. Writeln;
  3562. Writeln('Implementation section');
  3563. Writeln('-----------------------');
  3564. readimplementation;
  3565. end
  3566. else
  3567. ppufile.skipuntilentry(ibendimplementation);
  3568. {read the static symtable}
  3569. Writeln;
  3570. Writeln('Implementation symtable');
  3571. Writeln('----------------------');
  3572. readsymtableoptions('implementation');
  3573. if (ppufile.header.common.flags and uf_local_symtable)<>0 then
  3574. begin
  3575. if (verbose and v_defs)<>0 then
  3576. begin
  3577. Writeln;
  3578. Writeln('Static definitions');
  3579. Writeln('----------------------');
  3580. readdefinitions('implementation', nil);
  3581. end
  3582. else
  3583. ppufile.skipuntilentry(ibenddefs);
  3584. {read the symbols}
  3585. if (verbose and v_syms)<>0 then
  3586. begin
  3587. Writeln;
  3588. Writeln('Static Symbols');
  3589. Writeln('------------------');
  3590. readsymbols('implementation');
  3591. end
  3592. else
  3593. ppufile.skipuntilentry(ibendsyms);
  3594. end;
  3595. ReadCreatedObjTypes;
  3596. FreeDerefdata;
  3597. {shutdown ppufile}
  3598. ppufile.closefile;
  3599. ppufile.free;
  3600. Writeln;
  3601. end;
  3602. procedure WriteLogo;
  3603. begin
  3604. writeln(Title+' Version '+version_string);
  3605. writeln(Copyright);
  3606. writeln;
  3607. end;
  3608. procedure help;
  3609. begin
  3610. WriteLogo;
  3611. writeln('usage: ppudump [options] <filename1> <filename2>...');
  3612. writeln;
  3613. writeln('[options] can be:');
  3614. writeln(' -F<format> Set output format to <format>');
  3615. writeln(' t - text format (default)');
  3616. writeln(' j - JSON format');
  3617. writeln(' x - XML format');
  3618. writeln(' -M Exit with ExitCode=2 if more information is available');
  3619. writeln(' -S Skip PPU version check. May lead to reading errors');
  3620. writeln(' -V<verbose> Set verbosity to <verbose>');
  3621. writeln(' H - Show header info');
  3622. writeln(' I - Show interface');
  3623. writeln(' M - Show implementation');
  3624. writeln(' S - Show interface symbols');
  3625. writeln(' D - Show interface definitions');
  3626. writeln(' A - Show all');
  3627. writeln(' -h, -? This helpscreen');
  3628. halt;
  3629. end;
  3630. var
  3631. startpara,
  3632. nrfile,i : longint;
  3633. para : string;
  3634. const
  3635. error_on_more : boolean = false;
  3636. begin
  3637. if paramcount<1 then
  3638. help;
  3639. { turn verbose on by default }
  3640. verbose:=v_all;
  3641. { read options }
  3642. startpara:=1;
  3643. while copy(paramstr(startpara),1,1)='-' do
  3644. begin
  3645. para:=paramstr(startpara);
  3646. case upcase(para[2]) of
  3647. 'F' : begin
  3648. FreeAndNil(pout);
  3649. if Length(para) > 2 then
  3650. case upcase(para[3]) of
  3651. 'T':
  3652. nostdout:=False;
  3653. 'J':
  3654. begin
  3655. nostdout:=True;
  3656. pout:=TPpuJsonOutput.Create(Output);
  3657. end;
  3658. 'X':
  3659. begin
  3660. nostdout:=True;
  3661. pout:=TPpuXmlOutput.Create(Output);
  3662. end;
  3663. else
  3664. begin
  3665. WriteError('Invalid output format: ' + para[3]);
  3666. Halt(1);
  3667. end;
  3668. end;
  3669. end;
  3670. 'M' : error_on_more:=true;
  3671. 'S' : SkipVersionCheck:=True;
  3672. 'V' : begin
  3673. verbose:=0;
  3674. for i:=3 to length(para) do
  3675. case upcase(para[i]) of
  3676. 'H' : verbose:=verbose or v_header;
  3677. 'I' : verbose:=verbose or v_interface;
  3678. 'M' : verbose:=verbose or v_implementation;
  3679. 'D' : verbose:=verbose or v_defs;
  3680. 'S' : verbose:=verbose or v_syms;
  3681. 'A' : verbose:=verbose or v_all;
  3682. end;
  3683. end;
  3684. 'H' : help;
  3685. '?' : help;
  3686. else
  3687. begin
  3688. WriteError('Invalid option: ' + para);
  3689. Halt(1);
  3690. end;
  3691. end;
  3692. inc(startpara);
  3693. end;
  3694. if not nostdout then
  3695. WriteLogo;
  3696. UnitList:=TPpuContainerDef.Create(nil);
  3697. try
  3698. UnitList.ItemsName:='';
  3699. { process files }
  3700. for nrfile:=startpara to paramcount do
  3701. dofile (paramstr(nrfile));
  3702. if not has_errors and (pout <> nil) then
  3703. begin
  3704. pout.Init;
  3705. UnitList.Write(pout);
  3706. pout.Done;
  3707. end;
  3708. finally
  3709. UnitList.Free;
  3710. pout.Free;
  3711. end;
  3712. if has_errors then
  3713. Halt(1);
  3714. if error_on_more and
  3715. (has_more_infos or has_warnings) then
  3716. Halt(2);
  3717. end.