ppudump.pp 123 KB

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