ppudump.pp 127 KB

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