ppudump.pp 125 KB

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