ppudump.pp 110 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718
  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. (mask:pi_has_stack_allocs;
  1094. str:' allocates memory on stack, so stack may be unbalanced on exit ')
  1095. );
  1096. var
  1097. procinfooptions : tprocinfoflags;
  1098. i : longint;
  1099. first : boolean;
  1100. begin
  1101. ppufile.getsmallset(procinfooptions);
  1102. if procinfooptions<>[] then
  1103. begin
  1104. first:=true;
  1105. for i:=0 to procinfoopts do
  1106. if (procinfoopt[i].mask in procinfooptions) then
  1107. begin
  1108. if first then
  1109. first:=false
  1110. else
  1111. write(', ');
  1112. write(procinfoopt[i].str);
  1113. end;
  1114. end;
  1115. writeln;
  1116. end;
  1117. procedure readsymoptions(space : string; Def: TPpuDef = nil);
  1118. type
  1119. tsymopt=record
  1120. mask : tsymoption;
  1121. str : string[30];
  1122. end;
  1123. const
  1124. symopts=ord(high(tsymoption)) - ord(low(tsymoption));
  1125. { sp_none = 0 corresponds to nothing }
  1126. symopt : array[1..symopts] of tsymopt=(
  1127. (mask:sp_static; str:'Static'),
  1128. (mask:sp_hint_deprecated; str:'Hint Deprecated'),
  1129. (mask:sp_hint_platform; str:'Hint Platform'),
  1130. (mask:sp_hint_library; str:'Hint Library'),
  1131. (mask:sp_hint_unimplemented; str:'Hint Unimplemented'),
  1132. (mask:sp_hint_experimental; str:'Hint Experimental'),
  1133. (mask:sp_has_overloaded; str:'Has overloaded'),
  1134. (mask:sp_internal; str:'Internal'),
  1135. (mask:sp_implicitrename; str:'Implicit Rename'),
  1136. (mask:sp_generic_para; str:'Generic Parameter'),
  1137. (mask:sp_has_deprecated_msg; str:'Has Deprecated Message'),
  1138. (mask:sp_generic_dummy; str:'Generic Dummy'),
  1139. (mask:sp_explicitrename; str:'Explicit Rename')
  1140. );
  1141. var
  1142. symoptions : tsymoptions;
  1143. i : longint;
  1144. first : boolean;
  1145. begin
  1146. ppufile.getsmallset(symoptions);
  1147. if symoptions<>[] then
  1148. begin
  1149. if Def <> nil then
  1150. if sp_internal in symoptions then
  1151. Def.Visibility:=dvHidden;
  1152. first:=true;
  1153. for i:=1to symopts do
  1154. if (symopt[i].mask in symoptions) then
  1155. begin
  1156. if first then
  1157. first:=false
  1158. else
  1159. write(', ');
  1160. write(symopt[i].str);
  1161. end;
  1162. end;
  1163. writeln;
  1164. if sp_has_deprecated_msg in symoptions then
  1165. writeln([space,'Deprecated : ', ppufile.getstring]);
  1166. end;
  1167. procedure readvisibility(Def: TPpuDef = nil);
  1168. var
  1169. i: byte;
  1170. begin
  1171. i:=ppufile.getbyte;
  1172. if Def <> nil then
  1173. case tvisibility(i) of
  1174. vis_public: Def.Visibility:=dvPublic;
  1175. vis_published: Def.Visibility:=dvPublished;
  1176. vis_protected, vis_strictprotected: Def.Visibility:=dvProtected;
  1177. else Def.Visibility:=dvPrivate;
  1178. end;
  1179. writeln(Visibility2Str(i));
  1180. end;
  1181. procedure readcommonsym(const s:string; Def: TPpuDef = nil);
  1182. var
  1183. i: integer;
  1184. n: string;
  1185. begin
  1186. i:=ppufile.getlongint;
  1187. if Def <> nil then
  1188. Def.SetSymId(i);
  1189. writeln([space,'** Symbol Id ',i,' **']);
  1190. n:=ppufile.getstring;
  1191. if Def <> nil then
  1192. Def.Name:=n;
  1193. writeln([space,s,n]);
  1194. write ([space,' File Pos : ']);
  1195. readposinfo(Def);
  1196. write ([space,' Visibility : ']);
  1197. readvisibility(Def);
  1198. write ([space,' SymOptions : ']);
  1199. readsymoptions(space+' ',Def);
  1200. end;
  1201. var
  1202. { needed during tobjectdef parsing... }
  1203. current_defoptions : tdefoptions;
  1204. current_objectoptions : tobjectoptions;
  1205. procedure readcommondef(const s:string; out defoptions: tdefoptions; Def: TPpuDef = nil);
  1206. type
  1207. tdefopt=record
  1208. mask : tdefoption;
  1209. str : string[30];
  1210. end;
  1211. tdefstateinfo=record
  1212. mask : tdefstate;
  1213. str : string[30];
  1214. end;
  1215. tgenconstrflag=record
  1216. mask : tgenericconstraintflag;
  1217. str : string[30];
  1218. end;
  1219. ptoken=^ttoken;
  1220. pmsgstate =^tmsgstate;
  1221. const
  1222. defopt : array[1..ord(high(tdefoption))] of tdefopt=(
  1223. (mask:df_unique; str:'Unique Type'),
  1224. (mask:df_generic; str:'Generic'),
  1225. (mask:df_specialization; str:'Specialization'),
  1226. (mask:df_copied_def; str:'Copied Typedef'),
  1227. (mask:df_genconstraint; str:'Generic Constraint')
  1228. );
  1229. defstate : array[1..ord(high(tdefstate))] of tdefstateinfo=(
  1230. (mask:ds_vmt_written; str:'VMT Written'),
  1231. (mask:ds_rtti_table_used; str:'RTTITable Used'),
  1232. (mask:ds_init_table_used; str:'InitTable Used'),
  1233. (mask:ds_rtti_table_written; str:'RTTITable Written'),
  1234. (mask:ds_init_table_written; str:'InitTable Written'),
  1235. (mask:ds_dwarf_dbg_info_used; str:'Dwarf DbgInfo Used'),
  1236. (mask:ds_dwarf_dbg_info_written;str:'Dwarf DbgInfo Written')
  1237. );
  1238. genconstrflag : array[1..ord(high(tgenericconstraintflag))] of tgenconstrflag=(
  1239. (mask:gcf_constructor; str:'Constructor'),
  1240. (mask:gcf_class; str:'Class'),
  1241. (mask:gcf_record; str:'Record')
  1242. );
  1243. var
  1244. defstates : tdefstates;
  1245. i, nb{, msgvalue}, mesgnb : longint;
  1246. first : boolean;
  1247. copy_size, min_size, tokenbufsize : longint;
  1248. tokenbuf : pbyte;
  1249. // idtoken,
  1250. token : ttoken;
  1251. // state : tmsgstate;
  1252. new_settings : Tsettings;
  1253. len : sizeint;
  1254. wstring : widestring;
  1255. astring : ansistring;
  1256. genconstr : tgenericconstraintflags;
  1257. function readtoken: ttoken;
  1258. var
  1259. b,b2 : byte;
  1260. begin
  1261. b:=tokenbuf[i];
  1262. inc(i);
  1263. if (b and $80)<>0 then
  1264. begin
  1265. b2:=tokenbuf[i];
  1266. inc(i);
  1267. result:=ttoken(((b and $7f) shl 8) or b2);
  1268. end
  1269. else
  1270. result:=ttoken(b);
  1271. end;
  1272. function gettokenbufdword : dword;
  1273. var
  1274. var32 : dword;
  1275. begin
  1276. var32:=pdword(@tokenbuf[i])^;
  1277. inc(i,sizeof(dword));
  1278. if ppufile.change_endian then
  1279. var32:=swapendian(var32);
  1280. result:=var32;
  1281. end;
  1282. function gettokenbufword : word;
  1283. var
  1284. var16 : word;
  1285. begin
  1286. var16:=pword(@tokenbuf[i])^;
  1287. inc(i,sizeof(word));
  1288. if ppufile.change_endian then
  1289. var16:=swapendian(var16);
  1290. result:=var16;
  1291. end;
  1292. function gettokenbufsizeint : int64;
  1293. var
  1294. var64 : int64;
  1295. var32 : longint;
  1296. var16 : smallint;
  1297. begin
  1298. if CpuAddrBitSize[cpu]=64 then
  1299. begin
  1300. var64:=pint64(@tokenbuf[i])^;
  1301. inc(i,sizeof(int64));
  1302. if ppufile.change_endian then
  1303. var64:=swapendian(var64);
  1304. result:=var64;
  1305. end
  1306. else if CpuAddrBitSize[cpu]=32 then
  1307. begin
  1308. var32:=plongint(@tokenbuf[i])^;
  1309. inc(i,sizeof(longint));
  1310. if ppufile.change_endian then
  1311. var32:=swapendian(var32);
  1312. result:=var32;
  1313. end
  1314. else if CpuAddrBitSize[cpu]=16 then
  1315. begin
  1316. var16:=psmallint(@tokenbuf[i])^;
  1317. inc(i,sizeof(smallint));
  1318. if ppufile.change_endian then
  1319. var16:=swapendian(var16);
  1320. result:=var16;
  1321. end
  1322. else
  1323. begin
  1324. WriteError('Wrong CpuAddrBitSize');
  1325. result:=0;
  1326. end;
  1327. end;
  1328. begin
  1329. i:=ppufile.getlongint;
  1330. if Def <> nil then
  1331. Def.Id:=i;
  1332. writeln([space,'** Definition Id ',i,' **']);
  1333. writeln([space,s]);
  1334. write ([space,' Type symbol : ']);
  1335. if Def <> nil then
  1336. readderef('', Def.Ref)
  1337. else
  1338. readderef('');
  1339. write ([space,' DefOptions : ']);
  1340. ppufile.getsmallset(defoptions);
  1341. if defoptions<>[] then
  1342. begin
  1343. first:=true;
  1344. for i:=1to high(defopt) do
  1345. if (defopt[i].mask in defoptions) then
  1346. begin
  1347. if first then
  1348. first:=false
  1349. else
  1350. write(', ');
  1351. write(defopt[i].str);
  1352. end;
  1353. end;
  1354. writeln;
  1355. write ([space,' DefStates : ']);
  1356. ppufile.getsmallset(defstates);
  1357. if defstates<>[] then
  1358. begin
  1359. first:=true;
  1360. for i:=1 to high(defstate) do
  1361. if (defstate[i].mask in defstates) then
  1362. begin
  1363. if first then
  1364. first:=false
  1365. else
  1366. write(', ');
  1367. write(defstate[i].str);
  1368. end;
  1369. end;
  1370. writeln;
  1371. if df_genconstraint in defoptions then
  1372. begin
  1373. ppufile.getsmallset(genconstr);
  1374. write ([space,' GenConstraints : ']);
  1375. if genconstr<>[] then
  1376. begin
  1377. first:=true;
  1378. for i:=1 to high(genconstrflag) do
  1379. if (genconstrflag[i].mask in genconstr) then
  1380. begin
  1381. if first then
  1382. first:=false
  1383. else
  1384. write(', ');
  1385. write(genconstrflag[i].str);
  1386. end;
  1387. end;
  1388. writeln;
  1389. len:=ppufile.getasizeint;
  1390. if len>0 then
  1391. begin
  1392. space:=' '+space;
  1393. writeln([space,'------ constraint defs begin ------']);
  1394. for i:=0 to len-1 do
  1395. begin
  1396. writeln([space,'------ constraint def ',i,' ------']);
  1397. readderef(space);
  1398. end;
  1399. writeln([space,'------ constraint defs end ------']);
  1400. delete(space,1,4);
  1401. end;
  1402. end;
  1403. if df_generic in defoptions then
  1404. begin
  1405. tokenbufsize:=ppufile.getlongint;
  1406. writeln([space,' Tokenbuffer size : ',tokenbufsize]);
  1407. tokenbuf:=allocmem(tokenbufsize);
  1408. ppufile.getdata(tokenbuf^,tokenbufsize);
  1409. i:=0;
  1410. write([space,' Tokens: ']);
  1411. while i<tokenbufsize do
  1412. begin
  1413. token:=readtoken;
  1414. if token<>_GENERICSPECIALTOKEN then
  1415. begin
  1416. if token <= high(ttoken) then
  1417. write(arraytokeninfo[token].str)
  1418. else
  1419. begin
  1420. HasMoreInfos;
  1421. write('Error in Token List');
  1422. break;
  1423. end;
  1424. {idtoken:=}readtoken;
  1425. end;
  1426. case token of
  1427. _CWCHAR,
  1428. _CWSTRING :
  1429. begin
  1430. len:=gettokenbufsizeint;
  1431. setlength(wstring,len);
  1432. move(tokenbuf[i],wstring[1],len*2);
  1433. write([' ',wstring]);
  1434. inc(i,len*2);
  1435. end;
  1436. _CSTRING:
  1437. begin
  1438. len:=gettokenbufsizeint;
  1439. setlength(astring,len);
  1440. move(tokenbuf[i],astring[1],len);
  1441. write([' ',astring]);
  1442. inc(i,len);
  1443. end;
  1444. _CCHAR,
  1445. _INTCONST,
  1446. _REALNUMBER :
  1447. begin
  1448. write([' ',pshortstring(@tokenbuf[i])^]);
  1449. inc(i,tokenbuf[i]+1);
  1450. end;
  1451. _ID :
  1452. begin
  1453. write([' ',pshortstring(@tokenbuf[i])^]);
  1454. inc(i,tokenbuf[i]+1);
  1455. end;
  1456. _GENERICSPECIALTOKEN:
  1457. begin
  1458. { Short version of column change,
  1459. byte or $80 used }
  1460. if (tokenbuf[i] and $80)<>0 then
  1461. begin
  1462. write(['Col: ',tokenbuf[i] and $7f]);
  1463. inc(i);
  1464. end
  1465. else
  1466. case tspecialgenerictoken(tokenbuf[i]) of
  1467. ST_LOADSETTINGS:
  1468. begin
  1469. inc(i);
  1470. write('Settings');
  1471. { This does not load pmessage pointer }
  1472. new_settings.pmessage:=nil;
  1473. { TSettings size depends in target...
  1474. We first read the size of the copied part }
  1475. { Still not cross endian ready :( }
  1476. copy_size:=gettokenbufsizeint;
  1477. if copy_size < sizeof(tsettings)-sizeof(pointer) then
  1478. min_size:=copy_size
  1479. else
  1480. min_size:= sizeof(tsettings)-sizeof(pointer);
  1481. move(tokenbuf[i],new_settings, min_size);
  1482. inc(i,copy_size);
  1483. end;
  1484. ST_LOADMESSAGES:
  1485. begin
  1486. inc(i);
  1487. write('Messages:');
  1488. mesgnb:=tokenbuf[i];
  1489. inc(i);
  1490. for nb:=1 to mesgnb do
  1491. begin
  1492. {msgvalue:=}gettokenbufsizeint;
  1493. inc(i,sizeof(sizeint));
  1494. //state:=tmsgstate(gettokenbufsizeint);
  1495. end;
  1496. end;
  1497. ST_LINE:
  1498. begin
  1499. inc(i);
  1500. write(['Line: ',gettokenbufdword]);
  1501. end;
  1502. ST_COLUMN:
  1503. begin
  1504. inc(i);
  1505. write(['Col: ',gettokenbufword]);
  1506. end;
  1507. ST_FILEINDEX:
  1508. begin
  1509. inc(i);
  1510. write(['File: ',gettokenbufword]);
  1511. end;
  1512. end;
  1513. end;
  1514. end;
  1515. if i<tokenbufsize then
  1516. write(',');
  1517. end;
  1518. writeln;
  1519. freemem(tokenbuf);
  1520. end;
  1521. if df_specialization in defoptions then
  1522. begin
  1523. write ([space,' Orig. GenericDef : ']);
  1524. readderef('');
  1525. end;
  1526. current_defoptions:=defoptions;
  1527. end;
  1528. { Read abstract procdef and return if inline procdef }
  1529. { type tproccalloption is in globtype unit }
  1530. { type tproctypeoption is in globtype unit }
  1531. { type tprocoption is in globtype unit }
  1532. procedure read_abstract_proc_def(var proccalloption:tproccalloption;var procoptions:tprocoptions; ProcDef: TPpuProcDef);
  1533. type
  1534. tproccallopt=record
  1535. mask : tproccalloption;
  1536. str : string[30];
  1537. end;
  1538. tproctypeopt=record
  1539. mask : tproctypeoption;
  1540. str : string[30];
  1541. end;
  1542. tprocopt=record
  1543. mask : tprocoption;
  1544. str : string[31];
  1545. end;
  1546. const
  1547. {proccalloptionStr is also in globtype unit }
  1548. proctypeopt : array[1..ord(high(tproctypeoption))] of tproctypeopt=(
  1549. (mask:potype_proginit; str:'ProgInit'),
  1550. (mask:potype_unitinit; str:'UnitInit'),
  1551. (mask:potype_unitfinalize; str:'UnitFinalize'),
  1552. (mask:potype_constructor; str:'Constructor'),
  1553. (mask:potype_destructor; str:'Destructor'),
  1554. (mask:potype_operator; str:'Operator'),
  1555. (mask:potype_procedure; str:'Procedure'),
  1556. (mask:potype_function; str:'Function'),
  1557. (mask:potype_class_constructor; str:'Class Constructor'),
  1558. (mask:potype_class_destructor; str:'Class Destructor'),
  1559. { Dispinterface property accessors }
  1560. (mask:potype_propgetter; str:'Property Getter'),
  1561. (mask:potype_propsetter; str:'Property Setter'),
  1562. (mask:potype_exceptfilter; str:'SEH filter')
  1563. );
  1564. procopt : array[1..ord(high(tprocoption))] of tprocopt=(
  1565. (mask:po_classmethod; str:'ClassMethod'),
  1566. (mask:po_virtualmethod; str:'VirtualMethod'),
  1567. (mask:po_abstractmethod; str:'AbstractMethod'),
  1568. (mask:po_finalmethod; str:'FinalMethod'),
  1569. (mask:po_staticmethod; str:'StaticMethod'),
  1570. (mask:po_overridingmethod;str:'OverridingMethod'),
  1571. (mask:po_methodpointer; str:'MethodPointer'),
  1572. (mask:po_interrupt; str:'Interrupt'),
  1573. (mask:po_iocheck; str:'IOCheck'),
  1574. (mask:po_assembler; str:'Assembler'),
  1575. (mask:po_msgstr; str:'MsgStr'),
  1576. (mask:po_msgint; str:'MsgInt'),
  1577. (mask:po_exports; str:'Exports'),
  1578. (mask:po_external; str:'External'),
  1579. (mask:po_overload; str:'Overload'),
  1580. (mask:po_varargs; str:'VarArgs'),
  1581. (mask:po_internconst; str:'InternConst'),
  1582. (mask:po_addressonly; str:'AddressOnly'),
  1583. (mask:po_public; str:'Public'),
  1584. (mask:po_hascallingconvention;str:'HasCallingConvention'),
  1585. (mask:po_reintroduce; str:'ReIntroduce'),
  1586. (mask:po_explicitparaloc; str:'ExplicitParaloc'),
  1587. (mask:po_nostackframe; str:'NoStackFrame'),
  1588. (mask:po_has_mangledname; str:'HasMangledName'),
  1589. (mask:po_has_public_name; str:'HasPublicName'),
  1590. (mask:po_forward; str:'Forward'),
  1591. (mask:po_global; str:'Global'),
  1592. (mask:po_has_inlininginfo;str:'HasInliningInfo'),
  1593. (mask:po_syscall_legacy; str:'SyscallLegacy'),
  1594. (mask:po_syscall_sysv; str:'SyscallSysV'),
  1595. (mask:po_syscall_basesysv;str:'SyscallBaseSysV'),
  1596. (mask:po_syscall_sysvbase;str:'SyscallSysVBase'),
  1597. (mask:po_syscall_r12base; str:'SyscallR12Base'),
  1598. (mask:po_inline; str:'Inline'),
  1599. (mask:po_compilerproc; str:'CompilerProc'),
  1600. (mask:po_has_importdll; str:'HasImportDLL'),
  1601. (mask:po_has_importname; str:'HasImportName'),
  1602. (mask:po_kylixlocal; str:'KylixLocal'),
  1603. (mask:po_dispid; str:'DispId'),
  1604. (mask:po_weakexternal; str:'WeakExternal'),
  1605. (mask:po_objc; str:'ObjC'),
  1606. (mask:po_enumerator_movenext; str:'EnumeratorMoveNext'),
  1607. (mask:po_optional; str: 'Optional'),
  1608. (mask:po_delphi_nested_cc;str: 'Delphi-style nested frameptr'),
  1609. (mask:po_java_nonvirtual; str: 'Java non-virtual method'),
  1610. (mask:po_ignore_for_overload_resolution;str: 'Ignored for overload resolution'),
  1611. (mask:po_rtlproc; str: 'RTL procedure'),
  1612. (mask:po_auto_raised_visibility; str: 'Visibility raised by compiler'),
  1613. (mask:po_far; str: 'Far')
  1614. );
  1615. var
  1616. proctypeoption : tproctypeoption;
  1617. i : longint;
  1618. first : boolean;
  1619. tempbuf : array[0..255] of byte;
  1620. begin
  1621. write([space,' Return type : ']);
  1622. readderef('', ProcDef.ReturnType);
  1623. writeln([space,' Fpu used : ',ppufile.getbyte]);
  1624. proctypeoption:=tproctypeoption(ppufile.getbyte);
  1625. case proctypeoption of
  1626. potype_function: Include(ProcDef.Options, poFunction);
  1627. potype_procedure: Include(ProcDef.Options, poProcedure);
  1628. potype_constructor: Include(ProcDef.Options, poConstructor);
  1629. potype_destructor: Include(ProcDef.Options, poDestructor);
  1630. potype_operator: Include(ProcDef.Options, poOperator);
  1631. end;
  1632. write([space,' TypeOption : ']);
  1633. first:=true;
  1634. for i:=1 to high(proctypeopt) do
  1635. if (proctypeopt[i].mask=proctypeoption) then
  1636. begin
  1637. if first then
  1638. first:=false
  1639. else
  1640. write(', ');
  1641. write(proctypeopt[i].str);
  1642. end;
  1643. writeln;
  1644. proccalloption:=tproccalloption(ppufile.getbyte);
  1645. writeln([space,' CallOption : ',proccalloptionStr[proccalloption]]);
  1646. ppufile.getnormalset(procoptions);
  1647. if procoptions<>[] then
  1648. begin
  1649. if po_classmethod in procoptions then Include(ProcDef.Options, poClassMethod);
  1650. if po_virtualmethod in procoptions then Include(ProcDef.Options, poVirtual);
  1651. if po_abstractmethod in procoptions then Include(ProcDef.Options, poAbstract);
  1652. if po_overridingmethod in procoptions then Include(ProcDef.Options, poOverriding);
  1653. if po_overload in procoptions then Include(ProcDef.Options, poOverload);
  1654. if po_inline in procoptions then Include(ProcDef.Options, poInline);
  1655. if (po_methodpointer in procoptions) and (ProcDef.DefType = dtProcType) then
  1656. TPpuProcTypeDef(ProcDef).MethodPtr:=True;
  1657. write([space,' Options : ']);
  1658. first:=true;
  1659. for i:=1 to high(procopt) do
  1660. if (procopt[i].mask in procoptions) then
  1661. begin
  1662. if first then
  1663. first:=false
  1664. else
  1665. write(', ');
  1666. write(procopt[i].str);
  1667. end;
  1668. writeln;
  1669. end;
  1670. if (po_explicitparaloc in procoptions) then
  1671. begin
  1672. i:=ppufile.getbyte;
  1673. ppufile.getdata(tempbuf,i);
  1674. end;
  1675. end;
  1676. { type tvaroption is in unit symconst }
  1677. { register variable }
  1678. { type tvarregable is in unit symconst }
  1679. procedure readabstractvarsym(const s:string;var varoptions:tvaroptions; VarDef: TPpuVarDef = nil);
  1680. type
  1681. tvaropt=record
  1682. mask : tvaroption;
  1683. str : string[30];
  1684. end;
  1685. const
  1686. varopt : array[1..ord(high(tvaroption))] of tvaropt=(
  1687. (mask:vo_is_external; str:'External'),
  1688. (mask:vo_is_dll_var; str:'DLLVar'),
  1689. (mask:vo_is_thread_var; str:'ThreadVar'),
  1690. (mask:vo_has_local_copy; str:'HasLocalCopy'),
  1691. (mask:vo_is_const; str:'Constant'),
  1692. (mask:vo_is_public; str:'Public'),
  1693. (mask:vo_is_high_para; str:'HighValue'),
  1694. (mask:vo_is_funcret; str:'Funcret'),
  1695. (mask:vo_is_self; str:'Self'),
  1696. (mask:vo_is_vmt; str:'VMT'),
  1697. (mask:vo_is_result; str:'Result'),
  1698. (mask:vo_is_parentfp; str:'ParentFP'),
  1699. (mask:vo_is_loop_counter; str:'LoopCounter'),
  1700. (mask:vo_is_hidden_para; str:'Hidden'),
  1701. (mask:vo_has_explicit_paraloc;str:'ExplicitParaloc'),
  1702. (mask:vo_is_syscall_lib; str:'SysCallLib'),
  1703. (mask:vo_has_mangledname; str:'HasMangledName'),
  1704. (mask:vo_is_typed_const; str:'TypedConst'),
  1705. (mask:vo_is_range_check; str:'RangeCheckSwitch'),
  1706. (mask:vo_is_overflow_check; str:'OverflowCheckSwitch'),
  1707. (mask:vo_is_typinfo_para; str:'TypeInfo'),
  1708. (mask:vo_is_msgsel;str:'MsgSel'),
  1709. (mask:vo_is_weak_external;str:'WeakExternal'),
  1710. (mask:vo_is_first_field;str:'IsFirstField'),
  1711. (mask:vo_volatile; str:'Volatile'),
  1712. (mask:vo_has_section; str:'HasSection'),
  1713. (mask:vo_force_finalize; str:'ForceFinalize'),
  1714. (mask:vo_is_default_var; str:'DefaultIntrinsicVar')
  1715. );
  1716. var
  1717. i : longint;
  1718. first : boolean;
  1719. begin
  1720. readcommonsym(s, VarDef);
  1721. i:=ppufile.getbyte;
  1722. if (VarDef <> nil) and (VarDef.DefType = dtParam) then
  1723. with TPpuParamDef(VarDef) do
  1724. case tvarspez(i) of
  1725. vs_value: Spez:=psValue;
  1726. vs_var: Spez:=psVar;
  1727. vs_out: Spez:=psOut;
  1728. vs_const: Spez:=psConst;
  1729. vs_constref: Spez:=psConstRef;
  1730. end;
  1731. writeln([space,' Spez : ',Varspez2Str(i)]);
  1732. writeln([space,' Regable : ',Varregable2Str(ppufile.getbyte)]);
  1733. writeln([space,' Addr Taken : ',(ppufile.getbyte<>0)]);
  1734. write ([space,' Var Type : ']);
  1735. if VarDef <> nil then
  1736. readderef('',VarDef.VarType)
  1737. else
  1738. readderef('');
  1739. ppufile.getsmallset(varoptions);
  1740. if varoptions<>[] then
  1741. begin
  1742. if (VarDef <> nil) and (VarDef.DefType = dtParam) and (vo_is_hidden_para in varoptions) then
  1743. TPpuParamDef(VarDef).Spez:=psHidden;
  1744. write([space,' Options : ']);
  1745. first:=true;
  1746. for i:=1 to high(varopt) do
  1747. if (varopt[i].mask in varoptions) then
  1748. begin
  1749. if first then
  1750. first:=false
  1751. else
  1752. write(', ');
  1753. write(varopt[i].str);
  1754. if varopt[i].mask = vo_has_section then
  1755. writeln(['Section name:',ppufile.getansistring]);
  1756. end;
  1757. writeln;
  1758. end;
  1759. end;
  1760. procedure readobjectdefoptions(ObjDef: TPpuObjectDef = nil);
  1761. type
  1762. tsymopt=record
  1763. mask : tobjectoption;
  1764. str : string[30];
  1765. end;
  1766. const
  1767. symopt : array[1..ord(high(tobjectoption))] of tsymopt=(
  1768. (mask:oo_is_forward; str:'IsForward'),
  1769. (mask:oo_is_abstract; str:'IsAbstract'),
  1770. (mask:oo_is_sealed; str:'IsSealed'),
  1771. (mask:oo_has_virtual; str:'HasVirtual'),
  1772. (mask:oo_has_private; str:'HasPrivate'),
  1773. (mask:oo_has_protected; str:'HasProtected'),
  1774. (mask:oo_has_strictprivate; str:'HasStrictPrivate'),
  1775. (mask:oo_has_strictprotected;str:'HasStrictProtected'),
  1776. (mask:oo_has_constructor; str:'HasConstructor'),
  1777. (mask:oo_has_destructor; str:'HasDestructor'),
  1778. (mask:oo_has_vmt; str:'HasVMT'),
  1779. (mask:oo_has_msgstr; str:'HasMsgStr'),
  1780. (mask:oo_has_msgint; str:'HasMsgInt'),
  1781. (mask:oo_can_have_published; str:'CanHavePublished'),
  1782. (mask:oo_has_default_property;str:'HasDefaultProperty'),
  1783. (mask:oo_has_valid_guid; str:'HasValidGUID'),
  1784. (mask:oo_has_enumerator_movenext; str:'HasEnumeratorMoveNext'),
  1785. (mask:oo_has_enumerator_current; str:'HasEnumeratorCurrent'),
  1786. (mask:oo_is_external; str:'External'),
  1787. (mask:oo_is_formal; str:'Formal'),
  1788. (mask:oo_is_classhelper; str:'Class Helper/Category'),
  1789. (mask:oo_has_class_constructor; str:'HasClassConstructor'),
  1790. (mask:oo_has_class_destructor; str:'HasClassDestructor'),
  1791. (mask:oo_is_enum_class; str:'JvmEnumClass'),
  1792. (mask:oo_has_new_destructor; str:'HasNewDestructor')
  1793. );
  1794. var
  1795. i : longint;
  1796. first : boolean;
  1797. begin
  1798. ppufile.getsmallset(current_objectoptions);
  1799. if current_objectoptions<>[] then
  1800. begin
  1801. if ObjDef <> nil then
  1802. begin
  1803. if oo_is_abstract in current_objectoptions then
  1804. Include(ObjDef.Options, ooIsAbstract);
  1805. end;
  1806. first:=true;
  1807. for i:=1 to high(symopt) do
  1808. if (symopt[i].mask in current_objectoptions) then
  1809. begin
  1810. if first then
  1811. first:=false
  1812. else
  1813. write(', ');
  1814. write(symopt[i].str);
  1815. end;
  1816. end;
  1817. writeln;
  1818. end;
  1819. procedure readarraydefoptions(ArrayDef: TPpuArrayDef);
  1820. { type tarraydefoption is in unit symconst }
  1821. const
  1822. symopt : array[tarraydefoption] of string = (
  1823. { ado_IsConvertedPointer } 'ConvertedPointer',
  1824. { ado_IsDynamicArray } 'IsDynamicArray',
  1825. { ado_IsVariant } 'IsVariant',
  1826. { ado_IsConstructor } 'IsConstructor',
  1827. { ado_IsArrayOfConst } 'ArrayOfConst',
  1828. { ado_IsConstString } 'ConstString',
  1829. { ado_IsBitPacked } 'BitPacked'
  1830. );
  1831. var
  1832. symoptions: tarraydefoptions;
  1833. i: tarraydefoption;
  1834. first: boolean;
  1835. begin
  1836. ppufile.getsmallset(symoptions);
  1837. if symoptions<>[] then
  1838. begin
  1839. if ado_IsDynamicArray in symoptions then Include(ArrayDef.Options, aoDynamic);
  1840. first:=true;
  1841. for i:=Low(symopt) to high(symopt) do
  1842. if (i in symoptions) then
  1843. begin
  1844. if first then
  1845. first:=false
  1846. else
  1847. write(', ');
  1848. write(symopt[i]);
  1849. end;
  1850. end;
  1851. writeln;
  1852. end;
  1853. (* options for properties
  1854. tpropertyoption=(ppo_none,
  1855. ppo_indexed,
  1856. ppo_defaultproperty,
  1857. ppo_stored,
  1858. ppo_hasparameters,
  1859. ppo_implements,
  1860. ppo_enumerator_current,
  1861. ppo_overrides,
  1862. ppo_dispid_write { no longer used }
  1863. );
  1864. tpropertyoptions=set of tpropertyoption;
  1865. *)
  1866. function readpropertyoptions:tpropertyoptions;
  1867. { type tarraydefoption is in unit symconst }
  1868. type
  1869. tpropopt=record
  1870. mask : tpropertyoption;
  1871. str : string[30];
  1872. end;
  1873. const
  1874. symopt : array[1..ord(high(tpropertyoption))] of tpropopt=(
  1875. (mask:ppo_indexed;str:'indexed'),
  1876. (mask:ppo_defaultproperty;str:'default'),
  1877. (mask:ppo_stored;str:'stored'),
  1878. (mask:ppo_hasparameters;str:'has parameters'),
  1879. (mask:ppo_implements;str:'implements'),
  1880. (mask:ppo_enumerator_current;str:'enumerator current'),
  1881. (mask:ppo_overrides;str:'overrides'),
  1882. (mask:ppo_dispid_write;str:'dispid write') { no longer used }
  1883. );
  1884. var
  1885. i : longint;
  1886. first : boolean;
  1887. begin
  1888. ppufile.getsmallset(result);
  1889. if result<>[] then
  1890. begin
  1891. first:=true;
  1892. for i:=1 to high(symopt) do
  1893. if (symopt[i].mask in result) then
  1894. begin
  1895. if first then
  1896. first:=false
  1897. else
  1898. write(', ');
  1899. write(symopt[i].str);
  1900. end;
  1901. end;
  1902. writeln;
  1903. end;
  1904. procedure readnodetree;
  1905. var
  1906. l : longint;
  1907. p : pointer;
  1908. begin
  1909. with ppufile do
  1910. begin
  1911. if space<>'' then
  1912. Writeln([space,'------ nodetree ------']);
  1913. if readentry=ibnodetree then
  1914. begin
  1915. l:=entrysize;
  1916. Writeln([space,'Tree size : ',l]);
  1917. { Read data to prevent error that entry is not completly read }
  1918. getmem(p,l);
  1919. getdata(p^,l);
  1920. freemem(p);
  1921. end
  1922. else
  1923. begin
  1924. WriteError('!! ibnodetree not found');
  1925. end;
  1926. end;
  1927. end;
  1928. procedure ReadCreatedObjTypes;
  1929. var
  1930. i,j,
  1931. len,
  1932. bssize: longint;
  1933. bs: pbyte;
  1934. begin
  1935. if ppufile.readentry<>ibcreatedobjtypes then
  1936. begin
  1937. WriteError('!! ibcreatedobjtypes entry not found');
  1938. ppufile.skipdata(ppufile.entrysize);
  1939. exit
  1940. end;
  1941. writeln;
  1942. writeln([space,'WPO info']);
  1943. writeln([space,'--------']);
  1944. len:=ppufile.getlongint;
  1945. writeln([space,'** Instantiated Object/Class types: ',len,' **']);
  1946. space:=space+' ';
  1947. for i:=0 to len-1 do
  1948. readderef(space);
  1949. setlength(space,length(space)-2);
  1950. len:=ppufile.getlongint;
  1951. writeln([space,'** Instantiated ClassRef types: ',len,' **']);
  1952. space:=space+' ';
  1953. for i:=0 to len-1 do
  1954. readderef(space);
  1955. setlength(space,length(space)-2);
  1956. len:=ppufile.getlongint;
  1957. writeln([space,'** Possibly instantiated ClassRef types : ',len,' **']);
  1958. space:=space+' ';
  1959. for i:=0 to len-1 do
  1960. readderef(space);
  1961. setlength(space,length(space)-2);
  1962. len:=ppufile.getlongint;
  1963. writeln([space,'** Class types with called virtual methods info : ',len,' **']);
  1964. space:=space+' ';
  1965. for i:=0 to len-1 do
  1966. begin
  1967. write([space,'Class def : ']);
  1968. readderef('');
  1969. write([space+' ','Called vmtentries : ']);
  1970. bssize:=ppufile.getlongint;
  1971. getmem(bs,bssize);
  1972. ppufile.readdata(bs^,bssize);
  1973. for j:=0 to bssize*8-1 do
  1974. if (((bs+j shr 3)^ shr (j and 7)) and 1) <> 0 then
  1975. write([j,', ']);
  1976. writeln;
  1977. freemem(bs);
  1978. end;
  1979. setlength(space,length(space)-2);
  1980. end;
  1981. {****************************************************************************
  1982. Read Symbols Part
  1983. ****************************************************************************}
  1984. procedure readsymbols(const s:string; ParentDef: TPpuContainerDef = nil);
  1985. function _finddef(symdef: TPpuDef): TPpuDef;
  1986. begin
  1987. Result:=nil;
  1988. if symdef.Ref.IsCurUnit then
  1989. begin;
  1990. Result:=CurUnit.FindById(symdef.Ref.Id);
  1991. if (Result <> nil) and (Result.Ref.Id = symdef.Id) then
  1992. begin
  1993. Result.Name:=symdef.Name;
  1994. Result.FilePos:=symdef.FilePos;
  1995. end
  1996. else
  1997. Result:=nil;
  1998. end;
  1999. end;
  2000. type
  2001. pguid = ^tguid;
  2002. tguid = packed record
  2003. D1: LongWord;
  2004. D2: Word;
  2005. D3: Word;
  2006. D4: array[0..7] of Byte;
  2007. end;
  2008. var
  2009. b : byte;
  2010. pc : pchar;
  2011. ch : dword;
  2012. startnewline : boolean;
  2013. i,j,len : longint;
  2014. prettyname, ss : ansistring;
  2015. ws: widestring;
  2016. guid : tguid;
  2017. realvalue : ppureal;
  2018. doublevalue : double;
  2019. singlevalue : single;
  2020. extended : TSplit80bitReal;
  2021. tempbuf : array[0..127] of char;
  2022. pw : pcompilerwidestring;
  2023. varoptions : tvaroptions;
  2024. propoptions : tpropertyoptions;
  2025. iexp: Tconstexprint;
  2026. def: TPpuDef;
  2027. constdef: TPpuConstDef absolute def;
  2028. begin
  2029. with ppufile do
  2030. begin
  2031. if space<>'' then
  2032. Writeln([space,'------ ',s,' ------']);
  2033. if readentry=ibstartsyms then
  2034. begin
  2035. Writeln([space,'Symtable datasize : ',getlongint]);
  2036. Writeln([space,'Symtable alignment: ',getlongint]);
  2037. end
  2038. else
  2039. Writeln('!! ibstartsym not found');
  2040. repeat
  2041. def:=nil;
  2042. b:=readentry;
  2043. case b of
  2044. ibunitsym :
  2045. readcommonsym('Unit symbol ');
  2046. ibnamespacesym :
  2047. begin
  2048. readcommonsym('NameSpace symbol ');
  2049. write([space,' Hidden Unit : ']);
  2050. readderef('');
  2051. end;
  2052. iblabelsym :
  2053. readcommonsym('Label symbol ');
  2054. ibtypesym :
  2055. begin
  2056. def:=TPpuTypeRef.Create(nil);
  2057. readcommonsym('Type symbol ',def);
  2058. write([space,' Result Type : ']);
  2059. readderef('', def.Ref);
  2060. if _finddef(def) = nil then
  2061. def.Parent:=ParentDef;
  2062. prettyname:=getansistring;
  2063. if prettyname<>'' then
  2064. begin
  2065. write([space,' Pretty Name : ']);
  2066. Writeln(prettyname);
  2067. end;
  2068. end;
  2069. ibprocsym :
  2070. begin
  2071. def:=TPpuDef.Create(nil);
  2072. readcommonsym('Procedure symbol ', def);
  2073. len:=ppufile.getword;
  2074. for i:=1 to len do
  2075. begin
  2076. write([space,' Definition : ']);
  2077. readderef('', def.Ref);
  2078. _finddef(def);
  2079. end;
  2080. end;
  2081. ibconstsym :
  2082. begin
  2083. constdef:=TPpuConstDef.Create(ParentDef);
  2084. readcommonsym('Constant symbol ',constdef);
  2085. b:=getbyte;
  2086. case tconsttyp(b) of
  2087. constord :
  2088. begin
  2089. write ([space,' OrdinalType : ']);
  2090. readderef('',constdef.TypeRef);
  2091. iexp:=getexprint;
  2092. constdef.ConstType:=ctInt;
  2093. constdef.VInt:=iexp.svalue;
  2094. writeln([space,' Value : ',constexp.tostr(iexp)]);
  2095. end;
  2096. constpointer :
  2097. begin
  2098. write ([space,' PointerType : ']);
  2099. readderef('',constdef.TypeRef);
  2100. constdef.ConstType:=ctInt;
  2101. constdef.VInt:=getaint;
  2102. writeln([space,' Value : ',constdef.VInt])
  2103. end;
  2104. conststring,
  2105. constresourcestring :
  2106. begin
  2107. len:=getlongint;
  2108. getmem(pc,len+1);
  2109. getdata(pc^,len);
  2110. (pc+len)^:= #0;
  2111. writeln([space,' Length : ',len]);
  2112. writeln([space,' Value : "',pc,'"']);
  2113. constdef.ConstType:=ctStr;
  2114. SetString(constdef.VStr, pc, len);
  2115. constdef.VStr:=UTF8Encode(constdef.VStr);
  2116. freemem(pc,len+1);
  2117. end;
  2118. constreal :
  2119. begin
  2120. constdef.ConstType:=ctFloat;
  2121. write ([space,' RealType : ']);
  2122. readderef('',constdef.TypeRef);
  2123. write([space,' Value : ']);
  2124. if entryleft=sizeof(ppureal) then
  2125. begin
  2126. realvalue:=getrealsize(sizeof(ppureal));
  2127. constdef.VFloat:=realvalue;
  2128. writeln([realvalue]);
  2129. end
  2130. else if entryleft=sizeof(double) then
  2131. begin
  2132. doublevalue:=getrealsize(sizeof(double));
  2133. constdef.VFloat:=doublevalue;
  2134. writeln([doublevalue]);
  2135. end
  2136. else if entryleft=sizeof(single) then
  2137. begin
  2138. singlevalue:=getrealsize(sizeof(single));
  2139. constdef.VFloat:=singlevalue;
  2140. writeln([singlevalue]);
  2141. end
  2142. else if entryleft=10 then
  2143. begin
  2144. getdata(extended,entryleft);
  2145. ss:=Real80bitToStr(extended);
  2146. constdef.VFloat:=StrToFloat(ss);
  2147. writeln(ss);
  2148. end
  2149. else
  2150. begin
  2151. realvalue:=0.0;
  2152. WriteError('Error reading real value');
  2153. end;
  2154. end;
  2155. constset :
  2156. begin
  2157. constdef.ConstType:=ctSet;
  2158. write ([space,' Set Type : ']);
  2159. readderef('',constdef.TypeRef);
  2160. for i:=1to 4 do
  2161. begin
  2162. write ([space,' Value : ']);
  2163. for j:=1to 8 do
  2164. begin
  2165. if j>1 then
  2166. write(',');
  2167. b:=getbyte;
  2168. write(hexstr(b,2));
  2169. constdef.VSet[i*j-1]:=b;
  2170. end;
  2171. writeln;
  2172. end;
  2173. end;
  2174. constnil:
  2175. begin
  2176. writeln([space,' NIL pointer.']);
  2177. constdef.ConstType:=ctPtr;
  2178. constdef.VInt:=0;
  2179. end;
  2180. constwstring :
  2181. begin
  2182. initwidestring(pw);
  2183. setlengthwidestring(pw,getlongint);
  2184. if widecharsize=2 then
  2185. { don't use getdata, because the compilerwidechars may have to
  2186. be byteswapped
  2187. }
  2188. begin
  2189. for i:=0 to pw^.len-1 do
  2190. pw^.data[i]:=ppufile.getword;
  2191. SetString(ws, PWideChar(pw^.data), pw^.len);
  2192. constdef.VStr:=UTF8Encode(ws);
  2193. constdef.ConstType:=ctStr;
  2194. end
  2195. else if widecharsize=4 then
  2196. begin
  2197. for i:=0 to pw^.len-1 do
  2198. pw^.data[i]:=cardinal(ppufile.getlongint);
  2199. end
  2200. else
  2201. begin
  2202. WriteError('Unsupported tcompilerwidechar size');
  2203. end;
  2204. Write([space,'Wide string type']);
  2205. startnewline:=true;
  2206. for i:=0 to pw^.len-1 do
  2207. begin
  2208. if startnewline then
  2209. begin
  2210. writeln;
  2211. write(space);
  2212. startnewline:=false;
  2213. end;
  2214. ch:=pw^.data[i];
  2215. if widecharsize=2 then
  2216. write(hexstr(ch,4))
  2217. else
  2218. write(hexstr(ch,8));
  2219. if ((i + 1) mod 8)= 0 then
  2220. startnewline:=true
  2221. else
  2222. if i <> pw^.len-1 then
  2223. write(', ');
  2224. end;
  2225. donewidestring(pw);
  2226. Writeln;
  2227. end;
  2228. constguid:
  2229. begin
  2230. getdata(guid,sizeof(guid));
  2231. write ([space,' IID String: {',hexstr(guid.d1,8),'-',hexstr(guid.d2,4),'-',hexstr(guid.d3,4),'-']);
  2232. for i:=0 to 7 do
  2233. begin
  2234. write(hexstr(guid.d4[i],2));
  2235. if i=1 then write('-');
  2236. end;
  2237. writeln('}');
  2238. end
  2239. else
  2240. Writeln (['!! Invalid unit format : Invalid const type encountered: ',b]);
  2241. end;
  2242. end;
  2243. ibabsolutevarsym :
  2244. begin
  2245. def:=TPpuVarDef.Create(ParentDef);
  2246. readabstractvarsym('Absolute variable symbol ',varoptions,TPpuVarDef(def));
  2247. Write ([space,' Relocated to ']);
  2248. b:=getbyte;
  2249. case absolutetyp(b) of
  2250. tovar :
  2251. readpropaccesslist(space+' Sym : ');
  2252. toasm :
  2253. Writeln(['Assembler name : ',getstring]);
  2254. toaddr :
  2255. begin
  2256. Write(['Address : ',getlongint]);
  2257. if tsystemcpu(ppufile.header.cpu)=cpu_i386 then
  2258. WriteLn([' (Far: ',getbyte<>0,')']);
  2259. end;
  2260. else
  2261. Writeln (['!! Invalid unit format : Invalid absolute type encountered: ',b]);
  2262. end;
  2263. end;
  2264. ibfieldvarsym :
  2265. begin
  2266. def:=TPpuFieldDef.Create(ParentDef);
  2267. readabstractvarsym('Field Variable symbol ',varoptions,TPpuVarDef(def));
  2268. writeln([space,' Address : ',getaint]);
  2269. end;
  2270. ibstaticvarsym :
  2271. begin
  2272. def:=TPpuVarDef.Create(ParentDef);
  2273. readabstractvarsym('Global Variable symbol ',varoptions,TPpuVarDef(def));
  2274. write ([space,' DefaultConst : ']);
  2275. readderef('');
  2276. if (vo_has_mangledname in varoptions) then
  2277. {$ifdef symansistr}
  2278. writeln([space,' Mangledname : ',getansistring]);
  2279. {$else symansistr}
  2280. writeln([space,' Mangledname : ',getstring]);
  2281. {$endif symansistr}
  2282. end;
  2283. iblocalvarsym :
  2284. begin
  2285. readabstractvarsym('Local Variable symbol ',varoptions);
  2286. write ([space,' DefaultConst : ']);
  2287. readderef('');
  2288. end;
  2289. ibparavarsym :
  2290. begin
  2291. def:=TPpuParamDef.Create(ParentDef);
  2292. readabstractvarsym('Parameter Variable symbol ',varoptions,TPpuVarDef(def));
  2293. write ([space,' DefaultConst : ']);
  2294. readderef('',TPpuParamDef(def).DefaultValue);
  2295. writeln([space,' ParaNr : ',getword]);
  2296. writeln([space,' Univ : ',boolean(getbyte)]);
  2297. writeln([space,' VarState : ',getbyte]);
  2298. writeln([space,' Refs : ',getbyte]);
  2299. if (vo_has_explicit_paraloc in varoptions) then
  2300. begin
  2301. i:=getbyte;
  2302. getdata(tempbuf,i);
  2303. end;
  2304. end;
  2305. ibenumsym :
  2306. begin
  2307. def:=TPpuConstDef.Create(nil);
  2308. readcommonsym('Enumeration symbol ',def);
  2309. write ([space,' Definition : ']);
  2310. readderef('');
  2311. TPpuConstDef(def).ConstType:=ctInt;
  2312. TPpuConstDef(def).VInt:=getlongint;
  2313. writeln([space,' Value : ',TPpuConstDef(def).VInt]);
  2314. if (ParentDef <> nil) and (ParentDef.DefType = dtEnum) then
  2315. def.Parent:=ParentDef;
  2316. end;
  2317. ibsyssym :
  2318. begin
  2319. readcommonsym('Internal system symbol ');
  2320. writeln([space,' Internal Nr : ',getlongint]);
  2321. end;
  2322. ibmacrosym :
  2323. begin
  2324. readcommonsym('Macro symbol ');
  2325. writeln([space,' Name: ',getstring]);
  2326. writeln([space,' Defined: ',getbyte]);
  2327. writeln([space,' Compiler var: ',getbyte]);
  2328. len:=getlongint;
  2329. writeln([space,' Value length: ',len]);
  2330. if len > 0 then
  2331. begin
  2332. getmem(pc,len+1);
  2333. getdata(pc^,len);
  2334. (pc+len)^:= #0;
  2335. writeln([space,' Value: "',pc,'"']);
  2336. freemem(pc,len+1);
  2337. end;
  2338. end;
  2339. ibpropertysym :
  2340. begin
  2341. def:=TPpuPropDef.Create(ParentDef);
  2342. readcommonsym('Property ',def);
  2343. propoptions:=readpropertyoptions;
  2344. if ppo_overrides in propoptions then
  2345. begin
  2346. write ([space,' OverrideProp : ']);
  2347. readderef('');
  2348. end;
  2349. write ([space,' Prop Type : ']);
  2350. readderef('',TPpuPropDef(def).PropType);
  2351. writeln([space,' Index : ',getlongint]);
  2352. writeln([space,' Default : ',getlongint]);
  2353. write ([space,' Index Type : ']);
  2354. readderef('');
  2355. { palt_none }
  2356. readpropaccesslist('');
  2357. write ([space,' Readaccess : ']);
  2358. readpropaccesslist(space+' Sym: ',TPpuPropDef(def).Getter);
  2359. write ([space,' Writeaccess : ']);
  2360. readpropaccesslist(space+' Sym: ',TPpuPropDef(def).Setter);
  2361. write ([space,' Storedaccess : ']);
  2362. readpropaccesslist(space+' Sym: ');
  2363. if [ppo_hasparameters,ppo_overrides]*propoptions=[ppo_hasparameters] then
  2364. begin
  2365. space:=' '+space;
  2366. readsymtable('parast',TPpuPropDef(def));
  2367. delete(space,1,4);
  2368. end;
  2369. end;
  2370. iberror :
  2371. begin
  2372. WriteError('!! Error in PPU');
  2373. exit;
  2374. end;
  2375. ibendsyms :
  2376. break;
  2377. else
  2378. begin
  2379. WriteError('!! Skipping unsupported PPU Entry in Symbols: '+IntToStr(b));
  2380. end;
  2381. end;
  2382. if (def <> nil) and (def.Parent = nil) then
  2383. def.Free;
  2384. if not EndOfEntry then
  2385. HasMoreInfos;
  2386. until false;
  2387. end;
  2388. end;
  2389. {****************************************************************************
  2390. Read defintions Part
  2391. ****************************************************************************}
  2392. procedure readdefinitions(const s:string; ParentDef: TPpuContainerDef);
  2393. { type tordtype is in symconst unit }
  2394. {
  2395. uvoid,
  2396. u8bit,u16bit,u32bit,u64bit,
  2397. s8bit,s16bit,s32bit,s64bit,
  2398. bool8bit,bool16bit,bool32bit,bool64bit,
  2399. uchar,uwidechar,scurrency
  2400. ); }
  2401. { type tobjecttyp is in symconst unit }
  2402. { type tvarianttype is in symconst unit }
  2403. var
  2404. b : byte;
  2405. l,j : longint;
  2406. calloption : tproccalloption;
  2407. procoptions : tprocoptions;
  2408. defoptions: tdefoptions;
  2409. iexpr: Tconstexprint;
  2410. def: TPpuDef;
  2411. objdef: TPpuObjectDef absolute def;
  2412. arrdef: TPpuArrayDef absolute def;
  2413. enumdef: TPpuEnumDef absolute def;
  2414. setdef: TPpuSetDef absolute def;
  2415. orddef: TPpuOrdDef absolute def;
  2416. floatdef: TPpuFloatDef absolute def;
  2417. strdef: TPpuStringDef absolute def;
  2418. filedef: TPpuFileDef absolute def;
  2419. begin
  2420. with ppufile do
  2421. begin
  2422. if space<>'' then
  2423. Writeln([space,'------ ',s,' ------']);
  2424. if readentry<>ibstartdefs then
  2425. Writeln('!! ibstartdefs not found');
  2426. repeat
  2427. def:=nil;
  2428. b:=readentry;
  2429. case b of
  2430. ibpointerdef :
  2431. begin
  2432. def:=TPpuPointerDef.Create(ParentDef);
  2433. readcommondef('Pointer definition',defoptions,def);
  2434. write ([space,' Pointed Type : ']);
  2435. readderef('',TPpuPointerDef(def).Ptr);
  2436. if tsystemcpu(ppufile.header.cpu) in [cpu_i8086,cpu_i386,cpu_x86_64] then
  2437. begin
  2438. write([space,' X86 Pointer Type : ']);
  2439. b:=getbyte;
  2440. case tx86pointertyp(b) of
  2441. x86pt_near: writeln('Near');
  2442. x86pt_near_cs: writeln('Near ''CS''');
  2443. x86pt_near_ds: writeln('Near ''DS''');
  2444. x86pt_near_ss: writeln('Near ''SS''');
  2445. x86pt_near_es: writeln('Near ''ES''');
  2446. x86pt_near_fs: writeln('Near ''FS''');
  2447. x86pt_near_gs: writeln('Near ''GS''');
  2448. x86pt_far: writeln('Far');
  2449. x86pt_huge: writeln('Huge');
  2450. else
  2451. WriteWarning('Invalid x86 pointer type: ' + IntToStr(b));
  2452. end;
  2453. end;
  2454. writeln([space,' Has Pointer Math : ',(getbyte<>0)]);
  2455. end;
  2456. iborddef :
  2457. begin
  2458. orddef:=TPpuOrdDef.Create(ParentDef);
  2459. readcommondef('Ordinal definition',defoptions,orddef);
  2460. write ([space,' Base type : ']);
  2461. b:=getbyte;
  2462. case tordtype(b) of
  2463. uvoid:
  2464. begin
  2465. writeln('uvoid');
  2466. orddef.OrdType:=otVoid;
  2467. end;
  2468. u8bit:
  2469. begin
  2470. writeln('u8bit');
  2471. orddef.OrdType:=otUInt;
  2472. orddef.Size:=1;
  2473. end;
  2474. u16bit:
  2475. begin
  2476. writeln('u16bit');
  2477. orddef.OrdType:=otUInt;
  2478. orddef.Size:=2;
  2479. end;
  2480. u32bit:
  2481. begin
  2482. writeln('u32bit');
  2483. orddef.OrdType:=otUInt;
  2484. orddef.Size:=4;
  2485. end;
  2486. u64bit:
  2487. begin
  2488. writeln('u64bit');
  2489. orddef.OrdType:=otUInt;
  2490. orddef.Size:=8;
  2491. end;
  2492. s8bit:
  2493. begin
  2494. writeln('s8bit');
  2495. orddef.OrdType:=otSInt;
  2496. orddef.Size:=1;
  2497. end;
  2498. s16bit:
  2499. begin
  2500. writeln('s16bit');
  2501. orddef.OrdType:=otSInt;
  2502. orddef.Size:=2;
  2503. end;
  2504. s32bit:
  2505. begin
  2506. writeln('s32bit');
  2507. orddef.OrdType:=otSInt;
  2508. orddef.Size:=4;
  2509. end;
  2510. s64bit:
  2511. begin
  2512. writeln('s64bit');
  2513. orddef.OrdType:=otSInt;
  2514. orddef.Size:=8;
  2515. end;
  2516. pasbool8:
  2517. begin
  2518. writeln('pasbool8');
  2519. orddef.OrdType:=otPasBool;
  2520. orddef.Size:=1;
  2521. end;
  2522. pasbool16:
  2523. begin
  2524. writeln('pasbool16');
  2525. orddef.OrdType:=otPasBool;
  2526. orddef.Size:=2;
  2527. end;
  2528. pasbool32:
  2529. begin
  2530. writeln('pasbool32');
  2531. orddef.OrdType:=otPasBool;
  2532. orddef.Size:=4;
  2533. end;
  2534. pasbool64:
  2535. begin
  2536. writeln('pasbool64');
  2537. orddef.OrdType:=otPasBool;
  2538. orddef.Size:=8;
  2539. end;
  2540. bool8bit:
  2541. begin
  2542. writeln('bool8bit');
  2543. orddef.OrdType:=otBool;
  2544. orddef.Size:=1;
  2545. end;
  2546. bool16bit:
  2547. begin
  2548. writeln('bool16bit');
  2549. orddef.OrdType:=otBool;
  2550. orddef.Size:=2;
  2551. end;
  2552. bool32bit:
  2553. begin
  2554. writeln('bool32bit');
  2555. orddef.OrdType:=otBool;
  2556. orddef.Size:=4;
  2557. end;
  2558. bool64bit:
  2559. begin
  2560. writeln('bool64bit');
  2561. orddef.OrdType:=otBool;
  2562. orddef.Size:=8;
  2563. end;
  2564. uchar:
  2565. begin
  2566. writeln('uchar');
  2567. orddef.OrdType:=otChar;
  2568. orddef.Size:=1;
  2569. end;
  2570. uwidechar:
  2571. begin
  2572. writeln('uwidechar');
  2573. orddef.OrdType:=otChar;
  2574. orddef.Size:=2;
  2575. end;
  2576. scurrency:
  2577. begin
  2578. writeln('scurrency');
  2579. orddef.OrdType:=otCurrency;
  2580. orddef.Size:=8;
  2581. end;
  2582. else
  2583. WriteWarning('Invalid base type: ' + IntToStr(b));
  2584. end;
  2585. iexpr:=getexprint;
  2586. orddef.RangeLow:=iexpr.svalue;
  2587. write([space,' Range : ',constexp.tostr(iexpr)]);
  2588. iexpr:=getexprint;
  2589. orddef.RangeHigh:=iexpr.svalue;
  2590. writeln([' to ',constexp.tostr(iexpr)]);
  2591. end;
  2592. ibfloatdef :
  2593. begin
  2594. floatdef:=TPpuFloatDef.Create(ParentDef);
  2595. readcommondef('Float definition',defoptions,floatdef);
  2596. write ([space,' Float type : ']);
  2597. b:=getbyte;
  2598. case b of
  2599. ftSingle:
  2600. begin
  2601. writeln('Single');
  2602. floatdef.FloatType:=pftSingle;
  2603. end;
  2604. ftDouble:
  2605. begin
  2606. writeln('Double');
  2607. floatdef.FloatType:=pftDouble;
  2608. end;
  2609. ftExtended:
  2610. begin
  2611. writeln('Extended');
  2612. floatdef.FloatType:=pftExtended;
  2613. end;
  2614. ftComp:
  2615. begin
  2616. writeln('Comp');
  2617. floatdef.FloatType:=pftComp;
  2618. end;
  2619. ftCurr:
  2620. begin
  2621. writeln('Currency');
  2622. floatdef.FloatType:=pftCurrency;
  2623. end;
  2624. ftFloat128:
  2625. begin
  2626. writeln('Float128');
  2627. floatdef.FloatType:=pftFloat128;
  2628. end;
  2629. else
  2630. WriteWarning('Invalid float type: ' + IntToStr(b));
  2631. end;
  2632. end;
  2633. ibarraydef :
  2634. begin
  2635. arrdef:=TPpuArrayDef.Create(ParentDef);
  2636. readcommondef('Array definition',defoptions,arrdef);
  2637. write ([space,' Element type : ']);
  2638. readderef('',arrdef.ElType);
  2639. write ([space,' Range Type : ']);
  2640. readderef('',arrdef.RangeType);
  2641. arrdef.RangeLow:=getasizeint;
  2642. arrdef.RangeHigh:=getasizeint;
  2643. writeln([space,' Range : ',arrdef.RangeLow,' to ',arrdef.RangeHigh]);
  2644. write ([space,' Options : ']);
  2645. readarraydefoptions(arrdef);
  2646. readsymtable('symbols');
  2647. end;
  2648. ibprocdef :
  2649. begin
  2650. def:=TPpuProcDef.Create(ParentDef);
  2651. readcommondef('Procedure definition',defoptions,def);
  2652. read_abstract_proc_def(calloption,procoptions,TPpuProcDef(def));
  2653. if (po_has_mangledname in procoptions) then
  2654. {$ifdef symansistr}
  2655. writeln([space,' Mangled name : ',getansistring]);
  2656. {$else symansistr}
  2657. writeln([space,' Mangled name : ',getstring]);
  2658. {$endif symansistr}
  2659. writeln([space,' Number : ',getword]);
  2660. writeln([space,' Level : ',getbyte]);
  2661. write ([space,' Class : ']);
  2662. readderef('');
  2663. write ([space,' Procsym : ']);
  2664. readderef('', def.Ref);
  2665. write ([space,' File Pos : ']);
  2666. readposinfo(def);
  2667. write ([space,' Visibility : ']);
  2668. readvisibility(def);
  2669. write ([space,' SymOptions : ']);
  2670. readsymoptions(space+' ');
  2671. write ([space,' Synthetic kind : ',Synthetic2Str(ppufile.getbyte)]);
  2672. if tsystemcpu(ppufile.header.cpu)=cpu_powerpc then
  2673. begin
  2674. { library symbol for AmigaOS/MorphOS }
  2675. write ([space,' Library symbol : ']);
  2676. readderef('');
  2677. end;
  2678. if (po_has_importdll in procoptions) then
  2679. writeln([space,' Import DLL : ',getstring]);
  2680. if (po_has_importname in procoptions) then
  2681. writeln([space,' Import Name : ',getstring]);
  2682. writeln([space,' Import Nr : ',getword]);
  2683. if (po_msgint in procoptions) then
  2684. writeln([space,' MsgInt : ',getlongint]);
  2685. if (po_msgstr in procoptions) then
  2686. writeln([space,' MsgStr : ',getstring]);
  2687. if (po_dispid in procoptions) then
  2688. writeln([space,' DispID: ',ppufile.getlongint]);
  2689. if (po_has_inlininginfo in procoptions) then
  2690. begin
  2691. write ([space,' FuncretSym : ']);
  2692. readderef('');
  2693. readprocinfooptions(space);
  2694. end;
  2695. b:=ppufile.getbyte;
  2696. if b<>0 then
  2697. begin
  2698. write ([space,' Alias names : ']);
  2699. for j:=1 to b do
  2700. begin
  2701. write(ppufile.getstring);
  2702. if j<b then
  2703. write(', ');
  2704. end;
  2705. writeln;
  2706. end;
  2707. writeln([space,' Empty : ',getbyte<>0]);
  2708. if not EndOfEntry then
  2709. HasMoreInfos;
  2710. space:=' '+space;
  2711. { parast }
  2712. readsymtable('parast', TPpuProcDef(def));
  2713. { localst }
  2714. if (po_has_inlininginfo in procoptions) then
  2715. readsymtable('localst');
  2716. if (po_has_inlininginfo in procoptions) then
  2717. readnodetree;
  2718. delete(space,1,4);
  2719. end;
  2720. ibprocvardef :
  2721. begin
  2722. def:=TPpuProcTypeDef.Create(ParentDef);
  2723. readcommondef('Procedural type (ProcVar) definition',defoptions,def);
  2724. read_abstract_proc_def(calloption,procoptions, TPpuProcDef(def));
  2725. writeln([space,' Symtable level :',ppufile.getbyte]);
  2726. if not EndOfEntry then
  2727. HasMoreInfos;
  2728. space:=' '+space;
  2729. { parast }
  2730. readsymtable('parast',TPpuProcDef(def));
  2731. delete(space,1,4);
  2732. end;
  2733. ibshortstringdef :
  2734. begin
  2735. strdef:=TPpuStringDef.Create(ParentDef);
  2736. strdef.StrType:=stShort;
  2737. readcommondef('ShortString definition',defoptions,strdef);
  2738. strdef.Len:=getbyte;
  2739. writeln([space,' Length : ',strdef.Len]);
  2740. end;
  2741. ibwidestringdef :
  2742. begin
  2743. strdef:=TPpuStringDef.Create(ParentDef);
  2744. strdef.StrType:=stWide;
  2745. readcommondef('WideString definition',defoptions,strdef);
  2746. strdef.Len:=getaint;
  2747. writeln([space,' Length : ',strdef.Len]);
  2748. end;
  2749. ibunicodestringdef :
  2750. begin
  2751. strdef:=TPpuStringDef.Create(ParentDef);
  2752. strdef.StrType:=stUnicode;
  2753. readcommondef('UnicodeString definition',defoptions,strdef);
  2754. strdef.Len:=getaint;
  2755. writeln([space,' Length : ',strdef.Len]);
  2756. end;
  2757. ibansistringdef :
  2758. begin
  2759. strdef:=TPpuStringDef.Create(ParentDef);
  2760. strdef.StrType:=stAnsi;
  2761. readcommondef('AnsiString definition',defoptions,strdef);
  2762. strdef.Len:=getaint;
  2763. writeln([space,' Length : ',strdef.Len]);
  2764. end;
  2765. iblongstringdef :
  2766. begin
  2767. strdef:=TPpuStringDef.Create(ParentDef);
  2768. strdef.StrType:=stLong;
  2769. readcommondef('Longstring definition',defoptions,strdef);
  2770. strdef.Len:=getaint;
  2771. writeln([space,' Length : ',strdef.Len]);
  2772. end;
  2773. ibrecorddef :
  2774. begin
  2775. objdef:=TPpuRecordDef.Create(ParentDef);
  2776. readcommondef('Record definition',defoptions, objdef);
  2777. def.Name:=getstring;
  2778. writeln([space,' Name of Record : ',objdef.Name]);
  2779. writeln([space,' Import lib/pkg : ',getstring]);
  2780. write ([space,' Options : ']);
  2781. readobjectdefoptions(objdef);
  2782. if (df_copied_def in defoptions) then
  2783. begin
  2784. Include(TPpuRecordDef(def).Options, ooCopied);
  2785. write([space,' Copied from : ']);
  2786. readderef('',objdef.Ancestor);
  2787. end
  2788. else
  2789. begin
  2790. writeln([space,' FieldAlign : ',shortint(getbyte)]);
  2791. writeln([space,' RecordAlign : ',shortint(getbyte)]);
  2792. writeln([space,' PadAlign : ',shortint(getbyte)]);
  2793. writeln([space,'UseFieldAlignment : ',shortint(getbyte)]);
  2794. objdef.Size:=getasizeint;
  2795. writeln([space,' DataSize : ',objdef.Size]);
  2796. writeln([space,' PaddingSize : ',getword]);
  2797. end;
  2798. if not EndOfEntry then
  2799. HasMoreInfos;
  2800. {read the record definitions and symbols}
  2801. if not(df_copied_def in current_defoptions) then
  2802. begin
  2803. space:=' '+space;
  2804. readrecsymtableoptions;
  2805. readsymtable('fields',TPpuRecordDef(def));
  2806. Delete(space,1,4);
  2807. end;
  2808. end;
  2809. ibobjectdef :
  2810. begin
  2811. objdef:=TPpuObjectDef.Create(ParentDef);
  2812. readcommondef('Object/Class definition',defoptions,objdef);
  2813. objdef.Name:=getstring;
  2814. writeln([space,' Name of Class : ',objdef.Name]);
  2815. writeln([space,' Import lib/pkg : ',getstring]);
  2816. write ([space,' Options : ']);
  2817. readobjectdefoptions(objdef);
  2818. b:=getbyte;
  2819. write ([space,' Type : ']);
  2820. case tobjecttyp(b) of
  2821. odt_class : writeln('class');
  2822. odt_object : writeln('object');
  2823. odt_interfacecom : writeln('interfacecom');
  2824. odt_interfacecorba : writeln('interfacecorba');
  2825. odt_cppclass : writeln('cppclass');
  2826. odt_dispinterface : writeln('dispinterface');
  2827. odt_objcclass : writeln('objcclass');
  2828. odt_objcprotocol : writeln('objcprotocol');
  2829. odt_helper : writeln('helper');
  2830. odt_objccategory : writeln('objccategory');
  2831. odt_javaclass : writeln('Java class');
  2832. odt_interfacejava : writeln('Java interface');
  2833. else WriteWarning('Invalid object type: ' + IntToStr(b));
  2834. end;
  2835. case tobjecttyp(b) of
  2836. odt_class, odt_cppclass, odt_objcclass, odt_javaclass:
  2837. objdef.ObjType:=otClass;
  2838. odt_object:
  2839. objdef.ObjType:=otObject;
  2840. odt_interfacecom, odt_interfacecorba, odt_interfacejava, odt_dispinterface:
  2841. objdef.ObjType:=otInterface;
  2842. odt_helper:
  2843. objdef.ObjType:=otHelper;
  2844. end;
  2845. writeln([space,' External name : ',getstring]);
  2846. objdef.Size:=getasizeint;
  2847. writeln([space,' DataSize : ',objdef.Size]);
  2848. writeln([space,' PaddingSize : ',getword]);
  2849. writeln([space,' FieldAlign : ',shortint(getbyte)]);
  2850. writeln([space,' RecordAlign : ',shortint(getbyte)]);
  2851. writeln([space,' Vmt offset : ',getlongint]);
  2852. write ([space, ' Ancestor Class : ']);
  2853. readderef('',objdef.Ancestor);
  2854. if tobjecttyp(b) in [odt_interfacecom,odt_interfacecorba,odt_dispinterface] then
  2855. begin
  2856. { IIDGUID }
  2857. for j:=1to 16 do
  2858. getbyte;
  2859. objdef.IID:=getstring;
  2860. writeln([space,' IID String : ',objdef.IID]);
  2861. end;
  2862. writeln([space,' Abstract methods : ',getlongint]);
  2863. if (tobjecttyp(b)=odt_helper) or
  2864. (oo_is_classhelper in current_objectoptions) then
  2865. begin
  2866. write([space,' Helper parent : ']);
  2867. readderef('',objdef.HelperParent);
  2868. end;
  2869. l:=getlongint;
  2870. writeln([space,' VMT entries: ',l]);
  2871. for j:=1 to l do
  2872. begin
  2873. write([space,' ']);
  2874. readderef('');
  2875. write([space,' Visibility: ']);
  2876. readvisibility;
  2877. end;
  2878. if tobjecttyp(b) in [odt_class,odt_objcclass,odt_objcprotocol,odt_javaclass,odt_interfacejava] then
  2879. begin
  2880. l:=getlongint;
  2881. writeln([space,' Impl Intf Count : ',l]);
  2882. for j:=1 to l do
  2883. begin
  2884. write ([space,' - Definition : ']);
  2885. readderef('');
  2886. write ([space,' - Getter Def : ']);
  2887. readderef('');
  2888. writeln([space,' IOffset : ',getlongint]);
  2889. writeln([space,' Entry type : ',IntfEntryType2Str(getbyte)]);
  2890. end;
  2891. end;
  2892. if df_copied_def in current_defoptions then
  2893. begin
  2894. Include(objdef.Options, ooCopied);
  2895. writeln(' Copy of def: ');
  2896. readderef('',objdef.Ancestor);
  2897. end;
  2898. if not EndOfEntry then
  2899. HasMoreInfos;
  2900. if not(df_copied_def in current_defoptions) then
  2901. begin
  2902. {read the record definitions and symbols}
  2903. space:=' '+space;
  2904. readrecsymtableoptions;
  2905. readsymtable('fields',objdef);
  2906. Delete(space,1,4);
  2907. end;
  2908. end;
  2909. ibfiledef :
  2910. begin
  2911. filedef:=TPpuFileDef.Create(ParentDef);
  2912. ReadCommonDef('File definition',defoptions,filedef);
  2913. write ([space,' Type : ']);
  2914. case getbyte of
  2915. 0 : begin
  2916. writeln('Text');
  2917. filedef.FileType:=ftText;
  2918. end;
  2919. 1 : begin
  2920. writeln('Typed');
  2921. filedef.FileType:=ftTyped;
  2922. write ([space,' File of Type : ']);
  2923. readderef('',filedef.TypeRef);
  2924. end;
  2925. 2 : begin
  2926. writeln('Untyped');
  2927. filedef.FileType:=ftUntyped;
  2928. end;
  2929. end;
  2930. end;
  2931. ibformaldef :
  2932. begin
  2933. def:=TPpuFormalDef.Create(ParentDef);
  2934. readcommondef('Generic definition (void-typ)',defoptions,def);
  2935. TPpuFormalDef(def).IsTyped:=(getbyte<>0);
  2936. writeln([space,' Is Typed : ',TPpuFormalDef(def).IsTyped]);
  2937. end;
  2938. ibundefineddef :
  2939. begin
  2940. def:=TPpuUndefinedDef.Create(ParentDef);
  2941. readcommondef('Undefined definition (generic parameter)',defoptions,def);
  2942. end;
  2943. ibenumdef :
  2944. begin
  2945. enumdef:=TPpuEnumDef.Create(ParentDef);
  2946. readcommondef('Enumeration type definition',defoptions,enumdef);
  2947. enumdef.ElLow:=getaint;
  2948. writeln([space,' Smallest element : ',enumdef.ElLow]);
  2949. enumdef.ElHigh:=getaint;
  2950. writeln([space,' Largest element : ',enumdef.ElHigh]);
  2951. enumdef.Size:=byte(getaint);
  2952. writeln([space,' Size : ',enumdef.Size]);
  2953. {$ifdef jvm}
  2954. write([space,' Class def : ']);
  2955. readderef('');
  2956. {$endif}
  2957. if df_copied_def in defoptions then
  2958. begin
  2959. write([space,'Base enumeration type : ']);
  2960. readderef('',enumdef.CopyFrom);
  2961. end
  2962. else
  2963. begin
  2964. space:=' '+space;
  2965. readsymtable('elements',enumdef);
  2966. delete(space,1,4);
  2967. end;
  2968. end;
  2969. ibclassrefdef :
  2970. begin
  2971. def:=TPpuClassRefDef.Create(ParentDef);
  2972. readcommondef('Class reference definition',defoptions,def);
  2973. write ([space,' Pointed Type : ']);
  2974. readderef('',TPpuClassRefDef(def).ClassRef);
  2975. end;
  2976. ibsetdef :
  2977. begin
  2978. setdef:=TPpuSetDef.Create(ParentDef);
  2979. readcommondef('Set definition',defoptions,setdef);
  2980. write ([space,' Element type : ']);
  2981. readderef('',setdef.ElType);
  2982. setdef.Size:=getaint;
  2983. writeln([space,' Size : ',setdef.Size]);
  2984. setdef.SetBase:=getaint;
  2985. writeln([space,' Set Base : ',setdef.SetBase]);
  2986. setdef.SetMax:=getaint;
  2987. writeln([space,' Set Max : ',setdef.SetMax]);
  2988. end;
  2989. ibvariantdef :
  2990. begin
  2991. def:=TPpuVariantDef.Create(ParentDef);
  2992. readcommondef('Variant definition',defoptions,def);
  2993. write ([space,' Varianttype : ']);
  2994. b:=getbyte;
  2995. case tvarianttype(b) of
  2996. vt_normalvariant :
  2997. writeln('Normal');
  2998. vt_olevariant :
  2999. begin
  3000. TPpuVariantDef(def).IsOLE:=True;
  3001. writeln('OLE');
  3002. end
  3003. else
  3004. WriteWarning('Invalid varianttype: ' + IntToStr(b));
  3005. end;
  3006. end;
  3007. iberror :
  3008. begin
  3009. WriteError('!! Error in PPU');
  3010. exit;
  3011. end;
  3012. ibenddefs :
  3013. break;
  3014. else
  3015. begin
  3016. WriteError('!! Skipping unsupported PPU Entry in definitions: '+IntToStr(b));
  3017. end;
  3018. end;
  3019. if (def <> nil) and (def.Parent = nil) then
  3020. def.Free;
  3021. if not EndOfEntry then
  3022. HasMoreInfos;
  3023. until false;
  3024. end;
  3025. end;
  3026. procedure readmoduleoptions(space : string);
  3027. type
  3028. { tmoduleoption type is in unit fmodule }
  3029. tmoduleoption = (mo_none,
  3030. mo_hint_deprecated,
  3031. mo_hint_platform,
  3032. mo_hint_library,
  3033. mo_hint_unimplemented,
  3034. mo_hint_experimental,
  3035. mo_has_deprecated_msg
  3036. );
  3037. tmoduleoptions = set of tmoduleoption;
  3038. tmoduleopt=record
  3039. mask : tmoduleoption;
  3040. str : string[30];
  3041. end;
  3042. const
  3043. moduleopts=ord(high(tmoduleoption));
  3044. moduleopt : array[1..moduleopts] of tmoduleopt=(
  3045. (mask:mo_hint_deprecated; str:'Hint Deprecated'),
  3046. (mask:mo_hint_platform; str:'Hint Platform'),
  3047. (mask:mo_hint_library; str:'Hint Library'),
  3048. (mask:mo_hint_unimplemented; str:'Hint Unimplemented'),
  3049. (mask:mo_hint_experimental; str:'Hint Experimental'),
  3050. (mask:mo_has_deprecated_msg; str:'Has Deprecated Message')
  3051. );
  3052. var
  3053. moduleoptions : tmoduleoptions;
  3054. i : longint;
  3055. first : boolean;
  3056. begin
  3057. ppufile.getsmallset(moduleoptions);
  3058. if moduleoptions<>[] then
  3059. begin
  3060. first:=true;
  3061. for i:=1to moduleopts do
  3062. if (moduleopt[i].mask in moduleoptions) then
  3063. begin
  3064. if first then
  3065. first:=false
  3066. else
  3067. write(', ');
  3068. write(moduleopt[i].str);
  3069. end;
  3070. end;
  3071. writeln;
  3072. if mo_has_deprecated_msg in moduleoptions then
  3073. writeln([space,'Deprecated : ', ppufile.getstring]);
  3074. end;
  3075. {****************************************************************************
  3076. Read General Part
  3077. ****************************************************************************}
  3078. procedure readinterface;
  3079. var
  3080. b : byte;
  3081. sourcenumber, i : longint;
  3082. begin
  3083. with ppufile do
  3084. begin
  3085. repeat
  3086. b:=readentry;
  3087. case b of
  3088. ibmodulename :
  3089. begin
  3090. CurUnit.Name:=getstring;
  3091. Writeln(['Module Name: ',CurUnit.Name]);
  3092. end;
  3093. ibmoduleoptions:
  3094. readmoduleoptions(' ');
  3095. ibsourcefiles :
  3096. begin
  3097. sourcenumber:=1;
  3098. while not EndOfEntry do
  3099. begin
  3100. with TPpuSrcFile.Create(CurUnit.SourceFiles) do begin
  3101. Name:=getstring;
  3102. i:=getlongint;
  3103. if i >= 0 then
  3104. FileTime:=FileDateToDateTime(i);
  3105. Writeln(['Source file ',sourcenumber,' : ',Name,' ',filetimestring(i)]);
  3106. end;
  3107. inc(sourcenumber);
  3108. end;
  3109. end;
  3110. {$IFDEF MACRO_DIFF_HINT}
  3111. ibusedmacros :
  3112. begin
  3113. while not EndOfEntry do
  3114. begin
  3115. Write('Conditional ',getstring);
  3116. b:=getbyte;
  3117. if boolean(b)=true then
  3118. write(' defined at startup')
  3119. else
  3120. write(' not defined at startup');
  3121. b:=getbyte;
  3122. if boolean(b)=true then
  3123. writeln(' was used')
  3124. else
  3125. writeln;
  3126. end;
  3127. end;
  3128. {$ENDIF}
  3129. ibloadunit :
  3130. ReadLoadUnit;
  3131. iblinkunitofiles :
  3132. ReadLinkContainer('Link unit object file: ');
  3133. iblinkunitstaticlibs :
  3134. ReadLinkContainer('Link unit static lib: ');
  3135. iblinkunitsharedlibs :
  3136. ReadLinkContainer('Link unit shared lib: ');
  3137. iblinkotherofiles :
  3138. ReadLinkContainer('Link other object file: ');
  3139. iblinkotherstaticlibs :
  3140. ReadLinkContainer('Link other static lib: ');
  3141. iblinkothersharedlibs :
  3142. ReadLinkContainer('Link other shared lib: ');
  3143. iblinkotherframeworks:
  3144. ReadLinkContainer('Link framework: ');
  3145. ibmainname:
  3146. Writeln(['Specified main program symbol name: ',getstring]);
  3147. ibImportSymbols :
  3148. ReadImportSymbols;
  3149. ibderefdata :
  3150. ReadDerefData;
  3151. ibderefmap :
  3152. ReadDerefMap;
  3153. ibwpofile :
  3154. ReadWpoFileInfo;
  3155. ibresources :
  3156. ReadLinkContainer('Resource file: ');
  3157. iberror :
  3158. begin
  3159. WriteError('Error in PPU');
  3160. exit;
  3161. end;
  3162. ibendinterface :
  3163. break;
  3164. else
  3165. begin
  3166. WriteError('!! Skipping unsupported PPU Entry in General Part: '+IntToStr(b));
  3167. end;
  3168. end;
  3169. until false;
  3170. end;
  3171. end;
  3172. {****************************************************************************
  3173. Read Implementation Part
  3174. ****************************************************************************}
  3175. procedure readimplementation;
  3176. var
  3177. b : byte;
  3178. begin
  3179. with ppufile do
  3180. begin
  3181. repeat
  3182. b:=readentry;
  3183. case b of
  3184. ibasmsymbols :
  3185. ReadAsmSymbols;
  3186. ibloadunit :
  3187. ReadLoadUnit;
  3188. iberror :
  3189. begin
  3190. WriteError('Error in PPU');
  3191. exit;
  3192. end;
  3193. ibendimplementation :
  3194. break;
  3195. else
  3196. begin
  3197. WriteError('!! Skipping unsupported PPU Entry in Implementation: '+IntToStr(b));
  3198. end;
  3199. end;
  3200. until false;
  3201. end;
  3202. end;
  3203. procedure dofile (filename : string);
  3204. begin
  3205. { reset }
  3206. space:='';
  3207. { fix filename }
  3208. if pos('.',filename)=0 then
  3209. filename:=filename+'.ppu';
  3210. ppufile:=tppufile.create(filename);
  3211. if not ppufile.openfile then
  3212. begin
  3213. WriteError('IO-Error when opening : '+filename+', Skipping');
  3214. exit;
  3215. end;
  3216. { PPU File is open, check for PPU Id }
  3217. if not ppufile.CheckPPUID then
  3218. begin
  3219. WriteError(Filename+' : Not a valid PPU file, Skipping');
  3220. exit;
  3221. end;
  3222. { Check PPU Version }
  3223. ppuversion:=ppufile.GetPPUVersion;
  3224. Writeln(['Analyzing ',filename,' (v',PPUVersion,')']);
  3225. if PPUVersion<16 then
  3226. begin
  3227. WriteError(Filename+' : Old PPU Formats (<v16) are not supported, Skipping');
  3228. exit;
  3229. end;
  3230. if not SkipVersionCheck and (PPUVersion <> CurrentPPUVersion) then
  3231. begin
  3232. WriteError(Format('Unsupported PPU version %d. Expecting PPU version %d.', [PPUVersion, CurrentPPUVersion]));
  3233. exit;
  3234. end;
  3235. CurUnit:=TPpuUnitDef.Create(UnitList);
  3236. CurUnit.Version:=ppuversion;
  3237. { Write PPU Header Information }
  3238. if (verbose and v_header)<>0 then
  3239. begin
  3240. Writeln;
  3241. Writeln('Header');
  3242. Writeln('-------');
  3243. with ppufile.header do
  3244. begin
  3245. Writeln(['Compiler version : ',ppufile.header.compiler shr 14,'.',
  3246. (ppufile.header.compiler shr 7) and $7f,'.',
  3247. ppufile.header.compiler and $7f]);
  3248. WriteLn(['Target processor : ',Cpu2Str(cpu)]);
  3249. WriteLn(['Target operating system : ',Target2Str(target)]);
  3250. Writeln(['Unit flags : ',PPUFlags2Str(flags)]);
  3251. Writeln(['FileSize (w/o header) : ',size]);
  3252. Writeln(['Checksum : ',hexstr(checksum,8)]);
  3253. Writeln(['Interface Checksum : ',hexstr(interface_checksum,8)]);
  3254. Writeln(['Indirect Checksum : ',hexstr(indirect_checksum,8)]);
  3255. Writeln(['Definitions stored : ',tostr(deflistsize)]);
  3256. Writeln(['Symbols stored : ',tostr(symlistsize)]);
  3257. end;
  3258. end;
  3259. with ppufile.header do
  3260. begin
  3261. CurUnit.Crc:=checksum;
  3262. CurUnit.IntfCrc:=interface_checksum;
  3263. CurUnit.TargetCPU:=Cpu2Str(cpu);
  3264. CurUnit.TargetOS:=Target2Str(target);
  3265. end;
  3266. {read the general stuff}
  3267. if (verbose and v_interface)<>0 then
  3268. begin
  3269. Writeln;
  3270. Writeln('Interface section');
  3271. Writeln('------------------');
  3272. readinterface;
  3273. end
  3274. else
  3275. ppufile.skipuntilentry(ibendinterface);
  3276. Writeln;
  3277. Writeln('Interface symtable');
  3278. Writeln('----------------------');
  3279. readsymtableoptions('interface');
  3280. {read the definitions}
  3281. if (verbose and v_defs)<>0 then
  3282. begin
  3283. Writeln;
  3284. Writeln('Interface definitions');
  3285. Writeln('----------------------');
  3286. readdefinitions('interface', CurUnit);
  3287. end
  3288. else
  3289. ppufile.skipuntilentry(ibenddefs);
  3290. {read the symbols}
  3291. if (verbose and v_syms)<>0 then
  3292. begin
  3293. Writeln;
  3294. Writeln('Interface Symbols');
  3295. Writeln('------------------');
  3296. readsymbols('interface',CurUnit);
  3297. end
  3298. else
  3299. ppufile.skipuntilentry(ibendsyms);
  3300. {read the macro symbols}
  3301. if (verbose and v_syms)<>0 then
  3302. begin
  3303. Writeln;
  3304. Writeln('Interface Macro Symbols');
  3305. Writeln('-----------------------');
  3306. end;
  3307. if ppufile.readentry<>ibexportedmacros then
  3308. begin
  3309. WriteError('!! Error in PPU');
  3310. exit;
  3311. end;
  3312. if boolean(ppufile.getbyte) then
  3313. begin
  3314. readsymtableoptions('interface macro');
  3315. {skip the definition section for macros (since they are never used) }
  3316. ppufile.skipuntilentry(ibenddefs);
  3317. {read the macro symbols}
  3318. if (verbose and v_syms)<>0 then
  3319. readsymbols('interface macro')
  3320. else
  3321. ppufile.skipuntilentry(ibendsyms);
  3322. end
  3323. else
  3324. Writeln('(no exported macros)');
  3325. {read the implementation stuff}
  3326. if (verbose and v_implementation)<>0 then
  3327. begin
  3328. Writeln;
  3329. Writeln('Implementation section');
  3330. Writeln('-----------------------');
  3331. readimplementation;
  3332. end
  3333. else
  3334. ppufile.skipuntilentry(ibendimplementation);
  3335. {read the static symtable}
  3336. Writeln;
  3337. Writeln('Implementation symtable');
  3338. Writeln('----------------------');
  3339. readsymtableoptions('implementation');
  3340. if (ppufile.header.flags and uf_local_symtable)<>0 then
  3341. begin
  3342. if (verbose and v_defs)<>0 then
  3343. begin
  3344. Writeln;
  3345. Writeln('Static definitions');
  3346. Writeln('----------------------');
  3347. readdefinitions('implementation', nil);
  3348. end
  3349. else
  3350. ppufile.skipuntilentry(ibenddefs);
  3351. {read the symbols}
  3352. if (verbose and v_syms)<>0 then
  3353. begin
  3354. Writeln;
  3355. Writeln('Static Symbols');
  3356. Writeln('------------------');
  3357. readsymbols('implementation');
  3358. end
  3359. else
  3360. ppufile.skipuntilentry(ibendsyms);
  3361. end;
  3362. ReadCreatedObjTypes;
  3363. FreeDerefdata;
  3364. {shutdown ppufile}
  3365. ppufile.closefile;
  3366. ppufile.free;
  3367. Writeln;
  3368. end;
  3369. procedure WriteLogo;
  3370. begin
  3371. writeln(Title+' Version '+version_string);
  3372. writeln(Copyright);
  3373. writeln;
  3374. end;
  3375. procedure help;
  3376. begin
  3377. WriteLogo;
  3378. writeln('usage: ppudump [options] <filename1> <filename2>...');
  3379. writeln;
  3380. writeln('[options] can be:');
  3381. writeln(' -F<format> Set output format to <format>');
  3382. writeln(' t - text format (default)');
  3383. writeln(' j - JSON format');
  3384. writeln(' x - XML format');
  3385. writeln(' -M Exit with ExitCode=2 if more information is available');
  3386. writeln(' -S Skip PPU version check. May lead to reading errors');
  3387. writeln(' -V<verbose> Set verbosity to <verbose>');
  3388. writeln(' H - Show header info');
  3389. writeln(' I - Show interface');
  3390. writeln(' M - Show implementation');
  3391. writeln(' S - Show interface symbols');
  3392. writeln(' D - Show interface definitions');
  3393. writeln(' A - Show all');
  3394. writeln(' -h, -? This helpscreen');
  3395. halt;
  3396. end;
  3397. var
  3398. startpara,
  3399. nrfile,i : longint;
  3400. para : string;
  3401. const
  3402. error_on_more : boolean = false;
  3403. begin
  3404. if paramcount<1 then
  3405. help;
  3406. { turn verbose on by default }
  3407. verbose:=v_all;
  3408. { read options }
  3409. startpara:=1;
  3410. while copy(paramstr(startpara),1,1)='-' do
  3411. begin
  3412. para:=paramstr(startpara);
  3413. case upcase(para[2]) of
  3414. 'F' : begin
  3415. FreeAndNil(pout);
  3416. if Length(para) > 2 then
  3417. case upcase(para[3]) of
  3418. 'T':
  3419. nostdout:=False;
  3420. 'J':
  3421. begin
  3422. nostdout:=True;
  3423. pout:=TPpuJsonOutput.Create(Output);
  3424. end;
  3425. 'X':
  3426. begin
  3427. nostdout:=True;
  3428. pout:=TPpuXmlOutput.Create(Output);
  3429. end;
  3430. else
  3431. begin
  3432. WriteError('Invalid output format: ' + para[3]);
  3433. Halt(1);
  3434. end;
  3435. end;
  3436. end;
  3437. 'M' : error_on_more:=true;
  3438. 'S' : SkipVersionCheck:=True;
  3439. 'V' : begin
  3440. verbose:=0;
  3441. for i:=3 to length(para) do
  3442. case upcase(para[i]) of
  3443. 'H' : verbose:=verbose or v_header;
  3444. 'I' : verbose:=verbose or v_interface;
  3445. 'M' : verbose:=verbose or v_implementation;
  3446. 'D' : verbose:=verbose or v_defs;
  3447. 'S' : verbose:=verbose or v_syms;
  3448. 'A' : verbose:=verbose or v_all;
  3449. end;
  3450. end;
  3451. 'H' : help;
  3452. '?' : help;
  3453. else
  3454. begin
  3455. WriteError('Invalid option: ' + para);
  3456. Halt(1);
  3457. end;
  3458. end;
  3459. inc(startpara);
  3460. end;
  3461. if not nostdout then
  3462. WriteLogo;
  3463. UnitList:=TPpuContainerDef.Create(nil);
  3464. try
  3465. UnitList.ItemsName:='';
  3466. { process files }
  3467. for nrfile:=startpara to paramcount do
  3468. dofile (paramstr(nrfile));
  3469. if not has_errors and (pout <> nil) then
  3470. begin
  3471. pout.Init;
  3472. UnitList.Write(pout);
  3473. pout.Done;
  3474. end;
  3475. finally
  3476. UnitList.Free;
  3477. pout.Free;
  3478. end;
  3479. if has_errors then
  3480. Halt(1);
  3481. if error_on_more and has_more_infos then
  3482. Halt(2);
  3483. end.