ppudump.pp 156 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015
  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. {$packenum 1}
  20. {$define IN_PPUDUMP}
  21. uses
  22. { do NOT add symconst or globtype to make merging easier }
  23. { do include symconst and globtype now before splitting 2.5 PM 2011-06-15 }
  24. cutils,
  25. SysUtils,
  26. constexp,
  27. symconst,
  28. ppu,
  29. entfile,
  30. systems,
  31. cpuinfo,
  32. globals,
  33. globtype,
  34. widestr,
  35. tokens,
  36. version,
  37. ppuout,
  38. ppujson,
  39. ppuxml;
  40. const
  41. Title = 'PPU-Analyser';
  42. Copyright = 'Copyright (c) 1998-2013 by the Free Pascal Development Team';
  43. { verbosity }
  44. v_none = $0;
  45. v_header = $1;
  46. v_defs = $2;
  47. v_syms = $4;
  48. v_interface = $8;
  49. v_implementation = $10;
  50. // v_browser = $20;
  51. v_all = $ff;
  52. { not needed anymore $i systems.inc }
  53. { List of all supported cpus }
  54. const
  55. CpuTxt : array[tsystemcpu] of string[16]=
  56. (
  57. { 0 } 'none',
  58. { 1 } 'i386',
  59. { 2 } 'm68k',
  60. { 3 } 'alpha (obsolete)',
  61. { 4 } 'powerpc',
  62. { 5 } 'sparc',
  63. { 6 } 'vis (obsolete)',
  64. { 7 } 'ia64 (obsolete)',
  65. { 8 } 'x86_64',
  66. { 9 } 'mipseb',
  67. { 10 } 'arm',
  68. { 11 } 'powerpc64',
  69. { 12 } 'avr',
  70. { 13 } 'mipsel',
  71. { 14 } 'jvm',
  72. { 15 } 'i8086',
  73. { 16 } 'aarch64',
  74. { 17 } 'wasm',
  75. { 18 } 'sparc64',
  76. { 19 } 'riscv32',
  77. { 20 } 'riscv64'
  78. );
  79. CpuHasController : array[tsystemcpu] of boolean =
  80. (
  81. { 0 } false {'none'},
  82. { 1 } false {'i386'},
  83. { 2 } false {'m68k'},
  84. { 3 } false {'alpha (obsolete)'},
  85. { 4 } false {'powerpc'},
  86. { 5 } false {'sparc'},
  87. { 6 } false {'vis (obsolete)'},
  88. { 7 } false {'ia64 (obsolete)'},
  89. { 8 } false {'x86_64'},
  90. { 9 } false {'mipseb'},
  91. { 10 } true {'arm'},
  92. { 11 } false {'powerpc64'},
  93. { 12 } true {'avr'},
  94. { 13 } true {'mipsel'},
  95. { 14 } false {'jvm'},
  96. { 15 } false {'i8086'},
  97. { 16 } false {'aarch64'},
  98. { 17 } false {'wasm'},
  99. { 18 } false {'sparc64'},
  100. { 19 } false {'riscv32'},
  101. { 20 } false {'riscv64'}
  102. );
  103. { List of all supported system-cpu couples }
  104. const
  105. Targets : array[tsystem] of string[26]=(
  106. { 0 } 'none',
  107. { 1 } 'GO32V1 (obsolete)',
  108. { 2 } 'GO32V2',
  109. { 3 } 'Linux-i386',
  110. { 4 } 'OS/2',
  111. { 5 } 'Win32',
  112. { 6 } 'FreeBSD-i386',
  113. { 7 } 'Amiga',
  114. { 8 } 'Atari',
  115. { 9 } 'MacOS-m68k',
  116. { 10 } 'Linux-m68k',
  117. { 11 } 'PalmOS-m68k',
  118. { 12 } 'Linux-alpha (obsolete)',
  119. { 13 } 'Linux-ppc',
  120. { 14 } 'MacOS-ppc',
  121. { 15 } 'Solaris-i386',
  122. { 16 } 'BeOS-i386',
  123. { 17 } 'NetBSD-i386',
  124. { 18 } 'NetBSD-m68k',
  125. { 19 } 'Netware-i386-clib',
  126. { 20 } 'Qnx-i386',
  127. { 21 } 'WDOSX-i386',
  128. { 22 } 'Solaris-sparc',
  129. { 23 } 'Linux-sparc',
  130. { 24 } 'OpenBSD-i386',
  131. { 25 } 'OpenBSD-m68k (obsolete)',
  132. { 26 } 'Linux-x86-64',
  133. { 27 } 'Darwin-ppc',
  134. { 28 } 'OS/2 via EMX',
  135. { 29 } 'NetBSD-powerpc',
  136. { 30 } 'OpenBSD-powerpc',
  137. { 31 } 'Linux-arm',
  138. { 32 } 'Watcom-i386',
  139. { 33 } 'MorphOS-powerpc',
  140. { 34 } 'FreeBSD-x86-64',
  141. { 35 } 'Netware-i386-libc',
  142. { 36 } 'Amiga-PowerPC',
  143. { 37 } 'Win64-x64',
  144. { 38 } 'WinCE-ARM',
  145. { 39 } 'Win64-iA64 (obsolete)',
  146. { 40 } 'WinCE-i386',
  147. { 41 } 'Linux-x64',
  148. { 42 } 'GBA-arm',
  149. { 43 } 'Linux-powerpc64',
  150. { 44 } 'Darwin-i386',
  151. { 45 } 'PalmOS-arm',
  152. { 46 } 'Darwin-powerpc64',
  153. { 47 } 'NDS-arm',
  154. { 48 } 'Embedded-i386',
  155. { 49 } 'Embedded-m68k',
  156. { 50 } 'Embedded-alpha (obsolete)',
  157. { 51 } 'Embedded-powerpc',
  158. { 52 } 'Embedded-sparc',
  159. { 53 } 'Embedded-vm (obsolete)',
  160. { 54 } 'Embedded-iA64 (obsolete)',
  161. { 55 } 'Embedded-x64',
  162. { 56 } 'Embedded-mips',
  163. { 57 } 'Embedded-arm',
  164. { 58 } 'Embedded-powerpc64',
  165. { 59 } 'Symbian-i386',
  166. { 60 } 'Symbian-arm',
  167. { 61 } 'Darwin-x64',
  168. { 62 } 'Embedded-avr',
  169. { 63 } 'Haiku-i386',
  170. { 64 } 'Darwin-ARM',
  171. { 65 } 'Solaris-x86-64',
  172. { 66 } 'Linux-MIPS',
  173. { 67 } 'Linux-MIPSel',
  174. { 68 } 'NativeNT-i386',
  175. { 69 } 'iPhoneSim-i386',
  176. { 70 } 'Wii-powerpc',
  177. { 71 } 'OpenBSD-x86-64',
  178. { 72 } 'NetBSD-x86-64',
  179. { 73 } 'AIX-powerpc',
  180. { 74 } 'AIX-powerpc64',
  181. { 75 } 'Java-JVM',
  182. { 76 } 'Android-JVM',
  183. { 77 } 'Android-arm',
  184. { 78 } 'Android-i386',
  185. { 79 } 'MSDOS-i8086',
  186. { 80 } 'Android-MIPSel',
  187. { 81 } 'Embedded-mipseb',
  188. { 82 } 'Embedded-mipsel',
  189. { 83 } 'AROS-i386',
  190. { 84 } 'AROS-x86-64',
  191. { 85 } 'DragonFly-x86-64',
  192. { 86 } 'Darwin-AArch64',
  193. { 87 } 'iPhoneSim-x86-64',
  194. { 88 } 'Linux-AArch64',
  195. { 89 } 'Win16',
  196. { 90 } 'Embedded-i8086',
  197. { 91 } 'AROS-arm',
  198. { 92 } 'WebAssembly-wasm',
  199. { 93 } 'Linux-sparc64',
  200. { 94 } 'Solaris-sparc64',
  201. { 95 } 'NetBSD-arm',
  202. { 96 } 'Linux-RiscV32',
  203. { 97 } 'Linux-RiscV64',
  204. { 98 } 'Embedded-RiscV32',
  205. { 99 } 'Embedded-RiscV64',
  206. { 100 } 'Android-AArch64',
  207. { 101 } 'Android-x86-64',
  208. { 102 } 'Haiku-x86-64'
  209. );
  210. const
  211. { in widestr, we have the following definition
  212. type
  213. tcompilerwidechar = word;
  214. thus widecharsize seems to always be 2 bytes }
  215. widecharsize : longint = 2;
  216. cpu : tsystemcpu = cpu_no;
  217. { This type is defined in scanner.pas unit }
  218. type
  219. tspecialgenerictoken = (
  220. ST_LOADSETTINGS,
  221. ST_LINE,
  222. ST_COLUMN,
  223. ST_FILEINDEX,
  224. ST_LOADMESSAGES,
  225. ST_INVALID);
  226. type
  227. tcpu_i386 = (
  228. cpu_variant_i386_none,
  229. cpu_variant_386,
  230. cpu_variant_486,
  231. cpu_variant_Pentium,
  232. cpu_variant_Pentium2,
  233. cpu_variant_Pentium3,
  234. cpu_variant_Pentium4,
  235. cpu_variant_PentiumM,
  236. cpu_variant_core_i,
  237. cpu_variant_core_avx,
  238. cpu_variant_core_avx2);
  239. tcpu_m68k = (
  240. cpu_variant_m68k_none,
  241. cpu_variant_MC68000,
  242. cpu_variant_MC68020,
  243. cpu_variant_MC68040,
  244. cpu_variant_MC68060,
  245. cpu_variant_isa_a,
  246. cpu_variant_isa_a_p,
  247. cpu_variant_isa_b,
  248. cpu_variant_isa_c,
  249. cpu_variant_cfv4e
  250. );
  251. tcpu_powerpc = (
  252. cpu_variant_powerpc_none,
  253. cpu_variant_ppc604,
  254. cpu_variant_ppc750,
  255. cpu_variant_ppc7400,
  256. cpu_variant_ppc970
  257. );
  258. tcpu_sparc = (
  259. cpu_variant_sparc_none,
  260. cpu_variant_SPARC_V7,
  261. cpu_variant_SPARC_V8,
  262. cpu_variant_SPARC_V9
  263. );
  264. tcpu_x86_64 = (
  265. cpu_variant_x86_64_none,
  266. cpu_variant_athlon64,
  267. cpu_variant_x86_64_core_i,
  268. cpu_variant_x86_64_core_avx,
  269. cpu_variant_x86_64_core_avx2
  270. );
  271. tcpu_mipseb = (
  272. cpu_variant_mipseb_none,
  273. cpu_variant_mips1,
  274. cpu_variant_mips2,
  275. cpu_variant_mips3,
  276. cpu_variant_mips4,
  277. cpu_variant_mips5,
  278. cpu_variant_mips32,
  279. cpu_variant_mips32r2,
  280. cpu_variant_pic32mx
  281. );
  282. tcpu_arm = (
  283. cpu_variant_arm_none,
  284. cpu_variant_armv3,
  285. cpu_variant_armv4,
  286. cpu_variant_armv4t,
  287. cpu_variant_armv5,
  288. cpu_variant_armv5t,
  289. cpu_variant_armv5te,
  290. cpu_variant_armv5tej,
  291. cpu_variant_armv6,
  292. cpu_variant_armv6k,
  293. cpu_variant_armv6t2,
  294. cpu_variant_armv6z,
  295. cpu_variant_armv6m,
  296. cpu_variant_armv7,
  297. cpu_variant_armv7a,
  298. cpu_variant_armv7r,
  299. cpu_variant_armv7m,
  300. cpu_variant_armv7em
  301. );
  302. tcpu_powerpc64 = (
  303. cpu_variant_powerpc64_none,
  304. cpu_variant_powerpc64_ppc970
  305. );
  306. tcpu_avr = (
  307. cpu_variant_avr_none,
  308. cpu_variant_avr1,
  309. cpu_variant_avr2,
  310. cpu_variant_avr25,
  311. cpu_variant_avr3,
  312. cpu_variant_avr31,
  313. cpu_variant_avr35,
  314. cpu_variant_avr4,
  315. cpu_variant_avr5,
  316. cpu_variant_avr51,
  317. cpu_variant_avr6
  318. );
  319. tcpu_mipsel = tcpu_mipseb;
  320. tcpu_jvm = (
  321. cpu_variant_jvm_none,
  322. { jvm, same as cpu_none }
  323. cpu_variant_jvm,
  324. { jvm byte code to be translated into Dalvik bytecode: more type-
  325. sensitive }
  326. cpu_variant_dalvik
  327. );
  328. tcpu_i8086 = (
  329. cpu_variant_i8086_none,
  330. cpu_variant_8086,
  331. cpu_variant_186,
  332. cpu_variant_286,
  333. cpu_variant_i8086_386,
  334. cpu_variant_i8086_486,
  335. cpu_variant_i8086_Pentium,
  336. cpu_variant_i8086_Pentium2,
  337. cpu_variant_i8086_Pentium3,
  338. cpu_variant_i8086_Pentium4,
  339. cpu_variant_i8086_PentiumM
  340. );
  341. tcpu_aarch64 = (
  342. cpu_variant_aarch64_none,
  343. cpu_variant_armv8
  344. );
  345. tcpu_wasm = (
  346. cpu_variant_wasm_none);
  347. tcpu_sparc64 = (
  348. cpu_variant_sparc64_none,
  349. cpu_variant_SPARC64_V9
  350. );
  351. tcpu_riscv32 = (
  352. cpu_variant_riscv32_none,
  353. cpu_variant_rv32imafd,
  354. cpu_variant_rv32ima,
  355. cpu_variant_rv32im,
  356. cpu_variant_rv32i
  357. );
  358. tcpu_riscv64 = (
  359. cpu_variant_riscv64_none,
  360. cpu_variant_rv64imafdc,
  361. cpu_variant_rv64imafd,
  362. cpu_variant_rv64ima,
  363. cpu_variant_rv64im,
  364. cpu_variant_rv64i
  365. );
  366. tcpu_type = record
  367. case tsystemcpu of
  368. cpu_no: { 0 }
  369. ();
  370. cpu_i386: { 1 }
  371. (cpu_i386 : tcpu_i386;);
  372. cpu_m68k: { 2 }
  373. (cpu_m68k : tcpu_m68k;);
  374. obsolete_cpu_alpha: { 3 }
  375. ();
  376. cpu_powerpc: { 4 }
  377. (cpu_powerpc : tcpu_powerpc;);
  378. cpu_sparc: { 5 }
  379. (cpu_sparc : tcpu_sparc;);
  380. obsolete_cpu_vm: { 6 }
  381. ();
  382. obsolete_cpu_ia64: { 7 }
  383. ();
  384. cpu_x86_64: { 8 }
  385. (cpu_x86_64 : tcpu_x86_64;);
  386. cpu_mipseb: { 9 }
  387. (cpu_mipseb : tcpu_mipseb;);
  388. cpu_arm: { 10 }
  389. (cpu_arm : tcpu_arm;);
  390. cpu_powerpc64: { 11 }
  391. (cpu_powerpc64 : tcpu_powerpc64;);
  392. cpu_avr: { 12 }
  393. (cpu_avr : tcpu_avr;);
  394. cpu_mipsel: { 13 }
  395. (cpu_mipsel : tcpu_mipsel;);
  396. cpu_jvm: { 14 }
  397. (cpu_jvm : tcpu_jvm;);
  398. cpu_i8086: { 15 }
  399. (cpu_i8086 : tcpu_i8086;);
  400. cpu_aarch64: { 16 }
  401. (cpu_aarch64 : tcpu_aarch64;);
  402. cpu_wasm: { 17 }
  403. (cpu_wasm : tcpu_wasm;);
  404. cpu_sparc64: { 18 }
  405. (cpu_sparc64 : tcpu_sparc64;);
  406. cpu_riscv32: { 19 }
  407. (cpu_riscv32 : tcpu_riscv32;);
  408. cpu_riscv64: { 20 }
  409. (cpu_riscv64 : tcpu_riscv64;);
  410. end;
  411. TPpuModuleDef = class(TPpuUnitDef)
  412. ModuleFlags: tmoduleflags;
  413. end;
  414. type
  415. tppudumpfile = class(tppufile)
  416. protected
  417. procedure RaiseAssertion(Code: Longint); override;
  418. end;
  419. var
  420. ppufile : tppudumpfile;
  421. ppuversion : dword;
  422. space : string;
  423. verbose : longint;
  424. derefdata : pbyte;
  425. derefdatalen : longint;
  426. pout: TPpuOutput;
  427. nostdout: boolean;
  428. UnitList: TPpuContainerDef;
  429. CurUnit: TPpuModuleDef;
  430. SkipVersionCheck: boolean;
  431. SymAnsiStr: boolean;
  432. var
  433. { needed during tobjectdef parsing... }
  434. current_defoptions : tdefoptions;
  435. current_objectoptions : tobjectoptions;
  436. current_symtable_options : tsymtableoptions;
  437. {****************************************************************************
  438. Helper Routines
  439. ****************************************************************************}
  440. {****************************************************************************
  441. Routine to read 80-bit reals
  442. ****************************************************************************
  443. }
  444. {$PUSH}
  445. {$WARN 6018 OFF} { Turn off unreachable code warning }
  446. { On platforms with sizeof(ext) <> 10 the code below will cause an unreachable
  447. code warning, which will cause compilation failures with -Sew (KB) }
  448. type
  449. TSplit80bitReal = packed record
  450. case byte of
  451. 0: (bytes: Array[0..9] of byte);
  452. 1: (words: Array[0..4] of word);
  453. 2: (cards: Array[0..1] of cardinal; w: word);
  454. end;
  455. const
  456. maxDigits = 17;
  457. function Real80bitToStr(var e : TSplit80bitReal) : string;
  458. var
  459. Temp : string;
  460. new : TSplit80bitReal;
  461. fraczero, expmaximal, sign, outside_double : boolean;
  462. exp : smallint;
  463. ext : extended;
  464. d : double;
  465. i : longint;
  466. mantval : qword;
  467. begin
  468. if ppufile.change_endian then
  469. begin
  470. for i:=0 to 9 do
  471. new.bytes[i]:=e.bytes[9-i];
  472. e:=new;
  473. end;
  474. if sizeof(ext)=10 then
  475. begin
  476. ext:=pextended(@e)^;
  477. str(ext,result);
  478. exit;
  479. end;
  480. { extended, format (MSB): 1 Sign bit, 15 bit exponent, 64 bit mantissa }
  481. sign := (e.w and $8000) <> 0;
  482. expMaximal := (e.w and $7fff) = 32767;
  483. exp:=(e.w and $7fff) - 16383 - 63;
  484. fraczero := (e.cards[0] = 0) and
  485. ((e.cards[1] and $7fffffff) = 0);
  486. mantval := qword(e.cards[0]) or (qword(e.cards[1]) shl 32);
  487. if expMaximal then
  488. if fraczero then
  489. if sign then
  490. temp := '-Inf'
  491. else temp := '+Inf'
  492. else temp := 'Nan'
  493. else
  494. begin
  495. d:=double(mantval);
  496. if sign then
  497. d:=-d;
  498. outside_double:=false;
  499. Try
  500. if exp > 0 then
  501. begin
  502. for i:=1 to exp do
  503. d:=d *2.0;
  504. end
  505. else if exp < 0 then
  506. begin
  507. for i:=1 to -exp do
  508. d:=d /2.0;
  509. end;
  510. Except
  511. outside_double:=true;
  512. end;
  513. if (mantval<>0) and (d=0.0) then
  514. outside_double:=true;
  515. if outside_double then
  516. Temp:='Extended value outside double bound'
  517. else
  518. system.str(d,temp);
  519. end;
  520. result:=temp;
  521. end;
  522. {$POP}
  523. const has_errors : boolean = false;
  524. has_warnings : boolean = false;
  525. has_more_infos : boolean = false;
  526. procedure SetHasErrors;
  527. begin
  528. has_errors:=true;
  529. end;
  530. Procedure WriteError(const S : string);
  531. Begin
  532. system.Writeln(StdErr, S);
  533. SetHasErrors;
  534. End;
  535. procedure StrAppend(var st : string; const st2 : string);
  536. begin
  537. st:=st+st2;
  538. end;
  539. procedure tppudumpfile.RaiseAssertion(Code: Longint);
  540. begin
  541. WriteError('Internal Error ' + ToStr(Code));
  542. inherited RaiseAssertion(Code);
  543. end;
  544. Procedure WriteWarning(const S : string);
  545. var
  546. ss: string;
  547. Begin
  548. ss:='!! Warning: ' + S;
  549. if nostdout then
  550. system.Writeln(StdErr, ss)
  551. else
  552. system.Writeln(ss);
  553. has_warnings:=true;
  554. End;
  555. procedure Write(const s: string);
  556. begin
  557. if nostdout then exit;
  558. system.write(s);
  559. end;
  560. procedure Write(const params: array of const);
  561. var
  562. i: integer;
  563. { Last vtType define in rtl/inc/objpash.inc }
  564. const
  565. max_vttype = vtUnicodeString;
  566. begin
  567. if nostdout then exit;
  568. for i:=Low(params) to High(params) do
  569. { All vtType in
  570. vtInteger = 0;
  571. vtBoolean = 1;
  572. vtChar = 2;
  573. vtExtended = 3;
  574. vtString = 4;
  575. vtPointer = 5;
  576. vtPChar = 6;
  577. vtObject = 7;
  578. vtClass = 8;
  579. vtWideChar = 9;
  580. vtPWideChar = 10;
  581. vtAnsiString32 = 11; called vtAnsiString in objpas unit
  582. vtCurrency = 12;
  583. vtVariant = 13;
  584. vtInterface = 14;
  585. vtWideString = 15;
  586. vtInt64 = 16;
  587. vtQWord = 17;
  588. vtUnicodeString = 18;
  589. // vtAnsiString16 = 19; not yet used
  590. // vtAnsiString64 = 20; not yet used
  591. }
  592. with TVarRec(params[i]) do
  593. case VType of
  594. vtInteger: system.write(VInteger);
  595. vtBoolean: system.write(VBoolean);
  596. vtChar: system.write(VChar);
  597. vtExtended: system.write(VExtended^);
  598. vtString: system.write(VString^);
  599. vtPointer:
  600. begin
  601. { Not sure the display will be correct
  602. if sizeof pointer is not native }
  603. WriteWarning('Pointer constant');
  604. end;
  605. vtPChar: system.write(VPChar);
  606. vtObject:
  607. begin
  608. { Not sure the display will be correct
  609. if sizeof pointer is not native }
  610. WriteWarning('Object constant');
  611. end;
  612. vtClass:
  613. begin
  614. { Not sure the display will be correct
  615. if sizeof pointer is not native }
  616. WriteWarning('Class constant');
  617. end;
  618. vtWideChar: system.write(VWideChar);
  619. vtPWideChar:
  620. begin
  621. WriteWarning('PWideChar constant');
  622. end;
  623. vtAnsiString: system.write(ansistring(VAnsiString));
  624. vtCurrency : system.write(VCurrency^);
  625. vtVariant :
  626. begin
  627. { Not sure the display will be correct
  628. if sizeof pointer is not native }
  629. WriteWarning('Variant constant');
  630. end;
  631. vtInterface :
  632. begin
  633. { Not sure the display will be correct
  634. if sizeof pointer is not native }
  635. WriteWarning('Interface constant');
  636. end;
  637. vtWideString : system.write(widestring(VWideString));
  638. vtInt64: system.write(VInt64^);
  639. vtQWord: system.write(VQWord^);
  640. vtUnicodeString : system.write(unicodestring(VUnicodeString));
  641. else
  642. begin
  643. system.writeln;
  644. system.writeln('Unsupported var type: ', VType);
  645. Halt(10);
  646. end;
  647. end;
  648. end;
  649. procedure Writeln(const s: string = '');
  650. begin
  651. if nostdout then exit;
  652. system.writeln(s);
  653. end;
  654. procedure Writeln(const params: array of const);
  655. begin
  656. if nostdout then exit;
  657. Write(params);
  658. system.writeln;
  659. end;
  660. Procedure HasMoreInfos;
  661. begin
  662. Writeln('!! Entry has more information stored');
  663. has_more_infos:=true;
  664. end;
  665. function Unknown(const st : string; val :longint) : string;
  666. Begin
  667. Unknown:='<!! Unknown'+st+' value '+tostr(val)+'>';
  668. SetHasErrors;
  669. end;
  670. function ToStr(w:longint):String;
  671. begin
  672. Str(w,ToStr);
  673. end;
  674. Function Target2Str(w:longint):string;
  675. begin
  676. if w<=ord(high(tsystem)) then
  677. Target2Str:=Targets[tsystem(w)]
  678. else
  679. Target2Str:=Unknown('target',w);
  680. end;
  681. Function Cpu2Str(w:longint):string;
  682. begin
  683. if w<=ord(high(tsystemcpu)) then
  684. begin
  685. cpu:=tsystemcpu(w);
  686. Cpu2Str:=CpuTxt[cpu];
  687. end
  688. else
  689. Cpu2Str:=Unknown('cpu',w);
  690. end;
  691. Function Varspez2Str(w:longint):string;
  692. const
  693. { in symconst unit
  694. tvarspez = (vs_value,vs_const,vs_var,vs_out,vs_constref); }
  695. varspezstr : array[tvarspez] of string[8]=('Value','Const','Var','Out','ConstRef','Final');
  696. begin
  697. if w<=ord(high(varspezstr)) then
  698. Varspez2Str:=varspezstr[tvarspez(w)]
  699. else
  700. Varspez2Str:=Unknown('varspez',w);
  701. end;
  702. Function VarRegable2Str(w:longint):string;
  703. { tvarregable type is defined in symconst unit }
  704. const
  705. varregableStr : array[tvarregable] of string[6]=('None','IntReg','FPUReg','MMReg','Addr');
  706. begin
  707. if w<=ord(high(varregablestr)) then
  708. Varregable2Str:=varregablestr[tvarregable(w)]
  709. else
  710. Varregable2Str:=Unknown('regable',w);
  711. end;
  712. Function Visibility2Str(w:longint):string;
  713. const
  714. { tvisibility type is defined in symconst unit }
  715. visibilityName : array[tvisibility] of string[16] = (
  716. 'hidden','strict private','private','strict protected','protected',
  717. 'public','published','<none>'
  718. );
  719. begin
  720. if w<=ord(high(visibilityName)) then
  721. result:=visibilityName[tvisibility(w)]
  722. else
  723. result:=Unknown('visibility',w);
  724. end;
  725. Function IntfEntryType2Str(w:longint):string;
  726. const
  727. { tinterfaceentrytype type is defined in symconst unit }
  728. Name : array[tinterfaceentrytype] of string = (
  729. 'standard','virtual method result','static method result','field value','virtual method class',
  730. 'static method class','field value class'
  731. );
  732. begin
  733. if w<=ord(high(Name)) then
  734. result:=Name[tinterfaceentrytype(w)]
  735. else
  736. result:=Unknown('entry type',w);
  737. end;
  738. function PPUFlags2Str(flags:dword):string;
  739. type
  740. tflagopt=record
  741. mask : dword;
  742. str : string[30];
  743. end;
  744. const
  745. flagopts=8;
  746. flagopt : array[1..flagopts] of tflagopt=(
  747. (mask: $4 ;str:'big_endian'),
  748. // (mask: $10 ;str:'browser'),
  749. (mask: $20 ;str:'in_library'),
  750. (mask: $40 ;str:'smart_linked'),
  751. (mask: $80 ;str:'static_linked'),
  752. (mask: $100 ;str:'shared_linked'),
  753. (mask: $400 ;str:'no_link'),
  754. (mask: $1000 ;str:'little_endian'),
  755. (mask: $8000 ;str:'fpu_emulation_on')
  756. );
  757. var
  758. i : longint;
  759. ntflags : dword;
  760. first : boolean;
  761. s : string;
  762. begin
  763. s:='';
  764. ntflags:=flags;
  765. if flags<>0 then
  766. begin
  767. first:=true;
  768. for i:=1to flagopts do
  769. if (flags and flagopt[i].mask)<>0 then
  770. begin
  771. if first then
  772. first:=false
  773. else
  774. s:=s+', ';
  775. s:=s+flagopt[i].str;
  776. ntflags:=ntflags and (not flagopt[i].mask);
  777. end;
  778. end
  779. else
  780. s:='none';
  781. if ntflags<>0 then
  782. begin
  783. s:=s+' unknown '+hexstr(ntflags,8);
  784. SetHasErrors;
  785. end;
  786. PPUFlags2Str:=s;
  787. end;
  788. Function L0(l:longint):string;
  789. {
  790. return the string of value l, if l<10 then insert a zero, so
  791. the string is always at least 2 chars '01','02',etc
  792. }
  793. var
  794. s : string;
  795. begin
  796. Str(l,s);
  797. if l<10 then
  798. s:='0'+s;
  799. L0:=s;
  800. end;
  801. function filetimestring( t : longint) : string;
  802. {
  803. convert dos datetime t to a string YY/MM/DD HH:MM:SS
  804. }
  805. var
  806. DT : TDateTime;
  807. hsec : word;
  808. Year,Month,Day: Word;
  809. hour,min,sec : word;
  810. begin
  811. if t=-1 then
  812. begin
  813. Result := 'Not Found';
  814. SetHasErrors;
  815. exit;
  816. end;
  817. DT := FileDateToDateTime(t);
  818. DecodeTime(DT,hour,min,sec,hsec);
  819. DecodeDate(DT,year,month,day);
  820. Result := L0(Year)+'/'+L0(Month)+'/'+L0(Day)+' '+L0(Hour)+':'+L0(min)+':'+L0(sec);
  821. end;
  822. {****************************************************************************
  823. Read Routines
  824. ****************************************************************************}
  825. function readsymstr(ppufile: tppufile): ansistring;
  826. begin
  827. if not(mf_symansistr in CurUnit.ModuleFlags) then
  828. result:=ppufile.getstring
  829. else
  830. result:=ppufile.getansistring;
  831. end;
  832. function readmanagementoperatoroptions(const space : string;const name : string):tmanagementoperators;forward;
  833. procedure readrecsymtableoptions;
  834. var
  835. usefieldalignment : shortint;
  836. begin
  837. if ppufile.readentry<>ibrecsymtableoptions then
  838. begin
  839. SetHasErrors;
  840. exit;
  841. end;
  842. writeln([space,' recordalignment: ',shortint(ppufile.getbyte)]);
  843. usefieldalignment:=shortint(ppufile.getbyte);
  844. writeln([space,' usefieldalignment: ',usefieldalignment]);
  845. writeln([space,' recordalignmin: ',shortint(ppufile.getbyte)]);
  846. if (usefieldalignment=C_alignment) then
  847. writeln([space,' fieldalignment: ',shortint(ppufile.getbyte)]);
  848. readmanagementoperatoroptions(space,'Fields have MOPs');
  849. end;
  850. function readsymtableoptions(const s: string) : tsymtableoptions;
  851. type
  852. tsymtblopt=record
  853. mask : tsymtableoption;
  854. str : string[30];
  855. end;
  856. const
  857. symtblopts=ord(high(tsymtableoption)) + 1;
  858. symtblopt : array[1..symtblopts] of tsymtblopt=(
  859. (mask:sto_has_helper; str:'Has helper'),
  860. (mask:sto_has_generic; str:'Has generic'),
  861. (mask:sto_has_operator; str:'Has operator'),
  862. (mask:sto_needs_init_final;str:'Needs init final table'),
  863. (mask:sto_has_non_trivial_init;str:'Has non trivial init')
  864. );
  865. var
  866. options : tsymtableoptions;
  867. first : boolean;
  868. i : integer;
  869. begin
  870. if ppufile.readentry<>ibsymtableoptions then
  871. begin
  872. SetHasErrors;
  873. exit;
  874. end;
  875. ppufile.getsmallset(options);
  876. if space<>'' then
  877. writeln([space,'------ ',s,' ------']);
  878. write([space,'Symtable options: ']);
  879. if options<>[] then
  880. begin
  881. first:=true;
  882. for i:=1 to symtblopts do
  883. if (symtblopt[i].mask in options) then
  884. begin
  885. if first then
  886. first:=false
  887. else
  888. write(', ');
  889. write(symtblopt[i].str);
  890. end;
  891. end
  892. else
  893. write('none');
  894. writeln;
  895. readsymtableoptions:=options;
  896. end;
  897. procedure readdefinitions(const s:string; ParentDef: TPpuContainerDef); forward;
  898. procedure readsymbols(const s:string; ParentDef: TPpuContainerDef = nil); forward;
  899. procedure readsymtable(const s: string; ParentDef: TPpuContainerDef = nil);
  900. var
  901. stored_symtable_options : tsymtableoptions;
  902. begin
  903. stored_symtable_options:=current_symtable_options;
  904. current_symtable_options:=readsymtableoptions(s);
  905. readdefinitions(s, ParentDef);
  906. readsymbols(s, ParentDef);
  907. current_symtable_options:=stored_symtable_options;
  908. end;
  909. procedure readrecordsymtable(const s: string; ParentDef: TPpuContainerDef = nil);
  910. begin
  911. readrecsymtableoptions;
  912. readsymtable(s, ParentDef);
  913. end;
  914. Procedure ReadLinkContainer(const prefix:string);
  915. {
  916. Read a serie of strings and write to the screen starting every line
  917. with prefix
  918. }
  919. function maskstr(m:longint):string;
  920. { link options are in globtype unit
  921. const
  922. link_none = $0;
  923. link_always = $1;
  924. link_static = $2;
  925. link_smart = $4;
  926. link_shared = $8; }
  927. var
  928. s : string;
  929. begin
  930. s:='';
  931. if (m and link_always)<>0 then
  932. s:=s+'always ';
  933. if (m and link_static)<>0 then
  934. s:=s+'static ';
  935. if (m and link_smart)<>0 then
  936. s:=s+'smart ';
  937. if (m and link_shared)<>0 then
  938. s:=s+'shared ';
  939. maskstr:=s;
  940. end;
  941. var
  942. s : string;
  943. m : longint;
  944. begin
  945. while not ppufile.endofentry do
  946. begin
  947. s:=ppufile.getstring;
  948. m:=ppufile.getlongint;
  949. WriteLn([prefix,s,' (',maskstr(m),')']);
  950. end;
  951. end;
  952. Procedure ReadContainer(const prefix:string);
  953. {
  954. Read a series of strings and write to the screen starting every line
  955. with prefix
  956. }
  957. begin
  958. while not ppufile.endofentry do
  959. WriteLn([prefix,ppufile.getstring]);
  960. end;
  961. procedure ReadLoadUnit;
  962. var
  963. ucrc,uintfcrc, indcrc : cardinal;
  964. un: TPpuUnitDef;
  965. begin
  966. while not ppufile.EndOfEntry do
  967. begin
  968. un:=TPpuUnitDef.Create(CurUnit.UsedUnits);
  969. un.Name:=ppufile.getstring;
  970. write(['Uses unit: ',un.Name]);
  971. ucrc:=cardinal(ppufile.getlongint);
  972. uintfcrc:=cardinal(ppufile.getlongint);
  973. indcrc:=cardinal(ppufile.getlongint);
  974. writeln([' (Crc: ',hexstr(ucrc,8),', IntfcCrc: ',hexstr(uintfcrc,8),', IndCrc: ',hexstr(indcrc,8),')']);
  975. un.Crc:=ucrc;
  976. un.IntfCrc:=uintfcrc;
  977. end;
  978. end;
  979. Procedure ReadDerefmap;
  980. var
  981. i,mapsize : longint;
  982. s: string;
  983. begin
  984. mapsize:=ppufile.getlongint;
  985. writeln(['DerefMapsize: ',mapsize]);
  986. SetLength(CurUnit.RefUnits, mapsize);
  987. for i:=0 to mapsize-1 do
  988. begin
  989. s:=ppufile.getstring;
  990. writeln(['DerefMap[',i,'] = ',s]);
  991. CurUnit.RefUnits[i]:=LowerCase(s);
  992. end;
  993. end;
  994. Procedure ReadImportSymbols;
  995. var
  996. extlibname : string;
  997. j,
  998. extsymcnt : longint;
  999. extsymname : string;
  1000. extsymmangledname : string;
  1001. extsymordnr : longint;
  1002. extsymisvar : boolean;
  1003. begin
  1004. while not ppufile.endofentry do
  1005. begin
  1006. extlibname:=ppufile.getstring;
  1007. extsymcnt:=ppufile.getlongint;
  1008. writeln(['External Library: ',extlibname,' (',extsymcnt,' imports)']);
  1009. for j:=0 to extsymcnt-1 do
  1010. begin
  1011. extsymname:=ppufile.getstring;
  1012. extsymmangledname:=ppufile.getstring;
  1013. extsymordnr:=ppufile.getlongint;
  1014. extsymisvar:=ppufile.getbyte<>0;
  1015. writeln([' ',extsymname,' as ',extsymmangledname,
  1016. '(OrdNr: ',extsymordnr,' IsVar: ',extsymisvar,')']);
  1017. end;
  1018. end;
  1019. end;
  1020. Procedure ReadDerefdata;
  1021. begin
  1022. derefdatalen:=ppufile.entrysize;
  1023. if derefdatalen=0 then
  1024. begin
  1025. Writeln(['No Derefdata length=0']);
  1026. derefdata:=nil;
  1027. exit;
  1028. end;
  1029. Writeln(['Derefdata length: ',derefdatalen]);
  1030. derefdata:=allocmem(derefdatalen);
  1031. ppufile.getdata(derefdata^,derefdatalen);
  1032. end;
  1033. Procedure FreeDerefdata;
  1034. begin
  1035. if assigned(derefdata) then
  1036. begin
  1037. FreeMem(derefdata);
  1038. derefdata:=nil;
  1039. derefdatalen:=0;
  1040. end;
  1041. end;
  1042. Procedure ReadWpoFileInfo;
  1043. begin
  1044. Writeln(['Compiled with input whole-program optimisation from ',ppufile.getstring,' ',filetimestring(ppufile.getlongint)]);
  1045. end;
  1046. Procedure ReadAsmSymbols;
  1047. const
  1048. unitasmlisttype: array[tunitasmlisttype] of string[6]=(
  1049. 'PUBLIC',
  1050. 'EXTERN'
  1051. );
  1052. type
  1053. { Copied from aasmbase.pas }
  1054. TAsmsymbind=(
  1055. AB_NONE,AB_EXTERNAL,AB_COMMON,AB_LOCAL,AB_GLOBAL,AB_WEAK_EXTERNAL,
  1056. { global in the current program/library, but not visible outside it }
  1057. AB_PRIVATE_EXTERN,AB_LAZY,AB_IMPORT,
  1058. { a symbol that's internal to the compiler and used as a temp }
  1059. AB_TEMP,
  1060. { a global symbol that points to another global symbol and is only used
  1061. to allow indirect loading in case of packages and indirect imports }
  1062. AB_INDIRECT,AB_EXTERNAL_INDIRECT);
  1063. TAsmsymtype=(
  1064. AT_NONE,AT_FUNCTION,AT_DATA,AT_SECTION,AT_LABEL,
  1065. {
  1066. the address of this code label is taken somewhere in the code
  1067. so it must be taken care of it when creating pic
  1068. }
  1069. AT_ADDR,
  1070. { Label for debug or other non-program information }
  1071. AT_METADATA,
  1072. { label for data that must always be accessed indirectly, because it
  1073. is handled explcitely in the system unit or (e.g. RTTI and threadvar
  1074. tables) -- never seen in an assembler/assembler writer, always
  1075. changed to AT_DATA }
  1076. AT_DATA_FORCEINDIRECT,
  1077. { don't generate an implicit indirect symbol as that might be provided
  1078. by other means (e.g. the typed const builder) to ensure a correct
  1079. section name }
  1080. AT_DATA_NOINDIRECT,
  1081. { Thread-local symbol (ELF targets) }
  1082. AT_TLS,
  1083. { GNU indirect function (ELF targets) }
  1084. AT_GNU_IFUNC
  1085. );
  1086. var
  1087. s,
  1088. bindstr,
  1089. typestr : string;
  1090. i : longint;
  1091. t: tunitasmlisttype;
  1092. begin
  1093. writeln([space,'Assembler Symbols']);
  1094. writeln([space,'-----------------']);
  1095. t:=tunitasmlisttype(ppufile.getbyte);
  1096. if (t>=Low(tunitasmlisttype)) and (t<=High(tunitasmlisttype)) then
  1097. typestr:=unitasmlisttype[t]
  1098. else
  1099. typestr:='UNKNOWN';
  1100. writeln([space,'Type: ',typestr]);
  1101. writeln([space,'Count: ',ppufile.getlongint]);
  1102. i:=0;
  1103. while (not ppufile.endofentry) and (not ppufile.error) do
  1104. begin
  1105. s:=ppufile.getstring;
  1106. case tasmsymbind(ppufile.getbyte) of
  1107. AB_EXTERNAL :
  1108. bindstr:='External';
  1109. AB_COMMON :
  1110. bindstr:='Common';
  1111. AB_LOCAL :
  1112. bindstr:='Local';
  1113. AB_GLOBAL :
  1114. bindstr:='Global';
  1115. AB_WEAK_EXTERNAL :
  1116. bindstr:='Weak external';
  1117. AB_PRIVATE_EXTERN :
  1118. bindstr:='Private extern';
  1119. AB_LAZY :
  1120. bindstr:='Lazy';
  1121. AB_IMPORT :
  1122. bindstr:='Import';
  1123. AB_TEMP :
  1124. bindstr:='Temp';
  1125. AB_INDIRECT :
  1126. bindstr:='Indirect';
  1127. AB_EXTERNAL_INDIRECT :
  1128. bindstr:='Indirect external';
  1129. else
  1130. begin
  1131. bindstr:='<Error !!>';
  1132. SetHasErrors;
  1133. end;
  1134. end;
  1135. case tasmsymtype(ppufile.getbyte) of
  1136. AT_FUNCTION :
  1137. typestr:='Function';
  1138. AT_DATA :
  1139. typestr:='Data';
  1140. AT_SECTION :
  1141. typestr:='Section';
  1142. AT_LABEL :
  1143. typestr:='Label';
  1144. AT_ADDR :
  1145. typestr:='Label (with address taken)';
  1146. AT_METADATA :
  1147. typestr:='Metadata';
  1148. { this shouldn't appear in a PPU }
  1149. AT_DATA_FORCEINDIRECT :
  1150. typestr:='Data (ForceIndirect)';
  1151. { this shouldn't appear in a PPU }
  1152. AT_DATA_NOINDIRECT:
  1153. typestr:='Data (NoIndirect)';
  1154. AT_TLS :
  1155. typestr:='TLS';
  1156. AT_GNU_IFUNC :
  1157. typestr:='GNU IFUNC';
  1158. else
  1159. begin
  1160. typestr:='<Error !!>';
  1161. SetHasErrors;
  1162. end;
  1163. end;
  1164. Writeln([space,' ',i,' : ',s,' [',bindstr,',',typestr,']']);
  1165. inc(i);
  1166. end;
  1167. writeln([space]);
  1168. end;
  1169. function getexprint:Tconstexprint;
  1170. begin
  1171. getexprint.overflow:=false;
  1172. getexprint.signed:=ppufile.getboolean;
  1173. getexprint.svalue:=ppufile.getint64;
  1174. end;
  1175. Procedure ReadPosInfo(Def: TPpuDef = nil);
  1176. var
  1177. info : byte;
  1178. fileindex,line,column : longint;
  1179. begin
  1180. with ppufile do
  1181. begin
  1182. fileindex:=0;
  1183. line:=0;
  1184. column:=0;
  1185. {
  1186. info byte layout in bits:
  1187. 0-1 - amount of bytes for fileindex
  1188. 2-3 - amount of bytes for line
  1189. 4-5 - amount of bytes for column
  1190. }
  1191. info:=getbyte;
  1192. case (info and $03) of
  1193. 0 : fileindex:=getbyte;
  1194. 1 : fileindex:=getword;
  1195. 2 : fileindex:=(getbyte shl 16) or getword;
  1196. 3 : fileindex:=getlongint;
  1197. end;
  1198. case ((info shr 2) and $03) of
  1199. 0 : line:=getbyte;
  1200. 1 : line:=getword;
  1201. 2 : line:=(getbyte shl 16) or getword;
  1202. 3 : line:=getlongint;
  1203. end;
  1204. case ((info shr 4) and $03) of
  1205. 0 : column:=getbyte;
  1206. 1 : column:=getword;
  1207. 2 : column:=(getbyte shl 16) or getword;
  1208. 3 : column:=getlongint;
  1209. end;
  1210. Writeln([fileindex,' (',line,',',column,')']);
  1211. if Def <> nil then
  1212. begin
  1213. Def.FilePos.FileIndex:=fileindex;
  1214. Def.FilePos.Line:=line;
  1215. Def.FilePos.Col:=column;
  1216. end;
  1217. end;
  1218. end;
  1219. procedure readderef(const derefspace: string; Ref: TPpuRef = nil);
  1220. var
  1221. b : tdereftype;
  1222. first : boolean;
  1223. idx : longint;
  1224. i,n : byte;
  1225. pdata : pbyte;
  1226. begin
  1227. if not assigned(derefdata) then
  1228. exit;
  1229. first:=true;
  1230. idx:=ppufile.getlongint;
  1231. if idx = -1 then
  1232. begin
  1233. writeln('Nil');
  1234. exit;
  1235. end;
  1236. if (idx>derefdatalen) then
  1237. begin
  1238. WriteError('!! Error: Deref idx '+IntToStr(idx)+' > '+IntToStr(derefdatalen));
  1239. exit;
  1240. end;
  1241. write([derefspace,'(',idx,') ']);
  1242. pdata:=@derefdata[idx];
  1243. i:=0;
  1244. n:=pdata[i];
  1245. inc(i);
  1246. if n<1 then
  1247. begin
  1248. WriteError('!! Error: Deref len < 1');
  1249. exit;
  1250. end;
  1251. while (i<=n) do
  1252. begin
  1253. if not first then
  1254. write(', ')
  1255. else
  1256. first:=false;
  1257. b:=tdereftype(pdata[i]);
  1258. inc(i);
  1259. case b of
  1260. deref_nil :
  1261. write('Nil');
  1262. deref_symid :
  1263. begin
  1264. idx:=pdata[i] shl 24 or pdata[i+1] shl 16 or pdata[i+2] shl 8 or pdata[i+3];
  1265. inc(i,4);
  1266. write(['SymId ',idx]);
  1267. if Ref <> nil then
  1268. Ref.Id:=idx;
  1269. end;
  1270. deref_defid :
  1271. begin
  1272. idx:=pdata[i] shl 24 or pdata[i+1] shl 16 or pdata[i+2] shl 8 or pdata[i+3];
  1273. inc(i,4);
  1274. write(['DefId ',idx]);
  1275. if Ref <> nil then
  1276. Ref.Id:=idx;
  1277. end;
  1278. deref_unit :
  1279. begin
  1280. idx:=pdata[i] shl 8 or pdata[i+1];
  1281. inc(i,2);
  1282. write(['Unit ',idx]);
  1283. if Ref <> nil then
  1284. Ref.UnitIndex:=idx;
  1285. end;
  1286. else
  1287. begin
  1288. WriteError('!! unsupported dereftyp: '+IntToStr(ord(b)));
  1289. break;
  1290. end;
  1291. end;
  1292. end;
  1293. writeln;
  1294. end;
  1295. Procedure ReadUnitImportSyms;
  1296. var
  1297. c,i : longint;
  1298. begin
  1299. writeln([space,'Imported Symbols']);
  1300. writeln([space,'----------------']);
  1301. c:=ppufile.getlongint;
  1302. for i:=0 to c-1 do
  1303. readderef(space);
  1304. writeln([space]);
  1305. end;
  1306. procedure readpropaccesslist(const s:string; Ref: TPpuRef = nil);
  1307. { type tsltype is in symconst unit }
  1308. const
  1309. slstr : array[tsltype] of string[12] = (
  1310. '',
  1311. 'load',
  1312. 'call',
  1313. 'subscript',
  1314. 'vec',
  1315. 'typeconv',
  1316. 'absolutetype'
  1317. );
  1318. var
  1319. sl : tsltype;
  1320. begin
  1321. readderef('',Ref);
  1322. repeat
  1323. sl:=tsltype(ppufile.getbyte);
  1324. if sl=sl_none then
  1325. break;
  1326. write([s,'(',slstr[sl],') ']);
  1327. case sl of
  1328. sl_none : ;
  1329. sl_call,
  1330. sl_load,
  1331. sl_subscript :
  1332. if (Ref <> nil) and (Ref.IsNull) then
  1333. begin
  1334. readderef('',Ref);
  1335. Ref.IsSymId:=True;
  1336. end
  1337. else
  1338. readderef('');
  1339. sl_absolutetype,
  1340. sl_typeconv :
  1341. readderef('');
  1342. sl_vec :
  1343. begin
  1344. writeln([ppufile.getlongint]);
  1345. readderef('');
  1346. end;
  1347. end;
  1348. until false;
  1349. end;
  1350. (*
  1351. talignmentinfo = packed record
  1352. procalign,
  1353. loopalign,
  1354. jumpalign,
  1355. constalignmin,
  1356. constalignmax,
  1357. varalignmin,
  1358. varalignmax,
  1359. localalignmin,
  1360. localalignmax,
  1361. recordalignmin,
  1362. recordalignmax,
  1363. maxCrecordalign : longint;
  1364. end;
  1365. tsettings = packed record
  1366. alignment : talignmentinfo;
  1367. globalswitches : tglobalswitches;
  1368. moduleswitches : tmoduleswitches;
  1369. localswitches : tlocalswitches;
  1370. modeswitches : tmodeswitches;
  1371. optimizerswitches : toptimizerswitches;
  1372. { generate information necessary to perform these wpo's during a subsequent compilation }
  1373. genwpoptimizerswitches: twpoptimizerswitches;
  1374. { perform these wpo's using information generated during a previous compilation }
  1375. dowpoptimizerswitches: twpoptimizerswitches;
  1376. debugswitches : tdebugswitches;
  1377. { 0: old behaviour for sets <=256 elements
  1378. >0: round to this size }
  1379. setalloc,
  1380. packenum : shortint;
  1381. packrecords : shortint;
  1382. maxfpuregisters : shortint;
  1383. cputype,
  1384. optimizecputype : tcputype;
  1385. fputype : tfputype;
  1386. asmmode : tasmmode;
  1387. interfacetype : tinterfacetypes;
  1388. defproccall : tproccalloption;
  1389. sourcecodepage : tcodepagestring;
  1390. minfpconstprec : tfloattype;
  1391. disabledircache : boolean;
  1392. { CPU targets with microcontroller support can add a controller specific unit }
  1393. controllertype : tcontrollertype;
  1394. { WARNING: this pointer cannot be written as such in record token }
  1395. pmessage : pmessagestaterecord;
  1396. end;
  1397. *)
  1398. procedure readprocinfooptions(space : string);
  1399. (*
  1400. tprocinfoflag=(
  1401. { procedure has at least one assembler block }
  1402. pi_has_assembler_block,
  1403. { procedure does a call }
  1404. pi_do_call,
  1405. { procedure has a try statement = no register optimization }
  1406. pi_uses_exceptions,
  1407. { procedure is declared as @var(assembler), don't optimize}
  1408. pi_is_assembler,
  1409. { procedure contains data which needs to be finalized }
  1410. pi_needs_implicit_finally,
  1411. { procedure has the implicit try..finally generated }
  1412. pi_has_implicit_finally,
  1413. { procedure uses fpu}
  1414. pi_uses_fpu,
  1415. { procedure uses GOT for PIC code }
  1416. pi_needs_got,
  1417. { references var/proc/type/const in static symtable,
  1418. i.e. not allowed for inlining from other units }
  1419. pi_uses_static_symtable,
  1420. { set if the procedure has to push parameters onto the stack }
  1421. pi_has_stackparameter,
  1422. { set if the procedure has at least one label }
  1423. pi_has_label,
  1424. { calls itself recursive }
  1425. pi_is_recursive,
  1426. { stack frame optimization not possible (only on x86 probably) }
  1427. pi_needs_stackframe,
  1428. { set if the procedure has at least one register saved on the stack }
  1429. pi_has_saved_regs,
  1430. { dfa was generated for this proc }
  1431. pi_dfaavailable,
  1432. { subroutine contains interprocedural used labels }
  1433. pi_has_interproclabel,
  1434. { subroutine contains interprocedural gotos }
  1435. pi_has_global_goto
  1436. ); *)
  1437. type
  1438. tprocinfoopt=record
  1439. mask : tprocinfoflag;
  1440. str : string[81];
  1441. end;
  1442. const
  1443. procinfoopts=ord(high(tprocinfoflag)) - ord(low(tprocinfoflag));
  1444. procinfoopt : array[0..procinfoopts] of tprocinfoopt=(
  1445. (mask:pi_has_assembler_block;
  1446. str:' has at least one assembler block'),
  1447. (mask:pi_do_call;
  1448. str:' does a call'),
  1449. (mask:pi_uses_exceptions;
  1450. str:' has a try statement = no register optimization '),
  1451. (mask:pi_is_assembler;
  1452. str:' is declared as @var(assembler), don''t optimize'),
  1453. (mask:pi_needs_implicit_finally;
  1454. str:' contains data which needs to be finalized '),
  1455. (mask:pi_has_implicit_finally;
  1456. str:' has the implicit try..finally generated '),
  1457. (mask:pi_uses_fpu;
  1458. str:' uses fpu'),
  1459. (mask:pi_needs_got;
  1460. str:' uses GOT for PIC code '),
  1461. (mask:pi_uses_static_symtable;
  1462. str:' references var/proc/type/const in static symtable'),
  1463. (mask:pi_has_stackparameter;
  1464. str:' set if the procedure has to push parameters onto the stack '),
  1465. (mask:pi_has_label;
  1466. str:' set if the procedure has at least one label '),
  1467. (mask:pi_is_recursive;
  1468. str:' calls itself recursive '),
  1469. (mask:pi_needs_stackframe;
  1470. str:' stack frame optimization not possible (only on x86 probably) '),
  1471. (mask:pi_has_saved_regs;
  1472. str:' set if the procedure has at least one register saved on the stack '),
  1473. (mask:pi_dfaavailable;
  1474. str:' dfa was generated for this proc '),
  1475. (mask:pi_has_interproclabel;
  1476. str:' subroutine contains interprocedural used labels '),
  1477. (mask:pi_has_unwind_info;
  1478. str:' unwinding info was generated for this proc '),
  1479. (mask:pi_has_global_goto;
  1480. str:' subroutine contains interprocedural goto '),
  1481. (mask:pi_has_inherited;
  1482. str:' subroutine contains inherited call '),
  1483. (mask:pi_has_nested_exit;
  1484. str:' subroutine contains a nested subroutine which calls the exit of the current one '),
  1485. (mask:pi_has_stack_allocs;
  1486. str:' allocates memory on stack, so stack may be unbalanced on exit '),
  1487. (mask:pi_estimatestacksize;
  1488. str:' stack size is estimated before subroutine is compiled '),
  1489. (mask:pi_calls_c_varargs;
  1490. str:' calls function with C-style varargs '),
  1491. (mask:pi_has_open_array_parameter;
  1492. str:' has open array parameter '),
  1493. (mask:pi_uses_threadvar;
  1494. str:' uses threadvars '),
  1495. (mask:pi_has_except_table_data;
  1496. str:' has except table data ')
  1497. );
  1498. var
  1499. procinfooptions : tprocinfoflags;
  1500. i : longint;
  1501. first : boolean;
  1502. begin
  1503. ppufile.getsmallset(procinfooptions);
  1504. if procinfooptions<>[] then
  1505. begin
  1506. first:=true;
  1507. for i:=0 to procinfoopts do
  1508. if (procinfoopt[i].mask in procinfooptions) then
  1509. begin
  1510. if first then
  1511. first:=false
  1512. else
  1513. write(', ');
  1514. write(procinfoopt[i].str);
  1515. end;
  1516. end;
  1517. writeln;
  1518. end;
  1519. procedure readsymoptions(space : string; Def: TPpuDef = nil);
  1520. type
  1521. tsymopt=record
  1522. mask : tsymoption;
  1523. str : string[30];
  1524. end;
  1525. const
  1526. symopts=ord(high(tsymoption)) - ord(low(tsymoption));
  1527. { sp_none = 0 corresponds to nothing }
  1528. symopt : array[1..symopts] of tsymopt=(
  1529. (mask:sp_static; str:'Static'),
  1530. (mask:sp_hint_deprecated; str:'Hint Deprecated'),
  1531. (mask:sp_hint_platform; str:'Hint Platform'),
  1532. (mask:sp_hint_library; str:'Hint Library'),
  1533. (mask:sp_hint_unimplemented; str:'Hint Unimplemented'),
  1534. (mask:sp_hint_experimental; str:'Hint Experimental'),
  1535. (mask:sp_has_overloaded; str:'Has overloaded'),
  1536. (mask:sp_internal; str:'Internal'),
  1537. (mask:sp_implicitrename; str:'Implicit Rename'),
  1538. (mask:sp_generic_para; str:'Generic Parameter'),
  1539. (mask:sp_has_deprecated_msg; str:'Has Deprecated Message'),
  1540. (mask:sp_generic_dummy; str:'Generic Dummy'),
  1541. (mask:sp_explicitrename; str:'Explicit Rename')
  1542. );
  1543. var
  1544. symoptions : tsymoptions;
  1545. i : longint;
  1546. first : boolean;
  1547. begin
  1548. ppufile.getsmallset(symoptions);
  1549. if symoptions<>[] then
  1550. begin
  1551. if Def <> nil then
  1552. if sp_internal in symoptions then
  1553. Def.Visibility:=dvHidden;
  1554. first:=true;
  1555. for i:=1to symopts do
  1556. if (symopt[i].mask in symoptions) then
  1557. begin
  1558. if first then
  1559. first:=false
  1560. else
  1561. write(', ');
  1562. write(symopt[i].str);
  1563. end;
  1564. end;
  1565. writeln;
  1566. if sp_has_deprecated_msg in symoptions then
  1567. writeln([space,'Deprecated : ', ppufile.getstring]);
  1568. end;
  1569. procedure readvisibility(Def: TPpuDef = nil);
  1570. var
  1571. i: byte;
  1572. begin
  1573. i:=ppufile.getbyte;
  1574. if Def <> nil then
  1575. case tvisibility(i) of
  1576. vis_public: Def.Visibility:=dvPublic;
  1577. vis_published: Def.Visibility:=dvPublished;
  1578. vis_protected, vis_strictprotected: Def.Visibility:=dvProtected;
  1579. else Def.Visibility:=dvPrivate;
  1580. end;
  1581. writeln(Visibility2Str(i));
  1582. end;
  1583. procedure readattrs(def: TPpuDef);
  1584. var
  1585. i,cnt,paras: longint;
  1586. begin
  1587. cnt:=ppufile.getlongint;
  1588. if cnt>0 then
  1589. begin
  1590. writeln([space,' Attributes : ']);
  1591. space:=' '+space;
  1592. if assigned(def) then
  1593. SetLength(def.Attrs,cnt);
  1594. for i:=0 to cnt-1 do
  1595. begin
  1596. writeln([space,'** Custom Attribute ',i,' **']);
  1597. write ([space,' Type symbol : ']);
  1598. if assigned(def) then
  1599. begin
  1600. def.Attrs[i].TypeSym:=TPpuRef.Create;
  1601. readderef('',def.Attrs[i].TypeSym);
  1602. end
  1603. else
  1604. readderef('');
  1605. write ([space,' Type constructor : ']);
  1606. if assigned(def) then
  1607. begin
  1608. def.Attrs[i].TypeConstr:=TPpuRef.Create;
  1609. readderef('',def.Attrs[i].TypeConstr);
  1610. end
  1611. else
  1612. readderef('');
  1613. paras:=ppufile.getlongint;
  1614. writeln([space,' Parameters : ',paras]);
  1615. if assigned(def) then
  1616. def.Attrs[i].ParaCount:=paras;
  1617. end;
  1618. delete(space,1,4);
  1619. end;
  1620. end;
  1621. procedure readnodetree; forward;
  1622. procedure readattrparas(def: TPpuDef);
  1623. var
  1624. attr,para: LongInt;
  1625. begin
  1626. if Length(def.Attrs) > 0 then
  1627. writeln([space,' Attr Paras : ']);
  1628. space:=' '+space;
  1629. for attr:=0 to High(def.Attrs) do
  1630. begin
  1631. writeln([space,'** Custom Attribute ',attr,' Arguments **']);
  1632. space:=' '+space;
  1633. for para:=0 to def.Attrs[attr].ParaCount-1 do
  1634. begin
  1635. readnodetree;
  1636. end;
  1637. delete(space,1,4);
  1638. end;
  1639. delete(space,1,4);
  1640. end;
  1641. procedure readdefsubentries(def: TPpuDef);
  1642. begin
  1643. space:=' '+space;
  1644. readattrparas(def);
  1645. delete(space,1,4);
  1646. end;
  1647. procedure readsymsubentries(def: TPpuDef);
  1648. begin
  1649. readattrparas(def);
  1650. end;
  1651. procedure readcommonsym(const s:string; Def: TPpuDef = nil);
  1652. var
  1653. i: integer;
  1654. n: string;
  1655. begin
  1656. n:=ppufile.getstring;
  1657. if Def <> nil then
  1658. Def.Name:=n;
  1659. i:=ppufile.getlongint;
  1660. if Def <> nil then
  1661. Def.SetSymId(i);
  1662. writeln([space,'** Symbol Id ',i,' **']);
  1663. writeln([space,s,n]);
  1664. write ([space,' File Pos : ']);
  1665. readposinfo(Def);
  1666. write ([space,' Visibility : ']);
  1667. readvisibility(Def);
  1668. write ([space,' SymOptions : ']);
  1669. readsymoptions(space+' ',Def);
  1670. readattrs(Def);
  1671. end;
  1672. procedure readcgpara(const space:string);
  1673. { this is originally in cgbase.pas }
  1674. type
  1675. TCGLoc=(LOC_INVALID, LOC_VOID, LOC_CONSTANT, LOC_JUMP, LOC_FLAGS,
  1676. LOC_REGISTER, LOC_CREGISTER, LOC_FPUREGISTER, LOC_CFPUREGISTER,
  1677. LOC_MMXREGISTER, LOC_CMMXREGISTER, LOC_MMREGISTER, LOC_CMMREGISTER,
  1678. LOC_SUBSETREG, LOC_CSUBSETREG, LOC_SUBSETREF, LOC_CSUBSETREF,
  1679. LOC_CREFERENCE, LOC_REFERENCE);
  1680. const
  1681. tcgloc2str : array[TCGLoc] of string[12] = (
  1682. 'LOC_INVALID', 'LOC_VOID', 'LOC_CONST', 'LOC_JUMP', 'LOC_FLAGS',
  1683. 'LOC_REG', 'LOC_CREG', 'LOC_FPUREG', 'LOC_CFPUREG',
  1684. 'LOC_MMXREG', 'LOC_CMMXREG', 'LOC_MMREG', 'LOC_CMMREG',
  1685. 'LOC_SSETREG', 'LOC_CSSETREG', 'LOC_SSETREF', 'LOC_CSSETREF',
  1686. 'LOC_CREF', 'LOC_REF');
  1687. var
  1688. i: byte;
  1689. ii: longint;
  1690. np: byte;
  1691. loc: tcgloc;
  1692. begin
  1693. i:=ppufile.getbyte;
  1694. writeln([space,' Alignment : ',i]);
  1695. i:=ppufile.getbyte;
  1696. writeln([space,' Size : ',i]);
  1697. ii:=ppufile.getaint;
  1698. writeln([space,' IntSize : ',ii]);
  1699. readderef(space+' ');
  1700. np:=ppufile.getbyte;
  1701. writeln([space,' NumParaloc : ',np]);
  1702. while np > 0 do
  1703. begin
  1704. i:=ppufile.getbyte;
  1705. writeln([space,' Paraloc Size : ',i]);
  1706. loc:=tcgloc(ppufile.getbyte);
  1707. if loc > high(tcgloc) then
  1708. begin
  1709. WriteError('!! Location is out of range! '+IntToStr(ord(loc)));
  1710. loc:=LOC_INVALID;
  1711. end;
  1712. writeln([space,' Paraloc Loc : (',ord(loc),') ',tcgloc2str[loc]]);
  1713. case loc of
  1714. LOC_REFERENCE:
  1715. begin
  1716. writeln([space,' RegIndex : $',hexstr(ppufile.getdword,8)]);
  1717. writeln([space,' Offset : ',ppufile.getaint]);
  1718. end;
  1719. LOC_FPUREGISTER,
  1720. LOC_CFPUREGISTER,
  1721. LOC_MMREGISTER,
  1722. LOC_CMMREGISTER,
  1723. LOC_REGISTER,
  1724. LOC_CREGISTER :
  1725. begin
  1726. writeln([space,' ShiftVal : ',ppufile.getbyte]);
  1727. writeln([space,' Register : $',hexstr(ppufile.getdword,8)]);
  1728. end;
  1729. LOC_VOID:
  1730. begin end
  1731. else
  1732. WriteError('!! Invalid location error')
  1733. end;
  1734. dec(np);
  1735. end;
  1736. end;
  1737. procedure readcommondef(const s:string; out defoptions: tdefoptions; Def: TPpuDef = nil);
  1738. type
  1739. tdefopt=record
  1740. mask : tdefoption;
  1741. str : string[30];
  1742. end;
  1743. tdefstateinfo=record
  1744. mask : tdefstate;
  1745. str : string[30];
  1746. end;
  1747. tgenconstrflag=record
  1748. mask : tgenericconstraintflag;
  1749. str : string[30];
  1750. end;
  1751. ptoken=^ttoken;
  1752. pmsgstate =^tmsgstate;
  1753. const
  1754. defopt : array[1..ord(high(tdefoption))] of tdefopt=(
  1755. (mask:df_unique; str:'Unique Type'),
  1756. (mask:df_generic; str:'Generic'),
  1757. (mask:df_specialization; str:'Specialization'),
  1758. (mask:df_copied_def; str:'Copied Typedef'),
  1759. (mask:df_genconstraint; str:'Generic Constraint'),
  1760. { this should never happen for defs stored to a ppu file }
  1761. (mask:df_not_registered_no_free; str:'Unregistered/No free (invalid)'),
  1762. (mask:df_llvm_no_struct_packing; str:'LLVM unpacked struct'),
  1763. (mask:df_internal; str:'Internal')
  1764. );
  1765. defstate : array[1..ord(high(tdefstate))] of tdefstateinfo=(
  1766. (mask:ds_vmt_written; str:'VMT Written'),
  1767. (mask:ds_rtti_table_used; str:'RTTITable Used'),
  1768. (mask:ds_init_table_used; str:'InitTable Used'),
  1769. (mask:ds_rtti_table_written; str:'RTTITable Written'),
  1770. (mask:ds_init_table_written; str:'InitTable Written'),
  1771. (mask:ds_dwarf_dbg_info_used; str:'Dwarf DbgInfo Used'),
  1772. (mask:ds_dwarf_dbg_info_written;str:'Dwarf DbgInfo Written')
  1773. );
  1774. genconstrflag : array[1..ord(high(tgenericconstraintflag))] of tgenconstrflag=(
  1775. (mask:gcf_constructor; str:'Constructor'),
  1776. (mask:gcf_class; str:'Class'),
  1777. (mask:gcf_record; str:'Record')
  1778. );
  1779. var
  1780. defstates : tdefstates;
  1781. i, nb{, msgvalue}, mesgnb : longint;
  1782. first : boolean;
  1783. copy_size, min_size, tokenbufsize : longint;
  1784. tokenbuf : pbyte;
  1785. tbi, stbi, last_col, new_col : longint;
  1786. last_line,new_line : dword;
  1787. // idtoken,
  1788. token : ttoken;
  1789. // state : tmsgstate;
  1790. new_settings : Tsettings;
  1791. len : sizeint;
  1792. wstring : widestring;
  1793. astring : ansistring;
  1794. linestr,genstr : string;
  1795. genconstr : tgenericconstraintflags;
  1796. procedure dump_new_settings;
  1797. (* tsettings = record
  1798. alignment : talignmentinfo;
  1799. globalswitches : tglobalswitches;
  1800. targetswitches : ttargetswitches;
  1801. moduleswitches : tmoduleswitches;
  1802. localswitches : tlocalswitches;
  1803. modeswitches : tmodeswitches;
  1804. optimizerswitches : toptimizerswitches;
  1805. { generate information necessary to perform these wpo's during a subsequent compilation }
  1806. genwpoptimizerswitches: twpoptimizerswitches;
  1807. { perform these wpo's using information generated during a previous compilation }
  1808. dowpoptimizerswitches: twpoptimizerswitches;
  1809. debugswitches : tdebugswitches;
  1810. { 0: old behaviour for sets <=256 elements
  1811. >0: round to this size }
  1812. setalloc,
  1813. packenum : shortint;
  1814. packrecords : shortint;
  1815. maxfpuregisters : shortint;
  1816. cputype,
  1817. optimizecputype,
  1818. asmcputype : tcputype;
  1819. fputype : tfputype;
  1820. asmmode : tasmmode;
  1821. interfacetype : tinterfacetypes;
  1822. defproccall : tproccalloption;
  1823. sourcecodepage : tstringencoding;
  1824. minfpconstprec : tfloattype;
  1825. disabledircache : boolean;
  1826. tlsmodel : ttlsmodel;
  1827. {$if defined(i8086)}
  1828. x86memorymodel : tx86memorymodel;
  1829. {$endif defined(i8086)}
  1830. {$if defined(ARM)}
  1831. instructionset : tinstructionset;
  1832. {$endif defined(ARM)}
  1833. {$if defined(LLVM) and not defined(GENERIC_CPU)}
  1834. llvmversion: tllvmversion;
  1835. {$endif defined(LLVM) and not defined(GENERIC_CPU)}
  1836. { CPU targets with microcontroller support can add a controller specific unit }
  1837. controllertype : tcontrollertype;
  1838. { WARNING: this pointer cannot be written as such in record token }
  1839. pmessage : pmessagestaterecord;
  1840. end; *)
  1841. const
  1842. targetswitchname : array[ttargetswitch] of string[30] =
  1843. { global target-specific switches }
  1844. ('Target None', {ts_none}
  1845. { generate code that results in smaller TOCs than normal (AIX) }
  1846. 'Small TOC', {ts_small_toc}
  1847. { for the JVM target: generate integer array initializations via string
  1848. constants in order to reduce the generated code size (Java routines
  1849. are limited to 64kb of bytecode) }
  1850. 'JVM compact int array init', {ts_compact_int_array_init}
  1851. { for the JVM target: intialize enum fields in constructors with the
  1852. enum class instance corresponding to ordinal value 0 (not done by
  1853. default because this initialization can only be performed after the
  1854. inherited constructors have run, and if they call a virtual method
  1855. of the current class, then this virtual method may already have
  1856. initialized that field with another value and the constructor
  1857. initialization will result in data loss }
  1858. 'JVM enum field init', {ts_jvm_enum_field_init}
  1859. { when automatically generating getters/setters for properties, use
  1860. these strings as prefixes for the generated getters/setter names }
  1861. 'Auto getter prefix', {ts_auto_getter_prefix}
  1862. 'Auto setter prefix', {ts_auto_setter_predix}
  1863. 'Thumb interworking', {ts_thumb_interworking,}
  1864. { lowercase the first character of routine names, used to generate
  1865. names that are compliant with Java coding standards from code
  1866. written according to Delphi coding standards }
  1867. 'LowerCase proc start', {ts_lowercase_proc_start,}
  1868. { initialise local variables on the JVM target so you won't get
  1869. accidental uses of uninitialised values }
  1870. 'Init locals', {ts_init_locals}
  1871. { emit a CLD instruction before using the x86 string instructions }
  1872. 'Emit CLD instruction', {ts_cld}
  1873. { increment BP before pushing it in the function prologue and decrement
  1874. it after popping it in the function epilogue, iff the function is
  1875. going to terminate with a far ret. Thus, the BP value pushed on the
  1876. stack becomes odd if the function is far and even if the function is
  1877. near. This allows walking the BP chain on the stack and e.g.
  1878. obtaining a stack trace even if the program uses a mixture of near
  1879. and far calls. This is also required for Win16 real mode, because it
  1880. allows Windows to move code segments around (in order to defragment
  1881. memory) and then walk through the stacks of all running programs and
  1882. update the segment values of the segment that has moved. }
  1883. 'Use odd BP for far procs' {ts_x86_far_procs_push_odd_bp}
  1884. );
  1885. moduleswitchname : array[tmoduleswitch] of string[40] =
  1886. ('Module None', {cs_modulenone,}
  1887. { parser }
  1888. 'Floating Point Emulation',{ cs_fp_emulation}
  1889. 'Extended syntax', {cs_extsyntax}
  1890. 'Open string', {cs_openstring}
  1891. { support }
  1892. 'Goto allowed', {cs_support_goto}
  1893. 'Macro support', {cs_support_macro}
  1894. 'C operator support', {cs_support_c_operators}
  1895. { generation }
  1896. 'Profile', {cs_profile}
  1897. 'Debug information', {cs_debuginfo}
  1898. 'Compilation of System unit', {cs_compilesystem}
  1899. 'Line information', {cs_lineinfo}
  1900. 'Implicit exceptions', {cs_implicit_exceptions}
  1901. 'Explicit CodePage', {cs_explicit_codepage}
  1902. 'System CodePage', {cs_system_codepage}
  1903. { linking }
  1904. 'Create smart units', {cs_create_smart}
  1905. 'Create dynamic', {cs_create_dynamic}
  1906. 'Create PIC code', {cs_create_pic}
  1907. { browser switches are back }
  1908. 'Browser', {cs_browser}
  1909. 'Local Browser', {cs_local_browser}
  1910. { target specific }
  1911. 'Executable Stack', {cs_executable_stack}
  1912. { i8086 specific }
  1913. 'Hude code', {cs_huge_code}
  1914. 'Win16 smart callbacks', {cs_win16_smartcallbacks}
  1915. { Record usage of checkpointer experimental feature }
  1916. 'CheckPointer used', {cs_checkpointer_called}
  1917. 'Supports LLVM Link-Time Optimization' {cs_lto}
  1918. );
  1919. globalswitchname : array[tglobalswitch] of string[50] =
  1920. ('Global None',{cs_globalnone}
  1921. { parameter switches }
  1922. 'Check unit name', {cs_check_unit_name}
  1923. 'Constructor name', {cs_constructor_name}
  1924. 'Support exceptions',{cs_support_exceptions}
  1925. 'Support Objective-C pas',{ cs_support_c_objectivepas}
  1926. 'Transparent file names', {cs_transparent_file_names}
  1927. { units }
  1928. 'Load Objpas Unit', {cs_load_objpas_unit}
  1929. 'Load GPC unit', {cs_load_gpc_unit}
  1930. 'Load FPCKylix unit', {cs_load_fpcylix_unit}
  1931. 'Support Vectors', {cs_support_vectors}
  1932. { debuginfo }
  1933. 'Use HeapTRc unit', {cs_use_heaptrc}
  1934. 'Use line information', {cs_use_lineinfo}
  1935. 'Use GDB Valgrind', {cs_gdb_valgrind}
  1936. 'No regalloc', {cs_no_regalloc}
  1937. 'Stabs preserve cases', {cs_stabs_preservecase}
  1938. { assembling }
  1939. 'Leave assembler file', {cs_asm_leave}
  1940. 'Use external assembler', {cs_asm_extern}
  1941. 'Use pipes to call assembler', {cs_asm_pipe}
  1942. 'Add source infos into assembler files', {cs_asm_source}
  1943. 'Add register allocation into assembler files', {cs_asm_regalloc}
  1944. 'Add temporary allocation into assmebler files', {cs_asm_tempalloc}
  1945. 'Add node information into assembler files', {cs_asm_nodes}
  1946. 'Adapt assembler call to GNU version <= 2.25', {cs_asm_pre_binutils_2_25}
  1947. { linking }
  1948. 'Skip linking stage', {cs_link_nolink}
  1949. 'Link static', {cs_link_static}
  1950. 'Link smart', {cs_link_smart}
  1951. 'Link shared', {cs_link_shared}
  1952. 'Link deffile', {cs_link_deffile}
  1953. 'Strip after linking', {cs_link_strip}
  1954. 'Use linker static flag',{cs_link_staticflag}
  1955. 'Link on target OS',{cs_link_on_target}
  1956. 'Use external linker', {cs_link_extern}
  1957. 'Link opt vtable', {cs_link_opt_vtable}
  1958. 'Link opt used sections', {cs_link_opt_used_sections}
  1959. 'Link debug to separate file',{cs_link_separate_dbg_file}
  1960. 'Create linker map', {cs_link_map}
  1961. 'Link to pthread', {cs_link_pthread}
  1962. 'Link no default lib order', {cs_link_no_default_lib_order}
  1963. 'Link using native linker', {cs_link_native}
  1964. 'Link for GNU linker version <=2.19', {cs_link_pre_binutils_2_19}
  1965. 'Link using vlink', {cs_link_vlink}
  1966. 'Link-Time Optimization disabled for system unit' {cs_lto_nosystem}
  1967. );
  1968. localswitchname : array[tlocalswitch] of string[50] =
  1969. { Switches which can be changed locally }
  1970. ('Local None', {cs_localnone}
  1971. { codegen }
  1972. 'Check overflow', {cs_check_overflow}
  1973. 'Check range', {cs_check_range}
  1974. 'Check object error', {cs_check_object}
  1975. 'Check I/O error', {cs_check_io}
  1976. 'Check stack', {cs_check_stack}
  1977. 'Check pointer', {cs_checkpointer}
  1978. 'Check ordinal size', {cs_check_ordinal_size}
  1979. 'Generate stackframes', {cs_generate_stackframes}
  1980. 'Do assertions', {cs_do_assertion}
  1981. 'Generate RTTI', {cs_generate_rtti}
  1982. 'Full boolean evaluaion', {cs_full_boolean_eval}
  1983. 'Typed constant are writable', {cs_typed_const_writable}
  1984. 'Allow calcuation on enum types', {cs_allow_enum_calc}
  1985. 'Do inline', {cs_do_inline}
  1986. 'Add FWAIT instruction for FPU 8087', {cs_fpu_fwait}
  1987. 'IEEE errors', {cs_ieee_errors}
  1988. 'Check low address loading', {cs_check_low_addr_load}
  1989. 'Imported data', {cs_imported_data}
  1990. 'Excess precision', {cs_excessprecision}
  1991. 'Check fpu exceptions', {cs_check_fpu_exceptions}
  1992. 'Check all case coverage', {cs_check_all_case_coverage}
  1993. { mmx }
  1994. 'Allow MMX instructions', {cs_mmx}
  1995. 'Use MMX saturation', {cs_mmx_saturation}
  1996. { parser }
  1997. 'Use typed addresses', {cs_typed_addresses}
  1998. 'Use strict var strings', {cs_strict_var_strings}
  1999. 'Use reference counted strings', {cs_refcountedstrings}
  2000. 'Use bit-packing', {cs_bitpacking}
  2001. 'Use var property setter', {cs_varpropsetter}
  2002. 'Use scoped enums',{cs_scopedenums}
  2003. 'Use pointer math', {cs_pointermath}
  2004. { macpas specific}
  2005. 'MACPAS exteranl variable', {cs_external_var}
  2006. 'MACPAS externally visible', {cs_externally_visible}
  2007. { jvm specific }
  2008. 'JVM check var copyout', {cs_check_var_copyout}
  2009. 'Zero based strings', {cs_zerobasedstrings}
  2010. { i8086 specific }
  2011. 'i8086 force FAR calls', {cs_force_far_calls}
  2012. 'i8086 huge pointer arithmetic', {cs_hugeptr_arithmetic_normalization}
  2013. 'i8086 huge pointer comparison' {cs_hugeptr_comparison_normalization}
  2014. );
  2015. var
  2016. globalswitch : tglobalswitch;
  2017. targetswitch : ttargetswitch;
  2018. moduleswitch : tmoduleswitch;
  2019. localswitch : tlocalswitch;
  2020. modeswitch : tmodeswitch;
  2021. optimizerswitch : toptimizerswitch;
  2022. begin
  2023. {alignment : talignmentinfo;}
  2024. {talignmentinfo = packed record}
  2025. writeln('Procedure alignment: '+tostr(new_settings.alignment.procalign));
  2026. writeln('Loop alignment: '+tostr(new_settings.alignment.loopalign));
  2027. { alignment for labels after unconditional jumps, this must be a power of two }
  2028. writeln('Jump alignment: '+tostr(new_settings.alignment.jumpalign));
  2029. { max. alignment for labels after unconditional jumps:
  2030. the compiler tries to align jumpalign, however, to do so it inserts at maximum jumpalignskipmax bytes or uses
  2031. the next smaller power of two of jumpalign }
  2032. writeln('Jump skip max alignment: '+tostr(new_settings.alignment.jumpalignskipmax));
  2033. { alignment for labels where two flows of the program flow coalesce, this must be a power of two }
  2034. writeln('Coalescence alignment: '+tostr(new_settings.alignment.coalescealign));
  2035. { max. alignment for labels where two flows of the program flow coalesce
  2036. the compiler tries to align to coalescealign, however, to do so it inserts at maximum coalescealignskipmax bytes or uses
  2037. the next smaller power of two of coalescealign }
  2038. writeln('Coalescence skip max alignment: '+tostr(new_settings.alignment.coalescealignskipmax));
  2039. writeln('Const min alignment: '+tostr(new_settings.alignment.constalignmin));
  2040. writeln('Const max alignment: '+tostr(new_settings.alignment.constalignmax));
  2041. writeln('Var min alignment: '+tostr(new_settings.alignment.varalignmin));
  2042. writeln('Var max alignment: '+tostr(new_settings.alignment.varalignmax));
  2043. writeln('Local min alignment: '+tostr(new_settings.alignment.localalignmin));
  2044. writeln('Local max alignment: '+tostr(new_settings.alignment.localalignmax));
  2045. writeln('Min record alignment: '+tostr(new_settings.alignment.recordalignmin));
  2046. writeln('Max record alignment: '+tostr(new_settings.alignment.recordalignmax));
  2047. writeln('Max C record alignment: '+tostr(new_settings.alignment.maxCrecordalign));
  2048. for globalswitch:=low(tglobalswitch) to high(tglobalswitch) do
  2049. if globalswitch in new_settings.globalswitches then
  2050. writeln('global switch: '+globalswitchname[globalswitch]);
  2051. if (new_settings.globalswitches <> []) then
  2052. writeln('Unknown global switch');
  2053. for targetswitch:=low(ttargetswitch) to high(ttargetswitch) do
  2054. if targetswitch in new_settings.targetswitches then
  2055. writeln('target switch: '+targetswitchname[targetswitch]);
  2056. for moduleswitch:=low(tmoduleswitch) to high(tmoduleswitch) do
  2057. if moduleswitch in new_settings.moduleswitches then
  2058. writeln('module switch: '+moduleswitchname[moduleswitch]);
  2059. for localswitch:=low(tlocalswitch) to high(tlocalswitch) do
  2060. if localswitch in new_settings.localswitches then
  2061. writeln('local switch: '+localswitchname[localswitch]);
  2062. for modeswitch:=low(tmodeswitch) to high(tmodeswitch) do
  2063. if modeswitch in new_settings.modeswitches then
  2064. writeln(['mode switch: ',modeswitch]);
  2065. for optimizerswitch:=low(toptimizerswitch) to high(toptimizerswitch) do
  2066. if optimizerswitch in new_settings.optimizerswitches then
  2067. writeln(['optimizer switch: ',optimizerswitch]);
  2068. writeln(['Set allocation size ',new_settings.setalloc]);
  2069. writeln(['Pack enums ',new_settings.packenum]);
  2070. writeln(['Pack records ',new_settings.packrecords]);
  2071. writeln(['Max FPU registers ',new_settings.maxfpuregisters]);
  2072. writeln(['CPU type ',new_settings.cputype]);
  2073. writeln(['CPU optimize type ',new_settings.optimizecputype]);
  2074. writeln(['FPU type ',new_settings.fputype]);
  2075. writeln(['ASM mode ',new_settings.asmmode]);
  2076. end;
  2077. function readtoken: ttoken;
  2078. var
  2079. b,b2 : byte;
  2080. begin
  2081. b:=tokenbuf[tbi];
  2082. inc(tbi);
  2083. if (b and $80)<>0 then
  2084. begin
  2085. b2:=tokenbuf[tbi];
  2086. inc(tbi);
  2087. result:=ttoken(((b and $7f) shl 8) or b2);
  2088. end
  2089. else
  2090. result:=ttoken(b);
  2091. end;
  2092. function gettokenbufdword : dword;
  2093. var
  2094. var32 : dword;
  2095. begin
  2096. var32:=unaligned(pdword(@tokenbuf[tbi])^);
  2097. inc(tbi,sizeof(dword));
  2098. if ppufile.change_endian then
  2099. var32:=swapendian(var32);
  2100. result:=var32;
  2101. end;
  2102. function gettokenbufword : word;
  2103. var
  2104. var16 : word;
  2105. begin
  2106. var16:=unaligned(pword(@tokenbuf[tbi])^);
  2107. inc(tbi,sizeof(word));
  2108. if ppufile.change_endian then
  2109. var16:=swapendian(var16);
  2110. result:=var16;
  2111. end;
  2112. function gettokenbuflongint : longint;
  2113. var
  2114. var32 : longint;
  2115. begin
  2116. var32:=unaligned(plongint(@tokenbuf[tbi])^);
  2117. inc(tbi,sizeof(longint));
  2118. if ppufile.change_endian then
  2119. var32:=swapendian(var32);
  2120. result:=var32;
  2121. end;
  2122. function gettokenbufshortint : shortint;
  2123. var
  2124. var16 : shortint;
  2125. begin
  2126. var16:=unaligned(pshortint(@tokenbuf[tbi])^);
  2127. inc(tbi,sizeof(shortint));
  2128. if ppufile.change_endian then
  2129. var16:=swapendian(var16);
  2130. result:=var16;
  2131. end;
  2132. procedure tokenreadset(var b;size : longint);
  2133. var
  2134. i : longint;
  2135. begin
  2136. move(tokenbuf[tbi],b,size);
  2137. inc(tbi,size);
  2138. if ppufile.change_endian then
  2139. for i:=0 to size-1 do
  2140. Pbyte(@b)[i]:=reverse_byte(Pbyte(@b)[i]);
  2141. end;
  2142. function gettokenbufbyte : byte;
  2143. begin
  2144. result:=pbyte(@tokenbuf[tbi])^;
  2145. inc(tbi);
  2146. end;
  2147. function tokenreadenum(size : longint) : longword;
  2148. begin
  2149. if size=1 then
  2150. result:=gettokenbufbyte
  2151. else if size=2 then
  2152. result:=gettokenbufword
  2153. else if size=4 then
  2154. result:=gettokenbufdword;
  2155. end;
  2156. function gettokenbufsizeint : int64;
  2157. var
  2158. var64 : int64;
  2159. var32 : longint;
  2160. var16 : smallint;
  2161. begin
  2162. if CpuAddrBitSize[cpu]=64 then
  2163. begin
  2164. var64:=unaligned(pint64(@tokenbuf[tbi])^);
  2165. inc(tbi,sizeof(int64));
  2166. if ppufile.change_endian then
  2167. var64:=swapendian(var64);
  2168. result:=var64;
  2169. end
  2170. else if CpuAddrBitSize[cpu]=32 then
  2171. begin
  2172. var32:=unaligned(plongint(@tokenbuf[tbi])^);
  2173. inc(tbi,sizeof(longint));
  2174. if ppufile.change_endian then
  2175. var32:=swapendian(var32);
  2176. result:=var32;
  2177. end
  2178. else if CpuAddrBitSize[cpu]=16 then
  2179. begin
  2180. var16:=unaligned(psmallint(@tokenbuf[tbi])^);
  2181. inc(tbi,sizeof(smallint));
  2182. if ppufile.change_endian then
  2183. var16:=swapendian(var16);
  2184. result:=var16;
  2185. end
  2186. else
  2187. begin
  2188. WriteError('Wrong CpuAddrBitSize');
  2189. result:=0;
  2190. end;
  2191. end;
  2192. procedure tokenreadsettings(var asettings : tsettings; expected_size : asizeint);
  2193. { This procedure
  2194. needs to be changed whenever
  2195. globals.tsettings type is changed,
  2196. the problem is that no error will appear
  2197. before tests with generics are tested. PM }
  2198. var
  2199. startpos, endpos : longword;
  2200. begin
  2201. { WARNING all those fields need to be in the correct
  2202. order otherwise cross_endian PPU reading will fail }
  2203. startpos:=tbi;
  2204. with asettings do
  2205. begin
  2206. alignment.procalign:=gettokenbuflongint;
  2207. alignment.loopalign:=gettokenbuflongint;
  2208. alignment.jumpalign:=gettokenbuflongint;
  2209. alignment.jumpalignskipmax:=gettokenbuflongint;
  2210. alignment.coalescealign:=gettokenbuflongint;
  2211. alignment.coalescealignskipmax:=gettokenbuflongint;
  2212. alignment.constalignmin:=gettokenbuflongint;
  2213. alignment.constalignmax:=gettokenbuflongint;
  2214. alignment.varalignmin:=gettokenbuflongint;
  2215. alignment.varalignmax:=gettokenbuflongint;
  2216. alignment.localalignmin:=gettokenbuflongint;
  2217. alignment.localalignmax:=gettokenbuflongint;
  2218. alignment.recordalignmin:=gettokenbuflongint;
  2219. alignment.recordalignmax:=gettokenbuflongint;
  2220. alignment.maxCrecordalign:=gettokenbuflongint;
  2221. tokenreadset(globalswitches,sizeof(globalswitches));
  2222. tokenreadset(targetswitches,sizeof(targetswitches));
  2223. tokenreadset(moduleswitches,sizeof(moduleswitches));
  2224. tokenreadset(localswitches,sizeof(localswitches));
  2225. tokenreadset(modeswitches,sizeof(modeswitches));
  2226. tokenreadset(optimizerswitches,sizeof(optimizerswitches));
  2227. tokenreadset(genwpoptimizerswitches,sizeof(genwpoptimizerswitches));
  2228. tokenreadset(dowpoptimizerswitches,sizeof(dowpoptimizerswitches));
  2229. tokenreadset(debugswitches,sizeof(debugswitches));
  2230. { 0: old behaviour for sets <=256 elements
  2231. >0: round to this size }
  2232. setalloc:=gettokenbufshortint;
  2233. packenum:=gettokenbufshortint;
  2234. packrecords:=gettokenbufshortint;
  2235. maxfpuregisters:=gettokenbufshortint;
  2236. cputype:=tcputype(tokenreadenum(sizeof(tcputype)));
  2237. optimizecputype:=tcputype(tokenreadenum(sizeof(tcputype)));
  2238. fputype:=tfputype(tokenreadenum(sizeof(tfputype)));
  2239. asmmode:=tasmmode(tokenreadenum(sizeof(tasmmode)));
  2240. interfacetype:=tinterfacetypes(tokenreadenum(sizeof(tinterfacetypes)));
  2241. defproccall:=tproccalloption(tokenreadenum(sizeof(tproccalloption)));
  2242. { tstringencoding is word type,
  2243. thus this should be OK here }
  2244. sourcecodepage:=tstringEncoding(gettokenbufword);
  2245. minfpconstprec:=tfloattype(tokenreadenum(sizeof(tfloattype)));
  2246. disabledircache:=boolean(gettokenbufbyte);
  2247. tlsmodel:=ttlsmodel(tokenreadenum(sizeof(ttlsmodel)));
  2248. { TH: Since the field was conditional originally, it was not stored in PPUs. }
  2249. { While adding ControllerSupport constant, I decided not to store ct_none }
  2250. { on targets not supporting controllers, but this might be changed here and }
  2251. { in tokenwritesettings in the future to unify the PPU structure and handling }
  2252. { of this field in the compiler. }
  2253. {$PUSH}
  2254. {$WARN 6018 OFF} (* Unreachable code due to compile time evaluation *)
  2255. if CpuHasController[cpu] then
  2256. controllertype:=tcontrollertype(tokenreadenum(sizeof(tcontrollertype)))
  2257. else
  2258. ControllerType:=ct_none;
  2259. {$POP}
  2260. endpos:=tbi;
  2261. if endpos-startpos<>expected_size then
  2262. Writeln(['Wrong size of Settings read-in: ',expected_size,' expected, but got ',endpos-startpos]);
  2263. end;
  2264. end;
  2265. begin
  2266. i:=ppufile.getlongint;
  2267. if Def <> nil then
  2268. Def.Id:=i;
  2269. writeln([space,'** Definition Id ',i,' **']);
  2270. writeln([space,s]);
  2271. write ([space,' Type symbol : ']);
  2272. if Def <> nil then
  2273. readderef('', Def.Ref)
  2274. else
  2275. readderef('');
  2276. write ([space,' DefOptions : ']);
  2277. ppufile.getsmallset(defoptions);
  2278. if defoptions<>[] then
  2279. begin
  2280. first:=true;
  2281. for i:=1to high(defopt) do
  2282. if (defopt[i].mask in defoptions) then
  2283. begin
  2284. if first then
  2285. first:=false
  2286. else
  2287. write(', ');
  2288. write(defopt[i].str);
  2289. end;
  2290. end;
  2291. writeln;
  2292. write ([space,' DefStates : ']);
  2293. ppufile.getsmallset(defstates);
  2294. if defstates<>[] then
  2295. begin
  2296. first:=true;
  2297. for i:=1 to high(defstate) do
  2298. if (defstate[i].mask in defstates) then
  2299. begin
  2300. if first then
  2301. first:=false
  2302. else
  2303. write(', ');
  2304. write(defstate[i].str);
  2305. end;
  2306. end;
  2307. writeln;
  2308. if df_genconstraint in defoptions then
  2309. begin
  2310. ppufile.getsmallset(genconstr);
  2311. write ([space,' GenConstraints : ']);
  2312. if genconstr<>[] then
  2313. begin
  2314. first:=true;
  2315. for i:=1 to high(genconstrflag) do
  2316. if (genconstrflag[i].mask in genconstr) then
  2317. begin
  2318. if first then
  2319. first:=false
  2320. else
  2321. write(', ');
  2322. write(genconstrflag[i].str);
  2323. end;
  2324. end;
  2325. writeln;
  2326. len:=ppufile.getlongint;
  2327. if len>0 then
  2328. begin
  2329. space:=' '+space;
  2330. writeln([space,'------ constraint defs begin ------']);
  2331. for i:=0 to len-1 do
  2332. begin
  2333. writeln([space,'------ constraint def ',i,' ------']);
  2334. readderef(space);
  2335. end;
  2336. writeln([space,'------ constraint defs end ------']);
  2337. delete(space,1,4);
  2338. end;
  2339. end;
  2340. if [df_generic,df_specialization]*defoptions<>[] then
  2341. begin
  2342. nb:=ppufile.getlongint;
  2343. writeln([space,'has ',nb,' parameters']);
  2344. if nb>0 then
  2345. begin
  2346. for i:=0 to nb-1 do
  2347. begin
  2348. writeln([space,'parameter ',i,': ',ppufile.getstring]);
  2349. readderef(space);
  2350. end;
  2351. end;
  2352. end;
  2353. if df_generic in defoptions then
  2354. begin
  2355. last_line:=0;
  2356. last_col:=0;
  2357. linestr:='';
  2358. genstr:='';
  2359. tokenbufsize:=ppufile.getlongint;
  2360. writeln([space,' Tokenbuffer size : ',tokenbufsize]);
  2361. tokenbuf:=allocmem(tokenbufsize);
  2362. ppufile.getdata(tokenbuf^,tokenbufsize);
  2363. tbi:=0;
  2364. write([space,' Tokens: ']);
  2365. while tbi<tokenbufsize do
  2366. begin
  2367. token:=readtoken;
  2368. if token<>_GENERICSPECIALTOKEN then
  2369. begin
  2370. if token <= high(ttoken) then
  2371. begin
  2372. write(arraytokeninfo[token].str);
  2373. if not (token in [_CWCHAR, _CWSTRING, _CSTRING, _CCHAR,
  2374. _INTCONST,_REALNUMBER, _ID]) then
  2375. StrAppend(linestr,lowercase(arraytokeninfo[token].str));
  2376. end
  2377. else
  2378. begin
  2379. HasMoreInfos;
  2380. write('Error in Token List');
  2381. break;
  2382. end;
  2383. {idtoken:=}readtoken;
  2384. end;
  2385. case token of
  2386. _CWCHAR,
  2387. _CWSTRING :
  2388. begin
  2389. len:=gettokenbufsizeint;
  2390. setlength(wstring,len);
  2391. move(tokenbuf[tbi],wstring[1],len*2);
  2392. write([' ''',wstring,'''']);
  2393. StrAppend(linestr,' ''');
  2394. StrAppend(linestr,wstring);
  2395. StrAppend(linestr,'''');
  2396. inc(tbi,len*2);
  2397. end;
  2398. _CSTRING:
  2399. begin
  2400. len:=gettokenbufsizeint;
  2401. setlength(astring,len);
  2402. if len>0 then
  2403. move(tokenbuf[tbi],astring[1],len);
  2404. write([' ''',astring,'''']);
  2405. StrAppend(linestr,' ''');
  2406. StrAppend(linestr,astring);
  2407. StrAppend(linestr,'''');
  2408. inc(tbi,len);
  2409. end;
  2410. _CCHAR:
  2411. begin
  2412. write([' ''',unaligned(pshortstring(@tokenbuf[tbi])^),'''']);
  2413. StrAppend(linestr,' ''');
  2414. StrAppend(linestr,unaligned(pshortstring(@tokenbuf[tbi])^));
  2415. StrAppend(linestr,'''');
  2416. inc(tbi,tokenbuf[tbi]+1);
  2417. end;
  2418. _INTCONST,
  2419. _REALNUMBER :
  2420. begin
  2421. write([' ',unaligned(pshortstring(@tokenbuf[tbi])^)]);
  2422. StrAppend(linestr,unaligned(pshortstring(@tokenbuf[tbi])^));
  2423. inc(tbi,tokenbuf[tbi]+1);
  2424. end;
  2425. _ID :
  2426. begin
  2427. write([' ',unaligned(pshortstring(@tokenbuf[tbi])^)]);
  2428. StrAppend(linestr,unaligned(pshortstring(@tokenbuf[tbi])^));
  2429. inc(tbi,tokenbuf[tbi]+1);
  2430. end;
  2431. _GENERICSPECIALTOKEN:
  2432. begin
  2433. { Short version of column change,
  2434. byte or $80 used }
  2435. if (tokenbuf[tbi] and $80)<>0 then
  2436. begin
  2437. new_col:=tokenbuf[tbi] and $7f;
  2438. write(['Col: ',new_col]);
  2439. if length(linestr)<new_col-1 then
  2440. StrAppend(linestr,StringOfChar(' ',new_col - 1 - length(linestr)));
  2441. inc(tbi);
  2442. last_col:=new_col;
  2443. end
  2444. else
  2445. case tspecialgenerictoken(tokenbuf[tbi]) of
  2446. ST_LOADSETTINGS:
  2447. begin
  2448. inc(tbi);
  2449. write('Settings: ');
  2450. fillchar(new_settings,sizeof(new_settings),#0);
  2451. { This does not load pmessage pointer }
  2452. new_settings.pmessage:=nil;
  2453. { TSettings size depends in target...
  2454. We first read the size of the copied part }
  2455. { Still not cross endian ready :( }
  2456. copy_size:=gettokenbufsizeint;
  2457. stbi:=tbi;
  2458. tokenreadsettings(new_settings, copy_size);
  2459. tbi:=stbi+copy_size;
  2460. dump_new_settings;
  2461. writeln;
  2462. end;
  2463. ST_LOADMESSAGES:
  2464. begin
  2465. inc(tbi);
  2466. write('Messages:');
  2467. mesgnb:=tokenbuf[tbi];
  2468. inc(tbi);
  2469. for nb:=1 to mesgnb do
  2470. begin
  2471. {msgvalue:=}gettokenbufsizeint;
  2472. inc(tbi,sizeof(sizeint));
  2473. //state:=tmsgstate(gettokenbufsizeint);
  2474. end;
  2475. end;
  2476. ST_LINE:
  2477. begin
  2478. inc(tbi);
  2479. new_line:=gettokenbufdword;
  2480. if (new_line<>last_line) then
  2481. begin
  2482. StrAppend(genstr,linestr+LineEnding);
  2483. linestr:='';
  2484. end;
  2485. write(['Line: ',new_line]);
  2486. last_line:=new_line;
  2487. end;
  2488. ST_COLUMN:
  2489. begin
  2490. inc(tbi);
  2491. new_col:=gettokenbufword;
  2492. write(['Col: ',new_col]);
  2493. if length(linestr)<new_col - 1 then
  2494. StrAppend(linestr,StringOfChar(' ',new_col - 1 - length(linestr)));
  2495. last_col:=new_col;
  2496. end;
  2497. ST_FILEINDEX:
  2498. begin
  2499. inc(tbi);
  2500. StrAppend(genstr,linestr+LineEnding);
  2501. linestr:='';
  2502. write(['File: ',gettokenbufword]);
  2503. end;
  2504. else
  2505. begin
  2506. HasMoreInfos;
  2507. write('Error in Token List');
  2508. break;
  2509. end;
  2510. end;
  2511. end;
  2512. else ; { empty else to avoid warning }
  2513. end;
  2514. if tbi<tokenbufsize then
  2515. write(',');
  2516. end;
  2517. writeln;
  2518. StrAppend(genstr,linestr);
  2519. writeln(genstr);
  2520. freemem(tokenbuf);
  2521. end;
  2522. if df_specialization in defoptions then
  2523. begin
  2524. write ([space,' Orig. GenericDef : ']);
  2525. readderef('');
  2526. end;
  2527. space:=space+' ';
  2528. readattrs(def);
  2529. delete(space,1,4);
  2530. current_defoptions:=defoptions;
  2531. end;
  2532. { Read abstract procdef and return if inline procdef }
  2533. { type tproccalloption is in globtype unit }
  2534. { type tproctypeoption is in globtype unit }
  2535. { type tprocoption is in globtype unit }
  2536. procedure read_abstract_proc_def(var proccalloption:tproccalloption;var procoptions:tprocoptions; ProcDef: TPpuProcDef);
  2537. type
  2538. tproccallopt=record
  2539. mask : tproccalloption;
  2540. str : string[30];
  2541. end;
  2542. tproctypeopt=record
  2543. mask : tproctypeoption;
  2544. str : string[30];
  2545. end;
  2546. tprocopt=record
  2547. mask : tprocoption;
  2548. str : string[34];
  2549. end;
  2550. const
  2551. {proccalloptionStr is also in globtype unit }
  2552. proctypeopt : array[1..ord(high(tproctypeoption))] of tproctypeopt=(
  2553. (mask:potype_proginit; str:'ProgInit'),
  2554. (mask:potype_unitinit; str:'UnitInit'),
  2555. (mask:potype_unitfinalize; str:'UnitFinalize'),
  2556. (mask:potype_constructor; str:'Constructor'),
  2557. (mask:potype_destructor; str:'Destructor'),
  2558. (mask:potype_operator; str:'Operator'),
  2559. (mask:potype_procedure; str:'Procedure'),
  2560. (mask:potype_function; str:'Function'),
  2561. (mask:potype_class_constructor; str:'Class Constructor'),
  2562. (mask:potype_class_destructor; str:'Class Destructor'),
  2563. { Dispinterface property accessors }
  2564. (mask:potype_propgetter; str:'Property Getter'),
  2565. (mask:potype_propsetter; str:'Property Setter'),
  2566. (mask:potype_exceptfilter; str:'SEH filter'),
  2567. (mask:potype_mainstub; str:'main stub'),
  2568. (mask:potype_pkgstub; str:'package stub'),
  2569. (mask:potype_libmainstub; str:'library main stub')
  2570. );
  2571. procopt : array[1..ord(high(tprocoption))] of tprocopt=(
  2572. (mask:po_classmethod; str:'ClassMethod'),
  2573. (mask:po_virtualmethod; str:'VirtualMethod'),
  2574. (mask:po_abstractmethod; str:'AbstractMethod'),
  2575. (mask:po_finalmethod; str:'FinalMethod'),
  2576. (mask:po_staticmethod; str:'StaticMethod'),
  2577. (mask:po_overridingmethod;str:'OverridingMethod'),
  2578. (mask:po_methodpointer; str:'MethodPointer'),
  2579. (mask:po_interrupt; str:'Interrupt'),
  2580. (mask:po_iocheck; str:'IOCheck'),
  2581. (mask:po_assembler; str:'Assembler'),
  2582. (mask:po_msgstr; str:'MsgStr'),
  2583. (mask:po_msgint; str:'MsgInt'),
  2584. (mask:po_exports; str:'Exports'),
  2585. (mask:po_external; str:'External'),
  2586. (mask:po_overload; str:'Overload'),
  2587. (mask:po_varargs; str:'VarArgs'),
  2588. (mask:po_internconst; str:'InternConst'),
  2589. (mask:po_addressonly; str:'AddressOnly'),
  2590. (mask:po_public; str:'Public'),
  2591. (mask:po_hascallingconvention;str:'HasCallingConvention'),
  2592. (mask:po_reintroduce; str:'ReIntroduce'),
  2593. (mask:po_explicitparaloc; str:'ExplicitParaloc'),
  2594. (mask:po_nostackframe; str:'NoStackFrame'),
  2595. (mask:po_has_mangledname; str:'HasMangledName'),
  2596. (mask:po_has_public_name; str:'HasPublicName'),
  2597. (mask:po_forward; str:'Forward'),
  2598. (mask:po_global; str:'Global'),
  2599. (mask:po_syscall; str:'Syscall'),
  2600. (mask:po_syscall_legacy; str:'SyscallLegacy'),
  2601. (mask:po_syscall_basenone;str:'SyscallBaseNone'),
  2602. (mask:po_syscall_basefirst;str:'SyscallBaseFirst'),
  2603. (mask:po_syscall_baselast;str:'SyscallBaseLast'),
  2604. (mask:po_syscall_basereg; str:'SyscallBaseReg'),
  2605. (mask:po_syscall_has_libsym; str:'Has LibSym'),
  2606. (mask:po_syscall_has_importnr; str:'Uses ImportNr'),
  2607. (mask:po_inline; str:'Inline'),
  2608. (mask:po_compilerproc; str:'CompilerProc'),
  2609. (mask:po_has_importdll; str:'HasImportDLL'),
  2610. (mask:po_has_importname; str:'HasImportName'),
  2611. (mask:po_kylixlocal; str:'KylixLocal'),
  2612. (mask:po_dispid; str:'DispId'),
  2613. (mask:po_weakexternal; str:'WeakExternal'),
  2614. (mask:po_objc; str:'ObjC'),
  2615. (mask:po_enumerator_movenext; str:'EnumeratorMoveNext'),
  2616. (mask:po_optional; str: 'Optional'),
  2617. (mask:po_delphi_nested_cc;str: 'Delphi-style nested frameptr'),
  2618. (mask:po_java_nonvirtual; str: 'Java non-virtual method'),
  2619. (mask:po_ignore_for_overload_resolution;str: 'Ignored for overload resolution'),
  2620. (mask:po_rtlproc; str: 'RTL procedure'),
  2621. (mask:po_auto_raised_visibility; str: 'Visibility raised by compiler'),
  2622. (mask:po_far; str: 'Far'),
  2623. (mask:po_hasnearfarcallmodel; str: 'Near/Far explicit'),
  2624. (mask:po_noreturn; str: 'No return'),
  2625. (mask:po_is_function_ref; str: 'Function reference'),
  2626. (mask:po_is_block; str: 'C "Block"'),
  2627. (mask:po_is_auto_getter; str: 'Automatically generated getter'),
  2628. (mask:po_is_auto_setter; str: 'Automatically generated setter'),
  2629. (mask:po_noinline; str: 'Never inline'),
  2630. (mask:po_variadic; str: 'C VarArgs with array-of-const para')
  2631. );
  2632. var
  2633. proctypeoption : tproctypeoption;
  2634. i : longint;
  2635. first : boolean;
  2636. begin
  2637. write([space,' Return type : ']);
  2638. readderef('', ProcDef.ReturnType);
  2639. proctypeoption:=tproctypeoption(ppufile.getbyte);
  2640. case proctypeoption of
  2641. potype_function: Include(ProcDef.Options, poFunction);
  2642. potype_procedure: Include(ProcDef.Options, poProcedure);
  2643. potype_constructor: Include(ProcDef.Options, poConstructor);
  2644. potype_destructor: Include(ProcDef.Options, poDestructor);
  2645. potype_operator: Include(ProcDef.Options, poOperator);
  2646. end;
  2647. write([space,' TypeOption : ']);
  2648. first:=true;
  2649. for i:=1 to high(proctypeopt) do
  2650. if (proctypeopt[i].mask=proctypeoption) then
  2651. begin
  2652. if first then
  2653. first:=false
  2654. else
  2655. write(', ');
  2656. write(proctypeopt[i].str);
  2657. end;
  2658. writeln;
  2659. proccalloption:=tproccalloption(ppufile.getbyte);
  2660. writeln([space,' CallOption : ',proccalloptionStr[proccalloption]]);
  2661. ppufile.getnormalset(procoptions);
  2662. if procoptions<>[] then
  2663. begin
  2664. if po_classmethod in procoptions then Include(ProcDef.Options, poClassMethod);
  2665. if po_virtualmethod in procoptions then Include(ProcDef.Options, poVirtual);
  2666. if po_abstractmethod in procoptions then Include(ProcDef.Options, poAbstract);
  2667. if po_overridingmethod in procoptions then Include(ProcDef.Options, poOverriding);
  2668. if po_overload in procoptions then Include(ProcDef.Options, poOverload);
  2669. if po_inline in procoptions then Include(ProcDef.Options, poInline);
  2670. if (po_methodpointer in procoptions) and (ProcDef.DefType = dtProcType) then
  2671. TPpuProcTypeDef(ProcDef).MethodPtr:=True;
  2672. write([space,' Options : ']);
  2673. first:=true;
  2674. for i:=1 to high(procopt) do
  2675. if (procopt[i].mask in procoptions) then
  2676. begin
  2677. if first then
  2678. first:=false
  2679. else
  2680. write(', ');
  2681. write(procopt[i].str);
  2682. end;
  2683. writeln;
  2684. end;
  2685. if (po_explicitparaloc in procoptions) then
  2686. begin
  2687. readcgpara(space);
  2688. end;
  2689. end;
  2690. { type tvaroption is in unit symconst }
  2691. { register variable }
  2692. { type tvarregable is in unit symconst }
  2693. procedure readabstractvarsym(const s:string;var varoptions:tvaroptions; VarDef: TPpuVarDef = nil);
  2694. type
  2695. tvaropt=record
  2696. mask : tvaroption;
  2697. str : string[30];
  2698. end;
  2699. const
  2700. varopt : array[1..ord(high(tvaroption))] of tvaropt=(
  2701. (mask:vo_is_external; str:'External'),
  2702. (mask:vo_is_dll_var; str:'DLLVar'),
  2703. (mask:vo_is_thread_var; str:'ThreadVar'),
  2704. (mask:vo_has_local_copy; str:'HasLocalCopy'),
  2705. (mask:vo_is_const; str:'Constant'),
  2706. (mask:vo_is_public; str:'Public'),
  2707. (mask:vo_is_high_para; str:'HighValue'),
  2708. (mask:vo_is_funcret; str:'Funcret'),
  2709. (mask:vo_is_self; str:'Self'),
  2710. (mask:vo_is_vmt; str:'VMT'),
  2711. (mask:vo_is_result; str:'Result'),
  2712. (mask:vo_is_parentfp; str:'ParentFP'),
  2713. (mask:vo_is_loop_counter; str:'LoopCounter'),
  2714. (mask:vo_is_hidden_para; str:'Hidden'),
  2715. (mask:vo_has_explicit_paraloc;str:'ExplicitParaloc'),
  2716. (mask:vo_is_syscall_lib; str:'SysCallLib'),
  2717. (mask:vo_has_mangledname; str:'HasMangledName'),
  2718. (mask:vo_is_typed_const; str:'TypedConst'),
  2719. (mask:vo_is_range_check; str:'RangeCheckSwitch'),
  2720. (mask:vo_is_overflow_check; str:'OverflowCheckSwitch'),
  2721. (mask:vo_is_typinfo_para; str:'TypeInfo'),
  2722. (mask:vo_is_msgsel;str:'MsgSel'),
  2723. (mask:vo_is_weak_external;str:'WeakExternal'),
  2724. (mask:vo_is_first_field;str:'IsFirstField'),
  2725. (mask:vo_volatile; str:'Volatile'),
  2726. (mask:vo_has_section; str:'HasSection'),
  2727. (mask:vo_force_finalize; str:'ForceFinalize'),
  2728. (mask:vo_is_default_var; str:'DefaultIntrinsicVar'),
  2729. (mask:vo_is_far; str:'IsFar')
  2730. );
  2731. var
  2732. i : longint;
  2733. first : boolean;
  2734. begin
  2735. readcommonsym(s, VarDef);
  2736. i:=ppufile.getbyte;
  2737. if (VarDef <> nil) and (VarDef.DefType = dtParam) then
  2738. with TPpuParamDef(VarDef) do
  2739. case tvarspez(i) of
  2740. vs_value: Spez:=psValue;
  2741. vs_var: Spez:=psVar;
  2742. vs_out: Spez:=psOut;
  2743. vs_const: Spez:=psConst;
  2744. vs_constref: Spez:=psConstRef;
  2745. end;
  2746. writeln([space,' Spez : ',Varspez2Str(i)]);
  2747. writeln([space,' Regable : ',Varregable2Str(ppufile.getbyte)]);
  2748. writeln([space,' Addr Taken : ',(ppufile.getbyte<>0)]);
  2749. writeln([space,'Escaped Scope : ',(ppufile.getbyte<>0)]);
  2750. write ([space,' Var Type : ']);
  2751. if VarDef <> nil then
  2752. readderef('',VarDef.VarType)
  2753. else
  2754. readderef('');
  2755. ppufile.getsmallset(varoptions);
  2756. if varoptions<>[] then
  2757. begin
  2758. if (VarDef <> nil) and (VarDef.DefType = dtParam) and (vo_is_hidden_para in varoptions) then
  2759. TPpuParamDef(VarDef).Spez:=psHidden;
  2760. write([space,' Options : ']);
  2761. first:=true;
  2762. for i:=1 to high(varopt) do
  2763. if (varopt[i].mask in varoptions) then
  2764. begin
  2765. if first then
  2766. first:=false
  2767. else
  2768. write(', ');
  2769. write(varopt[i].str);
  2770. end;
  2771. writeln;
  2772. end;
  2773. end;
  2774. procedure readobjectdefoptions(ObjDef: TPpuObjectDef = nil);
  2775. type
  2776. tsymopt=record
  2777. mask : tobjectoption;
  2778. str : string[30];
  2779. end;
  2780. const
  2781. symopt : array[1..ord(high(tobjectoption))] of tsymopt=(
  2782. (mask:oo_is_forward; str:'IsForward'),
  2783. (mask:oo_is_abstract; str:'IsAbstract'),
  2784. (mask:oo_is_sealed; str:'IsSealed'),
  2785. (mask:oo_has_virtual; str:'HasVirtual'),
  2786. (mask:oo_has_private; str:'HasPrivate'),
  2787. (mask:oo_has_protected; str:'HasProtected'),
  2788. (mask:oo_has_strictprivate; str:'HasStrictPrivate'),
  2789. (mask:oo_has_strictprotected;str:'HasStrictProtected'),
  2790. (mask:oo_has_constructor; str:'HasConstructor'),
  2791. (mask:oo_has_destructor; str:'HasDestructor'),
  2792. (mask:oo_has_vmt; str:'HasVMT'),
  2793. (mask:oo_has_msgstr; str:'HasMsgStr'),
  2794. (mask:oo_has_msgint; str:'HasMsgInt'),
  2795. (mask:oo_can_have_published; str:'CanHavePublished'),
  2796. (mask:oo_has_default_property;str:'HasDefaultProperty'),
  2797. (mask:oo_has_valid_guid; str:'HasValidGUID'),
  2798. (mask:oo_has_enumerator_movenext; str:'HasEnumeratorMoveNext'),
  2799. (mask:oo_has_enumerator_current; str:'HasEnumeratorCurrent'),
  2800. (mask:oo_is_external; str:'External'),
  2801. (mask:oo_is_formal; str:'Formal'),
  2802. (mask:oo_is_classhelper; str:'Class Helper/Category'),
  2803. (mask:oo_has_class_constructor; str:'HasClassConstructor'),
  2804. (mask:oo_has_class_destructor; str:'HasClassDestructor'),
  2805. (mask:oo_is_enum_class; str:'JvmEnumClass'),
  2806. (mask:oo_has_new_destructor; str:'HasNewDestructor')
  2807. );
  2808. var
  2809. i : longint;
  2810. first : boolean;
  2811. begin
  2812. ppufile.getsmallset(current_objectoptions);
  2813. if current_objectoptions<>[] then
  2814. begin
  2815. if ObjDef <> nil then
  2816. begin
  2817. if oo_is_abstract in current_objectoptions then
  2818. Include(ObjDef.Options, ooIsAbstract);
  2819. end;
  2820. first:=true;
  2821. for i:=1 to high(symopt) do
  2822. if (symopt[i].mask in current_objectoptions) then
  2823. begin
  2824. if first then
  2825. first:=false
  2826. else
  2827. write(', ');
  2828. write(symopt[i].str);
  2829. end;
  2830. end;
  2831. writeln;
  2832. end;
  2833. procedure readprocimploptions(const space: string; out implprocoptions: timplprocoptions);
  2834. type
  2835. tpiopt=record
  2836. mask : timplprocoption;
  2837. str : string[30];
  2838. end;
  2839. const
  2840. piopt : array[low(timplprocoption)..high(timplprocoption)] of tpiopt=(
  2841. (mask:pio_empty; str:'IsEmpty'),
  2842. (mask:pio_has_inlininginfo; str:'HasInliningInfo'),
  2843. (mask:pio_inline_not_possible; str:'InlineNotPossible'),
  2844. (mask:pio_nested_access; str:'NestedAccess')
  2845. );
  2846. var
  2847. i: timplprocoption;
  2848. first: boolean;
  2849. begin
  2850. ppufile.getsmallset(implprocoptions);
  2851. if implprocoptions<>[] then
  2852. begin
  2853. first:=true;
  2854. write([space,' Options : ']);
  2855. for i:=low(piopt) to high(piopt) do
  2856. begin
  2857. if i in implprocoptions then
  2858. begin
  2859. if first then
  2860. first:=false
  2861. else
  2862. write(', ');
  2863. write(piopt[i].str);
  2864. end;
  2865. end;
  2866. writeln;
  2867. end;
  2868. end;
  2869. procedure readarraydefoptions(ArrayDef: TPpuArrayDef);
  2870. { type tarraydefoption is in unit symconst }
  2871. const
  2872. symopt : array[tarraydefoption] of string = (
  2873. { ado_IsConvertedPointer } 'ConvertedPointer',
  2874. { ado_IsDynamicArray } 'IsDynamicArray',
  2875. { ado_IsVariant } 'IsVariant',
  2876. { ado_IsConstructor } 'IsConstructor',
  2877. { ado_IsArrayOfConst } 'ArrayOfConst',
  2878. { ado_IsConstString } 'ConstString',
  2879. { ado_IsBitPacked } 'BitPacked'
  2880. );
  2881. var
  2882. symoptions: tarraydefoptions;
  2883. i: tarraydefoption;
  2884. first: boolean;
  2885. begin
  2886. ppufile.getsmallset(symoptions);
  2887. if symoptions<>[] then
  2888. begin
  2889. if ado_IsDynamicArray in symoptions then Include(ArrayDef.Options, aoDynamic);
  2890. first:=true;
  2891. for i:=Low(symopt) to high(symopt) do
  2892. if (i in symoptions) then
  2893. begin
  2894. if first then
  2895. first:=false
  2896. else
  2897. write(', ');
  2898. write(symopt[i]);
  2899. end;
  2900. end;
  2901. writeln;
  2902. end;
  2903. (* options for properties
  2904. tpropertyoption=(ppo_none,
  2905. ppo_indexed,
  2906. ppo_defaultproperty,
  2907. ppo_stored,
  2908. ppo_hasparameters,
  2909. ppo_implements,
  2910. ppo_enumerator_current,
  2911. ppo_overrides,
  2912. ppo_dispid_write { no longer used }
  2913. );
  2914. tpropertyoptions=set of tpropertyoption;
  2915. *)
  2916. function readpropertyoptions:tpropertyoptions;
  2917. { type tarraydefoption is in unit symconst }
  2918. type
  2919. tpropopt=record
  2920. mask : tpropertyoption;
  2921. str : string[30];
  2922. end;
  2923. const
  2924. symopt : array[1..ord(high(tpropertyoption))] of tpropopt=(
  2925. (mask:ppo_indexed;str:'indexed'),
  2926. (mask:ppo_defaultproperty;str:'default'),
  2927. (mask:ppo_stored;str:'stored'),
  2928. (mask:ppo_hasparameters;str:'has parameters'),
  2929. (mask:ppo_implements;str:'implements'),
  2930. (mask:ppo_enumerator_current;str:'enumerator current'),
  2931. (mask:ppo_overrides;str:'overrides'),
  2932. (mask:ppo_dispid_write;str:'dispid write') { no longer used }
  2933. );
  2934. var
  2935. i : longint;
  2936. first : boolean;
  2937. begin
  2938. ppufile.getsmallset(result);
  2939. if result<>[] then
  2940. begin
  2941. first:=true;
  2942. for i:=1 to high(symopt) do
  2943. if (symopt[i].mask in result) then
  2944. begin
  2945. if first then
  2946. first:=false
  2947. else
  2948. write(', ');
  2949. write(symopt[i].str);
  2950. end;
  2951. end;
  2952. writeln;
  2953. end;
  2954. function readmanagementoperatoroptions(const space : string;const name : string):tmanagementoperators;
  2955. { type is in unit symconst }
  2956. { Management operator options
  2957. tmanagementoperator=(
  2958. mop_none,
  2959. mop_initialize,
  2960. mop_finalize,
  2961. mop_addref,
  2962. mop_copy);
  2963. }
  2964. type
  2965. tmopopt=record
  2966. mask : tmanagementoperator;
  2967. str : string[10];
  2968. end;
  2969. const
  2970. managementoperatoropt : array[1..ord(high(tmanagementoperator))] of tmopopt=(
  2971. (mask:mop_initialize;str:'initialize'),
  2972. (mask:mop_finalize;str:'finalize'),
  2973. (mask:mop_addref;str:'addref'),
  2974. (mask:mop_copy;str:'copy')
  2975. );
  2976. var
  2977. i : longint;
  2978. first : boolean;
  2979. begin
  2980. ppufile.getsmallset(result);
  2981. if result<>[] then
  2982. begin
  2983. first:=true;
  2984. for i:=1 to high(managementoperatoropt) do
  2985. if (managementoperatoropt[i].mask in result) then
  2986. begin
  2987. if first then
  2988. begin
  2989. write(space);
  2990. write(name);
  2991. write(': ');
  2992. first:=false;
  2993. end
  2994. else
  2995. write(', ');
  2996. write(managementoperatoropt[i].str);
  2997. end;
  2998. if not first then
  2999. writeln;
  3000. end;
  3001. end;
  3002. procedure readnodetree;
  3003. var
  3004. l : longint;
  3005. p : pointer;
  3006. begin
  3007. with ppufile do
  3008. begin
  3009. if space<>'' then
  3010. Writeln([space,'------ nodetree ------']);
  3011. if readentry=ibnodetree then
  3012. begin
  3013. l:=entrysize;
  3014. Writeln([space,'Tree size : ',l]);
  3015. { Read data to prevent error that entry is not completly read }
  3016. getmem(p,l);
  3017. getdata(p^,l);
  3018. freemem(p);
  3019. end
  3020. else
  3021. begin
  3022. WriteError('!! ibnodetree not found');
  3023. end;
  3024. end;
  3025. end;
  3026. procedure ReadCreatedObjTypes;
  3027. var
  3028. i,j,
  3029. len,
  3030. bssize: longint;
  3031. bs: pbyte;
  3032. begin
  3033. if ppufile.readentry<>ibcreatedobjtypes then
  3034. begin
  3035. WriteError('!! ibcreatedobjtypes entry not found');
  3036. ppufile.skipdata(ppufile.entrysize);
  3037. exit
  3038. end;
  3039. writeln;
  3040. writeln([space,'WPO info']);
  3041. writeln([space,'--------']);
  3042. len:=ppufile.getlongint;
  3043. writeln([space,'** Instantiated Object/Class types: ',len,' **']);
  3044. space:=space+' ';
  3045. for i:=0 to len-1 do
  3046. readderef(space);
  3047. setlength(space,length(space)-2);
  3048. len:=ppufile.getlongint;
  3049. writeln([space,'** Instantiated ClassRef types: ',len,' **']);
  3050. space:=space+' ';
  3051. for i:=0 to len-1 do
  3052. readderef(space);
  3053. setlength(space,length(space)-2);
  3054. len:=ppufile.getlongint;
  3055. writeln([space,'** Possibly instantiated ClassRef types : ',len,' **']);
  3056. space:=space+' ';
  3057. for i:=0 to len-1 do
  3058. readderef(space);
  3059. setlength(space,length(space)-2);
  3060. len:=ppufile.getlongint;
  3061. writeln([space,'** Class types with called virtual methods info : ',len,' **']);
  3062. space:=space+' ';
  3063. for i:=0 to len-1 do
  3064. begin
  3065. write([space,'Class def : ']);
  3066. readderef('');
  3067. write([space+' ','Called vmtentries : ']);
  3068. bssize:=ppufile.getlongint;
  3069. getmem(bs,bssize);
  3070. ppufile.readdata(bs^,bssize);
  3071. for j:=0 to bssize*8-1 do
  3072. if (((bs+j shr 3)^ shr (j and 7)) and 1) <> 0 then
  3073. write([j,', ']);
  3074. writeln;
  3075. freemem(bs);
  3076. end;
  3077. setlength(space,length(space)-2);
  3078. end;
  3079. {****************************************************************************
  3080. Read Symbols Part
  3081. ****************************************************************************}
  3082. procedure readsymbols(const s:string; ParentDef: TPpuContainerDef = nil);
  3083. function _finddef(symdef: TPpuDef): TPpuDef;
  3084. begin
  3085. Result:=nil;
  3086. if symdef.Ref.IsCurUnit then
  3087. begin;
  3088. Result:=CurUnit.FindById(symdef.Ref.Id);
  3089. if (Result <> nil) and (Result.Ref.Id = symdef.Id) then
  3090. begin
  3091. Result.Name:=symdef.Name;
  3092. Result.FilePos:=symdef.FilePos;
  3093. end
  3094. else
  3095. Result:=nil;
  3096. end;
  3097. end;
  3098. type
  3099. pguid = ^tguid;
  3100. tguid = packed record
  3101. D1: LongWord;
  3102. D2: Word;
  3103. D3: Word;
  3104. D4: array[0..7] of Byte;
  3105. end;
  3106. var
  3107. b : byte;
  3108. pc : pchar;
  3109. ch : dword;
  3110. startnewline : boolean;
  3111. i,j,len : longint;
  3112. prettyname, ss : ansistring;
  3113. ws: widestring;
  3114. guid : tguid;
  3115. realvalue : ppureal;
  3116. doublevalue : double;
  3117. singlevalue : single;
  3118. extended : TSplit80bitReal;
  3119. pw : pcompilerwidestring;
  3120. varoptions : tvaroptions;
  3121. propoptions : tpropertyoptions;
  3122. iexp: Tconstexprint;
  3123. def: TPpuDef;
  3124. constdef: TPpuConstDef absolute def;
  3125. begin
  3126. with ppufile do
  3127. begin
  3128. if space<>'' then
  3129. Writeln([space,'------ ',s,' ------']);
  3130. if readentry=ibstartsyms then
  3131. begin
  3132. Writeln([space,'Symtable count: ',getlongint]);
  3133. end
  3134. else
  3135. Writeln('!! ibstartsym not found');
  3136. repeat
  3137. def:=nil;
  3138. b:=readentry;
  3139. case b of
  3140. ibunitsym :
  3141. readcommonsym('Unit symbol ');
  3142. ibnamespacesym :
  3143. begin
  3144. readcommonsym('NameSpace symbol ');
  3145. write([space,' Hidden Unit : ']);
  3146. readderef('');
  3147. end;
  3148. iblabelsym :
  3149. readcommonsym('Label symbol ');
  3150. ibtypesym :
  3151. begin
  3152. def:=TPpuTypeRef.Create(nil);
  3153. readcommonsym('Type symbol ',def);
  3154. write([space,' Result Type : ']);
  3155. readderef('', def.Ref);
  3156. if _finddef(def) = nil then
  3157. def.Parent:=ParentDef;
  3158. prettyname:=getansistring;
  3159. if prettyname<>'' then
  3160. begin
  3161. write([space,' Pretty Name : ']);
  3162. Writeln(prettyname);
  3163. end;
  3164. end;
  3165. ibprocsym :
  3166. begin
  3167. def:=TPpuDef.Create(nil);
  3168. readcommonsym('Procedure symbol ', def);
  3169. len:=ppufile.getword;
  3170. for i:=1 to len do
  3171. begin
  3172. write([space,' Definition : ']);
  3173. readderef('', def.Ref);
  3174. _finddef(def);
  3175. end;
  3176. end;
  3177. ibconstsym :
  3178. begin
  3179. constdef:=TPpuConstDef.Create(ParentDef);
  3180. readcommonsym('Constant symbol ',constdef);
  3181. b:=getbyte;
  3182. case tconsttyp(b) of
  3183. constord :
  3184. begin
  3185. write ([space,' OrdinalType : ']);
  3186. readderef('',constdef.TypeRef);
  3187. iexp:=getexprint;
  3188. constdef.ConstType:=ctInt;
  3189. constdef.VInt:=iexp.svalue;
  3190. writeln([space,' Value : ',constexp.tostr(iexp)]);
  3191. end;
  3192. constpointer :
  3193. begin
  3194. write ([space,' PointerType : ']);
  3195. readderef('',constdef.TypeRef);
  3196. constdef.ConstType:=ctInt;
  3197. constdef.VInt:=int64(getptruint);
  3198. writeln([space,' Value : ',constdef.VInt])
  3199. end;
  3200. conststring,
  3201. constresourcestring :
  3202. begin
  3203. write ([space,' StringType : ']);
  3204. readderef('',constdef.TypeRef);
  3205. len:=getlongint;
  3206. getmem(pc,len+1);
  3207. getdata(pc^,len);
  3208. (pc+len)^:= #0;
  3209. writeln([space,' Length : ',len]);
  3210. writeln([space,' Value : "',pc,'"']);
  3211. constdef.ConstType:=ctStr;
  3212. SetString(constdef.VStr, pc, len);
  3213. constdef.VStr:=UTF8Encode(constdef.VStr);
  3214. freemem(pc,len+1);
  3215. end;
  3216. constreal :
  3217. begin
  3218. constdef.ConstType:=ctFloat;
  3219. write ([space,' RealType : ']);
  3220. readderef('',constdef.TypeRef);
  3221. write([space,' Value : ']);
  3222. if entryleft=sizeof(ppureal) then
  3223. begin
  3224. realvalue:=getrealsize(sizeof(ppureal));
  3225. constdef.VFloat:=realvalue;
  3226. writeln([realvalue]);
  3227. end
  3228. else if entryleft=sizeof(double) then
  3229. begin
  3230. doublevalue:=getrealsize(sizeof(double));
  3231. constdef.VFloat:=doublevalue;
  3232. writeln([doublevalue]);
  3233. end
  3234. else if entryleft=sizeof(single) then
  3235. begin
  3236. singlevalue:=getrealsize(sizeof(single));
  3237. constdef.VFloat:=singlevalue;
  3238. writeln([singlevalue]);
  3239. end
  3240. else if entryleft=10 then
  3241. begin
  3242. getdata(extended,entryleft);
  3243. ss:=Real80bitToStr(extended);
  3244. constdef.VFloat:=StrToFloat(ss);
  3245. writeln(ss);
  3246. end
  3247. else
  3248. begin
  3249. realvalue:=0.0;
  3250. WriteError('Error reading real value');
  3251. end;
  3252. end;
  3253. constset :
  3254. begin
  3255. constdef.ConstType:=ctSet;
  3256. write ([space,' Set Type : ']);
  3257. readderef('',constdef.TypeRef);
  3258. for i:=1to 4 do
  3259. begin
  3260. write ([space,' Value : ']);
  3261. for j:=1to 8 do
  3262. begin
  3263. if j>1 then
  3264. write(',');
  3265. b:=getbyte;
  3266. write(hexstr(b,2));
  3267. constdef.VSet[i*j-1]:=b;
  3268. end;
  3269. writeln;
  3270. end;
  3271. end;
  3272. constnil:
  3273. begin
  3274. write([space,' NIL pointer :']);
  3275. readderef('',constdef.TypeRef);
  3276. constdef.ConstType:=ctPtr;
  3277. constdef.VInt:=0;
  3278. end;
  3279. constwstring :
  3280. begin
  3281. initwidestring(pw);
  3282. setlengthwidestring(pw,getlongint);
  3283. if widecharsize=2 then
  3284. { don't use getdata, because the compilerwidechars may have to
  3285. be byteswapped
  3286. }
  3287. begin
  3288. for i:=0 to pw^.len-1 do
  3289. pw^.data[i]:=ppufile.getword;
  3290. SetString(ws, PWideChar(pw^.data), pw^.len);
  3291. constdef.VStr:=UTF8Encode(ws);
  3292. constdef.ConstType:=ctStr;
  3293. end
  3294. else if widecharsize=4 then
  3295. begin
  3296. for i:=0 to pw^.len-1 do
  3297. pw^.data[i]:=cardinal(ppufile.getlongint);
  3298. end
  3299. else
  3300. begin
  3301. WriteError('Unsupported tcompilerwidechar size');
  3302. end;
  3303. Write([space,'Wide string type']);
  3304. startnewline:=true;
  3305. for i:=0 to pw^.len-1 do
  3306. begin
  3307. if startnewline then
  3308. begin
  3309. writeln;
  3310. write(space);
  3311. startnewline:=false;
  3312. end;
  3313. ch:=pw^.data[i];
  3314. if widecharsize=2 then
  3315. write(hexstr(ch,4))
  3316. else
  3317. write(hexstr(ch,8));
  3318. if ((i + 1) mod 8)= 0 then
  3319. startnewline:=true
  3320. else
  3321. if i <> pw^.len-1 then
  3322. write(', ');
  3323. end;
  3324. donewidestring(pw);
  3325. Writeln;
  3326. end;
  3327. constguid:
  3328. begin
  3329. write ([space,' IntfType : ']);
  3330. readderef('',constdef.TypeRef);
  3331. getdata(guid,sizeof(guid));
  3332. write ([space,' IID String: {',hexstr(guid.d1,8),'-',hexstr(guid.d2,4),'-',hexstr(guid.d3,4),'-']);
  3333. for i:=0 to 7 do
  3334. begin
  3335. write(hexstr(guid.d4[i],2));
  3336. if i=1 then write('-');
  3337. end;
  3338. writeln('}');
  3339. end
  3340. else
  3341. Writeln (['!! Invalid unit format : Invalid const type encountered: ',b]);
  3342. end;
  3343. end;
  3344. ibabsolutevarsym :
  3345. begin
  3346. def:=TPpuVarDef.Create(ParentDef);
  3347. readabstractvarsym('Absolute variable symbol ',varoptions,TPpuVarDef(def));
  3348. Write ([space,' Relocated to ']);
  3349. b:=getbyte;
  3350. case absolutetyp(b) of
  3351. tovar :
  3352. readpropaccesslist(space+' Sym : ');
  3353. toasm :
  3354. Writeln(['Assembler name : ',getstring]);
  3355. toaddr :
  3356. begin
  3357. Write(['Address : ',getpuint]);
  3358. if tsystemcpu(ppufile.header.common.cpu)=cpu_i386 then
  3359. Write([' (Far: ',getbyte<>0,')']);
  3360. if tsystemcpu(ppufile.header.common.cpu)=cpu_i8086 then
  3361. if getbyte<>0 then
  3362. Write([' (Far: TRUE, Segment=',getaword,')'])
  3363. else
  3364. Write([' (Far: FALSE)']);
  3365. Writeln;
  3366. end;
  3367. else
  3368. Writeln (['!! Invalid unit format : Invalid absolute type encountered: ',b]);
  3369. end;
  3370. end;
  3371. ibfieldvarsym :
  3372. begin
  3373. def:=TPpuFieldDef.Create(ParentDef);
  3374. readabstractvarsym('Field Variable symbol ',varoptions,TPpuVarDef(def));
  3375. writeln([space,' Address : ',getasizeint]);
  3376. if vo_has_mangledname in varoptions then
  3377. writeln([space,' Mangled name : ',getstring]);
  3378. end;
  3379. ibstaticvarsym :
  3380. begin
  3381. def:=TPpuVarDef.Create(ParentDef);
  3382. readabstractvarsym('Global Variable symbol ',varoptions,TPpuVarDef(def));
  3383. write ([space,' DefaultConst : ']);
  3384. readderef('');
  3385. if (vo_has_mangledname in varoptions) then
  3386. writeln([space,'Mangledname : ',readsymstr(ppufile)]);
  3387. if vo_has_section in varoptions then
  3388. writeln(['Section name:',ppufile.getansistring]);
  3389. write ([space,' FieldVarSymDeref: ']);
  3390. readderef('');
  3391. end;
  3392. iblocalvarsym :
  3393. begin
  3394. readabstractvarsym('Local Variable symbol ',varoptions);
  3395. write ([space,' DefaultConst : ']);
  3396. readderef('');
  3397. end;
  3398. ibparavarsym :
  3399. begin
  3400. def:=TPpuParamDef.Create(ParentDef);
  3401. readabstractvarsym('Parameter Variable symbol ',varoptions,TPpuVarDef(def));
  3402. write ([space,' DefaultConst : ']);
  3403. readderef('',TPpuParamDef(def).DefaultValue);
  3404. writeln([space,' ParaNr : ',getword]);
  3405. writeln([space,' Univ : ',getboolean]);
  3406. writeln([space,' VarState : ',getbyte]);
  3407. writeln([space,' Refs : ',getbyte]);
  3408. if (vo_has_explicit_paraloc in varoptions) then
  3409. begin
  3410. readcgpara(space+' ');
  3411. end;
  3412. end;
  3413. ibenumsym :
  3414. begin
  3415. def:=TPpuConstDef.Create(nil);
  3416. readcommonsym('Enumeration symbol ',def);
  3417. write ([space,' Definition : ']);
  3418. readderef('');
  3419. TPpuConstDef(def).ConstType:=ctInt;
  3420. TPpuConstDef(def).VInt:=getlongint;
  3421. writeln([space,' Value : ',TPpuConstDef(def).VInt]);
  3422. if (ParentDef <> nil) and (ParentDef.DefType = dtEnum) then
  3423. def.Parent:=ParentDef;
  3424. end;
  3425. ibsyssym :
  3426. begin
  3427. readcommonsym('Internal system symbol ');
  3428. writeln([space,' Internal Nr : ',getlongint]);
  3429. end;
  3430. ibmacrosym :
  3431. begin
  3432. readcommonsym('Macro symbol ');
  3433. writeln([space,' Defined: ',getboolean]);
  3434. writeln([space,' Compiler var: ',getboolean]);
  3435. len:=getlongint;
  3436. writeln([space,' Value length: ',len]);
  3437. if len > 0 then
  3438. begin
  3439. getmem(pc,len+1);
  3440. getdata(pc^,len);
  3441. (pc+len)^:= #0;
  3442. writeln([space,' Value: "',pc,'"']);
  3443. freemem(pc,len+1);
  3444. end;
  3445. end;
  3446. ibpropertysym :
  3447. begin
  3448. def:=TPpuPropDef.Create(ParentDef);
  3449. readcommonsym('Property ',def);
  3450. write ([space,' Prop Options : ']);
  3451. propoptions:=readpropertyoptions;
  3452. if ppo_overrides in propoptions then
  3453. begin
  3454. write ([space,' OverrideProp : ']);
  3455. readderef('');
  3456. end;
  3457. if ppo_defaultproperty in propoptions then
  3458. Include(TPpuPropDef(def).Options, poDefault);
  3459. write ([space,' Prop Type : ']);
  3460. readderef('',TPpuPropDef(def).PropType);
  3461. writeln([space,' Index : ',getlongint]);
  3462. writeln([space,' Default : ',getlongint]);
  3463. write ([space,' Index Type : ']);
  3464. readderef('');
  3465. { palt_none }
  3466. write ([space,' Noneaccess : ']);
  3467. readpropaccesslist('');
  3468. write ([space,' Readaccess : ']);
  3469. readpropaccesslist(space+' Sym: ',TPpuPropDef(def).Getter);
  3470. write ([space,' Writeaccess : ']);
  3471. readpropaccesslist(space+' Sym: ',TPpuPropDef(def).Setter);
  3472. write ([space,' Storedaccess : ']);
  3473. readpropaccesslist(space+' Sym: ');
  3474. if [ppo_hasparameters,ppo_overrides]*propoptions=[ppo_hasparameters] then
  3475. begin
  3476. space:=' '+space;
  3477. readsymtable('parast',TPpuPropDef(def));
  3478. delete(space,1,4);
  3479. end;
  3480. end;
  3481. iberror :
  3482. begin
  3483. WriteError('!! Error in PPU');
  3484. exit;
  3485. end;
  3486. ibendsyms :
  3487. break;
  3488. else
  3489. begin
  3490. WriteError('!! Skipping unsupported PPU Entry in Symbols: '+IntToStr(b));
  3491. end;
  3492. end;
  3493. if assigned(def) then
  3494. readsymsubentries(def);
  3495. if (def <> nil) and (def.Parent = nil) then
  3496. def.Free;
  3497. if not EndOfEntry then
  3498. HasMoreInfos;
  3499. until false;
  3500. end;
  3501. end;
  3502. {****************************************************************************
  3503. Read defintions Part
  3504. ****************************************************************************}
  3505. procedure readdefinitions(const s:string; ParentDef: TPpuContainerDef);
  3506. { type tordtype is in symconst unit }
  3507. {
  3508. uvoid,
  3509. u8bit,u16bit,u32bit,u64bit,u128bit,
  3510. s8bit,s16bit,s32bit,s64bit,s128bit,
  3511. bool8bit,bool16bit,bool32bit,bool64bit,
  3512. uchar,uwidechar,scurrency,customint
  3513. ); }
  3514. { type tobjecttyp is in symconst unit }
  3515. { type tvarianttype is in symconst unit }
  3516. { type thelpertype is in symconst unit }
  3517. var
  3518. b : byte;
  3519. otb : byte; { Object Type byte, needed later again }
  3520. l,j,tokenbufsize : longint;
  3521. tokenbuf : pbyte;
  3522. calloption : tproccalloption;
  3523. procoptions : tprocoptions;
  3524. implprocoptions: timplprocoptions;
  3525. defoptions: tdefoptions;
  3526. iexpr: Tconstexprint;
  3527. def: TPpuDef;
  3528. objdef: TPpuObjectDef absolute def;
  3529. arrdef: TPpuArrayDef absolute def;
  3530. enumdef: TPpuEnumDef absolute def;
  3531. setdef: TPpuSetDef absolute def;
  3532. orddef: TPpuOrdDef absolute def;
  3533. floatdef: TPpuFloatDef absolute def;
  3534. strdef: TPpuStringDef absolute def;
  3535. filedef: TPpuFileDef absolute def;
  3536. begin
  3537. with ppufile do
  3538. begin
  3539. if space<>'' then
  3540. Writeln([space,'------ ',s,' ------']);
  3541. if readentry<>ibstartdefs then
  3542. Writeln('!! ibstartdefs not found');
  3543. repeat
  3544. def:=nil;
  3545. b:=readentry;
  3546. case b of
  3547. ibpointerdef :
  3548. begin
  3549. def:=TPpuPointerDef.Create(ParentDef);
  3550. readcommondef('Pointer definition',defoptions,def);
  3551. write ([space,' Pointed Type : ']);
  3552. readderef('',TPpuPointerDef(def).Ptr);
  3553. writeln([space,' Has Pointer Math : ',(getbyte<>0)]);
  3554. if tsystemcpu(ppufile.header.common.cpu) in [cpu_i8086,cpu_i386,cpu_x86_64] then
  3555. begin
  3556. write([space,' X86 Pointer Type : ']);
  3557. b:=getbyte;
  3558. case tx86pointertyp(b) of
  3559. x86pt_near: writeln('Near');
  3560. x86pt_near_cs: writeln('Near ''CS''');
  3561. x86pt_near_ds: writeln('Near ''DS''');
  3562. x86pt_near_ss: writeln('Near ''SS''');
  3563. x86pt_near_es: writeln('Near ''ES''');
  3564. x86pt_near_fs: writeln('Near ''FS''');
  3565. x86pt_near_gs: writeln('Near ''GS''');
  3566. x86pt_far: writeln('Far');
  3567. x86pt_huge: writeln('Huge');
  3568. else
  3569. WriteWarning('Invalid x86 pointer type: ' + IntToStr(b));
  3570. end;
  3571. end;
  3572. end;
  3573. iborddef :
  3574. begin
  3575. orddef:=TPpuOrdDef.Create(ParentDef);
  3576. readcommondef('Ordinal definition',defoptions,orddef);
  3577. write ([space,' Base type : ']);
  3578. b:=getbyte;
  3579. case tordtype(b) of
  3580. uvoid:
  3581. begin
  3582. writeln('uvoid');
  3583. orddef.OrdType:=otVoid;
  3584. end;
  3585. u8bit:
  3586. begin
  3587. writeln('u8bit');
  3588. orddef.OrdType:=otUInt;
  3589. orddef.Size:=1;
  3590. end;
  3591. u16bit:
  3592. begin
  3593. writeln('u16bit');
  3594. orddef.OrdType:=otUInt;
  3595. orddef.Size:=2;
  3596. end;
  3597. u32bit:
  3598. begin
  3599. writeln('u32bit');
  3600. orddef.OrdType:=otUInt;
  3601. orddef.Size:=4;
  3602. end;
  3603. u64bit:
  3604. begin
  3605. writeln('u64bit');
  3606. orddef.OrdType:=otUInt;
  3607. orddef.Size:=8;
  3608. end;
  3609. u128bit:
  3610. begin
  3611. writeln('u128bit');
  3612. orddef.OrdType:=otUInt;
  3613. orddef.Size:=16;
  3614. end;
  3615. s8bit:
  3616. begin
  3617. writeln('s8bit');
  3618. orddef.OrdType:=otSInt;
  3619. orddef.Size:=1;
  3620. end;
  3621. s16bit:
  3622. begin
  3623. writeln('s16bit');
  3624. orddef.OrdType:=otSInt;
  3625. orddef.Size:=2;
  3626. end;
  3627. s32bit:
  3628. begin
  3629. writeln('s32bit');
  3630. orddef.OrdType:=otSInt;
  3631. orddef.Size:=4;
  3632. end;
  3633. s64bit:
  3634. begin
  3635. writeln('s64bit');
  3636. orddef.OrdType:=otSInt;
  3637. orddef.Size:=8;
  3638. end;
  3639. s128bit:
  3640. begin
  3641. writeln('s128bit');
  3642. orddef.OrdType:=otSInt;
  3643. orddef.Size:=16;
  3644. end;
  3645. pasbool1:
  3646. begin
  3647. writeln('pasbool1');
  3648. orddef.OrdType:=otPasBool;
  3649. orddef.Size:=1;
  3650. end;
  3651. pasbool8:
  3652. begin
  3653. writeln('pasbool8');
  3654. orddef.OrdType:=otPasBool;
  3655. orddef.Size:=1;
  3656. end;
  3657. pasbool16:
  3658. begin
  3659. writeln('pasbool16');
  3660. orddef.OrdType:=otPasBool;
  3661. orddef.Size:=2;
  3662. end;
  3663. pasbool32:
  3664. begin
  3665. writeln('pasbool32');
  3666. orddef.OrdType:=otPasBool;
  3667. orddef.Size:=4;
  3668. end;
  3669. pasbool64:
  3670. begin
  3671. writeln('pasbool64');
  3672. orddef.OrdType:=otPasBool;
  3673. orddef.Size:=8;
  3674. end;
  3675. bool8bit:
  3676. begin
  3677. writeln('bool8bit');
  3678. orddef.OrdType:=otBool;
  3679. orddef.Size:=1;
  3680. end;
  3681. bool16bit:
  3682. begin
  3683. writeln('bool16bit');
  3684. orddef.OrdType:=otBool;
  3685. orddef.Size:=2;
  3686. end;
  3687. bool32bit:
  3688. begin
  3689. writeln('bool32bit');
  3690. orddef.OrdType:=otBool;
  3691. orddef.Size:=4;
  3692. end;
  3693. bool64bit:
  3694. begin
  3695. writeln('bool64bit');
  3696. orddef.OrdType:=otBool;
  3697. orddef.Size:=8;
  3698. end;
  3699. uchar:
  3700. begin
  3701. writeln('uchar');
  3702. orddef.OrdType:=otChar;
  3703. orddef.Size:=1;
  3704. end;
  3705. uwidechar:
  3706. begin
  3707. writeln('uwidechar');
  3708. orddef.OrdType:=otChar;
  3709. orddef.Size:=2;
  3710. end;
  3711. scurrency:
  3712. begin
  3713. writeln('scurrency');
  3714. orddef.OrdType:=otCurrency;
  3715. orddef.Size:=8;
  3716. end;
  3717. customint:
  3718. begin
  3719. writeln('customint');
  3720. orddef.OrdType:=otSint;
  3721. orddef.Size:=sizeof(ASizeInt);
  3722. end
  3723. else
  3724. WriteWarning('Invalid base type: ' + IntToStr(b));
  3725. end;
  3726. iexpr:=getexprint;
  3727. orddef.RangeLow:=iexpr.svalue;
  3728. write([space,' Range : ',constexp.tostr(iexpr)]);
  3729. iexpr:=getexprint;
  3730. orddef.RangeHigh:=iexpr.svalue;
  3731. writeln([' to ',constexp.tostr(iexpr)]);
  3732. end;
  3733. ibfloatdef :
  3734. begin
  3735. floatdef:=TPpuFloatDef.Create(ParentDef);
  3736. readcommondef('Float definition',defoptions,floatdef);
  3737. write ([space,' Float type : ']);
  3738. b:=getbyte;
  3739. case b of
  3740. ftSingle:
  3741. begin
  3742. writeln('Single');
  3743. floatdef.FloatType:=pftSingle;
  3744. end;
  3745. ftDouble:
  3746. begin
  3747. writeln('Double');
  3748. floatdef.FloatType:=pftDouble;
  3749. end;
  3750. ftExtended:
  3751. begin
  3752. writeln('Extended');
  3753. floatdef.FloatType:=pftExtended;
  3754. end;
  3755. ftComp:
  3756. begin
  3757. writeln('Comp');
  3758. floatdef.FloatType:=pftComp;
  3759. end;
  3760. ftCurr:
  3761. begin
  3762. writeln('Currency');
  3763. floatdef.FloatType:=pftCurrency;
  3764. end;
  3765. ftFloat128:
  3766. begin
  3767. writeln('Float128');
  3768. floatdef.FloatType:=pftFloat128;
  3769. end;
  3770. else
  3771. WriteWarning('Invalid float type: ' + IntToStr(b));
  3772. end;
  3773. end;
  3774. ibarraydef :
  3775. begin
  3776. arrdef:=TPpuArrayDef.Create(ParentDef);
  3777. readcommondef('Array definition',defoptions,arrdef);
  3778. write ([space,' Element type : ']);
  3779. readderef('',arrdef.ElType);
  3780. write ([space,' Range Type : ']);
  3781. readderef('',arrdef.RangeType);
  3782. arrdef.RangeLow:=getasizeint;
  3783. arrdef.RangeHigh:=getasizeint;
  3784. writeln([space,' Range : ',arrdef.RangeLow,' to ',arrdef.RangeHigh]);
  3785. write ([space,' Options : ']);
  3786. readarraydefoptions(arrdef);
  3787. if tsystemcpu(ppufile.header.common.cpu)=cpu_i8086 then
  3788. writeln([space,' Huge : ',(getbyte<>0)]);
  3789. readsymtable('symbols', arrdef);
  3790. end;
  3791. ibprocdef :
  3792. begin
  3793. def:=TPpuProcDef.Create(ParentDef);
  3794. readcommondef('Procedure definition',defoptions,def);
  3795. read_abstract_proc_def(calloption,procoptions,TPpuProcDef(def));
  3796. if (po_has_mangledname in procoptions) then
  3797. writeln([space,' Mangled name : ',readsymstr(ppufile)]);
  3798. writeln([space,' Number : ',getword]);
  3799. writeln([space,' Level : ',getbyte]);
  3800. write ([space,' Class : ']);
  3801. readderef('');
  3802. write ([space,' Procsym : ']);
  3803. readderef('', def.Ref);
  3804. write ([space,' File Pos : ']);
  3805. readposinfo(def);
  3806. write ([space,' Visibility : ']);
  3807. readvisibility(def);
  3808. write ([space,' SymOptions : ']);
  3809. readsymoptions(space+' ');
  3810. if (po_has_importdll in procoptions) then
  3811. writeln([space,' Import DLL : ',getstring]);
  3812. if (po_has_importname in procoptions) then
  3813. writeln([space,' Import Name : ',getstring]);
  3814. writeln([space,' Import Nr : ',getword]);
  3815. if (po_msgint in procoptions) then
  3816. writeln([space,' MsgInt : ',getlongint]);
  3817. if (po_msgstr in procoptions) then
  3818. writeln([space,' MsgStr : ',getstring]);
  3819. if (po_dispid in procoptions) then
  3820. writeln([space,' DispID: ',ppufile.getlongint]);
  3821. readprocimploptions(space,implprocoptions);
  3822. if (pio_has_inlininginfo in implprocoptions) then
  3823. begin
  3824. write ([space,' FuncretSym : ']);
  3825. readderef('');
  3826. readprocinfooptions(space);
  3827. end;
  3828. b:=ppufile.getbyte;
  3829. if b<>0 then
  3830. begin
  3831. write ([space,' Alias names : ']);
  3832. for j:=1 to b do
  3833. begin
  3834. write(ppufile.getstring);
  3835. if j<b then
  3836. write(', ');
  3837. end;
  3838. writeln;
  3839. end;
  3840. tokenbufsize:=ppufile.getlongint;
  3841. if tokenbufsize<>0 then
  3842. begin
  3843. write ([space,' Declaration token buffer : TODO']);
  3844. tokenbuf:=allocmem(tokenbufsize);
  3845. ppufile.getdata(tokenbuf^,tokenbufsize);
  3846. freemem(tokenbuf);
  3847. end;
  3848. if po_syscall_has_libsym in procoptions then
  3849. begin
  3850. { library symbol for AmigaOS/MorphOS/AROS }
  3851. write ([space,' Library symbol : ']);
  3852. readderef('');
  3853. end;
  3854. if not EndOfEntry then
  3855. HasMoreInfos;
  3856. space:=' '+space;
  3857. { parast }
  3858. readsymtable('parast', TPpuProcDef(def));
  3859. { localst }
  3860. if (pio_has_inlininginfo in implprocoptions) then
  3861. readsymtable('inline localst')
  3862. else if (df_generic in defoptions) then
  3863. readsymtable('generic localst');
  3864. if (pio_has_inlininginfo in implprocoptions) then
  3865. readnodetree;
  3866. delete(space,1,4);
  3867. end;
  3868. ibprocvardef :
  3869. begin
  3870. def:=TPpuProcTypeDef.Create(ParentDef);
  3871. readcommondef('Procedural type (ProcVar) definition',defoptions,def);
  3872. read_abstract_proc_def(calloption,procoptions, TPpuProcDef(def));
  3873. writeln([space,' Symtable level :',ppufile.getbyte]);
  3874. if tsystemcpu(ppufile.header.common.cpu)=cpu_jvm then
  3875. readderef('');
  3876. if not EndOfEntry then
  3877. HasMoreInfos;
  3878. space:=' '+space;
  3879. { parast }
  3880. readsymtable('parast',TPpuProcDef(def));
  3881. delete(space,1,4);
  3882. end;
  3883. ibshortstringdef :
  3884. begin
  3885. strdef:=TPpuStringDef.Create(ParentDef);
  3886. strdef.StrType:=stShort;
  3887. readcommondef('ShortString definition',defoptions,strdef);
  3888. strdef.Len:=getbyte;
  3889. writeln([space,' Length : ',strdef.Len]);
  3890. end;
  3891. ibwidestringdef :
  3892. begin
  3893. strdef:=TPpuStringDef.Create(ParentDef);
  3894. strdef.StrType:=stWide;
  3895. readcommondef('WideString definition',defoptions,strdef);
  3896. strdef.Len:=getasizeint;
  3897. writeln([space,' Length : ',strdef.Len]);
  3898. end;
  3899. ibunicodestringdef :
  3900. begin
  3901. strdef:=TPpuStringDef.Create(ParentDef);
  3902. strdef.StrType:=stUnicode;
  3903. readcommondef('UnicodeString definition',defoptions,strdef);
  3904. strdef.Len:=getasizeint;
  3905. writeln([space,' Length : ',strdef.Len]);
  3906. writeln([space,' Encoding : ',getword]);
  3907. end;
  3908. ibansistringdef :
  3909. begin
  3910. strdef:=TPpuStringDef.Create(ParentDef);
  3911. strdef.StrType:=stAnsi;
  3912. readcommondef('AnsiString definition',defoptions,strdef);
  3913. strdef.Len:=getasizeint;
  3914. writeln([space,' Length : ',strdef.Len]);
  3915. writeln([space,' Encoding : ',getword]);
  3916. end;
  3917. iblongstringdef :
  3918. begin
  3919. strdef:=TPpuStringDef.Create(ParentDef);
  3920. strdef.StrType:=stLong;
  3921. readcommondef('Longstring definition',defoptions,strdef);
  3922. strdef.Len:=getasizeint;
  3923. writeln([space,' Length : ',strdef.Len]);
  3924. end;
  3925. ibrecorddef :
  3926. begin
  3927. objdef:=TPpuRecordDef.Create(ParentDef);
  3928. readcommondef('Record definition',defoptions, objdef);
  3929. def.Name:=getstring;
  3930. writeln([space,' Name of Record : ',objdef.Name]);
  3931. writeln([space,' Import lib/pkg : ',getstring]);
  3932. write ([space,' Options : ']);
  3933. readobjectdefoptions(objdef);
  3934. if (df_copied_def in defoptions) then
  3935. begin
  3936. Include(TPpuRecordDef(def).Options, ooCopied);
  3937. write([space,' Copied from : ']);
  3938. readderef('',objdef.Ancestor);
  3939. end
  3940. else
  3941. begin
  3942. writeln([space,' FieldAlign : ',shortint(getbyte)]);
  3943. writeln([space,' RecordAlign : ',shortint(getbyte)]);
  3944. writeln([space,' PadAlign : ',shortint(getbyte)]);
  3945. writeln([space,'UseFieldAlignment : ',shortint(getbyte)]);
  3946. writeln([space,' RecordAlignMin : ',shortint(getbyte)]);
  3947. objdef.Size:=getasizeint;
  3948. writeln([space,' DataSize : ',objdef.Size]);
  3949. writeln([space,' PaddingSize : ',getword]);
  3950. readmanagementoperatoroptions(space,'Management operators');
  3951. end;
  3952. {read the record definitions and symbols}
  3953. if not(df_copied_def in current_defoptions) then
  3954. begin
  3955. space:=' '+space;
  3956. readrecordsymtable('fields',TPpuRecordDef(def));
  3957. Delete(space,1,4);
  3958. end;
  3959. if not EndOfEntry then
  3960. HasMoreInfos;
  3961. end;
  3962. ibobjectdef :
  3963. begin
  3964. objdef:=TPpuObjectDef.Create(ParentDef);
  3965. readcommondef('Object/Class definition',defoptions,objdef);
  3966. objdef.Name:=getstring;
  3967. writeln([space,' Name of Class : ',objdef.Name]);
  3968. writeln([space,' Import lib/pkg : ',getstring]);
  3969. write ([space,' Options : ']);
  3970. readobjectdefoptions(objdef);
  3971. otb:=getbyte;
  3972. write ([space,' Type : ']);
  3973. case tobjecttyp(otb) of
  3974. odt_class : writeln('class');
  3975. odt_object : writeln('object');
  3976. odt_interfacecom : writeln('interfacecom');
  3977. odt_interfacecorba : writeln('interfacecorba');
  3978. odt_cppclass : writeln('cppclass');
  3979. odt_dispinterface : writeln('dispinterface');
  3980. odt_objcclass : writeln('objcclass');
  3981. odt_objcprotocol : writeln('objcprotocol');
  3982. odt_helper : writeln('helper');
  3983. odt_objccategory : writeln('objccategory');
  3984. odt_javaclass : writeln('Java class');
  3985. odt_interfacejava : writeln('Java interface');
  3986. else WriteWarning('Invalid object type: ' + IntToStr(b));
  3987. end;
  3988. case tobjecttyp(otb) of
  3989. odt_class, odt_cppclass, odt_objcclass, odt_javaclass:
  3990. objdef.ObjType:=otClass;
  3991. odt_object:
  3992. objdef.ObjType:=otObject;
  3993. odt_interfacecom, odt_interfacecorba, odt_interfacejava, odt_dispinterface:
  3994. objdef.ObjType:=otInterface;
  3995. odt_helper:
  3996. objdef.ObjType:=otHelper;
  3997. end;
  3998. b:=getbyte;
  3999. write ([space,' Helper Type : ']);
  4000. case thelpertype(b) of
  4001. ht_none : writeln('none');
  4002. ht_class : writeln('class helper');
  4003. ht_record : writeln('record helper');
  4004. ht_type : writeln('type helper');
  4005. else WriteWarning('Invalid helper type: ' + IntToStr(b));
  4006. end;
  4007. writeln([space,' External name : ',getstring]);
  4008. objdef.Size:=getasizeint;
  4009. writeln([space,' DataSize : ',objdef.Size]);
  4010. writeln([space,' PaddingSize : ',getword]);
  4011. writeln([space,' FieldAlign : ',shortint(getbyte)]);
  4012. writeln([space,' RecordAlign : ',shortint(getbyte)]);
  4013. writeln([space,' RecordAlignMin : ',shortint(getbyte)]);
  4014. write ([space, ' VmtField : ']);
  4015. readderef('',nil);
  4016. write ([space, ' Ancestor Class : ']);
  4017. readderef('',objdef.Ancestor);
  4018. if tobjecttyp(otb) in [odt_interfacecom,odt_interfacecorba,odt_dispinterface] then
  4019. begin
  4020. { IIDGUID }
  4021. for j:=1to 16 do
  4022. getbyte;
  4023. objdef.IID:=getstring;
  4024. writeln([space,' IID String : ',objdef.IID]);
  4025. end;
  4026. l:=getlongint;
  4027. if l > 0 then
  4028. objdef.Options:=objdef.Options + [ooAbstractMethods];
  4029. writeln([space,' Abstract methods : ',l]);
  4030. if tobjecttyp(otb)=odt_helper then
  4031. begin
  4032. write([space,' Helper parent : ']);
  4033. readderef('',objdef.HelperParent);
  4034. end;
  4035. l:=getlongint;
  4036. writeln([space,' VMT entries: ',l]);
  4037. for j:=1 to l do
  4038. begin
  4039. write([space,' ']);
  4040. readderef('');
  4041. write([space,' Visibility: ']);
  4042. readvisibility;
  4043. end;
  4044. if tobjecttyp(otb) in [odt_class,odt_objcclass,odt_objcprotocol,odt_javaclass,odt_interfacejava] then
  4045. begin
  4046. l:=getlongint;
  4047. writeln([space,' Impl Intf Count : ',l]);
  4048. for j:=1 to l do
  4049. begin
  4050. write ([space,' - Definition : ']);
  4051. readderef('');
  4052. write ([space,' - Getter Def : ']);
  4053. readderef('');
  4054. writeln([space,' IOffset : ',getlongint]);
  4055. writeln([space,' Entry type : ',IntfEntryType2Str(getbyte)]);
  4056. end;
  4057. end;
  4058. if df_copied_def in current_defoptions then
  4059. begin
  4060. Include(objdef.Options, ooCopied);
  4061. writeln(' Copy of def: ');
  4062. readderef('',objdef.Ancestor);
  4063. end
  4064. else
  4065. begin
  4066. {read the record definitions and symbols}
  4067. space:=' '+space;
  4068. readrecordsymtable('fields',objdef);
  4069. Delete(space,1,4);
  4070. end;
  4071. if not EndOfEntry then
  4072. HasMoreInfos;
  4073. end;
  4074. ibfiledef :
  4075. begin
  4076. filedef:=TPpuFileDef.Create(ParentDef);
  4077. ReadCommonDef('File definition',defoptions,filedef);
  4078. write ([space,' Type : ']);
  4079. case getbyte of
  4080. 0 : begin
  4081. writeln('Text');
  4082. filedef.FileType:=ftText;
  4083. end;
  4084. 1 : begin
  4085. writeln('Typed');
  4086. filedef.FileType:=ftTyped;
  4087. write ([space,' File of Type : ']);
  4088. readderef('',filedef.TypeRef);
  4089. end;
  4090. 2 : begin
  4091. writeln('Untyped');
  4092. filedef.FileType:=ftUntyped;
  4093. end;
  4094. end;
  4095. end;
  4096. ibformaldef :
  4097. begin
  4098. def:=TPpuFormalDef.Create(ParentDef);
  4099. readcommondef('Generic definition (void-typ)',defoptions,def);
  4100. TPpuFormalDef(def).IsTyped:=(getbyte<>0);
  4101. writeln([space,' Is Typed : ',TPpuFormalDef(def).IsTyped]);
  4102. end;
  4103. ibundefineddef :
  4104. begin
  4105. def:=TPpuUndefinedDef.Create(ParentDef);
  4106. readcommondef('Undefined definition (generic parameter)',defoptions,def);
  4107. end;
  4108. ibenumdef :
  4109. begin
  4110. enumdef:=TPpuEnumDef.Create(ParentDef);
  4111. readcommondef('Enumeration type definition',defoptions,enumdef);
  4112. enumdef.ElLow:=getaint;
  4113. writeln([space,' Smallest element : ',enumdef.ElLow]);
  4114. enumdef.ElHigh:=getaint;
  4115. writeln([space,' Largest element : ',enumdef.ElHigh]);
  4116. enumdef.Size:=byte(getaint);
  4117. writeln([space,' Size : ',enumdef.Size]);
  4118. if df_copied_def in defoptions then
  4119. begin
  4120. write([space,'Base enumeration type : ']);
  4121. readderef('',enumdef.CopyFrom);
  4122. end
  4123. else
  4124. begin
  4125. space:=' '+space;
  4126. readsymtable('elements',enumdef);
  4127. delete(space,1,4);
  4128. end;
  4129. if tsystemcpu(ppufile.header.common.cpu)=cpu_jvm then
  4130. begin
  4131. write([space,' Class def : ']);
  4132. readderef('');
  4133. end;
  4134. end;
  4135. ibclassrefdef :
  4136. begin
  4137. def:=TPpuClassRefDef.Create(ParentDef);
  4138. readcommondef('Class reference definition',defoptions,def);
  4139. write ([space,' Pointed Type : ']);
  4140. readderef('',TPpuClassRefDef(def).ClassRef);
  4141. end;
  4142. ibsetdef :
  4143. begin
  4144. setdef:=TPpuSetDef.Create(ParentDef);
  4145. readcommondef('Set definition',defoptions,setdef);
  4146. write ([space,' Element type : ']);
  4147. readderef('',setdef.ElType);
  4148. setdef.Size:=getasizeint;
  4149. writeln([space,' Size : ',setdef.Size]);
  4150. setdef.SetBase:=getasizeint;
  4151. writeln([space,' Set Base : ',setdef.SetBase]);
  4152. setdef.SetMax:=getasizeint;
  4153. writeln([space,' Set Max : ',setdef.SetMax]);
  4154. end;
  4155. ibvariantdef :
  4156. begin
  4157. def:=TPpuVariantDef.Create(ParentDef);
  4158. readcommondef('Variant definition',defoptions,def);
  4159. write ([space,' Varianttype : ']);
  4160. b:=getbyte;
  4161. case tvarianttype(b) of
  4162. vt_normalvariant :
  4163. writeln('Normal');
  4164. vt_olevariant :
  4165. begin
  4166. TPpuVariantDef(def).IsOLE:=True;
  4167. writeln('OLE');
  4168. end
  4169. else
  4170. WriteWarning('Invalid varianttype: ' + IntToStr(b));
  4171. end;
  4172. end;
  4173. iberror :
  4174. begin
  4175. WriteError('!! Error in PPU');
  4176. exit;
  4177. end;
  4178. ibenddefs :
  4179. break;
  4180. else
  4181. begin
  4182. WriteError('!! Skipping unsupported PPU Entry in definitions: '+IntToStr(b));
  4183. end;
  4184. end;
  4185. if assigned(def) then
  4186. readdefsubentries(def);
  4187. if (def <> nil) and (def.Parent = nil) then
  4188. def.Free;
  4189. if not EndOfEntry then
  4190. HasMoreInfos;
  4191. until false;
  4192. end;
  4193. end;
  4194. procedure readmoduleoptions(space : string);
  4195. type
  4196. { tmoduleoption type is in unit fmodule }
  4197. tmoduleoption = (mo_none,
  4198. mo_hint_deprecated,
  4199. mo_hint_platform,
  4200. mo_hint_library,
  4201. mo_hint_unimplemented,
  4202. mo_hint_experimental,
  4203. mo_has_deprecated_msg
  4204. );
  4205. tmoduleoptions = set of tmoduleoption;
  4206. tmoduleopt=record
  4207. mask : tmoduleoption;
  4208. str : string[30];
  4209. end;
  4210. const
  4211. moduleopts=ord(high(tmoduleoption));
  4212. moduleopt : array[1..moduleopts] of tmoduleopt=(
  4213. (mask:mo_hint_deprecated; str:'Hint Deprecated'),
  4214. (mask:mo_hint_platform; str:'Hint Platform'),
  4215. (mask:mo_hint_library; str:'Hint Library'),
  4216. (mask:mo_hint_unimplemented; str:'Hint Unimplemented'),
  4217. (mask:mo_hint_experimental; str:'Hint Experimental'),
  4218. (mask:mo_has_deprecated_msg; str:'Has Deprecated Message')
  4219. );
  4220. var
  4221. moduleoptions : tmoduleoptions;
  4222. i : longint;
  4223. first : boolean;
  4224. begin
  4225. ppufile.getsmallset(moduleoptions);
  4226. if moduleoptions<>[] then
  4227. begin
  4228. first:=true;
  4229. for i:=1to moduleopts do
  4230. if (moduleopt[i].mask in moduleoptions) then
  4231. begin
  4232. if first then
  4233. first:=false
  4234. else
  4235. write(', ');
  4236. write(moduleopt[i].str);
  4237. end;
  4238. end;
  4239. writeln;
  4240. if mo_has_deprecated_msg in moduleoptions then
  4241. writeln([space,'Deprecated : ', ppufile.getstring]);
  4242. end;
  4243. {****************************************************************************
  4244. Read General Part
  4245. ****************************************************************************}
  4246. procedure readinterface(silent : boolean);
  4247. var
  4248. b : byte;
  4249. sourcenumber, i : longint;
  4250. feature : tfeature;
  4251. features : tfeatures;
  4252. s : string;
  4253. begin
  4254. with ppufile do
  4255. begin
  4256. repeat
  4257. b:=readentry;
  4258. case b of
  4259. ibextraheader:
  4260. begin
  4261. CurUnit.LongVersion:=cardinal(getlongint);
  4262. Writeln(['LongVersion: ',CurUnit.LongVersion]);
  4263. getsmallset(CurUnit.ModuleFlags);
  4264. if mf_symansistr in CurUnit.ModuleFlags then
  4265. SymAnsiStr:=true;
  4266. end;
  4267. ibmodulename :
  4268. begin
  4269. CurUnit.Name:=getstring;
  4270. if not silent then
  4271. Writeln(['Module Name: ',CurUnit.Name]);
  4272. end;
  4273. ibfeatures :
  4274. begin
  4275. getsmallset(features);
  4276. Writeln('Features: ');
  4277. for feature:=low(tfeatures) to high(tfeature) do
  4278. if feature in features then
  4279. begin
  4280. str(feature,s);
  4281. s:=copy(s,3,255);
  4282. writeln([s]);
  4283. end;
  4284. end;
  4285. ibmoduleoptions:
  4286. if not silent then
  4287. readmoduleoptions(' ');
  4288. ibsourcefiles :
  4289. begin
  4290. sourcenumber:=1;
  4291. if not silent then
  4292. while not EndOfEntry do
  4293. begin
  4294. with TPpuSrcFile.Create(CurUnit.SourceFiles) do begin
  4295. Name:=getstring;
  4296. i:=getlongint;
  4297. if i >= 0 then
  4298. FileTime:=FileDateToDateTime(i);
  4299. Writeln(['Source file ',sourcenumber,' : ',Name,' ',filetimestring(i)]);
  4300. end;
  4301. inc(sourcenumber);
  4302. end;
  4303. end;
  4304. {$IFDEF MACRO_DIFF_HINT}
  4305. ibusedmacros :
  4306. begin
  4307. if not silent then
  4308. while not EndOfEntry do
  4309. begin
  4310. Write('Conditional ',getstring);
  4311. if getboolean then
  4312. write(' defined at startup')
  4313. else
  4314. write(' not defined at startup');
  4315. if getboolean then
  4316. writeln(' was used')
  4317. else
  4318. writeln;
  4319. end;
  4320. end;
  4321. {$ENDIF}
  4322. ibloadunit :
  4323. if not silent then
  4324. ReadLoadUnit;
  4325. iblinkunitofiles :
  4326. if not silent then
  4327. ReadLinkContainer('Link unit object file: ');
  4328. iblinkunitstaticlibs :
  4329. if not silent then
  4330. ReadLinkContainer('Link unit static lib: ');
  4331. iblinkunitsharedlibs :
  4332. if not silent then
  4333. ReadLinkContainer('Link unit shared lib: ');
  4334. iblinkotherofiles :
  4335. if not silent then
  4336. ReadLinkContainer('Link other object file: ');
  4337. iblinkotherstaticlibs :
  4338. if not silent then
  4339. ReadLinkContainer('Link other static lib: ');
  4340. iblinkothersharedlibs :
  4341. if not silent then
  4342. ReadLinkContainer('Link other shared lib: ');
  4343. iblinkotherframeworks:
  4344. if not silent then
  4345. ReadLinkContainer('Link framework: ');
  4346. ibjvmnamespace:
  4347. Writeln('JVM name space: '+getString);
  4348. ibmainname:
  4349. if not silent then
  4350. Writeln(['Specified main program symbol name: ',getstring]);
  4351. ibImportSymbols :
  4352. if not silent then
  4353. ReadImportSymbols;
  4354. ibderefdata :
  4355. ReadDerefData;
  4356. ibderefmap :
  4357. ReadDerefMap;
  4358. ibwpofile :
  4359. if not silent then
  4360. ReadWpoFileInfo;
  4361. ibresources :
  4362. if not silent then
  4363. ReadContainer('Resource file: ');
  4364. iborderedsymbols:
  4365. if not silent then
  4366. ReadContainer('Ordered symbol: ');
  4367. iberror :
  4368. begin
  4369. WriteError('Error in PPU');
  4370. exit;
  4371. end;
  4372. ibendinterface :
  4373. break;
  4374. else
  4375. begin
  4376. WriteError('!! Skipping unsupported PPU Entry in General Part: '+IntToStr(b));
  4377. end;
  4378. end;
  4379. until false;
  4380. end;
  4381. end;
  4382. {****************************************************************************
  4383. Read Implementation Part
  4384. ****************************************************************************}
  4385. procedure readimplementation;
  4386. var
  4387. b : byte;
  4388. begin
  4389. with ppufile do
  4390. begin
  4391. repeat
  4392. b:=readentry;
  4393. case b of
  4394. ibasmsymbols :
  4395. ReadAsmSymbols;
  4396. ibloadunit :
  4397. ReadLoadUnit;
  4398. ibunitimportsyms :
  4399. ReadUnitImportSyms;
  4400. iberror :
  4401. begin
  4402. WriteError('Error in PPU');
  4403. exit;
  4404. end;
  4405. ibendimplementation :
  4406. break;
  4407. else
  4408. begin
  4409. WriteError('!! Skipping unsupported PPU Entry in Implementation: '+IntToStr(b));
  4410. end;
  4411. end;
  4412. until false;
  4413. end;
  4414. end;
  4415. function parseextraheader(module: TPpuModuleDef; ppufile: tppufile): boolean;
  4416. var
  4417. b: byte;
  4418. begin
  4419. result:=false;
  4420. b:=ppufile.readentry;
  4421. if b<>ibextraheader then
  4422. exit;
  4423. CurUnit.LongVersion:=cardinal(ppufile.getlongint);
  4424. Writeln(['LongVersion: ',CurUnit.LongVersion]);
  4425. ppufile.getsmallset(CurUnit.ModuleFlags);
  4426. result:=ppufile.EndOfEntry;
  4427. end;
  4428. procedure dofile (filename : string);
  4429. begin
  4430. { reset }
  4431. space:='';
  4432. { fix filename }
  4433. if pos('.',filename)=0 then
  4434. filename:=filename+'.ppu';
  4435. ppufile:=tppudumpfile.create(filename);
  4436. if not ppufile.openfile then
  4437. begin
  4438. WriteError('IO-Error when opening : '+filename+', Skipping');
  4439. exit;
  4440. end;
  4441. { PPU File is open, check for PPU Id }
  4442. if not ppufile.CheckPPUID then
  4443. begin
  4444. WriteError(Filename+' : Not a valid PPU file, Skipping');
  4445. exit;
  4446. end;
  4447. { Check PPU Version }
  4448. ppuversion:=ppufile.getversion;
  4449. Writeln(['Analyzing ',filename,' (v',PPUVersion,')']);
  4450. if not SkipVersionCheck and (PPUVersion <> CurrentPPUVersion) then
  4451. begin
  4452. WriteError(Format('Unsupported PPU version %d. Expecting PPU version %d.', [PPUVersion, CurrentPPUVersion]));
  4453. exit;
  4454. end;
  4455. CurUnit:=TPpuModuleDef.Create(UnitList);
  4456. CurUnit.Version:=ppuversion;
  4457. if not parseextraheader(CurUnit, ppufile) then
  4458. begin
  4459. WriteError(Format('Unsupported PPU sub-version %d. Expecting PPU sub-version %d.', [CurUnit.LongVersion, CurrentPPULongVersion]));
  4460. end;
  4461. { Write PPU Header Information }
  4462. if (verbose and v_header)<>0 then
  4463. begin
  4464. Writeln;
  4465. Writeln('Header');
  4466. Writeln('-------');
  4467. with ppufile.header do
  4468. begin
  4469. Writeln(['Compiler version : ',ppufile.header.common.compiler shr 14,'.',
  4470. (ppufile.header.common.compiler shr 7) and $7f,'.',
  4471. ppufile.header.common.compiler and $7f]);
  4472. WriteLn(['Target processor : ',Cpu2Str(common.cpu)]);
  4473. WriteLn(['Target operating system : ',Target2Str(common.target)]);
  4474. Writeln(['Unit flags : ',PPUFlags2Str(common.flags)]);
  4475. Writeln(['FileSize (w/o header) : ',common.size]);
  4476. Writeln(['Checksum : ',hexstr(checksum,8)]);
  4477. Writeln(['Interface Checksum : ',hexstr(interface_checksum,8)]);
  4478. Writeln(['Indirect Checksum : ',hexstr(indirect_checksum,8)]);
  4479. Writeln(['Definitions stored : ',tostr(deflistsize)]);
  4480. Writeln(['Symbols stored : ',tostr(symlistsize)]);
  4481. end;
  4482. end;
  4483. with ppufile.header do
  4484. begin
  4485. CurUnit.Crc:=checksum;
  4486. CurUnit.IntfCrc:=interface_checksum;
  4487. CurUnit.TargetCPU:=Cpu2Str(common.cpu);
  4488. CurUnit.TargetOS:=Target2Str(common.target);
  4489. end;
  4490. {read the general stuff}
  4491. if (verbose and v_interface)<>0 then
  4492. begin
  4493. Writeln;
  4494. Writeln('Interface section');
  4495. Writeln('------------------');
  4496. readinterface(false);
  4497. end
  4498. { We need derefdata from Interface }
  4499. else if verbose and (v_defs or v_syms or v_implementation)<>0 then
  4500. readinterface(true)
  4501. else
  4502. ppufile.skipuntilentry(ibendinterface);
  4503. Writeln;
  4504. Writeln('Interface symtable');
  4505. Writeln('----------------------');
  4506. readsymtableoptions('interface');
  4507. {read the definitions}
  4508. if (verbose and v_defs)<>0 then
  4509. begin
  4510. Writeln;
  4511. Writeln('Interface definitions');
  4512. Writeln('----------------------');
  4513. readdefinitions('interface', CurUnit);
  4514. end
  4515. else
  4516. ppufile.skipuntilentry(ibenddefs);
  4517. {read the symbols}
  4518. if (verbose and v_syms)<>0 then
  4519. begin
  4520. Writeln;
  4521. Writeln('Interface Symbols');
  4522. Writeln('------------------');
  4523. readsymbols('interface',CurUnit);
  4524. end
  4525. else
  4526. ppufile.skipuntilentry(ibendsyms);
  4527. {read the macro symbols}
  4528. if (verbose and v_syms)<>0 then
  4529. begin
  4530. Writeln;
  4531. Writeln('Interface Macro Symbols');
  4532. Writeln('-----------------------');
  4533. end;
  4534. if ppufile.readentry<>ibexportedmacros then
  4535. begin
  4536. WriteError('!! Error in PPU');
  4537. exit;
  4538. end;
  4539. if ppufile.getboolean then
  4540. begin
  4541. readsymtableoptions('interface macro');
  4542. {skip the definition section for macros (since they are never used) }
  4543. ppufile.skipuntilentry(ibenddefs);
  4544. {read the macro symbols}
  4545. if (verbose and v_syms)<>0 then
  4546. readsymbols('interface macro')
  4547. else
  4548. ppufile.skipuntilentry(ibendsyms);
  4549. end
  4550. else
  4551. Writeln('(no exported macros)');
  4552. {read the implementation stuff}
  4553. if (verbose and v_implementation)<>0 then
  4554. begin
  4555. Writeln;
  4556. Writeln('Implementation section');
  4557. Writeln('-----------------------');
  4558. readimplementation;
  4559. end
  4560. else
  4561. ppufile.skipuntilentry(ibendimplementation);
  4562. {read the static symtable}
  4563. Writeln;
  4564. Writeln('Implementation symtable');
  4565. Writeln('----------------------');
  4566. readsymtableoptions('implementation');
  4567. if (mf_local_symtable in CurUnit.ModuleFlags) then
  4568. begin
  4569. if (verbose and v_defs)<>0 then
  4570. begin
  4571. Writeln;
  4572. Writeln('Static definitions');
  4573. Writeln('----------------------');
  4574. readdefinitions('implementation', nil);
  4575. end
  4576. else
  4577. ppufile.skipuntilentry(ibenddefs);
  4578. {read the symbols}
  4579. if (verbose and v_syms)<>0 then
  4580. begin
  4581. Writeln;
  4582. Writeln('Static Symbols');
  4583. Writeln('------------------');
  4584. readsymbols('implementation');
  4585. end
  4586. else
  4587. ppufile.skipuntilentry(ibendsyms);
  4588. end;
  4589. ReadCreatedObjTypes;
  4590. FreeDerefdata;
  4591. {shutdown ppufile}
  4592. ppufile.closefile;
  4593. ppufile.free;
  4594. Writeln;
  4595. end;
  4596. procedure WriteLogo;
  4597. begin
  4598. writeln(Title+' Version '+version_string);
  4599. writeln(Copyright);
  4600. writeln;
  4601. end;
  4602. procedure help;
  4603. begin
  4604. WriteLogo;
  4605. writeln('usage: ppudump [options] <filename1> <filename2>...');
  4606. writeln;
  4607. writeln('[options] can be:');
  4608. writeln(' -F<format> Set output format to <format>');
  4609. writeln(' t - text format (default)');
  4610. writeln(' j - JSON format');
  4611. writeln(' x - XML format');
  4612. writeln(' -M Exit with ExitCode=2 if more information is available');
  4613. writeln(' -S Skip PPU version check. May lead to reading errors');
  4614. writeln(' -V<verbose> Set verbosity to <verbose>');
  4615. writeln(' H - Show header info');
  4616. writeln(' I - Show interface');
  4617. writeln(' M - Show implementation');
  4618. writeln(' S - Show interface symbols');
  4619. writeln(' D - Show interface definitions');
  4620. writeln(' A - Show all');
  4621. writeln(' -h, -? This helpscreen');
  4622. halt;
  4623. end;
  4624. var
  4625. startpara,
  4626. nrfile,i : longint;
  4627. para : string;
  4628. const
  4629. error_on_more : boolean = false;
  4630. begin
  4631. if paramcount<1 then
  4632. help;
  4633. { turn verbose on by default }
  4634. verbose:=v_all;
  4635. { read options }
  4636. startpara:=1;
  4637. while copy(paramstr(startpara),1,1)='-' do
  4638. begin
  4639. para:=paramstr(startpara);
  4640. case upcase(para[2]) of
  4641. 'F' : begin
  4642. FreeAndNil(pout);
  4643. if Length(para) > 2 then
  4644. case upcase(para[3]) of
  4645. 'T':
  4646. nostdout:=False;
  4647. 'J':
  4648. begin
  4649. nostdout:=True;
  4650. pout:=TPpuJsonOutput.Create(StdOutputHandle);
  4651. end;
  4652. 'X':
  4653. begin
  4654. nostdout:=True;
  4655. pout:=TPpuXmlOutput.Create(StdOutputHandle);
  4656. end;
  4657. else
  4658. begin
  4659. WriteError('Invalid output format: ' + para[3]);
  4660. Halt(1);
  4661. end;
  4662. end;
  4663. end;
  4664. 'M' : error_on_more:=true;
  4665. 'S' : SkipVersionCheck:=True;
  4666. 'V' : begin
  4667. verbose:=0;
  4668. for i:=3 to length(para) do
  4669. case upcase(para[i]) of
  4670. 'H' : verbose:=verbose or v_header;
  4671. 'I' : verbose:=verbose or v_interface;
  4672. 'M' : verbose:=verbose or v_implementation;
  4673. 'D' : verbose:=verbose or v_defs;
  4674. 'S' : verbose:=verbose or v_syms;
  4675. 'A' : verbose:=verbose or v_all;
  4676. end;
  4677. end;
  4678. 'H' : help;
  4679. '?' : help;
  4680. else
  4681. begin
  4682. WriteError('Invalid option: ' + para);
  4683. Halt(1);
  4684. end;
  4685. end;
  4686. inc(startpara);
  4687. end;
  4688. if not nostdout then
  4689. WriteLogo;
  4690. UnitList:=TPpuContainerDef.Create(nil);
  4691. try
  4692. UnitList.ItemsName:='';
  4693. { process files }
  4694. for nrfile:=startpara to paramcount do
  4695. dofile (paramstr(nrfile));
  4696. if not has_errors and (pout <> nil) then
  4697. begin
  4698. pout.Init;
  4699. UnitList.Write(pout);
  4700. pout.Done;
  4701. end;
  4702. finally
  4703. UnitList.Free;
  4704. pout.Free;
  4705. end;
  4706. if has_errors then
  4707. Halt(1);
  4708. if error_on_more and
  4709. (has_more_infos or has_warnings) then
  4710. Halt(2);
  4711. end.