ppudump.pp 118 KB

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