ppudump.pp 111 KB

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