ppudump.pp 127 KB

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