ppudump.pp 167 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277
  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. (mask:pi_no_framepointer_needed;
  1546. str:' set if no frame pointer is needed, the rules when this applies is target specific'
  1547. )
  1548. );
  1549. var
  1550. procinfooptions : tprocinfoflags;
  1551. i : longint;
  1552. first : boolean;
  1553. begin
  1554. ppufile.getset(tppuset4(procinfooptions));
  1555. if procinfooptions<>[] then
  1556. begin
  1557. first:=true;
  1558. for i:=0 to procinfoopts do
  1559. if (procinfoopt[i].mask in procinfooptions) then
  1560. begin
  1561. if first then
  1562. first:=false
  1563. else
  1564. write(', ');
  1565. write(procinfoopt[i].str);
  1566. end;
  1567. end;
  1568. writeln;
  1569. end;
  1570. procedure readsymoptions(space : string; Def: TPpuDef = nil);
  1571. type
  1572. tsymopt=record
  1573. mask : tsymoption;
  1574. str : string[30];
  1575. end;
  1576. const
  1577. symopts=ord(high(tsymoption)) - ord(low(tsymoption));
  1578. { sp_none = 0 corresponds to nothing }
  1579. symopt : array[1..symopts] of tsymopt=(
  1580. (mask:sp_static; str:'Static'),
  1581. (mask:sp_hint_deprecated; str:'Hint Deprecated'),
  1582. (mask:sp_hint_platform; str:'Hint Platform'),
  1583. (mask:sp_hint_library; str:'Hint Library'),
  1584. (mask:sp_hint_unimplemented; str:'Hint Unimplemented'),
  1585. (mask:sp_hint_experimental; str:'Hint Experimental'),
  1586. (mask:sp_has_overloaded; str:'Has overloaded'),
  1587. (mask:sp_internal; str:'Internal'),
  1588. (mask:sp_implicitrename; str:'Implicit Rename'),
  1589. (mask:sp_generic_para; str:'Generic Parameter'),
  1590. (mask:sp_has_deprecated_msg; str:'Has Deprecated Message'),
  1591. (mask:sp_generic_dummy; str:'Generic Dummy'),
  1592. (mask:sp_explicitrename; str:'Explicit Rename'),
  1593. (mask:sp_generic_const; str:'Generic Constant Parameter')
  1594. );
  1595. var
  1596. symoptions : tsymoptions;
  1597. i : longint;
  1598. first : boolean;
  1599. begin
  1600. ppufile.getset(tppuset2(symoptions));
  1601. if symoptions<>[] then
  1602. begin
  1603. if Def <> nil then
  1604. begin
  1605. if sp_internal in symoptions then
  1606. Def.Visibility:=dvHidden;
  1607. if sp_generic_dummy in symoptions then
  1608. Def.GenericDummy:=true;
  1609. end;
  1610. first:=true;
  1611. for i:=1to symopts do
  1612. if (symopt[i].mask in symoptions) then
  1613. begin
  1614. if first then
  1615. first:=false
  1616. else
  1617. write(', ');
  1618. write(symopt[i].str);
  1619. end;
  1620. end;
  1621. writeln;
  1622. if sp_has_deprecated_msg in symoptions then
  1623. writeln([space,'Deprecated : ', ppufile.getstring]);
  1624. end;
  1625. procedure readvisibility(Def: TPpuDef = nil);
  1626. var
  1627. i: byte;
  1628. begin
  1629. i:=ppufile.getbyte;
  1630. if Def <> nil then
  1631. case tvisibility(i) of
  1632. vis_public: Def.Visibility:=dvPublic;
  1633. vis_published: Def.Visibility:=dvPublished;
  1634. vis_protected, vis_strictprotected: Def.Visibility:=dvProtected;
  1635. else Def.Visibility:=dvPrivate;
  1636. end;
  1637. writeln(Visibility2Str(i));
  1638. end;
  1639. procedure readattrs(def: TPpuDef);
  1640. var
  1641. i,cnt,paras: longint;
  1642. begin
  1643. cnt:=ppufile.getlongint;
  1644. if cnt>0 then
  1645. begin
  1646. writeln([space,' Attributes : ']);
  1647. space:=' '+space;
  1648. if assigned(def) then
  1649. SetLength(def.Attrs,cnt);
  1650. for i:=0 to cnt-1 do
  1651. begin
  1652. writeln([space,'** Custom Attribute ',i,' **']);
  1653. write ([space,' Type symbol : ']);
  1654. if assigned(def) then
  1655. begin
  1656. def.Attrs[i].TypeSym:=TPpuRef.Create;
  1657. readderef('',def.Attrs[i].TypeSym);
  1658. end
  1659. else
  1660. readderef('');
  1661. write ([space,' Type constructor : ']);
  1662. if assigned(def) then
  1663. begin
  1664. def.Attrs[i].TypeConstr:=TPpuRef.Create;
  1665. readderef('',def.Attrs[i].TypeConstr);
  1666. end
  1667. else
  1668. readderef('');
  1669. paras:=ppufile.getlongint;
  1670. writeln([space,' Parameters : ',paras]);
  1671. if assigned(def) then
  1672. def.Attrs[i].ParaCount:=paras;
  1673. end;
  1674. delete(space,1,4);
  1675. end;
  1676. end;
  1677. procedure readnodetree; forward;
  1678. procedure readattrparas(def: TPpuDef);
  1679. var
  1680. attr,para: LongInt;
  1681. begin
  1682. if Length(def.Attrs) > 0 then
  1683. writeln([space,' Attr Paras : ']);
  1684. space:=' '+space;
  1685. for attr:=0 to High(def.Attrs) do
  1686. begin
  1687. writeln([space,'** Custom Attribute ',attr,' Arguments **']);
  1688. space:=' '+space;
  1689. for para:=0 to def.Attrs[attr].ParaCount-1 do
  1690. begin
  1691. readnodetree;
  1692. end;
  1693. delete(space,1,4);
  1694. end;
  1695. delete(space,1,4);
  1696. end;
  1697. procedure readdefsubentries(def: TPpuDef);
  1698. begin
  1699. space:=' '+space;
  1700. readattrparas(def);
  1701. delete(space,1,4);
  1702. end;
  1703. procedure readsymsubentries(def: TPpuDef);
  1704. begin
  1705. readattrparas(def);
  1706. end;
  1707. procedure readcommonsym(const s:string; Def: TPpuDef = nil);
  1708. var
  1709. i: integer;
  1710. n: ansistring;
  1711. begin
  1712. n:=readsymstr(ppufile);
  1713. if Def <> nil then
  1714. Def.Name:=n;
  1715. i:=ppufile.getlongint;
  1716. if Def <> nil then
  1717. Def.SetSymId(i);
  1718. writeln([space,'** Symbol Id ',i,' **']);
  1719. writeln([space,s,n]);
  1720. write ([space,' File Pos : ']);
  1721. readposinfo(Def);
  1722. write ([space,' Visibility : ']);
  1723. readvisibility(Def);
  1724. write ([space,' SymOptions : ']);
  1725. readsymoptions(space+' ',Def);
  1726. readattrs(Def);
  1727. end;
  1728. procedure readcgpara(const space:string);
  1729. { this is originally in cgbase.pas }
  1730. type
  1731. TCGLoc=(LOC_INVALID, LOC_VOID, LOC_CONSTANT, LOC_JUMP, LOC_FLAGS,
  1732. LOC_REGISTER, LOC_CREGISTER, LOC_FPUREGISTER, LOC_CFPUREGISTER,
  1733. LOC_MMXREGISTER, LOC_CMMXREGISTER, LOC_MMREGISTER, LOC_CMMREGISTER,
  1734. LOC_SUBSETREG, LOC_CSUBSETREG, LOC_SUBSETREF, LOC_CSUBSETREF,
  1735. LOC_CREFERENCE, LOC_REFERENCE);
  1736. const
  1737. tcgloc2str : array[TCGLoc] of string[12] = (
  1738. 'LOC_INVALID', 'LOC_VOID', 'LOC_CONST', 'LOC_JUMP', 'LOC_FLAGS',
  1739. 'LOC_REG', 'LOC_CREG', 'LOC_FPUREG', 'LOC_CFPUREG',
  1740. 'LOC_MMXREG', 'LOC_CMMXREG', 'LOC_MMREG', 'LOC_CMMREG',
  1741. 'LOC_SSETREG', 'LOC_CSSETREG', 'LOC_SSETREF', 'LOC_CSSETREF',
  1742. 'LOC_CREF', 'LOC_REF');
  1743. var
  1744. i: byte;
  1745. ii: longint;
  1746. np: byte;
  1747. loc: tcgloc;
  1748. begin
  1749. i:=ppufile.getbyte;
  1750. writeln([space,' Alignment : ',i]);
  1751. i:=ppufile.getbyte;
  1752. writeln([space,' Size : ',i]);
  1753. ii:=ppufile.getaint;
  1754. writeln([space,' IntSize : ',ii]);
  1755. readderef(space+' ');
  1756. np:=ppufile.getbyte;
  1757. writeln([space,' NumParaloc : ',np]);
  1758. while np > 0 do
  1759. begin
  1760. i:=ppufile.getbyte;
  1761. writeln([space,' Paraloc Size : ',i]);
  1762. loc:=tcgloc(ppufile.getbyte);
  1763. if loc > high(tcgloc) then
  1764. begin
  1765. WriteError('!! Location is out of range! '+IntToStr(ord(loc)));
  1766. loc:=LOC_INVALID;
  1767. end;
  1768. writeln([space,' Paraloc Loc : (',ord(loc),') ',tcgloc2str[loc]]);
  1769. case loc of
  1770. LOC_REFERENCE:
  1771. begin
  1772. writeln([space,' RegIndex : $',hexstr(ppufile.getdword,8)]);
  1773. writeln([space,' Offset : ',ppufile.getaint]);
  1774. end;
  1775. LOC_FPUREGISTER,
  1776. LOC_CFPUREGISTER,
  1777. LOC_MMREGISTER,
  1778. LOC_CMMREGISTER,
  1779. LOC_REGISTER,
  1780. LOC_CREGISTER :
  1781. begin
  1782. writeln([space,' ShiftVal : ',ppufile.getbyte]);
  1783. writeln([space,' Register : $',hexstr(ppufile.getdword,8)]);
  1784. end;
  1785. LOC_VOID:
  1786. begin end
  1787. else
  1788. WriteError('!! Invalid location error')
  1789. end;
  1790. dec(np);
  1791. end;
  1792. end;
  1793. procedure displaytokenbuffer(tokenbuf : pbyte;tokenbufsize : longint);
  1794. type
  1795. ptoken=^ttoken;
  1796. pmsgstate =^tmsgstate;
  1797. var
  1798. tbi : longint;
  1799. state : tmsgstate;
  1800. prev_settings, new_settings : Tsettings;
  1801. nb, msgvalue, mesgnb : longint;
  1802. function readtoken: ttoken;
  1803. var
  1804. b,b2 : byte;
  1805. begin
  1806. b:=tokenbuf[tbi];
  1807. inc(tbi);
  1808. if (b and $80)<>0 then
  1809. begin
  1810. b2:=tokenbuf[tbi];
  1811. inc(tbi);
  1812. result:=ttoken(((b and $7f) shl 8) or b2);
  1813. end
  1814. else
  1815. result:=ttoken(b);
  1816. end;
  1817. function gettokenbufdword : dword;
  1818. var
  1819. var32 : dword;
  1820. begin
  1821. var32:=unaligned(pdword(@tokenbuf[tbi])^);
  1822. inc(tbi,sizeof(dword));
  1823. if ppufile.change_endian then
  1824. var32:=swapendian(var32);
  1825. result:=var32;
  1826. end;
  1827. function gettokenbufword : word;
  1828. var
  1829. var16 : word;
  1830. begin
  1831. var16:=unaligned(pword(@tokenbuf[tbi])^);
  1832. inc(tbi,sizeof(word));
  1833. if ppufile.change_endian then
  1834. var16:=swapendian(var16);
  1835. result:=var16;
  1836. end;
  1837. function gettokenbuflongint : longint;
  1838. var
  1839. var32 : longint;
  1840. begin
  1841. var32:=unaligned(plongint(@tokenbuf[tbi])^);
  1842. inc(tbi,sizeof(longint));
  1843. if ppufile.change_endian then
  1844. var32:=swapendian(var32);
  1845. result:=var32;
  1846. end;
  1847. function gettokenbufshortint : shortint;
  1848. var
  1849. var8 : shortint;
  1850. begin
  1851. var8:=pshortint(@tokenbuf[tbi])^;
  1852. inc(tbi,sizeof(shortint));
  1853. result:=var8;
  1854. end;
  1855. procedure tokenreadset(var b;size : longint);
  1856. var
  1857. i : longint;
  1858. begin
  1859. move(tokenbuf[tbi],b,size);
  1860. inc(tbi,size);
  1861. if ppufile.change_endian then
  1862. for i:=0 to size-1 do
  1863. Pbyte(@b)[i]:=reverse_byte(Pbyte(@b)[i]);
  1864. end;
  1865. function gettokenbufbyte : byte;
  1866. begin
  1867. result:=pbyte(@tokenbuf[tbi])^;
  1868. inc(tbi);
  1869. end;
  1870. function tokenreadenum(size : longint) : longword;
  1871. begin
  1872. if size=1 then
  1873. result:=gettokenbufbyte
  1874. else if size=2 then
  1875. result:=gettokenbufword
  1876. else if size=4 then
  1877. result:=gettokenbufdword;
  1878. end;
  1879. function gettokenbufsizeint : int64;
  1880. var
  1881. var64 : int64;
  1882. var32 : longint;
  1883. var16 : smallint;
  1884. begin
  1885. if CpuAddrBitSize[cpu]=64 then
  1886. begin
  1887. var64:=unaligned(pint64(@tokenbuf[tbi])^);
  1888. inc(tbi,sizeof(int64));
  1889. if ppufile.change_endian then
  1890. var64:=swapendian(var64);
  1891. result:=var64;
  1892. end
  1893. else if CpuAddrBitSize[cpu]=32 then
  1894. begin
  1895. var32:=unaligned(plongint(@tokenbuf[tbi])^);
  1896. inc(tbi,sizeof(longint));
  1897. if ppufile.change_endian then
  1898. var32:=swapendian(var32);
  1899. result:=var32;
  1900. end
  1901. else if CpuAddrBitSize[cpu]=16 then
  1902. begin
  1903. { ASizeInt is still a longint, see globtype.pas unit }
  1904. var32:=unaligned(plongint(@tokenbuf[tbi])^);
  1905. inc(tbi,sizeof(longint));
  1906. if ppufile.change_endian then
  1907. var32:=swapendian(var32);
  1908. result:=var32;
  1909. end
  1910. else
  1911. begin
  1912. WriteError('Wrong CpuAddrBitSize');
  1913. result:=0;
  1914. end;
  1915. end;
  1916. procedure tokenreadsettings(var asettings : tsettings; expected_size : asizeint);
  1917. { This procedure
  1918. needs to be changed whenever
  1919. globals.tsettings type is changed,
  1920. the problem is that no error will appear
  1921. before tests with generics are tested. PM }
  1922. var
  1923. startpos, endpos : longword;
  1924. begin
  1925. { WARNING all those fields need to be in the correct
  1926. order otherwise cross_endian PPU reading will fail }
  1927. startpos:=tbi;
  1928. with asettings do
  1929. begin
  1930. alignment.procalign:=gettokenbuflongint;
  1931. alignment.loopalign:=gettokenbuflongint;
  1932. alignment.jumpalign:=gettokenbuflongint;
  1933. alignment.jumpalignskipmax:=gettokenbuflongint;
  1934. alignment.coalescealign:=gettokenbuflongint;
  1935. alignment.coalescealignskipmax:=gettokenbuflongint;
  1936. alignment.constalignmin:=gettokenbuflongint;
  1937. alignment.constalignmax:=gettokenbuflongint;
  1938. alignment.varalignmin:=gettokenbuflongint;
  1939. alignment.varalignmax:=gettokenbuflongint;
  1940. alignment.localalignmin:=gettokenbuflongint;
  1941. alignment.localalignmax:=gettokenbuflongint;
  1942. alignment.recordalignmin:=gettokenbuflongint;
  1943. alignment.recordalignmax:=gettokenbuflongint;
  1944. alignment.maxCrecordalign:=gettokenbuflongint;
  1945. tokenreadset(globalswitches,sizeof(globalswitches));
  1946. tokenreadset(targetswitches,sizeof(targetswitches));
  1947. tokenreadset(moduleswitches,sizeof(moduleswitches));
  1948. tokenreadset(localswitches,sizeof(localswitches));
  1949. tokenreadset(modeswitches,sizeof(modeswitches));
  1950. tokenreadset(optimizerswitches,sizeof(optimizerswitches));
  1951. tokenreadset(genwpoptimizerswitches,sizeof(genwpoptimizerswitches));
  1952. tokenreadset(dowpoptimizerswitches,sizeof(dowpoptimizerswitches));
  1953. tokenreadset(debugswitches,sizeof(debugswitches));
  1954. { 0: old behaviour for sets <=256 elements
  1955. >0: round to this size }
  1956. setalloc:=gettokenbufshortint;
  1957. packenum:=gettokenbufshortint;
  1958. packrecords:=gettokenbufshortint;
  1959. maxfpuregisters:=gettokenbufshortint;
  1960. cputype:=tcputype(tokenreadenum(sizeof(tcputype)));
  1961. optimizecputype:=tcputype(tokenreadenum(sizeof(tcputype)));
  1962. fputype:=tfputype(tokenreadenum(sizeof(tfputype)));
  1963. asmmode:=tasmmode(tokenreadenum(sizeof(tasmmode)));
  1964. interfacetype:=tinterfacetypes(tokenreadenum(sizeof(tinterfacetypes)));
  1965. defproccall:=tproccalloption(tokenreadenum(sizeof(tproccalloption)));
  1966. { tstringencoding is word type,
  1967. thus this should be OK here }
  1968. sourcecodepage:=tstringEncoding(gettokenbufword);
  1969. minfpconstprec:=tfloattype(tokenreadenum(sizeof(tfloattype)));
  1970. disabledircache:=boolean(gettokenbufbyte);
  1971. tlsmodel:=ttlsmodel(tokenreadenum(sizeof(ttlsmodel)));
  1972. { TH: Since the field was conditional originally, it was not stored in PPUs. }
  1973. { While adding ControllerSupport constant, I decided not to store ct_none }
  1974. { on targets not supporting controllers, but this might be changed here and }
  1975. { in tokenwritesettings in the future to unify the PPU structure and handling }
  1976. { of this field in the compiler. }
  1977. {$PUSH}
  1978. {$WARN 6018 OFF} (* Unreachable code due to compile time evaluation *)
  1979. if CpuHasController[cpu] then
  1980. controllertype:=tcontrollertype(tokenreadenum(sizeof(tcontrollertype)))
  1981. else
  1982. ControllerType:=ct_none;
  1983. {$POP}
  1984. endpos:=tbi;
  1985. if endpos-startpos<>expected_size then
  1986. Writeln(['Wrong size of Settings read-in: ',expected_size,' expected, but got ',endpos-startpos]);
  1987. end;
  1988. end;
  1989. procedure dump_new_settings;
  1990. (* tsettings = record
  1991. alignment : talignmentinfo;
  1992. globalswitches : tglobalswitches;
  1993. targetswitches : ttargetswitches;
  1994. moduleswitches : tmoduleswitches;
  1995. localswitches : tlocalswitches;
  1996. modeswitches : tmodeswitches;
  1997. optimizerswitches : toptimizerswitches;
  1998. { generate information necessary to perform these wpo's during a subsequent compilation }
  1999. genwpoptimizerswitches: twpoptimizerswitches;
  2000. { perform these wpo's using information generated during a previous compilation }
  2001. dowpoptimizerswitches: twpoptimizerswitches;
  2002. debugswitches : tdebugswitches;
  2003. { 0: old behaviour for sets <=256 elements
  2004. >0: round to this size }
  2005. setalloc,
  2006. packenum : shortint;
  2007. packrecords : shortint;
  2008. maxfpuregisters : shortint;
  2009. cputype,
  2010. optimizecputype,
  2011. asmcputype : tcputype;
  2012. fputype : tfputype;
  2013. asmmode : tasmmode;
  2014. interfacetype : tinterfacetypes;
  2015. defproccall : tproccalloption;
  2016. sourcecodepage : tstringencoding;
  2017. minfpconstprec : tfloattype;
  2018. disabledircache : boolean;
  2019. tlsmodel : ttlsmodel;
  2020. {$if defined(i8086)}
  2021. x86memorymodel : tx86memorymodel;
  2022. {$endif defined(i8086)}
  2023. {$if defined(ARM)}
  2024. instructionset : tinstructionset;
  2025. {$endif defined(ARM)}
  2026. {$if defined(LLVM) and not defined(GENERIC_CPU)}
  2027. llvmversion: tllvmversion;
  2028. {$endif defined(LLVM) and not defined(GENERIC_CPU)}
  2029. { CPU targets with microcontroller support can add a controller specific unit }
  2030. controllertype : tcontrollertype;
  2031. { WARNING: this pointer cannot be written as such in record token }
  2032. pmessage : pmessagestaterecord;
  2033. end; *)
  2034. const
  2035. targetswitchname : array[ttargetswitch] of string[30] =
  2036. { global target-specific switches }
  2037. ('Target None', {ts_none}
  2038. { generate code that results in smaller TOCs than normal (AIX) }
  2039. 'Small TOC', {ts_small_toc}
  2040. { for the JVM target: generate integer array initializations via string
  2041. constants in order to reduce the generated code size (Java routines
  2042. are limited to 64kb of bytecode) }
  2043. 'JVM compact int array init', {ts_compact_int_array_init}
  2044. { for the JVM target: intialize enum fields in constructors with the
  2045. enum class instance corresponding to ordinal value 0 (not done by
  2046. default because this initialization can only be performed after the
  2047. inherited constructors have run, and if they call a virtual method
  2048. of the current class, then this virtual method may already have
  2049. initialized that field with another value and the constructor
  2050. initialization will result in data loss }
  2051. 'JVM enum field init', {ts_jvm_enum_field_init}
  2052. { when automatically generating getters/setters for properties, use
  2053. these strings as prefixes for the generated getters/setter names }
  2054. 'Auto getter prefix', {ts_auto_getter_prefix}
  2055. 'Auto setter prefix', {ts_auto_setter_predix}
  2056. 'Thumb interworking', {ts_thumb_interworking,}
  2057. { lowercase the first character of routine names, used to generate
  2058. names that are compliant with Java coding standards from code
  2059. written according to Delphi coding standards }
  2060. 'LowerCase proc start', {ts_lowercase_proc_start,}
  2061. { initialise local variables on the JVM target so you won't get
  2062. accidental uses of uninitialised values }
  2063. 'Init locals', {ts_init_locals}
  2064. { emit a CLD instruction before using the x86 string instructions }
  2065. 'Emit CLD instruction', {ts_cld}
  2066. { increment BP before pushing it in the function prologue and decrement
  2067. it after popping it in the function epilogue, iff the function is
  2068. going to terminate with a far ret. Thus, the BP value pushed on the
  2069. stack becomes odd if the function is far and even if the function is
  2070. near. This allows walking the BP chain on the stack and e.g.
  2071. obtaining a stack trace even if the program uses a mixture of near
  2072. and far calls. This is also required for Win16 real mode, because it
  2073. allows Windows to move code segments around (in order to defragment
  2074. memory) and then walk through the stacks of all running programs and
  2075. update the segment values of the segment that has moved. }
  2076. 'Use odd BP for far procs', {ts_x86_far_procs_push_odd_bp}
  2077. 'No exception support', {ts_wasm_no_exceptions}
  2078. 'Branchful exceptions support', {ts_wasm_bf_exceptions}
  2079. 'JavaScript-based exception support', {ts_wasm_js_exceptions}
  2080. 'Native WebAssembly exceptions support' {ts_wasm_native_exceptions}
  2081. );
  2082. moduleswitchname : array[tmoduleswitch] of string[40] =
  2083. ('Module None', {cs_modulenone,}
  2084. { parser }
  2085. 'Floating Point Emulation',{ cs_fp_emulation}
  2086. 'Extended syntax', {cs_extsyntax}
  2087. 'Open string', {cs_openstring}
  2088. { support }
  2089. 'Goto allowed', {cs_support_goto}
  2090. 'Macro support', {cs_support_macro}
  2091. 'C operator support', {cs_support_c_operators}
  2092. { generation }
  2093. 'Profile', {cs_profile}
  2094. 'Debug information', {cs_debuginfo}
  2095. 'Compilation of System unit', {cs_compilesystem}
  2096. 'Line information', {cs_lineinfo}
  2097. 'Implicit exceptions', {cs_implicit_exceptions}
  2098. 'Explicit CodePage', {cs_explicit_codepage}
  2099. 'System CodePage', {cs_system_codepage}
  2100. { linking }
  2101. 'Create smart units', {cs_create_smart}
  2102. 'Create dynamic', {cs_create_dynamic}
  2103. 'Create PIC code', {cs_create_pic}
  2104. { browser switches are back }
  2105. 'Browser', {cs_browser}
  2106. 'Local Browser', {cs_local_browser}
  2107. { target specific }
  2108. 'Executable Stack', {cs_executable_stack}
  2109. { i8086 specific }
  2110. 'Huge code', {cs_huge_code}
  2111. 'Win16 smart callbacks', {cs_win16_smartcallbacks}
  2112. { Record usage of checkpointer experimental feature }
  2113. 'CheckPointer used', {cs_checkpointer_called}
  2114. 'Supports LLVM Link-Time Optimization' {cs_lto}
  2115. );
  2116. globalswitchname : array[tglobalswitch] of string[50] =
  2117. ('Global None',{cs_globalnone}
  2118. { parameter switches }
  2119. 'Check unit name', {cs_check_unit_name}
  2120. 'Constructor name', {cs_constructor_name}
  2121. 'Support exceptions',{cs_support_exceptions}
  2122. 'Support Objective-C pas',{ cs_support_c_objectivepas}
  2123. 'Transparent file names', {cs_transparent_file_names}
  2124. { units }
  2125. 'Load Objpas Unit', {cs_load_objpas_unit}
  2126. 'Load GPC unit', {cs_load_gpc_unit}
  2127. 'Load FPCKylix unit', {cs_load_fpcylix_unit}
  2128. 'Support Vectors', {cs_support_vectors}
  2129. { debuginfo }
  2130. 'Use HeapTRc unit', {cs_use_heaptrc}
  2131. 'Use line information', {cs_use_lineinfo}
  2132. 'Use GDB Valgrind', {cs_gdb_valgrind}
  2133. 'No regalloc', {cs_no_regalloc}
  2134. 'Stabs preserve cases', {cs_stabs_preservecase}
  2135. { assembling }
  2136. 'Leave assembler file', {cs_asm_leave}
  2137. 'Use external assembler', {cs_asm_extern}
  2138. 'Use pipes to call assembler', {cs_asm_pipe}
  2139. 'Add source infos into assembler files', {cs_asm_source}
  2140. 'Add register allocation into assembler files', {cs_asm_regalloc}
  2141. 'Add temporary allocation into assmebler files', {cs_asm_tempalloc}
  2142. 'Add node information into assembler files', {cs_asm_nodes}
  2143. 'Adapt assembler call to GNU version <= 2.25', {cs_asm_pre_binutils_2_25}
  2144. { linking }
  2145. 'Skip linking stage', {cs_link_nolink}
  2146. 'Link static', {cs_link_static}
  2147. 'Link smart', {cs_link_smart}
  2148. 'Link shared', {cs_link_shared}
  2149. 'Link deffile', {cs_link_deffile}
  2150. 'Strip after linking', {cs_link_strip}
  2151. 'Use linker static flag',{cs_link_staticflag}
  2152. 'Link on target OS',{cs_link_on_target}
  2153. 'Use external linker', {cs_link_extern}
  2154. 'Link opt vtable', {cs_link_opt_vtable}
  2155. 'Link opt used sections', {cs_link_opt_used_sections}
  2156. 'Link debug to separate file',{cs_link_separate_dbg_file}
  2157. 'Create linker map', {cs_link_map}
  2158. 'Link to pthread', {cs_link_pthread}
  2159. 'Link no default lib order', {cs_link_no_default_lib_order}
  2160. 'Link using native linker', {cs_link_native}
  2161. 'Link for GNU linker version <=2.19', {cs_link_pre_binutils_2_19}
  2162. 'Link using vlink', {cs_link_vlink}
  2163. 'Link-Time Optimization disabled for system unit', {cs_lto_nosystem}
  2164. 'Assemble on target OS', {cs_asemble_on_target}
  2165. 'Use a memory model to support >2GB static data on 64 Bit target', {cs_large}
  2166. 'Generate UF2 binary' {cs_generate_uf2}
  2167. );
  2168. localswitchname : array[tlocalswitch] of string[50] =
  2169. { Switches which can be changed locally }
  2170. ('Local None', {cs_localnone}
  2171. { codegen }
  2172. 'Check overflow', {cs_check_overflow}
  2173. 'Check range', {cs_check_range}
  2174. 'Check object error', {cs_check_object}
  2175. 'Check I/O error', {cs_check_io}
  2176. 'Check stack', {cs_check_stack}
  2177. 'Check pointer', {cs_checkpointer}
  2178. 'Check ordinal size', {cs_check_ordinal_size}
  2179. 'Generate stackframes', {cs_generate_stackframes}
  2180. 'Do assertions', {cs_do_assertion}
  2181. 'Generate RTTI', {cs_generate_rtti}
  2182. 'Full boolean evaluaion', {cs_full_boolean_eval}
  2183. 'Typed constant are writable', {cs_typed_const_writable}
  2184. 'Allow calcuation on enum types', {cs_allow_enum_calc}
  2185. 'Do inline', {cs_do_inline}
  2186. 'Add FWAIT instruction for FPU 8087', {cs_fpu_fwait}
  2187. 'IEEE errors', {cs_ieee_errors}
  2188. 'Check low address loading', {cs_check_low_addr_load}
  2189. 'Imported data', {cs_imported_data}
  2190. 'Excess precision', {cs_excessprecision}
  2191. 'Check fpu exceptions', {cs_check_fpu_exceptions}
  2192. 'Check all case coverage', {cs_check_all_case_coverage}
  2193. { mmx }
  2194. 'Allow MMX instructions', {cs_mmx}
  2195. 'Use MMX saturation', {cs_mmx_saturation}
  2196. { parser }
  2197. 'Use typed addresses', {cs_typed_addresses}
  2198. 'Use strict var strings', {cs_strict_var_strings}
  2199. 'Use reference counted strings', {cs_refcountedstrings}
  2200. 'Use bit-packing', {cs_bitpacking}
  2201. 'Use var property setter', {cs_varpropsetter}
  2202. 'Use scoped enums',{cs_scopedenums}
  2203. 'Use pointer math', {cs_pointermath}
  2204. { macpas specific}
  2205. 'MACPAS exteranl variable', {cs_external_var}
  2206. 'MACPAS externally visible', {cs_externally_visible}
  2207. { jvm specific }
  2208. 'JVM check var copyout', {cs_check_var_copyout}
  2209. 'Zero based strings', {cs_zerobasedstrings}
  2210. { i8086 specific }
  2211. 'i8086 force FAR calls', {cs_force_far_calls}
  2212. 'i8086 huge pointer arithmetic', {cs_hugeptr_arithmetic_normalization}
  2213. 'i8086 huge pointer comparison', {cs_hugeptr_comparison_normalization}
  2214. 'enforce legacy ifend behaviour' {cs_legacyifend}
  2215. );
  2216. { Switches which can be changed by a mode (fpc,tp7,delphi) }
  2217. modeswitchname : array[tmodeswitch] of string[50] =
  2218. ('m_none',
  2219. { generic }
  2220. 'm_fpc','m_objfpc','m_delphi','m_tp7','m_mac','m_iso','m_extpas',
  2221. {$ifdef gpc_mode}'m_gpc',{$endif}
  2222. { more specific }
  2223. 'm_class', { delphi class model }
  2224. 'm_objpas', { load objpas unit }
  2225. 'm_result', { result in functions }
  2226. 'm_string_pchar', { pchar 2 string conversion }
  2227. 'm_cvar_support', { cvar variable directive }
  2228. 'm_nested_comment', { nested comments }
  2229. 'm_tp_procvar', { tp style procvars (no @ needed) }
  2230. 'm_mac_procvar', { macpas style procvars }
  2231. 'm_repeat_forward', { repeating forward declarations is needed }
  2232. 'm_pointer_2_procedure', { allows the assignement of pointers to
  2233. procedure variables }
  2234. 'm_autoderef', { does auto dereferencing of struct. vars }
  2235. 'm_initfinal', { initialization/finalization for units }
  2236. 'm_default_ansistring', { ansistring turned on by default }
  2237. 'm_out', { support the calling convention OUT }
  2238. 'm_default_para', { support default parameters }
  2239. 'm_hintdirective', { support hint directives }
  2240. 'm_duplicate_names', { allow locals/paras to have duplicate names of globals }
  2241. 'm_property', { allow properties }
  2242. 'm_default_inline', { allow inline proc directive }
  2243. 'm_except', { allow exception-related keywords }
  2244. 'm_objectivec1', { support interfacing with Objective-C (1.0) }
  2245. 'm_objectivec2', { support interfacing with Objective-C (2.0) }
  2246. 'm_nested_procvars', { support nested procedural variables }
  2247. 'm_non_local_goto', { support non local gotos (like iso pascal) }
  2248. 'm_advanced_records', { advanced record syntax with visibility sections, methods and properties }
  2249. 'm_isolike_unary_minus', { unary minus like in iso pascal: same precedence level as binary minus/plus }
  2250. 'm_systemcodepage', { use system codepage as compiler codepage by default, emit ansistrings with system codepage }
  2251. 'm_final_fields', { allows declaring fields as "final", which means they must be initialised
  2252. in the (class) constructor and are constant from then on (same as final
  2253. fields in Java) }
  2254. 'm_default_unicodestring', { makes the default string type in $h+ mode unicodestring rather than
  2255. ansistring; similarly, char becomes unicodechar rather than ansichar }
  2256. 'm_type_helpers', { allows the declaration of "type helper" for all supported types
  2257. (primitive types, records, classes, interfaces) }
  2258. 'm_blocks', { support for http://en.wikipedia.org/wiki/Blocks_(C_language_extension) }
  2259. 'm_isolike_io', { I/O as it required by an ISO compatible compiler }
  2260. 'm_isolike_program_para',{ program parameters as it required by an ISO compatible compiler }
  2261. 'm_isolike_mod', { mod operation as it is required by an iso compatible compiler }
  2262. 'm_array_operators', { use Delphi compatible array operators instead of custom ones ("+") }
  2263. 'm_multi_helpers', { helpers can appear in multiple scopes simultaneously }
  2264. 'm_array2dynarray', { regular arrays can be implicitly converted to dynamic arrays }
  2265. 'm_prefixed_attributes', { enable attributes that are defined before the type they belong to }
  2266. 'm_underscoreisseparator'{ _ can be used as separator to group digits in numbers }
  2267. );
  2268. { optimizer }
  2269. optimizerswitchname : array[toptimizerswitch] of string[50] =
  2270. ('cs_opt_none',
  2271. 'cs_opt_level1',
  2272. 'cs_opt_level2',
  2273. 'cs_opt_level3',
  2274. 'cs_opt_level4',
  2275. 'cs_opt_regvar',
  2276. 'cs_opt_uncertain',
  2277. 'cs_opt_size',
  2278. 'cs_opt_stackframe',
  2279. 'cs_opt_peephole',
  2280. 'cs_opt_loopunroll',
  2281. 'cs_opt_tailrecursion',
  2282. 'cs_opt_nodecse',
  2283. 'cs_opt_nodedfa',
  2284. 'cs_opt_loopstrength',
  2285. 'cs_opt_scheduler',
  2286. 'cs_opt_autoinline',
  2287. 'cs_useebp',
  2288. 'cs_userbp',
  2289. 'cs_opt_reorder_fields',
  2290. 'cs_opt_fastmath',
  2291. { Allow removing expressions whose result is not used, even when this
  2292. can change program behaviour (range check errors disappear',
  2293. access violations due to invalid pointer derefences disappear, ...).
  2294. Note: it does not (and must not) remove expressions that have
  2295. explicit side-effects, only implicit side-effects (like the ones
  2296. mentioned before) can disappear.
  2297. }
  2298. 'cs_opt_dead_values',
  2299. { compiler checks for empty procedures/methods and removes calls to them if possible }
  2300. 'cs_opt_remove_empty_proc',
  2301. 'cs_opt_constant_propagate',
  2302. 'cs_opt_dead_store_eliminate',
  2303. 'cs_opt_forcenostackframe',
  2304. 'cs_opt_use_load_modify_store',
  2305. 'cs_opt_unused_para',
  2306. 'cs_opt_consts',
  2307. 'cs_opt_forloop'
  2308. );
  2309. var
  2310. globalswitch : tglobalswitch;
  2311. targetswitch : ttargetswitch;
  2312. moduleswitch : tmoduleswitch;
  2313. localswitch : tlocalswitch;
  2314. modeswitch : tmodeswitch;
  2315. optimizerswitch : toptimizerswitch;
  2316. globalswitches : tglobalswitches;
  2317. targetswitches : ttargetswitches;
  2318. moduleswitches : tmoduleswitches;
  2319. localswitches : tlocalswitches;
  2320. modeswitches : tmodeswitches;
  2321. optimizerswitches : toptimizerswitches;
  2322. begin
  2323. {alignment : talignmentinfo;}
  2324. {talignmentinfo = packed record}
  2325. writeln('Procedure alignment: '+tostr(new_settings.alignment.procalign));
  2326. writeln('Loop alignment: '+tostr(new_settings.alignment.loopalign));
  2327. { alignment for labels after unconditional jumps, this must be a power of two }
  2328. writeln('Jump alignment: '+tostr(new_settings.alignment.jumpalign));
  2329. { max. alignment for labels after unconditional jumps:
  2330. the compiler tries to align jumpalign, however, to do so it inserts at maximum jumpalignskipmax bytes or uses
  2331. the next smaller power of two of jumpalign }
  2332. writeln('Jump skip max alignment: '+tostr(new_settings.alignment.jumpalignskipmax));
  2333. { alignment for labels where two flows of the program flow coalesce, this must be a power of two }
  2334. writeln('Coalescence alignment: '+tostr(new_settings.alignment.coalescealign));
  2335. { max. alignment for labels where two flows of the program flow coalesce
  2336. the compiler tries to align to coalescealign, however, to do so it inserts at maximum coalescealignskipmax bytes or uses
  2337. the next smaller power of two of coalescealign }
  2338. writeln('Coalescence skip max alignment: '+tostr(new_settings.alignment.coalescealignskipmax));
  2339. writeln('Const min alignment: '+tostr(new_settings.alignment.constalignmin));
  2340. writeln('Const max alignment: '+tostr(new_settings.alignment.constalignmax));
  2341. writeln('Var min alignment: '+tostr(new_settings.alignment.varalignmin));
  2342. writeln('Var max alignment: '+tostr(new_settings.alignment.varalignmax));
  2343. writeln('Local min alignment: '+tostr(new_settings.alignment.localalignmin));
  2344. writeln('Local max alignment: '+tostr(new_settings.alignment.localalignmax));
  2345. writeln('Min record alignment: '+tostr(new_settings.alignment.recordalignmin));
  2346. writeln('Max record alignment: '+tostr(new_settings.alignment.recordalignmax));
  2347. writeln('Max C record alignment: '+tostr(new_settings.alignment.maxCrecordalign));
  2348. globalswitches:=new_settings.globalswitches;
  2349. for globalswitch:=low(tglobalswitch) to high(tglobalswitch) do
  2350. if globalswitch in globalswitches then
  2351. begin
  2352. writeln('global switch: '+globalswitchname[globalswitch]);
  2353. exclude(globalswitches,globalswitch);
  2354. end;
  2355. if (globalswitches <> []) then
  2356. writeln('Unknown global switch');
  2357. targetswitches:=new_settings.targetswitches;
  2358. for targetswitch:=low(ttargetswitch) to high(ttargetswitch) do
  2359. if targetswitch in targetswitches then
  2360. begin
  2361. writeln('target switch: '+targetswitchname[targetswitch]);
  2362. exclude(targetswitches,targetswitch);
  2363. end;
  2364. if (targetswitches <> []) then
  2365. writeln('Unknown target switch');
  2366. moduleswitches:=new_settings.moduleswitches;
  2367. for moduleswitch:=low(tmoduleswitch) to high(tmoduleswitch) do
  2368. if moduleswitch in moduleswitches then
  2369. begin
  2370. writeln('module switch: '+moduleswitchname[moduleswitch]);
  2371. exclude(moduleswitches,moduleswitch);
  2372. end;
  2373. if (moduleswitches <> []) then
  2374. writeln('Unknown module switch');
  2375. localswitches:=new_settings.localswitches;
  2376. for localswitch:=low(tlocalswitch) to high(tlocalswitch) do
  2377. if localswitch in localswitches then
  2378. begin
  2379. writeln('local switch: '+localswitchname[localswitch]);
  2380. exclude(localswitches,localswitch);
  2381. end;
  2382. if (localswitches <> []) then
  2383. writeln('Unknown local switch');
  2384. modeswitches:=new_settings.modeswitches;
  2385. for modeswitch:=low(tmodeswitch) to high(tmodeswitch) do
  2386. if modeswitch in modeswitches then
  2387. begin
  2388. writeln(['mode switch: ',modeswitchname[modeswitch]]);
  2389. exclude(modeswitches,modeswitch);
  2390. end;
  2391. if (modeswitches <> []) then
  2392. writeln('Unknown mode switch');
  2393. optimizerswitches:=new_settings.optimizerswitches;
  2394. for optimizerswitch:=low(toptimizerswitch) to high(toptimizerswitch) do
  2395. if optimizerswitch in optimizerswitches then
  2396. begin
  2397. writeln(['optimizer switch: ',optimizerswitchname[optimizerswitch]]);
  2398. exclude(optimizerswitches,optimizerswitch);
  2399. end;
  2400. if (optimizerswitches <> []) then
  2401. writeln('Unknown optimizer switch');
  2402. writeln(['Set allocation size ',new_settings.setalloc]);
  2403. writeln(['Pack enums ',new_settings.packenum]);
  2404. writeln(['Pack records ',new_settings.packrecords]);
  2405. writeln(['Max FPU registers ',new_settings.maxfpuregisters]);
  2406. writeln(['CPU type ',new_settings.cputype]);
  2407. writeln(['CPU optimize type ',new_settings.optimizecputype]);
  2408. writeln(['FPU type ',new_settings.fputype]);
  2409. writeln(['ASM mode ',new_settings.asmmode]);
  2410. end;
  2411. var
  2412. linestr,genstr : string;
  2413. token : ttoken;
  2414. copy_size, stbi, last_col, new_col : longint;
  2415. last_line,new_line : dword;
  2416. len : sizeint;
  2417. wstring : widestring;
  2418. astring : ansistring;
  2419. begin
  2420. tbi:=0;
  2421. last_line:=0;
  2422. last_col:=0;
  2423. linestr:='';
  2424. genstr:='';
  2425. fillchar(new_settings,sizeof(new_settings),#0);
  2426. fillchar(prev_settings,sizeof(prev_settings),#0);
  2427. write([space,' Tokens: ']);
  2428. while tbi<tokenbufsize do
  2429. begin
  2430. token:=readtoken;
  2431. if token<>_GENERICSPECIALTOKEN then
  2432. begin
  2433. if token <= high(ttoken) then
  2434. begin
  2435. write(arraytokeninfo[token].str);
  2436. if not (token in [_CWCHAR, _CWSTRING, _CSTRING, _CCHAR,
  2437. _INTCONST,_REALNUMBER, _ID]) then
  2438. StrAppend(linestr,lowercase(arraytokeninfo[token].str));
  2439. end
  2440. else
  2441. begin
  2442. HasMoreInfos;
  2443. write('Error in Token List');
  2444. break;
  2445. end;
  2446. {idtoken:=}readtoken;
  2447. end;
  2448. case token of
  2449. _CWCHAR,
  2450. _CWSTRING :
  2451. begin
  2452. len:=gettokenbufsizeint;
  2453. setlength(wstring,len);
  2454. move(tokenbuf[tbi],wstring[1],len*2);
  2455. write([' ''',wstring,'''']);
  2456. StrAppend(linestr,' ''');
  2457. StrAppend(linestr,wstring);
  2458. StrAppend(linestr,'''');
  2459. inc(tbi,len*2);
  2460. end;
  2461. _CSTRING:
  2462. begin
  2463. len:=gettokenbufsizeint;
  2464. setlength(astring,len);
  2465. if len>0 then
  2466. move(tokenbuf[tbi],astring[1],len);
  2467. write([' ''',astring,'''']);
  2468. StrAppend(linestr,' ''');
  2469. StrAppend(linestr,astring);
  2470. StrAppend(linestr,'''');
  2471. inc(tbi,len);
  2472. end;
  2473. _CCHAR:
  2474. begin
  2475. write([' ''',unaligned(pshortstring(@tokenbuf[tbi])^),'''']);
  2476. StrAppend(linestr,' ''');
  2477. StrAppend(linestr,unaligned(pshortstring(@tokenbuf[tbi])^));
  2478. StrAppend(linestr,'''');
  2479. inc(tbi,tokenbuf[tbi]+1);
  2480. end;
  2481. _INTCONST,
  2482. _REALNUMBER :
  2483. begin
  2484. write([' ',unaligned(pshortstring(@tokenbuf[tbi])^)]);
  2485. StrAppend(linestr,unaligned(pshortstring(@tokenbuf[tbi])^));
  2486. inc(tbi,tokenbuf[tbi]+1);
  2487. end;
  2488. _ID :
  2489. begin
  2490. write([' ',unaligned(pshortstring(@tokenbuf[tbi])^)]);
  2491. StrAppend(linestr,unaligned(pshortstring(@tokenbuf[tbi])^));
  2492. inc(tbi,tokenbuf[tbi]+1);
  2493. end;
  2494. _GENERICSPECIALTOKEN:
  2495. begin
  2496. { Short version of column change,
  2497. byte or $80 used }
  2498. if (tokenbuf[tbi] and $80)<>0 then
  2499. begin
  2500. new_col:=tokenbuf[tbi] and $7f;
  2501. write(['Col: ',new_col]);
  2502. if length(linestr)<new_col-1 then
  2503. StrAppend(linestr,StringOfChar(' ',new_col - 1 - length(linestr)));
  2504. inc(tbi);
  2505. last_col:=new_col;
  2506. end
  2507. else
  2508. case tspecialgenerictoken(tokenbuf[tbi]) of
  2509. ST_LOADSETTINGS:
  2510. begin
  2511. inc(tbi);
  2512. write([space,'Settings: ']);
  2513. fillchar(new_settings,sizeof(new_settings),#0);
  2514. { This does not load pmessage pointer }
  2515. new_settings.pmessage:=nil;
  2516. { TSettings size depends in target...
  2517. We first read the size of the copied part }
  2518. { Still not cross endian ready :( }
  2519. copy_size:=gettokenbufsizeint;
  2520. stbi:=tbi;
  2521. tokenreadsettings(new_settings, copy_size);
  2522. tbi:=stbi+copy_size;
  2523. if CompareByte(new_settings,prev_settings,sizeof(new_settings))<>0 then
  2524. begin
  2525. dump_new_settings;
  2526. writeln;
  2527. end
  2528. else
  2529. begin
  2530. writeln('Unchanged');
  2531. end;
  2532. prev_settings:=new_settings;
  2533. end;
  2534. ST_LOADMESSAGES:
  2535. begin
  2536. inc(tbi);
  2537. mesgnb:=tokenbuf[tbi];
  2538. writeln([space,mesgnb,' messages: ']);
  2539. inc(tbi);
  2540. for nb:=1 to mesgnb do
  2541. begin
  2542. msgvalue:=gettokenbufsizeint;
  2543. //inc(tbi,sizeof(sizeint));
  2544. state:=tmsgstate(gettokenbufsizeint);
  2545. writeln(['#',msgvalue,' ',state]);
  2546. end;
  2547. end;
  2548. ST_LINE:
  2549. begin
  2550. inc(tbi);
  2551. new_line:=gettokenbufdword;
  2552. if (new_line<>last_line) then
  2553. begin
  2554. StrAppend(genstr,linestr+LineEnding);
  2555. linestr:='';
  2556. end;
  2557. writeln(['Line: ',new_line]);
  2558. last_line:=new_line;
  2559. end;
  2560. ST_COLUMN:
  2561. begin
  2562. inc(tbi);
  2563. new_col:=gettokenbufword;
  2564. write(['Col: ',new_col]);
  2565. if length(linestr)<new_col - 1 then
  2566. StrAppend(linestr,StringOfChar(' ',new_col - 1 - length(linestr)));
  2567. last_col:=new_col;
  2568. end;
  2569. ST_FILEINDEX:
  2570. begin
  2571. inc(tbi);
  2572. StrAppend(genstr,linestr+LineEnding);
  2573. linestr:='';
  2574. write(['File: ',gettokenbufword]);
  2575. end;
  2576. else
  2577. begin
  2578. HasMoreInfos;
  2579. write('Error in Token List');
  2580. break;
  2581. end;
  2582. end;
  2583. end;
  2584. else ; { empty else to avoid warning }
  2585. end;
  2586. if tbi<tokenbufsize then
  2587. write(',');
  2588. end;
  2589. writeln;
  2590. StrAppend(genstr,linestr);
  2591. writeln(['##',genstr,'##']);
  2592. end;
  2593. procedure readcommondef(const s:string; out defoptions: tdefoptions; Def: TPpuDef = nil);
  2594. type
  2595. tdefopt=record
  2596. mask : tdefoption;
  2597. str : string[30];
  2598. end;
  2599. tdefstateinfo=record
  2600. mask : tdefstate;
  2601. str : string[30];
  2602. end;
  2603. tgenconstrflag=record
  2604. mask : tgenericconstraintflag;
  2605. str : string[30];
  2606. end;
  2607. const
  2608. defopt : array[1..ord(high(tdefoption))] of tdefopt=(
  2609. (mask:df_unique; str:'Unique Type'),
  2610. (mask:df_generic; str:'Generic'),
  2611. (mask:df_specialization; str:'Specialization'),
  2612. (mask:df_copied_def; str:'Copied Typedef'),
  2613. (mask:df_genconstraint; str:'Generic Constraint'),
  2614. { this should never happen for defs stored to a ppu file }
  2615. (mask:df_not_registered_no_free; str:'Unregistered/No free (invalid)'),
  2616. (mask:df_llvm_no_struct_packing; str:'LLVM unpacked struct'),
  2617. (mask:df_internal; str:'Internal'),
  2618. (mask:df_has_global_ref; str:'Has Global Ref'),
  2619. (mask:df_has_generic_fields; str:'Has generic fields')
  2620. );
  2621. defstate : array[1..ord(high(tdefstate))] of tdefstateinfo=(
  2622. (mask:ds_vmt_written; str:'VMT Written'),
  2623. (mask:ds_rtti_table_used; str:'RTTITable Used'),
  2624. (mask:ds_init_table_used; str:'InitTable Used'),
  2625. (mask:ds_rtti_table_written; str:'RTTITable Written'),
  2626. (mask:ds_init_table_written; str:'InitTable Written'),
  2627. (mask:ds_dwarf_dbg_info_used; str:'Dwarf DbgInfo Used'),
  2628. (mask:ds_dwarf_dbg_info_written;str:'Dwarf DbgInfo Written')
  2629. );
  2630. genconstrflag : array[1..ord(high(tgenericconstraintflag))] of tgenconstrflag=(
  2631. (mask:gcf_constructor; str:'Constructor'),
  2632. (mask:gcf_class; str:'Class'),
  2633. (mask:gcf_record; str:'Record')
  2634. );
  2635. var
  2636. defstates : tdefstates;
  2637. i, nb, len : longint;
  2638. first : boolean;
  2639. min_size, tokenbufsize : longint;
  2640. tokenbuf : pbyte;
  2641. genconstr : tgenericconstraintflags;
  2642. begin
  2643. i:=ppufile.getlongint;
  2644. if Def <> nil then
  2645. Def.Id:=i;
  2646. writeln([space,'** Definition Id ',i,' **']);
  2647. writeln([space,s]);
  2648. write ([space,' Type symbol : ']);
  2649. if Def <> nil then
  2650. readderef('', Def.Ref)
  2651. else
  2652. readderef('');
  2653. write ([space,' DefOptions : ']);
  2654. ppufile.getset(tppuset2(defoptions));
  2655. if defoptions<>[] then
  2656. begin
  2657. first:=true;
  2658. for i:=1to high(defopt) do
  2659. if (defopt[i].mask in defoptions) then
  2660. begin
  2661. if first then
  2662. first:=false
  2663. else
  2664. write(', ');
  2665. write(defopt[i].str);
  2666. end;
  2667. end;
  2668. writeln;
  2669. write ([space,' DefStates : ']);
  2670. ppufile.getset(tppuset1(defstates));
  2671. if defstates<>[] then
  2672. begin
  2673. first:=true;
  2674. for i:=1 to high(defstate) do
  2675. if (defstate[i].mask in defstates) then
  2676. begin
  2677. if first then
  2678. first:=false
  2679. else
  2680. write(', ');
  2681. write(defstate[i].str);
  2682. end;
  2683. end;
  2684. writeln;
  2685. if df_genconstraint in defoptions then
  2686. begin
  2687. ppufile.getset(tppuset1(genconstr));
  2688. write ([space,' GenConstraints : ']);
  2689. if genconstr<>[] then
  2690. begin
  2691. first:=true;
  2692. for i:=1 to high(genconstrflag) do
  2693. if (genconstrflag[i].mask in genconstr) then
  2694. begin
  2695. if first then
  2696. first:=false
  2697. else
  2698. write(', ');
  2699. write(genconstrflag[i].str);
  2700. end;
  2701. end;
  2702. writeln;
  2703. len:=ppufile.getlongint;
  2704. if len>0 then
  2705. begin
  2706. space:=' '+space;
  2707. writeln([space,'------ constraint defs begin ------']);
  2708. for i:=0 to len-1 do
  2709. begin
  2710. writeln([space,'------ constraint def ',i,' ------']);
  2711. readderef(space);
  2712. end;
  2713. writeln([space,'------ constraint defs end ------']);
  2714. delete(space,1,4);
  2715. end;
  2716. end;
  2717. if [df_generic,df_specialization]*defoptions<>[] then
  2718. begin
  2719. nb:=ppufile.getlongint;
  2720. writeln([space,'has ',nb,' parameters']);
  2721. if nb>0 then
  2722. begin
  2723. for i:=0 to nb-1 do
  2724. begin
  2725. writeln([space,'parameter ',i,': ',ppufile.getstring]);
  2726. readderef(space);
  2727. end;
  2728. end;
  2729. end;
  2730. if df_generic in defoptions then
  2731. begin
  2732. tokenbufsize:=ppufile.getlongint;
  2733. writeln([space,' Tokenbuffer size : ',tokenbufsize]);
  2734. tokenbuf:=allocmem(tokenbufsize);
  2735. ppufile.getdata(tokenbuf^,tokenbufsize);
  2736. displaytokenbuffer(tokenbuf,tokenbufsize);
  2737. freemem(tokenbuf);
  2738. end;
  2739. if df_specialization in defoptions then
  2740. begin
  2741. write ([space,' Orig. GenericDef : ']);
  2742. readderef('');
  2743. end;
  2744. space:=space+' ';
  2745. readattrs(def);
  2746. delete(space,1,4);
  2747. current_defoptions:=defoptions;
  2748. end;
  2749. { Read abstract procdef and return if inline procdef }
  2750. { type tproccalloption is in globtype unit }
  2751. { type tproctypeoption is in globtype unit }
  2752. { type tprocoption is in globtype unit }
  2753. procedure read_abstract_proc_def(var proccalloption:tproccalloption;var procoptions:tprocoptions; ProcDef: TPpuProcDef);
  2754. type
  2755. tproccallopt=record
  2756. mask : tproccalloption;
  2757. str : string[30];
  2758. end;
  2759. tproctypeopt=record
  2760. mask : tproctypeoption;
  2761. str : string[30];
  2762. end;
  2763. tprocopt=record
  2764. mask : tprocoption;
  2765. str : string[34];
  2766. end;
  2767. const
  2768. {proccalloptionStr is also in globtype unit }
  2769. proctypeopt : array[1..ord(high(tproctypeoption))] of tproctypeopt=(
  2770. (mask:potype_proginit; str:'ProgInit'),
  2771. (mask:potype_unitinit; str:'UnitInit'),
  2772. (mask:potype_unitfinalize; str:'UnitFinalize'),
  2773. (mask:potype_constructor; str:'Constructor'),
  2774. (mask:potype_destructor; str:'Destructor'),
  2775. (mask:potype_operator; str:'Operator'),
  2776. (mask:potype_procedure; str:'Procedure'),
  2777. (mask:potype_function; str:'Function'),
  2778. (mask:potype_class_constructor; str:'Class Constructor'),
  2779. (mask:potype_class_destructor; str:'Class Destructor'),
  2780. { Dispinterface property accessors }
  2781. (mask:potype_propgetter; str:'Property Getter'),
  2782. (mask:potype_propsetter; str:'Property Setter'),
  2783. (mask:potype_exceptfilter; str:'SEH filter'),
  2784. (mask:potype_mainstub; str:'main stub'),
  2785. (mask:potype_pkgstub; str:'package stub'),
  2786. (mask:potype_libmainstub; str:'library main stub')
  2787. );
  2788. procopt : array[1..ord(high(tprocoption))] of tprocopt=(
  2789. (mask:po_classmethod; str:'ClassMethod'),
  2790. (mask:po_virtualmethod; str:'VirtualMethod'),
  2791. (mask:po_abstractmethod; str:'AbstractMethod'),
  2792. (mask:po_finalmethod; str:'FinalMethod'),
  2793. (mask:po_staticmethod; str:'StaticMethod'),
  2794. (mask:po_overridingmethod;str:'OverridingMethod'),
  2795. (mask:po_methodpointer; str:'MethodPointer'),
  2796. (mask:po_interrupt; str:'Interrupt'),
  2797. (mask:po_iocheck; str:'IOCheck'),
  2798. (mask:po_assembler; str:'Assembler'),
  2799. (mask:po_msgstr; str:'MsgStr'),
  2800. (mask:po_msgint; str:'MsgInt'),
  2801. (mask:po_exports; str:'Exports'),
  2802. (mask:po_external; str:'External'),
  2803. (mask:po_overload; str:'Overload'),
  2804. (mask:po_varargs; str:'VarArgs'),
  2805. (mask:po_internconst; str:'InternConst'),
  2806. (mask:po_addressonly; str:'AddressOnly'),
  2807. (mask:po_public; str:'Public'),
  2808. (mask:po_hascallingconvention;str:'HasCallingConvention'),
  2809. (mask:po_reintroduce; str:'ReIntroduce'),
  2810. (mask:po_explicitparaloc; str:'ExplicitParaloc'),
  2811. (mask:po_nostackframe; str:'NoStackFrame'),
  2812. (mask:po_has_mangledname; str:'HasMangledName'),
  2813. (mask:po_has_public_name; str:'HasPublicName'),
  2814. (mask:po_forward; str:'Forward'),
  2815. (mask:po_global; str:'Global'),
  2816. (mask:po_syscall; str:'Syscall'),
  2817. (mask:po_syscall_legacy; str:'SyscallLegacy'),
  2818. (mask:po_syscall_basenone;str:'SyscallBaseNone'),
  2819. (mask:po_syscall_basefirst;str:'SyscallBaseFirst'),
  2820. (mask:po_syscall_baselast;str:'SyscallBaseLast'),
  2821. (mask:po_syscall_basereg; str:'SyscallBaseReg'),
  2822. (mask:po_syscall_has_libsym; str:'Has LibSym'),
  2823. (mask:po_syscall_has_importnr; str:'Uses ImportNr'),
  2824. (mask:po_inline; str:'Inline'),
  2825. (mask:po_compilerproc; str:'CompilerProc'),
  2826. (mask:po_has_importdll; str:'HasImportDLL'),
  2827. (mask:po_has_importname; str:'HasImportName'),
  2828. (mask:po_kylixlocal; str:'KylixLocal'),
  2829. (mask:po_dispid; str:'DispId'),
  2830. (mask:po_weakexternal; str:'WeakExternal'),
  2831. (mask:po_objc; str:'ObjC'),
  2832. (mask:po_enumerator_movenext; str:'EnumeratorMoveNext'),
  2833. (mask:po_optional; str: 'Optional'),
  2834. (mask:po_delphi_nested_cc;str: 'Delphi-style nested frameptr'),
  2835. (mask:po_java_nonvirtual; str: 'Java non-virtual method'),
  2836. (mask:po_ignore_for_overload_resolution;str: 'Ignored for overload resolution'),
  2837. (mask:po_rtlproc; str: 'RTL procedure'),
  2838. (mask:po_auto_raised_visibility; str: 'Visibility raised by compiler'),
  2839. (mask:po_far; str: 'Far'),
  2840. (mask:po_hasnearfarcallmodel; str: 'Near/Far explicit'),
  2841. (mask:po_noreturn; str: 'No return'),
  2842. (mask:po_is_function_ref; str: 'Function reference'),
  2843. (mask:po_is_block; str: 'C "Block"'),
  2844. (mask:po_is_auto_getter; str: 'Automatically generated getter'),
  2845. (mask:po_is_auto_setter; str: 'Automatically generated setter'),
  2846. (mask:po_noinline; str: 'Never inline'),
  2847. (mask:po_variadic; str: 'C VarArgs with array-of-const para'),
  2848. (mask:po_objc_related_result_type; str: 'Objective-C related result type')
  2849. );
  2850. var
  2851. proctypeoption : tproctypeoption;
  2852. i : longint;
  2853. first : boolean;
  2854. begin
  2855. write([space,' Return type : ']);
  2856. readderef('', ProcDef.ReturnType);
  2857. proctypeoption:=tproctypeoption(ppufile.getbyte);
  2858. case proctypeoption of
  2859. potype_function: Include(ProcDef.Options, poFunction);
  2860. potype_procedure: Include(ProcDef.Options, poProcedure);
  2861. potype_constructor: Include(ProcDef.Options, poConstructor);
  2862. potype_destructor: Include(ProcDef.Options, poDestructor);
  2863. potype_operator: Include(ProcDef.Options, poOperator);
  2864. end;
  2865. write([space,' TypeOption : ']);
  2866. first:=true;
  2867. for i:=1 to high(proctypeopt) do
  2868. if (proctypeopt[i].mask=proctypeoption) then
  2869. begin
  2870. if first then
  2871. first:=false
  2872. else
  2873. write(', ');
  2874. write(proctypeopt[i].str);
  2875. end;
  2876. writeln;
  2877. proccalloption:=tproccalloption(ppufile.getbyte);
  2878. writeln([space,' CallOption : ',proccalloptionStr[proccalloption]]);
  2879. ppufile.getset(tppuset8(procoptions));
  2880. if procoptions<>[] then
  2881. begin
  2882. if po_classmethod in procoptions then Include(ProcDef.Options, poClassMethod);
  2883. if po_virtualmethod in procoptions then Include(ProcDef.Options, poVirtual);
  2884. if po_abstractmethod in procoptions then Include(ProcDef.Options, poAbstract);
  2885. if po_overridingmethod in procoptions then Include(ProcDef.Options, poOverriding);
  2886. if po_overload in procoptions then Include(ProcDef.Options, poOverload);
  2887. if po_inline in procoptions then Include(ProcDef.Options, poInline);
  2888. if (po_methodpointer in procoptions) and (ProcDef.DefType = dtProcType) then
  2889. TPpuProcTypeDef(ProcDef).MethodPtr:=True;
  2890. write([space,' Options : ']);
  2891. first:=true;
  2892. for i:=1 to high(procopt) do
  2893. if (procopt[i].mask in procoptions) then
  2894. begin
  2895. if first then
  2896. first:=false
  2897. else
  2898. write(', ');
  2899. write(procopt[i].str);
  2900. end;
  2901. writeln;
  2902. end;
  2903. if (po_explicitparaloc in procoptions) then
  2904. begin
  2905. readcgpara(space);
  2906. end;
  2907. end;
  2908. { type tvaroption is in unit symconst }
  2909. { register variable }
  2910. { type tvarregable is in unit symconst }
  2911. procedure readabstractvarsym(const s:string;var varoptions:tvaroptions; VarDef: TPpuVarDef = nil);
  2912. type
  2913. tvaropt=record
  2914. mask : tvaroption;
  2915. str : string[30];
  2916. end;
  2917. const
  2918. varopt : array[1..ord(high(tvaroption))] of tvaropt=(
  2919. (mask:vo_is_external; str:'External'),
  2920. (mask:vo_is_dll_var; str:'DLLVar'),
  2921. (mask:vo_is_thread_var; str:'ThreadVar'),
  2922. (mask:vo_has_local_copy; str:'HasLocalCopy'),
  2923. (mask:vo_is_const; str:'Constant'),
  2924. (mask:vo_is_public; str:'Public'),
  2925. (mask:vo_is_high_para; str:'HighValue'),
  2926. (mask:vo_is_funcret; str:'Funcret'),
  2927. (mask:vo_is_self; str:'Self'),
  2928. (mask:vo_is_vmt; str:'VMT'),
  2929. (mask:vo_is_result; str:'Result'),
  2930. (mask:vo_is_parentfp; str:'ParentFP'),
  2931. (mask:vo_is_loop_counter; str:'LoopCounter'),
  2932. (mask:vo_is_hidden_para; str:'Hidden'),
  2933. (mask:vo_has_explicit_paraloc;str:'ExplicitParaloc'),
  2934. (mask:vo_is_syscall_lib; str:'SysCallLib'),
  2935. (mask:vo_has_mangledname; str:'HasMangledName'),
  2936. (mask:vo_is_typed_const; str:'TypedConst'),
  2937. (mask:vo_is_range_check; str:'RangeCheckSwitch'),
  2938. (mask:vo_is_overflow_check; str:'OverflowCheckSwitch'),
  2939. (mask:vo_is_typinfo_para; str:'TypeInfo'),
  2940. (mask:vo_is_msgsel;str:'MsgSel'),
  2941. (mask:vo_is_weak_external;str:'WeakExternal'),
  2942. (mask:vo_is_first_field;str:'IsFirstField'),
  2943. (mask:vo_volatile; str:'Volatile'),
  2944. (mask:vo_has_section; str:'HasSection'),
  2945. (mask:vo_force_finalize; str:'ForceFinalize'),
  2946. (mask:vo_is_default_var; str:'DefaultIntrinsicVar'),
  2947. (mask:vo_is_far; str:'IsFar'),
  2948. (mask:vo_has_global_ref; str:'HasGlobalRef')
  2949. );
  2950. type
  2951. tvaraccessdesc=record
  2952. mask: tvarsymaccessflag;
  2953. str: string[30];
  2954. end;
  2955. const
  2956. varaccessstr : array[ord(low(tvarsymaccessflag))..ord(high(tvarsymaccessflag))] of tvaraccessdesc=(
  2957. (mask: vsa_addr_taken; str:'Address taken'),
  2958. (mask: vsa_different_scope; str:'Accessed from different scope')
  2959. );
  2960. var
  2961. i : longint;
  2962. accessflag: tvarsymaccessflag;
  2963. varsymaccessflags: tvarsymaccessflags;
  2964. first : boolean;
  2965. begin
  2966. readcommonsym(s, VarDef);
  2967. i:=ppufile.getbyte;
  2968. if (VarDef <> nil) and (VarDef.DefType = dtParam) then
  2969. with TPpuParamDef(VarDef) do
  2970. case tvarspez(i) of
  2971. vs_value: Spez:=psValue;
  2972. vs_var: Spez:=psVar;
  2973. vs_out: Spez:=psOut;
  2974. vs_const: Spez:=psConst;
  2975. vs_constref: Spez:=psConstRef;
  2976. end;
  2977. writeln([space,' Spez : ',Varspez2Str(i)]);
  2978. writeln([space,' Regable : ',Varregable2Str(ppufile.getbyte)]);
  2979. ppufile.getset(tppuset1(varsymaccessflags));
  2980. write([space, ' Access Flags : ']);
  2981. first:=true;
  2982. for i:=low(varaccessstr) to high(varaccessstr) do
  2983. begin
  2984. if varaccessstr[i].mask in varsymaccessflags then
  2985. begin
  2986. if first then
  2987. first:=false
  2988. else
  2989. write([', ']);
  2990. write([varaccessstr[i].str]);
  2991. end
  2992. end;
  2993. writeln;
  2994. write ([space,' Var Type : ']);
  2995. if VarDef <> nil then
  2996. readderef('',VarDef.VarType)
  2997. else
  2998. readderef('');
  2999. ppufile.getset(tppuset4(varoptions));
  3000. if varoptions<>[] then
  3001. begin
  3002. if (VarDef <> nil) and (VarDef.DefType = dtParam) and (vo_is_hidden_para in varoptions) then
  3003. TPpuParamDef(VarDef).Spez:=psHidden;
  3004. write([space,' Options : ']);
  3005. first:=true;
  3006. for i:=1 to high(varopt) do
  3007. if (varopt[i].mask in varoptions) then
  3008. begin
  3009. if first then
  3010. first:=false
  3011. else
  3012. write(', ');
  3013. write(varopt[i].str);
  3014. end;
  3015. writeln;
  3016. end;
  3017. end;
  3018. procedure readobjectdefoptions(ObjDef: TPpuObjectDef = nil);
  3019. type
  3020. tsymopt=record
  3021. mask : tobjectoption;
  3022. str : string[30];
  3023. end;
  3024. const
  3025. symopt : array[1..ord(high(tobjectoption))] of tsymopt=(
  3026. (mask:oo_is_forward; str:'IsForward'),
  3027. (mask:oo_is_abstract; str:'IsAbstract'),
  3028. (mask:oo_is_sealed; str:'IsSealed'),
  3029. (mask:oo_has_virtual; str:'HasVirtual'),
  3030. (mask:oo_has_private; str:'HasPrivate'),
  3031. (mask:oo_has_protected; str:'HasProtected'),
  3032. (mask:oo_has_strictprivate; str:'HasStrictPrivate'),
  3033. (mask:oo_has_strictprotected;str:'HasStrictProtected'),
  3034. (mask:oo_has_constructor; str:'HasConstructor'),
  3035. (mask:oo_has_destructor; str:'HasDestructor'),
  3036. (mask:oo_has_vmt; str:'HasVMT'),
  3037. (mask:oo_has_msgstr; str:'HasMsgStr'),
  3038. (mask:oo_has_msgint; str:'HasMsgInt'),
  3039. (mask:oo_can_have_published; str:'CanHavePublished'),
  3040. (mask:oo_has_default_property;str:'HasDefaultProperty'),
  3041. (mask:oo_has_valid_guid; str:'HasValidGUID'),
  3042. (mask:oo_has_enumerator_movenext; str:'HasEnumeratorMoveNext'),
  3043. (mask:oo_has_enumerator_current; str:'HasEnumeratorCurrent'),
  3044. (mask:oo_is_external; str:'External'),
  3045. (mask:oo_is_formal; str:'Formal'),
  3046. (mask:oo_is_classhelper; str:'Class Helper/Category'),
  3047. (mask:oo_has_class_constructor; str:'HasClassConstructor'),
  3048. (mask:oo_has_class_destructor; str:'HasClassDestructor'),
  3049. (mask:oo_is_enum_class; str:'JvmEnumClass'),
  3050. (mask:oo_has_new_destructor; str:'HasNewDestructor')
  3051. );
  3052. var
  3053. i : longint;
  3054. first : boolean;
  3055. begin
  3056. ppufile.getset(tppuset4(current_objectoptions));
  3057. if current_objectoptions<>[] then
  3058. begin
  3059. if ObjDef <> nil then
  3060. begin
  3061. if oo_is_abstract in current_objectoptions then
  3062. Include(ObjDef.Options, ooIsAbstract);
  3063. end;
  3064. first:=true;
  3065. for i:=1 to high(symopt) do
  3066. if (symopt[i].mask in current_objectoptions) then
  3067. begin
  3068. if first then
  3069. first:=false
  3070. else
  3071. write(', ');
  3072. write(symopt[i].str);
  3073. end;
  3074. end;
  3075. writeln;
  3076. end;
  3077. procedure readprocimploptions(const space: string; out implprocoptions: timplprocoptions);
  3078. type
  3079. tpiopt=record
  3080. mask : timplprocoption;
  3081. str : string[30];
  3082. end;
  3083. const
  3084. piopt : array[low(timplprocoption)..high(timplprocoption)] of tpiopt=(
  3085. (mask:pio_empty; str:'IsEmpty'),
  3086. (mask:pio_has_inlininginfo; str:'HasInliningInfo'),
  3087. (mask:pio_inline_not_possible; str:'InlineNotPossible'),
  3088. (mask:pio_nested_access; str:'NestedAccess'),
  3089. (mask:pio_thunk; str:'Thunk'),
  3090. (mask:pio_fastmath; str:'FastMath'),
  3091. (mask:pio_inline_forbidden; str:'InlineForbidden')
  3092. );
  3093. var
  3094. i: timplprocoption;
  3095. first: boolean;
  3096. begin
  3097. ppufile.getset(tppuset1(implprocoptions));
  3098. if implprocoptions<>[] then
  3099. begin
  3100. first:=true;
  3101. write([space,' Options : ']);
  3102. for i:=low(piopt) to high(piopt) do
  3103. begin
  3104. if i in implprocoptions then
  3105. begin
  3106. if first then
  3107. first:=false
  3108. else
  3109. write(', ');
  3110. write(piopt[i].str);
  3111. end;
  3112. end;
  3113. writeln;
  3114. end;
  3115. end;
  3116. procedure readarraydefoptions(ArrayDef: TPpuArrayDef);
  3117. { type tarraydefoption is in unit symconst }
  3118. const
  3119. symopt : array[tarraydefoption] of string = (
  3120. { ado_IsConvertedPointer } 'ConvertedPointer',
  3121. { ado_IsDynamicArray } 'IsDynamicArray',
  3122. { ado_IsVariant } 'IsVariant',
  3123. { ado_IsConstructor } 'IsConstructor',
  3124. { ado_IsArrayOfConst } 'ArrayOfConst',
  3125. { ado_IsConstString } 'ConstString',
  3126. { ado_IsBitPacked } 'BitPacked',
  3127. { ado_IsVector } 'Vector',
  3128. { ado_IsGeneric } 'Generic',
  3129. { ado_OpenArray } 'OpenArray'
  3130. );
  3131. var
  3132. symoptions: tarraydefoptions;
  3133. i: tarraydefoption;
  3134. first: boolean;
  3135. begin
  3136. ppufile.getset(tppuset2(symoptions));
  3137. if symoptions<>[] then
  3138. begin
  3139. if ado_IsDynamicArray in symoptions then Include(ArrayDef.Options, aoDynamic);
  3140. first:=true;
  3141. for i:=Low(symopt) to high(symopt) do
  3142. if (i in symoptions) then
  3143. begin
  3144. if first then
  3145. first:=false
  3146. else
  3147. write(', ');
  3148. write(symopt[i]);
  3149. end;
  3150. end;
  3151. writeln;
  3152. end;
  3153. (* options for properties
  3154. tpropertyoption=(ppo_none,
  3155. ppo_indexed,
  3156. ppo_defaultproperty,
  3157. ppo_stored,
  3158. ppo_hasparameters,
  3159. ppo_implements,
  3160. ppo_enumerator_current,
  3161. ppo_overrides,
  3162. ppo_dispid_write { no longer used }
  3163. );
  3164. tpropertyoptions=set of tpropertyoption;
  3165. *)
  3166. function readpropertyoptions:tpropertyoptions;
  3167. { type tarraydefoption is in unit symconst }
  3168. type
  3169. tpropopt=record
  3170. mask : tpropertyoption;
  3171. str : string[30];
  3172. end;
  3173. const
  3174. symopt : array[1..ord(high(tpropertyoption))] of tpropopt=(
  3175. (mask:ppo_indexed;str:'indexed'),
  3176. (mask:ppo_defaultproperty;str:'default'),
  3177. (mask:ppo_stored;str:'stored'),
  3178. (mask:ppo_hasparameters;str:'has parameters'),
  3179. (mask:ppo_implements;str:'implements'),
  3180. (mask:ppo_enumerator_current;str:'enumerator current'),
  3181. (mask:ppo_overrides;str:'overrides'),
  3182. (mask:ppo_dispid_write;str:'dispid write') { no longer used }
  3183. );
  3184. var
  3185. i : longint;
  3186. first : boolean;
  3187. begin
  3188. ppufile.getset(tppuset2(result));
  3189. if result<>[] then
  3190. begin
  3191. first:=true;
  3192. for i:=1 to high(symopt) do
  3193. if (symopt[i].mask in result) then
  3194. begin
  3195. if first then
  3196. first:=false
  3197. else
  3198. write(', ');
  3199. write(symopt[i].str);
  3200. end;
  3201. end;
  3202. writeln;
  3203. end;
  3204. function readmanagementoperatoroptions(const space : string;const name : string):tmanagementoperators;
  3205. { type is in unit symconst }
  3206. { Management operator options
  3207. tmanagementoperator=(
  3208. mop_none,
  3209. mop_initialize,
  3210. mop_finalize,
  3211. mop_addref,
  3212. mop_copy);
  3213. }
  3214. type
  3215. tmopopt=record
  3216. mask : tmanagementoperator;
  3217. str : string[10];
  3218. end;
  3219. const
  3220. managementoperatoropt : array[1..ord(high(tmanagementoperator))] of tmopopt=(
  3221. (mask:mop_initialize;str:'initialize'),
  3222. (mask:mop_finalize;str:'finalize'),
  3223. (mask:mop_addref;str:'addref'),
  3224. (mask:mop_copy;str:'copy')
  3225. );
  3226. var
  3227. i : longint;
  3228. first : boolean;
  3229. begin
  3230. ppufile.getset(tppuset1(result));
  3231. if result<>[] then
  3232. begin
  3233. first:=true;
  3234. for i:=1 to high(managementoperatoropt) do
  3235. if (managementoperatoropt[i].mask in result) then
  3236. begin
  3237. if first then
  3238. begin
  3239. write(space);
  3240. write(name);
  3241. write(': ');
  3242. first:=false;
  3243. end
  3244. else
  3245. write(', ');
  3246. write(managementoperatoropt[i].str);
  3247. end;
  3248. if not first then
  3249. writeln;
  3250. end;
  3251. end;
  3252. procedure readnodetree;
  3253. var
  3254. l : longint;
  3255. p : pointer;
  3256. begin
  3257. with ppufile do
  3258. begin
  3259. if space<>'' then
  3260. Writeln([space,'------ nodetree ------']);
  3261. if readentry=ibnodetree then
  3262. begin
  3263. l:=entrysize;
  3264. Writeln([space,'Tree size : ',l]);
  3265. { Read data to prevent error that entry is not completly read }
  3266. getmem(p,l);
  3267. getdata(p^,l);
  3268. freemem(p);
  3269. end
  3270. else
  3271. begin
  3272. WriteError('!! ibnodetree not found');
  3273. end;
  3274. end;
  3275. end;
  3276. procedure ReadCreatedObjTypes;
  3277. var
  3278. i,j,
  3279. len,
  3280. bssize: longint;
  3281. bs: pbyte;
  3282. begin
  3283. if ppufile.readentry<>ibcreatedobjtypes then
  3284. begin
  3285. WriteError('!! ibcreatedobjtypes entry not found');
  3286. ppufile.skipdata(ppufile.entrysize);
  3287. exit
  3288. end;
  3289. writeln;
  3290. writeln([space,'WPO info']);
  3291. writeln([space,'--------']);
  3292. len:=ppufile.getlongint;
  3293. writeln([space,'** Instantiated Object/Class 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,'** 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,'** Possibly instantiated ClassRef types : ',len,' **']);
  3306. space:=space+' ';
  3307. for i:=0 to len-1 do
  3308. readderef(space);
  3309. setlength(space,length(space)-2);
  3310. len:=ppufile.getlongint;
  3311. writeln([space,'** Class types with called virtual methods info : ',len,' **']);
  3312. space:=space+' ';
  3313. for i:=0 to len-1 do
  3314. begin
  3315. write([space,'Class def : ']);
  3316. readderef('');
  3317. write([space+' ','Called vmtentries : ']);
  3318. bssize:=ppufile.getlongint;
  3319. getmem(bs,bssize);
  3320. ppufile.readdata(bs^,bssize);
  3321. for j:=0 to bssize*8-1 do
  3322. if (((bs+j shr 3)^ shr (j and 7)) and 1) <> 0 then
  3323. write([j,', ']);
  3324. writeln;
  3325. freemem(bs);
  3326. end;
  3327. setlength(space,length(space)-2);
  3328. end;
  3329. {****************************************************************************
  3330. Read Symbols Part
  3331. ****************************************************************************}
  3332. procedure readsymbols(const s:string; ParentDef: TPpuContainerDef = nil);
  3333. function _finddef(symdef: TPpuDef): TPpuDef;
  3334. begin
  3335. Result:=nil;
  3336. if symdef.Ref.IsCurUnit then
  3337. begin;
  3338. Result:=CurUnit.FindById(symdef.Ref.Id);
  3339. if (Result <> nil) and (Result.Ref.Id = symdef.Id) then
  3340. begin
  3341. Result.Name:=symdef.Name;
  3342. Result.FilePos:=symdef.FilePos;
  3343. end
  3344. else
  3345. Result:=nil;
  3346. end;
  3347. end;
  3348. type
  3349. pguid = ^tguid;
  3350. tguid = packed record
  3351. D1: LongWord;
  3352. D2: Word;
  3353. D3: Word;
  3354. D4: array[0..7] of Byte;
  3355. end;
  3356. var
  3357. b : byte;
  3358. pc : pchar;
  3359. ch : dword;
  3360. startnewline : boolean;
  3361. i,j,len : longint;
  3362. prettyname, ss : ansistring;
  3363. ws: widestring;
  3364. guid : tguid;
  3365. realvalue : ppureal;
  3366. doublevalue : double;
  3367. singlevalue : single;
  3368. realstr : shortstring;
  3369. extended : TSplit80bitReal;
  3370. pw : pcompilerwidestring;
  3371. varoptions : tvaroptions;
  3372. propoptions : tpropertyoptions;
  3373. iexp: Tconstexprint;
  3374. def: TPpuDef;
  3375. constdef: TPpuConstDef absolute def;
  3376. begin
  3377. with ppufile do
  3378. begin
  3379. if space<>'' then
  3380. Writeln([space,'------ ',s,' ------']);
  3381. if readentry=ibstartsyms then
  3382. begin
  3383. Writeln([space,'Symtable count: ',getlongint]);
  3384. end
  3385. else
  3386. Writeln('!! ibstartsym not found');
  3387. repeat
  3388. def:=nil;
  3389. b:=readentry;
  3390. case b of
  3391. ibunitsym :
  3392. readcommonsym('Unit symbol ');
  3393. ibnamespacesym :
  3394. begin
  3395. readcommonsym('NameSpace symbol ');
  3396. write([space,' Hidden Unit : ']);
  3397. readderef('');
  3398. end;
  3399. iblabelsym :
  3400. readcommonsym('Label symbol ');
  3401. ibtypesym :
  3402. begin
  3403. def:=TPpuTypeRef.Create(nil);
  3404. readcommonsym('Type symbol ',def);
  3405. write([space,' Result Type : ']);
  3406. readderef('', def.Ref);
  3407. if _finddef(def) = nil then
  3408. def.Parent:=ParentDef;
  3409. prettyname:=getansistring;
  3410. if prettyname<>'' then
  3411. begin
  3412. write([space,' Pretty Name : ']);
  3413. Writeln(prettyname);
  3414. end;
  3415. end;
  3416. ibprocsym :
  3417. begin
  3418. def:=TPpuDef.Create(nil);
  3419. readcommonsym('Procedure symbol ', def);
  3420. len:=ppufile.getword;
  3421. for i:=1 to len do
  3422. begin
  3423. write([space,' Definition : ']);
  3424. readderef('', def.Ref);
  3425. _finddef(def);
  3426. end;
  3427. if def.GenericDummy then
  3428. begin
  3429. len:=ppufile.getword;
  3430. for i:=1 to len do
  3431. begin
  3432. write([space,' Gen Ovld : ']);
  3433. readderef('',def.Ref);
  3434. _finddef(def);
  3435. end;
  3436. end;
  3437. end;
  3438. ibconstsym :
  3439. begin
  3440. constdef:=TPpuConstDef.Create(ParentDef);
  3441. readcommonsym('Constant symbol ',constdef);
  3442. b:=getbyte;
  3443. case tconsttyp(b) of
  3444. constord :
  3445. begin
  3446. write ([space,' OrdinalType : ']);
  3447. readderef('',constdef.TypeRef);
  3448. iexp:=getexprint;
  3449. constdef.ConstType:=ctInt;
  3450. constdef.VInt:=iexp.svalue;
  3451. writeln([space,' Value : ',constexp.tostr(iexp)]);
  3452. end;
  3453. constpointer :
  3454. begin
  3455. write ([space,' PointerType : ']);
  3456. readderef('',constdef.TypeRef);
  3457. constdef.ConstType:=ctInt;
  3458. constdef.VInt:=int64(getptruint);
  3459. writeln([space,' Value : ',constdef.VInt])
  3460. end;
  3461. conststring,
  3462. constresourcestring :
  3463. begin
  3464. write ([space,' StringType : ']);
  3465. readderef('',constdef.TypeRef);
  3466. len:=getlongint;
  3467. getmem(pc,len+1);
  3468. getdata(pc^,len);
  3469. (pc+len)^:= #0;
  3470. writeln([space,' Length : ',len]);
  3471. writeln([space,' Value : "',pc,'"']);
  3472. constdef.ConstType:=ctStr;
  3473. SetString(constdef.VStr, pc, len);
  3474. constdef.VStr:=UTF8Encode(constdef.VStr);
  3475. freemem(pc,len+1);
  3476. end;
  3477. constreal :
  3478. begin
  3479. constdef.ConstType:=ctFloat;
  3480. write ([space,' RealType : ']);
  3481. readderef('',constdef.TypeRef);
  3482. write([space,' Value : ']);
  3483. if entryleft=sizeof(ppureal) then
  3484. begin
  3485. realvalue:=getrealsize(sizeof(ppureal));
  3486. constdef.VFloat:=realvalue;
  3487. system.str(realvalue,realstr);
  3488. writeln([realstr]);
  3489. end
  3490. else if entryleft=sizeof(double) then
  3491. begin
  3492. doublevalue:=getrealsize(sizeof(double));
  3493. constdef.VFloat:=doublevalue;
  3494. system.str(doublevalue,realstr);
  3495. writeln([realstr]);
  3496. end
  3497. else if entryleft=sizeof(single) then
  3498. begin
  3499. singlevalue:=getrealsize(sizeof(single));
  3500. constdef.VFloat:=singlevalue;
  3501. system.str(singlevalue,realstr);
  3502. writeln([realstr]);
  3503. end
  3504. else if entryleft=10 then
  3505. begin
  3506. getdata(extended,entryleft);
  3507. ss:=Real80bitToStr(extended,constdef.VFloat);
  3508. writeln(ss);
  3509. end
  3510. else
  3511. begin
  3512. realvalue:=0.0;
  3513. WriteError('Error reading real value');
  3514. end;
  3515. end;
  3516. constset :
  3517. begin
  3518. constdef.ConstType:=ctSet;
  3519. write ([space,' Set Type : ']);
  3520. readderef('',constdef.TypeRef);
  3521. for i:=1to 4 do
  3522. begin
  3523. write ([space,' Value : ']);
  3524. for j:=1to 8 do
  3525. begin
  3526. if j>1 then
  3527. write(',');
  3528. b:=getbyte;
  3529. write(hexstr(b,2));
  3530. constdef.VSet[i*j-1]:=b;
  3531. end;
  3532. writeln;
  3533. end;
  3534. end;
  3535. constnil:
  3536. begin
  3537. write([space,' NIL pointer :']);
  3538. readderef('',constdef.TypeRef);
  3539. constdef.ConstType:=ctPtr;
  3540. constdef.VInt:=0;
  3541. end;
  3542. constwstring :
  3543. begin
  3544. initwidestring(pw);
  3545. setlengthwidestring(pw,getlongint);
  3546. if widecharsize=2 then
  3547. { don't use getdata, because the compilerwidechars may have to
  3548. be byteswapped
  3549. }
  3550. begin
  3551. for i:=0 to pw^.len-1 do
  3552. pw^.data[i]:=ppufile.getword;
  3553. SetString(ws, PWideChar(pw^.data), pw^.len);
  3554. constdef.VStr:=UTF8Encode(ws);
  3555. constdef.ConstType:=ctStr;
  3556. end
  3557. else if widecharsize=4 then
  3558. begin
  3559. for i:=0 to pw^.len-1 do
  3560. pw^.data[i]:=cardinal(ppufile.getlongint);
  3561. end
  3562. else
  3563. begin
  3564. WriteError('Unsupported tcompilerwidechar size');
  3565. end;
  3566. Write([space,'Wide string type']);
  3567. startnewline:=true;
  3568. for i:=0 to pw^.len-1 do
  3569. begin
  3570. if startnewline then
  3571. begin
  3572. writeln;
  3573. write(space);
  3574. startnewline:=false;
  3575. end;
  3576. ch:=pw^.data[i];
  3577. if widecharsize=2 then
  3578. write(hexstr(ch,4))
  3579. else
  3580. write(hexstr(ch,8));
  3581. if ((i + 1) mod 8)= 0 then
  3582. startnewline:=true
  3583. else
  3584. if i <> pw^.len-1 then
  3585. write(', ');
  3586. end;
  3587. donewidestring(pw);
  3588. Writeln;
  3589. end;
  3590. constguid:
  3591. begin
  3592. write ([space,' IntfType : ']);
  3593. readderef('',constdef.TypeRef);
  3594. getdata(guid,sizeof(guid));
  3595. write ([space,' IID String: {',hexstr(guid.d1,8),'-',hexstr(guid.d2,4),'-',hexstr(guid.d3,4),'-']);
  3596. for i:=0 to 7 do
  3597. begin
  3598. write(hexstr(guid.d4[i],2));
  3599. if i=1 then write('-');
  3600. end;
  3601. writeln('}');
  3602. end
  3603. else
  3604. Writeln (['!! Invalid unit format : Invalid const type encountered: ',b]);
  3605. end;
  3606. end;
  3607. ibabsolutevarsym :
  3608. begin
  3609. def:=TPpuVarDef.Create(ParentDef);
  3610. readabstractvarsym('Absolute variable symbol ',varoptions,TPpuVarDef(def));
  3611. Write ([space,' Relocated to ']);
  3612. b:=getbyte;
  3613. case absolutetyp(b) of
  3614. tovar :
  3615. readpropaccesslist(space+' Sym : ');
  3616. toasm :
  3617. Writeln(['Assembler name : ',getstring]);
  3618. toaddr :
  3619. begin
  3620. Write(['Address : ',getpuint]);
  3621. if tsystemcpu(ppufile.header.common.cpu)=cpu_i386 then
  3622. Write([' (Far: ',getbyte<>0,')']);
  3623. if tsystemcpu(ppufile.header.common.cpu)=cpu_i8086 then
  3624. if getbyte<>0 then
  3625. Write([' (Far: TRUE, Segment=',getaword,')'])
  3626. else
  3627. Write([' (Far: FALSE)']);
  3628. Writeln;
  3629. end;
  3630. else
  3631. Writeln (['!! Invalid unit format : Invalid absolute type encountered: ',b]);
  3632. end;
  3633. end;
  3634. ibfieldvarsym :
  3635. begin
  3636. def:=TPpuFieldDef.Create(ParentDef);
  3637. readabstractvarsym('Field Variable symbol ',varoptions,TPpuVarDef(def));
  3638. writeln([space,' Address : ',getasizeint]);
  3639. if vo_has_mangledname in varoptions then
  3640. writeln([space,' Mangled name : ',getstring]);
  3641. end;
  3642. ibstaticvarsym :
  3643. begin
  3644. def:=TPpuVarDef.Create(ParentDef);
  3645. readabstractvarsym('Global Variable symbol ',varoptions,TPpuVarDef(def));
  3646. write ([space,' DefaultConst : ']);
  3647. readderef('');
  3648. if (vo_has_mangledname in varoptions) then
  3649. writeln([space,'Mangledname : ',readsymstr(ppufile)]);
  3650. if vo_has_section in varoptions then
  3651. writeln(['Section name:',ppufile.getansistring]);
  3652. write ([space,' FieldVarSymDeref: ']);
  3653. readderef('');
  3654. end;
  3655. iblocalvarsym :
  3656. begin
  3657. readabstractvarsym('Local Variable symbol ',varoptions);
  3658. write ([space,' DefaultConst : ']);
  3659. readderef('');
  3660. end;
  3661. ibparavarsym :
  3662. begin
  3663. def:=TPpuParamDef.Create(ParentDef);
  3664. readabstractvarsym('Parameter Variable symbol ',varoptions,TPpuVarDef(def));
  3665. write ([space,' DefaultConst : ']);
  3666. readderef('',TPpuParamDef(def).DefaultValue);
  3667. writeln([space,' ParaNr : ',getword]);
  3668. writeln([space,' Univ : ',getboolean]);
  3669. writeln([space,' VarState : ',getbyte]);
  3670. writeln([space,' Refs : ',getbyte]);
  3671. if (vo_has_explicit_paraloc in varoptions) then
  3672. begin
  3673. readcgpara(space+' ');
  3674. end;
  3675. end;
  3676. ibenumsym :
  3677. begin
  3678. def:=TPpuConstDef.Create(nil);
  3679. readcommonsym('Enumeration symbol ',def);
  3680. write ([space,' Definition : ']);
  3681. readderef('');
  3682. TPpuConstDef(def).ConstType:=ctInt;
  3683. TPpuConstDef(def).VInt:=getlongint;
  3684. writeln([space,' Value : ',TPpuConstDef(def).VInt]);
  3685. if (ParentDef <> nil) and (ParentDef.DefType = dtEnum) then
  3686. def.Parent:=ParentDef;
  3687. end;
  3688. ibsyssym :
  3689. begin
  3690. readcommonsym('Internal system symbol ');
  3691. writeln([space,' Internal Nr : ',getlongint]);
  3692. end;
  3693. ibmacrosym :
  3694. begin
  3695. readcommonsym('Macro symbol ');
  3696. writeln([space,' Defined: ',getboolean]);
  3697. writeln([space,' Compiler var: ',getboolean]);
  3698. len:=getlongint;
  3699. writeln([space,' Value length: ',len]);
  3700. if len > 0 then
  3701. begin
  3702. getmem(pc,len+1);
  3703. getdata(pc^,len);
  3704. (pc+len)^:= #0;
  3705. writeln([space,' Value: "',pc,'"']);
  3706. freemem(pc,len+1);
  3707. end;
  3708. end;
  3709. ibpropertysym :
  3710. begin
  3711. def:=TPpuPropDef.Create(ParentDef);
  3712. readcommonsym('Property ',def);
  3713. write ([space,' Prop Options : ']);
  3714. propoptions:=readpropertyoptions;
  3715. if ppo_overrides in propoptions then
  3716. begin
  3717. write ([space,' OverrideProp : ']);
  3718. readderef('');
  3719. end;
  3720. if ppo_defaultproperty in propoptions then
  3721. Include(TPpuPropDef(def).Options, poDefault);
  3722. write ([space,' Prop Type : ']);
  3723. readderef('',TPpuPropDef(def).PropType);
  3724. writeln([space,' Index : ',getlongint]);
  3725. writeln([space,' Default : ',getlongint]);
  3726. write ([space,' Index Type : ']);
  3727. readderef('');
  3728. { palt_none }
  3729. write ([space,' Noneaccess : ']);
  3730. readpropaccesslist('');
  3731. write ([space,' Readaccess : ']);
  3732. readpropaccesslist(space+' Sym: ',TPpuPropDef(def).Getter);
  3733. write ([space,' Writeaccess : ']);
  3734. readpropaccesslist(space+' Sym: ',TPpuPropDef(def).Setter);
  3735. write ([space,' Storedaccess : ']);
  3736. readpropaccesslist(space+' Sym: ');
  3737. if [ppo_hasparameters,ppo_overrides]*propoptions=[ppo_hasparameters] then
  3738. begin
  3739. space:=' '+space;
  3740. readsymtable('parast',TPpuPropDef(def));
  3741. delete(space,1,4);
  3742. end;
  3743. end;
  3744. iberror :
  3745. begin
  3746. WriteError('!! Error in PPU');
  3747. exit;
  3748. end;
  3749. ibendsyms :
  3750. break;
  3751. else
  3752. begin
  3753. WriteError('!! Skipping unsupported PPU Entry in Symbols: '+IntToStr(b));
  3754. end;
  3755. end;
  3756. if assigned(def) then
  3757. readsymsubentries(def);
  3758. if (def <> nil) and (def.Parent = nil) then
  3759. def.Free;
  3760. if not EndOfEntry then
  3761. HasMoreInfos;
  3762. until false;
  3763. end;
  3764. end;
  3765. {****************************************************************************
  3766. Read defintions Part
  3767. ****************************************************************************}
  3768. procedure readdefinitions(const s:string; ParentDef: TPpuContainerDef);
  3769. { type tordtype is in symconst unit }
  3770. {
  3771. uvoid,
  3772. u8bit,u16bit,u32bit,u64bit,u128bit,
  3773. s8bit,s16bit,s32bit,s64bit,s128bit,
  3774. bool8bit,bool16bit,bool32bit,bool64bit,
  3775. uchar,uwidechar,scurrency,customint
  3776. ); }
  3777. { type tobjecttyp is in symconst unit }
  3778. { type tvarianttype is in symconst unit }
  3779. { type thelpertype is in symconst unit }
  3780. var
  3781. b : byte;
  3782. otb : byte; { Object Type byte, needed later again }
  3783. l,j,tokenbufsize : longint;
  3784. tokenbuf : pbyte;
  3785. calloption : tproccalloption;
  3786. procoptions : tprocoptions;
  3787. implprocoptions: timplprocoptions;
  3788. defoptions: tdefoptions;
  3789. iexpr: Tconstexprint;
  3790. def: TPpuDef;
  3791. objdef: TPpuObjectDef absolute def;
  3792. arrdef: TPpuArrayDef absolute def;
  3793. enumdef: TPpuEnumDef absolute def;
  3794. setdef: TPpuSetDef absolute def;
  3795. orddef: TPpuOrdDef absolute def;
  3796. floatdef: TPpuFloatDef absolute def;
  3797. strdef: TPpuStringDef absolute def;
  3798. filedef: TPpuFileDef absolute def;
  3799. begin
  3800. with ppufile do
  3801. begin
  3802. if space<>'' then
  3803. Writeln([space,'------ ',s,' ------']);
  3804. if readentry<>ibstartdefs then
  3805. Writeln('!! ibstartdefs not found');
  3806. repeat
  3807. def:=nil;
  3808. b:=readentry;
  3809. case b of
  3810. ibpointerdef :
  3811. begin
  3812. def:=TPpuPointerDef.Create(ParentDef);
  3813. readcommondef('Pointer definition',defoptions,def);
  3814. write ([space,' Pointed Type : ']);
  3815. readderef('',TPpuPointerDef(def).Ptr);
  3816. writeln([space,' Has Pointer Math : ',(getbyte<>0)]);
  3817. if tsystemcpu(ppufile.header.common.cpu) in [cpu_i8086,cpu_i386,cpu_x86_64] then
  3818. begin
  3819. write([space,' X86 Pointer Type : ']);
  3820. b:=getbyte;
  3821. case tx86pointertyp(b) of
  3822. x86pt_near: writeln('Near');
  3823. x86pt_near_cs: writeln('Near ''CS''');
  3824. x86pt_near_ds: writeln('Near ''DS''');
  3825. x86pt_near_ss: writeln('Near ''SS''');
  3826. x86pt_near_es: writeln('Near ''ES''');
  3827. x86pt_near_fs: writeln('Near ''FS''');
  3828. x86pt_near_gs: writeln('Near ''GS''');
  3829. x86pt_far: writeln('Far');
  3830. x86pt_huge: writeln('Huge');
  3831. else
  3832. WriteWarning('Invalid x86 pointer type: ' + IntToStr(b));
  3833. end;
  3834. end;
  3835. end;
  3836. iborddef :
  3837. begin
  3838. orddef:=TPpuOrdDef.Create(ParentDef);
  3839. readcommondef('Ordinal definition',defoptions,orddef);
  3840. write ([space,' Base type : ']);
  3841. b:=getbyte;
  3842. case tordtype(b) of
  3843. uvoid:
  3844. begin
  3845. writeln('uvoid');
  3846. orddef.OrdType:=otVoid;
  3847. end;
  3848. u8bit:
  3849. begin
  3850. writeln('u8bit');
  3851. orddef.OrdType:=otUInt;
  3852. orddef.Size:=1;
  3853. end;
  3854. u16bit:
  3855. begin
  3856. writeln('u16bit');
  3857. orddef.OrdType:=otUInt;
  3858. orddef.Size:=2;
  3859. end;
  3860. u32bit:
  3861. begin
  3862. writeln('u32bit');
  3863. orddef.OrdType:=otUInt;
  3864. orddef.Size:=4;
  3865. end;
  3866. u64bit:
  3867. begin
  3868. writeln('u64bit');
  3869. orddef.OrdType:=otUInt;
  3870. orddef.Size:=8;
  3871. end;
  3872. u128bit:
  3873. begin
  3874. writeln('u128bit');
  3875. orddef.OrdType:=otUInt;
  3876. orddef.Size:=16;
  3877. end;
  3878. s8bit:
  3879. begin
  3880. writeln('s8bit');
  3881. orddef.OrdType:=otSInt;
  3882. orddef.Size:=1;
  3883. end;
  3884. s16bit:
  3885. begin
  3886. writeln('s16bit');
  3887. orddef.OrdType:=otSInt;
  3888. orddef.Size:=2;
  3889. end;
  3890. s32bit:
  3891. begin
  3892. writeln('s32bit');
  3893. orddef.OrdType:=otSInt;
  3894. orddef.Size:=4;
  3895. end;
  3896. s64bit:
  3897. begin
  3898. writeln('s64bit');
  3899. orddef.OrdType:=otSInt;
  3900. orddef.Size:=8;
  3901. end;
  3902. s128bit:
  3903. begin
  3904. writeln('s128bit');
  3905. orddef.OrdType:=otSInt;
  3906. orddef.Size:=16;
  3907. end;
  3908. pasbool1:
  3909. begin
  3910. writeln('pasbool1');
  3911. orddef.OrdType:=otPasBool;
  3912. orddef.Size:=1;
  3913. end;
  3914. pasbool8:
  3915. begin
  3916. writeln('pasbool8');
  3917. orddef.OrdType:=otPasBool;
  3918. orddef.Size:=1;
  3919. end;
  3920. pasbool16:
  3921. begin
  3922. writeln('pasbool16');
  3923. orddef.OrdType:=otPasBool;
  3924. orddef.Size:=2;
  3925. end;
  3926. pasbool32:
  3927. begin
  3928. writeln('pasbool32');
  3929. orddef.OrdType:=otPasBool;
  3930. orddef.Size:=4;
  3931. end;
  3932. pasbool64:
  3933. begin
  3934. writeln('pasbool64');
  3935. orddef.OrdType:=otPasBool;
  3936. orddef.Size:=8;
  3937. end;
  3938. bool8bit:
  3939. begin
  3940. writeln('bool8bit');
  3941. orddef.OrdType:=otBool;
  3942. orddef.Size:=1;
  3943. end;
  3944. bool16bit:
  3945. begin
  3946. writeln('bool16bit');
  3947. orddef.OrdType:=otBool;
  3948. orddef.Size:=2;
  3949. end;
  3950. bool32bit:
  3951. begin
  3952. writeln('bool32bit');
  3953. orddef.OrdType:=otBool;
  3954. orddef.Size:=4;
  3955. end;
  3956. bool64bit:
  3957. begin
  3958. writeln('bool64bit');
  3959. orddef.OrdType:=otBool;
  3960. orddef.Size:=8;
  3961. end;
  3962. uchar:
  3963. begin
  3964. writeln('uchar');
  3965. orddef.OrdType:=otChar;
  3966. orddef.Size:=1;
  3967. end;
  3968. uwidechar:
  3969. begin
  3970. writeln('uwidechar');
  3971. orddef.OrdType:=otChar;
  3972. orddef.Size:=2;
  3973. end;
  3974. scurrency:
  3975. begin
  3976. writeln('scurrency');
  3977. orddef.OrdType:=otCurrency;
  3978. orddef.Size:=8;
  3979. end;
  3980. customint:
  3981. begin
  3982. writeln('customint');
  3983. orddef.OrdType:=otSint;
  3984. orddef.Size:=sizeof(ASizeInt);
  3985. end
  3986. else
  3987. WriteWarning('Invalid base type: ' + IntToStr(b));
  3988. end;
  3989. iexpr:=getexprint;
  3990. orddef.RangeLow:=iexpr.svalue;
  3991. write([space,' Range : ',constexp.tostr(iexpr)]);
  3992. iexpr:=getexprint;
  3993. orddef.RangeHigh:=iexpr.svalue;
  3994. writeln([' to ',constexp.tostr(iexpr)]);
  3995. end;
  3996. ibfloatdef :
  3997. begin
  3998. floatdef:=TPpuFloatDef.Create(ParentDef);
  3999. readcommondef('Float definition',defoptions,floatdef);
  4000. write ([space,' Float type : ']);
  4001. b:=getbyte;
  4002. case b of
  4003. ftSingle:
  4004. begin
  4005. writeln('Single');
  4006. floatdef.FloatType:=pftSingle;
  4007. end;
  4008. ftDouble:
  4009. begin
  4010. writeln('Double');
  4011. floatdef.FloatType:=pftDouble;
  4012. end;
  4013. ftExtended:
  4014. begin
  4015. writeln('Extended');
  4016. floatdef.FloatType:=pftExtended;
  4017. end;
  4018. ftComp:
  4019. begin
  4020. writeln('Comp');
  4021. floatdef.FloatType:=pftComp;
  4022. end;
  4023. ftCurr:
  4024. begin
  4025. writeln('Currency');
  4026. floatdef.FloatType:=pftCurrency;
  4027. end;
  4028. ftFloat128:
  4029. begin
  4030. writeln('Float128');
  4031. floatdef.FloatType:=pftFloat128;
  4032. end;
  4033. else
  4034. WriteWarning('Invalid float type: ' + IntToStr(b));
  4035. end;
  4036. end;
  4037. ibarraydef :
  4038. begin
  4039. arrdef:=TPpuArrayDef.Create(ParentDef);
  4040. readcommondef('Array definition',defoptions,arrdef);
  4041. write ([space,' Element type : ']);
  4042. readderef('',arrdef.ElType);
  4043. write ([space,' Range Type : ']);
  4044. readderef('',arrdef.RangeType);
  4045. arrdef.RangeLow:=getasizeint;
  4046. arrdef.RangeHigh:=getasizeint;
  4047. writeln([space,' Range : ',arrdef.RangeLow,' to ',arrdef.RangeHigh]);
  4048. write ([space,' Options : ']);
  4049. readarraydefoptions(arrdef);
  4050. if tsystemcpu(ppufile.header.common.cpu)=cpu_i8086 then
  4051. writeln([space,' Huge : ',(getbyte<>0)]);
  4052. readsymtable('symbols', arrdef);
  4053. end;
  4054. ibprocdef :
  4055. begin
  4056. def:=TPpuProcDef.Create(ParentDef);
  4057. readcommondef('Procedure definition',defoptions,def);
  4058. read_abstract_proc_def(calloption,procoptions,TPpuProcDef(def));
  4059. if (po_has_mangledname in procoptions) then
  4060. writeln([space,' Mangled name : ',readsymstr(ppufile)]);
  4061. writeln([space,' Number : ',getword]);
  4062. writeln([space,' Level : ',getbyte]);
  4063. write ([space,' Class : ']);
  4064. readderef('');
  4065. write ([space,' Procsym : ']);
  4066. readderef('', def.Ref);
  4067. write ([space,' File Pos : ']);
  4068. readposinfo(def);
  4069. write ([space,' Visibility : ']);
  4070. readvisibility(def);
  4071. write ([space,' SymOptions : ']);
  4072. readsymoptions(space+' ');
  4073. if (po_has_importdll in procoptions) then
  4074. writeln([space,' Import DLL : ',getstring]);
  4075. if (po_has_importname in procoptions) then
  4076. writeln([space,' Import Name : ',getstring]);
  4077. writeln([space,' Import Nr : ',getword]);
  4078. if (po_msgint in procoptions) then
  4079. writeln([space,' MsgInt : ',getlongint]);
  4080. if (po_msgstr in procoptions) then
  4081. writeln([space,' MsgStr : ',getstring]);
  4082. if (po_dispid in procoptions) then
  4083. writeln([space,' DispID: ',ppufile.getlongint]);
  4084. readprocimploptions(space,implprocoptions);
  4085. if (pio_has_inlininginfo in implprocoptions) then
  4086. begin
  4087. write ([space,' FuncretSym : ']);
  4088. readderef('');
  4089. readprocinfooptions(space);
  4090. end;
  4091. b:=ppufile.getbyte;
  4092. if b<>0 then
  4093. begin
  4094. write ([space,' Alias names : ']);
  4095. for j:=1 to b do
  4096. begin
  4097. write(ppufile.getstring);
  4098. if j<b then
  4099. write(', ');
  4100. end;
  4101. writeln;
  4102. end;
  4103. tokenbufsize:=ppufile.getlongint;
  4104. if tokenbufsize<>0 then
  4105. begin
  4106. space:=space + ' ';
  4107. write ([space,'Declaration token buffer : size = ',tokenbufsize]);
  4108. tokenbuf:=allocmem(tokenbufsize);
  4109. ppufile.getdata(tokenbuf^,tokenbufsize);
  4110. displaytokenbuffer(tokenbuf,tokenbufsize);
  4111. freemem(tokenbuf);
  4112. delete(space,1,4);
  4113. end;
  4114. if po_syscall_has_libsym in procoptions then
  4115. begin
  4116. { library symbol for AmigaOS/MorphOS/AROS }
  4117. write ([space,' Library symbol : ']);
  4118. readderef('');
  4119. end;
  4120. if not EndOfEntry then
  4121. HasMoreInfos;
  4122. space:=' '+space;
  4123. { parast }
  4124. readsymtable('parast', TPpuProcDef(def));
  4125. { localst }
  4126. if (pio_has_inlininginfo in implprocoptions) then
  4127. readsymtable('inline localst')
  4128. else if (df_generic in defoptions) then
  4129. readsymtable('generic localst');
  4130. if (pio_has_inlininginfo in implprocoptions) then
  4131. readnodetree;
  4132. delete(space,1,4);
  4133. end;
  4134. ibprocvardef :
  4135. begin
  4136. def:=TPpuProcTypeDef.Create(ParentDef);
  4137. readcommondef('Procedural type (ProcVar) definition',defoptions,def);
  4138. read_abstract_proc_def(calloption,procoptions, TPpuProcDef(def));
  4139. writeln([space,' Symtable level :',ppufile.getbyte]);
  4140. if tsystemcpu(ppufile.header.common.cpu)=cpu_jvm then
  4141. readderef('');
  4142. if not EndOfEntry then
  4143. HasMoreInfos;
  4144. space:=' '+space;
  4145. { parast }
  4146. readsymtable('parast',TPpuProcDef(def));
  4147. delete(space,1,4);
  4148. end;
  4149. ibshortstringdef :
  4150. begin
  4151. strdef:=TPpuStringDef.Create(ParentDef);
  4152. strdef.StrType:=stShort;
  4153. readcommondef('ShortString definition',defoptions,strdef);
  4154. strdef.Len:=getbyte;
  4155. writeln([space,' Length : ',strdef.Len]);
  4156. end;
  4157. ibwidestringdef :
  4158. begin
  4159. strdef:=TPpuStringDef.Create(ParentDef);
  4160. strdef.StrType:=stWide;
  4161. readcommondef('WideString definition',defoptions,strdef);
  4162. strdef.Len:=getasizeint;
  4163. writeln([space,' Length : ',strdef.Len]);
  4164. end;
  4165. ibunicodestringdef :
  4166. begin
  4167. strdef:=TPpuStringDef.Create(ParentDef);
  4168. strdef.StrType:=stUnicode;
  4169. readcommondef('UnicodeString definition',defoptions,strdef);
  4170. strdef.Len:=getasizeint;
  4171. writeln([space,' Length : ',strdef.Len]);
  4172. writeln([space,' Encoding : ',getword]);
  4173. end;
  4174. ibansistringdef :
  4175. begin
  4176. strdef:=TPpuStringDef.Create(ParentDef);
  4177. strdef.StrType:=stAnsi;
  4178. readcommondef('AnsiString definition',defoptions,strdef);
  4179. strdef.Len:=getasizeint;
  4180. writeln([space,' Length : ',strdef.Len]);
  4181. writeln([space,' Encoding : ',getword]);
  4182. end;
  4183. iblongstringdef :
  4184. begin
  4185. strdef:=TPpuStringDef.Create(ParentDef);
  4186. strdef.StrType:=stLong;
  4187. readcommondef('Longstring definition',defoptions,strdef);
  4188. strdef.Len:=getasizeint;
  4189. writeln([space,' Length : ',strdef.Len]);
  4190. end;
  4191. ibrecorddef :
  4192. begin
  4193. objdef:=TPpuRecordDef.Create(ParentDef);
  4194. readcommondef('Record definition',defoptions, objdef);
  4195. def.Name:=getstring;
  4196. writeln([space,' Name of Record : ',objdef.Name]);
  4197. writeln([space,' Import lib/pkg : ',getstring]);
  4198. write ([space,' Options : ']);
  4199. readobjectdefoptions(objdef);
  4200. if (df_copied_def in defoptions) then
  4201. begin
  4202. Include(TPpuRecordDef(def).Options, ooCopied);
  4203. write([space,' Copied from : ']);
  4204. readderef('',objdef.Ancestor);
  4205. end
  4206. else
  4207. begin
  4208. writeln([space,' FieldAlign : ',shortint(getbyte)]);
  4209. writeln([space,' RecordAlign : ',shortint(getbyte)]);
  4210. writeln([space,' PadAlign : ',shortint(getbyte)]);
  4211. writeln([space,'UseFieldAlignment : ',shortint(getbyte)]);
  4212. writeln([space,' RecordAlignMin : ',shortint(getbyte)]);
  4213. objdef.Size:=getasizeint;
  4214. writeln([space,' DataSize : ',objdef.Size]);
  4215. writeln([space,' PaddingSize : ',getword]);
  4216. readmanagementoperatoroptions(space,'Management operators');
  4217. end;
  4218. {read the record definitions and symbols}
  4219. if not(df_copied_def in current_defoptions) then
  4220. begin
  4221. space:=' '+space;
  4222. readrecordsymtable('fields',TPpuRecordDef(def));
  4223. Delete(space,1,4);
  4224. end;
  4225. if not EndOfEntry then
  4226. HasMoreInfos;
  4227. end;
  4228. ibobjectdef :
  4229. begin
  4230. objdef:=TPpuObjectDef.Create(ParentDef);
  4231. readcommondef('Object/Class definition',defoptions,objdef);
  4232. objdef.Name:=getstring;
  4233. writeln([space,' Name of Class : ',objdef.Name]);
  4234. writeln([space,' Import lib/pkg : ',getstring]);
  4235. write ([space,' Options : ']);
  4236. readobjectdefoptions(objdef);
  4237. otb:=getbyte;
  4238. write ([space,' Type : ']);
  4239. case tobjecttyp(otb) of
  4240. odt_class : writeln('class');
  4241. odt_object : writeln('object');
  4242. odt_interfacecom : writeln('interfacecom');
  4243. odt_interfacecorba : writeln('interfacecorba');
  4244. odt_cppclass : writeln('cppclass');
  4245. odt_dispinterface : writeln('dispinterface');
  4246. odt_objcclass : writeln('objcclass');
  4247. odt_objcprotocol : writeln('objcprotocol');
  4248. odt_helper : writeln('helper');
  4249. odt_objccategory : writeln('objccategory');
  4250. odt_javaclass : writeln('Java class');
  4251. odt_interfacejava : writeln('Java interface');
  4252. else WriteWarning('Invalid object type: ' + IntToStr(b));
  4253. end;
  4254. case tobjecttyp(otb) of
  4255. odt_class, odt_cppclass, odt_objcclass, odt_javaclass:
  4256. objdef.ObjType:=otClass;
  4257. odt_object:
  4258. objdef.ObjType:=otObject;
  4259. odt_interfacecom, odt_interfacecorba, odt_interfacejava, odt_dispinterface:
  4260. objdef.ObjType:=otInterface;
  4261. odt_helper:
  4262. objdef.ObjType:=otHelper;
  4263. end;
  4264. b:=getbyte;
  4265. write ([space,' Helper Type : ']);
  4266. case thelpertype(b) of
  4267. ht_none : writeln('none');
  4268. ht_class : writeln('class helper');
  4269. ht_record : writeln('record helper');
  4270. ht_type : writeln('type helper');
  4271. else WriteWarning('Invalid helper type: ' + IntToStr(b));
  4272. end;
  4273. writeln([space,' External name : ',getstring]);
  4274. objdef.Size:=getasizeint;
  4275. writeln([space,' DataSize : ',objdef.Size]);
  4276. writeln([space,' PaddingSize : ',getword]);
  4277. writeln([space,' FieldAlign : ',shortint(getbyte)]);
  4278. writeln([space,' RecordAlign : ',shortint(getbyte)]);
  4279. writeln([space,' RecordAlignMin : ',shortint(getbyte)]);
  4280. write ([space, ' VmtField : ']);
  4281. readderef('',nil);
  4282. write ([space, ' Ancestor Class : ']);
  4283. readderef('',objdef.Ancestor);
  4284. if tobjecttyp(otb) in [odt_interfacecom,odt_interfacecorba,odt_dispinterface] then
  4285. begin
  4286. { IIDGUID }
  4287. for j:=1to 16 do
  4288. getbyte;
  4289. objdef.IID:=getstring;
  4290. writeln([space,' IID String : ',objdef.IID]);
  4291. end;
  4292. l:=getlongint;
  4293. if l > 0 then
  4294. objdef.Options:=objdef.Options + [ooAbstractMethods];
  4295. writeln([space,' Abstract methods : ',l]);
  4296. if tobjecttyp(otb)=odt_helper then
  4297. begin
  4298. write([space,' Helper parent : ']);
  4299. readderef('',objdef.HelperParent);
  4300. end;
  4301. l:=getlongint;
  4302. writeln([space,' VMT entries: ',l]);
  4303. for j:=1 to l do
  4304. begin
  4305. write([space,' ']);
  4306. readderef('');
  4307. write([space,' Visibility: ']);
  4308. readvisibility;
  4309. end;
  4310. if tobjecttyp(otb) in [odt_class,odt_objcclass,odt_objcprotocol,odt_javaclass,odt_interfacejava] then
  4311. begin
  4312. l:=getlongint;
  4313. writeln([space,' Impl Intf Count : ',l]);
  4314. for j:=1 to l do
  4315. begin
  4316. write ([space,' - Definition : ']);
  4317. readderef('');
  4318. write ([space,' - Getter Def : ']);
  4319. readderef('');
  4320. writeln([space,' IOffset : ',getlongint]);
  4321. writeln([space,' Entry type : ',IntfEntryType2Str(getbyte)]);
  4322. end;
  4323. end;
  4324. if df_copied_def in current_defoptions then
  4325. begin
  4326. Include(objdef.Options, ooCopied);
  4327. writeln(' Copy of def: ');
  4328. readderef('',objdef.Ancestor);
  4329. end
  4330. else
  4331. begin
  4332. {read the record definitions and symbols}
  4333. space:=' '+space;
  4334. readrecordsymtable('fields',objdef);
  4335. Delete(space,1,4);
  4336. end;
  4337. if not EndOfEntry then
  4338. HasMoreInfos;
  4339. end;
  4340. ibfiledef :
  4341. begin
  4342. filedef:=TPpuFileDef.Create(ParentDef);
  4343. ReadCommonDef('File definition',defoptions,filedef);
  4344. write ([space,' Type : ']);
  4345. case getbyte of
  4346. 0 : begin
  4347. writeln('Text');
  4348. filedef.FileType:=ftText;
  4349. end;
  4350. 1 : begin
  4351. writeln('Typed');
  4352. filedef.FileType:=ftTyped;
  4353. write ([space,' File of Type : ']);
  4354. readderef('',filedef.TypeRef);
  4355. end;
  4356. 2 : begin
  4357. writeln('Untyped');
  4358. filedef.FileType:=ftUntyped;
  4359. end;
  4360. end;
  4361. end;
  4362. ibformaldef :
  4363. begin
  4364. def:=TPpuFormalDef.Create(ParentDef);
  4365. readcommondef('Generic definition (void-typ)',defoptions,def);
  4366. TPpuFormalDef(def).IsTyped:=(getbyte<>0);
  4367. writeln([space,' Is Typed : ',TPpuFormalDef(def).IsTyped]);
  4368. end;
  4369. ibundefineddef :
  4370. begin
  4371. def:=TPpuUndefinedDef.Create(ParentDef);
  4372. readcommondef('Undefined definition (generic parameter)',defoptions,def);
  4373. end;
  4374. ibenumdef :
  4375. begin
  4376. enumdef:=TPpuEnumDef.Create(ParentDef);
  4377. readcommondef('Enumeration type definition',defoptions,enumdef);
  4378. enumdef.ElLow:=getaint;
  4379. writeln([space,' Smallest element : ',enumdef.ElLow]);
  4380. enumdef.ElHigh:=getaint;
  4381. writeln([space,' Largest element : ',enumdef.ElHigh]);
  4382. enumdef.Size:=byte(getaint);
  4383. writeln([space,' Size : ',enumdef.Size]);
  4384. if df_copied_def in defoptions then
  4385. begin
  4386. write([space,'Base enumeration type : ']);
  4387. readderef('',enumdef.CopyFrom);
  4388. end
  4389. else
  4390. begin
  4391. space:=' '+space;
  4392. readsymtable('elements',enumdef);
  4393. delete(space,1,4);
  4394. end;
  4395. if tsystemcpu(ppufile.header.common.cpu)=cpu_jvm then
  4396. begin
  4397. write([space,' Class def : ']);
  4398. readderef('');
  4399. end;
  4400. end;
  4401. ibclassrefdef :
  4402. begin
  4403. def:=TPpuClassRefDef.Create(ParentDef);
  4404. readcommondef('Class reference definition',defoptions,def);
  4405. write ([space,' Pointed Type : ']);
  4406. readderef('',TPpuClassRefDef(def).ClassRef);
  4407. end;
  4408. ibsetdef :
  4409. begin
  4410. setdef:=TPpuSetDef.Create(ParentDef);
  4411. readcommondef('Set definition',defoptions,setdef);
  4412. write ([space,' Element type : ']);
  4413. readderef('',setdef.ElType);
  4414. setdef.Size:=getasizeint;
  4415. writeln([space,' Size : ',setdef.Size]);
  4416. setdef.SetBase:=getasizeint;
  4417. writeln([space,' Set Base : ',setdef.SetBase]);
  4418. setdef.SetMax:=getasizeint;
  4419. writeln([space,' Set Max : ',setdef.SetMax]);
  4420. end;
  4421. ibvariantdef :
  4422. begin
  4423. def:=TPpuVariantDef.Create(ParentDef);
  4424. readcommondef('Variant definition',defoptions,def);
  4425. write ([space,' Varianttype : ']);
  4426. b:=getbyte;
  4427. case tvarianttype(b) of
  4428. vt_normalvariant :
  4429. writeln('Normal');
  4430. vt_olevariant :
  4431. begin
  4432. TPpuVariantDef(def).IsOLE:=True;
  4433. writeln('OLE');
  4434. end
  4435. else
  4436. WriteWarning('Invalid varianttype: ' + IntToStr(b));
  4437. end;
  4438. end;
  4439. iberror :
  4440. begin
  4441. WriteError('!! Error in PPU');
  4442. exit;
  4443. end;
  4444. ibenddefs :
  4445. break;
  4446. else
  4447. begin
  4448. WriteError('!! Skipping unsupported PPU Entry in definitions: '+IntToStr(b));
  4449. end;
  4450. end;
  4451. if assigned(def) then
  4452. readdefsubentries(def);
  4453. if (def <> nil) and (def.Parent = nil) then
  4454. def.Free;
  4455. if not EndOfEntry then
  4456. HasMoreInfos;
  4457. until false;
  4458. end;
  4459. end;
  4460. procedure readmoduleoptions(space : string);
  4461. type
  4462. { tmoduleoption type is in unit fmodule }
  4463. tmoduleoption = (mo_none,
  4464. mo_hint_deprecated,
  4465. mo_hint_platform,
  4466. mo_hint_library,
  4467. mo_hint_unimplemented,
  4468. mo_hint_experimental,
  4469. mo_has_deprecated_msg
  4470. );
  4471. tmoduleoptions = set of tmoduleoption;
  4472. tmoduleopt=record
  4473. mask : tmoduleoption;
  4474. str : string[30];
  4475. end;
  4476. const
  4477. moduleopts=ord(high(tmoduleoption));
  4478. moduleopt : array[1..moduleopts] of tmoduleopt=(
  4479. (mask:mo_hint_deprecated; str:'Hint Deprecated'),
  4480. (mask:mo_hint_platform; str:'Hint Platform'),
  4481. (mask:mo_hint_library; str:'Hint Library'),
  4482. (mask:mo_hint_unimplemented; str:'Hint Unimplemented'),
  4483. (mask:mo_hint_experimental; str:'Hint Experimental'),
  4484. (mask:mo_has_deprecated_msg; str:'Has Deprecated Message')
  4485. );
  4486. var
  4487. moduleoptions : tmoduleoptions;
  4488. i : longint;
  4489. first : boolean;
  4490. begin
  4491. ppufile.getset(tppuset1(moduleoptions));
  4492. if moduleoptions<>[] then
  4493. begin
  4494. first:=true;
  4495. for i:=1to moduleopts do
  4496. if (moduleopt[i].mask in moduleoptions) then
  4497. begin
  4498. if first then
  4499. first:=false
  4500. else
  4501. write(', ');
  4502. write(moduleopt[i].str);
  4503. end;
  4504. end;
  4505. writeln;
  4506. if mo_has_deprecated_msg in moduleoptions then
  4507. writeln([space,'Deprecated : ', ppufile.getstring]);
  4508. end;
  4509. {****************************************************************************
  4510. Read General Part
  4511. ****************************************************************************}
  4512. procedure readinterface(silent : boolean);
  4513. var
  4514. b : byte;
  4515. sourcenumber, i : longint;
  4516. feature : tfeature;
  4517. features : tfeatures;
  4518. s : string;
  4519. begin
  4520. with ppufile do
  4521. begin
  4522. repeat
  4523. b:=readentry;
  4524. case b of
  4525. ibmodulename :
  4526. begin
  4527. CurUnit.Name:=getstring;
  4528. if not silent then
  4529. Writeln(['Module Name: ',CurUnit.Name]);
  4530. end;
  4531. ibfeatures :
  4532. begin
  4533. getset(tppuset4(features));
  4534. Writeln('Features: ');
  4535. for feature:=low(tfeatures) to high(tfeature) do
  4536. if feature in features then
  4537. begin
  4538. str(feature,s);
  4539. s:=copy(s,3,255);
  4540. writeln([s]);
  4541. end;
  4542. end;
  4543. ibmoduleoptions:
  4544. if not silent then
  4545. readmoduleoptions(' ');
  4546. ibsourcefiles :
  4547. begin
  4548. sourcenumber:=1;
  4549. if not silent then
  4550. while not EndOfEntry do
  4551. begin
  4552. with TPpuSrcFile.Create(CurUnit.SourceFiles) do begin
  4553. Name:=getstring;
  4554. i:=getlongint;
  4555. try
  4556. if i >= 0 then
  4557. FileTime:=FileDateToDateTime(i);
  4558. Writeln(['Source file ',sourcenumber,' : ',Name,' ',filetimestring(i)]);
  4559. except
  4560. end;
  4561. end;
  4562. inc(sourcenumber);
  4563. end;
  4564. end;
  4565. {$IFDEF MACRO_DIFF_HINT}
  4566. ibusedmacros :
  4567. begin
  4568. if not silent then
  4569. while not EndOfEntry do
  4570. begin
  4571. Write('Conditional ',getstring);
  4572. if getboolean then
  4573. write(' defined at startup')
  4574. else
  4575. write(' not defined at startup');
  4576. if getboolean then
  4577. writeln(' was used')
  4578. else
  4579. writeln;
  4580. end;
  4581. end;
  4582. {$ENDIF}
  4583. ibloadunit :
  4584. if not silent then
  4585. ReadLoadUnit;
  4586. iblinkunitofiles :
  4587. if not silent then
  4588. ReadLinkContainer('Link unit object file: ');
  4589. iblinkunitstaticlibs :
  4590. if not silent then
  4591. ReadLinkContainer('Link unit static lib: ');
  4592. iblinkunitsharedlibs :
  4593. if not silent then
  4594. ReadLinkContainer('Link unit shared lib: ');
  4595. iblinkotherofiles :
  4596. if not silent then
  4597. ReadLinkContainer('Link other object file: ');
  4598. iblinkotherstaticlibs :
  4599. if not silent then
  4600. ReadLinkContainer('Link other static lib: ');
  4601. iblinkothersharedlibs :
  4602. if not silent then
  4603. ReadLinkContainer('Link other shared lib: ');
  4604. iblinkotherframeworks:
  4605. if not silent then
  4606. ReadLinkContainer('Link framework: ');
  4607. ibjvmnamespace:
  4608. Writeln('JVM name space: '+getString);
  4609. ibmainname:
  4610. if not silent then
  4611. Writeln(['Specified main program symbol name: ',getstring]);
  4612. ibImportSymbols :
  4613. if not silent then
  4614. ReadImportSymbols;
  4615. ibderefdata :
  4616. ReadDerefData;
  4617. ibderefmap :
  4618. ReadDerefMap;
  4619. ibwpofile :
  4620. if not silent then
  4621. ReadWpoFileInfo;
  4622. ibresources :
  4623. if not silent then
  4624. ReadContainer('Resource file: ');
  4625. iborderedsymbols:
  4626. if not silent then
  4627. ReadContainer('Ordered symbol: ');
  4628. iberror :
  4629. begin
  4630. WriteError('Error in PPU');
  4631. exit;
  4632. end;
  4633. ibendinterface :
  4634. break;
  4635. else
  4636. begin
  4637. WriteError('!! Skipping unsupported PPU Entry in General Part: '+IntToStr(b));
  4638. end;
  4639. end;
  4640. until false;
  4641. end;
  4642. end;
  4643. {****************************************************************************
  4644. Read Implementation Part
  4645. ****************************************************************************}
  4646. procedure readimplementation;
  4647. var
  4648. b : byte;
  4649. begin
  4650. with ppufile do
  4651. begin
  4652. repeat
  4653. b:=readentry;
  4654. case b of
  4655. ibasmsymbols :
  4656. ReadAsmSymbols;
  4657. ibloadunit :
  4658. ReadLoadUnit;
  4659. ibunitimportsyms :
  4660. ReadUnitImportSyms;
  4661. iberror :
  4662. begin
  4663. WriteError('Error in PPU');
  4664. exit;
  4665. end;
  4666. ibendimplementation :
  4667. break;
  4668. else
  4669. begin
  4670. WriteError('!! Skipping unsupported PPU Entry in Implementation: '+IntToStr(b));
  4671. end;
  4672. end;
  4673. until false;
  4674. end;
  4675. end;
  4676. function parseextraheader(module: TPpuModuleDef; ppufile: tppufile): boolean;
  4677. var
  4678. b: byte;
  4679. begin
  4680. result:=false;
  4681. b:=ppufile.readentry;
  4682. if b<>ibextraheader then
  4683. exit;
  4684. CurUnit.LongVersion:=cardinal(ppufile.getlongint);
  4685. Writeln(['LongVersion: ',CurUnit.LongVersion]);
  4686. ppufile.getset(tppuset4(CurUnit.ModuleFlags));
  4687. result:=ppufile.EndOfEntry and (CurUnit.LongVersion=CurrentPPULongVersion);
  4688. if mf_symansistr in CurUnit.ModuleFlags then
  4689. SymAnsiStr:=true;
  4690. end;
  4691. procedure dofile (filename : string);
  4692. begin
  4693. { reset }
  4694. space:='';
  4695. { fix filename }
  4696. if pos('.',filename)=0 then
  4697. filename:=filename+'.ppu';
  4698. ppufile:=tppudumpfile.create(filename);
  4699. if not ppufile.openfile then
  4700. begin
  4701. WriteError('IO-Error when opening : '+filename+', Skipping');
  4702. exit;
  4703. end;
  4704. { PPU File is open, check for PPU Id }
  4705. if not ppufile.CheckPPUID then
  4706. begin
  4707. WriteError(Filename+' : Not a valid PPU file, Skipping');
  4708. exit;
  4709. end;
  4710. { Check PPU Version }
  4711. ppuversion:=ppufile.getversion;
  4712. Writeln(['Analyzing ',filename,' (v',PPUVersion,')']);
  4713. if not SkipVersionCheck and (PPUVersion <> CurrentPPUVersion) then
  4714. begin
  4715. WriteError(Format('Unsupported PPU version %d. Expecting PPU version %d.', [PPUVersion, CurrentPPUVersion]));
  4716. exit;
  4717. end;
  4718. CurUnit:=TPpuModuleDef.Create(UnitList);
  4719. CurUnit.Version:=ppuversion;
  4720. if not parseextraheader(CurUnit, ppufile) then
  4721. begin
  4722. WriteError(Format('Unsupported PPU sub-version %d. Expecting PPU sub-version %d.', [CurUnit.LongVersion, CurrentPPULongVersion]));
  4723. end;
  4724. { Write PPU Header Information }
  4725. if (verbose and v_header)<>0 then
  4726. begin
  4727. Writeln;
  4728. Writeln('Header');
  4729. Writeln('-------');
  4730. with ppufile.header do
  4731. begin
  4732. Writeln(['Compiler version : ',ppufile.header.common.compiler shr 14,'.',
  4733. (ppufile.header.common.compiler shr 7) and $7f,'.',
  4734. ppufile.header.common.compiler and $7f]);
  4735. WriteLn(['Target processor : ',Cpu2Str(common.cpu)]);
  4736. WriteLn(['Target operating system : ',Target2Str(common.target)]);
  4737. Writeln(['Unit flags : ',PPUFlags2Str(common.flags)]);
  4738. Writeln(['FileSize (w/o header) : ',common.size]);
  4739. Writeln(['Checksum : ',hexstr(checksum,8)]);
  4740. Writeln(['Interface Checksum : ',hexstr(interface_checksum,8)]);
  4741. Writeln(['Indirect Checksum : ',hexstr(indirect_checksum,8)]);
  4742. Writeln(['Definitions stored : ',tostr(deflistsize)]);
  4743. Writeln(['Symbols stored : ',tostr(symlistsize)]);
  4744. end;
  4745. end;
  4746. with ppufile.header do
  4747. begin
  4748. CurUnit.Crc:=checksum;
  4749. CurUnit.IntfCrc:=interface_checksum;
  4750. CurUnit.TargetCPU:=Cpu2Str(common.cpu);
  4751. CurUnit.TargetOS:=Target2Str(common.target);
  4752. end;
  4753. {read the general stuff}
  4754. if (verbose and v_interface)<>0 then
  4755. begin
  4756. Writeln;
  4757. Writeln('Interface section');
  4758. Writeln('------------------');
  4759. readinterface(false);
  4760. end
  4761. { We need derefdata from Interface }
  4762. else if verbose and (v_defs or v_syms or v_implementation)<>0 then
  4763. readinterface(true)
  4764. else
  4765. ppufile.skipuntilentry(ibendinterface);
  4766. Writeln;
  4767. Writeln('Interface symtable');
  4768. Writeln('----------------------');
  4769. readsymtableoptions('interface');
  4770. {read the definitions}
  4771. if (verbose and v_defs)<>0 then
  4772. begin
  4773. Writeln;
  4774. Writeln('Interface definitions');
  4775. Writeln('----------------------');
  4776. readdefinitions('interface', CurUnit);
  4777. end
  4778. else
  4779. ppufile.skipuntilentry(ibenddefs);
  4780. {read the symbols}
  4781. if (verbose and v_syms)<>0 then
  4782. begin
  4783. Writeln;
  4784. Writeln('Interface Symbols');
  4785. Writeln('------------------');
  4786. readsymbols('interface',CurUnit);
  4787. end
  4788. else
  4789. ppufile.skipuntilentry(ibendsyms);
  4790. {read the macro symbols}
  4791. if (verbose and v_syms)<>0 then
  4792. begin
  4793. Writeln;
  4794. Writeln('Interface Macro Symbols');
  4795. Writeln('-----------------------');
  4796. end;
  4797. if ppufile.readentry<>ibexportedmacros then
  4798. begin
  4799. WriteError('!! Error in PPU');
  4800. exit;
  4801. end;
  4802. if ppufile.getboolean then
  4803. begin
  4804. readsymtableoptions('interface macro');
  4805. {skip the definition section for macros (since they are never used) }
  4806. ppufile.skipuntilentry(ibenddefs);
  4807. {read the macro symbols}
  4808. if (verbose and v_syms)<>0 then
  4809. readsymbols('interface macro')
  4810. else
  4811. ppufile.skipuntilentry(ibendsyms);
  4812. end
  4813. else
  4814. Writeln('(no exported macros)');
  4815. {read the implementation stuff}
  4816. if (verbose and v_implementation)<>0 then
  4817. begin
  4818. Writeln;
  4819. Writeln('Implementation section');
  4820. Writeln('-----------------------');
  4821. readimplementation;
  4822. end
  4823. else
  4824. ppufile.skipuntilentry(ibendimplementation);
  4825. {read the static symtable}
  4826. Writeln;
  4827. Writeln('Implementation symtable');
  4828. Writeln('----------------------');
  4829. readsymtableoptions('implementation');
  4830. if (mf_local_symtable in CurUnit.ModuleFlags) then
  4831. begin
  4832. if (verbose and v_defs)<>0 then
  4833. begin
  4834. Writeln;
  4835. Writeln('Static definitions');
  4836. Writeln('----------------------');
  4837. readdefinitions('implementation', nil);
  4838. end
  4839. else
  4840. ppufile.skipuntilentry(ibenddefs);
  4841. {read the symbols}
  4842. if (verbose and v_syms)<>0 then
  4843. begin
  4844. Writeln;
  4845. Writeln('Static Symbols');
  4846. Writeln('------------------');
  4847. readsymbols('implementation');
  4848. end
  4849. else
  4850. ppufile.skipuntilentry(ibendsyms);
  4851. end;
  4852. ReadCreatedObjTypes;
  4853. FreeDerefdata;
  4854. {shutdown ppufile}
  4855. ppufile.closefile;
  4856. ppufile.free;
  4857. Writeln;
  4858. end;
  4859. procedure WriteLogo;
  4860. begin
  4861. writeln(Title+' Version '+version_string);
  4862. writeln(Copyright);
  4863. writeln;
  4864. end;
  4865. procedure help;
  4866. begin
  4867. WriteLogo;
  4868. writeln('usage: ppudump [options] <filename1> <filename2>...');
  4869. writeln;
  4870. writeln('[options] can be:');
  4871. writeln(' -F<format> Set output format to <format>');
  4872. writeln(' t - text format (default)');
  4873. writeln(' j - JSON format');
  4874. writeln(' x - XML format');
  4875. writeln(' -M Exit with ExitCode=2 if more information is available');
  4876. writeln(' -S Skip PPU version check. May lead to reading errors');
  4877. writeln(' -V<verbose> Set verbosity to <verbose>');
  4878. writeln(' H - Show header info');
  4879. writeln(' I - Show interface');
  4880. writeln(' M - Show implementation');
  4881. writeln(' S - Show interface symbols');
  4882. writeln(' D - Show interface definitions');
  4883. writeln(' A - Show all');
  4884. writeln(' -h, -? This helpscreen');
  4885. halt;
  4886. end;
  4887. var
  4888. startpara,
  4889. nrfile,i : longint;
  4890. para : string;
  4891. const
  4892. error_on_more : boolean = false;
  4893. begin
  4894. if paramcount<1 then
  4895. help;
  4896. { turn verbose on by default }
  4897. verbose:=v_all;
  4898. { read options }
  4899. startpara:=1;
  4900. while copy(paramstr(startpara),1,1)='-' do
  4901. begin
  4902. para:=paramstr(startpara);
  4903. case upcase(para[2]) of
  4904. 'F' : begin
  4905. FreeAndNil(pout);
  4906. if Length(para) > 2 then
  4907. case upcase(para[3]) of
  4908. 'T':
  4909. nostdout:=False;
  4910. 'J':
  4911. begin
  4912. nostdout:=True;
  4913. pout:=TPpuJsonOutput.Create(StdOutputHandle);
  4914. end;
  4915. 'X':
  4916. begin
  4917. nostdout:=True;
  4918. pout:=TPpuXmlOutput.Create(StdOutputHandle);
  4919. end;
  4920. else
  4921. begin
  4922. WriteError('Invalid output format: ' + para[3]);
  4923. Halt(1);
  4924. end;
  4925. end;
  4926. end;
  4927. 'M' : error_on_more:=true;
  4928. 'S' : SkipVersionCheck:=True;
  4929. 'V' : begin
  4930. verbose:=0;
  4931. for i:=3 to length(para) do
  4932. case upcase(para[i]) of
  4933. 'H' : verbose:=verbose or v_header;
  4934. 'I' : verbose:=verbose or v_interface;
  4935. 'M' : verbose:=verbose or v_implementation;
  4936. 'D' : verbose:=verbose or v_defs;
  4937. 'S' : verbose:=verbose or v_syms;
  4938. 'A' : verbose:=verbose or v_all;
  4939. end;
  4940. end;
  4941. 'H' : help;
  4942. '?' : help;
  4943. else
  4944. begin
  4945. WriteError('Invalid option: ' + para);
  4946. Halt(1);
  4947. end;
  4948. end;
  4949. inc(startpara);
  4950. end;
  4951. if not nostdout then
  4952. WriteLogo;
  4953. UnitList:=TPpuContainerDef.Create(nil);
  4954. try
  4955. UnitList.ItemsName:='';
  4956. { process files }
  4957. for nrfile:=startpara to paramcount do
  4958. dofile (paramstr(nrfile));
  4959. if not has_errors and (pout <> nil) then
  4960. begin
  4961. pout.Init;
  4962. UnitList.Write(pout);
  4963. pout.Done;
  4964. end;
  4965. finally
  4966. UnitList.Free;
  4967. pout.Free;
  4968. end;
  4969. if has_errors then
  4970. Halt(1);
  4971. if error_on_more and
  4972. (has_more_infos or has_warnings) then
  4973. Halt(2);
  4974. end.