ppudump.pp 168 KB

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