ppudump.pp 173 KB

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