ppudump.pp 122 KB

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