ppudump.pp 116 KB

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