ppudump.pp 111 KB

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