ppudump.pp 113 KB

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