ppudump.pp 126 KB

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