ppudump.pp 167 KB

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