ppudump.pp 167 KB

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