ppudump.pp 168 KB

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