ppudump.pp 112 KB

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