ppudump.pp 168 KB

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