ppudump.pp 126 KB

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