ppudump.pp 100 KB

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