ppudump.pp 165 KB

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