ppudump.pp 113 KB

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