ppudump.pp 111 KB

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