ppudump.pp 161 KB

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