ppudump.pp 108 KB

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