ppudump.pp 50 KB

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