ppudump.pp 122 KB

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