ppudump.pp 109 KB

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