ppudump.pp 126 KB

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