ppudump.pp 168 KB

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