ppudump.pp 172 KB

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