ppudump.pp 118 KB

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