ppudump.pp 127 KB

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