ppudump.pp 166 KB

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