ppudump.pp 116 KB

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