2
0

ppudump.pp 125 KB

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