ppudump.pp 126 KB

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