ppudump.pp 127 KB

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