ppudump.pp 120 KB

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