ppudump.pp 119 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953
  1. {
  2. Copyright (c) 1998-2013 by the FPC Development Team
  3. Dumps the contents of a FPC unit file (PPU File)
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************}
  16. program ppudump;
  17. {$i fpcdefs.inc}
  18. {$H+}
  19. {$define IN_PPUDUMP}
  20. uses
  21. { do NOT add symconst or globtype to make merging easier }
  22. { do include symconst and globtype now before splitting 2.5 PM 2011-06-15 }
  23. SysUtils,
  24. constexp,
  25. symconst,
  26. ppu,
  27. entfile,
  28. systems,
  29. globals,
  30. globtype,
  31. widestr,
  32. tokens,
  33. version,
  34. ppuout,
  35. ppujson,
  36. ppuxml;
  37. const
  38. Title = 'PPU-Analyser';
  39. Copyright = 'Copyright (c) 1998-2013 by the Free Pascal Development Team';
  40. { verbosity }
  41. v_none = $0;
  42. v_header = $1;
  43. v_defs = $2;
  44. v_syms = $4;
  45. v_interface = $8;
  46. v_implementation = $10;
  47. // v_browser = $20;
  48. v_all = $ff;
  49. { not needed anymore $i systems.inc }
  50. { List of all supported cpus }
  51. const
  52. CpuTxt : array[tsystemcpu] of string[9]=
  53. (
  54. { 0 } 'none',
  55. { 1 } 'i386',
  56. { 2 } 'm68k',
  57. { 3 } 'alpha',
  58. { 4 } 'powerpc',
  59. { 5 } 'sparc',
  60. { 6 } 'vis',
  61. { 7 } 'ia64',
  62. { 8 } 'x86_64',
  63. { 9 } 'mipseb',
  64. { 10 } 'arm',
  65. { 11 } 'powerpc64',
  66. { 12 } 'avr',
  67. { 13 } 'mipsel',
  68. { 14 } 'jvm',
  69. { 15 } 'i8086',
  70. { 16 } 'aarch64',
  71. { 17 } 'spc32'
  72. );
  73. { List of all supported system-cpu couples }
  74. const
  75. Targets : array[tsystem] of string[18]=(
  76. { 0 } 'none',
  77. { 1 } 'GO32V1 (obsolete)',
  78. { 2 } 'GO32V2',
  79. { 3 } 'Linux-i386',
  80. { 4 } 'OS/2',
  81. { 5 } 'Win32',
  82. { 6 } 'FreeBSD-i386',
  83. { 7 } 'Amiga',
  84. { 8 } 'Atari',
  85. { 9 } 'MacOS-m68k',
  86. { 10 } 'Linux-m68k',
  87. { 11 } 'PalmOS-m68k',
  88. { 12 } 'Linux-alpha',
  89. { 13 } 'Linux-ppc',
  90. { 14 } 'MacOS-ppc',
  91. { 15 } 'Solaris-i386',
  92. { 16 } 'BeOS-i386',
  93. { 17 } 'NetBSD-i386',
  94. { 18 } 'NetBSD-m68k',
  95. { 19 } 'Netware-i386-clib',
  96. { 20 } 'Qnx-i386',
  97. { 21 } 'WDOSX-i386',
  98. { 22 } 'Solaris-sparc',
  99. { 23 } 'Linux-sparc',
  100. { 24 } 'OpenBSD-i386',
  101. { 25 } 'OpenBSD-m68k',
  102. { 26 } 'Linux-x86-64',
  103. { 27 } 'Darwin-ppc',
  104. { 28 } 'OS/2 via EMX',
  105. { 29 } 'NetBSD-powerpc',
  106. { 30 } 'OpenBSD-powerpc',
  107. { 31 } 'Linux-arm',
  108. { 32 } 'Watcom-i386',
  109. { 33 } 'MorphOS-powerpc',
  110. { 34 } 'FreeBSD-x86-64',
  111. { 35 } 'Netware-i386-libc',
  112. { 36 } 'Amiga-PowerPC',
  113. { 37 } 'Win64-x64',
  114. { 38 } 'WinCE-ARM',
  115. { 39 } 'Win64-iA64',
  116. { 40 } 'WinCE-i386',
  117. { 41 } 'Linux-x64',
  118. { 42 } 'GBA-arm',
  119. { 43 } 'Linux-powerpc64',
  120. { 44 } 'Darwin-i386',
  121. { 45 } 'PalmOS-arm',
  122. { 46 } 'Darwin-powerpc64',
  123. { 47 } 'NDS-arm',
  124. { 48 } 'Embedded-i386',
  125. { 49 } 'Embedded-m68k',
  126. { 50 } 'Embedded-alpha',
  127. { 51 } 'Embedded-powerpc',
  128. { 52 } 'Embedded-sparc',
  129. { 53 } 'Embedded-vm',
  130. { 54 } 'Embedded-iA64',
  131. { 55 } 'Embedded-x64',
  132. { 56 } 'Embedded-mips',
  133. { 57 } 'Embedded-arm',
  134. { 58 } 'Embedded-powerpc64',
  135. { 59 } 'Symbian-i386',
  136. { 60 } 'Symbian-arm',
  137. { 61 } 'Darwin-x64',
  138. { 62 } 'Embedded-avr',
  139. { 63 } 'Haiku-i386',
  140. { 64 } 'Darwin-ARM',
  141. { 65 } 'Solaris-x86-64',
  142. { 66 } 'Linux-MIPS',
  143. { 67 } 'Linux-MIPSel',
  144. { 68 } 'NativeNT-i386',
  145. { 69 } 'iPhoneSim-i386',
  146. { 70 } 'Wii-powerpc',
  147. { 71 } 'OpenBSD-x86-64',
  148. { 72 } 'NetBSD-x86-64',
  149. { 73 } 'AIX-powerpc',
  150. { 74 } 'AIX-powerpc64',
  151. { 75 } 'Java-JVM',
  152. { 76 } 'Android-JVM',
  153. { 77 } 'Android-arm',
  154. { 78 } 'Android-i386',
  155. { 79 } 'MSDOS-i8086',
  156. { 80 } 'Android-MIPSel',
  157. { 81 } 'Embedded-mipseb',
  158. { 82 } 'Embedded-mipsel',
  159. { 83 } 'AROS-i386',
  160. { 84 } 'AROS-x86-64',
  161. { 85 } 'DragonFly-x86-64',
  162. { 86 } 'Darwin-AArch64',
  163. { 87 } 'iPhoneSim-x86-64',
  164. { 88 } 'Linux-AArch64',
  165. { 89 } 'Win16',
  166. { 90 } 'Embedded-spc32' );
  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. write([space,'Imported Symbols']);
  1014. write([space,'----------------']);
  1015. c:=ppufile.getlongint;
  1016. for i:=0 to c-1 do
  1017. readderef(space);
  1018. end;
  1019. procedure readpropaccesslist(const s:string; Ref: TPpuRef = nil);
  1020. { type tsltype is in symconst unit }
  1021. const
  1022. slstr : array[tsltype] of string[12] = (
  1023. '',
  1024. 'load',
  1025. 'call',
  1026. 'subscript',
  1027. 'vec',
  1028. 'typeconv',
  1029. 'absolutetype'
  1030. );
  1031. var
  1032. sl : tsltype;
  1033. begin
  1034. readderef('',Ref);
  1035. repeat
  1036. sl:=tsltype(ppufile.getbyte);
  1037. if sl=sl_none then
  1038. break;
  1039. write([s,'(',slstr[sl],') ']);
  1040. case sl of
  1041. sl_call,
  1042. sl_load,
  1043. sl_subscript :
  1044. if (Ref <> nil) and (Ref.IsNull) then
  1045. begin
  1046. readderef('',Ref);
  1047. Ref.IsSymId:=True;
  1048. end
  1049. else
  1050. readderef('');
  1051. sl_absolutetype,
  1052. sl_typeconv :
  1053. readderef('');
  1054. sl_vec :
  1055. begin
  1056. writeln([ppufile.getlongint]);
  1057. readderef('');
  1058. end;
  1059. end;
  1060. until false;
  1061. end;
  1062. (*
  1063. talignmentinfo = packed record
  1064. procalign,
  1065. loopalign,
  1066. jumpalign,
  1067. constalignmin,
  1068. constalignmax,
  1069. varalignmin,
  1070. varalignmax,
  1071. localalignmin,
  1072. localalignmax,
  1073. recordalignmin,
  1074. recordalignmax,
  1075. maxCrecordalign : longint;
  1076. end;
  1077. tsettings = packed record
  1078. alignment : talignmentinfo;
  1079. globalswitches : tglobalswitches;
  1080. moduleswitches : tmoduleswitches;
  1081. localswitches : tlocalswitches;
  1082. modeswitches : tmodeswitches;
  1083. optimizerswitches : toptimizerswitches;
  1084. { generate information necessary to perform these wpo's during a subsequent compilation }
  1085. genwpoptimizerswitches: twpoptimizerswitches;
  1086. { perform these wpo's using information generated during a previous compilation }
  1087. dowpoptimizerswitches: twpoptimizerswitches;
  1088. debugswitches : tdebugswitches;
  1089. { 0: old behaviour for sets <=256 elements
  1090. >0: round to this size }
  1091. setalloc,
  1092. packenum : shortint;
  1093. packrecords : shortint;
  1094. maxfpuregisters : shortint;
  1095. cputype,
  1096. optimizecputype : tcputype;
  1097. fputype : tfputype;
  1098. asmmode : tasmmode;
  1099. interfacetype : tinterfacetypes;
  1100. defproccall : tproccalloption;
  1101. sourcecodepage : tcodepagestring;
  1102. minfpconstprec : tfloattype;
  1103. disabledircache : boolean;
  1104. { CPU targets with microcontroller support can add a controller specific unit }
  1105. controllertype : tcontrollertype;
  1106. { WARNING: this pointer cannot be written as such in record token }
  1107. pmessage : pmessagestaterecord;
  1108. end;
  1109. *)
  1110. procedure readprocinfooptions(space : string);
  1111. (*
  1112. tprocinfoflag=(
  1113. { procedure has at least one assembler block }
  1114. pi_has_assembler_block,
  1115. { procedure does a call }
  1116. pi_do_call,
  1117. { procedure has a try statement = no register optimization }
  1118. pi_uses_exceptions,
  1119. { procedure is declared as @var(assembler), don't optimize}
  1120. pi_is_assembler,
  1121. { procedure contains data which needs to be finalized }
  1122. pi_needs_implicit_finally,
  1123. { procedure has the implicit try..finally generated }
  1124. pi_has_implicit_finally,
  1125. { procedure uses fpu}
  1126. pi_uses_fpu,
  1127. { procedure uses GOT for PIC code }
  1128. pi_needs_got,
  1129. { references var/proc/type/const in static symtable,
  1130. i.e. not allowed for inlining from other units }
  1131. pi_uses_static_symtable,
  1132. { set if the procedure has to push parameters onto the stack }
  1133. pi_has_stackparameter,
  1134. { set if the procedure has at least one label }
  1135. pi_has_label,
  1136. { calls itself recursive }
  1137. pi_is_recursive,
  1138. { stack frame optimization not possible (only on x86 probably) }
  1139. pi_needs_stackframe,
  1140. { set if the procedure has at least one register saved on the stack }
  1141. pi_has_saved_regs,
  1142. { dfa was generated for this proc }
  1143. pi_dfaavailable,
  1144. { subroutine contains interprocedural used labels }
  1145. pi_has_interproclabel,
  1146. { subroutine contains interprocedural gotos }
  1147. pi_has_global_goto
  1148. ); *)
  1149. type
  1150. tprocinfoopt=record
  1151. mask : tprocinfoflag;
  1152. str : string[81];
  1153. end;
  1154. const
  1155. procinfoopts=ord(high(tprocinfoflag)) - ord(low(tprocinfoflag));
  1156. procinfoopt : array[0..procinfoopts] of tprocinfoopt=(
  1157. (mask:pi_has_assembler_block;
  1158. str:' has at least one assembler block'),
  1159. (mask:pi_do_call;
  1160. str:' does a call'),
  1161. (mask:pi_uses_exceptions;
  1162. str:' has a try statement = no register optimization '),
  1163. (mask:pi_is_assembler;
  1164. str:' is declared as @var(assembler), don''t optimize'),
  1165. (mask:pi_needs_implicit_finally;
  1166. str:' contains data which needs to be finalized '),
  1167. (mask:pi_has_implicit_finally;
  1168. str:' has the implicit try..finally generated '),
  1169. (mask:pi_uses_fpu;
  1170. str:' uses fpu'),
  1171. (mask:pi_needs_got;
  1172. str:' uses GOT for PIC code '),
  1173. (mask:pi_uses_static_symtable;
  1174. str:' references var/proc/type/const in static symtable'),
  1175. (mask:pi_has_stackparameter;
  1176. str:' set if the procedure has to push parameters onto the stack '),
  1177. (mask:pi_has_label;
  1178. str:' set if the procedure has at least one label '),
  1179. (mask:pi_is_recursive;
  1180. str:' calls itself recursive '),
  1181. (mask:pi_needs_stackframe;
  1182. str:' stack frame optimization not possible (only on x86 probably) '),
  1183. (mask:pi_has_saved_regs;
  1184. str:' set if the procedure has at least one register saved on the stack '),
  1185. (mask:pi_dfaavailable;
  1186. str:' dfa was generated for this proc '),
  1187. (mask:pi_has_interproclabel;
  1188. str:' subroutine contains interprocedural used labels '),
  1189. (mask:pi_has_unwind_info;
  1190. str:' unwinding info was generated for this proc '),
  1191. (mask:pi_has_global_goto;
  1192. str:' subroutine contains interprocedural goto '),
  1193. (mask:pi_has_inherited;
  1194. str:' subroutine contains inherited call '),
  1195. (mask:pi_has_nested_exit;
  1196. str:' subroutine contains a nested subroutine which calls the exit of the current one '),
  1197. (mask:pi_has_stack_allocs;
  1198. str:' allocates memory on stack, so stack may be unbalanced on exit '),
  1199. (mask:pi_estimatestacksize;
  1200. str:' stack size is estimated before subroutine is compiled '),
  1201. (mask:pi_calls_c_varargs;
  1202. str:' calls function with C-style varargs '),
  1203. (mask:pi_has_open_array_parameter;
  1204. str:' has open array parameter ')
  1205. );
  1206. var
  1207. procinfooptions : tprocinfoflags;
  1208. i : longint;
  1209. first : boolean;
  1210. begin
  1211. ppufile.getsmallset(procinfooptions);
  1212. if procinfooptions<>[] then
  1213. begin
  1214. first:=true;
  1215. for i:=0 to procinfoopts do
  1216. if (procinfoopt[i].mask in procinfooptions) then
  1217. begin
  1218. if first then
  1219. first:=false
  1220. else
  1221. write(', ');
  1222. write(procinfoopt[i].str);
  1223. end;
  1224. end;
  1225. writeln;
  1226. end;
  1227. procedure readsymoptions(space : string; Def: TPpuDef = nil);
  1228. type
  1229. tsymopt=record
  1230. mask : tsymoption;
  1231. str : string[30];
  1232. end;
  1233. const
  1234. symopts=ord(high(tsymoption)) - ord(low(tsymoption));
  1235. { sp_none = 0 corresponds to nothing }
  1236. symopt : array[1..symopts] of tsymopt=(
  1237. (mask:sp_static; str:'Static'),
  1238. (mask:sp_hint_deprecated; str:'Hint Deprecated'),
  1239. (mask:sp_hint_platform; str:'Hint Platform'),
  1240. (mask:sp_hint_library; str:'Hint Library'),
  1241. (mask:sp_hint_unimplemented; str:'Hint Unimplemented'),
  1242. (mask:sp_hint_experimental; str:'Hint Experimental'),
  1243. (mask:sp_has_overloaded; str:'Has overloaded'),
  1244. (mask:sp_internal; str:'Internal'),
  1245. (mask:sp_implicitrename; str:'Implicit Rename'),
  1246. (mask:sp_generic_para; str:'Generic Parameter'),
  1247. (mask:sp_has_deprecated_msg; str:'Has Deprecated Message'),
  1248. (mask:sp_generic_dummy; str:'Generic Dummy'),
  1249. (mask:sp_explicitrename; str:'Explicit Rename')
  1250. );
  1251. var
  1252. symoptions : tsymoptions;
  1253. i : longint;
  1254. first : boolean;
  1255. begin
  1256. ppufile.getsmallset(symoptions);
  1257. if symoptions<>[] then
  1258. begin
  1259. if Def <> nil then
  1260. if sp_internal in symoptions then
  1261. Def.Visibility:=dvHidden;
  1262. first:=true;
  1263. for i:=1to symopts do
  1264. if (symopt[i].mask in symoptions) then
  1265. begin
  1266. if first then
  1267. first:=false
  1268. else
  1269. write(', ');
  1270. write(symopt[i].str);
  1271. end;
  1272. end;
  1273. writeln;
  1274. if sp_has_deprecated_msg in symoptions then
  1275. writeln([space,'Deprecated : ', ppufile.getstring]);
  1276. end;
  1277. procedure readvisibility(Def: TPpuDef = nil);
  1278. var
  1279. i: byte;
  1280. begin
  1281. i:=ppufile.getbyte;
  1282. if Def <> nil then
  1283. case tvisibility(i) of
  1284. vis_public: Def.Visibility:=dvPublic;
  1285. vis_published: Def.Visibility:=dvPublished;
  1286. vis_protected, vis_strictprotected: Def.Visibility:=dvProtected;
  1287. else Def.Visibility:=dvPrivate;
  1288. end;
  1289. writeln(Visibility2Str(i));
  1290. end;
  1291. procedure readcommonsym(const s:string; Def: TPpuDef = nil);
  1292. var
  1293. i: integer;
  1294. n: string;
  1295. begin
  1296. n:=ppufile.getstring;
  1297. if Def <> nil then
  1298. Def.Name:=n;
  1299. i:=ppufile.getlongint;
  1300. if Def <> nil then
  1301. Def.SetSymId(i);
  1302. writeln([space,'** Symbol Id ',i,' **']);
  1303. writeln([space,s,n]);
  1304. write ([space,' File Pos : ']);
  1305. readposinfo(Def);
  1306. write ([space,' Visibility : ']);
  1307. readvisibility(Def);
  1308. write ([space,' SymOptions : ']);
  1309. readsymoptions(space+' ',Def);
  1310. end;
  1311. var
  1312. { needed during tobjectdef parsing... }
  1313. current_defoptions : tdefoptions;
  1314. current_objectoptions : tobjectoptions;
  1315. procedure readcommondef(const s:string; out defoptions: tdefoptions; Def: TPpuDef = nil);
  1316. type
  1317. tdefopt=record
  1318. mask : tdefoption;
  1319. str : string[30];
  1320. end;
  1321. tdefstateinfo=record
  1322. mask : tdefstate;
  1323. str : string[30];
  1324. end;
  1325. tgenconstrflag=record
  1326. mask : tgenericconstraintflag;
  1327. str : string[30];
  1328. end;
  1329. ptoken=^ttoken;
  1330. pmsgstate =^tmsgstate;
  1331. const
  1332. defopt : array[1..ord(high(tdefoption))] of tdefopt=(
  1333. (mask:df_unique; str:'Unique Type'),
  1334. (mask:df_generic; str:'Generic'),
  1335. (mask:df_specialization; str:'Specialization'),
  1336. (mask:df_copied_def; str:'Copied Typedef'),
  1337. (mask:df_genconstraint; str:'Generic Constraint'),
  1338. { this should never happen for defs stored to a ppu file }
  1339. (mask:df_not_registered_no_free; str:'Unregistered/No free (invalid)'),
  1340. (mask:df_llvm_no_struct_packing; str:'LLVM unpacked struct')
  1341. );
  1342. defstate : array[1..ord(high(tdefstate))] of tdefstateinfo=(
  1343. (mask:ds_vmt_written; str:'VMT Written'),
  1344. (mask:ds_rtti_table_used; str:'RTTITable Used'),
  1345. (mask:ds_init_table_used; str:'InitTable Used'),
  1346. (mask:ds_rtti_table_written; str:'RTTITable Written'),
  1347. (mask:ds_init_table_written; str:'InitTable Written'),
  1348. (mask:ds_dwarf_dbg_info_used; str:'Dwarf DbgInfo Used'),
  1349. (mask:ds_dwarf_dbg_info_written;str:'Dwarf DbgInfo Written')
  1350. );
  1351. genconstrflag : array[1..ord(high(tgenericconstraintflag))] of tgenconstrflag=(
  1352. (mask:gcf_constructor; str:'Constructor'),
  1353. (mask:gcf_class; str:'Class'),
  1354. (mask:gcf_record; str:'Record')
  1355. );
  1356. var
  1357. defstates : tdefstates;
  1358. i, nb{, msgvalue}, mesgnb : longint;
  1359. first : boolean;
  1360. copy_size, min_size, tokenbufsize : longint;
  1361. tokenbuf : pbyte;
  1362. // idtoken,
  1363. token : ttoken;
  1364. // state : tmsgstate;
  1365. new_settings : Tsettings;
  1366. len : sizeint;
  1367. wstring : widestring;
  1368. astring : ansistring;
  1369. genconstr : tgenericconstraintflags;
  1370. function readtoken: ttoken;
  1371. var
  1372. b,b2 : byte;
  1373. begin
  1374. b:=tokenbuf[i];
  1375. inc(i);
  1376. if (b and $80)<>0 then
  1377. begin
  1378. b2:=tokenbuf[i];
  1379. inc(i);
  1380. result:=ttoken(((b and $7f) shl 8) or b2);
  1381. end
  1382. else
  1383. result:=ttoken(b);
  1384. end;
  1385. function gettokenbufdword : dword;
  1386. var
  1387. var32 : dword;
  1388. begin
  1389. var32:=pdword(@tokenbuf[i])^;
  1390. inc(i,sizeof(dword));
  1391. if ppufile.change_endian then
  1392. var32:=swapendian(var32);
  1393. result:=var32;
  1394. end;
  1395. function gettokenbufword : word;
  1396. var
  1397. var16 : word;
  1398. begin
  1399. var16:=pword(@tokenbuf[i])^;
  1400. inc(i,sizeof(word));
  1401. if ppufile.change_endian then
  1402. var16:=swapendian(var16);
  1403. result:=var16;
  1404. end;
  1405. function gettokenbufsizeint : int64;
  1406. var
  1407. var64 : int64;
  1408. var32 : longint;
  1409. var16 : smallint;
  1410. begin
  1411. if CpuAddrBitSize[cpu]=64 then
  1412. begin
  1413. var64:=pint64(@tokenbuf[i])^;
  1414. inc(i,sizeof(int64));
  1415. if ppufile.change_endian then
  1416. var64:=swapendian(var64);
  1417. result:=var64;
  1418. end
  1419. else if CpuAddrBitSize[cpu]=32 then
  1420. begin
  1421. var32:=plongint(@tokenbuf[i])^;
  1422. inc(i,sizeof(longint));
  1423. if ppufile.change_endian then
  1424. var32:=swapendian(var32);
  1425. result:=var32;
  1426. end
  1427. else if CpuAddrBitSize[cpu]=16 then
  1428. begin
  1429. var16:=psmallint(@tokenbuf[i])^;
  1430. inc(i,sizeof(smallint));
  1431. if ppufile.change_endian then
  1432. var16:=swapendian(var16);
  1433. result:=var16;
  1434. end
  1435. else
  1436. begin
  1437. WriteError('Wrong CpuAddrBitSize');
  1438. result:=0;
  1439. end;
  1440. end;
  1441. begin
  1442. i:=ppufile.getlongint;
  1443. if Def <> nil then
  1444. Def.Id:=i;
  1445. writeln([space,'** Definition Id ',i,' **']);
  1446. writeln([space,s]);
  1447. write ([space,' Type symbol : ']);
  1448. if Def <> nil then
  1449. readderef('', Def.Ref)
  1450. else
  1451. readderef('');
  1452. write ([space,' DefOptions : ']);
  1453. ppufile.getsmallset(defoptions);
  1454. if defoptions<>[] then
  1455. begin
  1456. first:=true;
  1457. for i:=1to high(defopt) do
  1458. if (defopt[i].mask in defoptions) then
  1459. begin
  1460. if first then
  1461. first:=false
  1462. else
  1463. write(', ');
  1464. write(defopt[i].str);
  1465. end;
  1466. end;
  1467. writeln;
  1468. write ([space,' DefStates : ']);
  1469. ppufile.getsmallset(defstates);
  1470. if defstates<>[] then
  1471. begin
  1472. first:=true;
  1473. for i:=1 to high(defstate) do
  1474. if (defstate[i].mask in defstates) then
  1475. begin
  1476. if first then
  1477. first:=false
  1478. else
  1479. write(', ');
  1480. write(defstate[i].str);
  1481. end;
  1482. end;
  1483. writeln;
  1484. if df_genconstraint in defoptions then
  1485. begin
  1486. ppufile.getsmallset(genconstr);
  1487. write ([space,' GenConstraints : ']);
  1488. if genconstr<>[] then
  1489. begin
  1490. first:=true;
  1491. for i:=1 to high(genconstrflag) do
  1492. if (genconstrflag[i].mask in genconstr) then
  1493. begin
  1494. if first then
  1495. first:=false
  1496. else
  1497. write(', ');
  1498. write(genconstrflag[i].str);
  1499. end;
  1500. end;
  1501. writeln;
  1502. len:=ppufile.getasizeint;
  1503. if len>0 then
  1504. begin
  1505. space:=' '+space;
  1506. writeln([space,'------ constraint defs begin ------']);
  1507. for i:=0 to len-1 do
  1508. begin
  1509. writeln([space,'------ constraint def ',i,' ------']);
  1510. readderef(space);
  1511. end;
  1512. writeln([space,'------ constraint defs end ------']);
  1513. delete(space,1,4);
  1514. end;
  1515. end;
  1516. if [df_generic,df_specialization]*defoptions<>[] then
  1517. begin
  1518. nb:=ppufile.getlongint;
  1519. writeln([space,'has ',nb,' parameters']);
  1520. if nb>0 then
  1521. begin
  1522. for i:=0 to nb-1 do
  1523. begin
  1524. writeln([space,'parameter ',i,': ',ppufile.getstring]);
  1525. readderef(space);
  1526. end;
  1527. end;
  1528. end;
  1529. if df_generic in defoptions then
  1530. begin
  1531. tokenbufsize:=ppufile.getlongint;
  1532. writeln([space,' Tokenbuffer size : ',tokenbufsize]);
  1533. tokenbuf:=allocmem(tokenbufsize);
  1534. ppufile.getdata(tokenbuf^,tokenbufsize);
  1535. i:=0;
  1536. write([space,' Tokens: ']);
  1537. while i<tokenbufsize do
  1538. begin
  1539. token:=readtoken;
  1540. if token<>_GENERICSPECIALTOKEN then
  1541. begin
  1542. if token <= high(ttoken) then
  1543. write(arraytokeninfo[token].str)
  1544. else
  1545. begin
  1546. HasMoreInfos;
  1547. write('Error in Token List');
  1548. break;
  1549. end;
  1550. {idtoken:=}readtoken;
  1551. end;
  1552. case token of
  1553. _CWCHAR,
  1554. _CWSTRING :
  1555. begin
  1556. len:=gettokenbufsizeint;
  1557. setlength(wstring,len);
  1558. move(tokenbuf[i],wstring[1],len*2);
  1559. write([' ',wstring]);
  1560. inc(i,len*2);
  1561. end;
  1562. _CSTRING:
  1563. begin
  1564. len:=gettokenbufsizeint;
  1565. setlength(astring,len);
  1566. move(tokenbuf[i],astring[1],len);
  1567. write([' ',astring]);
  1568. inc(i,len);
  1569. end;
  1570. _CCHAR,
  1571. _INTCONST,
  1572. _REALNUMBER :
  1573. begin
  1574. write([' ',pshortstring(@tokenbuf[i])^]);
  1575. inc(i,tokenbuf[i]+1);
  1576. end;
  1577. _ID :
  1578. begin
  1579. write([' ',pshortstring(@tokenbuf[i])^]);
  1580. inc(i,tokenbuf[i]+1);
  1581. end;
  1582. _GENERICSPECIALTOKEN:
  1583. begin
  1584. { Short version of column change,
  1585. byte or $80 used }
  1586. if (tokenbuf[i] and $80)<>0 then
  1587. begin
  1588. write(['Col: ',tokenbuf[i] and $7f]);
  1589. inc(i);
  1590. end
  1591. else
  1592. case tspecialgenerictoken(tokenbuf[i]) of
  1593. ST_LOADSETTINGS:
  1594. begin
  1595. inc(i);
  1596. write('Settings');
  1597. { This does not load pmessage pointer }
  1598. new_settings.pmessage:=nil;
  1599. { TSettings size depends in target...
  1600. We first read the size of the copied part }
  1601. { Still not cross endian ready :( }
  1602. copy_size:=gettokenbufsizeint;
  1603. if copy_size < sizeof(tsettings)-sizeof(pointer) then
  1604. min_size:=copy_size
  1605. else
  1606. min_size:= sizeof(tsettings)-sizeof(pointer);
  1607. move(tokenbuf[i],new_settings, min_size);
  1608. inc(i,copy_size);
  1609. end;
  1610. ST_LOADMESSAGES:
  1611. begin
  1612. inc(i);
  1613. write('Messages:');
  1614. mesgnb:=tokenbuf[i];
  1615. inc(i);
  1616. for nb:=1 to mesgnb do
  1617. begin
  1618. {msgvalue:=}gettokenbufsizeint;
  1619. inc(i,sizeof(sizeint));
  1620. //state:=tmsgstate(gettokenbufsizeint);
  1621. end;
  1622. end;
  1623. ST_LINE:
  1624. begin
  1625. inc(i);
  1626. write(['Line: ',gettokenbufdword]);
  1627. end;
  1628. ST_COLUMN:
  1629. begin
  1630. inc(i);
  1631. write(['Col: ',gettokenbufword]);
  1632. end;
  1633. ST_FILEINDEX:
  1634. begin
  1635. inc(i);
  1636. write(['File: ',gettokenbufword]);
  1637. end;
  1638. end;
  1639. end;
  1640. end;
  1641. if i<tokenbufsize then
  1642. write(',');
  1643. end;
  1644. writeln;
  1645. freemem(tokenbuf);
  1646. end;
  1647. if df_specialization in defoptions then
  1648. begin
  1649. write ([space,' Orig. GenericDef : ']);
  1650. readderef('');
  1651. end;
  1652. current_defoptions:=defoptions;
  1653. end;
  1654. { Read abstract procdef and return if inline procdef }
  1655. { type tproccalloption is in globtype unit }
  1656. { type tproctypeoption is in globtype unit }
  1657. { type tprocoption is in globtype unit }
  1658. procedure read_abstract_proc_def(var proccalloption:tproccalloption;var procoptions:tprocoptions; ProcDef: TPpuProcDef);
  1659. type
  1660. tproccallopt=record
  1661. mask : tproccalloption;
  1662. str : string[30];
  1663. end;
  1664. tproctypeopt=record
  1665. mask : tproctypeoption;
  1666. str : string[30];
  1667. end;
  1668. tprocopt=record
  1669. mask : tprocoption;
  1670. str : string[31];
  1671. end;
  1672. const
  1673. {proccalloptionStr is also in globtype unit }
  1674. proctypeopt : array[1..ord(high(tproctypeoption))] of tproctypeopt=(
  1675. (mask:potype_proginit; str:'ProgInit'),
  1676. (mask:potype_unitinit; str:'UnitInit'),
  1677. (mask:potype_unitfinalize; str:'UnitFinalize'),
  1678. (mask:potype_constructor; str:'Constructor'),
  1679. (mask:potype_destructor; str:'Destructor'),
  1680. (mask:potype_operator; str:'Operator'),
  1681. (mask:potype_procedure; str:'Procedure'),
  1682. (mask:potype_function; str:'Function'),
  1683. (mask:potype_class_constructor; str:'Class Constructor'),
  1684. (mask:potype_class_destructor; str:'Class Destructor'),
  1685. { Dispinterface property accessors }
  1686. (mask:potype_propgetter; str:'Property Getter'),
  1687. (mask:potype_propsetter; str:'Property Setter'),
  1688. (mask:potype_exceptfilter; str:'SEH filter'),
  1689. (mask:potype_mainstub; str:'main stub')
  1690. );
  1691. procopt : array[1..ord(high(tprocoption))] of tprocopt=(
  1692. (mask:po_classmethod; str:'ClassMethod'),
  1693. (mask:po_virtualmethod; str:'VirtualMethod'),
  1694. (mask:po_abstractmethod; str:'AbstractMethod'),
  1695. (mask:po_finalmethod; str:'FinalMethod'),
  1696. (mask:po_staticmethod; str:'StaticMethod'),
  1697. (mask:po_overridingmethod;str:'OverridingMethod'),
  1698. (mask:po_methodpointer; str:'MethodPointer'),
  1699. (mask:po_interrupt; str:'Interrupt'),
  1700. (mask:po_iocheck; str:'IOCheck'),
  1701. (mask:po_assembler; str:'Assembler'),
  1702. (mask:po_msgstr; str:'MsgStr'),
  1703. (mask:po_msgint; str:'MsgInt'),
  1704. (mask:po_exports; str:'Exports'),
  1705. (mask:po_external; str:'External'),
  1706. (mask:po_overload; str:'Overload'),
  1707. (mask:po_varargs; str:'VarArgs'),
  1708. (mask:po_internconst; str:'InternConst'),
  1709. (mask:po_addressonly; str:'AddressOnly'),
  1710. (mask:po_public; str:'Public'),
  1711. (mask:po_hascallingconvention;str:'HasCallingConvention'),
  1712. (mask:po_reintroduce; str:'ReIntroduce'),
  1713. (mask:po_explicitparaloc; str:'ExplicitParaloc'),
  1714. (mask:po_nostackframe; str:'NoStackFrame'),
  1715. (mask:po_has_mangledname; str:'HasMangledName'),
  1716. (mask:po_has_public_name; str:'HasPublicName'),
  1717. (mask:po_forward; str:'Forward'),
  1718. (mask:po_global; str:'Global'),
  1719. (mask:po_syscall_legacy; str:'SyscallLegacy'),
  1720. (mask:po_syscall_sysv; str:'SyscallSysV'),
  1721. (mask:po_syscall_basesysv;str:'SyscallBaseSysV'),
  1722. (mask:po_syscall_sysvbase;str:'SyscallSysVBase'),
  1723. (mask:po_syscall_r12base; str:'SyscallR12Base'),
  1724. (mask:po_syscall_has_libsym; str:'Has LibSym'),
  1725. (mask:po_inline; str:'Inline'),
  1726. (mask:po_compilerproc; str:'CompilerProc'),
  1727. (mask:po_has_importdll; str:'HasImportDLL'),
  1728. (mask:po_has_importname; str:'HasImportName'),
  1729. (mask:po_kylixlocal; str:'KylixLocal'),
  1730. (mask:po_dispid; str:'DispId'),
  1731. (mask:po_weakexternal; str:'WeakExternal'),
  1732. (mask:po_objc; str:'ObjC'),
  1733. (mask:po_enumerator_movenext; str:'EnumeratorMoveNext'),
  1734. (mask:po_optional; str: 'Optional'),
  1735. (mask:po_delphi_nested_cc;str: 'Delphi-style nested frameptr'),
  1736. (mask:po_java_nonvirtual; str: 'Java non-virtual method'),
  1737. (mask:po_ignore_for_overload_resolution;str: 'Ignored for overload resolution'),
  1738. (mask:po_rtlproc; str: 'RTL procedure'),
  1739. (mask:po_auto_raised_visibility; str: 'Visibility raised by compiler'),
  1740. (mask:po_far; str: 'Far'),
  1741. (mask:po_noreturn; str: 'No return'),
  1742. (mask:po_is_function_ref; str: 'Function reference'),
  1743. (mask:po_is_block; str: 'C "Block"')
  1744. );
  1745. var
  1746. proctypeoption : tproctypeoption;
  1747. i : longint;
  1748. first : boolean;
  1749. tempbuf : array[0..255] of byte;
  1750. begin
  1751. write([space,' Return type : ']);
  1752. readderef('', ProcDef.ReturnType);
  1753. proctypeoption:=tproctypeoption(ppufile.getbyte);
  1754. case proctypeoption of
  1755. potype_function: Include(ProcDef.Options, poFunction);
  1756. potype_procedure: Include(ProcDef.Options, poProcedure);
  1757. potype_constructor: Include(ProcDef.Options, poConstructor);
  1758. potype_destructor: Include(ProcDef.Options, poDestructor);
  1759. potype_operator: Include(ProcDef.Options, poOperator);
  1760. end;
  1761. write([space,' TypeOption : ']);
  1762. first:=true;
  1763. for i:=1 to high(proctypeopt) do
  1764. if (proctypeopt[i].mask=proctypeoption) then
  1765. begin
  1766. if first then
  1767. first:=false
  1768. else
  1769. write(', ');
  1770. write(proctypeopt[i].str);
  1771. end;
  1772. writeln;
  1773. proccalloption:=tproccalloption(ppufile.getbyte);
  1774. writeln([space,' CallOption : ',proccalloptionStr[proccalloption]]);
  1775. ppufile.getnormalset(procoptions);
  1776. if procoptions<>[] then
  1777. begin
  1778. if po_classmethod in procoptions then Include(ProcDef.Options, poClassMethod);
  1779. if po_virtualmethod in procoptions then Include(ProcDef.Options, poVirtual);
  1780. if po_abstractmethod in procoptions then Include(ProcDef.Options, poAbstract);
  1781. if po_overridingmethod in procoptions then Include(ProcDef.Options, poOverriding);
  1782. if po_overload in procoptions then Include(ProcDef.Options, poOverload);
  1783. if po_inline in procoptions then Include(ProcDef.Options, poInline);
  1784. if (po_methodpointer in procoptions) and (ProcDef.DefType = dtProcType) then
  1785. TPpuProcTypeDef(ProcDef).MethodPtr:=True;
  1786. write([space,' Options : ']);
  1787. first:=true;
  1788. for i:=1 to high(procopt) do
  1789. if (procopt[i].mask in procoptions) then
  1790. begin
  1791. if first then
  1792. first:=false
  1793. else
  1794. write(', ');
  1795. write(procopt[i].str);
  1796. end;
  1797. writeln;
  1798. end;
  1799. if (po_explicitparaloc in procoptions) then
  1800. begin
  1801. i:=ppufile.getbyte;
  1802. ppufile.getdata(tempbuf,i);
  1803. end;
  1804. if po_syscall_has_libsym in procoptions then
  1805. readderef(space);
  1806. end;
  1807. { type tvaroption is in unit symconst }
  1808. { register variable }
  1809. { type tvarregable is in unit symconst }
  1810. procedure readabstractvarsym(const s:string;var varoptions:tvaroptions; VarDef: TPpuVarDef = nil);
  1811. type
  1812. tvaropt=record
  1813. mask : tvaroption;
  1814. str : string[30];
  1815. end;
  1816. const
  1817. varopt : array[1..ord(high(tvaroption))] of tvaropt=(
  1818. (mask:vo_is_external; str:'External'),
  1819. (mask:vo_is_dll_var; str:'DLLVar'),
  1820. (mask:vo_is_thread_var; str:'ThreadVar'),
  1821. (mask:vo_has_local_copy; str:'HasLocalCopy'),
  1822. (mask:vo_is_const; str:'Constant'),
  1823. (mask:vo_is_public; str:'Public'),
  1824. (mask:vo_is_high_para; str:'HighValue'),
  1825. (mask:vo_is_funcret; str:'Funcret'),
  1826. (mask:vo_is_self; str:'Self'),
  1827. (mask:vo_is_vmt; str:'VMT'),
  1828. (mask:vo_is_result; str:'Result'),
  1829. (mask:vo_is_parentfp; str:'ParentFP'),
  1830. (mask:vo_is_loop_counter; str:'LoopCounter'),
  1831. (mask:vo_is_hidden_para; str:'Hidden'),
  1832. (mask:vo_has_explicit_paraloc;str:'ExplicitParaloc'),
  1833. (mask:vo_is_syscall_lib; str:'SysCallLib'),
  1834. (mask:vo_has_mangledname; str:'HasMangledName'),
  1835. (mask:vo_is_typed_const; str:'TypedConst'),
  1836. (mask:vo_is_range_check; str:'RangeCheckSwitch'),
  1837. (mask:vo_is_overflow_check; str:'OverflowCheckSwitch'),
  1838. (mask:vo_is_typinfo_para; str:'TypeInfo'),
  1839. (mask:vo_is_msgsel;str:'MsgSel'),
  1840. (mask:vo_is_weak_external;str:'WeakExternal'),
  1841. (mask:vo_is_first_field;str:'IsFirstField'),
  1842. (mask:vo_volatile; str:'Volatile'),
  1843. (mask:vo_has_section; str:'HasSection'),
  1844. (mask:vo_force_finalize; str:'ForceFinalize'),
  1845. (mask:vo_is_default_var; str:'DefaultIntrinsicVar')
  1846. );
  1847. var
  1848. i : longint;
  1849. first : boolean;
  1850. begin
  1851. readcommonsym(s, VarDef);
  1852. i:=ppufile.getbyte;
  1853. if (VarDef <> nil) and (VarDef.DefType = dtParam) then
  1854. with TPpuParamDef(VarDef) do
  1855. case tvarspez(i) of
  1856. vs_value: Spez:=psValue;
  1857. vs_var: Spez:=psVar;
  1858. vs_out: Spez:=psOut;
  1859. vs_const: Spez:=psConst;
  1860. vs_constref: Spez:=psConstRef;
  1861. end;
  1862. writeln([space,' Spez : ',Varspez2Str(i)]);
  1863. writeln([space,' Regable : ',Varregable2Str(ppufile.getbyte)]);
  1864. writeln([space,' Addr Taken : ',(ppufile.getbyte<>0)]);
  1865. write ([space,' Var Type : ']);
  1866. if VarDef <> nil then
  1867. readderef('',VarDef.VarType)
  1868. else
  1869. readderef('');
  1870. ppufile.getsmallset(varoptions);
  1871. if varoptions<>[] then
  1872. begin
  1873. if (VarDef <> nil) and (VarDef.DefType = dtParam) and (vo_is_hidden_para in varoptions) then
  1874. TPpuParamDef(VarDef).Spez:=psHidden;
  1875. write([space,' Options : ']);
  1876. first:=true;
  1877. for i:=1 to high(varopt) do
  1878. if (varopt[i].mask in varoptions) then
  1879. begin
  1880. if first then
  1881. first:=false
  1882. else
  1883. write(', ');
  1884. write(varopt[i].str);
  1885. end;
  1886. writeln;
  1887. end;
  1888. end;
  1889. procedure readobjectdefoptions(ObjDef: TPpuObjectDef = nil);
  1890. type
  1891. tsymopt=record
  1892. mask : tobjectoption;
  1893. str : string[30];
  1894. end;
  1895. const
  1896. symopt : array[1..ord(high(tobjectoption))] of tsymopt=(
  1897. (mask:oo_is_forward; str:'IsForward'),
  1898. (mask:oo_is_abstract; str:'IsAbstract'),
  1899. (mask:oo_is_sealed; str:'IsSealed'),
  1900. (mask:oo_has_virtual; str:'HasVirtual'),
  1901. (mask:oo_has_private; str:'HasPrivate'),
  1902. (mask:oo_has_protected; str:'HasProtected'),
  1903. (mask:oo_has_strictprivate; str:'HasStrictPrivate'),
  1904. (mask:oo_has_strictprotected;str:'HasStrictProtected'),
  1905. (mask:oo_has_constructor; str:'HasConstructor'),
  1906. (mask:oo_has_destructor; str:'HasDestructor'),
  1907. (mask:oo_has_vmt; str:'HasVMT'),
  1908. (mask:oo_has_msgstr; str:'HasMsgStr'),
  1909. (mask:oo_has_msgint; str:'HasMsgInt'),
  1910. (mask:oo_can_have_published; str:'CanHavePublished'),
  1911. (mask:oo_has_default_property;str:'HasDefaultProperty'),
  1912. (mask:oo_has_valid_guid; str:'HasValidGUID'),
  1913. (mask:oo_has_enumerator_movenext; str:'HasEnumeratorMoveNext'),
  1914. (mask:oo_has_enumerator_current; str:'HasEnumeratorCurrent'),
  1915. (mask:oo_is_external; str:'External'),
  1916. (mask:oo_is_formal; str:'Formal'),
  1917. (mask:oo_is_classhelper; str:'Class Helper/Category'),
  1918. (mask:oo_has_class_constructor; str:'HasClassConstructor'),
  1919. (mask:oo_has_class_destructor; str:'HasClassDestructor'),
  1920. (mask:oo_is_enum_class; str:'JvmEnumClass'),
  1921. (mask:oo_has_new_destructor; str:'HasNewDestructor')
  1922. );
  1923. var
  1924. i : longint;
  1925. first : boolean;
  1926. begin
  1927. ppufile.getsmallset(current_objectoptions);
  1928. if current_objectoptions<>[] then
  1929. begin
  1930. if ObjDef <> nil then
  1931. begin
  1932. if oo_is_abstract in current_objectoptions then
  1933. Include(ObjDef.Options, ooIsAbstract);
  1934. end;
  1935. first:=true;
  1936. for i:=1 to high(symopt) do
  1937. if (symopt[i].mask in current_objectoptions) then
  1938. begin
  1939. if first then
  1940. first:=false
  1941. else
  1942. write(', ');
  1943. write(symopt[i].str);
  1944. end;
  1945. end;
  1946. writeln;
  1947. end;
  1948. procedure readprocimploptions(const space: string; out implprocoptions: timplprocoptions);
  1949. type
  1950. tpiopt=record
  1951. mask : timplprocoption;
  1952. str : string[30];
  1953. end;
  1954. const
  1955. piopt : array[low(timplprocoption)..high(timplprocoption)] of tpiopt=(
  1956. (mask:pio_empty; str:'IsEmpty'),
  1957. (mask:pio_has_inlininginfo; str:'HasInliningInfo')
  1958. );
  1959. var
  1960. i: timplprocoption;
  1961. first: boolean;
  1962. begin
  1963. ppufile.getsmallset(implprocoptions);
  1964. if implprocoptions<>[] then
  1965. begin
  1966. first:=true;
  1967. write([space,' Options : ']);
  1968. for i:=low(piopt) to high(piopt) do
  1969. begin
  1970. if i in implprocoptions then
  1971. begin
  1972. if first then
  1973. first:=false
  1974. else
  1975. write(', ');
  1976. write(piopt[i].str);
  1977. end;
  1978. end;
  1979. writeln;
  1980. end;
  1981. end;
  1982. procedure readarraydefoptions(ArrayDef: TPpuArrayDef);
  1983. { type tarraydefoption is in unit symconst }
  1984. const
  1985. symopt : array[tarraydefoption] of string = (
  1986. { ado_IsConvertedPointer } 'ConvertedPointer',
  1987. { ado_IsDynamicArray } 'IsDynamicArray',
  1988. { ado_IsVariant } 'IsVariant',
  1989. { ado_IsConstructor } 'IsConstructor',
  1990. { ado_IsArrayOfConst } 'ArrayOfConst',
  1991. { ado_IsConstString } 'ConstString',
  1992. { ado_IsBitPacked } 'BitPacked'
  1993. );
  1994. var
  1995. symoptions: tarraydefoptions;
  1996. i: tarraydefoption;
  1997. first: boolean;
  1998. begin
  1999. ppufile.getsmallset(symoptions);
  2000. if symoptions<>[] then
  2001. begin
  2002. if ado_IsDynamicArray in symoptions then Include(ArrayDef.Options, aoDynamic);
  2003. first:=true;
  2004. for i:=Low(symopt) to high(symopt) do
  2005. if (i in symoptions) then
  2006. begin
  2007. if first then
  2008. first:=false
  2009. else
  2010. write(', ');
  2011. write(symopt[i]);
  2012. end;
  2013. end;
  2014. writeln;
  2015. end;
  2016. (* options for properties
  2017. tpropertyoption=(ppo_none,
  2018. ppo_indexed,
  2019. ppo_defaultproperty,
  2020. ppo_stored,
  2021. ppo_hasparameters,
  2022. ppo_implements,
  2023. ppo_enumerator_current,
  2024. ppo_overrides,
  2025. ppo_dispid_write { no longer used }
  2026. );
  2027. tpropertyoptions=set of tpropertyoption;
  2028. *)
  2029. function readpropertyoptions:tpropertyoptions;
  2030. { type tarraydefoption is in unit symconst }
  2031. type
  2032. tpropopt=record
  2033. mask : tpropertyoption;
  2034. str : string[30];
  2035. end;
  2036. const
  2037. symopt : array[1..ord(high(tpropertyoption))] of tpropopt=(
  2038. (mask:ppo_indexed;str:'indexed'),
  2039. (mask:ppo_defaultproperty;str:'default'),
  2040. (mask:ppo_stored;str:'stored'),
  2041. (mask:ppo_hasparameters;str:'has parameters'),
  2042. (mask:ppo_implements;str:'implements'),
  2043. (mask:ppo_enumerator_current;str:'enumerator current'),
  2044. (mask:ppo_overrides;str:'overrides'),
  2045. (mask:ppo_dispid_write;str:'dispid write') { no longer used }
  2046. );
  2047. var
  2048. i : longint;
  2049. first : boolean;
  2050. begin
  2051. ppufile.getsmallset(result);
  2052. if result<>[] then
  2053. begin
  2054. first:=true;
  2055. for i:=1 to high(symopt) do
  2056. if (symopt[i].mask in result) then
  2057. begin
  2058. if first then
  2059. first:=false
  2060. else
  2061. write(', ');
  2062. write(symopt[i].str);
  2063. end;
  2064. end;
  2065. writeln;
  2066. end;
  2067. procedure readnodetree;
  2068. var
  2069. l : longint;
  2070. p : pointer;
  2071. begin
  2072. with ppufile do
  2073. begin
  2074. if space<>'' then
  2075. Writeln([space,'------ nodetree ------']);
  2076. if readentry=ibnodetree then
  2077. begin
  2078. l:=entrysize;
  2079. Writeln([space,'Tree size : ',l]);
  2080. { Read data to prevent error that entry is not completly read }
  2081. getmem(p,l);
  2082. getdata(p^,l);
  2083. freemem(p);
  2084. end
  2085. else
  2086. begin
  2087. WriteError('!! ibnodetree not found');
  2088. end;
  2089. end;
  2090. end;
  2091. procedure ReadCreatedObjTypes;
  2092. var
  2093. i,j,
  2094. len,
  2095. bssize: longint;
  2096. bs: pbyte;
  2097. begin
  2098. if ppufile.readentry<>ibcreatedobjtypes then
  2099. begin
  2100. WriteError('!! ibcreatedobjtypes entry not found');
  2101. ppufile.skipdata(ppufile.entrysize);
  2102. exit
  2103. end;
  2104. writeln;
  2105. writeln([space,'WPO info']);
  2106. writeln([space,'--------']);
  2107. len:=ppufile.getlongint;
  2108. writeln([space,'** Instantiated Object/Class types: ',len,' **']);
  2109. space:=space+' ';
  2110. for i:=0 to len-1 do
  2111. readderef(space);
  2112. setlength(space,length(space)-2);
  2113. len:=ppufile.getlongint;
  2114. writeln([space,'** Instantiated ClassRef types: ',len,' **']);
  2115. space:=space+' ';
  2116. for i:=0 to len-1 do
  2117. readderef(space);
  2118. setlength(space,length(space)-2);
  2119. len:=ppufile.getlongint;
  2120. writeln([space,'** Possibly instantiated ClassRef types : ',len,' **']);
  2121. space:=space+' ';
  2122. for i:=0 to len-1 do
  2123. readderef(space);
  2124. setlength(space,length(space)-2);
  2125. len:=ppufile.getlongint;
  2126. writeln([space,'** Class types with called virtual methods info : ',len,' **']);
  2127. space:=space+' ';
  2128. for i:=0 to len-1 do
  2129. begin
  2130. write([space,'Class def : ']);
  2131. readderef('');
  2132. write([space+' ','Called vmtentries : ']);
  2133. bssize:=ppufile.getlongint;
  2134. getmem(bs,bssize);
  2135. ppufile.readdata(bs^,bssize);
  2136. for j:=0 to bssize*8-1 do
  2137. if (((bs+j shr 3)^ shr (j and 7)) and 1) <> 0 then
  2138. write([j,', ']);
  2139. writeln;
  2140. freemem(bs);
  2141. end;
  2142. setlength(space,length(space)-2);
  2143. end;
  2144. {****************************************************************************
  2145. Read Symbols Part
  2146. ****************************************************************************}
  2147. procedure readsymbols(const s:string; ParentDef: TPpuContainerDef = nil);
  2148. function _finddef(symdef: TPpuDef): TPpuDef;
  2149. begin
  2150. Result:=nil;
  2151. if symdef.Ref.IsCurUnit then
  2152. begin;
  2153. Result:=CurUnit.FindById(symdef.Ref.Id);
  2154. if (Result <> nil) and (Result.Ref.Id = symdef.Id) then
  2155. begin
  2156. Result.Name:=symdef.Name;
  2157. Result.FilePos:=symdef.FilePos;
  2158. end
  2159. else
  2160. Result:=nil;
  2161. end;
  2162. end;
  2163. type
  2164. pguid = ^tguid;
  2165. tguid = packed record
  2166. D1: LongWord;
  2167. D2: Word;
  2168. D3: Word;
  2169. D4: array[0..7] of Byte;
  2170. end;
  2171. var
  2172. b : byte;
  2173. pc : pchar;
  2174. ch : dword;
  2175. startnewline : boolean;
  2176. i,j,len : longint;
  2177. prettyname, ss : ansistring;
  2178. ws: widestring;
  2179. guid : tguid;
  2180. realvalue : ppureal;
  2181. doublevalue : double;
  2182. singlevalue : single;
  2183. extended : TSplit80bitReal;
  2184. tempbuf : array[0..127] of char;
  2185. pw : pcompilerwidestring;
  2186. varoptions : tvaroptions;
  2187. propoptions : tpropertyoptions;
  2188. iexp: Tconstexprint;
  2189. def: TPpuDef;
  2190. constdef: TPpuConstDef absolute def;
  2191. begin
  2192. with ppufile do
  2193. begin
  2194. if space<>'' then
  2195. Writeln([space,'------ ',s,' ------']);
  2196. if readentry=ibstartsyms then
  2197. begin
  2198. Writeln([space,'Symtable datasize : ',getlongint]);
  2199. Writeln([space,'Symtable alignment: ',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 tsystemcpu(ppufile.header.common.cpu)=cpu_powerpc then
  2868. begin
  2869. { library symbol for AmigaOS/MorphOS }
  2870. write ([space,' Library symbol : ']);
  2871. readderef('');
  2872. end;
  2873. if (po_has_importdll in procoptions) then
  2874. writeln([space,' Import DLL : ',getstring]);
  2875. if (po_has_importname in procoptions) then
  2876. writeln([space,' Import Name : ',getstring]);
  2877. writeln([space,' Import Nr : ',getword]);
  2878. if (po_msgint in procoptions) then
  2879. writeln([space,' MsgInt : ',getlongint]);
  2880. if (po_msgstr in procoptions) then
  2881. writeln([space,' MsgStr : ',getstring]);
  2882. if (po_dispid in procoptions) then
  2883. writeln([space,' DispID: ',ppufile.getlongint]);
  2884. readprocimploptions(space,implprocoptions);
  2885. if (pio_has_inlininginfo in implprocoptions) then
  2886. begin
  2887. write ([space,' FuncretSym : ']);
  2888. readderef('');
  2889. readprocinfooptions(space);
  2890. end;
  2891. b:=ppufile.getbyte;
  2892. if b<>0 then
  2893. begin
  2894. write ([space,' Alias names : ']);
  2895. for j:=1 to b do
  2896. begin
  2897. write(ppufile.getstring);
  2898. if j<b then
  2899. write(', ');
  2900. end;
  2901. writeln;
  2902. end;
  2903. tokenbufsize:=ppufile.getlongint;
  2904. if tokenbufsize<>0 then
  2905. begin
  2906. write ([space,' Declaration token buffer : TODO']);
  2907. tokenbuf:=allocmem(tokenbufsize);
  2908. ppufile.getdata(tokenbuf^,tokenbufsize);
  2909. freemem(tokenbuf);
  2910. end;
  2911. if not EndOfEntry then
  2912. HasMoreInfos;
  2913. space:=' '+space;
  2914. { parast }
  2915. readsymtable('parast', TPpuProcDef(def));
  2916. { localst }
  2917. if (pio_has_inlininginfo in implprocoptions) then
  2918. readsymtable('localst');
  2919. if (pio_has_inlininginfo in implprocoptions) then
  2920. readnodetree;
  2921. delete(space,1,4);
  2922. end;
  2923. ibprocvardef :
  2924. begin
  2925. def:=TPpuProcTypeDef.Create(ParentDef);
  2926. readcommondef('Procedural type (ProcVar) definition',defoptions,def);
  2927. read_abstract_proc_def(calloption,procoptions, TPpuProcDef(def));
  2928. writeln([space,' Symtable level :',ppufile.getbyte]);
  2929. if not EndOfEntry then
  2930. HasMoreInfos;
  2931. space:=' '+space;
  2932. { parast }
  2933. readsymtable('parast',TPpuProcDef(def));
  2934. delete(space,1,4);
  2935. if tsystemcpu(ppufile.header.common.cpu)=cpu_jvm then
  2936. readderef('');
  2937. end;
  2938. ibshortstringdef :
  2939. begin
  2940. strdef:=TPpuStringDef.Create(ParentDef);
  2941. strdef.StrType:=stShort;
  2942. readcommondef('ShortString definition',defoptions,strdef);
  2943. strdef.Len:=getbyte;
  2944. writeln([space,' Length : ',strdef.Len]);
  2945. end;
  2946. ibwidestringdef :
  2947. begin
  2948. strdef:=TPpuStringDef.Create(ParentDef);
  2949. strdef.StrType:=stWide;
  2950. readcommondef('WideString definition',defoptions,strdef);
  2951. strdef.Len:=getaint;
  2952. writeln([space,' Length : ',strdef.Len]);
  2953. end;
  2954. ibunicodestringdef :
  2955. begin
  2956. strdef:=TPpuStringDef.Create(ParentDef);
  2957. strdef.StrType:=stUnicode;
  2958. readcommondef('UnicodeString definition',defoptions,strdef);
  2959. strdef.Len:=getaint;
  2960. writeln([space,' Length : ',strdef.Len]);
  2961. writeln([space,' Encoding : ',getword]);
  2962. end;
  2963. ibansistringdef :
  2964. begin
  2965. strdef:=TPpuStringDef.Create(ParentDef);
  2966. strdef.StrType:=stAnsi;
  2967. readcommondef('AnsiString definition',defoptions,strdef);
  2968. strdef.Len:=getaint;
  2969. writeln([space,' Length : ',strdef.Len]);
  2970. writeln([space,' Encoding : ',getword]);
  2971. end;
  2972. iblongstringdef :
  2973. begin
  2974. strdef:=TPpuStringDef.Create(ParentDef);
  2975. strdef.StrType:=stLong;
  2976. readcommondef('Longstring definition',defoptions,strdef);
  2977. strdef.Len:=getaint;
  2978. writeln([space,' Length : ',strdef.Len]);
  2979. end;
  2980. ibrecorddef :
  2981. begin
  2982. objdef:=TPpuRecordDef.Create(ParentDef);
  2983. readcommondef('Record definition',defoptions, objdef);
  2984. def.Name:=getstring;
  2985. writeln([space,' Name of Record : ',objdef.Name]);
  2986. writeln([space,' Import lib/pkg : ',getstring]);
  2987. write ([space,' Options : ']);
  2988. readobjectdefoptions(objdef);
  2989. if (df_copied_def in defoptions) then
  2990. begin
  2991. Include(TPpuRecordDef(def).Options, ooCopied);
  2992. write([space,' Copied from : ']);
  2993. readderef('',objdef.Ancestor);
  2994. end
  2995. else
  2996. begin
  2997. writeln([space,' FieldAlign : ',shortint(getbyte)]);
  2998. writeln([space,' RecordAlign : ',shortint(getbyte)]);
  2999. writeln([space,' PadAlign : ',shortint(getbyte)]);
  3000. writeln([space,'UseFieldAlignment : ',shortint(getbyte)]);
  3001. writeln([space,' RecordAlignMin : ',shortint(getbyte)]);
  3002. objdef.Size:=getasizeint;
  3003. writeln([space,' DataSize : ',objdef.Size]);
  3004. writeln([space,' PaddingSize : ',getword]);
  3005. end;
  3006. if not EndOfEntry then
  3007. HasMoreInfos;
  3008. {read the record definitions and symbols}
  3009. if not(df_copied_def in current_defoptions) then
  3010. begin
  3011. space:=' '+space;
  3012. readrecsymtableoptions;
  3013. readsymtable('fields',TPpuRecordDef(def));
  3014. Delete(space,1,4);
  3015. end;
  3016. end;
  3017. ibobjectdef :
  3018. begin
  3019. objdef:=TPpuObjectDef.Create(ParentDef);
  3020. readcommondef('Object/Class definition',defoptions,objdef);
  3021. objdef.Name:=getstring;
  3022. writeln([space,' Name of Class : ',objdef.Name]);
  3023. writeln([space,' Import lib/pkg : ',getstring]);
  3024. write ([space,' Options : ']);
  3025. readobjectdefoptions(objdef);
  3026. b:=getbyte;
  3027. write ([space,' Type : ']);
  3028. case tobjecttyp(b) of
  3029. odt_class : writeln('class');
  3030. odt_object : writeln('object');
  3031. odt_interfacecom : writeln('interfacecom');
  3032. odt_interfacecorba : writeln('interfacecorba');
  3033. odt_cppclass : writeln('cppclass');
  3034. odt_dispinterface : writeln('dispinterface');
  3035. odt_objcclass : writeln('objcclass');
  3036. odt_objcprotocol : writeln('objcprotocol');
  3037. odt_helper : writeln('helper');
  3038. odt_objccategory : writeln('objccategory');
  3039. odt_javaclass : writeln('Java class');
  3040. odt_interfacejava : writeln('Java interface');
  3041. else WriteWarning('Invalid object type: ' + IntToStr(b));
  3042. end;
  3043. case tobjecttyp(b) of
  3044. odt_class, odt_cppclass, odt_objcclass, odt_javaclass:
  3045. objdef.ObjType:=otClass;
  3046. odt_object:
  3047. objdef.ObjType:=otObject;
  3048. odt_interfacecom, odt_interfacecorba, odt_interfacejava, odt_dispinterface:
  3049. objdef.ObjType:=otInterface;
  3050. odt_helper:
  3051. objdef.ObjType:=otHelper;
  3052. end;
  3053. writeln([space,' External name : ',getstring]);
  3054. objdef.Size:=getasizeint;
  3055. writeln([space,' DataSize : ',objdef.Size]);
  3056. writeln([space,' PaddingSize : ',getword]);
  3057. writeln([space,' FieldAlign : ',shortint(getbyte)]);
  3058. writeln([space,' RecordAlign : ',shortint(getbyte)]);
  3059. writeln([space,' RecordAlignMin : ',shortint(getbyte)]);
  3060. write ([space, ' VmtField : ']);
  3061. readderef('',nil);
  3062. write ([space, ' Ancestor Class : ']);
  3063. readderef('',objdef.Ancestor);
  3064. if tobjecttyp(b) in [odt_interfacecom,odt_interfacecorba,odt_dispinterface] then
  3065. begin
  3066. { IIDGUID }
  3067. for j:=1to 16 do
  3068. getbyte;
  3069. objdef.IID:=getstring;
  3070. writeln([space,' IID String : ',objdef.IID]);
  3071. end;
  3072. writeln([space,' Abstract methods : ',getlongint]);
  3073. if tobjecttyp(b)=odt_helper then
  3074. begin
  3075. write([space,' Helper parent : ']);
  3076. readderef('',objdef.HelperParent);
  3077. end;
  3078. l:=getlongint;
  3079. writeln([space,' VMT entries: ',l]);
  3080. for j:=1 to l do
  3081. begin
  3082. write([space,' ']);
  3083. readderef('');
  3084. write([space,' Visibility: ']);
  3085. readvisibility;
  3086. end;
  3087. if tobjecttyp(b) in [odt_class,odt_objcclass,odt_objcprotocol,odt_javaclass,odt_interfacejava] then
  3088. begin
  3089. l:=getlongint;
  3090. writeln([space,' Impl Intf Count : ',l]);
  3091. for j:=1 to l do
  3092. begin
  3093. write ([space,' - Definition : ']);
  3094. readderef('');
  3095. write ([space,' - Getter Def : ']);
  3096. readderef('');
  3097. writeln([space,' IOffset : ',getlongint]);
  3098. writeln([space,' Entry type : ',IntfEntryType2Str(getbyte)]);
  3099. end;
  3100. end;
  3101. if df_copied_def in current_defoptions then
  3102. begin
  3103. Include(objdef.Options, ooCopied);
  3104. writeln(' Copy of def: ');
  3105. readderef('',objdef.Ancestor);
  3106. end;
  3107. if not EndOfEntry then
  3108. HasMoreInfos;
  3109. if not(df_copied_def in current_defoptions) then
  3110. begin
  3111. {read the record definitions and symbols}
  3112. space:=' '+space;
  3113. readrecsymtableoptions;
  3114. readsymtable('fields',objdef);
  3115. Delete(space,1,4);
  3116. end;
  3117. end;
  3118. ibfiledef :
  3119. begin
  3120. filedef:=TPpuFileDef.Create(ParentDef);
  3121. ReadCommonDef('File definition',defoptions,filedef);
  3122. write ([space,' Type : ']);
  3123. case getbyte of
  3124. 0 : begin
  3125. writeln('Text');
  3126. filedef.FileType:=ftText;
  3127. end;
  3128. 1 : begin
  3129. writeln('Typed');
  3130. filedef.FileType:=ftTyped;
  3131. write ([space,' File of Type : ']);
  3132. readderef('',filedef.TypeRef);
  3133. end;
  3134. 2 : begin
  3135. writeln('Untyped');
  3136. filedef.FileType:=ftUntyped;
  3137. end;
  3138. end;
  3139. end;
  3140. ibformaldef :
  3141. begin
  3142. def:=TPpuFormalDef.Create(ParentDef);
  3143. readcommondef('Generic definition (void-typ)',defoptions,def);
  3144. TPpuFormalDef(def).IsTyped:=(getbyte<>0);
  3145. writeln([space,' Is Typed : ',TPpuFormalDef(def).IsTyped]);
  3146. end;
  3147. ibundefineddef :
  3148. begin
  3149. def:=TPpuUndefinedDef.Create(ParentDef);
  3150. readcommondef('Undefined definition (generic parameter)',defoptions,def);
  3151. end;
  3152. ibenumdef :
  3153. begin
  3154. enumdef:=TPpuEnumDef.Create(ParentDef);
  3155. readcommondef('Enumeration type definition',defoptions,enumdef);
  3156. enumdef.ElLow:=getaint;
  3157. writeln([space,' Smallest element : ',enumdef.ElLow]);
  3158. enumdef.ElHigh:=getaint;
  3159. writeln([space,' Largest element : ',enumdef.ElHigh]);
  3160. enumdef.Size:=byte(getaint);
  3161. writeln([space,' Size : ',enumdef.Size]);
  3162. if df_copied_def in defoptions then
  3163. begin
  3164. write([space,'Base enumeration type : ']);
  3165. readderef('',enumdef.CopyFrom);
  3166. end
  3167. else
  3168. begin
  3169. space:=' '+space;
  3170. readsymtable('elements',enumdef);
  3171. delete(space,1,4);
  3172. end;
  3173. if tsystemcpu(ppufile.header.common.cpu)=cpu_jvm then
  3174. begin
  3175. write([space,' Class def : ']);
  3176. readderef('');
  3177. end;
  3178. end;
  3179. ibclassrefdef :
  3180. begin
  3181. def:=TPpuClassRefDef.Create(ParentDef);
  3182. readcommondef('Class reference definition',defoptions,def);
  3183. write ([space,' Pointed Type : ']);
  3184. readderef('',TPpuClassRefDef(def).ClassRef);
  3185. end;
  3186. ibsetdef :
  3187. begin
  3188. setdef:=TPpuSetDef.Create(ParentDef);
  3189. readcommondef('Set definition',defoptions,setdef);
  3190. write ([space,' Element type : ']);
  3191. readderef('',setdef.ElType);
  3192. setdef.Size:=getasizeint;
  3193. writeln([space,' Size : ',setdef.Size]);
  3194. setdef.SetBase:=getasizeint;
  3195. writeln([space,' Set Base : ',setdef.SetBase]);
  3196. setdef.SetMax:=getasizeint;
  3197. writeln([space,' Set Max : ',setdef.SetMax]);
  3198. end;
  3199. ibvariantdef :
  3200. begin
  3201. def:=TPpuVariantDef.Create(ParentDef);
  3202. readcommondef('Variant definition',defoptions,def);
  3203. write ([space,' Varianttype : ']);
  3204. b:=getbyte;
  3205. case tvarianttype(b) of
  3206. vt_normalvariant :
  3207. writeln('Normal');
  3208. vt_olevariant :
  3209. begin
  3210. TPpuVariantDef(def).IsOLE:=True;
  3211. writeln('OLE');
  3212. end
  3213. else
  3214. WriteWarning('Invalid varianttype: ' + IntToStr(b));
  3215. end;
  3216. end;
  3217. iberror :
  3218. begin
  3219. WriteError('!! Error in PPU');
  3220. exit;
  3221. end;
  3222. ibenddefs :
  3223. break;
  3224. else
  3225. begin
  3226. WriteError('!! Skipping unsupported PPU Entry in definitions: '+IntToStr(b));
  3227. end;
  3228. end;
  3229. if (def <> nil) and (def.Parent = nil) then
  3230. def.Free;
  3231. if not EndOfEntry then
  3232. HasMoreInfos;
  3233. until false;
  3234. end;
  3235. end;
  3236. procedure readmoduleoptions(space : string);
  3237. type
  3238. { tmoduleoption type is in unit fmodule }
  3239. tmoduleoption = (mo_none,
  3240. mo_hint_deprecated,
  3241. mo_hint_platform,
  3242. mo_hint_library,
  3243. mo_hint_unimplemented,
  3244. mo_hint_experimental,
  3245. mo_has_deprecated_msg
  3246. );
  3247. tmoduleoptions = set of tmoduleoption;
  3248. tmoduleopt=record
  3249. mask : tmoduleoption;
  3250. str : string[30];
  3251. end;
  3252. const
  3253. moduleopts=ord(high(tmoduleoption));
  3254. moduleopt : array[1..moduleopts] of tmoduleopt=(
  3255. (mask:mo_hint_deprecated; str:'Hint Deprecated'),
  3256. (mask:mo_hint_platform; str:'Hint Platform'),
  3257. (mask:mo_hint_library; str:'Hint Library'),
  3258. (mask:mo_hint_unimplemented; str:'Hint Unimplemented'),
  3259. (mask:mo_hint_experimental; str:'Hint Experimental'),
  3260. (mask:mo_has_deprecated_msg; str:'Has Deprecated Message')
  3261. );
  3262. var
  3263. moduleoptions : tmoduleoptions;
  3264. i : longint;
  3265. first : boolean;
  3266. begin
  3267. ppufile.getsmallset(moduleoptions);
  3268. if moduleoptions<>[] then
  3269. begin
  3270. first:=true;
  3271. for i:=1to moduleopts do
  3272. if (moduleopt[i].mask in moduleoptions) then
  3273. begin
  3274. if first then
  3275. first:=false
  3276. else
  3277. write(', ');
  3278. write(moduleopt[i].str);
  3279. end;
  3280. end;
  3281. writeln;
  3282. if mo_has_deprecated_msg in moduleoptions then
  3283. writeln([space,'Deprecated : ', ppufile.getstring]);
  3284. end;
  3285. {****************************************************************************
  3286. Read General Part
  3287. ****************************************************************************}
  3288. procedure readinterface(silent : boolean);
  3289. var
  3290. b : byte;
  3291. sourcenumber, i : longint;
  3292. begin
  3293. with ppufile do
  3294. begin
  3295. repeat
  3296. b:=readentry;
  3297. case b of
  3298. ibmodulename :
  3299. begin
  3300. CurUnit.Name:=getstring;
  3301. if not silent then
  3302. Writeln(['Module Name: ',CurUnit.Name]);
  3303. end;
  3304. ibmoduleoptions:
  3305. if not silent then
  3306. readmoduleoptions(' ');
  3307. ibsourcefiles :
  3308. begin
  3309. sourcenumber:=1;
  3310. if not silent then
  3311. while not EndOfEntry do
  3312. begin
  3313. with TPpuSrcFile.Create(CurUnit.SourceFiles) do begin
  3314. Name:=getstring;
  3315. i:=getlongint;
  3316. if i >= 0 then
  3317. FileTime:=FileDateToDateTime(i);
  3318. Writeln(['Source file ',sourcenumber,' : ',Name,' ',filetimestring(i)]);
  3319. end;
  3320. inc(sourcenumber);
  3321. end;
  3322. end;
  3323. {$IFDEF MACRO_DIFF_HINT}
  3324. ibusedmacros :
  3325. begin
  3326. if not silent then
  3327. while not EndOfEntry do
  3328. begin
  3329. Write('Conditional ',getstring);
  3330. b:=getbyte;
  3331. if boolean(b)=true then
  3332. write(' defined at startup')
  3333. else
  3334. write(' not defined at startup');
  3335. b:=getbyte;
  3336. if boolean(b)=true then
  3337. writeln(' was used')
  3338. else
  3339. writeln;
  3340. end;
  3341. end;
  3342. {$ENDIF}
  3343. ibloadunit :
  3344. if not silent then
  3345. ReadLoadUnit;
  3346. iblinkunitofiles :
  3347. if not silent then
  3348. ReadLinkContainer('Link unit object file: ');
  3349. iblinkunitstaticlibs :
  3350. if not silent then
  3351. ReadLinkContainer('Link unit static lib: ');
  3352. iblinkunitsharedlibs :
  3353. if not silent then
  3354. ReadLinkContainer('Link unit shared lib: ');
  3355. iblinkotherofiles :
  3356. if not silent then
  3357. ReadLinkContainer('Link other object file: ');
  3358. iblinkotherstaticlibs :
  3359. if not silent then
  3360. ReadLinkContainer('Link other static lib: ');
  3361. iblinkothersharedlibs :
  3362. if not silent then
  3363. ReadLinkContainer('Link other shared lib: ');
  3364. iblinkotherframeworks:
  3365. if not silent then
  3366. ReadLinkContainer('Link framework: ');
  3367. ibmainname:
  3368. if not silent then
  3369. Writeln(['Specified main program symbol name: ',getstring]);
  3370. ibImportSymbols :
  3371. if not silent then
  3372. ReadImportSymbols;
  3373. ibderefdata :
  3374. ReadDerefData;
  3375. ibderefmap :
  3376. ReadDerefMap;
  3377. ibwpofile :
  3378. if not silent then
  3379. ReadWpoFileInfo;
  3380. ibresources :
  3381. if not silent then
  3382. ReadLinkContainer('Resource file: ');
  3383. iberror :
  3384. begin
  3385. WriteError('Error in PPU');
  3386. exit;
  3387. end;
  3388. ibendinterface :
  3389. break;
  3390. else
  3391. begin
  3392. WriteError('!! Skipping unsupported PPU Entry in General Part: '+IntToStr(b));
  3393. end;
  3394. end;
  3395. until false;
  3396. end;
  3397. end;
  3398. {****************************************************************************
  3399. Read Implementation Part
  3400. ****************************************************************************}
  3401. procedure readimplementation;
  3402. var
  3403. b : byte;
  3404. begin
  3405. with ppufile do
  3406. begin
  3407. repeat
  3408. b:=readentry;
  3409. case b of
  3410. ibasmsymbols :
  3411. ReadAsmSymbols;
  3412. ibloadunit :
  3413. ReadLoadUnit;
  3414. ibunitimportsyms :
  3415. ReadUnitImportSyms;
  3416. iberror :
  3417. begin
  3418. WriteError('Error in PPU');
  3419. exit;
  3420. end;
  3421. ibendimplementation :
  3422. break;
  3423. else
  3424. begin
  3425. WriteError('!! Skipping unsupported PPU Entry in Implementation: '+IntToStr(b));
  3426. end;
  3427. end;
  3428. until false;
  3429. end;
  3430. end;
  3431. procedure dofile (filename : string);
  3432. begin
  3433. { reset }
  3434. space:='';
  3435. { fix filename }
  3436. if pos('.',filename)=0 then
  3437. filename:=filename+'.ppu';
  3438. ppufile:=tppufile.create(filename);
  3439. if not ppufile.openfile then
  3440. begin
  3441. WriteError('IO-Error when opening : '+filename+', Skipping');
  3442. exit;
  3443. end;
  3444. { PPU File is open, check for PPU Id }
  3445. if not ppufile.CheckPPUID then
  3446. begin
  3447. WriteError(Filename+' : Not a valid PPU file, Skipping');
  3448. exit;
  3449. end;
  3450. { Check PPU Version }
  3451. ppuversion:=ppufile.getversion;
  3452. Writeln(['Analyzing ',filename,' (v',PPUVersion,')']);
  3453. if PPUVersion<16 then
  3454. begin
  3455. WriteError(Filename+' : Old PPU Formats (<v16) are not supported, Skipping');
  3456. exit;
  3457. end;
  3458. if not SkipVersionCheck and (PPUVersion <> CurrentPPUVersion) then
  3459. begin
  3460. WriteError(Format('Unsupported PPU version %d. Expecting PPU version %d.', [PPUVersion, CurrentPPUVersion]));
  3461. exit;
  3462. end;
  3463. CurUnit:=TPpuUnitDef.Create(UnitList);
  3464. CurUnit.Version:=ppuversion;
  3465. { Write PPU Header Information }
  3466. if (verbose and v_header)<>0 then
  3467. begin
  3468. Writeln;
  3469. Writeln('Header');
  3470. Writeln('-------');
  3471. with ppufile.header do
  3472. begin
  3473. Writeln(['Compiler version : ',ppufile.header.common.compiler shr 14,'.',
  3474. (ppufile.header.common.compiler shr 7) and $7f,'.',
  3475. ppufile.header.common.compiler and $7f]);
  3476. WriteLn(['Target processor : ',Cpu2Str(common.cpu)]);
  3477. WriteLn(['Target operating system : ',Target2Str(common.target)]);
  3478. Writeln(['Unit flags : ',PPUFlags2Str(common.flags)]);
  3479. Writeln(['FileSize (w/o header) : ',common.size]);
  3480. Writeln(['Checksum : ',hexstr(checksum,8)]);
  3481. Writeln(['Interface Checksum : ',hexstr(interface_checksum,8)]);
  3482. Writeln(['Indirect Checksum : ',hexstr(indirect_checksum,8)]);
  3483. Writeln(['Definitions stored : ',tostr(deflistsize)]);
  3484. Writeln(['Symbols stored : ',tostr(symlistsize)]);
  3485. end;
  3486. end;
  3487. with ppufile.header do
  3488. begin
  3489. CurUnit.Crc:=checksum;
  3490. CurUnit.IntfCrc:=interface_checksum;
  3491. CurUnit.TargetCPU:=Cpu2Str(common.cpu);
  3492. CurUnit.TargetOS:=Target2Str(common.target);
  3493. end;
  3494. {read the general stuff}
  3495. if (verbose and v_interface)<>0 then
  3496. begin
  3497. Writeln;
  3498. Writeln('Interface section');
  3499. Writeln('------------------');
  3500. readinterface(false);
  3501. end
  3502. { We need derefdata from Interface }
  3503. else if verbose and (v_defs or v_syms or v_implementation)<>0 then
  3504. readinterface(true)
  3505. else
  3506. ppufile.skipuntilentry(ibendinterface);
  3507. Writeln;
  3508. Writeln('Interface symtable');
  3509. Writeln('----------------------');
  3510. readsymtableoptions('interface');
  3511. {read the definitions}
  3512. if (verbose and v_defs)<>0 then
  3513. begin
  3514. Writeln;
  3515. Writeln('Interface definitions');
  3516. Writeln('----------------------');
  3517. readdefinitions('interface', CurUnit);
  3518. end
  3519. else
  3520. ppufile.skipuntilentry(ibenddefs);
  3521. {read the symbols}
  3522. if (verbose and v_syms)<>0 then
  3523. begin
  3524. Writeln;
  3525. Writeln('Interface Symbols');
  3526. Writeln('------------------');
  3527. readsymbols('interface',CurUnit);
  3528. end
  3529. else
  3530. ppufile.skipuntilentry(ibendsyms);
  3531. {read the macro symbols}
  3532. if (verbose and v_syms)<>0 then
  3533. begin
  3534. Writeln;
  3535. Writeln('Interface Macro Symbols');
  3536. Writeln('-----------------------');
  3537. end;
  3538. if ppufile.readentry<>ibexportedmacros then
  3539. begin
  3540. WriteError('!! Error in PPU');
  3541. exit;
  3542. end;
  3543. if boolean(ppufile.getbyte) then
  3544. begin
  3545. readsymtableoptions('interface macro');
  3546. {skip the definition section for macros (since they are never used) }
  3547. ppufile.skipuntilentry(ibenddefs);
  3548. {read the macro symbols}
  3549. if (verbose and v_syms)<>0 then
  3550. readsymbols('interface macro')
  3551. else
  3552. ppufile.skipuntilentry(ibendsyms);
  3553. end
  3554. else
  3555. Writeln('(no exported macros)');
  3556. {read the implementation stuff}
  3557. if (verbose and v_implementation)<>0 then
  3558. begin
  3559. Writeln;
  3560. Writeln('Implementation section');
  3561. Writeln('-----------------------');
  3562. readimplementation;
  3563. end
  3564. else
  3565. ppufile.skipuntilentry(ibendimplementation);
  3566. {read the static symtable}
  3567. Writeln;
  3568. Writeln('Implementation symtable');
  3569. Writeln('----------------------');
  3570. readsymtableoptions('implementation');
  3571. if (ppufile.header.common.flags and uf_local_symtable)<>0 then
  3572. begin
  3573. if (verbose and v_defs)<>0 then
  3574. begin
  3575. Writeln;
  3576. Writeln('Static definitions');
  3577. Writeln('----------------------');
  3578. readdefinitions('implementation', nil);
  3579. end
  3580. else
  3581. ppufile.skipuntilentry(ibenddefs);
  3582. {read the symbols}
  3583. if (verbose and v_syms)<>0 then
  3584. begin
  3585. Writeln;
  3586. Writeln('Static Symbols');
  3587. Writeln('------------------');
  3588. readsymbols('implementation');
  3589. end
  3590. else
  3591. ppufile.skipuntilentry(ibendsyms);
  3592. end;
  3593. ReadCreatedObjTypes;
  3594. FreeDerefdata;
  3595. {shutdown ppufile}
  3596. ppufile.closefile;
  3597. ppufile.free;
  3598. Writeln;
  3599. end;
  3600. procedure WriteLogo;
  3601. begin
  3602. writeln(Title+' Version '+version_string);
  3603. writeln(Copyright);
  3604. writeln;
  3605. end;
  3606. procedure help;
  3607. begin
  3608. WriteLogo;
  3609. writeln('usage: ppudump [options] <filename1> <filename2>...');
  3610. writeln;
  3611. writeln('[options] can be:');
  3612. writeln(' -F<format> Set output format to <format>');
  3613. writeln(' t - text format (default)');
  3614. writeln(' j - JSON format');
  3615. writeln(' x - XML format');
  3616. writeln(' -M Exit with ExitCode=2 if more information is available');
  3617. writeln(' -S Skip PPU version check. May lead to reading errors');
  3618. writeln(' -V<verbose> Set verbosity to <verbose>');
  3619. writeln(' H - Show header info');
  3620. writeln(' I - Show interface');
  3621. writeln(' M - Show implementation');
  3622. writeln(' S - Show interface symbols');
  3623. writeln(' D - Show interface definitions');
  3624. writeln(' A - Show all');
  3625. writeln(' -h, -? This helpscreen');
  3626. halt;
  3627. end;
  3628. var
  3629. startpara,
  3630. nrfile,i : longint;
  3631. para : string;
  3632. const
  3633. error_on_more : boolean = false;
  3634. begin
  3635. if paramcount<1 then
  3636. help;
  3637. { turn verbose on by default }
  3638. verbose:=v_all;
  3639. { read options }
  3640. startpara:=1;
  3641. while copy(paramstr(startpara),1,1)='-' do
  3642. begin
  3643. para:=paramstr(startpara);
  3644. case upcase(para[2]) of
  3645. 'F' : begin
  3646. FreeAndNil(pout);
  3647. if Length(para) > 2 then
  3648. case upcase(para[3]) of
  3649. 'T':
  3650. nostdout:=False;
  3651. 'J':
  3652. begin
  3653. nostdout:=True;
  3654. pout:=TPpuJsonOutput.Create(Output);
  3655. end;
  3656. 'X':
  3657. begin
  3658. nostdout:=True;
  3659. pout:=TPpuXmlOutput.Create(Output);
  3660. end;
  3661. else
  3662. begin
  3663. WriteError('Invalid output format: ' + para[3]);
  3664. Halt(1);
  3665. end;
  3666. end;
  3667. end;
  3668. 'M' : error_on_more:=true;
  3669. 'S' : SkipVersionCheck:=True;
  3670. 'V' : begin
  3671. verbose:=0;
  3672. for i:=3 to length(para) do
  3673. case upcase(para[i]) of
  3674. 'H' : verbose:=verbose or v_header;
  3675. 'I' : verbose:=verbose or v_interface;
  3676. 'M' : verbose:=verbose or v_implementation;
  3677. 'D' : verbose:=verbose or v_defs;
  3678. 'S' : verbose:=verbose or v_syms;
  3679. 'A' : verbose:=verbose or v_all;
  3680. end;
  3681. end;
  3682. 'H' : help;
  3683. '?' : help;
  3684. else
  3685. begin
  3686. WriteError('Invalid option: ' + para);
  3687. Halt(1);
  3688. end;
  3689. end;
  3690. inc(startpara);
  3691. end;
  3692. if not nostdout then
  3693. WriteLogo;
  3694. UnitList:=TPpuContainerDef.Create(nil);
  3695. try
  3696. UnitList.ItemsName:='';
  3697. { process files }
  3698. for nrfile:=startpara to paramcount do
  3699. dofile (paramstr(nrfile));
  3700. if not has_errors and (pout <> nil) then
  3701. begin
  3702. pout.Init;
  3703. UnitList.Write(pout);
  3704. pout.Done;
  3705. end;
  3706. finally
  3707. UnitList.Free;
  3708. pout.Free;
  3709. end;
  3710. if has_errors then
  3711. Halt(1);
  3712. if error_on_more and
  3713. (has_more_infos or has_warnings) then
  3714. Halt(2);
  3715. end.