ppudump.pp 119 KB

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