ppudump.pp 110 KB

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