ppudump.pp 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820
  1. {
  2. $Id$
  3. Copyright (c) 1998-2000 by the FPC Development Team
  4. Dumps the contents of a FPC unit file (PPU File)
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************}
  17. {$ifdef TP}
  18. {$N+,E+}
  19. {$endif}
  20. program pppdump;
  21. uses
  22. {$ifdef go32v2}
  23. dpmiexcp,
  24. {$endif go32v2}
  25. ppu, cpubase;
  26. const
  27. Version = 'Version 1.10';
  28. Title = 'PPU-Analyser';
  29. Copyright = 'Copyright (c) 1998-2002 by the Free Pascal Development Team';
  30. { verbosity }
  31. v_none = $0;
  32. v_header = $1;
  33. v_defs = $2;
  34. v_syms = $4;
  35. v_interface = $8;
  36. v_implementation = $10;
  37. v_browser = $20;
  38. v_all = $ff;
  39. var
  40. ppufile : tppufile;
  41. space : string;
  42. read_member : boolean;
  43. unitindex : longint;
  44. verbose : longint;
  45. {****************************************************************************
  46. Helper Routines
  47. ****************************************************************************}
  48. const has_errors : boolean = false;
  49. Procedure Error(const S : string);
  50. Begin
  51. Writeln(S);
  52. has_errors:=true;
  53. End;
  54. Function Target2Str(w:longint):string;
  55. type
  56. { taken from systems.pas }
  57. ttarget =
  58. (
  59. target_none, { 0 }
  60. target_i386_GO32V1, { 1 }
  61. target_i386_GO32V2, { 2 }
  62. target_i386_linux, { 3 }
  63. target_i386_OS2, { 4 }
  64. target_i386_Win32, { 5 }
  65. target_i386_freebsd, { 6 }
  66. target_m68k_Amiga, { 7 }
  67. target_m68k_Atari, { 8 }
  68. target_m68k_Mac, { 9 }
  69. target_m68k_linux, { 10 }
  70. target_m68k_PalmOS, { 11 }
  71. target_alpha_linux, { 12 }
  72. target_powerpc_linux, { 13 }
  73. target_powerpc_macos, { 14 }
  74. target_i386_sunos, { 15 }
  75. target_i386_beos, { 16 }
  76. target_i386_netbsd, { 17 }
  77. target_m68k_netbsd, { 18 }
  78. target_i386_Netware, { 19 }
  79. target_i386_qnx, { 20 }
  80. target_i386_wdosx, { 21 }
  81. target_sparc_sunos, { 22 }
  82. target_sparc_linux { 23 }
  83. );
  84. const
  85. Targets : array[ttarget] of string[16]=(
  86. { 0 } 'none',
  87. { 1 } 'GO32V1',
  88. { 2 } 'GO32V2',
  89. { 3 } 'Linux-i386',
  90. { 4 } 'OS/2',
  91. { 5 } 'Win32',
  92. { 6 } 'FreeBSD-i386',
  93. { 7 } 'Amiga',
  94. { 8 } 'Atari',
  95. { 9 } 'MacOS-m68k',
  96. { 10 } 'Linux-m68k',
  97. { 11 } 'PalmOS-m68k',
  98. { 12 } 'Linux-alpha',
  99. { 13 } 'Linux-ppc',
  100. { 14 } 'MacOS-ppc',
  101. { 15 } 'Solaris-i386',
  102. { 16 } 'BeOS-i386',
  103. { 17 } 'NetBSD-i386',
  104. { 18 } 'NetBSD-m68k',
  105. { 19 } 'Netware',
  106. { 20 } 'Qnx-i386',
  107. { 21 } 'WDOSX-i386',
  108. { 22 } 'Solaris-sparc',
  109. { 23 } 'Linux-sparc'
  110. );
  111. begin
  112. if w<=ord(high(ttarget)) then
  113. Target2Str:=Targets[ttarget(w)]
  114. else
  115. Target2Str:='<Unknown>';
  116. end;
  117. Function Cpu2Str(w:longint):string;
  118. type
  119. { Copied from systems.pas }
  120. ttargetcpu=
  121. (
  122. no_cpu, { 0 }
  123. i386, { 1 }
  124. m68k, { 2 }
  125. alpha, { 3 }
  126. powerpc, { 4 }
  127. sparc, { 5 }
  128. vm { 6 }
  129. );
  130. const
  131. CpuTxt : array[ttargetcpu] of string[7]=
  132. ('none','i386','m68k','alpha','powerpc','sparc','vis');
  133. begin
  134. if w<=ord(high(ttargetcpu)) then
  135. Cpu2Str:=CpuTxt[ttargetcpu(w)]
  136. else
  137. Cpu2Str:='<Unknown>';
  138. end;
  139. function PPUFlags2Str(flags:longint):string;
  140. type
  141. tflagopt=record
  142. mask : longint;
  143. str : string[30];
  144. end;
  145. const
  146. flagopts=15;
  147. flagopt : array[1..flagopts] of tflagopt=(
  148. (mask: $1 ;str:'init'),
  149. (mask: $2 ;str:'final'),
  150. (mask: $4 ;str:'big_endian'),
  151. (mask: $8 ;str:'dbx'),
  152. (mask: $10 ;str:'browser'),
  153. (mask: $20 ;str:'in_library'),
  154. (mask: $40 ;str:'smart_linked'),
  155. (mask: $80 ;str:'static_linked'),
  156. (mask: $100 ;str:'shared_linked'),
  157. (mask: $200 ;str:'local_browser'),
  158. (mask: $400 ;str:'no_link'),
  159. (mask: $800 ;str:'has_resources'),
  160. (mask: $1000 ;str:'little_endian'),
  161. (mask: $2000 ;str:'release'),
  162. (mask: $4000 ;str:'local_threadvars')
  163. );
  164. var
  165. i : longint;
  166. first : boolean;
  167. s : string;
  168. begin
  169. s:='';
  170. if flags<>0 then
  171. begin
  172. first:=true;
  173. for i:=1to flagopts do
  174. if (flags and flagopt[i].mask)<>0 then
  175. begin
  176. if first then
  177. first:=false
  178. else
  179. s:=s+', ';
  180. s:=s+flagopt[i].str;
  181. end;
  182. end
  183. else
  184. s:='none';
  185. PPUFlags2Str:=s;
  186. end;
  187. const
  188. HexTbl : array[0..15] of char='0123456789ABCDEF';
  189. function HexB(b:byte):string;
  190. begin
  191. HexB[0]:=#2;
  192. HexB[1]:=HexTbl[b shr 4];
  193. HexB[2]:=HexTbl[b and $f];
  194. end;
  195. function hexstr(val : cardinal;cnt : byte) : string;
  196. const
  197. HexTbl : array[0..15] of char='0123456789ABCDEF';
  198. var
  199. i : longint;
  200. begin
  201. hexstr[0]:=char(cnt);
  202. for i:=cnt downto 1 do
  203. begin
  204. hexstr[i]:=hextbl[val and $f];
  205. val:=val shr 4;
  206. end;
  207. end;
  208. {****************************************************************************
  209. Read Routines
  210. ****************************************************************************}
  211. function getint64:int64;
  212. var
  213. l1,l2 : longint;
  214. begin
  215. l1:=ppufile.getlongint;
  216. l2:=ppufile.getlongint;
  217. getint64:=(int64(l2) shl 32) or l1;
  218. end;
  219. Procedure ReadLinkContainer(const prefix:string);
  220. {
  221. Read a serie of strings and write to the screen starting every line
  222. with prefix
  223. }
  224. function maskstr(m:longint):string;
  225. const
  226. { link options }
  227. link_none = $0;
  228. link_allways = $1;
  229. link_static = $2;
  230. link_smart = $4;
  231. link_shared = $8;
  232. var
  233. s : string;
  234. begin
  235. s:='';
  236. if (m and link_allways)<>0 then
  237. s:=s+'always ';
  238. if (m and link_static)<>0 then
  239. s:=s+'static ';
  240. if (m and link_smart)<>0 then
  241. s:=s+'smart ';
  242. if (m and link_shared)<>0 then
  243. s:=s+'shared ';
  244. maskstr:=s;
  245. end;
  246. var
  247. s : string;
  248. m : longint;
  249. begin
  250. while not ppufile.endofentry do
  251. begin
  252. s:=ppufile.getstring;
  253. m:=ppufile.getlongint;
  254. WriteLn(prefix,s,' (',maskstr(m),')');
  255. end;
  256. end;
  257. Procedure ReadContainer(const prefix:string);
  258. {
  259. Read a serie of strings and write to the screen starting every line
  260. with prefix
  261. }
  262. begin
  263. while not ppufile.endofentry do
  264. WriteLn(prefix,ppufile.getstring);
  265. end;
  266. Procedure ReadRef;
  267. begin
  268. if (verbose and v_browser)=0 then
  269. exit;
  270. while (not ppufile.endofentry) and (not ppufile.error) do
  271. Writeln(space,' - Refered : ',ppufile.getword,', (',ppufile.getlongint,',',ppufile.getword,')');
  272. end;
  273. Procedure ReadPosInfo;
  274. begin
  275. Writeln(ppufile.getword,' (',ppufile.getlongint,',',ppufile.getword,')');
  276. end;
  277. function readderef(const s:string;skipnil:boolean):boolean;
  278. type
  279. tdereftype = (derefnil,derefaktrecordindex,derefaktstaticindex,
  280. derefunit,derefrecord,derefindex,
  281. dereflocal,derefpara,derefaktlocalindex);
  282. var
  283. b : tdereftype;
  284. begin
  285. readderef:=true;
  286. repeat
  287. b:=tdereftype(ppufile.getbyte);
  288. case b of
  289. derefnil :
  290. begin
  291. if not skipnil then
  292. writeln('nil');
  293. readderef:=false;
  294. break;
  295. end;
  296. derefaktrecordindex :
  297. begin
  298. writeln('AktRecord ',s,' ',ppufile.getword);
  299. break;
  300. end;
  301. derefaktstaticindex :
  302. begin
  303. writeln('AktStatic ',s,' ',ppufile.getword);
  304. break;
  305. end;
  306. derefaktlocalindex :
  307. begin
  308. writeln('AktLocal ',s,' ',ppufile.getword);
  309. break;
  310. end;
  311. derefunit :
  312. begin
  313. writeln('Unit ',ppufile.getword);
  314. break;
  315. end;
  316. derefrecord :
  317. begin
  318. write('RecordDef ',ppufile.getword,', ');
  319. end;
  320. derefpara :
  321. begin
  322. write('Parameter of procdef ',ppufile.getword,', ');
  323. end;
  324. dereflocal :
  325. begin
  326. write('Local of procdef ',ppufile.getword,', ');
  327. end;
  328. derefindex :
  329. begin
  330. write(s,' ',ppufile.getword,', ');
  331. end;
  332. else
  333. begin
  334. writeln('!! unsupported dereftyp: ',ord(b));
  335. break;
  336. end;
  337. end;
  338. until false;
  339. end;
  340. function readdefref:boolean;
  341. begin
  342. readdefref:=readderef('Definition',false);
  343. end;
  344. function readsymref:boolean;
  345. begin
  346. readsymref:=readderef('Symbol',false);
  347. end;
  348. procedure readtype;
  349. var
  350. b1,b2 : boolean;
  351. begin
  352. b1:=readderef('Definition',true);
  353. b2:=readderef('Symbol',true);
  354. if not(b1 or b2) then
  355. Writeln('nil')
  356. else
  357. if (b1 and b2) then
  358. Writeln('!! Type has both definition and symbol stored');
  359. end;
  360. procedure readsymlist(const s:string);
  361. type
  362. tsltype = (sl_none,
  363. sl_load,
  364. sl_call,
  365. sl_subscript,
  366. sl_vec
  367. );
  368. const
  369. slstr : array[tsltype] of string[9] = ('',
  370. 'load',
  371. 'call',
  372. 'subscript',
  373. 'vec'
  374. );
  375. var
  376. sl : tsltype;
  377. begin
  378. readdefref;
  379. repeat
  380. sl:=tsltype(ppufile.getbyte);
  381. if sl=sl_none then
  382. break;
  383. write(s,'(',slstr[sl],') ');
  384. case sl of
  385. sl_call,
  386. sl_load,
  387. sl_subscript :
  388. readsymref;
  389. sl_vec :
  390. writeln(ppufile.getlongint);
  391. end;
  392. until false;
  393. end;
  394. { Read abstract procdef and return if inline procdef }
  395. type
  396. tproccalloption=(pocall_none,
  397. pocall_cdecl, { procedure uses C styled calling }
  398. pocall_cppdecl, { C++ calling conventions }
  399. pocall_compilerproc, { Procedure is used for internal compiler calls }
  400. pocall_far16, { Far16 for OS/2 }
  401. pocall_fpccall, { FPC default calling }
  402. pocall_inline, { Procedure is an assembler macro }
  403. pocall_internconst, { procedure has constant evaluator intern }
  404. pocall_internproc, { Procedure has compiler magic}
  405. pocall_palmossyscall, { procedure is a PalmOS system call }
  406. pocall_pascal, { pascal standard left to right }
  407. pocall_register, { procedure uses register (fastcall) calling }
  408. pocall_safecall, { safe call calling conventions }
  409. pocall_stdcall, { procedure uses stdcall call }
  410. pocall_system { system call }
  411. );
  412. tproccalloptions=set of tproccalloption;
  413. tproctypeoption=(potype_none,
  414. potype_proginit, { Program initialization }
  415. potype_unitinit, { unit initialization }
  416. potype_unitfinalize, { unit finalization }
  417. potype_constructor, { Procedure is a constructor }
  418. potype_destructor, { Procedure is a destructor }
  419. potype_operator { Procedure defines an operator }
  420. );
  421. tproctypeoptions=set of tproctypeoption;
  422. tprocoption=(po_none,
  423. po_classmethod, { class method }
  424. po_virtualmethod, { Procedure is a virtual method }
  425. po_abstractmethod, { Procedure is an abstract method }
  426. po_staticmethod, { static method }
  427. po_overridingmethod, { method with override directive }
  428. po_methodpointer, { method pointer, only in procvardef, also used for 'with object do' }
  429. po_containsself, { self is passed explicit to the compiler }
  430. po_interrupt, { Procedure is an interrupt handler }
  431. po_iocheck, { IO checking should be done after a call to the procedure }
  432. po_assembler, { Procedure is written in assembler }
  433. po_msgstr, { method for string message handling }
  434. po_msgint, { method for int message handling }
  435. po_exports, { Procedure has export directive (needed for OS/2) }
  436. po_external, { Procedure is external (in other object or lib)}
  437. po_savestdregs, { save std regs cdecl and stdcall need that ! }
  438. po_saveregisters, { save all registers }
  439. po_overload, { procedure is declared with overload directive }
  440. po_varargs { printf like arguments }
  441. );
  442. tprocoptions=set of tprocoption;
  443. function read_abstract_proc_def:tproccalloption;
  444. type
  445. tproccallopt=record
  446. mask : tproccalloption;
  447. str : string[30];
  448. end;
  449. tproctypeopt=record
  450. mask : tproctypeoption;
  451. str : string[30];
  452. end;
  453. tprocopt=record
  454. mask : tprocoption;
  455. str : string[30];
  456. end;
  457. const
  458. proccalloptionStr : array[tproccalloption] of string[14]=('',
  459. 'CDecl',
  460. 'CPPDecl',
  461. 'CompilerProc',
  462. 'Far16',
  463. 'FPCCall',
  464. 'Inline',
  465. 'InternConst',
  466. 'InternProc',
  467. 'PalmOSSysCall',
  468. 'Pascal',
  469. 'Register',
  470. 'SafeCall',
  471. 'StdCall',
  472. 'System'
  473. );
  474. proctypeopts=6;
  475. proctypeopt : array[1..proctypeopts] of tproctypeopt=(
  476. (mask:potype_proginit; str:'ProgInit'),
  477. (mask:potype_unitinit; str:'UnitInit'),
  478. (mask:potype_unitfinalize;str:'UnitFinalize'),
  479. (mask:potype_constructor; str:'Constructor'),
  480. (mask:potype_destructor; str:'Destructor'),
  481. (mask:potype_operator; str:'Operator')
  482. );
  483. procopts=18;
  484. procopt : array[1..procopts] of tprocopt=(
  485. (mask:po_classmethod; str:'ClassMethod'),
  486. (mask:po_virtualmethod; str:'VirtualMethod'),
  487. (mask:po_abstractmethod; str:'AbstractMethod'),
  488. (mask:po_staticmethod; str:'StaticMethod'),
  489. (mask:po_overridingmethod;str:'OverridingMethod'),
  490. (mask:po_methodpointer; str:'MethodPointer'),
  491. (mask:po_containsself; str:'ContainsSelf'),
  492. (mask:po_interrupt; str:'Interrupt'),
  493. (mask:po_iocheck; str:'IOCheck'),
  494. (mask:po_assembler; str:'Assembler'),
  495. (mask:po_msgstr; str:'MsgStr'),
  496. (mask:po_msgint; str:'MsgInt'),
  497. (mask:po_exports; str:'Exports'),
  498. (mask:po_external; str:'External'),
  499. (mask:po_savestdregs; str:'SaveStdRegs'),
  500. (mask:po_saveregisters; str:'SaveRegisters'),
  501. (mask:po_overload; str:'Overload'),
  502. (mask:po_varargs; str:'VarArgs')
  503. );
  504. tvarspez : array[0..3] of string[5]=('Value','Const','Var ','Out ');
  505. var
  506. proctypeoption : tproctypeoption;
  507. proccalloption : tproccalloption;
  508. procoptions : tprocoptions;
  509. i,params : longint;
  510. first : boolean;
  511. begin
  512. write(space,' Return type : ');
  513. readtype;
  514. writeln(space,' Fpu used : ',ppufile.getbyte);
  515. proctypeoption:=tproctypeoption(ppufile.getbyte);
  516. if proctypeoption<>potype_none then
  517. begin
  518. write(space,' TypeOption : ');
  519. first:=true;
  520. for i:=1to proctypeopts do
  521. if (proctypeopt[i].mask=proctypeoption) then
  522. begin
  523. if first then
  524. first:=false
  525. else
  526. write(', ');
  527. write(proctypeopt[i].str);
  528. end;
  529. writeln;
  530. end;
  531. proccalloption:=tproccalloption(ppufile.getbyte);
  532. read_abstract_proc_def:=proccalloption;
  533. writeln(space,' CallOption : ',proccalloptionStr[proccalloption]);
  534. ppufile.getsmallset(procoptions);
  535. if procoptions<>[] then
  536. begin
  537. write(space,' Options : ');
  538. first:=true;
  539. for i:=1to procopts do
  540. if (procopt[i].mask in procoptions) then
  541. begin
  542. if first then
  543. first:=false
  544. else
  545. write(', ');
  546. write(procopt[i].str);
  547. end;
  548. writeln;
  549. end;
  550. params:=ppufile.getword;
  551. writeln(space,' Nr of parameters : ',params);
  552. if params>0 then
  553. begin
  554. repeat
  555. write(space,' - ',tvarspez[ppufile.getbyte],' : ');
  556. readtype;
  557. write(space,' Default : ');
  558. readsymref;
  559. write(space,' Symbol : ');
  560. readsymref;
  561. dec(params);
  562. until params=0;
  563. end;
  564. end;
  565. procedure readcommonsym(const s:string);
  566. type
  567. tsymoption=(sp_none,
  568. sp_public,
  569. sp_private,
  570. sp_published,
  571. sp_protected,
  572. sp_forwarddef,
  573. sp_static,
  574. sp_primary_typesym { this is for typesym, to know who is the primary symbol of a def }
  575. );
  576. tsymoptions=set of tsymoption;
  577. tsymopt=record
  578. mask : tsymoption;
  579. str : string[30];
  580. end;
  581. const
  582. symopts=7;
  583. symopt : array[1..symopts] of tsymopt=(
  584. (mask:sp_public; str:'Public'),
  585. (mask:sp_private; str:'Private'),
  586. (mask:sp_published; str:'Published'),
  587. (mask:sp_protected; str:'Protected'),
  588. (mask:sp_forwarddef; str:'ForwardDef'),
  589. (mask:sp_static; str:'Static'),
  590. (mask:sp_primary_typesym;str:'PrimaryTypeSym')
  591. );
  592. var
  593. symoptions : tsymoptions;
  594. i : longint;
  595. first : boolean;
  596. begin
  597. writeln(space,'** Symbol Nr. ',ppufile.getword,' **');
  598. writeln(space,s,ppufile.getstring);
  599. ppufile.getsmallset(symoptions);
  600. if symoptions<>[] then
  601. begin
  602. write(space,' File Pos: ');
  603. readposinfo;
  604. write(space,' SymOptions: ');
  605. first:=true;
  606. for i:=1to symopts do
  607. if (symopt[i].mask in symoptions) then
  608. begin
  609. if first then
  610. first:=false
  611. else
  612. write(', ');
  613. write(symopt[i].str);
  614. end;
  615. writeln;
  616. end;
  617. end;
  618. procedure readcommondef(const s:string);
  619. type
  620. tdefoption=(df_none,
  621. df_has_inittable, { init data has been generated }
  622. df_has_rttitable { rtti data has been generated }
  623. );
  624. tdefoptions=set of tdefoption;
  625. var
  626. defopts : tdefoptions;
  627. begin
  628. writeln(space,'** Definition Nr. ',ppufile.getword,' **');
  629. writeln(space,s);
  630. write (space,' Type symbol : ');
  631. readsymref;
  632. ppufile.getsmallset(defopts);
  633. if df_has_rttitable in defopts then
  634. begin
  635. write (space,' RTTI symbol : ');
  636. readsymref;
  637. end;
  638. if df_has_inittable in defopts then
  639. begin
  640. write (space,' Init symbol : ');
  641. readsymref;
  642. end;
  643. end;
  644. {****************************************************************************
  645. Read Symbols Part
  646. ****************************************************************************}
  647. procedure readsymbols;
  648. Const
  649. vo_is_C_var = 2;
  650. Type
  651. absolutetyp = (tovar,toasm,toaddr);
  652. tconsttyp = (constnone,
  653. constord,conststring,constreal,constbool,
  654. constint,constchar,constset,constpointer,constnil,
  655. constresourcestring
  656. );
  657. var
  658. b : byte;
  659. pc : pchar;
  660. totalsyms,
  661. symcnt,
  662. i,j,len : longint;
  663. begin
  664. symcnt:=1;
  665. with ppufile do
  666. begin
  667. if space<>'' then
  668. Writeln(space,'-----------------------------');
  669. if readentry=ibstartsyms then
  670. begin
  671. totalsyms:=getlongint;
  672. Writeln(space,'Number of symbols : ',totalsyms);
  673. Writeln(space,'Symtable datasize : ',getlongint);
  674. Writeln(space,'Symtable alignment: ',getlongint);
  675. end
  676. else
  677. begin
  678. totalsyms:=-1;
  679. Writeln('!! ibstartsym not found');
  680. end;
  681. repeat
  682. b:=readentry;
  683. if not (b in [iberror,ibendsyms]) then
  684. inc(symcnt);
  685. case b of
  686. ibunitsym :
  687. readcommonsym('Unit symbol ');
  688. iblabelsym :
  689. readcommonsym('Label symbol ');
  690. ibtypesym :
  691. begin
  692. readcommonsym('Type symbol ');
  693. write(space,' Result Type: ');
  694. readtype;
  695. end;
  696. ibprocsym :
  697. begin
  698. readcommonsym('Procedure symbol ');
  699. repeat
  700. write(space,' Definition: ');
  701. until not readdefref;
  702. end;
  703. ibconstsym :
  704. begin
  705. readcommonsym('Constant symbol ');
  706. b:=getbyte;
  707. case tconsttyp(b) of
  708. constord :
  709. begin
  710. write (space,'OrdinalType: ');
  711. readtype;
  712. writeln (space,' Value: ',getlongint)
  713. end;
  714. constpointer :
  715. begin
  716. write (space,' Pointer Type: ');
  717. readtype;
  718. writeln (space,' Value: ',getlongint)
  719. end;
  720. conststring,
  721. constresourcestring :
  722. begin
  723. len:=getlongint;
  724. getmem(pc,len+1);
  725. getdata(pc^,len);
  726. writeln(space,' Length: ',len);
  727. writeln(space,' Value: "',pc,'"');
  728. freemem(pc,len+1);
  729. if tconsttyp(b)=constresourcestring then
  730. writeln(space,' Index: ',getlongint);
  731. end;
  732. constreal :
  733. writeln(space,' Value: ',getreal);
  734. constbool :
  735. if getlongint<>0 then
  736. writeln (space,' Value : True')
  737. else
  738. writeln (space,' Value: False');
  739. constint :
  740. writeln(space,' Value: ',getint64);
  741. constchar :
  742. writeln(space,' Value: "'+chr(getlongint)+'"');
  743. constset :
  744. begin
  745. write (space,' Set Type: ');
  746. readtype;
  747. for i:=1to 4 do
  748. begin
  749. write (space,' Value: ');
  750. for j:=1to 8 do
  751. begin
  752. if j>1 then
  753. write(',');
  754. write(hexb(getbyte));
  755. end;
  756. writeln;
  757. end;
  758. end;
  759. else
  760. Writeln ('!! Invalid unit format : Invalid const type encountered: ',b);
  761. end;
  762. end;
  763. ibvarsym :
  764. begin
  765. readcommonsym('Variable symbol ');
  766. writeln(space,' Type: ',getbyte);
  767. if read_member then
  768. writeln(space,' Address: ',getlongint);
  769. write (space,' Var Type: ');
  770. readtype;
  771. i:=getlongint;
  772. writeln(space,' Options: ',i);
  773. if (i and vo_is_C_var)<>0 then
  774. writeln(space,' Mangledname: ',getstring);
  775. end;
  776. ibenumsym :
  777. begin
  778. readcommonsym('Enumeration symbol ');
  779. write (space,' Definition: ');
  780. readdefref;
  781. writeln(space,' Value: ',getlongint);
  782. end;
  783. ibsyssym :
  784. begin
  785. readcommonsym('Internal system symbol ');
  786. writeln(space,' Internal Nr: ',getlongint);
  787. end;
  788. ibrttisym :
  789. begin
  790. readcommonsym('RTTI symbol ');
  791. writeln(space,' RTTI Type: ',getbyte);
  792. end;
  793. ibtypedconstsym :
  794. begin
  795. readcommonsym('Typed constant ');
  796. write (space,' Constant Type: ');
  797. readtype;
  798. writeln(space,' Label: ',getstring);
  799. writeln(space,' ReallyConst: ',(getbyte<>0));
  800. end;
  801. ibabsolutesym :
  802. begin
  803. readcommonsym('Absolute variable symbol ');
  804. writeln(space,' Type: ',getbyte);
  805. if read_member then
  806. writeln(space,' Address: ',getlongint);
  807. write (space,' Var Type: ');
  808. readtype;
  809. writeln(space,' Options: ',getlongint);
  810. Write (space,' Relocated to ');
  811. b:=getbyte;
  812. case absolutetyp(b) of
  813. tovar :
  814. Writeln('Name : ',getstring);
  815. toasm :
  816. Writeln('Assembler name : ',getstring);
  817. toaddr :
  818. begin
  819. Write('Address : ',getlongint);
  820. WriteLn(' (Far: ',getbyte<>0,')');
  821. end;
  822. else
  823. Writeln ('!! Invalid unit format : Invalid absolute type encountered: ',b);
  824. end;
  825. end;
  826. ibpropertysym :
  827. begin
  828. readcommonsym('Property ');
  829. i:=getlongint;
  830. writeln(space,' PropOptions: ',i);
  831. if (i and 32)>0 then
  832. begin
  833. write (space,'OverrideProp: ');
  834. readsymref;
  835. end
  836. else
  837. begin
  838. write (space,' Prop Type: ');
  839. readtype;
  840. writeln(space,' Index: ',getlongint);
  841. writeln(space,' Default: ',getlongint);
  842. write (space,' Index Type: ');
  843. readtype;
  844. write (space,' Readaccess: ');
  845. readsymlist(space+' Sym: ');
  846. write (space,' Writeaccess: ');
  847. readsymlist(space+' Sym: ');
  848. write (space,'Storedaccess: ');
  849. readsymlist(space+' Sym: ');
  850. end;
  851. end;
  852. ibfuncretsym :
  853. begin
  854. readcommonsym('Func return value ');
  855. write (space,' Return Type: ');
  856. readtype;
  857. writeln(space,' Address: ',getlongint);
  858. end;
  859. iberror :
  860. begin
  861. Writeln('!! Error in PPU');
  862. exit;
  863. end;
  864. ibendsyms :
  865. break;
  866. else
  867. WriteLn('!! Skipping unsupported PPU Entry in Symbols: ',b);
  868. end;
  869. if not EndOfEntry then
  870. Writeln('!! Entry has more information stored');
  871. until false;
  872. if (totalsyms<>-1) and (symcnt-1<>totalsyms) then
  873. Writeln('!! Only read ',symcnt-1,' of ',totalsyms,' symbols');
  874. end;
  875. end;
  876. {****************************************************************************
  877. Read defintions Part
  878. ****************************************************************************}
  879. procedure getusedregisters;
  880. var
  881. regs: tregisterset;
  882. r: tregister;
  883. first: boolean;
  884. begin
  885. first := true;
  886. ppufile.getnormalset(regs);
  887. for r := firstsaveintreg to lastsaveintreg do
  888. if r in regs then
  889. begin
  890. if not first then
  891. write(', ')
  892. else
  893. first := false;
  894. write(att_reg2str[r])
  895. end;
  896. if (firstsavefpureg <> R_NO) then
  897. for r := firstsavefpureg to lastsavefpureg do
  898. if r in regs then
  899. begin
  900. if not first then
  901. write(', ')
  902. else
  903. first := false;
  904. write(att_reg2str[r])
  905. end;
  906. if (firstsavemmreg <> R_NO) then
  907. for r := firstsavemmreg to lastsavemmreg do
  908. if r in regs then
  909. begin
  910. if not first then
  911. write(', ')
  912. else
  913. first := false;
  914. write(att_reg2str[r])
  915. end;
  916. writeln;
  917. end;
  918. procedure readdefinitions(start_read : boolean);
  919. type
  920. tsettype = (normset,smallset,varset);
  921. tbasetype = (
  922. uvoid,
  923. u8bit,u16bit,u32bit,u64bit,
  924. s8bit,s16bit,s32bit,s64bit,
  925. bool8bit,bool16bit,bool32bit,
  926. uchar,uwidechar
  927. );
  928. tobjectdeftype = (odt_none,
  929. odt_class,
  930. odt_object,
  931. odt_interfacecom,
  932. odt_interfacecorba,
  933. odt_cppclass
  934. );
  935. var
  936. b : byte;
  937. oldread_member : boolean;
  938. totaldefs,l,j,
  939. defcnt : longint;
  940. calloption : tproccalloption;
  941. begin
  942. defcnt:=0;
  943. with ppufile do
  944. begin
  945. if space<>'' then
  946. Writeln(space,'-----------------------------');
  947. if not start_read then
  948. if readentry=ibstartdefs then
  949. begin
  950. totaldefs:=getlongint;
  951. Writeln(space,'Number of definitions: ',totaldefs);
  952. end
  953. else
  954. begin
  955. totaldefs:=-1;
  956. Writeln('!! ibstartdef not found');
  957. end;
  958. repeat
  959. b:=readentry;
  960. if not (b in [iberror,ibenddefs]) then
  961. inc(defcnt);
  962. case b of
  963. ibpointerdef :
  964. begin
  965. readcommondef('Pointer definition');
  966. write (space,' Pointed Type : ');
  967. readtype;
  968. writeln(space,' Is Far : ',(getbyte<>0));
  969. end;
  970. iborddef :
  971. begin
  972. readcommondef('Ordinal definition');
  973. write (space,' Base type : ');
  974. b:=getbyte;
  975. case tbasetype(b) of
  976. uvoid : writeln('uvoid');
  977. u8bit : writeln('u8bit');
  978. u16bit : writeln('u16bit');
  979. u32bit : writeln('s32bit');
  980. u64bit : writeln('u64bit');
  981. s8bit : writeln('s8bit');
  982. s16bit : writeln('s16bit');
  983. s32bit : writeln('s32bit');
  984. s64bit : writeln('s64bit');
  985. bool8bit : writeln('bool8bit');
  986. bool16bit : writeln('bool16bit');
  987. bool32bit : writeln('bool32bit');
  988. uchar : writeln('uchar');
  989. uwidechar : writeln('uwidechar');
  990. else writeln('!! Warning: Invalid base type ',b);
  991. end;
  992. writeln(space,' Range : ',getint64,' to ',getint64);
  993. end;
  994. ibfloatdef :
  995. begin
  996. readcommondef('Float definition');
  997. writeln(space,' Float type : ',getbyte);
  998. end;
  999. ibarraydef :
  1000. begin
  1001. readcommondef('Array definition');
  1002. write (space,' Element type : ');
  1003. readtype;
  1004. write (space,' Range Type : ');
  1005. readtype;
  1006. writeln(space,' Range : ',getlongint,' to ',getlongint);
  1007. writeln(space,' Is Constructor : ',(getbyte<>0));
  1008. writeln(space,' Is Dynamic : ',(getbyte<>0));
  1009. end;
  1010. ibprocdef :
  1011. begin
  1012. readcommondef('Procedure definition');
  1013. calloption:=read_abstract_proc_def;
  1014. write (space,' Used Registers : ');
  1015. getusedregisters;
  1016. writeln(space,' Mangled name : ',getstring);
  1017. writeln(space,' Number : ',getlongint);
  1018. write (space,' Class : ');
  1019. readdefref;
  1020. write (space,' Procsym : ');
  1021. readsymref;
  1022. write (space,' File Pos : ');
  1023. readposinfo;
  1024. if (calloption=pocall_inline) then
  1025. begin
  1026. write (space,' FuncretSym : ');
  1027. readdefref;
  1028. end;
  1029. space:=' '+space;
  1030. { parast }
  1031. readdefinitions(false);
  1032. readsymbols;
  1033. { localst }
  1034. if (calloption=pocall_inline) or
  1035. ((ppufile.header.flags and uf_local_browser) <> 0) then
  1036. begin
  1037. readdefinitions(false);
  1038. readsymbols;
  1039. end;
  1040. delete(space,1,4);
  1041. end;
  1042. ibprocvardef :
  1043. begin
  1044. readcommondef('Procedural type (ProcVar) definition');
  1045. read_abstract_proc_def;
  1046. end;
  1047. ibshortstringdef :
  1048. begin
  1049. readcommondef('ShortString definition');
  1050. writeln(space,' Length : ',getbyte);
  1051. end;
  1052. ibwidestringdef :
  1053. begin
  1054. readcommondef('WideString definition');
  1055. writeln(space,' Length : ',getlongint);
  1056. end;
  1057. ibansistringdef :
  1058. begin
  1059. readcommondef('AnsiString definition');
  1060. writeln(space,' Length : ',getlongint);
  1061. end;
  1062. iblongstringdef :
  1063. begin
  1064. readcommondef('Longstring definition');
  1065. writeln(space,' Length : ',getlongint);
  1066. end;
  1067. ibrecorddef :
  1068. begin
  1069. readcommondef('Record definition');
  1070. writeln(space,' Size : ',getlongint);
  1071. {read the record definitions and symbols}
  1072. space:=' '+space;
  1073. oldread_member:=read_member;
  1074. read_member:=true;
  1075. readdefinitions(false);
  1076. readsymbols;
  1077. read_member:=oldread_member;
  1078. Delete(space,1,4);
  1079. end;
  1080. ibobjectdef :
  1081. begin
  1082. readcommondef('Object/Class definition');
  1083. b:=getbyte;
  1084. write (space,' Type : ');
  1085. case tobjectdeftype(b) of
  1086. odt_class : writeln('class');
  1087. odt_object : writeln('object');
  1088. odt_interfacecom : writeln('interfacecom');
  1089. odt_interfacecorba : writeln('interfacecorba');
  1090. odt_cppclass : writeln('cppclass');
  1091. else writeln('!! Warning: Invalid object type ',b);
  1092. end;
  1093. writeln(space,' Size : ',getlongint);
  1094. writeln(space,' Vmt offset : ',getlongint);
  1095. writeln(space,' Name of Class : ',getstring);
  1096. write(space, ' Ancestor Class : ');
  1097. readdefref;
  1098. writeln(space,' Options : ',getlongint);
  1099. if tobjectdeftype(b) in [odt_interfacecom,odt_interfacecorba] then
  1100. begin
  1101. writeln(space,' GUID Valid : ',(getbyte<>0));
  1102. { IIDGUID }
  1103. for j:=1to 16 do
  1104. getbyte;
  1105. writeln(space,' IID String : ',getstring);
  1106. writeln(space,' Last VTable idx : ',getlongint);
  1107. end;
  1108. if tobjectdeftype(b) in [odt_class,odt_interfacecorba] then
  1109. begin
  1110. l:=getlongint;
  1111. writeln(space,' Impl Intf Count : ',l);
  1112. for j:=1 to l do
  1113. begin
  1114. write (space,' - Definition : ');
  1115. readdefref;
  1116. writeln(space,' IOffset : ',getlongint);
  1117. end;
  1118. end;
  1119. {read the record definitions and symbols}
  1120. space:=' '+space;
  1121. oldread_member:=read_member;
  1122. read_member:=true;
  1123. readdefinitions(false);
  1124. readsymbols;
  1125. read_member:=oldread_member;
  1126. Delete(space,1,4);
  1127. end;
  1128. ibfiledef :
  1129. begin
  1130. ReadCommonDef('File definition');
  1131. write (space,' Type : ');
  1132. case getbyte of
  1133. 0 : writeln('Text');
  1134. 1 : begin
  1135. writeln('Typed');
  1136. write (space,' File of Type : ');
  1137. Readtype;
  1138. end;
  1139. 2 : writeln('Untyped');
  1140. end;
  1141. end;
  1142. ibformaldef :
  1143. readcommondef('Generic Definition (void-typ)');
  1144. ibenumdef :
  1145. begin
  1146. readcommondef('Enumeration type definition');
  1147. write(space,'Base enumeration type : ');
  1148. readdefref;
  1149. writeln(space,' Smallest element : ',getlongint);
  1150. writeln(space,' Largest element : ',getlongint);
  1151. writeln(space,' Size : ',getlongint);
  1152. end;
  1153. ibclassrefdef :
  1154. begin
  1155. readcommondef('Class reference definition');
  1156. write (space,' Pointed Type : ');
  1157. readtype;
  1158. end;
  1159. ibsetdef :
  1160. begin
  1161. readcommondef('Set definition');
  1162. write (space,' Element type : ');
  1163. readtype;
  1164. b:=getbyte;
  1165. case tsettype(b) of
  1166. smallset : writeln(space,' Set with 32 Elements');
  1167. normset : writeln(space,' Set with 256 Elements');
  1168. varset : writeln(space,' Set with ',getlongint,' Elements');
  1169. else writeln('!! Warning: Invalid set type ',b);
  1170. end;
  1171. end;
  1172. ibvariantdef :
  1173. begin
  1174. readcommondef('Variant definition');
  1175. end;
  1176. iberror :
  1177. begin
  1178. Writeln('!! Error in PPU');
  1179. exit;
  1180. end;
  1181. ibenddefs :
  1182. break;
  1183. else
  1184. WriteLn('!! Skipping unsupported PPU Entry in definitions: ',b);
  1185. end;
  1186. if not EndOfEntry then
  1187. Writeln('!! Entry has more information stored');
  1188. until false;
  1189. if (totaldefs<>-1) and (defcnt<>totaldefs) then
  1190. Writeln('!! Only read ',defcnt,' of ',totaldefs,' definitions');
  1191. end;
  1192. end;
  1193. {****************************************************************************
  1194. Read General Part
  1195. ****************************************************************************}
  1196. procedure readinterface;
  1197. var
  1198. b : byte;
  1199. sourcenumber,
  1200. unitnumber : word;
  1201. ucrc,uintfcrc : longint;
  1202. begin
  1203. with ppufile do
  1204. begin
  1205. repeat
  1206. b:=readentry;
  1207. case b of
  1208. ibmodulename :
  1209. Writeln('Module Name: ',getstring);
  1210. ibsourcefiles :
  1211. begin
  1212. sourcenumber:=1;
  1213. while not EndOfEntry do
  1214. begin
  1215. Writeln('Source file ',sourcenumber,' : ',getstring);
  1216. inc(sourcenumber);
  1217. end;
  1218. end;
  1219. ibusedmacros :
  1220. begin
  1221. while not EndOfEntry do
  1222. begin
  1223. Write('Conditional ',getstring);
  1224. b:=getbyte;
  1225. if boolean(b)=true then
  1226. write(' defined at startup')
  1227. else
  1228. write(' not defined at startup');
  1229. b:=getbyte;
  1230. if boolean(b)=true then
  1231. writeln(' was used')
  1232. else
  1233. writeln;
  1234. end;
  1235. end;
  1236. ibloadunit :
  1237. begin
  1238. unitnumber:=1;
  1239. while not EndOfEntry do
  1240. begin
  1241. write('Uses unit: ',getstring,' (Number: ',unitnumber,')');
  1242. ucrc:=getlongint;
  1243. uintfcrc:=getlongint;
  1244. write(' (Crc: ',hexstr(ucrc,8),', IntfcCrc: ',hexstr(uintfcrc,8),')');
  1245. if getbyte<>0 then
  1246. writeln(' (interface)')
  1247. else
  1248. writeln(' (implementation)');
  1249. inc(unitnumber);
  1250. end;
  1251. end;
  1252. iblinkunitofiles :
  1253. ReadLinkContainer('Link unit object file: ');
  1254. iblinkunitstaticlibs :
  1255. ReadLinkContainer('Link unit static lib: ');
  1256. iblinkunitsharedlibs :
  1257. ReadLinkContainer('Link unit shared lib: ');
  1258. iblinkotherofiles :
  1259. ReadLinkContainer('Link other object file: ');
  1260. iblinkotherstaticlibs :
  1261. ReadLinkContainer('Link other static lib: ');
  1262. iblinkothersharedlibs :
  1263. ReadLinkContainer('Link other shared lib: ');
  1264. iberror :
  1265. begin
  1266. Writeln('Error in PPU');
  1267. exit;
  1268. end;
  1269. ibendinterface :
  1270. break;
  1271. else
  1272. WriteLn('!! Skipping unsupported PPU Entry in General Part: ',b);
  1273. end;
  1274. until false;
  1275. end;
  1276. end;
  1277. {****************************************************************************
  1278. Read Implementation Part
  1279. ****************************************************************************}
  1280. procedure readimplementation;
  1281. var
  1282. b : byte;
  1283. begin
  1284. with ppufile do
  1285. begin
  1286. repeat
  1287. b:=readentry;
  1288. case b of
  1289. iberror :
  1290. begin
  1291. Writeln('Error in PPU');
  1292. exit;
  1293. end;
  1294. ibendimplementation :
  1295. break;
  1296. else
  1297. WriteLn('!! Skipping unsupported PPU Entry in Implementation: ',b);
  1298. end;
  1299. until false;
  1300. end;
  1301. end;
  1302. {****************************************************************************
  1303. Read Browser Part
  1304. ****************************************************************************}
  1305. procedure readbrowser;
  1306. var
  1307. b : byte;
  1308. const indent : string = '';
  1309. begin
  1310. Writeln(indent,'Start of symtable browser');
  1311. indent:=indent+'**';
  1312. with ppufile do
  1313. begin
  1314. repeat
  1315. b:=readentry;
  1316. case b of
  1317. ibbeginsymtablebrowser :
  1318. begin
  1319. { here we must read object and record symtables !! }
  1320. indent:=indent+' ';
  1321. Writeln(indent,'Record/Object symtable');
  1322. readbrowser;
  1323. Indent:=Copy(Indent,1,Length(Indent)-2);
  1324. end;
  1325. ibsymref :
  1326. begin
  1327. readsymref;
  1328. readref;
  1329. end;
  1330. ibdefref :
  1331. begin
  1332. readdefref;
  1333. readref;
  1334. if ((ppufile.header.flags and uf_local_browser)<>0) and
  1335. (UnitIndex=0) then
  1336. begin
  1337. { parast and localst }
  1338. indent:=indent+' ';
  1339. b:=ppufile.readentry;
  1340. if b=ibbeginsymtablebrowser then
  1341. readbrowser;
  1342. b:=ppufile.readentry;
  1343. if b=ibbeginsymtablebrowser then
  1344. readbrowser;
  1345. Indent:=Copy(Indent,1,Length(Indent)-2);
  1346. end;
  1347. end;
  1348. iberror :
  1349. begin
  1350. Writeln('Error in PPU');
  1351. exit;
  1352. end;
  1353. ibendsymtablebrowser :
  1354. break;
  1355. else
  1356. begin
  1357. WriteLn('!! Skipping unsupported PPU Entry in Browser: ',b);
  1358. Halt;
  1359. end;
  1360. end;
  1361. until false;
  1362. end;
  1363. Indent:=Copy(Indent,1,Length(Indent)-2);
  1364. Writeln(Indent,'End of symtable browser');
  1365. end;
  1366. procedure dofile (filename : string);
  1367. var
  1368. b : byte;
  1369. begin
  1370. { reset }
  1371. space:='';
  1372. { fix filename }
  1373. if pos('.',filename)=0 then
  1374. filename:=filename+'.ppu';
  1375. ppufile:=tppufile.create(filename);
  1376. if not ppufile.openfile then
  1377. begin
  1378. writeln ('IO-Error when opening : ',filename,', Skipping');
  1379. exit;
  1380. end;
  1381. { PPU File is open, check for PPU Id }
  1382. if not ppufile.CheckPPUID then
  1383. begin
  1384. writeln(Filename,' : Not a valid PPU file, Skipping');
  1385. exit;
  1386. end;
  1387. { Check PPU Version }
  1388. Writeln('Analyzing ',filename,' (v',ppufile.GetPPUVersion,')');
  1389. if ppufile.GetPPUVersion<16 then
  1390. begin
  1391. writeln(Filename,' : Old PPU Formats (<v16) are not supported, Skipping');
  1392. exit;
  1393. end;
  1394. { Write PPU Header Information }
  1395. if (verbose and v_header)<>0 then
  1396. begin
  1397. Writeln;
  1398. Writeln('Header');
  1399. Writeln('-------');
  1400. with ppufile.header do
  1401. begin
  1402. Writeln('Compiler version : ',hi(ppufile.header.compiler and $ff),'.',lo(ppufile.header.compiler));
  1403. WriteLn('Target processor : ',Cpu2Str(cpu));
  1404. WriteLn('Target operating system : ',Target2Str(target));
  1405. Writeln('Unit flags : ',PPUFlags2Str(flags));
  1406. Writeln('FileSize (w/o header) : ',size);
  1407. Writeln('Checksum : ',hexstr(checksum,8));
  1408. Writeln('Interface Checksum : ',hexstr(interface_checksum,8));
  1409. end;
  1410. end;
  1411. {read the general stuff}
  1412. if (verbose and v_interface)<>0 then
  1413. begin
  1414. Writeln;
  1415. Writeln('Interface section');
  1416. Writeln('------------------');
  1417. readinterface;
  1418. end
  1419. else
  1420. ppufile.skipuntilentry(ibendinterface);
  1421. {read the definitions}
  1422. if (verbose and v_defs)<>0 then
  1423. begin
  1424. Writeln;
  1425. Writeln('Interface definitions');
  1426. Writeln('----------------------');
  1427. readdefinitions(false);
  1428. end
  1429. else
  1430. ppufile.skipuntilentry(ibenddefs);
  1431. {read the symbols}
  1432. if (verbose and v_syms)<>0 then
  1433. begin
  1434. Writeln;
  1435. Writeln('Interface Symbols');
  1436. Writeln('------------------');
  1437. readsymbols;
  1438. end
  1439. else
  1440. ppufile.skipuntilentry(ibendsyms);
  1441. {read the implementation stuff}
  1442. { Not used at the moment (PFV)
  1443. if (verbose and v_implementation)<>0 then
  1444. begin
  1445. Writeln;
  1446. Writeln('Implementation section');
  1447. Writeln('-----------------------');
  1448. readimplementation;
  1449. end
  1450. else}
  1451. ppufile.skipuntilentry(ibendimplementation);
  1452. {read the static browser units stuff}
  1453. if (ppufile.header.flags and uf_local_browser)<>0 then
  1454. begin
  1455. if (verbose and v_defs)<>0 then
  1456. begin
  1457. Writeln;
  1458. Writeln('Static definitions');
  1459. Writeln('----------------------');
  1460. readdefinitions(false);
  1461. end
  1462. else
  1463. ppufile.skipuntilentry(ibenddefs);
  1464. {read the symbols}
  1465. if (verbose and v_syms)<>0 then
  1466. begin
  1467. Writeln;
  1468. Writeln('Static Symbols');
  1469. Writeln('------------------');
  1470. readsymbols;
  1471. end;
  1472. end;
  1473. {read the browser units stuff}
  1474. if (ppufile.header.flags and uf_has_browser)<>0 then
  1475. begin
  1476. if (verbose and v_browser)<>0 then
  1477. begin
  1478. Writeln;
  1479. Writeln('Browser section');
  1480. Writeln('---------------');
  1481. UnitIndex:=0;
  1482. repeat
  1483. b:=ppufile.readentry;
  1484. if b = ibendbrowser then break;
  1485. if b=ibbeginsymtablebrowser then
  1486. begin
  1487. Writeln('Unit ',UnitIndex);
  1488. readbrowser;
  1489. Inc(UnitIndex);
  1490. end
  1491. else
  1492. Writeln('Wrong end browser entry ',b,' should be ',ibendbrowser);
  1493. until false;
  1494. end;
  1495. end;
  1496. {read the static browser units stuff}
  1497. if (ppufile.header.flags and uf_local_browser)<>0 then
  1498. begin
  1499. if (verbose and v_browser)<>0 then
  1500. begin
  1501. Writeln;
  1502. Writeln('Static browser section');
  1503. Writeln('---------------');
  1504. UnitIndex:=0;
  1505. b:=ppufile.readentry;
  1506. if b=ibbeginsymtablebrowser then
  1507. readbrowser
  1508. else
  1509. Writeln('Wrong end browser entry ',b,' should be ',ibendbrowser);
  1510. end;
  1511. end;
  1512. {shutdown ppufile}
  1513. ppufile.closefile;
  1514. ppufile.free;
  1515. Writeln;
  1516. end;
  1517. procedure help;
  1518. begin
  1519. writeln('usage: ppudump [options] <filename1> <filename2>...');
  1520. writeln;
  1521. writeln('[options] can be:');
  1522. writeln(' -V<verbose> Set verbosity to <verbose>');
  1523. writeln(' H - Show header info');
  1524. writeln(' I - Show interface');
  1525. writeln(' M - Show implementation');
  1526. writeln(' S - Show interface symbols');
  1527. writeln(' D - Show interface definitions');
  1528. writeln(' B - Show browser info');
  1529. writeln(' A - Show all');
  1530. writeln(' -? This helpscreen');
  1531. halt;
  1532. end;
  1533. var
  1534. startpara,
  1535. nrfile,i : longint;
  1536. para : string;
  1537. begin
  1538. writeln(Title+' '+Version);
  1539. writeln(Copyright);
  1540. writeln;
  1541. if paramcount<1 then
  1542. begin
  1543. writeln('usage: dumpppu [options] <filename1> <filename2>...');
  1544. halt(1);
  1545. end;
  1546. { turn verbose on by default }
  1547. verbose:=v_all;
  1548. { read options }
  1549. startpara:=1;
  1550. while copy(paramstr(startpara),1,1)='-' do
  1551. begin
  1552. para:=paramstr(startpara);
  1553. case upcase(para[2]) of
  1554. 'V' : begin
  1555. verbose:=0;
  1556. for i:=3to length(para) do
  1557. case upcase(para[i]) of
  1558. 'H' : verbose:=verbose or v_header;
  1559. 'I' : verbose:=verbose or v_interface;
  1560. 'M' : verbose:=verbose or v_implementation;
  1561. 'D' : verbose:=verbose or v_defs;
  1562. 'S' : verbose:=verbose or v_syms;
  1563. 'B' : verbose:=verbose or v_browser;
  1564. 'A' : verbose:=verbose or v_all;
  1565. end;
  1566. end;
  1567. '?' : help;
  1568. end;
  1569. inc(startpara);
  1570. end;
  1571. { process files }
  1572. for nrfile:=startpara to paramcount do
  1573. dofile (paramstr(nrfile));
  1574. if has_errors then
  1575. Halt(1);
  1576. end.
  1577. {
  1578. $Log$
  1579. Revision 1.18 2002-04-07 10:23:36 carl
  1580. + added vm / sparc targets
  1581. Revision 1.17 2002/04/04 19:06:14 peter
  1582. * removed unused units
  1583. * use tlocation.size in cg.a_*loc*() routines
  1584. Revision 1.16 2002/04/04 18:50:27 carl
  1585. + added wdosx support (patch from Pavel)
  1586. Revision 1.15 2002/03/31 20:26:42 jonas
  1587. + a_loadfpu_* and a_loadmm_* methods in tcg
  1588. * register allocation is now handled by a class and is mostly processor
  1589. independent (+rgobj.pas and i386/rgcpu.pas)
  1590. * temp allocation is now handled by a class (+tgobj.pas, -i386\tgcpu.pas)
  1591. * some small improvements and fixes to the optimizer
  1592. * some register allocation fixes
  1593. * some fpuvaroffset fixes in the unary minus node
  1594. * push/popusedregisters is now called rg.save/restoreusedregisters and
  1595. (for i386) uses temps instead of push/pop's when using -Op3 (that code is
  1596. also better optimizable)
  1597. * fixed and optimized register saving/restoring for new/dispose nodes
  1598. * LOC_FPU locations now also require their "register" field to be set to
  1599. R_ST, not R_ST0 (the latter is used for LOC_CFPUREGISTER locations only)
  1600. - list field removed of the tnode class because it's not used currently
  1601. and can cause hard-to-find bugs
  1602. Revision 1.14 2002/03/28 20:48:52 carl
  1603. - remove go32v1 support
  1604. Revision 1.13 2002/03/28 16:44:59 armin
  1605. + new flag if unit has local threadvars
  1606. Revision 1.12 2002/03/01 14:08:47 peter
  1607. * parasym added
  1608. Revision 1.11 2002/01/06 12:08:16 peter
  1609. * removed uauto from orddef, use new range_to_basetype generating
  1610. the correct ordinal type for a range
  1611. Revision 1.10 2001/12/15 05:28:01 carl
  1612. + Added QNX target
  1613. Revision 1.9 2001/11/02 22:58:12 peter
  1614. * procsym definition rewrite
  1615. Revision 1.8 2001/09/22 04:52:27 carl
  1616. * updated targets
  1617. Revision 1.7 2001/08/30 20:55:02 peter
  1618. * rttisym support
  1619. Revision 1.6 2001/08/19 09:39:29 peter
  1620. * local browser support fixed
  1621. Revision 1.5 2001/06/29 19:42:18 peter
  1622. * new flags added
  1623. Revision 1.4 2001/06/04 11:53:15 peter
  1624. + varargs directive
  1625. Revision 1.3 2001/05/09 14:11:10 jonas
  1626. * range check error fixes from Peter
  1627. Revision 1.2 2001/05/06 14:49:19 peter
  1628. * ppu object to class rewrite
  1629. * move ppu read and write stuff to fppu
  1630. Revision 1.1 2001/04/25 22:40:07 peter
  1631. * compiler dependent utils in utils/ subdir
  1632. Revision 1.5 2001/04/10 21:21:41 peter
  1633. * variantdef support
  1634. * propertysym fixed
  1635. Revision 1.4 2001/04/04 22:42:59 peter
  1636. * updated for new objectdef with interfaces
  1637. Revision 1.3 2000/09/09 19:46:40 peter
  1638. * show dataalignment
  1639. Revision 1.2 2000/08/13 12:58:06 peter
  1640. * updated for ppu additions
  1641. Revision 1.1 2000/07/13 10:16:22 michael
  1642. + Initial import
  1643. Revision 1.15 2000/07/04 19:05:54 peter
  1644. * be optimistic: version 1.00 for some utils
  1645. Revision 1.14 2000/02/09 16:44:14 peter
  1646. * log truncated
  1647. Revision 1.13 2000/01/23 16:34:36 peter
  1648. * updated for new aktlocalindex
  1649. Revision 1.12 2000/01/07 16:46:03 daniel
  1650. * copyright 2000
  1651. Revision 1.11 1999/11/30 10:35:37 peter
  1652. * support new readtype
  1653. Revision 1.10 1999/11/08 14:06:45 florian
  1654. + indexref of propertysym is handle too now
  1655. Revision 1.9 1999/08/31 16:07:37 pierre
  1656. + support for writeusedmacros
  1657. Revision 1.8 1999/08/15 10:47:14 peter
  1658. * updates for new options
  1659. Revision 1.7 1999/08/13 21:25:35 peter
  1660. * updated flags
  1661. Revision 1.6 1999/07/27 23:45:29 peter
  1662. * updated for typesym writing
  1663. }