ppudump.pp 126 KB

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